Index: firmware/App/Controllers/DGInterface.c =================================================================== diff -u -r4fc093ea280a0bdb47c20d25efb7c840b9f9867a -r2991b6731ff88740f29ea2f19411115d4f8a4aa4 --- firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision 4fc093ea280a0bdb47c20d25efb7c840b9f9867a) +++ firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision 2991b6731ff88740f29ea2f19411115d4f8a4aa4) @@ -26,6 +26,7 @@ #include "ModeTreatmentParams.h" #include "OperationModes.h" #include "PersistentAlarm.h" +#include "SystemComm.h" #include "SystemCommMessages.h" #include "Timers.h" @@ -48,7 +49,13 @@ #define DIALYSATE_TEMP_LOW_SAFETY_LIMIT_C 42.0F ///< Dialysate low safety temperature limit in C. #define DIALYSATE_TEMP_LOW_SAFETY_TIMEOUT_MS ( 10 * MS_PER_SECOND ) ///< Dialysate temperature low safety timeout in milliseconds. +#define LOAD_CELL_DATA_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Load cell freshness timeout (in ms). + // ********** private data ********** +static const U32 DIP_LOAD_CELL_DATA_MESSAGE_ALARM_THRESHOLD = ((2 * MS_PER_SECOND) / TASK_GENERAL_INTERVAL); +static const U32 DIP_TEMPERATURE_DATA_MESSAGE_ALARM_THRESHOLD = ((2 * MS_PER_SECOND) / TASK_GENERAL_INTERVAL); +static const U32 DIP_RESERVOIRS_DATA_MESSAGE_ALARM_THRESHOLD = ((2 * MS_PER_SECOND) / TASK_GENERAL_INTERVAL); +static const U32 DIP_DG_OP_MODE_DATA_MESSAGE_ALARM_THRESHOLD = ((2 * MS_PER_SECOND) / TASK_GENERAL_INTERVAL); // DG status static DG_OP_MODE_T dgCurrentOpMode; ///< Current DG operation mode. @@ -61,7 +68,7 @@ static U32 timeStartMS = 0; // TODO is this needed? // DG sensor data -static F32 dgDialysateTemp; ///< Dialysate temperature reported by the DG. +static F32 dgDialysateTemp; ///< Dialysate temperature reported by the DG. static F32 dgRedundantDialysateTemp = 0.0; ///< Redundant dialysate temperature reported by the DG. static F32 dgPrimaryTemp = 0.0; ///< Latest RO water temperature reported by the DG. static F32 dgTrimmerTempSet; ///< Trimmer heater target temperature commanded. @@ -81,8 +88,16 @@ static F32 lgLoadCellBackupReadingsTotal[ NUM_OF_DG_RESERVOIRS ]; ///< Rolling total - used to calc large load cell moving average. // DG Dialysate flow rate -static F32 dgDialysateFlowRateMlMin; ///< Latest dialysate flow rate reported by the DG. -static BOOL dgDialysateFlowDataFreshFlag; ///< Flag to signal the execDialInFlowMonitor() to process fresh flow rate data +static F32 dgDialysateFlowRateMlMin = 0.0; ///< Latest dialysate flow rate reported by the DG. +static BOOL dgDialysateFlowDataFreshFlag = FALSE; ///< Flag to signal the execDialInFlowMonitor() to process fresh flow rate data +static BOOL dgLoadCellDataFreshFlag = FALSE; ///< Flag to signal the handleLoadCellReadingsFromDG() to process fresh load cell data +static BOOL dgDialysateTemperatureDataFreshFlag = FALSE; ///< Flag to signal the handleTemperatureReadingsFromDG() to process fresh temperature data +static BOOL dgReservoirsDataFreshFlag = FALSE; ///< Flag to signal the handleDGReservoirData() to process fresh reservoirs data +static BOOL dgOpModeDataFreshFlag = FALSE; ///< Flag to signal the handleDGOpMode() to process fresh dg op mode data +static U32 loadcellDataMessageFreshStatusCounter = 0; ///< Counter use to trigger alarm if no fresh load cell data message is received +static U32 temperatureDataMessageFreshStatusCounter = 0; ///< Counter use to trigger alarm if no fresh temperature data message is received +static U32 reservoirsDataMessageFreshStatusCounter = 0; ///< Counter use to trigger alarm if no fresh reservoirs data message is received +static U32 dgOpModeDataMessageFreshStatusCounter = 0; ///< Counter use to trigger alarm if no fresh dg op mode data message is received // Reservoir data static DG_RESERVOIR_ID_T dgActiveReservoir; ///< Latest active reservoir reported by the DG. @@ -170,7 +185,42 @@ initPersistentAlarm( ALARM_ID_HD_DIALYSATE_TEMP_BELOW_TARGET_TEMP, DIALYSATE_TEMP_OUT_OF_TARGET_TIMEOUT_MS, DIALYSATE_TEMP_OUT_OF_TARGET_TIMEOUT_MS ); initPersistentAlarm( ALARM_ID_HD_DIALYSATE_TEMP_ABOVE_TARGET_TEMP, DIALYSATE_TEMP_OUT_OF_TARGET_TIMEOUT_MS, DIALYSATE_TEMP_OUT_OF_TARGET_TIMEOUT_MS ); + + initPersistentAlarm( ALARM_ID_HD_NEW_LOAD_CELL_DATA_MESSAGE_NOT_RECEIVE, LOAD_CELL_DATA_TIMEOUT_MS, LOAD_CELL_DATA_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_HD_NEW_DIALYSATE_TEMPERATURE_DATA_MESSAGE_NOT_RECEIVE, LOAD_CELL_DATA_TIMEOUT_MS, LOAD_CELL_DATA_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_HD_NEW_RESERVOIRS_DATA_MESSAGE_NOT_RECEIVE, LOAD_CELL_DATA_TIMEOUT_MS, LOAD_CELL_DATA_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_HD_NEW_DG_OPERATION_MODE_MESSAGE_NOT_RECEIVE, LOAD_CELL_DATA_TIMEOUT_MS, LOAD_CELL_DATA_TIMEOUT_MS ); } + +/**********************************************************************//** + * @brief + * The checkDGDataFreshness function checks the condition + * for triggering an alarm if the DG fresh data is not received for 2 seconds. + * @details Inputs: none + * @details Outputs: an alarm is triggered or an alarm condition is cleared + * @param alarm ID of alarm to check + * @param flag to signal the fresh data processing + * @return None + *************************************************************************/ +void checkDGDataFreshness( ALARM_ID_T alarmID, BOOL *dgFreshDataFlag ) +{ + if ( TRUE == *dgFreshDataFlag ) + { + *dgFreshDataFlag = FALSE; + checkPersistentAlarm( alarmID, FALSE, 0.0, 0.0 ); + } + else + { // Alarm if not receiving DG fresh data message in timely manner + if ( TRUE == isDGCommunicating() ) + { + checkPersistentAlarm( alarmID, TRUE, 0.0, 0.0 ); + } + else + { + checkPersistentAlarm( alarmID, FALSE, 0.0, 0.0 ); + } + } +} /*********************************************************************//** * @brief @@ -182,9 +232,20 @@ *************************************************************************/ void execDGInterfaceMonitor( void ) { - // TODO - make sure DG sensor/state data is coming in timely manner (e.g. load cells s/b every 100 ms) + // Trigger alarm if not receiving new load cell data message in timely manner + /*checkDGDataFreshness( ALARM_ID_HD_NEW_LOAD_CELL_DATA_MESSAGE_NOT_RECEIVE, &dgLoadCellDataFreshFlag ); - // Check to see if DG has restarted + // Trigger alarm if not receiving new dialysate temperature data message in timely manner + checkDGDataFreshness( ALARM_ID_HD_NEW_DIALYSATE_TEMPERATURE_DATA_MESSAGE_NOT_RECEIVE, &dgDialysateTemperatureDataFreshFlag ); + + // Trigger alarm if not receiving new reservoirs data message in timely manner + checkDGDataFreshness( ALARM_ID_HD_NEW_RESERVOIRS_DATA_MESSAGE_NOT_RECEIVE, &dgReservoirsDataFreshFlag ); + + // Trigger alarm if not receiving new reservoirs data message in timely manner + checkDGDataFreshness( ALARM_ID_HD_NEW_DG_OPERATION_MODE_MESSAGE_NOT_RECEIVE, &dgOpModeDataFreshFlag ); + + // Check to see if DG has restarted*/ + checkDGRestart(); // Check the status of the trimmer heater @@ -298,6 +359,74 @@ return result; } + +/*********************************************************************//** + * @brief + * The getLoadCellDataFreshFlag function returns a flag to indicate + * if the load cell data message reported by the DG is fresh or stale data. + * @details Inputs: dgLoadCellDataFreshFlag + * @details Outputs: dgLoadCellDataFreshFlag + * @return T/F flag to indicate fresh/stale status of load cell data. + *************************************************************************/ +BOOL getLoadCellDataFreshFlag( void ) +{ + BOOL result = dgLoadCellDataFreshFlag; + + dgLoadCellDataFreshFlag = FALSE; + + return result; +} + +/*********************************************************************//** + * @brief + * The getTemperatureDataFreshFlag function returns a flag to indicate + * if the temperature data message reported by the DG is fresh or stale data. + * @details Inputs: dgDialysateTemperatureDataFreshFlag + * @details Outputs: dgDialysateTemperatureDataFreshFlag + * @return T/F flag to indicate fresh/stale status of load cell data. + *************************************************************************/ +BOOL getTemperatureDataFreshFlag( void ) // DN-19AUG2022 +{ + BOOL result = dgDialysateTemperatureDataFreshFlag; + + dgDialysateTemperatureDataFreshFlag = FALSE; + + return result; +} + +/*********************************************************************//** + * @brief + * The getReservoirsDataFreshFlag function returns a flag to indicate + * if the reservoirs data message reported by the DG is fresh or stale data. + * @details Inputs: dgReservoirsDataFreshFlag + * @details Outputs: dgReservoirsDataFreshFlag + * @return T/F flag to indicate fresh/stale status of load cell data. + *************************************************************************/ +BOOL getReservoirsDataFreshFlag( void ) // DN-22AUG2022 +{ + BOOL result = dgReservoirsDataFreshFlag; + + dgReservoirsDataFreshFlag = FALSE; + + return result; +} + +/*********************************************************************//** + * @brief + * The getDGOpModeDataFreshFlag function returns a flag to indicate + * if the dg op mode data message reported by the DG is fresh or stale data. + * @details Inputs: dgOpModeDataFreshFlag + * @details Outputs: dgOpModeDataFreshFlag + * @return T/F flag to indicate fresh/stale status of load cell data. + *************************************************************************/ +BOOL getDgOpModeDataFreshFlag( void ) // DN-22AUG2022 +{ + BOOL result = dgOpModeDataFreshFlag; + + dgOpModeDataFreshFlag = FALSE; + + return result; +} /*********************************************************************//** * @brief @@ -374,26 +503,26 @@ /*********************************************************************//** * @brief - * The getDialysateTemperature function gets the latest dialysate temperature. - * @details Inputs: dgDialysateTemp + * The getDGDisinfectsStates function returns the DG disinfects readings. + * @details Inputs: none * @details Outputs: none - * @return the current dialysate temperature + * @return the current DG disinfects readings *************************************************************************/ -F32 getDialysateTemperature( void ) +DG_DISINFECT_UI_STATES_T getDGDisinfectsStates( void ) { - return dgDialysateTemp; + return disinfectsStatus; } /*********************************************************************//** * @brief - * The getDGDisinfectsStates function returns the DG disinfects readings. - * @details Inputs: none + * The getDialysateTemperature function gets the latest dialysate temperature. + * @details Inputs: dgDialysateTemp * @details Outputs: none - * @return the current DG disinfects readings + * @return the current dialysate temperature *************************************************************************/ -DG_DISINFECT_UI_STATES_T getDGDisinfectsStates( void ) +F32 getDialysateTemperature( void ) { - return disinfectsStatus; + return dgDialysateTemp; } /*********************************************************************//** @@ -436,7 +565,7 @@ * @return none *************************************************************************/ void setDGOpMode( U32 opMode, U32 subMode ) -{ +{ if ( opMode < NUM_OF_DG_MODES ) { dgCurrentOpMode = (DG_OP_MODE_T)opMode; @@ -445,7 +574,9 @@ else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_DG_OPERATING_MODE, opMode ); - } + } + + dgOpModeDataFreshFlag = TRUE; } /*********************************************************************//** @@ -459,9 +590,11 @@ * @return none *************************************************************************/ void setDialysateTemperatureReadings( F32 temp1, F32 temp2 ) -{ - dgDialysateTemp = temp1; - dgRedundantDialysateTemp = temp2; +{ + dgDialysateTemp = temp1; + dgRedundantDialysateTemp = temp2; + + dgDialysateTemperatureDataFreshFlag = TRUE; } /*********************************************************************//** @@ -476,7 +609,7 @@ * @return none *************************************************************************/ void setDGReservoirsData( DG_RESERVOIR_ID_T resID, U32 fillVol, U32 drainVol ) -{ +{ if ( resID < NUM_OF_DG_RESERVOIRS ) { dgActiveReservoir = resID; @@ -486,7 +619,9 @@ else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_HD_INVALID_RESERVOIR_ID, resID ); - } + } + + dgReservoirsDataFreshFlag = TRUE; } /*********************************************************************//** @@ -554,6 +689,8 @@ // Update Dialysis sub-mode with new reservoir volumes updateReservoirVolumes( res1Primary, res2Primary ); + + dgLoadCellDataFreshFlag = TRUE; } /*********************************************************************//** @@ -901,6 +1038,19 @@ /*********************************************************************//** * @brief + * The cmdSetDGToServiceMode function sends a request to DG to transition + * to service mode. + * @details Inputs: none + * @details Outputs: none + * @return none + *************************************************************************/ +void cmdSetDGToServiceMode( void ) +{ + sendDGServiceModeRequest(); +} + +/*********************************************************************//** + * @brief * The handleDGCommandResponse function processes the latest DG command response. * @details Inputs: none * @details Outputs: process command response from DG