Index: firmware/App/Controllers/DGInterface.c =================================================================== diff -u -re654b368ff8f4d194678db88f1cda57b04e7d947 -rb21d331f7b18cb2a1dacad78bd1049b31152f029 --- firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision e654b368ff8f4d194678db88f1cda57b04e7d947) +++ firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision b21d331f7b18cb2a1dacad78bd1049b31152f029) @@ -7,8 +7,8 @@ * * @file DGInterface.c * -* @author (last) Dara Navaei -* @date (last) 13-Jul-2022 +* @author (last) Michael Garthwaite +* @date (last) 08-Aug-2022 * * @author (original) Sean * @date (original) 08-Apr-2020 @@ -24,7 +24,7 @@ #include "ModeInitPOST.h" #include "ModeTreatment.h" #include "ModeTreatmentParams.h" -#include "OperationModes.h" +#include "OperationModes.h" #include "PersistentAlarm.h" #include "SystemComm.h" #include "SystemCommMessages.h" @@ -57,13 +57,13 @@ static const U32 DIP_RESERVOIRS_DATA_MESSAGE_ALARM_THRESHOLD = ((2 * MS_PER_SECOND) / TASK_GENERAL_INTERVAL); static const U32 DIP_DG_OP_MODE_DATA_MESSAGE_ALARM_THRESHOLD = ((2 * MS_PER_SECOND) / TASK_GENERAL_INTERVAL); -// DG status -static DG_OP_MODE_T dgCurrentOpMode = DG_MODE_INIT; ///< Current DG operation mode. -static U32 dgSubMode = 0; ///< Current state (sub-mode) of current DG operation mode. -static BOOL dgStartCommandSent = FALSE; ///< Flag indicates command to start DG has been sent. -static BOOL dgStarted = FALSE; ///< Flag indicates whether we have commanded the DG to start or stop. -static BOOL dgTrimmerHeaterOn = FALSE; ///< Flag indicates whether we have commanded the DG to start or stop the trimmer heater. - +// DG status +static DG_OP_MODE_T dgCurrentOpMode; ///< Current DG operation mode. +static U32 dgSubMode; ///< Current state (sub-mode) of current DG operation mode. +static BOOL dgStartCommandSent; ///< Flag indicates command to start DG has been sent. +static BOOL dgStarted; ///< Flag indicates whether we have commanded the DG to start or stop. +static BOOL dgTrimmerHeaterOn; ///< Flag indicates whether we have commanded the DG to start or stop the trimmer heater. + // State machine states static U32 timeStartMS = 0; // TODO is this needed? @@ -95,9 +95,9 @@ static BOOL dgReservoirsDataFreshFlag = FALSE; ///< Flag to signal the handleDGReservoirData() to process fresh reservoirs data static BOOL dgOpModeDataFreshFlag = FALSE; ///< Flag to signal the handleDGOpMode() to process fresh dg op mode data -// Reservoir data -static DG_RESERVOIR_ID_T dgActiveReservoir = DG_RESERVOIR_2; ///< Latest active reservoir reported by the DG. -static DG_RESERVOIR_ID_T dgActiveReservoirSet = DG_RESERVOIR_2; ///< Active reservoir commanded. +// Reservoir data +static DG_RESERVOIR_ID_T dgActiveReservoir; ///< Latest active reservoir reported by the DG. +static DG_RESERVOIR_ID_T dgActiveReservoirSet; ///< Active reservoir commanded. // TODO remove below variables static U32 dgReservoirFillVolumeTarget = 0; ///< Latest fill-to volume reported by the DG. @@ -107,13 +107,16 @@ static DG_DISINFECT_UI_STATES_T disinfectsStatus; ///< DG disinfects status. static DG_MIXING_RATIOS_T dgMixingRatios; ///< DG mixing ratios. +static HEATERS_DATA_T dgHeatersData; ///< DG heaters data. +static DG_SERVICE_AND_USAGE_DATA_T dgServiceAndUsageData; ///< DG service and usage data. // DG command response static DG_CMD_RESPONSE_T dgCmdResp[ NUM_OF_DG_COMMANDS ]; ///< Keep the latest DG command response for each command. // ********** private function prototypes ********** static void checkDGRestart( void ); +static void checkDGTrimmerHeaterStatus( void ); /*********************************************************************//** * @brief @@ -126,30 +129,37 @@ { U32 i, j; - dgStarted = FALSE; - dgTrimmerHeaterOn = FALSE; - dgTrimmerTempSet = 0.0; - dgDialysateTemp = 0.0; - dgActiveReservoirSet = DG_RESERVOIR_2; - dgReservoirFillVolumeTargetSet = 0; + dgStarted = FALSE; + dgTrimmerHeaterOn = FALSE; + dgTrimmerTempSet = 0.0F; + dgActiveReservoirSet = DG_RESERVOIR_2; + dgActiveReservoir = DG_RESERVOIR_2; + dgReservoirFillVolumeTargetSet = 0; dgReservoirDrainVolumeTargetSet = 0; + dgDialysateTemp = 0.0F; + dgCurrentOpMode = DG_MODE_INIT; + dgSubMode = 0; + dgStartCommandSent = FALSE; + dgDialysateFlowRateMlMin = 0.0F; + dgDialysateFlowDataFreshFlag = FALSE; // initialize load cell weights for ( i = 0; i < NUM_OF_LOAD_CELLS; i++ ) { - loadCellWeightInGrams[ i ].data = 0.0; - loadCellWeightInGrams[ i ].ovInitData = 0.0; - loadCellWeightInGrams[ i ].ovData = 0.0; - loadCellWeightInGrams[ i ].override = 0; + loadCellWeightInGrams[ i ].data = 0.0F; + loadCellWeightInGrams[ i ].ovInitData = 0.0F; + loadCellWeightInGrams[ i ].ovData = 0.0F; + loadCellWeightInGrams[ i ].override = 0; } // initialize reservoirs weights for ( i = 0; i < NUM_OF_DG_RESERVOIRS; i++ ) { - lgFilteredReservoirWeightInGrams[ i ] = 0.0; + lgFilteredReservoirWeightInGrams[ i ] = 0.0F; + for ( j = 0; j < SIZE_OF_LARGE_LOAD_CELL_AVG; j++ ) { - lgLoadCellReadings[ i ][ j ] = 0.0; - lgLoadCellBackupReadings[ i ][ j ] = 0.0; + lgLoadCellReadings[ i ][ j ] = 0.0F; + lgLoadCellBackupReadings[ i ][ j ] = 0.0F; } } @@ -161,11 +171,11 @@ dgCmdResp[ i ].rejectCode = DG_CMD_REQUEST_REJECT_REASON_NONE; } - lgLoadCellReadingsIdx = 0; - lgLoadCellReadingsTotal[ DG_RESERVOIR_1 ] = 0.0; - lgLoadCellReadingsTotal[ DG_RESERVOIR_2 ] = 0.0; - lgLoadCellBackupReadingsTotal[ DG_RESERVOIR_1 ] = 0.0; - lgLoadCellBackupReadingsTotal[ DG_RESERVOIR_2 ] = 0.0; + lgLoadCellReadingsIdx = 0; + lgLoadCellReadingsTotal[ DG_RESERVOIR_1 ] = 0.0F; + lgLoadCellReadingsTotal[ DG_RESERVOIR_2 ] = 0.0F; + lgLoadCellBackupReadingsTotal[ DG_RESERVOIR_1 ] = 0.0F; + lgLoadCellBackupReadingsTotal[ DG_RESERVOIR_2 ] = 0.0F; initPersistentAlarm( ALARM_ID_HD_DIALYSATE_TEMP_OUT_OF_HIGH_SAFETY_RANGE, DIALYSATE_TEMP_HIGH_SAFETY_TIMEOUT_MS, DIALYSATE_TEMP_HIGH_SAFETY_TIMEOUT_MS ); initPersistentAlarm( ALARM_ID_HD_DIALYSATE_TEMP_OUT_OF_LOW_SAFETY_RANGE, DIALYSATE_TEMP_LOW_SAFETY_TIMEOUT_MS, DIALYSATE_TEMP_LOW_SAFETY_TIMEOUT_MS ); @@ -222,7 +232,7 @@ void execDGInterfaceMonitor( void ) { // Trigger alarm if not receiving new load cell data message in timely manner - checkDGDataFreshness( ALARM_ID_HD_NEW_LOAD_CELL_DATA_MESSAGE_NOT_RECEIVE, &dgLoadCellDataFreshFlag ); + /*checkDGDataFreshness( ALARM_ID_HD_NEW_LOAD_CELL_DATA_MESSAGE_NOT_RECEIVE, &dgLoadCellDataFreshFlag ); // Trigger alarm if not receiving new dialysate temperature data message in timely manner checkDGDataFreshness( ALARM_ID_HD_NEW_DIALYSATE_TEMPERATURE_DATA_MESSAGE_NOT_RECEIVE, &dgDialysateTemperatureDataFreshFlag ); @@ -233,8 +243,12 @@ // Trigger alarm if not receiving new DG op mode message in timely manner checkDGDataFreshness( ALARM_ID_HD_NEW_DG_OPERATION_MODE_MESSAGE_NOT_RECEIVE, &dgOpModeDataFreshFlag ); - // Check to see if DG has restarted + // Check to see if DG has restarted*/ + checkDGRestart(); + + // Check the status of the trimmer heater + checkDGTrimmerHeaterStatus(); } /*********************************************************************//** @@ -399,6 +413,22 @@ /*********************************************************************//** * @brief + * The getReservoirWeight function gets the load cell weight of a given reservoir. + * @details Inputs: loadCellWeightInGrams[] + * @details Outputs: none + * @param resID ID of reservoir to get weight for + * @return the current weight of the given reservoir in grams + *************************************************************************/ +F32 getReservoirWeight( DG_RESERVOIR_ID_T resID ) +{ + LOAD_CELL_ID_T lc = ( DG_RESERVOIR_1 == resID ? LOAD_CELL_RESERVOIR_1_PRIMARY : LOAD_CELL_RESERVOIR_2_PRIMARY ); + F32 wt = getLoadCellWeight( lc ); + + return wt; +} + +/*********************************************************************//** + * @brief * The getReservoirBackupWeightLargeFilter function gets the backup load cell weight * of the given reservoir after large (32 sample) filter applied. * @details Inputs: lgFilteredReservoirWeightInGrams[] @@ -420,26 +450,26 @@ /*********************************************************************//** * @brief - * The getDialysateTemperature function gets the latest dialysate temperature. - * @details Inputs: dgDialysateTemp + * The getDGDisinfectsStates function returns the DG disinfects readings. + * @details Inputs: none * @details Outputs: none - * @return the current dialysate temperature + * @return the current DG disinfects readings *************************************************************************/ -F32 getDialysateTemperature( void ) +DG_DISINFECT_UI_STATES_T getDGDisinfectsStates( void ) { - return dgDialysateTemp; + return disinfectsStatus; } /*********************************************************************//** * @brief - * The getDGDisinfectsStates function returns the DG disinfects readings. - * @details Inputs: none + * The getDialysateTemperature function gets the latest dialysate temperature. + * @details Inputs: dgDialysateTemp * @details Outputs: none - * @return the current DG disinfects readings + * @return the current dialysate temperature *************************************************************************/ -DG_DISINFECT_UI_STATES_T getDGDisinfectsStates( void ) +F32 getDialysateTemperature( void ) { - return disinfectsStatus; + return dgDialysateTemp; } /*********************************************************************//** @@ -457,18 +487,17 @@ /*********************************************************************//** * @brief - * The getReservoirWeight function gets the load cell weight of a given reservoir. - * @details Inputs: loadCellWeightInGrams[] + * The getHDVersionDGServiceAndUsageData function copies the HD version of + * the DG service and usage data into the provided buffer. + * @details Inputs: dgServiceAndUsageData * @details Outputs: none - * @param resID ID of reservoir to get weight for - * @return the current weight of the given reservoir in grams + * @param data which is a pointer of type DG_SERVICE_AND_USAGE_DATA_T that + * is the provided buffer + * @return none *************************************************************************/ -F32 getReservoirWeight( DG_RESERVOIR_ID_T resID ) +void getHDVersionDGServiceAndUsageData( DG_SERVICE_AND_USAGE_DATA_T* data ) { - LOAD_CELL_ID_T lc = ( DG_RESERVOIR_1 == resID ? LOAD_CELL_RESERVOIR_1_PRIMARY : LOAD_CELL_RESERVOIR_2_PRIMARY ); - F32 wt = getLoadCellWeight( lc ); - - return wt; + memcpy( data, &dgServiceAndUsageData, sizeof( DG_SERVICE_AND_USAGE_DATA_T ) ); } /*********************************************************************//** @@ -635,11 +664,56 @@ *************************************************************************/ void setDGMixingRatios( DG_MIXING_RATIOS_T ratios ) { - memcpy( &dgMixingRatios, &ratios, sizeof(DG_MIXING_RATIOS_T) ); + memcpy( &dgMixingRatios, &ratios, sizeof( DG_MIXING_RATIOS_T ) ); } /*********************************************************************//** * @brief + * The setDGHeatersData function sets heaters data that has been read from DG. + * @details Inputs: none + * @details Outputs: dgHeatersData + * @param data which is a pointer to the received heaters data + * @return none + *************************************************************************/ +void setDGHeatersData( HEATERS_DATA_T *data ) +{ + memcpy( &dgHeatersData, data, sizeof( HEATERS_DATA_T ) ); +} + +/*********************************************************************//** + * @brief + * The setHDVersionDGServiceRecord function sets the HD version of the DG + * service record. + * @details Inputs: none + * @details Outputs: dgServiceAndUsageData + * @param data which is a pointer to the received HD version of the DG service + * record + * @return none + *************************************************************************/ +void setHDVersionDGServiceRecord( HD_VERSION_DG_SERVICE_RECORD_T* data ) +{ + dgServiceAndUsageData.isDGServiceRecordAvailable = TRUE; + memcpy( &dgServiceAndUsageData.dgServiceRecord, data, sizeof( HD_VERSION_DG_SERVICE_RECORD_T ) ); +} + +/*********************************************************************//** + * @brief + * The setHDVersionDGUsageInfo function sets the HD version of the DG + * usage information. + * @details Inputs: none + * @details Outputs: dgServiceAndUsageData + * @param data which is a pointer to the received HD version of the DG usage + * info + * @return none + *************************************************************************/ +void setHDVersionDGUsageInfo( HD_VERSION_DG_USAGE_INFO_T* data ) +{ + dgServiceAndUsageData.isDGUsageInfoAviable = TRUE; + memcpy( &dgServiceAndUsageData.dgUsageInfo, data, sizeof( HD_VERSION_DG_USAGE_INFO_T ) ); +} + +/*********************************************************************//** + * @brief * The cmdSetDGDialysateHeatingParams function sends the dialysate heating * parameters to DG. * @details Inputs: none @@ -942,6 +1016,19 @@ /*********************************************************************//** * @brief + * The cmdSetDGToServiceMode function sends a request to DG to transition + * to service mode. + * @details Inputs: none + * @details Outputs: none + * @return none + *************************************************************************/ +void cmdSetDGToServiceMode( void ) +{ + sendDGServiceModeRequest(); +} + +/*********************************************************************//** + * @brief * The handleDGCommandResponse function processes the latest DG command response. * @details Inputs: none * @details Outputs: process command response from DG @@ -1007,43 +1094,29 @@ * @brief * The checkDialysateTemperature function checks the dialysate temperature * reported by DG and alarm if temperature is out of range. - * @details Inputs: dgTrimmerTempSet, dgDialysateTemp, dgRedundantDialysateTemp - * @details Outputs: alarm if dialysate temperature is out of accepted range + * @details Inputs: dgTrimmerTempSet, dgDialysateTemp + * @details Outputs: none * @return none *************************************************************************/ void checkDialysateTemperature( void ) { - BOOL const dialysateHighTemp = ( ( ( dgDialysateTemp - dgTrimmerTempSet ) > DIALYSATE_TEMP_TOLERANCE_C ) || - ( dgDialysateTemp > DIALYSATE_TEMP_HIGH_LIMIT_C ) ); + BOOL isTDiTempAboveHighSafety = ( dgDialysateTemp >= DIALYSATE_TEMP_HIGH_SAFETY_LIMIT_C ? TRUE : FALSE ); + BOOL isTDiTempAboveLowSafety = ( dgDialysateTemp >= DIALYSATE_TEMP_LOW_SAFETY_LIMIT_C ? TRUE : FALSE ); + F32 TDiHigh = dgTrimmerTempSet + DIALYSATE_TEMP_OUT_OF_TARGET_TOL_C; + BOOL isTDiTempAboveDialysateTarget = ( TDiHigh >= dgDialysateTemp ? TRUE : FALSE ); + F32 TDiLow = dgTrimmerTempSet - DIALYSATE_TEMP_OUT_OF_TARGET_TOL_C; + BOOL isTDiTempBelowDialysateTarget = ( TDiLow >= dgDialysateTemp ? TRUE : FALSE ); - BOOL const dialysateLowTemp = ( ( ( dgTrimmerTempSet - dgDialysateTemp ) > DIALYSATE_TEMP_TOLERANCE_C ) || - ( dgDialysateTemp < DIALYSATE_TEMP_LOW_LIMIT_C ) ); - - BOOL const dialysateTempRecovered = fabs( dgDialysateTemp - dgTrimmerTempSet ) < DIALYSATE_TEMP_RECOVERY_TOLERANCE_C ? TRUE : FALSE; - #ifndef _RELEASE_ if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_DIALYSATE_TEMP_CHECK ) != SW_CONFIG_ENABLE_VALUE ) #endif { - if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_DIALYSATE_TEMPERATURE_HIGH, dialysateHighTemp ) ) - { - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DIALYSATE_TEMPERATURE_HIGH, dgTrimmerTempSet, dgDialysateTemp ); - } + // Per PRS 377, PRS 124 + checkPersistentAlarm( ALARM_ID_HD_DIALYSATE_TEMP_OUT_OF_HIGH_SAFETY_RANGE, isTDiTempAboveHighSafety, dgDialysateTemp, DIALYSATE_TEMP_HIGH_SAFETY_LIMIT_C ); + checkPersistentAlarm( ALARM_ID_HD_DIALYSATE_TEMP_OUT_OF_LOW_SAFETY_RANGE, isTDiTempAboveLowSafety, dgDialysateTemp, DIALYSATE_TEMP_LOW_SAFETY_LIMIT_C ); - if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_DIALYSATE_TEMPERATURE_LOW, dialysateLowTemp ) ) - { - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DIALYSATE_TEMPERATURE_LOW, dgTrimmerTempSet, dgDialysateTemp ); - } - - if ( TRUE == isPersistentAlarmConditionCleared( ALARM_ID_DIALYSATE_TEMPERATURE_HIGH, dialysateHighTemp ) ) - { - clearAlarmCondition( ALARM_ID_DIALYSATE_TEMPERATURE_HIGH ); - } - - if ( TRUE == isPersistentAlarmConditionCleared( ALARM_ID_DIALYSATE_TEMPERATURE_LOW, dialysateTempRecovered ) ) - { - clearAlarmCondition( ALARM_ID_DIALYSATE_TEMPERATURE_LOW ); - } + checkPersistentAlarm( ALARM_ID_HD_DIALYSATE_TEMP_ABOVE_TARGET_TEMP, isTDiTempAboveDialysateTarget, dgDialysateTemp, TDiHigh ); + checkPersistentAlarm( ALARM_ID_HD_DIALYSATE_TEMP_BELOW_TARGET_TEMP, isTDiTempBelowDialysateTarget, dgDialysateTemp, TDiLow ); } } @@ -1075,7 +1148,29 @@ } } +/*********************************************************************//** + * @brief + * The checkDGTrimmerHeaterStatus function checks to see the status of the + * trimmer heater and set them according to the status of the trimmer heater flag. + * @details Inputs: dgTrimmerHeaterOn + * @details Outputs: none + * @return none + *************************************************************************/ +static void checkDGTrimmerHeaterStatus( void ) +{ + U32 trimmerState = dgHeatersData.trimmerHeaterState; + if ( ( TRUE == dgTrimmerHeaterOn ) && ( HEATER_EXEC_STATE_OFF == trimmerState ) ) + { + cmdStartDGTrimmerHeater(); + } + else if ( ( FALSE == dgTrimmerHeaterOn ) && ( trimmerState != HEATER_EXEC_STATE_OFF ) ) + { + cmdStopDGTrimmerHeater(); + } +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ Index: firmware/App/Modes/Prime.c =================================================================== diff -u -re654b368ff8f4d194678db88f1cda57b04e7d947 -rb21d331f7b18cb2a1dacad78bd1049b31152f029 --- firmware/App/Modes/Prime.c (.../Prime.c) (revision e654b368ff8f4d194678db88f1cda57b04e7d947) +++ firmware/App/Modes/Prime.c (.../Prime.c) (revision b21d331f7b18cb2a1dacad78bd1049b31152f029) @@ -8,7 +8,7 @@ * @file Prime.c * * @author (last) Michael Garthwaite -* @date (last) 21-Apr-2022 +* @date (last) 26-Aug-2022 * * @author (original) Quang Nguyen * @date (original) 08-Dec-2020 @@ -38,7 +38,7 @@ #define MAX_PRIME_TIME ( 15 * SEC_PER_MIN ) ///< Maximum prime time (in seconds). #define PRIME_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the prime data is published on the CAN bus. -#define BLOOD_PUMP_FAST_FLOW_RATE_PURGE_AIR_ML_MIN 150 ///< Blood pump fast flow rate to fill fluid. +#define BLOOD_PUMP_FAST_FLOW_RATE_PURGE_AIR_ML_MIN 300 ///< Blood pump fast flow rate to fill fluid. #define BLOOD_PUMP_SLOW_FLOW_RATE_PURGE_AIR_ML_MIN 150 ///< Blood pump slow flow rate after fluid reach lower level of air trap sensor. #define BLOOD_PUMP_SALINE_FLOW_RATE_PURGE_AIR_ML_MIN 200 ///< Blood pump very slow flow rate during prime saline dialyzer state #define BLOOD_PUMP_FLOW_RATE_CIRC_BLOOD_CIRCUIT_ML_MIN 150 ///< Blood pump flow rate during prime recirculate blood circuit state. @@ -50,8 +50,8 @@ #define DIALYZER_DVI_PATH_VOLUME_ML 17 ///< Path volume from the dialyzer to the VDI valve in mL. #define DIALYZER_VOLUME_SCALE_FACTOR 0.5F ///< Half of the dialyzer total volume. -#define NO_AIR_DETECTED_COUNT ( 20 * MS_PER_SECOND ) ///< No air detected time period count. -#define PURGE_AIR_TIME_OUT_COUNT ( 60 * MS_PER_SECOND ) ///< Time period count for purge air time out. +#define NO_AIR_DETECTED_COUNT ( 40 * MS_PER_SECOND ) ///< No air detected time period count. +#define PURGE_AIR_TIME_OUT_COUNT ( 120 * MS_PER_SECOND ) ///< Time period count for purge air time out. #define PRIME_SALINE_DIALYZER_TIME_OUT_COUNT ( 60 * MS_PER_SECOND ) ///< Time period count for prime saline dialyzer time out. #define LOAD_CELL_STEADY_VOLUME_SAMPLING_TIME ( 1 * MS_PER_SECOND ) ///< Time load cell reading steady state detection sampling time in seconds. #define PRIME_DIALYSATE_BYPASS_TIME_LIMIT ( 15 * MS_PER_SECOND ) ///< Time limit for priming dialysate bypass circuit. @@ -102,6 +102,7 @@ static BOOL primeStartRequested; ///< Flag indicates user requesting to start prime. static BOOL primeResumeRequested; ///< Flag indicates user requesting prime resume. +static BOOL primeFirstPurgePass; ///< Flag indicates to transition to a faster purge speed. static U32 noAirDetectedStartTime; ///< starting time when detecting no air. static U32 purgeAirTimeOutStartTime; ///< Starting time for purge air state time out. @@ -162,6 +163,7 @@ void transitionToPrime( void ) { primeStartTime = getMSTimerCount(); + primeFirstPurgePass = TRUE; setAlarmUserActionEnabled( ALARM_USER_ACTION_RESUME, TRUE ); setAlarmUserActionEnabled( ALARM_USER_ACTION_RINSEBACK, FALSE ); @@ -427,7 +429,14 @@ signalDialOutPumpHardStop(); signalDialInPumpHardStop(); - setBloodPumpTargetFlowRate( BLOOD_PUMP_FAST_FLOW_RATE_PURGE_AIR_ML_MIN, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); + if (FALSE == primeFirstPurgePass ) + { + setBloodPumpTargetFlowRate( BLOOD_PUMP_FAST_FLOW_RATE_PURGE_AIR_ML_MIN, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); + } + else + { + setBloodPumpTargetFlowRate( BLOOD_PUMP_SLOW_FLOW_RATE_PURGE_AIR_ML_MIN, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); + } } /*********************************************************************//** @@ -547,7 +556,12 @@ { purgeAirValvesBloodPumpControl(); purgeAirTimeOutStartTime = getMSTimerCount(); + if ( TRUE == primeFirstPurgePass ) + { + primeFirstPurgePass = FALSE; + } state = HD_PRIME_SALINE_PURGE_AIR_STATE; + } if ( TRUE == didTimeout( noAirDetectedStartTime, NO_AIR_DETECTED_COUNT ) ) @@ -592,7 +606,7 @@ setValveAirTrap( STATE_CLOSED ); signalBloodPumpHardStop(); - setDialInPumpTargetFlowRate( DIALYSATE_PUMP_PRIME_FLOW_RATE_ML_MIN, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); + setDialInPumpTargetFlowRate( DIALYSATE_PUMP_PRIME_FLOW_RATE_ML_MIN, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP, 0.0F ); setDialOutPumpTargetRate( DIALYSATE_PUMP_PRIME_FLOW_RATE_ML_MIN, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); // Calculate the time out value that must passed prior to checking for the steady state volume in the reservoir @@ -765,7 +779,7 @@ if ( TRUE == hasDGCompletedReservoirSwitch() ) { signalBloodPumpHardStop(); - setDialInPumpTargetFlowRate( DIALYSATE_PUMP_PRIME_FLOW_RATE_ML_MIN, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); + setDialInPumpTargetFlowRate( DIALYSATE_PUMP_PRIME_FLOW_RATE_ML_MIN, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP, 0.0F ); setValvePosition( VDI, VALVE_POSITION_C_CLOSE ); setValvePosition( VDO, VALVE_POSITION_C_CLOSE ); Index: firmware/App/Services/SystemComm.c =================================================================== diff -u -raf84c85045369aed91711afea71360280fd54c94 -rb21d331f7b18cb2a1dacad78bd1049b31152f029 --- firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision af84c85045369aed91711afea71360280fd54c94) +++ firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision b21d331f7b18cb2a1dacad78bd1049b31152f029) @@ -7,8 +7,8 @@ * * @file SystemComm.c * -* @author (last) Dara Navaei -* @date (last) 14-Jun-2022 +* @author (last) Michael Garthwaite +* @date (last) 07-Sep-2022 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -46,15 +46,14 @@ #define MAX_XMIT_RETRIES 5 ///< Maximum number of retries on no transmit complete interrupt timeout #define UI_COMM_TIMEOUT_IN_MS 5000 ///< UI has not checked in for this much time -#define DG_COMM_TIMEOUT_IN_MS 2000 ///< DG has not checked in for this much time +#define DG_COMM_TIMEOUT_IN_MS 1000 ///< DG has not checked in for this much time #define MAX_COMM_CRC_FAILURES 5 ///< Maximum number of CRC errors within window period before alarm #define MAX_COMM_CRC_FAILURE_WINDOW_MS (10 * SEC_PER_MIN * MS_PER_SECOND) ///< CRC error window #define MSG_NOT_ACKED_TIMEOUT_MS 150 ///< Maximum time for a Denali message that requires ACK to be ACK'd -#define MSG_NOT_ACKED_TIMEOUT_MS_INIT 5000 ///< Maximum time for a Denali message that requires ACK to be ACK'd on the INIT state for the first (UI version request) message of the POST -#define MSG_NOT_ACKED_MAX_RETRIES 3 ///< Maximum number of times a message that requires ACK that was not ACK'd can be re-sent before alarm +#define MSG_NOT_ACKED_MAX_RETRIES 20 ///< Maximum number of times a message that requires ACK that was not ACK'd can be re-sent before alarm #define PENDING_ACK_LIST_SIZE 25 ///< Maximum number of Denali messages that can be pending ACK at any given time #define MAX_FPGA_CLOCK_SPEED_ERRORS 3 ///< maximum number of FPGA clock speed errors within window period before alarm @@ -114,10 +113,6 @@ static U32 timeOfLastUICheckIn = 0; ///< Last time UI checked in static volatile BOOL uiDidCommunicate = FALSE; ///< Has UI every sent a message -#ifdef EMC_TEST_BUILD - static U32 badCANCount; // Test code in support of EMC testing -#endif - // ********** private function prototypes ********** static void clearCANXmitBuffers( void ); @@ -233,12 +228,16 @@ /*********************************************************************//** * @brief * The uiCommunicated function determines whether the UI has communicated. - * @details Inputs: uiDidCommunicate + * @details Inputs: none * @details Outputs: none * @return TRUE if UI has communicated since power up, FALSE if not *************************************************************************/ BOOL uiCommunicated( void ) -{ +{ +#ifdef SIMULATE_UI + uiDidCommunicate = TRUE; +#endif + return uiDidCommunicate; } @@ -532,8 +531,9 @@ * @brief * The processIncomingData function parses out messages from the Input * Comm Buffers and adds them to the Received Message Queue. - * @details Inputs: Input Comm Buffers - * @details Outputs: Parsed message(s) added to Received Message Queue + * @details Inputs: none + * @details Outputs:hdIsOnlyCANNode, rcvMsg, dgIsCommunicating, + * timeOfLastDGCheckIn * @return none *************************************************************************/ static void processIncomingData( void ) @@ -578,8 +578,8 @@ // Blank the new message record blankMessageInWrapper( &rcvMsg ); // Copy message header portion of message data to the new message - memcpy( &(rcvMsg.msg.hdr), dataPtr, sizeof(MESSAGE_HEADER_T) ); - dataPtr += sizeof(MESSAGE_HEADER_T); + memcpy( &(rcvMsg.msg.hdr), dataPtr, sizeof( MESSAGE_HEADER_T ) ); + dataPtr += sizeof( MESSAGE_HEADER_T ); // Copy message payload portion of message data to the new message memcpy( &(rcvMsg.msg.payload), dataPtr, rcvMsg.msg.hdr.payloadLen ); dataPtr += rcvMsg.msg.hdr.payloadLen; @@ -597,10 +597,6 @@ else if ( -1 == msgSize ) // Candidate message with bad CRC found? { badCRCDetected = TRUE; -#ifdef EMC_TEST_BUILD - badCANCount++; - broadcastCANErrorCount( badCANCount ); -#endif getFromCommBuffer( MSG_IN_BUFFERS[ i ], data, 1 ); // Consume sync byte so we can re-sync messagesInBuffer = TRUE; // Keep processing this buffer } // Looks like there is a complete message in the comm buffer @@ -735,10 +731,6 @@ } else // CRC failed { -#ifdef EMC_TEST_BUILD - badCANCount++; - broadcastCANErrorCount( badCANCount ); -#endif checkTooManyBadMsgCRCs(); } } @@ -756,7 +748,9 @@ static void checkForCommTimeouts( void ) { if ( TRUE == uiDidCommunicate ) - { + { + HD_OP_MODE_T opMode = getCurrentOperationMode(); + if ( TRUE == didTimeout( timeOfLastUICheckIn, UI_COMM_TIMEOUT_IN_MS ) ) { #ifndef _RELEASE_ @@ -767,13 +761,21 @@ } } - if ( TRUE == didTimeout( timeOfLastDGCheckIn, DG_COMM_TIMEOUT_IN_MS ) ) + // Only alarm on DG comm loss while in the treatment workflow + if ( MODE_PRET == opMode || MODE_TREA == opMode || MODE_POST == opMode ) { + if ( TRUE == didTimeout( timeOfLastDGCheckIn, DG_COMM_TIMEOUT_IN_MS ) ) + { #ifndef RUN_WITHOUT_DG - activateAlarmNoData( ALARM_ID_DG_COMM_TIMEOUT ); - dgIsCommunicating = FALSE; + activateAlarmNoData( ALARM_ID_DG_COMM_TIMEOUT ); + dgIsCommunicating = FALSE; #endif + } } + else // Otherwise clear the alarm + { + clearAlarm( ALARM_ID_DG_COMM_TIMEOUT ); + } } } @@ -884,13 +886,7 @@ // Find expired messages pending ACK for ( i = 0; i < PENDING_ACK_LIST_SIZE; i++ ) { // Pending ACK expired? - U32 timeoutPeriod = MSG_NOT_ACKED_TIMEOUT_MS; // set the timeout as default - - if ( MODE_INIT == getCurrentOperationMode() ) - { // change it to longer timeout if the HD is in INIT state - timeoutPeriod = MSG_NOT_ACKED_TIMEOUT_MS_INIT; - } - if ( ( TRUE == pendingAckList[ i ].used ) && ( TRUE == didTimeout( pendingAckList[ i ].timeStamp, timeoutPeriod ) ) ) + if ( ( TRUE == pendingAckList[ i ].used ) && ( TRUE == didTimeout( pendingAckList[ i ].timeStamp, MSG_NOT_ACKED_TIMEOUT_MS ) ) ) { // If retries left, reset and resend pending message if ( pendingAckList[ i ].retries > 0 ) { // Re-queue message for transmit @@ -985,13 +981,17 @@ case MSG_ID_DG_VERSION: handleDGVersionResponse( message ); + break; + + case MSG_ID_DG_HEATERS_DATA: + handleDGHeatersData( message ); break; case MSG_ID_DG_TEMPERATURE_DATA: handleDGTemperatureData( message ); break; - case MSG_ID_DG_DIALYSATE_FLOW_METER_DATA: + case MSG_ID_DG_FLOW_SENSORS_DATA: handleDialysateFlowData( message ); break; @@ -1151,12 +1151,19 @@ handleUIServiceModeRequest( message ); break; + case MSG_ID_DG_SERVICE_SCHEDULE_DATA: + handleDGServiceScheduleData( message ); + break; + + case MSG_ID_DG_USAGE_DATA: + handleDGUsageInfoData( message ); + break; + // NOTE: this always must be the last case case MSG_ID_TESTER_LOGIN_REQUEST: handleTesterLogInRequest( message ); break; - // The default cannot be reached in VectorCAST since the cases are run in a for loop default: // Un-recognized or un-handled message ID received - ignore break; @@ -1621,10 +1628,6 @@ handleTestSyringePumpHeprinBolusTargetRateOverrideRequest( message ); break; - case MSG_ID_HD_REQ_CURRENT_TREATMENT_PARAMETERS: - handleTestCurrentTreamtmentParametersRequest( message ); - break; - case MSG_ID_HD_FANS_DUTY_CYCLE_OVERRIDE: handleSetFansDutyCycleOverrideRequest( message ); break; @@ -1657,10 +1660,23 @@ handleSetBloodLeakEmbeddedModeCommand( message ); break; - case MSG_ID_HD_SEND_ALARMS_COMMAND: - handleResendAllAlarmsCommand( message ); + case MSG_ID_HD_REQ_CURRENT_TREATMENT_PARAMETERS: + handleTestCurrentTreamtmentParametersRequest( message ); break; + case MSG_ID_HD_BLOOD_PUMP_SET_PWM: + handleTestBloodPumpSetPWM( message ); + break; + + case MSG_ID_HD_DIAL_IN_SET_PWM: + handleTestDialInSetPWM( message ); + break; + + case MSG_ID_HD_DIAL_OUT_SET_PWM: + handleTestDialOutSetPWM( message ); + break; + + // The default cannot be reached in VectorCAST since the cases are run in a for loop default: // Unrecognized message ID received - ignore Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -re654b368ff8f4d194678db88f1cda57b04e7d947 -rb21d331f7b18cb2a1dacad78bd1049b31152f029 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision e654b368ff8f4d194678db88f1cda57b04e7d947) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision b21d331f7b18cb2a1dacad78bd1049b31152f029) @@ -7,8 +7,8 @@ * * @file SystemCommMessages.c * -* @author (last) Dara Navaei -* @date (last) 14-Jun-2022 +* @author (last) Darren Cox +* @date (last) 13-Sep-2022 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -28,6 +28,7 @@ #include "Fans.h" #include "FPGA.h" #include "ModeStandby.h" +#include "ModeInitPOST.h" #include "OperationModes.h" #include "RTC.h" #include "SampleWater.h" @@ -889,24 +890,26 @@ /*********************************************************************//** * @brief - * The handleSetHDStandbyDisinfectSubmode function handles setting the + * The handleSetHDStandbyDisinfectSubmodeRequest function handles setting the * standby submode to wait for disisnfect state. - * @details Inputs: none + * @details Inputs: 1=initiate, 0=cancel * @details Outputs: message handled * @param message a pointer to the message to handle * @return none *************************************************************************/ void handleSetHDStandbyDisinfectSubmodeRequest( MESSAGE_T *message ) { - BOOL result = FALSE; + U32 cmd; - // The payload should be 0 in this case because there is mode in this command - if ( 0 == message->hdr.payloadLen ) + if ( sizeof( U32 ) == message->hdr.payloadLen ) { - signalInitiateStandbyDisinfectSubmode(); + memcpy( &cmd, &message->payload[0], sizeof( U32 ) ); + signalInitiateStandbyDisinfectSubmode( cmd ); } - - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, result ); + else + { + handleSetHDStandbyDisinfectSubmodeResponse( FALSE, REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT ); + } } /*********************************************************************//** @@ -2000,35 +2003,6 @@ } -#ifdef EMC_TEST_BUILD -/*********************************************************************//** - * @brief - * The broadcastCANErrorCount function handles the CAN error count - * @details Inputs: none - * @details Outputs: message handled - * @param message a pointer to the message to handle - * @return none - *************************************************************************/ -BOOL broadcastCANErrorCount( U32 count ) -{ - BOOL result; - MESSAGE_T msg; - U08 *payloadPtr = msg.payload; - - // Create a message record - blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_CAN_ERROR_COUNT; - msg.hdr.payloadLen = sizeof( U32 ); - - memcpy( payloadPtr, &count, sizeof( U32 ) ); - - // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer - result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_BROADCAST, ACK_NOT_REQUIRED ); - - return result; -} -#endif - // *********************************************************************** // **************** Message Handling Helper Functions ******************** // *********************************************************************** @@ -2267,7 +2241,6 @@ { BOOL result; MESSAGE_T msg; - U08 *payloadPtr = msg.payload; // Create a message record blankMessage( &msg ); @@ -2336,17 +2309,36 @@ *************************************************************************/ void handleLoadCellReadingsFromDG( MESSAGE_T *message ) { - if ( message->hdr.payloadLen == sizeof(LOAD_CELL_READINGS_PAYLOAD_T) ) + if ( message->hdr.payloadLen == sizeof( LOAD_CELL_DATA_T ) ) { - LOAD_CELL_READINGS_PAYLOAD_T payload; + LOAD_CELL_DATA_T payload; - memcpy( &payload, message->payload, sizeof(LOAD_CELL_READINGS_PAYLOAD_T) ); - setNewLoadCellReadings( payload.res1PrimaryLoadCell, payload.res1BackupLoadCell, payload.res2PrimaryLoadCell, payload.res2BackupLoadCell ); + memcpy( &payload, message->payload, sizeof( LOAD_CELL_DATA_T ) ); + setNewLoadCellReadings( payload.loadCellA1inGram, payload.loadCellA2inGram, payload.loadCellB1inGram, payload.loadCellB2inGram ); } } /*********************************************************************//** * @brief + * The handleDGHeatersData function handles the heaters data reading from DG. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleDGHeatersData( MESSAGE_T *message ) +{ + if ( message->hdr.payloadLen == sizeof( HEATERS_DATA_T ) ) + { + HEATERS_DATA_T payload; + + memcpy( &payload, message->payload, sizeof( HEATERS_DATA_T ) ); + setDGHeatersData( &payload ); + } +} + +/*********************************************************************//** + * @brief * The handleDGTemperatureData function handles a temperature readings * broadcast message from the DG. * @details Inputs: none @@ -2376,12 +2368,12 @@ *************************************************************************/ void handleDialysateFlowData( MESSAGE_T *message ) { - if ( message->hdr.payloadLen == sizeof( DIALYSATE_FLOW_METER_DATA_T ) ) + if ( message->hdr.payloadLen == sizeof( FLOW_SENSORS_DATA_T ) ) { - DIALYSATE_FLOW_METER_DATA_T payload; + FLOW_SENSORS_DATA_T payload; - memcpy( &payload, message->payload, sizeof( DIALYSATE_FLOW_METER_DATA_T ) ); - setDialysateFlowData( payload.measuredDialysateFlowRate ); + memcpy( &payload, message->payload, sizeof( FLOW_SENSORS_DATA_T ) ); + setDialysateFlowData( payload.dialysateFlowRateLPM ); } } @@ -2667,111 +2659,111 @@ return result; } -/*********************************************************************//** - * @brief - * The handleChangeUFSettingsRequest function handles a ultrafiltration - * change settings request message from the UI. - * @details Inputs: none - * @details Outputs: message handled - * @param message a pointer to the message to handle - * @return none - *************************************************************************/ -void handleChangeUFSettingsRequest( MESSAGE_T *message ) -{ - if ( message->hdr.payloadLen == sizeof(F32) ) - { - F32 uFVolume; - - memcpy( &uFVolume, message->payload, sizeof(F32) ); - - verifyUFSettingsChange( uFVolume ); - } - else - { - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); - } -} - -/*********************************************************************//** - * @brief - * The handleChangeUFSettingsConfirmation function handles a ultrafiltration - * change setting confirmation message from the UI. - * @details Inputs: none - * @details Outputs: message handled - * @param message a pointer to the message to handle - * @return none - *************************************************************************/ -void handleChangeUFSettingsConfirmation( MESSAGE_T *message ) -{ - if ( message->hdr.payloadLen == sizeof(UF_SETTINGS_CHANGE_CONFIRMATION_PAYLOAD_T) ) - { - UF_SETTINGS_CHANGE_CONFIRMATION_PAYLOAD_T payload; - - memcpy( &payload, message->payload, sizeof(UF_SETTINGS_CHANGE_CONFIRMATION_PAYLOAD_T) ); - - verifyUFSettingsConfirmation( payload.volume_mL, payload.adjustType ); - } - else - { - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); - } -} - -/*********************************************************************//** - * @brief - * The handleChangeTreatmentDurationRequest function handles a treatment - * duration setting change message from the UI. - * @details Inputs: none - * @details Outputs: message handled - * @param message a pointer to the message to handle - * @return none - *************************************************************************/ -void handleChangeTreatmentDurationRequest( MESSAGE_T *message ) -{ - if ( message->hdr.payloadLen == sizeof(U32) ) - { +/*********************************************************************//** + * @brief + * The handleChangeUFSettingsRequest function handles a ultrafiltration + * change settings request message from the UI. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleChangeUFSettingsRequest( MESSAGE_T *message ) +{ + if ( message->hdr.payloadLen == sizeof(F32) ) + { + F32 uFVolume; + + memcpy( &uFVolume, message->payload, sizeof(F32) ); + + verifyUFSettingsChange( uFVolume ); + } + else + { + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); + } +} + +/*********************************************************************//** + * @brief + * The handleChangeUFSettingsConfirmation function handles a ultrafiltration + * change setting confirmation message from the UI. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleChangeUFSettingsConfirmation( MESSAGE_T *message ) +{ + if ( message->hdr.payloadLen == sizeof(UF_SETTINGS_CHANGE_CONFIRMATION_PAYLOAD_T) ) + { + UF_SETTINGS_CHANGE_CONFIRMATION_PAYLOAD_T payload; + + memcpy( &payload, message->payload, sizeof(UF_SETTINGS_CHANGE_CONFIRMATION_PAYLOAD_T) ); + + verifyUFSettingsConfirmation( payload.volume_mL, payload.adjustType ); + } + else + { + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); + } +} + +/*********************************************************************//** + * @brief + * The handleChangeTreatmentDurationRequest function handles a treatment + * duration setting change message from the UI. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleChangeTreatmentDurationRequest( MESSAGE_T *message ) +{ + if ( message->hdr.payloadLen == sizeof(U32) ) + { U32 timeInMin; - - memcpy( &timeInMin, message->payload, sizeof(U32) ); - verifyTreatmentDurationSettingChange( timeInMin ); - } - else - { - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); - } -} -/*********************************************************************//** - * @brief - * The handleChangeBloodDialysateRateChangeRequest function handles a blood - * and dialysate rate settings change message from the UI. - * @details Inputs: none - * @details Outputs: message handled - * @param message a pointer to the message to handle - * @return none - *************************************************************************/ -void handleChangeBloodDialysateRateChangeRequest( MESSAGE_T *message ) -{ - U32 expPayloadSize = sizeof(U32) + sizeof(U32); - - if ( expPayloadSize == message->hdr.payloadLen ) - { - U32 bloodRate; - U32 dialRate; - - memcpy( &bloodRate, &message->payload[0], sizeof(U32) ); - memcpy( &dialRate, &message->payload[sizeof(U32)], sizeof(U32) ); - - verifyBloodAndDialysateRateSettingsChange( bloodRate, dialRate ); - } - else - { - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); - } + memcpy( &timeInMin, message->payload, sizeof(U32) ); + verifyTreatmentDurationSettingChange( timeInMin ); + } + else + { + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); + } } /*********************************************************************//** * @brief + * The handleChangeBloodDialysateRateChangeRequest function handles a blood + * and dialysate rate settings change message from the UI. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleChangeBloodDialysateRateChangeRequest( MESSAGE_T *message ) +{ + U32 expPayloadSize = sizeof(U32) + sizeof(U32); + + if ( expPayloadSize == message->hdr.payloadLen ) + { + U32 bloodRate; + U32 dialRate; + + memcpy( &bloodRate, &message->payload[0], sizeof(U32) ); + memcpy( &dialRate, &message->payload[sizeof(U32)], sizeof(U32) ); + + verifyBloodAndDialysateRateSettingsChange( bloodRate, dialRate ); + } + else + { + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); + } +} + +/*********************************************************************//** + * @brief * The handleChangePressureLimitsRequest function handles a pressure limits * change message from the UI. * @details Inputs: none @@ -3212,23 +3204,26 @@ { MESSAGE_T msg; HD_SERVICE_RECORD_T service; + DG_SERVICE_AND_USAGE_DATA_T dgData; getNVRecord2Driver( GET_SRV_RECORD, (U08*)&service, sizeof( HD_SERVICE_RECORD_T ), 0, ALARM_ID_NO_ALARM ); + getHDVersionDGServiceAndUsageData( &dgData ); U08 *payloadPtr = msg.payload; - if ( message->hdr.payloadLen == sizeof( U32 ) + sizeof( U32 ) ) - { - // Create a message record - blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_HD_SERVICE_SCHEDULE_DATA; - msg.hdr.payloadLen = sizeof( U32 ) + sizeof( U32 ); + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_SERVICE_SCHEDULE_DATA; + msg.hdr.payloadLen = sizeof( U32 ) + sizeof( U32 ); - // Fill message payload - memcpy( payloadPtr, &service.lastServiceEpochDate, sizeof( U32 ) ); - payloadPtr += sizeof( U32 ); - memcpy( payloadPtr, &service.serviceIntervalSeconds, sizeof( U32 ) ); - } + // Fill message payload + memcpy( payloadPtr, &service.lastServiceEpochDate, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &service.serviceIntervalSeconds, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &dgData.dgServiceRecord.lastServiceDateEpoch, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &dgData.dgServiceRecord.serviceIntervalSeconds, sizeof( U32 ) ); // 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 ); @@ -5154,6 +5149,7 @@ if ( sizeof( TEST_OVERRIDE_PAYLOAD_T ) == message->hdr.payloadLen ) { memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_PAYLOAD_T ) ); + if ( FALSE == payload.reset ) { result = testSetBatteryRemainingPercentOverride( payload.state.u32 ); @@ -7029,15 +7025,26 @@ { BOOL status = FALSE; HD_OP_MODE_T currentMode = getCurrentOperationMode(); + DG_OP_MODE_T currentDGMode = getDGOpMode(); REQUEST_REJECT_REASON_CODE_T reject; if ( 0 == message->hdr.payloadLen ) { if ( ( MODE_STAN == currentMode ) || ( MODE_FAUL == currentMode ) ) { - status = TRUE; + requestNewOperationMode( MODE_SERV ); - reject = REQUEST_REJECT_REASON_NONE; + + if ( (DG_MODE_STAN == currentDGMode) || (DG_MODE_FAUL == currentDGMode) ) + { + status = TRUE; + cmdSetDGToServiceMode(); + reject = REQUEST_REJECT_REASON_NONE; + } + else + { + reject = REQUEST_REJECT_REASON_DG_NOT_IN_STANDBY_IDLE_STATE; + } } else { @@ -7107,6 +7114,96 @@ } /*********************************************************************//** + * @brief + * The sendDGUsageInfoRequestToDG function constructs a request msg + * to the DG to request the DG usage info and queues the msg for transmit + * on the appropriate CAN channel. + * @details Inputs: none + * @details Outputs: DG usage info result request msg constructed and queued. + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL sendDGUsageInfoRequestToDG( void ) +{ + BOOL result; + MESSAGE_T msg; + + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_REQUEST_DG_USAGE_INFO; + msg.hdr.payloadLen = 0; + + // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_DG, ACK_REQUIRED ); + + return result; +} + +/*********************************************************************//** + * @brief + * The sendDGServiceRequestToDG function constructs a request msg + * to the DG to request the DG service record and queues the msg for transmit + * on the appropriate CAN channel. + * @details Inputs: none + * @details Outputs: DG usage info result request msg constructed and queued. + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL sendDGServiceRequestToDG( void ) +{ + BOOL result; + MESSAGE_T msg; + + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_REQUEST_DG_SERVICE_RECORD; + msg.hdr.payloadLen = 0; + + // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_DG, ACK_REQUIRED ); + + return result; +} + +/*********************************************************************//** + * @brief + * The handleDGServiceScheduleData function receives the HD version of the + * DG service record. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleDGServiceScheduleData( MESSAGE_T *message ) +{ + if ( message->hdr.payloadLen == sizeof( HD_VERSION_DG_SERVICE_RECORD_T ) ) + { + HD_VERSION_DG_SERVICE_RECORD_T payload; + + memcpy( &payload, message->payload, sizeof( HD_VERSION_DG_SERVICE_RECORD_T ) ); + setHDVersionDGServiceRecord( &payload ); + } +} + +/*********************************************************************//** + * @brief + * The handleDGUsageInfoData function receives the HD version of the + * DG usage info. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleDGUsageInfoData( MESSAGE_T *message ) +{ + if ( message->hdr.payloadLen == sizeof( HD_VERSION_DG_USAGE_INFO_T ) ) + { + HD_VERSION_DG_USAGE_INFO_T payload; + + memcpy( &payload, message->payload, sizeof( HD_VERSION_DG_USAGE_INFO_T ) ); + setHDVersionDGUsageInfo( &payload ); + } +} + +/*********************************************************************//** * @brief * The handleGetHDUsageInfoRecord function handles a request to get the HD * usage information record. @@ -7315,4 +7412,110 @@ sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); } +/*********************************************************************//** + * @brief + * The sendDGServiceModeRequest function constructs a service mode request msg + * to the DG and queues the msg for transmit on the appropriate CAN channel. + * @details Inputs: none + * @details Outputs: DG Service mode request msg constructed and queued. + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL sendDGServiceModeRequest() +{ + BOOL result; + MESSAGE_T msg; + + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_REQUEST_DG_SERVICE_MODE; + msg.hdr.payloadLen = 0; + + // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_DG, ACK_REQUIRED ); + + return result; +} + +/*********************************************************************//** +* @brief +* The handleTestBloodPumpSetPWM function handles a request to override +* the Blood pumps duty cycle. +* @details Inputs: none +* @details Outputs: message handled +* @param message a pointer to the message to handle +* @return none +*************************************************************************/ +void handleTestBloodPumpSetPWM( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + // verify payload length + if ( sizeof( F32 ) == message->hdr.payloadLen ) + { + F32 payLoad; + + memcpy( &payLoad, message->payload, sizeof( F32 ) ); + + result = testSetBloodPumpTargetDutyCycle( payLoad ); + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** +* @brief +* The handleTestDialInSetPWM function handles a request to override +* the Dialysate Inlet pumps duty cycle. +* @details Inputs: none +* @details Outputs: message handled +* @param message a pointer to the message to handle +* @return none +*************************************************************************/ +void handleTestDialInSetPWM( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + // verify payload length + if ( sizeof( F32 ) == message->hdr.payloadLen ) + { + F32 payLoad; + + memcpy( &payLoad, message->payload, sizeof( F32 ) ); + + result = testSetDialInPumpTargetDutyCycle( payLoad ); + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** +* @brief +* The handleTestDialOutSetPWM function handles a request to override +* the Dialysate Outlet pumps duty cycle. +* @details Inputs: none +* @details Outputs: message handled +* @param message a pointer to the message to handle +* @return none +*************************************************************************/ +void handleTestDialOutSetPWM( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + // verify payload length + if ( sizeof( F32 ) == message->hdr.payloadLen ) + { + F32 payLoad; + + memcpy( &payLoad, message->payload, sizeof( F32 ) ); + + result = testSetDialOutPumpTargetDutyCycle( payLoad ); + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + + /**@}*/ Index: firmware/App/Tasks/TaskGeneral.c =================================================================== diff -u -r7b38edee0c5d5858ac89929981f7d3a42d0f3436 -rb21d331f7b18cb2a1dacad78bd1049b31152f029 --- firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 7b38edee0c5d5858ac89929981f7d3a42d0f3436) +++ firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision b21d331f7b18cb2a1dacad78bd1049b31152f029) @@ -66,9 +66,7 @@ execSystemCommRx(); // Prevent most processing until UI has started communicating -#ifndef SIMULATE_UI if ( TRUE == uiCommunicated() ) -#endif { #ifndef BOARD_WITH_NO_HARDWARE // Monitor DG