Index: firmware/App/Services/NVMessagingDD.c =================================================================== diff -u -rbe1ff666dbd2ff03342c22c8e50b21d0f9b988a9 -rf3af61ba8f46e4cdde1c5daf749a29ae31b9f514 --- firmware/App/Services/NVMessagingDD.c (.../NVMessagingDD.c) (revision be1ff666dbd2ff03342c22c8e50b21d0f9b988a9) +++ firmware/App/Services/NVMessagingDD.c (.../NVMessagingDD.c) (revision f3af61ba8f46e4cdde1c5daf749a29ae31b9f514) @@ -2,7 +2,6 @@ * * 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 @@ -13,6 +12,8 @@ ***************************************************************************/ #include // For ceilf function + +#include "ConductivitySensors.h" #include "Messaging.h" #include "NVJobQ.h" #include "NVMessagingDD.h" @@ -35,7 +36,6 @@ #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 @@ -45,85 +45,318 @@ 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 +#pragma pack(push, 1) + +/// DD NVM Get System Record Response Payload +typedef struct { - 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; + 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; -#pragma pack(push, 1) +/// 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 Record Request Payload +/// DD NVM Get Service Record Response Payload typedef struct { - U08 recType; ///< Enum of type of record requested -} DD_GET_NVM_RECORD_PAYLOAD_T; + 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 Record Payload +/// DD NVM Set Service Record Response 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; + 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 Record Payload for Institutional data of type U32 +/// DD NVM Get Usage Info Record Response Payload typedef struct { - U08 idx; ///< Index of institutional record component - U32 data; ///< Data to be sent -} DD_NVM_U32_INSTIT_REC_PAYLOAD_T; + 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 Record Payload for Institutional data of type F32 +/// DD NVM Set Usage Info Record Response Payload typedef struct { - U08 idx; ///< Index of institutional record component - F32 data; ///< Data to be sent -} DD_NVM_F32_INSTIT_REC_PAYLOAD_T; + BOOL accepted; ///< 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; -/// DD NVM Record Payload for Polynomial structures Calibration Data +/// Institutional data reject reason structure. typedef struct { - U08 idx; ///< Index of sensor / pump / concentrates - POLYNOMIAL_CAL_PAYLOAD_T data; ///< Data to be sent -} DD_NVM_POLYNOMIAL_CAL_REC_PAYLOAD_T; + 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 Record Payload for Acid Concentrate Calibration Data +/// DD NVM Get Institutional Basic Record Response Payload typedef struct { - U08 idx; ///< Index of acid concentrates + 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. + U32 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 idx; ///< Index of sensor / pump / concentrates + 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. + U32 idx; ///< Index of acid concentrates DD_ACID_CONCENTRATE_T data; ///< Data to be sent -} DD_NVM_ACID_CONC_CAL_REC_PAYLOAD_T; +} DD_NVM_GET_ACID_CONC_CAL_REC_PAYLOAD_T; -/// DD NVM Record Payload for Bicarb Concentrate Calibration Data +/// DD NVM Set Record Payload for Acid Concentrate Calibration Data typedef struct { - U08 idx; ///< Index of bicarb concentrates + BOOL accepted; ///< Accepted/Rejected + U32 rejectionReason; ///< Reason to reject the entire request + U32 idx; ///< Index of acid concentrates + 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. + U32 idx; ///< Index of bicarb concentrates DD_BICARB_CONCENTRATE_T data; ///< Data to be sent -} DD_NVM_BICARB_CONC_CAL_REC_PAYLOAD_T; +} 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 + U32 idx; ///< Index of bicarb concentrates + 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. + U32 idx; ///< Index of conductivity sensor + CONDUCTIVITY_COEFFICIENTS_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 idx; ///< Index of conductivity sensor + U32 K_highRejectReason; ///< Reason to reject conductivity sensor calibration record parameter K_high + U32 alpha_higRejectReason; ///< Reason to reject conductivity sensor calibration record parameter alpha_high + U32 eta_highRejectReason; ///< Reason to reject conductivity sensor calibration record parameter eta_high + U32 zeta_highRejectReason; ///< Reason to reject conductivity sensor calibration record parameter zeta_high + U32 K_lowRejectReason; ///< Reason to reject conductivity sensor calibration record parameter K_low + U32 alpha_lowRejectReason; ///< Reason to reject conductivity sensor calibration record parameter alpha_low + U32 eta_lowRejectReason; ///< Reason to reject conductivity sensor calibration record parameter eta_low + U32 zeta_lowRejectReason; ///< Reason to reject conductivity sensor calibration record parameter zeta_low + U32 betaRejectReason; ///< Reason to reject conductivity sensor calibration record parameter beta + U32 deltaRejectReason; ///< Reason to reject conductivity sensor calibration record parameter delta + U32 reserved1RejectReason; ///< Reason to reject conductivity sensor calibration record parameter reserved1 + U32 reserved2RejectReason; ///< Reason to reject conductivity sensor calibration record parameter reserved2 + 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_TYPE_T recordToPublish; ///< Record type which is being processed currently for sending -static NVM_RECORD_TYPE_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 U08 maxSensorIdx; ///< Total number of sensor in current calibration data being sent -static BOOL isPublishRecordRequested[ NUM_OF_NVM_RECORD_TYPES ]; ///< Record state machine publish request flag. +static SEND_RECORD_STATE_T nvMExecSendRecordState; ///< NVM exec process record state. +static U32 newRecordStartTimer; ///< New record availability start timer. +static BOOL isNewCalRecordAvailable; ///< Signal to indicate whether a new NVM data is available. +static NV_DATA_T recordToPublish; ///< Record type which is being processed currently for sending +static NV_DATA_T nvPublishRecordType; ///< Used to index over isPublishRecordRequested in the idle state +static U32 recordSendDataIntervalCounter; ///< Record data send to CAN bust interval counter. +static U08 sendCalIdx; ///< Current Index of sensor calibration data to be sent +static BOOL isPublishRecordRequested[ NUM_OF_NV_DD_DATA ]; ///< Record state machine publish request flag. +// Calibration Record Publish Flag for index of each component +static BOOL isGetPressureCalRequested[ NUM_OF_PRESSURE_SENSORS ]; ///< Pressure Sensors Get Calibration Request Flag +static BOOL isGetTempCalRequested[ NUM_OF_TEMPERATURE_SENSORS ]; ///< Temperature Sensors Get Calibration Request Flag +static BOOL isGetConcPumpCalRequested[ NUM_OF_CONCENTRATE_PUMPS ]; ///< Concentrate Pumps Get Calibration Request Flag +static BOOL isGetAcidConcCalRequested[ NUM_OF_ACID_TYPE ]; ///< Acid Concentrates Get Calibration Request Flag +static BOOL isGetBicarbConcCalRequested[ NUM_OF_BICARB_TYPE ]; ///< Bicarb Concentrates Get Calibration Request Flag +static BOOL isGetCondSensCalRequested[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Conductivity Sensor Get Calibration Request Flag + // ********** private function prototypes ********** // Process record functions @@ -132,54 +365,50 @@ static SEND_RECORD_STATE_T handleSendDDSystemRecord( void ); static SEND_RECORD_STATE_T handleSendDDServiceRecord( void ); -static SEND_RECORD_STATE_T handleSendDDInstitutionalRecord( void ); static SEND_RECORD_STATE_T handleSendDDUsageInfoRecord( void ); -static SEND_RECORD_STATE_T handleSendDDCalibrationRecord( 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 BOOL sendPressureSensorCalRecord( void ); -static BOOL sendTempSensorCalRecord( void ); -static BOOL sendConcPumpCalRecord( void ); -static BOOL sendD12PumpCalRecord( void ); -static BOOL sendD48PumpCalRecord( void ); -static BOOL sendAcidConcCalRecord( void ); -static BOOL sendBicarbConcCalRecord( void ); -static BOOL sendAccelSensorCalRecord( void ); -static BOOL sendBloodLeakSensorCalRecord( void ); - -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 Inputs: None * @details \b Outputs: nvMExecSendRecordState, * nvmExecreceiveRecordState, newRecordStartTimer, * isNewCalRecordAvailable, nvPublishRecordType, * isPublishRecordRequested, recordPublishMsgCount, * recordPublishTotalMsgs, recordSendDataIntervalCounter, * previousRecordMessageNum, recordReceiveStartTime - * @return none + * @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; - isPublishRecordRequested[ NVM_SYSTEM_RECORD ] = FALSE; - isPublishRecordRequested[ NVM_SERVICE_RECORD ] = FALSE; - isPublishRecordRequested[ NVM_CALIBRATION_RECORD ] = FALSE; - isPublishRecordRequested[ NVM_INSTITUTIONAL_RECORD ] = FALSE; - isPublishRecordRequested[ NVM_USAGE_INFO_RECORD ] = FALSE; + nvPublishRecordType = NV_DD_DATA_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_NV_DD_DATA; i++ ) + { + isPublishRecordRequested[ i ] = FALSE; + } } /*********************************************************************//** @@ -192,7 +421,7 @@ * nvmExecreceiveRecordState, recordReceiveStartTime * @details \b Outputs: nvMExecSendRecordState, * nvmExecreceiveRecordState - * @return none + * @return None *************************************************************************/ void execNVMPSendReceiveRecord( void ) { @@ -212,31 +441,29 @@ 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( 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 ); +// 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 ); +// sendNVEvent( NVM_INSTITUTIONAL_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(); } @@ -245,10 +472,10 @@ * @brief * The setNewCalibrationRecordAvailable function updates the flag * indicating new NV record availability. - * @details \b Inputs: none + * @details \b Inputs: None * @details \b Outputs: isNewCalRecordAvailable * @param value Flag value to be updated - * @return none + * @return None *************************************************************************/ void setNewCalibrationRecordAvailable( BOOL isAvailable) { @@ -260,7 +487,7 @@ * The getNewCalRecordAvalability function gets the status of new * calibration record availability. * @details \b Inputs: isNewCalRecordAvailable - * @details \b Outputs: none + * @details \b Outputs: None * @return TRUE if new calibration record is available otherwise FALSE *************************************************************************/ BOOL getNewCalRecordAvalability( void ) @@ -272,9 +499,9 @@ * @brief * The startNewCalRecordAvailableTimer function starts the time for * new calibration record availability. - * @details \b Inputs: none + * @details \b Inputs: None * @details \b Outputs: newRecordStartTimer - * @return none + * @return None *************************************************************************/ void startNewCalRecordAvailableTimer( void ) { @@ -299,7 +526,7 @@ if ( TRUE == isPublishRecordRequested[ nvPublishRecordType ] ) { - recordToPublish = ( NVM_RECORD_TYPE_T )nvPublishRecordType; + recordToPublish = nvPublishRecordType; // Set the publish flag to FALSE isPublishRecordRequested[ recordToPublish ] = FALSE; @@ -311,10 +538,10 @@ state = NVM_SEND_RECORD_STATE_SEND; } - nvPublishRecordType = ( NVM_RECORD_TYPE_T )( nvPublishRecordType + 1 ); - if( nvPublishRecordType >= NUM_OF_NVM_RECORD_TYPES ) + nvPublishRecordType = ( NV_DATA_T )( nvPublishRecordType + 1 ); + if( nvPublishRecordType >= NUM_OF_NV_DD_DATA ) { - nvPublishRecordType = NVM_SYSTEM_RECORD; + nvPublishRecordType = NV_DD_DATA_SYSTEM_RECORD; } return state; @@ -339,25 +566,69 @@ // If it is time to send data if ( ++recordSendDataIntervalCounter >= RECORD_DATA_SEND_INTERVAL_COUNT ) { - switch(recordToPublish) + switch ( recordToPublish ) { - case NVM_SYSTEM_RECORD: + case NV_DD_DATA_SYSTEM_RECORD: state = handleSendDDSystemRecord(); break; - case NVM_SERVICE_RECORD: + case NV_DD_DATA_SERVICE_RECORD: state = handleSendDDServiceRecord(); break; - case NVM_CALIBRATION_RECORD: - state = handleSendDDCalibrationRecord(); + case NV_DD_DATA_CAL_PRESSURE_SENOSRS: + state = handleSendPressureSensorCalRecord(); break; - case NVM_INSTITUTIONAL_RECORD: - state = handleSendDDInstitutionalRecord(); + case NV_DD_DATA_CAL_TEMPERATURE_SENSORS: + state = handleSendTempSensorCalRecord(); break; - case NVM_USAGE_INFO_RECORD: + case NV_DD_DATA_CAL_CONCENTRATE_PUMPS_RECORD: + state = handleSendConcPumpCalRecord(); + break; + + case NV_DD_DATA_CAL_D12_PUMP_RECORD: + state = handleSendD12PumpCalRecord(); + break; + + case NV_DD_DATA_CAL_D48_PUMP_RECORD: + state = handleSendD48PumpCalRecord(); + break; + + case NV_DD_DATA_CAL_ACID_CONCENTREATES: + state = handleSendAcidConcCalRecord(); + break; + + case NV_DD_DATA_CAL_BICARB_CONCENTRATES: + state = handleSendBicarbConcCalRecord(); + break; + + case NV_DD_DATA_CAL_ACCELEROMETER_SENSOR: + state = handleSendAccelSensorCalRecord(); + break; + + case NV_DD_DATA_CAL_BLOOD_LEAK_SENSOR: + state = handleSendBloodLeakSensorCalRecord(); + break; + + case NV_DD_DATA_CAL_CONDUCTIVITY_SENSORS: + state = handleSendConductivitySensorCalRecord(); + break; + + case NV_DD_DATA_INSTIT_BASIC_RECORD: + state = handleSendDDInstitBasicRecord(); + break; + + case NV_DD_DATA_INSTIT_ADVANCED_RECORD: + state = handleSendDDInstitAdvancedRecord(); + break; + + case NV_DD_DATA_INSTIT_ADDITIONAL_RECORD: + state = handleSendDDInstitAdditionalRecord(); + break; + + case NV_DD_DATA_USAGE_INFO_RECORD: state = handleSendDDUsageInfoRecord(); break; @@ -376,60 +647,38 @@ * 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: recordToPublish, sendRetryCount - * @details \b Outputs: recordToPublish, sendRetryCount + * @details \b Inputs: None + * @details \b Outputs: recordToPublish * @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 sysStatus = FALSE; - DD_SYSTEM_RECORD_T systemRecord; + SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; + DD_NVM_GET_SYSTEM_REC_PAYLOAD_T payload; // Get the record - if ( TRUE == getNVMRecord( GET_SYSTEM_RECORD, - (U08*)&systemRecord, - sizeof( DD_SYSTEM_RECORD_T ) , - 0, - ALARM_ID_DD_NVM_INVALID_SYSTEM_RECORD_CRC ) ) + if ( TRUE == getNVMRecord( NV_DD_DATA_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 - sysStatus = sendMessage( MSG_ID_DD_NVM_SYSTEM_RECORD_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&systemRecord, - sizeof( DD_SYSTEM_RECORD_T ) ); + 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 ) - sizeof( U16 ) ) ); } - // Check if record send successfully - if ( TRUE == sysStatus ) - { - // Reset the retry count - sendRetryCount = 0; + // Clear the publishing flags + recordToPublish = NUM_OF_NV_DD_DATA; - // Clear the publishing flags - recordToPublish = NUM_OF_NVM_RECORD_TYPES; + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; - // 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_RECORD_TYPES; - - // Move to Send Idle State - state = NVM_SEND_RECORD_STATE_IDLE; - } - return state; } @@ -438,200 +687,251 @@ * 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: recordToPublish, sendRetryCount - * @details \b Outputs: recordToPublish, sendRetryCount + * @details \b Inputs: None + * @details \b Outputs: recordToPublish * @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 serStatus = FALSE; - DD_SERVICE_RECORD_T serviceRecord; + SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; + DD_NVM_GET_SERVICE_REC_PAYLOAD_T payload; // Get the record - if ( TRUE == getNVMRecord( GET_SERVICE_RECORD, - (U08*)&serviceRecord, - sizeof( DD_SERVICE_RECORD_T ) , - 0, - ALARM_ID_DD_NVM_INVALID_SERVICE_RECORD_CRC ) ) + if ( TRUE == getNVMRecord( NV_DD_DATA_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 - serStatus = sendMessage( MSG_ID_DD_NVM_SERVICE_RECORD_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&serviceRecord, - sizeof( DD_SERVICE_RECORD_T ) ); + 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 ) - sizeof( U16 ) ) ); } - // Check if record send successfully - if ( TRUE == serStatus ) - { - // Reset the retry count - sendRetryCount = 0; + // Clear the publishing flags + recordToPublish = NUM_OF_NV_DD_DATA; - // Clear the publishing flags - recordToPublish = NUM_OF_NVM_RECORD_TYPES; + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; - // Move to Send Idle State - state = NVM_SEND_RECORD_STATE_IDLE; - } - else - { - sendRetryCount ++; - } + return state; +} - // Utilized all the retries. Something is wrong. - if ( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) +/*********************************************************************//** + * @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: recordToPublish + * @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; + DD_NVM_GET_USAGE_INFO_REC_PAYLOAD_T payload; + + // Get the record + if ( TRUE == getNVMRecord( NV_DD_DATA_USAGE_INFO_RECORD, + (U08*)&payload.data, + sizeof( DD_USAGE_INFO_RECORD_T ), + 0, + ALARM_ID_DD_NVM_INVALID_USAGE_RECORD_CRC ) ) { - // Reset the retry count - sendRetryCount = 0; + payload.accepted = TRUE; + payload.rejectionReason = 0; - // Clear the publishing flags - recordToPublish = NUM_OF_NVM_RECORD_TYPES; - - // Move to Send Idle State - state = NVM_SEND_RECORD_STATE_IDLE; + // Send the record + sendMessage( MSG_ID_DD_UI_NVM_GET_USAGE_INFO_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, + (U08*)&payload, + ( sizeof( DD_NVM_GET_USAGE_INFO_REC_PAYLOAD_T ) - sizeof( U16 ) ) ); } + // Clear the publishing flags + recordToPublish = NUM_OF_NV_DD_DATA; + + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; + return state; } /*********************************************************************//** * @brief - * The handleSendDDInstitutionalRecord function sends institutional - * record data one item at a time. It builds the payload based on the - * data type and manages retries and record sequencing. - * @details \b Inputs: sendInstitRec, recordToPublish, sendRetryCount - * @details \b Outputs: sendInstitRec, recordToPublish, sendRetryCount + * 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: recordToPublish * @return state next state of the state machine *************************************************************************/ -static SEND_RECORD_STATE_T handleSendDDInstitutionalRecord( void ) +static SEND_RECORD_STATE_T handleSendDDInstitBasicRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; - BOOL sendStatus = FALSE; - U32 valueU32 = 0; - F32 valueF32 = 0.0; - DD_NVM_RECORD_PAYLOAD_T payload; - CRITICAL_DATA_TYPES_T dataType; + DD_NVM_GET_INSTIT_BASIC_REC_PAYLOAD_T payload; - // Get the data type of the institutional record - dataType = getInstitRecDataType( (DD_INSTIT_REC_TYPE)sendInstitRec ); - - // Create the payload based on the data type - if ( CRITICAL_DATA_TYPE_U32 == dataType ) + // Get the record + if ( TRUE == getNVMRecord( NV_DD_DATA_INSTIT_BASIC_RECORD, + (U08*)&payload.data, + sizeof( DD_INSTIT_BASIC_RECORD_T ), + 0, + ALARM_ID_DD_NVM_INVALID_INSTIT_BASIC_RECORD_CRC ) ) { - if ( TRUE == ( getNVMInstitRecord( (DD_INSTIT_REC_TYPE)sendInstitRec, (U08*)&valueU32 ) ) ) - { - memcpy( &payload.data, &valueU32, sizeof( U32 ) ); - } - } + payload.accepted = TRUE; + payload.rejectionReason = 0; - if ( CRITICAL_DATA_TYPE_F32 == dataType ) - { - if ( TRUE == ( getNVMInstitRecord( (DD_INSTIT_REC_TYPE)sendInstitRec, (U08*)&valueF32 ) ) ) - { - memcpy( &payload.data, &valueF32, sizeof( F32 ) ); - } + // Send the record + 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 ) - sizeof( U16 ) ) ); } - payload.idx = (U08)sendInstitRec; + // Clear the publishing flags + recordToPublish = NUM_OF_NV_DD_DATA; - // Send the record - sendStatus = sendMessage( MSG_ID_DD_NVM_INSTITUTIONAL_RECORD_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&payload, - sizeof( DD_NVM_RECORD_PAYLOAD_T ) ); + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; - // Check if record was sent successfully - if ( TRUE == sendStatus ) - { - // Reset the retry count - sendRetryCount = 0; + return state; +} - // Move on to publish the next institutional record - sendInstitRec = (DD_INSTIT_REC_TYPE)( (U32)sendInstitRec + 1 ); +/*********************************************************************//** + * @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: recordToPublish + * @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; + DD_NVM_GET_INSTIT_ADVANCED_REC_PAYLOAD_T payload; - } - else + // Get the record + if ( TRUE == getNVMRecord( NV_DD_DATA_INSTIT_ADVANCED_RECORD, + (U08*)&payload.data, + sizeof( DD_INSTIT_ADVANCED_RECORD_T ), + 0, + ALARM_ID_DD_NVM_INVALID_INSTIT_ADVANCED_RECORD_CRC ) ) { - sendRetryCount ++; + payload.accepted = TRUE; + payload.rejectionReason = 0; + + // Send the record + 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 ) - sizeof( U16 ) ) ); } - // If all the allowed retries has been utilized or - // If all the institutional records have been published - if ( ( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) || - ( sendInstitRec >= NUM_OF_DD_INSTIT_RECORD_TYPE ) ) - { - // Reset Index tracker for next request. - sendInstitRec = DD_INSTIT_MIN_DIALYSATE_FLOW_MLPM; + // Clear the publishing flags + recordToPublish = NUM_OF_NV_DD_DATA; - // Clear the publishing flags - recordToPublish = NUM_OF_NVM_RECORD_TYPES; + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; - // Move to Send Idle State - state = NVM_SEND_RECORD_STATE_IDLE; - - // Reset the retry count - sendRetryCount = 0; - } - return state; } /*********************************************************************//** * @brief - * The handleSendDDUsageInfoRecord function sends the DD usage - * information record. It retries transmission on failure and returns + * 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: recordToPublish, sendRetryCount - * @details \b Outputs: recordToPublish, sendRetryCount + * @details \b Inputs: None + * @details \b Outputs: recordToPublish * @return state next state of the state machine *************************************************************************/ -static SEND_RECORD_STATE_T handleSendDDUsageInfoRecord( void ) +static SEND_RECORD_STATE_T handleSendDDInstitAdditionalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; - BOOL usageStatus = FALSE; - DD_USAGE_INFO_RECORD_T usageInfoRecord; + DD_NVM_GET_INSTIT_ADDITIONAL_REC_PAYLOAD_T payload; // Get the record - if ( TRUE == getNVMRecord( GET_USAGE_RECORD, - (U08*)&usageInfoRecord, - sizeof( DD_USAGE_INFO_RECORD_T ), - 0, - ALARM_ID_DD_NVM_INVALID_USAGE_RECORD_CRC ) ) + if ( TRUE == getNVMRecord( NV_DD_DATA_INSTIT_ADDITIONAL_RECORD, + (U08*)&payload.data, + sizeof( DD_INSTIT_ADDITIONAL_RECORD_T ), + 0, + ALARM_ID_DD_NVM_INVALID_INSTIT_ADDITIONAL_RECORD_CRC ) ) { + payload.accepted = TRUE; + payload.rejectionReason = 0; + // Send the record - usageStatus = sendMessage( MSG_ID_DD_NVM_USAGE_INFO_RECORD_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&usageInfoRecord, - sizeof( DD_USAGE_INFO_RECORD_T ) ); + 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 ) - sizeof( U16 ) ) ); } - // Check if record send successfully - if ( TRUE == usageStatus ) - { - // Reset the retry count - sendRetryCount = 0; + // Clear the publishing flags + recordToPublish = NUM_OF_NV_DD_DATA; - // Clear the publishing flags - recordToPublish = NUM_OF_NVM_RECORD_TYPES; + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; - // Move to Send Idle State - state = NVM_SEND_RECORD_STATE_IDLE; - } - else + return state; +} + +/*********************************************************************//** + * @brief + * The handleSendPressureSensorCalRecord function sends the calibration + * record of the selected pressure sensor. + * @details \b Inputs: sendCalIdx + * @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; + DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T payload; + DD_PRES_SENSORS_CAL_RECORD_T record; + + // Check if record of current sensor index was requested + if ( TRUE == isGetPressureCalRequested[ sendCalIdx ] ) { - sendRetryCount ++; + // Get the record + if ( TRUE == getNVMRecord( NV_DD_DATA_CAL_PRESSURE_SENOSRS, + (U08*)&record, + sizeof( DD_PRES_SENSORS_CAL_RECORD_T ), + NUM_OF_PRESSURE_SENSORS, + ALARM_ID_DD_NVM_INVALID_CAL_PRESSURE_SENSOR ) ) + { + payload.accepted = TRUE; + payload.rejectionReason = 0; + payload.idx = sendCalIdx; + payload.data = record.pressureSensors[ sendCalIdx ]; + + // Send the record + 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 ) - sizeof( U16 ) ) ); + } } - // Utilized all the retries. Something is wrong. - if ( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) + sendCalIdx = sendCalIdx + 1; + + if ( sendCalIdx >= NUM_OF_PRESSURE_SENSORS ) { - // Reset the retry count - sendRetryCount = 0; + // Reset Sensor Index + sendCalIdx = 0; // Clear the publishing flags - recordToPublish = NUM_OF_NVM_RECORD_TYPES; + recordToPublish = NUM_OF_NV_DD_DATA; // Move to Send Idle State state = NVM_SEND_RECORD_STATE_IDLE; @@ -642,984 +942,1582 @@ /*********************************************************************//** * @brief - * The handleSendDDCalibrationRecord function sends DD calibration - * records. It manages calibration record sequencing, sensor indexing, - * retries, and transitions back to the idle state when all records - * have been published or retries are exhausted. - * @details \b Inputs: sendCalRec, sendSensorIdx, - * maxSensorIdx, recordToPublish, sendRetryCount - * @details \b Outputs: sendCalRec, sendSensorIdx, - * recordToPublish, sendRetryCount + * The handleSendTempSensorCalRecord function sends the calibration record + * of the selected temperature sensor. + * @details \b Inputs: sendCalIdx + * @details \b Outputs: None * @return state next state of the state machine *************************************************************************/ -static SEND_RECORD_STATE_T handleSendDDCalibrationRecord( void ) +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; + DD_TEMP_SENSORS_CAL_RECORD_T record; - switch ( sendCalRec ) + // Check if record of current sensor index was requested + if ( TRUE == isGetTempCalRequested[ sendCalIdx ] ) { - case DD_CAL_RECORD_PRESSURE_SENSOR: - sendStatus = sendPressureSensorCalRecord(); - break; + // Get the record + if ( TRUE == getNVMRecord( NV_DD_DATA_CAL_TEMPERATURE_SENSORS, + (U08*)&record, + sizeof( DD_TEMP_SENSORS_CAL_RECORD_T ), + NUM_OF_TEMPERATURE_SENSORS, + ALARM_ID_DD_NVM_INVALID_CAL_TEMP_SENSOR ) ) + { + payload.accepted = TRUE; + payload.rejectionReason = 0; + payload.idx = sendCalIdx; + payload.data = record.tempSensors[ sendCalIdx ]; - case DD_CAL_RECORD_TEMPERATURE_SENSOR: - sendStatus = sendTempSensorCalRecord(); - break; + // Send the record + 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 ) - sizeof( U16 ) ) ); + } + } - case DD_CAL_RECORD_CONCENTRATE_PUMP: - sendStatus = sendConcPumpCalRecord(); - break; + sendCalIdx = sendCalIdx + 1; - case DD_CAL_RECORD_D12_PUMP: - sendStatus = sendD12PumpCalRecord(); - break; + if ( sendCalIdx >= NUM_OF_TEMPERATURE_SENSORS ) + { + // Reset Sensor Index + sendCalIdx = 0; - case DD_CAL_RECORD_D48_PUMP: - sendStatus = sendD48PumpCalRecord(); - break; + // Clear the publishing flags + recordToPublish = NUM_OF_NV_DD_DATA; - case DD_CAL_RECORD_ACID_CONCENTRATE: - sendStatus = sendAcidConcCalRecord(); - break; + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; + } - case DD_CAL_RECORD_BICARB_CONCENTRATE: - sendStatus = sendBicarbConcCalRecord(); - break; + return state; +} - case DD_CAL_RECORD_ACCELEROMETER_SENSOR: - sendStatus = sendAccelSensorCalRecord(); - break; +/*********************************************************************//** + * @brief + * The handleSendConcPumpCalRecord function sends the calibration record + * of the selected concentrate pump. + * @details \b Inputs: sendCalIdx + * @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; + DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T payload; + DD_CONC_PUMPS_CAL_RECORD_T record; - case DD_CAL_RECORD_BLLOD_LEAK_SENSOR: - sendStatus = sendBloodLeakSensorCalRecord(); - break; - - default: - break; - } - - // Check if record was sent successfully - if ( TRUE == sendStatus) + // Check if record of current sensor index was requested + if ( TRUE == isGetConcPumpCalRequested[ sendCalIdx ] ) { - sendSensorIdx++; - - // Check if we sent the last record of calibration component - if ( sendSensorIdx >= maxSensorIdx ) + // Get the record + if ( TRUE == getNVMRecord( NV_DD_DATA_CAL_CONCENTRATE_PUMPS_RECORD, + (U08*)&record, + sizeof( DD_CONC_PUMPS_CAL_RECORD_T ), + NUM_OF_CONCENTRATE_PUMPS, + ALARM_ID_DD_NVM_INVALID_CAL_CONC_PUMP ) ) { - // Reset Sensor Index for the next calibration data - sendSensorIdx = 0; + payload.accepted = TRUE; + payload.rejectionReason = 0; + payload.idx = sendCalIdx; + payload.data = record.concentratePumps[ sendCalIdx ]; - // Reset the retry count for the next calibration data - sendRetryCount = 0; - - // Move on to publish the next calibration record - sendCalRec = (DD_CAL_REC_TYPE)( (U32)sendCalRec + 1 ); + // Send the record + 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 ) - sizeof( U16 ) ) ); } } - else - { - sendRetryCount ++; - } - // If all the allowed retries has been utilized or - // If all the calibration records have been published - if ( ( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) || - ( sendCalRec >= NUM_OF_CAL_RECORD_TYPE ) ) + sendCalIdx = sendCalIdx + 1; + + if ( sendCalIdx >= NUM_OF_CONCENTRATE_PUMPS ) { - // Reset Sensor Index for the next request - sendSensorIdx = 0; + // Reset Sensor Index + sendCalIdx = 0; - // Reset Index tracker for next request. - sendCalRec = DD_CAL_RECORD_PRESSURE_SENSOR; - // Clear the publishing flags - recordToPublish = NUM_OF_NVM_RECORD_TYPES; + recordToPublish = NUM_OF_NV_DD_DATA; // Move to Send Idle State state = NVM_SEND_RECORD_STATE_IDLE; - - // Reset the retry count - sendRetryCount = 0; } return state; } /*********************************************************************//** * @brief - * The sendPressureSensorCalRecord function sends the calibration - * record of the selected pressure sensor. - * @details \b Inputs: sendSensorIdx - * @details \b Outputs: maxSensorIdx - * @return TRUE if the message was successfully sent otherwise FALSE + * The handleSendD12PumpCalRecord function sends the calibration record of + * the D12 dialysate pump. + * @details \b Inputs: None + * @details \b Outputs: sendCalIdx + * @return state next state of the state machine *************************************************************************/ -static BOOL sendPressureSensorCalRecord( void ) +static SEND_RECORD_STATE_T handleSendD12PumpCalRecord( void ) { - BOOL sendStatus = FALSE; - DD_NVM_POLYNOMIAL_CAL_REC_PAYLOAD_T payload; + SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; + DD_NVM_GET_D12_PUMP_CAL_REC_PAYLOAD_T payload; - maxSensorIdx = NUM_OF_PRESSURE_SENSORS; - payload.idx = sendSensorIdx; - payload.data = getPressureSensorCalRecord( sendSensorIdx ); + // Get the record + if ( TRUE == getNVMRecord( NV_DD_DATA_CAL_D12_PUMP_RECORD, + (U08*)&payload.data, + sizeof( DD_D12_DIALYSATE_PUMP_RECORD_T ), + 0, + ALARM_ID_DD_NVM_INVALID_CAL_D12_PUMP ) ) + { + payload.accepted = TRUE; + payload.rejectionReason = 0; + sendCalIdx = 0; - // Send the record - sendStatus = sendMessage( MSG_ID_DD_NVM_CAL_PRESSURE_SENSOR_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&payload, - sizeof( DD_NVM_POLYNOMIAL_CAL_REC_PAYLOAD_T ) ); + // Send the record + 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 ) - sizeof( U16 ) ) ); + } - return sendStatus; + return state; } /*********************************************************************//** * @brief - * The sendTempSensorCalRecord function sends the calibration record - * of the selected temperature sensor. - * @details \b Inputs: sendSensorIdx - * @details \b Outputs: maxSensorIdx - * @return TRUE if the message was successfully sent otherwise FALSE + * The handleSendD48PumpCalRecord function sends the calibration record of + * the D48 dialysate pump. + * @details \b Inputs: None + * @details \b Outputs: sendCalIdx + * @return state next state of the state machine *************************************************************************/ -static BOOL sendTempSensorCalRecord( void ) +static SEND_RECORD_STATE_T handleSendD48PumpCalRecord( void ) { - BOOL sendStatus = FALSE; - DD_NVM_POLYNOMIAL_CAL_REC_PAYLOAD_T payload; + SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; + DD_NVM_GET_D48_PUMP_CAL_REC_PAYLOAD_T payload; - maxSensorIdx = NUM_OF_TEMPERATURE_SENSORS; - payload.idx = sendSensorIdx; - payload.data = getTemperatureSensorCalRecord( sendSensorIdx ); + // Get the record + if ( TRUE == getNVMRecord( NV_DD_DATA_CAL_D48_PUMP_RECORD, + (U08*)&payload.data, + sizeof( DD_D48_DIALYSATE_PUMP_RECORD_T ), + 0, + ALARM_ID_DD_NVM_INVALID_CAL_D48_PUMP ) ) + { + payload.accepted = TRUE; + payload.rejectionReason = 0; + sendCalIdx = 0; - // Send the record - sendStatus = sendMessage( MSG_ID_DD_NVM_CAL_TEMP_SENSOR_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&payload, - sizeof( DD_NVM_POLYNOMIAL_CAL_REC_PAYLOAD_T ) ); + // Send the record + 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 ) - sizeof( U16 ) ) ); + } - return sendStatus; + return state; } /*********************************************************************//** * @brief - * The sendConcPumpCalRecord function sends the calibration record - * of the selected concentrate pump. - * @details \b Inputs: sendSensorIdx - * @details \b Outputs: maxSensorIdx - * @return TRUE if the message was successfully sent otherwise FALSE + * The handleSendAcidConcCalRecord function sends the calibration record of + * the selected acid concentrate. + * @details \b Inputs: sendCalIdx + * @details \b Outputs: None + * @return state next state of the state machine *************************************************************************/ -static BOOL sendConcPumpCalRecord( void ) +static SEND_RECORD_STATE_T handleSendAcidConcCalRecord( void ) { - BOOL sendStatus = FALSE; - DD_NVM_POLYNOMIAL_CAL_REC_PAYLOAD_T payload; + SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; + DD_NVM_GET_ACID_CONC_CAL_REC_PAYLOAD_T payload; + DD_ACID_CONCENTRATES_RECORD_T record; - maxSensorIdx = NUM_OF_CONCENTRATE_PUMPS; - payload.idx = sendSensorIdx; - payload.data = getConcPumpCalRecord( sendSensorIdx ); + // Check if record of current sensor index was requested + if ( TRUE == isGetAcidConcCalRequested[ sendCalIdx ] ) + { + // Get the record + if ( TRUE == getNVMRecord( NV_DD_DATA_CAL_ACID_CONCENTREATES, + (U08*)&record, + sizeof( DD_ACID_CONCENTRATES_RECORD_T ), + NUM_OF_ACID_TYPE, + ALARM_ID_DD_NVM_INVALID_CAL_ACID_CONCENTRATE ) ) + { + payload.accepted = TRUE; + payload.rejectionReason = 0; + payload.idx = sendCalIdx; + payload.data = record.acidConcentrate[ sendCalIdx ]; - // Send the record - sendStatus = sendMessage( MSG_ID_DD_NVM_CAL_CONC_PUMP_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&payload, - sizeof( DD_NVM_POLYNOMIAL_CAL_REC_PAYLOAD_T ) ); + // Send the record + 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 ) - sizeof( U16 ) ) ); + } + } - return sendStatus; -} + sendCalIdx = sendCalIdx + 1; -/*********************************************************************//** - * @brief - * The sendD12PumpCalRecord function sends the calibration record of - * the D12 dialysate pump. - * @details \b Inputs: none - * @details \b Outputs: sendSensorIdx, maxSensorIdx - * @return TRUE if the message was successfully sent otherwise FALSE - *************************************************************************/ -static BOOL sendD12PumpCalRecord( void ) -{ - BOOL sendStatus = FALSE; - DD_D12_DIALYSATE_PUMP_RECORD_T payload = getD12PumpCalRecord( ); + if ( sendCalIdx >= NUM_OF_ACID_TYPE ) + { + // Reset Sensor Index + sendCalIdx = 0; - sendSensorIdx = 0; - maxSensorIdx = 0; + // Clear the publishing flags + recordToPublish = NUM_OF_NV_DD_DATA; - // Send the record - sendStatus = sendMessage( MSG_ID_DD_NVM_CAL_D12_PUMP_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&payload, - sizeof( DD_D12_DIALYSATE_PUMP_RECORD_T ) ); + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; + } - return sendStatus; + return state; } /*********************************************************************//** * @brief - * The sendD48PumpCalRecord function sends the calibration record of - * the D48 dialysate pump. - * @details \b Inputs: none - * @details \b Outputs: sendSensorIdx, maxSensorIdx - * @return TRUE if the message was successfully sent otherwise FALSE + * The handleSendAcidConcCalRecord function sends the calibration record of + * the selected acid concentrate. + * @details \b Inputs: sendCalIdx + * @details \b Outputs: None + * @return state next state of the state machine *************************************************************************/ -static BOOL sendD48PumpCalRecord( void ) +static SEND_RECORD_STATE_T handleSendBicarbConcCalRecord( void ) { - BOOL sendStatus = FALSE; - DD_D48_DIALYSATE_PUMP_RECORD_T payload = getD48PumpCalRecord( ); + SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; + DD_NVM_GET_BICARB_CONC_CAL_REC_PAYLOAD_T payload; + DD_BICARB_CONCENTRATES_RECORD_T record; - sendSensorIdx = 0; - maxSensorIdx = 0; + // Check if record of current sensor index was requested + if ( TRUE == isGetBicarbConcCalRequested[ sendCalIdx ] ) + { + // Get the record + if ( TRUE == getNVMRecord( NV_DD_DATA_CAL_BICARB_CONCENTRATES, + (U08*)&record, + sizeof( DD_BICARB_CONCENTRATES_RECORD_T ), + NUM_OF_BICARB_TYPE, + ALARM_ID_DD_NVM_INVALID_CAL_BICARB_CONCENTRATE ) ) + { + payload.accepted = TRUE; + payload.rejectionReason = 0; + payload.idx = sendCalIdx; + payload.data = record.bicarbConcentrate[ sendCalIdx ]; - // Send the record - sendStatus = sendMessage( MSG_ID_DD_NVM_CAL_D48_PUMP_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&payload, - sizeof( DD_D48_DIALYSATE_PUMP_RECORD_T ) ); + // Send the record + 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 ) - sizeof( U16 ) ) ); + } + } - return sendStatus; -} + sendCalIdx = sendCalIdx + 1; -/*********************************************************************//** - * @brief - * The sendAcidConcCalRecord function sends the calibration record of - * the selected acid concentrate. - * @details \b Inputs: sendSensorIdx - * @details \b Outputs: maxSensorIdx - * @return TRUE if the message was successfully sent otherwise FALSE - *************************************************************************/ -static BOOL sendAcidConcCalRecord( void ) -{ - BOOL sendStatus = FALSE; - DD_NVM_ACID_CONC_CAL_REC_PAYLOAD_T payload; + if ( sendCalIdx >= NUM_OF_BICARB_TYPE ) + { + // Reset Sensor Index + sendCalIdx = 0; - maxSensorIdx = NUM_OF_ACID_TYPE; - payload.idx = sendSensorIdx; - payload.data = getAcidConcentrateCalRecord( sendSensorIdx ); + // Clear the publishing flags + recordToPublish = NUM_OF_NV_DD_DATA; - // Send the record - sendStatus = sendMessage( MSG_ID_DD_NVM_CAL_ACID_CONCENTRATE_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&payload, - sizeof( DD_NVM_ACID_CONC_CAL_REC_PAYLOAD_T ) ); + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; + } - return sendStatus; + return state; } /*********************************************************************//** * @brief - * The sendAcidConcCalRecord function sends the calibration record of - * the selected acid concentrate. - * @details \b Inputs: sendSensorIdx - * @details \b Outputs: maxSensorIdx - * @return TRUE if the message was successfully sent otherwise FALSE + * The handleSendAccelSensorCalRecord function sends the calibration record + * of the accelerometer sensor. + * @details \b Inputs: None + * @details \b Outputs: sendCalIdx + * @return state next state of the state machine *************************************************************************/ -static BOOL sendBicarbConcCalRecord( void ) +static SEND_RECORD_STATE_T handleSendAccelSensorCalRecord( void ) { - BOOL sendStatus = FALSE; - DD_NVM_BICARB_CONC_CAL_REC_PAYLOAD_T payload; + SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; + DD_NVM_GET_ACCEL_SENSOR_CAL_REC_PAYLOAD_T payload; - maxSensorIdx = NUM_OF_BICARB_TYPE; - payload.idx = sendSensorIdx; - payload.data = getBicarbConcentrateCalRecord( sendSensorIdx ); + // Get the record + if ( TRUE == getNVMRecord( NV_DD_DATA_CAL_ACCELEROMETER_SENSOR, + (U08*)&payload.data, + sizeof( DD_ACCEL_SENSOR_CAL_RECORD_T ), + 0, + ALARM_ID_DD_NVM_INVALID_CAL_ACCEL_SENSOR ) ) + { + payload.accepted = TRUE; + payload.rejectionReason = 0; + sendCalIdx = 0; - // Send the record - sendStatus = sendMessage( MSG_ID_DD_NVM_CAL_BICARB_CONCENTRATE_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&payload, - sizeof( DD_NVM_BICARB_CONC_CAL_REC_PAYLOAD_T ) ); + // Send the record + 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 ) - sizeof( U16 ) ) ); + } - return sendStatus; + // Clear the publishing flags + recordToPublish = NUM_OF_NV_DD_DATA; + + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; + + return state; } /*********************************************************************//** * @brief - * The sendAccelSensorCalRecord function sends the calibration record - * of the accelerometer sensor. - * @details \b Inputs: none - * @details \b Outputs: sendSensorIdx, maxSensorIdx - * @return TRUE if the message was successfully sent otherwise FALSE + * The handleSendBloodLeakSensorCalRecord function sends the calibration + * record of the blood leak sensor. + * @details \b Inputs: None + * @details \b Outputs: sendCalIdx + * @return state next state of the state machine *************************************************************************/ -static BOOL sendAccelSensorCalRecord( void ) +static SEND_RECORD_STATE_T handleSendBloodLeakSensorCalRecord( void ) { - BOOL sendStatus = FALSE; - DD_ACCEL_SENSOR_CAL_RECORD_T payload = getAccelSensorCalRecord( ); + SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; + DD_NVM_GET_BLOOD_LEAK_SENSOR_CAL_REC_PAYLOAD_T payload; - sendSensorIdx = 0; - maxSensorIdx = 0; + // Get the record + if ( TRUE == getNVMRecord( NV_DD_DATA_CAL_BLOOD_LEAK_SENSOR, + (U08*)&payload.data, + sizeof( DD_BLOOD_LEAK_SENSOR_CAL_RECORD_T ), + 0, + ALARM_ID_DD_NVM_INVALID_CAL_BLOOD_LEAK_SENSOR ) ) + { + payload.accepted = TRUE; + payload.rejectionReason = 0; + sendCalIdx = 0; - // Send the record - sendStatus = sendMessage( MSG_ID_DD_NVM_CAL_ACCEL_SENSOR_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&payload, - sizeof( DD_ACCEL_SENSOR_CAL_RECORD_T ) ); + // Send the record + 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 ) - sizeof( U16 ) ) ); + } - return sendStatus; + // Clear the publishing flags + recordToPublish = NUM_OF_NV_DD_DATA; + + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; + + return state; } /*********************************************************************//** * @brief - * The sendBloodLeakSensorCalRecord function sends the calibration - * record of the blood leak sensor. - * @details \b Inputs: none - * @details \b Outputs: sendSensorIdx, maxSensorIdx - * @return TRUE if the message was successfully sent otherwise FALSE + * The handleSendConductivitySensorCalRecord function sends the calibration + * record of the conductivity sensor. + * @details \b Inputs: sendCalIdx + * @details \b Outputs: None + * @return state next state of the state machine *************************************************************************/ -static BOOL sendBloodLeakSensorCalRecord( void ) +static SEND_RECORD_STATE_T handleSendConductivitySensorCalRecord( void ) { - BOOL sendStatus = FALSE; - DD_BLOOD_LEAK_SENSOR_CAL_RECORD_T payload = getBloodLeakSensorCalRecord( ); + SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; + DD_NVM_GET_CONDUCTIVITY_SENSOR_CAL_REC_PAYLOAD_T payload; + DD_CONDUCTIVITY_SENSOR_CAL_RECORD_T record; - sendSensorIdx = 0; - maxSensorIdx = 0; + // Check if record of current sensor index was requested + if ( TRUE == isGetCondSensCalRequested[ sendCalIdx ] ) + { + // Get the record + if ( TRUE == getNVMRecord( NV_DD_DATA_CAL_CONDUCTIVITY_SENSORS, + (U08*)&record, + sizeof( DD_CONDUCTIVITY_SENSOR_CAL_RECORD_T ), + NUM_OF_CONDUCTIVITY_SENSORS, + ALARM_ID_DD_NVM_INVALID_CAL_CONDUCTIVITY_SENSOR ) ) + { + payload.accepted = TRUE; + payload.rejectionReason = 0; + payload.idx = sendCalIdx; + payload.data = record.condSensors[ sendCalIdx ]; - // Send the record - sendStatus = sendMessage( MSG_ID_DD_NVM_CAL_BLOOD_LEAK_SENSOR_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&payload, - sizeof( DD_BLOOD_LEAK_SENSOR_CAL_RECORD_T ) ); + // Send the record + 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 ) - sizeof( U16 ) ) ); + } + } - return sendStatus; + sendCalIdx = sendCalIdx + 1; + + if ( sendCalIdx >= NUM_OF_CONDUCTIVITY_SENSORS ) + { + // Reset Sensor Index + sendCalIdx = 0; + + // Clear the publishing flags + recordToPublish = NUM_OF_NV_DD_DATA; + + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; + } + + return state; } /*********************************************************************//** * @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 + * 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 BOOL receiveCalRecord( MESSAGE_T* message, BOOL isIndexed, - DD_CAL_REC_TYPE calRecordType, U16 recordSize ) +static void monitorNewCalSignal( void ) { - BOOL status = FALSE; - U08* payloadPtr = message->payload; - U08 expectedPayloadLen = recordSize ; - MSG_ID_T msgID = getNVMCalRecordResponseMsgId( calRecordType ); - UI_RESPONSE_PAYLOAD_T response; + // 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 ); + } +} - if ( TRUE == isIndexed ) +BOOL handleDDGetSystemRecRequest( MESSAGE_T *message ) +{ + BOOL result = FALSE; + DD_NVM_GET_SYSTEM_REC_PAYLOAD_T response; + + if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - expectedPayloadLen = ( sizeof(U08) + recordSize ); + isPublishRecordRequested[ NV_DD_DATA_SYSTEM_RECORD ] = TRUE; + result = TRUE; } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; - DD_NVM_RECORD_PAYLOAD_T recvdPayload; + 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 ) { - // Get the index of the received calibration record if required - if ( TRUE == isIndexed ) - { - memcpy( &recvdPayload.idx, payloadPtr, sizeof(U08)); - payloadPtr += sizeof(U08); - } + memcpy( &record, message->payload, expectedPayloadLen ); + record.crc = crc16( (U08*)&record, expectedPayloadLen ); + setNVMMRecord( NV_DD_DATA_SYSTEM_RECORD, (U08*)&record, 0 ); + result = enqueueEraseAndWriteSector( NVM_SYSTEM_RECORD ); + sendNVEvent( NVM_SYSTEM_RECORD, 0, 0 ); + response.accepted = TRUE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; + } - memcpy( &recvdPayload.data, payloadPtr, recordSize ); + 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 ) ); - // CRC assumed at end of record - U16 *recordCRC = (U16*)( recvdPayload.data + ( recordSize - sizeof(U16) ) ); - U16 calcCRC = crc16( recvdPayload.data, recordSize - sizeof(U16) ); + return result; +} - if ( calcCRC == *recordCRC ) - { - nvmExecreceiveRecordState = NVM_RECEIVE_RECORD_STATE_RECEIVE; - status = setNVMCalRecord( calRecordType, (U08*)&recvdPayload.data, recvdPayload.idx ); +BOOL handleDDGetServicRecRequest( MESSAGE_T *message ) +{ + BOOL result = FALSE; + DD_NVM_GET_SERVICE_REC_PAYLOAD_T response; - response.accepted = TRUE; - response.rejectionReason = REQUEST_REJECT_REASON_NONE; + if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) + { + isPublishRecordRequested[ NV_DD_DATA_SERVICE_RECORD ] = TRUE; + result = TRUE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; - // 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; - } + 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 ); + record.crc = crc16( (U08*)&record, expectedPayloadLen ); + setNVMMRecord( NV_DD_DATA_SERVICE_RECORD, (U08*)&record, 0 ); + 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; } - response.fwValue = recvdPayload.idx; - sendMessage( msgID, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&response, - sizeof( UI_RESPONSE_PAYLOAD_T ) ); + 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 status; + return result; } -/*********************************************************************//** - * @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 ) +BOOL handleDDGetUsageInfoRecRequest( MESSAGE_T *message ) { - MSG_ID_T msgId = MSG_ID_UNUSED; + BOOL result = FALSE; + DD_NVM_GET_USAGE_INFO_REC_PAYLOAD_T response; - switch ( calRecordType ) + if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - case DD_CAL_RECORD_PRESSURE_SENSOR: - msgId = MSG_ID_DD_NVM_SET_CAL_PRESSURE_SENSOR_RESPONSE; - break; + isPublishRecordRequested[ NV_DD_DATA_USAGE_INFO_RECORD ] = TRUE; + result = TRUE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; - case DD_CAL_RECORD_TEMPERATURE_SENSOR: - msgId = MSG_ID_DD_NVM_SET_CAL_TEMP_SENSOR_RESPONSE; - break; + 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 ) ); + } - case DD_CAL_RECORD_CONCENTRATE_PUMP: - msgId = MSG_ID_DD_NVM_SET_CAL_CONC_PUMP_RESPONSE; - break; + return result; +} - case DD_CAL_RECORD_D12_PUMP: - msgId = MSG_ID_DD_NVM_SET_CAL_D12_PUMP_RESPONSE; - break; +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; - case DD_CAL_RECORD_D48_PUMP: - msgId = MSG_ID_DD_NVM_SET_CAL_D48_PUMP_RESPONSE; - break; + if ( message->hdr.payloadLen == expectedPayloadLen ) + { + memcpy( &record, message->payload, expectedPayloadLen ); + record.crc = crc16( (U08*)&record, expectedPayloadLen ); + setNVMMRecord( NV_DD_DATA_USAGE_INFO_RECORD, (U08*)&record, 0 ); + result = enqueueEraseAndWriteSector( NVM_USAGE_INFO_RECORD ); + sendNVEvent( NVM_USAGE_INFO_RECORD, 0, 0 ); + response.accepted = TRUE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } - case DD_CAL_RECORD_ACID_CONCENTRATE: - msgId = MSG_ID_DD_NVM_SET_CAL_ACID_CONCENTRATE_RESPONSE; - break; + 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 ) ); - case DD_CAL_RECORD_BICARB_CONCENTRATE: - msgId = MSG_ID_DD_NVM_SET_CAL_BICARB_CONCENTRATE_RESPONSE; - break; + return result; +} - case DD_CAL_RECORD_ACCELEROMETER_SENSOR: - msgId = MSG_ID_DD_NVM_SET_CAL_ACCEL_SENSOR_RESPONSE; - break; +BOOL handleDDGetInstitBasicRecRequest( MESSAGE_T *message ) +{ + BOOL result = FALSE; + DD_NVM_GET_INSTIT_BASIC_REC_PAYLOAD_T response; - case DD_CAL_RECORD_BLLOD_LEAK_SENSOR: - msgId = MSG_ID_DD_NVM_SET_CAL_BLOOD_LEAK_SENSOR_RESPONSE; - break; + if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) + { + isPublishRecordRequested[ NV_DD_DATA_INSTIT_BASIC_RECORD ] = TRUE; + result = TRUE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; - default: - // Software fault - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, ( U32 )calRecordType ); - break; + 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 msgId; + return result; } -/*********************************************************************//** - * @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 ) +BOOL handleDDSetInstitBasicRecRequest( MESSAGE_T *message ) { - // Check if new calibration record is available and - // the timer has elapsed - if ( ( TRUE == didTimeout( newRecordStartTimer, NEW_CAL_AVAILABLE_SIGNAL_TIMEOUT_MS ) ) && - ( TRUE == getNewCalRecordAvalability() ) ) + 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 ) { - // Clear the new calibration record available flag - setNewCalibrationRecordAvailable( FALSE ); + memcpy( &record, message->payload, expectedPayloadLen ); + record.crc = crc16( (U08*)&record, expectedPayloadLen ); + setNVMMRecord( NV_DD_DATA_INSTIT_BASIC_RECORD, (U08*)&record, 0 ); + result = enqueueEraseAndWriteSector( NVM_INSTITUTIONAL_RECORD ); + sendNVEvent( NVM_INSTITUTIONAL_RECORD, 0, 0 ); + response.accepted = TRUE; } + else + { + 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; -/************************************************************************* - * TEST SUPPORT FUNCTIONS - *************************************************************************/ + if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) + { + isPublishRecordRequested[ NV_DD_DATA_INSTIT_ADVANCED_RECORD ] = TRUE; + result = TRUE; + } + else + { + 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 ) ); + } -/*********************************************************************//** - * @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 ) + return result; +} + +BOOL handleDDSetInstitAdvancedRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; - NVM_RECORD_TYPE_T job; - UI_RESPONSE_PAYLOAD_T response; + 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; - // verify payload length - if ( sizeof( DD_GET_NVM_RECORD_PAYLOAD_T ) == message->hdr.payloadLen ) + if ( message->hdr.payloadLen == expectedPayloadLen ) { - job = ( NVM_RECORD_TYPE_T )message->payload[ 0 ]; + memcpy( &record, message->payload, expectedPayloadLen ); + record.crc = crc16( (U08*)&record, expectedPayloadLen ); + setNVMMRecord( NV_DD_DATA_INSTIT_ADVANCED_RECORD, (U08*)&record, 0 ); + result = enqueueEraseAndWriteSector( NVM_INSTITUTIONAL_RECORD ); + sendNVEvent( NVM_INSTITUTIONAL_RECORD, 0, 0 ); + response.accepted = TRUE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } - // 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 ) ) + 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[ NV_DD_DATA_INSTIT_ADDITIONAL_RECORD ] = TRUE; + result = TRUE; + } + else + { + 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, expectedPayloadLen ); + setNVMMRecord( NV_DD_DATA_INSTIT_ADDITIONAL_RECORD, (U08*)&record, 0 ); + result = enqueueEraseAndWriteSector( NVM_INSTITUTIONAL_RECORD ); + sendNVEvent( NVM_INSTITUTIONAL_RECORD, 0, 0 ); + response.accepted = TRUE; + } + else + { + 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; + U08* payloadPtr = message->payload; + U08 expectedPayloadLen = sizeof( U32 ); + DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T response; + U32 idx; + + if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) + { + if ( message->hdr.payloadLen == expectedPayloadLen ) { - isPublishRecordRequested[ job ] = TRUE; - recordToPublish = job; - result = TRUE; - response.accepted = TRUE; - response.rejectionReason = REQUEST_REJECT_REASON_NONE; + memcpy( &idx, payloadPtr, sizeof(U32)); + + if( idx < NUM_OF_PRESSURE_SENSORS ) + { + isPublishRecordRequested[ NV_DD_DATA_CAL_PRESSURE_SENOSRS ] = TRUE; + isGetPressureCalRequested[ idx ] = TRUE; + result = TRUE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INDEX_OUT_OF_RANGE; + } } else { - response.accepted = FALSE; - response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } } else { - response.accepted = FALSE; - response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + 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 ) ); } - sendMessage( MSG_ID_DD_NVM_GET_RECORD_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, - sizeof( UI_RESPONSE_PAYLOAD_T ) ); - 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 handleDDSetPressureSensorCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; - U08 tempBuffer[ sizeof( DD_SYSTEM_RECORD_T ) ]; - UI_RESPONSE_PAYLOAD_T response; + BOOL result = FALSE; + U08* payloadPtr = message->payload; + U08 recordSize = sizeof( LINEAR_CAL_PAYLOAD_T ) - sizeof( U16 ); // Data - CRC + U08 expectedPayloadLen = sizeof( U32 ) + recordSize; // Index + Data - CRC + DD_NVM_SET_LINEAR_CAL_REC_PAYLOAD_T response = { 0 }; + U32 idx; + LINEAR_CAL_PAYLOAD_T record; - // System record can be updated only in service mode + // Calibration record can be updated only in service mode if ( DD_MODE_SERV == getCurrentOperationMode() ) { - if (message->hdr.payloadLen == sizeof( DD_SYSTEM_RECORD_T )) + if ( message->hdr.payloadLen == expectedPayloadLen ) { - memcpy( tempBuffer, message->payload, sizeof( DD_SYSTEM_RECORD_T ) ); + memcpy( &idx, payloadPtr, sizeof(U32)); + payloadPtr += sizeof(U32); - // 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 ) + if( idx < NUM_OF_PRESSURE_SENSORS ) { - 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; + memcpy( &record, payloadPtr, recordSize ); + record.crc = crc16( (U08*)&record, recordSize ); + setNVMMRecord( NV_DD_DATA_CAL_PRESSURE_SENOSRS, (U08*)&record, idx ); + result = enqueueEraseAndWriteSector( NVM_CALIBRATION_RECORD ); + sendNVEvent( NVM_CALIBRATION_RECORD, 0, 0 ); + response.idx = idx; + response.accepted = TRUE; } else { - response.accepted = FALSE; - response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_CRC; + response.rejectionReason = REQUEST_REJECT_REASON_INDEX_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_NVM_SET_SYSTEM_RECORD_RESPONSE, + sendMessage( MSG_ID_DD_UI_NVM_SET_PRESSURE_SENSOR_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, - sizeof( UI_RESPONSE_PAYLOAD_T ) ); + sizeof( DD_NVM_SET_LINEAR_CAL_REC_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 handleDDGetTemperatureSensorCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; - U08 tempBuffer[ sizeof( DD_SERVICE_RECORD_T ) ]; - UI_RESPONSE_PAYLOAD_T response; + BOOL result = FALSE; + U08* payloadPtr = message->payload; + U08 expectedPayloadLen = sizeof( U32 ); + DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T response; + U32 idx; - // Service record can be updated only in service mode + if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) + { + if ( message->hdr.payloadLen == expectedPayloadLen ) + { + memcpy( &idx, payloadPtr, sizeof(U32)); + + if( idx < NUM_OF_TEMPERATURE_SENSORS ) + { + isPublishRecordRequested[ NV_DD_DATA_CAL_TEMPERATURE_SENSORS ] = TRUE; + isGetTempCalRequested[ idx ] = TRUE; + result = TRUE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INDEX_OUT_OF_RANGE; + } + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + } + else + { + 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; + U08* payloadPtr = message->payload; + U08 recordSize = sizeof( LINEAR_CAL_PAYLOAD_T ) - sizeof( U16 ); // Data - CRC + U08 expectedPayloadLen = sizeof( U32 ) + recordSize; // Index + Data - CRC + DD_NVM_SET_LINEAR_CAL_REC_PAYLOAD_T response = { 0 }; + U32 idx; + LINEAR_CAL_PAYLOAD_T record; + + // Calibration record can be updated only in service mode if ( DD_MODE_SERV == getCurrentOperationMode() ) { - if (message->hdr.payloadLen == ( sizeof( DD_SERVICE_RECORD_T ) ) ) + if ( message->hdr.payloadLen == expectedPayloadLen ) { - memcpy( tempBuffer, message->payload, sizeof( DD_SERVICE_RECORD_T ) ); + memcpy( &idx, payloadPtr, sizeof(U08)); + payloadPtr += sizeof(U08); - // 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( idx < NUM_OF_TEMPERATURE_SENSORS ) + { + memcpy( &record, payloadPtr, recordSize ); + record.crc = crc16( (U08*)&record, recordSize ); + setNVMMRecord( NV_DD_DATA_CAL_TEMPERATURE_SENSORS, (U08*)&record, idx ); + result = enqueueEraseAndWriteSector( NVM_CALIBRATION_RECORD ); + sendNVEvent( NVM_CALIBRATION_RECORD, 0, 0 ); + response.idx = idx; + response.accepted = TRUE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INDEX_OUT_OF_RANGE; + } + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; + } - if ( calcCRC == *recordCRC ) + sendMessage( MSG_ID_DD_UI_NVM_SET_TEMPERATURE_SENSOR_CAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, + sizeof( DD_NVM_SET_LINEAR_CAL_REC_PAYLOAD_T ) ); + + return result; +} + +BOOL handleDDGetConcPumpCalRecRequest( MESSAGE_T *message ) +{ + BOOL result = FALSE; + U08* payloadPtr = message->payload; + U08 expectedPayloadLen = sizeof( U32 ); + DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T response; + U32 idx; + + if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) + { + if ( message->hdr.payloadLen == expectedPayloadLen ) + { + memcpy( &idx, payloadPtr, sizeof(U32)); + + if( idx < NUM_OF_CONCENTRATE_PUMPS ) { - 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 ); + isPublishRecordRequested[ NV_DD_DATA_CAL_CONCENTRATE_PUMPS_RECORD] = TRUE; + isGetConcPumpCalRequested[ idx ] = TRUE; + result = TRUE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INDEX_OUT_OF_RANGE; + } + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; - response.accepted = TRUE; - response.rejectionReason = REQUEST_REJECT_REASON_NONE; + 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; + U08* payloadPtr = message->payload; + U08 recordSize = sizeof( LINEAR_CAL_PAYLOAD_T ) - sizeof( U16 ); // Data - CRC + U08 expectedPayloadLen = sizeof( U32 ) + recordSize; // Index + Data - CRC + DD_NVM_SET_LINEAR_CAL_REC_PAYLOAD_T response = { 0 }; + U32 idx; + LINEAR_CAL_PAYLOAD_T record; + + // Calibration 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_CONCENTRATE_PUMPS ) + { + memcpy( &record, payloadPtr, recordSize ); + record.crc = crc16( (U08*)&record, recordSize ); + setNVMMRecord( NV_DD_DATA_CAL_CONCENTRATE_PUMPS_RECORD, (U08*)&record, idx ); + result = enqueueEraseAndWriteSector( NVM_CALIBRATION_RECORD ); + sendNVEvent( NVM_CALIBRATION_RECORD, 0, 0 ); + response.idx = idx; + response.accepted = TRUE; } else { - response.accepted = FALSE; - response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_CRC; + response.rejectionReason = REQUEST_REJECT_REASON_INDEX_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_NVM_SET_SERVICE_RECORD_RESPONSE, + sendMessage( MSG_ID_DD_UI_NVM_SET_CONC_PUMP_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, - sizeof( UI_RESPONSE_PAYLOAD_T ) ); + sizeof( DD_NVM_SET_LINEAR_CAL_REC_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 handleDDGetD12PumpCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; - U08 tempBuffer[ sizeof( DD_USAGE_INFO_RECORD_T ) ]; - UI_RESPONSE_PAYLOAD_T response; + BOOL result = FALSE; + DD_NVM_GET_D12_PUMP_CAL_REC_PAYLOAD_T response; - if (message->hdr.payloadLen == ( sizeof( DD_USAGE_INFO_RECORD_T ) )) + if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - memcpy( tempBuffer, message->payload, sizeof( DD_USAGE_INFO_RECORD_T ) ); + isPublishRecordRequested[ NV_DD_DATA_CAL_D12_PUMP_RECORD] = TRUE; + result = TRUE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; - // 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) ); + 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 ) ); + } - if ( calcCRC == *recordCRC ) + return result; +} + +BOOL handleDDSetD12PumpCalRecRequest( MESSAGE_T *message ) +{ + BOOL result = FALSE; + U08* payloadPtr = message->payload; + U08 recordSize = sizeof( DD_D12_DIALYSATE_PUMP_RECORD_T ) - sizeof( U16 ); // Data - CRC + DD_NVM_SET_D12_PUMP_CAL_REC_PAYLOAD_T response = { 0 }; + DD_D12_DIALYSATE_PUMP_RECORD_T record; + + // Calibration record can be updated only in service mode + if ( DD_MODE_SERV == getCurrentOperationMode() ) + { + if ( message->hdr.payloadLen == recordSize ) { - 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 ); + memcpy( &record, payloadPtr, recordSize ); + record.crc = crc16( (U08*)&record, recordSize ); + setNVMMRecord( NV_DD_DATA_CAL_D12_PUMP_RECORD, (U08*)&record, 0 ); + result = enqueueEraseAndWriteSector( NVM_CALIBRATION_RECORD ); + sendNVEvent( NVM_CALIBRATION_RECORD, 0, 0 ); + response.accepted = TRUE; - response.accepted = TRUE; - response.rejectionReason = REQUEST_REJECT_REASON_NONE; } else { - response.accepted = FALSE; - response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_CRC; + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } } else { - response.accepted = FALSE; - response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; } - sendMessage( MSG_ID_DD_NVM_SET_USAGE_INFO_RECORD_RESPONSE, + sendMessage( MSG_ID_DD_UI_NVM_SET_D12_PUMP_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, - sizeof( UI_RESPONSE_PAYLOAD_T ) ); + sizeof( DD_NVM_SET_D12_PUMP_CAL_REC_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 handleDDGetD48PumpCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; - U08 idx = 0; - U08* payloadPtr = message->payload; - U08 expectedPayloadLen = sizeof( U08 ); - UI_RESPONSE_PAYLOAD_T response; + BOOL result = FALSE; + DD_NVM_GET_D48_PUMP_CAL_REC_PAYLOAD_T response; - if ( message->hdr.payloadLen >= expectedPayloadLen ) + if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - nvmExecreceiveRecordState = NVM_RECEIVE_RECORD_STATE_RECEIVE; + isPublishRecordRequested[ NV_DD_DATA_CAL_D48_PUMP_RECORD] = TRUE; + result = TRUE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; - memcpy( &idx, payloadPtr, sizeof( U08 ) ); - payloadPtr += sizeof( U08 ); + 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 ) ); + } - result = setNVMInstitRecord( (DD_INSTIT_REC_TYPE)idx, payloadPtr ); + return result; +} - response.accepted = TRUE; - response.rejectionReason = REQUEST_REJECT_REASON_NONE; +BOOL handleDDSetD48PumpCalRecRequest( MESSAGE_T *message ) +{ + BOOL result = FALSE; + U08* payloadPtr = message->payload; + U08 recordSize = sizeof( DD_D48_DIALYSATE_PUMP_RECORD_T ) - sizeof( U16 ); // Data - CRC + DD_NVM_SET_D48_PUMP_CAL_REC_PAYLOAD_T response = { 0 }; + DD_D48_DIALYSATE_PUMP_RECORD_T record; - // 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; + // Calibration record can be updated only in service mode + if ( DD_MODE_SERV == getCurrentOperationMode() ) + { + if ( message->hdr.payloadLen == recordSize ) + { + memcpy( &record, payloadPtr, recordSize ); + record.d48DialysatePump.crc = crc16( (U08*)&record, recordSize ); + setNVMMRecord( NV_DD_DATA_CAL_D48_PUMP_RECORD, (U08*)&record, 0 ); + result = enqueueEraseAndWriteSector( NVM_CALIBRATION_RECORD ); + sendNVEvent( NVM_CALIBRATION_RECORD, 0, 0 ); + response.accepted = TRUE; + + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } } else { - response.accepted = FALSE; - response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; } - response.fwValue = idx; - sendMessage( MSG_ID_DD_NVM_SET_INSTITUTIONAL_RECORD_RESPONSE, + sendMessage( MSG_ID_DD_UI_NVM_SET_D48_PUMP_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, - sizeof( UI_RESPONSE_PAYLOAD_T ) ); + sizeof( DD_NVM_SET_D48_PUMP_CAL_REC_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 handleDDGetAcidConcCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = FALSE; + U08* payloadPtr = message->payload; + U08 expectedPayloadLen = sizeof( U32 ); + DD_NVM_GET_ACID_CONC_CAL_REC_PAYLOAD_T response; + U32 idx; - result = receiveCalRecord( message, TRUE, DD_CAL_RECORD_PRESSURE_SENSOR, - sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); + if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) + { + if ( message->hdr.payloadLen == expectedPayloadLen ) + { + memcpy( &idx, payloadPtr, sizeof(U32)); + if( idx < NUM_OF_ACID_TYPE ) + { + isPublishRecordRequested[ NV_DD_DATA_CAL_ACID_CONCENTREATES] = TRUE; + isGetAcidConcCalRequested[ idx ] = TRUE; + result = TRUE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INDEX_OUT_OF_RANGE; + } + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + } + else + { + 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; } -/*********************************************************************//** - * @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 handleDDSetAcidConcCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = FALSE; + U08* payloadPtr = message->payload; + U08 recordSize = sizeof( DD_ACID_CONCENTRATE_T ) - sizeof( U16 ); // Data - CRC + U08 expectedPayloadLen = sizeof( U32 ) + recordSize; // Index + Data - CRC + DD_NVM_SET_ACID_CONC_CAL_REC_PAYLOAD_T response = { 0 }; + U32 idx; + DD_ACID_CONCENTRATE_T record; - result = receiveCalRecord( message, TRUE, DD_CAL_RECORD_TEMPERATURE_SENSOR, - sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); + // Calibration 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_ACID_TYPE ) + { + memcpy( &record, payloadPtr, recordSize ); + record.crc = crc16( (U08*)&record, recordSize ); + setNVMMRecord( NV_DD_DATA_CAL_ACID_CONCENTREATES, (U08*)&record, idx ); + result = enqueueEraseAndWriteSector( NVM_CALIBRATION_RECORD ); + sendNVEvent( NVM_CALIBRATION_RECORD, 0, 0 ); + response.idx = idx; + response.accepted = TRUE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INDEX_OUT_OF_RANGE; + } + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; + } + + sendMessage( MSG_ID_DD_UI_NVM_SET_ACID_CONC_CAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, + sizeof( DD_NVM_SET_ACID_CONC_CAL_REC_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 handleDDGetBicarbConcCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = FALSE; + U08* payloadPtr = message->payload; + U08 expectedPayloadLen = sizeof( U32 ); + DD_NVM_GET_BICARB_CONC_CAL_REC_PAYLOAD_T response; + U32 idx; - result = receiveCalRecord( message, TRUE, DD_CAL_RECORD_CONCENTRATE_PUMP, - sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); + if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) + { + if ( message->hdr.payloadLen == expectedPayloadLen ) + { + memcpy( &idx, payloadPtr, sizeof(U32)); + if( idx < NUM_OF_BICARB_TYPE ) + { + isPublishRecordRequested[ NV_DD_DATA_CAL_BICARB_CONCENTRATES] = TRUE; + isGetBicarbConcCalRequested[ idx ] = TRUE; + result = TRUE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INDEX_OUT_OF_RANGE; + } + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + } + else + { + 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; } -/*********************************************************************//** - * @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 handleDDSetBicarbConcCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = FALSE; + U08* payloadPtr = message->payload; + U08 recordSize = sizeof( DD_BICARB_CONCENTRATE_T ) - sizeof( U16 ); // Data - CRC + U08 expectedPayloadLen = sizeof( U32 ) + recordSize; // Index + Data - CRC + DD_NVM_SET_BICARB_CONC_CAL_REC_PAYLOAD_T response = { 0 }; + U32 idx; + DD_BICARB_CONCENTRATE_T record; - result = receiveCalRecord( message, FALSE, DD_CAL_RECORD_D12_PUMP, - sizeof( DD_D12_DIALYSATE_PUMP_RECORD_T ) ); + // Calibration 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_BICARB_TYPE ) + { + memcpy( &record, payloadPtr, recordSize ); + record.crc = crc16( (U08*)&record, recordSize ); + setNVMMRecord( NV_DD_DATA_CAL_BICARB_CONCENTRATES, (U08*)&record, idx ); + result = enqueueEraseAndWriteSector( NVM_CALIBRATION_RECORD ); + sendNVEvent( NVM_CALIBRATION_RECORD, 0, 0 ); + response.idx = idx; + response.accepted = TRUE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INDEX_OUT_OF_RANGE; + } + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; + } + + sendMessage( MSG_ID_DD_UI_NVM_SET_BICARB_CONC_CAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, + sizeof( DD_NVM_SET_BICARB_CONC_CAL_REC_PAYLOAD_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 handleDDGetAccelSensorCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; + DD_NVM_GET_ACCEL_SENSOR_CAL_REC_PAYLOAD_T response; - result = receiveCalRecord( message, FALSE, DD_CAL_RECORD_D48_PUMP, - sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); + if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) + { + isPublishRecordRequested[ NV_DD_DATA_CAL_ACCELEROMETER_SENSOR] = TRUE; + result = TRUE; + } + else + { + 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; } -/*********************************************************************//** - * @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 handleDDSetAccelSensorCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = FALSE; + U08* payloadPtr = message->payload; + U08 recordSize = sizeof( DD_ACCEL_SENSOR_CAL_RECORD_T ) - sizeof( U16 ); // Data - CRC + DD_NVM_SET_ACCEL_SENSOR_CAL_REC_PAYLOAD_T response = { 0 }; + DD_ACCEL_SENSOR_CAL_RECORD_T record; - result = receiveCalRecord( message, TRUE, DD_CAL_RECORD_ACID_CONCENTRATE, - sizeof( DD_ACID_CONCENTRATE_T ) ); + // Calibration record can be updated only in service mode + if ( DD_MODE_SERV == getCurrentOperationMode() ) + { + if ( message->hdr.payloadLen == recordSize ) + { + memcpy( &record, payloadPtr, recordSize ); + record.crc = crc16( (U08*)&record, recordSize ); + setNVMMRecord( NV_DD_DATA_CAL_ACCELEROMETER_SENSOR, (U08*)&record, 0 ); + result = enqueueEraseAndWriteSector( NVM_CALIBRATION_RECORD ); + sendNVEvent( NVM_CALIBRATION_RECORD, 0, 0 ); + response.accepted = TRUE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; + } + + sendMessage( MSG_ID_DD_UI_NVM_SET_ACCEL_SENSOR_CAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, + sizeof( DD_NVM_SET_ACCEL_SENSOR_CAL_REC_PAYLOAD_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 handleDDGetBloodLeakSensorCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; + DD_NVM_GET_BLOOD_LEAK_SENSOR_CAL_REC_PAYLOAD_T response; - result = receiveCalRecord( message, TRUE, DD_CAL_RECORD_BICARB_CONCENTRATE, - sizeof( DD_BICARB_CONCENTRATE_T ) ); + if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) + { + isPublishRecordRequested[ NV_DD_DATA_CAL_BLOOD_LEAK_SENSOR] = TRUE; + result = TRUE; + } + else + { + 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; } -/*********************************************************************//** - * @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 handleDDSetBloodLeakSensorCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = FALSE; + U08* payloadPtr = message->payload; + U08 recordSize = sizeof( DD_BLOOD_LEAK_SENSOR_CAL_RECORD_T ) - sizeof( U16 ); // Data - CRC + DD_NVM_SET_BLOOD_LEAK_SENSOR_CAL_REC_PAYLOAD_T response = { 0 }; + DD_BLOOD_LEAK_SENSOR_CAL_RECORD_T record; - result = receiveCalRecord( message, FALSE, DD_CAL_RECORD_ACCELEROMETER_SENSOR, - sizeof( DD_ACCEL_SENSOR_CAL_RECORD_T ) ); + // Calibration record can be updated only in service mode + if ( DD_MODE_SERV == getCurrentOperationMode() ) + { + if ( message->hdr.payloadLen == recordSize ) + { + memcpy( &record, payloadPtr, recordSize ); + record.crc = crc16( (U08*)&record, recordSize ); + setNVMMRecord( NV_DD_DATA_CAL_BLOOD_LEAK_SENSOR, (U08*)&record, 0 ); + result = enqueueEraseAndWriteSector( NVM_CALIBRATION_RECORD ); + sendNVEvent( NVM_CALIBRATION_RECORD, 0, 0 ); + response.accepted = TRUE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; + } + + sendMessage( MSG_ID_DD_UI_NVM_SET_BLOOD_LEAK_SENSOR_CAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, + sizeof( DD_NVM_SET_BLOOD_LEAK_SENSOR_CAL_REC_PAYLOAD_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 handleDDGetConductivitySensorCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = FALSE; + U08* payloadPtr = message->payload; + U08 expectedPayloadLen = sizeof( U32 ); + DD_NVM_GET_CONDUCTIVITY_SENSOR_CAL_REC_PAYLOAD_T response; + U32 idx; - result = receiveCalRecord( message, FALSE, DD_CAL_RECORD_BLLOD_LEAK_SENSOR, - sizeof( DD_BLOOD_LEAK_SENSOR_CAL_RECORD_T ) ); + if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) + { + if ( message->hdr.payloadLen == expectedPayloadLen ) + { + memcpy( &idx, payloadPtr, sizeof(U32)); + if( idx < NUM_OF_CONDUCTIVITY_SENSORS ) + { + isPublishRecordRequested[ NV_DD_DATA_CAL_CONDUCTIVITY_SENSORS ] = TRUE; + isGetCondSensCalRequested[ idx ] = TRUE; + result = TRUE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INDEX_OUT_OF_RANGE; + } + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + } + else + { + 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; + U08* payloadPtr = message->payload; + U08 recordSize = sizeof( CONDUCTIVITY_COEFFICIENTS_T ) - sizeof( U16 ); // Data - CRC + U08 expectedPayloadLen = sizeof( U32 ) + recordSize; // Index + Data - CRC + DD_NVM_SET_CONDUCTIVITY_SENSOR_CAL_REC_PAYLOAD_T response = { 0 }; + U32 idx; + CONDUCTIVITY_COEFFICIENTS_T record; + + // Calibration 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_CONDUCTIVITY_SENSORS ) + { + memcpy( &record, payloadPtr, recordSize ); + + // TODO: Update calibrationTime to current timestamp published by UI. + record.calibrationTime = 0; + record.crc = crc16( (U08*)&record, recordSize ); + setNVMMRecord( NV_DD_DATA_CAL_CONDUCTIVITY_SENSORS, (U08*)&record, idx ); + result = enqueueEraseAndWriteSector( NVM_CALIBRATION_RECORD ); + sendNVEvent( NVM_CALIBRATION_RECORD, 0, 0 ); + response.idx = idx; + response.accepted = TRUE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INDEX_OUT_OF_RANGE; + } + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; + } + + sendMessage( MSG_ID_DD_UI_NVM_SET_CONDUCTIVITY_SENSOR_CAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, + sizeof( DD_NVM_SET_CONDUCTIVITY_SENSOR_CAL_REC_PAYLOAD_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 + * @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