Index: firmware/App/Services/TxParams.c =================================================================== diff -u -r366a9c27c968b9102ef0e88669a9ce5bc76bf17e -r482b7687783895cd75bbbf1756f724952bcfcaf6 --- firmware/App/Services/TxParams.c (.../TxParams.c) (revision 366a9c27c968b9102ef0e88669a9ce5bc76bf17e) +++ firmware/App/Services/TxParams.c (.../TxParams.c) (revision 482b7687783895cd75bbbf1756f724952bcfcaf6) @@ -149,58 +149,267 @@ // ********** private function prototypes ********** -static void extractTreatmentParamsFromPayload( TREATMENT_PARAMS_DATA_PAYLOAD_T payload ); +static void resetAllTreatmentParameters( void ); static BOOL checkTreatmentParamsInRange( U32 *reasons ); static BOOL checkTreatmentParamsDependencies( U32 *reasons ); -static void sendTreatmentParamsResponse( BOOL paramsAreInvalid, U32 *reasons ); -static void resetAllTreatmentParameters( void ); +static void extractTreatmentParamsFromPayload( TREATMENT_PARAMS_DATA_PAYLOAD_T payload ); +//static void checkPressureParamsRange( TREATMENT_PARAMS_DATA_PAYLOAD_T* txParams ); +static void sendTreatmentParamsResponse( BOOL rejected, U32 *reasons ); +//static void getInstitutionalRecordEdgeValue( TREATMENT_PARAM_T param, CRITICAL_DATAS_T* value, BOOL isMin ); /*********************************************************************//** * @brief - * The resetTreatmentParameters function resets the Treatment Parameters - * session flags and parameter values. - * @details Inputs: none - * @details Outputs: validTreatParamsReceived, treatParamsConfirmed, - * treatParamsRejected cleared and parameters reset. + * The resetAllTreatmentParameters function resets treatment parameters + * to default values. + * @details \b Inputs: none + * @details \b Outputs: All treatment parameters reset to default values and + * original and staged treatment parameters reset to zero. * @return none *************************************************************************/ -void resetTreatmentParameters( void ) +static void resetAllTreatmentParameters( void ) { - validTreatParamsReceived = FALSE; - treatParamsConfirmed = FALSE; + TREATMENT_PARAM_T param; - resetAllTreatmentParameters(); + for ( param = TREATMENT_PARAM_FIRST_UINT; param < NUM_OF_TREATMENT_PARAMS; param++ ) + { + // Set type, range, and default value for each treatment parameter + treatmentParameters[ param ].typ = TREAT_PARAMS_PROPERTIES[ param ].dataType; + treatmentParameters[ param ].minimum = TREAT_PARAMS_PROPERTIES[ param ].min; + treatmentParameters[ param ].maximum = TREAT_PARAMS_PROPERTIES[ param ].max; + treatmentParameters[ param ].defValue = TREAT_PARAMS_PROPERTIES[ 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.arterialPressureLimitWindow_mmHg = 0; + origTreatmentParams.venousPressureLimitWindow_mmHg = 0; + origTreatmentParams.venousPressureLimitAsymmetric_mmHg = 0; + origTreatmentParams.tmpLimitWindow_mmHg = 0; + origTreatmentParams.uFVolume_L = 0.0F; } /*********************************************************************//** -* @brief -* The getValidTreatParamsReceived function reports whether a valid set -* of Treatment Parameters has been staged. -* @details Inputs: validTreatParamsReceived -* @details Outputs: none -* @return TRUE if valid parameters are available, FALSE otherwise. -**************************************************************************/ -BOOL getValidTreatParamsReceived( void ) + * @brief + * The setTreatmentParameterU32 function sets a given unsigned integer + * treatment parameter to a given value. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given param is invalid + * @details \b Inputs: treatmentParameters[] + * @details \b 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 ) { - return validTreatParamsReceived; + CRITICAL_DATAS_T integerData; + BOOL result = FALSE; + + integerData.uInt = value; + result = isTreatmentParamInRange( param, integerData ); + + // Validate parameter + if ( param <= TREATMENT_PARAM_LAST_UINT ) + { + if ( TRUE == result ) + { + CRITICAL_DATAS_T data = treatmentParameters[ param ].data; + + data.uInt = value; + result = setCriticalData( &treatmentParameters[ param ], data ); + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_SET_U32_PARAM, (U32)param ) + } + + return result; } /*********************************************************************//** * @brief - * The getTreatParamsConfirmed function reports whether the current - * Treatment Parameters have been confirmed by the user. - * @details Inputs: treatParamsConfirmed - * @details Outputs: none - * @return TRUE if the current Treatment Parameters are confirmed, - * FALSE otherwise. + * The setTreatmentParameterS32 function sets a given signed integer treatment + * parameter to a given value. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given param is invalid + * @details \b Inputs: treatmentParameters[] + * @details \b 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 getTreatParamsConfirmed( void ) +BOOL setTreatmentParameterS32( TREATMENT_PARAM_T param, S32 value ) { - return treatParamsConfirmed; + CRITICAL_DATAS_T unsignedIntData; + BOOL result = FALSE; + + unsignedIntData.sInt = value; + result = isTreatmentParamInRange( param, unsignedIntData ); + + // Validate parameter + if ( ( param >= TREATMENT_PARAM_FIRST_INT ) && ( param <= TREATMENT_PARAM_LAST_INT ) ) + { + if ( TRUE == result ) + { + CRITICAL_DATAS_T data = treatmentParameters[ param ].data; + + data.sInt = value; + result = setCriticalData( &treatmentParameters[ param ], data ); + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_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 \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given param is invalid + * @details \b Inputs: treatmentParameters[] + * @details \b 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 ) +{ + CRITICAL_DATAS_T floatData; + BOOL result = FALSE; + + floatData.sFlt = value; + result = isTreatmentParamInRange( param, floatData ); + + // Validate parameter + if ( ( param >= TREATMENT_PARAM_FIRST_F32 ) && ( param < NUM_OF_TREATMENT_PARAMS ) ) + { + if ( TRUE == result ) + { + CRITICAL_DATAS_T data = treatmentParameters[ param ].data; + + data.sFlt = value; + result = setCriticalData( &treatmentParameters[ param ], data ); + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_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 \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given param is invalid + * @details \b Inputs: treatmentParameters[] + * @details \b 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 = 1; + + // 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_TD_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 \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given param is invalid + * @details \b Inputs: treatmentParameters[] + * @details \b 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 = 1; + + // 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_TD_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 \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given param is invalid + * @details \b Inputs: treatmentParameters[] + * @details \b 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 = 1.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_TD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_GET_F32_PARAM, (U32)param ) + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getTreatmentParameterS32DefaultValue function gets the defaultvalue + * of a given signed integer treatment parameter. + * @details \b Inputs: TREAT_PARAMS_PROPERTIES[] + * @details \b Outputs: none + * @param param ID of treatment parameter to get signed integer default value for + * @return default value of given signed integer treatment parameter + *************************************************************************/ +S32 getTreatmentParameterS32DefaultValue( TREATMENT_PARAM_T param ) +{ + return TREAT_PARAMS_PROPERTIES[ param ].def.sInt; +} + +/*********************************************************************//** + * @brief * The validateAndSetTreatmentParameters function validates received * treatment parameters. * @details \b Message \b Sent: MSG_ID_TD_RESP_TREATMENT_PARAMS_TO_VALIDATE @@ -272,6 +481,77 @@ /*********************************************************************//** * @brief + * The checkTreatmentParamsInRange function checks whether received + * treatment parameters are in range. + * @details \b Inputs: stagedParams[] + * @details \b 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++ ) + { + if ( FALSE == isTreatmentParamInRange( param, stagedParams[ param ] ) ) + { + reasons[ param ] = REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE; + result = FALSE; + } + else + { + reasons[ param ] = REQUEST_REJECT_REASON_NONE; + } + } + + return result; +} + +/*********************************************************************//** + * @brief + * The checkTreatmentParamsDependencies function checks dependencies between + * received treatment parameters. + * @details \b Inputs: stagedParams[] + * @details \b 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 txDur = stagedParams[ TREATMENT_PARAM_TREATMENT_DURATION ].uInt; + U32 hepST = stagedParams[ TREATMENT_PARAM_HEPARIN_STOP_TIME ].uInt; + F32 hepDR = stagedParams[ TREATMENT_PARAM_HEPARIN_DISPENSE_RATE ].sFlt; + F32 hepBV = stagedParams[ TREATMENT_PARAM_HEPARIN_BOLUS_VOLUME ].sFlt; + F32 txVol = hepBV + ( hepDR * ( hepST / (F32)SEC_PER_MIN ) ) + SYRINGE_PUMP_PRIME_VOLUME_ML + SYRINGE_PUMP_FILL_VOLUME_OFFSET_ML; + + // Verify Heparin stop time is only set if Heparin dispense rate is set + if ( ( hepST > 0 ) && ( hepDR < NEARLY_ZERO ) ) + { + reasons[ TREATMENT_PARAM_HEPARIN_STOP_TIME ] = REQUEST_REJECT_REASON_HEPARIN_STOP_TIME_WITH_NO_DISPENSE; + result = FALSE; + } + // Verify Heparin stop time does not exceed Tx duration + else if ( hepST > txDur ) + { + reasons[ TREATMENT_PARAM_HEPARIN_STOP_TIME ] = REQUEST_REJECT_REASON_HEPARIN_STOP_TIME_EXCEEDS_DURATION; + result = FALSE; + } + // Verify Heparin stop time does not exceed max 10 mL Heparin volume + else if ( txVol > MAX_HEPARIN_VOLUME_ML ) + { + reasons[ TREATMENT_PARAM_HEPARIN_STOP_TIME ] = REQUEST_REJECT_REASON_HEPARIN_VOLUME_EXCEEDS_10_ML; + result = FALSE; + } + + return result; +} + +/*********************************************************************//** + * @brief * The validateAndSetUFVolume function validates received ultrafiltration * volume treatment parameter. * @details \b Message \b Sent: MSG_ID_TD_RESP_ULTRAFILTRATION_VOLUME_TO_VALIDATE @@ -288,190 +568,157 @@ F32 uFVolumeMl; F32 uFVolumeL; + // Verify message payload length is valid if ( sizeof( F32 ) == message->hdr.payloadLen ) { UF_VOLUME_VAL_RESP_DATA_PAYLOAD_T respPayload; + memcpy( &uFVolumeMl, message->payload, sizeof( F32 ) ); uFVolumeL = uFVolumeMl / (F32)ML_PER_LITER; + + // Validate given UF volume accepted = setTreatmentParameterF32( TREATMENT_PARAM_UF_VOLUME, uFVolumeL ); if ( TRUE == accepted ) { U32 treatmentDuration = getTreatmentParameterU32( TREATMENT_PARAM_TREATMENT_DURATION ); - if ( treatmentDuration > 0U ) + + // store the user set ultrafiltration volume in pre-treatment parameters setup, if it is validated, otherwise keep the initial 0.0 + origTreatmentParams.uFVolume_L = uFVolumeL; + + if ( treatmentDuration > 0 ) { F32 uFRate = uFVolumeMl / (F32)treatmentDuration; + if ( ( uFRate > MAX_UF_RATE_ML_MIN ) || ( uFRate < MIN_UF_RATE_ML_MIN ) ) { - accepted = FALSE; + accepted = FALSE; rejReason = REQUEST_REJECT_REASON_UF_RATE_OUT_OF_RANGE; } } - else { - accepted = FALSE; + accepted = FALSE; rejReason = REQUEST_REJECT_REASON_TREATMENT_TIME_LESS_THAN_MINIMUM; } } - else { rejReason = REQUEST_REJECT_REASON_UF_VOLUME_OUT_OF_RANGE; } - // respond to UI - uFVolumeL = getTreatmentParameterF32( TREATMENT_PARAM_UF_VOLUME ); + // Respond to set UF volume request message + uFVolumeL = getTreatmentParameterF32( TREATMENT_PARAM_UF_VOLUME ); uFVolumeMl = uFVolumeL * (F32)ML_PER_LITER; - respPayload.accepted = accepted; - respPayload.rejReason = rejReason; + respPayload.accepted = accepted; + respPayload.rejReason = rejReason; respPayload.ufVolumeMl = uFVolumeMl; - sendMessage( MSG_ID_TD_RESP_ULTRAFILTRATION_VOLUME_TO_VALIDATE, COMM_BUFFER_OUT_CAN_TD_2_UI, (U08*)(&respPayload), sizeof( UF_VOLUME_VAL_RESP_DATA_PAYLOAD_T ) ); + // setUserSetUFVolumeStatus( accepted ); // TODO - tell pre-tx whether UF volume has been set and accepted } return accepted; } /*********************************************************************//** * @brief + * The resetTreatmentParameters function resets the Treatment Parameters + * session flags and parameter values. + * @details Inputs: none + * @details Outputs: validTreatParamsReceived, treatParamsConfirmed, + * treatParamsRejected cleared and parameters reset. + * @return none + *************************************************************************/ +void resetTreatmentParameters( void ) +{ + validTreatParamsReceived = FALSE; + treatParamsConfirmed = FALSE; + + resetAllTreatmentParameters(); +} + +/*********************************************************************//** +* @brief +* The getValidTreatParamsReceived function reports whether a valid set +* of Treatment Parameters has been staged. +* @details Inputs: validTreatParamsReceived +* @details Outputs: none +* @return TRUE if valid parameters are available, FALSE otherwise. +**************************************************************************/ +BOOL getValidTreatParamsReceived( void ) +{ + return validTreatParamsReceived; +} + +/*********************************************************************//** + * @brief + * The getTreatParamsConfirmed function reports whether the current + * Treatment Parameters have been confirmed by the user. + * @details Inputs: treatParamsConfirmed + * @details Outputs: none + * @return TRUE if the current Treatment Parameters are confirmed, + * FALSE otherwise. + *************************************************************************/ +BOOL getTreatParamsConfirmed( void ) +{ + return treatParamsConfirmed; +} + +/*********************************************************************//** + * @brief * The signalUserConfirmationOfTreatmentParameters function sets the user * confirmation flag signaling user has confirmed or rejected treatment * parameters. * @details \b Inputs: none * @details \b Outputs: treatParamsConfirmed * @param message confirmation message from UI which includes the user - * confirmation or rejection. + * confirmation or restTreamentParameters. * @return TRUE if confirmation/rejection accepted, FALSE if not *************************************************************************/ -BOOL signalUserConfirmTreatmentParameters( MESSAGE_T *message ) +BOOL signalUserConfirmationOfTreatmentParameters( MESSAGE_T *message ) { BOOL confirmed = FALSE; + BOOL result = FALSE; + if ( sizeof( BOOL ) == message->hdr.payloadLen ) { memcpy( &confirmed, message->payload, sizeof( BOOL ) ); + if ( TRUE == confirmed ) + { + // ModePreTreat uses this via getTreatParamsConfirmed() + treatParamsConfirmed = TRUE; + } + else + { + // Rejected – clear session + resetTreatmentParameters(); + } + result = TRUE; } - if ( TRUE == confirmed ) - { - // ModePreTreat uses this via getTreatParamsConfirmed() - treatParamsConfirmed = TRUE; - } else { - // Rejected – clear session - resetTreatmentParameters(); + result = FALSE; } + + return result; } /*********************************************************************//** * @brief - * The resetAllTreatmentParameters function resets treatment parameters - * to default values. + * The signalAlarmActionToTreatParamsMode function executes the given alarm action + * as appropriate while in Treatment Parameters Mode. * @details \b Inputs: none - * @details \b Outputs: All treatment parameters reset to default values - * and original and staged treatment parameters reset to zero. + * @details \b Outputs: given alarm action executed + * @param action ID of alarm action to execute * @return none *************************************************************************/ -static void resetAllTreatmentParameters( void ) +void signalAlarmActionToTreatParamsMode( ALARM_ACTION_T action ) { - TREATMENT_PARAM_T param; - - for ( param = TREATMENT_PARAM_FIRST_UINT; param < NUM_OF_TREATMENT_PARAMS; param++ ) - { - // Set type, range, and default value for each treatment parameter - treatmentParameters[ param ].typ = TREAT_PARAMS_PROPERTIES[ param ].dataType; - treatmentParameters[ param ].minimum = TREAT_PARAMS_PROPERTIES[ param ].min; - treatmentParameters[ param ].maximum = TREAT_PARAMS_PROPERTIES[ param ].max; - treatmentParameters[ param ].defValue = TREAT_PARAMS_PROPERTIES[ 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.arterialPressureLimitWindow_mmHg = 0; - origTreatmentParams.venousPressureLimitWindow_mmHg = 0; - origTreatmentParams.venousPressureLimitAsymmetric_mmHg = 0; - origTreatmentParams.tmpLimitWindow_mmHg = 0; - origTreatmentParams.uFVolume_L = 0.0F; + // No special handling of alarm actions in this mode. } /*********************************************************************//** * @brief - * The checkTreatmentParamsInRange function checks whether received - * treatment parameters are in range. - * @details \b Inputs: stagedParams[] - * @details \b 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++ ) - { - if ( FALSE == isTreatmentParamInRange( param, stagedParams[ param ] ) ) - { - reasons[ param ] = REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE; - result = FALSE; - } - else - { - reasons[ param ] = REQUEST_REJECT_REASON_NONE; - } - } - - return result; -} - -/*********************************************************************//** - * @brief - * The checkTreatmentParamsDependencies function checks dependencies between - * received treatment parameters. - * @details \b Inputs: stagedParams[] - * @details \b 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 txDur = stagedParams[ TREATMENT_PARAM_TREATMENT_DURATION ].uInt; - U32 hepST = stagedParams[ TREATMENT_PARAM_HEPARIN_STOP_TIME ].uInt; - F32 hepDR = stagedParams[ TREATMENT_PARAM_HEPARIN_DISPENSE_RATE ].sFlt; - F32 hepBV = stagedParams[ TREATMENT_PARAM_HEPARIN_BOLUS_VOLUME ].sFlt; - F32 txVol = hepBV + ( hepDR * ( hepST / (F32)SEC_PER_MIN ) ) + SYRINGE_PUMP_PRIME_VOLUME_ML + SYRINGE_PUMP_FILL_VOLUME_OFFSET_ML; - - // Verify Heparin stop time is only set if Heparin dispense rate is set - if ( ( hepST > 0 ) && ( hepDR < NEARLY_ZERO ) ) - { - reasons[ TREATMENT_PARAM_HEPARIN_STOP_TIME ] = REQUEST_REJECT_REASON_HEPARIN_STOP_TIME_WITH_NO_DISPENSE; - result = FALSE; - } - // Verify Heparin stop time does not exceed Tx duration - else if ( hepST > txDur ) - { - reasons[ TREATMENT_PARAM_HEPARIN_STOP_TIME ] = REQUEST_REJECT_REASON_HEPARIN_STOP_TIME_EXCEEDS_DURATION; - result = FALSE; - } - // Verify Heparin stop time does not exceed max 10 mL Heparin volume - else if ( txVol > MAX_HEPARIN_VOLUME_ML ) - { - reasons[ TREATMENT_PARAM_HEPARIN_STOP_TIME ] = REQUEST_REJECT_REASON_HEPARIN_VOLUME_EXCEEDS_10_ML; - result = FALSE; - } - - 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. @@ -561,118 +808,337 @@ /*********************************************************************//** * @brief - * The setTreatmentParameterU32 function sets a given unsigned integer - * treatment parameter to a given value. + * The isTreatmentParamInRange function determines whether a given treatment + * parameter is in range. * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given param is invalid - * @details \b Inputs: treatmentParameters[] - * @details \b 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 + * @details \b Inputs: treatParamsRanges[], hdInstitutionalRecord + * @details \b 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 *************************************************************************/ -BOOL setTreatmentParameterU32( TREATMENT_PARAM_T param, U32 value ) +BOOL isTreatmentParamInRange( TREATMENT_PARAM_T param, CRITICAL_DATAS_T value ) { - CRITICAL_DATAS_T integerData; - BOOL result = FALSE; + BOOL result = TRUE; // TODO FALSE; - integerData.uInt = value; - result = isTreatmentParamInRange( param, integerData ); - - // Validate parameter - if ( param <= TREATMENT_PARAM_LAST_UINT ) + if ( param < NUM_OF_TREATMENT_PARAMS ) { - if ( TRUE == result ) - { - CRITICAL_DATAS_T data = treatmentParameters[ param ].data; - - data.uInt = value; - result = setCriticalData( &treatmentParameters[ param ], data ); - } +// switch( param ) +// { +// case TREATMENT_PARAM_BLOOD_FLOW: +// result = ( ( value.uInt >= hdInstitutionalRecord.minBloodFlowMLPM ) && +// ( value.uInt <= hdInstitutionalRecord.maxBloodFlowMLPM ) ? TRUE : FALSE ); +// break; +// +// case TREATMENT_PARAM_DIALYSATE_FLOW: +// result = ( ( value.uInt >= hdInstitutionalRecord.minDialysateFlowMLPM ) && +// ( value.uInt <= hdInstitutionalRecord.maxDialysateFlowMLPM ) ? TRUE : FALSE ); +// break; +// +// case TREATMENT_PARAM_TREATMENT_DURATION: +// result = ( ( value.uInt >= hdInstitutionalRecord.minTxDurationMIN ) && +// ( value.uInt <= hdInstitutionalRecord.maxTxDurationMIN ) ? TRUE : FALSE ); +// // If the 1-minute treatment is selected, it is ok to accept the time. This test configuration specifically checks for a 1-minute run +// result |= ( TRUE == getTestConfigStatus( TEST_CONFIG_ENABLE_ONE_MINUTE_TREATMENT ) ? TRUE : FALSE ); +// break; +// +// case TREATMENT_PARAM_SALINE_BOLUS_VOLUME: +// result = ( ( value.uInt >= hdInstitutionalRecord.minSalineBolusVolumeML ) && +// ( value.uInt <= hdInstitutionalRecord.maxSalineBolusVolumeML ) ? TRUE : FALSE ); +// break; +// +// case TREATMENT_PARAM_DIALYSATE_TEMPERATURE: +// result = ( ( value.sFlt >= hdInstitutionalRecord.minDialysateTempC ) && +// ( value.sFlt <= hdInstitutionalRecord.maxDialysateTempC ) ? TRUE : FALSE ); +// break; +// +// case TREATMENT_PARAM_ART_PRES_LIMIT_WINDOW: +// result = ( ( value.sInt >= hdInstitutionalRecord.minArtPressLimitWindowMMHG ) && +// ( value.sInt <= hdInstitutionalRecord.maxArtPressLimitWindowMMHG ) ? TRUE : FALSE ); +// break; +// +// case TREATMENT_PARAM_VEN_PRES_LIMIT_WINDOW: +// result = ( ( value.sInt >= hdInstitutionalRecord.minVenPressLimitWindowMMHG ) && +// ( value.sInt <= hdInstitutionalRecord.maxVenPressLimitWindowMMHG ) ? TRUE : FALSE ); +// break; +// +// case TREATMENT_PARAM_VEN_PRES_LIMIT_ASYMMETRIC: +// result = ( ( value.sInt >= hdInstitutionalRecord.minVenAsymPressLimitMMHG ) && +// ( value.sInt <= hdInstitutionalRecord.maxVenAsymPressLimitMMHG ) ? TRUE : FALSE ); +// break; +// +// case TREATMENT_PARAM_TMP_PRES_LIMIT_WINDOW: +// result = ( ( value.sInt >= hdInstitutionalRecord.minTmpPressLimitWindowMMHG ) && +// ( value.sInt <= hdInstitutionalRecord.maxTmpPressLimitWindowMMHG ) ? TRUE : FALSE ); +// break; +// +// case TREATMENT_PARAM_UF_VOLUME: +// result = ( ( value.sFlt >= hdInstitutionalRecord.minUFVolumeL ) && ( value.sFlt <= hdInstitutionalRecord.maxUFVolumeL ) ? TRUE : FALSE ); +// result |= ( fabs( value.sFlt ) <= NEARLY_ZERO ? TRUE : FALSE ); // There might be a minimum UF volume set in the institutional record but a treatment with 0 vol should be allowed +// break; +// +// default: +//#ifndef _VECTORCAST_ +// // The treatment parameters that do not have any institutional record. +// // Right now, all the F32 and S32 data types are covered in the institutional record and therefore, there is no test case that is either F32 or S32 +// // and gets here so it is removed from VectorCAST to be able to achieve 100% coverage of the function +// // The treatment parameters that do not have any institutional record. +// if ( CRITICAL_DATA_TYPE_U32 == TREAT_PARAMS_PROPERTIES[ param ].dataType ) +//#endif +// { +// result = ( ( value.uInt >= TREAT_PARAMS_PROPERTIES[ param ].min.uInt ) && +// ( value.uInt <= TREAT_PARAMS_PROPERTIES[ param ].max.uInt ) ? TRUE : FALSE ); +// } +//#ifndef _VECTORCAST_ +// // Right now, all the F32 and S32 data types are covered in the institutional record and therefore, there is no test case that is either F32 or S32 +// // and gets here so it is removed from VectorCAST to be able to achieve 100% coverage of the function +// else if ( CRITICAL_DATA_TYPE_S32 == TREAT_PARAMS_PROPERTIES[ param ].dataType ) +// { +// result = ( ( value.sInt >= TREAT_PARAMS_PROPERTIES[ param ].min.sInt ) && +// ( value.sInt <= TREAT_PARAMS_PROPERTIES[ param ].max.sInt ) ? TRUE : FALSE ); +// } +// else +// { +// result = ( ( value.sFlt >= TREAT_PARAMS_PROPERTIES[ param ].min.sFlt ) && +// ( value.sFlt <= TREAT_PARAMS_PROPERTIES[ param ].max.sFlt ) ? TRUE : FALSE ); +// } +//#endif +// } } else { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_SET_U32_PARAM, (U32)param ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_PARAM, (U32)param ) } return result; } /*********************************************************************//** * @brief - * The setTreatmentParameterS32 function sets a given signed integer treatment - * parameter to a given value. + * The getS32TreatmentParamLowerRangeLimit function returns the lower range + * limit for a given signed integer treatment parameter. * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given param is invalid * @details \b Inputs: treatmentParameters[] - * @details \b 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 + * @details \b Outputs: none + * @param param ID of parameter to get lower range limit for + * @return lower range limit for given signed integer treatment parameter *************************************************************************/ -BOOL setTreatmentParameterS32( TREATMENT_PARAM_T param, S32 value ) +S32 getS32TreatmentParamLowerRangeLimit( TREATMENT_PARAM_T param ) { - CRITICAL_DATAS_T unsignedIntData; - BOOL result = FALSE; + S32 result = 0; - unsignedIntData.sInt = value; - result = isTreatmentParamInRange( param, unsignedIntData ); + if ( param < NUM_OF_TREATMENT_PARAMS ) + { + CRITICAL_DATAS_T value; + // getInstitutionalRecordEdgeValue( param, &value, TRUE ); TODO + value = treatmentParameters[ param ].minimum; + result = value.sInt; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_GET_S32_PARAM_MIN_LIMIT, (U32)param ) + } - // Validate parameter - if ( ( param >= TREATMENT_PARAM_FIRST_INT ) && ( param <= TREATMENT_PARAM_LAST_INT ) ) + return result; +} + +/*********************************************************************//** + * @brief + * The getS32TreatmentParamUpperRangeLimit function returns the upper range + * limit for a given signed integer treatment parameter. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given param is invalid. + * @details \b Inputs: treatmentParameters[] + * @details \b Outputs: none + * @param param ID of parameter to get upper range limit for + * @return upper range limit for given signed integer treatment parameter + *************************************************************************/ +S32 getS32TreatmentParamUpperRangeLimit( TREATMENT_PARAM_T param ) +{ + S32 result = 0; + + if ( param < NUM_OF_TREATMENT_PARAMS ) { - if ( TRUE == result ) - { - CRITICAL_DATAS_T data = treatmentParameters[ param ].data; + CRITICAL_DATAS_T value; +// getInstitutionalRecordEdgeValue( param, &value, FALSE ); // TODO + value = treatmentParameters[ param ].maximum; + result = value.sInt; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_GET_S32_PARAM_MAX_LIMIT, (U32)param ) + } - data.sInt = value; - result = setCriticalData( &treatmentParameters[ param ], data ); - } + return result; +} + +/*********************************************************************//** + * @brief + * The getU32TreatmentParamLowerRangeLimit function returns the lower range + * limit for a given unsigned integer treatment parameter. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given param is invalid. + * @details \b Inputs: treatmentParameters[] + * @details \b Outputs: none + * @param param ID of parameter to get lower range limit for + * @return lower range limit for given unsigned integer treatment parameter + *************************************************************************/ +U32 getU32TreatmentParamLowerRangeLimit( TREATMENT_PARAM_T param ) +{ + U32 result = 0; + + if ( param < NUM_OF_TREATMENT_PARAMS ) + { + CRITICAL_DATAS_T value; +// getInstitutionalRecordEdgeValue( param, &value, TRUE ); // TODO + value = treatmentParameters[ param ].minimum; + result = value.uInt; } else { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_SET_S32_PARAM, (U32)param ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_GET_U32_PARAM_MIN_LIMIT, (U32)param ) } return result; } /*********************************************************************//** * @brief - * The setTreatmentParameterF32 sets a given floating point treatment parameter - * to a given value. - * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given param is invalid + * The getU32TreatmentParamUpperRangeLimit function returns the upper range + * limit for a given unsigned integer treatment parameter. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given param is invalid. * @details \b Inputs: treatmentParameters[] - * @details \b 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 + * @details \b Outputs: none + * @param param ID of parameter to get upper range limit for + * @return upper range limit for given unsigned integer treatment parameter *************************************************************************/ -BOOL setTreatmentParameterF32( TREATMENT_PARAM_T param, F32 value ) +U32 getU32TreatmentParamUpperRangeLimit( TREATMENT_PARAM_T param ) { - CRITICAL_DATAS_T floatData; - BOOL result = FALSE; + U32 result = 0; - floatData.sFlt = value; - result = isTreatmentParamInRange( param, floatData ); + if ( param < NUM_OF_TREATMENT_PARAMS ) + { + CRITICAL_DATAS_T value; +// getInstitutionalRecordEdgeValue( param, &value, FALSE ); // TODO + value = treatmentParameters[ param ].maximum; + result = value.uInt; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_GET_U32_PARAM_MAX_LIMIT, (U32)param ) + } - // Validate parameter - if ( ( param >= TREATMENT_PARAM_FIRST_F32 ) && ( param < NUM_OF_TREATMENT_PARAMS ) ) + return result; +} + +/*********************************************************************//** + * @brief + * The getF32TreatmentParamLowerRangeLimit function returns the lower range + * limit for a given float treatment parameter. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given param is invalid. + * @details \b Inputs: treatmentParameters[] + * @details \b Outputs: none + * @param param ID of parameter to get lower range limit for + * @return lower range limit for given float treatment parameter + *************************************************************************/ +F32 getF32TreatmentParamLowerRangeLimit( TREATMENT_PARAM_T param ) +{ + F32 result = 0; + + if ( param < NUM_OF_TREATMENT_PARAMS ) { - if ( TRUE == result ) - { - CRITICAL_DATAS_T data = treatmentParameters[ param ].data; + CRITICAL_DATAS_T value; +// getInstitutionalRecordEdgeValue( param, &value, TRUE ); // TODO + value = treatmentParameters[ param ].minimum; + result = value.sFlt; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_GET_F32_PARAM_MIN_LIMIT, (U32)param ) + } - data.sFlt = value; - result = setCriticalData( &treatmentParameters[ param ], data ); - } + return result; +} + +/*********************************************************************//** + * @brief + * The getF32TreatmentParamUpperRangeLimit function returns the upper range + * limit for a given float treatment parameter. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given param is invalid. + * @details \b Inputs: treatmentParameters[] + * @details \b Outputs: none + * @param param ID of parameter to get lower range limit for + * @return upper range limit for given float treatment parameter + *************************************************************************/ +F32 getF32TreatmentParamUpperRangeLimit( TREATMENT_PARAM_T param ) +{ + F32 result = 0; + + if ( param < NUM_OF_TREATMENT_PARAMS ) + { + CRITICAL_DATAS_T value; +// getInstitutionalRecordEdgeValue( param, &value, FALSE ); // TODO + value = treatmentParameters[ param ].maximum; + result = value.sFlt; } else { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_SET_F32_PARAM, (U32)param ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_GET_F32_PARAM_MAX_LIMIT, (U32)param ) } return result; } +/*********************************************************************//** + * @brief + * The getS32DefaultTreatmentParamEdge function returns the min or max of + * the default treatment parameters + * @details \b Inputs: TREAT_PARAMS_PROPERTIES[] + * @details \b Outputs: none + * @param param ID of parameter + * @param isMin to indicate whether minimum is needed for maximum + * @return the requested min or max value + *************************************************************************/ +S32 getS32DefaultTreatmentParamEdge( TREATMENT_PARAM_T param, BOOL isMin ) +{ + S32 value = ( TRUE == isMin ? TREAT_PARAMS_PROPERTIES[ param ].min.sInt : TREAT_PARAMS_PROPERTIES[ param ].max.sInt ); + + return value; +} + +/*********************************************************************//** + * @brief + * The getU32DefaultTreatmentParamEdge function returns the min or max of + * the default treatment parameters + * @details \b Inputs: TREAT_PARAMS_PROPERTIES[] + * @details \b Outputs: none + * @param param ID of parameter + * @param isMin to indicate whether minimum is needed for maximum + * @return the requested min or max value + *************************************************************************/ +U32 getU32DefaultTreatmentParamEdge( TREATMENT_PARAM_T param, BOOL isMin ) +{ + U32 value = ( TRUE == isMin ? TREAT_PARAMS_PROPERTIES[ param ].min.uInt : TREAT_PARAMS_PROPERTIES[ param ].max.uInt ); + + return value; +} + +/*********************************************************************//** + * @brief + * The getF32DefaultTreatmentParamEdge function returns the min or max of + * the default treatment parameters + * @details \b Inputs: TREAT_PARAMS_PROPERTIES[] + * @details \b Outputs: none + * @param param ID of parameter + * @param isMin to indicate whether minimum is needed for maximum + * @return the requested min or max value + *************************************************************************/ +F32 getF32DefaultTreatmentParamEdge( TREATMENT_PARAM_T param, BOOL isMin ) +{ + F32 value = ( TRUE == isMin ? TREAT_PARAMS_PROPERTIES[ param ].min.sFlt : TREAT_PARAMS_PROPERTIES[ param ].max.sFlt ); + + return value; +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ @@ -715,4 +1181,39 @@ return result; } +/*********************************************************************//** + * @brief + * The testTxParamsRequest function publishes the complete set of treatment + * parameters. + * @details \b Message \b Sent: MSG_ID_TD_RSP_CURRENT_TREATMENT_PARAMETERS + * @details \b Inputs: treatmentParameters[] + * @details \b Outputs: none + * @param message The message from Dialin requesting that treatment parameters + * be published. + * @return TRUE if publish treatment parameters request is successful, FALSE if not + *************************************************************************/ +BOOL testTxParamsRequest( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + // Verify payload length + if ( 0 == message->hdr.payloadLen ) + { + CURRENT_TREATMENT_PARAMS_DATA_PAYLOAD_T payload; + TREATMENT_PARAM_T param; + + // Build and publish current treatment parameters record + for ( param = (TREATMENT_PARAM_T)0; param < NUM_OF_TREATMENT_PARAMS; param++ ) + { + stagedParams[ param ] = treatmentParameters[ param ].data; + } + memcpy( (U08*)&payload, (U08*)&stagedParams[0], sizeof( CURRENT_TREATMENT_PARAMS_DATA_PAYLOAD_T ) ); + sendMessage( MSG_ID_TD_RSP_CURRENT_TREATMENT_PARAMETERS, COMM_BUFFER_OUT_CAN_PC, (U08*)&payload, sizeof( CURRENT_TREATMENT_PARAMS_DATA_PAYLOAD_T ) ); + + result = TRUE; + } + + return result; +} + /**@}*/