Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r9302e1bd2413cbf99e80ac51aac38502d94801d9 -rc6f3b01d1b0a5e3fdf480a7ee205ca349e10d6d2 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 9302e1bd2413cbf99e80ac51aac38502d94801d9) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision c6f3b01d1b0a5e3fdf480a7ee205ca349e10d6d2) @@ -25,8 +25,10 @@ #include "DialInFlow.h" #include "Dialysis.h" #include "FPGA.h" -#include "MessagePayloads.h" -#include "ModeTreatment.h" +#include "MessagePayloads.h" +#include "ModeStandby.h" +#include "ModeTreatment.h" +#include "ModeTreatmentParams.h" #include "PresOccl.h" #include "SafetyShutdown.h" #include "SystemComm.h" @@ -1267,7 +1269,7 @@ 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? // TODO - how to know if DG stops sending these? } @@ -1410,10 +1412,132 @@ { result = resumeUF(); } - } + } + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, result ); } +/************************************************************************* + * @brief + * The handleUIStartTreatmentMsg function handles a treatment start/cancel \n + * message from the UI. + * @details + * Inputs : none + * Outputs : message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleUIStartTreatmentMsg( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + if ( message->hdr.payloadLen == sizeof(U32) ) + { + U32 cmd; + + memcpy( &cmd, message->payload, sizeof(U32) ); + + if ( 0 == cmd ) // initiate treatment (go to treatment params mode) + { + result = signalUserStartingTreatment(); + } + else if ( 1 == cmd ) // cancel treatment (return from aborted treatment params mode) + { + result = signalUserCancelTreatment(); + } + else if ( 2 == cmd ) // start treatment + { + // TODO - handle when pre-treatment mode is ready for this + } + } + + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, result ); +} + +/************************************************************************* + * @brief + * The handleTreatmentParametersFromUI function handles a treatment parameters \n + * set and validate request message from the UI. + * @details + * Inputs : none + * Outputs : message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTreatmentParametersFromUI( MESSAGE_T *message ) +{ + if ( message->hdr.payloadLen == sizeof(TREATMENT_PARAMS_DATA_PAYLOAD_T) ) + { + TREATMENT_PARAMS_DATA_PAYLOAD_T treatmentParams; + + memcpy( &treatmentParams, message->payload, sizeof(TREATMENT_PARAMS_DATA_PAYLOAD_T) ); + + if ( FALSE == validateAndSetTreatmentParameters( treatmentParams ) ) + { + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); + } + } + else + { + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); + } +} + +/************************************************************************* + * @brief + * The handleUIUserConfirmTreatmentParameters function handles a user confirmation \n + * of treatment parameters message from the UI. + * @details + * Inputs : none + * Outputs : message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleUIUserConfirmTreatmentParameters( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + if ( 0 == message->hdr.payloadLen ) + { + result = signalUserConfirmationOfTreatmentParameters(); + } + + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, result ); +} + +/************************************************************************* + * @brief + * The sendTreatmentParametersResponseMsg function constructs a treatment parameters \n + * response to the UI and queues the msg for transmit on the appropriate CAN channel. + * @details + * Inputs : none + * Outputs : Treatment parameters response msg constructed and queued. + * @param accepted T/F - are settings ok? + * @param rejectReasons reasons each parameter was rejected (if not accepted) + * @param byteLength number of bytes that array of reject reasons takes + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL sendTreatmentParametersResponseMsg( BOOL accepted, U08 *rejectReasons, U32 byteLength ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_NEW_TREATMENT_PARAMS_RESPONSE; + msg.hdr.payloadLen = sizeof( BOOL ) + byteLength; + + memcpy( payloadPtr, &accepted, sizeof( BOOL ) ); + payloadPtr += sizeof( BOOL ); + memcpy( payloadPtr, rejectReasons, byteLength ); + + // 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 handleChangeUFSettingsRequest function handles a ultrafiltration \n @@ -1701,6 +1825,7 @@ if ( ( 3 == message->hdr.payloadLen ) && ( 0x31 == message->payload[ 0 ] ) && ( 0x32 == message->payload[ 1 ] ) && ( 0x33 == message->payload[ 2 ] ) ) { testerLoggedIn = TRUE; + checkInFromUI(); // allow tasks to begin normal processing when tester has logged in } else {