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)
def get_pod() -> Pod: global g_pod try: if g_pod is None: g_pod = Pod.Load(POD_FILE + POD_FILE_SUFFIX, POD_FILE + POD_LOG_SUFFIX) return g_pod except: logger.exception("Error while loading pod") return None
def _get_pod(): global g_pod try: if g_pod is None: if os.path.exists(DATA_PATH + POD_FILE + POD_FILE_SUFFIX): g_pod = Pod.Load(DATA_PATH + POD_FILE + POD_FILE_SUFFIX, DATA_PATH + POD_FILE + POD_DB_SUFFIX) else: g_pod = Pod() g_pod.path = DATA_PATH + POD_FILE + POD_FILE_SUFFIX g_pod.path_db = DATA_PATH + POD_FILE + POD_DB_SUFFIX g_pod.Save() return g_pod except: logger.exception("Error while loading pod") return None
def get_pod(): path = "data/bbe.json" log_path = "data/bbe.log" pod = None try: pod = Pod.Load(path) except: pass if pod is None: pod = Pod() pod.path = path pod.log_file_path = log_path pod.id_lot = 44147 pod.id_t = 1100256 pod.radio_address = 0x1f0e89f0 pod.Save() return pod
#!/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()
import time def skip_ack(packet): if packet.type == RadioPacketType.ACK: return None else: return packet path = "data/bbe.json" log_path = "data/bbe.log" pod = None try: pod = Pod.Load(path) except: pass if pod is None: pod = Pod() pod.path = path pod.log_file_path = log_path pod.id_lot = 44147 pod.id_t = 1100256 pod.radio_address = 0x1f0e89f0 pod.Save() mock_radio = MockPacketRadio(send_callback=skip_ack, allow_connect=True, allow_listen=True)
def get_pod(): return Pod.Load(POD_FILE + POD_FILE_SUFFIX, POD_FILE + POD_LOG_SUFFIX)
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()