software:firmware
MakAir Firmware
main_controller.cpp
Go to the documentation of this file.
1 
8 #pragma once
9 
10 // INCLUDES ===================================================================
11 
12 // Associated header
13 #include "../includes/main_controller.h"
14 
15 // Internal
16 #include "../includes/cpu_load.h"
17 
18 // INITIALISATION =============================================================
19 
21 
22 static const int32_t INVALID_ERROR_MARKER = INT32_MIN;
23 
24 // FUNCTIONS ==================================================================
25 
27  m_tick = 0;
29 
32  m_expiratoryFlow = 0;
37 
62 
69 
74 
79 
84 
89 
92 
95 
98 
101 
104 
107 
113 
115 
118 
128 
131 
132  m_cycleNb = 0;
133 
135 
136  m_sumOfPressures = 0;
140 
141  m_triggered = false;
142  m_isPeepDetected = false;
143  m_tidalVolumeAlreadyRead = false;
145 
146  m_patientHeight = 0;
147  m_patientGender = 0;
148 
150 
152 
154  for (uint8_t i = 0u; i < MAX_PRESSURE_SAMPLES; i++) {
155  m_lastPressureValues[i] = 0;
156  }
157 
159  for (uint8_t i = 0u; i < NUMBER_OF_BREATH_PERIOD; i++) {
161  }
162 }
163 
165  DBG_DO(Serial.println(VERSION);)
166  DBG_DO(Serial.println("Setup the controller");)
167 
169 
171 
173 }
174 
176  m_expiratoryVolume = 0;
177  DBG_DO(Serial.println("Init respiratory cycle");)
178  m_cycleNb++;
180 
182  m_triggered = false;
183  m_isPeepDetected = false;
184  m_tidalVolumeAlreadyRead = false;
185 
186  // Update new settings at the beginning of the respiratory cycle
201 
206 
211 
214 
217 
220 
221  // Run setup of the controller only if different from previous cycle
226  }
227 
229 
230  for (uint8_t i = 0u; i < MAX_PRESSURE_SAMPLES; i++) {
231  m_lastPressureValues[i] = 0;
232  }
234 
235  m_sumOfPressures = 0u;
236  m_numberOfPressures = 0u;
237 
238  m_PlateauMeasureSum = 0u;
240 
244 
246 }
247 
249  // Update the cycle phase
250  updatePhase();
251 
252  // Compute metrics for alarms
253  m_sumOfPressures += static_cast<uint32_t>(m_pressure);
255 
256  // Store last pressure values only every 10ms
257  uint32_t moduloValue = max(1u, (10u / MAIN_CONTROLLER_COMPUTE_PERIOD_MS));
258  if ((m_tick % moduloValue) == 0u) {
259  // Store the current pressure to compute aggregates
262 
263  // Start over if we reached the max samples number
264  if (m_lastPressureValuesIndex >= static_cast<uint16_t>(MAX_PRESSURE_SAMPLES)) {
266  }
267  }
268 
269  // Act accordingly
270  switch (m_phase) {
272  inhale();
274  break;
275 
277  exhale();
278  break;
279 
280  default:
281  // Do nothing
282  break;
283  }
284 
286 
287  // Send data snaphshot only every 10 ms
288  if ((m_tick % moduloValue) == 0u) {
291  max(int32_t(0), m_inspiratoryFlow / 10),
292  max(int32_t(0), m_expiratoryFlow / 10));
293  }
294 
295  executeCommands();
296 
297 #ifdef MASS_FLOW_METER_ENABLED
298  // Measure volume only during inspiration
299  // Add 100 ms to allow valve to close completely
303  int32_t volume = m_currentDeliveredVolume;
305  ((volume > 0xFFFE) || (volume < 0)) ? 0xFFFFu : static_cast<uint16_t>(volume);
306  }
307 
308 #else
309  m_tidalVolumeMeasure = UINT16_MAX;
310 #endif
312 }
313 
318 
319  } else {
322  }
323 }
324 
326  // Control loop
328 
329  // Update peak pressure and rebounce peak pressure
331  m_peakPressureMeasure = max((int16_t)0, m_pressure);
335  } else {
336  // Do nothing
337  }
338 
339  // Compute plateau at the end of the cycle
342  m_PlateauMeasureCount += 1u;
343  }
344 }
345 
347  // Control loop
349 
350  // Compute the PEEP pressure
351  int16_t minValue = m_lastPressureValues[0u];
352  int16_t maxValue = m_lastPressureValues[0u];
353  int16_t totalValues = m_lastPressureValues[0u];
354  for (uint8_t index = 1u; index < MAX_PRESSURE_SAMPLES; index++) {
355  minValue = min(minValue, m_lastPressureValues[index]);
356  maxValue = max(maxValue, m_lastPressureValues[index]);
357  totalValues += m_lastPressureValues[index];
358  }
359 
360  // Update PEEP value, when pressure is stable and close to target pressure
361  if (((maxValue - minValue) < 5) && (abs(m_pressure - m_peepCommand) < 30)) {
362  m_isPeepDetected = true;
363  m_peepMeasure = max(0, totalValues / static_cast<int16_t>(MAX_PRESSURE_SAMPLES));
364  }
365 
366  // This case is usefull when PEEP is never detected during the cycle
367  if (!m_isPeepDetected) {
368  m_peepMeasure = max(static_cast<int16_t>(0), m_pressure);
369  }
370 }
371 
372 void MainController::endRespiratoryCycle(uint32_t p_currentMillis) {
373  // Compute the respiratory rate: average on NUMBER_OF_BREATH_PERIOD breaths
374  uint32_t currentMillis = p_currentMillis;
376  currentMillis - m_lastEndOfRespirationDateMs;
380  }
381  uint32_t sum = 0;
382  for (uint8_t i = 0u; i < NUMBER_OF_BREATH_PERIOD; i++) {
383  sum += m_lastBreathPeriodsMs[i];
384  }
385  // Add "+(sum-1u)" to round instead of truncate
386  m_cyclesPerMinuteMeasure = (((NUMBER_OF_BREATH_PERIOD * 60u) * 1000u) + (sum - 1u)) / sum;
387  m_lastEndOfRespirationDateMs = currentMillis;
388 
389  // Plateau pressure is the mean pressure during plateau
390  m_plateauPressureMeasure = max(0, static_cast<int16_t>(m_PlateauMeasureSum)
391  / static_cast<int16_t>(m_PlateauMeasureCount));
392 
393  checkCycleAlarm();
394 
396 
397  // Send telemetry machine state snapshot message
399 
401 }
402 
404 #if DEBUG == 2
405  Serial.print(m_pressure);
406  Serial.print(",");
407  Serial.print(m_pressureCommand);
408  Serial.print(",");
409  Serial.print(m_inspiratoryFlow / 100); // division by 100 for homogenous scale in debug
410  Serial.print(",");
411  Serial.print(m_expiratoryFlow / 100); // division by 100 for homogenous scale in debug
412  Serial.print(",");
413  Serial.print(inspiratoryValve.command);
414  Serial.print(",");
415  Serial.print(expiratoryValve.command);
416  Serial.print(",");
417  Serial.print(blower.getSpeed() / 10); // division by 10 for homogenous scale in debug
418  Serial.println();
419 #endif
420 }
421 
422 void MainController::updatePressure(int16_t p_currentPressure) { m_pressure = p_currentPressure; }
423 
424 void MainController::updateDt(int32_t p_dt) { m_dt = p_dt; }
425 
426 void MainController::updateTick(uint32_t p_tick) { m_tick = p_tick; }
427 
428 void MainController::updateInspiratoryFlow(int32_t p_currentInspiratoryFlow) {
429  if (p_currentInspiratoryFlow != MASS_FLOW_ERROR_VALUE) {
430  m_inspiratoryFlow = p_currentInspiratoryFlow;
431 
434  }
435  }
436 }
437 
438 // cppcheck-suppress unusedFunction
439 void MainController::updateExpiratoryFlow(int32_t p_currentExpiratoryFlow) {
440  if (p_currentExpiratoryFlow != MASS_FLOW_ERROR_VALUE) {
441  m_expiratoryFlow = p_currentExpiratoryFlow;
442 
445  }
446  }
447 }
448 
449 // cppcheck-suppress unusedFunction
451  // get section in mm2 x 100
452  int32_t A2MultiplyBy100 = expiratoryValve.getSectionBigHoseX100();
453  int32_t A1MultiplyBy100 = 7853;
454  int32_t rhoMultiplyBy10 = 12;
455  int32_t pressure = max(int32_t(0), m_pressure - int32_t(50));
456  int32_t divider = (rhoMultiplyBy10
457  * (10000
458  - (100 * A2MultiplyBy100 / A1MultiplyBy100)
459  * (100 * A2MultiplyBy100 / A1MultiplyBy100)));
460  int32_t tempRatioX100 = (divider <= 0) ? 0 : (100 * (2 * pressure * 980000 / divider));
462  (tempRatioX100 < 0) ? 0 : (A2MultiplyBy100 * sqrt(tempRatioX100) * 60) / 1000;
463  /*if (openning == 125) {
464  m_expiratoryFlow = 0;
465  } else {
466  int32_t aMultiplyBy100 =
467  ((((-585 * openning) * openning) / 100000) + ((118 * openning) / 100)) - 62;
468  int32_t bMultiplyBy100 = ((((195 * openning) * openning) / 100) + 33300 - (489 * openning));
469  int32_t cMultiplyBy100 = 279000 - (2170 * openning);
470 
471  int32_t p = m_pressure;
472  m_expiratoryFlow =
473  (((aMultiplyBy100 * p) * p) + (bMultiplyBy100 * p) + cMultiplyBy100) / 100;
474  }*/
475 
476  /*Serial.print(A2MultiplyBy100);
477  Serial.print(",");
478  Serial.print(m_pressure);
479  Serial.print(",");
480  Serial.print(tempRatioX100);
481  Serial.print(",");
482  Serial.print(m_expiratoryFlow);
483  Serial.print(",");
484  Serial.println();*/
485 
486  m_expiratoryVolume += ((m_expiratoryFlow / 60) * m_dt) / 1000000;
487 }
488 
489 void MainController::updateCurrentDeliveredVolume(int32_t p_currentDeliveredVolume) {
490  if (p_currentDeliveredVolume != MASS_FLOW_ERROR_VALUE) {
491  m_currentDeliveredVolume = p_currentDeliveredVolume;
492  }
493 }
494 
495 void MainController::updateCurrentExpiratoryVolume(int32_t p_expiratoryVolume) {
496  if (p_expiratoryVolume != MASS_FLOW_ERROR_VALUE) {
497  m_expiratoryVolume = p_expiratoryVolume;
498  }
499 }
500 
503 
508 }
509 
511  if (m_pressure
518  m_pressure);
519  } else {
521  }
522 
525  blower.execute();
526 }
527 
529  // RCM-SW-1 + RCM-SW-14: check if plateau is reached
530  int16_t minPlateauBeforeAlarm =
532  int16_t maxPlateauBeforeAlarm =
534  if ((m_plateauPressureMeasure < minPlateauBeforeAlarm)
535  || (m_plateauPressureMeasure > maxPlateauBeforeAlarm)) {
538  } else {
541  }
542 
543  // RCM-SW-2 + RCM-SW-19: check is mean pressure was < 2 cmH2O
544  int16_t meanPressure = m_sumOfPressures / m_numberOfPressures;
545  if (meanPressure <= ALARM_THRESHOLD_MIN_PRESSURE) {
547  m_pressure);
549  m_pressure);
550  } else {
553  }
554 
555  // RCM-SW-3 + RCM-SW-15
556  int16_t PeepBeforeAlarm = m_peepCommand - ALARM_THRESHOLD_DIFFERENCE_PRESSURE;
557  int16_t maxPeepBeforeAlarm = m_peepCommand + ALARM_THRESHOLD_DIFFERENCE_PRESSURE;
558  if ((m_peepMeasure < PeepBeforeAlarm) || (m_peepMeasure > maxPeepBeforeAlarm)) {
561  } else {
564  }
565 
566  // RC-SW-4 & 5 : Inspiratory minute Volume is too low/high
567  int32_t inspiratoryMinuteVolume =
568  m_tidalVolumeMeasure * static_cast<int32_t>(m_cyclesPerMinuteMeasure); // In mL/min
569  if (inspiratoryMinuteVolume < m_lowInspiratoryMinuteVolumeAlarmThresholdCommand) {
572  inspiratoryMinuteVolume);
574  } else if (inspiratoryMinuteVolume > m_highInspiratoryMinuteVolumeAlarmThresholdCommand) {
577  inspiratoryMinuteVolume);
579  } else {
582  }
583 
584  // RC-SW-6 & 7 : Expiratory minute Volume is too low/high
585  int32_t expiratoryMinuteVolume =
586  m_expiratoryVolume * static_cast<int32_t>(m_cyclesPerMinuteMeasure); // In mL/min
587  if (expiratoryMinuteVolume < m_lowExpiratoryMinuteVolumeAlarmThresholdCommand) {
590  expiratoryMinuteVolume);
592  } else if (expiratoryMinuteVolume > m_highExpiratoryMinuteVolumeAlarmThresholdCommand) {
595  expiratoryMinuteVolume);
597  } else {
600  }
601 
602  // RC-SW-8 & 9 : Respiratory rate is too low/high
603  if (static_cast<int32_t>(m_cyclesPerMinuteMeasure)
609  } else if (static_cast<int32_t>(m_cyclesPerMinuteMeasure)
615  } else {
618  }
619 
620  // RC-SW-20 & 21 : tidal Volume is too low/high
629  } else {
632  }
633 
634  // RCM_SW_10 : Leak is too high
635  int32_t leakPerMinute = (m_currentDeliveredVolume - m_expiratoryVolume)
636  * static_cast<int32_t>(m_cyclesPerMinuteMeasure); // In mL/min
637  if (leakPerMinute > m_leakAlarmThresholdCommand) {
639  leakPerMinute);
640  } else {
642  }
643 
646  m_pressure);
647  } else {
649  }
650 
655  } else {
657  }
658 }
659 
663  executeCommands();
664 }
665 
681  static_cast<uint8_t>(m_targetInspiratoryFlowNextCommand / 1000),
684 }
685 
686 void MainController::stop(uint32_t p_currentMillis) {
687  blower.stop();
689  // When stopped, open the valves
691  m_lastEndOfRespirationDateMs = p_currentMillis;
692 
693  // Stop alarms related to breathing cycle
712  digitalWrite(PIN_LED_START, LED_START_INACTIVE);
713 }
714 
716  // Send the next command, because command has not been updated yet (will be at the beginning of
717  // the next cycle)
735  static_cast<uint8_t>(m_targetInspiratoryFlowNextCommand / 1000),
739 }
740 
741 void MainController::onVentilationModeSet(uint16_t p_ventilationControllerMode) {
742  // cppcheck-suppress misra-c2012-10.4
743  if ((m_ventilationControllerMode >= 1u)
744  // cppcheck-suppress misra-c2012-10.4
746  m_ventilationControllerMode = static_cast<VentilationModes>(p_ventilationControllerMode);
749  }
750  // Send acknowledgment to the UI
752 }
753 
755  DBG_DO(Serial.println("Cycle --");)
756 
758 
761  }
762  // Send acknowledgment to the UI
764 }
765 
767  DBG_DO(Serial.println("Cycle ++");)
768 
770 
773  }
774 
775  // Send acknowledgment to the UI
777 }
778 
779 // cppcheck-suppress unusedFunction
780 void MainController::onCycleSet(uint16_t p_cpm) {
781  if (p_cpm < CONST_MIN_CYCLE) {
783  } else if (p_cpm > CONST_MAX_CYCLE) {
785  } else {
787  }
788 
789  // Send acknowledgment to the UI
791 }
792 
794  DBG_DO(Serial.println("Peep Pressure --");)
795 
796  if (m_peepNextCommand >= 10) {
798  } else {
799  // Do nothing
800  }
801 
802  // Send acknowledgment to the UI
804 }
805 
807  DBG_DO(Serial.println("Peep Pressure ++");)
808 
809  // Peep target should be lower than plateau target
812  }
813 
816  }
817 
818  // Send acknowledgment to the UI
820 }
821 
822 // cppcheck-suppress unusedFunction
823 void MainController::onPeepSet(int16_t p_peep) {
824  if (p_peep > CONST_MAX_PEEP_PRESSURE) {
826  // cppcheck-suppress unsignedLessThanZero ; CONST_MIN_PEEP_PRESSURE might not be equal to 0
827  } else if (p_peep < CONST_MIN_PEEP_PRESSURE) {
829  } else {
830  m_peepNextCommand = p_peep;
831  }
832 
833  // Send acknowledgment to the UI
835 }
836 
838  DBG_DO(Serial.println("Plateau Pressure --");)
839 
842  }
843 
846  }
847 
850 
851  // Send acknowledgment to the UI
853 }
854 
856  DBG_DO(Serial.println("Plateau Pressure ++");)
857 
859 
861  min(m_plateauPressureNextCommand, static_cast<int16_t>(CONST_MAX_PLATEAU_PRESSURE));
864 
865  // Send acknowledgment to the UI
867 }
868 
869 // cppcheck-suppress unusedFunction
870 void MainController::onPlateauPressureSet(int16_t p_plateauPressure) {
871  if (p_plateauPressure > CONST_MAX_PLATEAU_PRESSURE) {
873  } else if (p_plateauPressure < CONST_MIN_PLATEAU_PRESSURE) {
875  } else {
876  m_plateauPressureNextCommand = p_plateauPressure;
877  }
880 
881  // Send acknowledgment to the UI
883 }
884 
886  DBG_DO(Serial.println("Peak Pressure --");)
887 #if DEBUG != 0
888  switch (m_ventilationControllerMode) {
889  case PC_CMV:
891  break;
892  case PC_AC:
894  break;
895  case VC_CMV:
897  break;
898  case PC_VSAI:
900  break;
901  default:
902  // Do nothing
903  break;
904  }
906 
907 #endif
908 }
909 
911  DBG_DO(Serial.println("Peak Pressure ++");)
912 #if DEBUG != 0
913  switch (m_ventilationControllerMode) {
914  case PC_CMV:
916  break;
917  case PC_AC:
919  break;
920  case VC_CMV:
922  break;
923  case PC_VSAI:
925  break;
926  default:
927  // Do nothing
928  break;
929  }
931 
932 #endif
933 }
934 
935 // cppcheck-suppress unusedFunction
936 void MainController::onExpiratoryTermSet(uint16_t p_expiratoryTerm) {
937  if (p_expiratoryTerm > CONST_MAX_EXPIRATORY_TERM) {
939  } else if (p_expiratoryTerm < CONST_MIN_EXPIRATORY_TERM) {
941  } else {
942  m_expiratoryTermNextCommand = p_expiratoryTerm;
943  }
944 
945  // Send acknowledgment to the UI
947 }
948 
949 // cppcheck-suppress unusedFunction
950 void MainController::onTriggerModeEnabledSet(uint16_t p_triggerEnabled) {
951  if ((p_triggerEnabled == 0u) || (p_triggerEnabled == 1u)) {
952  m_triggerModeEnabledNextCommand = p_triggerEnabled;
953  }
954  // Send acknowledgment to the UI
956 }
957 
958 // cppcheck-suppress unusedFunction
959 void MainController::onTriggerOffsetSet(uint16_t p_triggerOffset) {
960  if (p_triggerOffset > CONST_MAX_TRIGGER_OFFSET) {
962  // cppcheck-suppress unsignedLessThanZero
963  } else if (p_triggerOffset < CONST_MIN_TRIGGER_OFFSET) {
965  } else {
966  m_pressureTriggerOffsetNextCommand = p_triggerOffset;
967  }
968 
969  // Send acknowledgment to the UI
971 }
972 
973 // cppcheck-suppress unusedFunction
974 void MainController::onInspiratoryTriggerFlowSet(uint16_t p_inspiratoryTriggerFlow) {
975  // CONST_MIN_INSPIRATORY_TRIGGER_FLOW might not be equal to 0
976  // cppcheck-suppress unsignedPositive
977  if ((p_inspiratoryTriggerFlow >= CONST_MIN_INSPIRATORY_TRIGGER_FLOW)
978  && (p_inspiratoryTriggerFlow <= CONST_MAX_INSPIRATORY_TRIGGER_FLOW)) {
979  m_inspiratoryTriggerFlowNextCommand = p_inspiratoryTriggerFlow;
980  }
981 
982  // Send acknowledgment to the UI
984 }
985 
986 // cppcheck-suppress unusedFunction
987 void MainController::onExpiratoryTriggerFlowSet(uint16_t p_expiratoryTriggerFlow) {
988  // CONST_MIN_EXPIRATORY_TRIGGER_FLOW might not be equal to 0
989  // cppcheck-suppress unsignedPositive
990  if ((p_expiratoryTriggerFlow >= CONST_MIN_EXPIRATORY_TRIGGER_FLOW)
991  && (p_expiratoryTriggerFlow <= CONST_MAX_EXPIRATORY_TRIGGER_FLOW)) {
992  m_expiratoryTriggerFlowNextCommand = p_expiratoryTriggerFlow;
993  }
994 
995  // Send acknowledgment to the UI
997 }
998 
999 // cppcheck-suppress unusedFunction
1000 void MainController::onTiMinSet(uint16_t p_tiMin) {
1001  if ((p_tiMin >= CONST_MIN_MIN_INSPIRATION_DURATION)
1002  && (p_tiMin <= CONST_MAX_MIN_INSPIRATION_DURATION)) {
1003  m_tiMinNextCommand = p_tiMin;
1004  }
1005 
1006  // Send acknowledgment to the UI
1008 }
1009 
1010 // cppcheck-suppress unusedFunction
1011 void MainController::onTiMaxSet(uint16_t p_tiMax) {
1012  if ((p_tiMax >= CONST_MIN_MAX_INSPIRATION_DURATION)
1013  && (p_tiMax <= CONST_MAX_MAX_INSPIRATION_DURATION)) {
1014  m_tiMaxNextCommand = p_tiMax;
1015  }
1016 
1017  // Send acknowledgment to the UI
1019 }
1020 
1021 // cppcheck-suppress unusedFunction
1023  uint16_t p_lowInspiratoryMinuteVolumeAlarmThreshold) {
1024  // CONST_MIN_LOW_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD might not be equal to 0
1025  if ((p_lowInspiratoryMinuteVolumeAlarmThreshold
1026  // cppcheck-suppress unsignedPositive ;
1028  && (p_lowInspiratoryMinuteVolumeAlarmThreshold
1031  // cppcheck-suppress cert-INT31-c ;
1032  1000 * (int32_t)p_lowInspiratoryMinuteVolumeAlarmThreshold;
1033  }
1034 
1035  // Send acknowledgment to the UI
1037 }
1038 
1039 // cppcheck-suppress unusedFunction
1041  uint16_t p_highInspiratoryMinuteVolumeAlarmThreshold) {
1042  if ((p_highInspiratoryMinuteVolumeAlarmThreshold
1044  && (p_highInspiratoryMinuteVolumeAlarmThreshold
1047  1000 * (int32_t)p_highInspiratoryMinuteVolumeAlarmThreshold;
1048  }
1049 
1050  // Send acknowledgment to the UI
1052 }
1053 
1054 // cppcheck-suppress unusedFunction
1056  uint16_t p_lowExpiratoryMinuteVolumeAlarmThreshold) {
1057  // CONST_MIN_LOW_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD might not be equal to 0
1058  if ((p_lowExpiratoryMinuteVolumeAlarmThreshold
1059  // cppcheck-suppress unsignedPositive ;
1061  && (p_lowExpiratoryMinuteVolumeAlarmThreshold
1064  // cppcheck-suppress cert-INT31-c ;
1065  1000 * (int32_t)p_lowExpiratoryMinuteVolumeAlarmThreshold;
1066  }
1067 
1068  // Send acknowledgment to the UI
1070 }
1071 
1072 // cppcheck-suppress unusedFunction
1074  uint16_t p_highExpiratoryMinuteVolumeAlarmThreshold) {
1075  if ((p_highExpiratoryMinuteVolumeAlarmThreshold
1077  && (p_highExpiratoryMinuteVolumeAlarmThreshold
1080  1000 * (int32_t)p_highExpiratoryMinuteVolumeAlarmThreshold;
1081  }
1082 
1083  // Send acknowledgment to the UI
1085 }
1086 
1087 // cppcheck-suppress unusedFunction
1089  uint16_t p_lowRespiratoryRateAlarmThreshold) {
1090  if ((p_lowRespiratoryRateAlarmThreshold >= CONST_MIN_LOW_RESPIRATORY_RATE_ALARM_THRESHOLD)
1091  && (p_lowRespiratoryRateAlarmThreshold <= CONST_MAX_LOW_RESPIRATORY_RATE_ALARM_THRESHOLD)) {
1092  m_lowRespiratoryRateAlarmThresholdNextCommand = p_lowRespiratoryRateAlarmThreshold;
1093  }
1094 
1095  // Send acknowledgment to the UI
1097 }
1098 
1099 // cppcheck-suppress unusedFunction
1101  uint16_t p_highRespiratoryRateAlarmThreshold) {
1102  if ((p_highRespiratoryRateAlarmThreshold >= CONST_MIN_HIGH_RESPIRATORY_RATE_ALARM_THRESHOLD)
1103  && (p_highRespiratoryRateAlarmThreshold
1105  m_highRespiratoryRateAlarmThresholdNextCommand = p_highRespiratoryRateAlarmThreshold;
1106  }
1107 
1108  // Send acknowledgment to the UI
1110 }
1111 
1112 // cppcheck-suppress unusedFunction
1113 void MainController::onTargetTidalVolumeSet(uint16_t p_targetTidalVolume) {
1114  if ((p_targetTidalVolume >= CONST_MIN_TIDAL_VOLUME)
1115  && (p_targetTidalVolume <= CONST_MAX_TIDAL_VOLUME)) {
1116  m_tidalVolumeNextCommand = p_targetTidalVolume;
1117  }
1118  // Send acknowledgment to the UI
1120 }
1121 
1122 // cppcheck-suppress unusedFunction
1123 void MainController::onLowTidalVolumeAlarmThresholdSet(uint16_t p_lowTidalVolumeAlarmThreshold) {
1124  // CONST_MIN_LOW_TIDAL_VOLUME_ALARM_THRESHOLD might not be equal to 0
1125  // cppcheck-suppress unsignedPositive ;
1126  if ((p_lowTidalVolumeAlarmThreshold >= CONST_MIN_LOW_TIDAL_VOLUME_ALARM_THRESHOLD)
1127  && (p_lowTidalVolumeAlarmThreshold <= CONST_MAX_LOW_TIDAL_VOLUME_ALARM_THRESHOLD)) {
1128  m_lowTidalVolumeAlarmThresholdNextCommand = p_lowTidalVolumeAlarmThreshold;
1129  }
1130 
1131  // Send acknowledgment to the UI
1133 }
1134 
1135 // cppcheck-suppress unusedFunction
1136 void MainController::onHighTidalVolumeAlarmThresholdSet(uint16_t p_highTidalVolumeAlarmThreshold) {
1137  if ((p_highTidalVolumeAlarmThreshold >= CONST_MIN_HIGH_TIDAL_VOLUME_ALARM_THRESHOLD)
1138  && (p_highTidalVolumeAlarmThreshold <= CONST_MAX_HIGH_TIDAL_VOLUME_ALARM_THRESHOLD)) {
1139  m_highTidalVolumeAlarmThresholdNextCommand = p_highTidalVolumeAlarmThreshold;
1140  }
1141 
1142  // Send acknowledgment to the UI
1144 }
1145 
1146 // cppcheck-suppress unusedFunction
1147 void MainController::onPlateauDurationSet(uint16_t p_plateauDuration) {
1148  // CONST_MIN_PLATEAU_DURATION might not be equal to 0
1149  // cppcheck-suppress unsignedPositive ;
1150  if ((p_plateauDuration >= CONST_MIN_PLATEAU_DURATION)
1151  && (p_plateauDuration <= CONST_MAX_PLATEAU_DURATION)) {
1152  m_plateauDurationNextCommand = p_plateauDuration;
1153  }
1154 
1155  // Send acknowledgment to the UI
1157 }
1158 
1159 // cppcheck-suppress unusedFunction
1160 void MainController::onLeakAlarmThresholdSet(uint16_t p_leakAlarmThreshold) {
1161  if ((p_leakAlarmThreshold >= CONST_MIN_LEAK_ALARM_THRESHOLD)
1162  && (p_leakAlarmThreshold <= CONST_MIN_LEAK_ALARM_THRESHOLD)) {
1163  m_leakAlarmThresholdNextCommand = 10u * p_leakAlarmThreshold;
1164  }
1165 
1166  // Send acknowledgment to the UI
1168 }
1169 
1170 // cppcheck-suppress unusedFunction
1171 void MainController::onTargetInspiratoryFlow(uint16_t p_targetInspiratoryFlow) {
1172  int32_t temporaryValue = static_cast<int32_t>(p_targetInspiratoryFlow) * 1000;
1173  if ((temporaryValue >= CONST_MIN_INSPIRATORY_FLOW)
1174  && (temporaryValue <= CONST_MAX_INSPIRATORY_FLOW)) {
1175  m_targetInspiratoryFlowNextCommand = temporaryValue;
1176  }
1177 
1178  // Send acknowledgment to the UI
1179  sendControlAck(25, static_cast<uint16_t>(m_targetInspiratoryFlowNextCommand / 1000));
1180 }
1181 
1182 // cppcheck-suppress unusedFunction
1183 void MainController::onInspiratoryDuration(uint16_t p_inspiratoryDuration) {
1184  if ((p_inspiratoryDuration >= CONST_MIN_INSPIRATORY_DURATION)
1185  && (p_inspiratoryDuration <= CONST_MAX_INSPIRATORY_DURATION)) {
1186  m_inspiratoryDurationNextCommand = p_inspiratoryDuration;
1187  }
1188 
1189  // Send acknowledgment to the UI
1191 }
1192 
1193 // cppcheck-suppress unusedFunction
1194 void MainController::onPeakPressureAlarmThreshold(int16_t p_peakPressureAlarmThreshold) {
1195  if ((p_peakPressureAlarmThreshold >= CONST_MIN_PEAK_PRESSURE_ALARM_THRESHOLD)
1196  && (p_peakPressureAlarmThreshold <= CONST_MAX_PEAK_PRESSURE_ALARM_THRESHOLD)) {
1197  m_peakPressureAlarmThresholdNextCommand = p_peakPressureAlarmThreshold;
1198  }
1199 
1200  // Send acknowledgment to the UI
1202 }
1203 
1204 // cppcheck-suppress unusedFunction
1205 void MainController::onPatientHeight(int16_t p_patientHeight) {
1206  if ((p_patientHeight >= CONST_MIN_PATIENT_HEIGHT)
1207  && (p_patientHeight <= CONST_MAX_PATIENT_HEIGHT)) {
1208  m_patientHeight = p_patientHeight;
1209  } else {
1211  }
1212 
1213  // Send acknowledgment to the UI
1215 
1217 }
1218 
1219 // cppcheck-suppress unusedFunction
1220 void MainController::onPatientGender(int16_t p_patientGender) {
1221  if ((p_patientGender >= CONST_MIN_PATIENT_GENDER)
1222  && (p_patientGender <= CONST_MAX_PATIENT_GENDER)) {
1223  m_patientGender = p_patientGender;
1224  } else {
1226  }
1227 
1228  // Send acknowledgment to the UI
1230 
1232 }
1233 
1234 // cppcheck-suppress unusedFunction
1236  int32_t theoricalWeight = 0;
1237  int32_t tidalVolume = 0;
1238 
1239  // Male
1240  if (m_patientGender == 0) {
1241  theoricalWeight = 23 * (m_patientHeight * m_patientHeight) / 10000;
1242  } else {
1243  theoricalWeight = 21 * (m_patientHeight * m_patientHeight) / 10000;
1244  }
1245 
1246  tidalVolume = theoricalWeight * 7;
1247 
1248  tidalVolume = tidalVolume - (tidalVolume % 10);
1249 
1250  m_tidalVolumeNextCommand = tidalVolume;
1251  m_peepNextCommand = 50u;
1253  m_plateauPressureNextCommand = m_peepNextCommand + ((172 * tidalVolume) / 1000);
1254 
1256  (static_cast<int32_t>(m_cyclesPerMinuteCommand) * tidalVolume) - 1500;
1258  (static_cast<int32_t>(m_cyclesPerMinuteCommand) * tidalVolume) + 1500;
1260  (static_cast<int32_t>(m_cyclesPerMinuteCommand) * tidalVolume) - 1500;
1262  (static_cast<int32_t>(m_cyclesPerMinuteCommand) * tidalVolume) + 1500;
1265  m_lowTidalVolumeAlarmThresholdNextCommand = tidalVolume - 100;
1266  m_highTidalVolumeAlarmThresholdNextCommand = tidalVolume + 100;
1269 }
AlarmController alarmController
Instance of the alarm controller.
#define RCM_SW_20
#define RCM_SW_15
#define RCM_SW_3
#define RCM_SW_5
#define RCM_SW_18
#define RCM_SW_23
#define RCM_SW_19
#define RCM_SW_6
#define RCM_SW_1
#define RCM_SW_9
#define RCM_SW_14
#define RCM_SW_8
#define RCM_SW_4
#define RCM_SW_21
#define RCM_SW_2
#define RCM_SW_22
#define RCM_SW_10
#define RCM_SW_7
uint32_t getBatteryLevelX100()
Returns battery level x100 for better accuracy.
Definition: battery.cpp:129
uint32_t getBatteryLevel()
Returns battery level.
Definition: battery.cpp:123
Blower blower
Definition: blower.cpp:20
bool isSnoozed() const
Check if alarms are currently snoozed.
void updateCoreData(uint32_t p_tick, uint16_t p_pressure, CyclePhases p_phase, uint32_t p_cycle_number)
Update internal state of alarm controller with data from pressure controller.
void detectedAlarm(uint8_t p_alarmCode, uint32_t p_cycleNumber, uint32_t p_expected, uint32_t p_measured)
Mark a specific alarm as detected.
uint8_t * triggeredAlarms()
Get the alarms triggered during this cycle.
void updateEnabledAlarms(Alarms enabledAlarms)
Update the list of enabled alarms (alarms not provided here will have no effects)
void notDetectedAlarm(uint8_t p_alarmCode)
Reset detection of a specific alarm.
uint16_t getSpeed() const
Get speed value.
Definition: blower.cpp:101
void stop()
Stops the blower.
Definition: blower.cpp:105
void execute()
Definition: blower.cpp:55
Controls breathing cycle.
void onTargetInspiratoryFlow(uint16_t p_targetInspiratoryFlow)
Set the inspiratory flow target.
void sendStopMessageToUi()
Send a "stopped" telemetry message.
int16_t m_pressure
Measured pressure.
void onTriggerOffsetSet(uint16_t p_triggerOffset)
Set the desired offset for expiratory trigger.
void onInspiratoryDuration(uint16_t p_inspiratoryDuration)
Set the inspiration duration.
void executeCommands()
Send the computed commands to actuators.
void updatePhase()
Update the cycle phase.
uint16_t m_PlateauMeasureCount
Count for calulating plateau value.
void onPeakPressureIncrease()
Increase the desired peak pressure.
int16_t m_tiMaxNextCommand
Max duration of inspiration in ms for next cycle.
uint32_t m_cycleNb
Number of elapsed cycles since beginning.
void updateFakeExpiratoryFlow()
Calculate expiratory flow from pressure and valve angle.
uint16_t m_expiratoryTermCommand
Actual expiratory term.
int16_t m_plateauPressureCommand
Actual desired plateau pressure.
int32_t m_highExpiratoryMinuteVolumeAlarmThresholdCommand
Threshold for high inspiratory minute volume alarm.
int16_t m_expiratoryTriggerFlowNextCommand
Desired expiratory trigger flow for next cycle (in percent of max flow)
int16_t m_peakPressureNextCommand
Peak pressure desired by the operator for the next cycle.
void onCycleSet(uint16_t p_cpm)
Set the desired number of cycles per minute.
int16_t m_inspiratoryDurationNextCommand
Duration of inspiration.
VentilationController * m_ventilationControllerNextCommand
Ventilation controller for the next cycle.
uint32_t m_tick
Actual tick number (given by the main state machine)
int16_t m_tiMinCommand
Minimum duration of inspiration in ms.
void checkCycleAlarm()
At the end of a respiratory cycle, check if some alarms are triggered.
void onLowTidalVolumeAlarmThresholdSet(uint16_t p_lowTidalVolumeAlarmThreshold)
Set threshold on tidal volume below which an alarm is raised.
void onlowRespiratoryRateAlarmThresholdSet(uint16_t p_lowRespiratoryRateAlarmThreshold)
Set alarm threshold for low respiratory rate.
int32_t m_highInspiratoryMinuteVolumeAlarmThresholdNextCommand
Threshold for high inspiratory minute volume alarm for next cycle.
void onPeakPressureDecrease()
Decrease the desired peak pressure.
void onLeakAlarmThresholdSet(uint16_t p_leakAlarmThreshold)
Set the threshold for leak that raise the alarm.
void onCycleIncrease()
Increase the desired number of cycles per minute.
uint16_t m_cyclesPerMinuteNextCommand
Number of cycles per minute desired by the operator for the next cycle.
void onExpiratoryTermSet(uint16_t p_expiratoryTerm)
Set the desired expiratory term.
uint16_t m_cyclesPerMinuteCommand
Actual desired number of cycles per minute.
int16_t m_lastPressureValues[MAX_PRESSURE_SAMPLES]
Last pressure values.
int16_t m_plateauDurationCommand
Plateau duration command (used in VC modes)
int32_t m_highRespiratoryRateAlarmThresholdNextCommand
Threshold for low respiratory rate for next cycle.
void onhighRespiratoryRateAlarmThresholdSet(uint16_t p_highRespiratoryRateAlarmThreshold)
Set alarm threshold for high respiratory rate.
int16_t m_tidalVolumeMeasure
Measured value of the Tidal volume (volume of air pushed in patient lungs in last inspiration)
void onPatientComputePreset()
Updates patient computed params.
int16_t m_rebouncePeakPressureMeasure
Measured value of rebounce peak pressure.
int32_t m_leakAlarmThresholdCommand
Threshold for leak alarm.
int32_t m_lowExpiratoryMinuteVolumeAlarmThresholdNextCommand
Threshold for low inspiratory minute volume alarm for next cycle.
int32_t m_lowInspiratoryMinuteVolumeAlarmThresholdCommand
Threshold for low inspiratory minute volume alarm.
void endRespiratoryCycle(uint32_t p_currentMillis)
End a respiratory cycle.
void onTiMinSet(uint16_t p_tiMin)
Set min inspiratory time.
int32_t m_highTidalVolumeAlarmThresholdCommand
Threshold for high tidal Volume Alarm.
int32_t m_lowExpiratoryMinuteVolumeAlarmThresholdCommand
Threshold for low inspiratory minute volume alarm.
int32_t m_maxExpiratoryFlow
Measured max inspiratory flow.
int16_t m_plateauPressureMeasure
Measured value of the plateau pressure.
int32_t m_highTidalVolumeAlarmThresholdNextCommand
Threshold for high tidal Volume Alarm next cycle.
int16_t pressure() const
Get the current measured pressure.
void onInspiratoryTriggerFlowSet(uint16_t p_inspiratoryTriggerFlow)
Set inspiratory trigger flow.
void onPlateauPressureIncrease()
Increase the desired plateau pressure.
int32_t m_patientHeight
void updateDt(int32_t p_dt)
Input the real duration since the last pressure controller computation.
void updateExpiratoryFlow(int32_t p_currentExpiratoryFlow)
Input an expiratory flow reading.
VentilationController * m_ventilationController
Ventilation controller in use (for everything related to breathing control)
void updateCurrentExpiratoryVolume(int32_t p_expiratoryVolume)
int32_t m_pressureCommand
Requested pressure at a given point in time.
uint16_t m_numberOfPressures
Number of the current cycle's pressures.
uint32_t m_plateauDurationMs
Duration of the plateau.
bool m_isPeepDetected
Is PEEP pressure detected in the cycle?
uint16_t m_ticksPerCycle
Number of hundredth of second per cycle.
void onCycleDecrease()
Decrease the desired number of cycles per minute.
int16_t m_tidalVolumeCommand
Tidal volume command (used in VC modes)
void onTiMaxSet(uint16_t p_tiMax)
Set max inspiratory time.
int16_t m_tiMinNextCommand
Minimum duration of inspiration in ms for next cycle.
int16_t m_peakPressureAlarmThresholdNextCommand
Threshold for peak pressure alarmfor next cycle.
void onPeepPressureIncrease()
Increase the minimal PEEP desired.
void updateCurrentDeliveredVolume(int32_t p_currentDeliveredVolume)
Input the current delivered volume in inspiratory branch since beginning of the respiratory cycle.
void onPeepSet(int16_t p_peep)
Set the desired PEEP.
void onPeepPressureDecrease()
Decrease the minimal PEEP desired.
uint32_t m_inspiratoryValveAngle
Blower valve angle at peak.
int16_t m_pressureTriggerOffsetNextCommand
Desired pressure trigger offset for the next cycle.
uint32_t m_lastBreathPeriodsMsIndex
Index for the m_lastBreathPeriodsMs array.
void onPeakPressureAlarmThreshold(int16_t p_peakPressureAlarmThreshold)
Set the desired threshold for max peak pressure.
int32_t m_highExpiratoryMinuteVolumeAlarmThresholdNextCommand
Threshold for high inspiratory minute volume alarm for next cycle.
int16_t m_tiMaxCommand
Max duration of inspiration in ms.
uint32_t m_sumOfPressures
Sum of the current cycle's pressures.
void onLowExpiratoryMinuteVolumeAlarmThresholdSet(uint16_t p_lowExpiratoryMinuteVolumeAlarmThreshold)
Set alarm threshold for low expiratory minute volume.
int32_t m_lowRespiratoryRateAlarmThresholdCommand
Threshold for low respiratory rate.
int16_t m_inspiratoryTriggerFlowNextCommand
Desired inspiratory trigger flow for next cycle.
int32_t m_lowTidalVolumeAlarmThresholdCommand
Threshold for low tidal Volume Alarm.
void sendMachineState()
Send a "machine state snapshot" telemetry message.
int32_t m_highInspiratoryMinuteVolumeAlarmThresholdCommand
Threshold for high inspiratory minute volume alarm.
void updatePressure(int16_t p_currentPressure)
Input a pressure reading.
int16_t m_inhalationLastPressure
Last pressure of inhalation.
int32_t m_patientGender
void computeTickParameters()
Compute various cycle durations given the desired number of cycles per minute.
void exhale()
Perform the pressure control and compute the actuators commands during the exhalation phase.
bool m_tidalVolumeAlreadyRead
True if Tidal volume has already been read during cycle.
uint32_t m_ticksPerInhalation
Number of hundredth of second per inhalation.
int32_t m_expiratoryVolume
Volume expired by the patient during the exhalation phase.
int16_t m_peepMeasure
Measured value of the PEEP.
void printDebugValues()
Print debug values, used to tweak PID, and triggers.
int32_t m_dt
Time since the last computation (in microsecond)
uint32_t m_cyclesPerMinuteMeasure
Measured number of cycles per minute.
bool m_triggered
Is inspiratory triggered or not?
void setup()
Initialize actuators.
void onPlateauPressureSet(int16_t p_plateauPressure)
Set the desired plateau pressure.
int32_t m_currentDeliveredVolume
Current delivered volume by the blower.
CyclePhases m_phase
Current respiratory cycle phase.
int32_t m_leakAlarmThresholdNextCommand
Threshold for leak alarm for next cycle.
int16_t m_inspiratoryTriggerFlowCommand
Desired inspiratory trigger flow.
int16_t m_peakPressureMeasure
Measured value of peak pressure.
void initRespiratoryCycle()
Begin a respiratory cycle.
int32_t m_lowTidalVolumeAlarmThresholdNextCommand
Threshold for low tidal Volume Alarm next cycle.
int16_t m_pressureTriggerOffsetCommand
Actual pressure trigger offset.
int32_t m_targetInspiratoryFlowNextCommand
inspiratory flow required (used in VC modes) for next cycle
void onPatientHeight(int16_t p_patientHeight)
Set the desired patient height.
void onPatientGender(int16_t p_patientGender)
Set the desired patient gender.
int16_t m_plateauPressureNextCommand
Plateau pressure desired by the operator for the next cycle.
void onLowInspiratoryMinuteVolumeAlarmThresholdSet(uint16_t p_lowInspiratoryMinuteVolumeAlarmThreshold)
Set alarm threshold for low inspiratory minute volume.
int64_t m_PlateauMeasureSum
Sum for calulating plateau value.
void stop(uint32_t p_currentMillis)
Stop the breathing.
int32_t m_targetInspiratoryFlowCommand
inspiratory flow required (used in VC modes)
int16_t m_plateauPressureToDisplay
Measured value of the plateau pressure for display.
void onPlateauPressureDecrease()
Decrease the desired plateau pressure.
VentilationController * m_ventilationControllersTable[NUMBER_OF_VENTILATION_MODES+1u]
Array containing pointers to different ventilation controllers.
int16_t m_peakPressureCommand
Actual desired peak pressure.
void onHighInspiratoryMinuteVolumeAlarmThresholdSet(uint16_t p_highInspiratoryMinuteVolumeAlarmThreshold)
Set alarm threshold for high inspiratory minute volume.
void onVentilationModeSet(uint16_t p_ventilationControllerMode)
Set ventilation mode.
void reachSafetyPosition()
Put actuators in safety position.
void onTargetTidalVolumeSet(uint16_t p_targetTidalVolume)
Set target tidal volume (used in VC modes)
void onHighExpiratoryMinuteVolumeAlarmThresholdSet(uint16_t p_highExpiratoryMinuteVolumeAlarmThreshold)
Set alarm threshold for high expiratory minute volume.
void compute()
Perform the pressure control.
int16_t m_expiratoryTriggerFlowCommand
Desired expiratory trigger flow (in percent of max flow)
void inhale()
Perform the pressure control and compute the actuators commands during the inhalation phase.
int32_t m_highRespiratoryRateAlarmThresholdCommand
Threshold for low respiratory rate.
int16_t m_peepCommand
Actual desired PEEP.
int16_t m_inspiratoryDurationCommand
Duration of inspiration.
uint32_t m_lastBreathPeriodsMs[NUMBER_OF_BREATH_PERIOD]
Period durations of last beathings.
int16_t m_plateauDurationNextCommand
Plateau duration command for next cycle.
uint32_t m_lastEndOfRespirationDateMs
Date of the last ending of a respiration.
int32_t m_lowInspiratoryMinuteVolumeAlarmThresholdNextCommand
Threshold for low inspiratory minute volume alarm for next cycle.
void onPlateauDurationSet(uint16_t p_plateauDuration)
Set the duration of Pause at the end of expiration in VC modes.
uint16_t m_lastPressureValuesIndex
Last pressure index.
int16_t m_tidalVolumeNextCommand
Tidal volume command for next cycle.
int32_t m_expiratoryFlow
Measured inspiratory flow.
int16_t m_peepNextCommand
Desired PEEP for the next cycle.
void updateTick(uint32_t p_tick)
Input a tick number.
int32_t m_maxInspiratoryFlow
Measured max inspiratory flow.
void updateInspiratoryFlow(int32_t p_currentInspiratoryFlow)
Input an inspiratory flow reading.
int32_t m_inspiratoryFlow
Measured inspiratory flow.
bool m_triggerModeEnabledNextCommand
Desired state of enabling of trigger mode for the next cycle.
VentilationModes m_ventilationControllerMode
uint16_t m_expiratoryTermNextCommand
Desired expiratory term for the next cycle.
void onExpiratoryTriggerFlowSet(uint16_t p_expiratoryTriggerFlow)
Set expiratory trigger flow.
bool m_triggerModeEnabledCommand
Actual state of enabling of trigger mode.
void onTriggerModeEnabledSet(uint16_t p_triggerEnabled)
Enable or disable expiratory trigger mode.
void onHighTidalVolumeAlarmThresholdSet(uint16_t p_highTidalVolumeAlarmThreshold)
Set threshold on tidal volume for which an alarm is raised.
MainController()
Default constructor.
int32_t m_lowRespiratoryRateAlarmThresholdNextCommand
Threshold for low respiratory rate for next cycle.
int16_t m_peakPressureAlarmThresholdCommand
Threshold for peak pressure alarm.
int32_t m_lastMaxExpiratoryFlow
Measured max inspiratory flow.
uint16_t command
Value of the requested aperture.
int32_t getSectionBigHoseX100()
void execute()
Command the valve to go to the requested aperture.
void open()
Request opening of the Pressure Valve.
void close()
Request closing of the Pressure Valve.
uint16_t position
Current aperture.
virtual struct Alarms enabledAlarms() const =0
List of alarms that must be enabled for this mode.
virtual void endCycle()=0
End the current breathing cycle.
virtual void exhale()=0
Control the exhalation.
virtual void initCycle()=0
Begin a new breathing cycle.
virtual void inhale()=0
Control the inhalation.
virtual void setup()=0
Initialize controller.
uint8_t readCpuLoadPercent(void)
Get the value of the CPU load.
Definition: cpu_load.cpp:39
VentilationModes
Supported ventilation modes.
Definition: cycle.h:22
@ PC_CMV
PC-CMV (default)
Definition: cycle.h:24
@ VC_AC
VC-AC.
Definition: cycle.h:32
@ VC_CMV
VC-CMV.
Definition: cycle.h:28
@ PC_AC
PC-AC.
Definition: cycle.h:26
@ PC_VSAI
PC-VSAI.
Definition: cycle.h:30
#define NUMBER_OF_VENTILATION_MODES
Definition: cycle.h:9
@ EXHALATION
Exhalation and pause.
Definition: cycle.h:18
@ INHALATION
Inspiration and inspiration holding.
Definition: cycle.h:16
#define DBG_DO(statement)
Expand arbitrary code only when in debug mode.
Definition: debug.h:24
static const int32_t INVALID_ERROR_MARKER
MainController mainController
#define MAX_PRESSURE_SAMPLES
Number of values to aggregate when computing plateau pressure.
uint16_t i
#define CONST_MAX_TRIGGER_OFFSET
Definition: parameters.h:40
#define CONST_MIN_PEAK_PRESSURE_ALARM_THRESHOLD
Definition: parameters.h:77
#define CONST_MAX_HIGH_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:66
#define CONST_MIN_TIDAL_VOLUME
Definition: parameters.h:43
#define DEFAULT_INSPIRATORY_TRIGGER_FLOW_COMMAND
Definition: parameters.h:95
#define CONST_MAX_LOW_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:60
#define CONST_MAX_PLATEAU_DURATION
Definition: parameters.h:54
#define ALARM_THRESHOLD_DIFFERENCE_PERCENT
Definition: parameters.h:312
#define TRIGGER_MODE_ENABLED_BY_DEFAULT
Definition: parameters.h:127
#define DEFAULT_LEAK_ALARM_THRESHOLD
Definition: parameters.h:109
#define VERSION
Current version of the software.
Definition: parameters.h:20
#define CONST_MIN_EXPIRATORY_TRIGGER_FLOW
Definition: parameters.h:48
#define DEFAULT_MIN_INSPIRATION_DURATION_COMMAND
Definition: parameters.h:97
#define CONST_MIN_TRIGGER_OFFSET
Definition: parameters.h:39
#define LED_START_INACTIVE
Definition: parameters.h:258
#define CONST_MIN_HIGH_TIDAL_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:73
#define CONST_MAX_EXPIRATORY_TRIGGER_FLOW
Definition: parameters.h:47
#define PIN_LED_START
Definition: parameters.h:252
#define CONST_MIN_PEEP_PRESSURE
Definition: parameters.h:38
#define CONST_MAX_PATIENT_HEIGHT
Definition: parameters.h:80
#define CONST_MAX_EXPIRATORY_TERM
Definition: parameters.h:86
#define ALARM_THRESHOLD_DIFFERENCE_PRESSURE
Definition: parameters.h:313
#define DEFAULT_HIGH_TIDAL_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:108
#define DEFAULT_LOW_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:101
#define CONST_MIN_MIN_INSPIRATION_DURATION
Definition: parameters.h:49
#define DEFAULT_HIGH_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:103
#define CONST_MAX_PEAK_PRESSURE_ALARM_THRESHOLD
Definition: parameters.h:78
#define CONST_MAX_INSPIRATORY_TRIGGER_FLOW
Definition: parameters.h:45
#define CONST_MIN_INSPIRATORY_TRIGGER_FLOW
Definition: parameters.h:46
#define CONST_MIN_HIGH_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:63
#define CONST_MAX_MAX_INSPIRATION_DURATION
Definition: parameters.h:52
#define CONST_MAX_MIN_INSPIRATION_DURATION
Definition: parameters.h:50
#define ALARM_THRESHOLD_MIN_PRESSURE
Definition: parameters.h:311
#define DEFAULT_LOW_TIDAL_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:107
#define CONST_MAX_PLATEAU_PRESSURE
Definition: parameters.h:35
#define CONST_MIN_EXPIRATORY_TERM
Definition: parameters.h:85
#define CONST_MIN_INSPIRATORY_FLOW
Definition: parameters.h:55
#define MAIN_CONTROLLER_COMPUTE_PERIOD_MS
Definition: parameters.h:28
#define DEFAULT_EXPIRATORY_TRIGGER_FLOW_COMMAND
Definition: parameters.h:96
#define CONST_MIN_PATIENT_GENDER
Definition: parameters.h:81
#define CONST_MAX_PEEP_PRESSURE
Definition: parameters.h:37
#define CONST_MIN_MAX_INSPIRATION_DURATION
Definition: parameters.h:51
#define CONST_MAX_INSPIRATORY_FLOW
Definition: parameters.h:56
#define CONST_MIN_HIGH_RESPIRATORY_RATE_ALARM_THRESHOLD
Definition: parameters.h:69
#define MAIN_CONTROLLER_COMPUTE_PERIOD_MICROSECONDS
Definition: parameters.h:30
#define DEFAULT_LOW_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:102
#define PEAK_PRESSURE_ALARM_THRESHOLD_OFFSET_FROM_PLATEAU
Definition: parameters.h:114
#define AIR_EXHAUST_THRESHOLD_FROM_PEAK_PRESSURE_ALARM
Definition: parameters.h:115
#define DEFAULT_PLATEAU_DURATION_COMMAND
Definition: parameters.h:93
#define CONST_MIN_LOW_RESPIRATORY_RATE_ALARM_THRESHOLD
Definition: parameters.h:67
#define CONST_MIN_PLATEAU_PRESSURE
Definition: parameters.h:36
#define DEFAULT_PLATEAU_COMMAND
Definition: parameters.h:89
#define DEFAULT_CYCLE_PER_MINUTE_COMMAND
Definition: parameters.h:117
#define CONST_MIN_PATIENT_HEIGHT
Definition: parameters.h:79
#define DEFAULT_MAX_INSPIRATION_DURATION_COMMAND
Definition: parameters.h:98
#define MIN_EXPIRATORY_FLOW_OFFSET
Definition: parameters.h:125
#define VALVE_CLOSED_STATE
Angle when closed.
Definition: parameters.h:170
#define DEFAULT_TIDAL_VOLUME_COMMAND
Definition: parameters.h:92
#define CONST_MAX_LOW_TIDAL_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:72
#define DEFAULT_EXPIRATORY_TERM_COMMAND
Definition: parameters.h:91
#define CONST_MAX_INSPIRATORY_DURATION
Definition: parameters.h:58
#define CONST_MIN_LOW_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:61
#define DEFAULT_PEEP_COMMAND
Definition: parameters.h:88
#define CONST_MAX_CYCLE
Definition: parameters.h:118
#define DEFAULT_LOW_RESPIRATORY_RATE_ALARM_THRESHOLD
Definition: parameters.h:105
#define MASS_FLOW_ERROR_VALUE
Definition: parameters.h:302
#define NUMBER_OF_BREATH_PERIOD
Number of periods used for calculating the respiratory rate.
Definition: parameters.h:157
#define DEFAULT_INSPIRATORY_DURATION
Definition: parameters.h:100
#define DEFAULT_TARGET_FLOW_COMMAND
Definition: parameters.h:99
#define CONST_MIN_LEAK_ALARM_THRESHOLD
Definition: parameters.h:76
#define DEFAULT_PATIENT_GENDER
Definition: parameters.h:112
#define CONST_INITIAL_ZERO_VOLUME
Definition: parameters.h:42
#define DEFAULT_PEAK_PRESSURE_COMMAND
Definition: parameters.h:90
#define DEFAULT_PEAK_PRESSURE_ALARM_THRESHOLD
Definition: parameters.h:110
#define DEFAULT_HIGH_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:104
#define CONST_MIN_LOW_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:59
#define CONST_MIN_HIGH_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:65
#define CONST_MAX_LOW_RESPIRATORY_RATE_ALARM_THRESHOLD
Definition: parameters.h:68
#define CONST_MIN_CYCLE
Definition: parameters.h:119
#define CONST_MAX_HIGH_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:64
#define CONST_MAX_LOW_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:62
#define CONST_MIN_INSPIRATORY_DURATION
Definition: parameters.h:57
#define CONST_MAX_HIGH_TIDAL_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:74
#define CONST_INITIAL_ZERO_PRESSURE
Definition: parameters.h:41
#define DEFAULT_TRIGGER_OFFSET
Definition: parameters.h:94
#define CONST_MAX_TIDAL_VOLUME
Definition: parameters.h:44
#define CONST_MAX_PATIENT_GENDER
Definition: parameters.h:82
#define DEFAULT_HIGH_RESPIRATORY_RATE_ALARM_THRESHOLD
Definition: parameters.h:106
#define CONST_MAX_HIGH_RESPIRATORY_RATE_ALARM_THRESHOLD
Definition: parameters.h:70
#define CONST_MIN_PLATEAU_DURATION
Definition: parameters.h:53
#define CONST_MIN_LOW_TIDAL_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:71
#define DEFAULT_PATIENT_HEIGHT
Definition: parameters.h:111
PC_AC_Controller pcAcController
PC_CMV_Controller pcCmvController
PC_VSAI_Controller pcVsaiController
PressureValve inspiratoryValve
PressureValve expiratoryValve
void sendControlAck(uint8_t setting, uint16_t valueValue)
Send a "control ack" message.
Definition: telemetry.cpp:1109
uint8_t mmH2OtoCmH2O(uint16_t pressure)
Convert and round a pressure in mmH2O to a pressure in cmH2O.
Definition: telemetry.cpp:1459
void sendStoppedMessage(uint8_t peakCommand, uint8_t plateauCommand, uint8_t peepCommand, uint8_t cpmCommand, uint8_t expiratoryTerm, bool triggerEnabled, uint8_t triggerOffset, bool alarmSnoozed, uint8_t cpuLoad, VentilationModes ventilationMode, uint8_t inspiratoryTriggerFlow, uint8_t expiratoryTriggerFlow, uint16_t tiMinValue, uint16_t tiMaxValue, uint8_t lowInspiratoryMinuteVolumeAlarmThreshold, uint8_t highInspiratoryMinuteVolumeAlarmThreshold, uint8_t lowExpiratoryMinuteVolumeAlarmThreshold, uint8_t highExpiratoryMinuteVolumeAlarmThreshold, uint8_t lowRespiratoryRateAlarmThreshold, uint8_t highRespiratoryRateAlarmThreshold, uint16_t targetTidalVolumeValue, uint16_t lowTidalVolumeAlarmThresholdValue, uint16_t highTidalVolumeAlarmThresholdValue, uint16_t plateauDurationValue, uint16_t leakAlarmThresholdValue, uint8_t targetInspiratoryFlow, uint16_t inspiratoryDurationCommandValue, uint16_t batteryLevelValue, uint8_t currentAlarmCodes[ALARMS_SIZE], uint16_t localeValue, uint8_t patientHeight, uint8_t patientGender, uint16_t peakPressureAlarmThresholdValue)
Send a "stopped" message.
Definition: telemetry.cpp:164
void sendDataSnapshot(uint16_t centileValue, int16_t pressureValue, CyclePhases phase, uint8_t blowerValvePosition, uint8_t patientValvePosition, uint8_t blowerRpm, uint8_t batteryLevel, int16_t inspiratoryFlowValue, int16_t expiratoryFlowValue)
Send a "data snapshot" message.
Definition: telemetry.cpp:481
void sendMachineStateSnapshot(uint32_t cycleValue, uint8_t peakCommand, uint8_t plateauCommand, uint8_t peepCommand, uint8_t cpmCommand, uint16_t previousPeakPressureValue, uint16_t previousPlateauPressureValue, uint16_t previousPeepPressureValue, uint8_t currentAlarmCodes[ALARMS_SIZE], uint16_t volumeValue, uint8_t expiratoryTerm, bool triggerEnabled, uint8_t triggerOffset, uint8_t previouscpmValue, bool alarmSnoozed, uint8_t cpuLoad, VentilationModes ventilationMode, uint8_t inspiratoryTriggerFlow, uint8_t expiratoryTriggerFlow, uint16_t tiMinValue, uint16_t tiMaxValue, uint8_t lowInspiratoryMinuteVolumeAlarmThreshold, uint8_t highInspiratoryMinuteVolumeAlarmThreshold, uint8_t lowExpiratoryMinuteVolumeAlarmThreshold, uint8_t highExpiratoryMinuteVolumeAlarmThreshold, uint8_t lowRespiratoryRateAlarmThreshold, uint8_t highRespiratoryRateAlarmThreshold, uint16_t targetTidalVolumeValue, uint16_t lowTidalVolumeAlarmThresholdValue, uint16_t highTidalVolumeAlarmThresholdValue, uint16_t plateauDurationValue, uint16_t leakAlarmThresholdValue, uint8_t targetInspiratoryFlow, uint16_t inspiratoryDurationCommandValue, uint16_t previousInspiratoryDurationValue, uint16_t batteryLevelValue, uint16_t localeValue, uint8_t patientHeight, uint8_t patientGender, uint16_t peakPressureAlarmThresholdValue)
Send a "machine state snapshot" message.
Definition: telemetry.cpp:592
VC_AC_Controller vcAcController
VC_CMV_Controller vcCmvController