Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -r6fcdec8a308be986e5a64b4222918e718622a19d -r1a57bf50544cb2442e050976433666c3715da472 --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 6fcdec8a308be986e5a64b4222918e718622a19d) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 1a57bf50544cb2442e050976433666c3715da472) @@ -1235,7 +1235,8 @@ // Get the flow sensors calibration record HD_FLOW_SENSORS_CAL_RECORD_T cal = getHDFlowSensorsCalibrationRecord(); - if ( DFM_SENSOR_PARAM_CORRUPT_STATUS != dfmStatus ) + // Retrieve dialysate flow sensor calibration data + if ( DFM_SENSOR_PARAM_CORRUPT_STATUS != dfmStatus ) { dialInFlowCalGain = cal.hdFlowSensors[ CAL_DATA_HD_DIALYZER_FLOW_SENSOR ].gain; dialInFlowCalOffset = cal.hdFlowSensors[ CAL_DATA_HD_DIALYZER_FLOW_SENSOR ].offset; Index: firmware/App/Controllers/PresOccl.c =================================================================== diff -u -r5d13922ee2e8c851bc5db67ef4d0120b47de6f07 -r1a57bf50544cb2442e050976433666c3715da472 --- firmware/App/Controllers/PresOccl.c (.../PresOccl.c) (revision 5d13922ee2e8c851bc5db67ef4d0120b47de6f07) +++ firmware/App/Controllers/PresOccl.c (.../PresOccl.c) (revision 1a57bf50544cb2442e050976433666c3715da472) @@ -50,15 +50,16 @@ #define VENOUS_PRESSURE_SELF_TEST_MIN ( -100.0 ) ///< Minimum self-test value for venous pressure sensor reading (in mmHg). #define VENOUS_PRESSURE_SELF_TEST_MAX ( 600.0 ) ///< Maximum self-test value for venous pressure sensor reading (in mmHg). +#define VENOUS_PRESSURE_MIN_TEMP ( 0.0 ) ///< Minimum venous pressure sensor temperature. TODO - get from Systems +#define VENOUS_PRESSURE_MAX_TEMP ( 50.0 ) ///< Maximum venous pressure sensor temperature. TODO - get from Systems + #define PSI_TO_MMHG ( 51.7149 ) ///< Conversion factor for converting PSI to mmHg. #define VENOUS_PRESSURE_NORMAL_OP 0 ///< Venous pressure status bits indicate normal operation. #define VENOUS_PRESSURE_CMD_MODE 1 ///< Venous pressure status bits indicate sensor in command mode. #define VENOUS_PRESSURE_STALE_DATA 2 ///< Venous pressure status bits indicate data is stale (no new data since last fpga read). #define VENOUS_PRESSURE_DIAG_CONDITION 3 ///< Venous pressure status bits diagnostic condition (alarm). -static const U32 MAX_TIME_BETWEEN_VENOUS_READINGS = ( 500 / TASK_GENERAL_INTERVAL ); ///< Maximum time without fresh inline venous pressure reading. - #define OCCLUSION_THRESHOLD 25000 ///< Threshold above which an occlusion is detected. #define CARTRIDGE_LOADED_THRESHOLD 5000 ///< Threshold above which a cartridge is considered loaded. @@ -101,8 +102,12 @@ static OVERRIDE_U32_T dialInPumpOcclusion = {0, 0, 0, 0 }; ///< Measured dialysate inlet pump occlusion pressure. static OVERRIDE_U32_T dialOutPumpOcclusion = {0, 0, 0, 0 }; ///< Measured dialysate outlet pump occlusion pressure. -static U32 staleVenousPressureCtr = 0; ///< Timer counter for stale venous pressure reading. static U32 emptySalineBagCtr = 0; ///< Timer counter for empty bag detection. + +static U08 lastVenousPressureReadCtr; ///< Previous venous pressure read counter. +static U08 lastBPOcclReadCtr; ///< Previous BP occlusion read counter. +static U08 lastDPiOcclReadCtr; ///< Previous DPi occlusion read counter. +static U08 lastDPoOcclReadCtr; ///< Previous DPo occlusion read counter. // ********** private function prototypes ********** @@ -130,6 +135,16 @@ initPersistentAlarm( ALARM_ID_ARTERIAL_PRESSURE_HIGH, PRES_ALARM_PERSISTENCE, PRES_ALARM_PERSISTENCE ); initPersistentAlarm( ALARM_ID_VENOUS_PRESSURE_LOW, PRES_ALARM_PERSISTENCE, PRES_ALARM_PERSISTENCE ); initPersistentAlarm( ALARM_ID_VENOUS_PRESSURE_HIGH, PRES_ALARM_PERSISTENCE, PRES_ALARM_PERSISTENCE ); + initPersistentAlarm( ALARM_ID_HD_VENOUS_PRESSURE_READ_TIMEOUT_ERROR, 0, PRES_ALARM_PERSISTENCE ); + initPersistentAlarm( ALARM_ID_HD_VENOUS_PRESSURE_SENSOR_TEMP_OUT_OF_RANGE, 0, PRES_ALARM_PERSISTENCE ); + initPersistentAlarm( ALARM_ID_HD_BP_OCCLUSION_READ_TIMEOUT_ERROR, 0, PRES_ALARM_PERSISTENCE ); + initPersistentAlarm( ALARM_ID_HD_DPI_OCCLUSON_READ_TIMEOUT_ERROR, 0, PRES_ALARM_PERSISTENCE ); + initPersistentAlarm( ALARM_ID_HD_DPO_OCCLUSION_READ_TIMEOUT_ERROR, 0, PRES_ALARM_PERSISTENCE ); + + lastVenousPressureReadCtr = 0; + lastBPOcclReadCtr = 0; + lastDPiOcclReadCtr = 0; + lastDPoOcclReadCtr = 0; } /*********************************************************************//** @@ -286,15 +301,17 @@ { U32 fpgaArtPres = getFPGAArterialPressure(); S32 artPres = (S32)( fpgaArtPres & MASK_OFF_U32_MSB ) - 0x800000; // Subtract 2^23 from low 24 bits to get signed reading - U08 artPresAlarm = (U08)( fpgaArtPres >> 24 ); // High byte is alarm code for arterial pressure + U08 artPresAlarm = (U08)( fpgaArtPres >> SHIFT_24_BITS ); // High byte is alarm code for arterial pressure U16 fpgaVenPres = getFPGAVenousPressure(); U16 venPres = fpgaVenPres & 0x3FFF; // 14-bit data U08 venPresStatus = (U08)( fpgaVenPres >> 14 ); // High 2 bits is status code for venous pressure F32 venPresPSI; + F32 venTemp = getFPGAVenousPressureTemperature(); + U08 venReadCtr = getFPGAVenousPressureReadCounter(); // TODO - any filtering required??? - // Convert arterial pressure to mmHg if no alarm + // Convert arterial pressure to mmHg if no fault if ( 0 == artPresAlarm ) { arterialPressure.data = ARTERIAL_PRESSURE_V_PER_BIT * ( (F32)(artPres) / ( ARTERIAL_PRESSURE_SENSITIVITY * ARTERIAL_PRESSURE_V_BIAS ) ); @@ -306,31 +323,33 @@ #endif } - // Convert venous pressure to PSI + // Check for stale venous pressure reading + if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_VENOUS_PRESSURE_READ_TIMEOUT_ERROR, ( lastVenousPressureReadCtr == venReadCtr ) ) ) + { + activateAlarmNoData( ALARM_ID_HD_VENOUS_PRESSURE_READ_TIMEOUT_ERROR ); + } + // Record venous read counter for next time around + lastVenousPressureReadCtr = venReadCtr; + // Convert venous pressure to PSI and then mmHg venPresPSI = ( (F32)(venPres - VENOUS_PRESSURE_OFFSET) * (VENOUS_PRESSURE_MAX - VENOUS_PRESSURE_MIN) / (F32)VENOUS_PRESSURE_SCALE ) + VENOUS_PRESSURE_MIN; // Convert venous pressure from PSI to mmHg if sensor status is normal if ( VENOUS_PRESSURE_NORMAL_OP == venPresStatus ) { venousPressure.data = venPresPSI * PSI_TO_MMHG; - staleVenousPressureCtr = 0; } - // If venous pressure sensor status is not normal or reading is stale for too long, fault + // If venous pressure sensor status is not normal, fault else { - if ( ++staleVenousPressureCtr > MAX_TIME_BETWEEN_VENOUS_READINGS ) - { #ifndef DISABLE_PRESSURE_CHECKS - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_VENOUS_PRESSURE_SENSOR_FAULT, VENOUS_PRESSURE_STALE_DATA ) + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_VENOUS_PRESSURE_SENSOR_FAULT, (U32)venPresStatus ) // TODO - persistence? #endif - } } - // Check for venous pressure sensor alarm or in wrong (cmd) mode - if ( ( VENOUS_PRESSURE_DIAG_CONDITION == venPresStatus ) || ( VENOUS_PRESSURE_CMD_MODE == venPresStatus ) ) + // Check venous pressure sensor temperature + if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_VENOUS_PRESSURE_SENSOR_TEMP_OUT_OF_RANGE, + ( venTemp > VENOUS_PRESSURE_MAX_TEMP || venTemp < VENOUS_PRESSURE_MIN_TEMP ) ) ) { -#ifndef DISABLE_PRESSURE_CHECKS - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_VENOUS_PRESSURE_SENSOR_FAULT, (U32)venPresStatus ) -#endif + SET_ALARM_WITH_1_F32_DATA( ALARM_ID_VENOUS_PRESSURE_SENSOR_FAULT, venTemp ) } } @@ -343,10 +362,50 @@ *************************************************************************/ static void convertOcclusionPressures( void ) { - // Occlusion sensor values have no unit - take as is + U08 bpReadCtr = getFPGABloodPumpOcclusionReadCounter(); + U08 dpiReadCtr = getFPGADialInPumpOcclusionReadCounter(); + U08 dpoReadCtr = getFPGADialOutPumpOcclusionReadCounter(); + U08 bpErrorCtr = getFPGABloodPumpOcclusionErrorCounter(); + U08 dpiErrorCtr = getFPGADialInPumpOcclusionErrorCounter(); + U08 dpoErrorCtr = getFPGADialOutPumpOcclusionErrorCounter(); + + // Check for sensor errors + if ( bpErrorCtr > 0 ) + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_BP_OCCLUSION_SENSOR_ERROR, (U32)bpErrorCtr ) + } + if ( dpiErrorCtr > 0 ) + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_DPI_OCCLUSION_SENSOR_ERROR, (U32)dpiErrorCtr ) + } + if ( dpoErrorCtr > 0 ) + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_DPO_OCCLUSION_SENSOR_ERROR, (U32)dpoErrorCtr ) + } + + // Check for stale occlusion reads + if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_BP_OCCLUSION_READ_TIMEOUT_ERROR, ( bpReadCtr == lastBPOcclReadCtr ) ) ) + { + activateAlarmNoData( ALARM_ID_HD_BP_OCCLUSION_READ_TIMEOUT_ERROR ); + } + if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_BP_OCCLUSION_READ_TIMEOUT_ERROR, ( dpiReadCtr == lastDPiOcclReadCtr ) ) ) + { + activateAlarmNoData( ALARM_ID_HD_DPI_OCCLUSON_READ_TIMEOUT_ERROR ); + } + if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_BP_OCCLUSION_READ_TIMEOUT_ERROR, ( dpoReadCtr == lastDPoOcclReadCtr ) ) ) + { + activateAlarmNoData( ALARM_ID_HD_DPO_OCCLUSION_READ_TIMEOUT_ERROR ); + } + + // Record occlusion sensor readings bloodPumpOcclusion.data = (U32)getFPGABloodPumpOcclusion(); dialInPumpOcclusion.data = (U32)getFPGADialInPumpOcclusion(); dialOutPumpOcclusion.data = (U32)getFPGADialOutPumpOcclusion(); + + // Record occlusion read counters for next time around + lastBPOcclReadCtr = bpReadCtr; + lastDPiOcclReadCtr = dpiReadCtr; + lastDPoOcclReadCtr = dpoReadCtr; } /*********************************************************************//** Index: firmware/App/Services/SystemComm.c =================================================================== diff -u -r5fef605363d4f8023b3db2989b097b6c5f58db1a -r1a57bf50544cb2442e050976433666c3715da472 --- firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 5fef605363d4f8023b3db2989b097b6c5f58db1a) +++ firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 1a57bf50544cb2442e050976433666c3715da472) @@ -1261,6 +1261,18 @@ handleTreatmentEndCmd( message ); break; + case MSG_ID_UI_PATIENT_DISCONNECTION_CONFIRM: + handlePatientDisconnectionConfirmCmd( message ); + break; + + case MSG_ID_UI_DISPOSABLE_REMOVAL_CONFIRM: + handleDisposableRemovalConfirmCmd( message ); + break; + + case MSG_ID_UI_TREATMENT_LOG_DATA_REQUEST: + handleUITreatmentLogDataRequest( message ); + break; + case MSG_ID_DG_COMMAND_RESPONSE: handleDGCmdResp( message ); break; Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r5fef605363d4f8023b3db2989b097b6c5f58db1a -r1a57bf50544cb2442e050976433666c3715da472 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 5fef605363d4f8023b3db2989b097b6c5f58db1a) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 1a57bf50544cb2442e050976433666c3715da472) @@ -23,14 +23,10 @@ #include "AlarmLamp.h" #include "Buttons.h" #include "ConsumableSelfTest.h" -#include "DGInterface.h" #include "FPGA.h" -#include "ModePreTreat.h" #include "ModeStandby.h" -#include "ModeTreatment.h" #include "ModeTreatmentParams.h" #include "OperationModes.h" -#include "PresOccl.h" #include "RTC.h" #include "SampleWater.h" #include "SafetyShutdown.h" @@ -39,7 +35,6 @@ #include "TreatmentEnd.h" #include "TreatmentRecirc.h" #include "Utilities.h" -#include "Valves.h" #include "WatchdogMgmt.h" /** @@ -575,7 +570,108 @@ result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_UI, ACK_REQUIRED ); return result; +} + +/*********************************************************************//** + * @brief + * The handlePatientDisconnectionConfirmCmd function handles user confirms + * patient disconnection. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none. + *************************************************************************/ +void handlePatientDisconnectionConfirmCmd( MESSAGE_T *message ) +{ + if ( 0 == message->hdr.payloadLen ) + { + signalUserConfirmPatientDisconnection(); + } + + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); } + +/*********************************************************************//** + * @brief + * The handleDisposableRemovalConfirmCmd function handles user confirms + * disposable removal. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none. + *************************************************************************/ +void handleDisposableRemovalConfirmCmd( MESSAGE_T *message ) +{ + if ( 0 == message->hdr.payloadLen ) + { + signalUserConfirmDisposableRemoval(); + } + + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); +} + +/*********************************************************************//** + * @brief + * The sendDisposableRemovalConfirmResponse function constructs a disposable + * removal confirm user action response to the UI and queues the msg for + * transmit on the appropriate CAN channel. + * @details Inputs: none + * @details Outputs: Disposable removal confirm response msg constructed and queued. + * @param accepted T/F - was disposable removal confirm request accepted? + * @param reason reason why request was rejected (or zero if accepted) + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL sendDisposableRemovalConfirmResponse( BOOL accepted, U32 reason ) +{ + return sendUIResponseMsg( MSG_ID_HD_DISPOSABLE_REMOVAL_CONFIRM_RESPONSE, accepted, reason ); +} + +/*********************************************************************//** + * @brief + * The handleUITreatmentLogDataRequest function handles UI treatment log data request. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none. + *************************************************************************/ +void handleUITreatmentLogDataRequest( MESSAGE_T *message ) +{ + if ( 0 == message->hdr.payloadLen ) + { + handleTreatmentLogDataRequest(); + } + + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); +} + +/*********************************************************************//** + * @brief + * The sendTreatmentLogData function constructs a treatment log data message + * for UI and queues the msg for transmit on the appropriate CAN channel. + * @details Inputs: none + * @details Outputs: Treatment log data msg constructed and queued. + * @param logDataPtr treatment log data record pointer + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL sendTreatmentLogData( BOOL accepted, U32 reason, TREATMENT_LOG_DATA_PAYLOAD_T *logDataPtr ) +{ + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_TREATMENT_LOG_DATA_RESPONSE; + msg.hdr.payloadLen = sizeof( BOOL ) + sizeof( U32 ) + sizeof( TREATMENT_LOG_DATA_PAYLOAD_T ); + + memcpy( payloadPtr, &accepted, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &reason, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, logDataPtr, sizeof( TREATMENT_LOG_DATA_PAYLOAD_T ) ); + + // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + return serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_UI, ACK_REQUIRED ); +} /*********************************************************************//** * @brief @@ -1594,6 +1690,30 @@ /*********************************************************************//** * @brief + * The broadcastPostTreatmentState function constructs a post treatment state msg + * to be broadcast and queues the msg for transmit on the appropriate CAN channel. + * @details Inputs: none + * @details Outputs: post-treatment state msg constructed and queued + * @param postTreatmentSubMode post-treatment state sub-mode + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastPostTreatmentState( U32 postTreatmentSubMode ) +{ + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_POST_TREATMENT_STATE; + msg.hdr.payloadLen = sizeof( U32 ); + + memcpy( payloadPtr, &postTreatmentSubMode, sizeof( U32 ) ); + + // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + return serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_BROADCAST, ACK_NOT_REQUIRED ); +} + +/*********************************************************************//** + * @brief * The broadcastPreTreatmentState function constructs a pre-treatment state msg to * be broadcast and queues the msg for transmit on the appropriate CAN channel. * @details Inputs: none @@ -3162,7 +3282,6 @@ /*********************************************************************//** * @brief * The sendDebugDataToUI function sends debug string to the UI for logging. - * @details * @details Inputs: none * @details Outputs: Message constructed and queued for transmit * @param str Pointer to debug string Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -r5fef605363d4f8023b3db2989b097b6c5f58db1a -r1a57bf50544cb2442e050976433666c3715da472 --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 5fef605363d4f8023b3db2989b097b6c5f58db1a) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 1a57bf50544cb2442e050976433666c3715da472) @@ -18,16 +18,17 @@ #ifndef __SYSTEM_COMM_MESSAGES_H__ #define __SYSTEM_COMM_MESSAGES_H__ -#include "HDCommon.h" #include "AirTrap.h" #include "BloodFlow.h" #include "BloodPrime.h" #include "DGInterface.h" -#include "DialInFlow.h" +#include "DialInFlow.h" #include "DialOutFlow.h" -#include "Dialysis.h" +#include "Dialysis.h" #include "FluidLeak.h" -#include "Prime.h" +#include "HDCommon.h" +#include "Prime.h" +#include "ModePostTreat.h" #include "ModePreTreat.h" #include "ModeTreatment.h" #include "MsgQueues.h" @@ -235,6 +236,21 @@ // MSG_ID_HD_RECIRC_CMD_RESPONSE BOOL sendTreatmentEndCmdResponse( BOOL accepted, U32 rejReason ); +// MSG_ID_UI_PATIENT_DISCONNECTION_CONFIRM +void handlePatientDisconnectionConfirmCmd( MESSAGE_T *message ); + +// MSG_ID_UI_DISPOSABLE_REMOVAL_CONFIRM +void handleDisposableRemovalConfirmCmd( MESSAGE_T *message ); + +// MSG_ID_HD_DISPOSABLE_REMOVAL_CONFIRM_RESPONSE +BOOL sendDisposableRemovalConfirmResponse( BOOL accepted, U32 reason ); + +// MSG_ID_UI_TREATMENT_LOG_DATA_REQUEST +void handleUITreatmentLogDataRequest( MESSAGE_T *message ); + +// MSG_ID_HD_TREATMENT_LOG_DATA_RESPONSE +BOOL sendTreatmentLogData( BOOL accepted, U32 reason, TREATMENT_LOG_DATA_PAYLOAD_T *logDataPtr ); + // *********** public DG command functions ********** // MSG_ID_SET_DG_DIALYSATE_TEMP_TARGETS @@ -320,6 +336,9 @@ // MSG_ID_TREATMENT_STATE BOOL broadcastTreatmentState( TREATMENT_STATE_DATA_T payload ); +// MSG_ID_HD_POST_TREATMENT_STATE +BOOL broadcastPostTreatmentState( U32 postTreatmentSubMode ); + // MSG_ID_PRE_TREATMENT_STATE BOOL broadcastPreTreatmentState( PRE_TREATMENT_STATE_DATA_T *preTreatmentDataPtr );