Skip to content

Commit

Permalink
mm-glucose.py is working. It fetches all the cgm pages and tries to d…
Browse files Browse the repository at this point in the history
…ecode them. Still working on the mm-history, not sure which are the correct pages to fetch
  • Loading branch information
Fokko authored and bewest committed Jun 21, 2015
1 parent ec42912 commit 7aa0ff7
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 21 deletions.
1 change: 1 addition & 0 deletions bin/cgm.json

Large diffs are not rendered by default.

39 changes: 21 additions & 18 deletions bin/mm-glucose.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python
# PYTHON_ARGCOMPLETE_OK

from decocare import commands, models
import json, argparse
from decocare import commands, models, cgm
import json, argparse, sys

from decocare.history import HistoryPage
from decocare.helpers import cli
Expand Down Expand Up @@ -47,31 +47,34 @@ def find_records (self, page):
record.update(timestamp=dt.isoformat( ))
return records

def download_history (self, args):
def download_history (self, args, pageRange):
records = [ ]
for i in range(0, 10):
for i in range(1 + pageRange['page'] - pageRange['isig'], pageRange['page']):
print "Next page ", i
pageHistory = self.download_page(i)
records.extend(self.find_records(pageHistory.data))
args.parsed_data.write(json.dumps(records))
try:
pageRaw = self.download_page(i).data
pageResult = cgm.PagedData.Data(pageRaw)
records.extend(pageResult.decode())
except:
print "Unexpected error when downloading cgm-page ", i, " from pump:", sys.exc_info()[0]

def getRange(self):
recordsJson = json.dumps(records);
args.parsed_data.write(recordsJson)

handle = open('cgm.json', 'wb')
handle.write(recordsJson)
handle.close( )

def getPagesRange(self):
range = self.exec_request(self.pump, commands.ReadCurGlucosePageNumber, render_decoded=False,render_hexdump=False)
return range.getData
return range.getData( )

def main (self, args):
# Set Global variables..
self.timezone = args.timezone

info = self.getRange()
print "yes"
print info
print vars(info)
print repr(info)
print "yes"


self.download_history(args)
info = self.getPagesRange()
self.download_history(args, info)

if __name__ == '__main__':
app = DownloadHistory( )
Expand Down
2 changes: 1 addition & 1 deletion bin/mm-history.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def main (self, args):
print "yes"


self.download_history(args)
#self.download_history(args)

if __name__ == '__main__':
app = DownloadHistory( )
Expand Down
4 changes: 2 additions & 2 deletions decocare/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ class ReadGlucoseHistory (ReadSensorHistoryData):
>>> ReadGlucoseHistory(params=[3]).params
[3]
"""
descr = "read glucose history"
descr = "Read glucose history"
code = 154
params = [ ]

Expand All @@ -1319,7 +1319,7 @@ class ReadISIGHistory (ReadSensorHistoryData):
[0, 0, 0, 2]
"""
descr = "read ISIG history"
descr = "Read ISIG history"
code = 155
params = [ ]
maxRecords = 32
Expand Down
38 changes: 38 additions & 0 deletions download-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

SERIAL="417540"
PORT="/dev/ttyUSB0"
FOLDER="./data/"

if [ ! -e ${PORT} 2>/dev/null ]; then
echo "Cannot find USB dongle!"
exit 1
fi

# Get the number of pages
./bin/mm-send-comm.py --init --serial ${SERIAL} --port ${PORT} --prefix-path ${FOLDER} --prefix ReadCurGlucosePageNumber --save sleep 0 > ${FOLDER}ReadCurGlucosePageNumber.markdown


pages=`cat ${FOLDER}ReadCurGlucosePageNumber.markdown | grep -Po "page': \K([0-9]*)" | head -n 1`
glucose=`cat ${FOLDER}ReadCurGlucosePageNumber.markdown | grep -Po "glucose': \K([0-9]*)" | head -n 1`
start=$(expr $pages - $glucose)

for page in `seq ${start} ${pages}`; do
`./bin/mm-send-comm.py --serial ${SERIAL} --port ${PORT} --prefix-path ${FOLDER} tweak ReadGlucoseHistory --page ${page} --save > ${FOLDER}ReadGlucoseHistory-page-${page}.markdown`
`./bin/mm-send-comm.py --serial ${SERIAL} --port ${PORT} --prefix-path ${FOLDER} tweak ReadHistoryData --page ${page} --save > ${FOLDER}ReadHistoryData-page-${page}.markdown`

echo "Decoding page ${page}.."
`./list_cgm.py ${FOLDER}ReadGlucoseHistory-page-${page}.data > ${FOLDER}ReadGlucoseHistory-page-${page}.json`

curl --header "Content-type: application/json" --request POST --data-binary "@data/ReadGlucoseHistory-page-${page}.json" http://localhost:9000/upload

echo "Decoding page ${page}.."
`./list_dates.py ${FOLDER}ReadHistoryData-page-${page}.data > ${FOLDER}ReadHistoryData-page-${page}-dates.json`
`./list_history.py ${FOLDER}ReadHistoryData-page-${page}.data > ${FOLDER}ReadHistoryData-page-${page}-history.json`
#curl --header "Content-type: application/json" --request POST --data-binary "@data/ReadHistoryData-page-${page}.json" http://localhost:9000/upload

done

#Page: 58
#./bin/mm-send-comm.py --serial 417540 --port /dev/ttyUSB0 --prefix-path ./ tweak ReadGlucoseHistory --page 58 --save
#python ./list_cgm.py ./ReadGlucoseHistory-page-58.data

0 comments on commit 7aa0ff7

Please sign in to comment.