Skip to content

Bewest/nodejs ify #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
ldata
history.json
1 change: 0 additions & 1 deletion HEAD

This file was deleted.

96 changes: 96 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@

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 uart = require('comlink2-uart');

var pump = null;
var serial = null;
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 transport');
session(transport.session);
})
;
*/

return transport;
};

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);
get_pump(function (pump, stream) {
console.log(pump);
pump.open( )
.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);
});
}
})
.end(function ( ) {
console.log("GAH CLOSE");
stream.close( );
});
;

})
;

});
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);

4 changes: 0 additions & 4 deletions config

This file was deleted.

1 change: 0 additions & 1 deletion description

This file was deleted.

15 changes: 3 additions & 12 deletions his2.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,12 @@ unset IFS



$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
sed -n "/.*bolusdata:/,/.*bolusdata:/p" ldata | tee part1 >/dev/null
#remove markers
sed -e 's/bolusdata://g' part1 > part2
#remove line feeds
tr '\n' ' ' < part2
# get last 6 hours of data
mm-latest.py --serial $serial --init --rf-minutes 3 360 --parser-out history.json | tee ldata > /dev/null
tr '\n' ' ' < history.json

echo""
echo "</body></html>"
rm part1
rm part2
# have to erase files
# leave ldata for debug purposes in case of app crash



Expand Down
15 changes: 0 additions & 15 deletions hooks/applypatch-msg.sample

This file was deleted.

24 changes: 0 additions & 24 deletions hooks/commit-msg.sample

This file was deleted.

8 changes: 0 additions & 8 deletions hooks/post-update.sample

This file was deleted.

14 changes: 0 additions & 14 deletions hooks/pre-applypatch.sample

This file was deleted.

49 changes: 0 additions & 49 deletions hooks/pre-commit.sample

This file was deleted.

54 changes: 0 additions & 54 deletions hooks/pre-push.sample

This file was deleted.

Loading