Index: sources/StateController.cpp =================================================================== diff -u -r6e0ddbfa4863bb12a64dfde5baeada941acadaf8 -r13f1a9b24d08848b27c8e345c21d0e540c0b78de --- sources/StateController.cpp (.../StateController.cpp) (revision 6e0ddbfa4863bb12a64dfde5baeada941acadaf8) +++ sources/StateController.cpp (.../StateController.cpp) (revision 13f1a9b24d08848b27c8e345c21d0e540c0b78de) @@ -1172,7 +1172,9 @@ msg.append(10.2); msg.append(12.3); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); + _isBroadcastListReady = false; _broadcastMessages.append(msg); + _isBroadcastListReady = true; } void StateController::prepareTreatmentTimeBroadcastData() @@ -1246,8 +1248,8 @@ QVariantList msg; msg.append(static_cast(ID_DIALYSATE_OUT_FLOW_DATA_BC)); msg.append(Can_Id::eChlid_HD_Sync); - msg.append(2.0); - msg.append(0.3); + msg.append(_treatmentVars.refUFVolumeML); + msg.append(_treatmentVars.measUFVolumeML); msg.append(0.0); msg.append(0.0); msg.append(0.0); msg.append(0.0); msg.append(0.0); msg.append(0.0); msg.append(0.0); msg.append(0.0); msg.append(0); msg.append(0.0); msg.append(0); @@ -1264,30 +1266,32 @@ float maxQdMLPM = 0.0; if (_treatmentVars.treatmentElapsedTimeS > 0) { - maxQdMLPM = (MAX_DIALYSATE_VOLUME_ML - dialVolumeSoFarML) / (_treatmentVars.treatmentElapsedTimeS / SECONDS_PER_MINUTE); + maxQdMLPM = (MAX_DIALYSATE_VOLUME_ML - dialVolumeSoFarML) / (_treatmentVars.remainingTreatmentTimeS / SECONDS_PER_MINUTE); } quint32 minTimeMins = qMax(elapsedTimeMins + 2, (quint32)MIN_TX_TIME_MINS); float prescribedUF = (_treatmentVars.prescribedUFRate > 0.0 ? _treatmentVars.prescribedUFRate : 1); quint32 maxTimeRemMins = (MAX_UF_VOL_ML - _treatmentVars.refUFVolumeML) / prescribedUF; quint32 maxTime1 = minTimeMins + maxTimeRemMins; quint32 maxTime2 = MAX_DIAL_RATE_MLPM / _treatmentParams.dialysateFlowRateMLPM; quint32 maxTimeMins = qMax(maxTime1, maxTime2); - qDebug() << "Ranges Values" << minTimeMins << maxTimeRemMins << maxTime2 << maxTimeMins; + qDebug() << "Time Ranges Values" << minTimeMins << maxTimeRemMins << maxTime2 << maxTimeMins << _treatmentVars.prescribedUFRate; float minUFVolML = _treatmentVars.refUFVolumeML + _treatmentVars.prescribedUFRate; - float maxUFVol1 = minUFVolML + (_treatmentParams.txDurationMins - elapsedTimeMins) * MAX_UF_RATE_MLPM; + float maxUFVol1 = minUFVolML + ((_treatmentParams.txDurationMins - elapsedTimeMins) * MAX_UF_RATE_MLPM); float maxUFVol2 = minUFVolML; if (_treatmentVars.prescribedUFRate > 0.0 ) { maxUFVol2 = minUFVolML + (MAX_TX_TIME_MINS - elapsedTimeMins - 1) * _treatmentVars.prescribedUFRate; } - float maxUFVol = qMax(maxUFVol1, maxUFVol2); + float maxUFVol = qMax(maxUFVol1, maxUFVol2); quint32 minDialFlowRateMLPM = MIN_DIAL_RATE_MLPM; quint32 maxDialFlowRateMLPM = (maxQdMLPM > MIN_DIAL_RATE_MLPM ? maxQdMLPM : minDialFlowRateMLPM); - maxTimeMins = qMin(maxTimeMins, (quint32)MAX_TX_TIME_MINS) ; - maxUFVol = qMin(maxUFVol, (float)MAX_UF_VOL_ML); + maxTimeMins = qMin(maxTimeMins, (quint32)MAX_TX_TIME_MINS) ; + maxUFVol = qMin(maxUFVol, (float)MAX_UF_VOL_ML); maxDialFlowRateMLPM = qMin(maxDialFlowRateMLPM, (quint32)MAX_DIAL_RATE_MLPM); + qDebug() << "New UF" << minUFVolML << maxUFVol1 << maxUFVol2 << maxUFVol << maxDialFlowRateMLPM; + QVariantList msg; msg.append(static_cast(ID_HD_TX_PARAMS_RANGES_DATA)); msg.append(Can_Id::eChlid_HD_Sync); @@ -1324,38 +1328,38 @@ Types::U32 txDurMinType; GetValue(payload.toByteArray(), IDIndex, txDurMinType); - quint32 txDurMin = txDurMinType.value; + quint32 txDurMin = txDurMinType.value; quint32 elapsedTimeMins = _treatmentVars.treatmentElapsedTimeS / SECONDS_PER_MINUTE; if ((txDurMin > elapsedTimeMins) && (txDurMin >= MIN_TX_TIME_MINS)) { float UFVolumeL = ((txDurMin - elapsedTimeMins) * _treatmentVars.prescribedUFRate) + _treatmentVars.refUFVolumeML; - UFVolumeL /= MILLILITERS_PER_LITER; + UFVolumeL /= MILLILITERS_PER_LITER; - // TODO from treatment params - quint32 dialVolume = _treatmentParams.dialysateFlowRateMLPM * txDurMin; - bool isMinTxTimeValid = (txDurMin >= MIN_TX_TIME_MINS ? true : false); - bool isTxTimeValid = (txDurMin <= DEF_TX_PARAM_PRESCRIBED_DUR_S ? true : false); - bool isMinUFVolValid = ((UFVolumeL >= 0.0) || (UFVolumeL <= 0.0) ? true : false); // TODO fix the UF Vol - bool isUFVolValid = (UFVolumeL <= DEF_TX_PARAM_UF_VOLUME_L ? true : false); + // Upper and lower range values are from #defines + quint32 dialVolume = _treatmentParams.dialysateFlowRateMLPM * txDurMin; + bool isMinTxTimeValid = (txDurMin >= MIN_TX_TIME_MINS ? true : false); + bool isTxTimeValid = (txDurMin <= MAX_TX_TIME_MINS ? true : false); + bool isMinUFVolValid = ((UFVolumeL >= MIN_UF_VOL_L) || (UFVolumeL <= 0.0) ? true : false); // TODO fix the UF Vol + bool isUFVolValid = (UFVolumeL <= MAX_UF_VOL_L ? true : false); qDebug() << "Test of tx" << _treatmentVars.prescribedUFRate << elapsedTimeMins << UFVolumeL << isUFVolValid; if (isMinTxTimeValid && isTxTimeValid && isMinUFVolValid && isUFVolValid && (dialVolume <= MAX_DIALYSATE_VOLUME_ML)) { _treatmentVars.prescribedTreatmentTimeS = txDurMin * SECONDS_PER_MINUTE; _treatmentVars.prescribedMaxUFVolML = UFVolumeL * MILLILITERS_PER_LITER; - accept = ACCEPT_VALUE; + accept = ACCEPT_VALUE; qDebug() << "New tx time" << txDurMin * SECONDS_PER_MINUTE << accept; } } - _isSendListReady = false; QVariantList resp; resp.append(static_cast(ID_USER_TX_TIME_CHANGES_RESP)); resp.append(Can_Id::eChlid_HD_UI); resp.append(accept); resp.append(0); - resp.append(_treatmentVars.prescribedTreatmentTimeS); + resp.append(_treatmentVars.prescribedTreatmentTimeS /SECONDS_PER_MINUTE); resp.append(_treatmentVars.prescribedMaxUFVolML); + _isSendListReady = false; _sendMessages.append(resp); _isSendListReady = true; } @@ -1508,11 +1512,11 @@ } } -void StateController::onStartTreatmentStateChange(bool) +void StateController::onStartTreatmentStateChange(bool active) { static State_Status status = STATE_ON_ENTRY; - auto entry = [=](){ + auto inEntry = [=](){ qDebug() << "Start Treatment active"; resetVariables(); @@ -1535,102 +1539,106 @@ QVariant emptyVariantList; setTreatmentParams(false, emptyVariantList); - _treatmentVars.prescribedMaxUFVolML = DEF_TX_PARAM_UF_VOLUME_L * MILLILITERS_PER_LITER; // TODO from tx params - _treatmentVars.prescribedUFRate = _treatmentVars.prescribedMaxUFVolML / _treatmentParams.txDurationMins; - _treatmentVars.refUFVolumeML = (_treatmentVars.treatmentElapsedTimeS / SECONDS_PER_MINUTE) * _treatmentVars.prescribedUFRate; - status = STATE_ON_EXIT; }; - auto action = [](){}; - auto exit = [=](){ + auto inAction = [](){}; + auto inExit = [=](){ status = STATE_ON_ENTRY; _dryDemo.submitEvent("Start_Tx_2_Blood_Prime"); }; switch (status) { // TODO macro it later - case STATE_ON_ENTRY : entry (); break; - case STATE_ON_ACTION: action(); break; - case STATE_ON_EXIT : exit (); break; + case STATE_ON_ENTRY : inEntry (); break; + case STATE_ON_ACTION: if (active) inAction(); break; + case STATE_ON_EXIT : inExit (); break; } } -void StateController::onTreatmentBloodPrimeStateChange(bool) +void StateController::onTreatmentBloodPrimeStateChange(bool active) { static State_Status status = STATE_ON_ENTRY; _treatmentVars.broadcastIntervalCount++; - auto entry = [=](){ + auto inEntry = [=](){ resetVariables(); qDebug() << "Blood prime entry"; status = STATE_ON_ACTION; }; - auto action = [=](){ + auto inAction = [=](){ _treatmentVars.accumulatedVolumeML += (DEF_TX_PARAM_BLOOD_FLOW_RATE_MLPM * BLOOD_FLOW_INTEGRATOR); if (_treatmentVars.broadcastIntervalCount % NUM_OF_BC_COUNTS_ADJUSTED == 0) { - _isBroadcastListReady = false; QVariantList msg; msg.append(static_cast(ID_HD_BLOOD_PRIME_BC)); msg.append(Can_Id::eChlid_HD_Sync); msg.append(BLOOD_PRIME_VOLUME_ML); msg.append(_treatmentVars.accumulatedVolumeML); + _isBroadcastListReady = false; _broadcastMessages.append(msg); + _isBroadcastListReady = true; prepareOcclusionBroadcastData(); prepareTreatmentParamsRangesBroadcastData(); - _isBroadcastListReady = true; } if (_treatmentVars.accumulatedVolumeML > BLOOD_PRIME_VOLUME_ML) { // send blood prime value on last time - _isBroadcastListReady = false; QVariantList msg; msg.append(static_cast(ID_HD_BLOOD_PRIME_BC)); msg.append(Can_Id::eChlid_HD_Sync); msg.append(BLOOD_PRIME_VOLUME_ML); msg.append(_treatmentVars.accumulatedVolumeML); + _isBroadcastListReady = false; _broadcastMessages.append(msg); _isBroadcastListReady = true; status = STATE_ON_EXIT; } }; - auto exit = [=](){ + auto inExit = [=](){ qDebug() << "Blood prime exit"; status = STATE_ON_ENTRY; _dryDemo.submitEvent("Blood_Prime_2_Treatment"); }; switch (status) { // TODO macro it later - case STATE_ON_ENTRY : entry (); break; - case STATE_ON_ACTION: action(); break; - case STATE_ON_EXIT : exit (); break; + case STATE_ON_ENTRY : inEntry (); break; + case STATE_ON_ACTION: if (active) inAction(); break; + case STATE_ON_EXIT : inExit (); break; } } -void StateController::onTreatmentTreatmentStateChange(bool) +void StateController::onTreatmentTreatmentStateChange(bool active) { static State_Status status = STATE_ON_ENTRY; - _treatmentVars.broadcastIntervalCount++; handleTreatmentReceivedMessages(); - auto entry = [=](){ + auto inEntry = [=](){ resetVariables(); qDebug() << "Treatment Treatment state"; _treatmentVars.prescribedTreatmentTimeS = _treatmentParams.txDurationMins * SECONDS_PER_MINUTE; _treatmentVars.treatmentElapsedTimeS = DEF_TX_ELAPSED_TIME_S; _treatmentVars.remainingTreatmentTimeS = _treatmentVars.prescribedTreatmentTimeS - _treatmentVars.treatmentElapsedTimeS; + + _treatmentVars.prescribedMaxUFVolML = DEF_TX_PARAM_UF_VOLUME_L * MILLILITERS_PER_LITER; // TODO from tx params + _treatmentVars.prescribedUFRate = _treatmentVars.prescribedMaxUFVolML / _treatmentParams.txDurationMins; + _treatmentVars.refUFVolumeML = (_treatmentVars.treatmentElapsedTimeS / SECONDS_PER_MINUTE) * _treatmentVars.prescribedUFRate; + status = STATE_ON_ACTION; }; - auto action = [=](){ + auto inAction = [=](){ + _treatmentVars.broadcastIntervalCount++; - _treatmentVars.refUFVolumeML += (0.1 / SECONDS_PER_MINUTE) * _treatmentVars.prescribedUFRate; - qDebug() << "UF Va;ue" << _treatmentVars.refUFVolumeML << _treatmentVars.prescribedUFRate; + float timeSinceLastCallMS = static_cast(QOBJECT_TIMER_TIMEOUT_MS) / static_cast(MILLISECONDS_PER_SECOND); + + _treatmentVars.refUFVolumeML += (timeSinceLastCallMS / SECONDS_PER_MINUTE) * _treatmentVars.prescribedUFRate; + _treatmentVars.measUFVolumeML = _treatmentVars.refUFVolumeML; + //qDebug() << "UF Va;ue" << QTime::currentTime() << _treatmentVars.refUFVolumeML << _treatmentVars.prescribedUFRate; if (_treatmentVars.broadcastIntervalCount % NUM_OF_BC_COUNTS_ADJUSTED == 0) { QVariantList msg; msg.append(2); msg.append(1); msg.append(0); msg.append(0); msg.append(0); @@ -1656,16 +1664,16 @@ //} }; - auto exit = [=](){ + auto inExit = [=](){ qDebug() << "Treat Treatment exit"; status = STATE_ON_ENTRY; _dryDemo.submitEvent("Treatment_2_End_Treatment"); // TODO bring back }; switch (status) { // TODO macro it later - case STATE_ON_ENTRY : entry (); break; - case STATE_ON_ACTION: action(); break; - case STATE_ON_EXIT : exit (); break; + case STATE_ON_ENTRY : inEntry (); break; + case STATE_ON_ACTION: if (active) inAction(); break; + case STATE_ON_EXIT : inExit (); break; } } Index: sources/StateController.h =================================================================== diff -u -r6e0ddbfa4863bb12a64dfde5baeada941acadaf8 -r13f1a9b24d08848b27c8e345c21d0e540c0b78de --- sources/StateController.h (.../StateController.h) (revision 6e0ddbfa4863bb12a64dfde5baeada941acadaf8) +++ sources/StateController.h (.../StateController.h) (revision 13f1a9b24d08848b27c8e345c21d0e540c0b78de) @@ -53,15 +53,17 @@ #define QOBJECT_TIMER_TIMEOUT_MS 100 #define PROGRESS_TIME_BC_INTERVAL_MS 1000 #define NUM_OF_COUNTS_TIMER_BC_EMIT (PROGRESS_TIME_BC_INTERVAL_MS / QOBJECT_TIMER_TIMEOUT_MS) - #define NUM_OF_BC_COUNTS_ADJUSTED (NUM_OF_COUNTS_TIMER_BC_EMIT * 2) + #define NUM_OF_BC_COUNTS_ADJUSTED (NUM_OF_COUNTS_TIMER_BC_EMIT * 1) #define NUM_OF_COUNTS_TO_BC_MSG 3 // Treatment params #define MIN_DIAL_RATE_MLPM 100 #define MAX_DIAL_RATE_MLPM 600 #define MIN_TX_TIME_MINS (1 * MINUTES_PER_HOUR) #define MAX_TX_TIME_MINS (8 * MINUTES_PER_HOUR) - #define MAX_UF_VOL_ML (8 * MILLILITERS_PER_LITER) + #define MIN_UF_VOL_L 0.0 + #define MAX_UF_VOL_L 8.0 + #define MAX_UF_VOL_ML (MAX_UF_VOL_L * MILLILITERS_PER_LITER) #define MAX_UF_RATE_MLPM (2000.0 / MINUTES_PER_HOUR) #define DEF_TX_ELAPSED_TIME_S (2 * MINUTES_PER_HOUR) * SECONDS_PER_MINUTE @@ -153,6 +155,7 @@ float prescribedMaxUFVolML; float prescribedUFRate; float refUFVolumeML; + float measUFVolumeML; }; State_Status _stateStatus; // TODO remove @@ -192,9 +195,9 @@ void onUltrafiltrationStateChange(bool active); void onConnectionStateChange(bool active); - void onStartTreatmentStateChange(bool); - void onTreatmentBloodPrimeStateChange(bool); - void onTreatmentTreatmentStateChange(bool); + void onStartTreatmentStateChange(bool active); + void onTreatmentBloodPrimeStateChange(bool active); + void onTreatmentTreatmentStateChange(bool active); void onEndTreatmentStateChange(bool active); void onDisinfectStateChange(bool active);