Index: firmware/App/Controllers/DGInterface.c =================================================================== diff -u -r968f9908941a8f8ceeacdb6aa40655abf54c1ef4 -rbd738c0705e8640d2c532ecece876aaa3496ee32 --- firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision 968f9908941a8f8ceeacdb6aa40655abf54c1ef4) +++ firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision bd738c0705e8640d2c532ecece876aaa3496ee32) @@ -29,12 +29,22 @@ // ********** private data ********** +// DG mode static DG_OP_MODE_T dgCurrentOpMode = DG_MODE_INIT; + +// DG sensor data static F32 dgPressures[ NUM_OF_DG_PRESSURE_SENSORS ]; +static F32 dgPrimaryTempSet = 0.0; +static F32 dgPrimaryTemp = 0.0; +static F32 dgTrimmerTempSet = 0.0; +static F32 dgTrimmerTemp = 0.0; + +// DG pumps data static F32 dgROPumpFlowRateMlMin = 0.0; static U32 dgROPumpPressureSetPtPSI = 0; static U32 dgDrainPumpSpeedSetPtRPM = 0; +// reservoir data static DG_RESERVOIR_ID_T dgActiveReservoir = DG_RESERVOIR_2; static DG_RESERVOIR_ID_T dgActiveReservoirSet = DG_RESERVOIR_2; static U32 dgReservoirFillVolumeTarget = 0; @@ -58,6 +68,14 @@ // TODO - anything to initialize? } +/*********************************************************************//** + * @brief + * The getDGOpMode function gets the current DG operating mode. + * @details + * Inputs : dgCurrentOpMode + * Outputs : none + * @return Current DG operating mode. + *************************************************************************/ DG_OP_MODE_T getDGOpMode( void ) { DG_OP_MODE_T result = dgCurrentOpMode; @@ -70,7 +88,7 @@ * The getDGPressure function gets the latest pressure reported by the DG \n * for a given pressure sensor. * @details - * Inputs : none + * Inputs : dgPressures[] * Outputs : none * @param sensorID : pressure sensor we are getting reading for. * @return Latest pressure reading reported by DG for the given sensor. @@ -91,80 +109,258 @@ return result; } +/*********************************************************************//** + * @brief + * The getDGROPumpPressureSetPt function gets the latest RO pump \n + * pressure set point reported by the DG. + * @details + * Inputs : dgROPumpPressureSetPtPSI + * Outputs : none + * @return Latest RO pump pressure set point reported by DG. + *************************************************************************/ U32 getDGROPumpPressureSetPt( void ) { U32 result = dgROPumpPressureSetPtPSI; return result; } +/*********************************************************************//** + * @brief + * The getDGROPumpFlowRateMlMin function gets the latest RO pump flow \n + * rate reported by the DG. + * @details + * Inputs : dgROPumpFlowRateMlMin + * Outputs : none + * @return Latest RO pump flow rate reported by DG. + *************************************************************************/ F32 getDGROPumpFlowRateMlMin( void ) { F32 result = dgROPumpFlowRateMlMin; return result; } +/*********************************************************************//** + * @brief + * The getDGDrainPumpRPMSetPt function gets the latest drain pump RPM \n + * set point reported by the DG. + * @details + * Inputs : dgDrainPumpSpeedSetPtRPM + * Outputs : none + * @return Latest drain pump RPM set point reported by DG. + *************************************************************************/ U32 getDGDrainPumpRPMSetPt( void ) { U32 result = dgDrainPumpSpeedSetPtRPM; return result; } +/*********************************************************************//** + * @brief + * The setDGOpMode function sets the latest DG operating mode reported by \n + * the DG. + * @details + * Inputs : none + * Outputs : dgCurrentOpMode + * @param opMode : operating mode reported by DG. + * @return none + *************************************************************************/ void setDGOpMode( U32 opMode ) { + if ( opMode < NUM_OF_DG_MODES ) + { + dgCurrentOpMode = (DG_OP_MODE_T)opMode; + } +} +/*********************************************************************//** + * @brief + * The setDGDialysateTemperatures function sets the latest temperature data \n + * reported by the DG. + * @details + * Inputs : none + * Outputs : dgPrimaryTemp, dgTrimmerTemp + * @param primaryHtrTemp : Primary heater temperature reported by DG. + * @param trimmerHtrTemp : Trimmer heater temperature reported by DG. + * @return none + *************************************************************************/ +void setDGDialysateTemperatures( F32 primaryHtrTemp, F32 trimmerHtrTemp ) +{ + dgPrimaryTemp = primaryHtrTemp; + dgTrimmerTemp = trimmerHtrTemp; } +/*********************************************************************//** + * @brief + * The setDGReservoirsData function sets the latest reservoir data \n + * reported by the DG. + * @details + * Inputs : none + * Outputs : dgActiveReservoir, dgReservoirFillVolumeTarget, dgReservoirDrainVolumeTarget + * @param resID : ID of active reservoir. + * @param fillVol : Reservoir fill to volume reported by DG. + * @param drainVol : Reservoir drain to volume reported by DG. + * @return none + *************************************************************************/ void setDGReservoirsData( U32 resID, U32 fillVol, U32 drainVol ) { - + if ( resID < NUM_OF_DG_RESERVOIRS ) + { + dgActiveReservoir = resID; + dgReservoirFillVolumeTarget = fillVol; + dgReservoirDrainVolumeTarget = drainVol; + } } +/*********************************************************************//** + * @brief + * The setDGPressures function sets the latest pressures reported by the DG. + * @details + * Inputs : none + * Outputs : dgPressures[] + * @param roIn : latest RO pump inlet pressure reported by DG. + * @param roOut : latest RO pump outlet pressure reported by DG. + * @param drainIn : latest drain pump inlet pressure reported by DG. + * @param drainOut : latest drain pump outlet pressure reported by DG. + * @return none + *************************************************************************/ void setDGPressures( F32 roIn, F32 roOut, F32 drainIn, F32 drainOut ) { - + dgPressures[ DG_PRESSURE_SENSOR_RO_PUMP_INLET ] = roIn; + dgPressures[ DG_PRESSURE_SENSOR_RO_PUMP_OUTLET ] = roOut; + dgPressures[ DG_PRESSURE_SENSOR_DRAIN_PUMP_INLET ] = drainIn; + dgPressures[ DG_PRESSURE_SENSOR_DRAIN_PUMP_OUTLET ] = drainOut; } +/*********************************************************************//** + * @brief + * The setDGROPumpData function sets the latest RO pump data reported by the DG. + * @details + * Inputs : none + * Outputs : dgROPumpPressureSetPtPSI, dgROPumpFlowRateMlMin + * @param presSetPt : latest RO pump pressure set point reported by DG. + * @param flowRate : latest RO pump flow rate reported by DG. + * @return none + *************************************************************************/ void setDGROPumpData( U32 presSetPt, F32 flowRate ) { - + dgROPumpPressureSetPtPSI = presSetPt; + dgROPumpFlowRateMlMin = flowRate; } +/*********************************************************************//** + * @brief + * The setDGDrainPumpData function sets the latest drain pump data reported by the DG. + * @details + * Inputs : none + * Outputs : dgDrainPumpSpeedSetPtRPM + * @param rpmSetPt : latest drain pump RPM set point reported by DG. + * @return none + *************************************************************************/ void setDGDrainPumpData( U32 rpmSetPt ) { - + dgDrainPumpSpeedSetPtRPM = rpmSetPt; } -void cmdSetDGDialysateTargetTemps( U32 primaryHtr, U32 trimmerHtr ) +/*********************************************************************//** + * @brief + * The cmdSetDGDialysateTargetTemps function sends a target dialysate \n + * temperature command message to the DG. + * @details + * Inputs : none + * Outputs : dgPrimaryTempSet, dgTrimmerTempSet + * @param primaryHtrTemp : commanded target dialysate temperature for the primary heater. + * @param trimmerHtrTemp : commanded target dialysate temperature for the trimmer heater. + * @return none + *************************************************************************/ +void cmdSetDGDialysateTargetTemps( U32 primaryHtrTemp, U32 trimmerHtrTemp ) { - + dgPrimaryTempSet = primaryHtrTemp; + dgTrimmerTempSet = trimmerHtrTemp; + // TODO - send command to DG } +/*********************************************************************//** + * @brief + * The cmdStartDG function sends a start command to the DG. DG will transition \n + * from standby to re-circulate mode and start producing warm, pure water. + * @details + * Inputs : none + * Outputs : start DG command sent + * @return none + *************************************************************************/ void cmdStartDG( void ) { - + // TODO - send command to DG } +/*********************************************************************//** + * @brief + * The cmdStopDG function sends a stop command to the DG. DG will transition \n + * from re-circulate mode to standby mode. Pumps and heater go off. + * @details + * Inputs : none + * Outputs : stop DG command sent + * @return none + *************************************************************************/ void cmdStopDG( void ) { - + // TODO - send command to DG } +/*********************************************************************//** + * @brief + * The cmdSetDGActiveReservoir function sends a set active reservoir command \n + * message to the DG. + * @details + * Inputs : none + * Outputs : set active reservoir command sent to DG. + * @param resID : ID of reservoir to set as active (reservoir for HD to draw from). + * @return none + *************************************************************************/ void cmdSetDGActiveReservoir( DG_RESERVOIR_ID_T resID ) { - + if ( resID < NUM_OF_DG_RESERVOIRS ) + { + dgActiveReservoirSet = resID; + // TODO - send command to DG + } + else + { + // TODO - s/w fault + } } +/*********************************************************************//** + * @brief + * The cmdStartDGFill function sends a fill command message to the DG. + * @details + * Inputs : none + * Outputs : fill command sent to DG. + * @param fillToVolMl : volume (in mL) to fill inactive reservoir to. + * @return none + *************************************************************************/ void cmdStartDGFill( U32 fillToVolMl ) { - + dgReservoirFillVolumeTargetSet = fillToVolMl; + // TODO - send command to DG } +/*********************************************************************//** + * @brief + * The cmdStartDGDrain function sends a drain command message to the DG. + * @details + * Inputs : none + * Outputs : drain command sent to DG. + * @param drainToVolMl : volume (in mL) to drain inactive reservoir to. + * @return none + *************************************************************************/ void cmdStartDGDrain( U32 drainToVolMl ) { - + dgReservoirDrainVolumeTargetSet = drainToVolMl; + // TODO - send command to DG } /**@}*/ Index: firmware/App/Controllers/DGInterface.h =================================================================== diff -u -r968f9908941a8f8ceeacdb6aa40655abf54c1ef4 -rbd738c0705e8640d2c532ecece876aaa3496ee32 --- firmware/App/Controllers/DGInterface.h (.../DGInterface.h) (revision 968f9908941a8f8ceeacdb6aa40655abf54c1ef4) +++ firmware/App/Controllers/DGInterface.h (.../DGInterface.h) (revision bd738c0705e8640d2c532ecece876aaa3496ee32) @@ -78,12 +78,13 @@ U32 getDGDrainPumpRPMSetPt( void ); void setDGOpMode( U32 opMode ); +void setDGDialysateTemperatures( F32 primaryHtrTemp, F32 trimmerHtrTemp ); void setDGReservoirsData( U32 resID, U32 fillVol, U32 drainVol ); void setDGPressures( F32 roIn, F32 roOut, F32 drainIn, F32 drainOut ); void setDGROPumpData( U32 presSetPt, F32 flowRate ); void setDGDrainPumpData( U32 rpmSetPt ); -void cmdSetDGDialysateTargetTemps( U32 primaryHtr, U32 trimmerHtr ); +void cmdSetDGDialysateTargetTemps( U32 primaryHtrTemp, U32 trimmerHtrTemp ); void cmdStartDG( void ); void cmdStopDG( void ); void cmdSetDGActiveReservoir( DG_RESERVOIR_ID_T resID ); Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r968f9908941a8f8ceeacdb6aa40655abf54c1ef4 -rbd738c0705e8640d2c532ecece876aaa3496ee32 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 968f9908941a8f8ceeacdb6aa40655abf54c1ef4) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision bd738c0705e8640d2c532ecece876aaa3496ee32) @@ -287,7 +287,7 @@ } // *********************************************************************** -// ********************* MSG_ID_OFF_BUTTON_PRESS ************************* +// ***************** Message Sending Helper Functions ******************** // *********************************************************************** /************************************************************************* @@ -319,225 +319,7 @@ } /************************************************************************* - * @brief handleDGCheckIn - * The handleDGCheckIn function handles a check-in from the DG. - * @details - * Inputs : none - * Outputs : check in the DG with the SystemComm module. - * @param message : a pointer to the message to handle - * @return none - *************************************************************************/ -void handleDGCheckIn( MESSAGE_T *message ) -{ - checkInFromDG(); -} - -/************************************************************************* - * @brief handleUICheckIn - * The handleUICheckIn function handles a check-in from the UI. - * @details - * Inputs : none - * Outputs : check in the UI with the SystemComm module. - * @param message : a pointer to the message to handle - * @return none - *************************************************************************/ -void handleUICheckIn( MESSAGE_T *message ) -{ - checkInFromUI(); -} - -/************************************************************************* - * @brief handleOffButtonConfirmMsgFromUI - * The handleOffButtonConfirmMsgFromUI function handles a response to an \n - * off button message to the UI. - * @details - * Inputs : none - * Outputs : message handled - * @param message : a pointer to the message to handle - * @return none - *************************************************************************/ -void handleOffButtonConfirmMsgFromUI( MESSAGE_T *message ) -{ - OFF_BUTTON_MESSAGE_FROM_UI_PAYLOAD_T payload; - - if ( message->hdr.payloadLen == sizeof(OFF_BUTTON_MESSAGE_FROM_UI_PAYLOAD_T) ) - { - memcpy( &payload, message->payload, sizeof(OFF_BUTTON_MESSAGE_FROM_UI_PAYLOAD_T) ); - userConfirmOffButton( payload.confirmed ); - } -} - -/************************************************************************* * @brief - * The handleLoadCellReadingsFromDG function handles a load cell readings \n - * broadcast message from the DG. - * @details - * Inputs : none - * Outputs : message handled - * @param message : a pointer to the message to handle - * @return none - *************************************************************************/ -void handleLoadCellReadingsFromDG( MESSAGE_T *message ) -{ - BOOL result = FALSE; - - if ( message->hdr.payloadLen == sizeof(LOAD_CELL_READINGS_PAYLOAD_T) ) - { - LOAD_CELL_READINGS_PAYLOAD_T payload; - - memcpy( &payload, message->payload, sizeof(LOAD_CELL_READINGS_PAYLOAD_T) ); - result = setNewLoadCellReadings( payload.res1PrimaryLoadCell, payload.res1BackupLoadCell, payload.res2PrimaryLoadCell, payload.res2BackupLoadCell ); - } - // TODO - what to do if invalid payload length? -} - -/************************************************************************* - * @brief - * The handleROPumpData function handles an RO pump data broadcast \n - * message from the DG. - * @details - * Inputs : none - * Outputs : message handled - * @param message : a pointer to the message to handle - * @return none - *************************************************************************/ -void handleROPumpData( MESSAGE_T *message ) -{ - if ( message->hdr.payloadLen == sizeof(DG_RO_PUMP_DATA_PAYLOAD_T) ) - { - DG_RO_PUMP_DATA_PAYLOAD_T payload; - - memcpy( &payload, message->payload, sizeof(DG_RO_PUMP_DATA_PAYLOAD_T) ); - setDGROPumpData( payload.setPtPSI, payload.measFlowRateMlMin ); - } - // TODO - what to do if invalid payload length? -} - -/************************************************************************* - * @brief - * The handleDrainPumpData function handles a drain pump broadcast \n - * message from the DG. - * @details - * Inputs : none - * Outputs : message handled - * @param message : a pointer to the message to handle - * @return none - *************************************************************************/ -void handleDrainPumpData( MESSAGE_T *message ) -{ - if ( message->hdr.payloadLen == sizeof(DG_DRAIN_PUMP_DATA_PAYLOAD_T) ) - { - DG_DRAIN_PUMP_DATA_PAYLOAD_T payload; - - memcpy( &payload, message->payload, sizeof(DG_DRAIN_PUMP_DATA_PAYLOAD_T) ); - setDGDrainPumpData( payload.setPtRPM ); - } - // TODO - what to do if invalid payload length? -} - -/************************************************************************* - * @brief - * The handleDGPressuresData function handles a DG pressure sensor readings \n - * broadcast message from the DG. - * @details - * Inputs : none - * Outputs : message handled - * @param message : a pointer to the message to handle - * @return none - *************************************************************************/ -void handleDGPressuresData( MESSAGE_T *message ) -{ - if ( message->hdr.payloadLen == sizeof(DG_PRESSURES_DATA_PAYLOAD_T) ) - { - DG_PRESSURES_DATA_PAYLOAD_T payload; - - memcpy( &payload, message->payload, sizeof(DG_PRESSURES_DATA_PAYLOAD_T) ); - setDGPressures( payload.roInPSI, payload.roOutPSI, payload.drainInPSI, payload.drainOutPSI ); - } - // TODO - what to do if invalid payload length? -} - -/************************************************************************* - * @brief - * The handleDGReservoirData function handles a reservoir data broadcast \n - * message from the DG. - * @details - * Inputs : none - * Outputs : message handled - * @param message : a pointer to the message to handle - * @return none - *************************************************************************/ -void handleDGReservoirData( MESSAGE_T *message ) -{ - if ( message->hdr.payloadLen == sizeof(DG_RESERVOIRS_DATA_PAYLOAD_T) ) - { - DG_RESERVOIRS_DATA_PAYLOAD_T payload; - - memcpy( &payload, message->payload, sizeof(DG_RESERVOIRS_DATA_PAYLOAD_T) ); - setDGReservoirsData( payload.resID, payload.setFillToVolumeMl, payload.setDrainToVolumeMl ); - } - // TODO - what to do if invalid payload length? -} - -/************************************************************************* - * @brief - * The handleUFPauseResumeRequest function handles a ultrafiltration pause \n - * or resume request message from the UI. - * @details - * Inputs : none - * Outputs : message handled - * @param message : a pointer to the message to handle - * @return none - *************************************************************************/ -void handleUFPauseResumeRequest( MESSAGE_T *message ) -{ - BOOL result = FALSE; - - if ( message->hdr.payloadLen == sizeof(U32) ) - { - U32 cmd; - - memcpy( &cmd, message->payload, sizeof(U32) ); - if ( UF_CMD_PAUSE == cmd ) - { - result = pauseUF(); - } - else if ( UF_CMD_RESUME == cmd ) - { - result = resumeUF(); - } - } - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, result ); -} - -/************************************************************************* - * @brief - * The handleChangeUFSettingsRequest function handles a ultrafiltration \n - * change settings request message from the UI. - * @details - * Inputs : none - * Outputs : message handled - * @param message : a pointer to the message to handle - * @return none - *************************************************************************/ -void handleChangeUFSettingsRequest( MESSAGE_T *message ) -{ - if ( message->hdr.payloadLen == sizeof(F32) ) - { - F32 uFVolume; - - memcpy( &uFVolume, message->payload, sizeof(F32) ); - - verifyUFSettingsChange( uFVolume ); - } - else - { - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); - } -} - -/************************************************************************* - * @brief * The sendChangeUFSettingsResponse function constructs a UF change settings \n * response to the UI and queues the msg for transmit on the appropriate CAN \n * channel. @@ -587,58 +369,6 @@ /************************************************************************* * @brief - * The handleChangeUFSettingsConfirmation function handles a ultrafiltration \n - * change setting confirmation message from the UI. - * @details - * Inputs : none - * Outputs : message handled - * @param message : a pointer to the message to handle - * @return none - *************************************************************************/ -void handleChangeUFSettingsConfirmation( MESSAGE_T *message ) -{ - if ( message->hdr.payloadLen == sizeof(UF_SETTINGS_CHANGE_CONFIRMATION_PAYLOAD_T) ) - { - UF_SETTINGS_CHANGE_CONFIRMATION_PAYLOAD_T payload; - - memcpy( &payload, message->payload, sizeof(UF_SETTINGS_CHANGE_CONFIRMATION_PAYLOAD_T) ); - - verifyUFSettingsConfirmation( payload.volume_mL, payload.adjustType ); - } - else - { - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); - } -} - -/************************************************************************* - * @brief - * The handleChangeTreatmentDurationRequest function handles a treatment \n - * duration setting change message from the UI. - * @details - * Inputs : none - * Outputs : message handled - * @param message : a pointer to the message to handle - * @return none - *************************************************************************/ -void handleChangeTreatmentDurationRequest( MESSAGE_T *message ) -{ - if ( message->hdr.payloadLen == sizeof(U32) ) - { - U32 timeInMin; - - memcpy( &timeInMin, message->payload, sizeof(U32) ); - - verifyTreatmentDurationSettingChange( timeInMin ); - } - else - { - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); - } -} - -/************************************************************************* - * @brief * The sendChangeTreatmentDurationResponse function constructs a treatment \n * duration change response to the UI and queues the msg for transmit on the \n * appropriate CAN channel. @@ -679,36 +409,6 @@ /************************************************************************* * @brief - * The handleChangeBloodDialysateRateChangeRequest function handles a blood \n - * and dialysate rate settings change message from the UI. - * @details - * Inputs : none - * Outputs : message handled - * @param message : a pointer to the message to handle - * @return none - *************************************************************************/ -void handleChangeBloodDialysateRateChangeRequest( MESSAGE_T *message ) -{ - U32 expPayloadSize = sizeof(U32) + sizeof(U32); - - if ( expPayloadSize == message->hdr.payloadLen ) - { - U32 bloodRate; - U32 dialRate; - - memcpy( &bloodRate, &message->payload[0], sizeof(U32) ); - memcpy( &dialRate, &message->payload[sizeof(U32)], sizeof(U32) ); - - verifyBloodAndDialysateRateSettingsChange( bloodRate, dialRate ); - } - else - { - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); - } -} - -/************************************************************************* - * @brief * The sendChangeBloodDialysateRateChangeResponse function constructs a change \n * blood and dialysate rate settings response to the UI and queues the msg for \n * transmit on the appropriate CAN channel. @@ -792,63 +492,6 @@ /************************************************************************* * @brief - * The handleDGOpMode function handles a DG broadcast of it's current mode. - * @details - * Inputs : none - * Outputs : message handled, response constructed and queued for transmit. - * @param message : a pointer to the message to handle. - * @return none - *************************************************************************/ -void handleDGOpMode( MESSAGE_T *message ) -{ - if ( message->hdr.payloadLen == sizeof(U32) ) - { - U32 mode; - - memcpy( &mode, message->payload, sizeof(U32) ); - - setDGOpMode( mode ); - } - else - { - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_DG, FALSE ); - } -} - -/************************************************************************* - * @brief - * The handleFWVersionRequest function handles a request for HD f/w version. - * @details - * Inputs : none - * Outputs : message handled, response constructed and queued for transmit. - * @param message : a pointer to the message to handle. - * @return none - *************************************************************************/ -void handleFWVersionRequest( MESSAGE_T *message ) -{ - MESSAGE_T msg; - U08 major = (U08)HD_VERSION_MAJOR; - U08 minor = (U08)HD_VERSION_MINOR; - U16 build = (U16)HD_VERSION_BUILD; - U08 *payloadPtr = msg.payload; - - // create a message record - blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_HD_VERSION; - msg.hdr.payloadLen = sizeof( U08 ) + sizeof( U08 ) + sizeof( U16 ); - - memcpy( payloadPtr, &major, sizeof( U08 ) ); - payloadPtr += sizeof( U08 ); - memcpy( payloadPtr, &minor, sizeof( U08 ) ); - payloadPtr += sizeof( U08 ); - memcpy( payloadPtr, &build, sizeof( U16 ) ); - - // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer - serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_UI, ACK_REQUIRED ); -} - -/************************************************************************* - * @brief * The sendDialysateTempTargetsToDG function constructs a dialysate temperature \n * set points message for DG and queues the msg for transmit on the appropriate CAN channel. * @details @@ -1270,8 +913,369 @@ return result; } +// *********************************************************************** +// **************** Message Handling Helper Functions ******************** +// *********************************************************************** /************************************************************************* + * @brief handleDGCheckIn + * The handleDGCheckIn function handles a check-in from the DG. + * @details + * Inputs : none + * Outputs : check in the DG with the SystemComm module. + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleDGCheckIn( MESSAGE_T *message ) +{ + checkInFromDG(); +} + +/************************************************************************* + * @brief handleUICheckIn + * The handleUICheckIn function handles a check-in from the UI. + * @details + * Inputs : none + * Outputs : check in the UI with the SystemComm module. + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleUICheckIn( MESSAGE_T *message ) +{ + checkInFromUI(); +} + +/************************************************************************* + * @brief handleOffButtonConfirmMsgFromUI + * The handleOffButtonConfirmMsgFromUI function handles a response to an \n + * off button message to the UI. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleOffButtonConfirmMsgFromUI( MESSAGE_T *message ) +{ + OFF_BUTTON_MESSAGE_FROM_UI_PAYLOAD_T payload; + + if ( message->hdr.payloadLen == sizeof(OFF_BUTTON_MESSAGE_FROM_UI_PAYLOAD_T) ) + { + memcpy( &payload, message->payload, sizeof(OFF_BUTTON_MESSAGE_FROM_UI_PAYLOAD_T) ); + userConfirmOffButton( payload.confirmed ); + } +} + +/************************************************************************* + * @brief + * The handleLoadCellReadingsFromDG function handles a load cell readings \n + * broadcast message from the DG. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleLoadCellReadingsFromDG( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + if ( message->hdr.payloadLen == sizeof(LOAD_CELL_READINGS_PAYLOAD_T) ) + { + LOAD_CELL_READINGS_PAYLOAD_T payload; + + memcpy( &payload, message->payload, sizeof(LOAD_CELL_READINGS_PAYLOAD_T) ); + result = setNewLoadCellReadings( payload.res1PrimaryLoadCell, payload.res1BackupLoadCell, payload.res2PrimaryLoadCell, payload.res2BackupLoadCell ); + } + // TODO - what to do if invalid payload length? +} + +/************************************************************************* + * @brief + * The handleROPumpData function handles an RO pump data broadcast \n + * message from the DG. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleROPumpData( MESSAGE_T *message ) +{ + if ( message->hdr.payloadLen == sizeof(DG_RO_PUMP_DATA_PAYLOAD_T) ) + { + DG_RO_PUMP_DATA_PAYLOAD_T payload; + + memcpy( &payload, message->payload, sizeof(DG_RO_PUMP_DATA_PAYLOAD_T) ); + setDGROPumpData( payload.setPtPSI, payload.measFlowRateMlMin ); + } + // TODO - what to do if invalid payload length? +} + +/************************************************************************* + * @brief + * The handleDrainPumpData function handles a drain pump broadcast \n + * message from the DG. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleDrainPumpData( MESSAGE_T *message ) +{ + if ( message->hdr.payloadLen == sizeof(DG_DRAIN_PUMP_DATA_PAYLOAD_T) ) + { + DG_DRAIN_PUMP_DATA_PAYLOAD_T payload; + + memcpy( &payload, message->payload, sizeof(DG_DRAIN_PUMP_DATA_PAYLOAD_T) ); + setDGDrainPumpData( payload.setPtRPM ); + } + // TODO - what to do if invalid payload length? +} + +/************************************************************************* + * @brief + * The handleDGPressuresData function handles a DG pressure sensor readings \n + * broadcast message from the DG. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleDGPressuresData( MESSAGE_T *message ) +{ + if ( message->hdr.payloadLen == sizeof(DG_PRESSURES_DATA_PAYLOAD_T) ) + { + DG_PRESSURES_DATA_PAYLOAD_T payload; + + memcpy( &payload, message->payload, sizeof(DG_PRESSURES_DATA_PAYLOAD_T) ); + setDGPressures( payload.roInPSI, payload.roOutPSI, payload.drainInPSI, payload.drainOutPSI ); + } + // TODO - what to do if invalid payload length? +} + +/************************************************************************* + * @brief + * The handleDGReservoirData function handles a reservoir data broadcast \n + * message from the DG. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleDGReservoirData( MESSAGE_T *message ) +{ + if ( message->hdr.payloadLen == sizeof(DG_RESERVOIRS_DATA_PAYLOAD_T) ) + { + DG_RESERVOIRS_DATA_PAYLOAD_T payload; + + memcpy( &payload, message->payload, sizeof(DG_RESERVOIRS_DATA_PAYLOAD_T) ); + setDGReservoirsData( payload.resID, payload.setFillToVolumeMl, payload.setDrainToVolumeMl ); + } + // TODO - what to do if invalid payload length? +} + +/************************************************************************* + * @brief + * The handleUFPauseResumeRequest function handles a ultrafiltration pause \n + * or resume request message from the UI. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleUFPauseResumeRequest( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + if ( message->hdr.payloadLen == sizeof(U32) ) + { + U32 cmd; + + memcpy( &cmd, message->payload, sizeof(U32) ); + if ( UF_CMD_PAUSE == cmd ) + { + result = pauseUF(); + } + else if ( UF_CMD_RESUME == cmd ) + { + result = resumeUF(); + } + } + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, result ); +} + +/************************************************************************* + * @brief + * The handleChangeUFSettingsRequest function handles a ultrafiltration \n + * change settings request message from the UI. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleChangeUFSettingsRequest( MESSAGE_T *message ) +{ + if ( message->hdr.payloadLen == sizeof(F32) ) + { + F32 uFVolume; + + memcpy( &uFVolume, message->payload, sizeof(F32) ); + + verifyUFSettingsChange( uFVolume ); + } + else + { + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); + } +} + +/************************************************************************* + * @brief + * The handleChangeUFSettingsConfirmation function handles a ultrafiltration \n + * change setting confirmation message from the UI. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleChangeUFSettingsConfirmation( MESSAGE_T *message ) +{ + if ( message->hdr.payloadLen == sizeof(UF_SETTINGS_CHANGE_CONFIRMATION_PAYLOAD_T) ) + { + UF_SETTINGS_CHANGE_CONFIRMATION_PAYLOAD_T payload; + + memcpy( &payload, message->payload, sizeof(UF_SETTINGS_CHANGE_CONFIRMATION_PAYLOAD_T) ); + + verifyUFSettingsConfirmation( payload.volume_mL, payload.adjustType ); + } + else + { + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); + } +} + +/************************************************************************* + * @brief + * The handleChangeTreatmentDurationRequest function handles a treatment \n + * duration setting change message from the UI. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleChangeTreatmentDurationRequest( MESSAGE_T *message ) +{ + if ( message->hdr.payloadLen == sizeof(U32) ) + { + U32 timeInMin; + + memcpy( &timeInMin, message->payload, sizeof(U32) ); + + verifyTreatmentDurationSettingChange( timeInMin ); + } + else + { + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); + } +} + +/************************************************************************* + * @brief + * The handleChangeBloodDialysateRateChangeRequest function handles a blood \n + * and dialysate rate settings change message from the UI. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleChangeBloodDialysateRateChangeRequest( MESSAGE_T *message ) +{ + U32 expPayloadSize = sizeof(U32) + sizeof(U32); + + if ( expPayloadSize == message->hdr.payloadLen ) + { + U32 bloodRate; + U32 dialRate; + + memcpy( &bloodRate, &message->payload[0], sizeof(U32) ); + memcpy( &dialRate, &message->payload[sizeof(U32)], sizeof(U32) ); + + verifyBloodAndDialysateRateSettingsChange( bloodRate, dialRate ); + } + else + { + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); + } +} + +/************************************************************************* + * @brief + * The handleDGOpMode function handles a DG broadcast of it's current mode. + * @details + * Inputs : none + * Outputs : message handled, response constructed and queued for transmit. + * @param message : a pointer to the message to handle. + * @return none + *************************************************************************/ +void handleDGOpMode( MESSAGE_T *message ) +{ + if ( message->hdr.payloadLen == sizeof(U32) ) + { + U32 mode; + + memcpy( &mode, message->payload, sizeof(U32) ); + + setDGOpMode( mode ); + } + else + { + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_DG, FALSE ); + } +} + +/************************************************************************* + * @brief + * The handleFWVersionRequest function handles a request for HD f/w version. + * @details + * Inputs : none + * Outputs : message handled, response constructed and queued for transmit. + * @param message : a pointer to the message to handle. + * @return none + *************************************************************************/ +void handleFWVersionRequest( MESSAGE_T *message ) +{ + MESSAGE_T msg; + U08 major = (U08)HD_VERSION_MAJOR; + U08 minor = (U08)HD_VERSION_MINOR; + U16 build = (U16)HD_VERSION_BUILD; + U08 *payloadPtr = msg.payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_VERSION; + msg.hdr.payloadLen = sizeof( U08 ) + sizeof( U08 ) + sizeof( U16 ); + + memcpy( payloadPtr, &major, sizeof( U08 ) ); + payloadPtr += sizeof( U08 ); + memcpy( payloadPtr, &minor, sizeof( U08 ) ); + payloadPtr += sizeof( U08 ); + memcpy( payloadPtr, &build, sizeof( U16 ) ); + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_UI, ACK_REQUIRED ); +} + + +/************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/