Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r68b7f509295fb25aead139a4391913ca05989fdc -rb6416214042da75dfa311b726e401442b34315d7 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 68b7f509295fb25aead139a4391913ca05989fdc) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision b6416214042da75dfa311b726e401442b34315d7) @@ -8,7 +8,7 @@ * @file SystemCommMessages.c * * @author (last) Dara Navaei -* @date (last) 21-Mar-2023 +* @date (last) 28-Mar-2023 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -81,7 +81,8 @@ // ********** private function prototypes ********** static BOOL sendTestAckResponseMsg( MSG_ID_T msgID, BOOL ack ); -static BOOL sendAckResponseMsg( MSG_ID_T msgID, COMM_BUFFER_T buffer, BOOL ack ); +static BOOL sendAckResponseMsg( MSG_ID_T msgID, COMM_BUFFER_T buffer, BOOL ack ); +static BOOL sendUIResponseMsg( MSG_ID_T msgID, BOOL accepted, U32 reason ); /*********************************************************************//** * @brief @@ -222,7 +223,39 @@ return result; } +/*********************************************************************//** + * @brief + * The sendUIResponseMsg function constructs an UI response message for a + * handled UI message and queues it for transmit on the appropriate CAN channel. + * @details Inputs: none + * @details Outputs: response message constructed and queued for transmit. + * @param msgID ID of handled message that we are responding to + * @param accepted T/F - request accepted? + * @param reason reason code if rejected + * @return TRUE if response message successfully queued for transmit, FALSE if not + *************************************************************************/ +static BOOL sendUIResponseMsg( MSG_ID_T msgID, BOOL accepted, U32 reason ) +{ + BOOL result; + MESSAGE_T msg; + UI_RESPONSE_PAYLOAD_T cmd; + cmd.accepted = accepted; + cmd.rejectionReason = reason; + + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = msgID; + msg.hdr.payloadLen = sizeof( UI_RESPONSE_PAYLOAD_T ); + memcpy( &msg.payload, &cmd, sizeof( UI_RESPONSE_PAYLOAD_T ) ); + + // 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_DG_2_UI, ACK_REQUIRED ); + + return result; +} + + // *********************************************************************** // ***************** Message Sending Helper Functions ******************** // *********************************************************************** @@ -962,11 +995,11 @@ if ( message->hdr.payloadLen == sizeof( U32 ) ) { - DG_VALVE_SETTING_ID_T valveSettingID; + U32 valveSettingID; result = TRUE; memcpy( &valveSettingID, message->payload, sizeof( U32 ) ); - changeValveSettingCmd( valveSettingID ); + changeValveSettingCmd( (DG_VALVE_SETTING_ID_T)valveSettingID ); } sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_DG_2_HD, result ); @@ -1049,18 +1082,20 @@ { BOOL result = FALSE; - if ( message->hdr.payloadLen == sizeof( BOOL ) ) + if ( message->hdr.payloadLen == sizeof( DG_START_STOP_TX_CMD_REQUEST_T ) ) { - BOOL startingTreatment; + DG_START_STOP_TX_CMD_REQUEST_T startingTreatment; DG_OP_MODE_T dgMode = getCurrentOperationMode(); - memcpy( &startingTreatment, message->payload, sizeof( BOOL ) ); + memcpy( &startingTreatment, message->payload, sizeof( DG_START_STOP_TX_CMD_REQUEST_T ) ); - if ( ( DG_MODE_STAN == dgMode ) && ( TRUE == startingTreatment ) ) + if ( ( DG_MODE_STAN == dgMode ) && ( TRUE == startingTreatment.start ) ) { + // If the command is start DG, set the acid and bicarb types to be used, otherwise in the stop command it does not matter + setAcidAndBicarbType( startingTreatment.acidType, startingTreatment.bicarbType ); result = requestDGStart(); } - else if ( ( dgMode >= DG_MODE_GENE ) && ( dgMode <= DG_MODE_DRAI ) && ( FALSE == startingTreatment ) ) + else if ( ( dgMode >= DG_MODE_GENE ) && ( dgMode <= DG_MODE_DRAI ) && ( FALSE == startingTreatment.start ) ) { result = requestDGStop(); } @@ -1684,7 +1719,76 @@ sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_DG_2_HD, status ); } +/*********************************************************************//** + * @brief + * The handleSetROOnlyMode function handles the setting of the RO mode only. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSetROOnlyMode( MESSAGE_T* message ) +{ + REQUEST_REJECT_REASON_CODE_T rejReason = REQUEST_REJECT_REASON_DG_RO_ONLY_MODE_INVALID_PAYLOAD_LENGTH; + BOOL accepted = FALSE; + if ( message->hdr.payloadLen == sizeof(U32) ) + { + BOOL result; + + rejReason = REQUEST_REJECT_REASON_NONE; + + memcpy( &result, message->payload, sizeof(BOOL) ); + + if ( ( FALSE == result ) || ( TRUE == result ) ) + { + switch ( getCurrentOperationMode() ) + { + case DG_MODE_FAUL: + case DG_MODE_SERV: + case DG_MODE_INIT: + case DG_MODE_STAN: + case DG_MODE_SOLO: + setROMode( result ); + accepted = TRUE; + break; + + default: + rejReason = REQUEST_REJECT_REASON_DG_RO_ONLY_MODE_DG_BUSY; + break; + } + } + else + { + rejReason = REQUEST_REJECT_REASON_DG_RO_ONLY_MODE_INVALID_PARAMETER; + } + } + + sendUIResponseMsg( MSG_ID_DG_RO_ONLY_MODE_STATUS_RESPONSE, accepted, rejReason ); +} + +/*********************************************************************//** + * @brief + * The requestROOnlyModeStatusFromUI function handles the request + * the RO only mode status from UI. + * @details Inputs: none + * @details Outputs: message handled + * @return none + *************************************************************************/ +void requestROOnlyModeStatusFromUI( void ) +{ + MESSAGE_T msg; + + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_DG_RO_ONLY_MODE_STATUS_REQUEST; + msg.hdr.payloadLen = 0; + + // 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_DG_2_UI, ACK_REQUIRED ); +} + + // *********************************************************************** // **************** Message Handling Helper Functions ******************** // ***********************************************************************