From 54b7daea6c449d9bb962ceb7f941147fb74df0d2 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Mon, 8 Dec 2014 21:39:13 +1100 Subject: [PATCH] Added DEVID decoder for Sierra Wireless AVL --- lib/NMEA.js | 3 +++ lib/codes/DEVID.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 lib/codes/DEVID.js diff --git a/lib/NMEA.js b/lib/NMEA.js index a184dcd..3600715 100644 --- a/lib/NMEA.js +++ b/lib/NMEA.js @@ -10,6 +10,7 @@ var MWV = require("./codes/MWV.js"); var DBT = require("./codes/DBT.js"); var HDG = require("./codes/HDG.js"); var VHW = require("./codes/VHW.js"); +var DEVID = require("./codes/DEVID.js"); var Helper = require("./Helper.js"); /** NMEA module */ @@ -185,6 +186,8 @@ var NMEA = ( function() { nmea.addParser(new GLL.Decoder("GPGLL")); nmea.addParser(new HDG.Decoder("HCHDG")); nmea.addParser(new VHW.Decoder("VWVHW")); + // non-standard decoders + nmea.addParser(new DEVID.Decoder("DEVID")); // add the standard encoders nmea.addEncoder(new GGA.Encoder("GPGGA")); nmea.addEncoder(new RMC.Encoder("GPRMC")); diff --git a/lib/codes/DEVID.js b/lib/codes/DEVID.js new file mode 100644 index 0000000..a6d8421 --- /dev/null +++ b/lib/codes/DEVID.js @@ -0,0 +1,36 @@ +// Sierra Wireless GX 440 Device ID Parser +// $DEVID,0x0000028A003D2A10*40 + +var Helper = require("../Helper.js"); + +exports.Decoder = function(id) { + this.id = id; + this.talker_type_id = "DEVID"; + this.talker_type_desc = "Device ID"; + + this.parse = function(tokens) { + if(tokens.length < 2) { + throw new Error('DEVID: not enough tokens'); + } + + // trim whitespace + // some parsers may not want the tokens trimmed so the individual parser has to do it if applicable + var i; + for(i=0;i 2){ + deviceId = deviceId.substr(2); + } + + return { + id : tokens[0].substr(1), + talker_type_id: this.talker_type_id, + talker_type_desc: this.talker_type_desc, + device:deviceId + }; + }; +};