Comparing version 0.1.18 to 0.1.19
@@ -15,2 +15,5 @@ /* | ||
* limitations under the License. | ||
* | ||
* This adaptater takes AIS input in AIS/NMEA Binary Format from either GPSd or Socket | ||
* Note is will not accept AIS positioning before target send a static AIS message | ||
*/ | ||
@@ -52,3 +55,4 @@ | ||
function DevAdapter (controller) { | ||
this.uid = "adapter:aisfeed@" + controller.svcopts.hostname + ":" +controller.svcopts.remport; | ||
this.id = controller.svc; | ||
this.uid = "//" + controller.svcopts.adapter + "/" + controller.svc + "@" + controller.svcopts.hostname + ":" +controller.svcopts.remport; | ||
this.info = 'TcpAis'; | ||
@@ -59,4 +63,5 @@ this.control = 'tcpfeed'; // this adapter connect onto a remote server | ||
this.gateway = controller.gateway; | ||
this.Debug (1,"DevAdapter: %s", this.uid); | ||
this.Debug (1,"uid=%s", this.uid); | ||
this.count =0; // stat counter | ||
this.session = {}; // special object to store AIS multipart messages | ||
}; | ||
@@ -103,5 +108,7 @@ | ||
DevAdapter.prototype.ParseLine = function(socket, line) { | ||
var device; | ||
this.Debug (8, "line=[%s]", line); | ||
// send AIS message to parser | ||
var ais= new AisDecode (line); | ||
var ais= new AisDecode (line, this.session); | ||
@@ -125,7 +132,12 @@ // check if message was valid | ||
// if we exist in active client and we're log then update position now | ||
var device = this.gateway.activeClients [ais.mmsi]; | ||
if (device !== undefined && device.logged) { // device has sent its static info | ||
device.ProcessData (data); // update ship position in DB | ||
device = this.gateway.activeClients [ais.mmsi]; | ||
if (device) { // is device is not logged we use a trempry name | ||
device.ProcessData (data); // update ship position in DB | ||
} else { | ||
this.Debug (3, "Ignoring AIS count:%s mmsi:%s type:%s [not logged]", this.count++, ais.mmsi, ais.aistype); | ||
this.Debug (3, "Tempry log for mmsi:%s type:%s", ais.mmsi, ais.aistype); | ||
device = new TcpClient (socket); | ||
this.gateway.activeClients [ais.mmsi] = device; | ||
device.devid = ais.mmsi; | ||
data.cmd= TrackerCmd.GetFrom.TMPLOG; | ||
device.ProcessData (data); // update ship position in DB | ||
} | ||
@@ -138,8 +150,9 @@ break; | ||
// if device is not in active list we force a new object to keep track of it | ||
if (this.gateway.activeClients [ais.mmsi] === undefined) { | ||
var device = new TcpClient (socket); | ||
// if we have shipname update device even is unknown from DB | ||
if (ais.shipname !== undefined) ais.shipname = device.name; | ||
// force authent [due to DB delay we ignore first AIS paquets] | ||
if (!this.gateway.activeClients [ais.mmsi]) { | ||
device = new TcpClient (socket); | ||
this.gateway.activeClients [ais.mmsi] = device; | ||
} else device=this.gateway.activeClients [ais.mmsi]; | ||
if (!device.logged) { // if we have shipname update device even is unknown from DB | ||
if (ais.shipname) device.name = ais.shipname; | ||
var data = | ||
@@ -151,2 +164,6 @@ {devid : ais.mmsi | ||
,call : ais.callsign | ||
,dimA : ais.dimA | ||
,dimB : ais.dimB | ||
,dimC : ais.dimC | ||
,dimD : ais.dimD | ||
}; | ||
@@ -157,4 +174,10 @@ // ask client to process login | ||
break; | ||
case 25: // ping self | ||
if (device !== undefined && device.logged) { // device has sent its static info | ||
data.cmd= TrackerCmd.GetFrom.PING; | ||
device.ProcessData (data); // update ship position in DB | ||
} | ||
break; | ||
default: | ||
this.Debug (4,"Hoops: AIS aistype=%s not supported", ais.aistype) | ||
this.Debug (4,"Hoops: AIS aistype=%s not supported", ais.aistype); | ||
} | ||
@@ -161,0 +184,0 @@ }; |
@@ -27,3 +27,4 @@ /* | ||
function DevAdapter (controller) { | ||
this.uid = "adapterTK103/GPS103//" + controller.svcopts.port;; | ||
this.id = controller.svc; | ||
this.uid = "//" + controller.svcopts.adapter + "/" + controller.svc + ":" + controller.svcopts.port;; | ||
this.control = 'tcpsock'; | ||
@@ -33,3 +34,3 @@ this.info = 'Tk102-Gps103'; | ||
this.controller= controller; | ||
this.Debug (1,"%s", this.uid); | ||
this.Debug (1,"uid=%s", this.uid); | ||
}; | ||
@@ -107,3 +108,4 @@ | ||
lon: ProcessCardinal(args[9], args[10]), | ||
sog: parseInt (args[11] * 1853 / 360)/10, | ||
//sog: parseInt (args[11] * 1853 / 360)/10, // MS/S | ||
sog: parseInt (args[11]*10)/10, // KNTS | ||
cog: args[12], | ||
@@ -125,3 +127,4 @@ alt: -1 | ||
lon: ProcessCardinal(args[9], args[10]), | ||
sog: parseInt (args[11] * 1853 / 360)/10, | ||
//sog: parseInt (args[11] * 1853 / 360)/10, // MS/S | ||
sog: parseInt (args[11]*10)/10, // KNTS | ||
cog: args[12], | ||
@@ -128,0 +131,0 @@ alt: CheckArg(args[13]), |
@@ -45,3 +45,4 @@ /* | ||
function DevAdapter (controller) { | ||
this.uid = "adapter:gtcfree//" + + controller.svcopts.port;; | ||
this.id = controller.svc; | ||
this.uid = "//" + controller.svcopts.adapter + "/" + controller.svc + ":" + controller.svcopts.port;; | ||
this.info = 'GtcFree'; | ||
@@ -52,3 +53,3 @@ this.debug = controller.svcopts.debug; // inherit debug from controller | ||
this.control = 'http'; | ||
this.Debug (1,"%s", this.uid); | ||
this.Debug (1,"uid=%s", this.uid); | ||
}; | ||
@@ -78,3 +79,3 @@ | ||
response.writeHeader(400, {"Content-Type": "text/plain"}); | ||
response.write('ERR: This is not a valid CellTracGTS request'); | ||
response.write('CellTracGTS: Invalid Input Format'); | ||
response.end(); | ||
@@ -101,2 +102,3 @@ return; | ||
// force authent [due to DB delay we may refuse first NMEA packets] | ||
device.LoginDev ({devid: devid}); | ||
@@ -114,10 +116,13 @@ } | ||
// if parsing abort then force line as invalid | ||
var data = new NmeaDecode(query.gprmc); | ||
if (data.valid) { | ||
this.Debug (7,"--> NMEA Lat:%s Lon:%s Sog:%d Cog:%d Alt:%d Date:%s" | ||
, data.lat, data.lon, data.sog, data.cog, data.alt, data.date); | ||
data.cmd = TrackerCmd.GetFrom.TRACK; | ||
device.ProcessData (data); | ||
} | ||
result = "OK"; | ||
if (query.gprmc) { | ||
var data = new NmeaDecode(query.gprmc); | ||
if (data.valid) { | ||
this.Debug (7,"--> NMEA Lat:%s Lon:%s Sog:%d Cog:%d Alt:%d Date:%s" | ||
, data.lat, data.lon, data.sog, data.cog, data.alt, data.date); | ||
data.cmd = TrackerCmd.GetFrom.TRACK; | ||
device.ProcessData (data); | ||
} | ||
result = "OK"; | ||
} else result = "FX"; | ||
response.writeHeader(200, {"Content-Type": "text/plain"}); | ||
@@ -124,0 +129,0 @@ response.write(result); |
@@ -55,5 +55,4 @@ /* | ||
function DevAdapter (controller) { | ||
this.uid = "adapter:httpdajax//" + controller.svcopts.port; | ||
this.id = controller.svc; | ||
this.uid = "//" + controller.svcopts.adapter + "/" + controller.svc + ":" + controller.svcopts.port;; | ||
this.info = 'HttpdAjax'; | ||
@@ -60,0 +59,0 @@ this.debug = controller.svcopts.debug; // inherit debug from controller |
@@ -36,3 +36,4 @@ /* | ||
function DevAdapter (controller) { | ||
this.uid = "adapter:" + "json2ais//" + controller.svcopts.port; | ||
this.id = controller.svc; | ||
this.uid = "//" + controller.svcopts.adapter + "/" + controller.svc + ":" + controller.svcopts.port;; | ||
this.info = 'json2ais'; | ||
@@ -39,0 +40,0 @@ this.control = 'tcpsock'; // this wait for AIS clients to connect via TCP |
@@ -46,3 +46,4 @@ /* | ||
function DevAdapter (controller) { | ||
this.uid = "adapter:nmeafeed@" + controller.svcopts.remport; | ||
this.id = controller.svc; | ||
this.uid = "//" + controller.svcopts.adapter + "/" + controller.svc + "@" + controller.svcopts.hostname + ":" +controller.svcopts.remport; | ||
this.info = 'nmeatcp'; | ||
@@ -61,3 +62,3 @@ this.control = 'tcpfeed'; // this adapter connect onto a remote server | ||
registermmsi [this.mmsi] = true; | ||
this.Debug (1,"%s mmsi=%s", this.uid,this.mmsi); | ||
this.Debug (1,"uid=%s mmsi=%s", this.uid,this.mmsi); | ||
@@ -79,2 +80,3 @@ }; | ||
,devid : this.mmsi | ||
,name : this.id | ||
,model:'gprmc' | ||
@@ -81,0 +83,0 @@ ,call :'none' |
@@ -52,3 +52,4 @@ /* | ||
function DevAdapter (controller) { | ||
this.uid = "adapter:osmtracker//" + + controller.svcopts.port;; | ||
this.id = controller.svc; | ||
this.uid = "//" + controller.svcopts.adapter + "/" + controller.svc + ":" + controller.svcopts.port;; | ||
this.info = 'OSMtracker'; | ||
@@ -59,3 +60,3 @@ this.debug = controller.svcopts.debug; // inherit debug from controller | ||
this.control = 'http'; | ||
this.Debug (1,"%s", this.uid); | ||
this.Debug (1,"uid=%s", this.uid); | ||
}; | ||
@@ -81,3 +82,3 @@ | ||
response.writeHeader(400, {"Content-Type": "text/plain"}); | ||
response.write('ERR: Invalid IMEI in Http Request'); | ||
response.write('OSM/Traccar: Invalid Input Format'); | ||
response.end(); | ||
@@ -84,0 +85,0 @@ return; |
@@ -33,4 +33,4 @@ /* | ||
function DevAdapter (controller) { | ||
this.uid = "adapter:restapi//" + controller.svcopts.port; | ||
this.id = controller.svc; | ||
this.uid = "//" + controller.svcopts.adapter + "/" + controller.svc + ":" + controller.svcopts.port;; | ||
this.info = 'Restapi'; | ||
@@ -37,0 +37,0 @@ this.debug = controller.svcopts.debug; // inherit debug from controller |
@@ -99,3 +99,3 @@ /* | ||
,["BASE SEAR TXT TXT EOL" ,"this.cmd='DBSEAR' ; this.devid=$3; this.limit=parseInt($4); return (this);"] | ||
,["BASE CREA TXT TXT TXT ARGS EOL","this.cmd='DBCREA' ; this.devid=$3; this.callsign=$4; this.model=$5;return (this);"] | ||
,["BASE CREA TXT TXT TXT TXT TXT TXT TXT ARGS EOL","this.cmd='DBCREA' ; this.devid=$3; this.mmsi=$4; this.callsign=$5; this.cargo=$6; this.length=$7; this.width=$8; this.model=$9; return (this);"] | ||
@@ -118,7 +118,8 @@ ,["EVTS STAR EOL" ,"this.cmd='EVTSTART' ; return (this);"] | ||
this.uid = "adapter:telnet//" + controller.svcopts.port; | ||
this.id = controller.svc; | ||
this.uid = "//" + controller.svcopts.adapter + "/" + controller.svc + ":" + controller.svcopts.port;; | ||
this.control = "tcpsock"; | ||
this.info = "Telnet"; | ||
this.debug = controller.svcopts.debug; // inherit debug from controller | ||
this.Debug (1,"%s", this.uid); | ||
this.Debug (1,"uid=%s", this.uid); | ||
this.controller= controller; // keep a link to device controller and TCP socket | ||
@@ -249,3 +250,3 @@ this.parser = new Jison(grammar); | ||
socket.write ("> db init [if not exist create table in database]\n"); | ||
socket.write ("> db create xxxx 00112233 xxmodel abcd [create devices in database devid=xxx 0112233=calling-number xxmodel=model-name abcd=device-name]\n"); | ||
socket.write ("> db create devid mmsi callsign cargo length/cm width/cm model name....name \n"); | ||
socket.write ("> db remove xxxx [delete devices in database devid=xxx]\n"); | ||
@@ -398,3 +399,7 @@ socket.write ("> db search xxxx [search last devices dev.stampitions in database devid=xxx]\n"); | ||
,model : data.model | ||
} | ||
,mmsi : data.mmsi | ||
,cargo : data.cargo | ||
,length : data.length | ||
,width : data.width | ||
}; | ||
@@ -463,3 +468,3 @@ for (var slot in cmdcreate) { | ||
,"DBinit " : "db init" | ||
,"DBCreate " : "db create 123456 My Friendly Name" | ||
,"DBCreate " : "db create devid mmsi callsign length width My Friendly Name" | ||
,"DBRemove " : "db remove 123456" | ||
@@ -466,0 +471,0 @@ ,"DBSearch1 " : "db search 123456" |
@@ -44,3 +44,3 @@ /* | ||
,devid: device.devid | ||
,src : adapter.src | ||
,src : adapter.src + ' ' + device.adapter.id | ||
,model: device.type | ||
@@ -52,5 +52,21 @@ ,name : device.name | ||
}; | ||
function EventDevTmp (device){ | ||
device.websock=0; // special counter to repost full device every 20 positions | ||
adapter.Debug (5, "EventDevAuth devid=%s name=%s", device.devid, device.name); | ||
var msg = | ||
{type : 0 | ||
,devid: device.devid | ||
,src : adapter.src + ' ' + device.adapter.id | ||
,lat : device.stamp.lat | ||
,lon : device.stamp.lon | ||
,sog : device.stamp.sog | ||
,cog : device.stamp.cog | ||
}; | ||
adapter.BroadcastJson (msg); | ||
}; | ||
// Events successful process by tracker adapter | ||
function EventDevPos (device){ | ||
adapter.Debug (6, "EventDevPos devid=%s name=%s", device.devid, device.name); | ||
@@ -63,3 +79,3 @@ // force push of full device info every 20 positions update | ||
,devid: device.devid | ||
,src : adapter.src | ||
,src : adapter.src + ' ' +device.adapter.id | ||
,lat : device.stamp.lat | ||
@@ -73,6 +89,17 @@ ,lon : device.stamp.lon | ||
// Events successful process by tracker adapter | ||
function EventDevPing (device){ | ||
adapter.Debug (7, "EventDevPing devid=%s name=%s", device.devid, device.name); | ||
var msg = | ||
{type : 3 | ||
,devid: device.devid | ||
}; | ||
adapter.BroadcastJson (msg); | ||
}; | ||
// Events on action refused by tracker adapter | ||
function EventDevQuit (device){ | ||
var msg= | ||
{type: 3 | ||
{type: 4 | ||
,devid: device.devid | ||
@@ -83,4 +110,6 @@ }; | ||
backend.event.on("dev-tmp" ,EventDevTmp); | ||
backend.event.on("dev-auth",EventDevAuth); | ||
backend.event.on("dev-pos" ,EventDevPos); | ||
backend.event.on("dev-ign" ,EventDevPing); | ||
backend.event.on("dev-quit",EventDevQuit); | ||
@@ -91,11 +120,13 @@ }; | ||
function DevAdapter (controller) { | ||
this.uid = "adapter:" + "websock//" + controller.svcopts.port; | ||
this.id = controller.svc; | ||
this.uid = "//" + controller.svcopts.adapter + "/" + controller.svc + ":" + controller.svcopts.port;; | ||
this.id = controller.svcopts.adapter; | ||
this.info = 'websock'; | ||
this.control = 'websock'; // this wait for clients to connect via websock | ||
this.debug = controller.svcopts.debug; // inherit debug from controller | ||
this.src = controller.svcopts.src || controller.svcopts.port; // websock serial id for HTML clients | ||
this.src = controller.svcopts.src || controller.svcopts.port; // websock serial id for HTML clients | ||
this.controller = controller; // keep a link to device controller and TCP socket | ||
this.clients = []; // array to keep track of client | ||
this.count = 0; // index for incomming client | ||
this.Debug (1,"%s", this.uid); | ||
this.Debug (1,"uid=%s", this.uid); | ||
@@ -156,3 +187,3 @@ HookBackendEvent(this, controller.gateway.backend); | ||
{type: 1 //auth witout position | ||
,src : this.src | ||
,src : this.src + ' ' + device.adapter.id | ||
,devid: device.devid | ||
@@ -166,3 +197,3 @@ ,model: device.type | ||
{type: 0 //auth with position | ||
,src : this.src | ||
,src : this.src + ' ' + device.adapter.id | ||
,devid: device.devid | ||
@@ -187,3 +218,3 @@ ,model: device.type | ||
DevAdapter.prototype.ClientQuit = function (socket) { | ||
this.Debug (4, 'Quit websock client: %s', this.clients[sock.id].uid); | ||
this.Debug (4, 'Quit websock client: %s', this.clients[socket.id].uid); | ||
delete this.clients[socket.id]; | ||
@@ -190,0 +221,0 @@ }; |
@@ -106,15 +106,10 @@ /* | ||
BackendStorage.prototype.DummyName = function (devid) { | ||
var devname = devid.toString(); | ||
return devname.substring(devname.length-5); | ||
BackendStorage.prototype.TempryLoggin = function (device) { | ||
this.Debug(5, "TempryLogin Device:%s", device.uid); | ||
this.event.emit("dev-tmp", device); | ||
}; | ||
BackendStorage.prototype.LoginDev = function (device) { | ||
this.Debug (4,"Authentication accepted for device=%s", device.uid); | ||
var emeifix = this.DummyName (device.devid); | ||
this.Debug (1,"Authentication accepted for device=%s name=%s", device.uid, device.name); | ||
device.logged = true; | ||
device.callsign = "FX-" + emeifix; | ||
device.model = device.devid; | ||
device.name = "Droid-" + emeifix; | ||
@@ -144,2 +139,7 @@ // Create Ram storage array for tracking this.storesize positions | ||
BackendStorage.prototype.IgnorePosDev = function (device) { | ||
this.Debug(5, "IgnorePos Device:%s", device.uid); | ||
this.event.emit("dev-ign", device); | ||
}; | ||
BackendStorage.prototype.UpdatePosDev = function (device) { | ||
@@ -146,0 +146,0 @@ this.Debug (4,"UpdateDev device:%s", device.uid); |
@@ -180,2 +180,12 @@ /* | ||
BackendStorage.prototype.TempryLoggin = function (device) { | ||
this.Debug(5, "TempryLogin Device:%s", device.uid); | ||
this.event.emit("dev-tmp", device); | ||
}; | ||
BackendStorage.prototype.IgnorePosDev = function (device) { | ||
this.Debug(6, "IgnoreDev Device:%s", device.uid); | ||
this.event.emit("dev-ign", device); | ||
}; | ||
// If Elapsed Moved cannot be retreived from device session, we compute it from DB | ||
@@ -182,0 +192,0 @@ BackendStorage.prototype.FixeMovedElapsed = function (device, data, rowid) { |
@@ -157,4 +157,14 @@ /* | ||
BackendStorage.prototype.TempryLoggin = function (device) { | ||
this.Debug(6, "TempryLogin Device:%s", device.uid); | ||
this.event.emit("dev-tmp", device); | ||
}; | ||
BackendStorage.prototype.IgnorePosDev = function (device) { | ||
this.Debug(6, "IgnoreDev Device:%s", device.uid); | ||
this.event.emit("dev-ign", device); | ||
}; | ||
// Query are done asynchronously and function will return before result is known | ||
BackendStorage.prototype.UpdatePosDev = function (device, data) { | ||
BackendStorage.prototype.UpdatePosDev = function (device) { | ||
var self= this; | ||
@@ -165,3 +175,3 @@ | ||
function ResponseCB (err, response) { | ||
if (err != null) { | ||
if (err !== null) { | ||
self.Debug(0, 'Hoops MongoDB device=%s error=%j', device.devid, err); | ||
@@ -178,7 +188,7 @@ return; | ||
// launch insertion of new position asynchronously | ||
device.mogotrack.insert (data, {w:1}, ResponseCB); | ||
device.mogotrack.insert (device.stamp, {w:1}, ResponseCB); | ||
}; | ||
// Query are done asynchronously and function will return before result is known | ||
BackendStorage.prototype.UpdateObdDev = function (device, data) { | ||
BackendStorage.prototype.UpdateObdDev = function (device) { | ||
var self= this; | ||
@@ -201,6 +211,6 @@ | ||
// launch insertion of new position asynchronously | ||
device.mogoobd.insert (data, {w:1}, ResponseCB); | ||
device.mogoobd.insert (device.stamp, {w:1}, ResponseCB); | ||
}; | ||
// Query are done asynchronously and function will return before result is known | ||
BackendStorage.prototype.UpdateAlarmDev = function (device, data) { | ||
BackendStorage.prototype.UpdateAlarmDev = function (device) { | ||
var self= this; | ||
@@ -223,3 +233,3 @@ | ||
// launch insertion of new position asynchronously | ||
device.mogoalarm.insert (data, {w:1}, ResponseCB); | ||
device.mogoalarm.insert (device.stamp, {w:1}, ResponseCB); | ||
}; | ||
@@ -234,3 +244,3 @@ | ||
if (err) { | ||
device.Debug(0, "MongoDB Find Err=%s", err); | ||
self.Debug(0, "MongoDB Find Err=%s", err); | ||
return; | ||
@@ -237,0 +247,0 @@ } |
@@ -94,2 +94,6 @@ /* | ||
+ 'callsign CHAR(20) NOT NULL,' | ||
+ 'mmsi CHAR(20) NOT NULL,' | ||
+ 'length SMALLINT NOT NULL,' | ||
+ 'width SMALLINT NOT NULL,' | ||
+ 'cargo SMALLINT NOT NULL,' | ||
+ 'model CHAR(20) NOT NULL,' | ||
@@ -110,2 +114,3 @@ + 'track CHAR(20) NOT NULL,' | ||
if (err) { | ||
gateway.debug (0,"MySQL ERROR","CreateTable", table, err); | ||
gateway.event.emit ("notice", "MySQL ERROR","CreateTable",table ,err); | ||
@@ -142,19 +147,19 @@ } | ||
,odb: 'CREATE TABLE IF NOT EXISTS O_' + devid + ' (' | ||
+ 'id INT NOT NULL AUTO_INCREMENT,' | ||
+ 'trip INT,' | ||
+ 'rfuel INT,' | ||
+ 'afuel FLOAT,' | ||
+ 'dtime INT,' | ||
+ 'speed INT,' | ||
+ 'pload FLOAT,' | ||
+ 'temp INT,' | ||
+ 'atp FLOAT,' | ||
+ 'rpm INT,' | ||
+ 'bat FLOAT,' | ||
+ 'diag INT,' | ||
+ 'gpsdate DATETIME,' | ||
+ 'acquired_at BIGINT,' | ||
+ 'PRIMARY KEY (id )' | ||
+ ') DEFAULT CHARSET=utf8;' | ||
// ,odb: 'CREATE TABLE IF NOT EXISTS O_' + devid + ' (' | ||
// + 'id INT NOT NULL AUTO_INCREMENT,' | ||
// + 'trip INT,' | ||
// + 'rfuel INT,' | ||
// + 'afuel FLOAT,' | ||
// + 'dtime INT,' | ||
// + 'speed INT,' | ||
// + 'pload FLOAT,' | ||
// + 'temp INT,' | ||
// + 'atp FLOAT,' | ||
// + 'rpm INT,' | ||
// + 'bat FLOAT,' | ||
// + 'diag INT,' | ||
// + 'gpsdate DATETIME,' | ||
// + 'acquired_at BIGINT,' | ||
// + 'PRIMARY KEY (id )' | ||
// + ') DEFAULT CHARSET=utf8;' | ||
@@ -179,2 +184,6 @@ }; | ||
,model : data.model | ||
,mmsi : data.mmsi | ||
,cargo : data.cargo | ||
,length : data.length | ||
,width : data.width | ||
,track : 'T_' + devid | ||
@@ -250,3 +259,9 @@ ,obd : 'O_' + devid | ||
device.name = result.devname; // friendly name extracted from database | ||
device.mmsi = result.mmsi; | ||
device.callsign= result.callsign; | ||
device.cargo = result.cargo; | ||
device.dimA = 0; | ||
device.dimB = result.length/100; | ||
device.dimC = 0; | ||
device.dimD = result.width/100; | ||
device.model = result.model; | ||
@@ -276,5 +291,15 @@ device.sqlid = result.id; // this is MySQL unique ID and not device's DEVID | ||
BackendStorage.prototype.TempryLoggin = function (device) { | ||
this.Debug(6, "TempryLogin Device:%s", device.uid); | ||
this.event.emit("dev-tmp", device); | ||
}; | ||
BackendStorage.prototype.IgnorePosDev = function (device) { | ||
this.Debug(6, "IgnorePosDev Device:%s", device.uid); | ||
this.event.emit("dev-ign", device); | ||
}; | ||
// Query are done asynchronously and function will return before result is knowned | ||
BackendStorage.prototype.UpdatePosDev = function (device, data) { | ||
BackendStorage.prototype.UpdatePosDev = function (device) { | ||
var self=this; | ||
@@ -287,3 +312,3 @@ this.Debug (6,"Updating Track MySQL devid=%s", device.devid); | ||
// launch insertion of new position asynchronously | ||
var insertQuery = this.base.query(queryString, data); | ||
var insertQuery = this.base.query(queryString, device.stamp); | ||
@@ -297,3 +322,3 @@ insertQuery.on("error", function(err) { | ||
BackendStorage.prototype.UpdateObdDev = function (device, data) { | ||
BackendStorage.prototype.UpdateObdDev = function (device) { | ||
var self=this; | ||
@@ -306,3 +331,3 @@ this.Debug (6,"Updating OBD MySQL devid=%s", device.devid); | ||
// launch insertion of new position asynchronously | ||
var insertQuery = this.base.query(queryString, data); | ||
var insertQuery = this.base.query(queryString, device.stamp); | ||
@@ -314,3 +339,3 @@ insertQuery.on("error", function(err) { | ||
BackendStorage.prototype.UpdateAlarmDev = function (device, data) { | ||
BackendStorage.prototype.UpdateAlarmDev = function (device) { | ||
var self=this; | ||
@@ -323,3 +348,3 @@ this.Debug (6,"Updating Alarm MySQL devid=%s", device.devid); | ||
// launch insertion of new position asynchronously | ||
var insertQuery = this.base.query(queryString, data); | ||
var insertQuery = this.base.query(queryString, device.stamp); | ||
@@ -326,0 +351,0 @@ insertQuery.on("error", function(err) { |
@@ -47,3 +47,3 @@ /* | ||
this.adapter = adapter; | ||
this.adapter = adapter; | ||
this.gateway = adapter.gateway; | ||
@@ -58,2 +58,5 @@ this.controller = adapter.controller; | ||
this.errorcount = 0; // number of ignore messages | ||
this.uid = "httpclient://" + this.adapter.info + ":" + this.adapter.id; | ||
}; | ||
@@ -81,2 +84,8 @@ | ||
GpsdHttpClient.prototype.DummyName = function (devid) { | ||
var devname = devid.toString(); | ||
return devname.substring(devname.length-8); | ||
}; | ||
GpsdHttpClient.prototype.LoginDev = function(data) { | ||
@@ -96,2 +105,9 @@ // make code simpler to read | ||
gateway.activeClients [this.devid] = this; | ||
//Propose a fake name in case nothing exist | ||
var emeifix = this.DummyName (this.devid); | ||
this.callsign = "FX-" + emeifix; | ||
this.model = this.devid; | ||
if (!data.name) this.name = this.adapter.id + "-" + emeifix; | ||
else this.name = data.name; | ||
@@ -172,5 +188,6 @@ // ask backend to authenticate device and eventfully to change logged state to true | ||
this.stamp = new PositionObj(data); | ||
gateway.backend.UpdatePosDev (this, this.stamp); | ||
gateway.backend.UpdatePosDev (this); | ||
} else { | ||
this.Debug(6,"%s Dev=%s ignored moved %dm<%dm ?", this.count, this.devid, moved, this.controller.svcopts.mindist); | ||
this.gateway.backend.IgnorePosDev (this); | ||
} | ||
@@ -177,0 +194,0 @@ break; |
@@ -76,5 +76,5 @@ /* | ||
if (socket.remoteAddress !== undefined) { | ||
this.uid= "sockclient//" + this.adapter.info + "/remote:" + socket.remoteAddress +":" + socket.remotePort; | ||
this.uid= "tcpclient//" + this.adapter.info + "/remote:" + socket.remoteAddress +":" + socket.remotePort; | ||
} else { | ||
this.uid = "tcpclient://" + this.adapter.info + ":" + socket.port; | ||
this.uid= "tcpclient://" + this.adapter.info + ":" + socket.port; | ||
} | ||
@@ -119,2 +119,3 @@ }; | ||
this.call = data.call; | ||
this.name = data.name; | ||
@@ -136,22 +137,32 @@ //Update/Create device socket store by uid at this.gateway level | ||
// if not logged exit now except for login | ||
if (!this.logged && data.cmd !== TrackerCmd.GetFrom.LOGIN) { | ||
this.Debug (3,"tracker update not logged DEVID=%s", this.devid); | ||
return (-1); | ||
} | ||
// update lastshow for cleanup cron | ||
this.lastshow= new Date().getTime(); | ||
this.count ++; | ||
// if not logged exit now except for login | ||
if (!this.logged) { | ||
switch (data.cmd) { | ||
// This device is not register inside TcpClient Object | ||
case TrackerCmd.GetFrom.LOGIN: | ||
this.LoginDev (data); | ||
break; | ||
case TrackerCmd.GetFrom.TMPLOG: | ||
data.acquired_at = new Date().getTime(); | ||
this.stamp = new PositionObj(data); | ||
this.gateway.backend.TempryLoggin (this); | ||
break; | ||
default: | ||
this.Debug (3,"tracker update TempryLoggin DEVID=%s", this.devid); | ||
return (-1); | ||
} | ||
return; | ||
} | ||
// process login in DB & active client list | ||
// process login in DB & active client list | ||
switch (data.cmd) { | ||
// This device is not register inside TcpClient Object | ||
case TrackerCmd.GetFrom.LOGIN: { | ||
this.LoginDev (data); | ||
break; | ||
}; | ||
// Device keep alive service | ||
case TrackerCmd.GetFrom.PING: | ||
this.gateway.backend.IgnorePosDev (this); | ||
break; | ||
@@ -184,5 +195,6 @@ | ||
this.stamp = new PositionObj(data); | ||
this.gateway.backend.UpdateAlarmDev (this, new PositionObj (data)); | ||
this.gateway.backend.UpdateAlarmDev (this); | ||
break; | ||
// Standard tracking information | ||
@@ -227,6 +239,7 @@ case TrackerCmd.GetFrom.TRACK: | ||
this.stamp = new PositionObj(data); | ||
this.gateway.backend.UpdatePosDev (this, this.stamp); | ||
this.gateway.backend.UpdatePosDev (this); | ||
} else { | ||
this.Debug (6, "DevId=%s [%s] Update Ignored moved:%dm/%d speed:%dms/%d" | ||
this.gateway.backend.IgnorePosDev (this); | ||
this.Debug (5, "DevId=%s [%s] Update Ignored moved:%dm/%d speed:%dms/%d" | ||
, this.devid, this.name, moved, this.controller.svcopts.mindist, speedms, this.controller.svcopts.maxspeedms); | ||
@@ -233,0 +246,0 @@ } |
@@ -25,2 +25,3 @@ /* | ||
, OBD : 3 | ||
, TMPLOG : 4 | ||
@@ -27,0 +28,0 @@ , HELPME : 5 // help me,1409050559,1234,F,215931.000,A,4737.1058,N,00245.6524,W,0.00,0;" |
@@ -58,3 +58,3 @@ /* | ||
this.adapter.ClientQuit(socket); | ||
socket.end(); | ||
try {socket.destroy();} catch(e){}; | ||
}); | ||
@@ -64,3 +64,3 @@ | ||
socket.on('end', function () { | ||
socket.controller.Debug(4, "SockClient Quit devid=%s uid=%s", socket.device.devid, socket.device.uid); | ||
socket.controller.Debug(4, "SockClient Quit devid=%s uid=%s", socket.device.devid, socket.device.uid); | ||
this.adapter.ClientQuit(socket); | ||
@@ -125,3 +125,3 @@ }); | ||
var svcopts = this.svcopts; // make objec info visible inside timer handler | ||
var controller = this.controller; | ||
var controller= this.controller; | ||
var gateway = this.controller.gateway; | ||
@@ -128,0 +128,0 @@ var svc = this.controller.svc; |
@@ -21,5 +21,2 @@ /* | ||
var util = require("util"); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var async = require("async"); | ||
@@ -41,14 +38,16 @@ var EventEmitter = require("events").EventEmitter; | ||
// let's call back ourself after inactivity*1000/4 | ||
gateway.Debug (5, "SetCrontab inactivity=%d", inactivity); | ||
setTimeout (function(){SetCrontab (gateway, inactivity);}, inactivity*250); | ||
// let compute inactivity timeout limit | ||
var timeout = new Date ().getTime - (inactivity *1000); | ||
var timeout = new Date().getTime() - (inactivity *1000); | ||
for (var device in gateway.activeClients) { | ||
for (var devid in gateway.activeClients) { | ||
var device = gateway.activeClients[devid]; | ||
if (device.lastshow < timeout) { | ||
gateway.Debug (6, "Removed ActiveDev Id=%s uid=%s", device.devid, device.uid); | ||
delete gateway.activeClients [device]; | ||
gateway.Debug (1, "Removed ActiveDev Id=%s uid=%s", device.devid, device.uid); | ||
delete gateway.activeClients [devid]; | ||
} | ||
} | ||
}; | ||
@@ -189,3 +188,3 @@ | ||
console.log ("\nGateway Start: " + opts.name ); | ||
this.Debug (0, "Gateway Start: %s ", opts.name ); | ||
@@ -204,3 +203,3 @@ // Create databaseObj and attach it to Gateway | ||
if (this.backend.error) { | ||
this.Debug (0, "Fail conecting dbBackend: %s", this.backend.info); | ||
this.Debug (0, "Fail connecting dbBackend: %s", this.backend.info); | ||
console.log ("Gateway aborted"); | ||
@@ -214,3 +213,3 @@ process.exit(-1); | ||
// Cron is an even handler executed outside of current object | ||
SetCrontab (this, opts.inactivity); | ||
SetCrontab (this, parseInt (opts.inactivity) || 3600); | ||
@@ -217,0 +216,0 @@ // For each adapter start a dedicated device server |
{ | ||
"name" : "ggserver", | ||
"description" : "GeoGate is an opensource GPS tracking server framework", | ||
"version" : "0.1.18", | ||
"version" : "0.1.19", | ||
"author" : { | ||
@@ -6,0 +6,0 @@ "name" : "Fulup Ar Foll", |
267553
39
5374
18