Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (
Help us improve Python packaging - Donate today!

Audit, inspect, and command MM insulin pumps.

Project Description
# Decoding carelink

For an intro, see
We are hoping to help diabetics independently reproduce therapeutic
audits of their Medtronic insulin pumps. This experimental software
will download pump settings, and the entire log of historical data.

## Status

We can decode many of the opcodes that store configuration settings.
We can also download all pages of history from the ReadHistoryData
command, which contains the log of all actions the pump has taken on
your behalf:

* glucose readings
* all bolus dosings, all usage of bolus wizard
* unabsorbed insulin
* alarms, etc...
* current settings

## Install first run

This only needs to be done once:

git clone
cd decoding-carelink
sudo python # only if you rarely use python
sudo python develop
git checkout -b myname/init # replace <myname> with your name
# all done

Congratulations, now you are ready for the demo:
Plug in the carelink usb stick, and run this:
dmesg | grep ttyUSB # notice the new ttyUSB$x
sudo ./

You are all done with setup.
Here's how to test just the usb stick, then we'll run the full suite of

* on **MAC** the `PORT` is called `/dev/tty.serial` or something.
* on **windows** the `PORT` is called `COM1` or something
* on **Linux** the `PORT` is called `/dev/ttyUSBx` or something

python decocare/ /dev/ttyUSB0 # on windows this is called COM1
# should get a bunch of output, notably some counters called INTERFACE STATS
# run all experiments:
./ /dev/ttyUSB0 <pump-serial> # use your pump's serial number

Send me your results!

Do this every time, after you run some experiments:
git commit -avm 'for @bewest, these are @<my-name> results'

Set up for sending me results.
# email me your results like this:
git bundle create myname-expr.bundle master..myname/init
# you can send me myname-expr.bundle in an email

Even better, [fork the repo](
and setup to for easy.
# add your fork like this:
git remote rename origin author
git remote add origin<my-user-name>/decoding-carelink.git
git push -u origin myname/init

Now you can do this easily:
./ /dev/ttyUSB0 <pump-serial> # use your pump's serial number
git commit -avm 'for @bewest, these are @<my-name> results'
git push -u origin myname/init

Repeat. The easiest way to see what happened is to look at
explain.log, and use `git diff` and `git show`. Pushing to github as
shown above will allow everyone to discuss our analysis together.

There are several log files created for each experiment.

## Demo

> If you don't want to use your own equipment, I've made some of my
> test equipment available.
Talk to my test insulin pump over the internet.

Requires `socat` and `python 2.7`. The script [`./bin/`](
will connect to my server, `` where my test insulin
pump, serial `208850` is waiting to talk to you.

Here's an example using my scripts:

$ git checkout -b tester # create a new branch with just your stuff, please
$ . ./bin/common # import some handy run_* functions
$ ./bin/ & # get my test insulin pump from
$ ls carelink.ttyUSB0 # creates this thing
$ ./ ./carelink.ttyUSB0
$ PORT=./carelink.ttyUSB0 SERIAL=208850 run_download

* [download](
* [commands](

Try figuring out the dosing commands. Is it possible to rewind
the pump? Is it possible to enter new profiles and schedules?

## Future work

* collect more data
* finish [analyzing pages of insulin pump history](
** [analyze insulin pump bolus records](
** [help analyze prime events](
** [help analyze pump midnight events](

Once we can decode historical logs, we'll clean up and merge back into

### Help needed

Documentation of protocol, decoders, etc...

# fork the repo on github
# clone the repo
$ git clone<yourname>/decoding-carelink.git
$ cd decoding-carelink
$ git checkout -b <yourname>
$ ./ # will ask for sudo to configure usbserial for the stick
# ./ [[<path>|/dev/ttyUSB0>] [<serial>|208850]] eg:
$ ./ /dev/ttyUSB0 208850
$ git commit -avm "here is my data <yourname>"
$ git push -u origin <yourname>
If you can include CSV export from carelink, it would be helpful.

### Decoding

We know how to
[decode time](
and as a result we can find and parse most records now.

And lining this up with the Carelink CSV exports reveals the nature of
the contents for further analysis.

Once we can decode all records, it should be useful for
diabetics, to get basic reports, more or less on par with the
vendor's solution.
We'll use it to
[collect diabetes data](
over the internet, allowing anyone to independently audit their
therapy, and then send the data to their preferred auditing software.

## Tools

#### ``

` </dev/ttyUSB0> <SERIAL>` runs several experiments, described below.
Each experiment is saved in the `./logs` directory, which is tracked by git.

##### `. bin/common`
Source a bunch of helper functions, notably:

##### `run_stick`_
Runs `python decocare/ /dev/ttyUSB0`
and saves results in `logs/stick.log`.
When run by ``, it creates
`./logs/baseline.stick.log` before continuing.
At end of experiments, it records `./logs/postmortem.stick.log`

##### `run_session`_
Runs `python decocare/ /dev/ttyUSB0 <SERIAL>`
and saves results in `logs/session.log`.

##### `run_commands`_
Runs `python decocare/ /dev/ttyUSB0 <SERIAL>`
and saves results in `logs/commands.log`.

##### `run_download`_

Runs `python decocare/ /dev/ttyUSB0 <SERIAL>`
and saves results in `logs/download.log`.

The download script is configured to save each page of historical data as a raw
binary blob in the `./logs/` subdirectory like this:

This script can take several minutes to run; it attempts to download
all pages of data available.

#### quick overview:

`` also tries to summarize what happened, saving a quick
explanation of what happened in `logs/explain.log`. The entire output
is saved in `./status-quo.log`.

#### `run_regress`
After `. bin/common`, `export SERIAL=511888` with your serial number.

Runs `python` on each binary file found in `logs/`, saves
results in `./analysis/<SERIAL>/...`.

This is what I use to render the markdown files in analysis.
Often, the diffs between runs help test theories.

#### ``
` [--larger] ./logs/`
List/decode a page of history as markdown.

#### ``
List records found in binary data by looking for opcodes, and a
regular data structure associated with that length. Includes at least
one variable stop length strength.

#### ``
List records found in binary data by looking for dates.


# was used to filter the raw usblyzer csv export into
# something a bit more manageable.
$ history
553 ./ first_run.csv
554 ls
555 git mv first_run.csv pcaps/first_run/
556 ./ pcaps/first_run/first_run.csv
557 ./ pcaps/first_run/first_run.csv > pcaps/first_run/pcap.csv
558 git mv second_run.csv pcaps/second_run/
559 ./ pcaps/second_run/second_run.csv
560 ./ pcaps/second_run/second_run.csv > pcaps/second_run/pcap.csv
561 git mv third_run.csv pcaps/third_run/
562 ./ pcaps/third_run/third_run.csv
563 ./ pcaps/third_run/third_run.csv > pcaps/third_run/pcap.csv

Release History

Release History

This version
History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
decocare-0.0.5.tar.gz (28.5 kB) Copy SHA256 Checksum SHA256 Source Apr 4, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting