Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -rd3ae2d91603ae6d2d25b9abdb220cc144cf90692 -r62ca8a35aac0f60278cfa07b74b27760c608c909 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision d3ae2d91603ae6d2d25b9abdb220cc144cf90692) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 62ca8a35aac0f60278cfa07b74b27760c608c909) @@ -21,9 +21,9 @@ #include "AlarmLamp.h" #include "BloodFlow.h" #include "Buttons.h" +#include "DGInterface.h" #include "DialInFlow.h" #include "Dialysis.h" -#include "MsgQueues.h" #include "ModeTreatment.h" #include "PresOccl.h" #include "WatchdogMgmt.h" @@ -97,16 +97,36 @@ typedef struct { - F32 volume_mL; - UF_ADJ_T adjustType; -} UF_SETTINGS_CHANGE_REQ_PAYLOAD_T; + U32 setPtPSI; + F32 measFlowRateMlMin; + F32 setPWM; +} DG_RO_PUMP_DATA_PAYLOAD_T; typedef struct { - BOOL confirmed; - F32 volume_mL; - U32 treatTime_min; - F32 uFRate_mL_min; + U32 setPtRPM; + F32 setPWM; +} DG_DRAIN_PUMP_DATA_PAYLOAD_T; + +typedef struct +{ + F32 roInPSI; + F32 roOutPSI; + F32 drainInPSI; + F32 drainOutPSI; +} DG_PRESSURES_DATA_PAYLOAD_T; + +typedef struct +{ + DG_RESERVOIR_ID_T resID; + U32 setFillToVolumeMl; + U32 setDrainToVolumeMl; +} DG_RESERVOIRS_DATA_PAYLOAD_T; + +typedef struct +{ + F32 volume_mL; + UF_ADJ_T adjustType; } UF_SETTINGS_CHANGE_CONFIRMATION_PAYLOAD_T; #pragma pack(pop) @@ -266,7 +286,7 @@ } // *********************************************************************** -// ********************* MSG_ID_OFF_BUTTON_PRESS ************************* +// ***************** Message Sending Helper Functions ******************** // *********************************************************************** /************************************************************************* @@ -298,231 +318,351 @@ } /************************************************************************* - * @brief handleDGCheckIn - * The handleDGCheckIn function handles a check-in from the DG. + * @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. * @details * Inputs : none - * Outputs : check in the DG with the SystemComm module. - * @param message : a pointer to the message to handle - * @return none + * Outputs : UF change settings response msg constructed and queued. + * @param accepted : alarm status record + * @param reason : reason rejected (if not accepted) + * @param volume_mL : alarm status record + * @param time_min : alarm status record + * @param ufRate_mL_min : alarm status record + * @param timeDiff : alarm status record + * @param rateDiff : alarm status record + * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ -void handleDGCheckIn( MESSAGE_T *message ) +BOOL sendChangeUFSettingsResponse( BOOL accepted, U32 reason, F32 volume_mL, U32 time_min, F32 ufRate_mL_min, S32 timeDiff, F32 rateDiff ) { - checkInFromDG(); + BOOL result; + F32 volume_L = volume_mL / (F32)ML_PER_LITER; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_USER_UF_SETTINGS_CHANGE_RESPONSE; + msg.hdr.payloadLen = sizeof( BOOL ) + sizeof( U32 ) + sizeof( F32 ) + sizeof( U32 ) + sizeof( U32 ) + sizeof( F32 ) + sizeof ( F32 ); + + memcpy( payloadPtr, &accepted, sizeof( BOOL ) ); + payloadPtr += sizeof( BOOL ); + memcpy( payloadPtr, &reason, sizeof( U32) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &volume_L, sizeof( F32 ) ); + payloadPtr += sizeof( F32 ); + memcpy( payloadPtr, &time_min, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &timeDiff, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &ufRate_mL_min, sizeof( F32 ) ); + payloadPtr += sizeof( F32 ); + memcpy( payloadPtr, &rateDiff, sizeof( F32 ) ); + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_UI, ACK_REQUIRED ); + + return result; } /************************************************************************* - * @brief handleUICheckIn - * The handleUICheckIn function handles a check-in from the UI. + * @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. * @details * Inputs : none - * Outputs : check in the UI with the SystemComm module. - * @param message : a pointer to the message to handle - * @return none + * Outputs : treatment duration change settings response msg constructed and queued. + * @param accepted : alarm status record + * @param reason : reason rejected (if not accepted) + * @param time_min : alarm status record + * @param volume_mL : alarm status record + * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ -void handleUICheckIn( MESSAGE_T *message ) +BOOL sendChangeTreatmentDurationResponse( BOOL accepted, U32 reason, U32 time_min, F32 volume_mL ) { - checkInFromUI(); + BOOL result; + F32 volume_L = volume_mL / (F32)ML_PER_LITER; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_USER_TREATMENT_TIME_CHANGE_RESPONSE; + msg.hdr.payloadLen = sizeof( BOOL ) + sizeof( U32 ) + sizeof( U32 ) + sizeof( F32 ); + + memcpy( payloadPtr, &accepted, sizeof( BOOL ) ); + payloadPtr += sizeof( BOOL ); + memcpy( payloadPtr, &reason, sizeof( U32) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &time_min, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &volume_L, sizeof( F32 ) ); + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_UI, ACK_REQUIRED ); + + return result; } /************************************************************************* - * @brief handleOffButtonConfirmMsgFromUI - * The handleOffButtonConfirmMsgFromUI function handles a response to an \n - * off button message to the UI. + * @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. * @details * Inputs : none - * Outputs : message handled - * @param message : a pointer to the message to handle - * @return none + * Outputs : Blood & dialysate rate change response msg constructed and queued. + * @param accepted : alarm status record + * @param reason : reason code for rejection or unused if accepted + * @param bloodRate : new blood flow rate + * @param dialRate : new dialysate flow rate + * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ -void handleOffButtonConfirmMsgFromUI( MESSAGE_T *message ) +BOOL sendChangeBloodDialysateRateChangeResponse( BOOL accepted, U32 reason, U32 bloodRate, U32 dialRate ) { - OFF_BUTTON_MESSAGE_FROM_UI_PAYLOAD_T payload; + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.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 ); - } + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_USER_BLOOD_DIAL_RATE_CHANGE_RESPONSE; + msg.hdr.payloadLen = sizeof( BOOL ) + sizeof( U32 ) + sizeof( U32 ) + sizeof( U32 ); + + memcpy( payloadPtr, &accepted, sizeof( BOOL ) ); + payloadPtr += sizeof( BOOL ); + memcpy( payloadPtr, &reason, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &bloodRate, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &dialRate, sizeof( U32 ) ); + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_UI, ACK_REQUIRED ); + + return result; } /************************************************************************* * @brief - * The handleLoadCellReadingsFromDG function handles a load cell readings \n - * message from the DG. + * The sendTreatmentParamsRangesToUI function constructs a treatment parameter \n + * ranges message to the UI and queues the msg for transmit on the appropriate CAN channel. * @details * Inputs : none - * Outputs : message handled - * @param message : a pointer to the message to handle - * @return none + * Outputs : Treatment parameter ranges msg constructed and queued. + * @param minTime : Minimum treatment duration (in minutes). + * @param maxTime : Maximum treatment duration (in minutes). + * @param minUFVol : Minimum ultrafiltration volume (in mL). + * @param maxUFVol : Maximum ultrafiltration volume (in mL). + * @param minDialRate : Minimum dialysate flow rate (in mL/min). + * @param maxDialRate : Maximum dialysate flow rate (in mL/min). + * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ -void handleLoadCellReadingsFromDG( MESSAGE_T *message ) +BOOL sendTreatmentParamsRangesToUI( U32 minTime, U32 maxTime, U32 minUFVol, U32 maxUFVol, U32 minDialRate, U32 maxDialRate ) { - BOOL result = FALSE; + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; - if ( message->hdr.payloadLen == sizeof(LOAD_CELL_READINGS_PAYLOAD_T) ) - { - LOAD_CELL_READINGS_PAYLOAD_T payload; + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_TREATMENT_PARAM_CHANGE_RANGES; + msg.hdr.payloadLen = sizeof( U32 ) + sizeof( U32 ) + sizeof( U32 ) + sizeof( U32 ) + sizeof( U32 ) + sizeof( U32 ); - 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? + memcpy( payloadPtr, &minTime, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &maxTime, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &minUFVol, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &maxUFVol, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &minDialRate, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &maxDialRate, sizeof( U32 ) ); + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_UI, ACK_REQUIRED ); + + return result; } /************************************************************************* * @brief - * The handleUFPauseResumeRequest function handles a ultrafiltration pause \n - * or resume request message from the UI. + * 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 * Inputs : none - * Outputs : message handled - * @param message : a pointer to the message to handle - * @return none + * Outputs : Dialysate temperature set points msg constructed and queued. + * @param primary : temperature set point for primary heater. + * @param trimmer : temperature set point for trimmer heater. + * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ -void handleUFPauseResumeRequest( MESSAGE_T *message ) +BOOL sendDialysateTempTargetsToDG( F32 primary, F32 trimmer ) { - BOOL result = FALSE; + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; - if ( message->hdr.payloadLen == sizeof(U32) ) - { - U32 cmd; + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_SET_DG_DIALYSATE_TEMP_TARGETS; + msg.hdr.payloadLen = sizeof( F32 ) + sizeof( F32 ); - 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 ); + memcpy( payloadPtr, &primary, sizeof( F32 ) ); + payloadPtr += sizeof( F32 ); + memcpy( payloadPtr, &trimmer, sizeof( F32 ) ); + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_DG, ACK_REQUIRED ); + + return result; } /************************************************************************* * @brief - * The handleChangeUFSettingsRequest function handles a ultrafiltration \n - * change settings request message from the UI. + * The sendDGSwitchReservoirCommand function constructs a DG set active \n + * reservoir message for DG and queues the msg for transmit on the appropriate CAN channel. * @details * Inputs : none - * Outputs : message handled - * @param message : a pointer to the message to handle - * @return none + * Outputs : DG set active reservoir msg constructed and queued. + * @param activeReservoir : reservoir ID to set as active. + * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ -void handleChangeUFSettingsRequest( MESSAGE_T *message ) +BOOL sendDGSwitchReservoirCommand( DG_RESERVOIR_ID_T activeReservoir ) { - BOOL result = FALSE; + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; - if ( message->hdr.payloadLen == sizeof(UF_SETTINGS_CHANGE_REQ_PAYLOAD_T) ) - { - UF_SETTINGS_CHANGE_REQ_PAYLOAD_T payload; + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_DG_SWITCH_RESERVOIR_CMD; + msg.hdr.payloadLen = sizeof( DG_RESERVOIR_ID_T ); - memcpy( &payload, message->payload, sizeof(UF_SETTINGS_CHANGE_REQ_PAYLOAD_T) ); + memcpy( payloadPtr, &activeReservoir, sizeof( DG_RESERVOIR_ID_T ) ); - result = verifyUFSettingsChange( payload.volume_mL, payload.adjustType ); - } - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, result ); + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_DG, ACK_REQUIRED ); + + return result; } /************************************************************************* * @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. + * The sendDGFillCommand function constructs a DG fill command message \n + * and queues the msg for transmit on the appropriate CAN channel. * @details * Inputs : none - * Outputs : UF change settings response msg constructed and queued. - * @param accepted : alarm status record - * @param volume_mL : alarm status record - * @param time_min : alarm status record - * @param ufRate_mL_min : alarm status record - * @param timeDiff : alarm status record - * @param rateDiff : alarm status record + * Outputs : DG fill command msg constructed and queued. + * @param fillToVolumeMl : volume (in mL) to fill inactive reservoir to. * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ -BOOL sendChangeUFSettingsResponse( BOOL accepted, F32 volume_mL, U32 time_min, F32 ufRate_mL_min, S32 timeDiff, F32 rateDiff ) +BOOL sendDGFillCommand( U32 fillToVolumeMl ) { BOOL result; - F32 volume_L = volume_mL / (F32)ML_PER_LITER; MESSAGE_T msg; U08 *payloadPtr = msg.payload; // create a message record blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_USER_UF_SETTINGS_CHANGE_RESPONSE; - msg.hdr.payloadLen = sizeof( BOOL ) + sizeof( F32 ) + sizeof( U32 ) + sizeof( F32 ) + sizeof( U32 ) + sizeof (F32 ); + msg.hdr.msgID = MSG_ID_DG_FILL_CMD; + msg.hdr.payloadLen = sizeof( U32 ); - memcpy( payloadPtr, &accepted, sizeof( BOOL ) ); - payloadPtr += sizeof( BOOL ); - memcpy( payloadPtr, &volume_L, sizeof( F32 ) ); - payloadPtr += sizeof( F32 ); - memcpy( payloadPtr, &time_min, sizeof( U32 ) ); - payloadPtr += sizeof( U32 ); - memcpy( payloadPtr, &ufRate_mL_min, sizeof( F32 ) ); - payloadPtr += sizeof( F32 ); - memcpy( payloadPtr, &timeDiff, sizeof( U32 ) ); - payloadPtr += sizeof( U32 ); - memcpy( payloadPtr, &rateDiff, sizeof( F32 ) ); + memcpy( payloadPtr, &fillToVolumeMl, sizeof( U32 ) ); // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer - result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_UI, ACK_REQUIRED ); + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_DG, ACK_REQUIRED ); return result; } /************************************************************************* * @brief - * The handleChangeUFSettingsConfirmation function handles a ultrafiltration \n - * change setting confirmation message from the UI. + * The sendDGDrainCommand function constructs a DG drain command message \n + * and queues the msg for transmit on the appropriate CAN channel. * @details * Inputs : none - * Outputs : message handled - * @param message : a pointer to the message to handle - * @return none + * Outputs : DG drain command msg constructed and queued. + * @param drainToVolumeMl : volume (in mL) to drain the inactive reservoir to. + * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ -void handleChangeUFSettingsConfirmation( MESSAGE_T *message ) +BOOL sendDGDrainCommand( U32 drainToVolumeMl ) { - BOOL result = FALSE; + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; - if ( message->hdr.payloadLen == sizeof(UF_SETTINGS_CHANGE_CONFIRMATION_PAYLOAD_T) ) - { - UF_SETTINGS_CHANGE_CONFIRMATION_PAYLOAD_T payload; + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_DG_DRAIN_CMD; + msg.hdr.payloadLen = sizeof( U32 ); - memcpy( &payload, message->payload, sizeof(UF_SETTINGS_CHANGE_CONFIRMATION_PAYLOAD_T) ); + memcpy( payloadPtr, &drainToVolumeMl, sizeof( U32 ) ); - result = verifyUFSettingsConfirmation( payload.confirmed, payload.volume_mL, payload.treatTime_min, payload.uFRate_mL_min ); - } - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, result ); + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_DG, ACK_REQUIRED ); + + return result; } /************************************************************************* * @brief - * The handleChangeTreatmentDurationRequest function handles a treatment \n - * duration setting change message from the UI. + * The sendDGStartStopCommand function constructs a DG start/stop command \n + * message and queues the msg for transmit on the appropriate CAN channel. * @details * Inputs : none - * Outputs : message handled - * @param message : a pointer to the message to handle - * @return none + * Outputs : DG start/stop command msg constructed and queued. + * @param start : TRUE indicates start DG, FALSE indicates stop DG. + * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ -void handleChangeTreatmentDurationRequest( MESSAGE_T *message ) +BOOL sendDGStartStopCommand( BOOL start ) { - BOOL result = FALSE; + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; - if ( message->hdr.payloadLen == sizeof(U32) ) - { - U32 timeInMin; + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_STARTING_STOPPING_TREATMENT_CMD; + msg.hdr.payloadLen = sizeof( BOOL ); - memcpy( &timeInMin, message->payload, sizeof(U32) ); + memcpy( payloadPtr, &start, sizeof( BOOL ) ); - result = verifyTreatmentDurationSettingChange( timeInMin ); - } - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, result ); + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_DG, ACK_REQUIRED ); + + return result; } /************************************************************************* + * @brief + * The sendDGSampleWaterCommand function constructs a DG sample water command \n + * message and queues the msg for transmit on the appropriate CAN channel. + * @details + * Inputs : none + * Outputs : DG sample water command msg constructed and queued. + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL sendDGSampleWaterCommand( void ) +{ + BOOL result; + MESSAGE_T msg; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_DG_SAMPLE_WATER_CMD; + msg.hdr.payloadLen = 0; + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_DG, ACK_REQUIRED ); + + return result; +} + +/************************************************************************* * @brief broadcastAlarmStatus * The broadcastAlarmStatus function constructs an alarm status msg to \n * be broadcast and queues the msg for transmit on the appropriate CAN channel. @@ -913,8 +1053,401 @@ return result; } +/************************************************************************* + * @brief + * The broadcastHDOperationMode function constructs an HD operation mode \n + * broadcast message and queues the msg for transmit on the appropriate CAN channel. + * @details + * Inputs : none + * Outputs : HD operation mode msg constructed and queued + * @param mode : current HD operation mode. + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastHDOperationMode( U32 mode ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_OP_MODE; + msg.hdr.payloadLen = sizeof( U32 ); + + memcpy( payloadPtr, &mode, sizeof( U32 ) ); + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_BROADCAST, ACK_NOT_REQUIRED ); + + 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; + U08 micro = (U08)HD_VERSION_MICRO; + 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( U08 ) + sizeof( U16 ); + + memcpy( payloadPtr, &major, sizeof( U08 ) ); + payloadPtr += sizeof( U08 ); + memcpy( payloadPtr, &minor, sizeof( U08 ) ); + payloadPtr += sizeof( U08 ); + memcpy( payloadPtr, µ, 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 *************************************************************************/