Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -rd3ae2d91603ae6d2d25b9abdb220cc144cf90692 -rfb4b4a4f9d16742bfb76f62970a43c97e1ac14f0 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision d3ae2d91603ae6d2d25b9abdb220cc144cf90692) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision fb4b4a4f9d16742bfb76f62970a43c97e1ac14f0) @@ -99,14 +99,6 @@ { F32 volume_mL; UF_ADJ_T adjustType; -} UF_SETTINGS_CHANGE_REQ_PAYLOAD_T; - -typedef struct -{ - BOOL confirmed; - F32 volume_mL; - U32 treatTime_min; - F32 uFRate_mL_min; } UF_SETTINGS_CHANGE_CONFIRMATION_PAYLOAD_T; #pragma pack(pop) @@ -413,17 +405,18 @@ *************************************************************************/ void handleChangeUFSettingsRequest( MESSAGE_T *message ) { - BOOL result = FALSE; - - if ( message->hdr.payloadLen == sizeof(UF_SETTINGS_CHANGE_REQ_PAYLOAD_T) ) + if ( message->hdr.payloadLen == sizeof(F32) ) { - UF_SETTINGS_CHANGE_REQ_PAYLOAD_T payload; + F32 uFVolume; - memcpy( &payload, message->payload, sizeof(UF_SETTINGS_CHANGE_REQ_PAYLOAD_T) ); + memcpy( &uFVolume, message->payload, sizeof(F32) ); - result = verifyUFSettingsChange( payload.volume_mL, payload.adjustType ); + verifyUFSettingsChange( uFVolume ); } - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, result ); + else + { + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); + } } /************************************************************************* @@ -435,14 +428,15 @@ * Inputs : 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 *************************************************************************/ -BOOL sendChangeUFSettingsResponse( BOOL accepted, F32 volume_mL, U32 time_min, F32 ufRate_mL_min, S32 timeDiff, F32 rateDiff ) +BOOL sendChangeUFSettingsResponse( BOOL accepted, U32 reason, F32 volume_mL, U32 time_min, F32 ufRate_mL_min, S32 timeDiff, F32 rateDiff ) { BOOL result; F32 volume_L = volume_mL / (F32)ML_PER_LITER; @@ -452,10 +446,12 @@ // 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.payloadLen = sizeof( BOOL ) + sizeof( U32 ) + sizeof( F32 ) + sizeof( U32 ) + sizeof( F32 ) + sizeof( U32 ) + 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 ) ); @@ -484,17 +480,18 @@ *************************************************************************/ void handleChangeUFSettingsConfirmation( MESSAGE_T *message ) { - BOOL result = FALSE; - 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) ); - result = verifyUFSettingsConfirmation( payload.confirmed, payload.volume_mL, payload.treatTime_min, payload.uFRate_mL_min ); + verifyUFSettingsConfirmation( payload.volume_mL, payload.adjustType ); } - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, result ); + else + { + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); + } } /************************************************************************* @@ -509,20 +506,238 @@ *************************************************************************/ void handleChangeTreatmentDurationRequest( MESSAGE_T *message ) { - BOOL result = FALSE; - if ( message->hdr.payloadLen == sizeof(U32) ) { U32 timeInMin; memcpy( &timeInMin, message->payload, sizeof(U32) ); - result = verifyTreatmentDurationSettingChange( timeInMin ); + verifyTreatmentDurationSettingChange( timeInMin ); } - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, result ); + 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. + * @details + * Inputs : 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 + *************************************************************************/ +BOOL sendChangeTreatmentDurationResponse( BOOL accepted, U32 reason, U32 time_min, F32 volume_mL ) +{ + 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 + * 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. + * @details + * Inputs : 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 + *************************************************************************/ +BOOL sendChangeBloodDialysateRateChangeResponse( BOOL accepted, U32 reason, U32 bloodRate, U32 dialRate ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // 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 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 : 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 + *************************************************************************/ +BOOL sendTreatmentParamsRangesToUI( U32 minTime, U32 maxTime, U32 minUFVol, U32 maxUFVol, U32 minDialRate, U32 maxDialRate ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.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( 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 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 + * Inputs : 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 + *************************************************************************/ +BOOL sendDialysateTempTargetsToDG( F32 primary, F32 trimmer ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_SET_DG_DIALYSATE_TEMP_TARGETS; + msg.hdr.payloadLen = sizeof( F32 ) + sizeof( F32 ); + + 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 broadcastAlarmStatus * The broadcastAlarmStatus function constructs an alarm status msg to \n * be broadcast and queues the msg for transmit on the appropriate CAN channel.