Skip to content

Commit

Permalink
Implement SRS-0015 and SRS-0020
Browse files Browse the repository at this point in the history
  • Loading branch information
LMcslabs committed Nov 30, 2020
1 parent 461634c commit 7b75996
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 21 deletions.
11 changes: 11 additions & 0 deletions include/application/tasks/ventilation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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_ */
40 changes: 23 additions & 17 deletions src/application/tasks/ventilation.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand All @@ -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:
Expand All @@ -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() {
Expand Down
6 changes: 6 additions & 0 deletions test/test_runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
95 changes: 91 additions & 4 deletions test/ventilation_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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};
Expand All @@ -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
Expand All @@ -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};
Expand All @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down
6 changes: 6 additions & 0 deletions test/ventilation_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 7b75996

Please sign in to comment.