Index: firmware/App/Services/NVMessagingDD.c =================================================================== diff -u -r7362b089e676aadfaa614cca148e2aed007bae95 -rf3af61ba8f46e4cdde1c5daf749a29ae31b9f514 --- firmware/App/Services/NVMessagingDD.c (.../NVMessagingDD.c) (revision 7362b089e676aadfaa614cca148e2aed007bae95) +++ firmware/App/Services/NVMessagingDD.c (.../NVMessagingDD.c) (revision f3af61ba8f46e4cdde1c5daf749a29ae31b9f514) @@ -12,6 +12,7 @@ ***************************************************************************/ #include // For ceilf function + #include "ConductivitySensors.h" #include "Messaging.h" #include "NVJobQ.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 @@ -180,7 +180,7 @@ { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Rejection reason if not accepted. - U08 idx; ///< Index of sensor / pump / concentrates + U32 idx; ///< Index of sensor / pump / concentrates LINEAR_CAL_PAYLOAD_T data; ///< Data to be sent } DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T; @@ -189,6 +189,7 @@ { 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; @@ -230,7 +231,7 @@ { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Rejection reason if not accepted. - U08 idx; ///< Index of acid concentrates + U32 idx; ///< Index of acid concentrates DD_ACID_CONCENTRATE_T data; ///< Data to be sent } DD_NVM_GET_ACID_CONC_CAL_REC_PAYLOAD_T; @@ -239,6 +240,7 @@ { 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 @@ -251,7 +253,7 @@ { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Rejection reason if not accepted. - U08 idx; ///< Index of bicarb concentrates + U32 idx; ///< Index of bicarb concentrates DD_BICARB_CONCENTRATE_T data; ///< Data to be sent } DD_NVM_GET_BICARB_CONC_CAL_REC_PAYLOAD_T; @@ -260,6 +262,7 @@ { 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 @@ -308,15 +311,16 @@ { BOOL accepted; ///< Accepted/Rejected U32 rejectionReason; ///< Rejection reason if not accepted. - U08 idx; ///< Index of conductivity sensor - CONDUCTIVITY_COEFFICIENTS_T data; ///< Data to be sent + 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 @@ -342,7 +346,6 @@ 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 U32 sendRetryCount; ///< Counter for number of retries to send a record 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. @@ -377,12 +380,8 @@ static SEND_RECORD_STATE_T handleSendBloodLeakSensorCalRecord( void ); static SEND_RECORD_STATE_T handleSendConductivitySensorCalRecord( void ); -static SEND_RECORD_STATE_T updateSendRetryCount( BOOL sendStatus ); -static SEND_RECORD_STATE_T updateCalSendRetryCountAndIndex( BOOL sendStatus, U08 maxIdx ); - static void monitorNewCalSignal( void ); - /*********************************************************************//** * @brief * The initNVMessagingDD function initializes NV messaging related @@ -649,13 +648,12 @@ * It retries transmission on failure and returns to the idle state * after a successful send or when retries are exhausted. * @details \b Inputs: None - * @details \b Outputs: None + * @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 sendStatus = FALSE; DD_NVM_GET_SYSTEM_REC_PAYLOAD_T payload; // Get the record @@ -669,14 +667,18 @@ payload.rejectionReason = 0; // Send the record - sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_SYSTEM_RECORD_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&payload, - ( sizeof( DD_NVM_GET_SYSTEM_REC_PAYLOAD_T ) - sizeof( U16 ) ) ); + 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 ) ) ); } - state = updateSendRetryCount( sendStatus ); + // Clear the publishing flags + recordToPublish = NUM_OF_NV_DD_DATA; + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; + return state; } @@ -686,13 +688,12 @@ * It retries transmission on failure and returns to the idle state * after a successful send or when retries are exhausted. * @details \b Inputs: None - * @details \b Outputs: None + * @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 sendStatus = FALSE; DD_NVM_GET_SERVICE_REC_PAYLOAD_T payload; // Get the record @@ -706,14 +707,18 @@ payload.rejectionReason = 0; // Send the record - sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_SERVICE_RECORD_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&payload, - ( sizeof( DD_NVM_GET_SERVICE_REC_PAYLOAD_T ) - sizeof( U16 ) ) ); + 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 ) ) ); } - state = updateSendRetryCount( sendStatus ); + // Clear the publishing flags + recordToPublish = NUM_OF_NV_DD_DATA; + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; + return state; } @@ -724,13 +729,12 @@ * to the idle state after a successful send or when retries are * exhausted. * @details \b Inputs: None - * @details \b Outputs: 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; - BOOL sendStatus = FALSE; DD_NVM_GET_USAGE_INFO_REC_PAYLOAD_T payload; // Get the record @@ -744,14 +748,18 @@ payload.rejectionReason = 0; // Send the record - sendStatus = sendMessage( MSG_ID_DD_UI_NVM_GET_USAGE_INFO_RECORD_RESPONSE, - COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08*)&payload, - ( sizeof( DD_NVM_GET_USAGE_INFO_REC_PAYLOAD_T ) - sizeof( U16 ) ) ); + 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 ) ) ); } - state = updateSendRetryCount( sendStatus ); + // Clear the publishing flags + recordToPublish = NUM_OF_NV_DD_DATA; + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; + return state; } @@ -762,13 +770,12 @@ * to the idle state after a successful send or when retries are * exhausted. * @details \b Inputs: None - * @details \b Outputs: None + * @details \b Outputs: recordToPublish * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendDDInstitBasicRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; - BOOL sendStatus = FALSE; DD_NVM_GET_INSTIT_BASIC_REC_PAYLOAD_T payload; // Get the record @@ -782,14 +789,18 @@ 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 ) - sizeof( U16 ) ) ); + 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 ) ) ); } - state = updateSendRetryCount( sendStatus ); + // Clear the publishing flags + recordToPublish = NUM_OF_NV_DD_DATA; + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; + return state; } @@ -800,13 +811,12 @@ * to the idle state after a successful send or when retries are * exhausted. * @details \b Inputs: None - * @details \b Outputs: 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; - BOOL sendStatus = FALSE; DD_NVM_GET_INSTIT_ADVANCED_REC_PAYLOAD_T payload; // Get the record @@ -820,14 +830,18 @@ 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 ) - sizeof( U16 ) ) ); + 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 ) ) ); } - state = updateSendRetryCount( sendStatus ); + // Clear the publishing flags + recordToPublish = NUM_OF_NV_DD_DATA; + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; + return state; } @@ -838,13 +852,12 @@ * to the idle state after a successful send or when retries are * exhausted. * @details \b Inputs: None - * @details \b Outputs: None + * @details \b Outputs: recordToPublish * @return state next state of the state machine *************************************************************************/ static SEND_RECORD_STATE_T handleSendDDInstitAdditionalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; - BOOL sendStatus = FALSE; DD_NVM_GET_INSTIT_ADDITIONAL_REC_PAYLOAD_T payload; // Get the record @@ -858,14 +871,18 @@ 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 ) - sizeof( U16 ) ) ); + 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 ) ) ); } - state = updateSendRetryCount( sendStatus ); + // Clear the publishing flags + recordToPublish = NUM_OF_NV_DD_DATA; + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; + return state; } @@ -880,31 +897,46 @@ static SEND_RECORD_STATE_T handleSendPressureSensorCalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; - BOOL sendStatus = FALSE; DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T payload; DD_PRES_SENSORS_CAL_RECORD_T record; - // 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 ) ) + // Check if record of current sensor index was requested + if ( TRUE == isGetPressureCalRequested[ sendCalIdx ] ) { - payload.accepted = TRUE; - payload.rejectionReason = 0; - payload.idx = sendCalIdx; - payload.data = record.pressureSensors[ sendCalIdx ]; + // 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 ) - sizeof( U16 ) ) ); + // 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 ) ) ); + } } - state = updateCalSendRetryCountAndIndex( sendStatus, NUM_OF_PRESSURE_SENSORS ); + sendCalIdx = sendCalIdx + 1; + if ( sendCalIdx >= NUM_OF_PRESSURE_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; } @@ -919,31 +951,46 @@ 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; - // 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 ) ) + // Check if record of current sensor index was requested + if ( TRUE == isGetTempCalRequested[ sendCalIdx ] ) { - payload.accepted = TRUE; - payload.rejectionReason = 0; - payload.idx = sendCalIdx; - payload.data = record.tempSensors[ sendCalIdx ]; + // 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 ) - sizeof( U16 ) ) ); + // 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 ) ) ); + } } - state = updateCalSendRetryCountAndIndex( sendStatus, NUM_OF_TEMPERATURE_SENSORS ); + sendCalIdx = sendCalIdx + 1; + if ( sendCalIdx >= NUM_OF_TEMPERATURE_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; } @@ -958,31 +1005,46 @@ static SEND_RECORD_STATE_T handleSendConcPumpCalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; - BOOL sendStatus = FALSE; DD_NVM_GET_LINEAR_CAL_REC_PAYLOAD_T payload; DD_CONC_PUMPS_CAL_RECORD_T record; - // 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 ) ) + // Check if record of current sensor index was requested + if ( TRUE == isGetConcPumpCalRequested[ sendCalIdx ] ) { - payload.accepted = TRUE; - payload.rejectionReason = 0; - payload.idx = sendCalIdx; - payload.data = record.concentratePumps[ sendCalIdx ]; + // 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 ) - sizeof( U16 ) ) ); + // 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 ) ) ); + } } - state = updateCalSendRetryCountAndIndex( sendStatus, NUM_OF_CONCENTRATE_PUMPS ); + sendCalIdx = sendCalIdx + 1; + if ( sendCalIdx >= NUM_OF_CONCENTRATE_PUMPS ) + { + // 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; } @@ -997,7 +1059,6 @@ static SEND_RECORD_STATE_T handleSendD12PumpCalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; - BOOL sendStatus = FALSE; DD_NVM_GET_D12_PUMP_CAL_REC_PAYLOAD_T payload; // Get the record @@ -1012,14 +1073,12 @@ 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 ) - sizeof( U16 ) ) ); + 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 ) ) ); } - state = updateCalSendRetryCountAndIndex( sendStatus, 0 ); - return state; } @@ -1034,7 +1093,6 @@ static SEND_RECORD_STATE_T handleSendD48PumpCalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; - BOOL sendStatus = FALSE; DD_NVM_GET_D48_PUMP_CAL_REC_PAYLOAD_T payload; // Get the record @@ -1049,14 +1107,12 @@ 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 ) - sizeof( U16 ) ) ); + 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 ) ) ); } - state = updateCalSendRetryCountAndIndex( sendStatus, 0 ); - return state; } @@ -1071,31 +1127,46 @@ static SEND_RECORD_STATE_T handleSendAcidConcCalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; - BOOL sendStatus = FALSE; DD_NVM_GET_ACID_CONC_CAL_REC_PAYLOAD_T payload; DD_ACID_CONCENTRATES_RECORD_T record; - // 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 ) ) + // Check if record of current sensor index was requested + if ( TRUE == isGetAcidConcCalRequested[ sendCalIdx ] ) { - payload.accepted = TRUE; - payload.rejectionReason = 0; - payload.idx = sendCalIdx; - payload.data = record.acidConcentrate[ 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_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 ) ) ); + // 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 ) ) ); + } } - state = updateCalSendRetryCountAndIndex( sendStatus, NUM_OF_ACID_TYPE ); + sendCalIdx = sendCalIdx + 1; + if ( sendCalIdx >= NUM_OF_ACID_TYPE ) + { + // 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; } @@ -1110,31 +1181,46 @@ static SEND_RECORD_STATE_T handleSendBicarbConcCalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; - BOOL sendStatus = FALSE; DD_NVM_GET_BICARB_CONC_CAL_REC_PAYLOAD_T payload; DD_BICARB_CONCENTRATES_RECORD_T record; - // 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 ) ) + // Check if record of current sensor index was requested + if ( TRUE == isGetBicarbConcCalRequested[ sendCalIdx ] ) { - payload.accepted = TRUE; - payload.rejectionReason = 0; - payload.idx = sendCalIdx; - payload.data = record.bicarbConcentrate[ 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_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 ) ) ); + // 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 ) ) ); + } } - state = updateCalSendRetryCountAndIndex( sendStatus, NUM_OF_BICARB_TYPE ); + sendCalIdx = sendCalIdx + 1; + if ( sendCalIdx >= NUM_OF_BICARB_TYPE ) + { + // 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; } @@ -1149,7 +1235,6 @@ static SEND_RECORD_STATE_T handleSendAccelSensorCalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; - BOOL sendStatus = FALSE; DD_NVM_GET_ACCEL_SENSOR_CAL_REC_PAYLOAD_T payload; // Get the record @@ -1164,14 +1249,18 @@ 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 ) - sizeof( U16 ) ) ); + 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 ) ) ); } - state = updateCalSendRetryCountAndIndex( sendStatus, 0 ); + // Clear the publishing flags + recordToPublish = NUM_OF_NV_DD_DATA; + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; + return state; } @@ -1186,7 +1275,6 @@ static SEND_RECORD_STATE_T handleSendBloodLeakSensorCalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; - BOOL sendStatus = FALSE; DD_NVM_GET_BLOOD_LEAK_SENSOR_CAL_REC_PAYLOAD_T payload; // Get the record @@ -1201,14 +1289,18 @@ 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 ) - sizeof( U16 ) ) ); + 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 ) ) ); } - state = updateCalSendRetryCountAndIndex( sendStatus, 0 ); + // Clear the publishing flags + recordToPublish = NUM_OF_NV_DD_DATA; + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; + return state; } @@ -1223,31 +1315,46 @@ static SEND_RECORD_STATE_T handleSendConductivitySensorCalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; - BOOL sendStatus = FALSE; DD_NVM_GET_CONDUCTIVITY_SENSOR_CAL_REC_PAYLOAD_T payload; DD_CONDUCTIVITY_SENSOR_CAL_RECORD_T record; - // 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 ) ) + // Check if record of current sensor index was requested + if ( TRUE == isGetCondSensCalRequested[ sendCalIdx ] ) { - payload.accepted = TRUE; - payload.rejectionReason = 0; - payload.idx = sendCalIdx; - payload.data = record.condSensors[ 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_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 ) ) ); + // 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 ) ) ); + } } - state = updateCalSendRetryCountAndIndex( sendStatus, NUM_OF_CONDUCTIVITY_SENSORS ); + 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; } @@ -1272,108 +1379,6 @@ } } -/*********************************************************************//** - * @brief - * The updateSendRetryCount function updates the retry counts and - * record to be published based on the send status. - * @details \b Inputs: None - * @details \b Outputs: recordToPublish, sendRetryCount - * @param sendStatus True if record was sent successfully, otherwise FALSE. - * @return state next state of the state machine - *************************************************************************/ -static SEND_RECORD_STATE_T updateSendRetryCount( BOOL sendStatus ) -{ - SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; - - // Check if record send successfully - if ( TRUE == sendStatus ) - { - // Reset the retry count - sendRetryCount = 0; - - // Clear the publishing flags - recordToPublish = NUM_OF_NV_DD_DATA; - - // 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_NV_DD_DATA; - - // Move to Send Idle State - state = NVM_SEND_RECORD_STATE_IDLE; - } - - return state; -} - -/*********************************************************************//** - * @brief - * The updateCalSendRetryCountAndIndex function updates the retry counts, - * sensor index, record to be published based on the send status of the calibration data. - * @details \b Inputs: None - * @details \b Outputs: recordToPublish, sendRetryCount, 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 - *************************************************************************/ -static SEND_RECORD_STATE_T updateCalSendRetryCountAndIndex( BOOL sendStatus, U08 maxIdx ) -{ - SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; - BOOL resetState = FALSE; - - // Check if record was sent successfully - if ( TRUE == sendStatus) - { - sendCalIdx++; - sendRetryCount = 0; - - // Check if we sent the last record of calibration component - if ( sendCalIdx >= maxIdx ) - { - resetState = TRUE; - } - } - else - { - sendRetryCount ++; - } - - // If all the allowed retries has been utilized or - if ( sendRetryCount >= MAX_NUM_OF_SEND_RETRIES ) - { - resetState = TRUE; - } - - if ( TRUE == resetState) - { - // Reset Sensor Index for the next request - sendCalIdx = 0; - - // Reset the retry count - sendRetryCount = 0; - - // Clear the publishing flags - recordToPublish = NUM_OF_NV_DD_DATA; - - // Move to Send Idle State - state = NVM_SEND_RECORD_STATE_IDLE; - } - - return state; -} - BOOL handleDDGetSystemRecRequest( MESSAGE_T *message ) { BOOL result = FALSE; @@ -1410,6 +1415,7 @@ if ( message->hdr.payloadLen == expectedPayloadLen ) { 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 ); @@ -1468,6 +1474,7 @@ 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 ); @@ -1523,6 +1530,7 @@ 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 ); @@ -1573,7 +1581,7 @@ if ( message->hdr.payloadLen == expectedPayloadLen ) { memcpy( &record, message->payload, expectedPayloadLen ); - record.crc = crc16( (U08*)&record, sizeof( DD_INSTIT_BASIC_RECORD_T ) - sizeof( U16 ) ); + 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 ); @@ -1624,7 +1632,7 @@ if ( message->hdr.payloadLen == expectedPayloadLen ) { memcpy( &record, message->payload, expectedPayloadLen ); - record.crc = crc16( (U08*)&record, sizeof( DD_INSTIT_ADVANCED_RECORD_T ) - sizeof( U16 ) ); + 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 ); @@ -1675,7 +1683,7 @@ if ( message->hdr.payloadLen == expectedPayloadLen ) { memcpy( &record, message->payload, expectedPayloadLen ); - record.crc = crc16( (U08*)&record, sizeof( DD_INSTIT_ADDITIONAL_RECORD_T ) - sizeof( U16 ) ); + 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 ); @@ -1697,15 +1705,15 @@ { BOOL result = FALSE; U08* payloadPtr = message->payload; - U08 expectedPayloadLen = sizeof( U32 ) + 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, &message->payload, sizeof(U32)); + memcpy( &idx, payloadPtr, sizeof(U32)); if( idx < NUM_OF_PRESSURE_SENSORS ) { @@ -1761,6 +1769,7 @@ 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 @@ -1787,13 +1796,33 @@ BOOL handleDDGetTemperatureSensorCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; + 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 ) { - isPublishRecordRequested[ NV_DD_DATA_CAL_TEMPERATURE_SENSORS ] = TRUE; - result = TRUE; + 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 { @@ -1813,9 +1842,9 @@ 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 + U08 expectedPayloadLen = sizeof( U32 ) + recordSize; // Index + Data - CRC DD_NVM_SET_LINEAR_CAL_REC_PAYLOAD_T response = { 0 }; - U08 idx; + U32 idx; LINEAR_CAL_PAYLOAD_T record; // Calibration record can be updated only in service mode @@ -1833,6 +1862,7 @@ 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 @@ -1859,13 +1889,33 @@ BOOL handleDDGetConcPumpCalRecRequest( MESSAGE_T *message ) { - BOOL result = FALSE; + 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 ) { - isPublishRecordRequested[ NV_DD_DATA_CAL_CONCENTRATE_PUMPS_RECORD] = TRUE; - result = TRUE; + if ( message->hdr.payloadLen == expectedPayloadLen ) + { + memcpy( &idx, payloadPtr, sizeof(U32)); + + if( idx < NUM_OF_CONCENTRATE_PUMPS ) + { + 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 { @@ -1885,9 +1935,9 @@ 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 + U08 expectedPayloadLen = sizeof( U32 ) + recordSize; // Index + Data - CRC DD_NVM_SET_LINEAR_CAL_REC_PAYLOAD_T response = { 0 }; - U08 idx; + U32 idx; LINEAR_CAL_PAYLOAD_T record; // Calibration record can be updated only in service mode @@ -1905,6 +1955,7 @@ 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 @@ -2053,13 +2104,33 @@ 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; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - isPublishRecordRequested[ NV_DD_DATA_CAL_ACID_CONCENTREATES] = TRUE; - result = TRUE; + 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 { @@ -2079,9 +2150,9 @@ 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 + U08 expectedPayloadLen = sizeof( U32 ) + recordSize; // Index + Data - CRC DD_NVM_SET_ACID_CONC_CAL_REC_PAYLOAD_T response = { 0 }; - U08 idx; + U32 idx; DD_ACID_CONCENTRATE_T record; // Calibration record can be updated only in service mode @@ -2099,6 +2170,7 @@ 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 @@ -2125,13 +2197,33 @@ 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; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - isPublishRecordRequested[ NV_DD_DATA_CAL_BICARB_CONCENTRATES] = TRUE; - result = TRUE; + 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 { @@ -2151,9 +2243,9 @@ 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 + U08 expectedPayloadLen = sizeof( U32 ) + recordSize; // Index + Data - CRC DD_NVM_SET_BICARB_CONC_CAL_REC_PAYLOAD_T response = { 0 }; - U08 idx; + U32 idx; DD_BICARB_CONCENTRATE_T record; // Calibration record can be updated only in service mode @@ -2171,6 +2263,7 @@ 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 @@ -2319,13 +2412,33 @@ 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; if ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) { - isPublishRecordRequested[ NV_DD_DATA_CAL_CONDUCTIVITY_SENSORS ] = TRUE; - result = TRUE; + 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 { @@ -2345,9 +2458,9 @@ BOOL result = FALSE; U08* payloadPtr = message->payload; U08 recordSize = sizeof( CONDUCTIVITY_COEFFICIENTS_T ) - sizeof( U16 ); // Data - CRC - U08 expectedPayloadLen = sizeof( U08 ) + recordSize; // Index + Data - CRC + U08 expectedPayloadLen = sizeof( U32 ) + recordSize; // Index + Data - CRC DD_NVM_SET_CONDUCTIVITY_SENSOR_CAL_REC_PAYLOAD_T response = { 0 }; - U08 idx; + U32 idx; CONDUCTIVITY_COEFFICIENTS_T record; // Calibration record can be updated only in service mode @@ -2368,6 +2481,7 @@ 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