/************************************************************************** * * Copyright (c) 2026-2027 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 NVMessagingDD.c * * @author (original) Arpita Srivastava * @date (original) 31-Mar-2026 * ***************************************************************************/ #include // For ceilf function #include "Messaging.h" #include "NVJobQ.h" #include "NVMessagingDD.h" #include "NVRecordsDD.h" #include "OperationModes.h" #include "TaskGeneral.h" #include "Timers.h" #include "Utilities.h" // For crc calculation /** * @addtogroup NVMessagingDD * @{ */ // ********** private definitions ********** #define NEW_CAL_AVAILABLE_SIGNAL_TIMEOUT_MS (1 * MS_PER_SECOND) ///< New calibration available signal timeout in milliseconds. #define NUM_OF_BYTES_PER_RECORD_PAYLOAD ( MAX_MSG_PAYLOAD_SIZE - ( sizeof( U32 ) ) ) ///< Number of bytes per calibration payload. #define RECORD_DATA_SEND_INTERVAL_COUNT (MS_PER_SECOND / (5 * TASK_GENERAL_INTERVAL)) ///< Calibration data send time interval in counts. #define RECORD_DATA_RECEIVE_TIMEOUT_MS (4 * MS_PER_SECOND) ///< Record data receive all the data packets timeout in ms. #define RECORD_DATA_MAX_MESSAGE_DFFIRENCE 1 ///< Calibration data receive message different from the previous message. #define RECORD_DATA_FIRST_RECEIVING_MSG_NUM 1 ///< Calibration data first receiving message number. #define MAX_NUM_OF_SEND_RETRIES 5 ///< Maximum number of retries to send a record /// NVM send records states typedef enum NVM_Send_Records_States { NVM_SEND_RECORD_STATE_IDLE = 0, ///< NVM process record idle state. NVM_SEND_RECORD_STATE_SEND, ///< NVM process record send record state. NUM_OF_NVM_SEND_RECORD_STATES ///< Number of NVM process records state. } SEND_RECORD_STATE_T; /// NVM receive records states typedef enum NVM_Receive_Records_States { NVM_RECEIVE_RECORD_STATE_IDLE = 0, ///< NVM receive record idle. NVM_RECEIVE_RECORD_STATE_RECEIVE, ///< NVM receive record receive. NUM_OF_NVM_RECEIVE_RECORD_STATES ///< Number of NVM receive record. } RECEIVE_RECORD_STATE_T; #pragma pack(push, 1) /// DD NVM Record Payload typedef struct { U08 idx; ///< Index of sensor / pump / concentrates U08 data[ NUM_OF_BYTES_PER_RECORD_PAYLOAD ]; ///< Data to be sent } DD_NVM_RECORD_PAYLOAD_T; /// DD NVM Get System Record Response Payload typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Rejection reason if not accepted. DD_SYSTEM_RECORD_T data; ///< Data to be sent }DD_NVM_GET_SYSTEM_REC_PAYLOAD_T /// DD NVM Set System Record Response Payload typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Reason to reject the entire request U32 isROFeaturedRejectReason; ///< Reason to reject System record parameter isROFeatured U32 isROFeaturedBoostPumpRejectReason; ///< Reason to reject System record parameter isROFeaturedBoostPump U32 topLevelPNRejectReason; ///< Reason to reject System record parameter topLevelPN[ MAX_TOP_LEVEL_PN_CHARS ] U32 topLevelSNRejectReason; ///< Reason to reject System record parameter topLevelSN[ MAX_TOP_LEVEL_SN_CHARS ] U32 mfgLocationRejectReason; ///< Reason to reject System record parameter mfgLocation U32 mfgDateRejectReason; ///< Reason to reject System record parameter mfgDate }DD_NVM_SET_SYSTEM_REC_PAYLOAD_T /// DD NVM Get Service Record Response Payload typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Rejection reason if not accepted. DD_SERVICE_RECORD_T data; ///< Data to be sent }DD_NVM_GET_SERVICE_REC_PAYLOAD_T /// DD NVM Set Service Record Response Payload typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Reason to reject the entire request U32 isHDFOnlineFluidAvailableRejectReason; ///< Reason to reject Service record parameter isHDFOnlineFluidAvailable U32 waterRecoveryRejectReason; ///< Reason to reject Service record parameter waterRecovery U32 serviceLocRejectReason; ///< Reason to reject Service record parameter serviceLoc U32 lastServiceEpochDateRejectReason; ///< Reason to reject Service record parameter lastServiceEpochDate U32 serviceIntervalSecondsRejectReason; ///< Reason to reject Service record parameter serviceIntervalSeconds U32 lastResetTimeEpochRejectReason; ///< Reason to reject Service record parameter lastResetTimeEpoch }DD_NVM_SET_SERVICE_REC_PAYLOAD_T /// DD NVM Get Usage Info Record Response Payload typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Rejection reason if not accepted. DD_USAGE_INFO_RECORD_T data; ///< Data to be sent }DD_NVM_GET_USAGE_INFO_REC_PAYLOAD_T /// DD NVM Set Usage Info Record Response Payload typedef struct { BOOL acceptedRejectReason; ///< Accepted/Rejected U32 rejectionReason; ///< Reason to reject the entire request U32 roWaterGenTotalLRejectReason; ///< Reason to reject Usage Info record parameter roWaterGenTotalL U32 roWaterGenSinceLastServiceLRejectReason; ///< Reason to reject Usage Info record parameter roWaterGenSinceLastServiceL U32 lastBasicFlushCompleteDateEpochRejectReason; ///< Reason to reject Usage Info record parameter lastBasicFlushCompleteDateEpoch U32 lastHeatDisCompleteDateEpochRejectReason; ///< Reason to reject Usage Info record parameter lastHeatDisCompleteDateEpoch U32 lastHeatActiveCoolCompleteDateEpochRejectReason; ///< Reason to reject Usage Info record parameter lastHeatActiveCoolCompleteDateEpoch U32 lastFilterFlushCompleteDateEpochRejectReason; ///< Reason to reject Usage Info record parameter lastFilterFlushCompleteDateEpoch U32 lastResetTimeEpochRejectReason; ///< Reason to reject Usage Info record parameter lastResetTimeEpoch }DD_NVM_SET_USAGE_INFO_REC_PAYLOAD_T /// Institutional data reject reason structure. typedef struct { U32 minRejectReason; ///< Reason to reject Institutional record parameter min U32 maxRejectReason; ///< Reason to reject Institutional record parameter max U32 defRejectReason; ///< Reason to reject Institutional record parameter def } INSTIT_DATA_REJECT_REASON_T; /// DD NVM Get Institutional Basic Record Response Payload typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Rejection reason if not accepted. DD_INSTIT_BASIC_RECORD_T data; ///< Data to be sent }DD_NVM_GET_INSTIT_BASIC_REC_PAYLOAD_T /// DD NVM Set Institutional Basic Record Response Payload typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Reason to reject the entire request INSTIT_DATA_REJECT_REASON_T param[ NUM_OF_INSTIT_BASIC ] ///< Reject reasons for each param of basic institutional record. }DD_NVM_SET_INSTIT_BASIC_REC_PAYLOAD_T /// DD NVM Get Institutional Advanced Record Response Payload typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Rejection reason if not accepted. DD_INSTIT_ADVANCED_RECORD_T data; ///< Data to be sent }DD_NVM_GET_INSTIT_ADVANCED_REC_PAYLOAD_T /// DD NVM Set Institutional Advanced Record Response Payload typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Reason to reject the entire request INSTIT_DATA_REJECT_REASON_T param[ NUM_OF_INSTIT_ADVANCED ] ///< Reject reasons for each param of advanced institutional record. }DD_NVM_SET_INSTIT_ADVANCED_REC_PAYLOAD_T /// DD NVM Get Institutional Additional Record Response Payload typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Rejection reason if not accepted. DD_INSTIT_ADDITIONAL_RECORD_T data; ///< Data to be sent }DD_NVM_GET_INSTIT_ADDITIONAL_REC_PAYLOAD_T /// DD NVM Set Institutional Additional Record Response Payload typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Reason to reject the entire request INSTIT_DATA_REJECT_REASON_T param[ NUM_OF_INSTIT_ADDITIONAL ] ///< Reject reasons for each param of Additional institutional record. }DD_NVM_SET_INSTIT_ADDITIONAL_REC_PAYLOAD_T /// Linear reject reason calibration structure typedef struct { U32 gainRejectReason; ///< Reason to reject linear calibration record parameter gain. U32 offsetRejectReason; ///< Reason to reject linear calibration record parameter offset. U32 calibrationTimeRejectReason; ///< Reason to reject linear calibration record parameter calibrationTime. } LINEAR_REJECT_REASON_CAL_PAYLOAD_T; /// DD NVM Get Record Payload for Linear structures Calibration Data typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Rejection reason if not accepted. U08 idx; ///< Index of sensor / pump / concentrates LINEAR_CAL_PAYLOAD_T data; ///< Data to be sent } DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T; /// DD NVM Set Record Payload for Linear structures Calibration Data typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Reason to reject the entire request U32 idxRejectReason; ///< Reason to reject sensor index of the calibration record LINEAR_REJECT_REASON_CAL_PAYLOAD_T data; ///< Linear record reject reasons } DD_NVM_SET_LINEAR_CAL_REC_PAYLOAD_T; /// DD NVM Get Record Payload for D12 Pump Calibration Data typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Rejection reason if not accepted. DD_D12_DIALYSATE_PUMP_RECORD_T data; ///< Data to be sent } DD_NVM_GET_D12_PUMP_CAL_REC_PAYLOAD_T; /// DD NVM Set Record Payload for D12 Pump Calibration Data typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Reason to reject the entire request U32 targetPumpSpeedRejectReason; ///< Reason to reject D12 pump calibration record parameter targetPumpSpeed U32 calibrationTimeRejectReason; ///< Reason to reject D12 pump calibration record parameter calibrationTime } DD_NVM_SET_D12_PUMP_CAL_REC_PAYLOAD_T; /// DD NVM Get Record Payload for D48 Pump Calibration Data typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Rejection reason if not accepted. LINEAR_CAL_PAYLOAD_T data; ///< Data to be sent } DD_NVM_GET_D48_PUMP_CAL_REC_PAYLOAD_T; /// DD NVM Set Record Payload for D48 Pump Calibration Data typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Reason to reject the entire request LINEAR_REJECT_REASON_CAL_PAYLOAD_T data; ///< Reason to reject D48 pump calibration record parameter } DD_NVM_SET_D48_PUMP_CAL_REC_PAYLOAD_T; /// DD NVM Get Record Payload for Acid Concentrate Calibration Data typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Rejection reason if not accepted. U08 idx; ///< Index of acid concentrates DD_ACID_CONCENTRATE_T data; ///< Data to be sent } DD_NVM_GET_ACID_CONC_CAL_REC_PAYLOAD_T; /// DD NVM Set Record Payload for Acid Concentrate Calibration Data typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Reason to reject the entire request U32 idxRejectReason; ///< Reason to reject Acid Conc index U32 acidConcMixRatioRejectReason; ///< Reason to reject Acid Conc calibration record parameter acidConcMixRatio U32 acidFullBottleVolumeMLRejectReason; ///< Reason to reject Acid Conc calibration record parameter acidFullBottleVolumeML U32 acidConductivityUSPerCMRejectReason; ///< Reason to reject Acid Conc calibration record parameter acidConductivityUSPerCM U32 acidBottleTemperatureRejectReason; ///< Reason to reject Acid Conc calibration record parameter acidBottleTemperature U32 calibrationTimeRejectReason; ///< Reason to reject Acid Conc calibration record parameter calibrationTime } DD_NVM_SET_ACID_CONC_CAL_REC_PAYLOAD_T; /// DD NVM Get Record Payload for Bicarb Concentrate Calibration Data typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Rejection reason if not accepted. U08 idx; ///< Index of bicarb concentrates DD_BICARB_CONCENTRATE_T data; ///< Data to be sent } DD_NVM_GET_BICARB_CONC_CAL_REC_PAYLOAD_T; /// DD NVM Set Record Payload for Bicarb Concentrate Calibration Data typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Reason to reject the entire request U08 idxRejectReason; ///< Reason to reject bicarb Conc index U32 bicarbConcMixRatioRejectReason; ///< Reason to reject bicarb Conc calibration record parameter bicarbConcMixRatio U32 bicarbStartVolumeMLRejectReason; ///< Reason to reject bicarb Conc calibration record parameter bicarbStartVolumeML U32 bicarbConductivityUSPerCMRejectReason; ///< Reason to reject bicarb Conc calibration record parameter bicarbConductivityUSPerCM U32 bicarbBottleTemperatureRejectReason; ///< Reason to reject bicarb Conc calibration record parameter bicarbBottleTemperature U32 calibrationTimeRejectReason; ///< Reason to reject bicarb Conc calibration record parameter calibrationTime } DD_NVM_SET_BICARB_CONC_CAL_REC_PAYLOAD_T; /// DD NVM Get Record Payload for Accelerometer Sensor Calibration Data typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Rejection reason if not accepted. DD_ACCEL_SENSOR_CAL_RECORD_T data; ///< Data to be sent } DD_NVM_GET_ACCEL_SENSOR_CAL_REC_PAYLOAD_T; /// DD NVM Set Record Payload for Accelerometer Sensor Calibration Data typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Reason to reject the entire request U32 accelXOffsetRejectReason; ///< Reason to reject accel sensor calibration record parameter accelXOffset U32 accelYOffsetRejectReason; ///< Reason to reject accel sensor calibration record parameter accelYOffset U32 accelZOffsetRejectReason; ///< Reason to reject accel sensor calibration record parameter accelZOffset U32 calibrationTimeRejectReason; ///< Reason to reject accel sensor calibration record parameter calibrationTime } DD_NVM_SET_ACCEL_SENSOR_CAL_REC_PAYLOAD_T; /// DD NVM Get Record Payload for Blood Leak Sensor Calibration Data typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Rejection reason if not accepted. DD_BLOOD_LEAK_SENSOR_CAL_RECORD_T data; ///< Data to be sent } DD_NVM_GET_BLOOD_LEAK_SENSOR_CAL_REC_PAYLOAD_T; /// DD NVM Set Record Payload for Blood Leak Sensor Calibration Data typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Reason to reject the entire request U32 setPointRejectReason; ///< Reason to reject blood leak sensor calibration record parameter setPoint U32 calibrationTimeRejectReason; ///< Reason to reject blood leak sensor calibration record parameter calibrationTime } DD_NVM_SET_BLOOD_LEAK_SENSOR_CAL_REC_PAYLOAD_T; /// DD NVM Get Record Payload for Conductivity Sensor Calibration Data typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Rejection reason if not accepted. U08 idx; ///< Index of conductivity sensor DD_CONDUCTIVITY_SENSOR_T data; ///< Data to be sent } DD_NVM_GET_CONDUCTIVITY_SENSOR_CAL_REC_PAYLOAD_T; /// DD NVM Set Record Payload for Conductivity Sensor Calibration Data typedef struct { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Reason to reject the entire request U32 idxRejectReason; ///< Reason to reject conductivity sensor index U32 coeff1RejectReason; ///< Reason to reject conductivity sensor calibration record parameter coeff1 U32 coeff2RejectReason; ///< Reason to reject conductivity sensor calibration record parameter coeff2 U32 coeff3RejectReason; ///< Reason to reject conductivity sensor calibration record parameter coeff3 U32 coeff4RejectReason; ///< Reason to reject conductivity sensor calibration record parameter coeff4 U32 coeff5RejectReason; ///< Reason to reject conductivity sensor calibration record parameter coeff5 U32 coeff6RejectReason; ///< Reason to reject conductivity sensor calibration record parameter coeff6 U32 coeff7RejectReason; ///< Reason to reject conductivity sensor calibration record parameter coeff7 U32 coeff8RejectReason; ///< Reason to reject conductivity sensor calibration record parameter coeff8 U32 coeff9RejectReason; ///< Reason to reject conductivity sensor calibration record parameter coeff9 U32 coeff10RejectReason; ///< Reason to reject conductivity sensor calibration record parameter coeff10 U32 coeff11RejectReason; ///< Reason to reject conductivity sensor calibration record parameter coeff11 U32 coeff12RejectReason; ///< Reason to reject conductivity sensor calibration record parameter coeff12 U32 calibrationTimeRejectReason; ///< Reason to reject conductivity sensor calibration record parameter calibrationTime } DD_NVM_SET_CONDUCTIVITY_SENSOR_CAL_REC_PAYLOAD_T; #pragma pack(pop) // ********** private data ********** static SEND_RECORD_STATE_T nvMExecSendRecordState; ///< NVM exec process record state. static RECEIVE_RECORD_STATE_T nvmExecreceiveRecordState; ///< NVM exec receive record state. static U32 newRecordStartTimer; ///< New record availability start timer. static BOOL isNewCalRecordAvailable; ///< Signal to indicate whether a new NVM data is available. static NVM_RECORD_ITEMS_T recordToPublish; ///< Record type which is being processed currently for sending static NVM_RECORD_ITEMS_T nvPublishRecordType; ///< Used to index over isPublishRecordRequested in the idle state static NVM_RECORD_TYPE_T currentRxRecordType; ///< Record type which is being processed currently for receiving static U32 recordSendDataIntervalCounter; ///< Record data send to CAN bust interval counter. static U32 sendRetryCount; ///< Counter for number of retries to send a record static U32 calRecordReceiveStartTime; ///< Time stamp the calibration record was received. static U32 institRecordReceiveStartTime; ///< Time stamp the institutional record was received. static DD_INSTIT_REC_TYPE sendInstitRec; ///< Current Institutional Record to be sent static DD_CAL_REC_TYPE sendCalRec; ///< Current Calibration Record to be sent static U08 sendSensorIdx; ///< Current Index of sensor calibration data to be sent static BOOL isPublishRecordRequested[ NUM_OF_NVM_REC_ITEMS ]; ///< Record state machine publish request flag. // ********** private function prototypes ********** // Process record functions static SEND_RECORD_STATE_T handleExecSendRecordIdleState( void ); static SEND_RECORD_STATE_T handleExecSendRecordSendState( void ); static SEND_RECORD_STATE_T handleSendDDSystemRecord( void ); static SEND_RECORD_STATE_T handleSendDDServiceRecord( void ); static SEND_RECORD_STATE_T handleSendDDUsageInfoRecord( void ); static SEND_RECORD_STATE_T handleSendDDInstitBasicRecord( void ); static SEND_RECORD_STATE_T handleSendDDInstitAdvancedRecord( void ); static SEND_RECORD_STATE_T handleSendDDInstitAdditionalRecord( void ); static SEND_RECORD_STATE_T handleSendPressureSensorCalRecord( void ); static SEND_RECORD_STATE_T handleSendTempSensorCalRecord( void ); static SEND_RECORD_STATE_T handleSendConcPumpCalRecord( void ); static SEND_RECORD_STATE_T handleSendD12PumpCalRecord( void ); static SEND_RECORD_STATE_T handleSendD48PumpCalRecord( void ); static SEND_RECORD_STATE_T handleSendAcidConcCalRecord( void ); static SEND_RECORD_STATE_T handleSendBicarbConcCalRecord( void ); static SEND_RECORD_STATE_T handleSendAccelSensorCalRecord( void ); static SEND_RECORD_STATE_T handleSendBloodLeakSensorCalRecord( void ); static SEND_RECORD_STATE_T handleSendConductivitySensorCalRecord( void ); static void updateSendRetryCount( BOOL sendStatus ); static SEND_RECORD_STATE_T updateCalSendRetryCountAndIndex( BOOL sendStatus, U08 maxIdx) static BOOL receiveCalRecord( MESSAGE_T *message, BOOL isIndexed, DD_CAL_REC_TYPE calRecordType, U16 recordSize ); static MSG_ID_T getNVMCalRecordResponseMsgId(DD_CAL_REC_TYPE calRecordType ); static void monitorNewCalSignal( void ); /*********************************************************************//** * @brief * The initNVMessagingDD function initializes NV messaging related * states and variables. It resets send and receive states, flags, * counters, and timing values. * @details \b Inputs: None * @details \b Outputs: nvMExecSendRecordState, * nvmExecreceiveRecordState, newRecordStartTimer, * isNewCalRecordAvailable, nvPublishRecordType, * isPublishRecordRequested, recordPublishMsgCount, * recordPublishTotalMsgs, recordSendDataIntervalCounter, * previousRecordMessageNum, recordReceiveStartTime * @return None *************************************************************************/ void initNVMessagingDD( void ) { nvMExecSendRecordState = NVM_SEND_RECORD_STATE_IDLE; nvmExecreceiveRecordState = NVM_RECEIVE_RECORD_STATE_IDLE; newRecordStartTimer = 0; isNewCalRecordAvailable = FALSE; nvPublishRecordType = NVM_SYSTEM_RECORD; recordSendDataIntervalCounter = 0; sendInstitRec = DD_INSTIT_MIN_DIALYSATE_FLOW_MLPM; sendCalRec = DD_CAL_RECORD_PRESSURE_SENSOR; U32 i; for ( i = 0; i < NUM_OF_NVM_REC_ITEMS; i++ ) { isPublishRecordRequested[ i ] = FALSE; } } /*********************************************************************//** * @brief * The execNVMPSendreceiveDDRecord function executes the NV record processing * state machines. It handles send and receive operations and monitors * for timeouts and calibration signals. * @details \b Alarms: ALARM_ID_DD_SOFTWARE_FAULT if invalid send state * @details \b Inputs: nvMExecSendRecordState, * nvmExecreceiveRecordState, recordReceiveStartTime * @details \b Outputs: nvMExecSendRecordState, * nvmExecreceiveRecordState * @return None *************************************************************************/ void execNVMPSendReceiveRecord( void ) { switch ( nvMExecSendRecordState ) { case NVM_SEND_RECORD_STATE_IDLE: nvMExecSendRecordState = handleExecSendRecordIdleState(); break; case NVM_SEND_RECORD_STATE_SEND: nvMExecSendRecordState = handleExecSendRecordSendState(); break; default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_NVM_INVALID_EXEC_SEND_STATE, ( U32 )nvMExecSendRecordState ); nvMExecSendRecordState = NVM_SEND_RECORD_STATE_IDLE; break; } if( nvmExecreceiveRecordState == NVM_RECEIVE_RECORD_STATE_RECEIVE ) { if ( ( NVM_CALIBRATION_RECORD == currentRxRecordType ) && ( TRUE == didTimeout( calRecordReceiveStartTime, RECORD_DATA_RECEIVE_TIMEOUT_MS ) ) ) { updateRecordCRC(NVM_CALIBRATION_RECORD); enqueueEraseAndWriteSector( NVM_CALIBRATION_RECORD ); startNewCalRecordAvailableTimer(); setNewCalibrationRecordAvailable( TRUE ); PROCESS_RECORD_SPECS_T recordSpec = getProcessRecord( NVM_CALIBRATION_RECORD ); sendNVEvent( NVM_CALIBRATION_RECORD , 0, 0 ); nvmExecreceiveRecordState = NVM_RECEIVE_RECORD_STATE_IDLE; } if ( ( NVM_INSTITUTIONAL_RECORD == currentRxRecordType ) && ( TRUE == didTimeout( institRecordReceiveStartTime, RECORD_DATA_RECEIVE_TIMEOUT_MS ) ) ) { updateRecordCRC(NVM_INSTITUTIONAL_RECORD); enqueueEraseAndWriteSector( NVM_INSTITUTIONAL_RECORD ); PROCESS_RECORD_SPECS_T recordSpec = getProcessRecord( NVM_INSTITUTIONAL_RECORD ); sendNVEvent( NVM_INSTITUTIONAL_RECORD , 0, 0 ); nvmExecreceiveRecordState = NVM_RECEIVE_RECORD_STATE_IDLE; } } // Check the calibration signal monitorNewCalSignal(); } /*********************************************************************//** * @brief * The setNewCalibrationRecordAvailable function updates the flag * indicating new NV record availability. * @details \b Inputs: None * @details \b Outputs: isNewCalRecordAvailable * @param value Flag value to be updated * @return None *************************************************************************/ void setNewCalibrationRecordAvailable( BOOL isAvailable) { isNewCalRecordAvailable = isAvailable; } /*********************************************************************//** * @brief * The getNewCalRecordAvalability function gets the status of new * calibration record availability. * @details \b Inputs: isNewCalRecordAvailable * @details \b Outputs: None * @return TRUE if new calibration record is available otherwise FALSE *************************************************************************/ BOOL getNewCalRecordAvalability( void ) { return isNewCalRecordAvailable; } /*********************************************************************//** * @brief * The startNewCalRecordAvailableTimer function starts the time for * new calibration record availability. * @details \b Inputs: None * @details \b Outputs: newRecordStartTimer * @return None *************************************************************************/ void startNewCalRecordAvailableTimer( void ) { newRecordStartTimer = getMSTimerCount(); } /*********************************************************************//** * @brief * The handleExecSendRecordIdleState function handles the idle state of * the exec send record state machine. It prepares record data for * publishing when requested. * @details \b Inputs: isPublishRecordRequested, * nvPublishRecordType * @details \b Outputs: isPublishRecordRequested, * recordPublishTotalMsgs, recordPublishMsgCount, * recordSendDataIntervalCounter, nvPublishRecordType, * recordToPublish * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleExecSendRecordIdleState( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_IDLE; if ( TRUE == isPublishRecordRequested[ nvPublishRecordType ] ) { recordToPublish = ( NVM_RECORD_TYPE_T )nvPublishRecordType; // Set the publish flag to FALSE isPublishRecordRequested[ recordToPublish ] = FALSE; // Time interval in between data to be sent. It is set to the interval count so on the first call // of the send calibration record function, the first packet of data is sent recordSendDataIntervalCounter = RECORD_DATA_SEND_INTERVAL_COUNT; state = NVM_SEND_RECORD_STATE_SEND; } nvPublishRecordType = ( NVM_RECORD_TYPE_T )( nvPublishRecordType + 1 ); if( nvPublishRecordType >= NUM_OF_NVM_RECORD_TYPES ) { nvPublishRecordType = NVM_SYSTEM_RECORD; } return state; } /*********************************************************************//** * @brief * The handleExecSendRecordSendState function handles the send state of * the exec send record state machine. It sends record data in chunks * based on timing and message count. * @details \b Inputs: recordPublishTotalMsgs, * recordPublishMsgCount, recordSendDataIntervalCounter, * recordToPublish * @details \b Outputs: recordPublishMsgCount, * recordSendDataIntervalCounter * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleExecSendRecordSendState( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; // If it is time to send data if ( ++recordSendDataIntervalCounter >= RECORD_DATA_SEND_INTERVAL_COUNT ) { switch(recordToPublish) { case NVM_REC_TYPE_SYSTEM: state = handleSendDDSystemRecord(); break; case NVM_REC_TYPE_SERVICE: state = handleSendDDServiceRecord(); break; case NVM_REC_TYPE_USAGE_INFO: state = handleSendDDUsageInfoRecord(); break; case NVM_REC_TYPE_INSTIT_BASIC: state = handleSendDDInstitBasicRecord(); break; case NVM_REC_TYPE_INSTIT_ADVANCED: state = handleSendDDInstitAdvancedRecord(); break; case NVM_REC_TYPE_INSTIT_ADDITIONAL: state = handleSendDDInstitAdditionalRecord(); break; case NVM_REC_TYPE_CAL_PRESSURE_SENSORS: state = handleSendPressureSensorCalRecord(); break; case NVM_REC_TYPE_CAL_TEMPERATURE_SENSORS: state = handleSendTempSensorCalRecord(); break; case NVM_REC_TYPE_CAL_CONC_PUMPS: state = handleSendConcPumpCalRecord(); break; case NVM_REC_TYPE_CAL_D12_PUMP: state = handleSendD12PumpCalRecord(); break; case NVM_REC_TYPE_CAL_D48_PUMP: state = handleSendD48PumpCalRecord(); break; case NVM_REC_TYPE_CAL_ACID_CONCENTREATES: state = handleSendAcidConcCalRecord(); break; case NVM_REC_TYPE_CAL_BICARB_CONCENTRATES: state = handleSendBicarbConcCalRecord(); break; case NVM_REC_TYPE_CAL_ACCEL_SENSOR: state = handleSendAccelSensorCalRecord(); break; case NVM_REC_TYPE_CAL_BLOOD_LEAK_SENSOR: state = handleSendBloodLeakSensorCalRecord(); break; case NVM_REC_TYPE_CAL_CONDUCTIVITY_SENSORS: state = handleSendConductivitySensorCalRecord(); break; default: break; } recordSendDataIntervalCounter = 0; } return state; } /*********************************************************************//** * @brief * The handleSendDDSystemRecord function sends the DD system record. * It retries transmission on failure and returns to the idle state * after a successful send or when retries are exhausted. * @details \b Inputs: None * @details \b Outputs: None * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendDDSystemRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_SYSTEM_REC_PAYLOAD_T payload; // Get the record if ( TRUE == getNVMRecord( GET_SYSTEM_RECORD, (U08*)&payload.data, sizeof( DD_SYSTEM_RECORD_T ) , 0, ALARM_ID_DD_NVM_INVALID_SYSTEM_RECORD_CRC ) ) { payload.accepted = TRUE; payload.rejectionReason = 0; // Send the record sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_SYSTEM_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&payload, sizeof( DD_NVM_GET_SYSTEM_REC_PAYLOAD_T ) ); } state = updateSendRetryCount( sendStatus ); return state; } /*********************************************************************//** * @brief * The handleSendDDServiceRecord function sends the DD service record. * It retries transmission on failure and returns to the idle state * after a successful send or when retries are exhausted. * @details \b Inputs: None * @details \b Outputs: None * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendDDServiceRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_SERVICE_REC_PAYLOAD_T payload; // Get the record if ( TRUE == getNVMRecord( GET_SERVICE_RECORD, (U08*)&payload.data, sizeof( DD_SERVICE_RECORD_T ) , 0, ALARM_ID_DD_NVM_INVALID_SERVICE_RECORD_CRC ) ) { payload.accepted = TRUE; payload.rejectionReason = 0; // Send the record sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_SERVICE_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&payload, sizeof( DD_NVM_GET_SERVICE_REC_PAYLOAD_T ) ); } state = updateSendRetryCount( sendStatus ); return state; } /*********************************************************************//** * @brief * The handleSendDDUsageInfoRecord function sends the DD usage * information record. It retries transmission on failure and returns * to the idle state after a successful send or when retries are * exhausted. * @details \b Inputs: None * @details \b Outputs: None * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendDDUsageInfoRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_USAGE_INFO_REC_PAYLOAD_T payload; // Get the record if ( TRUE == getNVMRecord( GET_USAGE_RECORD, (U08*)&payload.data, sizeof( DD_USAGE_INFO_RECORD_T ), 0, ALARM_ID_DD_NVM_INVALID_USAGE_RECORD_CRC ) ) { payload.accepted = TRUE; payload.rejectionReason = 0; // Send the record sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_USAGE_INFO_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&usageInfoRecord, sizeof( DD_NVM_GET_USAGE_INFO_REC_PAYLOAD_T ) ); } state = updateSendRetryCount( sendStatus ); return state; } /*********************************************************************//** * @brief * The handleSendDDInstitBasicRecord function sends the DD basic * institutional record. It retries transmission on failure and returns * to the idle state after a successful send or when retries are * exhausted. * @details \b Inputs: None * @details \b Outputs: None * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendDDInstitBasicRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_INSTIT_BASIC_REC_PAYLOAD_T payload; // Get the record payload.accepted = TRUE; payload.rejectionReason = 0; payload.data = getNVMInstitBasicRecord(); // Send the record sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_INSTIT_BASIC_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&payload, sizeof( DD_NVM_GET_INSTIT_BASIC_REC_PAYLOAD_T ) ); state = updateSendRetryCount( sendStatus ); return state; } /*********************************************************************//** * @brief * The handleSendDDInstitAdvancedRecord function sends the DD advanced * institutional record. It retries transmission on failure and returns * to the idle state after a successful send or when retries are * exhausted. * @details \b Inputs: None * @details \b Outputs: None * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendDDInstitAdvancedRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_INSTIT_ADVANCED_REC_PAYLOAD_T payload; // Get the record payload.accepted = TRUE; payload.rejectionReason = 0; payload.data = getNVMInstitAdvancedRecord(); // Send the record sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_INSTIT_ADVANCED_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&payload, sizeof( DD_NVM_GET_INSTIT_ADVANCED_REC_PAYLOAD_T ) ); state = updateSendRetryCount( sendStatus ); return state; } /*********************************************************************//** * @brief * The handleSendDDInstitAdditionalRecord function sends the DD additional * institutional record. It retries transmission on failure and returns * to the idle state after a successful send or when retries are * exhausted. * @details \b Inputs: None * @details \b Outputs: None * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendDDInstitAdditionalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_INSTIT_ADDITIONAL_REC_PAYLOAD_T payload; // Get the record payload.accepted = TRUE; payload.rejectionReason = 0; payload.data = getNVMInstitAdditionalRecord(); // Send the record sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_INSTIT_ADDITIONAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&payload, sizeof( DD_NVM_GET_INSTIT_ADDITIONAL_REC_PAYLOAD_T ) ); state = updateSendRetryCount( sendStatus ); return state; } /*********************************************************************//** * @brief * The handleSendPressureSensorCalRecord function sends the calibration * record of the selected pressure sensor. * @details \b Inputs: sendSensorIdx * @details \b Outputs: None * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendPressureSensorCalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T payload; payload.accepted = TRUE; payload.rejectionReason = 0; payload.idx = sendSensorIdx; payload.data = getPressureSensorCalRecord( sendSensorIdx ); // Send the record sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_PRESSURE_SENSOR_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&payload, sizeof( DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T ) ); state = updateCalSendRetryCountAndIndex( sendStatus, NUM_OF_PRESSURE_SENSORS ); return sendStatus; } /*********************************************************************//** * @brief * The handleSendTempSensorCalRecord function sends the calibration record * of the selected temperature sensor. * @details \b Inputs: sendSensorIdx * @details \b Outputs: None * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendTempSensorCalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T payload; payload.accepted = TRUE; payload.rejectionReason = 0; payload.idx = sendSensorIdx; payload.data = getTemperatureSensorCalRecord( sendSensorIdx ); // Send the record sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_TEMPERATURE_SENSOR_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&payload, sizeof( DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T ) ); state = updateCalSendRetryCountAndIndex( sendStatus, NUM_OF_TEMPERATURE_SENSORS ); return sendStatus; } /*********************************************************************//** * @brief * The handleSendConcPumpCalRecord function sends the calibration record * of the selected concentrate pump. * @details \b Inputs: sendSensorIdx * @details \b Outputs: None * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendConcPumpCalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T payload; payload.accepted = TRUE; payload.rejectionReason = 0; payload.idx = sendSensorIdx; payload.data = getConcPumpCalRecord( sendSensorIdx ); // Send the record sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_CONC_PUMP_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&payload, sizeof( DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T ) ); state = updateCalSendRetryCountAndIndex( sendStatus, NUM_OF_CONCENTRATE_PUMPS ); return sendStatus; } /*********************************************************************//** * @brief * The handleSendD12PumpCalRecord function sends the calibration record of * the D12 dialysate pump. * @details \b Inputs: None * @details \b Outputs: sendSensorIdx * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendD12PumpCalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_D12_PUMP_CAL_REC_PAYLOAD_T payload; payload.accepted = TRUE; payload.rejectionReason = 0; sendSensorIdx = 0; payload.data = getD12PumpCalRecord( ); // Send the record sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_D12_PUMP_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&payload, sizeof( DD_NVM_GET_D12_PUMP_CAL_REC_PAYLOAD_T ) ); state = updateCalSendRetryCountAndIndex( sendStatus, 0 ); return sendStatus; } /*********************************************************************//** * @brief * The handleSendD48PumpCalRecord function sends the calibration record of * the D48 dialysate pump. * @details \b Inputs: None * @details \b Outputs: sendSensorIdx * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendD48PumpCalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_D48_PUMP_CAL_REC_PAYLOAD_T payload; payload.accepted = TRUE; payload.rejectionReason = 0; sendSensorIdx = 0; payload.data = getD48PumpCalRecord( ); // Send the record sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_D48_PUMP_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&payload, sizeof( DD_NVM_GET_D48_PUMP_CAL_REC_PAYLOAD_T ) ); state = updateCalSendRetryCountAndIndex( sendStatus, 0 ); return sendStatus; } /*********************************************************************//** * @brief * The handleSendAcidConcCalRecord function sends the calibration record of * the selected acid concentrate. * @details \b Inputs: sendSensorIdx * @details \b Outputs: None * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendAcidConcCalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_ACID_CONC_CAL_REC_PAYLOAD_T payload; payload.accepted = TRUE; payload.rejectionReason = 0; payload.idx = sendSensorIdx; payload.data = getAcidConcentrateCalRecord( sendSensorIdx ); // Send the record sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_ACID_CONC_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&payload, sizeof( DD_NVM_GET_ACID_CONC_CAL_REC_PAYLOAD_T ) ); state = updateCalSendRetryCountAndIndex( sendStatus, NUM_OF_ACID_TYPE ); return sendStatus; } /*********************************************************************//** * @brief * The handleSendAcidConcCalRecord function sends the calibration record of * the selected acid concentrate. * @details \b Inputs: sendSensorIdx * @details \b Outputs: None * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendBicarbConcCalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_BICARB_CONC_CAL_REC_PAYLOAD_T payload; payload.accepted = TRUE; payload.rejectionReason = 0; payload.idx = sendSensorIdx; payload.data = getBicarbConcentrateCalRecord( sendSensorIdx ); // Send the record sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_BICARB_CONC_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&payload, sizeof( DD_NVM_GET_BICARB_CONC_CAL_REC_PAYLOAD_T ) ); state = updateCalSendRetryCountAndIndex( sendStatus, NUM_OF_BICARB_TYPE ); return sendStatus; } /*********************************************************************//** * @brief * The handleSendAccelSensorCalRecord function sends the calibration record * of the accelerometer sensor. * @details \b Inputs: None * @details \b Outputs: sendSensorIdx * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendAccelSensorCalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_ACCEL_SENSOR_CAL_REC_PAYLOAD_T payload; payload.accepted = TRUE; payload.rejectionReason = 0; sendSensorIdx = 0; payload.data = getAccelSensorCalRecord(); // Send the record sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_ACCEL_SENSOR_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&payload, sizeof( DD_NVM_GET_ACCEL_SENSOR_CAL_REC_PAYLOAD_T ) ); state = updateCalSendRetryCountAndIndex( sendStatus, 0 ); return sendStatus; } /*********************************************************************//** * @brief * The handleSendBloodLeakSensorCalRecord function sends the calibration * record of the blood leak sensor. * @details \b Inputs: None * @details \b Outputs: sendSensorIdx * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendBloodLeakSensorCalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_BLOOD_LEAK_SENSOR_CAL_REC_PAYLOAD_T payload; payload.accepted = TRUE; payload.rejectionReason = 0; sendSensorIdx = 0; payload.data = getBloodLeakSensorCalRecord( ); // Send the record sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_BLOOD_LEAK_SENSOR_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&payload, sizeof( DD_NVM_GET_BLOOD_LEAK_SENSOR_CAL_REC_PAYLOAD_T ) ); state = updateCalSendRetryCountAndIndex( sendStatus, 0 ); return sendStatus; } /*********************************************************************//** * @brief * The handleSendConductivitySensorCalRecord function sends the calibration * record of the conductivity sensor. * @details \b Inputs: sendSensorIdx * @details \b Outputs: None * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendConductivitySensorCalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_CONDUCTIVITY_SENSOR_CAL_REC_PAYLOAD_T payload; payload.accepted = TRUE; payload.rejectionReason = 0; payload.idx = sendSensorIdx; payload.data = getConductivitySensorCalRecord( sendSensorIdx ); // Send the record sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_CONDUCTIVITY_SENSOR_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&payload, sizeof( DD_NVM_GET_CONDUCTIVITY_SENSOR_CAL_REC_PAYLOAD_T ) ); state = updateCalSendRetryCountAndIndex( sendStatus, NUM_OF_CONDUCTIVITY_SENSORS ); return sendStatus; } /*********************************************************************//** * @brief * The receiveCalRecord function receives a calibration record, * validates its CRC, updates the calibration data, and sends a * response indicating whether the request was accepted. * @details \b Inputs: None * @details \b Outputs: nvmExecreceiveRecordState, * calRecordReceiveStartTime, currentRxRecordType * @param message Pointer to the received message * @param isIndexed True, if the received record contains an index value. * @param calRecordType Calibration record type being received * @param recordSize Size of the calibration record in bytes * @return TRUE if the calibration record was accepted and processed * successfully otherwise FALSE *************************************************************************/ static BOOL receiveCalRecord( MESSAGE_T* message, BOOL isIndexed, DD_CAL_REC_TYPE calRecordType, U16 recordSize ) { BOOL status = FALSE; U08* payloadPtr = message->payload; U08 expectedPayloadLen = recordSize ; MSG_ID_T msgID = getNVMCalRecordResponseMsgId( calRecordType ); UI_RESPONSE_PAYLOAD_T response; if ( TRUE == isIndexed ) { expectedPayloadLen = ( sizeof(U08) + recordSize ); } DD_NVM_RECORD_PAYLOAD_T recvdPayload; if ( DD_MODE_SERV == getCurrentOperationMode() ) { if ( message->hdr.payloadLen == expectedPayloadLen ) { // Get the index of the received calibration record if required if ( TRUE == isIndexed ) { memcpy( &recvdPayload.idx, payloadPtr, sizeof(U08)); payloadPtr += sizeof(U08); } memcpy( &recvdPayload.data, payloadPtr, recordSize ); // CRC assumed at end of record U16 *recordCRC = (U16*)( recvdPayload.data + ( recordSize - sizeof(U16) ) ); U16 calcCRC = crc16( recvdPayload.data, recordSize - sizeof(U16) ); if ( calcCRC == *recordCRC ) { nvmExecreceiveRecordState = NVM_RECEIVE_RECORD_STATE_RECEIVE; status = setNVMCalRecord( calRecordType, (U08*)&recvdPayload.data, recvdPayload.idx ); response.accepted = TRUE; response.rejectionReason = REQUEST_REJECT_REASON_NONE; // It is possible that we receive multiple packets of cal record // So we write it to flash when we finish receiving all packets or // a timeout occurs. calRecordReceiveStartTime = getMSTimerCount(); currentRxRecordType = NVM_CALIBRATION_RECORD; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_CRC; } } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; } response.fwValue = recvdPayload.idx; sendMessage( msgID, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&response, sizeof( UI_RESPONSE_PAYLOAD_T ) ); return status; } /*********************************************************************//** * @brief * The getNVMCalRecordResponseMsgId function gets the response message * ID corresponding to the specified calibration record type. * @details \b Alarms: ALARM_ID_DD_SOFTWARE_FAULT if invalid calibration * record type is provided * @details \b Inputs: None * @details \b Outputs: None * @param calRecordType Calibration record type * @return msgId corresponding response message ID *************************************************************************/ static MSG_ID_T getNVMCalRecordResponseMsgId( DD_CAL_REC_TYPE calRecordType ) { MSG_ID_T msgId = MSG_ID_UNUSED; switch ( calRecordType ) { case DD_CAL_RECORD_PRESSURE_SENSOR: msgId = MSG_ID_DD_NVM_SET_CAL_PRESSURE_SENSOR_RESPONSE; break; case DD_CAL_RECORD_TEMPERATURE_SENSOR: msgId = MSG_ID_DD_NVM_SET_CAL_TEMP_SENSOR_RESPONSE; break; case DD_CAL_RECORD_CONCENTRATE_PUMP: msgId = MSG_ID_DD_NVM_SET_CAL_CONC_PUMP_RESPONSE; break; case DD_CAL_RECORD_D12_PUMP: msgId = MSG_ID_DD_NVM_SET_CAL_D12_PUMP_RESPONSE; break; case DD_CAL_RECORD_D48_PUMP: msgId = MSG_ID_DD_NVM_SET_CAL_D48_PUMP_RESPONSE; break; case DD_CAL_RECORD_ACID_CONCENTRATE: msgId = MSG_ID_DD_NVM_SET_CAL_ACID_CONCENTRATE_RESPONSE; break; case DD_CAL_RECORD_BICARB_CONCENTRATE: msgId = MSG_ID_DD_NVM_SET_CAL_BICARB_CONCENTRATE_RESPONSE; break; case DD_CAL_RECORD_ACCELEROMETER_SENSOR: msgId = MSG_ID_DD_NVM_SET_CAL_ACCEL_SENSOR_RESPONSE; break; case DD_CAL_RECORD_BLOOD_LEAK_SENSOR: msgId = MSG_ID_DD_NVM_SET_CAL_BLOOD_LEAK_SENSOR_RESPONSE; break; default: // Software fault SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, ( U32 )calRecordType ); break; } return msgId; } /*********************************************************************//** * @brief * The monitorNewCalSignal function monitors the new calibration signal * and clears it when the timeout has elapsed. * @details \b Inputs: isNewCalRecordAvailable, * newRecordStartTimer * @details \b Outputs: isNewCalRecordAvailable * @return None *************************************************************************/ static void monitorNewCalSignal( void ) { // Check if new calibration record is available and // the timer has elapsed if ( ( TRUE == didTimeout( newRecordStartTimer, NEW_CAL_AVAILABLE_SIGNAL_TIMEOUT_MS ) ) && ( TRUE == getNewCalRecordAvalability() ) ) { // Clear the new calibration record available flag setNewCalibrationRecordAvailable( FALSE ); } } /*********************************************************************//** * @brief * The updateSendRetryCount function updates the retry counts and * record to be published based on the send status. * @details \b Inputs: None * @details \b Outputs: recordToPublish, sendRetryCount * @param sendStatus True if record was sent successfully, otherwise FALSE. * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T updateSendRetryCount( BOOL sendStatus ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; // Check if record send successfully if ( TRUE == sendStatus ) { // Reset the retry count sendRetryCount = 0; // Clear the publishing flags recordToPublish = NUM_OF_NVM_REC_ITEMS; // Move to Send Idle State state = NVM_SEND_RECORD_STATE_IDLE; } else { sendRetryCount++; } // Utilized all the retries. Something is wrong. if ( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) { // Reset the retry count sendRetryCount = 0; // Clear the publishing flags recordToPublish = NUM_OF_NVM_REC_ITEMS; // Move to Send Idle State state = NVM_SEND_RECORD_STATE_IDLE; } return state; } /*********************************************************************//** * @brief * The updateCalSendRetryCountAndIndex function updates the retry counts, * sensor index, record to be published based on the send status of the calibration data. * @details \b Inputs: None * @details \b Outputs: recordToPublish, sendRetryCount, sendSensorIdx * @param sendStatus True if record was sent successfully, otherwise FALSE. * @@param maxIdx Maximum Index value of the current calibration item being sent * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T updateCalSendRetryCountAndIndex( BOOL sendStatus, U08 maxIdx) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL resetState = FALSE; // Check if record was sent successfully if ( TRUE == sendStatus) { sendSensorIdx++; sendRetryCount = 0; // Check if we sent the last record of calibration component if ( sendSensorIdx >= maxIdx ) { resetState = TRUE; } } else { sendRetryCount ++; } // If all the allowed retries has been utilized or if ( sendRetryCount >= MAX_NUM_OF_SEND_RETRIES ) { resetState = TRUE; } if ( TRUE == resetState) { // Reset Sensor Index for the next request sendSensorIdx = 0; // Reset the retry count sendRetryCount = 0; // Clear the publishing flags recordToPublish = NUM_OF_NVM_REC_ITEMS; // Move to Send Idle State state = NVM_SEND_RECORD_STATE_IDLE; } return state; } /*********************************************************************//** * @brief * The handleDDGetNVRecord function processes a request to publish an NV * record. It validates the payload and sets the publish request flag * for the selected record. * @details \b Inputs: nvMExecSendRecordState * @details \b Outputs: isPublishRecordRequested, * recordToPublish * @param message Pointer to the received message * @return TRUE if the request is accepted otherwise FALSE *************************************************************************/ BOOL handleDDGetNVRecord( MESSAGE_T *message ) { BOOL result = FALSE; NVM_RECORD_TYPE_T job; UI_RESPONSE_PAYLOAD_T response; job = ( NVM_RECORD_TYPE_T )message->payload[ 0 ]; // Accept the request only if the send exec is in the idle state if ( ( job < NUM_OF_NVM_RECORD_TYPES ) && ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) ) { isPublishRecordRequested[ job ] = TRUE; recordToPublish = job; result = TRUE; response.accepted = TRUE; response.rejectionReason = REQUEST_REJECT_REASON_NONE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; } sendMessage( MSG_ID_DD_NVM_GET_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( UI_RESPONSE_PAYLOAD_T ) ); return result; } BOOL handleDDGetSystemRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; DD_NVM_GET_SYSTEM_REC_PAYLOAD_T response; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { isPublishRecordRequested[ NVM_REC_TYPE_SYSTEM ] = TRUE; result = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_SYSTEM_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_GET_SYSTEM_REC_PAYLOAD_T ) ); } return result; } BOOL handleDDSetSystemRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; U08 expectedPayloadLen = sizeof( DD_SYSTEM_RECORD_T ) - sizeof( U16 ); DD_NVM_SET_SYSTEM_REC_PAYLOAD_T response = { 0 }; DD_SYSTEM_RECORD_T record; // System record can be updated only in service mode if ( DD_MODE_SERV == getCurrentOperationMode() ) { if ( message->hdr.payloadLen == expectedPayloadLen ) { memcpy( record, message->payload, expectedPayloadLen ); setSystemRecord( record ); updateRecordCRC( NVM_SYSTEM_RECORD ); result = enqueueEraseAndWriteSector( NVM_SYSTEM_RECORD ); sendNVEvent( NVM_SYSTEM_RECORD, 0, 0 ); response.accepted = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; } sendMessage( MSG_ID_DD_UI_NVM_SET_SYSTEM_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_SET_SYSTEM_REC_PAYLOAD_T ) ); return result; } BOOL handleDDGetServicRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; DD_NVM_GET_SERVICE_REC_PAYLOAD_T response; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { isPublishRecordRequested[ NVM_REC_TYPE_SERVICE ] = TRUE; result = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_SERVICE_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_GET_SERVICE_REC_PAYLOAD_T ) ); } return result; } BOOL handleDDSetServicRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; U08 expectedPayloadLen = sizeof( DD_SERVICE_RECORD_T ) - sizeof( U16 ); DD_NVM_SET_SERVICE_REC_PAYLOAD_T response = { 0 }; DD_SERVICE_RECORD_T record; // Service record can be updated only in service mode if ( DD_MODE_SERV == getCurrentOperationMode() ) { if ( message->hdr.payloadLen == expectedPayloadLen ) { memcpy( record, message->payload, expectedPayloadLen ); setServiceRecord( record ); updateRecordCRC( NVM_SERVICE_RECORD ); result = enqueueEraseAndWriteSector( NVM_SERVICE_RECORD ); sendNVEvent( NVM_SERVICE_RECORD, 0, 0 ); response.accepted = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; } sendMessage( MSG_ID_DD_UI_NVM_SET_SERVICE_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_SET_SERVICE_REC_PAYLOAD_T ) ); return result; } BOOL handleDDGetUsageInfoRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; DD_NVM_GET_USAGE_INFO_REC_PAYLOAD_T response; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { isPublishRecordRequested[ NVM_REC_TYPE_USAGE_INFO ] = TRUE; result = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_USAGE_INFO_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_GET_USAGE_INFO_REC_PAYLOAD_T ) ); } return result; } BOOL handleDDSetUsageInfoRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; U08 expectedPayloadLen = sizeof( DD_USAGE_INFO_RECORD_T ) - sizeof( U16 ); DD_NVM_SET_USAGE_INFO_REC_PAYLOAD_T response = { 0 }; DD_USAGE_INFO_RECORD_T record; if ( message->hdr.payloadLen == expectedPayloadLen ) { memcpy( record, message->payload, expectedPayloadLen ); setUsageInfoRecord( record ); updateRecordCRC( NVM_USAGE_INFO_RECORD ); result = enqueueEraseAndWriteSector( NVM_USAGE_INFO_RECORD ); sendNVEvent( NVM_USAGE_INFO_RECORD, 0, 0 ); response.accepted = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } sendMessage( MSG_ID_DD_UI_NVM_SET_USAGE_INFO_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_SET_USAGE_INFO_REC_PAYLOAD_T ) ); return result; } BOOL handleDDGetInstitBasicRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; DD_NVM_GET_INSTIT_BASIC_REC_PAYLOAD_T response; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { isPublishRecordRequested[ NVM_REC_TYPE_INSTIT_BASIC ] = TRUE; result = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_INSTIT_BASIC_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_GET_INSTIT_BASIC_REC_PAYLOAD_T ) ); } return result; } BOOL handleDDSetInstitBasicRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; U08 expectedPayloadLen = sizeof( DD_INSTIT_BASIC_RECORD_T ) - sizeof( U16 ); DD_NVM_SET_INSTIT_BASIC_REC_PAYLOAD_T response = { 0 }; DD_INSTIT_BASIC_RECORD_T record; if ( message->hdr.payloadLen == expectedPayloadLen ) { memcpy( record, message->payload, expectedPayloadLen ); record.crc = crc16 ( (U08*)&record, sizeof( DD_INSTIT_BASIC_RECORD_T ) - sizeof( U16 ) ); setInstitBasicRecord( record ); updateRecordCRC( NVM_INSTITUTIONAL_RECORD ); result = enqueueEraseAndWriteSector( NVM_INSTITUTIONAL_RECORD ); sendNVEvent( NVM_INSTITUTIONAL_RECORD, 0, 0 ); response.accepted = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } sendMessage( MSG_ID_DD_UI_NVM_SET_INSTIT_BASIC_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_SET_INSTIT_BASIC_REC_PAYLOAD_T ) ); return result; } BOOL handleDDGetInstitAdvancedRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; DD_NVM_GET_INSTIT_ADVANCED_REC_PAYLOAD_T response; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { isPublishRecordRequested[ NVM_REC_TYPE_INSTIT_ADVANCED ] = TRUE; result = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_INSTIT_ADVANCED_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_GET_INSTIT_ADVANCED_REC_PAYLOAD_T ) ); } return result; } BOOL handleDDSetInstitAdvancedRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; U08 expectedPayloadLen = sizeof( DD_INSTIT_ADVANCED_RECORD_T ) - sizeof( U16 ); DD_NVM_SET_INSTIT_ADVANCED_REC_PAYLOAD_T response = { 0 }; DD_INSTIT_ADVANCED_RECORD_T record; if ( message->hdr.payloadLen == expectedPayloadLen ) { memcpy( record, message->payload, expectedPayloadLen ); record.crc = crc16 ( (U08*)&record, sizeof( DD_INSTIT_ADVANCED_RECORD_T ) - sizeof( U16 ) ); setInstitAdvancedRecord( record ); updateRecordCRC( NVM_INSTITUTIONAL_RECORD ); result = enqueueEraseAndWriteSector( NVM_INSTITUTIONAL_RECORD ); sendNVEvent( NVM_INSTITUTIONAL_RECORD, 0, 0 ); response.accepted = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } sendMessage( MSG_ID_DD_UI_NVM_SET_INSTIT_ADVANCED_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_SET_INSTIT_ADVANCED_REC_PAYLOAD_T ) ); return result; } BOOL handleDDGetInstitAdditionalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; DD_NVM_GET_INSTIT_ADDITIONAL_REC_PAYLOAD_T response; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { isPublishRecordRequested[ NVM_REC_TYPE_INSTIT_ADDITIONAL ] = TRUE; result = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_INSTIT_ADDITIONAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_GET_INSTIT_ADDITIONAL_REC_PAYLOAD_T ) ); } return result; } BOOL handleDDSetInstitAdditionalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; U08 expectedPayloadLen = sizeof( DD_INSTIT_ADDITIONAL_RECORD_T ) - sizeof( U16 ); DD_NVM_SET_INSTIT_ADDITIONAL_REC_PAYLOAD_T response = { 0 }; DD_INSTIT_ADDITIONAL_RECORD_T record; if ( message->hdr.payloadLen == expectedPayloadLen ) { memcpy( record, message->payload, expectedPayloadLen ); record.crc = crc16 ( (U08*)&record, sizeof( DD_INSTIT_ADDITIONAL_RECORD_T ) - sizeof( U16 ) ); setInstitAdditionalRecord( record ); updateRecordCRC( NVM_INSTITUTIONAL_RECORD ); result = enqueueEraseAndWriteSector( NVM_INSTITUTIONAL_RECORD ); sendNVEvent( NVM_INSTITUTIONAL_RECORD, 0, 0 ); response.accepted = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } sendMessage( MSG_ID_DD_UI_NVM_SET_INSTIT_ADDITIONAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_SET_INSTIT_ADDITIONAL_REC_PAYLOAD_T ) ); return result; } BOOL handleDDGetPressureSensorCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T response; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { isPublishRecordRequested[ NVM_REC_TYPE_CAL_PRESSURE_SENSORS ] = TRUE; result = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_PRESSURE_SENSOR_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T ) ); } return result; } BOOL handleDDSetPressureSensorCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; DD_NVM_SET_LINEAR_CAL_REC_PAYLOAD_T response = { 0 }; U08* payloadPtr = message->payload; U08 recordSize = sizeof( LINEAR_CAL_PAYLOAD_T ) - sizeof( U16 ); // Data - CRC U08 expectedPayloadLen = sizeof( U08 ) + recordSize; // Index + Data - CRC U08 idx; LINEAR_CAL_PAYLOAD_T record; // System record can be updated only in service mode if ( DD_MODE_SERV == getCurrentOperationMode() ) { if ( message->hdr.payloadLen == expectedPayloadLen ) { memcpy( &idx, payloadPtr, sizeof(U08)); payloadPtr += sizeof(U08); if( idx < NUM_OF_PRESSURE_SENSORS ) { memcpy( &record, payloadPtr, recordSize ); record.crc = crc16 ( (U08*)&record, recordSize ); setPressureSensorCalRecord( idx, record ); updateRecordCRC( NVM_CALIBRATION_RECORD ); result = enqueueEraseAndWriteSector( NVM_CALIBRATION_RECORD ); sendNVEvent( NVM_CALIBRATION_RECORD, 0, 0 ); response.accepted = TRUE; } else { response.accepted = FALSE; response.idxRejectReason = REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE; } } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; } sendMessage( MSG_ID_DD_UI_NVM_SET_PRESSURE_SENSOR_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_SET_LINEAR_CAL_REC_PAYLOAD_T ) ); return result; } BOOL handleDDGetTemperatureSensorCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T response; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { isPublishRecordRequested[ NVM_REC_TYPE_CAL_TEMPERATURE_SENSORS ] = TRUE; result = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_TEMPERATURE_SENSOR_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T ) ); } return result; } BOOL handleDDSetTemperatureSensorCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; return result; } BOOL handleDDGetConcPumpCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T response; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { isPublishRecordRequested[ NVM_REC_TYPE_CAL_CONC_PUMPS] = TRUE; result = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_CONC_PUMP_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T ) ); } return result; } BOOL handleDDSetConcPumpCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; return result; } BOOL handleDDGetD12PumpCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; DD_NVM_GET_D12_PUMP_CAL_REC_PAYLOAD_T response; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { isPublishRecordRequested[ NVM_REC_TYPE_CAL_D12_PUMP] = TRUE; result = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_D12_PUMP_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_GET_D12_PUMP_CAL_REC_PAYLOAD_T ) ); } return result; } BOOL handleDDSetD12PumpCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; return result; } BOOL handleDDGetD48PumpCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; DD_NVM_GET_D48_PUMP_CAL_REC_PAYLOAD_T response; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { isPublishRecordRequested[ NVM_REC_TYPE_CAL_D48_PUMP] = TRUE; result = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_D48_PUMP_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_GET_D48_PUMP_CAL_REC_PAYLOAD_T ) ); } return result; } BOOL handleDDSetD48PumpCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; return result; } BOOL handleDDGetAcidConcCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; DD_NVM_GET_ACID_CONC_CAL_REC_PAYLOAD_T response; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { isPublishRecordRequested[ NVM_REC_TYPE_CAL_ACID_CONCENTREATES] = TRUE; result = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_ACID_CONC_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_GET_ACID_CONC_CAL_REC_PAYLOAD_T ) ); } return result; } BOOL handleDDSetAcidConcCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; return result; } BOOL handleDDGetBicarbConcCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; DD_NVM_GET_BICARB_CONC_CAL_REC_PAYLOAD_T response; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { isPublishRecordRequested[ NVM_REC_TYPE_CAL_BICARB_CONCENTREATES] = TRUE; result = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_BICARB_CONC_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_GET_BICARB_CONC_CAL_REC_PAYLOAD_T ) ); } return result; } BOOL handleDDSetBicarbConcCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; return result; } BOOL handleDDGetAccelSensorCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; DD_NVM_GET_ACCEL_SENSOR_CAL_REC_PAYLOAD_T response; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { isPublishRecordRequested[ NVM_REC_TYPE_CAL_ACCEL_SENSOR] = TRUE; result = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_ACCEL_SENSOR_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_GET_ACCEL_SENSOR_CAL_REC_PAYLOAD_T ) ); } return result; } BOOL handleDDSetAccelSensorCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; return result; } BOOL handleDDGetBloodLeakSensorCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; DD_NVM_GET_BLOOD_LEAK_SENSOR_CAL_REC_PAYLOAD_T response; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { isPublishRecordRequested[ NVM_REC_TYPE_CAL_BLOOD_LEAK_SENSOR] = TRUE; result = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_BLOOD_LEAK_SENSOR_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_GET_BLOOD_LEAK_SENSOR_CAL_REC_PAYLOAD_T ) ); } return result; } BOOL handleDDSetBloodLeakSensorCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; return result; } BOOL handleDDGetConductivitySensorCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; DD_NVM_GET_CONDUCTIVITY_SENSOR_CAL_REC_PAYLOAD_T response; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { isPublishRecordRequested[ NVM_REC_TYPE_CAL_CONDUCTIVITY_SENSORS] = TRUE; result = TRUE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_CONDUCTIVITY_SENSOR_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( DD_NVM_GET_CONDUCTIVITY_SENSOR_CAL_REC_PAYLOAD_T ) ); } return result; } BOOL handleDDSetConductivitySensorCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; return result; } /*********************************************************************//** * @brief * The handleDDSetNVSystemRecord function processes a request to update * the system record. It allows updates only when the system is in * service mode. * @details \b Inputs: None * @details \b Outputs: None * @param message Pointer to the received message * @return TRUE if the record is successfully processed otherwise FALSE *************************************************************************/ BOOL handleDDSetNVSystemRecord( MESSAGE_T *message ) { BOOL result = FALSE; U08 tempBuffer[ sizeof( DD_SYSTEM_RECORD_T ) ]; UI_RESPONSE_PAYLOAD_T response; // System record can be updated only in service mode if ( DD_MODE_SERV == getCurrentOperationMode() ) { if (message->hdr.payloadLen == sizeof( DD_SYSTEM_RECORD_T )) { memcpy( tempBuffer, message->payload, sizeof( DD_SYSTEM_RECORD_T ) ); // CRC received at end of record U16 *recordCRC = (U16 *)( tempBuffer + ( sizeof( DD_SYSTEM_RECORD_T ) - sizeof(U16) ) ); U16 calcCRC = crc16( tempBuffer, sizeof( DD_SYSTEM_RECORD_T ) - sizeof(U16) ); if ( calcCRC == *recordCRC ) { currentRxRecordType = NVM_SYSTEM_RECORD; PROCESS_RECORD_SPECS_T recordSpec = getProcessRecord( NVM_SYSTEM_RECORD ); memcpy( recordSpec.structAddressPtr, tempBuffer, sizeof( DD_SYSTEM_RECORD_T ) ); setNVMRecord( NVM_SYSTEM_RECORD, tempBuffer ); result = enqueueEraseAndWriteSector( NVM_SYSTEM_RECORD ); sendNVEvent( NVM_SYSTEM_RECORD, 0, 0 ); response.accepted = TRUE; response.rejectionReason = REQUEST_REJECT_REASON_NONE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_CRC; } } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; } sendMessage( MSG_ID_DD_NVM_SET_SYSTEM_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( UI_RESPONSE_PAYLOAD_T ) ); return result; } /*********************************************************************//** * @brief * The handleDDSetNVServiceRecord function processes a request to update * the service record. It allows updates only when the system is in * service mode. * @details \b Inputs: None * @details \b Outputs: None * @param message Pointer to the received message * @return TRUE if the record is successfully processed otherwise FALSE *************************************************************************/ BOOL handleDDSetNVServiceRecord( MESSAGE_T *message ) { BOOL result = FALSE; U08 tempBuffer[ sizeof( DD_SERVICE_RECORD_T ) ]; UI_RESPONSE_PAYLOAD_T response; // Service record can be updated only in service mode if ( DD_MODE_SERV == getCurrentOperationMode() ) { if (message->hdr.payloadLen == ( sizeof( DD_SERVICE_RECORD_T ) ) ) { memcpy( tempBuffer, message->payload, sizeof( DD_SERVICE_RECORD_T ) ); // CRC assumed at end of record U16 *recordCRC = (U16 *)( tempBuffer + ( sizeof( DD_SERVICE_RECORD_T ) - sizeof(U16) ) ); U16 calcCRC = crc16( tempBuffer, sizeof( DD_SERVICE_RECORD_T ) - sizeof(U16) ); if ( calcCRC == *recordCRC ) { currentRxRecordType = NVM_SERVICE_RECORD; PROCESS_RECORD_SPECS_T recordSpec = getProcessRecord( NVM_SERVICE_RECORD ); memcpy( recordSpec.structAddressPtr, tempBuffer, sizeof( DD_SERVICE_RECORD_T ) ); setNVMRecord( NVM_SERVICE_RECORD, tempBuffer ); result = enqueueEraseAndWriteSector( NVM_SERVICE_RECORD ); sendNVEvent( NVM_SERVICE_RECORD, 0, 0 ); response.accepted = TRUE; response.rejectionReason = REQUEST_REJECT_REASON_NONE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_CRC; } } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; } sendMessage( MSG_ID_DD_NVM_SET_SERVICE_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( UI_RESPONSE_PAYLOAD_T ) ); return result; } /*********************************************************************//** * @brief * The handleDDSetNVUsageInfoRecord function processes a request to * update the usage information record. * @details \b Inputs: None * @details \b Outputs: None * @param message Pointer to the received message * @return TRUE if the record is successfully processed otherwise FALSE *************************************************************************/ BOOL handleDDSetNVUsageInfoRecord( MESSAGE_T *message ) { BOOL result = FALSE; U08 tempBuffer[ sizeof( DD_USAGE_INFO_RECORD_T ) ]; UI_RESPONSE_PAYLOAD_T response; if (message->hdr.payloadLen == ( sizeof( DD_USAGE_INFO_RECORD_T ) )) { memcpy( tempBuffer, message->payload, sizeof( DD_USAGE_INFO_RECORD_T ) ); // CRC assumed at end of record U16 *recordCRC = (U16 *)( tempBuffer + ( sizeof( DD_USAGE_INFO_RECORD_T ) - sizeof(U16) ) ); U16 calcCRC = crc16( tempBuffer, sizeof( DD_USAGE_INFO_RECORD_T ) - sizeof(U16) ); if ( calcCRC == *recordCRC ) { currentRxRecordType = NVM_USAGE_INFO_RECORD; PROCESS_RECORD_SPECS_T recordSpec = getProcessRecord( NVM_USAGE_INFO_RECORD ); memcpy( recordSpec.structAddressPtr, tempBuffer, sizeof( DD_USAGE_INFO_RECORD_T ) ); setNVMRecord( NVM_USAGE_INFO_RECORD, tempBuffer ); result = enqueueEraseAndWriteSector( NVM_USAGE_INFO_RECORD ); sendNVEvent( NVM_USAGE_INFO_RECORD, 0, 0 ); response.accepted = TRUE; response.rejectionReason = REQUEST_REJECT_REASON_NONE; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_CRC; } } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } sendMessage( MSG_ID_DD_NVM_SET_USAGE_INFO_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( UI_RESPONSE_PAYLOAD_T ) ); return result; } /*********************************************************************//** * @brief * The handleDDSetNVInstitutionalRecord function processes a request to * update the institutional record. * @details \b Inputs: None * @details \b Outputs: None * @param message Pointer to the received message * @return TRUE if the record is successfully processed otherwise FALSE *************************************************************************/ BOOL handleDDSetNVInstitutionalRecord( MESSAGE_T *message ) { BOOL result = FALSE; U08 idx = 0; U08* payloadPtr = message->payload; U08 expectedPayloadLen = sizeof( U08 ); UI_RESPONSE_PAYLOAD_T response; if ( message->hdr.payloadLen >= expectedPayloadLen ) { nvmExecreceiveRecordState = NVM_RECEIVE_RECORD_STATE_RECEIVE; memcpy( &idx, payloadPtr, sizeof( U08 ) ); payloadPtr += sizeof( U08 ); result = setNVMInstitRecord( (DD_INSTIT_REC_TYPE)idx, payloadPtr ); response.accepted = TRUE; response.rejectionReason = REQUEST_REJECT_REASON_NONE; // It is possible that we receive multiple packets of instit record // So we write it to flash when we finish receiving all packets or // a timeout occurs. institRecordReceiveStartTime = getMSTimerCount(); currentRxRecordType = NVM_INSTITUTIONAL_RECORD; } else { response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } response.fwValue = idx; sendMessage( MSG_ID_DD_NVM_SET_INSTITUTIONAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, sizeof( UI_RESPONSE_PAYLOAD_T ) ); return result; } /*********************************************************************//** * @brief * The handleDDSetPressureSensorCalRecord function processes a request * to update a pressure sensor calibration record. * @details \b Inputs: None * @details \b Outputs: None * @param message Pointer to the received message * @return TRUE if the calibration record was accepted and processed * successfully otherwise FALSE *************************************************************************/ BOOL handleDDSetPressureSensorCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; result = receiveCalRecord( message, TRUE, DD_CAL_RECORD_PRESSURE_SENSOR, sizeof( LINEAR_CAL_PAYLOAD_T ) ); return result; } /*********************************************************************//** * @brief * The handleDDSetTempSensorCalRecord function processes a request to * update a temperature sensor calibration record. * @details \b Inputs: None * @details \b Outputs: None * @param message Pointer to the received message * @return TRUE if the calibration record was accepted and processed * successfully otherwise FALSE *************************************************************************/ BOOL handleDDSetTempSensorCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; result = receiveCalRecord( message, TRUE, DD_CAL_RECORD_TEMPERATURE_SENSOR, sizeof( LINEAR_CAL_PAYLOAD_T ) ); return result; } /*********************************************************************//** * @brief * The handleDDSetConcPumpCalRecord function processes a request to * update a concentrate pump calibration record. * @details \b Inputs: None * @details \b Outputs: None * @param message Pointer to the received message * @return TRUE if the calibration record was accepted and processed * successfully otherwise FALSE *************************************************************************/ BOOL handleDDSetConcPumpCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; result = receiveCalRecord( message, TRUE, DD_CAL_RECORD_CONCENTRATE_PUMP, sizeof( LINEAR_CAL_PAYLOAD_T ) ); return result; } /*********************************************************************//** * @brief * The handleDDSetD12PumpCalRecord function processes a request to * update the D12 dialysate pump calibration record. * @details \b Inputs: None * @details \b Outputs: None * @param message Pointer to the received message * @return TRUE if the calibration record was accepted and processed * successfully otherwise FALSE *************************************************************************/ BOOL handleDDSetD12PumpCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; result = receiveCalRecord( message, FALSE, DD_CAL_RECORD_D12_PUMP, sizeof( DD_D12_DIALYSATE_PUMP_RECORD_T ) ); return result; } /*********************************************************************//** * @brief * The handleDDSetD48PumpCalRecord function processes a request to * update the D48 dialysate pump calibration record. * @details \b Inputs: None * @details \b Outputs: None * @param message Pointer to the received message * @return TRUE if the calibration record was accepted and processed * successfully otherwise FALSE *************************************************************************/ BOOL handleDDSetD48CalRecord( MESSAGE_T *message ) { BOOL result = FALSE; result = receiveCalRecord( message, FALSE, DD_CAL_RECORD_D48_PUMP, sizeof( LINEAR_CAL_PAYLOAD_T ) ); return result; } /*********************************************************************//** * @brief * The handleDDSetAcidConcCalRecord function processes a request to * update an acid concentrate calibration record. * @details \b Inputs: None * @details \b Outputs: None * @param message Pointer to the received message * @return TRUE if the calibration record was accepted and processed * successfully otherwise FALSE *************************************************************************/ BOOL handleDDSetAcidConcCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; result = receiveCalRecord( message, TRUE, DD_CAL_RECORD_ACID_CONCENTRATE, sizeof( DD_ACID_CONCENTRATE_T ) ); return result; } /*********************************************************************//** * @brief * The handleDDSetBicarbConcCalRecord function processes a request to * update a bicarb concentrate calibration record. * @details \b Inputs: None * @details \b Outputs: None * @param message Pointer to the received message * @return TRUE if the calibration record was accepted and processed * successfully otherwise FALSE *************************************************************************/ BOOL handleDDSetBicarbConcCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; result = receiveCalRecord( message, TRUE, DD_CAL_RECORD_BICARB_CONCENTRATE, sizeof( DD_BICARB_CONCENTRATE_T ) ); return result; } /*********************************************************************//** * @brief * The handleDDSetAccelSensorCalRecord function processes a request to * update the accelerometer sensor calibration record. * @details \b Inputs: None * @details \b Outputs: None * @param message Pointer to the received message * @return TRUE if the calibration record was accepted and processed * successfully otherwise FALSE *************************************************************************/ BOOL handleDDSetAccelSensorCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; result = receiveCalRecord( message, FALSE, DD_CAL_RECORD_ACCELEROMETER_SENSOR, sizeof( DD_ACCEL_SENSOR_CAL_RECORD_T ) ); return result; } /*********************************************************************//** * @brief * The handleDDSetBloodLeakSensorCalRecord function processes a request * to update the blood leak sensor calibration record. * @details \b Inputs: None * @details \b Outputs: None * @param message Pointer to the received message * @return TRUE if the calibration record was accepted and processed * successfully otherwise FALSE *************************************************************************/ BOOL handleDDSetBloodLeakSensorCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; result = receiveCalRecord( message, FALSE, DD_CAL_RECORD_BLOOD_LEAK_SENSOR, sizeof( DD_BLOOD_LEAK_SENSOR_CAL_RECORD_T ) ); return result; } /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ /*********************************************************************//** * @brief * The testSetNVRecordCRCOverride function overrides the CRC value of * the selected non-volatile record and schedules it for writing. * @details \b Inputs: None * @details \b Outputs: None * @param job The job whose CRC needs to be overridden * @param crc The CRC value to be set * @return TRUE if the job was scheduled successfully otherwise FALSE *************************************************************************/ BOOL testSetNVRecordCRCOverride( MESSAGE_T *message ) { BOOL result = FALSE; U32 job = 0; U16 crc = 0; U08* payloadPtr = message->payload; U08 expectedPayloadLen = sizeof( U32 ) + sizeof( U16 ); if ( message->hdr.payloadLen >= expectedPayloadLen ) { memcpy( &job, payloadPtr, sizeof( U32 ) ); payloadPtr += sizeof( U32 ); memcpy( &crc, payloadPtr, sizeof( U16 ) ); result = updateNVRecordCRC( job, crc ); } return result; } /**@}*/