Index: firmware/App/Services/TxParams.c =================================================================== diff -u -rc92e2b5ae61f359e5633b32b2d5b691347d0d293 -r4644222ff44fd3fc588bd071e794aabad9780bae --- firmware/App/Services/TxParams.c (.../TxParams.c) (revision c92e2b5ae61f359e5633b32b2d5b691347d0d293) +++ firmware/App/Services/TxParams.c (.../TxParams.c) (revision 4644222ff44fd3fc588bd071e794aabad9780bae) @@ -181,11 +181,11 @@ 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 validTreatmentDurationReceived = FALSE; ///< Flag indicates valid treatment duration was validated. -static U32 validatedTreatmentDuration_min = 0U; ///< Last validated treatment duration in minutes. -static F32 validatedUFVolumeGoalL = 0.0F; ///< Last validated UF volume goal in L. -static F32 validatedUFRateLhr = 0.0F; ///< Last validated UF rate in L/hr. -static BOOL validUFVolumeReceived = FALSE; ///< Flag indicates valid UF volume was validated. +static BOOL validTreatmentDurationReceived; ///< Flag indicates valid treatment duration was validated. +static U32 validatedTreatmentDuration_min; ///< Last validated treatment duration in minutes. +static F32 validatedUFVolumeGoalL; ///< Last validated UF volume goal in L. +static F32 validatedUFRateLhr; ///< Last validated UF rate in L/hr. +static BOOL validUFVolumeReceived; ///< Flag indicates valid UF volume was validated. // ********** private function prototypes ********** @@ -198,11 +198,11 @@ 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 BOOL isPressureLimitValueValid( S32 value, S32 minValue, S32 maxValue ); -static BOOL isArterialPressureLimitWindowValid( S32 value ); -static BOOL isVenousPressureLimitWindowValid( S32 value ); -static BOOL isVenousAsymmetricPressureLimitWindowValid( S32 value ); -static BOOL isTmpPressureLimitWindowValid( S32 value ); +static BOOL isPressureLimitValueValid( U32 value, U32 minValue, U32 maxValue ); +static BOOL isArterialPressureLimitWindowValid( U32 value ); +static BOOL isVenousPressureLimitWindowValid( U32 value ); +static BOOL isVenousAsymmetricPressureLimitWindowValid( U32 value ); +static BOOL isTmpPressureLimitWindowValid( U32 value ); //static void getInstitutionalRecordEdgeValue( TREATMENT_PARAM_T param, CRITICAL_DATAS_T* value, BOOL isMin ); @@ -403,7 +403,7 @@ U32 result = 1; // Validate parameter - if ( param <= NUM_OF_SYS_CONFIG_TREATMENT_PARAMS ) + if ( param < NUM_OF_SYS_CONFIG_TREATMENT_PARAMS ) { CRITICAL_DATAS_T data = getCriticalData( &sysConfigTreatmentParameters[ param ] ); @@ -433,6 +433,35 @@ /*********************************************************************//** * @brief + * The setSysConfigTreatmentParameterU32 function sets a given unsigned + * integer system configured treatment parameter. + * @details \b Inputs: parameter ID and value to set + * @details \b Outputs: updated system configured treatment parameter value + * @param param ID of system configured treatment parameter to set + * @param value unsigned integer value to set + * @return TRUE if parameter updated successfully, FALSE otherwise + *************************************************************************/ +BOOL setSysConfigTreatmentParameterU32( SYS_CONFIG_TREATMENT_PARAM_T param, U32 value ) +{ + BOOL result = FALSE; + + if ( param < NUM_OF_SYS_CONFIG_TREATMENT_PARAMS ) + { + CRITICAL_DATAS_T data = getCriticalData( &sysConfigTreatmentParameters[ param ] ); + + data.uInt = value; + result = setCriticalData( &sysConfigTreatmentParameters[ 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 validateAndSetTreatmentParameters function validates received * treatment parameters. * @details \b Message \b Sent: MSG_ID_TD_RESP_TREATMENT_PARAMS_TO_VALIDATE @@ -471,7 +500,6 @@ // 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] ); @@ -839,8 +867,13 @@ *************************************************************************/ void resetTreatmentParameters( void ) { - validTreatParamsReceived = FALSE; - treatParamsConfirmed = FALSE; + validTreatParamsReceived = FALSE; + treatParamsConfirmed = FALSE; + validTreatmentDurationReceived = FALSE; + validatedTreatmentDuration_min = 0U; + validatedUFVolumeGoalL = 0.0F; + validatedUFRateLhr = 0.0F; + validUFVolumeReceived = FALSE; resetAllTreatmentParameters(); } @@ -974,10 +1007,22 @@ *************************************************************************/ BOOL isTreatmentParamInRange( TREATMENT_PARAM_T param, CRITICAL_DATAS_T value ) { - BOOL result = TRUE; // TODO FALSE; + BOOL result = FALSE; if ( param < NUM_OF_TREATMENT_PARAMS ) { + if ( CRITICAL_DATA_TYPE_U32 == TREAT_PARAMS_PROPERTIES[ param ].dataType ) + { + result = ( ( value.uInt >= TREAT_PARAMS_PROPERTIES[ param ].min.uInt ) && + ( value.uInt <= TREAT_PARAMS_PROPERTIES[ param ].max.uInt ) ? TRUE : FALSE ); + } + else + { + result = ( ( value.sFlt >= TREAT_PARAMS_PROPERTIES[ param ].min.sFlt ) && + ( value.sFlt <= TREAT_PARAMS_PROPERTIES[ param ].max.sFlt ) ? TRUE : FALSE ); + } + } + // switch( param ) // { // case TREATMENT_PARAM_TREATMENT_MODALITY: @@ -1107,7 +1152,7 @@ // } //#endif // } - } + else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_PARAM, (U32)param ) @@ -1422,17 +1467,13 @@ /*********************************************************************//** * @brief - * The validateAndSetTreatmentDuration function handles the UI treatment - * duration validation request during Treatment mode. - * @details \b Message \b Sent: - * MSG_ID_TD_DURATION_VALIDATE_RESPONSE including acceptance - * status, rejection reason, requested duration, UF volume goal - * (L), and calculated UF rate (L/hr). - * @details \b Inputs: - * message containing requested treatment duration (minutes). - * @details \b Outputs: - * validated treatment duration and UF rate stored for - * confirmation. + * The validateAndSetTreatmentDuration function handles the UI treatment duration validation request during Treatment mode. + * @details \b Message \b Sent: MSG_ID_TD_DURATION_VALIDATE_RESPONSE including acceptance status, rejection reason, + * requested duration, UF volume goal (L), and calculated UF rate (L/hr). + * @details \b Inputs: message, request.duration, presUFVolumeMl, elapsedTreatmentTimeMin, measuredUFVolumeMl, + * remainingUFVolumeMl, minDuration, maxDuration. + * @details \b Outputs: response, validTreatmentDurationReceived, validatedTreatmentDuration_min, validatedUFRateLhr. + * @param message set message from UI which includes the requested treatment duration in minutes. * @return TRUE if response message is sent successfully, FALSE otherwise. *************************************************************************/ BOOL validateAndSetTreatmentDuration( MESSAGE_T *message ) @@ -1517,13 +1558,11 @@ /*********************************************************************//** * @brief - * The validateAndSetBolusVolume function handles the UI fluid bolus - * volume change request during Treatment mode. - * @details \b Message \b Sent: - * MSG_ID_TD_BOLUS_VOLUME_CHANGE_RESPONSE including acceptance - * status and rejection reason. - * @details \b Inputs: - * message containing requested bolus volume. + * The validateAndSetBolusVolume function handles the UI fluid bolus volume change request during Treatment mode. + * @details \b Message \b Sent: MSG_ID_TD_BOLUS_VOLUME_CHANGE_RESPONSE including acceptance status and rejection reason. + * @details \b Inputs: message, request.bolusVolume, minBolusVolume_mL, maxBolusVolume_mL. + * @details \b Outputs: response. + * @param message set message from UI which includes the requested bolus volume. * @return TRUE if response message is sent successfully, FALSE otherwise. *************************************************************************/ BOOL validateAndSetBolusVolume( MESSAGE_T *message ) @@ -1562,15 +1601,11 @@ /*********************************************************************//** * @brief - * The pressureLimitHandleChangeRequest function handles the UI pressure - * limit change request during Treatment mode. - * @details \b Message \b Sent: - * MSG_ID_TD_PRESSURE_LIMITS_CHANGE_RESPONSE - * @details \b Inputs: message containing requested pressure limit - * window values. - * @details \b Outputs: response updated with acceptance status and - * per-parameter rejection reasons. When accepted, treatment - * parameters are updated and pressure limits recalculated. + * The pressureLimitHandleChangeRequest function handles the UI pressure limit change request during Treatment mode. + * @details \b Message \b Sent: MSG_ID_TD_PRESSURE_LIMITS_CHANGE_RESPONSE including acceptance status and per-parameter rejection reasons. + * @details \b Inputs: message, request.arterialPressureLimitWindowMMHG, request.venousPressureLimitWindowMMHG, + * request.venousAsymmetricPressureLimitWindowMMHG, request.tmpPressureLimitWindowMMHG. + * @details \b Outputs: response. * @return TRUE if response message is sent successfully, FALSE otherwise. *************************************************************************/ BOOL pressureLimitHandleChangeRequest( MESSAGE_T *message ) @@ -1627,13 +1662,13 @@ if ( TRUE == accepted ) { - setTreatmentParameterU32( TREATMENT_PARAM_ART_PRES_LIMIT_WINDOW, request.arterialPressureLimitWindowMMHG ); + setSysConfigTreatmentParameterU32( TREATMENT_PARAM_ART_PRES_LIMIT_WINDOW, request.arterialPressureLimitWindowMMHG ); - setTreatmentParameterU32( TREATMENT_PARAM_VEN_PRES_LIMIT_WINDOW, request.venousPressureLimitWindowMMHG ); + setSysConfigTreatmentParameterU32( TREATMENT_PARAM_VEN_PRES_LIMIT_WINDOW, request.venousPressureLimitWindowMMHG ); - setTreatmentParameterU32( TREATMENT_PARAM_VEN_PRES_LIMIT_ASYMMETRIC, request.venousAsymmetricPressureLimitWindowMMHG ); + setSysConfigTreatmentParameterU32( TREATMENT_PARAM_VEN_PRES_LIMIT_ASYMMETRIC, request.venousAsymmetricPressureLimitWindowMMHG ); - setTreatmentParameterU32( TREATMENT_PARAM_TMP_PRES_LIMIT_WINDOW, request.tmpPressureLimitWindowMMHG ); + setSysConfigTreatmentParameterU32( TREATMENT_PARAM_TMP_PRES_LIMIT_WINDOW, request.tmpPressureLimitWindowMMHG ); updatePressureLimitWindows(); } @@ -1651,112 +1686,106 @@ * The isPressureLimitValueValid function checks whether a pressure limit * value is within the specified range. * @details \b Inputs: value, minValue, maxValue. - * @details \b Outputs: none. + * @details \b Outputs: None. * @return TRUE if value is valid, FALSE otherwise. *************************************************************************/ -static BOOL isPressureLimitValueValid( S32 value, S32 minValue, S32 maxValue ) +static BOOL isPressureLimitValueValid( U32 value, U32 minValue, U32 maxValue ) { return ( ( value >= minValue ) && ( value <= maxValue ) ); } /*********************************************************************//** * @brief - * Validates the arterial pressure limit window value. - * @details This function checks whether the provided arterial pressure - * limit window value is within the allowable range defined in - * treatment parameter limits. + * The isArterialPressureLimitWindowValid function validates the arterial + * pressure limit window value. + * @details \b Inputs: value. + * @details \b Outputs: pressureValid. * @param value Arterial pressure limit window value (mmHg). * @return TRUE if the value is within valid range, FALSE otherwise. *************************************************************************/ -static BOOL isArterialPressureLimitWindowValid( S32 value ) +static BOOL isArterialPressureLimitWindowValid( U32 value ) { BOOL pressureValid; pressureValid = isPressureLimitValueValid( value, - (S32)getU32SysConfigTreatmentParamLowerRangeLimit( TREATMENT_PARAM_ART_PRES_LIMIT_WINDOW ), - (S32)getU32SysConfigTreatmentParamUpperRangeLimit( TREATMENT_PARAM_ART_PRES_LIMIT_WINDOW ) ); + getU32SysConfigTreatmentParamLowerRangeLimit( TREATMENT_PARAM_ART_PRES_LIMIT_WINDOW ), + getU32SysConfigTreatmentParamUpperRangeLimit( TREATMENT_PARAM_ART_PRES_LIMIT_WINDOW ) ); return pressureValid; } /*********************************************************************//** * @brief - * Validates the venous pressure limit window value. - * @details This function checks whether the provided venous pressure - * limit window value is within the allowable range defined in - * treatment parameter limits. + * The isVenousPressureLimitWindowValid function validates the venous + * pressure limit window value. + * @details \b Inputs: value. + * @details \b Outputs: pressureValid. * @param value Venous pressure limit window value (mmHg). * @return TRUE if the value is within valid range, FALSE otherwise. *************************************************************************/ -static BOOL isVenousPressureLimitWindowValid( S32 value ) +static BOOL isVenousPressureLimitWindowValid( U32 value ) { BOOL pressureValid; pressureValid = isPressureLimitValueValid( value, - (S32)getU32SysConfigTreatmentParamLowerRangeLimit( TREATMENT_PARAM_VEN_PRES_LIMIT_WINDOW ), - (S32)getU32SysConfigTreatmentParamUpperRangeLimit( TREATMENT_PARAM_VEN_PRES_LIMIT_WINDOW ) ); + getU32SysConfigTreatmentParamLowerRangeLimit( TREATMENT_PARAM_VEN_PRES_LIMIT_WINDOW ), + getU32SysConfigTreatmentParamUpperRangeLimit( TREATMENT_PARAM_VEN_PRES_LIMIT_WINDOW ) ); return pressureValid; } /*********************************************************************//** * @brief - * Validates the venous asymmetric pressure limit window value. - * @details This function checks whether the provided venous asymmetric - * pressure limit window value is within the allowable range - * defined in treatment parameter limits. + * The isVenousAsymmetricPressureLimitWindowValid function validates the + * venous asymmetric pressure limit window value. + * @details \b Inputs: value. + * @details \b Outputs: pressureValid. * @param value Venous asymmetric pressure limit window value (mmHg). * @return TRUE if the value is within valid range, FALSE otherwise. *************************************************************************/ -static BOOL isVenousAsymmetricPressureLimitWindowValid( S32 value ) +static BOOL isVenousAsymmetricPressureLimitWindowValid( U32 value ) { BOOL pressureValid; pressureValid = isPressureLimitValueValid( value, - (S32)getU32SysConfigTreatmentParamLowerRangeLimit( TREATMENT_PARAM_VEN_PRES_LIMIT_ASYMMETRIC ), - (S32)getU32SysConfigTreatmentParamUpperRangeLimit( TREATMENT_PARAM_VEN_PRES_LIMIT_ASYMMETRIC ) ); + getU32SysConfigTreatmentParamLowerRangeLimit( TREATMENT_PARAM_VEN_PRES_LIMIT_ASYMMETRIC ), + getU32SysConfigTreatmentParamUpperRangeLimit( TREATMENT_PARAM_VEN_PRES_LIMIT_ASYMMETRIC ) ); return pressureValid; } /*********************************************************************//** * @brief - * Validates the TMP pressure limit window value. - * @details This function checks whether the provided TMP pressure - * limit window value is within the allowable range defined in - * treatment parameter limits. + * The isTmpPressureLimitWindowValid function validates the TMP pressure + * limit window value. + * @details \b Inputs: value. + * @details \b Outputs: pressureValid. * @param value TMP pressure limit window value (mmHg). * @return TRUE if the value is within valid range, FALSE otherwise. *************************************************************************/ -static BOOL isTmpPressureLimitWindowValid( S32 value ) +static BOOL isTmpPressureLimitWindowValid( U32 value ) { BOOL pressureValid; pressureValid = isPressureLimitValueValid( value, - (S32)getU32SysConfigTreatmentParamLowerRangeLimit( TREATMENT_PARAM_TMP_PRES_LIMIT_WINDOW ), - (S32)getU32SysConfigTreatmentParamUpperRangeLimit( TREATMENT_PARAM_TMP_PRES_LIMIT_WINDOW ) ); + getU32SysConfigTreatmentParamLowerRangeLimit( TREATMENT_PARAM_TMP_PRES_LIMIT_WINDOW ), + getU32SysConfigTreatmentParamUpperRangeLimit( TREATMENT_PARAM_TMP_PRES_LIMIT_WINDOW ) ); return pressureValid; } /*********************************************************************//** * @brief - * The validateAndSetUFVolume function validates the received ultrafiltration - * volume treatment parameter. - * @details \b Message \b Sent: - * MSG_ID_TD_RESP_ULTRAFILTRATION_VOLUME_TO_VALIDATE including - * acceptance status, rejection reason, UF volume goal (L), - * duration (minutes), and UF rate (L/hr). - * @details \b Inputs: - * message containing requested UF volume in L. - * @details \b Outputs: - * validated UF volume and UF rate stored for confirmation. - * @param message Set message from UI which includes the requested UF volume - * in L. + * The validateAndSetUFVolume function handles the UI ultrafiltration volume validation request during Treatment mode. + * @details \b Message \b Sent: MSG_ID_TD_RESP_ULTRAFILTRATION_VOLUME_TO_VALIDATE including acceptance status, rejection reason, UF volume goal (L), duration (minutes), and UF rate (L/hr). + * @details \b Inputs: message, request.ufVolume, elapsedTreatmentTimeMin, measuredUFVolumeMl, treatmentDurationMin, + * requestedUFVolumeMl, requestedUFVolumeL, remainingUFVolumeMl, remainingTreatmentTimeMin, newUfRateMlMin, minUFVolumeL, maxUFVolumeL. + * @details \b Outputs: response, validUFVolumeReceived, validatedUFVolumeGoalL, validatedUFRateLhr. + * @param message set message from UI which includes the requested UF volume in L. * @return TRUE if response message is sent successfully, FALSE otherwise. *************************************************************************/ BOOL validateAndSetUFVolume( MESSAGE_T *message ) @@ -1851,18 +1880,271 @@ /*********************************************************************//** * @brief - * The signalUserConfirmationOfTreatmentDuration function handles the UI - * treatment duration confirmation request during Treatment mode. - * @details \b Message \b Sent: - * MSG_ID_TD_DURATION_CONFIRM_RESPONSE including acceptance - * status, rejection reason, duration (minutes), UF volume goal - * (L), and UF rate (L/hr). - * @details \b Inputs: - * message containing confirmed treatment duration and UF rate. - * @details \b Outputs: - * validated duration and UF rate cleared after confirmation. + * The validateAndSetTreatmentSetPoints function handles a UI treatment set point change request during Treatment mode. + * @details \b Message \b Sent: MSG_ID_TD_TREATMENT_SET_POINTS_CHANGE_RESPONSE including acceptance status and rejection reason for each treatment set point parameter. + * @details \b Inputs: message, request, requestedValue, isValid. + * @details \b Outputs: response. + * @param message set message from UI which includes the requested treatment set point values. * @return TRUE if response message is sent successfully, FALSE otherwise. *************************************************************************/ +BOOL validateAndSetTreatmentSetPoints( MESSAGE_T *message ) +{ + BOOL result = FALSE; + BOOL isValid = TRUE; + CRITICAL_DATAS_T requestedValue; + TREATMENT_PARAMETER_EDIT_REQUEST_T request; + TREATMENT_SET_POINTS_CHANGE_RESPONSE_T response; + + memset( &requestedValue, 0, sizeof( requestedValue ) ); + memset( &request, 0, sizeof( request ) ); + memset( &response, 0, sizeof( response ) ); + + if ( message->hdr.payloadLen == sizeof( request ) ) + { + memcpy( &request, message->payload, sizeof( TREATMENT_PARAMETER_EDIT_REQUEST_T ) ); + + requestedValue.uInt = request.treatmentModality; + if ( FALSE == isTreatmentParamInRange( TREATMENT_PARAM_TREATMENT_MODALITY, requestedValue ) ) + { + response.rejectionReason[ TREATMENT_SETPOINT_TREATMENT_MODALITY ] = REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE; + isValid = FALSE; + } + + requestedValue.uInt = request.bloodFlowRate; + if ( FALSE == isTreatmentParamInRange( TREATMENT_PARAM_BLOOD_FLOW, requestedValue ) ) + { + response.rejectionReason[ TREATMENT_SETPOINT_BLOOD_FLOW ] = REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE; + isValid = FALSE; + } + + requestedValue.uInt = request.dialysateFlowRate; + if ( FALSE == isTreatmentParamInRange( TREATMENT_PARAM_DIALYSATE_FLOW, requestedValue ) ) + { + response.rejectionReason[ TREATMENT_SETPOINT_DIALYSATE_FLOW ] = REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE; + isValid = FALSE; + } + + requestedValue.sFlt = request.dialysateTemperature; + if ( FALSE == isTreatmentParamInRange( TREATMENT_PARAM_DIALYSATE_TEMPERATURE, requestedValue ) ) + { + response.rejectionReason[ TREATMENT_SETPOINT_DIALYSATE_TEMPERATURE ] = REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE; + isValid = FALSE; + } + + requestedValue.uInt = request.hepatitis; + if ( FALSE == isTreatmentParamInRange( TREATMENT_PARAM_HEPATITIS_B, requestedValue ) ) + { + response.rejectionReason[ TREATMENT_SETPOINT_HEPATITIS_STATUS ] = REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE; + isValid = FALSE; + } + + requestedValue.uInt = request.acidConcentrate; + if ( FALSE == isTreatmentParamInRange( TREATMENT_PARAM_ACID_CONCENTRATE, requestedValue ) ) + { + response.rejectionReason[ TREATMENT_SETPOINT_ACID_CONCENTRATE ] = REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE; + isValid = FALSE; + } + + requestedValue.sFlt = request.acidConcentrateConversionFactor; + if ( FALSE == isTreatmentParamInRange( TREATMENT_PARAM_ACID_CONCENTRATE_CONV_FACTOR, requestedValue ) ) + { + response.rejectionReason[ TREATMENT_SETPOINT_ACID_CONVERSION_FACTOR ] = REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE; + isValid = FALSE; + } + + requestedValue.uInt = request.bicarbonateConcentrate; + if ( FALSE == isTreatmentParamInRange( TREATMENT_PARAM_DRY_BICARB_CART_SIZE, requestedValue ) ) + { + response.rejectionReason[ TREATMENT_SETPOINT_BICARB_CONCENTRATE ] = REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE; + isValid = FALSE; + } + + requestedValue.uInt = request.sodium; + if ( FALSE == isTreatmentParamInRange( TREATMENT_PARAM_SODIUM, requestedValue ) ) + { + response.rejectionReason[ TREATMENT_SETPOINT_SODIUM ] = REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE; + isValid = FALSE; + } + + requestedValue.uInt = request.bicarbonate; + if ( FALSE == isTreatmentParamInRange( TREATMENT_PARAM_BICARBONATE, requestedValue ) ) + { + response.rejectionReason[ TREATMENT_SETPOINT_BICARBONATE ] = REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE; + isValid = FALSE; + } + + if ( TRUE == isValid ) + { + setTreatmentParameterU32( TREATMENT_PARAM_TREATMENT_MODALITY, request.treatmentModality ); + setTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW, request.bloodFlowRate ); + setTreatmentParameterU32( TREATMENT_PARAM_DIALYSATE_FLOW, request.dialysateFlowRate ); + setTreatmentParameterF32( TREATMENT_PARAM_DIALYSATE_TEMPERATURE, request.dialysateTemperature ); + setTreatmentParameterU32( TREATMENT_PARAM_HEPATITIS_B, request.hepatitis ); + setTreatmentParameterU32( TREATMENT_PARAM_ACID_CONCENTRATE, request.acidConcentrate ); + setTreatmentParameterF32( TREATMENT_PARAM_ACID_CONCENTRATE_CONV_FACTOR, request.acidConcentrateConversionFactor ); + setTreatmentParameterU32( TREATMENT_PARAM_DRY_BICARB_CART_SIZE, request.bicarbonateConcentrate ); + setTreatmentParameterU32( TREATMENT_PARAM_SODIUM, request.sodium ); + setTreatmentParameterU32( TREATMENT_PARAM_BICARBONATE, request.bicarbonate ); + + response.accepted = TRUE; + } + } + else + { + response.rejectionReason[ TREATMENT_SETPOINT_BLOOD_FLOW ] = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + + result = sendMessage( MSG_ID_TD_TREATMENT_SET_POINTS_CHANGE_RESPONSE, COMM_BUFFER_OUT_CAN_TD_2_UI, (U08 *)&response, sizeof( TREATMENT_SET_POINTS_CHANGE_RESPONSE_T ) ); + + return result; +} + +/*********************************************************************//** + * @brief + * The validateAndSetBloodFlowRate function handles a UI treatment set point blood flow rate change request during Treatment mode. + * @details \b Message \b Sent: MSG_ID_TD_TREATMENT_SET_POINT_BLOOD_FLOW_CHANGE_RESPONSE including acceptance status and rejection reason. + * @details \b Inputs: message, request.flowRate, requestedValue. + * @details \b Outputs: response. + * @param message set message from UI which includes the requested blood flow rate. + * @return TRUE if response message is sent successfully, FALSE otherwise. + *************************************************************************/ +BOOL validateAndSetBloodFlowRate( MESSAGE_T *message ) +{ + BOOL result = FALSE; + CRITICAL_DATAS_T requestedValue; + BLOOD_FLOW_RATE_CHANGE_REQUEST_PAYLOAD_T request; + BLOOD_FLOW_RATE_CHANGE_RESPONSE_PAYLOAD_T response; + + memset( &requestedValue, 0, sizeof( requestedValue ) ); + memset( &request, 0, sizeof( request ) ); + memset( &response, 0, sizeof( response ) ); + + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + + if ( message->hdr.payloadLen == sizeof( BLOOD_FLOW_RATE_CHANGE_REQUEST_PAYLOAD_T ) ) + { + memcpy( &request, &message->payload[ 0 ], sizeof( BLOOD_FLOW_RATE_CHANGE_REQUEST_PAYLOAD_T ) ); + + requestedValue.uInt = request.flowRate; + + if ( TRUE == isTreatmentParamInRange( TREATMENT_PARAM_BLOOD_FLOW, requestedValue ) ) + { + setTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW, request.flowRate ); + + response.accepted = TRUE; + response.rejectionReason = REQUEST_REJECT_REASON_NONE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE; + } + } + + result = sendMessage( MSG_ID_TD_TREATMENT_SET_POINT_BLOOD_FLOW_CHANGE_RESPONSE, COMM_BUFFER_OUT_CAN_TD_2_UI, (U08 *)&response, sizeof( BLOOD_FLOW_RATE_CHANGE_RESPONSE_PAYLOAD_T ) ); + + return result; +} + +/*********************************************************************//** + * @brief + * The validateAndSetDialysateFlowRate function handles a UI treatment set point dialysate flow rate change request during Treatment mode. + * @details \b Message \b Sent: MSG_ID_TD_TREATMENT_SET_POINT_DIALYSATE_FLOW_CHANGE_RESPONSE including acceptance status and rejection reason. + * @details \b Inputs: message, request.flowRate, requestedValue. + * @details \b Outputs: response. + * @param message set message from UI which includes the requested dialysate flow rate. + * @return TRUE if response message is sent successfully, FALSE otherwise. + *************************************************************************/ +BOOL validateAndSetDialysateFlowRate( MESSAGE_T *message ) +{ + BOOL result = FALSE; + CRITICAL_DATAS_T requestedValue; + DIALYSATE_FLOW_RATE_CHANGE_REQUEST_PAYLOAD_T request; + DIALYSATE_FLOW_RATE_CHANGE_RESPONSE_PAYLOAD_T response; + + memset( &requestedValue, 0, sizeof( requestedValue ) ); + memset( &request, 0, sizeof( request ) ); + memset( &response, 0, sizeof( response ) ); + + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + + if ( message->hdr.payloadLen == sizeof( DIALYSATE_FLOW_RATE_CHANGE_REQUEST_PAYLOAD_T ) ) + { + memcpy( &request, &message->payload[ 0 ], sizeof( DIALYSATE_FLOW_RATE_CHANGE_REQUEST_PAYLOAD_T ) ); + + requestedValue.uInt = request.flowRate; + + if ( TRUE == isTreatmentParamInRange( TREATMENT_PARAM_DIALYSATE_FLOW, requestedValue ) ) + { + setTreatmentParameterU32( TREATMENT_PARAM_DIALYSATE_FLOW, request.flowRate ); + + response.accepted = TRUE; + response.rejectionReason = REQUEST_REJECT_REASON_NONE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE; + } + } + + result = sendMessage( MSG_ID_TD_TREATMENT_SET_POINT_DIALYSATE_FLOW_CHANGE_RESPONSE, COMM_BUFFER_OUT_CAN_TD_2_UI, (U08 *)&response, sizeof( DIALYSATE_FLOW_RATE_CHANGE_RESPONSE_PAYLOAD_T ) ); + + return result; +} + +/*********************************************************************//** + * @brief + * The validateAndSetDialysateTemperature function handles a UI treatment set point dialysate temperature change request during Treatment mode. + * @details \b Message \b Sent: MSG_ID_TD_TREATMENT_SET_POINT_DIALYSATE_TEMPERATURE_CHANGE_RESPONSE including acceptance status and rejection reason. + * @details \b Inputs: message, request.temperature, requestedValue. + * @details \b Outputs: response. + * @param message set message from UI which includes the requested dialysate temperature. + * @return TRUE if response message is sent successfully, FALSE otherwise. + *************************************************************************/ +BOOL validateAndSetDialysateTemperature( MESSAGE_T *message ) +{ + BOOL result = FALSE; + CRITICAL_DATAS_T requestedValue; + DIALYSATE_TEMPERATURE_CHANGE_REQUEST_PAYLOAD_T request; + DIALYSATE_TEMPERATURE_CHANGE_RESPONSE_PAYLOAD_T response; + + memset( &requestedValue, 0, sizeof( requestedValue ) ); + memset( &request, 0, sizeof( request ) ); + memset( &response, 0, sizeof( response ) ); + + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + + if ( message->hdr.payloadLen == sizeof( DIALYSATE_TEMPERATURE_CHANGE_REQUEST_PAYLOAD_T ) ) + { + memcpy( &request, &message->payload[ 0 ], sizeof( DIALYSATE_TEMPERATURE_CHANGE_REQUEST_PAYLOAD_T ) ); + + requestedValue.sFlt = request.temperature; + + if ( TRUE == isTreatmentParamInRange( TREATMENT_PARAM_DIALYSATE_TEMPERATURE, requestedValue ) ) + { + setTreatmentParameterF32( TREATMENT_PARAM_DIALYSATE_TEMPERATURE, request.temperature ); + + response.accepted = TRUE; + response.rejectionReason = REQUEST_REJECT_REASON_NONE; + } + else + { + response.rejectionReason = REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE; + } + } + + result = sendMessage( MSG_ID_TD_TREATMENT_SET_POINT_DIALYSATE_TEMPERATURE_CHANGE_RESPONSE, COMM_BUFFER_OUT_CAN_TD_2_UI, (U08 *)&response, sizeof( DIALYSATE_TEMPERATURE_CHANGE_RESPONSE_PAYLOAD_T ) ); + + return result; +} + +/*********************************************************************//** + * @brief + * The signalUserConfirmationOfTreatmentDuration function handles the UI treatment duration confirmation request during Treatment mode. + * @details \b Message \b Sent: MSG_ID_TD_DURATION_CONFIRM_RESPONSE including acceptance status, rejection reason, duration (minutes), UF volume goal (L), and UF rate (L/hr). + * @details \b Inputs: message, request.duration, request.ufRate, presUFVolumeMl, validatedUFRateMlMin. + * @details \b Outputs: response, validTreatmentDurationReceived, validatedTreatmentDuration_min, validatedUFRateLhr. + * @return TRUE if response message is sent successfully, FALSE otherwise. + *************************************************************************/ BOOL signalUserConfirmationOfTreatmentDuration( MESSAGE_T *message ) { BOOL result = FALSE; @@ -1886,7 +2168,9 @@ response.ufVolumeGoal = presUFVolumeMl / (F32)ML_PER_LITER; response.ufRate = validatedUFRateLhr; - if ( ( TRUE == validTreatmentDurationReceived ) && ( request.duration == validatedTreatmentDuration_min ) && ( fabs( request.ufRate - validatedUFRateLhr ) < NEARLY_ZERO ) ) + // Verify confirmed duration and UF rate match previously validated values. + if ( ( TRUE == validTreatmentDurationReceived ) && ( request.duration == validatedTreatmentDuration_min ) && + ( fabs( request.ufRate - validatedUFRateLhr ) < NEARLY_ZERO ) ) { setTreatmentParameterU32( TREATMENT_PARAM_TREATMENT_DURATION, validatedTreatmentDuration_min ); setDialysisDDParams( getTreatmentParameterU32( TREATMENT_PARAM_DIALYSATE_FLOW ), presUFVolumeMl, validatedUFRateMlMin ); @@ -1916,18 +2200,11 @@ /*********************************************************************//** * @brief - * The signalUserConfirmationOfUFVolume function handles the UI - * confirmation request for ultrafiltration (UF) volume change. - * @details \b Message \b Sent: - * MSG_ID_TD_ULTRAFILTRATION_CHANGE_VALIDATE_RESPONSE including - * acceptance status, rejection reason, UF volume goal (L), - * duration (minutes), and UF rate (L/hr). - * @details \b Inputs: - * message containing confirmed UF volume and UF rate. - * @details \b Outputs: - * validated UF volume and UF rate cleared after confirmation. - * @param message set message from UI which includes the confirmed - * ultrafiltration volume and UF rate. + * The signalUserConfirmationOfUFVolume function handles the UI ultrafiltration volume confirmation request during Treatment mode. + * @details \b Message \b Sent: MSG_ID_TD_ULTRAFILTRATION_CHANGE_VALIDATE_RESPONSE including acceptance status, rejection reason, UF volume goal (L), duration (minutes), and UF rate (L/hr). + * @details \b Inputs: message, request.ufVolume, request.ufRate, validatedUFVolumeGoalMl, validatedUFRateMlMin. + * @details \b Outputs: response, validUFVolumeReceived, validatedUFVolumeGoalL, validatedUFRateLhr. + * @param message set message from UI which includes the confirmed UF volume and UF rate. * @return TRUE if response message is sent successfully, FALSE otherwise. *************************************************************************/ BOOL signalUserConfirmationOfUFVolume( MESSAGE_T *message ) @@ -1956,7 +2233,9 @@ validatedUFVolumeGoalMl = validatedUFVolumeGoalL * (F32)ML_PER_LITER; validatedUFRateMlMin = ( validatedUFRateLhr * (F32)ML_PER_LITER ) / (F32)MIN_PER_HOUR; - if ( ( TRUE == validUFVolumeReceived ) && ( fabs( request.ufVolume - validatedUFVolumeGoalL ) < NEARLY_ZERO ) && ( fabs( request.ufRate - validatedUFRateLhr ) < NEARLY_ZERO ) ) + // Verify confirmed UF volume and UF rate match previously validated values. + if ( ( TRUE == validUFVolumeReceived ) && ( fabs( request.ufVolume - validatedUFVolumeGoalL ) < NEARLY_ZERO ) && + ( fabs( request.ufRate - validatedUFRateLhr ) < NEARLY_ZERO ) ) { setTreatmentParameterF32( TREATMENT_PARAM_UF_VOLUME, validatedUFVolumeGoalL );