Skip to content

Commit

Permalink
Merge pull request #7 from paulokow/feature/downloadstatus
Browse files Browse the repository at this point in the history
Feature/downloadstatus
  • Loading branch information
paulokow authored Jan 4, 2021
2 parents b60f704 + b4cd9d6 commit 08571fc
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 68 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Join the chat at https://gitter.im/pazaan/decoding-contour-next-link](https://badges.gitter.im/pazaan/decoding-contour-next-link.svg)](https://gitter.im/pazaan/decoding-contour-next-link?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Space to collaborate on decoding Contour Next Link comms protocols, and the piggy-backed pump comms
Space to collaborate on decoding Contour Next Link 2.4 comms protocols, and the piggy-backed pump comms

## Getting Started
* Make sure you have `python` and `pip` installed
Expand Down
5 changes: 3 additions & 2 deletions Random Protocol Notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ KR = last bolus reference
SS = sensor status
SU = sensor control?
SC = sensor calibration minutes remaining
SB = sensor battery
SB = sensor battery (4 youngest bits)
SX = sensor rate of change (div 100)

SM = sensor mode active (incs each on and each off, if bit 0 is set then on)
Expand Down Expand Up @@ -303,7 +303,8 @@ Sensor/Transmitter:

[SU] 8bit = ?
[SC] 16bit = time remaining to next calibration in minutes (720 mins max count, FFFF = unknown)
[SB] 8bit = ? unconfirmed as transmitter battery (0x3F 100% ... 0x27 47% . 0x23 20%)
[SB] 8bit = 4 youngest bits represent the sensor battery 0x0f = 100%. (0x3F & 0x0F = 0x0F = 100%, 0x27 & 0x0F = 0x07 = 47%, 0x23 & 0x0F = 0x03 = 20%)
bit 5 seems always set. bit 4 is only set with 100%.
[SX] 16bit = isig rate of change? relates to use for trend arrows? (/100 for decimal value) (RATE_OF_CHANGE value in Carelink)

sensor warm-up noted:
Expand Down
24 changes: 13 additions & 11 deletions get_hmac_and_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
from read_minimed_next24 import Config, Medtronic600SeriesDriver

class CareLinkRequest( javaobj.JavaObjectMarshaller ):
def __init__( self ):
self.object_stream = io.StringIO()
def __init__( self, minimedAddressRoot ):
self.object_stream = io.BytesIO()
self._writeStreamHeader()
self.minimedAddressRoot = minimedAddressRoot

class CareLinkKeyRequest( CareLinkRequest ):
def buildRequest( self, serial ):
Expand All @@ -29,7 +30,7 @@ def buildRequest( self, serial ):
return self.object_stream.getvalue()

def decodeResponse( self, data ):
decoder = javaobj.JavaObjectUnmarshaller( io.StringIO( data ) )
decoder = javaobj.JavaObjectUnmarshaller( io.BytesIO(data) )
int1 = struct.unpack( '>I', decoder.readObject() )[0]
# If int1 is 16, then we have valid data in the following object. If it's 0,
# then no data follows
Expand All @@ -47,7 +48,7 @@ def decodeResponse( self, data ):
def post( self, longSerial, session ):
data = self.buildRequest( longSerial )

response = session.post( 'https://carelink.minimed.eu/patient/main/../secure/SnapshotServer/',
response = session.post( 'https://%s/patient/main/../secure/SnapshotServer/' % self.minimedAddressRoot,
headers = { 'Content-Type': 'application/octet-stream' },
data = data
)
Expand All @@ -63,15 +64,15 @@ def buildRequest( self, serial ):
return self.object_stream.getvalue()

def decodeResponse( self, data ):
decoder = javaobj.JavaObjectUnmarshaller( io.StringIO( data ) )
decoder = javaobj.JavaObjectUnmarshaller( io.BytesIO(data ) )
hmacArray = decoder.readObject()
hmac = ''.join('{:02x}'.format( x & 0xff ) for x in reversed(hmacArray) )
return hmac

def post( self, serial, session ):
data = self.buildRequest( serial )

response = session.post( 'https://carelink.minimed.eu/patient/main/../secure/SnapshotServer/',
response = session.post( 'https://%s/patient/main/../secure/SnapshotServer/' % self.minimedAddressRoot,
headers = { 'Content-Type': 'application/octet-stream' },
data = data
)
Expand All @@ -83,12 +84,12 @@ def getHmac( serial ):
digest = hashlib.sha256(serial + paddingKey).hexdigest()
return "".join(reversed([digest[i:i+2] for i in range(0, len(digest), 2)]))

def getHmacAndKey( config, serial, longSerial, session ):
#request = CareLinkHMACRequest()
def getHmacAndKey( config, serial, longSerial, session, addressRoot ):
#request = CareLinkHMACRequest(addressRoot)
#hmac = request.post( serial, session )
hmac = getHmac( serial )

request = CareLinkKeyRequest()
request = CareLinkKeyRequest(addressRoot)
( int1, key, count ) = request.post( longSerial, session )

config.hmac = hmac
Expand All @@ -100,6 +101,7 @@ def getHmacAndKey( config, serial, longSerial, session ):
parser = argparse.ArgumentParser()
parser.add_argument( 'username', help='The CareLink username with which to retrieve the HMAC and key' )
parser.add_argument( '--db', action='store_true', help='Process all entries in the config database, rather than the connected USB stick' )
parser.add_argument( '-a', '--addressRoot', type=str, default='carelink.minimed.eu', help='The domain name of which CareLink reagion you wish to connect to. Defaults to the EU reagion')
args = parser.parse_args()

password = getpass.getpass( 'Enter the password for the CareLink user {0}: '.format( args.username ) )
Expand All @@ -117,7 +119,7 @@ def getHmacAndKey( config, serial, longSerial, session ):
}

with requests.Session() as session:
session.post( 'https://carelink.minimed.eu/patient/j_security_check', data = payload )
session.post( 'https://%s/patient/j_security_check' % args.addressRoot, data = payload )

if args.db:
for row in c.fetchall():
Expand All @@ -144,4 +146,4 @@ def getHmacAndKey( config, serial, longSerial, session ):
serial = re.sub( r"\d+-", "", longSerial )
config = Config( longSerial )

getHmacAndKey( config, serial, longSerial, session )
getHmacAndKey( config, serial, longSerial, session, args.addressRoot )
11 changes: 7 additions & 4 deletions install/install_rpi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ pip install hidapi
pip install requests astm PyCrypto crc16 python-dateutil
pip install python-lzo

#allow script running w/o root access
sudo copy 30-bayer.rules to /etc/udev/rules.d/
add group bayerusb
add user to the group bayerusb
# Allow script running w/o root access
sudo cp 30-bayer.rules to /etc/udev/rules.d/

# Add group bayerusb
sudo addgroup bayerusb

# Add user to the group bayerusb
sudo usermod -a -G bayerusb pi
Loading

0 comments on commit 08571fc

Please sign in to comment.