Index: firmware/App/Services/NVMessagingDD.c =================================================================== diff -u -rbeb95e3e8f85740707704d7089db8b3ec8574bbd -r0599bd5494eb64416999de0487a9882c557b6044 --- firmware/App/Services/NVMessagingDD.c (.../NVMessagingDD.c) (revision beb95e3e8f85740707704d7089db8b3ec8574bbd) +++ firmware/App/Services/NVMessagingDD.c (.../NVMessagingDD.c) (revision 0599bd5494eb64416999de0487a9882c557b6044) @@ -13,6 +13,7 @@ ***************************************************************************/ #include // For ceilf function +#include "Messaging.h" #include "NVJobQ.h" #include "NVMessagingDD.h" #include "NVRecordsDD.h" @@ -105,11 +106,8 @@ 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 previousRecordMessageNum; ///< Record previous message number. -static U32 recordUpdateAddress; ///< DD record update address for all the write operations. static U32 calRecordReceiveStartTime; ///< Time stamp the calibration record was received. static U32 institRecordReceiveStartTime; ///< Time stamp the institutional record was received. -static U32 recordReceiveStartTime; ///< Time stamp the calibration/service 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 @@ -139,10 +137,7 @@ static BOOL sendBloodLeakSensorCalRecord( void ); static BOOL receiveCalRecord( MESSAGE_T *message, DD_CAL_REC_TYPE calRecordType, U16 recordSize ); - static BOOL verifyAndSaveReceivedRecord( NVM_RECORD_TYPE_T job, U32 currentMessage, - U32 totalMessages, U32 length, U08 *addressPtr ); -static NVM_RECORD_TYPE_T getNVMRecordJobState( MSG_ID_T msgID ); -static MSG_ID_T getNVMRecordResponseMsgId (NVM_RECORD_TYPE_T job ); +static MSG_ID_T getNVMCalRecordResponseMsgId(DD_CAL_REC_TYPE calRecordType ); static void monitorNewCalSignal( void ); /*********************************************************************//** @@ -172,8 +167,6 @@ isPublishRecordRequested[ NVM_INSTITUTIONAL_RECORD ] = FALSE; isPublishRecordRequested[ NVM_USAGE_INFO_RECORD ] = FALSE; recordSendDataIntervalCounter = 0; - previousRecordMessageNum = 0; - recordReceiveStartTime = 0; sendInstitRec = DD_INSTIT_MIN_DIALYSATE_FLOW_MLPM; sendCalRec = DD_CAL_RECORD_PRESSURE_SENSOR; } @@ -367,6 +360,15 @@ return state; } +/*********************************************************************//** + * @brief + * The handleSendDDSystemRecord function sends the DD system record. + * It retries transmission on failure and returns to the idle state + * after a successful send or when retries are exhausted. + * @details \b Inputs: recordToPublish, sendRetryCount + * @details \b Outputs: recordToPublish, sendRetryCount + * @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; @@ -375,7 +377,7 @@ DD_SYSTEM_RECORD_T systemRecord; // Get the record - if( TRUE == getNVMRecord( GET_SYSTEM_RECORD, + if ( TRUE == getNVMRecord( GET_SYSTEM_RECORD, (U08*)&systemRecord, sizeof( DD_SYSTEM_RECORD_T ) , 0, @@ -384,7 +386,7 @@ // Send the record sysStatus = sendMessage( MSG_ID_DD_NVM_SYSTEM_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08 *)&systemRecord, + (U08*)&systemRecord, sizeof( DD_SYSTEM_RECORD_T ) ); } @@ -406,7 +408,7 @@ } // Utilized all the retries. Something is wrong. - if( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) + if ( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) { // Reset the retry count sendRetryCount = 0; @@ -421,23 +423,32 @@ return state; } +/*********************************************************************//** + * @brief + * The handleSendDDServiceRecord function sends the DD service record. + * It retries transmission on failure and returns to the idle state + * after a successful send or when retries are exhausted. + * @details \b Inputs: recordToPublish, sendRetryCount + * @details \b Outputs: recordToPublish, sendRetryCount + * @return state next state of the state machine + *************************************************************************/ static SEND_RECORD_STATE_T handleSendDDServiceRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL serStatus = FALSE; DD_SERVICE_RECORD_T serviceRecord; // Get the record - if( TRUE == getNVMRecord( GET_SERVICE_RECORD, + if ( TRUE == getNVMRecord( GET_SERVICE_RECORD, (U08*)&serviceRecord, sizeof( DD_SERVICE_RECORD_T ) , 0, - ALARM_ID_DD_NVM_INVALID_SYSTEM_RECORD_CRC ) ) + ALARM_ID_DD_NVM_INVALID_SERVICE_RECORD_CRC ) ) { // Send the record serStatus = sendMessage( MSG_ID_DD_NVM_SERVICE_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08 *)&serviceRecord, + (U08*)&serviceRecord, sizeof( DD_SERVICE_RECORD_T ) ); } @@ -459,7 +470,7 @@ } // Utilized all the retries. Something is wrong. - if( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) + if ( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) { // Reset the retry count sendRetryCount = 0; @@ -474,8 +485,15 @@ return state; } - - +/*********************************************************************//** + * @brief + * The handleSendDDInstitutionalRecord function sends institutional + * record data one item at a time. It builds the payload based on the + * data type and manages retries and record sequencing. + * @details \b Inputs: sendInstitRec, recordToPublish, sendRetryCount + * @details \b Outputs: sendInstitRec, recordToPublish, sendRetryCount + * @return state next state of the state machine + *************************************************************************/ static SEND_RECORD_STATE_T handleSendDDInstitutionalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; @@ -489,17 +507,17 @@ dataType = getInstitRecDataType( (DD_INSTIT_REC_TYPE)sendInstitRec ); // Create the payload based on the data type - if( CRITICAL_DATA_TYPE_U32 == dataType ) + if ( CRITICAL_DATA_TYPE_U32 == dataType ) { - if ( TRUE == ( getNVMInstitRecord((DD_INSTIT_REC_TYPE)sendInstitRec , (U08*)&valueU32 ) ) ) + if ( TRUE == ( getNVMInstitRecord( (DD_INSTIT_REC_TYPE)sendInstitRec, (U08*)&valueU32 ) ) ) { memcpy( &payload.data, &valueU32, sizeof( U32 ) ); } } - if( CRITICAL_DATA_TYPE_F32 == dataType ) + if ( CRITICAL_DATA_TYPE_F32 == dataType ) { - if ( TRUE == ( getNVMInstitRecord((DD_INSTIT_REC_TYPE)sendInstitRec , (U08*)&valueF32 ) ) ) + if ( TRUE == ( getNVMInstitRecord( (DD_INSTIT_REC_TYPE)sendInstitRec, (U08*)&valueF32 ) ) ) { memcpy( &payload.data, &valueF32, sizeof( F32 ) ); } @@ -514,7 +532,7 @@ sizeof( DD_NVM_SEND_RECORD_PAYLOAD_T ) ); // Check if record was sent successfully - if ( TRUE == sendStatus) + if ( TRUE == sendStatus ) { // Reset the retry count sendRetryCount = 0; @@ -549,15 +567,24 @@ return state; } +/*********************************************************************//** + * @brief + * The handleSendDDUsageInfoRecord function sends the DD usage + * information record. It retries transmission on failure and returns + * to the idle state after a successful send or when retries are + * exhausted. + * @details \b Inputs: recordToPublish, sendRetryCount + * @details \b Outputs: recordToPublish, sendRetryCount + * @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 usageStatus = FALSE; DD_USAGE_INFO_RECORD_T usageInfoRecord; - // Get the record - if( TRUE == getNVMRecord( GET_USAGE_RECORD, + if ( TRUE == getNVMRecord( GET_USAGE_RECORD, (U08*)&usageInfoRecord, sizeof( DD_USAGE_INFO_RECORD_T ), 0, @@ -566,7 +593,7 @@ // Send the record usageStatus = sendMessage( MSG_ID_DD_NVM_USAGE_INFO_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08 *)&usageInfoRecord, + (U08*)&usageInfoRecord, sizeof( DD_USAGE_INFO_RECORD_T ) ); } @@ -588,7 +615,7 @@ } // Utilized all the retries. Something is wrong. - if( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) + if ( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) { // Reset the retry count sendRetryCount = 0; @@ -603,12 +630,24 @@ return state; } +/*********************************************************************//** + * @brief + * The handleSendDDCalibrationRecord function sends DD calibration + * records. It manages calibration record sequencing, sensor indexing, + * retries, and transitions back to the idle state when all records + * have been published or retries are exhausted. + * @details \b Inputs: sendCalRec, sendSensorIdx, + * maxSensorIdx, recordToPublish, sendRetryCount + * @details \b Outputs: sendCalRec, sendSensorIdx, + * recordToPublish, sendRetryCount + * @return state next state of the state machine + *************************************************************************/ static SEND_RECORD_STATE_T handleSendDDCalibrationRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; - switch( sendCalRec ) + switch ( sendCalRec ) { case DD_CAL_RECORD_PRESSURE_SENSOR: sendStatus = sendPressureSensorCalRecord(); @@ -651,54 +690,60 @@ } // Check if record was sent successfully - if ( TRUE == sendStatus) + if ( TRUE == sendStatus) + { + sendSensorIdx++; + + // Check if we sent the last record of calibration component + if ( sendSensorIdx >= maxSensorIdx ) { - // Check if we sent the last record of calibration component - if ( sendSensorIdx >= maxSensorIdx ) - { - // Reset Sensor Index for the next calibration data - sendSensorIdx = 0; + // Reset Sensor Index for the next calibration data + sendSensorIdx = 0; - // Reset the retry count for the next calibration data - sendRetryCount = 0; + // Reset the retry count for the next calibration data + sendRetryCount = 0; - // Move on to publish the next calibration record - sendCalRec = (DD_CAL_REC_TYPE)( (U32)sendCalRec + 1 ); - } - else - { - sendSensorIdx++; - } + // Move on to publish the next calibration record + sendCalRec = (DD_CAL_REC_TYPE)( (U32)sendCalRec + 1 ); } - else - { - sendRetryCount ++; - } + } + else + { + sendRetryCount ++; + } - // If all the allowed retries has been utilized or - // If all the calibration records have been published - if ( ( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) || - ( sendCalRec >= NUM_OF_CAL_RECORD_TYPE ) ) - { - // Reset Sensor Index for the next request - sendSensorIdx = 0; + // If all the allowed retries has been utilized or + // If all the calibration records have been published + if ( ( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) || + ( sendCalRec >= NUM_OF_CAL_RECORD_TYPE ) ) + { + // Reset Sensor Index for the next request + sendSensorIdx = 0; - // Reset Index tracker for next request. - sendCalRec = DD_CAL_RECORD_PRESSURE_SENSOR; + // Reset Index tracker for next request. + sendCalRec = DD_CAL_RECORD_PRESSURE_SENSOR; - // Clear the publishing flags - recordToPublish = NUM_OF_NVM_RECORD_TYPES; + // Clear the publishing flags + recordToPublish = NUM_OF_NVM_RECORD_TYPES; - // Move to Send Idle State - state = NVM_SEND_RECORD_STATE_IDLE; + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; - // Reset the retry count - sendRetryCount = 0; - } + // Reset the retry count + sendRetryCount = 0; + } return state; } +/*********************************************************************//** + * @brief + * The sendPressureSensorCalRecord function sends the calibration + * record of the selected pressure sensor. + * @details \b Inputs: sendSensorIdx + * @details \b Outputs: maxSensorIdx + * @return TRUE if the message was successfully sent otherwise FALSE + *************************************************************************/ static BOOL sendPressureSensorCalRecord( void ) { BOOL sendStatus = FALSE; @@ -716,6 +761,14 @@ return sendStatus; } +/*********************************************************************//** + * @brief + * The sendTempSensorCalRecord function sends the calibration record + * of the selected temperature sensor. + * @details \b Inputs: sendSensorIdx + * @details \b Outputs: maxSensorIdx + * @return TRUE if the message was successfully sent otherwise FALSE + *************************************************************************/ static BOOL sendTempSensorCalRecord( void ) { BOOL sendStatus = FALSE; @@ -733,6 +786,14 @@ return sendStatus; } +/*********************************************************************//** + * @brief + * The sendConcPumpCalRecord function sends the calibration record + * of the selected concentrate pump. + * @details \b Inputs: sendSensorIdx + * @details \b Outputs: maxSensorIdx + * @return TRUE if the message was successfully sent otherwise FALSE + *************************************************************************/ static BOOL sendConcPumpCalRecord( void ) { BOOL sendStatus = FALSE; @@ -750,6 +811,14 @@ return sendStatus; } +/*********************************************************************//** + * @brief + * The sendD12PumpCalRecord function sends the calibration record of + * the D12 dialysate pump. + * @details \b Inputs: none + * @details \b Outputs: sendSensorIdx, maxSensorIdx + * @return TRUE if the message was successfully sent otherwise FALSE + *************************************************************************/ static BOOL sendD12PumpCalRecord( void ) { BOOL sendStatus = FALSE; @@ -765,6 +834,14 @@ return sendStatus; } +/*********************************************************************//** + * @brief + * The sendD48PumpCalRecord function sends the calibration record of + * the D48 dialysate pump. + * @details \b Inputs: none + * @details \b Outputs: sendSensorIdx, maxSensorIdx + * @return TRUE if the message was successfully sent otherwise FALSE + *************************************************************************/ static BOOL sendD48PumpCalRecord( void ) { BOOL sendStatus = FALSE; @@ -780,6 +857,14 @@ return sendStatus; } +/*********************************************************************//** + * @brief + * The sendAcidConcCalRecord function sends the calibration record of + * the selected acid concentrate. + * @details \b Inputs: sendSensorIdx + * @details \b Outputs: maxSensorIdx + * @return TRUE if the message was successfully sent otherwise FALSE + *************************************************************************/ static BOOL sendAcidConcCalRecord( void ) { BOOL sendStatus = FALSE; @@ -797,6 +882,14 @@ return sendStatus; } +/*********************************************************************//** + * @brief + * The sendAcidConcCalRecord function sends the calibration record of + * the selected acid concentrate. + * @details \b Inputs: sendSensorIdx + * @details \b Outputs: maxSensorIdx + * @return TRUE if the message was successfully sent otherwise FALSE + *************************************************************************/ static BOOL sendBicarbConcCalRecord( void ) { BOOL sendStatus = FALSE; @@ -814,6 +907,14 @@ return sendStatus; } +/*********************************************************************//** + * @brief + * The sendAccelSensorCalRecord function sends the calibration record + * of the accelerometer sensor. + * @details \b Inputs: none + * @details \b Outputs: sendSensorIdx, maxSensorIdx + * @return TRUE if the message was successfully sent otherwise FALSE + *************************************************************************/ static BOOL sendAccelSensorCalRecord( void ) { BOOL sendStatus = FALSE; @@ -829,6 +930,14 @@ return sendStatus; } +/*********************************************************************//** + * @brief + * The sendBloodLeakSensorCalRecord function sends the calibration + * record of the blood leak sensor. + * @details \b Inputs: none + * @details \b Outputs: sendSensorIdx, maxSensorIdx + * @return TRUE if the message was successfully sent otherwise FALSE + *************************************************************************/ static BOOL sendBloodLeakSensorCalRecord( void ) { BOOL sendStatus = FALSE; @@ -844,54 +953,153 @@ return sendStatus; } -static BOOL receiveCalRecord( MESSAGE_T *message, DD_CAL_REC_TYPE calRecordType, U16 recordSize ) +/*********************************************************************//** + * @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 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, DD_CAL_REC_TYPE calRecordType, U16 recordSize ) { - BOOL status = FALSE; -// U08 idx = 0; -// MSG_ID_T msgID = (MSG_ID_T)message->hdr.msgID; - U08* payloadPtr = message->payload; + BOOL status = FALSE; + U08* payloadPtr = message->payload; U08 expectedPayloadLen = ( sizeof(U08) + recordSize ); -// U08 tempBuffer[ recordSize ]; + MSG_ID_T msgID = getNVMCalRecordResponseMsgId( calRecordType ); + UI_RESPONSE_PAYLOAD_T response; DD_NVM_SEND_RECORD_PAYLOAD_T recvdPayload; - if ( message->hdr.payloadLen == expectedPayloadLen ) + if ( DD_MODE_SERV == getCurrentOperationMode() ) { - memcpy( &recvdPayload.idx, payloadPtr, sizeof(U32)); - payloadPtr += sizeof(U08); + if ( message->hdr.payloadLen == expectedPayloadLen ) + { + memcpy( &recvdPayload.idx, payloadPtr, sizeof(U32)); + payloadPtr += sizeof(U08); - memcpy( &recvdPayload.data, payloadPtr, recordSize ); + 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) ); + // 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 ); + if ( calcCRC == *recordCRC ) + { + nvmExecreceiveRecordState = NVM_RECEIVE_RECORD_STATE_RECEIVE; + status = setNVMCalRecord( calRecordType, (U08*)&recvdPayload.data, recvdPayload.idx ); - // 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; + 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_BLLOD_LEAK_SENSOR: + msgId = MSG_ID_DD_NVM_SET_CAL_BLOOD_LEAK_SENSOR_RESPONSE; + break; + + default: + // Software fault + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, ( U32 )calRecordType ); + break; + } + + return msgId; +} + +/*********************************************************************//** + * @brief * The monitorNewCalSignal function monitors the new calibration signal * and clears it when the timeout has elapsed. * @details \b Inputs: isNewCalRecordAvailable, * newRecordStartTimer * @details \b Outputs: isNewCalRecordAvailable * @return none *************************************************************************/ - static void monitorNewCalSignal( void ) { // Check if new calibration record is available and @@ -923,8 +1131,9 @@ *************************************************************************/ BOOL testDDGetNVRecord( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = FALSE; NVM_RECORD_TYPE_T job; + UI_RESPONSE_PAYLOAD_T response; // verify payload length if ( 1 == message->hdr.payloadLen ) @@ -938,10 +1147,25 @@ 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; + } } + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + sendMessage( MSG_ID_DD_NVM_GET_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, + sizeof( UI_RESPONSE_PAYLOAD_T ) ); + return result; } @@ -957,20 +1181,20 @@ *************************************************************************/ BOOL testDDSetNVSystemRecord( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = FALSE; U08 tempBuffer[ sizeof( DD_SYSTEM_RECORD_T ) ]; + UI_RESPONSE_PAYLOAD_T response; - // System record can be updated only in service mode if ( DD_MODE_SERV == getCurrentOperationMode() ) { if (message->hdr.payloadLen == sizeof( DD_SYSTEM_RECORD_T )) { memcpy( tempBuffer, message->payload, sizeof( DD_SYSTEM_RECORD_T ) ); - // CRC assumed at end of record + // 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) ); + U16 calcCRC = crc16( tempBuffer, sizeof( DD_SYSTEM_RECORD_T ) - sizeof(U16) ); if ( calcCRC == *recordCRC ) { @@ -980,10 +1204,32 @@ setNVMRecord( NVM_SYSTEM_RECORD, tempBuffer ); result = enqueueEraseAndWriteSector( NVM_SYSTEM_RECORD ); sendNVEvent( NVM_SYSTEM_RECORD, 0, 0 ); + + response.accepted = TRUE; + response.rejectionReason = REQUEST_REJECT_REASON_NONE; } + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_CRC; + } } + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } } + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; + } + sendMessage( MSG_ID_DD_NVM_SET_SYSTEM_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, + sizeof( UI_RESPONSE_PAYLOAD_T ) ); + return result; } @@ -999,8 +1245,9 @@ *************************************************************************/ BOOL testDDSetNVServiceRecord( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = FALSE; U08 tempBuffer[ sizeof( DD_SERVICE_RECORD_T ) ]; + UI_RESPONSE_PAYLOAD_T response; // Service record can be updated only in service mode if ( DD_MODE_SERV == getCurrentOperationMode() ) @@ -1021,11 +1268,32 @@ setNVMRecord( NVM_SERVICE_RECORD, tempBuffer ); result = enqueueEraseAndWriteSector( NVM_SERVICE_RECORD ); sendNVEvent( NVM_SERVICE_RECORD, 0, 0 ); + + response.accepted = TRUE; + response.rejectionReason = REQUEST_REJECT_REASON_NONE; } + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_CRC; + } } - + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } } + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; + } + sendMessage( MSG_ID_DD_NVM_SET_SERVICE_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, + sizeof( UI_RESPONSE_PAYLOAD_T ) ); + return result; } @@ -1040,8 +1308,9 @@ *************************************************************************/ BOOL testDDSetNVUsageInfoRecord( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = FALSE; U08 tempBuffer[ sizeof( DD_USAGE_INFO_RECORD_T ) ]; + UI_RESPONSE_PAYLOAD_T response; if (message->hdr.payloadLen == ( sizeof( DD_USAGE_INFO_RECORD_T ) )) { @@ -1059,9 +1328,26 @@ setNVMRecord( NVM_USAGE_INFO_RECORD, tempBuffer ); result = enqueueEraseAndWriteSector( NVM_USAGE_INFO_RECORD ); sendNVEvent( NVM_USAGE_INFO_RECORD, 0, 0 ); + + response.accepted = TRUE; + response.rejectionReason = REQUEST_REJECT_REASON_NONE; } + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_CRC; + } } + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + sendMessage( MSG_ID_DD_NVM_SET_USAGE_INFO_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, + sizeof( UI_RESPONSE_PAYLOAD_T ) ); + return result; } @@ -1076,10 +1362,11 @@ *************************************************************************/ BOOL testDDSetNVInstitutionalRecord( MESSAGE_T *message ) { - BOOL result = FALSE; - U08 idx = 0; - U08* payloadPtr = message->payload; + BOOL result = FALSE; + U08 idx = 0; + U08* payloadPtr = message->payload; U08 expectedPayloadLen = sizeof(U08); + UI_RESPONSE_PAYLOAD_T response; if ( message->hdr.payloadLen >= expectedPayloadLen ) { @@ -1090,124 +1377,210 @@ 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 testDDSetPressureSensorCalRecord 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 testDDSetPressureSensorCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; - if ( DD_MODE_SERV == getCurrentOperationMode() ) - { - result = receiveCalRecord( message, DD_CAL_RECORD_PRESSURE_SENSOR , sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); - } + result = receiveCalRecord( message, DD_CAL_RECORD_PRESSURE_SENSOR, + sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); + return result; } +/*********************************************************************//** + * @brief + * The testDDSetTempSensorCalRecord 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 testDDSetTempSensorCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; - if ( DD_MODE_SERV == getCurrentOperationMode() ) - { - result = receiveCalRecord( message, DD_CAL_RECORD_TEMPERATURE_SENSOR , sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); - } + result = receiveCalRecord( message, DD_CAL_RECORD_TEMPERATURE_SENSOR, + sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); return result; } +/*********************************************************************//** + * @brief + * The testDDSetConcPumpCalRecord 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 testDDSetConcPumpCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; - if ( DD_MODE_SERV == getCurrentOperationMode() ) - { - result = receiveCalRecord( message, DD_CAL_RECORD_CONCENTRATE_PUMP , sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); - } + result = receiveCalRecord( message, DD_CAL_RECORD_CONCENTRATE_PUMP, + sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); return result; } +/*********************************************************************//** + * @brief + * The testDDSetD12PumpCalRecord 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 testDDSetD12PumpCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; - if ( DD_MODE_SERV == getCurrentOperationMode() ) - { - result = receiveCalRecord( message, DD_CAL_RECORD_D12_PUMP , sizeof( DD_D12_DIALYSATE_PUMP_RECORD_T ) ); - } + result = receiveCalRecord( message, DD_CAL_RECORD_D12_PUMP, + sizeof( DD_D12_DIALYSATE_PUMP_RECORD_T ) ); return result; } +/*********************************************************************//** + * @brief + * The testDDSetD48PumpCalRecord 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 testDDSetD48CalRecord( MESSAGE_T *message ) { BOOL result = FALSE; - if ( DD_MODE_SERV == getCurrentOperationMode() ) - { - result = receiveCalRecord( message, DD_CAL_RECORD_D48_PUMP , sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); - } + result = receiveCalRecord( message, DD_CAL_RECORD_D48_PUMP, + sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); return result; } +/*********************************************************************//** + * @brief + * The testDDSetAcidConcCalRecord 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 testDDSetAcidConcCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; - if ( DD_MODE_SERV == getCurrentOperationMode() ) - { - result = receiveCalRecord( message, DD_CAL_RECORD_ACID_CONCENTRATE , sizeof( DD_ACID_CONCENTRATE_T ) ); - } + result = receiveCalRecord( message, DD_CAL_RECORD_ACID_CONCENTRATE, + sizeof( DD_ACID_CONCENTRATE_T ) ); return result; } +/*********************************************************************//** + * @brief + * The testDDSetBicarbConcCalRecord 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 testDDSetBicarbConcCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; - if ( DD_MODE_SERV == getCurrentOperationMode() ) - { - result = receiveCalRecord( message, DD_CAL_RECORD_BICARB_CONCENTRATE , sizeof( DD_BICARB_CONCENTRATE_T ) ); - } + result = receiveCalRecord( message, DD_CAL_RECORD_BICARB_CONCENTRATE, + sizeof( DD_BICARB_CONCENTRATE_T ) ); return result; } +/*********************************************************************//** + * @brief + * The testDDSetAccelSensorCalRecord 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 testDDSetAccelSensorCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; - if ( DD_MODE_SERV == getCurrentOperationMode() ) - { - result = receiveCalRecord( message, DD_CAL_RECORD_ACCELEROMETER_SENSOR , sizeof( DD_ACCEL_SENSOR_CAL_RECORD_T ) ); - } + result = receiveCalRecord( message, DD_CAL_RECORD_ACCELEROMETER_SENSOR, + sizeof( DD_ACCEL_SENSOR_CAL_RECORD_T ) ); return result; } +/*********************************************************************//** + * @brief + * The testDDSetBloodLeakSensorCalRecord 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 testDDSetBloodLeakSensorCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; - if ( DD_MODE_SERV == getCurrentOperationMode() ) - { - result = receiveCalRecord( message, DD_CAL_RECORD_BLLOD_LEAK_SENSOR , sizeof( DD_BLOOD_LEAK_SENSOR_CAL_RECORD_T ) ); - } + result = receiveCalRecord( message, DD_CAL_RECORD_BLLOD_LEAK_SENSOR, + sizeof( DD_BLOOD_LEAK_SENSOR_CAL_RECORD_T ) ); return result; } - /*********************************************************************//** * @brief * The testSetNVRecordCRCOverride function overrides the CRC value of @@ -1225,6 +1598,4 @@ return result; } - - /**@}*/