Index: firmware/App/Controllers/DGInterface.c =================================================================== diff -u -r766708fceb0bdf1af8c7897df29d4f5036bfd3db -r3e24cbff2cbf0ce9af2e998e6a9a2ed4733bbe27 --- firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision 766708fceb0bdf1af8c7897df29d4f5036bfd3db) +++ firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision 3e24cbff2cbf0ce9af2e998e6a9a2ed4733bbe27) @@ -14,8 +14,9 @@ * @date (original) 08-Apr-2020 * ***************************************************************************/ - + #include "DialInFlow.h" +#include "DGDefs.h" #include "ModeTreatment.h" #include "OperationModes.h" #include "SystemCommMessages.h" @@ -105,7 +106,9 @@ static U32 dgReservoirDrainVolumeTargetSet = 0; ///< Drain-to volume commanded. static U32 resUseTimer = 0; ///< Used to track time pumping from active reservoir (for volume used calculation). static F32 resUseVolumeMl = 0.0; ///< Accumulated volume used from active reservoir. -static BOOL resHasBeenTared[ NUM_OF_DG_RESERVOIRS ]; ///< Flags indicate whether the reservoir has been tared for this treatment. + +// DG command response +static DG_CMD_RESPONSE_T dgCmdResp; ///< Used to keep the latest DG command response. // ********** private function prototypes ********** @@ -152,6 +155,11 @@ lgLoadCellReadings[ i ][ j ] = 0.0; } } + + dgCmdResp.commandID = DG_CMD_NONE; + dgCmdResp.rejected = TRUE; + dgCmdResp.rejectCode = DG_CMD_REQUEST_REJECT_REASON_NONE; + smLoadCellReadingsIdx = 0; smLoadCellReadingsTotal[ DG_RESERVOIR_1 ] = 0.0; smLoadCellReadingsTotal[ DG_RESERVOIR_2 ] = 0.0; @@ -173,21 +181,6 @@ // TODO - make sure DG sensor/state data is coming in timely manner (e.g. load cells s/b every 100 ms) } -/*********************************************************************//** - * @brief - * The initPreTreatmentReservoirMgmt function initializes the pre-treatment - * reservoir management state machine. - * @details Inputs: none - * @details Outputs: pre-treatment reservoir management state machine initialized. - * @return none - *************************************************************************/ -void initPreTreatmentReservoirMgmt( void ) -{ - // TODO - currentPreTrtResMgmtState = TREATMENT_RESERVOIR_MGMT_START_STATE; - resMgmtTimer = 0; - resHasBeenTared[ DG_RESERVOIR_1 ] = FALSE; - resHasBeenTared[ DG_RESERVOIR_2 ] = FALSE; -} /*********************************************************************//** * @brief @@ -489,7 +482,7 @@ /*********************************************************************//** * @brief * The getReservoirWeightSmallFilter function gets the load cell weight - * of the given reservoir after large (8 sample) filter applied. + * of the given reservoir after small (8 sample) filter applied. * @details Inputs: lgFilteredReservoirWeightInGrams[] * @details Outputs: none * @param resID ID of reservoir to get filtered weight for @@ -710,7 +703,7 @@ { dgPrimaryTempSet = primaryHtrTemp; dgTrimmerTempSet = trimmerHtrTemp; - sendDialysateTempTargetsToDG( primaryHtrTemp, trimmerHtrTemp ); + sendDialysateTempTargetsToDG( dgPrimaryTempSet, dgTrimmerTempSet ); } /*********************************************************************//** @@ -751,8 +744,9 @@ *************************************************************************/ void cmdStartDGTrimmerHeater( void ) { - dgTrimmerHeaterOn = TRUE; - sendDGStartStopTrimmerHeaterCommand( START_DG_CMD ); + dgTrimmerHeaterOn = TRUE; + dgCmdResp.commandID = DG_CMD_NONE; + sendDGStartStopTrimmerHeaterCommand( START_DG_CMD, dgTrimmerTempSet ); } /*********************************************************************//** @@ -765,8 +759,9 @@ *************************************************************************/ void cmdStopDGTrimmerHeater( void ) { - dgTrimmerHeaterOn = FALSE; - sendDGStartStopTrimmerHeaterCommand( STOP_DG_CMD ); + dgTrimmerHeaterOn = FALSE; + dgCmdResp.commandID = DG_CMD_NONE; + sendDGStartStopTrimmerHeaterCommand( STOP_DG_CMD, 0 ); } /*********************************************************************//** @@ -782,7 +777,8 @@ { if ( resID < NUM_OF_DG_RESERVOIRS ) { - dgActiveReservoirSet = resID; + dgActiveReservoirSet = resID; + dgCmdResp.commandID = DG_CMD_NONE; sendDGSwitchReservoirCommand( (U32)resID ); } else @@ -800,7 +796,8 @@ * @return none *************************************************************************/ void cmdStartDGFill( U32 fillToVolMl ) -{ +{ + dgCmdResp.commandID = DG_CMD_NONE; dgReservoirFillVolumeTargetSet = fillToVolMl; sendDGFillCommand( fillToVolMl ); } @@ -818,6 +815,7 @@ { DRAIN_RESERVOIR_CMD_PAYLOAD_T payload; + dgCmdResp.commandID = DG_CMD_NONE; payload.drainToVolumeML = drainToVolMl; payload.tareLoadCells = tareLoadCell; dgReservoirDrainVolumeTargetSet = drainToVolMl; @@ -837,7 +835,50 @@ sendDGSampleWaterCommand(); } +/*********************************************************************//** + * @brief + * The handleDGCommandResponse function processes the latest DG command response. + * @details Inputs: none + * @details Outputs: process command response from DG + * @param cmdRespPtr pointer to DG command response data record + * @return none + *************************************************************************/ +void handleDGCommandResponse( U08 *cmdRespPtr ) +{ + memcpy( &dgCmdResp, cmdRespPtr, sizeof( DG_CMD_RESPONSE_T ) ); + if ( TRUE == dgCmdResp.rejected ) + { + switch ( dgCmdResp.rejectCode ) + { + case DG_CMD_REQUEST_REJECT_REASON_INVALID_PARAMETER: + activateAlarmNoData( ALARM_ID_DG_COMMAND_INVALID_PARAMETER_FAULT ); + break; + + case DG_CMD_REQUEST_REJECT_REASON_NONE: + case DG_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 + break; + } + } +} + +/*********************************************************************//** + * @brief + * The getDGCommandResponse function gets the latest command response from DG. + * @details Inputs: dgCmdResp + * @details Outputs: none + * @param cmdRespPtr pointer to data record to copy DG command response to + * @return none + *************************************************************************/ +void getDGCommandResponse( DG_CMD_RESPONSE_T *cmdRespPtr ) +{ + memcpy( &cmdRespPtr, &dgCmdResp, sizeof( DG_CMD_RESPONSE_T ) ); +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/