From 4d44849cfc752cdc9872ab53409a43696edce36e Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Thu, 10 Jan 2019 15:03:42 -0500 Subject: add support for Dexcom G5 Mobile and make it default --- dexcom_reader/database_records.py | 3 +++ dexcom_reader/dexcom_dumper.py | 18 +++++++++++++----- dexcom_reader/readdata.py | 10 ++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/dexcom_reader/database_records.py b/dexcom_reader/database_records.py index fa09bea..eb06d88 100644 --- a/dexcom_reader/database_records.py +++ b/dexcom_reader/database_records.py @@ -338,4 +338,7 @@ class G5EGVRecord (EGVRecord): def full_trend(self): return self.data[12] +class G5MobileEGVRecord (EGVRecord): + FORMAT = '<2IHxxxxxxxxxcxxxH' + diff --git a/dexcom_reader/dexcom_dumper.py b/dexcom_reader/dexcom_dumper.py index c4db06a..b0a52e2 100755 --- a/dexcom_reader/dexcom_dumper.py +++ b/dexcom_reader/dexcom_dumper.py @@ -16,7 +16,7 @@ from database_records import GenericTimestampedRecord, EGVRecord, EventRecord from optparse import OptionParser -G5_IS_DEFAULT = True +DEFAULT_RECEIVER_TYPE = "g5m" def get_dracos_host(): res = subprocess.check_output([ @@ -26,8 +26,9 @@ def get_dracos_host(): return res.decode('utf-8') parser = OptionParser() -parser.add_option("--g4", action="store_false", dest="g5", default=G5_IS_DEFAULT, help="use Dexcom G4 instead of Dexcom G5") -parser.add_option("--g5", action="store_true", dest="g5", default=G5_IS_DEFAULT, help="use Dexcom G5 instead of Dexcom G4") +parser.add_option("--g4", const="g4", action="store_const", dest="receiver_type", help="use Dexcom G4 instead of Dexcom G5") +parser.add_option("--g5", const="g5", action="store_const", dest="receiver_type", help="use Dexcom G5 instead of Dexcom G4") +parser.add_option("--g5m", const="g5m", action="store_const", dest="receiver_type", help="use Dexcom G5 Mobile instead of Dexcom G4") parser.add_option("-a", "--all", action="store_const", dest="command", const="dump_everything", help="dump all available records") parser.add_option("-p", "--poll", action="store_const", dest="command", const="poll", help="poll for latest CGM record") @@ -43,6 +44,9 @@ parser.add_option("--client", action="store_true", dest="client", help="act as c (options, args) = parser.parse_args() +if not options.receiver_type: + options.receiver_type = DEFAULT_RECEIVER_TYPE + command = options.command or "dump_cgm" VERBOSE = options.verbose HUMAN = options.human @@ -63,7 +67,10 @@ if options.num_records <= 0: options.num_records = None def get_dexcom_reader(): - if options.g5: + if options.receiver_type == "g5m": + dd = readdata.DexcomG5Mobile.FindDevice() + return readdata.DexcomG5Mobile(dd) + elif options.receiver_type == "g5": dd = readdata.DexcomG5.FindDevice() return readdata.DexcomG5(dd) else: @@ -228,7 +235,8 @@ def poll(): global dr if dr: dr.Disconnect() - dr = readdata.DexcomG5(devicer.device.device_node) + drf = readdata.DexcomG5 if options.receiver_type == "g5" else readdata.DexcomG5Mobile + dr = drf(devicer.device.device_node) print("Device opened.") while devicer.have(): diff --git a/dexcom_reader/readdata.py b/dexcom_reader/readdata.py index 84033f0..ded95d3 100644 --- a/dexcom_reader/readdata.py +++ b/dexcom_reader/readdata.py @@ -362,6 +362,16 @@ class DexcomG5 (Dexcom): 'SENSOR_DATA': database_records.SensorRecord, } +class DexcomG5Mobile (Dexcom): + PARSER_MAP = { + 'USER_EVENT_DATA': database_records.EventRecord, + 'METER_DATA': database_records.G5MeterRecord, + 'CAL_SET': database_records.Calibration, + 'INSERTION_TIME': database_records.G5InsertionRecord, + 'EGV_DATA': database_records.G5MobileEGVRecord, + 'SENSOR_DATA': database_records.SensorRecord, + } + def GetDevice (port, G5=False): if G5: return DexcomG5(port) -- cgit v1.2.3