From 686ca0b3f54fb087a05bf5b75f28a5c2bc7b8397 Mon Sep 17 00:00:00 2001 From: Leonardo Gatica Date: Wed, 2 Mar 2016 17:16:07 -0300 Subject: [PATCH] Remove extra gprmc data, remove async data. --- README.md | 29 +- example.js | 2 +- src/index.js | 234 ++---- test/test.js | 2033 +++++++++++++++----------------------------------- 4 files changed, 695 insertions(+), 1603 deletions(-) diff --git a/README.md b/README.md index 5470dec..5edcc18 100644 --- a/README.md +++ b/README.md @@ -25,21 +25,16 @@ const raw = new Buffer('$$B6869444005480041|91$GPRMC,194329.000,A,3321.6735,S,07 const data = tz.parse(raw); /*{ raw: '$$B6869444005480041|91$GPRMC,194329.000,A,3321.6735,S,07030.7640,W,0.00,0.00,090216,,,A*6C|02.1|01.3|01.7|000000000000|20160209194326|13981188|00000000|32D3A03F|0000|0.6376|0100|7B20\r\n', - type: 'TZ-AVL05', - imei: 869444005480041, - alarmType: { type: 'Sleep', status: true }, - gprmcData: { - raw: '$GPRMC,194329.000,A,3321.6735,S,07030.7640,W,0.00,0.00,090216,,,A*6C', - valid: true, - type: 'RMC', - datetime: Tue Feb 09 2016 19:43:29 GMT+0000 (UTC), - loc: { type: 'Point', coordinates: [ -70.51273333, -33.361225 ] }, - gps: true, - speed: 0, - track: '0.00', - magneticVariation: null, - mode: 'Autonomous' - }, + device: 'TZ-AVL05', + type: 'data', + imei: '869444005480041', + alarm: { type: 'Sleep', status: true }, + loc: { type: 'Point', coordinates: [ -70.51273333, -33.361225 ] }, + gpsStatus: true, + speed: 0, + track: '0.00', + magneticVariation: null, + gpsMode: 'Autonomous' pdop: 2.1, hdop: 1.3, vdop: 1.7, @@ -57,8 +52,6 @@ const data = tz.parse(raw); temperature: 0, odometer: 0.6376, serialId: 100, - valid: true, - currentData: { isCurrent: false, diff: '13 días' }, - gps: 'enable' + valid: true }*/ ``` diff --git a/example.js b/example.js index a6faa63..6839be6 100644 --- a/example.js +++ b/example.js @@ -1,4 +1,4 @@ const tz = require('tz-parser'); const raw = new Buffer('$$B6869444005480041|91$GPRMC,194329.000,A,3321.6735,S,07030.7640,W,0.00,0.00,090216,,,A*6C|02.1|01.3|01.7|000000000000|20160209194326|13981188|00000000|32D3A03F|0000|0.6376|0100|7B20\r\n'); -const data = await tz.parse(raw); +const data = tz.parse(raw); diff --git a/src/index.js b/src/index.js index 09f9bee..4ab9005 100644 --- a/src/index.js +++ b/src/index.js @@ -5,14 +5,6 @@ import 'babel-polyfill'; import crc from 'crc'; import moment from 'moment'; import nmea from 'node-nmea'; -import redisUrl from 'redis-url'; -import nodeGeocoder from 'node-geocoder'; -import bscoords from 'bscoords'; -import Promise from 'bluebird'; - -Promise.promisifyAll(bscoords); - -let client; const patterns = { avl05: /^\$\$([0-9A-F]{2})(\d{15})\|([0-9A]{2})(\$GPRMC\,(\d{6}\.\d{3})\,([AV])\,(\d{4}\.\d{4}\,[NS])\,(\d{5}\.\d{4}\,[WE])\,(\d{1,3}\.\d{1,3})?\,(\d{1,3}\.\d{1,3})?\,(\d{6})\,((\d{1,3}\.\d{1,3})?\,([WE])?)\,?([ADENS])?\*([0-9A-F]{2})|[0]{60})\|(\d{2}\.\d{1})\|(\d{2}\.\d{1})\|(\d{2}\.\d{1})\|([01])([01])([01])([01])([01])([01])([01])([01])([01])([01])([01])([01])\|(\d{14})\|([01])(\d{3})(\d{4})\|(\d{4})(\d{4})\|([0-9A-F]{4})([0-9A-F]{4})\|([01\-]\d{3})\|(\d{1,4}\.\d{1,12})\|(\d{4})\|([0-9A-F]{4})\r\n$/, @@ -77,24 +69,21 @@ const isValid = (raw, len, checksum) =>{ return verifyCrc(raw, checksum) && verifyLen(raw, len); }; -const checkCurrentInfoPanel = (datetime) => { - moment.locale('es'); - const now = moment.utc(); - now.subtract(1, 'minutes'); - return { - isCurrent: now < moment.utc(datetime), - diff: moment.duration(now.diff(datetime)).humanize() - }; -}; - -const getAvl05 = async function(raw, options) { +const getAvl05 = (raw) => { const match = patterns.avl05.exec(raw.toString()); + const gprmcData = nmea.parse(match[4]); const data = { raw: match[0], - type: 'TZ-AVL05', - imei: parseInt(match[2], 10), - alarmType: getAlarm(match[3]), - gprmcData: nmea.parse(match[4]), + device: 'TZ-AVL05', + type: 'data', + imei: match[2], + alarm: getAlarm(match[3]), + loc: gprmcData.loc ? gprmcData.loc.geojson : null, + speed: gprmcData.speed ? gprmcData.speed.kmh : null, + gpsStatus: gprmcData.gps, + track: gprmcData.track, + magneticVariation: gprmcData.magneticVariation, + gpsMode: gprmcData.mode, pdop: parseFloat(match[17]), hdop: parseFloat(match[18]), vdop: parseFloat(match[19]), @@ -102,11 +91,11 @@ const getAvl05 = async function(raw, options) { raw: match.slice(20, 32).join(''), sos: match[20] === '1', input: { - '5': match[21] === '1', '1': match[24] === '1', '2': match[25] === '1', '3': match[26] === '1', - '4': match[27] === '1' + '4': match[27] === '1', + '5': match[21] === '1' }, output: { '1': match[28] === '1', @@ -128,32 +117,24 @@ const getAvl05 = async function(raw, options) { serialId: parseInt(match[42]), valid: isValid(match[0], parseInt(match[1], 16), parseInt(match[43], 16)) }; - data.currentData = checkCurrentInfoPanel(data.datetime); - data.gps = data.gprmcData.loc ? 'enable' : 'disable'; - try { - if (!data.gprmcData.loc) { - const loc = await getLoc(options.mcc, options.mnc, data.lac, data.cid); - if (!loc) return data; - data.gprmcData.loc = loc; - data.gps = 'triangulation'; - } - const [lng, lat] = data.gprmcData.loc.geojson.coordinates; - const address = await getAddress(lat, lng); - data.gprmcData.address = address; - return data; - } catch (err) { - return data; - } + return data; }; -const getAvl08 = async function(raw, options) { +const getAvl08 = (raw) => { const match = patterns.avl08.exec(raw.toString()); + const gprmcData = nmea.parse(match[4]); const data = { raw: match[0], - type: 'TZ-AVL08', - imei: parseInt(match[2], 10), - alarmType: getAlarm(match[3]), - gprmcData: nmea.parse(match[4]), + device: 'TZ-AVL08', + type: 'data', + imei: match[2], + alarm: getAlarm(match[3]), + loc: gprmcData.loc ? gprmcData.loc.geojson : null, + speed: gprmcData.speed ? gprmcData.speed.kmh : null, + gpsStatus: gprmcData.gps, + track: gprmcData.track, + magneticVariation: gprmcData.magneticVariation, + gpsMode: gprmcData.mode, pdop: parseFloat(match[17]), hdop: parseFloat(match[18]), vdop: parseFloat(match[19]), @@ -190,32 +171,24 @@ const getAvl08 = async function(raw, options) { rfidNumber: match[43] ? parseInt(match[43]) : null, valid: isValid(match[0], parseInt(match[1], 16), parseInt(match[44], 16)) }; - data.currentData = checkCurrentInfoPanel(data.datetime); - data.gps = data.gprmcData.loc ? 'enable' : 'disable'; - try { - if (!data.gprmcData.loc) { - const loc = await getLoc(options.mcc, options.mnc, data.lac, data.cid); - if (!loc) return data; - data.gprmcData.loc = loc; - data.gps = 'triangulation'; - } - const [lng, lat] = data.gprmcData.loc.geojson.coordinates; - const address = await getAddress(lat, lng); - data.gprmcData.address = address; - return data; - } catch (err) { - return data; - } + return data; }; -const getAvl201 = async function(raw, options) { +const getAvl201 = (raw) => { const match = patterns.avl201.exec(raw.toString()); + const gprmcData = nmea.parse(match[4]); const data = { raw: match[0], - type: 'TZ-AVL201', - imei: parseInt(match[2], 10), - alarmType: getAlarm(match[3]), - gprmcData: nmea.parse(match[4]), + device: 'TZ-AVL201', + type: 'data', + imei: match[2], + alarm: getAlarm(match[3]), + loc: gprmcData.loc ? gprmcData.loc.geojson : null, + speed: gprmcData.speed ? gprmcData.speed.kmh : null, + gpsStatus: gprmcData.gps, + track: gprmcData.track, + magneticVariation: gprmcData.magneticVariation, + gpsMode: gprmcData.mode, pdop: parseFloat(match[17]), hdop: parseFloat(match[18]), vdop: parseFloat(match[19]), @@ -243,22 +216,7 @@ const getAvl201 = async function(raw, options) { serialId: parseInt(match[40]), valid: isValid(match[0], parseInt(match[1], 16), parseInt(match[41], 16)) }; - data.currentData = checkCurrentInfoPanel(data.datetime); - data.gps = data.gprmcData.loc ? 'enable' : 'disable'; - try { - if (!data.gprmcData.loc) { - const loc = await getLoc(options.mcc, options.mnc, data.lac, data.cid); - if (!loc) return data; - data.gprmcData.loc = loc; - data.gps = 'triangulation'; - } - const [lng, lat] = data.gprmcData.loc.geojson.coordinates; - const address = await getAddress(lat, lng); - data.gprmcData.address = address; - return data; - } catch (err) { - return data; - } + return data; }; const getCommand = (raw) => { @@ -266,7 +224,7 @@ const getCommand = (raw) => { const password = match[1]; const code = match[2]; const extra = match[3] ? match[3].substr(1).split(',') : null; - let data = {type: 'TZ-COMMAND', password: password}; + let data = {device: 'TZ-COMMAND', type: 'command', password: password}; if (code === '001') { data.command = 'SetUserPassword'; data.newPassword = extra[0]; @@ -535,7 +493,7 @@ const getCommand = (raw) => { let [x, y] = extra; data.command = 'SETIMEI'; data.enable = x === '1'; - data.newImei = parseInt(y, 10); + data.newImei = y; } else if (code === '404') { let [x, y] = extra; data.command = 'SETIDLE'; @@ -580,31 +538,44 @@ const getCommand = (raw) => { return data; }; -const getPicture = (data) => { - const results = data.toString().match(/\$U\d{15}\d{5}\d{3}\d{3}[0-9a-fA-F]{1,200}#/g).map(x => { +const getPicture = (raw) => { + const results = raw.toString().match(/\$U\d{15}\d{5}\d{3}\d{3}[0-9a-fA-F]{1,200}#/g).map(x => { const match = /\$U(\d{15})(\d{5})(\d{3})(\d{3})([0-9a-fA-F]{1,200})#/.exec(x); return { - imei: parseInt(match[1], 10), + imei: match[1], number: parseInt(match[2], 10), total: parseInt(match[3], 10), sequence: parseInt(match[4], 10), data: match[5] }; }); - return {type: 'TZ-IMAGE', data: results}; + const imei = results[0].imei; + const number = results[0].number; + const total = results[0].total; + const data = results.map(x => { + return {sequence: x.sequence, data: x.data}; + }); + return { + device: 'TZ-IMAGE', + type: 'image', + imei: imei, + number: number, + total: total, + data: data + }; }; const getCommandError = (data) => { const match = patterns.receiveErr.exec(data.toString()); - return {type: 'TZ-ERROR', command: match[0]}; + return {device: 'TZ-ERROR', type: 'error', command: match[0]}; }; const getCommandFirmware = (data) => { const match = patterns.firmware.exec(data.toString()); return { - type: 'TZ-FIRMWARE', - command: 'request_firmware', - imei: parseInt(match[1], 10), + device: 'TZ-FIRMWARE', + type: 'firmware', + imei: match[1], firmware: match[2], gsm: match[3] }; @@ -613,8 +584,8 @@ const getCommandFirmware = (data) => { const getCommandInfo = (data) => { const match = patterns.info.exec(data.toString()); return { - type: 'TZ-INFO', - command: 'info', + device: 'TZ-INFO', + type: 'info', latitude: match[1], longitude: match[2], speed: parseInt(match[3], 10), @@ -631,82 +602,22 @@ const getCommandInfo = (data) => { const getCommandMap = (data) => { const match = patterns.map.exec(data.toString()); return { - type: 'TZ-MAP', - command: 'map_link', + device: 'TZ-MAP', + type: 'map_link', url: match[0], latitude: parseFloat(match[1]), longitude: parseFloat(match[2]) }; }; -const setCache = (uri) => { - try { - client = redisUrl.connect(uri); - Promise.promisifyAll(Object.getPrototypeOf(client)); - } catch (err) { - throw err; - } -}; - -const getReverse = async function(lat, lon) { - const geocoderProvider = 'google'; - const httpAdapter = 'http'; - const geocoder = nodeGeocoder(geocoderProvider, httpAdapter); - try { - const res = await geocoder.reverse({lat: lat, lon: lon}); - if (res.length === 0) return null; - return res[0].formattedAddress.split(',').map(x => x.trim()).slice(0, 2).join(', '); - } catch (err) { - return null; - } -}; - -const getAddress = async function(lat, lng) { - try { - let address; - if (client) { - const reply = await client.getAsync(`geocoder:${lat}:${lng}`); - if (reply) return reply; - address = await getReverse(lat, lng); - if (!address) return null; - client.set(`geocoder:${lat}:${lng}`, address); - } else { - address = await getReverse(lat, lng); - } - return address; - } catch (err) { - return null; - } -}; - -const getLoc = async function(mcc, mnc, lac, cellid) { - try { - const coords = await bscoords.requestGoogleAsync(mcc, mnc, lac, cellid); - return { - dmm: { - latitude: nmea.latToDmm(coords.lat), - longitude: nmea.lngToDmm(coords.lon) - }, - geojson: { - coordinates: [coords.lon, coords.lat], - type: 'Point' - } - }; - } catch (err) { - return null; - } -}; - -const parse = async function(raw, options = {}) { - options.mcc = options.mcc || 730; - options.mnc = options.mnc || 1; +const parse = (raw) => { let result = {type: 'UNKNOWN', raw: raw.toString()}; if (patterns.avl05.test(raw.toString())) { - result = await getAvl05(raw, options); + result = getAvl05(raw); } else if (patterns.avl08.test(raw.toString())) { - result = await getAvl08(raw, options); + result = getAvl08(raw); } else if (patterns.avl201.test(raw.toString())) { - result = await getAvl201(raw, options); + result = getAvl201(raw); } else if (patterns.receiveOk.test(raw.toString())) { result = getCommand(raw); } else if (patterns.picture.test(raw.toString())) { @@ -735,7 +646,6 @@ module.exports = { getCommandFirmware: getCommandFirmware, getCommandInfo: getCommandInfo, getCommandMap: getCommandMap, - setCache: setCache, verifyLen: verifyLen, verifyCrc: verifyCrc }; diff --git a/test/test.js b/test/test.js index 7dbdf4c..a4b7590 100644 --- a/test/test.js +++ b/test/test.js @@ -1,1492 +1,681 @@ 'use strict'; -import tzParser from '../lib'; +import tz from '../lib'; import {expect} from 'chai'; describe('tz-parzer', () => { - describe('valid TZ-AVL05 data with gps', () => { + it('should return TZ-AVL05 data parsed', () => { const raw = new Buffer('$$B6869444005480041|AA$GPRMC,194329.000,A,3321.6735,S,07030.7640,W,0.00,0.00,090216,,,A*6C|02.1|01.3|01.7|000000000000|20160209194326|13981188|00000000|32D3A03F|0000|0.6376|0100|995F\r\n'); - let data; - let error; - - before((done) => { - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.raw).to.eql(raw.toString()); - expect(data.type).to.eql('TZ-AVL05'); - expect(data.imei).to.eql(869444005480041); - expect(data.alarmType.type).to.eql('Gps'); - expect(data.gprmcData.raw).to.eql('$GPRMC,194329.000,A,3321.6735,S,07030.7640,W,0.00,0.00,090216,,,A*6C'); - expect(data.pdop).to.eql(2.1); - expect(data.hdop).to.eql(1.3); - expect(data.vdop).to.eql(1.7); - expect(data.status.raw).to.eql('000000000000'); - expect(data.status.sos).to.be.false; - expect(data.status.input[1]).to.be.false; - expect(data.status.input[2]).to.be.false; - expect(data.status.input[3]).to.be.false; - expect(data.status.input[4]).to.be.false; - expect(data.status.input[5]).to.be.false; - expect(data.status.output[1]).to.be.false; - expect(data.status.output[2]).to.be.false; - expect(data.status.charge).to.be.true; - expect(data.datetime).to.eql(new Date(2016, 1, 9, 19, 43, 26)); - expect(data.voltage.battery).to.eql(3.98); - expect(data.voltage.inputCharge).to.eql(11.88); - expect(data.voltage.ada).to.eql(0); - expect(data.voltage.adb).to.eql(0); - expect(data.lac).to.eql(13011); - expect(data.cid).to.eql(41023); - expect(data.temperature).to.eql(0); - expect(data.odometer).to.eql(0.6376); - expect(data.serialId).to.eql(100); - expect(data.valid).to.be.true; - expect(data.currentData.isCurrent).to.be.false; - expect(data.currentData.diff).to.be.a.string; - expect(data.gps).to.eql('enable'); - expect(data.address).to.a.string; - expect(error).to.be.undefined; - }); - }); + const data = tz.parse(raw); + expect(data.raw).to.eql(raw.toString()); + expect(data.device).to.eql('TZ-AVL05'); + expect(data.type).to.eql('data'); + expect(data.imei).to.eql('869444005480041'); + expect(data.alarm.type).to.eql('Gps'); + expect(data.loc.type).to.eql('Point'); + expect(data.loc.coordinates).to.eql([-70.51273333333333, -33.361225]); + expect(data.speed).to.eql(0); + expect(data.gpsStatus).to.be.a.true; + expect(data.track).to.eql('0.00'); + expect(data.magneticVariation).to.be.null; + expect(data.gpsMode).to.eql('Autonomous'); + expect(data.pdop).to.eql(2.1); + expect(data.hdop).to.eql(1.3); + expect(data.vdop).to.eql(1.7); + expect(data.status.raw).to.eql('000000000000'); + expect(data.status.sos).to.be.false; + expect(data.status.input[1]).to.be.false; + expect(data.status.input[2]).to.be.false; + expect(data.status.input[3]).to.be.false; + expect(data.status.input[4]).to.be.false; + expect(data.status.input[5]).to.be.false; + expect(data.status.output[1]).to.be.false; + expect(data.status.output[2]).to.be.false; + expect(data.status.charge).to.be.true; + expect(data.datetime).to.eql(new Date(2016, 1, 9, 19, 43, 26)); + expect(data.voltage.battery).to.eql(3.98); + expect(data.voltage.inputCharge).to.eql(11.88); + expect(data.voltage.ada).to.eql(0); + expect(data.voltage.adb).to.eql(0); + expect(data.lac).to.eql(13011); + expect(data.cid).to.eql(41023); + expect(data.temperature).to.eql(0); + expect(data.odometer).to.eql(0.6376); + expect(data.serialId).to.eql(100); + expect(data.valid).to.be.true; }); - describe('valid TZ-AVL08 data with gps', () => { + it('should return TZ-AVL08 data parsed', () => { const raw = new Buffer('$$B7869444005480041|AA$GPRMC,194329.000,A,3321.6735,S,07030.7640,W,0.00,0.00,090216,,,A*6C|02.1|01.3|01.7|000000000000|20160209194326|13981188|00000000|32D3A03F|0000|0.6376|0100||56E2\r\n'); - let data; - let error; - - before((done) => { - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.raw).to.eql(raw.toString()); - expect(data.type).to.eql('TZ-AVL08'); - expect(data.imei).to.eql(869444005480041); - expect(data.alarmType.type).to.eql('Gps'); - expect(data.gprmcData.raw).to.eql('$GPRMC,194329.000,A,3321.6735,S,07030.7640,W,0.00,0.00,090216,,,A*6C'); - expect(data.pdop).to.eql(2.1); - expect(data.hdop).to.eql(1.3); - expect(data.vdop).to.eql(1.7); - expect(data.status.raw).to.eql('000000000000'); - expect(data.status.sos).to.be.false; - expect(data.status.input[1]).to.be.false; - expect(data.status.input[2]).to.be.false; - expect(data.status.input[3]).to.be.false; - expect(data.status.input[4]).to.be.false; - expect(data.status.input[5]).to.be.false; - expect(data.status.output[1]).to.be.false; - expect(data.status.output[2]).to.be.false; - expect(data.status.output[3]).to.be.false; - expect(data.status.output[4]).to.be.false; - expect(data.status.charge).to.be.true; - expect(data.datetime).to.eql(new Date(2016, 1, 9, 19, 43, 26)); - expect(data.voltage.battery).to.eql(3.98); - expect(data.voltage.inputCharge).to.eql(11.88); - expect(data.voltage.ada).to.eql(0); - expect(data.voltage.adb).to.eql(0); - expect(data.lac).to.eql(13011); - expect(data.cid).to.eql(41023); - expect(data.temperature).to.eql(0); - expect(data.odometer).to.eql(0.6376); - expect(data.serialId).to.eql(100); - expect(data.valid).to.be.true; - expect(data.currentData.isCurrent).to.be.false; - expect(data.currentData.diff).to.be.a.string; - expect(data.gps).to.eql('enable'); - expect(data.address).to.a.string; - expect(data.rfidNumber).to.be.null; - expect(error).to.be.undefined; - }); - }); + const data = tz.parse(raw); + expect(data.raw).to.eql(raw.toString()); + expect(data.device).to.eql('TZ-AVL08'); + expect(data.type).to.eql('data'); + expect(data.imei).to.eql('869444005480041'); + expect(data.alarm.type).to.eql('Gps'); + expect(data.loc.type).to.eql('Point'); + expect(data.loc.coordinates).to.eql([-70.51273333333333, -33.361225]); + expect(data.speed).to.eql(0); + expect(data.gpsStatus).to.be.a.true; + expect(data.track).to.eql('0.00'); + expect(data.magneticVariation).to.be.null; + expect(data.gpsMode).to.eql('Autonomous'); + expect(data.pdop).to.eql(2.1); + expect(data.hdop).to.eql(1.3); + expect(data.vdop).to.eql(1.7); + expect(data.status.raw).to.eql('000000000000'); + expect(data.status.sos).to.be.false; + expect(data.status.input[1]).to.be.false; + expect(data.status.input[2]).to.be.false; + expect(data.status.input[3]).to.be.false; + expect(data.status.input[4]).to.be.false; + expect(data.status.input[5]).to.be.false; + expect(data.status.output[1]).to.be.false; + expect(data.status.output[2]).to.be.false; + expect(data.status.output[3]).to.be.false; + expect(data.status.output[4]).to.be.false; + expect(data.status.charge).to.be.true; + expect(data.datetime).to.eql(new Date(2016, 1, 9, 19, 43, 26)); + expect(data.voltage.battery).to.eql(3.98); + expect(data.voltage.inputCharge).to.eql(11.88); + expect(data.voltage.ada).to.eql(0); + expect(data.voltage.adb).to.eql(0); + expect(data.lac).to.eql(13011); + expect(data.cid).to.eql(41023); + expect(data.temperature).to.eql(0); + expect(data.odometer).to.eql(0.6376); + expect(data.serialId).to.eql(100); + expect(data.valid).to.be.true; + expect(data.rfidNumber).to.be.null; }); - describe('valid TZ-AVL201 data with gps', () => { + it('should return TZ-AVL201 data parsed', () => { const raw = new Buffer('$$AD869444005480041|AA$GPRMC,194329.000,A,3321.6735,S,07030.7640,W,0.00,0.00,090216,,,A*6C|02.1|01.3|01.7|000000000000|20160209194326|13981188|32D3A03F|0000|0.6376|0100|5BEB\r\n'); - let data; - let error; - - before((done) => { - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.raw).to.eql(raw.toString()); - expect(data.type).to.eql('TZ-AVL201'); - expect(data.imei).to.eql(869444005480041); - expect(data.alarmType.type).to.eql('Gps'); - expect(data.gprmcData.raw).to.eql('$GPRMC,194329.000,A,3321.6735,S,07030.7640,W,0.00,0.00,090216,,,A*6C'); - expect(data.pdop).to.eql(2.1); - expect(data.hdop).to.eql(1.3); - expect(data.vdop).to.eql(1.7); - expect(data.status.raw).to.eql('000000000000'); - expect(data.status.input[1]).to.be.false; - expect(data.status.input[2]).to.be.false; - expect(data.status.input[3]).to.be.false; - expect(data.status.output[1]).to.be.false; - expect(data.status.charge).to.be.true; - expect(data.datetime).to.eql(new Date(2016, 1, 9, 19, 43, 26)); - expect(data.voltage.battery).to.eql(3.98); - expect(data.voltage.inputCharge).to.eql(11.88); - expect(data.lac).to.eql(13011); - expect(data.cid).to.eql(41023); - expect(data.temperature).to.eql(0); - expect(data.odometer).to.eql(0.6376); - expect(data.serialId).to.eql(100); - expect(data.valid).to.be.true; - expect(data.currentData.isCurrent).to.be.false; - expect(data.currentData.diff).to.be.a.string; - expect(data.gps).to.eql('enable'); - expect(data.address).to.a.string; - expect(error).to.be.undefined; - }); - }); + const data = tz.parse(raw); + expect(data.raw).to.eql(raw.toString()); + expect(data.device).to.eql('TZ-AVL201'); + expect(data.type).to.eql('data'); + expect(data.imei).to.eql('869444005480041'); + expect(data.alarm.type).to.eql('Gps'); + expect(data.loc.type).to.eql('Point'); + expect(data.loc.coordinates).to.eql([-70.51273333333333, -33.361225]); + expect(data.speed).to.eql(0); + expect(data.gpsStatus).to.be.a.true; + expect(data.track).to.eql('0.00'); + expect(data.magneticVariation).to.be.null; + expect(data.gpsMode).to.eql('Autonomous'); + expect(data.pdop).to.eql(2.1); + expect(data.hdop).to.eql(1.3); + expect(data.vdop).to.eql(1.7); + expect(data.status.raw).to.eql('000000000000'); + expect(data.status.input[1]).to.be.false; + expect(data.status.input[2]).to.be.false; + expect(data.status.input[3]).to.be.false; + expect(data.status.output[1]).to.be.false; + expect(data.status.charge).to.be.true; + expect(data.datetime).to.eql(new Date(2016, 1, 9, 19, 43, 26)); + expect(data.voltage.battery).to.eql(3.98); + expect(data.voltage.inputCharge).to.eql(11.88); + expect(data.lac).to.eql(13011); + expect(data.cid).to.eql(41023); + expect(data.temperature).to.eql(0); + expect(data.odometer).to.eql(0.6376); + expect(data.serialId).to.eql(100); + expect(data.valid).to.be.true; }); - describe('TZ-INFO', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Lat:-3321.6664S\r\nLong:-07030.8921W\r\nSpd:000km/h\r\nFix:A\r\nSat:04\r\nHDOP:02.2\r\nGSM:29\r\nBatt:04.01V\r\nMile:0.1527\r\nTime:19/02/16 15:00:17\r\n'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.type).to.eql('TZ-INFO'); - expect(data.command).to.eql('info'); - expect(data.latitude).to.eql('-3321.6664S'); - expect(data.longitude).to.eql('-07030.8921W'); - expect(data.speed).to.eql(0); - expect(data.fix).to.eql('A'); - expect(data.sat).to.eql(4); - expect(data.hdop).to.eql(2.2); - expect(data.gsm).to.eql(29); - expect(data.battery).to.eql(4.01); - expect(data.odometer).to.eql(0.1527); - expect(data.datetime).to.eql(new Date(2016, 1, 19, 15, 0, 17)); - expect(error).to.be.undefined; - }); - }); + it('should return TZ-INFO data parsed', () => { + const raw = new Buffer('Lat:-3321.6664S\r\nLong:-07030.8921W\r\nSpd:000km/h\r\nFix:A\r\nSat:04\r\nHDOP:02.2\r\nGSM:29\r\nBatt:04.01V\r\nMile:0.1527\r\nTime:19/02/16 15:00:17\r\n'); + const data = tz.parse(raw); + expect(data.device).to.eql('TZ-INFO'); + expect(data.type).to.eql('info'); + expect(data.latitude).to.eql('-3321.6664S'); + expect(data.longitude).to.eql('-07030.8921W'); + expect(data.speed).to.eql(0); + expect(data.fix).to.eql('A'); + expect(data.sat).to.eql(4); + expect(data.hdop).to.eql(2.2); + expect(data.gsm).to.eql(29); + expect(data.battery).to.eql(4.01); + expect(data.odometer).to.eql(0.1527); + expect(data.datetime).to.eql(new Date(2016, 1, 19, 15, 0, 17)); }); - describe('TZ-COMMAND SetUserPassword', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'001\'OK\r\n*000000,001,111111#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SetUserPassword'); - expect(data.newPassword).to.eql('111111'); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SetUserPassword data parsed', () => { + const raw = new Buffer('Receive:\'001\'OK\r\n*000000,001,111111#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SetUserPassword'); + expect(data.newPassword).to.eql('111111'); }); - describe('TZ-COMMAND SETINTERVALOFSMS', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'002\'OK\r\n*000000,002,1,999#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETINTERVALOFSMS'); - expect(data.enable).to.be.true; - expect(data.interval).to.eql('1'); - expect(data.limit).to.eql('999'); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETINTERVALOFSMS data parsed', () => { + const raw = new Buffer('Receive:\'002\'OK\r\n*000000,002,1,999#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETINTERVALOFSMS'); + expect(data.enable).to.be.true; + expect(data.interval).to.eql('1'); + expect(data.limit).to.eql('999'); }); - describe('TZ-COMMAND SETPHONESMSFORSOS', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'003\'OK\r\n*000000,003,0,1,005695487459,005695487459#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETPHONESMSFORSOS'); - expect(data.enable).to.be.true; - expect(data.callNumber).to.eql('005695487459'); - expect(data.smsNumber).to.eql('005695487459'); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETPHONESMSFORSOS data parsed', () => { + const raw = new Buffer('Receive:\'003\'OK\r\n*000000,003,0,1,005695487459,005695487459#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETPHONESMSFORSOS'); + expect(data.enable).to.be.true; + expect(data.callNumber).to.eql('005695487459'); + expect(data.smsNumber).to.eql('005695487459'); }); - describe('TZ-COMMAND SETLOWPOWERALARM', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'004\'OK\r\n*000000,004,380,350#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETLOWPOWERALARM'); - expect(data.lowPower).to.eql(3.8); - expect(data.autoShutdown).to.eql(3.5); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETLOWPOWERALARM data parsed', () => { + const raw = new Buffer('Receive:\'004\'OK\r\n*000000,004,380,350#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETLOWPOWERALARM'); + expect(data.lowPower).to.eql(3.8); + expect(data.autoShutdown).to.eql(3.5); }); - describe('TZ-COMMAND SETOVERSPEEDALARM', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'005\'OK\r\n*000000,005,1,100,10,360#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETOVERSPEEDALARM'); - expect(data.enable).to.be.true; - expect(data.speed).to.eql(100); - expect(data.times).to.eql(10); - expect(data.interval).to.eql(360); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETOVERSPEEDALARM data parsed', () => { + const raw = new Buffer('Receive:\'005\'OK\r\n*000000,005,1,100,10,360#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETOVERSPEEDALARM'); + expect(data.enable).to.be.true; + expect(data.speed).to.eql(100); + expect(data.times).to.eql(10); + expect(data.interval).to.eql(360); }); - describe('TZ-COMMAND SETGEOFENCEALARM', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'006\'OK\r\n*000000,006,-3321.6805,-07030.9513,-3321.6095,-07030.8714,1,1#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETGEOFENCEALARM'); - expect(data.enable).to.be.true; - expect(data.mode).to.eql('inside'); - expect(data.geojson.type).to.eql('Polygon'); - expect(data.geojson.coordinates).to.eql([[ - [-70.51452333333333, -33.36015833333333], - [-70.51452333333333, -33.36134166666667], - [-70.515855, -33.36134166666667], - [-70.515855, -33.36015833333333], - [-70.51452333333333, -33.36015833333333] - ]]); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETGEOFENCEALARM data parsed', () => { + const raw = new Buffer('Receive:\'006\'OK\r\n*000000,006,-3321.6805,-07030.9513,-3321.6095,-07030.8714,1,1#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETGEOFENCEALARM'); + expect(data.enable).to.be.true; + expect(data.mode).to.eql('inside'); + expect(data.geojson.type).to.eql('Polygon'); + expect(data.geojson.coordinates).to.eql([[ + [-70.51452333333333, -33.36015833333333], + [-70.51452333333333, -33.36134166666667], + [-70.515855, -33.36134166666667], + [-70.515855, -33.36015833333333], + [-70.51452333333333, -33.36015833333333] + ]]); }); - describe('TZ-COMMAND SETEXTEND', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'008\'OK\r\n*000000,008,0000000#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETEXTEND'); - expect(data.extend).to.eql({a: false, b: false, c: false, d: false, e: false, f: false, g: false}); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETEXTEND data parsed', () => { + const raw = new Buffer('Receive:\'008\'OK\r\n*000000,008,0000000#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETEXTEND'); + expect(data.extend).to.eql({a: false, b: false, c: false, d: false, e: false, f: false, g: false}); }); - describe('TZ-COMMAND SETGSMBAUD', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'009\'OK\r\n*000000,009,2#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETGSMBAUD'); - expect(data.band).to.eql('auto'); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETGSMBAUD data parsed', () => { + const raw = new Buffer('Receive:\'009\'OK\r\n*000000,009,2#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETGSMBAUD'); + expect(data.band).to.eql('auto'); }); - describe('TZ-COMMAND SETAPN', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'011\'OK\r\n*000000,011,imovil.entelpcs.cl,entelpcs,entelpcs#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETAPN'); - expect(data.apn).to.eql('imovil.entelpcs.cl'); - expect(data.username).to.eql('entelpcs'); - expect(data.pass).to.eql('entelpcs'); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETAPN data parsed', () => { + const raw = new Buffer('Receive:\'011\'OK\r\n*000000,011,imovil.entelpcs.cl,entelpcs,entelpcs#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETAPN'); + expect(data.apn).to.eql('imovil.entelpcs.cl'); + expect(data.username).to.eql('entelpcs'); + expect(data.pass).to.eql('entelpcs'); }); - describe('TZ-COMMAND SETDNS', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'014\'OK\r\n*000000,014,1,8.8.8.8,8.8.4.4#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETDNS'); - expect(data.enable).to.be.true; - expect(data.dns1).to.eql('8.8.8.8'); - expect(data.dns2).to.eql('8.8.4.4'); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETDNS data parsed', () => { + const raw = new Buffer('Receive:\'014\'OK\r\n*000000,014,1,8.8.8.8,8.8.4.4#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETDNS'); + expect(data.enable).to.be.true; + expect(data.dns1).to.eql('8.8.8.8'); + expect(data.dns2).to.eql('8.8.4.4'); }); - describe('TZ-COMMAND SETIPANDPORT', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'015\'OK\r\n*000000,015,1,server.com,1331#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETIPANDPORT'); - expect(data.host).to.eql('server.com'); - expect(data.port).to.eql(1331); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETIPANDPORT data parsed', () => { + const raw = new Buffer('Receive:\'015\'OK\r\n*000000,015,1,server.com,1331#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETIPANDPORT'); + expect(data.host).to.eql('server.com'); + expect(data.port).to.eql(1331); }); - describe('TZ-COMMAND SETGPRSINTERVAL', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'018\'OK\r\n*000000,018,10,999#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETGPRSINTERVAL'); - expect(data.enable).to.be.true; - expect(data.interval).to.eql(10); - expect(data.limit).to.eql(999); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETGPRSINTERVAL data parsed', () => { + const raw = new Buffer('Receive:\'018\'OK\r\n*000000,018,10,999#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETGPRSINTERVAL'); + expect(data.enable).to.be.true; + expect(data.interval).to.eql(10); + expect(data.limit).to.eql(999); }); - describe('TZ-COMMAND SETSYSSWITCH', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'016\'OK\r\n*000000,016,1#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETSYSSWITCH'); - expect(data.enable).to.be.true; - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETSYSSWITCH data parsed', () => { + const raw = new Buffer('Receive:\'016\'OK\r\n*000000,016,1#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETSYSSWITCH'); + expect(data.enable).to.be.true; }); - describe('TZ-COMMAND SETTCPSWITCH', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'019\'OK\r\n*000000,019,1#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETTCPSWITCH'); - expect(data.mode).to.eql('tcp'); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETTCPSWITCH data parsed', () => { + const raw = new Buffer('Receive:\'019\'OK\r\n*000000,019,1#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETTCPSWITCH'); + expect(data.mode).to.eql('tcp'); }); - describe('TZ-COMMAND SETTREMBLESWITCH', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'021\'OK\r\n*000000,021,1,1#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETTREMBLESWITCH'); - expect(data.sleep).to.be.true; - expect(data.tremble).to.be.true; - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETTREMBLESWITCH data parsed', () => { + const raw = new Buffer('Receive:\'021\'OK\r\n*000000,021,1,1#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETTREMBLESWITCH'); + expect(data.sleep).to.be.true; + expect(data.tremble).to.be.true; }); - describe('TZ-COMMAND SETSLEEPSWITCH', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'022\'OK\r\n*000000,022,0,0#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETSLEEPSWITCH'); - expect(data.closeGps).to.be.true; - expect(data.closeGsm).to.be.true; - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETSLEEPSWITCH data parsed', () => { + const raw = new Buffer('Receive:\'022\'OK\r\n*000000,022,0,0#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETSLEEPSWITCH'); + expect(data.closeGps).to.be.true; + expect(data.closeGsm).to.be.true; }); - describe('TZ-COMMAND SETIOSWITCH', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'025\'OK\r\n*000000,025,A,1#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETIOSWITCH'); - expect(data.enable).to.be.true; - expect(data.port).to.eql(1); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETIOSWITCH data parsed', () => { + const raw = new Buffer('Receive:\'025\'OK\r\n*000000,025,A,1#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETIOSWITCH'); + expect(data.enable).to.be.true; + expect(data.port).to.eql(1); }); - describe('TZ-COMMAND SETHEARTBEATSWITCH', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'040\'OK\r\n*000000,040,0#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETHEARTBEATSWITCH'); - expect(data.enable).to.be.false; - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETHEARTBEATSWITCH data parsed', () => { + const raw = new Buffer('Receive:\'040\'OK\r\n*000000,040,0#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETHEARTBEATSWITCH'); + expect(data.enable).to.be.false; }); - describe('TZ-COMMAND SETHEARTBEATINTERVAL', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'041\'OK\r\n*000000,041,0#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETHEARTBEATINTERVAL'); - expect(data.enable).to.be.false; - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETHEARTBEATINTERVAL data parsed', () => { + const raw = new Buffer('Receive:\'041\'OK\r\n*000000,041,0#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETHEARTBEATINTERVAL'); + expect(data.enable).to.be.false; }); - describe('TZ-COMMAND SETHEARTBEATINIT', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'042\'OK\r\n*000000,042#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETHEARTBEATINIT'); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETHEARTBEATINIT data parsed', () => { + const raw = new Buffer('Receive:\'042\'OK\r\n*000000,042#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETHEARTBEATINIT'); }); - describe('TZ-COMMAND SETTREMBLETOSLEEP', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'044\'OK\r\n*000000,044,30#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETTREMBLETOSLEEP'); - expect(data.after).to.eql(30); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETTREMBLETOSLEEP data parsed', () => { + const raw = new Buffer('Receive:\'044\'OK\r\n*000000,044,30#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETTREMBLETOSLEEP'); + expect(data.after).to.eql(30); }); - describe('TZ-COMMAND SETTREMBLETOWAKEUP', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'043\'OK\r\n*000000,043,10#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETTREMBLETOWAKEUP'); - expect(data.after).to.eql(10); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETTREMBLETOWAKEUP data parsed', () => { + const raw = new Buffer('Receive:\'043\'OK\r\n*000000,043,10#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETTREMBLETOWAKEUP'); + expect(data.after).to.eql(10); }); - describe('TZ-COMMAND SETPARKINGALARM', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'110\'OK\r\n*000000,110,0#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETPARKINGALARM'); - expect(data.enable).to.be.false; - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETPARKINGALARM data parsed', () => { + const raw = new Buffer('Receive:\'110\'OK\r\n*000000,110,0#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETPARKINGALARM'); + expect(data.enable).to.be.false; }); - describe('TZ-FIRMWARE', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('IMEI:869444005480041\r\nVER:TC_AVL05vSST_JOSE10.12\r\nGSMVER:1116B02SIM840WL_MXIC\r\n'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.type).to.eql('TZ-FIRMWARE'); - expect(data.command).to.eql('request_firmware'); - expect(data.imei).to.eql(869444005480041); - expect(data.firmware).to.eql('TC_AVL05vSST_JOSE10.12'); - expect(data.gsm).to.eql('1116B02SIM840WL_MXIC'); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND FACTORYRESET data parsed', () => { + const raw = new Buffer('Receive:\'990\'OK\r\n*000000,990#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('FACTORYRESET'); }); - describe('TZ-COMMAND FACTORYRESET', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'990\'OK\r\n*000000,990#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('FACTORYRESET'); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND RBOOT data parsed', () => { + const raw = new Buffer('Receive:\'991\'OK\r\n*000000,991#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('RBOOT'); }); - describe('TZ-COMMAND RBOOT', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'991\'OK\r\n*000000,991#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('RBOOT'); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETOILSENSER data parsed', () => { + const raw = new Buffer('Receive:\'113\'OK\r\n*000000,113,100,500#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETOILSENSER'); + expect(data.empty).to.eql(1); + expect(data.full).to.eql(5); }); - describe('TZ-MAP', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('http://maps.google.com/maps?f=q&hl=en&q=-33.361106,-070.514868&ie=UTF8&z=16&iwloc=addr&om=1'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.type).to.eql('TZ-MAP'); - expect(data.command).to.eql('map_link'); - expect(data.url).to.eql('http://maps.google.com/maps?f=q&hl=en&q=-33.361106,-070.514868&ie=UTF8&z=16&iwloc=addr&om=1'); - expect(data.latitude).to.eql(-33.361106); - expect(data.longitude).to.eql(-70.514868); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETSHUTOIL data parsed', () => { + const raw = new Buffer('Receive:\'117\'OK\r\n*000000,117,60,500,3000,5#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETSHUTOIL'); + expect(data.speed).to.eql(60); + expect(data.off).to.eql(500); + expect(data.restart).to.eql(3000); + expect(data.repeat).to.eql(5); }); - describe('TZ-COMMAND SETOILSENSER', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'113\'OK\r\n*000000,113,100,500#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETOILSENSER'); - expect(data.empty).to.eql(1); - expect(data.full).to.eql(5); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETSHUTOILSWITCH data parsed', () => { + const raw = new Buffer('Receive:\'116\'OK\r\n*000000,116,0#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETSHUTOILSWITCH'); + expect(data.enable).to.be.false; }); - describe('TZ-COMMAND SETSHUTOIL', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'117\'OK\r\n*000000,117,60,500,3000,5#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETSHUTOIL'); - expect(data.speed).to.eql(60); - expect(data.off).to.eql(500); - expect(data.restart).to.eql(3000); - expect(data.repeat).to.eql(5); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETCALLA data parsed', () => { + const raw = new Buffer('Receive:\'103\'OK\r\n*000000,103,0,005695487459#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETCALLA'); + expect(data.mode).to.eql('gprs'); + expect(data.number).to.eql('005695487459'); }); - describe('TZ-COMMAND SETSHUTOILSWITCH', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'116\'OK\r\n*000000,116,0#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETSHUTOILSWITCH'); - expect(data.enable).to.be.false; - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETEXTEND2 data parsed', () => { + const raw = new Buffer('Receive:\'118\'OK\r\n*000000,118,00000000#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETEXTEND2'); + expect(data.extend).to.eql({a: false, b: false, c: false, d: false, e: false, f: false, g: false, h: false}); }); - describe('TZ-COMMAND SETCALLA', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'103\'OK\r\n*000000,103,0,005695487459#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETCALLA'); - expect(data.mode).to.eql('gprs'); - expect(data.number).to.eql('005695487459'); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETPIN data parsed', () => { + const raw = new Buffer('Receive:\'122\'OK\r\n*000000,122,0,1234#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETPIN'); + expect(data.enable).to.be.false; + expect(data.pin).to.eql('1234'); }); - describe('TZ-COMMAND SETEXTEND2', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'118\'OK\r\n*000000,118,00000000#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETEXTEND2'); - expect(data.extend).to.eql({a: false, b: false, c: false, d: false, e: false, f: false, g: false, h: false}); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETANGLE data parsed', () => { + const raw = new Buffer('Receive:\'300\'OK\r\n*000000,300,0,360#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETANGLE'); + expect(data.enable).to.be.false; + expect(data.angle).to.eql(360); }); - describe('TZ-COMMAND SETPIN', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'122\'OK\r\n*000000,122,0,1234#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETPIN'); - expect(data.enable).to.be.false; - expect(data.pin).to.eql('1234'); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETANGLE data parsed', () => { + const raw = new Buffer('Receive:\'400\'OK\r\n*000000,400,0,360#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETANGLE'); + expect(data.enable).to.be.false; + expect(data.angle).to.eql(360); }); - describe('TZ-COMMAND SETANGLE', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'300\'OK\r\n*000000,300,0,360#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETANGLE'); - expect(data.enable).to.be.false; - expect(data.angle).to.eql(360); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETREBOOT data parsed', () => { + const raw = new Buffer('Receive:\'600\'OK\r\n*000000,600,0,30#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETREBOOT'); + expect(data.enable).to.be.false; + expect(data.interval).to.eql(30); }); - describe('TZ-COMMAND SETANGLE', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'400\'OK\r\n*000000,400,0,360#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETANGLE'); - expect(data.enable).to.be.false; - expect(data.angle).to.eql(360); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETACCALARM data parsed', () => { + const raw = new Buffer('Receive:\'120\'OK\r\n*000000,120,0,30,30#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETACCALARM'); + expect(data.enable).to.be.false; + expect(data.acceleration).to.eql(30); + expect(data.deceleration).to.eql(30); }); - describe('TZ-COMMAND SETREBOOT', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'600\'OK\r\n*000000,600,0,30#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETREBOOT'); - expect(data.enable).to.be.false; - expect(data.interval).to.eql(30); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETROAMING data parsed', () => { + const raw = new Buffer('Receive:\'121\'OK\r\n*000000,121,0,30,210#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETROAMING'); + expect(data.enable).to.be.false; + expect(data.interval).to.eql(30); + expect(data.network).to.eql('210'); }); - describe('TZ-COMMAND SETACCALARM', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'120\'OK\r\n*000000,120,0,30,30#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETACCALARM'); - expect(data.enable).to.be.false; - expect(data.acceleration).to.eql(30); - expect(data.deceleration).to.eql(30); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETACKSTATE data parsed', () => { + const raw = new Buffer('Receive:\'123\'OK\r\n*000000,123,0#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETACKSTATE'); + expect(data.enable).to.be.false; }); - describe('TZ-COMMAND SETROAMING', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'121\'OK\r\n*000000,121,0,30,210#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETROAMING'); - expect(data.enable).to.be.false; - expect(data.interval).to.eql(30); - expect(data.network).to.eql('210'); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETCALLFILTER data parsed', () => { + const raw = new Buffer('Receive:\'130\'OK\r\n*000000,130,0,0#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETCALLFILTER'); + expect(data.enable).to.be.false; + expect(data.caller).to.eql('0'); }); - describe('TZ-COMMAND SETACKSTATE', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'123\'OK\r\n*000000,123,0#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETACKSTATE'); - expect(data.enable).to.be.false; - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETSENDTYPE data parsed', () => { + const raw = new Buffer('Receive:\'119\'OK\r\n*000000,119,0#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETSENDTYPE'); + expect(data.mode).to.eql('gprs'); }); - describe('TZ-COMMAND SETCALLFILTER', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'130\'OK\r\n*000000,130,0,0#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETCALLFILTER'); - expect(data.enable).to.be.false; - expect(data.caller).to.eql('0'); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETPICTUREINTERVAL data parsed', () => { + const raw = new Buffer('Receive:\'200\'OK\r\n*000000,200,10,999#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETPICTUREINTERVAL'); + expect(data.interval).to.eql(10); + expect(data.times).to.eql(999); }); - describe('TZ-COMMAND SETSENDTYPE', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'119\'OK\r\n*000000,119,0#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETSENDTYPE'); - expect(data.mode).to.eql('gprs'); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND CLEARBUF data parsed', () => { + const raw = new Buffer('Receive:\'500\'OK\r\n*000000,500#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('CLEARBUF'); }); - describe('TZ-COMMAND SETPICTUREINTERVAL', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'200\'OK\r\n*000000,200,10,999#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETPICTUREINTERVAL'); - expect(data.interval).to.eql(10); - expect(data.times).to.eql(999); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND GETPICTURE data parsed', () => { + const raw = new Buffer('Receive:\'210\'OK\r\n*000000,210#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('GETPICTURE'); }); - describe('TZ-COMMAND CLEARBUF', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'500\'OK\r\n*000000,500#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('CLEARBUF'); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETDATAFLASH data parsed', () => { + const raw = new Buffer('Receive:\'601\'OK\r\n*000000,601,1#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETDATAFLASH'); + expect(data.enable).to.be.true; }); - describe('TZ-COMMAND GETPICTURE', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'210\'OK\r\n*000000,210#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('GETPICTURE'); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETTRACKINGINTERVAL data parsed', () => { + const raw = new Buffer('Receive:\'156\'OK\r\n*000000,156,0,30,30#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETTRACKINGINTERVAL'); + expect(data.enable).to.be.false; + expect(data.intervalOn).to.eql(30); + expect(data.intervalOff).to.eql(30); }); - describe('TZ-COMMAND SETDATAFLASH', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'601\'OK\r\n*000000,601,1#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETDATAFLASH'); - expect(data.enable).to.be.true; - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETSENDODOMETER data parsed', () => { + const raw = new Buffer('Receive:\'151\'OK\r\n*000000,151,0,100#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETSENDODOMETER'); + expect(data.enable).to.be.false; + expect(data.range).to.eql(100); }); - describe('TZ-COMMAND SETTRACKINGINTERVAL', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'156\'OK\r\n*000000,156,0,30,30#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETTRACKINGINTERVAL'); - expect(data.enable).to.be.false; - expect(data.intervalOn).to.eql(30); - expect(data.intervalOff).to.eql(30); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETIMEI data parsed', () => { + const raw = new Buffer('Receive:\'155\'OK\r\n*000000,155,0,000000000000000#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETIMEI'); + expect(data.enable).to.be.false; + expect(data.newImei).to.eql('000000000000000'); }); - describe('TZ-COMMAND SETSENDODOMETER', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'151\'OK\r\n*000000,151,0,100#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETSENDODOMETER'); - expect(data.enable).to.be.false; - expect(data.range).to.eql(100); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETIDLE data parsed', () => { + const raw = new Buffer('Receive:\'404\'OK\r\n*000000,404,0,30#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETIDLE'); + expect(data.enable).to.be.false; + expect(data.interval).to.eql(30); }); - describe('TZ-COMMAND SETIMEI', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'155\'OK\r\n*000000,155,0,000000000000000#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETIMEI'); - expect(data.enable).to.be.false; - expect(data.newImei).to.eql(0); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETINTERVALGPRSSTANDBY data parsed', () => { + const raw = new Buffer('Receive:\'023\'OK\r\n*000000,023,0,30#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETINTERVALGPRSSTANDBY'); + expect(data.enable).to.be.false; + expect(data.interval).to.eql(30); }); - describe('TZ-COMMAND SETIDLE', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'404\'OK\r\n*000000,404,0,30#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETIDLE'); - expect(data.enable).to.be.false; - expect(data.interval).to.eql(30); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETIOPICTURE data parsed', () => { + const raw = new Buffer('Receive:\'201\'OK\r\n*000000,201,3,3,5#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETIOPICTURE'); + expect(data.enable).to.be.true; + expect(data.port).to.eql(2); + expect(data.mode).to.eql('both'); + expect(data.times).to.eql(5); }); - describe('TZ-COMMAND SETINTERVALGPRSSTANDBY', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'023\'OK\r\n*000000,023,0,30#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETINTERVALGPRSSTANDBY'); - expect(data.enable).to.be.false; - expect(data.interval).to.eql(30); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-COMMAND SETPICTUREPACKET data parsed', () => { + const raw = new Buffer('Receive:\'202\'OK\r\n*000000,202,6#'); + const data = tz.parse(raw); + expect(data.password).to.eql('000000'); + expect(data.device).to.eql('TZ-COMMAND'); + expect(data.command).to.eql('SETPICTUREPACKET'); + expect(data.number).to.eql(6); }); - describe('TZ-COMMAND SETIOPICTURE', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'201\'OK\r\n*000000,201,3,3,5#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETIOPICTURE'); - expect(data.enable).to.be.true; - expect(data.port).to.eql(2); - expect(data.mode).to.eql('both'); - expect(data.times).to.eql(5); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-FIRMWARE data parsed', () => { + const raw = new Buffer('IMEI:869444005480041\r\nVER:TC_AVL05vSST_JOSE10.12\r\nGSMVER:1116B02SIM840WL_MXIC\r\n'); + const data = tz.parse(raw); + expect(data.device).to.eql('TZ-FIRMWARE'); + expect(data.type).to.eql('firmware'); + expect(data.imei).to.eql('869444005480041'); + expect(data.firmware).to.eql('TC_AVL05vSST_JOSE10.12'); + expect(data.gsm).to.eql('1116B02SIM840WL_MXIC'); }); - describe('TZ-COMMAND SETPICTUREPACKET', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:\'202\'OK\r\n*000000,202,6#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.password).to.eql('000000'); - expect(data.type).to.eql('TZ-COMMAND'); - expect(data.command).to.eql('SETPICTUREPACKET'); - expect(data.number).to.eql(6); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-MAP data parsed', () => { + const raw = new Buffer('http://maps.google.com/maps?f=q&hl=en&q=-33.361106,-070.514868&ie=UTF8&z=16&iwloc=addr&om=1'); + const data = tz.parse(raw); + expect(data.device).to.eql('TZ-MAP'); + expect(data.type).to.eql('map_link'); + expect(data.url).to.eql('http://maps.google.com/maps?f=q&hl=en&q=-33.361106,-070.514868&ie=UTF8&z=16&iwloc=addr&om=1'); + expect(data.latitude).to.eql(-33.361106); + expect(data.longitude).to.eql(-70.514868); }); - describe('TZ-ERROR', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('Receive:Set Err\r\n*000000,999,9999#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.type).to.eql('TZ-ERROR'); - expect(data.command).to.eql('Receive:Set Err\r\n*000000,999,9999#'); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-ERROR data parsed', () => { + const raw = new Buffer('Receive:Set Err\r\n*000000,999,9999#'); + const data = tz.parse(raw); + expect(data.device).to.eql('TZ-ERROR'); + expect(data.type).to.eql('error'); + expect(data.command).to.eql('Receive:Set Err\r\n*000000,999,9999#'); }); - describe('TZ-IMAGE', () => { - let data; - let error; - before((done) => { - const raw = new Buffer('$U35977203928389100001071001FFD8FFDB008400100B0C0E0C0A100E0D0E1211101318281A181616183123251D283A333D3C3933383740485C4E404457453738506D51575F626768673E4D71797064785C656763011112121815182F1A1A2F634238426363636363636363636363636363#'); - tzParser.parse(raw).then(result => { - data = result; - done(); - }).catch(err => { - error = err; - done(); - }); - }); - describe('parse', () => { - it('should return the raw data parsed', () => { - expect(data.type).to.eql('TZ-IMAGE'); - expect(data.data).to.eql([{ - imei: 359772039283891, - number: 1, - total: 71, - sequence: 1, - data: 'FFD8FFDB008400100B0C0E0C0A100E0D0E1211101318281A181616183123251D283A333D3C3933383740485C4E404457453738506D51575F626768673E4D71797064785C656763011112121815182F1A1A2F634238426363636363636363636363636363' - }]); - expect(error).to.be.undefined; - }); - }); + + it('should return TZ-IMAGE data parsed', () => { + const raw = new Buffer('$U35977203928389100001071001FFD8FFDB008400100B0C0E0C0A100E0D0E1211101318281A181616183123251D283A333D3C3933383740485C4E404457453738506D51575F626768673E4D71797064785C656763011112121815182F1A1A2F634238426363636363636363636363636363#'); + const data = tz.parse(raw); + expect(data.device).to.eql('TZ-IMAGE'); + expect(data.type).to.eql('image'); + expect(data.imei).to.eql('359772039283891'); + expect(data.number).to.eql(1); + expect(data.total).to.eql(71); + expect(data.data).to.eql([{ + sequence: 1, + data: 'FFD8FFDB008400100B0C0E0C0A100E0D0E1211101318281A181616183123251D283A333D3C3933383740485C4E404457453738506D51575F626768673E4D71797064785C656763011112121815182F1A1A2F634238426363636363636363636363636363' + }]); }); });