openaps / dexcom_reader

MIT License
19 stars 20 forks source link

osx 10.11.6 CrcError parsing records #15

Open cropp opened 7 years ago

cropp commented 7 years ago

I am hoping this is not a me only problem, then again I hope it's not happening to others. I was trying to use this tool first then install the Clarity app and was able to upload record data successful.

There are a few command that are successful like user_even_data DescribeClocks GetFirmwareHeader { "DexBootVersion": "5", "BLESoftwareVersion": "1.0.0.76/1.0.1", "RFVersion": "1", "ApiVersion": "3.0.0.0", "ProductName": "Dexcom G5 Mobile Receiver", "SoftwareNumber": "SW10617", "TestApiVersion": "2.10.0.0", "BLEHardwareVersion": "HW0072", "SchemaVersion": "1", "ProductId": "G5MobileReceiver", "PortVersion": "4.6.4.66", "FirmwareVersion": "4.0.1.048", "BLEDeviceAddress": "****" }

But a lot around glucose and sensor basically any iter_* return an error similar to below. Any help would be appreciated.

Traceback (most recent call last): File "/usr/local/bin/openaps-use", line 4, in import('pkg_resources').run_script('openaps==0.1.5', 'openaps-use') File "/usr/local/lib/python2.7/site-packages/pkg_resources/init.py", line 726, in run_script self.require(requires)[0].run_script(script_name, ns) File "/usr/local/lib/python2.7/site-packages/pkg_resources/init.py", line 1651, in run_script exec(code, namespace, namespace) File "/usr/local/lib/python2.7/site-packages/openaps-0.1.5-py2.7.egg/EGG-INFO/scripts/openaps-use", line 63, in app( ) File "/usr/local/lib/python2.7/site-packages/openaps-0.1.5-py2.7.egg/openaps/cli/init.py", line 51, in call self.run(self.args) File "/usr/local/lib/python2.7/site-packages/openaps-0.1.5-py2.7.egg/EGG-INFO/scripts/openaps-use", line 57, in run output = app(args, self) File "/usr/local/lib/python2.7/site-packages/openaps-0.1.5-py2.7.egg/openaps/uses/init.py", line 92, in call return self.method.selected(args)(args, app) File "/usr/local/lib/python2.7/site-packages/openaps-0.1.5-py2.7.egg/openaps/uses/init.py", line 31, in call return self.method(args, app) File "/usr/local/lib/python2.7/site-packages/openaps-0.1.5-py2.7.egg/openaps/uses/use.py", line 45, in call output = self.main(args, app) File "/usr/local/lib/python2.7/site-packages/openaps-0.1.5-py2.7.egg/openaps/vendors/dexcom.py", line 297, in main for item in self.dexcom.iter_records(self.RECORD_TYPE): File "/usr/local/lib/python2.7/site-packages/dexcom_reader-0.1.10-py2.7.egg/dexcom_reader/readdata.py", line 301, in iter_records records = list(self.ReadDatabasePage(record_type, x)) File "/usr/local/lib/python2.7/site-packages/dexcom_reader-0.1.10-py2.7.egg/dexcom_reader/readdata.py", line 267, in GenericRecordYielder yield record_type.Create(data, x) File "/usr/local/lib/python2.7/site-packages/dexcom_reader-0.1.10-py2.7.egg/dexcom_reader/database_records.py", line 60, in Create return cls(unpacked_data, raw_data) File "/usr/local/lib/python2.7/site-packages/dexcom_reader-0.1.10-py2.7.egg/dexcom_reader/database_records.py", line 42, in init self.check_crc() File "/usr/local/lib/python2.7/site-packages/dexcom_reader-0.1.10-py2.7.egg/dexcom_reader/database_records.py", line 47, in check_crc raise constants.CrcError('Could not parse %s' % self.class.name) dexcom_reader.constants.CrcError: Could not parse EGVRecord

PieterGit commented 7 years ago

@cropp : is this still valid? or did you find a way to fix this issue?

afcady commented 5 years ago

G5MobileReceiver has a different EGVRecord format than G5Receiver. Two extra bytes have been inserted into the record. To be precise, FORMAT = '<2IHxxxxxxxxxcxxxH'.

I just fixed this problem in my own dexcom_reader-derived code, about a week ago, when I got a new G5MobileReceiver, after the old G5Receiver failed. (By the way, the G5Mobile is a travesty of software/UI gore. Truly a terrible regression -- inferior in every way to the G5, except that it supports the backfill.)

I think the dexcom_reader project is dead unfortunately. My PRs from a year ago have yet to receive comment. Along with this thread.

But anyway, I'll create a PR that fixes the issue, eventually. To do it properly requires making it automatically use the format for G5 or G5R, which I haven't done. For now here is a quick fix:

--- a/dexcom_reader/database_records.py
+++ b/dexcom_reader/database_records.py
@@ -333,12 +333,6 @@ class EGVRecord(GenericTimestampedRecord):
                                            self.trend_arrow, self.display_only)

 class G5EGVRecord (EGVRecord):
-  FORMAT = '<2IHBBBBBBBBBcBH'
-  @property
-  def full_trend(self):
-    return self.data[12]
-
-class G5MobileEGVRecord (EGVRecord):
   FORMAT = '<2IHxxxxxxxxxcxxxH'

What I actually have in my code is this:

+++ 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'

--- 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,
+    }
+

Then you need to construct the reader like so:

dd = readdata.DexcomG5Mobile.FindDevice()
return readdata.DexcomG5Mobile(dd)

I use a command line option to choose G5R or G5 (or G4). It doesn't auto-detect.

afcady commented 5 years ago

Actually it turns out that this was implemented in #19 just three days ago. It auto-detects G4, G5, G5M, and even G6.