openaps / decocare

python serial driver for mm comlink2 protocol
Other
27 stars 29 forks source link

Parsing history with a ChangeBolusWizardSetup record fails #19

Open tmecklem opened 7 years ago

tmecklem commented 7 years ago

On a 722 pump, a history page fails to decode after a ChangeBolusWizardSetup record is encountered. It appears this is due to an incorrect expectation of command length. The history page in question parses correctly in Rileylink iOS's MinimedKit, which declares the length of a ChangeBolusWizardSetup record to have 39 total bytes including the opcode (see https://github.com/ps2/rileylink_ios/blob/dev/MinimedKit/PumpEvents/ChangeBolusWizardSetupPumpEvent.swift#L17). Decocare declares the total length to be 47: 40 body + 5 byte timestamp + 2 byte opcode/param (see https://github.com/openaps/decocare/blob/master/decocare/history.py#L228). The decocare code causes an exception in this case (see below), while the Rilelylink code returns proper records and timestamps for the page records. This leads me to believe that the decocare ChangeBolusWizardSetup parsing should be changed to have a body size of 32. Making that change causes the rest of the history page to be decoded with plausibly correct records and timestamps like Rileylink. PR forthcoming with that change.

History page (raw): https://gist.github.com/tmecklem/d47c1dae50a7b29e2b059f9491f0f24c

History Page hex:

33 00 2F 98 07 4E 11 00 16 01 2F 98 07 4E 11 33 2C 35 A0 07 4E 11 00 16 01 35 A0 07 4E 11 33 00 35 AC 07 4E 11 00 16 01 35 AC 07 4E 11 33 4C 35 B4 07 4E 11 00 16 01 35 B4 07 4E 11 33 2C 01 8E 08 4E 11 00 16 01 01 8E 08 4E 11 33 44 19 93 08 4E 11 00 16 01 19 93 08 4E 11 33 5E 32 9D 08 4E 11 00 16 01 32 9D 08 4E 11 33 7E 2A A8 08 4E 11 00 16 01 2A A8 08 4E 11 33 7E 2B A8 08 4E 11 00 16 01 2B A8 08 4E 11 33 2C 00 BA 08 4E 11 00 16 01 00 BA 08 4E 11 5B 00 0E BB 08 0E 11 1E 50 09 23 4B 00 21 00 00 00 00 21 5A 5C 08 18 21 14 10 DF 14 01 21 21 00 0E BB 28 0E 11 0B 70 00 0D 9F 29 AE 11 4F 00 0C A1 09 0E 11 21 51 00 8C 37 28 1E 00 3C 14 00 1E 3C 25 85 3E 20 51 00 8C 37 28 1E 00 3C 14 00 1E 3C 25 85 3E 5B 00 2B A4 0D 0E 11 1E 50 07 23 4B 00 2A 00 00 00 00 2A 5A 5C 08 58 14 14 2C 1E 14 01 2A 2A 00 2B A4 2D 0E 11 1E 00 21 B8 0D 0E 11 1F 00 30 8E 0E 0E 11 4F 00 2B 99 0E 0E 11 20 51 00 8C 37 28 1E 00 3C 14 00 1E 3C 25 85 3E 21 51 00 8C 37 28 1E 00 3C 14 00 1E 3C 25 85 3E 0B 6D 00 3B 81 2F AE 11 0A 1E 27 82 2F 6E 91 3F 23 27 82 CF 6E 11 80 98 44 5B 1E 3A 82 0F 0E 11 00 51 07 23 4B 38 00 00 00 1B 00 1D 5A 5C 0B A8 5C 04 58 6A 14 2C 74 14 01 1D 1D 00 3B 82 2F 0E 11 33 8C 20 87 0F 4E 11 00 16 01 20 87 0F 4E 11 0B 68 00 1F 99 30 AE 11 0A CC 29 9C 30 6E 11 3F 19 29 9C 90 6E 11 80 98 44 5B CC 2B 9C 10 0E 11 00 50 06 23 4B 20 00 00 00 1B 00 05 5A 5C 0E 74 58 04 A8 B2 04 58 C0 14 2C CA 14 01 05 05 00 2B 9C 30 0E 11 33 8C 06 A1 10 4E 11 00 16 01 06 A1 10 4E 11 0B 65 CC 01 A9 30 AE 11 5B 00 13 AF 10 0E 11 14 50 06 23 4B 00 21 00 00 00 00 21 5A 5C 11 14 1B 04 74 6B 04 A8 C5 04 58 D3 14 2C DD 14 01 21 21 00 13 AF 30 0E 11 33 3C 07 B4 10 4E 11 00 16 01 07 B4 10 4E 11 33 36 3B 84 11 4E 11 00 16 01 3B 84 11 4E 11 33 36 3B 98 11 4E 11 00 16 01 3B 98 11 4E 11 33 36 01 AA 11 4E 11 00 16 01 01 AA 11 4E 11 33 36 0E BA 11 4E 11 00 16 01 0E BA 11 4E 11 33 8C 38 84 12 4E 11 00 16 01 38 84 12 4E 11 33 3E 34 9C 12 4E 11 00 16 01 34 9C 12 4E 11 33 8C 39 84 13 4E 11 00 16 01 39 84 13 4E 11 0B 65 8C 13 8F 33 AE 11 0A 68 2F 8F 33 0E 11 0B 69 00 00 9C 35 AE 11 0A 3F 29 9D 35 6E 11 3F 07 29 9D F5 6E 11 85 62 50 5B 3F 2A 9E 15 0E 11 0D 50 06 23 4B FC 15 F0 00 00 00 11 5A 5C 0B 84 22 14 14 36 14 74 86 14 01 11 11 00 2A 9E 35 0E 11 33 00 05 B6 16 0E 11 00 16 01 05 B6 16 0E 11 0A 2D 36 81 37 6E 11 3F 05 36 81 B7 6E 11 85 62 50 1E 00 0D A4 17 0E 11 0B 65 8F 1F AD 37 AE 11 07 00 00 07 4E 2E 11 6D 2E 11 05 10 84 2D 1E 07 00 00 07 4E 04 AA 40 02 A4 24 00 5D 02 A4 24 01 F4 4A 00 B0 1A 00 00 00 08 04 04 00 00 00 64 39 CC C5 04 0A 72 1D 9E 20 6F 11 3F 0E 1D 9E 40 6F 11 85 95 51 1F 00 31 9E 00 0F 11 5B 72 23 A4 00 0F 11 0F 50 0D 23 4B 06 0B 00 00 03 00 0E 5A 5C 08 44 BA 04 84 DC 14 01 0E 0E 00 23 A4 20 0F 11 0B 65 90 3B 81 21 AF 11 0B 65 C0 01 81 22 AF 11 0B 65 C8 3B 81 23 AF 11 0B 65 D3 01 81 24 AF 11 0B 65 E8 3B 81 25 AF 11 0B 65 E3 01 81 26 AF 11 0B 65 CF 3B 81 27 AF 11 0B 65 BC 01 81 28 AF 11 0A CA 21 82 28 6F 11 3F 19 21 82 48 6F 11 80 98 44 5B CA 2D 82 08 0F 11 00 50 09 23 4B 20 00 00 00 00 00 20 5A 5C 05 38 C4 14 01 20 20 00 2D 82 28 0F 11 00 00 00 00 00 00 00 B2 33

Output of history decoding (error occurs after the parsing of the ChangeBolusWizardSetup Record:

python bin/mm-decode-history-page.py --model 722 --data pump --no-larger ~/Desktop/ReadHistoryData-page-0.data 
## START /Users/tmecklem/Desktop/ReadHistoryData-page-0.data
Traceback (most recent call last):
  File "bin/mm-decode-history-page.py", line 143, in <module>
    main( )
  File "bin/mm-decode-history-page.py", line 121, in main
    records = find_records(stream, opts)
  File "bin/mm-decode-history-page.py", line 93, in find_records
    record = parse_record( stream, B, model=opts.model, larger=opts.larger )
  File "/Users/tmecklem/src/t1d/openaps/decocare/decocare/history.py", line 783, in parse_record
    record.parse( head + date + body )
  File "/Users/tmecklem/src/t1d/openaps/decocare/decocare/records/base.py", line 66, in parse
    return self.decode( )
  File "/Users/tmecklem/src/t1d/openaps/decocare/decocare/history.py", line 186, in decode
    temp = { 0: 'absolute', 1: 'percent' }[(self.body[0] >> 3)]
KeyError: 6