Skip to content

Commit 5a769e0

Browse files
committed
more dac 316 decoding
1 parent 4751c1e commit 5a769e0

File tree

3 files changed

+134
-2
lines changed

3 files changed

+134
-2
lines changed

Library/JSONAIS.cpp

Lines changed: 118 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,36 @@ namespace AIS
318318
U(msg, AIS::KEY_MESSAGE_ID, 90, 6); // Message Identifier (6 bits)
319319

320320
unsigned message_id = msg.getUint(90, 6);
321-
if (message_id == 3) {
321+
if (message_id == 1) {
322+
// Weather Station Message - decode first weather report
323+
// Each report is 144 bits, starting at bit 96
324+
if (msg.getLength() >= 240) { // Ensure we have at least one complete report (96 + 144 = 240 bits)
325+
int start_bit = 96;
326+
327+
// Timetag (20 bits): Month(4), Day(5), Hours(5), Minutes(6)
328+
U(msg, AIS::KEY_MONTH, start_bit, 4, 0); // Month 1-12, 0=not available
329+
U(msg, AIS::KEY_DAY, start_bit + 4, 5, 0); // Day 1-31, 0=not available
330+
U(msg, AIS::KEY_HOUR, start_bit + 9, 5, 24); // Hours 0-23, 24=not available
331+
U(msg, AIS::KEY_MINUTE, start_bit + 14, 6, 60); // Minutes 0-59, 60=not available
332+
333+
// Station ID (42 bits): Seven 6-bit ASCII characters
334+
T(msg, AIS::KEY_STATION_ID, start_bit + 20, 42, text);
335+
336+
// Position (49 bits total)
337+
SL(msg, AIS::KEY_LON, start_bit + 62, 25, 1 / 60000.0f, 0, 10800000); // Longitude in 1/1000 min, 181°=not available
338+
SL(msg, AIS::KEY_LAT, start_bit + 87, 24, 1 / 60000.0f, 0, 5400000); // Latitude in 1/1000 min, 91°=not available
339+
340+
// Weather Station Data (33 bits total)
341+
SL(msg, AIS::KEY_AIR_TEMPERATURE, start_bit + 111, 11, 0.1f, -60.0f, 2047); // Air temperature in °C*10, 2047=not available
342+
U(msg, AIS::KEY_RELATIVE_HUMIDITY, start_bit + 122, 7, 127); // Relative humidity %, 127=not available
343+
U(msg, AIS::KEY_BAROMETRIC_PRESSURE, start_bit + 129, 9, 511); // Barometric pressure in hPa-800, 511=not available
344+
U(msg, AIS::KEY_PRESSURE_TENDENCY, start_bit + 138, 2); // Pressure tendency: 0=steady, 1=decreasing, 2=increasing, 3=not available
345+
346+
// Reserved (4 bits) - skip
347+
X(msg, AIS::KEY_SPARE, start_bit + 140, 4);
348+
}
349+
}
350+
else if (message_id == 3) {
322351
// Water Level Message - decode first water level report
323352
// Each report is 144 bits, starting at bit 96
324353
if (msg.getLength() >= 240) { // Ensure we have at least one complete report (96 + 144 = 240 bits)
@@ -347,6 +376,35 @@ namespace AIS
347376
X(msg, AIS::KEY_SPARE, start_bit + 132, 12);
348377
}
349378
}
379+
else if (message_id == 2) {
380+
// Wind Information Message - decode first wind report
381+
// Each report is 144 bits, starting at bit 96
382+
if (msg.getLength() >= 240) { // Ensure we have at least one complete report (96 + 144 = 240 bits)
383+
int start_bit = 96;
384+
385+
// Timetag (20 bits): Month(4), Day(5), Hours(5), Minutes(6)
386+
U(msg, AIS::KEY_MONTH, start_bit, 4, 0); // Month 1-12, 0=not available
387+
U(msg, AIS::KEY_DAY, start_bit + 4, 5, 0); // Day 1-31, 0=not available
388+
U(msg, AIS::KEY_HOUR, start_bit + 9, 5, 24); // Hours 0-23, 24=not available
389+
U(msg, AIS::KEY_MINUTE, start_bit + 14, 6, 60); // Minutes 0-59, 60=not available
390+
391+
// Station ID (42 bits): Seven 6-bit ASCII characters
392+
T(msg, AIS::KEY_STATION_ID, start_bit + 20, 42, text);
393+
394+
// Position (49 bits total)
395+
SL(msg, AIS::KEY_LON, start_bit + 62, 25, 1 / 60000.0f, 0, 10800000); // Longitude in 1/1000 min, 181°=not available
396+
SL(msg, AIS::KEY_LAT, start_bit + 87, 24, 1 / 60000.0f, 0, 5400000); // Latitude in 1/1000 min, 91°=not available
397+
398+
// Wind Information Data (34 bits total)
399+
SL(msg, AIS::KEY_WIND_SPEED_AVG, start_bit + 111, 8, 0.1f, 0, 255); // Average wind speed in knots*10, 255=not available
400+
U(msg, AIS::KEY_WIND_DIRECTION_AVG, start_bit + 119, 9, 511); // Average wind direction in degrees, 511=not available
401+
SL(msg, AIS::KEY_WIND_GUST_SPEED, start_bit + 128, 8, 0.1f, 0, 255); // Wind gust speed in knots*10, 255=not available
402+
U(msg, AIS::KEY_WIND_GUST_DIRECTION, start_bit + 136, 9, 511); // Wind gust direction in degrees, 511=not available
403+
404+
// Reserved (9 bits) - skip
405+
X(msg, AIS::KEY_SPARE, start_bit + 145, 9);
406+
}
407+
}
350408
else if (message_id == 6) {
351409
// Water Flow Message - decode first water flow report
352410
// Each report is 144 bits, starting at bit 96
@@ -549,7 +607,36 @@ namespace AIS
549607
U(msg, AIS::KEY_MESSAGE_ID, 58, 6); // Message Identifier (6 bits)
550608

551609
unsigned message_id = msg.getUint(58, 6);
552-
if (message_id == 3) {
610+
if (message_id == 1) {
611+
// Weather Station Message - decode first weather report
612+
// Each report is 144 bits, starting at bit 64
613+
if (msg.getLength() >= 208) { // Ensure we have at least one complete report (64 + 144 = 208 bits)
614+
int start_bit = 64;
615+
616+
// Timetag (20 bits): Month(4), Day(5), Hours(5), Minutes(6)
617+
U(msg, AIS::KEY_MONTH, start_bit, 4, 0); // Month 1-12, 0=not available
618+
U(msg, AIS::KEY_DAY, start_bit + 4, 5, 0); // Day 1-31, 0=not available
619+
U(msg, AIS::KEY_HOUR, start_bit + 9, 5, 24); // Hours 0-23, 24=not available
620+
U(msg, AIS::KEY_MINUTE, start_bit + 14, 6, 60); // Minutes 0-59, 60=not available
621+
622+
// Station ID (42 bits): Seven 6-bit ASCII characters
623+
T(msg, AIS::KEY_STATION_ID, start_bit + 20, 42, text);
624+
625+
// Position (49 bits total)
626+
SL(msg, AIS::KEY_LON, start_bit + 62, 25, 1 / 60000.0f, 0, 10800000); // Longitude in 1/1000 min, 181°=not available
627+
SL(msg, AIS::KEY_LAT, start_bit + 87, 24, 1 / 60000.0f, 0, 5400000); // Latitude in 1/1000 min, 91°=not available
628+
629+
// Weather Station Data (33 bits total)
630+
SL(msg, AIS::KEY_AIR_TEMPERATURE, start_bit + 111, 11, 0.1f, -60.0f, 2047); // Air temperature in °C*10, 2047=not available
631+
U(msg, AIS::KEY_RELATIVE_HUMIDITY, start_bit + 122, 7, 127); // Relative humidity %, 127=not available
632+
U(msg, AIS::KEY_BAROMETRIC_PRESSURE, start_bit + 129, 9, 511); // Barometric pressure in hPa-800, 511=not available
633+
U(msg, AIS::KEY_PRESSURE_TENDENCY, start_bit + 138, 2); // Pressure tendency: 0=steady, 1=decreasing, 2=increasing, 3=not available
634+
635+
// Reserved (4 bits) - skip
636+
X(msg, AIS::KEY_SPARE, start_bit + 140, 4);
637+
}
638+
}
639+
else if (message_id == 3) {
553640
// Water Level Message - decode first water level report
554641
// Each report is 144 bits, starting at bit 64
555642
if (msg.getLength() >= 208) { // Ensure we have at least one complete report (64 + 144 = 208 bits)
@@ -578,6 +665,35 @@ namespace AIS
578665
X(msg, AIS::KEY_SPARE, start_bit + 132, 12);
579666
}
580667
}
668+
else if (message_id == 2) {
669+
// Wind Information Message - decode first wind report
670+
// Each report is 144 bits, starting at bit 64
671+
if (msg.getLength() >= 208) { // Ensure we have at least one complete report (64 + 144 = 208 bits)
672+
int start_bit = 64;
673+
674+
// Timetag (20 bits): Month(4), Day(5), Hours(5), Minutes(6)
675+
U(msg, AIS::KEY_MONTH, start_bit, 4, 0); // Month 1-12, 0=not available
676+
U(msg, AIS::KEY_DAY, start_bit + 4, 5, 0); // Day 1-31, 0=not available
677+
U(msg, AIS::KEY_HOUR, start_bit + 9, 5, 24); // Hours 0-23, 24=not available
678+
U(msg, AIS::KEY_MINUTE, start_bit + 14, 6, 60); // Minutes 0-59, 60=not available
679+
680+
// Station ID (42 bits): Seven 6-bit ASCII characters
681+
T(msg, AIS::KEY_STATION_ID, start_bit + 20, 42, text);
682+
683+
// Position (49 bits total)
684+
SL(msg, AIS::KEY_LON, start_bit + 62, 25, 1 / 60000.0f, 0, 10800000); // Longitude in 1/1000 min, 181°=not available
685+
SL(msg, AIS::KEY_LAT, start_bit + 87, 24, 1 / 60000.0f, 0, 5400000); // Latitude in 1/1000 min, 91°=not available
686+
687+
// Wind Information Data (34 bits total)
688+
SL(msg, AIS::KEY_WIND_SPEED_AVG, start_bit + 111, 8, 0.1f, 0, 255); // Average wind speed in knots*10, 255=not available
689+
U(msg, AIS::KEY_WIND_DIRECTION_AVG, start_bit + 119, 9, 511); // Average wind direction in degrees, 511=not available
690+
SL(msg, AIS::KEY_WIND_GUST_SPEED, start_bit + 128, 8, 0.1f, 0, 255); // Wind gust speed in knots*10, 255=not available
691+
U(msg, AIS::KEY_WIND_GUST_DIRECTION, start_bit + 136, 9, 511); // Wind gust direction in degrees, 511=not available
692+
693+
// Reserved (9 bits) - skip
694+
X(msg, AIS::KEY_SPARE, start_bit + 145, 9);
695+
}
696+
}
581697
else if (message_id == 6) {
582698
// Water Flow Message - decode first water flow report
583699
// Each report is 144 bits, starting at bit 64

Library/Keys.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,14 @@ namespace AIS
395395
{"current_direction_2", "", "", ""},
396396
{"current_speed_3", "", "", ""},
397397
{"current_direction_3", "", "", ""},
398+
{"wind_speed_avg", "", "", ""},
399+
{"wind_direction_avg", "", "", ""},
400+
{"wind_gust_speed", "", "", ""},
401+
{"wind_gust_direction", "", "", ""},
402+
{"air_temperature", "", "", ""},
403+
{"relative_humidity", "", "", ""},
404+
{"barometric_pressure", "", "", ""},
405+
{"pressure_tendency", "", "", ""},
398406
{"watertemp", "", "", ""},
399407
{"wavedir", "", "", ""},
400408
{"weather_report_type", "", "", ""},

Library/Keys.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,14 @@ namespace AIS
408408
KEY_CURRENT_DIRECTION_2,
409409
KEY_CURRENT_SPEED_3,
410410
KEY_CURRENT_DIRECTION_3,
411+
KEY_WIND_SPEED_AVG,
412+
KEY_WIND_DIRECTION_AVG,
413+
KEY_WIND_GUST_SPEED,
414+
KEY_WIND_GUST_DIRECTION,
415+
KEY_AIR_TEMPERATURE,
416+
KEY_RELATIVE_HUMIDITY,
417+
KEY_BAROMETRIC_PRESSURE,
418+
KEY_PRESSURE_TENDENCY,
411419
KEY_WATERTEMP,
412420
KEY_WAVEDIR,
413421
KEY_WEATHER_REPORT_TYPE,

0 commit comments

Comments
 (0)