Index: firmware/App/Drivers/ConductivityTeensy.c =================================================================== diff -u -r46a42611591cb92eef5f20c8d39964d406c5c8cc -rbc7dad193df69c64cf213db463e5115b1ba8a5f0 --- firmware/App/Drivers/ConductivityTeensy.c (.../ConductivityTeensy.c) (revision 46a42611591cb92eef5f20c8d39964d406c5c8cc) +++ firmware/App/Drivers/ConductivityTeensy.c (.../ConductivityTeensy.c) (revision bc7dad193df69c64cf213db463e5115b1ba8a5f0) @@ -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( 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 ); +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 ); /*********************************************************************//** * @brief @@ -837,16 +837,15 @@ 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 - initStatusInProgress = ( COND_INIT_STATUS_T )condRxBuffer[ 0 ]; + // Read the data from the receive buffer. Pull 2nd byte as first byte is + // discarded. initStatusInitialized = ( COND_INIT_STATUS_T )condRxBuffer[ 1 ]; // Store the init status @@ -1790,12 +1789,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 Conductivity from raw values - calculateConductivity( tempSensor.sensorNum - 1 ); - // Calculate and store Temperature from raw values. calculateTemperature( tempSensor.sensorNum - 1 ); + // Calculate and store Conductivity from raw values + calculateConductivity( tempSensor.sensorNum - 1 ); + parseStatus = COND_PARSE_SUCCESS; } } @@ -1811,7 +1810,7 @@ * @param sensorId - Id of DD Conductivity Sensors * @return sensorNum - Sensor Index. *************************************************************************/ -static U32 getTeensyCondId( CONDUCTIVITY_SENSORS_T sensorId ) +static U32 getTeensyCondId( U32 sensorId ) { U32 sensorNum = 0; @@ -1853,7 +1852,7 @@ * @param sensorId ID of conductivity sensor to get conductivity. * @return The current conductivity of a given conductivity sensor. *************************************************************************/ -F32 getTeensyConductivityValue( CONDUCTIVITY_SENSORS_T sensorId ) +F32 getTeensyConductivityValue( U32 sensorId ) { U32 sensorNum = getTeensyCondId( sensorId ); F32 result = 0.0F; @@ -1876,7 +1875,7 @@ * @param sensorId ID of conductivity sensor to get temperature. * @return The current temperature of a given conductivity sensor. *************************************************************************/ -F32 getTeensyConductivityTemperatureValue( CONDUCTIVITY_SENSORS_T sensorId ) +F32 getTeensyConductivityTemperatureValue( U32 sensorId ) { U32 sensorNum = getTeensyCondId( sensorId ); F32 result = 0.0F; @@ -1899,7 +1898,7 @@ * @param sensorId ID of conductivity sensor to get temperature. * @return The current temperature of a given conductivity sensor. *************************************************************************/ -F32 getTeensyConductivityResistanceValue( CONDUCTIVITY_SENSORS_T sensorId ) +F32 getTeensyConductivityResistanceValue( U32 sensorId ) { U32 sensorNum = getTeensyCondId( sensorId ); F32 result = 0.0F; @@ -1922,7 +1921,7 @@ * @param isFPSensor - T/F if sensor is on FP hardware. * @return *************************************************************************/ -static void calculateConductivity( TEENSY_SENSOR_INDEX_T sensorNum ) +static void calculateConductivity( U32 sensorNum ) { BOOL isFPSensor = FALSE; @@ -1955,7 +1954,7 @@ * @param isFPSensor - T/F if sensor is on FP hardware. * @return *************************************************************************/ -static void calculateConductivityAly( TEENSY_SENSOR_INDEX_T sensorNum, BOOL isFPSensor ) +static void calculateConductivityAly( U32 sensorNum, BOOL isFPSensor ) { F32 calculatedConductivity = 0.0; F32 B3 = 0.0; @@ -1972,6 +1971,11 @@ { 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 ) { @@ -2008,7 +2012,7 @@ * @param isFPSensor - T/F if sensor is on FP hardware. * @return *************************************************************************/ -static void calculateConductivityUpdatedStandard( TEENSY_SENSOR_INDEX_T sensorNum, BOOL isFPSensor ) +static void calculateConductivityUpdatedStandard( U32 sensorNum, BOOL isFPSensor ) { F32 calculatedConductivity = 0.0; F64 alpha = 0.0; @@ -2042,20 +2046,25 @@ * @param isFPSensor - T/F if sensor is on FP hardware. * @return *************************************************************************/ -static void calculateConductivityStandard( TEENSY_SENSOR_INDEX_T sensorNum, BOOL isFPSensor ) +static void calculateConductivityStandard( U32 sensorNum, BOOL isFPSensor ) { F32 calculatedConductivity = 0.0; F64 alpha = 0.0; F64 k = 0.0; F32 R = condRawMeasurement[ sensorNum ].impRzMag; - // Aly sensors are known to send the driver INF in unfavorable conditions for impedance. e.g: open air + // 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 ) { @@ -2086,7 +2095,7 @@ * @param isFPSensor - T/F if sensor is on FP hardware. * @return *************************************************************************/ -static void calculateResistance( TEENSY_SENSOR_INDEX_T sensorNum, BOOL isFPSensor ) +static void calculateResistance( U32 sensorNum, BOOL isFPSensor ) { F32 calculatedResistance = 0.0; @@ -2125,7 +2134,7 @@ * @param sensorNum - Teensy sensor index value. * @return *************************************************************************/ -static void calculateTemperature( TEENSY_SENSOR_INDEX_T sensorNum ) +static void calculateTemperature( U32 sensorNum ) { F32 calculatedTemperature = 0.0; @@ -2159,7 +2168,7 @@ TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; OVERRIDE_TYPE_T ovType = getOverrideArrayPayloadFromMessage( message, &payload ); - if ( payload.index <= LAST_FP_COND_SENSOR ) + if ( payload.index < NUM_OF_CONDUCTIVITY_SENSORS ) { // D74 is not connected to Teensy and does not have a data structure to override. if ( LAST_DD_COND_SENSOR != payload.index ) @@ -2169,13 +2178,13 @@ { F32 value = payload.state.f32; - condCalculatedMeasurement[ payload.index ].Conductivity.ovData = value; - condCalculatedMeasurement[ payload.index ].Conductivity.override = OVERRIDE_KEY; + condCalculatedMeasurement[ getTeensyCondId( payload.index ) ].Conductivity.ovData = value; + condCalculatedMeasurement[ getTeensyCondId( payload.index ) ].Conductivity.override = OVERRIDE_KEY; } else { - condCalculatedMeasurement[ payload.index ].Conductivity.override = OVERRIDE_RESET; - condCalculatedMeasurement[ payload.index ].Conductivity.ovData = condCalculatedMeasurement[ payload.index ].Conductivity.ovInitData; + condCalculatedMeasurement[ getTeensyCondId( payload.index ) ].Conductivity.override = OVERRIDE_RESET; + condCalculatedMeasurement[ getTeensyCondId( payload.index ) ].Conductivity.ovData = condCalculatedMeasurement[ payload.index ].Conductivity.ovInitData; } } } @@ -2198,7 +2207,7 @@ TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; OVERRIDE_TYPE_T ovType = getOverrideArrayPayloadFromMessage( message, &payload ); - if ( payload.index <= LAST_FP_COND_SENSOR ) + if ( payload.index < NUM_OF_CONDUCTIVITY_SENSORS ) { // D74 is not connected to Teensy and does not have a data structure to override. if ( LAST_DD_COND_SENSOR != payload.index ) @@ -2238,7 +2247,7 @@ TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; OVERRIDE_TYPE_T ovType = getOverrideArrayPayloadFromMessage( message, &payload ); - if ( payload.index <= LAST_FP_COND_SENSOR ) + if ( payload.index < NUM_OF_CONDUCTIVITY_SENSORS ) { // D74 is not connected to Teensy and does not have a data structure to override. if ( LAST_DD_COND_SENSOR != payload.index )