Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -ref330fd4007687c0b5014a49f4715ea481a9df2e -r4c26b49a73736fa697bf7565dd7685c4e1cd599a --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision ef330fd4007687c0b5014a49f4715ea481a9df2e) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 4c26b49a73736fa697bf7565dd7685c4e1cd599a) @@ -1,14 +1,14 @@ /************************************************************************** * -* Copyright (c) 2019-2023 Diality Inc. - All Rights Reserved. +* Copyright (c) 2019-2024 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file SystemCommMessages.c * * @author (last) Dara Navaei -* @date (last) 20-Oct-2023 +* @date (last) 10-May-2024 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -61,10 +61,39 @@ /// Payload record structure for block message transmission request. typedef struct { - U16 blockedMessages[ MAX_MSGS_BLOCKED_FOR_XMIT ]; + U16 blockedMessages[ MAX_MSGS_BLOCKED_FOR_XMIT ]; ///< Blocked messages. } BLOCKED_MSGS_DATA_T; #pragma pack(pop) +typedef struct +{ + U32 minBloodFlowMLPM; ///< Min blood flow in mL/min. + U32 maxBloodFlowMLPM; ///< Max blood flow in mL/min. + U32 minDialysateFlowMLPM; ///< Min dialysate flow in mL/min. + U32 maxDialysateFlowMLPM; ///< Max dialysate flow in mL/min. + U32 minTxDurationMIN; ///< Min treatment duration in minutes. + U32 maxTxDurationMIN; ///< Max treatment duration in minutes. + U32 minStopHeparinDispBeforeTxEndMIN; ///< Min stop heparin dispense before treatment end in minutes. + U32 maxStopHeparinDispBeforeTxEndMIN; ///< Max stop heparin dispense before treatment end in minutes. + U32 minSalineBolusVolumeML; ///< Min saline bolus volume in milliliters. + U32 maxSalineBolusVolumeML; ///< Max saline bolus volume in milliliters. + F32 minDialysateTempC; ///< Min dialysate temperature in C. + F32 maxDialysateTempC; ///< Max dialysate temperature in C. + S32 minArtPressLimitWindowMMHG; ///< Min arterial pressure limit window in mmHg. + S32 maxArtPressLimitWindowMMHG; ///< Max arterial pressure limit window in mmHg. + S32 minVenPressLimitWindowMMHG; ///< Min venous pressure limit window in mmHg. + S32 maxVenPressLimitWindowMMHG; ///< Max venous pressure limit window in mmHg. + S32 minVenAsymPressLimitMMHG; ///< Min venous asymmetric pressure limit in mmHg. + S32 maxVenAsymPressLimitMMHG; ///< Max venous asymmetric pressure limit in mmHg. + F32 minUFVolumeL; ///< Min ultrafiltration volume in mL. + F32 maxUFVolumeL; ///< Max ultrafiltration volume in mL. + F32 minHeparinDispRateMLPHR; ///< Min heparin dispense rate in mL/hr. + F32 maxHeparinDispRateMLPHR; ///< Max heparin dispense rate in mL/hr. + F32 minHeparinBolusVolumeML; ///< Min heparin bolus volume in mL. + F32 maxHeparinBolusVolumeML; ///< Max heparin bolus volume in mL. + U32 enableChemicalDisinfect; ///< Enable/disable chemical disinfect. +} HD_INSTITUTIONAL_LOCAL_RECORD_T; + // ********** private data ********** static BOOL testerLoggedIn = FALSE; ///< Flag indicates whether an external tester (connected PC) has sent a valid login message. @@ -78,6 +107,7 @@ static BOOL sendTestAckResponseMsg( MSG_ID_T msgID, 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 ); +static void sendInstitutionalRecordToUI( HD_INSTITUTIONAL_LOCAL_RECORD_T* instit ); /*********************************************************************//** * @brief @@ -855,7 +885,7 @@ } else if ( DG_DISINFECT_CHEM_FLUSH_STATE == cmd ) // Command 3 = chemical disinfect flush { - result = signalUserInitiateChemcialDisinfectFlushMode(); + result = signalUserInitiateChemicalDisinfectFlushMode(); } else if ( DG_DISINFECT_RO_PERMEATE_SAMPLE_STATE == cmd ) // Command 4 = RO permeate sample { @@ -1060,22 +1090,22 @@ * @param almData1 data associates with the alarm * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ -BOOL sendTreatmentLogAlarmEventData( ALARM_ID_T alarmID, ALARM_DATA_T almData1, ALARM_DATA_T almData2 ) +BOOL sendTreatmentLogAlarmEventData( ALARM_ID_T alarmID, F32 alarmData1, F32 alarmData2 ) { MESSAGE_T msg; U08 *payloadPtr = msg.payload; - U32 id = (U32)alarmID; + U32 id = (U32)alarmID; // Create a message record blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_HD_TREATMENT_LOG_ALARM_EVENT; + msg.hdr.msgID = MSG_ID_HD_TREATMENT_LOG_ALARM_EVENT; msg.hdr.payloadLen = sizeof( U32 ) + 2 * sizeof( F32 ); memcpy( payloadPtr, &id, sizeof( U32 ) ); payloadPtr += sizeof( U32 ); - memcpy( payloadPtr, &almData1.data, sizeof( F32 ) ); + memcpy( payloadPtr, &alarmData1, sizeof( F32 ) ); payloadPtr += sizeof( F32 ); - memcpy( payloadPtr, &almData2.data, sizeof( F32 ) ); + memcpy( payloadPtr, &alarmData2, sizeof( F32 ) ); // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer return serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_UI, ACK_REQUIRED ); @@ -1659,16 +1689,17 @@ *************************************************************************/ void handleUIClockSyncRequest( MESSAGE_T *message ) { - BOOL result = FALSE; - U32 rejReason = REQUEST_REJECT_REASON_NONE; MESSAGE_T msg; - U08 *payloadPtr = msg.payload; + BOOL result = FALSE; + U32 rejReason = REQUEST_REJECT_REASON_NONE; + U08 *payloadPtr = msg.payload; + U32 *messagePayload = (U32*)message->payload; if ( message->hdr.payloadLen == sizeof( U32 ) ) { U32 epoch; - memcpy( &epoch, message->payload, sizeof( U32 ) ); + memcpy( &epoch, messagePayload, sizeof( U32 ) ); result = setRTCEpoch( epoch ); if ( FALSE == result ) { @@ -1986,7 +2017,7 @@ * @brief * The sendHDServiceRecord function sends out the HD service record. * @details Inputs: none - * @details Outputs: HD system record msg constructed and queued + * @details Outputs: HD service record msg constructed and queued * @param msgCurrNum: current payload number * @param msgTotalNum: total number of payloads * @param length: buffer length to be written @@ -3291,8 +3322,14 @@ *************************************************************************/ void handleHDSerialNumberRequest( void ) { + typedef struct + { + U08 topLevelSN[ MAX_TOP_LEVEL_SN_CHARS ]; + } LOCAL_TOP_SN_T; MESSAGE_T msg; HD_SYSTEM_RECORD_T system; + U08 i; + LOCAL_TOP_SN_T localTopLevelSN; // Get the system's record. There are no arrays of system to check and also, raise no alarm since the system record // has been already checked in POST @@ -3307,8 +3344,15 @@ // Add 1 byte for null terminator msg.hdr.payloadLen = MAX_TOP_LEVEL_SN_CHARS + 1; + for ( i = 0; i < MAX_TOP_LEVEL_SN_CHARS; i++ ) + { + // NOTE: A local variable was created to avoid system.topLevelSN in the messages list + // NOTE: For loop was used instead of memory copy to ensure it is not parsed in the messages list script + localTopLevelSN.topLevelSN[ i ] = system.topLevelSN[ i ]; + } + // Fill message payload - memcpy( payloadPtr, &system.topLevelSN, sizeof( U08 ) * MAX_TOP_LEVEL_SN_CHARS ); + memcpy( payloadPtr, &localTopLevelSN, sizeof( LOCAL_TOP_SN_T ) ); payloadPtr += MAX_TOP_LEVEL_SN_CHARS; *payloadPtr = 0; @@ -3361,11 +3405,13 @@ if ( 0 == message->hdr.payloadLen ) { + U32 lastServiceEpochDate = service.lastServiceEpochDate; + U32 serviceIntervalSeconds = ( 0 == service.lastServiceEpochDate ? 0 : service.serviceIntervalSeconds ); + // Fill message payload - memcpy( payloadPtr, &service.lastServiceEpochDate, sizeof( U32 ) ); + memcpy( payloadPtr, &lastServiceEpochDate, sizeof( U32 ) ); payloadPtr += sizeof( U32 ); - service.serviceIntervalSeconds = ( 0 == service.lastServiceEpochDate ? 0 : service.serviceIntervalSeconds ); - memcpy( payloadPtr, &service.serviceIntervalSeconds, sizeof( U32 ) ); + memcpy( payloadPtr, &serviceIntervalSeconds, sizeof( U32 ) ); } // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer @@ -3590,7 +3636,85 @@ } } +/*********************************************************************//** + * @brief + * The handleSendInstitutionalRecordToUI function sends the institutional record to UI + * @details Inputs: none + * @details Outputs: none + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSendInstitutionalRecordToUI( MESSAGE_T* message ) +{ + if ( 0 == message->hdr.payloadLen ) + { + HD_INSTITUTIONAL_RECORD_T hdInstitutionalRecord; + HD_INSTITUTIONAL_LOCAL_RECORD_T hdInstitutionalLocalRecord; + getNVRecord2Driver( GET_INSTITUTIONAL_RECORD, (U08*)&hdInstitutionalRecord, sizeof( HD_INSTITUTIONAL_RECORD_T ), 0, ALARM_ID_NO_ALARM ); + + memcpy( &hdInstitutionalLocalRecord, &hdInstitutionalRecord, sizeof( HD_INSTITUTIONAL_LOCAL_RECORD_T ) ); + + sendInstitutionalRecordToUI( &hdInstitutionalLocalRecord ); + } +} + +/*********************************************************************//** + * @brief + * The sendInstitutionalRecordToUI function sends the institutional record to UI + * @details Inputs: none + * @details Outputs: none + * @param instit a pointer to the local institutional recored in the system + * messages that is without calibration time and crc + * @return none + *************************************************************************/ +static void sendInstitutionalRecordToUI( HD_INSTITUTIONAL_LOCAL_RECORD_T* instit ) +{ + MESSAGE_T msg; + + U08 *payloadPtr = msg.payload; + U32 accept = 1; + U32 reason = 0; + + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_INSTITUTIONAL_RECORD_RESPONSE; + msg.hdr.payloadLen = sizeof( U32 ) + sizeof( U32 ) + sizeof( HD_INSTITUTIONAL_LOCAL_RECORD_T ); + + memcpy( payloadPtr, &accept, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &reason, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, instit, sizeof( HD_INSTITUTIONAL_LOCAL_RECORD_T ) ); + + // 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_HD_2_UI, ACK_NOT_REQUIRED ); +} + +/*********************************************************************//** + * @brief + * The handleUIHDResetInServiceModeRequest function handles the UI request + * to reset HD in service mode + * @details Inputs: none + * @details Outputs: none + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleUIHDResetInServiceModeRequest( MESSAGE_T* message ) +{ + // Verify payload length + if ( ( 0 == message->hdr.payloadLen ) && ( MODE_SERV == getCurrentOperationMode() ) ) + { +#ifndef _VECTORCAST_ + systemREG1->SYSECR = (0x2) << 14; // Reset processor +#endif + } + + // Respond to request + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ @@ -4492,6 +4616,70 @@ /*********************************************************************//** * @brief + * The handleTestFilteredBloodPumpOcclusionOverrideRequest function handles a request to + * override the filtered blood pump occlusion sensor readings. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTestFilteredBloodPumpOcclusionOverrideRequest( 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 = testSetFilteredBloodPumpOcclusionOverride( payload.state.f32 ); + } + else + { + result = testResetFilteredBloodPumpOcclusionOverride(); + } + } + + // Respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** + * @brief + * The handleTestBloodPumpOcclusionBaselineOverrideRequest function handles a request to + * override the blood pump occlusion baseline value. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTestBloodPumpOcclusionBaselineOverrideRequest( 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 = testSetBloodPumpPartialOcclusionBaselineOverride( payload.state.f32 ); + } + else + { + result = testResetBloodPumpPartialOcclusionBaselineOverride(); + } + } + + // Respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** + * @brief * The handleTestPresOcclBroadcastIntervalOverrideRequest function handles a request to * override the broadcast interval for pressure/occlusion data. * @details Inputs: none @@ -5207,6 +5395,38 @@ /*********************************************************************//** * @brief + * The handleSetRawAirTrapLevelSensorOverrideRequest function handles a request to + * override an air trap level sensor raw value. + * @details Inputs: none + * @details Outputs: message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSetRawAirTrapLevelSensorOverrideRequest( MESSAGE_T *message ) +{ + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + BOOL result = FALSE; + + // Verify payload length + if ( sizeof( TEST_OVERRIDE_ARRAY_PAYLOAD_T ) == message->hdr.payloadLen ) + { + memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_ARRAY_PAYLOAD_T ) ); + if ( FALSE == payload.reset ) + { + result = testSetRawAirTrapLevelOverride( (AIR_TRAP_LEVEL_SENSORS_T)payload.index, (AIR_TRAP_LEVELS_T)( payload.state.u32 ) ); + } + else + { + result = testResetRawAirTrapLevelOverride( (AIR_TRAP_LEVEL_SENSORS_T)payload.index ); + } + } + + // Respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** + * @brief * The handleSetFluidLeakBroadcastIntervalOverrideRequest function handles a * request to override the fluid leak state broadcast interval. * @details Inputs: none @@ -8596,4 +8816,106 @@ } } +/*********************************************************************//** +* @brief +* The handleGetHDInstitutionalRecord function handles a request to get the HD +* institutional record. +* @details Inputs: none +* @details Outputs: message handled +* @param message a pointer to the message to handle +* @return none +*************************************************************************/ +void handleGetHDInstitutionalRecord( 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_INTITUTIONAL_RECORD ); + } + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** + * @brief + * The sendHDInstitutionalRecord function sends out the HD institutional record. + * @details Inputs: none + * @details Outputs: HD institutional record msg constructed and queued + * @param msgCurrNum: current payload number + * @param msgTotalNum: total number of payloads + * @param length: buffer length to be written + * @param srvcRcrdAddress: start address of the institutional record + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL sendHDInstitutionalRecord( U32 payloadCurrNum, U32 payloadTotalNum, U32 length, U08* srvcRcrdAddress ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_SEND_INSTITUTIONAL_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, srvcRcrdAddress, 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 handleSetHDInstitutionalRecord function handles a request to set the HD +* institutional data record. +* @details Inputs: none +* @details Outputs: message handled +* @param message a pointer to the message to handle +* @return none +*************************************************************************/ +void handleSetHDInstitutionalRecord( MESSAGE_T *message ) +{ + BOOL status = FALSE; + U08* payloadPtr = message->payload; + U32 currentMessage; + U32 totalMessages; + U32 payloadLength; + + if ( ( message->hdr.payloadLen >= ( sizeof(currentMessage) + sizeof(totalMessages) + sizeof(payloadLength) ) ) && + ( MODE_SERV == getCurrentOperationMode() ) ) + { + 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_INTITUTIONAL_RECORD, currentMessage, totalMessages, payloadLength, payloadPtr ); + } + + // Respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, status ); +} + /**@}*/