From 7cfbf6a2d11a150de526ac40de236d49869f8c5a Mon Sep 17 00:00:00 2001 From: Ben West Date: Wed, 7 Jan 2015 18:35:41 -0800 Subject: [PATCH 1/7] clean up repo a bit remove results from what looks like accidental checkin of a --bare repo. Set executable chmod a+xr flag on cgi-bin scripts. --- HEAD | 1 - config | 4 - description | 1 - his2.sh | 1 + hooks/applypatch-msg.sample | 15 --- hooks/commit-msg.sample | 24 ----- hooks/post-update.sample | 8 -- hooks/pre-applypatch.sample | 14 --- hooks/pre-commit.sample | 49 --------- hooks/pre-push.sample | 54 ---------- hooks/pre-rebase.sample | 169 -------------------------------- hooks/prepare-commit-msg.sample | 36 ------- hooks/update.sample | 128 ------------------------ info/exclude | 6 -- tb_qs.sh | 0 15 files changed, 1 insertion(+), 509 deletions(-) delete mode 100644 HEAD delete mode 100644 config delete mode 100644 description mode change 100644 => 100755 his2.sh delete mode 100755 hooks/applypatch-msg.sample delete mode 100755 hooks/commit-msg.sample delete mode 100755 hooks/post-update.sample delete mode 100755 hooks/pre-applypatch.sample delete mode 100755 hooks/pre-commit.sample delete mode 100755 hooks/pre-push.sample delete mode 100755 hooks/pre-rebase.sample delete mode 100755 hooks/prepare-commit-msg.sample delete mode 100755 hooks/update.sample delete mode 100644 info/exclude mode change 100644 => 100755 tb_qs.sh diff --git a/HEAD b/HEAD deleted file mode 100644 index cb089cd..0000000 --- a/HEAD +++ /dev/null @@ -1 +0,0 @@ -ref: refs/heads/master diff --git a/config b/config deleted file mode 100644 index 07d359d..0000000 --- a/config +++ /dev/null @@ -1,4 +0,0 @@ -[core] - repositoryformatversion = 0 - filemode = true - bare = true diff --git a/description b/description deleted file mode 100644 index 498b267..0000000 --- a/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/his2.sh b/his2.sh old mode 100644 new mode 100755 index 1d924d3..2254450 --- a/his2.sh +++ b/his2.sh @@ -19,6 +19,7 @@ unset IFS +# get last 6 hours of data $dir/decoding-carelink/bin/mm-latest2.py 360 --init --port $port --serial $serial | tee ldata > /dev/null sed -n -e 's/.*data://p' ldata #grab just history diff --git a/hooks/applypatch-msg.sample b/hooks/applypatch-msg.sample deleted file mode 100755 index 8b2a2fe..0000000 --- a/hooks/applypatch-msg.sample +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -# -# An example hook script to check the commit log message taken by -# applypatch from an e-mail message. -# -# The hook should exit with non-zero status after issuing an -# appropriate message if it wants to stop the commit. The hook is -# allowed to edit the commit message file. -# -# To enable this hook, rename this file to "applypatch-msg". - -. git-sh-setup -test -x "$GIT_DIR/hooks/commit-msg" && - exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"} -: diff --git a/hooks/commit-msg.sample b/hooks/commit-msg.sample deleted file mode 100755 index b58d118..0000000 --- a/hooks/commit-msg.sample +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -# -# An example hook script to check the commit log message. -# Called by "git commit" with one argument, the name of the file -# that has the commit message. The hook should exit with non-zero -# status after issuing an appropriate message if it wants to stop the -# commit. The hook is allowed to edit the commit message file. -# -# To enable this hook, rename this file to "commit-msg". - -# Uncomment the below to add a Signed-off-by line to the message. -# Doing this in a hook is a bad idea in general, but the prepare-commit-msg -# hook is more suited to it. -# -# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') -# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" - -# This example catches duplicate Signed-off-by lines. - -test "" = "$(grep '^Signed-off-by: ' "$1" | - sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { - echo >&2 Duplicate Signed-off-by lines. - exit 1 -} diff --git a/hooks/post-update.sample b/hooks/post-update.sample deleted file mode 100755 index ec17ec1..0000000 --- a/hooks/post-update.sample +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# -# An example hook script to prepare a packed repository for use over -# dumb transports. -# -# To enable this hook, rename this file to "post-update". - -exec git update-server-info diff --git a/hooks/pre-applypatch.sample b/hooks/pre-applypatch.sample deleted file mode 100755 index b1f187c..0000000 --- a/hooks/pre-applypatch.sample +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh -# -# An example hook script to verify what is about to be committed -# by applypatch from an e-mail message. -# -# The hook should exit with non-zero status after issuing an -# appropriate message if it wants to stop the commit. -# -# To enable this hook, rename this file to "pre-applypatch". - -. git-sh-setup -test -x "$GIT_DIR/hooks/pre-commit" && - exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"} -: diff --git a/hooks/pre-commit.sample b/hooks/pre-commit.sample deleted file mode 100755 index 68d62d5..0000000 --- a/hooks/pre-commit.sample +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh -# -# An example hook script to verify what is about to be committed. -# Called by "git commit" with no arguments. The hook should -# exit with non-zero status after issuing an appropriate message if -# it wants to stop the commit. -# -# To enable this hook, rename this file to "pre-commit". - -if git rev-parse --verify HEAD >/dev/null 2>&1 -then - against=HEAD -else - # Initial commit: diff against an empty tree object - against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 -fi - -# If you want to allow non-ASCII filenames set this variable to true. -allownonascii=$(git config --bool hooks.allownonascii) - -# Redirect output to stderr. -exec 1>&2 - -# Cross platform projects tend to avoid non-ASCII filenames; prevent -# them from being added to the repository. We exploit the fact that the -# printable range starts at the space character and ends with tilde. -if [ "$allownonascii" != "true" ] && - # Note that the use of brackets around a tr range is ok here, (it's - # even required, for portability to Solaris 10's /usr/bin/tr), since - # the square bracket bytes happen to fall in the designated range. - test $(git diff --cached --name-only --diff-filter=A -z $against | - LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 -then - cat <<\EOF -Error: Attempt to add a non-ASCII file name. - -This can cause problems if you want to work with people on other platforms. - -To be portable it is advisable to rename the file. - -If you know what you are doing you can disable this check using: - - git config hooks.allownonascii true -EOF - exit 1 -fi - -# If there are whitespace errors, print the offending file names and fail. -exec git diff-index --check --cached $against -- diff --git a/hooks/pre-push.sample b/hooks/pre-push.sample deleted file mode 100755 index 1f3bceb..0000000 --- a/hooks/pre-push.sample +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/sh - -# An example hook script to verify what is about to be pushed. Called by "git -# push" after it has checked the remote status, but before anything has been -# pushed. If this script exits with a non-zero status nothing will be pushed. -# -# This hook is called with the following parameters: -# -# $1 -- Name of the remote to which the push is being done -# $2 -- URL to which the push is being done -# -# If pushing without using a named remote those arguments will be equal. -# -# Information about the commits which are being pushed is supplied as lines to -# the standard input in the form: -# -# -# -# This sample shows how to prevent push of commits where the log message starts -# with "WIP" (work in progress). - -remote="$1" -url="$2" - -z40=0000000000000000000000000000000000000000 - -IFS=' ' -while read local_ref local_sha remote_ref remote_sha -do - if [ "$local_sha" = $z40 ] - then - # Handle delete - : - else - if [ "$remote_sha" = $z40 ] - then - # New branch, examine all commits - range="$local_sha" - else - # Update to existing branch, examine new commits - range="$remote_sha..$local_sha" - fi - - # Check for WIP commit - commit=`git rev-list -n 1 --grep '^WIP' "$range"` - if [ -n "$commit" ] - then - echo "Found WIP commit in $local_ref, not pushing" - exit 1 - fi - fi -done - -exit 0 diff --git a/hooks/pre-rebase.sample b/hooks/pre-rebase.sample deleted file mode 100755 index 33730ca..0000000 --- a/hooks/pre-rebase.sample +++ /dev/null @@ -1,169 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2006, 2008 Junio C Hamano -# -# The "pre-rebase" hook is run just before "git rebase" starts doing -# its job, and can prevent the command from running by exiting with -# non-zero status. -# -# The hook is called with the following parameters: -# -# $1 -- the upstream the series was forked from. -# $2 -- the branch being rebased (or empty when rebasing the current branch). -# -# This sample shows how to prevent topic branches that are already -# merged to 'next' branch from getting rebased, because allowing it -# would result in rebasing already published history. - -publish=next -basebranch="$1" -if test "$#" = 2 -then - topic="refs/heads/$2" -else - topic=`git symbolic-ref HEAD` || - exit 0 ;# we do not interrupt rebasing detached HEAD -fi - -case "$topic" in -refs/heads/??/*) - ;; -*) - exit 0 ;# we do not interrupt others. - ;; -esac - -# Now we are dealing with a topic branch being rebased -# on top of master. Is it OK to rebase it? - -# Does the topic really exist? -git show-ref -q "$topic" || { - echo >&2 "No such branch $topic" - exit 1 -} - -# Is topic fully merged to master? -not_in_master=`git rev-list --pretty=oneline ^master "$topic"` -if test -z "$not_in_master" -then - echo >&2 "$topic is fully merged to master; better remove it." - exit 1 ;# we could allow it, but there is no point. -fi - -# Is topic ever merged to next? If so you should not be rebasing it. -only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` -only_next_2=`git rev-list ^master ${publish} | sort` -if test "$only_next_1" = "$only_next_2" -then - not_in_topic=`git rev-list "^$topic" master` - if test -z "$not_in_topic" - then - echo >&2 "$topic is already up-to-date with master" - exit 1 ;# we could allow it, but there is no point. - else - exit 0 - fi -else - not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` - /usr/bin/perl -e ' - my $topic = $ARGV[0]; - my $msg = "* $topic has commits already merged to public branch:\n"; - my (%not_in_next) = map { - /^([0-9a-f]+) /; - ($1 => 1); - } split(/\n/, $ARGV[1]); - for my $elem (map { - /^([0-9a-f]+) (.*)$/; - [$1 => $2]; - } split(/\n/, $ARGV[2])) { - if (!exists $not_in_next{$elem->[0]}) { - if ($msg) { - print STDERR $msg; - undef $msg; - } - print STDERR " $elem->[1]\n"; - } - } - ' "$topic" "$not_in_next" "$not_in_master" - exit 1 -fi - -<<\DOC_END - -This sample hook safeguards topic branches that have been -published from being rewound. - -The workflow assumed here is: - - * Once a topic branch forks from "master", "master" is never - merged into it again (either directly or indirectly). - - * Once a topic branch is fully cooked and merged into "master", - it is deleted. If you need to build on top of it to correct - earlier mistakes, a new topic branch is created by forking at - the tip of the "master". This is not strictly necessary, but - it makes it easier to keep your history simple. - - * Whenever you need to test or publish your changes to topic - branches, merge them into "next" branch. - -The script, being an example, hardcodes the publish branch name -to be "next", but it is trivial to make it configurable via -$GIT_DIR/config mechanism. - -With this workflow, you would want to know: - -(1) ... if a topic branch has ever been merged to "next". Young - topic branches can have stupid mistakes you would rather - clean up before publishing, and things that have not been - merged into other branches can be easily rebased without - affecting other people. But once it is published, you would - not want to rewind it. - -(2) ... if a topic branch has been fully merged to "master". - Then you can delete it. More importantly, you should not - build on top of it -- other people may already want to - change things related to the topic as patches against your - "master", so if you need further changes, it is better to - fork the topic (perhaps with the same name) afresh from the - tip of "master". - -Let's look at this example: - - o---o---o---o---o---o---o---o---o---o "next" - / / / / - / a---a---b A / / - / / / / - / / c---c---c---c B / - / / / \ / - / / / b---b C \ / - / / / / \ / - ---o---o---o---o---o---o---o---o---o---o---o "master" - - -A, B and C are topic branches. - - * A has one fix since it was merged up to "next". - - * B has finished. It has been fully merged up to "master" and "next", - and is ready to be deleted. - - * C has not merged to "next" at all. - -We would want to allow C to be rebased, refuse A, and encourage -B to be deleted. - -To compute (1): - - git rev-list ^master ^topic next - git rev-list ^master next - - if these match, topic has not merged in next at all. - -To compute (2): - - git rev-list master..topic - - if this is empty, it is fully merged to "master". - -DOC_END diff --git a/hooks/prepare-commit-msg.sample b/hooks/prepare-commit-msg.sample deleted file mode 100755 index f093a02..0000000 --- a/hooks/prepare-commit-msg.sample +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -# -# An example hook script to prepare the commit log message. -# Called by "git commit" with the name of the file that has the -# commit message, followed by the description of the commit -# message's source. The hook's purpose is to edit the commit -# message file. If the hook fails with a non-zero status, -# the commit is aborted. -# -# To enable this hook, rename this file to "prepare-commit-msg". - -# This hook includes three examples. The first comments out the -# "Conflicts:" part of a merge commit. -# -# The second includes the output of "git diff --name-status -r" -# into the message, just before the "git status" output. It is -# commented because it doesn't cope with --amend or with squashed -# commits. -# -# The third example adds a Signed-off-by line to the message, that can -# still be edited. This is rarely a good idea. - -case "$2,$3" in - merge,) - /usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;; - -# ,|template,) -# /usr/bin/perl -i.bak -pe ' -# print "\n" . `git diff --cached --name-status -r` -# if /^#/ && $first++ == 0' "$1" ;; - - *) ;; -esac - -# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') -# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" diff --git a/hooks/update.sample b/hooks/update.sample deleted file mode 100755 index d847583..0000000 --- a/hooks/update.sample +++ /dev/null @@ -1,128 +0,0 @@ -#!/bin/sh -# -# An example hook script to blocks unannotated tags from entering. -# Called by "git receive-pack" with arguments: refname sha1-old sha1-new -# -# To enable this hook, rename this file to "update". -# -# Config -# ------ -# hooks.allowunannotated -# This boolean sets whether unannotated tags will be allowed into the -# repository. By default they won't be. -# hooks.allowdeletetag -# This boolean sets whether deleting tags will be allowed in the -# repository. By default they won't be. -# hooks.allowmodifytag -# This boolean sets whether a tag may be modified after creation. By default -# it won't be. -# hooks.allowdeletebranch -# This boolean sets whether deleting branches will be allowed in the -# repository. By default they won't be. -# hooks.denycreatebranch -# This boolean sets whether remotely creating branches will be denied -# in the repository. By default this is allowed. -# - -# --- Command line -refname="$1" -oldrev="$2" -newrev="$3" - -# --- Safety check -if [ -z "$GIT_DIR" ]; then - echo "Don't run this script from the command line." >&2 - echo " (if you want, you could supply GIT_DIR then run" >&2 - echo " $0 )" >&2 - exit 1 -fi - -if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then - echo "usage: $0 " >&2 - exit 1 -fi - -# --- Config -allowunannotated=$(git config --bool hooks.allowunannotated) -allowdeletebranch=$(git config --bool hooks.allowdeletebranch) -denycreatebranch=$(git config --bool hooks.denycreatebranch) -allowdeletetag=$(git config --bool hooks.allowdeletetag) -allowmodifytag=$(git config --bool hooks.allowmodifytag) - -# check for no description -projectdesc=$(sed -e '1q' "$GIT_DIR/description") -case "$projectdesc" in -"Unnamed repository"* | "") - echo "*** Project description file hasn't been set" >&2 - exit 1 - ;; -esac - -# --- Check types -# if $newrev is 0000...0000, it's a commit to delete a ref. -zero="0000000000000000000000000000000000000000" -if [ "$newrev" = "$zero" ]; then - newrev_type=delete -else - newrev_type=$(git cat-file -t $newrev) -fi - -case "$refname","$newrev_type" in - refs/tags/*,commit) - # un-annotated tag - short_refname=${refname##refs/tags/} - if [ "$allowunannotated" != "true" ]; then - echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 - echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 - exit 1 - fi - ;; - refs/tags/*,delete) - # delete tag - if [ "$allowdeletetag" != "true" ]; then - echo "*** Deleting a tag is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/tags/*,tag) - # annotated tag - if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 - then - echo "*** Tag '$refname' already exists." >&2 - echo "*** Modifying a tag is not allowed in this repository." >&2 - exit 1 - fi - ;; - refs/heads/*,commit) - # branch - if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then - echo "*** Creating a branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/heads/*,delete) - # delete branch - if [ "$allowdeletebranch" != "true" ]; then - echo "*** Deleting a branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/remotes/*,commit) - # tracking branch - ;; - refs/remotes/*,delete) - # delete tracking branch - if [ "$allowdeletebranch" != "true" ]; then - echo "*** Deleting a tracking branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - *) - # Anything else (is there anything else?) - echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 - exit 1 - ;; -esac - -# --- Finished -exit 0 diff --git a/info/exclude b/info/exclude deleted file mode 100644 index a5196d1..0000000 --- a/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tb_qs.sh b/tb_qs.sh old mode 100644 new mode 100755 From be7cc9dd669602b1c1854077394dbbe1b47d8505 Mon Sep 17 00:00:00 2001 From: Ben West Date: Wed, 7 Jan 2015 19:37:08 -0800 Subject: [PATCH 2/7] this seams to do more or less the same thing --- his2.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/his2.sh b/his2.sh index 2254450..04ac9b1 100755 --- a/his2.sh +++ b/his2.sh @@ -20,19 +20,23 @@ unset IFS # get last 6 hours of data -$dir/decoding-carelink/bin/mm-latest2.py 360 --init --port $port --serial $serial | tee ldata > /dev/null +# $dir/decoding-carelink/bin/mm-latest2.py 360 --init --serial $serial | tee ldata > /dev/null +# python mm-latest2.py 360 --init --serial $serial | tee ldata > /dev/null +mm-latest.py --serial $serial --init --rf-minutes 3 360 --parser-out history.json | tee ldata > /dev/null +</dev/null #remove markers sed -e 's/bolusdata://g' part1 > part2 #remove line feeds -tr '\n' ' ' < part2 +EOT +tr '\n' ' ' < history.json echo"" echo "" -rm part1 -rm part2 +# rm part1 +# rm part2 # have to erase files # leave ldata for debug purposes in case of app crash From 8c58172b48fa236b4e375364d5e81a5a9e6c6ab3 Mon Sep 17 00:00:00 2001 From: Ben West Date: Wed, 7 Jan 2015 19:38:11 -0800 Subject: [PATCH 3/7] clean up a bit --- his2.sh | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/his2.sh b/his2.sh index 04ac9b1..dad0ca2 100755 --- a/his2.sh +++ b/his2.sh @@ -20,25 +20,11 @@ unset IFS # get last 6 hours of data -# $dir/decoding-carelink/bin/mm-latest2.py 360 --init --serial $serial | tee ldata > /dev/null -# python mm-latest2.py 360 --init --serial $serial | tee ldata > /dev/null mm-latest.py --serial $serial --init --rf-minutes 3 360 --parser-out history.json | tee ldata > /dev/null -</dev/null -#remove markers -sed -e 's/bolusdata://g' part1 > part2 -#remove line feeds -EOT tr '\n' ' ' < history.json echo"" echo "" -# rm part1 -# rm part2 -# have to erase files -# leave ldata for debug purposes in case of app crash From aab06eb9eb1d54fc01fd0332d0533645cfe14a07 Mon Sep 17 00:00:00 2001 From: Ben West Date: Thu, 8 Jan 2015 15:10:55 -0800 Subject: [PATCH 4/7] hack together barely working usb version This uses comlink2-uart to implement a websocket server that also talks usb usingn the carelink usb stick to talk to remote pumps. --- .gitignore | 3 + app.js | 77 ++++++ lib/get-rtc.js | 29 ++ lib/remote.js | 19 ++ package.json | 27 ++ ajax-loader.gif => static/ajax-loader.gif | Bin index.html => static/index.html | 259 +++++++++--------- iob.js => static/iob.js | 0 .../jquery.dynatable.css | 0 .../jquery.dynatable.js | 0 static/latest.js | 28 ++ 11 files changed, 316 insertions(+), 126 deletions(-) create mode 100644 .gitignore create mode 100644 app.js create mode 100644 lib/get-rtc.js create mode 100644 lib/remote.js create mode 100644 package.json rename ajax-loader.gif => static/ajax-loader.gif (100%) rename index.html => static/index.html (65%) rename iob.js => static/iob.js (100%) rename jquery.dynatable.css => static/jquery.dynatable.css (100%) rename jquery.dynatable.js => static/jquery.dynatable.js (100%) create mode 100644 static/latest.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..abd5365 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +ldata +history.json diff --git a/app.js b/app.js new file mode 100644 index 0000000..7b4c37b --- /dev/null +++ b/app.js @@ -0,0 +1,77 @@ + +var express = require('express'); + +var app = express( ); +var server = require('http').Server(app); + +var remote = require('./lib/remote'); +var io = require('socket.io')(server); + +var pump = null; +var serial = null; +function get_pump ( ) { + var transport = remote.transport( ); + pump = transport.session + .open(function ( ) { + console.log('created usb transport'); + }) + ; + return pump; +}; + +app.use(express.static(__dirname + "/static")); +app.get('/latest.json', function (req, res) { + console.log("REQ PARAMS", req.params, 'QUERY', req.query); + if (req.query.serial) + pump = get_pump( ) + .serial(req.query.serial) + ; + pump = pump + .prelude({minutes: 3}) + .ReadPumpModel(function rec_model (model, msg) { + pump.model = model; + }) + .tap(function ( ) { + console.log('PUMP', pump.model, pump); + if (pump.model) { + this.ReadHistoryData({ page: 0 }, function (history, msg) { + console.log(history, msg); + res.send(history.json); + }); + } + }) +}); + +io.on('connection', function (socket) { + socket.on('query', function (data) { + console.log('querying', data, serial); + pump = get_pump( ) + .serial(serial) + .prelude({minutes: 3}) + .ReadPumpModel(function rec_model (model, msg) { + pump.model = model; + socket.emit('model', model); + }) + .read_clock(function (clock, msg) { + console.log("CLOCK", arguments); + socket.emit('clock', clock, msg); + }) + .tap(function ( ) { + if (pump.model) { + this.ReadHistoryData({ page: 0 }, function (history, msg) { + console.log(history, msg); + socket.emit('history', history, msg); + }); + } + }) + ; + }); + socket.on('serial', function (data) { + console.log('serial data input', data, arguments); + serial = data; + // pump = (pump || get_pump( )).serial(data) ; + }); +}); + +server.listen(process.env.PORT || 8080); + diff --git a/lib/get-rtc.js b/lib/get-rtc.js new file mode 100644 index 0000000..d858bd7 --- /dev/null +++ b/lib/get-rtc.js @@ -0,0 +1,29 @@ + +var commands = require('comlink2-uart/lib/session/commands'); + +var moment = require('moment'); + +function ReadRTC (opts) { + return commands.create({ + name: 'ReadRTC' + , op: 122 + , decode: function (data) { + var d = { + hour : (data[0]), + minute: (data[1]), + second: (data[2]), + year : 2000 + (data[4] & 0x1F), + month : (data[5]), + day : (data[6]), + } + var date = [d.year, d.month, d.day].join('-'); + var time = [d.hour, d.minute, d.second].join(':'); + return moment([date, time].join('T')); + } + }); +} + +commands.register('read_clock', ReadRTC); + +module.exports = ReadRTC; + diff --git a/lib/remote.js b/lib/remote.js new file mode 100644 index 0000000..60717b9 --- /dev/null +++ b/lib/remote.js @@ -0,0 +1,19 @@ + +var uart = require('comlink2-uart'); +var extras = require('./get-rtc'); + +// var Serial = require('serialport'); + + +function transport ( ) { + var usb = require('comlink2-uart/lib/usb'); + // var stream = new Serial.SerialPort('/dev/serial/by-id/usb-0a21_8001-if00-port0', {bufferSize: 64}); + var stream = usb( ); + stream.on('error', console.error.bind(console, "USB")); + stream.open( ); + var transport = uart(stream); + console.log("TRANSPORT", transport); + return transport; +} + +module.exports.transport = transport; diff --git a/package.json b/package.json new file mode 100644 index 0000000..5f33699 --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "name": "ihawk", + "version": "0.0.0", + "description": "JQuery Mobile based application to query status and set temp basal rates on Medtronic insulin pumps remotely. ihawk is based on Ben West's amazing decocare tools (http://github.com/bewest/decoding-carelink/). Utilizes a Raspberry Pi running an Apache 2 server to run an interface for CGI scripts that run decocare and the carelink stick.", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git://github.com/bewest/ihawk.git" + }, + "author": "", + "license": "AGPLv3", + "bugs": { + "url": "https://github.com/bewest/ihawk/issues" + }, + "dependencies": { + "express": "~4.10.7", + "comlink2-uart": "git://github.com/bewest/comlink2-uart.git", + "socket.io": "~1.2.1", + "serialport": "~1.4.10" + }, + "devDependencies": { + "nodemon": "~1.2.1" + } +} diff --git a/ajax-loader.gif b/static/ajax-loader.gif similarity index 100% rename from ajax-loader.gif rename to static/ajax-loader.gif diff --git a/index.html b/static/index.html similarity index 65% rename from index.html rename to static/index.html index 84496a5..acb772d 100644 --- a/index.html +++ b/static/index.html @@ -3,6 +3,9 @@ + + + @@ -95,132 +98,136 @@ //query event handler -$("#qpump").click(function(){ - -//prevent user from temp basal during query -document.getElementById("settempbasal").disabled = true; -document.getElementById("qpump").disabled = true; - -serial=$("#idserial").val(); -port=$("#idport").val(); -dir=$("#iddir").val(); - -//change file location by machine - urlcmd="cgi-bin/his2.sh/?serial="+serial+"&port="+port+"&dir="+dir; - $.get(urlcmd,function(Mydata,status){ -document.getElementById("settempbasal").disabled = false; -document.getElementById("qpump").disabled = false; - console.log(Mydata); - -//replace all ' with " for parsing JSON properly -Mydata=Mydata.replace(/'/g,'"'); -//parse results from mm-latest2 script - -//status info - firstLine = Mydata.split('\n')[5]; - junk=firstLine.toLowerCase(); - statusobj = JSON.parse(junk); -//temp basal - firstLine = Mydata.split('\n')[6]; - junk=firstLine.toLowerCase(); -tempbasalobj = JSON.parse(junk); -//basal pattern -firstline=Mydata.split('\n')[7]; -basalobj=JSON.parse(firstline); -//find current default basal rate -//convert pumptime to 2 digits per - it is not a datestring or JSON 0's are missing -//split after T but strip errant " first -pumptimej = Mydata.split('\n')[4]; -pumptimej2=pumptimej.replace("\'","\""); -pumptime=pumptimej2.replace("\'","\""); -pumptime = pumptime.substring(0, pumptime.length - 1); -ptarray = pumptime.split("T"); -//now grab pieces, 0 is hours, 1 is min, and 2 is sec -ptime=ptarray[1].split(":"); -//add leading 0's if they are not there -hk=ptime[0]; -mk=ptime[1]; -sk=ptime[2]; -if (hk.length==1) {hk="0"+hk;} -if (mk.length==1) {mk="0"+mk;} -if (sk.length==1) {sk="0"+sk} -pto=hk+":"+mk+":"+sk; -n=Object.keys(basalobj).length; -found=-1; -i=0; -while(i=basalobj[i].start && pto<=basalobj[i+1].start) found=i; -i++; -} -if (found==-1) found=0; //this means it must be last record, start of next is record 0 - -if (found>1&&found<(n-2)) { -curbasalrate=basalobj[found-1].rate; -curbasalend=basalobj[found+1].start; -nextbasalrate=basalobj[found].rate; -nextbasalend=basalobj[found+2].start;} -else if (found==n-2) { -curbasalrate=basalobj[found].rate; -curbasalend=basalobj[found+1].start; -nextbasalrate=basalobj[found+1].rate; -nextbasalend=basalobj[0].start;} -else if (found==0) { -curbasalrate=basalobj[0].rate; -curbasalend=basalobj[1].start; -nextbasalrate=basalobj[1].rate; -nextbasalend=basalobj[2].start; -} -else //found=n-1 -{ -curbasalrate=basalobj[n-1].rate; -curbasalend=basalobj[0].start; -nextbasalrate=basalobj[0].rate; -nextbasalend=basalobj[1].start; -} - -insulinremaining=Mydata.split('\n')[8]; -//history data -junk=Mydata.split('\n')[11]; -junk=junk.replace(/'/g,'"'); -historyobj=JSON.parse(junk); -//settings data -firstLine=Mydata.split('\n')[3]; -junk=firstLine.toLowerCase(); -settingsobj=JSON.parse(junk); -//pump type -pumptype=Mydata.split('\n')[2]; -pumptype = pumptype.substring(0, pumptype.length - 1); -//find bolus history in range (currently grabbing up to 6 hours to match iob) - -ai = [0.0,0.0]; -ai =iob(historyobj,settingsobj,pumptime); -actintot=ai[1]; //total active insulin -actincor=ai[0]; //total active insulin minus insulin used to cover carbs -actincarb=actintot-actincor; //calc act insulin from carbs - - -//update time and status -document.getElementById('pumptime').innerHTML = pumptime; -document.getElementById('ptype').innerHTML = pumptype; - document.getElementById('status').innerHTML = statusobj.status; -document.getElementById('bolusing').innerHTML = statusobj.bolusing; -document.getElementById('suspended').innerHTML = statusobj.suspended; -//update current temp basal state -document.getElementById('insulinremaining').innerHTML = insulinremaining; -document.getElementById('duration').innerHTML = tempbasalobj.duration; -document.getElementById('rate').innerHTML = tempbasalobj.rate; -//update active insulin -document.getElementById('idactin').innerHTML = actintot.toFixed(2); -document.getElementById('idactincor').innerHTML = actincor.toFixed(2); -document.getElementById('idactincarb').innerHTML = actincarb.toFixed(2); -//basal rates -document.getElementById('idcurbasalrate').innerHTML = curbasalrate.toFixed(2); -document.getElementById('idcurbasalend').innerHTML = curbasalend; -document.getElementById('idnextbasalrate').innerHTML = nextbasalrate.toFixed(2); -document.getElementById('idnextbasalend').innerHTML = nextbasalend; - - - }); //from get query +$("#qpumpxxxx").click(function(){ + + //prevent user from temp basal during query + document.getElementById("settempbasal").disabled = true; + document.getElementById("qpump").disabled = true; + + serial=$("#idserial").val(); + port=$("#idport").val(); + dir=$("#iddir").val(); + + //change file location by machine + urlcmd="latest.json?serial="+serial; + $.get(urlcmd,function(Mydata,status){ + document.getElementById("settempbasal").disabled = false; + document.getElementById("qpump").disabled = false; + console.log(Mydata); + + /* + //replace all ' with " for parsing JSON properly + Mydata=Mydata.replace(/'/g,'"'); + //parse results from mm-latest2 script + + //status info + firstLine = Mydata.split('\n')[5]; + junk=firstLine.toLowerCase(); + statusobj = JSON.parse(junk); + //temp basal + firstLine = Mydata.split('\n')[6]; + junk=firstLine.toLowerCase(); + tempbasalobj = JSON.parse(junk); + //basal pattern + firstline=Mydata.split('\n')[7]; + basalobj=JSON.parse(firstline); + //find current default basal rate + //convert pumptime to 2 digits per - it is not a datestring or JSON 0's are missing + //split after T but strip errant " first + pumptimej = Mydata.split('\n')[4]; + pumptimej2=pumptimej.replace("\'","\""); + pumptime=pumptimej2.replace("\'","\""); + pumptime = pumptime.substring(0, pumptime.length - 1); + ptarray = pumptime.split("T"); + //now grab pieces, 0 is hours, 1 is min, and 2 is sec + ptime=ptarray[1].split(":"); + //add leading 0's if they are not there + hk=ptime[0]; + mk=ptime[1]; + sk=ptime[2]; + if (hk.length==1) {hk="0"+hk;} + if (mk.length==1) {mk="0"+mk;} + if (sk.length==1) {sk="0"+sk} + pto=hk+":"+mk+":"+sk; + n=Object.keys(basalobj).length; + */ + basalobj = Mydata; + + found=-1; + i=0; + while(i=basalobj[i].start && pto<=basalobj[i+1].start) found=i; + i++; + } + if (found==-1) found=0; //this means it must be last record, start of next is record 0 + + if (found>1&&found<(n-2)) { + curbasalrate=basalobj[found-1].rate; + curbasalend=basalobj[found+1].start; + nextbasalrate=basalobj[found].rate; + nextbasalend=basalobj[found+2].start;} + else if (found==n-2) { + curbasalrate=basalobj[found].rate; + curbasalend=basalobj[found+1].start; + nextbasalrate=basalobj[found+1].rate; + nextbasalend=basalobj[0].start;} + else if (found==0) { + curbasalrate=basalobj[0].rate; + curbasalend=basalobj[1].start; + nextbasalrate=basalobj[1].rate; + nextbasalend=basalobj[2].start; + } + else //found=n-1 + { + curbasalrate=basalobj[n-1].rate; + curbasalend=basalobj[0].start; + nextbasalrate=basalobj[0].rate; + nextbasalend=basalobj[1].start; + } + + insulinremaining=Mydata.split('\n')[8]; + //history data + junk=Mydata.split('\n')[11]; + junk=junk.replace(/'/g,'"'); + historyobj=JSON.parse(junk); + //settings data + firstLine=Mydata.split('\n')[3]; + junk=firstLine.toLowerCase(); + settingsobj=JSON.parse(junk); + //pump type + pumptype=Mydata.split('\n')[2]; + pumptype = pumptype.substring(0, pumptype.length - 1); + //find bolus history in range (currently grabbing up to 6 hours to match iob) + + ai = [0.0,0.0]; + ai =iob(historyobj,settingsobj,pumptime); + actintot=ai[1]; //total active insulin + actincor=ai[0]; //total active insulin minus insulin used to cover carbs + actincarb=actintot-actincor; //calc act insulin from carbs + + + //update time and status + document.getElementById('pumptime').innerHTML = pumptime; + document.getElementById('ptype').innerHTML = pumptype; + document.getElementById('status').innerHTML = statusobj.status; + document.getElementById('bolusing').innerHTML = statusobj.bolusing; + document.getElementById('suspended').innerHTML = statusobj.suspended; + //update current temp basal state + document.getElementById('insulinremaining').innerHTML = insulinremaining; + document.getElementById('duration').innerHTML = tempbasalobj.duration; + document.getElementById('rate').innerHTML = tempbasalobj.rate; + //update active insulin + document.getElementById('idactin').innerHTML = actintot.toFixed(2); + document.getElementById('idactincor').innerHTML = actincor.toFixed(2); + document.getElementById('idactincarb').innerHTML = actincarb.toFixed(2); + //basal rates + document.getElementById('idcurbasalrate').innerHTML = curbasalrate.toFixed(2); + document.getElementById('idcurbasalend').innerHTML = curbasalend; + document.getElementById('idnextbasalrate').innerHTML = nextbasalrate.toFixed(2); + document.getElementById('idnextbasalend').innerHTML = nextbasalend; + + + }); //from get query }); //from button click diff --git a/iob.js b/static/iob.js similarity index 100% rename from iob.js rename to static/iob.js diff --git a/jquery.dynatable.css b/static/jquery.dynatable.css similarity index 100% rename from jquery.dynatable.css rename to static/jquery.dynatable.css diff --git a/jquery.dynatable.js b/static/jquery.dynatable.js similarity index 100% rename from jquery.dynatable.js rename to static/jquery.dynatable.js diff --git a/static/latest.js b/static/latest.js new file mode 100644 index 0000000..170be82 --- /dev/null +++ b/static/latest.js @@ -0,0 +1,28 @@ + +$(window).ready(function (ev) { + console.log('window ready'); + var socket = io.connect( ); + socket.on('connect', function ( ) { + console.log('connected to websocket'); + var serial=$("#idserial").val(); + socket.emit('serial', serial); + }); + + socket.on('clock', function (clock, msg) { + console.log("CLOCK", clock, msg, arguments); + var now = moment(clock); + console.log("NOW", now, clock); + $('#clock').trigger('now', now, clock); + + }); + socket.on('model', function (model, msg) { + console.log("MODEL", model); + }); + socket.on('history', function (history, msg) { + console.log("HISTORY", history); + }); + var serial=$("#idserial").val(); + $("#qpump").click(function(){ + socket.emit('query', serial); + }) +}); From f0760b18d37491315efb93ec94c6197601c9dd21 Mon Sep 17 00:00:00 2001 From: Ben West Date: Thu, 8 Jan 2015 17:46:24 -0800 Subject: [PATCH 5/7] get clock correctly --- app.js | 3 +++ lib/get-rtc.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++-- static/latest.js | 2 +- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 7b4c37b..edee6f6 100644 --- a/app.js +++ b/app.js @@ -64,7 +64,10 @@ io.on('connection', function (socket) { }); } }) + .end( ); + ; + }); socket.on('serial', function (data) { console.log('serial data input', data, arguments); diff --git a/lib/get-rtc.js b/lib/get-rtc.js index d858bd7..d0acefb 100644 --- a/lib/get-rtc.js +++ b/lib/get-rtc.js @@ -6,7 +6,9 @@ var moment = require('moment'); function ReadRTC (opts) { return commands.create({ name: 'ReadRTC' - , op: 122 + , op: 112 + , retries: 2 + , effectTime: 500 , decode: function (data) { var d = { hour : (data[0]), @@ -18,7 +20,7 @@ function ReadRTC (opts) { } var date = [d.year, d.month, d.day].join('-'); var time = [d.hour, d.minute, d.second].join(':'); - return moment([date, time].join('T')); + return [date, time].join('T'); } }); } @@ -27,3 +29,47 @@ commands.register('read_clock', ReadRTC); module.exports = ReadRTC; +if (!module.parent) { + + var usb = require('comlink2-uart/lib/usb'); + var create = require('comlink2-uart'); + var prog = process.argv.slice(1,2).pop( ); + var serial = process.argv.slice(2,3).pop( ) || process.env['SERIAL']; + if (!serial) { + console.log('usage: ', prog, 'SERIAL'); + process.exit(1); + } + console.log('howdy'); + var stream = usb( ); + stream.on('error', function ( ) { + console.log("BAD ERROR", arguments); + stream.close( ); + stream.end( ); + }); + + stream.open( ); + var session = create(stream) + + var pump = session.session; + pump.open(console.log.bind(console, "OPENED")) + .serial(serial) + // .power_on_ten_minutes(console.log.bind(console, 'POWER ON')) + .prelude({minutes: 3}) + .ReadPumpModel(function model (res, msg) { + session.model = res; + console.log('MODEL', res); + console.log("ERROR?", msg); + msg.save( ); + }) + .tap(function ( ) { + if (session.model) { + this.read_clock(function (clock, msg) { + console.log("XXX CLOCK", clock); + }); + + } + }) + .end( ) + ; + +} diff --git a/static/latest.js b/static/latest.js index 170be82..5cabaca 100644 --- a/static/latest.js +++ b/static/latest.js @@ -12,7 +12,7 @@ $(window).ready(function (ev) { console.log("CLOCK", clock, msg, arguments); var now = moment(clock); console.log("NOW", now, clock); - $('#clock').trigger('now', now, clock); + $('#clock').trigger('now', now, clock, msg.data.toString('hex')); }); socket.on('model', function (model, msg) { From 70c4a7597e3498cbc52181a90e378ddceaccc5c0 Mon Sep 17 00:00:00 2001 From: Ben West Date: Thu, 8 Jan 2015 20:18:34 -0800 Subject: [PATCH 6/7] attempt using serial --- app.js | 26 ++++++++++++++++++++------ lib/get-rtc.js | 2 +- lib/remote.js | 20 +++++++++++++------- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/app.js b/app.js index edee6f6..eca78ad 100644 --- a/app.js +++ b/app.js @@ -6,17 +6,26 @@ var server = require('http').Server(app); var remote = require('./lib/remote'); var io = require('socket.io')(server); +var uart = require('comlink2-uart'); var pump = null; var serial = null; -function get_pump ( ) { - var transport = remote.transport( ); - pump = transport.session +function get_pump (session) { + var transport = remote.transport(function opened ( ) { + console.log('creating transport'); + var stream = this; + session(uart(stream).session, stream); + }); + /* + pump = transport.duplex .open(function ( ) { - console.log('created usb transport'); + console.log('created transport'); + session(transport.session); }) ; - return pump; + */ + + return transport; }; app.use(express.static(__dirname + "/static")); @@ -45,7 +54,9 @@ app.get('/latest.json', function (req, res) { io.on('connection', function (socket) { socket.on('query', function (data) { console.log('querying', data, serial); - pump = get_pump( ) + get_pump(function (pump, stream) { + console.log(pump); + pump.open( ) .serial(serial) .prelude({minutes: 3}) .ReadPumpModel(function rec_model (model, msg) { @@ -63,9 +74,12 @@ io.on('connection', function (socket) { socket.emit('history', history, msg); }); } + // stream.close( ); }) .end( ); + ; + }) ; }); diff --git a/lib/get-rtc.js b/lib/get-rtc.js index d0acefb..c76cc47 100644 --- a/lib/get-rtc.js +++ b/lib/get-rtc.js @@ -14,7 +14,7 @@ function ReadRTC (opts) { hour : (data[0]), minute: (data[1]), second: (data[2]), - year : 2000 + (data[4] & 0x1F), + year : 2000 + (data[4] & 0x0F), month : (data[5]), day : (data[6]), } diff --git a/lib/remote.js b/lib/remote.js index 60717b9..0c8aafe 100644 --- a/lib/remote.js +++ b/lib/remote.js @@ -2,16 +2,22 @@ var uart = require('comlink2-uart'); var extras = require('./get-rtc'); -// var Serial = require('serialport'); +var Serial = require('serialport'); -function transport ( ) { - var usb = require('comlink2-uart/lib/usb'); - // var stream = new Serial.SerialPort('/dev/serial/by-id/usb-0a21_8001-if00-port0', {bufferSize: 64}); - var stream = usb( ); - stream.on('error', console.error.bind(console, "USB")); - stream.open( ); +function transport (session) { + // var usb = require('comlink2-uart/lib/usb'); + // var stream = usb( ); + var stream = new Serial.SerialPort('/dev/serial/by-id/usb-0a21_8001-if00-port0', {bufferSize: 64}); + stream.on('error', console.error.bind(console, "ERROR TRANSPORT")); + stream.on('disconnect', console.error.bind(console, "DISCONNECT TRANSPORT")); + stream.on('close', console.error.bind(console, "CLOSE TRANSPORT")); + // stream.open(console.log.bind(console, 'OPENED') ); + stream.open(session.bind(stream)); + + return stream; var transport = uart(stream); + transport.duplex = stream; console.log("TRANSPORT", transport); return transport; } From 121a4e63758c1889a4a5a8e7bc67adf183139227 Mon Sep 17 00:00:00 2001 From: Ben West Date: Thu, 8 Jan 2015 20:26:50 -0800 Subject: [PATCH 7/7] runs but gets clogged-ish --- app.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index eca78ad..845a9e4 100644 --- a/app.js +++ b/app.js @@ -74,9 +74,11 @@ io.on('connection', function (socket) { socket.emit('history', history, msg); }); } - // stream.close( ); }) - .end( ); + .end(function ( ) { + console.log("GAH CLOSE"); + stream.close( ); + }); ; })