Permalink
Browse files

initial add

  • Loading branch information...
pdeschen committed Jul 19, 2011
0 parents commit ada52434a2d1a6713dec0696914b5179a9841036
Showing with 137 additions and 0 deletions.
  1. +11 −0 .project
  2. +82 −0 bancroft.js
  3. +15 −0 package.json
  4. +15 −0 test.js
  5. +14 −0 test/out.dat
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>bancroft</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ </buildSpec>
+ <natures>
+ </natures>
+</projectDescription>
@@ -0,0 +1,82 @@
+var spawn = require('child_process').spawn, sys = require('sys'), events = require('events'), fs = require('fs');
+
+var Bancroft = function (options) {
+ var emitter = events.EventEmitter.call(this);
+ var opts = mixin(options, {
+ 'port' : 2947,
+ 'hostname' : 'localhost'
+ });
+ var net = require('net');
+
+ var serviceSocket = new net.Socket();
+ serviceSocket.setEncoding('ascii');
+ serviceSocket.on("data", function (payload) {
+
+ var info = payload.split('\n');
+ for ( var index = 0; index < info.length; index++) {
+ if (info[index]) {
+ var data = JSON.parse(info[index]);
+ console.log('got', data);
+ if (data.class === 'VERSION') {
+ emitter.emit('connect', {
+ 'release' : data.release,
+ 'version' : data.version
+ });
+ } else if (data.class === 'TPV') {
+ emitter.emit('location', data);
+ } else if (data.class === 'SKY') {
+ emitter.emit('satellite', data);
+ }
+ }
+ }
+ /* serviceSocket.write('?POLL;\n'); */
+
+ });
+ serviceSocket.on("close", function (err) {
+ emitter.emit('disconnect', err);
+ });
+
+ serviceSocket.on('connect', function (socket) {
+ serviceSocket.write('?WATCH={"enable":true,"json":true}\n');
+ serviceSocket.write('?POLL;\n');
+ });
+
+ serviceSocket.connect(opts.port, opts.hostname);
+
+ return this;
+};
+
+var mixin = function (source, destination) {
+
+ if (typeof (source) == "object") {
+ for ( var prop in source) {
+ if ((typeof (source[prop]) == "object") && (source[prop] instanceof Array)) {
+ if (destination[prop] === undefined) {
+ destination[prop] = [];
+ }
+ for ( var index = 0; index < source[prop].length; index += 1) {
+ if (typeof (source[prop][index]) == "object") {
+ if (destination[prop][index] === undefined) {
+ destination[prop][index] = {};
+ }
+ destination[prop].push(mixin(source[prop][index], destination[prop][index]));
+ } else {
+ destination[prop].push(source[prop][index]);
+ }
+ }
+ } else if (typeof (source[prop]) == "object") {
+ if (destination[prop] === undefined) {
+ destination[prop] = {};
+ }
+ mixin(source[prop], destination[prop]);
+ } else {
+ destination[prop] = source[prop];
+ }
+ }
+ }
+
+ return destination;
+};
+
+sys.inherits(Bancroft, events.EventEmitter);
+module.exports = Bancroft;
@@ -0,0 +1,15 @@
+{
+ "author": "Pascal Deschenes <pdeschen@rassemblr.com> (http://blog.rassemblr.com)",
+ "name": "bancroft",
+ "description": "gpsd client",
+ "version": "0.0.1",
+ "repository": {
+ "url": ""
+ },
+ "main": "bancroft",
+ "engines": {
+ "node": "v0.4.5"
+ },
+ "dependencies": {},
+ "devDependencies": {}
+}
15 test.js
@@ -0,0 +1,15 @@
+var Bancroft = require('./bancroft.js');
+
+var bancroft = new Bancroft();
+bancroft.on('connect', function () {
+ console.log('connected');
+});
+bancroft.on('location', function (location) {
+ console.log('got location');
+});
+bancroft.on('satellite', function (location) {
+ console.log('got satellite');
+});
+bancroft.on('disconnect', function (err) {
+ console.log('disconnected');
+});
@@ -0,0 +1,14 @@
+
+{"class":"VERSION","release":"2.95","rev":"2010-12-03T21:16:23","proto_major":3,"proto_minor":3}
+{"class":"DEVICES","devices":[{"class":"DEVICE","path":"/dev/ttyUSB0"}]}
+{"class":"WATCH","enable":true,"json":true,"nmea":false,"raw":0,"scaled":false,"timing":false}
+
+
+{"class":"TPV","tag":"GLL","device":"/dev/ttyUSB0","time":1311042294.000,"ept":0.005,"lat":45.457871667,"lon":-73.569558333,"alt":74.700,"epv":23.000,"track":0.0000,"speed":0.000,"climb":0.000,"mode":3}
+{"class":"SKY","tag":"GSV","device":"/dev/ttyUSB0","vdop":1.00,"hdop":6.70,"pdop":6.80,"satellites":[{"PRN":2,"el":50,"az":268,"ss":0,"used":false},{"PRN":4,"el":76,"az":37,"ss":50,"used":true},{"PRN":5,"el":15,"az":204,"ss":0,"used":false},{"PRN":10,"el":58,"az":166,"ss":0,"used":false},{"PRN":12,"el":39,"az":297,"ss":38,"used":true},{"PRN":13,"el":17,"az":94,"ss":0,"used":false},{"PRN":17,"el":44,"az":119,"ss":0,"used":false},{"PRN":20,"el":9,"az":42,"ss":0,"used":false},{"PRN":23,"el":18,"az":63,"ss":40,"used":true},{"PRN":25,"el":13,"az":323,"ss":0,"used":false}]}
+{"class":"TPV","tag":"GLL","device":"/dev/ttyUSB0","time":1311042296.000,"ept":0.005,"lat":45.457868333,"lon":-73.569558333,"alt":74.700,"epv":23.000,"track":0.0000,"speed":0.000,"climb":0.000,"mode":3}
+{"class":"TPV","tag":"GLL","device":"/dev/ttyUSB0","time":1311042298.000,"ept":0.005,"lat":45.457863333,"lon":-73.569560000,"alt":74.700,"epv":23.000,"track":0.0000,"speed":0.000,"climb":0.000,"mode":3}
+{"class":"TPV","tag":"GLL","device":"/dev/ttyUSB0","time":1311042300.000,"ept":0.005,"lat":45.457856667,"lon":-73.569560000,"alt":74.700,"epv":23.000,"track":0.0000,"speed":0.000,"climb":0.000,"mode":3}
+{"class":"SKY","tag":"GSV","device":"/dev/ttyUSB0","vdop":1.00,"hdop":6.70,"pdop":6.80,"satellites":[{"PRN":2,"el":50,"az":268,"ss":0,"used":false},{"PRN":4,"el":76,"az":37,"ss":50,"used":true},{"PRN":5,"el":15,"az":204,"ss":0,"used":false},{"PRN":10,"el":58,"az":166,"ss":0,"used":false},{"PRN":12,"el":39,"az":297,"ss":37,"used":true},{"PRN":13,"el":17,"az":94,"ss":0,"used":false},{"PRN":17,"el":44,"az":119,"ss":0,"used":false},{"PRN":20,"el":9,"az":42,"ss":0,"used":false},{"PRN":23,"el":18,"az":63,"ss":40,"used":true},{"PRN":25,"el":13,"az":323,"ss":0,"used":false}]}
+{"class":"TPV","tag":"GLL","device":"/dev/ttyUSB0","time":1311042302.000,"ept":0.005,"lat":45.457848333,"lon":-73.569560000,"alt":74.700,"epv":23.000,"track":0.0000,"speed":0.000,"climb":0.000,"mode":3}
+

0 comments on commit ada5243

Please sign in to comment.