Index: firmware/App/Services/DDInterface.c =================================================================== diff -u -rf688e0f8bded1f0a687437e3136cfba8b14f87b6 -r9ea1971251bb0064e626c21e7d94215114254a98 --- firmware/App/Services/DDInterface.c (.../DDInterface.c) (revision f688e0f8bded1f0a687437e3136cfba8b14f87b6) +++ firmware/App/Services/DDInterface.c (.../DDInterface.c) (revision 9ea1971251bb0064e626c21e7d94215114254a98) @@ -34,62 +34,25 @@ // ********** private definitions ********** -#define START_DG_CMD TRUE ///< Parameter for DG start/stop command function. True = start. -#define STOP_DG_CMD FALSE ///< Parameter for DG start/stop command function. False = stop. +#define DD_DATA_FRESHNESS_TIMEOUT_MS ( 3 * MS_PER_SECOND ) ///< DD data freshness timeout (in ms). -#define SIZE_OF_LARGE_LOAD_CELL_AVG 32 ///< Large load cell moving average has 32 samples. - -#define DIALYSATE_TEMP_OUT_OF_TARGET_CLEAR_TOL_C 2.0F ///< Dialysate temperature clear alarm tolerance C -#define DIALYSATE_TEMP_OUT_OF_TARGET_TOL_C 4.0F ///< Dialysate temperature out of target tolerance C. -#define DIALYSATE_TEMP_OUT_OF_TARGET_TIMEOUT_MS ( 90 * MS_PER_SECOND ) ///< Dialysate temperature out of target timeout in milliseconds. -#define DIALYSATE_TEMP_UPPER_MAX_SAFETY_LIMIT_C 46.0F ///< Dialysate upper bound maximum temperature limit in C. -#define DIALYSATE_TEMP_UPPER_MAX_SAFETY_TIMEOUT_MS ( 1 * MS_PER_SECOND ) ///< Dialysate temperature upper bound maximum safety timeout in milliseconds. -#define DIALYSATE_TEMP_UPPER_SAFETY_LIMIT_C 42.0F ///< Dialysate upper bound safety temperature limit in C. -#define DIALYSATE_TEMP_UPPER_SAFETY_TIMEOUT_MS ( 300 * MS_PER_SECOND ) ///< Dialysate temperature upper bound timeout in milliseconds. -#define DIALYSATE_TEMP_LOWER_SAFETY_LIMIT_C 33.0F ///< Dialysate lower bound safety temperature limit in C. -#define DIALYSATE_TEMP_LOWER_SAFETY_TIMEOUT_MS ( 300 * MS_PER_SECOND ) ///< Dialysate temperature lower bound timeout in milliseconds. -#define DIALYSATE_TEMP_CLEAR_TIMEOUT_MS ( 10 * MS_PER_SECOND ) ///< Dialysate temperature clear persistence timeout. -#define DG_DATA_FRESHNESS_TIMEOUT_MS ( 3 * MS_PER_SECOND ) ///< DG data freshness timeout (in ms). -#define DG_TRIMMER_HTR_CHECK_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL + 2 ) ///< DG trimmer heater check interval in general task execution time counts. - // ********** private data ********** // DG status -static DG_OP_MODE_T dgCurrentOpMode; ///< Current DG operation mode. -static U32 dgSubMode; ///< Current state (sub-mode) of current DG operation mode. -static BOOL dgStartCommandSent; ///< Flag indicates command to start DG has been sent. -static BOOL dgStarted; ///< Flag indicates whether we have commanded the DG to start or stop. -static BOOL dgTrimmerHeaterOn; ///< Flag indicates whether we have commanded the DG to start or stop the trimmer heater. +static DD_OP_MODE_T ddCurrentOpMode; ///< Current DD operation mode. +static U32 ddSubMode; ///< Current state (sub-mode) of current DG operation mode. +static BOOL ddStartCommandSent; ///< Flag indicates command to start DG has been sent. +static BOOL ddStarted; ///< Flag indicates whether we have commanded the DD to start or stop. -// DG sensor data -static F32 dgDialysateTemp; ///< Dialysate temperature reported by the DG. -static F32 dgRedundantDialysateTemp; ///< Redundant dialysate temperature reported by the DG. -static F32 dgHeatDisinfectTemp; ///< Heat disinfect temperature reported by the DG. -static F32 dgTrimmerTempSet; ///< Trimmer heater target temperature commanded. +static BOOL ddOpModeDataFreshFlag = FALSE; ///< Flag to signal the handleDDOpMode() to process fresh dd op mode data -static U32 dgTrimmerTempCheckTimerCtr; ///< Trimmer heater temp check interval timer counter. - -// DG Dialysate flow rate -static F32 dgDialysateFlowRateLMin; ///< Latest dialysate flow rate (in L/min) reported by the DG. -static F32 dgDialysateFlowRateRawLMin; ///< Latest raw dialysate flow rate (in L/min) reported by the DG. -static BOOL dgDialysateFlowDataFreshFlag = FALSE; ///< Flag to signal the execDialInFlowMonitor() to process fresh flow rate 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 DG_DISINFECT_UI_STATES_T disinfectsStatus; ///< DG disinfects status. -static DG_MIXING_RATIOS_T dgMixingRatios; ///< DG mixing ratios. -static HEATERS_DATA_T dgHeatersData; ///< DG heaters data. -static DG_SERVICE_AND_USAGE_DATA_T dgServiceAndUsageData; ///< DG service and usage data. - // DG command response -static DG_CMD_RESPONSE_T dgCmdResp[ NUM_OF_DG_COMMANDS ]; ///< Keep the latest DG command response for each command. +static DD_CMD_RESPONSE_T ddCmdResp[ NUM_OF_DD_COMMANDS ]; ///< Keep the latest DD command response for each command. // ********** private function prototypes ********** -static void checkDGRestart( void ); -static void checkDGTrimmerHeaterStatus( void ); -static void checkDGDataFreshness( ALARM_ID_T alarmID, BOOL *dgFreshDataFlag ); +static void checkDDRestart( void ); +static void checkDDDataFreshness( ALARM_ID_T alarmID, BOOL *ddFreshDataFlag ); /*********************************************************************//** * @brief @@ -103,33 +66,20 @@ U32 i; // NOTE: the active reservoir is set to reservoir 1 since DG will send active reservoir 1 as active on power up - dgStarted = FALSE; - dgTrimmerHeaterOn = FALSE; - dgTrimmerTempSet = 0.0F; - dgTrimmerTempCheckTimerCtr = 0; - dgDialysateTemp = 0.0F; - dgCurrentOpMode = DG_MODE_INIT; - dgSubMode = 0; - dgStartCommandSent = FALSE; - dgDialysateFlowRateLMin = 0.0F; - dgDialysateFlowRateRawLMin = 0.0F; - dgDialysateFlowDataFreshFlag = FALSE; - dgHeatDisinfectTemp = 0.0F; + ddStarted = FALSE; + ddCurrentOpMode = DD_MODE_INIT; + ddSubMode = 0; + ddStartCommandSent = FALSE; - // initialize DG command response - for ( i = 0; i < NUM_OF_DG_COMMANDS; i++ ) + // initialize DD command response + for ( i = 0; i < NUM_OF_DD_COMMANDS; i++ ) { - dgCmdResp[ i ].commandID = DG_CMD_NONE; - dgCmdResp[ i ].rejected = TRUE; - dgCmdResp[ i ].rejectCode = DG_CMD_REQUEST_REJECT_REASON_NONE; + ddCmdResp[ i ].commandID = DD_CMD_NONE; + ddCmdResp[ i ].rejected = TRUE; + ddCmdResp[ i ].rejectCode = DD_CMD_REQUEST_REJECT_REASON_NONE; } -// initPersistentAlarm( ALARM_ID_HD_DIALYSATE_TEMP_ABOVE_TARGET_TEMP, DIALYSATE_TEMP_CLEAR_TIMEOUT_MS, DIALYSATE_TEMP_OUT_OF_TARGET_TIMEOUT_MS ); -// initPersistentAlarm( ALARM_ID_HD_DIALYSATE_TEMP_BELOW_TARGET_TEMP, DIALYSATE_TEMP_CLEAR_TIMEOUT_MS, DIALYSATE_TEMP_OUT_OF_TARGET_TIMEOUT_MS ); -// initPersistentAlarm( ALARM_ID_HD_DIALYSATE_TEMP_ABOVE_SAFETY_TEMP, DIALYSATE_TEMP_CLEAR_TIMEOUT_MS, DIALYSATE_TEMP_UPPER_MAX_SAFETY_TIMEOUT_MS ); - -// initPersistentAlarm( ALARM_ID_HD_NEW_DIALYSATE_TEMP_DATA_MESSAGE_NOT_RECEIVE, DG_DATA_FRESHNESS_TIMEOUT_MS, DG_DATA_FRESHNESS_TIMEOUT_MS ); -// initPersistentAlarm( ALARM_ID_HD_DG_NEW_OPERATION_MODE_MESSAGE_NOT_RECEIVE, DG_DATA_FRESHNESS_TIMEOUT_MS, DG_DATA_FRESHNESS_TIMEOUT_MS ); +// initPersistentAlarm( ALARM_ID_TD_DD_NEW_OPERATION_MODE_MESSAGE_NOT_RECEIVE, DD_DATA_FRESHNESS_TIMEOUT_MS, DD_DATA_FRESHNESS_TIMEOUT_MS ); } /**********************************************************************//** @@ -172,7 +122,7 @@ * dgReservoirsDataFreshFlag, dgOpModeDataFreshFlag * @return none *************************************************************************/ -void execDGInterfaceMonitor( void ) +void execDDInterfaceMonitor( void ) { // if ( getCPLDACPowerLossDetected() != TRUE ) { @@ -187,28 +137,21 @@ // setDGOpMode( DG_MODE_FAUL, 0 ); // } - // Check to see if DG has restarted - checkDGRestart(); - - // Check the status of the trimmer heater - if ( ++dgTrimmerTempCheckTimerCtr >= DG_TRIMMER_HTR_CHECK_INTERVAL ) - { - dgTrimmerTempCheckTimerCtr = 0; - checkDGTrimmerHeaterStatus(); - } + // Check to see if DD has restarted + checkDDRestart(); } } /*********************************************************************//** * @brief - * The getDGOpMode function gets the current DG operating mode. - * @details Inputs: dgCurrentOpMode + * The getDDOpMode function gets the current DD operating mode. + * @details Inputs: ddCurrentOpMode * @details Outputs: none - * @return Current DG operating mode. + * @return Current DD operating mode. *************************************************************************/ -DG_OP_MODE_T getDGOpMode( void ) +DD_OP_MODE_T getDDOpMode( void ) { - return dgCurrentOpMode; + return ddCurrentOpMode; } /*********************************************************************//** @@ -218,151 +161,13 @@ * @details Outputs: none * @return Current DG operating sub-mode. *************************************************************************/ -U32 getDGSubMode( void ) +U32 getDDSubMode( void ) { - return dgSubMode; + return ddSubMode; } /*********************************************************************//** * @brief - * The getDGDialysateFlowRateLMin function gets the latest dialysate flow - * rate reported by the DG. - * @details Inputs: dgDialysateFlowRateLMin - * @details Outputs: none - * @return Latest dialysate flow rate (in L/min) reported by DG. - *************************************************************************/ -F32 getDGDialysateFlowRateLMin( void ) -{ - F32 result = dgDialysateFlowRateLMin; - - return result; -} - -/*********************************************************************//** - * @brief - * The getDGRawDialysateFlowRateLMin function gets the latest raw dialysate flow - * rate reported by the DG. - * @details Inputs: dgDialysateFlowRateRawLMin - * @details Outputs: none - * @return Latest dialysate flow rate (in L/min) reported by DG. - *************************************************************************/ -F32 getDGRawDialysateFlowRateLMin( void ) -{ - F32 result = dgDialysateFlowRateRawLMin; - - return result; -} - -/*********************************************************************//** - * @brief - * The getDialysateFlowDataFreshFlag function returns a flag to indicate - * if the dialysate flow rate data reported by the DG is fresh or stale data. - * @details Inputs: dgDialysateFlowDataFreshFlag - * @details Outputs: dgDialysateFlowDataFreshFlag - * @return T/F flag to indicate fresh/stale status of dialysate flow data. - *************************************************************************/ -BOOL getDialysateFlowDataFreshFlag( void ) -{ - BOOL result = dgDialysateFlowDataFreshFlag; - - dgDialysateFlowDataFreshFlag = FALSE; - - return result; -} - -/*********************************************************************//** - * @brief - * The getDialysateTemperature function gets the latest dialysate temperature. - * @details Inputs: dgDialysateTemp - * @details Outputs: none - * @return the latest dialysate temperature - *************************************************************************/ -F32 getDialysateTemperature( void ) -{ - return dgDialysateTemp; -} - -/*********************************************************************//** - * @brief - * The getRedundantDialysateTemperature function gets the latest redundant - * dialysate temperature. - * @details Inputs: dgRedundantDialysateTemp - * @details Outputs: none - * @return the latest redundant dialysate temperature - *************************************************************************/ -F32 getRedundantDialysateTemperature( void ) -{ - return dgRedundantDialysateTemp; -} - -/*********************************************************************//** - * @brief - * The getHeatDisinfectTemperatureSensorValue function gets the latest - * heat disinfect temperature sensor value. - * @details Inputs: dgDialysateTemp - * @details Outputs: none - * @return the current heat disinfect temperature sensor value - *************************************************************************/ -F32 getHeatDisinfectTemperatureSensorValue( void ) -{ - return dgHeatDisinfectTemp; -} - -/*********************************************************************//** - * @brief - * The getTrimmerHeaterCommandedOn function gets the latest on/off commanded - * status of the trimmer heater. - * @details Inputs: dgTrimmerHeaterOn - * @details Outputs: none - * @return dgTrimmerHeaterOn - *************************************************************************/ -BOOL getTrimmerHeaterCommandedOn( void ) -{ - return dgTrimmerHeaterOn; -} - -/*********************************************************************//** - * @brief - * The getDGDisinfectsStates function returns the DG disinfects readings. - * @details Inputs: disinfectsStatus - * @details Outputs: none - * @return the current DG disinfects readings - *************************************************************************/ -DG_DISINFECT_UI_STATES_T getDGDisinfectsStates( void ) -{ - return disinfectsStatus; -} - -/*********************************************************************//** - * @brief - * The getDGMixingRatios function returns the DG mixing ratios and the fill - * prep time. - * @details Inputs: dgMixingRatios - * @details Outputs: none - * @return getDGMixingRatios which is the DG mixing ratios - *************************************************************************/ -DG_MIXING_RATIOS_T getDGMixingRatios( void ) -{ - return dgMixingRatios; -} - -/*********************************************************************//** - * @brief - * The getHDVersionDGServiceAndUsageData function copies the HD version of - * the DG service and usage data into the provided buffer. - * @details Inputs: dgServiceAndUsageData - * @details Outputs: none - * @param data which is a pointer of type DG_SERVICE_AND_USAGE_DATA_T that - * is the provided buffer - * @return none - *************************************************************************/ -void getHDVersionDGServiceAndUsageData( DG_SERVICE_AND_USAGE_DATA_T* data ) -{ - memcpy( data, &dgServiceAndUsageData, sizeof( DG_SERVICE_AND_USAGE_DATA_T ) ); -} - -/*********************************************************************//** - * @brief * The setDGOpMode function sets the latest DG operating mode reported by * the DG. * @details Inputs: none @@ -371,547 +176,59 @@ * @param subMode sub-mode (current state) of operating mode reported by DG * @return none *************************************************************************/ -void setDGOpMode( U32 opMode, U32 subMode ) +void setDDOpMode( U32 opMode, U32 subMode ) { - if ( opMode < NUM_OF_DG_MODES ) + if ( opMode < NUM_OF_DD_MODES ) { // reset POST passed flag if DG restarted or faulted or went to service mode - if ( ( opMode < DG_MODE_STAN ) && ( dgCurrentOpMode >= DG_MODE_STAN ) ) + if ( ( opMode < DD_MODE_STAN ) && ( ddCurrentOpMode >= DD_MODE_STAN ) ) { signalDDPOSTFinalResult( FALSE ); } // update DG op mode and sub-mode - dgCurrentOpMode = (DG_OP_MODE_T)opMode; - dgSubMode = subMode; + ddCurrentOpMode = (DD_OP_MODE_T)opMode; + ddSubMode = subMode; } else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_DD_OPERATING_MODE, opMode ); } - dgOpModeDataFreshFlag = TRUE; + ddOpModeDataFreshFlag = TRUE; } /*********************************************************************//** * @brief - * The setDialysateTemperatureReadings function sets the latest dialysate - * temperatures reported by the DG. + * The handleDDCommandResponse function processes the latest DD command response. * @details Inputs: none - * @details Outputs: dgDialysateTemp, dgRedundantDialysateTemp, - * dgDialysateTemperatureDataFreshFlag - * @param tdi dialysate temperature reported by DG - * @param tro redundant dialysate temperature reported by DG - * @param thd heat disinfect temperature sensor reported by DG + * @details Outputs: process command response from DD + * @param ddCmdRespPtr pointer to DD command response data record * @return none *************************************************************************/ -void setDialysateTemperatureReadings( F32 tdi, F32 tro, F32 thd ) +void handleDDCommandResponse( DD_CMD_RESPONSE_T *ddCmdRespPtr ) { - dgDialysateTemp = tdi; - dgRedundantDialysateTemp = tro; - dgHeatDisinfectTemp = thd; - dgDialysateTemperatureDataFreshFlag = TRUE; -} - -/*********************************************************************//** - * @brief - * The setDialysateFlowData function sets the latest dialysate flow rate - * and its freshness status. The dialysate flow data is reported by the DG. - * @details Inputs: none - * @details Outputs: dgDialysateFlowRateLMin, dgDialysateFlowRateRawLMin, - * dgDialysateFlowDataFreshFlag - * @param flowRates latest DG flow rates (mL/min) reported by DG - * @return none - *************************************************************************/ -void setDialysateFlowData( FLOW_SENSORS_DATA_T flowRates ) -{ - // Check if the sent value by DG is a NaN - if ( isnan( flowRates.dialysateFlowRateLPM ) ) + if ( ddCmdRespPtr->commandID < NUM_OF_DD_COMMANDS ) { - flowRates.dialysateFlowRateLPM = 0.0F; - } - if ( isnan( flowRates.dialysateRawFlowRateLPM ) ) - { - flowRates.dialysateRawFlowRateLPM = 0.0F; - } - - dgDialysateFlowRateLMin = flowRates.dialysateFlowRateLPM; - dgDialysateFlowRateRawLMin = flowRates.dialysateRawFlowRateLPM; - dgDialysateFlowDataFreshFlag = TRUE; -} - -/*********************************************************************//** - * @brief - * The setDGDisinfectsStates function sets the latest disinfects states - * from DG. - * @details Inputs: none - * @details Outputs: disinfectsStatus - * @param states latest DG disinfects state readings - * @return none - *************************************************************************/ -void setDGDisinfectsStates( DG_DISINFECT_UI_STATES_T states ) -{ - memcpy( &disinfectsStatus, &states, sizeof(DG_DISINFECT_UI_STATES_T) ); -} - -/*********************************************************************//** - * @brief - * The setDGMixingRatios function sets the mixing ratios as well as the fill - * prep time upon a request from DG. - * @details Inputs: none - * @details Outputs: dgMixingRatios - * @param ratios the mixing ratios from DG - * @return none - *************************************************************************/ -void setDGMixingRatios( DG_MIXING_RATIOS_T ratios ) -{ - memcpy( &dgMixingRatios, &ratios, sizeof( DG_MIXING_RATIOS_T ) ); -} - -/*********************************************************************//** - * @brief - * The setDGHeatersData function sets heaters data that has been read from DG. - * @details Inputs: none - * @details Outputs: dgHeatersData - * @param data which is a pointer to the received heaters data - * @return none - *************************************************************************/ -void setDGHeatersData( HEATERS_DATA_T *data ) -{ - memcpy( &dgHeatersData, data, sizeof( HEATERS_DATA_T ) ); -} - -/*********************************************************************//** - * @brief - * The setHDVersionDGServiceRecord function sets the HD version of the DG - * service record. - * @details Inputs: none - * @details Outputs: dgServiceAndUsageData - * @param data which is a pointer to the received HD version of the DG service - * record - * @return none - *************************************************************************/ -void setHDVersionDGServiceRecord( DG_SERVICE_RECORD_T* data ) -{ - dgServiceAndUsageData.isDGServiceRecordAvailable = TRUE; - memcpy( &dgServiceAndUsageData.dgServiceRecord, data, sizeof( DG_SERVICE_RECORD_T ) ); -} - -/*********************************************************************//** - * @brief - * The setHDVersionDGUsageInfo function sets the HD version of the DG - * usage information. - * @details Inputs: none - * @details Outputs: dgServiceAndUsageData - * @param data which is a pointer to the received HD version of the DG usage - * info - * @return none - *************************************************************************/ -void setHDVersionDGUsageInfo( DG_USAGE_INFO_RECORD_T* data ) -{ - dgServiceAndUsageData.isDGUsageInfoAvailable = TRUE; - memcpy( &dgServiceAndUsageData.dgUsageInfo, data, sizeof( DG_USAGE_INFO_RECORD_T ) ); -} - -/*********************************************************************//** - * @brief - * The cmdSetDGDialysateHeatingParams function sends the dialysate heating - * parameters to DG. - * @details Inputs: none - * @details Outputs: dgTrimmerTempSet - * @param heatingParams Dialysate heating parameters to be sent to DG - * @return none - *************************************************************************/ -void cmdSetDGDialysateHeatingParams( DG_CMD_DIALYSATE_HEATING_PARAMS_T heatingParams ) -{ - dgTrimmerTempSet = heatingParams.trimmerTargetTemperature; - // TODO what should we do with the BOOL return of this function? -// sendDialysateHeatingParamsToDG( &heatingParams ); -} - -/*********************************************************************//** - * @brief - * The cmdStartDG function sends a start command to the DG. DG will transition - * from standby to recirculate mode and start producing warm, pure water. - * @details Inputs: none - * @details Outputs: start DG command sent - * @return none - *************************************************************************/ -void cmdStartDG( void ) -{ - dgStartCommandSent = TRUE; - -// sendDGStartStopCommand( (BOOL)START_DG_CMD ); -} - -/*********************************************************************//** - * @brief - * The cmdStopDG function sends a stop command to the DG. DG will transition - * from recirculate mode to standby mode. Pumps and heater go off. - * @details Inputs: none - * @details Outputs: stop DG command sent - * @return none - *************************************************************************/ -void cmdStopDG( void ) -{ - dgStarted = FALSE; - -// sendDGStartStopCommand( (BOOL)STOP_DG_CMD ); -} - -/*********************************************************************//** - * @brief - * The cmdStartDGTrimmerHeater function sends a start trimmer heater command - * to the DG. - * @details Inputs: none - * @details Outputs: start DG trimmer heater command sent - * @return none - *************************************************************************/ -void cmdStartDGTrimmerHeater( void ) -{ - dgTrimmerHeaterOn = TRUE; - dgCmdResp[ DG_CMD_START_TRIMMER_HEATER ].commandID = DG_CMD_NONE; - -// sendDGStartStopTrimmerHeaterCommand( START_DG_CMD ); -} - -/*********************************************************************//** - * @brief - * The cmdStopDGTrimmerHeater function sends a stop trimmer heater command - * to the DG. - * @details Inputs: none - * @details Outputs: stop DG trimmer heater command sent - * @return none - *************************************************************************/ -void cmdStopDGTrimmerHeater( void ) -{ - dgTrimmerHeaterOn = FALSE; - dgCmdResp[ DG_CMD_STOP_TRIMMER_HEATER ].commandID = DG_CMD_NONE; - -// sendDGStartStopTrimmerHeaterCommand( STOP_DG_CMD ); -} - -/*********************************************************************//** - * @brief - * The cmdStartDGFill function sends a fill command message to the DG. - * @details Inputs: none - * @details Outputs: fill command sent to DG. - * @param fillToVolMl volume (in mL) to fill inactive reservoir to - * @param targetFlowLPM target flow rate in L/min - * @return none - *************************************************************************/ -void cmdStartDGFill( U32 fillToVolMl, F32 targetFlowLPM ) -{ -// dgCmdResp[ DG_CMD_START_FILL ].commandID = DG_CMD_NONE; -// -// if ( ( FALSE == isAlarmActive( ALARM_ID_DG_ACID_BOTTLE_LOW_VOLUME ) ) && ( FALSE == isAlarmActive( ALARM_ID_DG_BICARB_BOTTLE_LOW_VOLUME ) ) ) -// { -// // The empty bottle alarms should not be active. If they are, the user shall insert the new bottle first and then hit Ok/Resume and -// // then the fill can go. This is to make sure the next fill is done the full bottles -// sendDGFillCommand( DG_CMD_START, fillToVolMl, targetFlowLPM ); -// } -} - -/*********************************************************************//** - * @brief - * The cmdStopDGFill function sends a fill command with stop parameter message to the DG. - * @details Inputs: none - * @details Outputs: fill command with stop parameter sent to DG. - * @return none - *************************************************************************/ -void cmdStopDGFill( void ) -{ - dgCmdResp[ DG_CMD_STOP_FILL ].commandID = DG_CMD_NONE; - -// sendDGFillCommand( DG_CMD_STOP, 0, 0 ); -} - -/*********************************************************************//** - * @brief - * The cmdStartDGDrain function sends a drain command message to the DG. - * @details Inputs: none - * @details Outputs: drain command sent to DG. - * @param drainToVolMl volume (in mL) to drain inactive reservoir to - * @param tareLoadCell flag to tell DG tare load cell or not - * @param start flag to tell DG to start or stop the drain mode - * @return none - *************************************************************************/ -void cmdStartDGDrain( U32 drainToVolMl, BOOL tareLoadCell, BOOL rinse, BOOL start ) -{ - DRAIN_RESERVOIR_CMD_PAYLOAD_T payload; - - dgCmdResp[ DG_CMD_START_DRAIN ].commandID = DG_CMD_NONE; - payload.drainToVolumeML = drainToVolMl; - payload.tareLoadCells = tareLoadCell; - payload.rinseConcentrateLines = rinse; - payload.cmd = start; - -// sendDGDrainCommand( &payload ); -} - -/*********************************************************************//** - * @brief - * The cmdDGSampleWater function sends a sample water command message to the DG. - * @details Inputs: none - * @details Outputs: sample water command sent to DG. - * @return none - *************************************************************************/ -void cmdDGSampleWater( SAMPLE_WATER_CMD_T cmd ) -{ -// sendDGSampleWaterCommand( cmd ); -} - -/*********************************************************************//** - * @brief - * The cmdDGParkConcentratePumps function sends a park concentrate pumps command - * message to the DG. - * @details Inputs: none - * @details Outputs: park concentrate pumps command sent to DG. - * @return none - *************************************************************************/ -void cmdDGParkConcentratePumps( void ) -{ - dgCmdResp[ DG_CMD_PARK_CONCENTRATE_PUMPS ].commandID = DG_CMD_NONE; - -// sendDGParkConcentratePumpsCommand( ); -} - -/*********************************************************************//** - * @brief - * The cmdStartDGFlush function sends a start flush command message to - * the DG. - * @details Inputs: none - * @details Outputs: start flush mode command sent to DG. - * @return none - *************************************************************************/ -void cmdStartDGFlush( void ) -{ - BOOL start = TRUE; - - dgCmdResp[ DG_CMD_START_FLUSH ].commandID = DG_CMD_NONE; - -// sendDGStartFlushModeCommand( start ); -} - -/*********************************************************************//** - * @brief - * The cmdStopDGFlush function sends a stop flush command message to - * the DG. - * @details Inputs: none - * @details Outputs: stop flush mode command sent to DG. - * @return none - *************************************************************************/ -void cmdStopDGFlush( void ) -{ - BOOL start = FALSE; - - dgCmdResp[ DG_CMD_STOP_FLUSH ].commandID = DG_CMD_NONE; - -// sendDGStartFlushModeCommand( start ); -} - -/*********************************************************************//** - * @brief - * The cmdStartDGHeatDisinfect function sends a start heat disinfect - * command message to the DG. - * @details Inputs: none - * @details Outputs: start heat disinfect mode command sent to DG. - * @return none - *************************************************************************/ -void cmdStartDGHeatDisinfect( void ) -{ - BOOL start = TRUE; - - dgCmdResp[ DG_CMD_START_HEAT_DISINFECT ].commandID = DG_CMD_NONE; - -// sendDGStartHeatDisinfectModeCommand( start ); -} - -/*********************************************************************//** - * @brief - * The cmdStopDGHeatDisinfect function sends a stop heat disinfect - * command message to the DG. - * @details Inputs: none - * @details Outputs: stop heat disinfect mode command sent to DG. - * @return none - *************************************************************************/ -void cmdStopDGHeatDisinfect( void ) -{ - BOOL start = FALSE; - - dgCmdResp[ DG_CMD_STOP_HEAT_DISINFECT ].commandID = DG_CMD_NONE; - -// sendDGStartHeatDisinfectModeCommand( start ); -} - -/*********************************************************************//** - * @brief - * The cmdStartDGChemicalDisinfect function sends a start chemical disinfect - * command message to the DG. - * @details Inputs: none - * @details Outputs: start chemical disinfect mode command sent to DG. - * @return none - *************************************************************************/ -void cmdStartDGChemicalDisinfect( void ) -{ - BOOL start = TRUE; - - dgCmdResp[ DG_CMD_START_CHEM_DISINFECT ].commandID = DG_CMD_NONE; -// sendDGStartChemicalDisinfectModeCommand( start ); -} - -/*********************************************************************//** - * @brief - * The cmdStopDGChemicalDisinfect function sends a stop chemical disinfect - * command message to the DG. - * @details Inputs: none - * @details Outputs: stop chemical disinfect mode command sent to DG. - * @return none - *************************************************************************/ -void cmdStopDGChemicalDisinfect( void ) -{ - BOOL start = FALSE; - - dgCmdResp[ DG_CMD_STOP_CHEM_DISINFECT ].commandID = DG_CMD_NONE; -// sendDGStartChemicalDisinfectModeCommand( start ); -} - -/*********************************************************************//** - * @brief - * The cmdStartDGChemicalFlushDisinfect function sends a start chemical disinfect - * flush command message to the DG. - * @details Inputs: none - * @details Outputs: start chemical disinfect flush mode command sent to DG. - * @return none - *************************************************************************/ -void cmdStartDGChemicalFlushDisinfect( void ) -{ - BOOL start = TRUE; - - dgCmdResp[ DG_CMD_START_CHEM_DISINFECT_FLUSH ].commandID = DG_CMD_NONE; -// sendDGStartStopChemicalDisinfectFlushModeCommand( start ); -} - -/*********************************************************************//** - * @brief - * The cmdStopDGChemFlushDisinfect function sends a stop chemical disinfect - * flush command message to the DG. - * @details Inputs: none - * @details Outputs: stop chemical disinfect flush mode command sent to DG. - * @return none - *************************************************************************/ -void cmdStopDGChemFlushDisinfect( void ) -{ - BOOL start = FALSE; - - dgCmdResp[ DG_CMD_STOP_CHEM_DISINFECT_FLUSH ].commandID = DG_CMD_NONE; -// sendDGStartStopChemicalDisinfectFlushModeCommand( start ); -} - -/*********************************************************************//** - * @brief - * The cmdStopDGActiveCool function sends a stop active cool command - * message to the DG. - * @details Inputs: none - * @details Outputs: stop active cool mode command sent to DG. - * @return none - *************************************************************************/ -void cmdStopDGActiveCool( void ) -{ - dgCmdResp[ DG_CMD_STOP_ACTIVE_COOL ].commandID = DG_CMD_NONE; -// sendDGStopActiveCoolModeCommand(); -} - -/*********************************************************************//** - * @brief - * The cmdStartDGROPermeateSampleMode function sends an RO permeate sample - * start command message to the DG. - * @details Inputs: none - * @details Outputs: start RO permeate sample mode command sent to DG. - * @return none - *************************************************************************/ -void cmdStartDGROPermeateSampleMode( void ) -{ - BOOL start = TRUE; - - dgCmdResp[ DG_CMD_START_RO_PERMEATE_SAMPLE ].commandID = DG_CMD_NONE; -// sendDGStartStopDGROPermeateSampleModeCommand( start ); -} - -/*********************************************************************//** - * @brief - * The cmdStopDGROPermeateSampleMode function sends an RO permeate sample - * stop command message to the DG. - * @details Inputs: none - * @details Outputs: stop RO permeate sample mode command sent to DG. - * @return none - *************************************************************************/ -void cmdStopDGROPermeateSampleMode( void ) -{ - BOOL start = FALSE; - - dgCmdResp[ DG_CMD_STOP_RO_PERMEATE_SAMPLE ].commandID = DG_CMD_NONE; -// sendDGStartStopDGROPermeateSampleModeCommand( start ); -} - -/*********************************************************************//** - * @brief - * The cmdRequestDGConcentrateRatios function sends a request to DG to receive - * the concentrate ratios. - * @details Inputs: none - * @details Outputs: none - * @return none - *************************************************************************/ -void cmdRequestDGMixingRatios( void ) -{ - dgCmdResp[ DG_CMD_REQUEST_CONC_MIXING_RATIOS ].commandID = DG_CMD_NONE; -// sendDGConcentrateMixingRatiosRequest(); -} - -/*********************************************************************//** - * @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 - * @param dgCmdRespPtr pointer to DG command response data record - * @return none - *************************************************************************/ -void handleDGCommandResponse( DG_CMD_RESPONSE_T *dgCmdRespPtr ) -{ - if ( dgCmdRespPtr->commandID < NUM_OF_DG_COMMANDS ) - { - if ( DG_CMD_NONE != dgCmdRespPtr->commandID ) + if ( DD_CMD_NONE != ddCmdRespPtr->commandID ) { - memcpy( &dgCmdResp[ dgCmdRespPtr->commandID ], dgCmdRespPtr, sizeof( DG_CMD_RESPONSE_T ) ); + memcpy( &ddCmdResp[ ddCmdRespPtr->commandID ], ddCmdRespPtr, sizeof( DD_CMD_RESPONSE_T ) ); } } else { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_DD_INVALID_COMMAND_RESPONSE_ID, dgCmdRespPtr->commandID ); + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_DD_INVALID_COMMAND_RESPONSE_ID, ddCmdRespPtr->commandID ); } - if ( TRUE == dgCmdRespPtr->rejected ) + if ( TRUE == ddCmdRespPtr->rejected ) { - switch ( dgCmdRespPtr->rejectCode ) + switch ( ddCmdRespPtr->rejectCode ) { - case DG_CMD_REQUEST_REJECT_REASON_INVALID_PARAMETER: -// SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_DG_COMMAND_INVALID_PARAMETER_FAULT, dgCmdRespPtr->commandID ); + case DD_CMD_REQUEST_REJECT_REASON_INVALID_PARAMETER: +// SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_DG_COMMAND_INVALID_PARAMETER_FAULT, ddCmdRespPtr->commandID ); break; - case DG_CMD_REQUEST_REJECT_REASON_NONE: - case DG_CMD_REQUEST_REJECT_REASON_INVALID_MODE: + case DD_CMD_REQUEST_REJECT_REASON_NONE: + case DD_CMD_REQUEST_REJECT_REASON_INVALID_MODE: default: // Our state machines will detect and handle DG mode out of sync // TODO Consider a generic handler for all state machine @@ -922,136 +239,54 @@ /*********************************************************************//** * @brief - * The getDGCommandResponse function gets the latest command response from DG. - * @details Inputs: dgCmdResp + * The getDDCommandResponse function gets the latest command response from DD. + * @details Inputs: ddCmdResp * @details Outputs: none * @param commandID id of specific interested command response - * @param cmdRespPtr pointer to data record to copy DG command response to + * @param cmdRespPtr pointer to data record to copy DD command response to * @return TRUE if a specific command response has been received, otherwise FALSE *************************************************************************/ -BOOL getDGCommandResponse( U32 commandID, DG_CMD_RESPONSE_T *cmdRespPtr ) +BOOL getDDCommandResponse( U32 commandID, DD_CMD_RESPONSE_T *cmdRespPtr ) { BOOL hasCommandResp = FALSE; - if ( commandID == dgCmdResp[ commandID ].commandID ) + if ( commandID == ddCmdResp[ commandID ].commandID ) { hasCommandResp = TRUE; - memcpy( cmdRespPtr, &dgCmdResp[ commandID ], sizeof( DG_CMD_RESPONSE_T ) ); + memcpy( cmdRespPtr, &ddCmdResp[ commandID ], sizeof( DD_CMD_RESPONSE_T ) ); } return hasCommandResp; } /*********************************************************************//** * @brief - * The checkDialysateTemperature function checks the dialysate temperature - * reported by DG and alarm if temperature is out of range. - * @details Inputs: dgTrimmerTempSet, dgDialysateTemp - * @details Outputs: none + * The checkDDRestart function checks to see if DD has restarted after started + * by TD and triggers appropriate alarm. + * @details Inputs: ddStartCommandSent, ddStarted, ddCurrentOpMode + * @details Outputs: ddStartCommandSent, ddStarted, triggers a fault alarm if DD restarted * @return none *************************************************************************/ -void checkDialysateTemperature( void ) +static void checkDDRestart( void ) { - BOOL isTDiTempAboveHighSafety = ( dgDialysateTemp >= DIALYSATE_TEMP_UPPER_MAX_SAFETY_LIMIT_C ? TRUE : FALSE ); - BOOL isTDiTempAboveLowSafety = ( dgDialysateTemp > DIALYSATE_TEMP_UPPER_SAFETY_LIMIT_C ? TRUE : FALSE ); - BOOL isTDITempBelowLowSafety = ( dgDialysateTemp < DIALYSATE_TEMP_LOWER_SAFETY_LIMIT_C ? TRUE : FALSE ); - F32 TDiHigh = dgTrimmerTempSet + DIALYSATE_TEMP_OUT_OF_TARGET_TOL_C; - BOOL isTDiTempAboveDialysateTarget = ( dgDialysateTemp >= TDiHigh ? TRUE : FALSE ); - F32 TDiLow = dgTrimmerTempSet - DIALYSATE_TEMP_OUT_OF_TARGET_TOL_C; - BOOL isTDiTempBelowDialysateTarget = ( dgDialysateTemp <= TDiLow ? TRUE : FALSE ); - BOOL isTempBelowTrigger = (BOOL)( isTDITempBelowLowSafety || isTDiTempBelowDialysateTarget ); - BOOL isTempAboveTrigger = (BOOL)( isTDiTempAboveLowSafety || isTDiTempAboveDialysateTarget ); + if ( ( ddStartCommandSent == TRUE ) && ( DD_MODE_GEND == ddCurrentOpMode ) ) + { + ddStartCommandSent = FALSE; + ddStarted = TRUE; + } -// if ( getTargetDialInFlowRate() > 0 ) +// if ( TRUE == ddStarted ) // { -// // check clear condition first -// if ( TRUE == isAlarmActive( ALARM_ID_HD_DIALYSATE_TEMP_ABOVE_SAFETY_TEMP ) ) +// if ( ( DG_MODE_FAUL != ddCurrentOpMode ) && ( DG_MODE_GEND != ddCurrentOpMode ) && +// ( DG_MODE_FILL != ddCurrentOpMode ) && ( DG_MODE_DRAI != ddCurrentOpMode ) ) // { -// isTDiTempAboveHighSafety = ( dgDialysateTemp <= ( dgTrimmerTempSet + DIALYSATE_TEMP_OUT_OF_TARGET_CLEAR_TOL_C ) ? FALSE : TRUE ); +// activateAlarmNoData( ALARM_ID_HD_DG_RESTARTED_FAULT ); +// ddStarted = FALSE; // do not want to re-trigger alarm after alarm is cleared // } -// checkPersistentAlarm(ALARM_ID_HD_DIALYSATE_TEMP_ABOVE_SAFETY_TEMP, isTDiTempAboveHighSafety, dgDialysateTemp, dgTrimmerTempSet ); -// -// if ( TRUE == isAlarmActive( ALARM_ID_HD_DIALYSATE_TEMP_ABOVE_TARGET_TEMP ) ) -// { -// isTempAboveTrigger = ( dgDialysateTemp <= ( dgTrimmerTempSet + DIALYSATE_TEMP_OUT_OF_TARGET_CLEAR_TOL_C ) ? FALSE : TRUE ); -// } -// checkPersistentAlarm(ALARM_ID_HD_DIALYSATE_TEMP_ABOVE_TARGET_TEMP, isTempAboveTrigger, dgDialysateTemp, dgTrimmerTempSet ); -// -// if ( TRUE == isAlarmActive( ALARM_ID_HD_DIALYSATE_TEMP_BELOW_TARGET_TEMP ) ) -// { -// isTempBelowTrigger = ( dgDialysateTemp >= ( dgTrimmerTempSet - DIALYSATE_TEMP_OUT_OF_TARGET_CLEAR_TOL_C ) ? FALSE : TRUE ); -// } -// checkPersistentAlarm(ALARM_ID_HD_DIALYSATE_TEMP_BELOW_TARGET_TEMP, isTempBelowTrigger, dgDialysateTemp, dgTrimmerTempSet ); // } -// else -// { -// checkPersistentAlarm(ALARM_ID_HD_DIALYSATE_TEMP_ABOVE_SAFETY_TEMP, FALSE, dgDialysateTemp, dgTrimmerTempSet ); -// checkPersistentAlarm(ALARM_ID_HD_DIALYSATE_TEMP_ABOVE_TARGET_TEMP, FALSE, dgDialysateTemp, dgTrimmerTempSet ); -// checkPersistentAlarm(ALARM_ID_HD_DIALYSATE_TEMP_BELOW_TARGET_TEMP, FALSE, dgDialysateTemp, dgTrimmerTempSet ); -// } } -// ********** private functions ********** -/*********************************************************************//** - * @brief - * The checkDGRestart function checks to see if DG has restarted after started - * by HD and triggers appropriate alarm. - * @details Inputs: dgStartCommandSent, dgStarted, dgCurrentOpMode - * @details Outputs: dgStartCommandSent, dgStarted, triggers a fault alarm if DG restarted - * @return none - *************************************************************************/ -static void checkDGRestart( void ) -{ - if ( ( dgStartCommandSent == TRUE ) && ( DG_MODE_GENE == dgCurrentOpMode ) ) - { - dgStartCommandSent = FALSE; - dgStarted = TRUE; - } - - if ( TRUE == dgStarted ) - { - if ( ( DG_MODE_FAUL != dgCurrentOpMode ) && ( DG_MODE_GENE != dgCurrentOpMode ) && - ( DG_MODE_FILL != dgCurrentOpMode ) && ( DG_MODE_DRAI != dgCurrentOpMode ) ) - { -// activateAlarmNoData( ALARM_ID_HD_DG_RESTARTED_FAULT ); - dgStarted = FALSE; // do not want to re-trigger alarm after alarm is cleared - } - } -} - -/*********************************************************************//** - * @brief - * The checkDGTrimmerHeaterStatus function checks to see the status of the - * trimmer heater and set them according to the status of the trimmer heater flag. - * @details Inputs: dgTrimmerHeaterOn, dgHeatersData - * @details Outputs: none - * @return none - *************************************************************************/ -static void checkDGTrimmerHeaterStatus( void ) -{ - U32 trimmerState = dgHeatersData.trimmerHeaterState; - DG_OP_MODE_T dgOp = getDGOpMode(); - -// if ( getCPLDACPowerLossDetected() != TRUE ) - { - if ( ( DG_MODE_GENE == dgOp ) || ( DG_MODE_FILL == dgOp ) || ( DG_MODE_DRAI == dgOp ) ) - { - // In heat disinfect and chemical disinfect, the trimmer heater is controlled by the DG itself so no commands from HD should be sent - // regarding the trimmer heater. - if ( ( TRUE == dgTrimmerHeaterOn ) && ( HEATER_EXEC_STATE_OFF == trimmerState ) ) - { - cmdStartDGTrimmerHeater(); - } - else if ( ( FALSE == dgTrimmerHeaterOn ) && ( trimmerState != HEATER_EXEC_STATE_OFF ) ) - { - cmdStopDGTrimmerHeater(); - } - } - } -} - - /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/