summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2019-01-10 15:03:42 -0500
committerAndrew Cady <d@jerkface.net>2019-01-10 15:03:42 -0500
commit4d44849cfc752cdc9872ab53409a43696edce36e (patch)
treeb03f74c7740f779a51d940fa652c7dc30149ee95
parent247fb6b7fe3a70d1e9378f20ffaa19c8d4c3ea17 (diff)
add support for Dexcom G5 Mobile and make it defaultHEADmaster
-rw-r--r--dexcom_reader/database_records.py3
-rwxr-xr-xdexcom_reader/dexcom_dumper.py18
-rw-r--r--dexcom_reader/readdata.py10
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):
338 def full_trend(self): 338 def full_trend(self):
339 return self.data[12] 339 return self.data[12]
340 340
341class G5MobileEGVRecord (EGVRecord):
342 FORMAT = '<2IHxxxxxxxxxcxxxH'
343
341 344
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
16 16
17from optparse import OptionParser 17from optparse import OptionParser
18 18
19G5_IS_DEFAULT = True 19DEFAULT_RECEIVER_TYPE = "g5m"
20 20
21def get_dracos_host(): 21def get_dracos_host():
22 res = subprocess.check_output([ 22 res = subprocess.check_output([
@@ -26,8 +26,9 @@ def get_dracos_host():
26 return res.decode('utf-8') 26 return res.decode('utf-8')
27 27
28parser = OptionParser() 28parser = OptionParser()
29parser.add_option("--g4", action="store_false", dest="g5", default=G5_IS_DEFAULT, help="use Dexcom G4 instead of Dexcom G5") 29parser.add_option("--g4", const="g4", action="store_const", dest="receiver_type", help="use Dexcom G4 instead of Dexcom G5")
30parser.add_option("--g5", action="store_true", dest="g5", default=G5_IS_DEFAULT, help="use Dexcom G5 instead of Dexcom G4") 30parser.add_option("--g5", const="g5", action="store_const", dest="receiver_type", help="use Dexcom G5 instead of Dexcom G4")
31parser.add_option("--g5m", const="g5m", action="store_const", dest="receiver_type", help="use Dexcom G5 Mobile instead of Dexcom G4")
31 32
32parser.add_option("-a", "--all", action="store_const", dest="command", const="dump_everything", help="dump all available records") 33parser.add_option("-a", "--all", action="store_const", dest="command", const="dump_everything", help="dump all available records")
33parser.add_option("-p", "--poll", action="store_const", dest="command", const="poll", help="poll for latest CGM record") 34parser.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
43 44
44(options, args) = parser.parse_args() 45(options, args) = parser.parse_args()
45 46
47if not options.receiver_type:
48 options.receiver_type = DEFAULT_RECEIVER_TYPE
49
46command = options.command or "dump_cgm" 50command = options.command or "dump_cgm"
47VERBOSE = options.verbose 51VERBOSE = options.verbose
48HUMAN = options.human 52HUMAN = options.human
@@ -63,7 +67,10 @@ if options.num_records <= 0:
63 options.num_records = None 67 options.num_records = None
64 68
65def get_dexcom_reader(): 69def get_dexcom_reader():
66 if options.g5: 70 if options.receiver_type == "g5m":
71 dd = readdata.DexcomG5Mobile.FindDevice()
72 return readdata.DexcomG5Mobile(dd)
73 elif options.receiver_type == "g5":
67 dd = readdata.DexcomG5.FindDevice() 74 dd = readdata.DexcomG5.FindDevice()
68 return readdata.DexcomG5(dd) 75 return readdata.DexcomG5(dd)
69 else: 76 else:
@@ -228,7 +235,8 @@ def poll():
228 global dr 235 global dr
229 if dr: 236 if dr:
230 dr.Disconnect() 237 dr.Disconnect()
231 dr = readdata.DexcomG5(devicer.device.device_node) 238 drf = readdata.DexcomG5 if options.receiver_type == "g5" else readdata.DexcomG5Mobile
239 dr = drf(devicer.device.device_node)
232 240
233 print("Device opened.") 241 print("Device opened.")
234 while devicer.have(): 242 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):
362 'SENSOR_DATA': database_records.SensorRecord, 362 'SENSOR_DATA': database_records.SensorRecord,
363 } 363 }
364 364
365class DexcomG5Mobile (Dexcom):
366 PARSER_MAP = {
367 'USER_EVENT_DATA': database_records.EventRecord,
368 'METER_DATA': database_records.G5MeterRecord,
369 'CAL_SET': database_records.Calibration,
370 'INSERTION_TIME': database_records.G5InsertionRecord,
371 'EGV_DATA': database_records.G5MobileEGVRecord,
372 'SENSOR_DATA': database_records.SensorRecord,
373 }
374
365def GetDevice (port, G5=False): 375def GetDevice (port, G5=False):
366 if G5: 376 if G5:
367 return DexcomG5(port) 377 return DexcomG5(port)