Index: firmware/App/Drivers/ConductivityTeensy.c =================================================================== diff -u -r94a98f376c6c8c3785f05f5a1b19cc1108fe336e -re0c45c725884d780b76dd54a617ab6ed333d7ba2 --- firmware/App/Drivers/ConductivityTeensy.c (.../ConductivityTeensy.c) (revision 94a98f376c6c8c3785f05f5a1b19cc1108fe336e) +++ firmware/App/Drivers/ConductivityTeensy.c (.../ConductivityTeensy.c) (revision e0c45c725884d780b76dd54a617ab6ed333d7ba2) @@ -181,13 +181,13 @@ static COND_PARSE_STATUS parseEEPROMdata( const U08 *buffer, U32 len ); static COND_PARSE_STATUS parseConductivityMeasurements( const U08 *buffer ); -static U32 getTeensyCondId( U32 sensorId ); -static void calculateConductivity( U32 sensorNum ); -static void calculateConductivityAly( U32 sensorNum, BOOL isFPSensor ); -static void calculateConductivityUpdatedStandard( U32 sensorNum, BOOL isFPSensor ); -static void calculateConductivityStandard( U32 sensorNum, BOOL isFPSensor ); -static void calculateTemperature( U32 sensorNum ); -static void calculateResistance( U32 sensorNum, BOOL isFPSensor ); +static U32 getTeensyCondId( CONDUCTIVITY_SENSORS_T sensorId ); +static void calculateConductivity( TEENSY_SENSOR_INDEX_T sensorNum ); +static void calculateConductivityAly( TEENSY_SENSOR_INDEX_T sensorNum, BOOL isFPSensor ); +static void calculateConductivityUpdatedStandard( TEENSY_SENSOR_INDEX_T sensorNum, BOOL isFPSensor ); +static void calculateConductivityStandard( TEENSY_SENSOR_INDEX_T sensorNum, BOOL isFPSensor ); +static void calculateTemperature( TEENSY_SENSOR_INDEX_T sensorNum ); +static void calculateResistance( TEENSY_SENSOR_INDEX_T sensorNum, BOOL isFPSensor ); /*********************************************************************//** * @brief @@ -838,15 +838,16 @@ static COND_COMM_STATE_T rxInitSensor( void ) { COND_COMM_STATE_T state = COND_COMM_STATE_RX; + COND_INIT_STATUS_T initStatusInProgress = COND_INIT_STATUS_FAILED; // set to fail for testing COND_INIT_STATUS_T initStatusInitialized = COND_INIT_STATUS_FAILED; // if data populates BOOL recvComplete = rxTeensyReadRsp( TEENSY_CMD_INIT_SENSOR ); if ( TRUE == recvComplete ) { // Reset the timer for next use. condResponseTime = 0; - // Read the data from the receive buffer. Pull 2nd byte as first byte is - // discarded. + // Read the data from the receive buffer + initStatusInProgress = ( COND_INIT_STATUS_T )condRxBuffer[ 0 ]; initStatusInitialized = ( COND_INIT_STATUS_T )condRxBuffer[ 1 ]; // Store the init status @@ -1790,12 +1791,12 @@ // Store Raw value in array index for position ( sensorNum - 1 ) memcpy( &condRawMeasurement[ tempSensor.sensorNum - 1 ], &tempSensor, sizeof( COND_SENSOR_DATA_T ) ); - // Calculate and store Temperature from raw values. - calculateTemperature( tempSensor.sensorNum - 1 ); - // 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; } } @@ -1811,7 +1812,7 @@ * @param sensorId - Id of DD Conductivity Sensors * @return sensorNum - Sensor Index. *************************************************************************/ -static U32 getTeensyCondId( U32 sensorId ) +static U32 getTeensyCondId( CONDUCTIVITY_SENSORS_T sensorId ) { U32 sensorNum = 0; @@ -1853,7 +1854,7 @@ * @param sensorId ID of conductivity sensor to get conductivity. * @return The current conductivity of a given conductivity sensor. *************************************************************************/ -F32 getTeensyConductivityValue( U32 sensorId ) +F32 getTeensyConductivityValue( CONDUCTIVITY_SENSORS_T sensorId ) { U32 sensorNum = getTeensyCondId( sensorId ); F32 result = 0.0F; @@ -1876,7 +1877,7 @@ * @param sensorId ID of conductivity sensor to get temperature. * @return The current temperature of a given conductivity sensor. *************************************************************************/ -F32 getTeensyConductivityTemperatureValue( U32 sensorId ) +F32 getTeensyConductivityTemperatureValue( CONDUCTIVITY_SENSORS_T sensorId ) { U32 sensorNum = getTeensyCondId( sensorId ); F32 result = 0.0F; @@ -1899,7 +1900,7 @@ * @param sensorId ID of conductivity sensor to get temperature. * @return The current temperature of a given conductivity sensor. *************************************************************************/ -F32 getTeensyConductivityResistanceValue( U32 sensorId ) +F32 getTeensyConductivityResistanceValue( CONDUCTIVITY_SENSORS_T sensorId ) { U32 sensorNum = getTeensyCondId( sensorId ); F32 result = 0.0F; @@ -1922,7 +1923,7 @@ * @param isFPSensor - T/F if sensor is on FP hardware. * @return *************************************************************************/ -static void calculateConductivity( U32 sensorNum ) +static void calculateConductivity( TEENSY_SENSOR_INDEX_T sensorNum ) { BOOL isFPSensor = FALSE; @@ -1955,7 +1956,7 @@ * @param isFPSensor - T/F if sensor is on FP hardware. * @return *************************************************************************/ -static void calculateConductivityAly( U32 sensorNum, BOOL isFPSensor ) +static void calculateConductivityAly( TEENSY_SENSOR_INDEX_T sensorNum, BOOL isFPSensor ) { F32 calculatedConductivity = 0.0; F32 B3 = 0.0; @@ -1972,11 +1973,6 @@ { R = COND_INFINITE_R_VALUE; } - // To prevent nan's being thrown into our rolling average by dividing by 0, we set to 1. - else if ( R == 0 ) - { - R = 1; - } if ( TRUE == isFPSensor ) { @@ -2013,7 +2009,7 @@ * @param isFPSensor - T/F if sensor is on FP hardware. * @return *************************************************************************/ -static void calculateConductivityUpdatedStandard( U32 sensorNum, BOOL isFPSensor ) +static void calculateConductivityUpdatedStandard( TEENSY_SENSOR_INDEX_T sensorNum, BOOL isFPSensor ) { F32 calculatedConductivity = 0.0; F64 alpha = 0.0; @@ -2047,25 +2043,20 @@ * @param isFPSensor - T/F if sensor is on FP hardware. * @return *************************************************************************/ -static void calculateConductivityStandard( U32 sensorNum, BOOL isFPSensor ) +static void calculateConductivityStandard( TEENSY_SENSOR_INDEX_T sensorNum, BOOL isFPSensor ) { F32 calculatedConductivity = 0.0; F64 alpha = 0.0; F64 k = 0.0; F32 R = condRawMeasurement[ sensorNum ].impRzMag; - // Sensors are known to send the driver INF in unfavorable conditions for impedance. e.g: open air + // Aly sensors are known to send the driver INF in unfavorable conditions for impedance. e.g: open air // Change it to some high value that can be determined that we are reading INF. // Otherwise we will publish no updated value or 0. if ( R == INFINITY ) { R = COND_INFINITE_R_VALUE; } - // To prevent nan's being thrown into our rolling average by dividing by 0, we set to 1. - else if ( R == 0 ) - { - R = 1; - } if ( TRUE == isFPSensor ) { @@ -2096,7 +2087,7 @@ * @param isFPSensor - T/F if sensor is on FP hardware. * @return *************************************************************************/ -static void calculateResistance( U32 sensorNum, BOOL isFPSensor ) +static void calculateResistance( TEENSY_SENSOR_INDEX_T sensorNum, BOOL isFPSensor ) { F32 calculatedResistance = 0.0; @@ -2135,7 +2126,7 @@ * @param sensorNum - Teensy sensor index value. * @return *************************************************************************/ -static void calculateTemperature( U32 sensorNum ) +static void calculateTemperature( TEENSY_SENSOR_INDEX_T sensorNum ) { F32 calculatedTemperature = 0.0; @@ -2169,7 +2160,7 @@ TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; OVERRIDE_TYPE_T ovType = getOverrideArrayPayloadFromMessage( message, &payload ); - if ( payload.index < NUM_OF_CONDUCTIVITY_SENSORS ) + if ( payload.index <= LAST_FP_COND_SENSOR ) { // D74 is not connected to Teensy and does not have a data structure to override. if ( LAST_DD_COND_SENSOR != payload.index ) @@ -2179,13 +2170,13 @@ { F32 value = payload.state.f32; - condCalculatedMeasurement[ getTeensyCondId( payload.index ) ].Conductivity.ovData = value; - condCalculatedMeasurement[ getTeensyCondId( payload.index ) ].Conductivity.override = OVERRIDE_KEY; + condCalculatedMeasurement[ payload.index ].Conductivity.ovData = value; + condCalculatedMeasurement[ payload.index ].Conductivity.override = OVERRIDE_KEY; } else { - condCalculatedMeasurement[ getTeensyCondId( payload.index ) ].Conductivity.override = OVERRIDE_RESET; - condCalculatedMeasurement[ getTeensyCondId( payload.index ) ].Conductivity.ovData = condCalculatedMeasurement[ payload.index ].Conductivity.ovInitData; + condCalculatedMeasurement[ payload.index ].Conductivity.override = OVERRIDE_RESET; + condCalculatedMeasurement[ payload.index ].Conductivity.ovData = condCalculatedMeasurement[ payload.index ].Conductivity.ovInitData; } } } @@ -2208,7 +2199,7 @@ TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; OVERRIDE_TYPE_T ovType = getOverrideArrayPayloadFromMessage( message, &payload ); - if ( payload.index < NUM_OF_CONDUCTIVITY_SENSORS ) + if ( payload.index <= LAST_FP_COND_SENSOR ) { // D74 is not connected to Teensy and does not have a data structure to override. if ( LAST_DD_COND_SENSOR != payload.index ) @@ -2248,7 +2239,7 @@ TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; OVERRIDE_TYPE_T ovType = getOverrideArrayPayloadFromMessage( message, &payload ); - if ( payload.index < NUM_OF_CONDUCTIVITY_SENSORS ) + if ( payload.index <= LAST_FP_COND_SENSOR ) { // D74 is not connected to Teensy and does not have a data structure to override. if ( LAST_DD_COND_SENSOR != payload.index )