Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -rc230be1bd4296324bf5dfc288c212eb7c2ce5d2d -rb0f90032367640dd22ddfbe0307a20cb6e931ceb --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision c230be1bd4296324bf5dfc288c212eb7c2ce5d2d) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision b0f90032367640dd22ddfbe0307a20cb6e931ceb) @@ -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 ******************** // *********************************************************************** @@ -1685,7 +1718,79 @@ 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) ) + { + U32 result; + + rejReason = REQUEST_REJECT_REASON_NONE; + + memcpy( &result, message->payload, sizeof(U32) ); + + if ( ( 0 == result ) || ( 1 == result ) ) + { + switch ( getCurrentOperationMode() ) + { + case DG_MODE_FAUL: + case DG_MODE_SERV: + case DG_MODE_INIT: + case DG_MODE_STAN: + if ( TRUE == (BOOL)result ) + { + enableROOnlyMode(); + 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 ); + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_DG_2_UI, ACK_REQUIRED ); +} + +/*********************************************************************//** + * @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 ******************** // ***********************************************************************