Skip to content

Commit

Permalink
more better
Browse files Browse the repository at this point in the history
  • Loading branch information
martukas committed Nov 1, 2024
1 parent 214e53c commit 98b8779
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 103 deletions.
2 changes: 1 addition & 1 deletion software/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ These are utilities for bench testing with mechanical lung simulators only. It i
* [design](design) - documents on software architecture and requirements
* [common](common) - code common to both controller and GUI executables
* [controller](controller) - code for pneumatic system controller (stm32)
* [debug](debug) - controller debug client and other tools for calibration, configuration and testing
* [tools](tools) - controller debug client and other tools for calibration, configuration and testing
* [gui](gui) - code for the ventilator graphical interface (Qt)
39 changes: 10 additions & 29 deletions software/bootstrap/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# This script should work no matter where you call it from.
pushd "$(dirname "$0")" > /dev/null || exit_fail

# Fail if any command fails
set -e
set -o pipefail
. ../common/base.sh

# Print each command as it executes
if [ -n "$VERBOSE" ]; then
set -o xtrace
fi

EXIT_FAILURE=1
EXIT_SUCCESS=0

# Check if Linux
PLATFORM="$(uname -s)"
if [ $PLATFORM != "Linux" ]; then
echo "Error: This script only supports 'Linux'. You have $PLATFORM."
exit $EXIT_FAILURE
fi

# Make sure we are not in sudo
if [ "$EUID" -eq 0 ] && [ "$2" != "-f" ]; then
echo "Please do not run this script with root privileges!"
exit $EXIT_FAILURE
fi
ensure_linux
ensure_not_root

message="RespiraWorks Ventilator update utility
Expand All @@ -58,27 +40,27 @@ if zenity --question --no-wrap --title="Ventilator update" \
then
echo "Continuing with update..."
else
exit $EXIT_FAILURE
exit_fail
fi

# This script should run from repo/software dir
cd "$(dirname "$0")"/../..
pushd "$(dirname "$0")"/../.. || exit_fail

### Will not switch branch to master!
git pull

### Set RW background - must be done in Desktop mode, thus not in boostrap.sh
pcmanfm --set-wallpaper ${HOME}/ventilator/software/bootstrap/desktop_background.jpg
pcmanfm --set-wallpaper "${HOME}/ventilator/software/bootstrap/desktop_background.jpg"

### Update Desktop shortcuts
/bin/cp -rf ${HOME}/ventilator/software/bootstrap/user/Desktop/* ${HOME}/Desktop
/bin/cp -rf "${HOME}/ventilator/software/bootstrap/user/Desktop/*" "${HOME}/Desktop"

if zenity --question --no-wrap --title="PIO Update" \
--text "<span size=\"large\">Update PlatformIO and libraries?</span>"
then
### Clean and update PIO
echo "Updating PlatformIO and libraries..."
./controller/controller.sh update
./common/common.sh update
fi

if zenity --question --no-wrap --title="Controller Build" \
Expand Down Expand Up @@ -107,4 +89,3 @@ then
fi

zenity --info --no-wrap --title="Success" --text "Ventilator update executed successfully!"
exit $EXIT_SUCCESS
4 changes: 2 additions & 2 deletions software/common/base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ function ensure_linux() {
fi
}

# Silent pushd
function pushd() {
# Silent pushd
command pushd "$@" > /dev/null
}

# Silent popd
function popd() {
# Silent popd
command popd > /dev/null
}

Expand Down
2 changes: 1 addition & 1 deletion software/tools/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# generated network protocol code
protocols/*
protocols/*pb2.py
Empty file.
51 changes: 29 additions & 22 deletions software/tools/miscellaneous/decoder.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
import serial # pip install pySerial
import serial
from protocols import network_protocol_pb2
import time
import argparse

p = serial.Serial("/dev/ttyACM0", 115200)

while True:
last_packet = time.time()
s = b""
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("serialport", metavar="SERIAL", type=str, help="Serial port")
args = parser.parse_args()

port = serial.Serial(args.serialport, 115200)

while True:
if p.in_waiting > 0:
b = p.read()
s += b
last_packet = time.time()
if (
time.time() - last_packet
) > 0.001: # Arbitrary longish time picked up by experiment
break
last_packet = time.time()
s = b""
while True:
if port.in_waiting > 0:
b = port.read()
s += b
last_packet = time.time()
if (
time.time() - last_packet
) > 0.001: # Arbitrary longish time picked up by experiment
break

stat = network_protocol_pb2.ControllerStatus()
stat = network_protocol_pb2.ControllerStatus()

try:
stat.ParseFromString(s)
print("------")
print(stat)
except:
pass
try:
stat.ParseFromString(s)
print("------")
print(stat)
except:
pass

while p.in_waiting == 0:
pass
while port.in_waiting == 0:
pass
88 changes: 43 additions & 45 deletions software/tools/miscellaneous/mock_cycle_controller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/python3 -u

# use socat -d -d pty,raw,echo=0 pty,raw,echo=0
# you will get something like this:

Expand All @@ -8,59 +6,59 @@
# 2020/05/02 22:27:09 socat[23367] N starting data transfer loop with FDs [5,5] and [7,7]

# note the /dev/pts/*,
# run mock-cycle-controller.py /dev/pts/1
# and specify the other one for ventillator GUI
# poetry run mock-controller /dev/pts/1
# and specify the other one for ventilator GUI

import serial
from protocols import network_protocol_pb2
import time
import argparse
import math

parser = argparse.ArgumentParser()
parser.add_argument("serialport", metavar="SERIAL", type=str, help="Serial port")
parser.add_argument(
"interframe_interval_ms",
metavar="INTERVAL",
type=int,
help="Milliseconds between frames",
)
args = parser.parse_args()

p = serial.Serial(args.serialport, 115200)
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("serialport", metavar="SERIAL", type=str, help="Serial port")
parser.add_argument(
"interframe_interval_ms",
metavar="INTERVAL",
type=int,
help="Milliseconds between frames",
)
args = parser.parse_args()

stat = network_protocol_pb2.ControllerStatus()
stat.uptime_ms = int(time.time())
stat.sensor_readings.pressure_cm_h2o = 0.9
stat.sensor_readings.volume_ml = -0.5
stat.sensor_readings.flow_ml_per_min = 0.5
port = serial.Serial(args.serialport, 115200)

alarm = stat.controller_alarms.add()
alarm.start_time = int(time.time()) - 1
alarm.kind = network_protocol_pb2.RESPIRATORY_RATE_TOO_LOW
stat = network_protocol_pb2.ControllerStatus()
stat.uptime_ms = int(time.time())
stat.pressure_setpoint_cm_h2o = 1
stat.fan_power = 0.8

stat.pressure_setpoint_cm_h2o = 1
stat.fan_power = 0.8
stat.sensor_readings.breath_id = 0
stat.sensor_readings.patient_pressure_cm_h2o = 0.9
stat.sensor_readings.volume_ml = -0.5
stat.sensor_readings.flow_ml_per_min = 10
stat.sensor_readings.inflow_pressure_diff_cm_h2o = 0.5
stat.sensor_readings.outflow_pressure_diff_cm_h2o = 0.5
stat.sensor_readings.flow_correction_ml_per_min = 0.5
stat.sensor_readings.fio2 = 0.5

stat.active_params.mode = network_protocol_pb2.OFF
stat.active_params.peep_cm_h2o = 2
stat.active_params.breaths_per_min = 8
stat.active_params.pip_cm_h2o = 1
stat.active_params.inspiratory_expiratory_ratio = 0.5
stat.active_params.rise_time_ms = 10
stat.active_params.inspiratory_trigger_cm_h2o = 2
stat.active_params.expiratory_trigger_ml_per_min = 900
stat.active_params.alarm_lo_tidal_volume_ml = 900
stat.active_params.alarm_hi_tidal_volume_ml = 100
stat.active_params.alarm_lo_breaths_per_min = 6
stat.active_params.alarm_hi_breaths_per_min = 10
stat.active_params.fio2 = 0.5
stat.active_params.mode = network_protocol_pb2.OFF
stat.active_params.peep_cm_h2o = 2
stat.active_params.breaths_per_min = 8
stat.active_params.pip_cm_h2o = 1
stat.active_params.inspiratory_expiratory_ratio = 0.5
stat.active_params.inspiratory_trigger_cm_h2o = 2
stat.active_params.expiratory_trigger_ml_per_min = 900

i = 0
while True:
stat.sensor_readings.pressure_cm_h2o = math.sin(i)
p.write(stat.SerializeToString())
p.flush()
while p.in_waiting > 0:
p.read()
time.sleep(0.001 * args.interframe_interval_ms)
i += 0.01
i = 0
while True:
stat.sensor_readings.breath_id += 1
stat.sensor_readings.patient_pressure_cm_h2o = math.sin(i)
port.write(stat.SerializeToString())
port.flush()
while port.in_waiting > 0:
port.read()
time.sleep(0.001 * args.interframe_interval_ms)
i += 0.01
24 changes: 22 additions & 2 deletions software/tools/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
5 changes: 4 additions & 1 deletion software/tools/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "debug"
version = "0.1.0"
description = "RespiraWorks ventilator debug interface"
description = "RespiraWorks ventilator debug tools"
authors = ["Martin Shetty <[email protected]>"]
readme = "README.md"
packages = [
Expand All @@ -17,6 +17,7 @@ matplotlib = "^3.9.2"
pandas = "^2.2.3"
gitpython = "^3.1.43"
platformio = "^6.1.16"
protobuf = "^5.28.3"

[tool.poetry.group.dev.dependencies]
pytest = "^8.3.3"
Expand All @@ -27,6 +28,8 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry.scripts]
debug = "debug.debug_cli:main"
decode = "miscellaneous.decoder:main"
mock_controller = "miscellaneous.mock_cycle_controller:main"

[tool.pytest.ini_options]
testpaths = [
Expand Down

0 comments on commit 98b8779

Please sign in to comment.