Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5672c00
more radio optimizations and better error handling w. retries
winemug Feb 14, 2019
c1e92b9
fixed remaining cleanup method
winemug Feb 14, 2019
ec5d781
fixes missed by code inspection
winemug Feb 14, 2019
6b215de
various small improvements and fixes
winemug Feb 15, 2019
10b0d0b
fix for invalid packets with a lucky crc match
winemug Feb 15, 2019
b230aa9
small refactoring of command execution rules
winemug Feb 15, 2019
e9dae3d
streamlining exceptions
winemug Feb 16, 2019
fc0f8da
added ack. alerts
winemug Feb 16, 2019
b9ce658
pod/pdm attributes moved into definitions.py
winemug Feb 16, 2019
dbb5eb7
pdm.is_busy added
winemug Feb 16, 2019
8a22fa0
missing changes from pdmbusy commit
winemug Feb 16, 2019
6e99b4f
removed unused traceback print
winemug Feb 16, 2019
241a9e8
moved text data to definitions
winemug Feb 16, 2019
3b7b99f
RileyLink timeout error no more propagated as exception
winemug Feb 16, 2019
3d1cac4
removed hardcoded mac from test script
winemug Feb 16, 2019
93f4bbd
removed incorrect err handler
winemug Feb 16, 2019
8695faf
clear/configure alerts wip
winemug Feb 17, 2019
3e70f1c
rileylink fw version check
winemug Feb 17, 2019
84541e5
deactivate pod
winemug Feb 17, 2019
9b94f2e
added ack alerts to rest api
winemug Feb 17, 2019
8059e5b
added deactivate to rest api
winemug Feb 17, 2019
3a8e8bb
added type to status req in rest api
winemug Feb 17, 2019
4965d58
added archiving of expired pods
winemug Feb 17, 2019
c716c38
comment out unfinished code
winemug Feb 17, 2019
354ecab
small improvements for rl battery life
winemug Feb 17, 2019
c8dc993
added rl fw verification script
winemug Feb 17, 2019
ad946e8
added rl battery level check
winemug Feb 17, 2019
7bb502e
various setup scripts
winemug Feb 17, 2019
0de7d1e
small fixes to setup
winemug Feb 17, 2019
b2e55f5
commented out bt nap setup
winemug Feb 17, 2019
936546f
commented out bt.nap script on service
winemug Feb 17, 2019
8a86c49
removed unused cc1111 firmware
winemug Feb 17, 2019
5183adc
finalized radio improvements & fixes
winemug Feb 17, 2019
4cea6df
fixed misinterpreted alarms and fault response
winemug Feb 17, 2019
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
2,049 changes: 0 additions & 2,049 deletions bin/cc1111emkRfCat-20180131.hex

This file was deleted.

40 changes: 5 additions & 35 deletions bolus.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,50 +1,20 @@
#!/usr/bin/python3
from podcomm.pod import Pod
from podcomm.pdm import Pdm
from podcomm.pdmutils import PdmError
import logging
import sys
import time
from decimal import *

from podcomm.pdm import Pdm
from podcomm.pod import Pod

logging.basicConfig(level=logging.DEBUG)

pod = Pod.Load(sys.argv[1])
pdm = Pdm(pod)

amount = Decimal(sys.argv[2])

print("\nStarting bolus of %.2f units\n" % (amount))


try:
pdm.bolus(amount, False)
print("Bolus started status:")
pdm.updatePodStatus()
print(pdm.pod)
except PdmError as e:
pdm.updatePodStatus()

print("\n\nBolusing %.2f units\n\nPress ctrl+c to cancel\n\n" % (amount))

try:
while True:
print("Getting interim status")
pdm.updatePodStatus()
print(pdm.pod)
if pdm.pod.bolusState != 2:
break
time.sleep(5)

except KeyboardInterrupt:
print("\nCancelling bolus...\n")
pdm.cancelBolus()

print("Getting final status")
print("\nStarting bolus of %.2f units\n" % amount)

pdm.updatePodStatus()
print(pdm.pod)

pdm.cleanUp()
pdm.bolus(amount, False)

print(pdm.pod)
4 changes: 2 additions & 2 deletions btnap.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
killall bt-network > /dev/null 2>&1
sudo killall bt-network > /dev/null 2>&1
while true
do
bt-network -c $1 nap > /dev/null 2>&1
sudo bt-network -c $1 nap > /dev/null 2>&1
sleep 5
done
15 changes: 4 additions & 11 deletions cancelbolus.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
#!/usr/bin/python3
from podcomm.pod import Pod
from podcomm.pdm import Pdm
from podcomm.pdmutils import PdmError
from podcomm.radio import ProtocolError
import logging
import sys

from podcomm.pdm import Pdm
from podcomm.pod import Pod

logging.basicConfig(level=logging.DEBUG)

pod = Pod.Load(sys.argv[1])
pdm = Pdm(pod)

try:
pdm.cancelBolus()
except PdmError as ProtocolError:
pdm.updatePodStatus()

pdm.cleanUp()

pdm.cancelBolus()
print(pdm.pod)
1 change: 0 additions & 1 deletion canceltempbasal.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
pdm = Pdm(pod)

pdm.cancelTempBasal()
pdm.cleanUp()

print(pdm.pod)
2 changes: 1 addition & 1 deletion omnipy.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def main():
exit_event = threading.Event()


def signal_handler(signo, _frame):
def signal_handler(_, _frame):
exit_event.set()


Expand Down
14 changes: 14 additions & 0 deletions omnipy.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=Omnipy Rest API
After=network.target

[Service]
ExecStart=/bin/bash /home/pi/omnipy.sh
WorkingDirectory=/home/pi/omnipy
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi

[Install]
WantedBy=multi-user.target
4 changes: 4 additions & 0 deletions omnipy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
#/bin/bash $HOME/omnipy/btnap.sh >/dev/null &2>1 &
/usr/bin/python3 -u $HOME/omnipy/omnipy_beacon.py &
/usr/bin/python3 -u $HOME/omnipy/restapi.py
13 changes: 13 additions & 0 deletions omnipy_beacon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/python3
from socketserver import UDPServer, BaseRequestHandler


class OmnipyBeacon(BaseRequestHandler):
def handle(self):
socket = self.request[1]
socket.sendto("wut", self.client_address)


addr = ("", 6664)
server = UDPServer(addr, OmnipyBeacon)
server.serve_forever()
150 changes: 97 additions & 53 deletions pi-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,37 @@ echo
echo ${bold}Step 2/35: ${normal}Upgrading existing packages
sudo apt upgrade -y

if [ ! -d $HOME/omnipy ]
then
echo
echo ${bold}Step 3/35: ${normal}Downloading and installing omnipy
cd $HOME
git clone https://github.com/winemug/omnipy.git
cd $HOME/omnipy
else
echo
echo ${bold}Step 3/35: ${normal}Updating omnipy
cd $HOME/omnipy
git stash
git pull
fi

echo
echo ${bold}Step 3/35: ${normal}Installing dependencies
sudo apt install -y bluez-tools python3 python3-pip screen git build-essential libglib2.0-dev vim screen
sudo pip3 install paho-mqtt
echo ${bold}Step 4/35: ${normal}Installing dependencies
sudo apt install -y bluez-tools python3 python3-pip git build-essential libglib2.0-dev vim
sudo pip3 install simplejson
sudo pip3 install Flask
sudo pip3 install cryptography
sudo pip3 install requests

echo
echo ${bold}Step 4/35: ${normal}Configuring and installing bluepy
cd $HOME
git clone https://github.com/IanHarvey/bluepy.git
python ./bluepy/setup.py build
sudo python ./bluepy/setup.py install
cd bluepy
python3 ./setup.py build
sudo python3 ./setup.py install
cd $HOME/omnipy

echo
echo ${bold}Step 5/35: ${normal}Enabling bluetooth management for users
Expand All @@ -41,60 +58,87 @@ sudo setcap 'cap_net_raw,cap_net_admin+eip' `which bt-network`
sudo setcap 'cap_net_raw,cap_net_admin+eip' `which bt-device`
sudo find / -name bluepy-helper -exec setcap 'cap_net_raw,cap_net_admin+eip' {} \;

echo ${bold}Step 4/35: ${normal}Setting up bluetooth personal area network
echo
echo "Removing existing bluetooth devices"
sudo btmgmt power on
sudo bt-device -l | grep -e \(.*\) --color=never -o| cut -d'(' -f2 | cut -d')' -f1 | while read -r mac
do
if [ !mac ]; then
sudo bt-device -d $mac
sudo bt-device -r $mac
fi
done
echo ${bold}Step 6/35: ${normal}Omnipy HTTP API Password configuration
/usr/bin/python3 ./set_api_password.py

echo
echo "Activating bluetooth pairing mode"
sudo btmgmt connectable yes
sudo btmgmt discov yes
sudo btmgmt pairable yes
sudo killall bt-agent
sudo bt-agent -c NoInputNoOutput -d
echo "Bluetooth device is now discoverable"
echo ${bold}Step 7/35: ${normal}RileyLink test
echo
echo "Open ${bold}bluetooth settings${normal} on your phone to search for and ${bold}pair${normal} with this device"
echo "If you have already paired it on your phone, please unpair it first, then pair again"
echo This step will test if your RileyLink device is connectable and has the
echo correct firmware version installed.
echo
printf "Waiting for connection.."
read -p "Press Enter to continue..."
/usr/bin/python3 $HOME/omnipy/verify_rl.py

btdevice=
while [ -z "$btdevice" ]
do
printf "."
sleep 1
btdevice=`sudo bt-device -l | grep -e \(.*\)`
done
# echo ${bold}Step 8/35: ${normal}Setting up bluetooth personal area network
# echo
# echo "Removing existing bluetooth devices"
# sudo btmgmt power on
# sudo bt-device -l | grep -e \(.*\) --color=never -o| cut -d'(' -f2 | cut -d')' -f1 | while read -r mac
# do
# if [ !mac ]; then
# sudo bt-device -d $mac
# sudo bt-device -r $mac
# fi
# done
# echo
# echo "Activating bluetooth pairing mode"
# sudo btmgmt connectable yes
# sudo btmgmt discov yes
# sudo btmgmt pairable yes
# sudo killall bt-agent
# sudo bt-agent -c NoInputNoOutput -d
# echo "Bluetooth device is now discoverable"
# echo
# echo "Open ${bold}bluetooth settings${normal} on your phone to search for and ${bold}pair${normal} with this device"
# echo "If you have already paired it on your phone, please unpair it first, then pair again"
# echo
# printf "Waiting for connection.."

sudo btmgmt discov no
# btdevice=
# while [ -z "$btdevice" ]
# do
# printf "."
# sleep 1
# btdevice=`sudo bt-device -l | grep -e \(.*\)`
# done

echo
# sudo btmgmt discov no

echo "${bold}Paired with $btdevice.${normal}"
mac=`echo $btdevice | cut -d'(' -f2 | cut -d')' -f1`
# echo

# echo "${bold}Paired with $btdevice.${normal}"
# mac=`echo $btdevice | cut -d'(' -f2 | cut -d')' -f1`

# echo
# echo
# echo "Please ${bold}enable bluetooth tethering${normal} on your phone if it's not already enabled"
# echo "Waiting for connection."
# sudo /bin/bash ./btnap.sh $mac & > /dev/null 2>&1
# ipaddr=
# while [ -z "$ipaddr" ]
# do
# printf "."
# sleep 1
# ipaddr=`sudo ip -o -4 address | grep bnep0 | grep -e inet.*/ -o | cut -d' ' -f2 | cut -d'/' -f1`
# done
# echo
# echo
# echo "${bold}Connection test succeeeded${normal}. IP address: $ipaddr"
# sudo killall -9 btnap.sh > /dev/null 2>&1
# sudo killall -9 bt-network > /dev/null 2>&1

# echo
# echo ${bold}Step 9/35: ${normal}Creating and starting omnipy service
# sudo cp /home/pi/omnipy/omnipy.service /etc/systemd/system/
# sudo systemctl enable omnipy.service
# sudo systemctl start omnipy.service

# echo
# echo ${bold}Step 10/35: ${normal}Informing the user about the actual number of steps
# echo
# echo Setup needed no more than 10 steps.
# echo
# echo ${bold}Setup completed.${normal}

echo
echo
echo "Please ${bold}enable bluetooth tethering${normal} on your phone if it's not already enabled"
echo "Waiting for connection."
sudo /bin/bash ./btnap.sh $mac & > /dev/null 2>&1
ipaddr=
while [ -z "$ipaddr" ]
do
printf "."
sleep 1
ipaddr=`sudo ip -o -4 address | grep bnep0 | grep -e inet.*/ -o | cut -d' ' -f2 | cut -d'/' -f1`
done
echo
echo
echo "${bold}Connection test succeeeded${normal}. IP address: $ipaddr"
sudo killall -9 btnap.sh > /dev/null 2>&1
sudo killall -9 bt-network > /dev/null 2>&1
63 changes: 63 additions & 0 deletions podcomm/definitions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from enum import IntEnum

RILEYLINK_MAC_FILE = ".rladdr"
PDM_LOCK_FILE = ".pdmlock"
TOKENS_FILE = ".tokens"
KEY_FILE = ".key"
RESPONSE_FILE = ".response"
POD_FILE = "pod"
POD_FILE_SUFFIX = ".json"
POD_LOG_SUFFIX = ".log"

API_VERSION_MAJOR = 1
API_VERSION_MINOR = 0


class BolusState(IntEnum):
NotRunning = 0
Extended = 1
Immediate = 2


class BasalState(IntEnum):
NotRunning = 0
TempBasal = 1
Program = 2


class PodProgress(IntEnum):
InitialState = 0
TankPowerActivated = 1
TankFillCompleted = 2
PairingSuccess = 3
Purging = 4
ReadyForInjection = 5
InjectionDone = 6
Priming = 7
Running = 8
RunningLow = 9
ErrorShuttingDown = 13
AlertExpiredShuttingDown = 14
Inactive = 15


class PodAlert(IntEnum):
AutoOff = 0x01
Unknown = 0x02
EndOfService = 0x04
Expired = 0x08
LowReservoir = 0x10
SuspendInProgress = 0x20
SuspendEnded = 0x40
TimerLimit = 0x80


class PodAlertBit(IntEnum):
AutoOff = 0x00
Unknown = 0x01
EndOfService = 0x02
Expired = 0x03
LowReservoir = 0x04
SuspendInProgress = 0x05
SuspendEnded = 0x06
TimerLimit = 0x07
Loading