Index: firmware/App/Drivers/ConductivitySensors.c =================================================================== diff -u -r895a48e398bbd9621425f781f9ff7974fb3dd523 -r89c78ab89ac3909d5fe74f491f6f3b3cadd0ccf8 --- firmware/App/Drivers/ConductivitySensors.c (.../ConductivitySensors.c) (revision 895a48e398bbd9621425f781f9ff7974fb3dd523) +++ firmware/App/Drivers/ConductivitySensors.c (.../ConductivitySensors.c) (revision 89c78ab89ac3909d5fe74f491f6f3b3cadd0ccf8) @@ -80,10 +80,23 @@ 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_INIT_STATUS_T conductivityInitStatus; static CONDUCTIVITY_EEPROM_DATA_T conductivityEEPROMdata; -static CONDUCTIVITY_SENSOR_DATA_T conductivityMeasurements[ MAX_CONDUCTIVITY_SENSOR ]; +static CONDUCTIVITY_MEASUREMENT_SETTINGS_T conductivityMeasurementSettings; +static CONDUCTIVITY_SENSOR_DATA_T rawConductivityValues[ MAX_TEENSY_SENSOR ]; +static CONDUCTIVITY_CALCULATED_MEASUREMENTS_T calculatedMeasurement[ MAX_TEENSY_SENSOR ]; +static CONDUCTIVITY_COEFFICIENTS_T conductivityCoeff[MAX_TEENSY_SENSOR]; +static const TEENSY_SENSOR_INDEX_T teensySensorMapping[NUM_OF_CONDUCTIVITY_SENSORS] = { + [D17_COND] = TEENSY_SENSOR_0, + [D27_COND] = TEENSY_SENSOR_1, + [D43_COND] = TEENSY_SENSOR_2, + [D74_COND] = TEENSY_SENSOR_3, + [P9_COND] = TEENSY_SENSOR_4, + [P18_COND] = TEENSY_SENSOR_5 +}; + + // ********** private function prototypes ********** static void checkConductivitySensors( void ); @@ -92,10 +105,36 @@ 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 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); +static CONDUCTIVITY_PARSE_STATUS parseConductivityMeasurements( const U32 *buffer, U32 len ); +static void sendCmd_getInitStatus( void ); +static void sendCmd_updateEEPROMdata( CONDUCTIVITY_EEPROM_DATA_T eepromData); +static void sendCmd_getEEPROMdata( void ); +static void sendCmd_updateMeasurementSettings( CONDUCTIVITY_MEASUREMENT_SETTINGS_T measurememtSettings ); +static void sendCmd_getMeasurementSettings( void ); +static void sendCmd_getSingleMeasurement( CONDUCTIVITY_SENSORS_T sensorID ); +static void sendCmd_getAllMeasurements( void ); + +static void receiveResponse_getInitStatus( void ); +static void receiveResponse_updateEEPROMdata( void ); +static void receiveResponse_getEEPROMdata( void ); +static void receiveResponse_updateMeasurementSettings( void ); +static void receiveResponse_getMeasurementSettings( void ); +static void receiveResponse_getSingleMeasurement( CONDUCTIVITY_SENSORS_T sensorID ); +static void receiveResponse_getAllMeasurements( void ); + +static CONDUCTIVITY_INIT_STATUS_T getInitStatus( void ); +static const CONDUCTIVITY_EEPROM_DATA_T* getEEPROMdata( void ); +static const CONDUCTIVITY_MEASUREMENT_SETTINGS_T* getMeasurementSettings( void ); +static const CONDUCTIVITY_SENSOR_DATA_T* getSingleMeasurement( CONDUCTIVITY_SENSORS_T sensorID ); +static const CONDUCTIVITY_SENSOR_DATA_T* getAllMeasurements( void ); + +static void calculateConductivity( CONDUCTIVITY_SENSORS_T sensorID ); +static void calculateTemperature( CONDUCTIVITY_SENSORS_T sensorID ); +static TEENSY_SENSOR_INDEX_T getTeensySensorNum( CONDUCTIVITY_SENSORS_T sensorID ); + /*********************************************************************//** * @brief * The initConductivitySensors function initializes the ConductivitySensors unit. @@ -371,6 +410,36 @@ /*********************************************************************//** * @brief + * The getImpedanceValue function gets the current calculated conductivity / + impedance value. + * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT if given sensor is invalid. + * @details \b Inputs: lastConductivityErrorCounter + * @details \b Outputs: none + * @param sensor ID of conductivity sensor to get error count for. + * @return The current conductivity sensor error count of a given conductivity sensor. + *************************************************************************/ +F64 getImpedanceValue( U32 sensorNum ) +{ + return calculatedMeasurement[sensorNum].Conductivity; +} + +/*********************************************************************//** + * @brief + * The getRTDValue function gets the current conductivity sensor + * error count for a given conductivity sensor. + * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT if given sensor is invalid. + * @details \b Inputs: lastConductivityErrorCounter + * @details \b Outputs: none + * @param sensor ID of conductivity sensor to get error count for. + * @return The current conductivity sensor error count of a given conductivity sensor. + *************************************************************************/ +F64 getRTDValue( U32 sensorNum ) +{ + return calculatedMeasurement[sensorNum].Temperature; +} + +/*********************************************************************//** + * @brief * The requestConductivitySensorReset function commands the given * the conductivity sensor to go for reset. * @details \b Inputs: none @@ -997,7 +1066,16 @@ return state; } - +/*********************************************************************//** + * @brief + * The parseMeasurementSettings Reads measurement settings from buffer and + * stores in conductivityMeasurementSettings. + * @details \b Inputs : none + * @details \b Outputs: conductivityMeasurementSettings - Measurement Settings + * @param buffer - Data to be parsed and stored. + * len - Length of the input data. + * @return CONDUCTIVITY_PARSE_STATUS to tell if parsing was successful or not. + *************************************************************************/ static CONDUCTIVITY_PARSE_STATUS parseMeasurementSettings( const U32 *buffer, U32 len ) { CONDUCTIVITY_PARSE_STATUS parseStatus = CONDUCTIVITY_PARSE_SUCCESS; @@ -1022,6 +1100,16 @@ return parseStatus; } +/*********************************************************************//** + * @brief + * The parseEEPROMdata Reads EEPROM data from buffer and + * stores in conductivityEEPROMdata. + * @details \b Inputs : none + * @details \b Outputs: conductivityEEPROMdata - EEPROM data + * @param buffer - Data to be parsed and stored. + * len - Length of the input data. + * @return CONDUCTIVITY_PARSE_STATUS to tell if parsing was successful or not. + *************************************************************************/ static CONDUCTIVITY_PARSE_STATUS parseEEPROMdata( const U32 *buffer, U32 len ) { CONDUCTIVITY_PARSE_STATUS parseStatus = CONDUCTIVITY_PARSE_SUCCESS; @@ -1046,7 +1134,17 @@ return parseStatus; } -static CONDUCTIVITY_PARSE_STATUS parseConductivityMeasurements(const U32 *buffer, U32 len) +/*********************************************************************//** + * @brief + * The parseConductivityMeasurements Reads Conductivity Measurements / Sensor readings + * from buffer and stores in rawConductivityValues. + * @details \b Inputs : none + * @details \b Outputs: rawConductivityValues - Raw Conductivity Measurements / Sensor readings + * @param buffer - Data to be parsed and stored. + * len - Length of the input data. + * @return CONDUCTIVITY_PARSE_STATUS to tell if parsing was successful or not. + *************************************************************************/ +static CONDUCTIVITY_PARSE_STATUS parseConductivityMeasurements( const U32 *buffer, U32 len ) { CONDUCTIVITY_PARSE_STATUS parseStatus = CONDUCTIVITY_PARSE_SUCCESS; U32 expectedDataLength = sizeof( CONDUCTIVITY_SENSOR_DATA_T ); @@ -1078,7 +1176,7 @@ // And check if the received sensor number id valid if ( (tempSensor.sensorNum < 1 ) || - ( tempSensor.sensorNum > MAX_CONDUCTIVITY_SENSOR ) ) + ( tempSensor.sensorNum > MAX_TEENSY_SENSOR ) ) { parseStatus = CONDUCTIVITY_PARSE_ERROR_INVALID_SENSOR_NUM; break; @@ -1087,17 +1185,168 @@ { // 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; + rawConductivityValues[tempSensor.sensorNum - 1] = tempSensor; } } } return parseStatus; } +static void sendCmd_getInitStatus( void ) +{ +} +static void sendCmd_updateEEPROMdata(CONDUCTIVITY_EEPROM_DATA_T eepromData) +{ +} + +static void sendCmd_getEEPROMdata( void ) +{ + +} + +static void sendCmd_updateMeasurementSettings( CONDUCTIVITY_MEASUREMENT_SETTINGS_T measurememtSettings ) +{ + +} + +static void sendCmd_getMeasurementSettings( void ) +{ + +} + +static void sendCmd_getSingleMeasurement( CONDUCTIVITY_SENSORS_T sensorID ) +{ + TEENSY_SENSOR_INDEX_T sensorNum = getTeensySensorNum(sensorID); +} + +static void sendCmd_getAllMeasurements( void ) +{ + +} + + +static void receiveResponse_getInitStatus( void ) +{ + +} + +static void receiveResponse_updateEEPROMdata( void ) +{ + +} + +static void receiveResponse_getEEPROMdata( void ) +{ + +} + +static void receiveResponse_updateMeasurementSettings( void ) +{ + +} + +static void receiveResponse_getMeasurementSettings( void ) +{ + +} + +static void receiveResponse_getSingleMeasurement( CONDUCTIVITY_SENSORS_T sensorID ) +{ + TEENSY_SENSOR_INDEX_T sensorNum = getTeensySensorNum(sensorID); +} + +static void receiveResponse_getAllMeasurements( void ) +{ + +} + +static CONDUCTIVITY_INIT_STATUS_T getInitStatus( void ) +{ + sendInitStatusCommand(); + receiveInitStatusResponse(); + return conductivityInitStatus; +} + +static const CONDUCTIVITY_EEPROM_DATA_T* getEEPROMdata(void) +{ + return &conductivityEEPROMdata; +} + + +static const CONDUCTIVITY_MEASUREMENT_SETTINGS_T* getMeasurementSettings(void) +{ + return &conductivityMeasurementSettings; +} + +static const CONDUCTIVITY_SENSOR_DATA_T* getSingleMeasurement( CONDUCTIVITY_SENSORS_T sensorID ) +{ + const CONDUCTIVITY_SENSOR_DATA_T* result = NULL; + + TEENSY_SENSOR_INDEX_T sensorNum = getTeensySensorNum( sensorID ); + + if (sensorNum < MAX_TEENSY_SENSOR) + { + result = &rawConductivityValues[ sensorNum ]; + } + + return result; +} + + + +static const CONDUCTIVITY_SENSOR_DATA_T* getAllMeasurements( void ) +{ + return rawConductivityValues; +} + +static void calculateConductivity( CONDUCTIVITY_SENSORS_T sensorID ) +{ + TEENSY_SENSOR_INDEX_T sensorNum = getTeensySensorNum( sensorID ); + F64 calculatedConductivity = 0.0; + F64 B3 = conductivityCoeff[ sensorNum ].B3; + F64 B2 = conductivityCoeff[ sensorNum ].B2; + F64 B1 = conductivityCoeff[ sensorNum ].B1; + F64 B0 = conductivityCoeff[ sensorNum ].B0; + F64 R = rawConductivityValues[ sensorNum ].impRzMag; + F64 Z = rawConductivityValues[ sensorNum ].rtdRzMag; + + calculatedConductivity = ( ( B3 * ( 1000.0 / R ) ) + + ( B2 * ( Z / R ) ) + + ( B1 * ( ( 100 * log( Z ) ) / R ) ) + + B0 + ); + + calculatedMeasurement[sensorNum].Conductivity = calculatedConductivity; + +} + +static void calculateTemperature( CONDUCTIVITY_SENSORS_T sensorID ) +{ + TEENSY_SENSOR_INDEX_T sensorNum = getTeensySensorNum( sensorID ); + F64 calculatedTemperature = 0.0; + F64 A1 = conductivityCoeff[ sensorNum ].A1; + F64 A0 = conductivityCoeff[ sensorNum ].A0; + F64 Z = rawConductivityValues[ sensorNum ].rtdRzMag; + + calculatedTemperature = ( ( A1 * Z ) + A0 ); + + calculatedMeasurement[sensorNum].Temperature = calculatedTemperature; +} + +static TEENSY_SENSOR_INDEX_T getTeensySensorNum( CONDUCTIVITY_SENSORS_T sensorID ) +{ + if ( sensorID >= NUM_OF_CONDUCTIVITY_SENSORS ) + { + return MAX_TEENSY_SENSOR; // Invalid sensor ID + } + return teensySensorMapping[ sensorID ]; +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/