diff --git a/arduino/hev_prototype_v1/src/BreathingLoop.cpp b/arduino/hev_prototype_v1/src/BreathingLoop.cpp index e7771ad21518167d09dd103d6efb1c2a159cb1a8..d73a89ca76f5dd8e6c8f28717506f1351046f4d4 100644 --- a/arduino/hev_prototype_v1/src/BreathingLoop.cpp +++ b/arduino/hev_prototype_v1/src/BreathingLoop.cpp @@ -1088,7 +1088,6 @@ bool BreathingLoop::exhaleTrigger() if(en == true){ //logMsg("exhale trigger"); uint32_t tnow = static_cast<uint32_t>(millis()); - valve_params vp = _valves_controller.getValveParams(); if((_running_avg_flow < (_targets_current->exhale_trigger_threshold * _peak_flow)) && (tnow - _peak_flow_time >= 100)){ // wait 10ms after peak //TODO - check we're past 'peak' diff --git a/arduino/hev_prototype_v1/src/UILoop.cpp b/arduino/hev_prototype_v1/src/UILoop.cpp index d1878449375c376516fb80efebc9457ed90939a7..05753f76509dcb5199111f37749c82ba661b18b5 100644 --- a/arduino/hev_prototype_v1/src/UILoop.cpp +++ b/arduino/hev_prototype_v1/src/UILoop.cpp @@ -388,6 +388,12 @@ int UILoop::doCommand(cmd_format &cf) // case CMD_TYPE::SET_PERSONAL: // cmdSetPersonal(cf); // break; + case CMD_TYPE::GET_THRESHOLD_MIN : + cmdGetThresholdMin(cf); + break; + case CMD_TYPE::GET_THRESHOLD_MAX : + cmdGetThresholdMax(cf); + break; default: break; } @@ -486,13 +492,49 @@ void UILoop::cmdGetTarget(cmd_format &cf){ // FIXME shouldn't these use setThresholdMin,Max ...? void UILoop::cmdSetThresholdMin(cmd_format &cf) { - setAlarm<float>(static_cast<ALARM_CODES>(cf.cmd_code), _alarm_loop->getThresholdsMin(), cf.param); + ALARM_CODES alarm_code = static_cast<ALARM_CODES>(cf.cmd_code); + setAlarm<float>(alarm_code, _alarm_loop->getThresholdsMin(), cf.param); + reportThresholdMin(alarm_code); } void UILoop::cmdSetThresholdMax(cmd_format &cf) { - setAlarm<float>(static_cast<ALARM_CODES>(cf.cmd_code), _alarm_loop->getThresholdsMax(), cf.param); + ALARM_CODES alarm_code = static_cast<ALARM_CODES>(cf.cmd_code); + setAlarm<float>(alarm_code, _alarm_loop->getThresholdsMax(), cf.param); + reportThresholdMax(alarm_code); +} + +void UILoop::cmdGetThresholdMin(cmd_format &cf) { + ALARM_CODES alarm_code = static_cast<ALARM_CODES>(cf.cmd_code); + reportThresholdMin(alarm_code); +} + +void UILoop::cmdGetThresholdMax(cmd_format &cf) { + ALARM_CODES alarm_code = static_cast<ALARM_CODES>(cf.cmd_code); + reportThresholdMax(alarm_code); } void UILoop::cmdSetValve(cmd_format &cf) { setValveParam(static_cast<CMD_SET_VALVE>(cf.cmd_code), _breathing_loop->getValvesController()->getValveParams(), cf.param); } + +void UILoop::reportThresholdMin(ALARM_CODES alarm_code) +{ + cmd_format response; + response.timestamp = millis(); + response.cmd_type = CMD_TYPE::GET_THRESHOLD_MIN; + response.cmd_code = alarm_code; + response.param = _alarm_loop->getThresholdsMin()[alarm_code]; + _pl_send.setPayload(PRIORITY::DATA_ADDR, reinterpret_cast<void *>(&response), sizeof(response)); + _comms->writePayload(_pl_send); + +} +void UILoop::reportThresholdMax(ALARM_CODES alarm_code) +{ + cmd_format response; + response.timestamp = millis(); + response.cmd_type = CMD_TYPE::GET_THRESHOLD_MAX; + response.cmd_code = alarm_code; + response.param = _alarm_loop->getThresholdsMax()[alarm_code]; + _pl_send.setPayload(PRIORITY::DATA_ADDR, reinterpret_cast<void *>(&response), sizeof(response)); + _comms->writePayload(_pl_send); +} \ No newline at end of file diff --git a/arduino/hev_prototype_v1/src/UILoop.h b/arduino/hev_prototype_v1/src/UILoop.h index 9d7665278884501a3da1aeb692290130b266e6cf..2314b5b7cd5914b8f896b3b8a3af9a3b23d52d46 100644 --- a/arduino/hev_prototype_v1/src/UILoop.h +++ b/arduino/hev_prototype_v1/src/UILoop.h @@ -37,6 +37,10 @@ private: void cmdSetMode(cmd_format &cf); void cmdSetThresholdMin(cmd_format &cf); void cmdSetThresholdMax(cmd_format &cf); + void cmdGetThresholdMin(cmd_format &cf); + void cmdGetThresholdMax(cmd_format &cf); + void reportThresholdMin(ALARM_CODES alarm_code); + void reportThresholdMax(ALARM_CODES alarm_code); void cmdSetValve(cmd_format &cf); void cmdSetPersonal(cmd_format &cf); diff --git a/arduino/hev_prototype_v1/src/common.h b/arduino/hev_prototype_v1/src/common.h index e0c25e1627ecab01413fe43983b3cec9e556ee3d..326f6844f476fb0eecd68266fcd50d1f5014e0e6 100644 --- a/arduino/hev_prototype_v1/src/common.h +++ b/arduino/hev_prototype_v1/src/common.h @@ -63,7 +63,9 @@ enum CMD_TYPE : uint8_t { SET_TARGET_TEST = 12, SET_TARGET_CURRENT = 13, GET_TARGETS = 14, - SET_PERSONAL = 15 + SET_PERSONAL = 15, + GET_THRESHOLD_MIN = 16, + GET_THRESHOLD_MAX = 17 }; enum CMD_GENERAL : uint8_t { diff --git a/raspberry-dataserver/CommsCommon.py b/raspberry-dataserver/CommsCommon.py index ddfb45c19380535b4b8db7ce245d0b8dfb6635e7..22249ca47c169ed8c347a38f8da1d5ca72f370db 100644 --- a/raspberry-dataserver/CommsCommon.py +++ b/raspberry-dataserver/CommsCommon.py @@ -31,6 +31,9 @@ class CMD_TYPE(Enum): SET_TARGET_TEST = 12 SET_TARGET_CURRENT = 13 GET_TARGETS = 14 + SET_PERSONAL = 15 + GET_THRESHOLD_MIN = 16 + GET_THRESHOLD_MAX = 17 @unique diff --git a/raspberry-dataserver/CommsDebug2.py b/raspberry-dataserver/CommsDebug2.py index cf0ea815757e3094b4dc0167a0481d84b0907bff..eb95e8b3698aa577e00954f65ec7f11867dcb4f1 100755 --- a/raspberry-dataserver/CommsDebug2.py +++ b/raspberry-dataserver/CommsDebug2.py @@ -62,6 +62,8 @@ class Dependant(object): logging.info(f"LOGMSG {payload.timestamp}:{payload.message} {fsm}") if payload.getType() == PAYLOAD_TYPE.TARGET.value: logging.info(f"TARGET {payload} {fsm}") + if payload.getType() == PAYLOAD_TYPE.CMD.value: + logging.info(f"CMD (alarm threshold) {payload} {fsm}") #if hasattr(payload, 'ventilation_mode'): # logging.info(f"payload received: {payload.ventilation_mode}") #if hasattr(payload, 'duration_inhale'): @@ -94,14 +96,17 @@ async def commsDebug(): await asyncio.sleep(1) # # Change TIMEOUT of breathing cycle (BUFF-PRE-INHALE) await asyncio.sleep(1) - print('get personal info') - send_cmd(cmd_type="GENERAL", cmd_code="GET_PERSONAL") + #print('get personal info') + #send_cmd(cmd_type="GENERAL", cmd_code="GET_PERSONAL") #await asyncio.sleep(10) #print('send personal info') #send_personal("Jessica Jones", 29, 'F', 175, 58) - + send_cmd(cmd_type="GET_THRESHOLD_MAX", cmd_code="APNEA") + await asyncio.sleep(1) + print('set apnea max 10') + send_cmd(cmd_type="SET_THRESHOLD_MAX", cmd_code="APNEA", param=10) #print('get targets pcac, current') #send_cmd(cmd_type="GET_TARGETS", cmd_code="PC_AC", param=0) #send_cmd(cmd_type="GET_TARGETS", cmd_code="TEST", param=0)