-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from SignalK/plugin-providers
Fresh start
- Loading branch information
Showing
6 changed files
with
124 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* | ||
* prototype-server: An implementation of a Signal K server for boats. | ||
* Copyright (C) 2014 Fabian Tollenaar <[email protected]>, | ||
* Teppo Kurki <[email protected]> *et al*. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
exports.init = function(settings, send, _debug) { | ||
var debug = !!_debug; | ||
var spawn = require('child_process').spawn; | ||
|
||
/* SEND IDENTITY ON FORK START */ | ||
send({ | ||
messageType: 'identity', // in order to find out if the message contains actual data or the Provider's identity | ||
payload: { | ||
name: 'execute', // name of Provider | ||
version: '0.0.1', // version of Provider | ||
author: 'Fabian Tollenaar <[email protected]>', // author of Provider | ||
provides: 'Execute any (Signal K producing) command set by user.', // description of what the Provider provides | ||
capabilities: ['*'], // capabilities/tags | ||
protocol: 'Signal K', // protocol of the actual data. Should be signal K | ||
|
||
device: { // device information | ||
protocol: '-', // original protocol | ||
type: 'command', // device type | ||
location: '-', // device location | ||
manufacturer: '-', // device manufacturer | ||
product: '-', // product identifier | ||
serial: '-' // serial number | ||
} | ||
} | ||
}); | ||
|
||
// TODO retrieve command from settings and add a panel to settings to set the command. | ||
|
||
process.nextTick(function() { | ||
var command = spawn('echo', ['{"self":"a34af45a","vessels":{"a34af45a":{"source":{"type":"NMEA0183","label":"signalk/nmea-signalk"},"timestamp":"2014-05-06T15:51:30.241Z","uuid":"a34af45a","navigation":{"courseOverGroundTrue":{"source":{"type":"NMEA0183","sentence":"RMC","device":"nmea-signalk"},"timestamp":"2014-05-03T09:14:11.000Z","value":28.17},"location":{"latitude":52.371901666666666,"longitude":4.90974,"source":{"type":"NMEA0183","sentence":"RMC","device":"nmea-signalk"},"timestamp":"2014-05-03T09:14:11.000Z"},"magneticVariaton":{"source":{"type":"NMEA0183","sentence":"RMC","device":"nmea-signalk"},"timestamp":"2014-05-03T09:14:11.000Z","value":0},"speedOverGround":{"source":{"type":"NMEA0183","sentence":"RMC","device":"nmea-signalk"},"timestamp":"2014-05-03T09:14:11.000Z","value":0.18},"gnss":{"source":{"type":"NMEA0183","sentence":"GGA","device":"nmea-signalk"},"timestamp":"2014-06-06T09:14:00.000Z","quality":1,"satellites":8,"antennaAltitude":1,"horizontalDilution":0,"geoidalSeparation":47,"differentialAge":0,"differentialReference":0},"position":{"source":{"type":"NMEA0183","sentence":"GGA","device":"nmea-signalk"},"timestamp":"2014-06-06T09:14:00.000Z","longitude":52.371903333333336,"latitude":4.909741666666667}}}},"version":"2.0","timestamp":"2014-05-06T15:51:30.123Z","source":{"type":"NMEA0183","label":"signalk/nmea-signalk"}}']); | ||
|
||
command.stdout.on('data', function(data) { | ||
try { | ||
send(JSON.parse(data.toString())); | ||
} catch(err) { | ||
if(debug === true) console.log('[provider-execute] error', err.toString()); | ||
} | ||
}); | ||
|
||
command.stderr.on('data', function(err) { | ||
if(debug === true) console.log('[provider-execute] error', err.toString()); | ||
}); | ||
|
||
command.on('exit', function(code) { | ||
if(debug === true) console.log('[provider-execute] exit', code); | ||
}); | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,47 +19,20 @@ | |
* | ||
*/ | ||
|
||
|
||
if(typeof process.send !== 'function') { | ||
return process.exit(); | ||
} | ||
|
||
var Parser, fs, reader, filestream, parser, mw, colors, counter, Throttle, throttled, last, path, vessel, FILE; | ||
|
||
// FILE = 'gofree-merrimac.log'; | ||
// FILE = 'gps.log'; | ||
FILE = 'plaka.log'; | ||
FILE = 'plaka.log'; | ||
|
||
path = require('path'); | ||
path = require('path'); | ||
vessel = require(path.normalize(__dirname + '/../../settings.json')).vessel; | ||
colors = require('colors'); | ||
fs = require('fs'); | ||
fs = require('fs'); | ||
Parser = require('nmea0183-signalk').Parser; | ||
Throttle = require('stream-throttle').Throttle; | ||
|
||
/* SEND IDENTITY ON FORK START */ | ||
process.send({ | ||
messageType: 'identity', // in order to find out if the message contains actual data or the Provider's identity | ||
payload: { | ||
name: 'filerunner', // name of Provider | ||
version: '0.0.1', // version of Provider | ||
author: 'Fabian Tollenaar <[email protected]>', // author of Provider | ||
provides: 'Loops through a log file of nmea0183 sentences', // description of what the Provider provides | ||
capabilities: ['nmea0183'], // capabilities/tags | ||
protocol: 'Signal K', // protocol of the actual data. Should be signal K | ||
|
||
device: { // device information | ||
protocol: 'nmea0183', // original protocol | ||
type: 'file', // device type | ||
location: './nmea.log', // device location | ||
manufacturer: '-', // device manufacturer | ||
product: '-', // product identifier | ||
serial: '-' // serial number | ||
} | ||
} | ||
}); | ||
|
||
function reader() { | ||
function reader(send) { | ||
filestream = fs.createReadStream(__dirname + '/logs/' + FILE); | ||
|
||
parser = new Parser({ | ||
|
@@ -75,7 +48,7 @@ function reader() { | |
throttled.pipe(parser); | ||
|
||
parser.on('sentence', function(data) { | ||
process.send(data); | ||
send(data); | ||
}); | ||
|
||
filestream.on('end', function() { | ||
|
@@ -85,11 +58,36 @@ function reader() { | |
setTimeout(function() { | ||
// console.log(((Date.now() - counter) / 1000) + "s. elapsed. Restarting reader."); | ||
// counter = Date.now(); | ||
reader(); | ||
reader(send); | ||
}, 200); | ||
}); | ||
} | ||
|
||
reader(); | ||
exports.init = function(settings, send, _debug) { | ||
var debug = !!_debug; | ||
|
||
/* SEND IDENTITY ON FORK START */ | ||
send({ | ||
messageType: 'identity', // in order to find out if the message contains actual data or the Provider's identity | ||
payload: { | ||
name: 'filerunner', // name of Provider | ||
version: '0.0.2', // version of Provider | ||
author: 'Fabian Tollenaar <[email protected]>', // author of Provider | ||
provides: 'Loops through a log file of nmea0183 sentences', // description of what the Provider provides | ||
capabilities: ['nmea0183'], // capabilities/tags | ||
protocol: 'Signal K', // protocol of the actual data. Should be signal K | ||
|
||
device: { // device information | ||
protocol: 'nmea0183', // original protocol | ||
type: 'file', // device type | ||
location: './nmea.log', // device location | ||
manufacturer: '-', // device manufacturer | ||
product: '-', // product identifier | ||
serial: '-' // serial number | ||
} | ||
} | ||
}); | ||
|
||
reader(send); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters