Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_ */
70 changes: 40 additions & 30 deletions src/application/tasks/ventilation.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,24 @@

//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
*/
static int start_current_breath_cycle = 0;

/*
* the time the current breath cycle was supposed to start
*/
// static int breath_cycle_duration = 125; //to do replace this value by the real one

/*
* 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,21 +46,17 @@ uint32_t get_circuit_pressure() {


void ventilation(){
/*Attention there is no initialisation of start_current_breath_cycle for the
* ventilation to start as soon as the code is called this will lead to a
* 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 @@ -74,27 +66,45 @@ void ventilation(){

void start_inspiration(){
uint32_t current_time = get_current_time();
uint32_t RR = 0;
uint32_t breath_cycle_duration = 125;
if (get_respiratory_rate(& RR) == STATUS_OK) {
breath_cycle_duration = RR / 60000;
}
uint32_t RR = 15;
uint32_t breath_cycle_duration;
get_respiratory_rate(&RR);
breath_cycle_duration = 60000 / RR;
if (current_time >= start_current_breath_cycle + breath_cycle_duration) {
if (get_circuit_pressure() < MAX_CIRCUIT_PRESSURE_FOR_OPENING_INS_VALVE_CSP) {
start_current_breath_cycle = current_time;
if (get_circuit_pressure() > MAX_CIRCUIT_PRESSURE_FOR_OPENING_INS_VALVE_CSP) {
dss();
} else {
open_inspiratory_valve();
ventilation_phase = 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() {
return ventilation_phase;
}

int get_start_current_breath_cycle() {
return start_current_breath_cycle;
}
10 changes: 3 additions & 7 deletions test/stubs/clinician_input_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ static uint32_t* RR_to_return;
static status_t* status_RR_to_return;
static int RR_current_call = 0;

void set_respiratory_rate(uint32_t* RR, status_t* status, size_t size){
free(RR_to_return);
free(status_RR_to_return);
RR_to_return = (uint32_t*) malloc(sizeof(*RR) * size);
status_RR_to_return = (status_t*) malloc(sizeof(*status) * size);
memcpy(RR_to_return, RR, sizeof(*RR) * size);
memcpy(status_RR_to_return, status, sizeof(*status) * size);
void set_respiratory_rate(uint32_t* RR, status_t* status) {
RR_to_return = RR;
status_RR_to_return = status;
RR_current_call = 0;
}

Expand Down
4 changes: 2 additions & 2 deletions test/stubs/clinician_input_stub.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* clinician_info_stub.h
* clinician_input_stub.h
*
* Stub for the function that retreive the clinician inputs
*/
Expand All @@ -8,7 +8,7 @@
#include <stdint.h>
#include "platform/common.h"

void set_respiratory_rate(uint32_t* RR, status_t* status, size_t size);
void set_respiratory_rate(uint32_t* RR, status_t* status);

status_t get_respiratory_rate(uint32_t * RR);

Expand Down
6 changes: 2 additions & 4 deletions test/stubs/system_info_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
static int* time_to_return;
static int current_call = 0;

void set_current_time(int* times, size_t size){
free(time_to_return);
time_to_return = (int*) malloc(sizeof(*times) * size);
memcpy(time_to_return, times, sizeof(*times) * size);
void set_current_time(int* times){
time_to_return = times;
current_call = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion test/stubs/system_info_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <stddef.h>

void set_current_time(int* times, size_t size);
void set_current_time(int* times);

int get_current_time();

26 changes: 21 additions & 5 deletions test/test_runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@
#include "test_util.h"

int main(int argc, char **argv) {
test(startVentilation_afterOneInspiration_openInspiratoryValve,
"startVentilation_afterOneInspiration_openInspiratoryValve");
test(startVentilation_duringInspiration_doesNotopenInspiratoryValve,
"startVentilation_duringInspiration_doesNotopenInspiratoryValve");
test(getCircuitPressure_validValues_returnsMeanPressure,
"getCircuitPressure_validValues_returnsMeanPressure");
"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,
"startInspiration_duringInspiration_doesNotChangeVentilationPhase");
test(startInspiration_duringInspiration_doesNotopenInspiratoryValve,
"startInspiration_duringInspiration_doesNotopenInspiratoryValve");
test(startInspiration_circuitPressureTooHigh_DoesNotStartCurrentBreathCycle,
"startInspiration_circuitPressureToHigh_DoesNotStartCurrentBreathCycle");

int result = print_result();
return !result;
Expand Down
Loading