Exemplo n.º 1
0
    def pdm_loop(self):
        self.i_pod = Pod.Load("/home/pi/omnipy/data/pod.json", "/home/pi/omnipy/data/pod.db")
        self.i_pdm = Pdm(self.i_pod)
        self.g_pod = Pod.Load("/home/pi/glucopy/data/pod.json", "/home/pi/glucopy/data/pod.db")
        self.g_pdm = Pdm(self.g_pod)
        self.check_wait = 3600
        while(True):
            if self.rate_check_event.wait(self.check_wait):
                self.rate_check_event.clear()

            with self.rate_request_lock:
                i_requested, g_requested = self.rate_requested

            wait1 = 3600
            wait2 = 3600

            if self.i_pod.state_progress == 8 or self.i_pod.state_progress == 9:
                self.i_pdm.start_radio()
                self.rate_check(i_requested, 1.6, self.i_pod, self.i_pdm)
                wait1 = self.check_wait
                self.i_pdm.stop_radio()

            if self.g_pod.state_progress == 8 or self.g_pod.state_progress == 9:
                self.g_pdm.start_radio()
                self.rate_check(g_requested, 0.3, self.g_pod, self.g_pdm)
                wait2 = self.check_wait
                self.g_pdm.stop_radio()

            self.check_wait = min(wait1, wait2)
Exemplo n.º 2
0
def _get_pdm():
    global g_pdm
    try:
        if g_pdm is None:
            g_pdm = Pdm(_get_pod())
        return g_pdm
    except:
        logger.exception("Error while creating pdm instance")
        return None
Exemplo n.º 3
0
def main():
    schedule = [Decimal("2.75")] * 3
    schedule += [Decimal("1.25")] * 3
    schedule += [Decimal("1.75")] * 3
    schedule += [Decimal("0.05")] * 3
    schedule += [Decimal("0.35")] * 3
    schedule += [Decimal("1.95")] * 3
    schedule += [Decimal("1.05")] * 3
    schedule += [Decimal("0.05")] * 3
    schedule += [Decimal("1.65")] * 3
    schedule += [Decimal("0.85")] * 3
    schedule += [Decimal("14.95")] * 3
    schedule += [Decimal("30.00")] * 3
    schedule += [Decimal("0.15")] * 3
    schedule += [Decimal("1.05")] * 3
    schedule += [Decimal("6.95")] * 3
    schedule += [Decimal("1.00")] * 3

    pdm = Pdm(get_pod())
    pdm.bolus(Decimal("0.15"))
    print(pdm.pod)

    pdm.get_radio().stop()
Exemplo n.º 4
0
def main():

    #todo: options:
    # 1) initialize new pod
    # 2) choose existing pdm session on disk
    # 3) .. previously paired pod

    lot = int(raw_input("Please enter the lot id of the pod: "))
    tid = int(raw_input("Please enter tid of the pod: "))
    print("Starting the PDM emulator")
    sniffer = Sniffer(None, messageHandler, None)
    sniffer.start()
    print(
        "Perform an insulin delivery related operation within the next 60 seconds using the pdm"
    )

    if not parametersObserved.wait(60):
        print(
            "Error: Necessary parameters for the emulator were NOT observed.")
        return

    print("Gathered enough information to emulate the PDM.")
    print("Please shut down the PDM and press ENTER to continue")

    raw_input()
    sniffer.stop()

    print("\n\n\n*** Did you turn off the Omnipod PDM? ***\n\n")
    response = raw_input("Type \'YES\' in capital letters to continue): ")

    if response == "YES":
        pdm = Pdm(pdmMessageHandler, sniffer.lot, sniffer.tid, sniffer.address)
        pdm.start()
        while displayMenu():
            pass
        pdm.stop()
    print("Goodbye then.")
Exemplo n.º 5
0
#!/usr/bin/python3
from podcomm.pod import Pod
from podcomm.pdm import Pdm, PdmError
import logging
import sys
import time
from decimal import *

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 ProtocolError:
    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()
Exemplo n.º 6
0
def get_pdm():
    return Pdm(get_pod())
Exemplo n.º 7
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--POD-CONFIG", required=True)
    parser.add_argument("--MQTT-SERVER",
                        required=True,
                        default=None,
                        nargs="?")
    parser.add_argument("--MQTT-PORT",
                        required=False,
                        default="1881",
                        nargs="?")
    parser.add_argument("--MQTT-SSL", required=False, default="", nargs="?")
    parser.add_argument("--MQTT-CLIENTID",
                        required=True,
                        default="",
                        nargs="?")
    parser.add_argument("--MQTT-TOPIC", required=True, default="", nargs="?")
    parser.add_argument("--LOG-LEVEL",
                        required=False,
                        default="DEBUG",
                        nargs="?")
    parser.add_argument("--LOG-FILE", required=False, default=None, nargs="?")

    args = parser.parse_args()

    formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
    ch = logging.StreamHandler(sys.stdout)
    ch.setFormatter(formatter)
    ch.setLevel(level=args.LOG_LEVEL)
    logging.basicConfig(level=args.LOG_LEVEL, handlers=[ch])

    if args.LOG_FILE:
        fh = logging.FileHandler(filename=args.LOG_FILE)
        fh.setFormatter(formatter)
        fh.setLevel(level=args.LOG_LEVEL)
        logging.getLogger().addHandler(fh)

    pod = Pod.Load(args.POD_CONFIG)

    mqtt_client = Client(client_id=args.MQTT_CLIENTID,
                         clean_session=False,
                         protocol=MQTTv311,
                         transport="tcp")

    if args.MQTT_SSL != "":
        mqtt_client.tls_set(certfile=None,
                            keyfile=None,
                            cert_reqs=ssl.CERT_REQUIRED,
                            tls_version=ssl.PROTOCOL_TLSv1_2,
                            ciphers=None)
        mqtt_client.tls_insecure_set(True)

    mqtt_client.reconnect_delay_set(min_delay=5, max_delay=120)
    mqtt_client.retry_first_connection = True

    pdm = Pdm(pod)

    processor = Processor(mqtt_client, args.MQTT_TOPIC, pdm)

    processor.start(args.MQTT_SERVER, int(args.MQTT_PORT), 30)

    try:
        while not exit_event.wait(timeout=10):
            pass
    except KeyboardInterrupt:
        pass

    processor.stop()