From 7b75996cf092b2b2f1b7c0867b85bc0a83d73e8d Mon Sep 17 00:00:00 2001 From: Laure Millet Date: Sun, 29 Nov 2020 11:57:26 -0800 Subject: [PATCH] Implement SRS-0015 and SRS-0020 --- include/application/tasks/ventilation.h | 11 +++ src/application/tasks/ventilation.c | 40 ++++++----- test/test_runner.c | 6 ++ test/ventilation_test.c | 95 +++++++++++++++++++++++-- test/ventilation_test.h | 6 ++ 5 files changed, 137 insertions(+), 21 deletions(-) diff --git a/include/application/tasks/ventilation.h b/include/application/tasks/ventilation.h index 162f051..f03dc9e 100644 --- a/include/application/tasks/ventilation.h +++ b/include/application/tasks/ventilation.h @@ -9,6 +9,7 @@ #include "platform/common.h" #define MAX_CIRCUIT_PRESSURE_FOR_OPENING_INS_VALVE_CSP 32 //todo replace this value by the real value +#define MIN_CIRCUIT_PRESSURE_FOR_OPENING_EXP_VALVE_CSP 8 //todo replace this value by the real value /* * SLS-0055 @@ -27,4 +28,14 @@ uint32_t get_circuit_pressure(); */ void start_inspiration(); +/** + * Ends inspiration and Start Expiration + * + * Verify that the pressure is acceptable to start an expiration + * Ends the inspiration by closing the inspiratory valve + * Starts the expiration by opening the expiratory valve + * SRS-0015 and SRS-0020 + */ +void start_expiration(); + #endif /* INC_PLATFORM_VENTILATION_H_ */ diff --git a/src/application/tasks/ventilation.c b/src/application/tasks/ventilation.c index 28c1a1e..91e2213 100644 --- a/src/application/tasks/ventilation.c +++ b/src/application/tasks/ventilation.c @@ -15,9 +15,7 @@ //todo rename this so that it does not look like they are time #define INSPIRATION 1 -#define INSPIRATORY_PAUSE 2 -#define EXPIRATION 3 -#define EXPIRATORY_PAUSE 4 +#define EXPIRATION 2 /* * the time the current breath cycle was supposed to start @@ -27,11 +25,14 @@ static int start_current_breath_cycle = 0; /* * Phase of the ventilation * This should always be one of - * INSPIRATION | INSPIRATORY_PAUSE - * | EXPIRATION | EXPIRATORY_PAUSE + * INSPIRATION | EXPIRATION + * The pauses are obtained through the mechanical parts of the system + * and not the software parts. + * The inspiration pause is obtained through the maximal pressure + * The expiration pause is obtained through the PEEP valve */ -static int ventilation_phase = EXPIRATORY_PAUSE; +static int ventilation_phase = EXPIRATION; uint32_t get_circuit_pressure() { @@ -50,20 +51,12 @@ void ventilation(){ * a waiting period of breath_cycle_duration for the first ventilation preiod */ switch (ventilation_phase) { - case EXPIRATORY_PAUSE: + case EXPIRATION: start_inspiration(); break; case INSPIRATION: - // statements - break; - - case INSPIRATORY_PAUSE: - // statements - break; - - case EXPIRATION: - // statements + start_expiration(); break; default: @@ -86,13 +79,26 @@ void start_inspiration(){ } } +void start_expiration(){ + uint32_t current_time = get_current_time(); + uint32_t selected_inspiratory_time; + get_selected_inspiratory_time(&selected_inspiratory_time); + if (current_time >= start_current_breath_cycle + selected_inspiratory_time) { + if (get_circuit_pressure() > MIN_CIRCUIT_PRESSURE_FOR_OPENING_EXP_VALVE_CSP){ + close_inspiratory_valve(); + open_expiratory_valve(); + ventilation_phase = EXPIRATION; + } + } +} + /* * function for test only */ void reset_to_inspiration_start(){ - ventilation_phase = EXPIRATORY_PAUSE; + ventilation_phase = EXPIRATION; } int get_ventilation_phase() { diff --git a/test/test_runner.c b/test/test_runner.c index 88bb0e4..8e55e20 100644 --- a/test/test_runner.c +++ b/test/test_runner.c @@ -6,10 +6,16 @@ int main(int argc, char **argv) { "getCircuitPressure_validValues_returnsMeanPressure"); test(startInspiration_afterOneInspiration_openInspiratoryValve, "startInspiration_afterOneInspiration_openInspiratoryValve"); + test(startExpiration_afterOneInspiration_closeInspiratoryValve, + "startExpiration_afterOneInspiration_closeInspiratoryValve"); test(startInspiration_afterOneInspiration_setsVentilationPhaseToInspiration, "startInspiration_afterOneInspiration_setsVentilationPhaseToInspiration"); + test(startExpiration_afterOneInspiration_opensExpiratoryValve, + "startExpiration_afterOneInspiration_opensExpiratoryValve"); test(startInspiration_afterTwoInspirations_updatesStartCurrentBreathCycle, "startInspiration_afterTwoInspirations_updatesStartCurrentBreathCycle"); + test(startExpiration_afterThreeInspiration_updatesVentilationPhase, + "startExpiration_afterThreeInspiration_updatesVentilationPhase"); test(startInspiration_duringInspiration_doesNotUpdateStartOfcurrentBreathCycle, "startInspiration_duringInspiration_doesNotUpdateStartOfcurrentBreathCycle"); test(startInspiration_duringInspiration_doesNotChangeVentilationPhase, diff --git a/test/ventilation_test.c b/test/ventilation_test.c index eaf2108..0246ca2 100644 --- a/test/ventilation_test.c +++ b/test/ventilation_test.c @@ -44,7 +44,7 @@ int startInspiration_afterOneInspiration_openInspiratoryValve() { //initialize the function get_current_time int breath_cycle_duration = 60000/RR[0]; - int times[1] = {breath_cycle_duration + 1}; + int times[1] = {breath_cycle_duration}; set_current_time(times); //initialize the function to get circuit pressure @@ -63,6 +63,35 @@ int startInspiration_afterOneInspiration_openInspiratoryValve() { assertTrue(inspiratory_valve_status == VALVE_OPEN); } +int startExpiration_afterOneInspiration_closeInspiratoryValve() { + //initialize the function get_respiratory_rate + uint32_t RR[1] = {20}; + status_t status[1] = {STATUS_OK}; + set_respiratory_rate(RR, status); + + int breath_cycle_duration = 60000/RR[0]; + + //initialize the selected inspiratory time + uint32_t insp_time [1] = {breath_cycle_duration/2}; + set_selected_inspiratory_time(insp_time, status); + + //initialize the function get_current_time + int times[1] = {breath_cycle_duration + insp_time[0]}; + set_current_time(times); + + //initialize the function to get circuit pressure + uint32_t inspiratory[1] = {40}; + uint32_t expiratory[1] = {41}; + set_inspiratory_pressure(inspiratory, status); + set_expiratory_pressure(expiratory, status); + + //reinitialize the system to be sure that the valve wasn't previously open + start_expiration(); + + int inspiratory_valve_status = get_inspiratory_valve_status(); + assertTrue(inspiratory_valve_status == VALVE_CLOSE); +} + int startInspiration_afterOneInspiration_setsVentilationPhaseToInspiration() { //initialize the function get_respiratory_rate uint32_t RR[1] = {20}; @@ -71,7 +100,7 @@ int startInspiration_afterOneInspiration_setsVentilationPhaseToInspiration() { //initialize the function get_current_time int breath_cycle_duration = 60000/RR[0]; - int times[1] = {(breath_cycle_duration + 1) * 2}; + int times[1] = {(breath_cycle_duration) * 2}; set_current_time(times); //initialize the function to get circuit pressure @@ -88,6 +117,35 @@ int startInspiration_afterOneInspiration_setsVentilationPhaseToInspiration() { assertTrue(ventilation_phase == 1); } +int startExpiration_afterOneInspiration_opensExpiratoryValve() { + //initialize the function get_respiratory_rate + uint32_t RR[1] = {20}; + status_t status[1] = {STATUS_OK}; + set_respiratory_rate(RR, status); + + int breath_cycle_duration = 60000/RR[0]; + + //initialize the selected inspiratory time + uint32_t insp_time [1] = {breath_cycle_duration/2}; + set_selected_inspiratory_time(insp_time, status); + + //initialize the function get_current_time + int times[1] = {breath_cycle_duration * 2 + insp_time[0]}; + set_current_time(times); + + //initialize the function to get circuit pressure + uint32_t inspiratory[1] = {40}; + uint32_t expiratory[1] = {41}; + set_inspiratory_pressure(inspiratory, status); + set_expiratory_pressure(expiratory, status); + + //reinitialize the system to be sure that the valve wasn't previously open + start_expiration(); + + int expiratory_valve_status = get_expiratory_valve_status(); + assertTrue(expiratory_valve_status == VALVE_OPEN); +} + int startInspiration_afterTwoInspirations_updatesStartCurrentBreathCycle() { //initialize the function get_respiratory_rate uint32_t RR[1] = {20}; @@ -96,7 +154,7 @@ int startInspiration_afterTwoInspirations_updatesStartCurrentBreathCycle() { //initialize the function get_current_time int breath_cycle_duration = 60000/RR[0]; - int time = (breath_cycle_duration + 1) * 3; + int time = (breath_cycle_duration) * 3; int times[1] = {time}; set_current_time(times); @@ -114,6 +172,35 @@ int startInspiration_afterTwoInspirations_updatesStartCurrentBreathCycle() { assertTrue(time_of_start_current_breath_cycle == time); } +int startExpiration_afterThreeInspiration_updatesVentilationPhase() { + //initialize the function get_respiratory_rate + uint32_t RR[1] = {20}; + status_t status[1] = {STATUS_OK}; + set_respiratory_rate(RR, status); + + int breath_cycle_duration = 60000/RR[0]; + + //initialize the selected inspiratory time + uint32_t insp_time [1] = {breath_cycle_duration/2}; + set_selected_inspiratory_time(insp_time, status); + + //initialize the function get_current_time + int times[1] = {breath_cycle_duration * 3 + insp_time[0]}; + set_current_time(times); + + //initialize the function to get circuit pressure + uint32_t inspiratory[1] = {40}; + uint32_t expiratory[1] = {41}; + set_inspiratory_pressure(inspiratory, status); + set_expiratory_pressure(expiratory, status); + + //reinitialize the system to be sure that the valve wasn't previously open + start_expiration(); + + int ventilation_phase = get_ventilation_phase(); + assertTrue(ventilation_phase == 2); +} + int startInspiration_duringInspiration_doesNotopenInspiratoryValve() { int times[1] = {0}; set_current_time (times); @@ -158,7 +245,7 @@ int startInspiration_duringInspiration_doesNotChangeVentilationPhase() { start_inspiration(); int ventilation_phase = get_ventilation_phase(); - assertTrue(ventilation_phase == 4); + assertTrue(ventilation_phase == 2); } int startInspiration_duringInspiration_doesNotUpdateStartOfcurrentBreathCycle() { diff --git a/test/ventilation_test.h b/test/ventilation_test.h index f9daa5e..3f1a5bb 100644 --- a/test/ventilation_test.h +++ b/test/ventilation_test.h @@ -7,6 +7,12 @@ int getCircuitPressure_validValues_returnsMeanPressure(); int startInspiration_afterOneInspiration_openInspiratoryValve(); +int startExpiration_afterOneInspiration_closeInspiratoryValve(); + +int startExpiration_afterOneInspiration_opensExpiratoryValve(); + +int startExpiration_afterThreeInspiration_updatesVentilationPhase(); + int startInspiration_duringInspiration_doesNotopenInspiratoryValve(); int startInspiration_afterOneInspiration_setsVentilationPhaseToInspiration();