Index: firmware/App/Services/NVMessagingDD.c =================================================================== diff -u -r6a30402a7d47d1c77c04845a1c880935f00c6551 -rb50ce33669efe6dfcf5f8a211c78a6c2c309adf3 --- firmware/App/Services/NVMessagingDD.c (.../NVMessagingDD.c) (revision 6a30402a7d47d1c77c04845a1c880935f00c6551) +++ firmware/App/Services/NVMessagingDD.c (.../NVMessagingDD.c) (revision b50ce33669efe6dfcf5f8a211c78a6c2c309adf3) @@ -359,17 +359,17 @@ static RECEIVE_RECORD_STATE_T nvmExecreceiveRecordState; ///< NVM exec receive record state. static U32 newRecordStartTimer; ///< New record availability start timer. static BOOL isNewCalRecordAvailable; ///< Signal to indicate whether a new NVM data is available. -static NVM_RECORD_ITEMS_T recordToPublish; ///< Record type which is being processed currently for sending -static NVM_RECORD_ITEMS_T nvPublishRecordType; ///< Used to index over isPublishRecordRequested in the idle state +static 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 NVM_RECORD_TYPE_T currentRxRecordType; ///< Record type which is being processed currently for receiving static U32 recordSendDataIntervalCounter; ///< Record data send to CAN bust interval counter. static U32 sendRetryCount; ///< Counter for number of retries to send a record static U32 calRecordReceiveStartTime; ///< Time stamp the calibration record was received. static U32 institRecordReceiveStartTime; ///< Time stamp the institutional record was received. static DD_INSTIT_REC_TYPE sendInstitRec; ///< Current Institutional Record to be sent static DD_CAL_REC_TYPE sendCalRec; ///< Current Calibration Record to be sent -static U08 sendSensorIdx; ///< Current Index of sensor calibration data to be sent -static BOOL isPublishRecordRequested[ NUM_OF_NVM_REC_ITEMS ]; ///< Record state machine publish request flag. +static U08 sendCalIdx; ///< Current Index of sensor calibration data to be sent +static BOOL isPublishRecordRequested[ NV_DATA_T ]; ///< Record state machine publish request flag. // ********** private function prototypes ********** @@ -393,12 +393,10 @@ static SEND_RECORD_STATE_T handleSendAccelSensorCalRecord( void ); static SEND_RECORD_STATE_T handleSendBloodLeakSensorCalRecord( void ); static SEND_RECORD_STATE_T handleSendConductivitySensorCalRecord( void ); + static void updateSendRetryCount( BOOL sendStatus ); static SEND_RECORD_STATE_T updateCalSendRetryCountAndIndex( BOOL sendStatus, U08 maxIdx) -static BOOL receiveCalRecord( MESSAGE_T *message, BOOL isIndexed, - DD_CAL_REC_TYPE calRecordType, U16 recordSize ); -static MSG_ID_T getNVMCalRecordResponseMsgId(DD_CAL_REC_TYPE calRecordType ); static void monitorNewCalSignal( void ); @@ -422,13 +420,11 @@ nvmExecreceiveRecordState = NVM_RECEIVE_RECORD_STATE_IDLE; newRecordStartTimer = 0; isNewCalRecordAvailable = FALSE; - nvPublishRecordType = NVM_SYSTEM_RECORD; + 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_NVM_REC_ITEMS; i++ ) + for ( i = 0; i < NUM_OF_NV_DD_DATA; i++ ) { isPublishRecordRequested[ i ] = FALSE; } @@ -683,11 +679,11 @@ DD_NVM_GET_SYSTEM_REC_PAYLOAD_T payload; // Get the record - if ( TRUE == getNVMRecord( GET_SYSTEM_RECORD, - (U08*)&payload.data, - sizeof( DD_SYSTEM_RECORD_T ) , - 0, - ALARM_ID_DD_NVM_INVALID_SYSTEM_RECORD_CRC ) ) + 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; @@ -720,11 +716,11 @@ DD_NVM_GET_SERVICE_REC_PAYLOAD_T payload; // Get the record - if ( TRUE == getNVMRecord( GET_SERVICE_RECORD, - (U08*)&payload.data, - sizeof( DD_SERVICE_RECORD_T ) , - 0, - ALARM_ID_DD_NVM_INVALID_SERVICE_RECORD_CRC ) ) + 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; @@ -758,13 +754,12 @@ DD_NVM_GET_USAGE_INFO_REC_PAYLOAD_T payload; // Get the record - if ( TRUE == getNVMRecord( GET_USAGE_RECORD, - (U08*)&payload.data, - sizeof( DD_USAGE_INFO_RECORD_T ), - 0, - ALARM_ID_DD_NVM_INVALID_USAGE_RECORD_CRC ) ) + if ( TRUE == getNVMRecord( NV_DD_DATA_USAGE_RECORD, + (U08*)&payload.data, + sizeof( DD_USAGE_INFO_RECORD_T ), + 0, + ALARM_ID_DD_NVM_INVALID_USAGE_RECORD_CRC ) ) { - payload.accepted = TRUE; payload.rejectionReason = 0; @@ -797,15 +792,21 @@ DD_NVM_GET_INSTIT_BASIC_REC_PAYLOAD_T payload; // Get the record - payload.accepted = TRUE; - payload.rejectionReason = 0; - payload.data = getNVMInstitBasicRecord(); + if ( TRUE == getNVMRecord( NV_DD_DATA_INSTIT_BASIC_RECORD, + (U08*)&payload.data, + sizeof( DD_INSTIT_BASIC_RECORD_T ), + 0, + ALARM_ID_DD_NVM_INVALID_INSTITUTIONAL_RECORD_CRC ) ) + { + payload.accepted = TRUE; + payload.rejectionReason = 0; - // Send the record - sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_INSTIT_BASIC_RECORD_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&payload, - sizeof( DD_NVM_GET_INSTIT_BASIC_REC_PAYLOAD_T ) ); + // Send the record + sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_INSTIT_BASIC_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, + (U08*)&payload, + sizeof( DD_NVM_GET_INSTIT_BASIC_REC_PAYLOAD_T ) ); + } state = updateSendRetryCount( sendStatus ); @@ -829,15 +830,21 @@ DD_NVM_GET_INSTIT_ADVANCED_REC_PAYLOAD_T payload; // Get the record - payload.accepted = TRUE; - payload.rejectionReason = 0; - payload.data = getNVMInstitAdvancedRecord(); + if ( TRUE == getNVMRecord( NV_DD_DATA_INSTIT_ADVANCED_RECORD, + (U08*)&payload.data, + sizeof( DD_INSTIT_ADVANCED_RECORD_T ), + 0, + ALARM_ID_DD_NVM_INVALID_INSTITUTIONAL_RECORD_CRC ) ) + { + payload.accepted = TRUE; + payload.rejectionReason = 0; - // Send the record - sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_INSTIT_ADVANCED_RECORD_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&payload, - sizeof( DD_NVM_GET_INSTIT_ADVANCED_REC_PAYLOAD_T ) ); + // Send the record + sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_INSTIT_ADVANCED_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, + (U08*)&payload, + sizeof( DD_NVM_GET_INSTIT_ADVANCED_REC_PAYLOAD_T ) ); + } state = updateSendRetryCount( sendStatus ); @@ -861,15 +868,21 @@ DD_NVM_GET_INSTIT_ADDITIONAL_REC_PAYLOAD_T payload; // Get the record - payload.accepted = TRUE; - payload.rejectionReason = 0; - payload.data = getNVMInstitAdditionalRecord(); + if ( TRUE == getNVMRecord( NV_DD_DATA_INSTIT_ADDITIONAL_RECORD, + (U08*)&payload.data, + sizeof( DD_INSTIT_ADDITIONAL_RECORD_T ), + 0, + ALARM_ID_DD_NVM_INVALID_INSTITUTIONAL_RECORD_CRC ) ) + { + payload.accepted = TRUE; + payload.rejectionReason = 0; - // Send the record - sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_INSTIT_ADDITIONAL_RECORD_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&payload, - sizeof( DD_NVM_GET_INSTIT_ADDITIONAL_REC_PAYLOAD_T ) ); + // Send the record + sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_INSTIT_ADDITIONAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, + (U08*)&payload, + sizeof( DD_NVM_GET_INSTIT_ADDITIONAL_REC_PAYLOAD_T ) ); + } state = updateSendRetryCount( sendStatus ); @@ -880,7 +893,7 @@ * @brief * The handleSendPressureSensorCalRecord function sends the calibration * record of the selected pressure sensor. - * @details \b Inputs: sendSensorIdx + * @details \b Inputs: sendCalIdx * @details \b Outputs: None * @return state next state of the state machine *************************************************************************/ @@ -889,17 +902,26 @@ SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T payload; + DD_PRES_SENSORS_CAL_RECORD_T record; - payload.accepted = TRUE; - payload.rejectionReason = 0; - payload.idx = sendSensorIdx; - payload.data = getPressureSensorCalRecord( sendSensorIdx ); + // 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 - sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_PRESSURE_SENSOR_CAL_RECORD_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&payload, - sizeof( DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T ) ); + // Send the record + sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_PRESSURE_SENSOR_CAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, + (U08*)&payload, + sizeof( DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T ) ); + } state = updateCalSendRetryCountAndIndex( sendStatus, NUM_OF_PRESSURE_SENSORS ); @@ -910,7 +932,7 @@ * @brief * The handleSendTempSensorCalRecord function sends the calibration record * of the selected temperature sensor. - * @details \b Inputs: sendSensorIdx + * @details \b Inputs: sendCalIdx * @details \b Outputs: None * @return state next state of the state machine *************************************************************************/ @@ -919,17 +941,26 @@ 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; - payload.accepted = TRUE; - payload.rejectionReason = 0; - payload.idx = sendSensorIdx; - payload.data = getTemperatureSensorCalRecord( sendSensorIdx ); + // 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 ]; - // Send the record - sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_TEMPERATURE_SENSOR_CAL_RECORD_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&payload, - sizeof( DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T ) ); + // Send the record + sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_TEMPERATURE_SENSOR_CAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, + (U08*)&payload, + sizeof( DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T ) ); + } state = updateCalSendRetryCountAndIndex( sendStatus, NUM_OF_TEMPERATURE_SENSORS ); @@ -940,7 +971,7 @@ * @brief * The handleSendConcPumpCalRecord function sends the calibration record * of the selected concentrate pump. - * @details \b Inputs: sendSensorIdx + * @details \b Inputs: sendCalIdx * @details \b Outputs: None * @return state next state of the state machine *************************************************************************/ @@ -949,17 +980,26 @@ SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T payload; + DD_CONC_PUMPS_CAL_RECORD_T record; - payload.accepted = TRUE; - payload.rejectionReason = 0; - payload.idx = sendSensorIdx; - payload.data = getConcPumpCalRecord( sendSensorIdx ); + // 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 ) ) + { + payload.accepted = TRUE; + payload.rejectionReason = 0; + payload.idx = sendCalIdx; + payload.data = record.concentratePumps[ sendCalIdx ]; - // Send the record - sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_CONC_PUMP_CAL_RECORD_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&payload, - sizeof( DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T ) ); + // Send the record + sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_CONC_PUMP_CAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, + (U08*)&payload, + sizeof( DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T ) ); + } state = updateCalSendRetryCountAndIndex( sendStatus, NUM_OF_CONCENTRATE_PUMPS ); @@ -971,7 +1011,7 @@ * The handleSendD12PumpCalRecord function sends the calibration record of * the D12 dialysate pump. * @details \b Inputs: None - * @details \b Outputs: sendSensorIdx + * @details \b Outputs: sendCalIdx * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendD12PumpCalRecord( void ) @@ -980,16 +1020,23 @@ BOOL sendStatus = FALSE; DD_NVM_GET_D12_PUMP_CAL_REC_PAYLOAD_T payload; - payload.accepted = TRUE; - payload.rejectionReason = 0; - sendSensorIdx = 0; - payload.data = getD12PumpCalRecord( ); + // 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_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 ) ); + // Send the record + sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_D12_PUMP_CAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, + (U08*)&payload, + sizeof( DD_NVM_GET_D12_PUMP_CAL_REC_PAYLOAD_T ) ); + } state = updateCalSendRetryCountAndIndex( sendStatus, 0 ); @@ -1001,7 +1048,7 @@ * The handleSendD48PumpCalRecord function sends the calibration record of * the D48 dialysate pump. * @details \b Inputs: None - * @details \b Outputs: sendSensorIdx + * @details \b Outputs: sendCalIdx * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendD48PumpCalRecord( void ) @@ -1010,16 +1057,23 @@ BOOL sendStatus = FALSE; DD_NVM_GET_D48_PUMP_CAL_REC_PAYLOAD_T payload; - payload.accepted = TRUE; - payload.rejectionReason = 0; - sendSensorIdx = 0; - payload.data = getD48PumpCalRecord( ); + // 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_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 ) ); + // Send the record + sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_D48_PUMP_CAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, + (U08*)&payload, + sizeof( DD_NVM_GET_D48_PUMP_CAL_REC_PAYLOAD_T ) ); + } state = updateCalSendRetryCountAndIndex( sendStatus, 0 ); @@ -1030,7 +1084,7 @@ * @brief * The handleSendAcidConcCalRecord function sends the calibration record of * the selected acid concentrate. - * @details \b Inputs: sendSensorIdx + * @details \b Inputs: sendCalIdx * @details \b Outputs: None * @return state next state of the state machine *************************************************************************/ @@ -1039,17 +1093,26 @@ SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_ACID_CONC_CAL_REC_PAYLOAD_T payload; + DD_ACID_CONCENTRATES_RECORD_T record; - payload.accepted = TRUE; - payload.rejectionReason = 0; - payload.idx = sendSensorIdx; - payload.data = getAcidConcentrateCalRecord( sendSensorIdx ); + // 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_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 ) ); + // Send the record + sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_ACID_CONC_CAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, + (U08*)&payload, + sizeof( DD_NVM_GET_ACID_CONC_CAL_REC_PAYLOAD_T ) ); + } state = updateCalSendRetryCountAndIndex( sendStatus, NUM_OF_ACID_TYPE ); @@ -1060,7 +1123,7 @@ * @brief * The handleSendAcidConcCalRecord function sends the calibration record of * the selected acid concentrate. - * @details \b Inputs: sendSensorIdx + * @details \b Inputs: sendCalIdx * @details \b Outputs: None * @return state next state of the state machine *************************************************************************/ @@ -1069,17 +1132,26 @@ SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_BICARB_CONC_CAL_REC_PAYLOAD_T payload; + DD_BICARB_CONCENTRATES_RECORD_T record; - payload.accepted = TRUE; - payload.rejectionReason = 0; - payload.idx = sendSensorIdx; - payload.data = getBicarbConcentrateCalRecord( sendSensorIdx ); + // 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_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 ) ); + // Send the record + sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_BICARB_CONC_CAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, + (U08*)&payload, + sizeof( DD_NVM_GET_BICARB_CONC_CAL_REC_PAYLOAD_T ) ); + } state = updateCalSendRetryCountAndIndex( sendStatus, NUM_OF_BICARB_TYPE ); @@ -1091,7 +1163,7 @@ * The handleSendAccelSensorCalRecord function sends the calibration record * of the accelerometer sensor. * @details \b Inputs: None - * @details \b Outputs: sendSensorIdx + * @details \b Outputs: sendCalIdx * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendAccelSensorCalRecord( void ) @@ -1100,16 +1172,23 @@ BOOL sendStatus = FALSE; DD_NVM_GET_ACCEL_SENSOR_CAL_REC_PAYLOAD_T payload; - payload.accepted = TRUE; - payload.rejectionReason = 0; - sendSensorIdx = 0; - payload.data = getAccelSensorCalRecord(); + // Get the record + if ( TRUE == getNVMRecord( NV_DD_DATA_CAL_ACCEL_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_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 ) ); + // Send the record + sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_ACCEL_SENSOR_CAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, + (U08*)&payload, + sizeof( DD_NVM_GET_ACCEL_SENSOR_CAL_REC_PAYLOAD_T ) ); + } state = updateCalSendRetryCountAndIndex( sendStatus, 0 ); @@ -1121,7 +1200,7 @@ * The handleSendBloodLeakSensorCalRecord function sends the calibration * record of the blood leak sensor. * @details \b Inputs: None - * @details \b Outputs: sendSensorIdx + * @details \b Outputs: sendCalIdx * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendBloodLeakSensorCalRecord( void ) @@ -1130,16 +1209,23 @@ BOOL sendStatus = FALSE; DD_NVM_GET_BLOOD_LEAK_SENSOR_CAL_REC_PAYLOAD_T payload; - payload.accepted = TRUE; - payload.rejectionReason = 0; - sendSensorIdx = 0; - payload.data = getBloodLeakSensorCalRecord( ); + // 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_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 ) ); + // Send the record + sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_BLOOD_LEAK_SENSOR_CAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, + (U08*)&payload, + sizeof( DD_NVM_GET_BLOOD_LEAK_SENSOR_CAL_REC_PAYLOAD_T ) ); + } state = updateCalSendRetryCountAndIndex( sendStatus, 0 ); @@ -1150,7 +1236,7 @@ * @brief * The handleSendConductivitySensorCalRecord function sends the calibration * record of the conductivity sensor. - * @details \b Inputs: sendSensorIdx + * @details \b Inputs: sendCalIdx * @details \b Outputs: None * @return state next state of the state machine *************************************************************************/ @@ -1159,17 +1245,26 @@ SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; DD_NVM_GET_CONDUCTIVITY_SENSOR_CAL_REC_PAYLOAD_T payload; + DD_CONDUCTIVITY_SENSOR_CAL_RECORD_T record; - payload.accepted = TRUE; - payload.rejectionReason = 0; - payload.idx = sendSensorIdx; - payload.data = getConductivitySensorCalRecord( sendSensorIdx ); + // Get the record + if ( TRUE == getNVMRecord( NV_DD_DATA_CAL_CONDUCTIVITY_SENSOR, + (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_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 ) ); + // Send the record + sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_CONDUCTIVITY_SENSOR_CAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, + (U08*)&payload, + sizeof( DD_NVM_GET_CONDUCTIVITY_SENSOR_CAL_REC_PAYLOAD_T ) ); + } state = updateCalSendRetryCountAndIndex( sendStatus, NUM_OF_CONDUCTIVITY_SENSORS ); @@ -1178,155 +1273,6 @@ /*********************************************************************//** * @brief - * The receiveCalRecord function receives a calibration record, - * validates its CRC, updates the calibration data, and sends a - * response indicating whether the request was accepted. - * @details \b Inputs: None - * @details \b Outputs: nvmExecreceiveRecordState, - * calRecordReceiveStartTime, currentRxRecordType - * @param message Pointer to the received message - * @param isIndexed True, if the received record contains an index value. - * @param calRecordType Calibration record type being received - * @param recordSize Size of the calibration record in bytes - * @return TRUE if the calibration record was accepted and processed - * successfully otherwise FALSE - *************************************************************************/ -static BOOL receiveCalRecord( MESSAGE_T* message, BOOL isIndexed, - DD_CAL_REC_TYPE calRecordType, U16 recordSize ) -{ - BOOL status = FALSE; - U08* payloadPtr = message->payload; - U08 expectedPayloadLen = recordSize ; - MSG_ID_T msgID = getNVMCalRecordResponseMsgId( calRecordType ); - UI_RESPONSE_PAYLOAD_T response; - - if ( TRUE == isIndexed ) - { - expectedPayloadLen = ( sizeof(U08) + recordSize ); - } - - DD_NVM_RECORD_PAYLOAD_T recvdPayload; - - if ( DD_MODE_SERV == getCurrentOperationMode() ) - { - if ( message->hdr.payloadLen == expectedPayloadLen ) - { - // Get the index of the received calibration record if required - if ( TRUE == isIndexed ) - { - memcpy( &recvdPayload.idx, payloadPtr, sizeof(U08)); - payloadPtr += sizeof(U08); - } - - memcpy( &recvdPayload.data, payloadPtr, recordSize ); - - // CRC assumed at end of record - U16 *recordCRC = (U16*)( recvdPayload.data + ( recordSize - sizeof(U16) ) ); - U16 calcCRC = crc16( recvdPayload.data, recordSize - sizeof(U16) ); - - if ( calcCRC == *recordCRC ) - { - nvmExecreceiveRecordState = NVM_RECEIVE_RECORD_STATE_RECEIVE; - status = setNVMCalRecord( calRecordType, (U08*)&recvdPayload.data, recvdPayload.idx ); - - response.accepted = TRUE; - response.rejectionReason = REQUEST_REJECT_REASON_NONE; - - // It is possible that we receive multiple packets of cal record - // So we write it to flash when we finish receiving all packets or - // a timeout occurs. - calRecordReceiveStartTime = getMSTimerCount(); - currentRxRecordType = NVM_CALIBRATION_RECORD; - } - else - { - response.accepted = FALSE; - response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_CRC; - } - } - else - { - response.accepted = FALSE; - response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; - } - } - else - { - response.accepted = FALSE; - response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; - } - - response.fwValue = recvdPayload.idx; - sendMessage( msgID, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&response, - sizeof( UI_RESPONSE_PAYLOAD_T ) ); - - return status; -} - -/*********************************************************************//** - * @brief - * The getNVMCalRecordResponseMsgId function gets the response message - * ID corresponding to the specified calibration record type. - * @details \b Alarms: ALARM_ID_DD_SOFTWARE_FAULT if invalid calibration - * record type is provided - * @details \b Inputs: None - * @details \b Outputs: None - * @param calRecordType Calibration record type - * @return msgId corresponding response message ID - *************************************************************************/ -static MSG_ID_T getNVMCalRecordResponseMsgId( DD_CAL_REC_TYPE calRecordType ) -{ - MSG_ID_T msgId = MSG_ID_UNUSED; - - switch ( calRecordType ) - { - case DD_CAL_RECORD_PRESSURE_SENSOR: - msgId = MSG_ID_DD_NVM_SET_CAL_PRESSURE_SENSOR_RESPONSE; - break; - - case DD_CAL_RECORD_TEMPERATURE_SENSOR: - msgId = MSG_ID_DD_NVM_SET_CAL_TEMP_SENSOR_RESPONSE; - break; - - case DD_CAL_RECORD_CONCENTRATE_PUMP: - msgId = MSG_ID_DD_NVM_SET_CAL_CONC_PUMP_RESPONSE; - break; - - case DD_CAL_RECORD_D12_PUMP: - msgId = MSG_ID_DD_NVM_SET_CAL_D12_PUMP_RESPONSE; - break; - - case DD_CAL_RECORD_D48_PUMP: - msgId = MSG_ID_DD_NVM_SET_CAL_D48_PUMP_RESPONSE; - break; - - case DD_CAL_RECORD_ACID_CONCENTRATE: - msgId = MSG_ID_DD_NVM_SET_CAL_ACID_CONCENTRATE_RESPONSE; - break; - - case DD_CAL_RECORD_BICARB_CONCENTRATE: - msgId = MSG_ID_DD_NVM_SET_CAL_BICARB_CONCENTRATE_RESPONSE; - break; - - case DD_CAL_RECORD_ACCELEROMETER_SENSOR: - msgId = MSG_ID_DD_NVM_SET_CAL_ACCEL_SENSOR_RESPONSE; - break; - - case DD_CAL_RECORD_BLOOD_LEAK_SENSOR: - msgId = MSG_ID_DD_NVM_SET_CAL_BLOOD_LEAK_SENSOR_RESPONSE; - break; - - default: - // Software fault - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, ( U32 )calRecordType ); - break; - } - - return msgId; -} - -/*********************************************************************//** - * @brief * The monitorNewCalSignal function monitors the new calibration signal * and clears it when the timeout has elapsed. * @details \b Inputs: isNewCalRecordAvailable, @@ -1397,7 +1343,7 @@ * The updateCalSendRetryCountAndIndex function updates the retry counts, * sensor index, record to be published based on the send status of the calibration data. * @details \b Inputs: None - * @details \b Outputs: recordToPublish, sendRetryCount, sendSensorIdx + * @details \b Outputs: recordToPublish, sendRetryCount, sendCalIdx * @param sendStatus True if record was sent successfully, otherwise FALSE. * @@param maxIdx Maximum Index value of the current calibration item being sent * @return state next state of the state machine @@ -1410,11 +1356,11 @@ // Check if record was sent successfully if ( TRUE == sendStatus) { - sendSensorIdx++; + sendCalIdx++; sendRetryCount = 0; // Check if we sent the last record of calibration component - if ( sendSensorIdx >= maxIdx ) + if ( sendCalIdx >= maxIdx ) { resetState = TRUE; } @@ -1433,7 +1379,7 @@ if ( TRUE == resetState) { // Reset Sensor Index for the next request - sendSensorIdx = 0; + sendCalIdx = 0; // Reset the retry count sendRetryCount = 0; @@ -1448,61 +1394,18 @@ return state; } -/*********************************************************************//** - * @brief - * The handleDDGetNVRecord function processes a request to publish an NV - * record. It validates the payload and sets the publish request flag - * for the selected record. - * @details \b Inputs: nvMExecSendRecordState - * @details \b Outputs: isPublishRecordRequested, - * recordToPublish - * @param message Pointer to the received message - * @return TRUE if the request is accepted otherwise FALSE - *************************************************************************/ -BOOL handleDDGetNVRecord( MESSAGE_T *message ) -{ - BOOL result = FALSE; - NVM_RECORD_TYPE_T job; - UI_RESPONSE_PAYLOAD_T response; - - job = ( NVM_RECORD_TYPE_T )message->payload[ 0 ]; - - // Accept the request only if the send exec is in the idle state - if ( ( job < NUM_OF_NVM_RECORD_TYPES ) && - ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) ) - { - isPublishRecordRequested[ job ] = TRUE; - recordToPublish = job; - result = TRUE; - response.accepted = TRUE; - response.rejectionReason = REQUEST_REJECT_REASON_NONE; - } - else - { - response.accepted = FALSE; - response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; - } - - sendMessage( MSG_ID_DD_NVM_GET_RECORD_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, - sizeof( UI_RESPONSE_PAYLOAD_T ) ); - - return result; -} - BOOL handleDDGetSystemRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; DD_NVM_GET_SYSTEM_REC_PAYLOAD_T response; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - isPublishRecordRequested[ NVM_REC_TYPE_SYSTEM ] = TRUE; + isPublishRecordRequested[ NV_DD_DATA_SYSTEM_RECORD ] = TRUE; result = TRUE; } else { - response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_SYSTEM_RECORD_RESPONSE, @@ -1527,21 +1430,18 @@ if ( message->hdr.payloadLen == expectedPayloadLen ) { memcpy( record, message->payload, expectedPayloadLen ); - setSystemRecord( record ); - updateRecordCRC( NVM_SYSTEM_RECORD ); + 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.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } } else { - response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; } @@ -1559,12 +1459,11 @@ if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - isPublishRecordRequested[ NVM_REC_TYPE_SERVICE ] = TRUE; + isPublishRecordRequested[ NV_DD_DATA_SERVICE_RECORD ] = TRUE; result = TRUE; } else { - response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_SERVICE_RECORD_RESPONSE, @@ -1589,21 +1488,18 @@ if ( message->hdr.payloadLen == expectedPayloadLen ) { memcpy( record, message->payload, expectedPayloadLen ); - setServiceRecord( record ); - updateRecordCRC( NVM_SERVICE_RECORD ); + 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; } @@ -1621,12 +1517,11 @@ if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - isPublishRecordRequested[ NVM_REC_TYPE_USAGE_INFO ] = TRUE; + isPublishRecordRequested[ NV_DD_DATA_USAGE_INFO_RECORD ] = TRUE; result = TRUE; } else { - response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_USAGE_INFO_RECORD_RESPONSE, @@ -1648,15 +1543,13 @@ if ( message->hdr.payloadLen == expectedPayloadLen ) { memcpy( record, message->payload, expectedPayloadLen ); - setUsageInfoRecord( record ); - updateRecordCRC( NVM_USAGE_INFO_RECORD ); + 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.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } @@ -1674,12 +1567,11 @@ if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - isPublishRecordRequested[ NVM_REC_TYPE_INSTIT_BASIC ] = TRUE; + isPublishRecordRequested[ NV_DD_DATA_INSTIT_BASIC_RECORD ] = TRUE; result = TRUE; } else { - response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_INSTIT_BASIC_RECORD_RESPONSE, @@ -1702,15 +1594,13 @@ { memcpy( record, message->payload, expectedPayloadLen ); record.crc = crc16 ( (U08*)&record, sizeof( DD_INSTIT_BASIC_RECORD_T ) - sizeof( U16 ) ); - setInstitBasicRecord( record ); - updateRecordCRC( NVM_INSTITUTIONAL_RECORD ); + 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.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } @@ -1728,12 +1618,11 @@ if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - isPublishRecordRequested[ NVM_REC_TYPE_INSTIT_ADVANCED ] = TRUE; + isPublishRecordRequested[ NV_DD_DATA_INSTIT_ADVANCED_RECORD ] = TRUE; result = TRUE; } else { - response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_INSTIT_ADVANCED_RECORD_RESPONSE, @@ -1756,15 +1645,13 @@ { memcpy( record, message->payload, expectedPayloadLen ); record.crc = crc16 ( (U08*)&record, sizeof( DD_INSTIT_ADVANCED_RECORD_T ) - sizeof( U16 ) ); - setInstitAdvancedRecord( record ); - updateRecordCRC( NVM_INSTITUTIONAL_RECORD ); + 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.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } @@ -1782,12 +1669,11 @@ if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - isPublishRecordRequested[ NVM_REC_TYPE_INSTIT_ADDITIONAL ] = TRUE; + isPublishRecordRequested[ NV_DD_DATA_INSTIT_ADDITIONAL_RECORD ] = TRUE; result = TRUE; } else { - response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_INSTIT_ADDITIONAL_RECORD_RESPONSE, @@ -1810,15 +1696,13 @@ { memcpy( record, message->payload, expectedPayloadLen ); record.crc = crc16 ( (U08*)&record, sizeof( DD_INSTIT_ADDITIONAL_RECORD_T ) - sizeof( U16 ) ); - setInstitAdditionalRecord( record ); - updateRecordCRC( NVM_INSTITUTIONAL_RECORD ); + 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.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } @@ -1836,12 +1720,11 @@ if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - isPublishRecordRequested[ NVM_REC_TYPE_CAL_PRESSURE_SENSORS ] = TRUE; + isPublishRecordRequested[ NV_DD_DATA_CAL_PRESSURE_SENOSRS ] = TRUE; result = TRUE; } else { - response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_PRESSURE_SENSOR_CAL_RECORD_RESPONSE, @@ -1856,14 +1739,14 @@ BOOL handleDDSetPressureSensorCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; - DD_NVM_SET_LINEAR_CAL_REC_PAYLOAD_T response = { 0 }; - U08* payloadPtr = message->payload; - U08 recordSize = sizeof( LINEAR_CAL_PAYLOAD_T ) - sizeof( U16 ); // Data - CRC + U08* payloadPtr = message->payload; + U08 recordSize = sizeof( LINEAR_CAL_PAYLOAD_T ) - sizeof( U16 ); // Data - CRC U08 expectedPayloadLen = sizeof( U08 ) + recordSize; // Index + Data - CRC + DD_NVM_SET_LINEAR_CAL_REC_PAYLOAD_T response = { 0 }; U08 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 == expectedPayloadLen ) @@ -1875,27 +1758,23 @@ { memcpy( &record, payloadPtr, recordSize ); record.crc = crc16 ( (U08*)&record, recordSize ); - setPressureSensorCalRecord( idx, record ); - updateRecordCRC( NVM_CALIBRATION_RECORD ); + setNVMMRecord( NV_DD_DATA_CAL_PRESSURE_SENOSRS, (U08*)&record, idx ); result = enqueueEraseAndWriteSector( NVM_CALIBRATION_RECORD ); sendNVEvent( NVM_CALIBRATION_RECORD, 0, 0 ); response.accepted = TRUE; } else { - response.accepted = FALSE; response.idxRejectReason = REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE; } } else { - response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } } else { - response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; } @@ -1913,12 +1792,11 @@ if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - isPublishRecordRequested[ NVM_REC_TYPE_CAL_TEMPERATURE_SENSORS ] = TRUE; + isPublishRecordRequested[ NV_DD_DATA_CAL_TEMPERATURE_SENSORS ] = TRUE; result = TRUE; } else { - response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_TEMPERATURE_SENSOR_CAL_RECORD_RESPONSE, @@ -1932,7 +1810,50 @@ BOOL handleDDSetTemperatureSensorCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = FALSE; + U08* payloadPtr = message->payload; + U08 recordSize = sizeof( LINEAR_CAL_PAYLOAD_T ) - sizeof( U16 ); // Data - CRC + U08 expectedPayloadLen = sizeof( U08 ) + recordSize; // Index + Data - CRC + DD_NVM_SET_LINEAR_CAL_REC_PAYLOAD_T response = { 0 }; + U08 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_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.accepted = TRUE; + } + else + { + response.idxRejectReason = REQUEST_REJECT_REASON_PARAM_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_TEMPERATURE_SENSOR_CAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, + sizeof( DD_NVM_SET_LINEAR_CAL_REC_PAYLOAD_T ) ); + return result; } @@ -1943,12 +1864,11 @@ if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - isPublishRecordRequested[ NVM_REC_TYPE_CAL_CONC_PUMPS] = TRUE; + isPublishRecordRequested[ NV_DD_DATA_CAL_CONCENTRATE_PUMPS_RECORD] = TRUE; result = TRUE; } else { - response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_CONC_PUMP_CAL_RECORD_RESPONSE, @@ -1962,7 +1882,50 @@ BOOL handleDDSetConcPumpCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = FALSE; + U08* payloadPtr = message->payload; + U08 recordSize = sizeof( LINEAR_CAL_PAYLOAD_T ) - sizeof( U16 ); // Data - CRC + U08 expectedPayloadLen = sizeof( U08 ) + recordSize; // Index + Data - CRC + DD_NVM_SET_LINEAR_CAL_REC_PAYLOAD_T response = { 0 }; + U08 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.accepted = TRUE; + } + else + { + response.idxRejectReason = REQUEST_REJECT_REASON_PARAM_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_CONC_PUMP_CAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, + sizeof( DD_NVM_SET_LINEAR_CAL_REC_PAYLOAD_T ) ); + return result; } @@ -1973,12 +1936,11 @@ if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - isPublishRecordRequested[ NVM_REC_TYPE_CAL_D12_PUMP] = TRUE; + isPublishRecordRequested[ NV_DD_DATA_CAL_D12_PUMP_RECORD] = TRUE; result = TRUE; } else { - response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_D12_PUMP_CAL_RECORD_RESPONSE, @@ -1992,7 +1954,39 @@ BOOL handleDDSetD12PumpCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; + 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 ) + { + 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; + + } + 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_D12_PUMP_CAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, + sizeof( DD_NVM_SET_D12_PUMP_CAL_REC_PAYLOAD_T ) ); + return result; } @@ -2003,12 +1997,11 @@ if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - isPublishRecordRequested[ NVM_REC_TYPE_CAL_D48_PUMP] = TRUE; + isPublishRecordRequested[ NV_DD_DATA_CAL_D48_PUMP_RECORD] = TRUE; result = TRUE; } else { - response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_D48_PUMP_CAL_RECORD_RESPONSE, @@ -2022,7 +2015,39 @@ BOOL handleDDSetD48PumpCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; + 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; + + // 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_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.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; + } + + sendMessage( MSG_ID_DD_UI_NVM_SET_D48_PUMP_CAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, + sizeof( DD_NVM_SET_D48_PUMP_CAL_REC_PAYLOAD_T ) ); + return result; } @@ -2033,12 +2058,11 @@ if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - isPublishRecordRequested[ NVM_REC_TYPE_CAL_ACID_CONCENTREATES] = TRUE; + isPublishRecordRequested[ NV_DD_DATA_CAL_ACID_CONCENTREATES] = TRUE; result = TRUE; } else { - response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_ACID_CONC_CAL_RECORD_RESPONSE, @@ -2052,7 +2076,50 @@ 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( U08 ) + recordSize; // Index + Data - CRC + DD_NVM_SET_ACID_CONC_CAL_REC_PAYLOAD_T response = { 0 }; + U08 idx; + DD_ACID_CONCENTRATE_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_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.accepted = TRUE; + } + else + { + response.idxRejectReason = REQUEST_REJECT_REASON_PARAM_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; } @@ -2063,12 +2130,11 @@ if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - isPublishRecordRequested[ NVM_REC_TYPE_CAL_BICARB_CONCENTREATES] = TRUE; + isPublishRecordRequested[ NV_DD_DATA_CAL_BICARB_CONCENTRATES] = TRUE; result = TRUE; } else { - response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_BICARB_CONC_CAL_RECORD_RESPONSE, @@ -2082,7 +2148,50 @@ 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( U08 ) + recordSize; // Index + Data - CRC + DD_NVM_SET_BICARB_CONC_CAL_REC_PAYLOAD_T response = { 0 }; + U08 idx; + DD_BICARB_CONCENTRATE_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_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.accepted = TRUE; + } + else + { + response.idxRejectReason = REQUEST_REJECT_REASON_PARAM_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; } @@ -2093,12 +2202,11 @@ if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - isPublishRecordRequested[ NVM_REC_TYPE_CAL_ACCEL_SENSOR] = TRUE; + isPublishRecordRequested[ NV_DD_DATA_CAL_ACCEL_SENSOR] = TRUE; result = TRUE; } else { - response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; sendMessage( MSG_ID_DD_UI_NVM_GET_ACCEL_SENSOR_CAL_RECORD_RESPONSE, @@ -2112,485 +2220,165 @@ BOOL handleDDSetAccelSensorCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; - return result; -} + 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; -BOOL handleDDGetBloodLeakSensorCalRecRequest( MESSAGE_T *message ) -{ - BOOL result = FALSE; - DD_NVM_GET_BLOOD_LEAK_SENSOR_CAL_REC_PAYLOAD_T response; - - if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) + // Calibration record can be updated only in service mode + if ( DD_MODE_SERV == getCurrentOperationMode() ) { - isPublishRecordRequested[ NVM_REC_TYPE_CAL_BLOOD_LEAK_SENSOR] = TRUE; - result = TRUE; + if ( message->hdr.payloadLen == recordSize ) + { + memcpy( &record, payloadPtr, recordSize ); + record.crc = crc16 ( (U08*)&record, recordSize ); + setNVMMRecord( NV_DD_DATA_CAL_ACCEL_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.accepted = FALSE; - response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; - - sendMessage( MSG_ID_DD_UI_NVM_GET_BLOOD_LEAK_SENSOR_CAL_RECORD_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08 *)&response, - sizeof( DD_NVM_GET_BLOOD_LEAK_SENSOR_CAL_REC_PAYLOAD_T ) ); + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; } - return result; -} + 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 ) ); -BOOL handleDDSetBloodLeakSensorCalRecRequest( MESSAGE_T *message ) -{ - BOOL result = FALSE; return result; } -BOOL handleDDGetConductivitySensorCalRecRequest( MESSAGE_T *message ) +BOOL handleDDGetBloodLeakSensorCalRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; - DD_NVM_GET_CONDUCTIVITY_SENSOR_CAL_REC_PAYLOAD_T response; + DD_NVM_GET_BLOOD_LEAK_SENSOR_CAL_REC_PAYLOAD_T response; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - isPublishRecordRequested[ NVM_REC_TYPE_CAL_CONDUCTIVITY_SENSORS] = TRUE; + isPublishRecordRequested[ NV_DD_DATA_CAL_BLOOD_LEAK_SENSOR] = TRUE; result = TRUE; } else { - response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; - sendMessage( MSG_ID_DD_UI_NVM_GET_CONDUCTIVITY_SENSOR_CAL_RECORD_RESPONSE, + 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_CONDUCTIVITY_SENSOR_CAL_REC_PAYLOAD_T ) ); + sizeof( DD_NVM_GET_BLOOD_LEAK_SENSOR_CAL_REC_PAYLOAD_T ) ); } return result; } -BOOL handleDDSetConductivitySensorCalRecRequest( MESSAGE_T *message ) +BOOL handleDDSetBloodLeakSensorCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; - return result; -} + 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; -/*********************************************************************//** - * @brief - * The handleDDSetNVSystemRecord function processes a request to update - * the system record. It allows updates only when the system is in - * service mode. - * @details \b Inputs: None - * @details \b Outputs: None - * @param message Pointer to the received message - * @return TRUE if the record is successfully processed otherwise FALSE - *************************************************************************/ -BOOL handleDDSetNVSystemRecord( MESSAGE_T *message ) -{ - BOOL result = FALSE; - U08 tempBuffer[ sizeof( DD_SYSTEM_RECORD_T ) ]; - UI_RESPONSE_PAYLOAD_T response; - - // System record can be updated only in service mode + // 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 == recordSize ) { - memcpy( tempBuffer, message->payload, sizeof( DD_SYSTEM_RECORD_T ) ); + 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; - // CRC received at end of record - U16 *recordCRC = (U16 *)( tempBuffer + ( sizeof( DD_SYSTEM_RECORD_T ) - sizeof(U16) ) ); - U16 calcCRC = crc16( tempBuffer, sizeof( DD_SYSTEM_RECORD_T ) - sizeof(U16) ); - - if ( calcCRC == *recordCRC ) - { - currentRxRecordType = NVM_SYSTEM_RECORD; - PROCESS_RECORD_SPECS_T recordSpec = getProcessRecord( NVM_SYSTEM_RECORD ); - memcpy( recordSpec.structAddressPtr, tempBuffer, sizeof( DD_SYSTEM_RECORD_T ) ); - setNVMRecord( NVM_SYSTEM_RECORD, tempBuffer ); - result = enqueueEraseAndWriteSector( NVM_SYSTEM_RECORD ); - sendNVEvent( NVM_SYSTEM_RECORD, 0, 0 ); - - response.accepted = TRUE; - response.rejectionReason = REQUEST_REJECT_REASON_NONE; - } - else - { - response.accepted = FALSE; - response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_CRC; - } } else { - response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } } else { - response.accepted = FALSE; response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; } - sendMessage( MSG_ID_DD_NVM_SET_SYSTEM_RECORD_RESPONSE, + sendMessage( MSG_ID_DD_UI_NVM_SET_BLOOD_LEAK_SENSOR_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, - sizeof( UI_RESPONSE_PAYLOAD_T ) ); + sizeof( DD_NVM_SET_BLOOD_LEAK_SENSOR_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 handleDDGetConductivitySensorCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; - U08 tempBuffer[ sizeof( DD_SERVICE_RECORD_T ) ]; - UI_RESPONSE_PAYLOAD_T response; + BOOL result = FALSE; + DD_NVM_GET_CONDUCTIVITY_SENSOR_CAL_REC_PAYLOAD_T response; - // Service record can be updated only in service mode - if ( DD_MODE_SERV == getCurrentOperationMode() ) + if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - if (message->hdr.payloadLen == ( sizeof( DD_SERVICE_RECORD_T ) ) ) - { - memcpy( tempBuffer, message->payload, sizeof( DD_SERVICE_RECORD_T ) ); - - // CRC assumed at end of record - U16 *recordCRC = (U16 *)( tempBuffer + ( sizeof( DD_SERVICE_RECORD_T ) - sizeof(U16) ) ); - U16 calcCRC = crc16( tempBuffer, sizeof( DD_SERVICE_RECORD_T ) - sizeof(U16) ); - - if ( calcCRC == *recordCRC ) - { - currentRxRecordType = NVM_SERVICE_RECORD; - PROCESS_RECORD_SPECS_T recordSpec = getProcessRecord( NVM_SERVICE_RECORD ); - memcpy( recordSpec.structAddressPtr, tempBuffer, sizeof( DD_SERVICE_RECORD_T ) ); - setNVMRecord( NVM_SERVICE_RECORD, tempBuffer ); - result = enqueueEraseAndWriteSector( NVM_SERVICE_RECORD ); - sendNVEvent( NVM_SERVICE_RECORD, 0, 0 ); - - response.accepted = TRUE; - response.rejectionReason = REQUEST_REJECT_REASON_NONE; - } - else - { - response.accepted = FALSE; - response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_CRC; - } - } - else - { - response.accepted = FALSE; - response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; - } + isPublishRecordRequested[ NV_DD_DATA_CAL_CONDUCTIVITY_SENSOR] = TRUE; + result = TRUE; } else { - response.accepted = FALSE; - response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; + 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 ) ); } - sendMessage( MSG_ID_DD_NVM_SET_SERVICE_RECORD_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, - sizeof( UI_RESPONSE_PAYLOAD_T ) ); - return result; } -/*********************************************************************//** - * @brief - * The handleDDSetNVUsageInfoRecord function processes a request to - * update the usage information record. - * @details \b Inputs: None - * @details \b Outputs: None - * @param message Pointer to the received message - * @return TRUE if the record is successfully processed otherwise FALSE - *************************************************************************/ -BOOL handleDDSetNVUsageInfoRecord( MESSAGE_T *message ) +BOOL handleDDSetConductivitySensorCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; - U08 tempBuffer[ sizeof( DD_USAGE_INFO_RECORD_T ) ]; - UI_RESPONSE_PAYLOAD_T response; + BOOL result = FALSE; + U08* payloadPtr = message->payload; + U08 recordSize = sizeof( DD_CONDUCTIVITY_SENSOR_T ) - sizeof( U16 ); // Data - CRC + DD_NVM_SET_CONDUCTIVITY_SENSOR_CAL_REC_PAYLOAD_T response = { 0 }; + DD_CONDUCTIVITY_SENSOR_T record; - if (message->hdr.payloadLen == ( sizeof( DD_USAGE_INFO_RECORD_T ) )) + // Calibration record can be updated only in service mode + if ( DD_MODE_SERV == getCurrentOperationMode() ) { - memcpy( tempBuffer, message->payload, sizeof( DD_USAGE_INFO_RECORD_T ) ); - - // CRC assumed at end of record - U16 *recordCRC = (U16 *)( tempBuffer + ( sizeof( DD_USAGE_INFO_RECORD_T ) - sizeof(U16) ) ); - U16 calcCRC = crc16( tempBuffer, sizeof( DD_USAGE_INFO_RECORD_T ) - sizeof(U16) ); - - if ( calcCRC == *recordCRC ) + 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_CONDUCTIVITY_SENSOR, (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_CONDUCTIVITY_SENSOR_CAL_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, - sizeof( UI_RESPONSE_PAYLOAD_T ) ); + sizeof( DD_NVM_SET_CONDUCTIVITY_SENSOR_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 result = FALSE; - U08 idx = 0; - U08* payloadPtr = message->payload; - U08 expectedPayloadLen = sizeof( U08 ); - UI_RESPONSE_PAYLOAD_T response; - if ( message->hdr.payloadLen >= expectedPayloadLen ) - { - nvmExecreceiveRecordState = NVM_RECEIVE_RECORD_STATE_RECEIVE; - - memcpy( &idx, payloadPtr, sizeof( U08 ) ); - payloadPtr += sizeof( U08 ); - - result = setNVMInstitRecord( (DD_INSTIT_REC_TYPE)idx, payloadPtr ); - - response.accepted = TRUE; - response.rejectionReason = REQUEST_REJECT_REASON_NONE; - - // It is possible that we receive multiple packets of instit record - // So we write it to flash when we finish receiving all packets or - // a timeout occurs. - institRecordReceiveStartTime = getMSTimerCount(); - currentRxRecordType = NVM_INSTITUTIONAL_RECORD; - } - else - { - response.accepted = FALSE; - response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; - } - - response.fwValue = idx; - sendMessage( MSG_ID_DD_NVM_SET_INSTITUTIONAL_RECORD_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, - sizeof( UI_RESPONSE_PAYLOAD_T ) ); - - return result; -} - - - -/*********************************************************************//** - * @brief - * The handleDDSetPressureSensorCalRecord function processes a request - * to update a pressure sensor calibration record. - * @details \b Inputs: None - * @details \b Outputs: None - * @param message Pointer to the received message - * @return TRUE if the calibration record was accepted and processed - * successfully otherwise FALSE - *************************************************************************/ -BOOL handleDDSetPressureSensorCalRecord( MESSAGE_T *message ) -{ - BOOL result = FALSE; - - result = receiveCalRecord( message, TRUE, DD_CAL_RECORD_PRESSURE_SENSOR, - sizeof( LINEAR_CAL_PAYLOAD_T ) ); - - return result; -} - -/*********************************************************************//** - * @brief - * The handleDDSetTempSensorCalRecord function processes a request to - * update a temperature sensor calibration record. - * @details \b Inputs: None - * @details \b Outputs: None - * @param message Pointer to the received message - * @return TRUE if the calibration record was accepted and processed - * successfully otherwise FALSE - *************************************************************************/ -BOOL handleDDSetTempSensorCalRecord( MESSAGE_T *message ) -{ - BOOL result = FALSE; - - result = receiveCalRecord( message, TRUE, DD_CAL_RECORD_TEMPERATURE_SENSOR, - sizeof( LINEAR_CAL_PAYLOAD_T ) ); - - return result; -} - -/*********************************************************************//** - * @brief - * The handleDDSetConcPumpCalRecord function processes a request to - * update a concentrate pump calibration record. - * @details \b Inputs: None - * @details \b Outputs: None - * @param message Pointer to the received message - * @return TRUE if the calibration record was accepted and processed - * successfully otherwise FALSE - *************************************************************************/ -BOOL handleDDSetConcPumpCalRecord( MESSAGE_T *message ) -{ - BOOL result = FALSE; - - result = receiveCalRecord( message, TRUE, DD_CAL_RECORD_CONCENTRATE_PUMP, - sizeof( LINEAR_CAL_PAYLOAD_T ) ); - - return result; -} - -/*********************************************************************//** - * @brief - * The handleDDSetD12PumpCalRecord function processes a request to - * update the D12 dialysate pump calibration record. - * @details \b Inputs: None - * @details \b Outputs: None - * @param message Pointer to the received message - * @return TRUE if the calibration record was accepted and processed - * successfully otherwise FALSE - *************************************************************************/ -BOOL handleDDSetD12PumpCalRecord( MESSAGE_T *message ) -{ - BOOL result = FALSE; - - result = receiveCalRecord( message, FALSE, DD_CAL_RECORD_D12_PUMP, - sizeof( DD_D12_DIALYSATE_PUMP_RECORD_T ) ); - - return result; -} - -/*********************************************************************//** - * @brief - * The handleDDSetD48PumpCalRecord function processes a request to - * update the D48 dialysate pump calibration record. - * @details \b Inputs: None - * @details \b Outputs: None - * @param message Pointer to the received message - * @return TRUE if the calibration record was accepted and processed - * successfully otherwise FALSE - *************************************************************************/ -BOOL handleDDSetD48CalRecord( MESSAGE_T *message ) -{ - BOOL result = FALSE; - - result = receiveCalRecord( message, FALSE, DD_CAL_RECORD_D48_PUMP, - sizeof( LINEAR_CAL_PAYLOAD_T ) ); - - return result; -} - -/*********************************************************************//** - * @brief - * The handleDDSetAcidConcCalRecord function processes a request to - * update an acid concentrate calibration record. - * @details \b Inputs: None - * @details \b Outputs: None - * @param message Pointer to the received message - * @return TRUE if the calibration record was accepted and processed - * successfully otherwise FALSE - *************************************************************************/ -BOOL handleDDSetAcidConcCalRecord( MESSAGE_T *message ) -{ - BOOL result = FALSE; - - result = receiveCalRecord( message, TRUE, DD_CAL_RECORD_ACID_CONCENTRATE, - sizeof( DD_ACID_CONCENTRATE_T ) ); - - return result; -} - -/*********************************************************************//** - * @brief - * The handleDDSetBicarbConcCalRecord function processes a request to - * update a bicarb concentrate calibration record. - * @details \b Inputs: None - * @details \b Outputs: None - * @param message Pointer to the received message - * @return TRUE if the calibration record was accepted and processed - * successfully otherwise FALSE - *************************************************************************/ -BOOL handleDDSetBicarbConcCalRecord( MESSAGE_T *message ) -{ - BOOL result = FALSE; - - result = receiveCalRecord( message, TRUE, DD_CAL_RECORD_BICARB_CONCENTRATE, - sizeof( DD_BICARB_CONCENTRATE_T ) ); - - return result; -} - -/*********************************************************************//** - * @brief - * The handleDDSetAccelSensorCalRecord function processes a request to - * update the accelerometer sensor calibration record. - * @details \b Inputs: None - * @details \b Outputs: None - * @param message Pointer to the received message - * @return TRUE if the calibration record was accepted and processed - * successfully otherwise FALSE - *************************************************************************/ -BOOL handleDDSetAccelSensorCalRecord( MESSAGE_T *message ) -{ - BOOL result = FALSE; - - result = receiveCalRecord( message, FALSE, DD_CAL_RECORD_ACCELEROMETER_SENSOR, - sizeof( DD_ACCEL_SENSOR_CAL_RECORD_T ) ); - - return result; -} - -/*********************************************************************//** - * @brief - * The handleDDSetBloodLeakSensorCalRecord function processes a request - * to update the blood leak sensor calibration record. - * @details \b Inputs: None - * @details \b Outputs: None - * @param message Pointer to the received message - * @return TRUE if the calibration record was accepted and processed - * successfully otherwise FALSE - *************************************************************************/ -BOOL handleDDSetBloodLeakSensorCalRecord( MESSAGE_T *message ) -{ - BOOL result = FALSE; - - result = receiveCalRecord( message, FALSE, DD_CAL_RECORD_BLOOD_LEAK_SENSOR, - sizeof( DD_BLOOD_LEAK_SENSOR_CAL_RECORD_T ) ); - - return result; -} - - - /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/