Index: firmware/App/Modes/ModeTreatmentParams.c =================================================================== diff -u -r2df21d2472a8d79d78af7e359518acf3614accc5 -rde533ac3aec99c9f4807570a87f1011036fa4e6e --- firmware/App/Modes/ModeTreatmentParams.c (.../ModeTreatmentParams.c) (revision 2df21d2472a8d79d78af7e359518acf3614accc5) +++ firmware/App/Modes/ModeTreatmentParams.c (.../ModeTreatmentParams.c) (revision de533ac3aec99c9f4807570a87f1011036fa4e6e) @@ -1,103 +1,778 @@ /************************************************************************** - * - * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. - * - * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN - * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. - * - * @file ModeOpParams.c - * - * @date 19-Sep-2019 - * @author S. Nash - * - * @brief Top-level state machine for the operating parameters mode. - * - **************************************************************************/ +* +* Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file ModeTreatmentParams.c +* +* @author (last) Sean Nash +* @date (last) 10-Sep-2020 +* +* @author (original) Sean Nash +* @date (original) 29-May-2020 +* +***************************************************************************/ +#include // for memcpy() + #include "AlarmLamp.h" #include "BloodFlow.h" +#include "Buttons.h" #include "DialInFlow.h" #include "DialOutFlow.h" -#include "Buttons.h" +#include "ModeTreatmentParams.h" #include "OperationModes.h" +#include "SystemCommMessages.h" #ifdef RM46_EVAL_BOARD_TARGET #include "Timers.h" static U32 start; #endif - /** - * @addtogroup HDTreatmentParamsMode - * @{ - */ +/** + * @addtogroup HDTreatmentParamsMode + * @{ + */ +// ********** private definitions ********** + +#define MAX_DIALYSATE_VOLUME_ML ( 150 * ML_PER_LITER ) ///< Maximum dialysate volume (in mL) +#define MIN_PRESSURE_ALARM_LIMIT_DELTA_MMHG ( 25 ) ///< Minimum pressure alarm limit delta (in mmHg) + +/// Record for range and default of treatment parameters. +typedef struct +{ + CRITICAL_DATA_TYPES_T dataType; ///< Data type for the treatment parameter + CRITICAL_DATAS_T min; ///< minimum of range + CRITICAL_DATAS_T max; ///< maximum of range + CRITICAL_DATAS_T def; ///< default value +} TREATMENT_PARAMS_PROPERTIES_T; + // ********** private data ********** +static HD_TREATMENT_PARAMS_MODE_STATE_T currentTreatmentParamsState; ///< Current state of treatment parameters mode state machine. + +/// Treatment parameter properties (types, ranges and defaults). +const TREATMENT_PARAMS_PROPERTIES_T treatParamsProperties[ NUM_OF_TREATMENT_PARAMS ] = +{ + { CRITICAL_DATA_TYPE_U32, {.uInt=100}, {.uInt=500}, {.uInt=100} }, // TREATMENT_PARAM_BLOOD_FLOW + { CRITICAL_DATA_TYPE_U32, {.uInt=100}, {.uInt=600}, {.uInt=100} }, // TREATMENT_PARAM_DIALYSATE_FLOW + { CRITICAL_DATA_TYPE_U32, {.uInt=60}, {.uInt=480}, {.uInt=240} }, // TREATMENT_PARAM_TREATMENT_DURATION + { CRITICAL_DATA_TYPE_U32, {.uInt=0}, {.uInt=480}, {.uInt=0} }, // TREATMENT_PARAM_HEPARIN_PRE_STOP_TIME + { CRITICAL_DATA_TYPE_U32, {.uInt=100}, {.uInt=300}, {.uInt=100} }, // TREATMENT_PARAM_SALINE_BOLUS_VOLUME + { CRITICAL_DATA_TYPE_U32, {.uInt=0}, {.uInt=2}, {.uInt=0} }, // TREATMENT_PARAM_ACID_CONCENTRATE + { CRITICAL_DATA_TYPE_U32, {.uInt=0}, {.uInt=0}, {.uInt=0} }, // TREATMENT_PARAM_BICARB_CONCENTRATE + { CRITICAL_DATA_TYPE_U32, {.uInt=0}, {.uInt=3}, {.uInt=0} }, // TREATMENT_PARAM_DIALYZER_TYPE + { CRITICAL_DATA_TYPE_U32, {.uInt=0}, {.uInt=60}, {.uInt=30} }, // TREATMENT_PARAM_BP_MEAS_INTERVAL + { CRITICAL_DATA_TYPE_U32, {.uInt=50}, {.uInt=150}, {.uInt=75} }, // TREATMENT_PARAM_RINSEBACK_FLOW_RATE + { CRITICAL_DATA_TYPE_S32, {.sInt=-300}, {.sInt=200}, {.sInt=-300} }, // TREATMENT_PARAM_ART_PRESSURE_LOW_LIMIT + { CRITICAL_DATA_TYPE_S32, {.sInt=-300}, {.sInt=200}, {.sInt=100} }, // TREATMENT_PARAM_ART_PRESSURE_HIGH_LIMIT + { CRITICAL_DATA_TYPE_S32, {.sInt=-100}, {.sInt=600}, {.sInt=-100} }, // TREATMENT_PARAM_VEN_PRESSURE_LOW_LIMIT + { CRITICAL_DATA_TYPE_S32, {.sInt=100}, {.sInt=600}, {.sInt=400} }, // TREATMENT_PARAM_VEN_PRESSURE_HIGH_LIMIT + { CRITICAL_DATA_TYPE_F32, {.sFlt=0.0}, {.sFlt=1.0}, {.sFlt=0.0} }, // TREATMENT_PARAM_HEPARIN_DISPENSE_RATE + { CRITICAL_DATA_TYPE_F32, {.sFlt=0.0}, {.sFlt=2.0}, {.sFlt=0.0} }, // TREATMENT_PARAM_HEPARIN_BOLUS_VOLUME + { CRITICAL_DATA_TYPE_F32, {.sFlt=35.0}, {.sFlt=38.0}, {.sFlt=37.0} }, // TREATMENT_PARAM_DIALYSATE_TEMPERATURE + { CRITICAL_DATA_TYPE_F32, {.sFlt=0.0}, {.sFlt=8.0}, {.sFlt=0.0} }, // TREATMENT_PARAM_UF_VOLUME +}; + +// current treatment parameter values +static CRITICAL_DATA_T treatmentParameters[ NUM_OF_TREATMENT_PARAMS ]; ///< Treatment parameters. +static CRITICAL_DATAS_T stagedParams[ NUM_OF_TREATMENT_PARAMS ]; ///< Temporary staged treatment parameters for validation and awaiting user confirmation. + +// original treatment parameter values (for those that can be changed during treatment) +static ADJ_TREATMENT_PARAMS_T origTreatmentParams; ///< Originally set (before treatment) treatment parameters. + +static BOOL validTreatParamsReceived = FALSE; ///< Flag indicates user has provided treatment parameters. +static BOOL treatParamsConfirmed = FALSE; ///< Flag indicates user has confirmed the treatment parameters. +static BOOL treatmentCancelled = FALSE; ///< Flag indicates user has cancelled the treatment. + // ********** private function prototypes ********** -/************************************************************************* - * @brief initOpParamsMode +static void resetAllTreatmentParameters( void ); +static HD_TREATMENT_PARAMS_MODE_STATE_T handleWaitForUI2SendState( void ); +static HD_TREATMENT_PARAMS_MODE_STATE_T handleWaitForUI2ConfirmState( void ); +static BOOL checkTreatmentParamsInRange( U32 *reasons ); +static BOOL checkTreatmentParamsDependencies( U32 *reasons ); +static BOOL isTreatmentParamInRange( TREATMENT_PARAM_T param, CRITICAL_DATAS_T value ); +static void extractTreatmentParamsFromPayload( TREATMENT_PARAMS_DATA_PAYLOAD_T payload ); +static void sendTreatmentParamsResponse( BOOL valid, U32 *reasons ); + +/*********************************************************************//** + * @brief * The initOpParamsMode function initializes the Operating Parameters Mode module. * @details * Inputs : none * Outputs : Operating Parameters Mode module initialized. - * @param none * @return none *************************************************************************/ void initTreatParamsMode( void ) { + currentTreatmentParamsState = HD_TREATMENT_PARAMS_MODE_STATE_START; } -/************************************************************************* - * @brief transitionToOpParamsMode - * The transitionToOpParamsMode function prepares for transition to operating \n +/*********************************************************************//** + * @brief + * The transitionToOpParamsMode function prepares for transition to operating * parameters mode. * @details * Inputs : none - * Outputs : - * @param none + * Outputs : Treatment Parameters mode reset prior to starting * @return none *************************************************************************/ void transitionToTreatParamsMode( void ) { + // reset this mode + initTreatParamsMode(); + + // reset all treatment parameters when transitioning to this mode + resetAllTreatmentParameters(); + + validTreatParamsReceived = FALSE; + treatParamsConfirmed = FALSE; + treatmentCancelled = FALSE; + // temporary test code. TODO - remove later -#ifndef UF_TEST_ENABLED - setBloodPumpTargetFlowRate( 300, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); - setDialInPumpTargetFlowRate( 300, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); - setDialOutPumpTargetRate( 325, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); -#else -#endif #ifdef RM46_EVAL_BOARD_TARGET start = getMSTimerCount(); #endif } -/************************************************************************* - * @brief execOpParamsMode - * The execFaultMode function executes the Operating Parameters Mode state machine. +/*********************************************************************//** + * @brief + * The resetAllTreatmentParameters function resets treatment parameters + * to default values. * @details * Inputs : none - * Outputs : - * @param none + * Outputs : All treatment parameters reset to default values. + * @return none + *************************************************************************/ +static void resetAllTreatmentParameters( void ) +{ + U32 param; + + for ( param = 0; param < NUM_OF_TREATMENT_PARAMS; param++ ) + { + // set type, range, and default value for each treatment parameter + treatmentParameters[ param ].typ = treatParamsProperties[ param ].dataType; + treatmentParameters[ param ].minimum = treatParamsProperties[ param ].min; + treatmentParameters[ param ].maximum = treatParamsProperties[ param ].max; + treatmentParameters[ param ].defValue = treatParamsProperties[ param ].def; + resetCriticalData( &treatmentParameters[ param ] ); + // set staged parameter values to zero + stagedParams[ param ].uInt = 0; + } + + // zero original parameter values + origTreatmentParams.bloodFlowRate_mL_min = 0; + origTreatmentParams.dialysateFlowRate_mL_min = 0; + origTreatmentParams.treatmentDuration_min = 0; + origTreatmentParams.arterialPressureLowLimit_mmHg = 0; + origTreatmentParams.arterialPressureHighLimit_mmHg = 0; + origTreatmentParams.venousPressureLowLimit_mmHg = 0; + origTreatmentParams.venousPressureHighLimit_mmHg = 0; + origTreatmentParams.uFVolume_L = 0.0; +} + +/*********************************************************************//** + * @brief + * The signalUserConfirmationOfTreatmentParameters function sets the user + * confirmation flag signaling user has confirmed treatment parameters. + * @details + * Inputs : none + * Outputs : treatParamsConfirmed + * @return TRUE if confirmation accepted, FALSE if not + *************************************************************************/ +BOOL signalUserConfirmationOfTreatmentParameters( void ) +{ + BOOL result = FALSE; + + if ( ( MODE_TPAR == getCurrentOperationMode() ) && ( HD_TREATMENT_PARAMS_MODE_STATE_WAIT_4_UI_2_CONFIRM == currentTreatmentParamsState ) ) + { + treatParamsConfirmed = TRUE; + result = TRUE; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The signalUserCancelTreatment function sets the cancelled treatment + * flag signaling the user has cancelled the treatment. + * @details + * Inputs : none + * Outputs : treatmentCancelled + * @return TRUE if cancel accepted, FALSE if not + *************************************************************************/ +BOOL signalUserCancelTreatment( void ) +{ + BOOL result = FALSE; + + if ( MODE_TPAR == getCurrentOperationMode() ) + { + treatmentCancelled = TRUE; + result = TRUE; + } + sendTreatmentStartResponseMsg( result, 0 ); // TODO - provide reason code if rejected + + return result; +} + +/*********************************************************************//** + * @brief + * The execFaultMode function executes the Operating Parameters Mode state machine. + * @details + * Inputs : treatParamsState + * Outputs : treatParamsState * @return current state (sub-mode) *************************************************************************/ U32 execTreatParamsMode( void ) { - BOOL stop = isStopButtonPressed(); - -#ifndef UF_TEST_ENABLED - if ( TRUE == stop ) -#endif + // execute mode state machine + switch ( currentTreatmentParamsState ) { - requestNewOperationMode( MODE_PRET ); + case HD_TREATMENT_PARAMS_MODE_STATE_START: + currentTreatmentParamsState = HD_TREATMENT_PARAMS_MODE_STATE_WAIT_4_UI_2_SEND; + break; + + case HD_TREATMENT_PARAMS_MODE_STATE_WAIT_4_UI_2_SEND: + currentTreatmentParamsState = handleWaitForUI2SendState(); + break; + + case HD_TREATMENT_PARAMS_MODE_STATE_WAIT_4_UI_2_CONFIRM: + currentTreatmentParamsState = handleWaitForUI2ConfirmState(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_STATE, (U32)currentTreatmentParamsState ) + break; + } +#ifdef UF_TEST_ENABLED + requestNewOperationMode( MODE_PRET ); +#endif #ifdef RM46_EVAL_BOARD_TARGET if ( TRUE == didTimeout( start, 5000U ) ) { requestNewOperationMode( MODE_PRET ); } #endif - return 0; // TODO - return current state + return (U32)currentTreatmentParamsState; } +/*********************************************************************//** + * @brief + * The handleWaitForUI2SendState function handles the wait for UI to send + * treatment parameters state of treatment parameters mode. + * @details + * Inputs : + * Outputs : + * @return current state (sub-mode) + *************************************************************************/ +static HD_TREATMENT_PARAMS_MODE_STATE_T handleWaitForUI2SendState( void ) +{ + HD_TREATMENT_PARAMS_MODE_STATE_T result = HD_TREATMENT_PARAMS_MODE_STATE_WAIT_4_UI_2_SEND; + + if ( TRUE == treatmentCancelled ) + { + // go back to standby mode + requestNewOperationMode( MODE_STAN ); + + treatmentCancelled = FALSE; + } + else if ( TRUE == validTreatParamsReceived ) + { + // go to wait for user confirmation state + result = HD_TREATMENT_PARAMS_MODE_STATE_WAIT_4_UI_2_CONFIRM; + + validTreatParamsReceived = FALSE; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The handleWaitForUI2ConfirmState function handles the wait for UI to send + * user confirmation state of treatment parameters mode. + * @details + * Inputs : + * Outputs : + * @return current state (sub-mode) + *************************************************************************/ +static HD_TREATMENT_PARAMS_MODE_STATE_T handleWaitForUI2ConfirmState( void ) +{ + HD_TREATMENT_PARAMS_MODE_STATE_T result = HD_TREATMENT_PARAMS_MODE_STATE_WAIT_4_UI_2_CONFIRM; + + // if user confirms treatment parameters, set them + if ( TRUE == treatParamsConfirmed ) + { + TREATMENT_PARAM_T param; + + // set all treatment parameters (except UF volume which is not yet received) + for ( param = TREATMENT_PARAM_FIRST_UINT; param < TREATMENT_PARAM_UF_VOLUME; param++ ) + { + if ( FALSE == setCriticalData( &treatmentParameters[ param ], stagedParams[ param ] ) ) + { + // TODO - should never get here - s/w fault? + } + } + // retain original settings for treatment that may be adjusted later during treatment + origTreatmentParams.bloodFlowRate_mL_min = getCriticalData( &treatmentParameters[ TREATMENT_PARAM_BLOOD_FLOW ] ).uInt; + origTreatmentParams.dialysateFlowRate_mL_min = getCriticalData( &treatmentParameters[ TREATMENT_PARAM_DIALYSATE_FLOW ] ).uInt; + origTreatmentParams.treatmentDuration_min = getCriticalData( &treatmentParameters[ TREATMENT_PARAM_TREATMENT_DURATION ] ).uInt; + origTreatmentParams.arterialPressureLowLimit_mmHg = getCriticalData( &treatmentParameters[ TREATMENT_PARAM_ART_PRESSURE_LOW_LIMIT ] ).sInt; + origTreatmentParams.arterialPressureHighLimit_mmHg = getCriticalData( &treatmentParameters[ TREATMENT_PARAM_ART_PRESSURE_HIGH_LIMIT ] ).sInt; + origTreatmentParams.venousPressureLowLimit_mmHg = getCriticalData( &treatmentParameters[ TREATMENT_PARAM_VEN_PRESSURE_LOW_LIMIT ] ).sInt; + origTreatmentParams.venousPressureHighLimit_mmHg = getCriticalData( &treatmentParameters[ TREATMENT_PARAM_VEN_PRESSURE_HIGH_LIMIT ] ).sInt; + + // go to pre-treatment mode + requestNewOperationMode( MODE_PRET ); + + treatParamsConfirmed = FALSE; + } + else if ( TRUE == treatmentCancelled ) + { + // go back to standby mode + requestNewOperationMode( MODE_STAN ); + + treatmentCancelled = FALSE; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The validateAndSetTreatmentParameters function validates received + * treatment parameters. + * @details + * Inputs : none + * Outputs : stagedParams[], response sent + * @param params payload record from treatment parameters message received from UI + * @return TRUE if received treatment parameters are valid, FALSE if not + *************************************************************************/ +BOOL validateAndSetTreatmentParameters( TREATMENT_PARAMS_DATA_PAYLOAD_T params ) +{ + BOOL paramsAreInvalid = TRUE; + BOOL paramsAreInRange, paramsAreConsistent; + U32 rejReasons[ NUM_OF_TREATMENT_PARAMS ]; + + // extract treatment parameters from given payload to staging array so we can more easily work with them + extractTreatmentParamsFromPayload( params ); + + // range check each treatment parameter + paramsAreInRange = checkTreatmentParamsInRange( &rejReasons[0] ); + + // validate dependencies + paramsAreConsistent = checkTreatmentParamsDependencies( &rejReasons[0] ); + + // determine overall validity of received treatment parameters + if ( ( TRUE == paramsAreInRange ) && ( TRUE == paramsAreConsistent ) ) + { + paramsAreInvalid = FALSE; + validTreatParamsReceived = TRUE; + } + + // respond to set treatment parameters request message + sendTreatmentParamsResponse( paramsAreInvalid, &rejReasons[0] ); + + return !paramsAreInvalid; +} + +/*********************************************************************//** + * @brief + * The checkTreatmentParamsInRange function checks whether received + * treatment parameters are in range. + * @details + * Inputs : stagedParams[] + * Outputs : reasons[] + * @param reasons Pointer to array of reject reason codes for each parameter + * @return TRUE if treatment parameters are in range, FALSE if not + *************************************************************************/ +static BOOL checkTreatmentParamsInRange( U32 *reasons ) +{ + BOOL result = TRUE; + TREATMENT_PARAM_T param; + + // range check treatment parameters up to (but not including) UF volume + for ( param = TREATMENT_PARAM_FIRST_UINT; param < TREATMENT_PARAM_UF_VOLUME; param++ ) + { + BOOL isParamInRange = isTreatmentParamInRange( param, stagedParams[ param ] ); + + reasons[ param ] = ( TRUE == isParamInRange ? REQUEST_REJECT_REASON_NONE : REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE ); + if ( FALSE == isParamInRange ) + { + result = FALSE; + } + } + + return result; +} + +/*********************************************************************//** + * @brief + * The checkTreatmentParamsDependencies function checks dependencies between + * received treatment parameters. + * @details + * Inputs : stagedParams[] + * Outputs : reasons[] + * @param reasons Pointer to array of reject reason codes for each parameter + * @return TRUE if treatment parameter dependencies are ok, FALSE if not + *************************************************************************/ +static BOOL checkTreatmentParamsDependencies( U32 *reasons ) +{ + BOOL result = TRUE; + U32 dialysateVolume_mL = stagedParams[ TREATMENT_PARAM_DIALYSATE_FLOW ].uInt * \ + stagedParams[ TREATMENT_PARAM_TREATMENT_DURATION ].uInt; + S32 arterialPresLimitDelta = stagedParams[ TREATMENT_PARAM_ART_PRESSURE_HIGH_LIMIT ].sInt - \ + stagedParams[ TREATMENT_PARAM_ART_PRESSURE_LOW_LIMIT ].sInt; + S32 venousPresLimitDelta = stagedParams[ TREATMENT_PARAM_VEN_PRESSURE_HIGH_LIMIT ].sInt - \ + stagedParams[ TREATMENT_PARAM_VEN_PRESSURE_LOW_LIMIT ].sInt; + + // check max dialysate volume dependency + if ( dialysateVolume_mL > MAX_DIALYSATE_VOLUME_ML ) + { + reasons[ TREATMENT_PARAM_DIALYSATE_FLOW ] = REQUEST_REJECT_REASON_DIAL_VOLUME_OUT_OF_RANGE; + reasons[ TREATMENT_PARAM_TREATMENT_DURATION ] = REQUEST_REJECT_REASON_DIAL_VOLUME_OUT_OF_RANGE; + result = FALSE; + } + + // check Heparin pre-stop vs. treatment duration + if ( stagedParams[ TREATMENT_PARAM_HEPARIN_PRE_STOP_TIME ].uInt > stagedParams[ TREATMENT_PARAM_TREATMENT_DURATION ].uInt ) + { + reasons[ TREATMENT_PARAM_HEPARIN_PRE_STOP_TIME ] = REQUEST_REJECT_REASON_HEPARIN_PRESTOP_EXCEEDS_DURATION; + result = FALSE; + } + + // check arterial alarm limits dependency + if ( arterialPresLimitDelta < MIN_PRESSURE_ALARM_LIMIT_DELTA_MMHG ) + { + reasons[ TREATMENT_PARAM_ART_PRESSURE_LOW_LIMIT ] = REQUEST_REJECT_REASON_ARTERIAL_PRESSURE_LOW_VS_HIGH; + reasons[ TREATMENT_PARAM_ART_PRESSURE_HIGH_LIMIT ] = REQUEST_REJECT_REASON_ARTERIAL_PRESSURE_LOW_VS_HIGH; + result = FALSE; + } + + // check venous alarm limits dependency + if ( venousPresLimitDelta < MIN_PRESSURE_ALARM_LIMIT_DELTA_MMHG ) + { + reasons[ TREATMENT_PARAM_VEN_PRESSURE_LOW_LIMIT ] = REQUEST_REJECT_REASON_VENOUS_PRESSURE_LOW_VS_HIGH; + reasons[ TREATMENT_PARAM_VEN_PRESSURE_HIGH_LIMIT ] = REQUEST_REJECT_REASON_VENOUS_PRESSURE_LOW_VS_HIGH; + result = FALSE; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The isTreatmentParamInRange function determines whether a given treatment + * parameter is in range. + * @details + * Inputs : treatParamsRanges[] + * Outputs : none + * @param param ID of parameter to check range for + * @param value value of parameter to check range for + * @return TRUE if given treatment parameter is in range, FALSE if not + *************************************************************************/ +static BOOL isTreatmentParamInRange( TREATMENT_PARAM_T param, CRITICAL_DATAS_T value ) +{ + BOOL result = FALSE; + + if ( param < NUM_OF_TREATMENT_PARAMS ) + { + if ( CRITICAL_DATA_TYPE_U32 == treatParamsProperties[ param ].dataType ) + { + if ( value.uInt >= treatParamsProperties[ param ].min.uInt && value.uInt <= treatParamsProperties[ param ].max.uInt ) + { + result = TRUE; + } + } + else if ( CRITICAL_DATA_TYPE_S32 == treatParamsProperties[ param ].dataType ) + { + if ( value.sInt >= treatParamsProperties[ param ].min.sInt && value.sInt <= treatParamsProperties[ param ].max.sInt ) + { + result = TRUE; + } + } + else + { + if ( value.sFlt >= treatParamsProperties[ param ].min.sFlt && value.sFlt <= treatParamsProperties[ param ].max.sFlt ) + { + result = TRUE; + } + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_PARAM, (U32)param ) + } + + return result; +} + +/*********************************************************************//** + * @brief + * The extractTreatmentParamsFromPayload function extracts the individual + * treatment parameters received from the UI into a staging array where + * they will be validated and stay until user confirms them. + * @details + * Inputs : none + * Outputs : stagedParams[] + * @param payload message payload record containing received treatment parameters + * @return none + *************************************************************************/ +static void extractTreatmentParamsFromPayload( TREATMENT_PARAMS_DATA_PAYLOAD_T payload ) +{ + // pull treatment parameters into data array so we can more easily work with them + memcpy( &stagedParams[0], &payload, sizeof(TREATMENT_PARAMS_DATA_PAYLOAD_T) ); +} + +/*********************************************************************//** + * @brief + * The sendTreatmentParamsResponse function responds to the treatment parameters + * received from the UI. An over-all ok/rejected flag as well as individual reject + * reason codes for each parameter are provided back to the UI. + * @details + * Inputs : none + * Outputs : Response to treatment parameters message constructed and sent. + * @param valid 1 if valid, 0 if not + * @param reasons array of reject reason codes for each parameter (0=not rejected) + * @return none + *************************************************************************/ +static void sendTreatmentParamsResponse( BOOL valid, U32 *reasons ) +{ + U32 respPayload[NUM_OF_TREATMENT_PARAMS]; + + memcpy( &respPayload[0], &reasons[0], sizeof(TREATMENT_PARAMS_DATA_PAYLOAD_T) ); + + sendTreatmentParametersResponseMsg( valid, (U08*)(&respPayload[0]), ( NUM_OF_TREATMENT_PARAMS - 1 ) * sizeof(U32) ); // UF vol. param not included in reject reasons +} + +/*********************************************************************//** + * @brief + * The setTreatmentParameterU32 function sets a given unsigned integer + * treatment parameter to a given value. + * @details + * Inputs : treatmentParameters[] + * Outputs : treatmentParameters[] + * @param param ID of treatment parameter to set unsigned integer value for + * @param value unsigned integer value to assign to given treatment parameter + * @return TRUE if set was successful, FALSE if not + *************************************************************************/ +BOOL setTreatmentParameterU32( TREATMENT_PARAM_T param, U32 value ) +{ + BOOL result = FALSE; + + // validate parameter + if ( param <= TREATMENT_PARAM_LAST_UINT ) + { + CRITICAL_DATAS_T data = treatmentParameters[ param ].data; + + data.uInt = value; + result = setCriticalData( &treatmentParameters[ param ], data ); + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_SET_U32_PARAM, (U32)param ) + } + + return result; +} + +/*********************************************************************//** + * @brief + * The setTreatmentParameterS32 function sets a given signed integer treatment + * parameter to a given value. + * @details + * Inputs : treatmentParameters[] + * Outputs : treatmentParameters[] + * @param param ID of treatment parameter to set signed integer value for + * @param value signed integer value to assign to given treatment parameter + * @return TRUE if set was successful, FALSE if not + *************************************************************************/ +BOOL setTreatmentParameterS32( TREATMENT_PARAM_T param, S32 value ) +{ + BOOL result = FALSE; + + // validate parameter + if ( ( param >= TREATMENT_PARAM_FIRST_INT ) && ( param <= TREATMENT_PARAM_LAST_INT ) ) + { + CRITICAL_DATAS_T data = treatmentParameters[ param ].data; + + data.sInt = value; + result = setCriticalData( &treatmentParameters[ param ], data ); + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_SET_S32_PARAM, (U32)param ) + } + + return result; +} + +/*********************************************************************//** + * @brief + * The setTreatmentParameterF32 sets a given floating point treatment parameter + * to a given value. + * @details + * Inputs : treatmentParameters[] + * Outputs : treatmentParameters[] + * @param param ID of treatment parameter to set floating point value for + * @param value floating point value to assign to given treatment parameter + * @return TRUE if set was successful, FALSE if not + *************************************************************************/ +BOOL setTreatmentParameterF32( TREATMENT_PARAM_T param, F32 value ) +{ + BOOL result = FALSE; + + // validate parameter + if ( ( param >= TREATMENT_PARAM_FIRST_F32 ) && ( param < NUM_OF_TREATMENT_PARAMS ) ) + { + CRITICAL_DATAS_T data = treatmentParameters[ param ].data; + + data.sFlt = value; + result = setCriticalData( &treatmentParameters[ param ], data ); + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_SET_F32_PARAM, (U32)param ) + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getTreatmentParameterU32 function gets the value of a given unsigned + * integer treatment parameter. + * @details + * Inputs : treatmentParameters[] + * Outputs : none + * @param param ID of treatment parameter to get unsigned integer value for + * @return value of given unsigned integer treatment parameter + *************************************************************************/ +U32 getTreatmentParameterU32( TREATMENT_PARAM_T param ) +{ + U32 result = 0; + + // validate parameter + if ( param <= TREATMENT_PARAM_LAST_UINT ) + { + CRITICAL_DATAS_T data = getCriticalData( &treatmentParameters[ param ] ); + + result = data.uInt; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_GET_U32_PARAM, (U32)param ) + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getTreatmentParameterS32 function gets the value of a given signed + * integer treatment parameter. + * @details + * Inputs : treatmentParameters[] + * Outputs : none + * @param param ID of treatment parameter to get signed integer value for + * @return value of given signed integer treatment parameter + *************************************************************************/ +S32 getTreatmentParameterS32( TREATMENT_PARAM_T param ) +{ + S32 result = 0; + + // validate parameter + if ( ( param >= TREATMENT_PARAM_FIRST_INT ) && ( param <= TREATMENT_PARAM_LAST_INT ) ) + { + CRITICAL_DATAS_T data = getCriticalData( &treatmentParameters[ param ] ); + + result = data.sInt; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_GET_S32_PARAM, (U32)param ) + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getTreatmentParameterF32 function gets the value of a given floating point + * treatment parameter. + * @details + * Inputs : treatmentParameters[] + * Outputs : none + * @param param ID of treatment parameter to get floating point value for + * @return value of given floating point treatment parameter + *************************************************************************/ +F32 getTreatmentParameterF32( TREATMENT_PARAM_T param ) +{ + F32 result = 0.0; + + // validate parameter + if ( ( param >= TREATMENT_PARAM_FIRST_F32 ) && ( param < NUM_OF_TREATMENT_PARAMS ) ) + { + CRITICAL_DATAS_T data = getCriticalData( &treatmentParameters[ param ] ); + + result = data.sFlt; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_GET_F32_PARAM, (U32)param ) + } + + return result; +} + + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testSetTreatmentParameterOverride function overrides the value of a + * given treatment parameter. + * @details + * Inputs : none + * Outputs : treatment parameter set to given value + * @param param ID of treatment parameter to set value of + * @param value value to set for given treatment parameter + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetTreatmentParameter( TREATMENT_PARAM_T param, CRITICAL_DATAS_T value ) +{ + BOOL result = FALSE; + + if ( param < NUM_OF_TREATMENT_PARAMS ) + { + if ( TRUE == isTestingActivated() ) + { + // set parameter per its type + if ( CRITICAL_DATA_TYPE_U32 == treatParamsProperties[ param ].dataType ) + { + result = setTreatmentParameterU32( param, value.uInt ); + } + else if ( CRITICAL_DATA_TYPE_S32 == treatParamsProperties[ param ].dataType ) + { + result = setTreatmentParameterS32( param, value.sInt ); + } + else + { + result = setTreatmentParameterF32( param, value.sFlt ); + } + } + } + + return result; +} + /**@}*/