Index: firmware/App/Drivers/ConductivityTeensy.c =================================================================== diff -u -r1768e1d302978a3748ab1e684576f208472e4a54 -rfea37ad4659d4162d43f3e343cd5b266c2757ea9 --- firmware/App/Drivers/ConductivityTeensy.c (.../ConductivityTeensy.c) (revision 1768e1d302978a3748ab1e684576f208472e4a54) +++ firmware/App/Drivers/ConductivityTeensy.c (.../ConductivityTeensy.c) (revision fea37ad4659d4162d43f3e343cd5b266c2757ea9) @@ -25,6 +25,8 @@ #include "ConductivityTeensy.h" #include "Timers.h" +// ********** private definitions ********** + #define SCI_RECEIVE_DMA_REQUEST 30 ///< Serial port receive DMA request line. #define SCI_TRANSMIT_DMA_REQUEST 31 ///< Serial port transmit DMA request line. @@ -92,7 +94,7 @@ static COND_CALCULATED_MEASUREMENTS_T condCalculatedMeasurement[ MAX_TEENSY_SENSOR ]; ///< Calculated conductivity and temperature values static COND_COEFF_T condCoeff[ MAX_TEENSY_SENSOR ]; ///< Coefficients used to calculate conductivity and temperature values. -static TEENSY_SENSOR_INDEX_T currentSelectedSensor; ///< Current selected sensor to get measurement of single sensor. +static TEENSY_SENSOR_INDEX_T currentSelectedSensor; ///< Current selected sensor to get measurement of single sensor. Value 1 to 6. static COND_EEPROM_DATA_T eePromDataTX; ///< Transmitted EEPROM data to Teensy for update EEPROM cmd. static COND_EEPROM_DATA_T eePromDataRX; ///< Received EEPROM data by get EEPROM data cmd. static COND_MEASUREMENT_SETTINGS_T measurementSettingsTX; ///< Transmitted measurement settings to Teensy for update measurement settings cmd. @@ -110,7 +112,6 @@ { TEENSY_CMD_START_MEASUREMENT , ( U08* )"m" , RX_SIZE_START_MEASUREMENT }, { TEENSY_CMD_STOP_MEASUREMENT , ( U08* )"n" , RX_SIZE_STOP_MEASUREMENT }, { TEENSY_CMD_GET_ALL_MEASUREMENTS , ( U08* )"g" , RX_SIZE_GET_ALL_MEASUREMENTS }, - { TEENSY_CMD_SELECT_SENSOR , ( U08* )"j" , RX_SIZE_SELECT_SENSOR }, { TEENSY_CMD_GET_SINGLE_MEASUREMENT , ( U08* )"h" , RX_SIZE_GET_SINGLE_MEASUREMENT }, }; @@ -166,26 +167,23 @@ static COND_COMM_STATE_T txGetAllMeasurements( void ); static COND_COMM_STATE_T rxGetAllMeasurements( void ); -static COND_COMM_STATE_T txSelectSensor( TEENSY_SENSOR_INDEX_T sensorNum ); -static COND_COMM_STATE_T rxSelectSensor( TEENSY_SENSOR_INDEX_T sensorNum ); +static COND_COMM_STATE_T txGetSingleMeasurement( void); +static COND_COMM_STATE_T rxGetSingleMeasurement( void ); +static void enqueueSingleMeasurement(TEENSY_SENSOR_INDEX_T sensorNum); -static COND_COMM_STATE_T txGetSingleMeasurement( TEENSY_SENSOR_INDEX_T sensorNum ); -static COND_COMM_STATE_T rxGetSingleMeasurement( TEENSY_SENSOR_INDEX_T sensorNum ); - static COND_PARSE_STATUS parseMeasurementSettings( const U08 *buffer, U32 len ); static COND_PARSE_STATUS parseEEPROMdata( const U08 *buffer, U32 len ); static COND_PARSE_STATUS parseConductivityMeasurements( const U08 *buffer, U32 len ); static U32 getTeensyCondId( CONDUCTIVITY_SENSORS_T sensorId ); -static void calculateConductivity( U32 sensorNum ); -static void calculateTemperature( U32 sensorNum ); +static void calculateConductivity( TEENSY_SENSOR_INDEX_T sensorNum ); +static void calculateTemperature( TEENSY_SENSOR_INDEX_T sensorNum ); /*********************************************************************//** * @brief * The initConductivityTeensy function initializes ConductivityTeensy unit * @details \b Inputs: none * @details \b Outputs: ConductivityTeensy unit variables initialized - * @param none * @return none *************************************************************************/ void initConductivityTeensy( void ) @@ -218,25 +216,28 @@ condInitStatus = COND_INIT_STATUS_UNITIALIZED; condUpdateEEPROMstatus = COND_UPDATE_EEPROM_STATUS_UNITIALIZED; + condStopMeasurementSatus = 0; currentSelectedSensor = TEENSY_SENSOR_0; initCondDMAchannels(); + //TODO Clean up after testing. // add init conductivity commands enqueue( TEENSY_CMD_STOP_MEASUREMENT ); enqueue( TEENSY_CMD_INIT_SENSOR ); enqueue( TEENSY_CMD_GET_INIT_STATUS ); - initEEPROMdata( ); - initMeasurementSettings( ); +// initEEPROMdata( ); +// initMeasurementSettings( ); +// enqueueSingleMeasurement(2); + } /*********************************************************************//** * @brief * The initCondDMAchannels function configures DMA based SCI communication. * @details \b Inputs: none * @details \b Outputs: none - * @param none * @return none *************************************************************************/ static void initCondDMAchannels( void ) @@ -299,9 +300,8 @@ * @brief * The initEEPROMdata function populates eePromDataTX structure and enqueues * update EEPROM data command in the the command queue. - * @details \b Inputs: eePromDataTX : EEPROM data to be updated on Teensy. - * @details \b Outputs: none - * @param none + * @details \b Inputs: none + * @details \b Outputs: eePromDataTX : EEPROM data to be updated on Teensy. * @return none *************************************************************************/ static void initEEPROMdata( void ) @@ -334,17 +334,15 @@ eePromDataTX.floatValue[ 15 ] = 0.0; enqueue( TEENSY_CMD_UPDATE_EEPROM_DATA ); - } /*********************************************************************//** * @brief * The initMeasurementSettings function populates measurementSettingsTX structure and enqueues * update measurement settings command in the the command queue. - * @details \b Inputs:measurementSettingsTX - MEasurememt settings data to updated on Teensy. - * @details \b Outputs: - * @param - * @return + * @details \b Inputs:none + * @details \b Outputs:measurementSettingsTX - Measurement settings data to updated on Teensy. + * @return none *************************************************************************/ static void initMeasurementSettings( void ) { @@ -479,13 +477,9 @@ case TEENSY_CMD_GET_ALL_MEASUREMENTS: state = txGetAllMeasurements(); break; - case TEENSY_CMD_SELECT_SENSOR: - state = txSelectSensor( currentSelectedSensor ); - break; case TEENSY_CMD_GET_SINGLE_MEASUREMENT: - state = txGetSingleMeasurement( currentSelectedSensor ); + state = txGetSingleMeasurement(); break; - default: break; } @@ -535,12 +529,12 @@ case TEENSY_CMD_GET_ALL_MEASUREMENTS: state = rxGetAllMeasurements(); break; - case TEENSY_CMD_SELECT_SENSOR: - state = rxSelectSensor( currentSelectedSensor ); - break; case TEENSY_CMD_GET_SINGLE_MEASUREMENT: - state = rxGetSingleMeasurement( currentSelectedSensor ); + state = rxGetSingleMeasurement( ); break; + default: + break; + } return state; @@ -579,8 +573,6 @@ break; case TEENSY_CMD_GET_ALL_MEASUREMENTS: break; - case TEENSY_CMD_SELECT_SENSOR: - break; case TEENSY_CMD_GET_SINGLE_MEASUREMENT: break; default: @@ -634,7 +626,6 @@ * the next DMA write command to the Teensy. * @details \b Inputs: condDMAWriteControlRecord * @details \b Outputs: DMA write command is initiated - * @param none * @return none *************************************************************************/ static void startConductivityDMAWriteCmd( void ) @@ -714,8 +705,8 @@ /*********************************************************************//** * @brief - * The isQueueFull checks whether the queue is full and if it is full, - * it will return a true. + * The isQueueFull checks whether the queue is full and + * if it is full, it will return a TRUE. * @details Inputs: queueCount * @details Outputs: none * @return TRUE if queue is full. Otherwise, FALSE. @@ -734,11 +725,11 @@ /*********************************************************************//** * @brief - * The isQueueEmpty checks whether the queue is empty and if it is empty, - * it will return a false. + * The isQueueEmpty checks whether the queue is empty and + * if it is empty, it will return a TRUE. * @details Inputs: queueCount * @details Outputs: none - * @return TRUE if queue is not empty + * @return TRUE if queue is empty. Otherwise, FALSE. *************************************************************************/ static BOOL isQueueEmpty ( void ) { @@ -765,7 +756,7 @@ BOOL result = FALSE; _disable_IRQ(); - if ( !isQueueFull() ) + if ( FALSE == isQueueFull() ) { queueCount++; condCmdQ[ queueRearIndex ] = cmd; @@ -790,7 +781,7 @@ _disable_IRQ(); tempIndex = queueFrontIndex; - if ( !isQueueEmpty() ) + if ( FALSE == isQueueEmpty() ) { queueFrontIndex = INC_WRAP( queueFrontIndex, 0, COND_CMD_Q_LEN - 1 ); currentCmd = condCmdQ [ tempIndex ]; @@ -879,10 +870,9 @@ /*********************************************************************//** * @brief - * The txInitSensor function sends initialize sensors command to the Teesny. + * The txInitSensor function sends initialize sensors command to the Teensy. * @details \b Inputs: none * @details \b Outputs: condResponseTime - Time at which command was transmitted. - * @param none * @return state - Next state. *************************************************************************/ static COND_COMM_STATE_T txInitSensor( void ) @@ -913,7 +903,6 @@ * @details \b Inputs: condResponseTime - Time at which command was transmitted, * @details \b Inputs: condRxBuffer - Received response buffer * @details \b Outputs: condInitStatus - Sensor Initialization status. - * @param none * @return state - Next state. *************************************************************************/ static COND_COMM_STATE_T rxInitSensor( void ) @@ -969,7 +958,7 @@ /*********************************************************************//** * @brief * The txGetInitStatus function sends get sensor initialization status command -* to the Teesny. +* to the Teensy. * @details \b Inputs: none * @details \b Outputs: condResponseTime - Time at which command was transmitted. * @param none @@ -1004,7 +993,6 @@ * @details \b Inputs: condResponseTime - Time at which command was transmitted, * @details \b Inputs: condRxBuffer - Received response buffer * @details \b Outputs: condInitStatus - Sensor Initialization status. - * @param none * @return state - Next state. *************************************************************************/ static COND_COMM_STATE_T rxGetInitStatus( void ) @@ -1060,7 +1048,6 @@ * The txUpdateEEPROMdata function sends update EEPRPM data command to Teensy. * @details \b Inputs: eePromDataTX - EEPROM data to be updated in Teensy. * @details \b Outputs: condResponseTime - Time at which command was transmitted. - * @param none * @return state - Next state. *************************************************************************/ static COND_COMM_STATE_T txUpdateEEPROMdata( void ) @@ -1119,7 +1106,6 @@ * @details \b Inputs: condResponseTime - Time at which command was transmitted, * @details \b Inputs: condRxBuffer - Received response buffer * @details \b Outputs: condUpdateEEPROMstatus - Update EEPRPM data status. - * @param none * @return state - Next state. *************************************************************************/ static COND_COMM_STATE_T rxUpdateEEPROMdata( void ) @@ -1155,10 +1141,9 @@ /*********************************************************************//** * @brief - * The txGetEEPROMdata function sends get EEPROM data command to the Teesny. + * The txGetEEPROMdata function sends get EEPROM data command to the Teensy. * @details \b Inputs: none * @details \b Outputs: condResponseTime - Time at which command was transmitted. - * @param none * @return state - Next state. *************************************************************************/ @@ -1190,7 +1175,6 @@ * @details \b Inputs: condResponseTime - Time at which command was transmitted, * @details \b Inputs: condRxBuffer - Received response buffer * @details \b Outputs: eePromDataRX - Received EEPROM data. - * @param none * @return state - Next state. *************************************************************************/ static COND_COMM_STATE_T rxGetEEPROMdata( void ) @@ -1238,10 +1222,9 @@ /*********************************************************************//** * @brief * The txUpdateMeasurementSettings function sends update measurement settings command - * to the Teesny. + * to the Teensy. * @details \b Inputs: none * @details \b Outputs: condResponseTime - Time at which command was transmitted. - * @param none * @return state - Next state. *************************************************************************/ @@ -1285,7 +1268,6 @@ * @details \b Inputs: condResponseTime - Time at which command was transmitted, * @details \b Inputs: condRxBuffer - Received response buffer * @details \b Outputs: condUpdateSettingStatus - Update measurement settings status. - * @param none * @return state - Next state. *************************************************************************/ static COND_COMM_STATE_T rxUpdateMeasurementSettings( void ) @@ -1323,10 +1305,9 @@ /*********************************************************************//** * @brief * The txGetMeasurementSettings function sends get measurement settings command - * to the Teesny. + * to the Teensy. * @details \b Inputs: none * @details \b Outputs: condResponseTime - Time at which command was transmitted. - * @param none * @return state - Next state. *************************************************************************/ @@ -1359,7 +1340,6 @@ * @details \b Inputs: condResponseTime - Time at which command was transmitted, * @details \b Inputs: condRxBuffer - Received response buffer * @details \b Outputs: measurementSettingsRX - Received Measurement Settings - * @param none * @return state - Next state. *************************************************************************/ static COND_COMM_STATE_T rxGetMeasurementSettings( void ) @@ -1406,20 +1386,19 @@ /*********************************************************************//** * @brief - * The txStartMeasurements function sends start measurements command to the Teesny. + * The txStartMeasurements function sends start measurements command to the Teensy. * This command will start the automated Conductivity measurements polling. * @details \b Inputs: none * @details \b Outputs: condResponseTime - Time at which command was transmitted. * @details \b Outputs: condAutomatedDataPolling set to TRUE. - * @param none * @return state - Next state. *************************************************************************/ static COND_COMM_STATE_T txStartMeasurements( void ) { COND_COMM_STATE_T state = COND_COMM_STATE_TX; - // If get measurement settings cmd was sent successfully + // If start measurement settings cmd was sent successfully if ( TRUE == txTeensyWriteCmd( TEENSY_CMD_START_MEASUREMENT, NULL ) ) { // Set the flag to indicate that automated conductivity data polling has started. @@ -1446,13 +1425,13 @@ * @details \b Inputs: condRxBuffer - Received response buffer * @details \b Outputs: condRawMeasurement - Raw Conductivity Measurements (includes impedance and rtd) * @details \b Outputs: condCalculatedMeasurement - Calculated Conductivity and temperature. - * @param none * @return state - Next state. *************************************************************************/ static COND_COMM_STATE_T rxStartMeasurements( void ) { COND_COMM_STATE_T state = COND_COMM_STATE_RX; - COND_PARSE_STATUS parseStatus; + COND_PARSE_STATUS parseStatus = COND_PARSE_NONE; + // Check if a response is received in the RX buffer BOOL recvComplete = rxTeensyReadRsp( TEENSY_CMD_START_MEASUREMENT ); @@ -1476,6 +1455,11 @@ state = COND_COMM_STATE_IDLE; } } + else if ( TRUE == didTimeout( condResponseTime, COND_DATA_TIMEOUT_MS ) ) + { + // Go to failed state + state = COND_COMM_STATE_FAILED; + } else { // Do Nothing. Wait until we either receive a response OR timeout happens. @@ -1486,25 +1470,34 @@ /*********************************************************************//** * @brief - * The txStopMeasurement function sends stop measurements command to the Teesny. + * The txStopMeasurement function sends stop measurements command to the Teensy. * This command will stop the automated polling of conductivity measurements data. * @details \b Inputs: none * @details \b Outputs: condResponseTime - Time at which command was transmitted. * @details \b Outputs: condAutomatedDataPolling set to FALSE. - * @param none * @return state - Next state. *************************************************************************/ static COND_COMM_STATE_T txStopMeasurement( void ) { COND_COMM_STATE_T state = COND_COMM_STATE_TX; + // If get measurement settings cmd was sent successfully if ( TRUE == txTeensyWriteCmd( TEENSY_CMD_STOP_MEASUREMENT, NULL ) ) { - state = COND_COMM_STATE_RX; + // Set the flag to indicate that automated conductivity data polling has stopped. condAutomatedDataPolling = FALSE; + // Get the current time condResponseTime = getMSTimerCount(); + + // Go to receive state to receive the measurement data + state = COND_COMM_STATE_RX; } + else + { + // Go to failed state + state = COND_COMM_STATE_FAILED; + } return state; } @@ -1515,42 +1508,75 @@ * @details \b Inputs: condResponseTime - Time at which command was transmitted, * @details \b Inputs: condRxBuffer - Received response buffer * @details \b Outputs: condStopMeasurementSatus - Stop measurement status - * @param none * @return state - Next state. *************************************************************************/ static COND_COMM_STATE_T rxStopMeasurement( void ) { COND_COMM_STATE_T state = COND_COMM_STATE_RX; - // Wait 1s so we can q next cmd. - // TODO wait for reply via DMA from teensy once implemented - if ( TRUE == didTimeout( condResponseTime, 1000 ) ) - { - // Go to failed state - state = COND_COMM_STATE_IDLE; - } + // Check if a response is received in the RX buffer + BOOL recvComplete = rxTeensyReadRsp( TEENSY_CMD_STOP_MEASUREMENT ); + + if ( TRUE == recvComplete ) + { + // Reset the timer for next use. + condResponseTime = 0; + + // Read the data from the receive buffer + memcpy(&condStopMeasurementSatus, &condRxBuffer, teensyCmdMap[ TEENSY_CMD_STOP_MEASUREMENT ].rxSize ); + + // Check if parsing was done successfully + if ( TRUE == condStopMeasurementSatus ) + { + // Go to the idle state to execute next cmd in the queue + state = COND_COMM_STATE_IDLE; + } + else + { + // Go to failed state + state = COND_COMM_STATE_IDLE; + } + } + else if ( TRUE == didTimeout( condResponseTime, COND_STATUS_TIMEOUT_MS ) ) + { + // Go to failed state + state = COND_COMM_STATE_FAILED; + } + else + { + // Do Nothing. Wait until we either receive a response OR timeout happens. + } + return state; } /*********************************************************************//** * @brief * The txGetAllMeasurements function sends command to get measurements of all sensors - * connected to the Teesny. + * connected to the Teensy. * @details \b Inputs: none * @details \b Outputs: condResponseTime - Time at which command was transmitted. - * @param none * @return state - Next state. *************************************************************************/ static COND_COMM_STATE_T txGetAllMeasurements( void ) { COND_COMM_STATE_T state = COND_COMM_STATE_TX; + // If get measurement settings cmd was sent successfully if ( TRUE == txTeensyWriteCmd( TEENSY_CMD_GET_ALL_MEASUREMENTS, NULL ) ) { // Get the current time condResponseTime = getMSTimerCount(); + + // Go to receive state to receive the measurement data + state = COND_COMM_STATE_RX; } + else + { + // Go to failed state + state = COND_COMM_STATE_FAILED; + } return state; } @@ -1563,12 +1589,12 @@ * @details \b Inputs: condRxBuffer - Received response buffer * @details \b Outputs: condRawMeasurement - Raw Conductivity Measurements (includes impedance and rtd) * @details \b Outputs: condCalculatedMeasurement - Calculated Conductivity and temperature. - * @param none * @return state - Next state. *************************************************************************/ static COND_COMM_STATE_T rxGetAllMeasurements( void ) { COND_COMM_STATE_T state = COND_COMM_STATE_RX; + COND_PARSE_STATUS parseStatus = COND_PARSE_NONE; // Check if a response is received in the RX buffer BOOL recvComplete = rxTeensyReadRsp( TEENSY_CMD_GET_ALL_MEASUREMENTS ); @@ -1578,7 +1604,7 @@ condResponseTime = 0; // Read the data from the receive buffer - COND_PARSE_STATUS parseStatus = parseConductivityMeasurements( condRxBuffer, COND_RX_BUFFER_LEN ); + parseStatus = parseConductivityMeasurements( condRxBuffer, COND_RX_BUFFER_LEN ); // Check if parsing was done successfully if ( COND_PARSE_SUCCESS == parseStatus ) @@ -1607,61 +1633,22 @@ /*********************************************************************//** * @brief - * The txSelectSensor function sends select sensor for single sensor measurement - * to the Teesny. Always call this function before calling txGetSingleMeasurement(). - * @details \b Inputs: none + * The txGetSingleMeasurement function sends get single sensor measurement command + * to the Teensy. + * @details \b Inputs: currentSelectedSensor - Sensor number to be read. * @details \b Outputs: condResponseTime - Time at which command was transmitted. - * @param none * @return state - Next state. *************************************************************************/ -static COND_COMM_STATE_T txSelectSensor( TEENSY_SENSOR_INDEX_T sensorNum ) +static COND_COMM_STATE_T txGetSingleMeasurement( void ) { COND_COMM_STATE_T state = COND_COMM_STATE_TX; U08 paramStr[ 8 ]; - snprintf( ( char* )paramStr, sizeof( paramStr ), "%d", sensorNum ); + snprintf( ( char* )paramStr, sizeof( paramStr ), "%d", currentSelectedSensor ); - if ( TRUE == txTeensyWriteCmd( TEENSY_CMD_SELECT_SENSOR, paramStr ) ) - { - - } - - return state; -} - -/*********************************************************************//** - * @brief - * The rxSelectSensor function handles received response of select sensor command. - * @details \b Inputs: condResponseTime - Time at which command was transmitted, - * @details \b Inputs: condRxBuffer - Received response buffer - * @details \b Outputs: currentSelectedSensor - Current selected sensor. - * @param none - * @return state - Next state. - *************************************************************************/ -static COND_COMM_STATE_T rxSelectSensor( TEENSY_SENSOR_INDEX_T sensorNum ) -{ - COND_COMM_STATE_T state = COND_COMM_STATE_RX; - - return state; -} - -/*********************************************************************//** - * @brief - * The txGetSingleMeasurement function sends get single sensor measurement command - * to the Teesny. Always call txSelectSensor() function before calling this function. - * @details \b Inputs: none - * @details \b Outputs: condResponseTime - Time at which command was transmitted. - * @param none - * @return state - Next state. - *************************************************************************/ - -static COND_COMM_STATE_T txGetSingleMeasurement( TEENSY_SENSOR_INDEX_T sensorNum ) -{ - COND_COMM_STATE_T state = COND_COMM_STATE_TX; - // Assumes sensor has already been selected - if ( TRUE == txTeensyWriteCmd( TEENSY_CMD_GET_SINGLE_MEASUREMENT, NULL ) ) + if ( TRUE == txTeensyWriteCmd( TEENSY_CMD_GET_SINGLE_MEASUREMENT, paramStr ) ) { // Get the current time condResponseTime = getMSTimerCount(); @@ -1678,10 +1665,9 @@ * @details \b Inputs: condRxBuffer - Received response buffer * @details \b Outputs: condRawMeasurement - Raw Conductivity Measurements (includes impedance and rtd) * @details \b Outputs: condCalculatedMeasurement - Calculated Conductivity and temperature. - * @param none * @return state - Next state. *************************************************************************/ -static COND_COMM_STATE_T rxGetSingleMeasurement( TEENSY_SENSOR_INDEX_T sensorNum ) +static COND_COMM_STATE_T rxGetSingleMeasurement( void ) { COND_COMM_STATE_T state = COND_COMM_STATE_RX; @@ -1717,11 +1703,29 @@ // Do Nothing. Wait until we either receive a response OR timeout happens. } - return state; + return state; } /*********************************************************************//** * @brief + * The enqueueSingleMeasurement function updates current select sensor in format + * acceptable to Teensy and enqueues get single measurement command. + * @details \b Inputs : none + * @details \b Outputs: currentSelectedSensor - Current Selected Sensor indexed 1 to 6. + * @param sensorNum - Teensy sensor index + * @return none + *************************************************************************/ +static void enqueueSingleMeasurement(TEENSY_SENSOR_INDEX_T sensorNum) +{ + // Sensors are indexed 1 to 6 in Teensy. So send (sensorNum + 1) as parameter. + currentSelectedSensor = sensorNum + 1; + + // Enqueue get single measurement command. + enqueue(TEENSY_CMD_GET_SINGLE_MEASUREMENT); +} + +/*********************************************************************//** + * @brief * The parseMeasurementSettings Reads measurement settings from buffer and * stores in measurementSettingsRX. * @details \b Inputs : none @@ -1816,17 +1820,22 @@ // Read the sensor data temporarily memcpy( &tempSensor, buffer, teensyCmdMap[ currentCmd ].rxSize ); - // Check if the received sensor number is valid + // Check if the received sensor number is valid. Sensors are numbered 1 to 6 on Teensy. if ( ( tempSensor.sensorNum < 1 ) || ( tempSensor.sensorNum > MAX_TEENSY_SENSOR ) ) { parseStatus = COND_PARSE_ERROR_INVALID_SENSOR_NUM; } else { - // Store value in array index for position ( sensorNum - 1 ) + // Store Raw value in array index for position ( sensorNum - 1 ) condRawMeasurement[ tempSensor.sensorNum - 1 ] = tempSensor; + + // Calculate and store Conductivity from raw values calculateConductivity( tempSensor.sensorNum - 1 ); + + // Calculate and store Temperature from raw values. calculateTemperature( tempSensor.sensorNum - 1 ); + parseStatus = COND_PARSE_SUCCESS; } } @@ -1836,11 +1845,11 @@ /*********************************************************************//** * @brief - * The getTeensyCondId function maps Teensy Sensor Index to Conductivity Sensors. + * The getTeensyCondId function maps Sensor Index to Conductivity Sensors. * @details \b Inputs: * @details \b Outputs: - * @param - * @return + * @param sensorId - Id of DD Conductivity Sensors + * @return sensorNum - Sensor Index. *************************************************************************/ static U32 getTeensyCondId( CONDUCTIVITY_SENSORS_T sensorId ) { @@ -1878,7 +1887,7 @@ * @details \b Inputs: condCalculatedMeasurement * @details \b Outputs: none * @param sensor ID of conductivity sensor to get conductivity. - * @return The current conductivity sensor conductivity of a given conductivity sensor. + * @return The current conductivity of a given conductivity sensor. *************************************************************************/ F32 getTeensyConductivityValue( CONDUCTIVITY_SENSORS_T sensorId ) { @@ -1900,7 +1909,7 @@ * @details \b Inputs: condCalculatedMeasurement * @details \b Outputs: none * @param sensorId ID of conductivity sensor to get temperature. - * @return The current conductivity sensor temperature of a given conductivity sensor. + * @return The current temperature of a given conductivity sensor. *************************************************************************/ F32 getTeensyConductivityTemperatureValue( CONDUCTIVITY_SENSORS_T sensorId ) { @@ -1917,13 +1926,14 @@ /*********************************************************************//** * @brief - * The calculateConductivity function - * @details \b Inputs: - * @details \b Outputs: - * @param + * The calculateConductivity function calculates the conductivity value. + * @details \b Inputs: condCoeff - Conductivity Coefficients + * @details \b Inputs: condRawMeasurement - Raw measurement values + * @details \b Outputs: condCalculatedMeasurement - calculated conductivity value + * @param sensorNum - Teensy sensor index value. * @return *************************************************************************/ -static void calculateConductivity( U32 sensorNum ) +static void calculateConductivity( TEENSY_SENSOR_INDEX_T sensorNum ) { F64 calculatedConductivity = 0.0; F64 B3 = condCoeff[ sensorNum ].B3; @@ -1945,13 +1955,14 @@ /*********************************************************************//** * @brief - * The calculateTemperature function - * @details \b Inputs: - * @details \b Outputs: - * @param + * The calculateTemperature function calculates the temperature values. + * @details \b Inputs: condCoeff - Conductivity Coefficients + * @details \b Inputs: condRawMeasurement - Raw measurement values + * @details \b Outputs: condCalculatedMeasurement - calculated temperature value + * @param sensorNum - Teensy sensor index value. * @return *************************************************************************/ -static void calculateTemperature( U32 sensorNum ) +static void calculateTemperature( TEENSY_SENSOR_INDEX_T sensorNum ) { F64 calculatedTemperature = 0.0; F64 A1 = condCoeff[ sensorNum ].A1;