signalk-vessels-to-ais 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +24 -24
- package/README.md +25 -20
- package/index.js +442 -309
- package/package.json +26 -24
package/.eslintrc.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
env: {
|
|
3
|
-
commonjs: true,
|
|
4
|
-
es2021: true,
|
|
5
|
-
node: true,
|
|
6
|
-
browser: true,
|
|
7
|
-
jquery: true,
|
|
8
|
-
},
|
|
9
|
-
extends: [
|
|
10
|
-
'airbnb-base',
|
|
11
|
-
],
|
|
12
|
-
parserOptions: {
|
|
13
|
-
ecmaVersion: 12,
|
|
14
|
-
},
|
|
15
|
-
rules: {
|
|
16
|
-
'linebreak-style': 0,
|
|
17
|
-
'no-console': 0,
|
|
18
|
-
'func-names': 0,
|
|
19
|
-
'prefer-destructuring': 0,
|
|
20
|
-
'one-var-declaration-per-line': 0,
|
|
21
|
-
'one-var': 0,
|
|
22
|
-
'no-plusplus': 0,
|
|
23
|
-
},
|
|
24
|
-
};
|
|
1
|
+
module.exports = {
|
|
2
|
+
env: {
|
|
3
|
+
commonjs: true,
|
|
4
|
+
es2021: true,
|
|
5
|
+
node: true,
|
|
6
|
+
browser: true,
|
|
7
|
+
jquery: true,
|
|
8
|
+
},
|
|
9
|
+
extends: [
|
|
10
|
+
'airbnb-base',
|
|
11
|
+
],
|
|
12
|
+
parserOptions: {
|
|
13
|
+
ecmaVersion: 12,
|
|
14
|
+
},
|
|
15
|
+
rules: {
|
|
16
|
+
'linebreak-style': 0,
|
|
17
|
+
'no-console': 0,
|
|
18
|
+
'func-names': 0,
|
|
19
|
+
'prefer-destructuring': 0,
|
|
20
|
+
'one-var-declaration-per-line': 0,
|
|
21
|
+
'one-var': 0,
|
|
22
|
+
'no-plusplus': 0,
|
|
23
|
+
},
|
|
24
|
+
};
|
package/README.md
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
# signalk-vessels-to-ais
|
|
2
|
-
[](https://badge.fury.io/js/signalk-vessels-to-ais)
|
|
3
|
-
[](https://snyk.io/test/github/KEGustafsson/signalk-vessels-to-ais)
|
|
4
|
-
|
|
5
|
-
SignalK server plugin to convert other vessel data to NMEA0183 AIS format and forward it out to 3rd party applications.
|
|
6
|
-
|
|
7
|
-
User can configure:
|
|
8
|
-
- How often data is sent out
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- v1.
|
|
13
|
-
- v1.1.
|
|
14
|
-
- v1.
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
- v0.0.
|
|
1
|
+
# signalk-vessels-to-ais
|
|
2
|
+
[](https://badge.fury.io/js/signalk-vessels-to-ais)
|
|
3
|
+
[](https://snyk.io/test/github/KEGustafsson/signalk-vessels-to-ais)
|
|
4
|
+
|
|
5
|
+
SignalK server plugin to convert other vessel data to NMEA0183 AIS format and forward it out to 3rd party applications.
|
|
6
|
+
|
|
7
|
+
User can configure:
|
|
8
|
+
- How often data is sent out
|
|
9
|
+
- Own data can be added to AIS sending
|
|
10
|
+
|
|
11
|
+
New:
|
|
12
|
+
- v1.2.0, updated fetch method, no need for NODE_TLS_REJECT_UNAUTHORIZED=0 anymore
|
|
13
|
+
- v1.1.5, updated vessels within selected timeframe are sent out, radius filtering around own vessel and tag-block option added
|
|
14
|
+
- v1.1.4, small fix
|
|
15
|
+
- v1.1.3, add: own vessel data and sending interval modified
|
|
16
|
+
- v1.1.2, fix: http/https url selection and better error info
|
|
17
|
+
- v1.1.1, fix: current status of the plugin updated
|
|
18
|
+
- v1.1.0, fix: numeric value test for text strings of AIS
|
|
19
|
+
- v1.0.0, v1 release
|
|
20
|
+
- v0.0.6, fix: node-fetch issue with self signed cert
|
|
21
|
+
- v0.0.5, fix: callSign default value
|
|
22
|
+
- v0.0.4, fix: beam calc
|
|
23
|
+
- v0.0.3, fix: ais path
|
|
24
|
+
- v0.0.2, fix: data parsing
|
|
25
|
+
- v0.0.1, 1st version
|
package/index.js
CHANGED
|
@@ -1,309 +1,442 @@
|
|
|
1
|
-
/*
|
|
2
|
-
MIT License
|
|
3
|
-
|
|
4
|
-
Copyright (c) 2020 Karl-Erik Gustafsson
|
|
5
|
-
|
|
6
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
in the Software without restriction, including without limitation the rights
|
|
9
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
furnished to do so, subject to the following conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
const fetch =
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
plugin
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
let
|
|
38
|
-
let
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
1
|
+
/*
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2020 Karl-Erik Gustafsson
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
|
|
26
|
+
const https = require('https');
|
|
27
|
+
const AisEncode = require('ggencoder').AisEncode;
|
|
28
|
+
const moment = require('moment');
|
|
29
|
+
const haversine = require('haversine-distance');
|
|
30
|
+
|
|
31
|
+
module.exports = function createPlugin(app) {
|
|
32
|
+
const plugin = {};
|
|
33
|
+
plugin.id = 'signalk-vessels-to-ais';
|
|
34
|
+
plugin.name = 'Other vessels data to AIS NMEA0183';
|
|
35
|
+
plugin.description = 'SignalK server plugin to convert other vessel data to NMEA0183 AIS format and forward it out to 3rd party applications';
|
|
36
|
+
|
|
37
|
+
let positionUpdate = null;
|
|
38
|
+
let distance;
|
|
39
|
+
let sendOwn;
|
|
40
|
+
let url;
|
|
41
|
+
let intervalRun;
|
|
42
|
+
const setStatus = app.setPluginStatus || app.setProviderStatus;
|
|
43
|
+
|
|
44
|
+
let position_update;
|
|
45
|
+
let useTag;
|
|
46
|
+
|
|
47
|
+
const httpsAgent = new https.Agent({
|
|
48
|
+
rejectUnauthorized: false,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
let getParam;
|
|
52
|
+
|
|
53
|
+
plugin.start = function (options, restartPlugin) {
|
|
54
|
+
position_update = options.position_update * 60;
|
|
55
|
+
useTag = options.useTag;
|
|
56
|
+
|
|
57
|
+
positionUpdate = options.position_update;
|
|
58
|
+
distance = options.distance;
|
|
59
|
+
sendOwn = options.sendOwn;
|
|
60
|
+
|
|
61
|
+
let port = options.port || 3000;
|
|
62
|
+
let portSec = options.portSec || 3443;
|
|
63
|
+
|
|
64
|
+
url = 'https://localhost:' + portSec + '/signalk/v1/api/vessels';
|
|
65
|
+
getParam = { method: 'GET', agent: httpsAgent };
|
|
66
|
+
fetch(url, getParam)
|
|
67
|
+
.then((res) => {
|
|
68
|
+
console.log(`${plugin.id}: SSL enabled, using https`);
|
|
69
|
+
if (!res.ok) {
|
|
70
|
+
console.error(`${plugin.id}: SSL enabled, but error accessing server. Check 'Allow Readonly Access' and enable it.`);
|
|
71
|
+
setStatus("Error accessing server. Check 'Allow Readonly Access' and enable it");
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
.catch(() => {
|
|
75
|
+
url = 'http://localhost:' + port + '/signalk/v1/api/vessels';
|
|
76
|
+
getParam = { method: 'GET' };
|
|
77
|
+
fetch(url, getParam)
|
|
78
|
+
.then((res) => {
|
|
79
|
+
console.log(`${plugin.id}: SSL disabled, using http`);
|
|
80
|
+
if (!res.ok) {
|
|
81
|
+
console.error(`${plugin.id}: SSL disabled, but error accessing server. Check 'Allow Readonly Access' and enable it.`);
|
|
82
|
+
setStatus("Error accessing server. Check 'Allow Readonly Access' and enable it");
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
.finally(() => {
|
|
87
|
+
intervalRun = setInterval(readData, (positionUpdate * 60000), getParam);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
app.debug('Plugin started');
|
|
91
|
+
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
//----------------------------------------------------------------------------
|
|
95
|
+
// State Mapping
|
|
96
|
+
|
|
97
|
+
const stateMapping = {
|
|
98
|
+
motoring: 0,
|
|
99
|
+
anchored: 1,
|
|
100
|
+
'not under command': 2,
|
|
101
|
+
'restricted manouverability': 3,
|
|
102
|
+
'constrained by draft': 4,
|
|
103
|
+
moored: 5,
|
|
104
|
+
aground: 6,
|
|
105
|
+
fishing: 7,
|
|
106
|
+
sailing: 8,
|
|
107
|
+
'hazardous material high speed': 9,
|
|
108
|
+
'hazardous material wing in ground': 10,
|
|
109
|
+
'ais-sart': 14,
|
|
110
|
+
default: 15,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
//----------------------------------------------------------------------------
|
|
114
|
+
// Rad to Deg
|
|
115
|
+
function radToDegrees(radians) {
|
|
116
|
+
const pi = Math.PI;
|
|
117
|
+
return ((radians * 180) / pi);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
//----------------------------------------------------------------------------
|
|
121
|
+
// m/s to knots
|
|
122
|
+
function msToKnots(speed) {
|
|
123
|
+
return ((speed * 3.6) / 1.852);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//----------------------------------------------------------------------------
|
|
127
|
+
// nmea out
|
|
128
|
+
|
|
129
|
+
function aisOut(encMsg, aisTime) {
|
|
130
|
+
const enc = new AisEncode(encMsg);
|
|
131
|
+
const sentence = enc.nmea;
|
|
132
|
+
let taggString = '';
|
|
133
|
+
if (useTag) {
|
|
134
|
+
taggString = createTagBlock(aisTime)
|
|
135
|
+
}
|
|
136
|
+
if (sentence && sentence.length > 0) {
|
|
137
|
+
app.debug(taggString+sentence);
|
|
138
|
+
app.emit('nmea0183out', taggString+sentence);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const m_hex = [
|
|
143
|
+
'0',
|
|
144
|
+
'1',
|
|
145
|
+
'2',
|
|
146
|
+
'3',
|
|
147
|
+
'4',
|
|
148
|
+
'5',
|
|
149
|
+
'6',
|
|
150
|
+
'7',
|
|
151
|
+
'8',
|
|
152
|
+
'9',
|
|
153
|
+
'A',
|
|
154
|
+
'B',
|
|
155
|
+
'C',
|
|
156
|
+
'D',
|
|
157
|
+
'E',
|
|
158
|
+
'F'
|
|
159
|
+
]
|
|
160
|
+
|
|
161
|
+
function toHexString (v) {
|
|
162
|
+
let msn = (v >> 4) & 0x0f
|
|
163
|
+
let lsn = (v >> 0) & 0x0f
|
|
164
|
+
return m_hex[msn] + m_hex[lsn]
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function createTagBlock (aisTime) {
|
|
168
|
+
let tagBlock = ''
|
|
169
|
+
tagBlock += 's:SK0001,'
|
|
170
|
+
//tagBlock += 'c:' + aisTime + ','
|
|
171
|
+
tagBlock += 'c:' + Date.now(aisTime) + ','
|
|
172
|
+
tagBlock = tagBlock.slice(0, - 1)
|
|
173
|
+
let tagBlockChecksum = 0
|
|
174
|
+
for (let i = 0; i < tagBlock.length; i++) {
|
|
175
|
+
tagBlockChecksum ^= tagBlock.charCodeAt(i)
|
|
176
|
+
}
|
|
177
|
+
return `\\${tagBlock}*` + toHexString(tagBlockChecksum) + `\\`
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
//----------------------------------------------------------------------------
|
|
181
|
+
// Read and parse AIS data
|
|
182
|
+
|
|
183
|
+
function readData(getParam) {
|
|
184
|
+
let i, mmsi, aisTime, aisDelay, shipName, lat, lon, sog, cog, rot, navStat, hdg, dst, callSign, imo, id, type;
|
|
185
|
+
let draftCur, length, beam, ais, encMsg3, encMsg5, encMsg18, encMsg240, encMsg241, own;
|
|
186
|
+
let ownLat = app.getSelfPath('navigation.position.value.latitude');
|
|
187
|
+
let ownLon = app.getSelfPath('navigation.position.value.longitude');
|
|
188
|
+
fetch(url, getParam)
|
|
189
|
+
.then((res) => res.json())
|
|
190
|
+
.then((json) => {
|
|
191
|
+
const jsonContent = JSON.parse(JSON.stringify(json));
|
|
192
|
+
const numberAIS = Object.keys(jsonContent).length;
|
|
193
|
+
for (i = 0; i < numberAIS; i++) {
|
|
194
|
+
const jsonKey = Object.keys(jsonContent)[i];
|
|
195
|
+
|
|
196
|
+
try {
|
|
197
|
+
aisTime = jsonContent[jsonKey].sensors.ais.class.timestamp;
|
|
198
|
+
if ((parseFloat((moment(new Date(Date.now())).diff(aisTime)/1000).toFixed(3))) < position_update) {
|
|
199
|
+
aisDelay = true;
|
|
200
|
+
} else {
|
|
201
|
+
aisDelay = false;
|
|
202
|
+
}
|
|
203
|
+
} catch (error) {
|
|
204
|
+
if (i === 0) {
|
|
205
|
+
aisTime = new Date(Date.now()).toISOString();
|
|
206
|
+
aisDelay = true;
|
|
207
|
+
} else {
|
|
208
|
+
aisTime = null;
|
|
209
|
+
aisDelay = false;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
try {
|
|
213
|
+
mmsi = jsonContent[jsonKey].mmsi;
|
|
214
|
+
} catch (error) { mmsi = null; }
|
|
215
|
+
try {
|
|
216
|
+
shipName = jsonContent[jsonKey].name;
|
|
217
|
+
} catch (error) { shipName = ''; }
|
|
218
|
+
try {
|
|
219
|
+
lat = jsonContent[jsonKey].navigation.position.value.latitude;
|
|
220
|
+
} catch (error) { lat = null; }
|
|
221
|
+
try {
|
|
222
|
+
lon = jsonContent[jsonKey].navigation.position.value.longitude;
|
|
223
|
+
} catch (error) { lon = null; }
|
|
224
|
+
try {
|
|
225
|
+
sog = msToKnots(jsonContent[jsonKey].navigation.speedOverGround.value);
|
|
226
|
+
} catch (error) { sog = null; }
|
|
227
|
+
try {
|
|
228
|
+
cog = radToDegrees(jsonContent[jsonKey].navigation.courseOverGroundTrue.value);
|
|
229
|
+
} catch (error) { cog = null; }
|
|
230
|
+
try {
|
|
231
|
+
rot = radToDegrees(jsonContent[jsonKey].navigation.rateOfTurn.value);
|
|
232
|
+
} catch (error) { rot = null; }
|
|
233
|
+
try {
|
|
234
|
+
navStat = stateMapping[jsonContent[jsonKey].navigation.state.value];
|
|
235
|
+
} catch (error) { navStat = ''; }
|
|
236
|
+
try {
|
|
237
|
+
hdg = radToDegrees(jsonContent[jsonKey].navigation.headingTrue.value);
|
|
238
|
+
} catch (error) { hdg = null; }
|
|
239
|
+
try {
|
|
240
|
+
dst = jsonContent[jsonKey].navigation.destination.commonName.value;
|
|
241
|
+
} catch (error) { dst = ''; }
|
|
242
|
+
try {
|
|
243
|
+
if (i === 0) {
|
|
244
|
+
callSign = jsonContent[jsonKey].communication.callsignVhf;
|
|
245
|
+
} else {
|
|
246
|
+
callSign = jsonContent[jsonKey].communication.value.callsignVhf;
|
|
247
|
+
}
|
|
248
|
+
} catch (error) { callSign = ''; }
|
|
249
|
+
try {
|
|
250
|
+
imo = (jsonContent[jsonKey].registrations.value.imo).substring(4, 20);
|
|
251
|
+
} catch (error) { imo = null; }
|
|
252
|
+
try {
|
|
253
|
+
id = jsonContent[jsonKey].design.aisShipType.value.id;
|
|
254
|
+
} catch (error) { id = null; }
|
|
255
|
+
try {
|
|
256
|
+
type = jsonContent[jsonKey].design.aisShipType.value.name;
|
|
257
|
+
} catch (error) { type = ''; }
|
|
258
|
+
try {
|
|
259
|
+
draftCur = (jsonContent[jsonKey].design.draft.value.current) / 10;
|
|
260
|
+
} catch (error) { draftCur = null; }
|
|
261
|
+
try {
|
|
262
|
+
length = jsonContent[jsonKey].design.length.value.overall;
|
|
263
|
+
} catch (error) { length = null; }
|
|
264
|
+
try {
|
|
265
|
+
beam = (jsonContent[jsonKey].design.beam.value) / 2;
|
|
266
|
+
} catch (error) { beam = null; }
|
|
267
|
+
try {
|
|
268
|
+
ais = jsonContent[jsonKey].sensors.ais.class.value;
|
|
269
|
+
} catch (error) { ais = null; }
|
|
270
|
+
|
|
271
|
+
if (shipName % 1 === 0) {
|
|
272
|
+
shipName = '';
|
|
273
|
+
}
|
|
274
|
+
if (dst % 1 === 0) {
|
|
275
|
+
dst = '';
|
|
276
|
+
}
|
|
277
|
+
if (callSign % 1 === 0) {
|
|
278
|
+
callSign = '';
|
|
279
|
+
}
|
|
280
|
+
if (type % 1 === 0) {
|
|
281
|
+
type = '';
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (i === 0) {
|
|
285
|
+
own = true;
|
|
286
|
+
if (sendOwn) {
|
|
287
|
+
ais = 'A';
|
|
288
|
+
} else {
|
|
289
|
+
ais = '';
|
|
290
|
+
}
|
|
291
|
+
} else {
|
|
292
|
+
own = false;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const a = { lat: ownLat, lon: ownLon }
|
|
296
|
+
const b = { lat: lat, lon: lon }
|
|
297
|
+
let dist = (haversine(a, b)/1000).toFixed(2);
|
|
298
|
+
|
|
299
|
+
if (dist <= distance) {
|
|
300
|
+
|
|
301
|
+
encMsg3 = {
|
|
302
|
+
own,
|
|
303
|
+
aistype: 3, // class A position report
|
|
304
|
+
repeat: 0,
|
|
305
|
+
mmsi,
|
|
306
|
+
navstatus: navStat,
|
|
307
|
+
sog,
|
|
308
|
+
lon,
|
|
309
|
+
lat,
|
|
310
|
+
cog,
|
|
311
|
+
hdg,
|
|
312
|
+
rot,
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
encMsg5 = {
|
|
316
|
+
own,
|
|
317
|
+
aistype: 5, // class A static
|
|
318
|
+
repeat: 0,
|
|
319
|
+
mmsi,
|
|
320
|
+
imo,
|
|
321
|
+
cargo: id,
|
|
322
|
+
callsign: callSign,
|
|
323
|
+
shipname: shipName,
|
|
324
|
+
draught: draftCur,
|
|
325
|
+
destination: dst,
|
|
326
|
+
dimA: 0,
|
|
327
|
+
dimB: length,
|
|
328
|
+
dimC: beam,
|
|
329
|
+
dimD: beam,
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
encMsg18 = {
|
|
333
|
+
own,
|
|
334
|
+
aistype: 18, // class B position report
|
|
335
|
+
repeat: 0,
|
|
336
|
+
mmsi,
|
|
337
|
+
sog,
|
|
338
|
+
accuracy: 0,
|
|
339
|
+
lon,
|
|
340
|
+
lat,
|
|
341
|
+
cog,
|
|
342
|
+
hdg,
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
encMsg240 = {
|
|
346
|
+
own,
|
|
347
|
+
aistype: 24, // class B static
|
|
348
|
+
repeat: 0,
|
|
349
|
+
part: 0,
|
|
350
|
+
mmsi,
|
|
351
|
+
shipname: shipName,
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
encMsg241 = {
|
|
355
|
+
own,
|
|
356
|
+
aistype: 24, // class B static
|
|
357
|
+
repeat: 0,
|
|
358
|
+
part: 1,
|
|
359
|
+
mmsi,
|
|
360
|
+
cargo: id,
|
|
361
|
+
callsign: callSign,
|
|
362
|
+
dimA: 0,
|
|
363
|
+
dimB: length,
|
|
364
|
+
dimC: beam,
|
|
365
|
+
dimD: beam,
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
if (aisDelay && (ais === 'A' || ais === 'B')) {
|
|
369
|
+
app.debug("Distance range: " + distance + "km, AIS target distance: " + dist + "km" + ", Class " + ais + " Vessel" + ", MMSI:" + mmsi)
|
|
370
|
+
if (ais === 'A') {
|
|
371
|
+
app.debug(`class A, ${i}, time: ${aisTime}`);
|
|
372
|
+
aisOut(encMsg3, aisTime);
|
|
373
|
+
aisOut(encMsg5, aisTime);
|
|
374
|
+
}
|
|
375
|
+
if (ais === 'B') {
|
|
376
|
+
app.debug(`class B, ${i}, time: ${aisTime}`);
|
|
377
|
+
aisOut(encMsg18, aisTime);
|
|
378
|
+
aisOut(encMsg240, aisTime);
|
|
379
|
+
aisOut(encMsg241, aisTime);
|
|
380
|
+
}
|
|
381
|
+
app.debug("--------------------------------------------------------");
|
|
382
|
+
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
const dateobj = new Date(Date.now());
|
|
387
|
+
const date = dateobj.toISOString();
|
|
388
|
+
app.handleMessage(plugin.id, {
|
|
389
|
+
context: `vessels.${app.selfId}`,
|
|
390
|
+
updates: [
|
|
391
|
+
],
|
|
392
|
+
});
|
|
393
|
+
setStatus(`AIS NMEA message send: ${date}`);
|
|
394
|
+
})
|
|
395
|
+
.catch((err) => console.error(err));
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
//----------------------------------------------------------------------------
|
|
399
|
+
|
|
400
|
+
plugin.stop = function stop() {
|
|
401
|
+
clearInterval(intervalRun);
|
|
402
|
+
app.debug('Stopped');
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
plugin.schema = {
|
|
406
|
+
type: 'object',
|
|
407
|
+
properties: {
|
|
408
|
+
position_update: {
|
|
409
|
+
type: 'number',
|
|
410
|
+
default: 1,
|
|
411
|
+
title: 'How often AIS data is sent to NMEA0183 out (in minutes). E.g. 0.5 = 30s, 1 = 1min',
|
|
412
|
+
},
|
|
413
|
+
port: {
|
|
414
|
+
type: 'number',
|
|
415
|
+
title: 'HTTP port',
|
|
416
|
+
default: 3000
|
|
417
|
+
},
|
|
418
|
+
portSec: {
|
|
419
|
+
type: 'number',
|
|
420
|
+
title: 'HTTPS port',
|
|
421
|
+
default: 3443
|
|
422
|
+
},
|
|
423
|
+
sendOwn: {
|
|
424
|
+
type: 'boolean',
|
|
425
|
+
title: 'Send own AIS data, VDO',
|
|
426
|
+
default: true
|
|
427
|
+
},
|
|
428
|
+
useTag: {
|
|
429
|
+
type: 'boolean',
|
|
430
|
+
title: 'Add Tag-block',
|
|
431
|
+
default: false
|
|
432
|
+
},
|
|
433
|
+
distance: {
|
|
434
|
+
type: 'integer',
|
|
435
|
+
default: 100,
|
|
436
|
+
title: 'AIS target within range [km]',
|
|
437
|
+
},
|
|
438
|
+
},
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
return plugin;
|
|
442
|
+
};
|
package/package.json
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "signalk-vessels-to-ais",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "SignalK server plugin to convert other vessel data to NMEA0183 AIS format and forward it out to 3rd party applications",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
"signalk-node-server-plugin"
|
|
11
|
-
],
|
|
12
|
-
"repository": "https://github.com/KEGustafsson/signalk-vessels-to-ais",
|
|
13
|
-
"author": "Karl-Erik Gustafsson",
|
|
14
|
-
"license": "MIT",
|
|
15
|
-
"dependencies": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"eslint
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "signalk-vessels-to-ais",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "SignalK server plugin to convert other vessel data to NMEA0183 AIS format and forward it out to 3rd party applications",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"signalk-node-server-plugin"
|
|
11
|
+
],
|
|
12
|
+
"repository": "https://github.com/KEGustafsson/signalk-vessels-to-ais",
|
|
13
|
+
"author": "Karl-Erik Gustafsson",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"haversine-distance": "^1.2.1",
|
|
17
|
+
"moment": "^2.29.1",
|
|
18
|
+
"node-fetch": "^3.1.1",
|
|
19
|
+
"ggencoder": "^1.0.5"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"eslint": "^7.17.0",
|
|
23
|
+
"eslint-config-airbnb-base": "^14.2.1",
|
|
24
|
+
"eslint-plugin-import": "^2.22.1"
|
|
25
|
+
}
|
|
26
|
+
}
|