signalk-ais-navionics-converter 1.0.3 → 1.0.5

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/README.md CHANGED
@@ -327,4 +327,8 @@ Issues and pull requests are welcome!
327
327
  - Changed to "Embedded Plugin Configuration Forms"
328
328
  ### Version 1.0.3
329
329
  - AIS message types for class A / B separated
330
- - AIS Websocket server added
330
+ - AIS Websocket server added
331
+ ### Version 1.0.4
332
+ - minor bug corrections for unavailable ROT / Heading
333
+ ### Version 1.0.5
334
+ - bug fixing Heading
package/ais-encoder.js CHANGED
@@ -173,17 +173,22 @@ computeAisSogCog(sogValue, sogUnits, cogValue, cogUnits, headingValue, headingUn
173
173
  // --- HEADING ---
174
174
  //
175
175
  // AIS: 511 = not available
176
- let headingInt = 511;
176
+ const HEADING_UNAVALABLE=511
177
+ let headingInt = HEADING_UNAVALABLE;
177
178
 
178
179
  // Heading nur gültig, wenn SOG > 0 UND COG gültig
179
- if (sogKn >= minAlarmSOG && cog10 !== 3600 && Number.isFinite(headingValue)) {
180
-
180
+ if (sogKn >= minAlarmSOG && cog10 !== 3600 && Number.isFinite(headingValue)) {
181
181
  let headingDeg;
182
-
182
+
183
183
  if (headingUnits) {
184
184
  const u = headingUnits.toLowerCase();
185
185
  if (u.includes("rad")) {
186
- headingDeg = headingValue * 180 / Math.PI;
186
+ if (headingValue > 2 * Math.PI) {
187
+ // Wert ist definitiv falsch bwz. bei 8.91863247972741 genau gleich 511 Grad === unavailable
188
+ headingInt = HEADING_UNAVALABLE;
189
+ }else{
190
+ headingDeg = headingValue * 180 / Math.PI;
191
+ }
187
192
  } else if (u.includes("deg")) {
188
193
  headingDeg = headingValue;
189
194
  } else {
@@ -196,11 +201,15 @@ computeAisSogCog(sogValue, sogUnits, cogValue, cogUnits, headingValue, headingUn
196
201
  ? headingValue * 180 / Math.PI
197
202
  : headingValue;
198
203
  }
199
-
200
- headingDeg = ((headingDeg % 360) + 360) % 360;
201
-
202
- headingInt = Math.round(headingDeg);
203
- if (headingInt > 359) headingInt = 359;
204
+ // Filter für ungültige Werte
205
+ if (headingDeg >= 360 && headingDeg <= HEADING_UNAVALABLE) {
206
+ // Wert ist im "ungültig"-Bereich (360-511)
207
+ headingInt = HEADING_UNAVALABLE;
208
+ } else {
209
+ headingDeg = ((headingDeg % 360) + 360) % 360;
210
+ headingInt = Math.round(headingDeg);
211
+ if (headingInt > 359) headingInt = 359;
212
+ }
204
213
  }
205
214
 
206
215
  return { sog10, cog10, headingInt };
@@ -209,6 +218,7 @@ computeAisSogCog(sogValue, sogUnits, cogValue, cogUnits, headingValue, headingUn
209
218
 
210
219
  computeAisRot(rateValue, rateUnits) {
211
220
  // AIS default: ROT not available
221
+ const ROT_UNAVAILABLE = -2.23402144306284;
212
222
  let rot = -128; // standard -128 (unavailable)
213
223
 
214
224
  // Kein Wert → fertig
@@ -226,6 +236,9 @@ computeAisRot(rateValue, rateUnits) {
226
236
 
227
237
  if (u.includes("rad/s")) {
228
238
  // rad/s → deg/min
239
+ if (Math.abs(rate - ROT_UNAVAILABLE) < 1e-6) {
240
+ return rot; // -128
241
+ }
229
242
  rate = rate * (180 / Math.PI) * 60;
230
243
 
231
244
  } else if (u.includes("deg/s")) {
@@ -357,7 +370,7 @@ computeAisRot(rateValue, rateUnits) {
357
370
 
358
371
  return this.bitsToPayload(bits);
359
372
  } catch (error) {
360
- this.app.error('Error creating position report:', error);
373
+ this.app.error('Error creating position report type 1:', error);
361
374
  return null;
362
375
  }
363
376
  }
@@ -499,7 +512,7 @@ computeAisRot(rateValue, rateUnits) {
499
512
 
500
513
  return this.bitsToPayload(bits);
501
514
  } catch (err) {
502
- this.app.error("Error creating type 19:", err);
515
+ this.app.error("Error creating position report type 19", err);
503
516
  return null;
504
517
  }
505
518
  }
package/index.js CHANGED
@@ -334,6 +334,7 @@ module.exports = function(app) {
334
334
  app.debug(`VesselFinder UDP forwarding enabled: ${options.vesselFinderHost}:${options.vesselFinderPort}`);
335
335
  }
336
336
 
337
+
337
338
  function broadcastTCP(message) {
338
339
  tcpClients.forEach(client => {
339
340
  try {
@@ -342,6 +343,8 @@ module.exports = function(app) {
342
343
  app.error(`Error broadcasting to TCP client: ${err}`);
343
344
  }
344
345
  });
346
+ // Broadcast message to SignalK TCP server on port 10110
347
+ // app.emit('nmea0183out', message)
345
348
  }
346
349
 
347
350
  function broadcastWebSocket(message) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "signalk-ais-navionics-converter",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "SignalK plugin to convert AIS data to NMEA 0183 sentences to TCP clients (e.g. Navionics boating app, OpenCpn) and optional to vesselfinder.com",
5
5
  "main": "index.js",
6
6
  "keywords": [