Index: firmware/App/Drivers/ConductivitySensors.c =================================================================== diff -u -r325e67dab10f6666702bf0f1256015b31e58de4f -r895a48e398bbd9621425f781f9ff7974fb3dd523 --- firmware/App/Drivers/ConductivitySensors.c (.../ConductivitySensors.c) (revision 325e67dab10f6666702bf0f1256015b31e58de4f) +++ firmware/App/Drivers/ConductivitySensors.c (.../ConductivitySensors.c) (revision 895a48e398bbd9621425f781f9ff7974fb3dd523) @@ -80,6 +80,10 @@ static CONDUCTIVITY_SENSOR_CONTROL_T conductivitySensorControl[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Conductivity sensor Control for reset, init, read and write operations. +static CONDUCTIVITY_MEASUREMENT_SETTINGS_T conductivityMeasurementSettings; +static CONDUCTIVITY_EEPROM_DATA_T conductivityEEPROMdata; +static CONDUCTIVITY_SENSOR_DATA_T conductivityMeasurements[ MAX_CONDUCTIVITY_SENSOR ]; + // ********** private function prototypes ********** static void checkConductivitySensors( void ); @@ -88,6 +92,10 @@ static CONDUCTIVITY_WRITE_STATE_T handleConductivitySensorsWriteInitiate( CONDUCTIVITY_SENSORS_T sensorID ); static CONDUCTIVITY_READ_STATE_T handleConductivitySensorsReadComplete( CONDUCTIVITY_SENSORS_T sensorID ); +static CONDUCTIVITY_PARSE_STATUS parseMeasurementSettings(const U32 *buffer, U32 len); +static CONDUCTIVITY_PARSE_STATUS parseEEPROMdata( const U32 *buffer, U32 len ); +static CONDUCTIVITY_PARSE_STATUS parseConductivityMeasurements(const U32 *buffer, uint32_t len); + /*********************************************************************//** * @brief * The initConductivitySensors function initializes the ConductivitySensors unit. @@ -990,6 +998,106 @@ } +static CONDUCTIVITY_PARSE_STATUS parseMeasurementSettings( const U32 *buffer, U32 len ) +{ + CONDUCTIVITY_PARSE_STATUS parseStatus = CONDUCTIVITY_PARSE_SUCCESS; + U32 expectedDataLength = sizeof( CONDUCTIVITY_MEASUREMENT_SETTINGS_T ); + + // Validate buffer + if ( buffer == NULL ) + { + parseStatus = CONDUCTIVITY_PARSE_ERROR_NULL_BUFFER; + } + // Validate buffer length + else if ( len != expectedDataLength ) + { + parseStatus = CONDUCTIVITY_PARSE_ERROR_INVALID_LENGTH; + } + else + { + // Parse and Store the data + memcpy( &conductivityMeasurementSettings, buffer, expectedDataLength ); + } + + return parseStatus; +} + +static CONDUCTIVITY_PARSE_STATUS parseEEPROMdata( const U32 *buffer, U32 len ) +{ + CONDUCTIVITY_PARSE_STATUS parseStatus = CONDUCTIVITY_PARSE_SUCCESS; + U32 expectedDataLength = sizeof( CONDUCTIVITY_EEPROM_DATA_T ); + + // Validate buffer + if ( buffer == NULL ) + { + parseStatus = CONDUCTIVITY_PARSE_ERROR_NULL_BUFFER; + } + // Validate buffer length + else if ( len != expectedDataLength ) + { + parseStatus = CONDUCTIVITY_PARSE_ERROR_INVALID_LENGTH; + } + else + { + // Parse and Store the data + memcpy( &conductivityEEPROMdata, buffer, expectedDataLength ); + } + + return parseStatus; +} + +static CONDUCTIVITY_PARSE_STATUS parseConductivityMeasurements(const U32 *buffer, U32 len) +{ + CONDUCTIVITY_PARSE_STATUS parseStatus = CONDUCTIVITY_PARSE_SUCCESS; + U32 expectedDataLength = sizeof( CONDUCTIVITY_SENSOR_DATA_T ); + U32 sensorCount = 0; + U16 sensorIdx = 0; + + // // Validate buffer + if ( NULL == buffer ) + { + parseStatus = CONDUCTIVITY_PARSE_ERROR_NULL_BUFFER; + } + + // Validate buffer length + else if ( ( len % expectedDataLength ) != 0 ) + { + parseStatus = CONDUCTIVITY_PARSE_ERROR_INVALID_LENGTH; + } + else + { + // Calculate the number of sensors for which we have received the data + sensorCount = len / expectedDataLength; + + // Parse the data and store in conductivityMeasurements[] + for ( sensorIdx = 0; sensorIdx < sensorCount; sensorIdx++ ) + { + // Read the sensor data temporarily + CONDUCTIVITY_SENSOR_DATA_T tempSensor; + memcpy(&tempSensor, ( buffer + ( sensorIdx * expectedDataLength ) ), expectedDataLength ); + + // And check if the received sensor number id valid + if ( (tempSensor.sensorNum < 1 ) || + ( tempSensor.sensorNum > MAX_CONDUCTIVITY_SENSOR ) ) + { + parseStatus = CONDUCTIVITY_PARSE_ERROR_INVALID_SENSOR_NUM; + break; + } + else + { + // The received data value contains sensor values from 1 to 6. + // So store value in array index for position (sensorNum - 1) i.e. 0 to 5. + conductivityMeasurements[tempSensor.sensorNum - 1] = tempSensor; + } + } + } + + return parseStatus; +} + + + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/