Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r46bf7baaa9d8095e0405b018fcd4bc594907797e -r740929e7f04220e1a74e1a6f8ce71129f40a7be1 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 46bf7baaa9d8095e0405b018fcd4bc594907797e) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 740929e7f04220e1a74e1a6f8ce71129f40a7be1) @@ -8,7 +8,7 @@ * @file SystemCommMessages.c * * @author (last) Dara Navaei -* @date (last) 21-Jun-2022 +* @date (last) 21-Sep-2022 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -24,6 +24,7 @@ #include "ConcentratePumps.h" #include "ConductivitySensors.h" #include "Fans.h" +#include "FlowSensors.h" #include "FPGA.h" #include "Heaters.h" #include "ModeFill.h" @@ -34,7 +35,6 @@ #include "MsgQueues.h" #include "NVDataMgmt.h" #include "OperationModes.h" -#include "DialysateFlow.h" #include "Pressures.h" #include "Reservoirs.h" #include "RTC.h" @@ -454,6 +454,7 @@ if ( message->hdr.payloadLen == sizeof( DG_CMD_DIALYSATE_HEATING_PARAMS_T ) ) { DG_CMD_DIALYSATE_HEATING_PARAMS_T payload; + result = TRUE; memcpy( &payload, message->payload, sizeof( DG_CMD_DIALYSATE_HEATING_PARAMS_T ) ); setDialysateHeatingParameters( payload ); @@ -476,6 +477,11 @@ DG_VERSIONS_T payload; U08 *payloadPtr = msg.payload; + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_DG_VERSION; + msg.hdr.payloadLen = sizeof( DG_VERSIONS_T ); + if ( message->hdr.payloadLen == sizeof( U08 ) + sizeof( U08 ) + sizeof( U08 ) + sizeof( U16 ) + sizeof( U32 ) ) { // populate payload @@ -486,11 +492,6 @@ payload.compatibilityRev = (U32)SW_COMPATIBILITY_REV; getFPGAVersions( &payload.fpgaId, &payload.fpgaMajor, &payload.fpgaMinor, &payload.fpgaLab ); - // create a message record - blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_DG_VERSION; - msg.hdr.payloadLen = sizeof( DG_VERSIONS_T ); - // fill message payload memcpy( payloadPtr, &payload, sizeof( DG_VERSIONS_T ) ); } @@ -547,27 +548,27 @@ { MESSAGE_T msg; DG_SERVICE_RECORD_T service; + U08 *payloadPtr = msg.payload; // Get the service record. There are no arrays of service to check and also, raise no alarm since the service record // has been already checked in POST getNVRecord2Driver( GET_SRV_RECORD, (U08*)&service, sizeof( DG_SERVICE_RECORD_T ), 0, ALARM_ID_NO_ALARM ); - U08 *payloadPtr = msg.payload; - if ( message->hdr.payloadLen == sizeof( U32 ) + sizeof( U32 ) ) - { - // Create a message record - blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_DG_SERVICE_SCHEDULE_DATA; - msg.hdr.payloadLen = sizeof( U32 ) + sizeof( U32 ); + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_DG_SERVICE_SCHEDULE_DATA; + msg.hdr.payloadLen = sizeof( U32 ) + sizeof( U32 ); + if ( 0 == message->hdr.payloadLen ) + { // Fill message payload memcpy( payloadPtr, &service.lastServiceEpochDate, sizeof( U32 ) ); payloadPtr += sizeof( U32 ); memcpy( payloadPtr, &service.serviceIntervalSeconds, sizeof( U32 ) ); } // 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 ); + serializeMessage( msg, COMM_BUFFER_OUT_CAN_DG_2_HD, ACK_REQUIRED ); } /*********************************************************************//** @@ -728,45 +729,6 @@ /*********************************************************************//** * @brief - * The sendDGServiceRecord function sends out the DG service record. - * @details Inputs: none - * @details Outputs: DG system record msg constructed and queued - * @param msgCurrNum: current payload number - * @param msgTotalNum: total number of payloads - * @param length: buffer length to be written - * @param scheduledRcrdAddress: start address of the scheduled runs record - * @return TRUE if msg successfully queued for transmit, FALSE if not - *************************************************************************/ -BOOL sendDGScheduledRunsRecord( U32 payloadCurrNum, U32 payloadTotalNum, U32 length, U08* scheduledRcrdAddress ) -{ - BOOL result; - MESSAGE_T msg; - U08 *payloadPtr = msg.payload; - - // Create a message record - blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_DG_SEND_SCHEDULED_RUNS_RECORD; - msg.hdr.payloadLen = sizeof( U32 ) + sizeof( U32 ) + sizeof( U32 ) + length; - - memcpy( payloadPtr, &payloadCurrNum, sizeof( U32 ) ); - payloadPtr += sizeof( U32 ); - - memcpy( payloadPtr, &payloadTotalNum, sizeof( U32 ) ); - payloadPtr += sizeof( U32 ); - - memcpy( payloadPtr, &length, sizeof( U32 ) ); - payloadPtr += sizeof( U32 ); - - memcpy( payloadPtr, scheduledRcrdAddress, length ); - - // 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_PC, ACK_NOT_REQUIRED ); - - return result; -} - -/*********************************************************************//** - * @brief * The sendPOSTTestResult function constructs an DG POST test result message * and queues the msg for transmit on the appropriate CAN channel. * @details Inputs: none @@ -866,37 +828,6 @@ } /*********************************************************************//** - * @brief - * The handleDGScheduledRunsRequest function handles a request for DG - * scheduled runs information. - * @details Inputs: none - * @details Outputs: message handled, response constructed and queued for - * transmit. - * @return none - *************************************************************************/ -void handleDGScheduledRunsRequest( MESSAGE_T *message ) -{ - MESSAGE_T msg; - DG_SCHEDULED_RUN_RECORD_T scheduledService; - - // Get the service record. There are no arrays of service to check and also, raise no alarm since the service record - // has been already checked in POST - getNVRecord2Driver( GET_SRR_RECORD, (U08*)&scheduledService, sizeof( DG_SCHEDULED_RUN_RECORD_T ), 0, ALARM_ID_NO_ALARM ); - - U08 *payloadPtr = msg.payload; - - // Create a message record - blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_DG_SCHEDULED_RUNS_DATA; - msg.hdr.payloadLen = sizeof( U32 ) + sizeof( U32 ); - - // TODO this message is for Phase 1B. - - // 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 ); -} - -/*********************************************************************//** * @brief * The handleStartStopDGFlush function handles a request to start or stop * DG flush mode. @@ -1134,12 +1065,7 @@ if ( TRUE == isSet ) { -#ifndef _RELEASE_ - if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_TRIMMER_HEATER ) != SW_CONFIG_ENABLE_VALUE ) -#endif - { - startHeater( DG_TRIMMER_HEATER ); - } + startHeater( DG_TRIMMER_HEATER ); } else { @@ -1392,6 +1318,56 @@ /*********************************************************************//** * @brief + * The handleTestSetOpModeRequest function handles a request to set the + * DG operation mode. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTestSetOpModeRequest( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + if ( message->hdr.payloadLen == sizeof(U32) ) + { + U32 mode; + + memcpy( &mode, message->payload, sizeof(U32) ); + result = testSetOperationMode( (DG_OP_MODE_T)mode ); + } + + // Respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** + * @brief + * The handleTestTareReservoirRequest function handles a request to tare a + * given reservoir's weight. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTestTareReservoirRequest( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + if ( message->hdr.payloadLen == sizeof(U32) ) + { + U32 res; + + memcpy( &res, message->payload, sizeof(U32) ); + result = testTareReservoir( res ); + } + + // Respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** + * @brief * The handleSetHDOperationMode function receives the HD operation modes data * publish message. * @details Inputs: none @@ -1407,8 +1383,8 @@ // HD mode broadcast is operations mode and submode so 8 bytes if ( message->hdr.payloadLen == sizeof( U32 ) + sizeof( U32 ) ) { - U32 mode; - U32 subMode; + U32 mode = 0; + U32 subMode = 0; memcpy( payloadPtr, &mode, sizeof( U32 ) ); payloadPtr += sizeof( U32 ); @@ -1421,7 +1397,45 @@ return status; } +/*********************************************************************//** + * @brief + * The handleHDRequestDGUsageInfo function handles a request for DG + * usage information. + * @details Inputs: none + * @details Outputs: message handled, response constructed and queued for + * transmit. + * @return none + *************************************************************************/ +void handleHDRequestDGUsageInfo( MESSAGE_T * message ) +{ + MESSAGE_T msg; + DG_USAGE_INFO_RECORD_T usageInfo; + U08 *payloadPtr = msg.payload; + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_DG_USAGE_DATA; + msg.hdr.payloadLen = sizeof( U32 ) + sizeof( U32 ) + sizeof( BOOL ); + + // Get the service record. There are no arrays of service to check and also, raise no alarm since the service record + // has been already checked in POST + getNVRecord2Driver( GET_USAGE_RECORD, (U08*)&usageInfo, sizeof( DG_USAGE_INFO_RECORD_T ), 0, ALARM_ID_NO_ALARM ); + + if ( 0 == message->hdr.payloadLen ) + { + // Fill message payload + memcpy( payloadPtr, &usageInfo.lastHeatDisDateEpoch, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &usageInfo.lastChemicalDisDateEpoch, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &usageInfo.isDisinfected, sizeof( BOOL ) ); + } + + // 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 ); +} + + // *********************************************************************** // **************** Message Handling Helper Functions ******************** // *********************************************************************** @@ -1571,20 +1585,26 @@ *************************************************************************/ void handleTestLoadCellOverrideRequest( MESSAGE_T *message ) { - TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + typedef struct + { + TEST_OVERRIDE_ARRAY_PAYLOAD_T ovRecord; + BOOL flag; + } LC_OVERRIDE_PAYLOAD_T; + + LC_OVERRIDE_PAYLOAD_T payload; BOOL result = FALSE; // verify payload length - if ( sizeof( TEST_OVERRIDE_ARRAY_PAYLOAD_T ) == message->hdr.payloadLen ) + if ( sizeof( LC_OVERRIDE_PAYLOAD_T ) == message->hdr.payloadLen ) { - memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_ARRAY_PAYLOAD_T ) ); - if ( FALSE == payload.reset ) + memcpy( &payload, message->payload, sizeof( LC_OVERRIDE_PAYLOAD_T ) ); + if ( FALSE == payload.ovRecord.reset ) { - result = testSetLoadCellOverride( payload.index, payload.state.f32 ); + result = testSetLoadCellOverride( payload.ovRecord.index, payload.ovRecord.state.f32, payload.flag ); } else { - result = testResetLoadCellOverride( payload.index ); + result = testResetLoadCellOverride( payload.ovRecord.index, payload.flag ); } } @@ -1785,32 +1805,31 @@ sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); } - /*********************************************************************//** * @brief - * The handleTestROMeasuredFlowOverrideRequest function handles a request to - * override the RO flow rate. + * The handleTestMeasuredFlowOverrideRequest function handles a request to + * override the measured flow sensor rate. * @details Inputs: none * @details Outputs: message handled * @param message a pointer to the message to handle * @return none *************************************************************************/ -void handleTestROMeasuredFlowOverrideRequest( MESSAGE_T *message ) +void handleTestMeasuredFlowOverrideRequest( 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 = testSetMeasuredROFlowRateOverride( payload.state.f32 ); + result = testSetMeasuredFlowRateOverride( payload.index, payload.state.f32 ); } else { - result = testResetMeasuredROFlowRateOverride(); + result = testResetMeasuredFlowRateOverride( payload.index ); } } @@ -1820,38 +1839,6 @@ /*********************************************************************//** * @brief - * The handleTestDialysateMeasuredFlowOverrideRequest function handles a request to - * override the Dialysate flow rate. - * @details Inputs: none - * @details Outputs: message handled - * @param message a pointer to the message to handle - * @return none - *************************************************************************/ -void handleTestDialysateMeasuredFlowOverrideRequest( 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 = testSetMeasuredDialysateFlowRateOverride( payload.state.f32 ); - } - else - { - result = testResetMeasuredDialysateFlowRateOverride(); - } - } - - // respond to request - sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); -} - -/*********************************************************************//** - * @brief * The handleTestROPumpDataBroadcastIntervalOverrideRequest function handles * a request to override the broadcast interval for RO pump data. * @details Inputs: none @@ -1884,14 +1871,14 @@ /*********************************************************************//** * @brief - * The handleTestDialysateFlowDataBroadcastIntervalOverrideRequest function handles - * a request to override the broadcast interval for dialysate flow data. + * The handleTestFlowSensorsDataBroadcastIntervalOverrideRequest function handles + * a request to override the broadcast interval for the flow sensors data. * @details Inputs: none * @details Outputs: message handled * @param message a pointer to the message to handle * @return none *************************************************************************/ -void handleTestDialysateFlowDataBroadcastIntervalOverrideRequest( MESSAGE_T *message ) +void handleTestFlowSensorsDataBroadcastIntervalOverrideRequest( MESSAGE_T *message ) { TEST_OVERRIDE_PAYLOAD_T payload; BOOL result = FALSE; @@ -1902,11 +1889,11 @@ memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_PAYLOAD_T ) ); if ( FALSE == payload.reset ) { - result = testSetDialysateFlowDataPublishIntervalOverride( payload.state.u32 ); + result = testSetFlowDataPublishIntervalOverride( payload.state.u32 ); } else { - result = testResetDialysateFlowDataPublishIntervalOverride(); + result = testResetFlowDataPublishIntervalOverride(); } } @@ -3074,76 +3061,20 @@ U32 totalMessages; U32 payloadLength; - memcpy(¤tMessage, payloadPtr, sizeof(U32)); - payloadPtr += sizeof(U32); - - memcpy(&totalMessages, payloadPtr, sizeof(U32)); - payloadPtr += sizeof(U32); - - memcpy(&payloadLength, payloadPtr, sizeof(U32)); - payloadPtr += sizeof(U32); - - status = receiveRecordFromDialin( NVDATAMGMT_SERVICE_RECORD, currentMessage, totalMessages, payloadLength, payloadPtr ); - - // Respond to request - sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, status ); -} - -/*********************************************************************//** -* @brief -* The handleGetDGServiceRecord function handles a request to get the DG -* scheduled runs data record. -* @details Inputs: none -* @details Outputs: message handled -* @param message a pointer to the message to handle -* @return none -*************************************************************************/ -void handleGetDGScheduledRunsRecord( MESSAGE_T *message ) -{ - BOOL result = FALSE; - - // verify payload length if ( 0 == message->hdr.payloadLen ) { - // Tester must be logged in - if ( TRUE == isTestingActivated() ) - { - result = sendRecordToDialin( NVDATAMGMT_SCHEDULED_RUNS_RECORD ); - } - } + memcpy(¤tMessage, payloadPtr, sizeof(U32)); + payloadPtr += sizeof(U32); - // respond to request - sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); -} + memcpy(&totalMessages, payloadPtr, sizeof(U32)); + payloadPtr += sizeof(U32); -/*********************************************************************//** -* @brief -* The handleSetDGScheduledRunsRecord function handles a request to set the DG -* scheduled runs data record. -* @details Inputs: none -* @details Outputs: message handled -* @param message a pointer to the message to handle -* @return none -*************************************************************************/ -void handleSetDGScheduledRunsRecord( MESSAGE_T *message ) -{ - BOOL status = FALSE; - U08* payloadPtr = message->payload; - U32 currentMessage; - U32 totalMessages; - U32 payloadLength; + memcpy(&payloadLength, payloadPtr, sizeof(U32)); + payloadPtr += sizeof(U32); - memcpy(¤tMessage, payloadPtr, sizeof(U32)); - payloadPtr += sizeof(U32); + status = receiveRecordFromDialin( NVDATAMGMT_SERVICE_RECORD, currentMessage, totalMessages, payloadLength, payloadPtr ); + } - memcpy(&totalMessages, payloadPtr, sizeof(U32)); - payloadPtr += sizeof(U32); - - memcpy(&payloadLength, payloadPtr, sizeof(U32)); - payloadPtr += sizeof(U32); - - status = receiveRecordFromDialin( NVDATAMGMT_SCHEDULED_RUNS_RECORD, currentMessage, totalMessages, payloadLength, payloadPtr ); - // Respond to request sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, status ); } @@ -3553,7 +3484,7 @@ memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_PAYLOAD_T ) ); if ( FALSE == payload.reset ) { - result = testSetHDCommunicationStatus(payload.state.u32); + result = testSetHDCommunicationStatus( payload.state.u32 ); } else { @@ -3566,6 +3497,39 @@ } /*********************************************************************//** + * @brief + * The handleSetPrimaryAndTrimmerHeatersTargetTemperature function handles + * setting primary and trimmer heaters target temperature. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSetPrimaryAndTrimmerHeatersTargetTemperature( MESSAGE_T *message ) +{ + BOOL status = FALSE; + U08* payloadPtr = message->payload; + + if ( message->hdr.payloadLen >= ( sizeof( F32 ) + sizeof( F32 ) ) ) + { + F32 primaryTargetTemp = 0.0F; + F32 trimmerTargetTemp = 0.0F; + status = TRUE; + + memcpy( &primaryTargetTemp, payloadPtr, sizeof( F32 ) ); + payloadPtr += sizeof( F32 ); + + memcpy( &trimmerTargetTemp, payloadPtr, sizeof( F32 ) ); + + setHeaterTargetTemperature( DG_PRIMARY_HEATER, primaryTargetTemp ); + setHeaterTargetTemperature( DG_TRIMMER_HEATER, trimmerTargetTemp ); + } + + // Respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, status ); +} + +/*********************************************************************//** * @brief * The handleGetDGUsageInfoRecord function handles a request to get the DG * usage information record. @@ -3691,4 +3655,73 @@ sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); } +/*********************************************************************//** +* @brief +* The handleServiceModeRequest function handles a request to enter service +* mode. +* @details Inputs: none +* @details Outputs: message handled +* @param message a pointer to the message to handle +* @return none +*************************************************************************/ +void handleServiceModeRequest( MESSAGE_T *message ) +{ + BOOL status = FALSE; + DG_OP_MODE_T currentMode = getCurrentOperationMode(); + REQUEST_REJECT_REASON_CODE_T reject; + + if ( 0 == message->hdr.payloadLen ) + { + if ( ( DG_MODE_STAN == currentMode ) || ( DG_MODE_FAUL == currentMode ) ) + { + status = TRUE; + requestNewOperationMode( DG_MODE_SERV ); + reject = REQUEST_REJECT_REASON_NONE; + } + else + { + reject = REQUEST_REJECT_REASON_DG_NOT_IN_STANDBY_IDLE_STATE; + } + } + else + { + reject = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + + // Respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, status ); + sendServiceModeResponse( status, (U32)reject ); +} + +/*********************************************************************//** + * @brief + * The sendServiceModeResponse function sends out the DG response to a + * UI request to go to service mode. + * @details Inputs: none + * @details Outputs: Service mode request response msg constructed and queued + * @param accepted TRUE if request was accepted, FALSE if not + * @param rejCode Reject reason code explaining why request was rejected + * @return none + *************************************************************************/ +BOOL sendServiceModeResponse( BOOL accepted, U32 rejCode ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_DG_RESPONSE_SERVICE_MODE_REQUEST; + msg.hdr.payloadLen = sizeof( BOOL ) + sizeof( U32 ); + + memcpy( payloadPtr, &accepted, sizeof( BOOL ) ); + payloadPtr += sizeof( BOOL ); + memcpy( payloadPtr, &rejCode, 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_DG_2_HD, ACK_REQUIRED ); + + return result; +} + /**@}*/