Skip to content
Snippets Groups Projects
Commit a98a5ced authored by Karol Hennessy's avatar Karol Hennessy
Browse files

fixes to structs in python

parent d1af22ed
Branches
No related merge requests found
......@@ -115,8 +115,15 @@ float BreathingLoop::getFlow(){
if ((dp_raw -0.5) == 0.000)
sign = 0.0;
float dp = sign*pow(((dp_raw/0.4)-1.25),2) * 5.25;
//
float flow = dp;
return dp;
// NLPM - normal litres per minute = 1 Si Litre per minute * (293.15/T)*(P/1013.25)
float T = 25+273.15; //_readings_avgs.temperature_buffer;
float P = _readings_avgs.pressure_patient;
float nlpm_factor = (293.15/T)*(P/1013.25);
return flow;
/*
float R = 0.08206 * 1/0.98692 *1000; // mbar *l * mol-1 *K-1
float T = 25+273.15; //_readings_avgs.temperature_buffer;
......@@ -127,7 +134,7 @@ float BreathingLoop::getFlow(){
float n1 = _readings_avgs.pressure_buffer * V_buffer/(R*T);
float n2 = _readings_avgs.pressure_inhale * V_tube/(R*T);
float M = 15.99; // molar mass O2 g.mol-1
float rho = 1.42 * 1000; // density ) 2kg/m3 @ 25 deg
float rho = 1.42 * 1000; // density 1.2kg/m3 @ 25 deg
*/
}
......@@ -135,7 +142,7 @@ float BreathingLoop::getFlow(){
float BreathingLoop::getIERatio(){
// TODO : check with Oscar/Xavier
float total_inhale_time = _states_durations.inhale + _states_durations.pause;
float total_exhale_time = _states_durations.exhale_fill + _states_durations.exhale_fill;
float total_exhale_time = _states_durations.exhale_fill + _states_durations.exhale;
return total_inhale_time/total_exhale_time;
}
......@@ -339,8 +346,8 @@ void BreathingLoop::FSM_breathCycle()
break;
case BL_STATES::EXHALE:
// TODO: exhale timeout based on
// (inhale_time* (Exhale/Inhale ratio)) - fill time
_states_durations.exhale = calculateTimeoutExhale();
// (inhale_time* (Exhale/Inhale ratio)) - exhale fill time
_states_durations.exhale = calculateDurationExhale();
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, 0.9 * VALVE_STATE::OPEN, VALVE_STATE::CLOSED);
_fsm_timeout = _states_durations.exhale;
//update total cycle time
......@@ -430,9 +437,13 @@ states_durations &BreathingLoop::getDurations() {
return _states_durations;
}
// FIXME 1/1 has to be replaced using exhale/inhale ratio
uint32_t BreathingLoop::calculateTimeoutExhale() {
return static_cast<uint32_t>(_states_durations.inhale * ( 1/ 1) ) - _states_durations.buff_fill;
uint32_t BreathingLoop::calculateDurationExhale() {
// TODO : should have sane minimum times
// for now min = 100ms
uint32_t exhale_duration = (_states_durations.inhale * getIERatio()) - _states_durations.exhale_fill ;
if (exhale_duration < 100)
exhale_duration = 100;
return static_cast<uint32_t>(exhale_duration);
}
ValvesController* BreathingLoop::getValvesController()
......
......@@ -88,7 +88,7 @@ private:
readings<uint16_t> _calib_avgs;
// timeouts
uint32_t calculateTimeoutExhale();
uint32_t calculateDurationExhale();
states_durations _states_durations = {10000, 600, 600, 100, 600, 100, 100, 1000, 500, 600, 400};
// readings
......
......@@ -178,7 +178,7 @@ struct readback_data_format {
uint8_t valve_inhale = 0;
uint8_t valve_exhale = 0;
uint8_t valve_purge = 0;
uint8_t ventilation_mode = 0;
uint8_t ventilation_mode = CMD_SET_MODE::HEV_MODE_PS;
uint8_t valve_inhale_percent = 0; // replaced by a min level and a max level; bias inhale level. very slightly open at "closed" position
uint8_t valve_exhale_percent = 0;
......
......@@ -106,8 +106,8 @@ void loop()
breathing_loop.FSM_breathCycle();
ui_loop.reportFastReadings();
// ui_loop.reportReadbackValues();
// ui_loop.reportCycleReadings();
ui_loop.reportReadbackValues();
ui_loop.reportCycleReadings();
// per cycle sender
comms.sender();
......
......@@ -46,10 +46,10 @@ class CMD_SET_TIMEOUT(Enum):
EXHALE = 11
class CMD_SET_MODE(Enum):
HEV_MODE_PS = auto()
HEV_MODE_CPAP = auto()
HEV_MODE_PRVC = auto()
HEV_MODE_TEST = auto()
HEV_MODE_PS = 1
HEV_MODE_CPAP = 2
HEV_MODE_PRVC = 3
HEV_MODE_TEST = 4
@unique
class ALARM_TYPE(Enum):
......@@ -192,7 +192,7 @@ class BaseFormat():
@dataclass
class DataFormat(BaseFormat):
# subclass dataformat
_dataStruct = Struct("<BIBBHHHHHHHHHHHIII")
_dataStruct = Struct("<BIBBHHHHHHHHHHHfff")
_type = PAYLOAD_TYPE.DATA
# subclass member variables
......@@ -251,7 +251,7 @@ class DataFormat(BaseFormat):
# =======================================
@dataclass
class ReadbackFormat(BaseFormat):
_dataStruct = Struct("<BIBHHHHHHHHHHHBBBBBBBBBBBBBBI")
_dataStruct = Struct("<BIBHHHHHHHHHHHBBBBBBBBBBBBBBf")
_type = PAYLOAD_TYPE.DATA
data_type: int = DATA_TYPE.READBACK
......@@ -272,7 +272,7 @@ class ReadbackFormat(BaseFormat):
valve_inhale: int = 0
valve_exhale: int = 0
valve_purge: int = 0
ventilation_mode: int = 0
ventilation_mode: int = 0 #CMD_SET_MODE.HEV_MODE_PS
valve_inhale_percent: int = 0
valve_exhale_percent: int = 0
......@@ -327,7 +327,7 @@ class ReadbackFormat(BaseFormat):
@dataclass
class CycleFormat(BaseFormat):
# subclass dataformat
_dataStruct = Struct("<BIBIIIIIIIIIHHHHBHHB")
_dataStruct = Struct("<BIBfffffffffHHHHBHHB")
_type = PAYLOAD_TYPE.DATA
data_type: int = DATA_TYPE.CYCLE
......
......@@ -232,7 +232,7 @@ class CommsControl():
payload = CommsCommon.ReadbackFormat()
elif data_type == CommsCommon.DATA_TYPE.CYCLE:
payload = CommsCommon.CycleFormat()
elif data_type == CommsCommon.DATA_TYPE.THRESHOLD:
elif data_type == CommsCommon.DATA_TYPE.THRESHOLDS:
# FIXME: nothing yet defined, TBD!!
return False
else:
......
......@@ -16,8 +16,8 @@ class Dependant(object):
self._lli.bind_to(self.update_llipacket)
def update_llipacket(self, payload):
#logging.info(f"payload received: {payload}")
logging.info(f"payload received: {payload.fsm_state}")
logging.info(f"payload received: {payload}")
#logging.info(f"payload received: {payload.fsm_state}")
#logging.info(f"payload received: {payload.timestamp}")
#logging.info(f"payload received: {payload.readback_valve_o2_in} {payload.readback_valve_inhale} {payload.readback_valve_exhale} {payload.readback_valve_purge} {payload.fsm_state}")
self._llipacket = payload.getDict() # returns a dict
......@@ -28,7 +28,6 @@ dep = Dependant(comms)
# initialise as start command, automatically executes toByteArray()
cmd = CommandFormat(cmd_type=CMD_TYPE.GENERAL.value, cmd_code=CMD_GENERAL.START.value, param=0)
print(cmd)
time.sleep(4)
comms.writePayload(cmd)
print('sent cmd start')
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment