Index: firmware/App/Services/NVMsgQ.c =================================================================== diff -u -r724f9a0cf2b603e988a519420bf95f4aa4da4b93 -r1be7dc9ec7ae5a6576a4c841e3b22ac77aea8db8 --- firmware/App/Services/NVMsgQ.c (.../NVMsgQ.c) (revision 724f9a0cf2b603e988a519420bf95f4aa4da4b93) +++ firmware/App/Services/NVMsgQ.c (.../NVMsgQ.c) (revision 1be7dc9ec7ae5a6576a4c841e3b22ac77aea8db8) @@ -18,6 +18,7 @@ #include "MsgDefs.h" #include "NVMsgQ.h" #include "NVRecordsDD.h" +#include "OperationModes.h" #include "TaskGeneral.h" #include "Timers.h" #include "Utilities.h" // For crc calculation @@ -74,6 +75,13 @@ U08 data[NUM_OF_BYTES_PER_RECORD_PAYLOAD]; } DD_NVM_RECORD_PAYLOAD_T; +/// DD institutional values structure. +typedef struct +{ + U32 minRORejectionRatioPCT; ///< Min RO rejection ratio in percent. + F32 minInletWaterCondAlarmLimitUSPCM; ///< Min inlet water conductivity alarm limit in uS/cm. +} DD_INSTITUTIONAL_VALUES_T; + // ********** private data ********** static PROCESS_RECORD_JOB_T recordJobQueue[ QUEUE_MAX_SIZE ]; ///< Record queue jobs. @@ -103,6 +111,8 @@ // Process record functions static PROCESS_RECORD_STATE_T handleExecProcessRecordIdleState( void ); static PROCESS_RECORD_STATE_T handleExecProcessRecordSendRecordState( void ); +static void sendInstitutionalRecordToUI( DD_INSTITUTIONAL_LOCAL_RECORD_T* instit ); +static void handleDGRequestInstitutionalValues( MESSAGE_T* message ); static BOOL sendDDRecord( MSG_ID_T msgId, U32 payloadCurrNum, U32 payloadTotalNum, U32 length, U08* calRcrdAddress ); static RECORD_JOBS_STATE_T getNVMRecordJobState( MSG_ID_T msgID ); static MSG_ID_T getNVMRecordResponseMsgId (RECORD_JOBS_STATE_T job ); @@ -125,9 +135,6 @@ hasPublishRecordBeenRequested[ NVDATAMGMT_SYSTEM_RECORD ] = FALSE; hasPublishRecordBeenRequested[ NVDATAMGMT_SERVICE_RECORD ] = FALSE; hasPublishRecordBeenRequested[ NVDATAMGMT_USAGE_INFO_RECORD ] = FALSE; -#ifndef _RELEASE_ - hasPublishRecordBeenRequested[ NVDATAMGMT_SW_CONFIG_RECORD ] = FALSE; -#endif newCalStartTimer = 0; @@ -518,6 +525,92 @@ /*********************************************************************//** * @brief + * The handleSendInstitutionalRecordToUI function sends the institutional record to UI + * @details Inputs: none + * @details Outputs: none + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSendInstitutionalRecordToUI( MESSAGE_T* message ) +{ + if ( 0 == message->hdr.payloadLen ) + { + DD_INSTITUTIONAL_RECORD_T ddInstitutionalRecord; + DD_INSTITUTIONAL_LOCAL_RECORD_T ddInstitutionalLocalRecord; + + getNVRecord2Driver( GET_INSTITUTIONAL_RECORD, (U08*)&ddInstitutionalRecord, sizeof( DD_INSTITUTIONAL_RECORD_T ), 0, ALARM_ID_NO_ALARM ); + + memcpy( &ddInstitutionalLocalRecord, &ddInstitutionalRecord, sizeof( DD_INSTITUTIONAL_LOCAL_RECORD_T ) ); + + sendInstitutionalRecordToUI( &ddInstitutionalLocalRecord ); + } +} + +/*********************************************************************//** + * @brief + * The sendInstitutionalRecordToUI function sends the institutional record to UI + * @details Inputs: none + * @details Outputs: none + * @param instit a pointer to the local institutional recored in the system + * messages that is without calibration time and crc + * @return none + *************************************************************************/ +static void sendInstitutionalRecordToUI( DD_INSTITUTIONAL_LOCAL_RECORD_T* instit ) +{ + MESSAGE_T msg; + + U08 *payloadPtr = msg.payload; + U32 accept = 1; + U32 reason = 0; + + // Create a message record + blankMessage( &msg ); +// msg.hdr.msgID = MSG_ID_HD_INSTITUTIONAL_RECORD_RESPONSE; + msg.hdr.payloadLen = sizeof( U32 ) + sizeof( U32 ) + sizeof( DD_INSTITUTIONAL_LOCAL_RECORD_T ); + + memcpy( payloadPtr, &accept, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &reason, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, instit, sizeof( DD_INSTITUTIONAL_LOCAL_RECORD_T ) ); + + // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer +// serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_UI, ACK_REQUIRED ); +} + +/*********************************************************************//** + * @brief + * The handleDGRequestInstitutionalValues function handles the DG request + * to receive the DG institutional values from HD institutional record. + * @details Inputs: none + * @details Outputs: none + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +static void handleDGRequestInstitutionalValues( MESSAGE_T* message ) +{ + if ( 0 == message->hdr.payloadLen ) + { + MESSAGE_T msg; + DD_INSTITUTIONAL_VALUES_T ddInstitValues; + + ddInstitValues.minRORejectionRatioPCT = getMinRORejectionRatioInInstitRecordPCT(); + ddInstitValues.minInletWaterCondAlarmLimitUSPCM = getMinInletWaterConductivityLimitInstitRecordUSPCM(); + + // Create a message record + blankMessage( &msg ); +// msg.hdr.msgID = MSG_ID_DG_INSTIT_VALUES_FROM_HD_INSTIT_RECORD_RESPONSE; + msg.hdr.payloadLen = sizeof( DD_INSTITUTIONAL_VALUES_T ); + + memcpy( msg.payload, &ddInstitValues, sizeof( DD_INSTITUTIONAL_VALUES_T ) ); + + // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer +// serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_DG, ACK_REQUIRED ); + } +} + +/*********************************************************************//** + * @brief * The receiveRecordFromDialin function receives the record that has been sent * from Dialin and if the CRCs passed, it schedules a write to the NV data. * @details Inputs: currentMessage, nvDataMgmtExecReceiveRecordState, @@ -569,6 +662,12 @@ // Get the CRC of the structure without the last 16 bits which is the CRC as well as the padding values U16 recordCRC = *(U16*)recordSpec.structCRCPtr; + if ( NVDATAMGMT_INTITUTIONAL_RECORD == job ) + { +// isInstRcrdValid = isNVInstitutionalRecordInRange( &ddInstitutionalGroup.ddInstitutionalRecord ); + status = isInstRcrdValid; + } + if ( ( calcCRC != recordCRC ) || ( FALSE == isInstRcrdValid ) ) { // Institutional record has failed so do not write it into the NV memory and read back what was in the NV memory @@ -583,6 +682,18 @@ // CRC passed, enqueue an erase, a write of calibration data and a write of service record BOOL scheduleStatus = enqueueSector0Records(); + MESSAGE_T institMsg; + // Got new data for the EEPROM records, set the latest institutional record to treatment parameters to make sure + // the treatment parameters have the record available all the time +// setNVInstitutionalRecordToTxParamsRecord( &ddInstitutionalGroup.ddInstitutionalRecord ); + + // Received new institutional record and it is valid, send it to the UI to be up to date + institMsg.hdr.msgID = 0; + institMsg.hdr.payloadLen = 0; + handleSendInstitutionalRecordToUI( &institMsg ); + // Received new institutional record and it is valid, send it to the DG to be up to date + handleDGRequestInstitutionalValues( &institMsg ); + // Signal that there is a new calibration record available. // NOTE: as of now, this signal will be sent even after the system record is sent newCalStartTimer = getMSTimerCount(); @@ -660,12 +771,6 @@ job = NVDATAMGMT_USAGE_INFO_RECORD; break; -#ifndef _RELEASE_ - case MSG_ID_DD_NVM_SET_SW_CONFIG_RECORD: - job = NVDATAMGMT_SW_CONFIG_RECORD; - break; -#endif - default: // Software Fault break; @@ -697,12 +802,6 @@ msgID = MSG_ID_DD_NVM_SEND_USAGE_INFO_RECORD; break; -#ifndef _RELEASE_ - case NVDATAMGMT_SW_CONFIG_RECORD: - msgID = MSG_ID_DD_NVM_SEND_SW_CONFIG_RECORD; - break; -#endif - default: // Software fault break;