Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -ra8ee65f27d84c7ae435b8bbae6a1d82a51e804f1 -r782cbace651eebeccbbfd3e2f2b607436269ee7f --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision a8ee65f27d84c7ae435b8bbae6a1d82a51e804f1) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 782cbace651eebeccbbfd3e2f2b607436269ee7f) @@ -7,8 +7,8 @@ * * @file SystemCommMessages.c * -* @author (last) Michael Garthwaite -* @date (last) 20-Mar-2023 +* @author (last) Dara Navaei +* @date (last) 31-May-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 ******************** // *********************************************************************** @@ -963,11 +996,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 ); @@ -1050,18 +1083,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(); } @@ -1571,7 +1606,7 @@ } // 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_HD, ACK_REQUIRED ); + serializeMessage( msg, COMM_BUFFER_OUT_CAN_DG_BROADCAST, ACK_REQUIRED ); } /*********************************************************************//** @@ -1685,7 +1720,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 ******************** // *********************************************************************** @@ -1711,6 +1815,19 @@ /*********************************************************************//** * @brief + * The setTesterStatusToLoggedOut function sets the status of the tester to + * logged out. + * @details Inputs: none + * @details Outputs: testerLoggedIn + * @return none + *************************************************************************/ +void setTesterStatusToLoggedOut( void ) +{ + testerLoggedIn = FALSE; +} + +/*********************************************************************//** + * @brief * The sendTestAckResponseMsg function constructs a simple response message for * a handled test message and queues it for transmit on the appropriate UART channel. * @details Inputs: none @@ -3428,20 +3545,20 @@ *************************************************************************/ void handleSetDrainPumpMeasuredRPMOverrideRequest( MESSAGE_T *message ) { - TEST_OVERRIDE_PAYLOAD_T payload; + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; BOOL result = FALSE; // verify payload length - if ( sizeof( TEST_OVERRIDE_PAYLOAD_T ) == message->hdr.payloadLen ) + if ( sizeof( TEST_OVERRIDE_ARRAY_PAYLOAD_T ) == message->hdr.payloadLen ) { - memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_PAYLOAD_T ) ); + memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_ARRAY_PAYLOAD_T ) ); if ( FALSE == payload.reset ) { - result = testSetDrainPumpMeasuredRPMOverride( payload.state.u32 ); + result = testSetDrainPumpMeasuredRPMOverride( payload.index, payload.state.u32 ); } else { - result = testResetDrainPumpMeasuredRPMOverride(); + result = testResetDrainPumpMeasuredRPMOverride( payload.index ); } } @@ -3656,6 +3773,7 @@ sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); } +#ifndef _RELEASE_ /*********************************************************************//** * @brief * The handleGetDGSoftwareConfigRecord function handles a request to get the DG @@ -3718,6 +3836,7 @@ // Respond to request sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, status ); } +#endif /*********************************************************************//** * @brief @@ -3785,38 +3904,6 @@ } /*********************************************************************//** -* The handleTestDGDrainPumpCurrentOverrideRequest function handles a -* request to override the drain pump measured current. -* @details Inputs: none -* @details Outputs: message handled -* @param message a pointer to the message to handle -* @return none -*************************************************************************/ -void handleTestDGDrainPumpCurrentOverrideRequest( MESSAGE_T *message ) -{ - TEST_OVERRIDE_PAYLOAD_T payload; - BOOL result = FALSE; - - // verify payload length - if ( sizeof( TEST_OVERRIDE_PAYLOAD_T ) == message->hdr.payloadLen ) - { - memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_PAYLOAD_T ) ); - - if ( FALSE == payload.reset ) - { - result = testSetDrainPumpMeasuredCurrentOverride( payload.state.f32 ); - } - else - { - result = testResetDrainPumpMeasuredCurrentOverride(); - } - } - - // Respond to request - sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); -} - -/*********************************************************************//** * The handleTestDGDrainPumpDirectionOverrideRequest function handles a * request to override the drain pump measured direction. * @details Inputs: none @@ -4466,4 +4553,192 @@ sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, status ); } +/*********************************************************************//** + * @brief + * The handleTestDGSetTestConfig function handles a request to set the + * test configuration. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTestDGSetTestConfig( MESSAGE_T *message ) +{ + BOOL status = FALSE; + + if ( message->hdr.payloadLen == sizeof( TEST_CONFIG_PAYLOAD_T ) ) + { + TEST_CONFIG_PAYLOAD_T payload; + + memcpy( &payload, message->payload, sizeof( TEST_CONFIG_PAYLOAD_T ) ); + + if ( TRUE == payload.reset ) + { + status = resetTestConfig( (TEST_CONFIG_T)payload.config ); + } + else + { + status = setTestConfig( (TEST_CONFIG_T)payload.config ); + } + } + + // Respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, status ); +} + +/*********************************************************************//** + * @brief + * The handleTestDGGetTestConfig function handles a request to get the + * test configuration per request. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTestDGGetTestConfig( MESSAGE_T* message ) +{ + BOOL result = FALSE; + + // verify payload length + if ( 0 == message->hdr.payloadLen ) + { + result = sendTestConfigStatusToDialin(); + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** + * @brief + * The handleTestDGResetAllTestConfigs function handles a request to reset + * all of the test configurations. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTestDGResetAllTestConfigs( MESSAGE_T* message ) +{ + BOOL result = FALSE; + + // verify payload length + if ( 0 == message->hdr.payloadLen ) + { + result = resetAllTestConfigs(); + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** + * @brief + * The handleTestDGDialinCheckIn function handles check in from Dialin. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTestDGDialinCheckIn( MESSAGE_T* message ) +{ + BOOL status = FALSE; + + if ( 0 == message->hdr.payloadLen ) + { + status = TRUE; + setDialinCheckInTimeStamp(); + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, status ); +} + +/*********************************************************************//** + * @brief + * The handleTestDGGetLoadCellsTareValues function handles a request to + * get the load cells tare values. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTestDGGetLoadCellsTareValues( MESSAGE_T* message ) +{ + BOOL status = FALSE; + + if ( 0 == message->hdr.payloadLen ) + { + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_DG_SEND_LOAD_CELLS_TARE_VALUES; + msg.hdr.payloadLen = sizeof( F32 ) * NUM_OF_LOAD_CELLS; + + getLoadCellsTareValues( payloadPtr ); + + // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + status = serializeMessage( msg, COMM_BUFFER_OUT_CAN_PC, ACK_NOT_REQUIRED ); + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, status ); +} + +/*********************************************************************//** + * @brief + * The handleTestDGSetLoadCellsTareValues function handles a request to + * set the load cells tare values. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTestDGSetLoadCellsTareValues( MESSAGE_T* message ) +{ + BOOL status = FALSE; + + if ( ( sizeof( F32 ) * NUM_OF_LOAD_CELLS ) == message->hdr.payloadLen ) + { + F32 payload[ NUM_OF_LOAD_CELLS ]; + + status = TRUE; + + memcpy( &payload, message->payload, sizeof( F32 ) * NUM_OF_LOAD_CELLS ); + + setLoadCellsTareValues( (U08*)&payload ); + } + + // Respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, status ); +} + +/*********************************************************************//** + * @brief + * The handleTestDGSetConductivitySensorCalTable function handles a request to + * set the conductivity sensor's calibration table. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTestDGSetConductivitySensorCalTable( MESSAGE_T* message ) +{ + BOOL status = FALSE; + + if ( sizeof( CONDUCTIVITY_SENSOR_CAL_TABLE_T ) == message->hdr.payloadLen ) + { + CONDUCTIVITY_SENSOR_CAL_TABLE_T payload; + + memcpy( &payload, message->payload, sizeof( CONDUCTIVITY_SENSOR_CAL_TABLE_T ) ); + + testSetConductivitySensorCalibrationTable( &payload ); + } + + // Respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, status ); +} + /**@}*/