Debian Codegraph @

src/libais/ais8.cpp

raw symbols SCIP
1 // Binary Broadcast Message (BBM) - 8
2
3 // See also: http://www.e-navigation.nl/asm
4
5 #include <iomanip>
6
7 #include "ais.h"
8
9 namespace libais {
10
11 Ais8::Ais8(const char *nmea_payload, const size_t pad)
12 : AisMsg(nmea_payload, pad), spare(0), dac(0), fi(0) {
13 if (!CheckStatus()) {
14 return;
15 }
16
17 // in bits w/o DAC/FI
18 // TODO(schwehr): Verify if this is 46 or 56 (accumulated bits below).
19 const int payload_len = num_bits - 56;
20 if (payload_len < 0 || payload_len > 952) {
21 status = AIS_ERR_BAD_BIT_COUNT;
22 return;
23 }
24
25 assert(message_id == 8);
26
27 bits.SeekTo(38);
28 spare = bits.ToUnsignedInt(38, 2);
29 dac = bits.ToUnsignedInt(40, 10);
30 fi = bits.ToUnsignedInt(50, 6);
31 }
32
33 Ais8_1_0::Ais8_1_0(const char *nmea_payload, const size_t pad)
34 : Ais8(nmea_payload, pad), ack_required(false), msg_seq(0), text(),
35 spare2(0) {
36 assert(dac == 1);
37 assert(fi == 0);
38
39 if (!CheckStatus()) {
40 return;
41 }
42
43 if (num_bits < 68 || num_bits > 1024) {
44 status = AIS_ERR_BAD_BIT_COUNT;
45 return;
46 }
47
48 bits.SeekTo(56);
49 ack_required = bits[56];
50 msg_seq = bits.ToUnsignedInt(57, 11);
51
52 const size_t text_size = 6 * ((num_bits - 68)/6);
53 // wrong? needs to land on 8-bit boundary
54 const size_t spare2_size = num_bits - 68 - text_size;
55 text = bits.ToString(68, text_size);
56
57 // TODO(schwehr): Is this correct?
58 if (!spare2_size)
59 spare2 = 0;
60 else
61 spare2 = bits.ToUnsignedInt(68, spare2_size);
62
63 assert(bits.GetRemaining() == 0);
64 status = AIS_OK;
65 }
66
67 Ais8_1_11::Ais8_1_11(const char *nmea_payload, const size_t pad)
68 : Ais8(nmea_payload, pad), day(0), hour(0), minute(0), wind_ave(0),
69 wind_gust(0), wind_dir(0), wind_gust_dir(0), air_temp(0.0), rel_humid(0),
70 dew_point(0.0), air_pres(0.0), air_pres_trend(0), horz_vis(0.0),
71 water_level(0.0), water_level_trend(0), surf_cur_speed(0.0),
72 surf_cur_dir(0), cur_speed_2(0.0), cur_dir_2(0), cur_depth_2(0),
73 cur_speed_3(0.0), cur_dir_3(0), cur_depth_3(0), wave_height(0.0),
74 wave_period(0), wave_dir(0), swell_height(0.0), swell_period(0),
75 swell_dir(0), sea_state(0), water_temp(0.0), precip_type(0),
76 salinity(0.0), ice(0), spare2(0), extended_water_level(0) {
77 assert(dac == 1);
78 assert(fi == 11);
79
80 if (!CheckStatus()) {
81 return;
82 }
83 if (num_bits != 352) {
84 status = AIS_ERR_BAD_BIT_COUNT;
85 return;
86 }
87
88 // 352 + 2 spares to be 6 bit aligned
89
90 bits.SeekTo(56);
91 // Reverse order lat/lng!
92 // TODO(schwehr): Reverse order, or just reverse bit count? Compare 6.1.14!
93 double y = bits.ToInt(56, 24) / 60000.0;
94 double x = bits.ToInt(80, 25) / 60000.0;
95 position = AisPoint(x, y);
96
97 day = bits.ToUnsignedInt(105, 5);
98 hour = bits.ToUnsignedInt(110, 5);
99 minute = bits.ToUnsignedInt(115, 6);
100 wind_ave = bits.ToUnsignedInt(121, 7);
101 wind_gust = bits.ToUnsignedInt(128, 7);
102 wind_dir = bits.ToUnsignedInt(135, 9);
103 wind_gust_dir = bits.ToUnsignedInt(144, 9);
104 air_temp = bits.ToUnsignedInt(153, 11) / 10. - 60;
105 rel_humid = bits.ToUnsignedInt(164, 7);
106 dew_point = bits.ToUnsignedInt(171, 10) / 10. - 20; // TODO(schwehr): verify
107 air_pres = bits.ToUnsignedInt(181, 9) + 800;
108 air_pres_trend = bits.ToUnsignedInt(190, 2);
109 horz_vis = bits.ToUnsignedInt(192, 8) / 10.;
110 // TODO(schwehr): verify for -10.0 to 30.0
111 water_level = bits.ToUnsignedInt(200, 9) / 10. - 10;
112 water_level_trend = bits.ToUnsignedInt(209, 2);
113 surf_cur_speed = bits.ToUnsignedInt(211, 8) / 10.;
114 surf_cur_dir = bits.ToUnsignedInt(219, 9);
115 cur_speed_2 = bits.ToUnsignedInt(228, 8) / 10.;
116 cur_dir_2 = bits.ToUnsignedInt(236, 9);
117 cur_depth_2 = bits.ToUnsignedInt(245, 5);
118 cur_speed_3 = bits.ToUnsignedInt(250, 8) / 10.;
119 cur_dir_3 = bits.ToUnsignedInt(258, 9);
120 cur_depth_3 = bits.ToUnsignedInt(267, 5);
121
122 wave_height = bits.ToUnsignedInt(272, 8) / 10.;
123 wave_period = bits.ToUnsignedInt(280, 6);
124 wave_dir = bits.ToUnsignedInt(286, 9);
125 swell_height = bits.ToUnsignedInt(295, 8) / 10.;
126 swell_period = bits.ToUnsignedInt(303, 6);
127 swell_dir = bits.ToUnsignedInt(309, 9);
128
129 sea_state = bits.ToUnsignedInt(318, 4);
130 // TODO(schwehr): verify for -10.0 to +50.0
131 water_temp = bits.ToUnsignedInt(322, 10) / 10. - 10;
132 precip_type = bits.ToUnsignedInt(332, 3);
133 salinity = bits.ToUnsignedInt(335, 9) / 10.0; // Part per mil (1/1000).
134 ice = bits.ToUnsignedInt(344, 2);
135 // There is no way to know which meaning to attach to the following 6 bits
136 // TODO(schwehr): how to treat this spare vrs water level?
137 spare2 = bits.ToUnsignedInt(346, 6);
138 bits.SeekRelative(-6);
139 extended_water_level = bits.ToUnsignedInt(346, 6);
140
141 assert(bits.GetRemaining() == 0);
142 status = AIS_OK;
143 }
144
145 // No 8_1_12
146
147 // IMO Circ 289 - Fairway Closed
148 // See also Circ 236
149 Ais8_1_13::Ais8_1_13(const char *nmea_payload, const size_t pad)
150 : Ais8(nmea_payload, pad), reason(), location_from(), location_to(),
151 radius(0), units(0), day_from(0), month_from(0), hour_from(0),
152 minute_from(0), day_to(0), month_to(0), hour_to(0), minute_to(0),
153 spare2(0) {
154 assert(dac == 1);
155 assert(fi == 13);
156
157 if (!CheckStatus()) {
158 return;
159 }
160 if (num_bits != 472) {
161 status = AIS_ERR_BAD_BIT_COUNT;
162 return;
163 }
164
165 bits.SeekTo(56);
166 reason = bits.ToString(56, 120);
167 location_from = bits.ToString(176, 120);
168 location_to = bits.ToString(296, 120);
169 radius = bits.ToUnsignedInt(416, 10);
170 units = bits.ToUnsignedInt(426, 2);
171 day_from = bits.ToUnsignedInt(428, 5);
172 month_from = bits.ToUnsignedInt(433, 4);
173 hour_from = bits.ToUnsignedInt(437, 5);
174 minute_from = bits.ToUnsignedInt(442, 6);
175 day_to = bits.ToUnsignedInt(448, 5);
176 month_to = bits.ToUnsignedInt(453, 4);
177 hour_to = bits.ToUnsignedInt(457, 5);
178 minute_to = bits.ToUnsignedInt(462, 6);
179 spare2 = bits.ToUnsignedInt(468, 4);
180
181 assert(bits.GetRemaining() == 0);
182 status = AIS_OK;
183 }
184
185 // No 8_1_14
186
187 // IMO Circ 289 - Extended Shipdata - Air gap
188 // See also Circ 236
189 Ais8_1_15::Ais8_1_15(const char *nmea_payload, const size_t pad)
190 : Ais8(nmea_payload, pad), air_draught(0.0), spare2(0) {
191 assert(dac == 1);
192 assert(fi == 15);
193
194 if (!CheckStatus()) {
195 return;
196 }
197 if (num_bits != 72) {
198 status = AIS_ERR_BAD_BIT_COUNT;
199 return;
200 }
201
202 bits.SeekTo(56);
203 air_draught = bits.ToUnsignedInt(56, 11) / 10.;
204 spare2 = bits.ToUnsignedInt(67, 5);
205
206 assert(bits.GetRemaining() == 0);
207 status = AIS_OK;
208 }
209
210 // IMO Circ 289 - Number of persons on board
211 // See also Circ 236
212 // TODO(schwehr): there might also be an addressed version?
213 Ais8_1_16::Ais8_1_16(const char *nmea_payload, const size_t pad)
214 : Ais8(nmea_payload, pad), persons(0), spare2(0) {
215 assert(dac == 1);
216 assert(fi == 16);
217
218 if (!CheckStatus()) {
219 return;
220 }
221 if (num_bits != 72) {
222 status = AIS_ERR_BAD_BIT_COUNT;
223 return;
224 }
225
226 bits.SeekTo(56);
227 persons = bits.ToUnsignedInt(56, 13);
228 spare2 = bits.ToUnsignedInt(69, 3);
229
230 assert(bits.GetRemaining() == 0);
231 status = AIS_OK;
232 }
233
234 Ais8_1_17_Target::Ais8_1_17_Target()
235 : type(0), id(), spare(0), cog(0), timestamp(0), sog(0) {}
236
237 // IMO Circ 289 - VTS Generated/Synthetic Targets
238 // See also Circ 236
239 Ais8_1_17::Ais8_1_17(const char *nmea_payload, const size_t pad)
240 : Ais8(nmea_payload, pad) {
241 assert(dac == 1);
242 assert(fi == 17);
243
244 if (!CheckStatus()) {
245 return;
246 }
247
248 const size_t num_targets = (num_bits - 56) / 120;
249 const size_t extra_bits = (num_bits - 56) % 120;
250
251 if (extra_bits || num_targets > 4) {
252 status = AIS_ERR_BAD_BIT_COUNT;
253 return;
254 }
255
256 bits.SeekTo(56);
257 for (size_t target_num = 0; target_num < num_targets; target_num++) {
258 Ais8_1_17_Target target;
259 const size_t start = 56 + (120 * target_num);
260 target.type = bits.ToUnsignedInt(start, 2);
261 target.id = bits.ToString(start + 2, 42);
262 target.spare = bits.ToUnsignedInt(start + 44, 4);
263 // booo - lat, lon inverse order
264 double y = bits.ToInt(start + 48, 24) / 60000.0;
265 double x = bits.ToInt(start + 72, 25) / 60000.0;
266 target.position = AisPoint(x, y);
267
268 target.cog = bits.ToUnsignedInt(start + 97, 9);
269 target.timestamp = bits.ToUnsignedInt(start + 106, 6);
270 target.sog = bits.ToUnsignedInt(start + 112, 8);
271 }
272
273 assert(bits.GetRemaining() == 0);
274 status = AIS_OK;
275 }
276
277 // No msg 8_1_18
278
279 // IMO Circ 289 - Marine traffic signal
280 Ais8_1_19::Ais8_1_19(const char *nmea_payload, const size_t pad)
281 : Ais8(nmea_payload, pad), link_id(0), name(), status(0), signal(0),
282 utc_hour_next(0), utc_min_next(0), spare2() {
283 assert(dac == 1);
284 assert(fi == 19);
285
286 if (!CheckStatus()) {
287 return;
288 }
289
290 // Some people transmit without the idiodic spare padding
291 if (num_bits != 258 && num_bits != 360) {
292 status = AIS_ERR_BAD_BIT_COUNT;
293 return;
294 }
295
296 bits.SeekTo(56);
297 link_id = bits.ToUnsignedInt(56, 10);
298 name = bits.ToString(66, 120);
299 position = bits.ToAisPoint(186, 49);
300 status = bits.ToUnsignedInt(235, 2);
301 signal = bits.ToUnsignedInt(237, 5);
302 utc_hour_next = bits.ToUnsignedInt(242, 5);
303 utc_min_next = bits.ToUnsignedInt(247, 6);
304 next_signal = bits.ToUnsignedInt(253, 5);
305 if (num_bits == 360) {
306 spare2[0] = bits.ToUnsignedInt(258, 32);
307 spare2[1] = bits.ToUnsignedInt(290, 32);
308 spare2[2] = bits.ToUnsignedInt(322, 32);
309 spare2[3] = bits.ToUnsignedInt(354, 6);
310 }
311
312 assert(bits.GetRemaining() == 0);
313 status = AIS_OK;
314 }
315
316 // No 8_1_20
317
318 // IMO Circ 289 - Weather observation report from ship
319 // See also Circ 236
320 Ais8_1_21::Ais8_1_21(const char *nmea_payload, const size_t pad)
321 : Ais8(nmea_payload, pad), type_wx_report(0), location(), utc_day(0),
322 utc_hour(), utc_min(), horz_viz(0.0), humidity(0), wind_speed(0),
323 wind_dir(0), pressure(0.0), pressure_tendency(0), air_temp(0.0),
324 water_temp(0.0), wave_period(0), wave_height(0.0), wave_dir(0),
325 swell_height(0.0), swell_dir(0), swell_period(0), spare2(0),
326 utc_month(0), cog(0), sog(0.0), heading(0), rel_pressure(0.0),
327 wind_speed_ms(0.0), wind_dir_rel(0), wind_speed_rel(0.0),
328 wind_gust_speed(0.0), wind_gust_dir(0), air_temp_raw(0),
329 water_temp_raw(0), wx(), cloud_total(0), cloud_low(0),
330 cloud_low_type(0), cloud_middle_type(0), cloud_high_type(0),
331 alt_lowest_cloud_base(0.0), swell_dir_2(0), swell_period_2(0),
332 swell_height_2(0.0), ice_thickness(0.0), ice_accretion(0),
333 ice_accretion_cause(0), sea_ice_concentration(0), amt_type_ice(0),
334 ice_situation(0), ice_devel(0), bearing_ice_edge(0) {
335 assert(dac == 1);
336 assert(fi == 21);
337
338 if (!CheckStatus()) {
339 return;
340 }
341 if (num_bits != 360) {
342 status = AIS_ERR_BAD_BIT_COUNT;
343 return;
344 }
345
346 bits.SeekTo(56);
347 type_wx_report = bits[56];
348 if (!type_wx_report) {
349 // WX obs from ship
350 location = bits.ToString(57, 120);
351 position = bits.ToAisPoint(177, 49);
352 utc_day = bits.ToUnsignedInt(226, 5);
353 utc_hour = bits.ToUnsignedInt(231, 5);
354 utc_min = bits.ToUnsignedInt(236, 6);
355 wx[0] = bits.ToUnsignedInt(242, 4); // TODO(schwehr): set wx[1] and wx[2]?
356 horz_viz = bits.ToUnsignedInt(246, 8) / 10.; // nautical miles
357 humidity = bits.ToUnsignedInt(254, 7); // %
358 wind_speed = bits.ToUnsignedInt(261, 7); // ave knots
359 wind_dir = bits.ToUnsignedInt(268, 9);
360 pressure = bits.ToUnsignedInt(277, 9); // hPa
361 pressure_tendency = bits.ToUnsignedInt(286, 4);
362 // TODO(schwehr): is air_temp correct?
363 air_temp = bits.ToInt(290, 11) / 10.; // C
364 water_temp = bits.ToUnsignedInt(301, 10) / 10. - 10; // C
365 wave_period = bits.ToUnsignedInt(311, 6); // s
366 wave_height = bits.ToUnsignedInt(317, 8) / 10.;
367 wave_dir = bits.ToUnsignedInt(325, 9);
368 swell_height = bits.ToUnsignedInt(334, 8) / 10.; // m
369 swell_dir = bits.ToUnsignedInt(342, 9);
370 swell_period = bits.ToUnsignedInt(351, 6); // s
371 spare2 = bits.ToUnsignedInt(357, 3);
372 } else {
373 // Type 1: WMO OBS from ship.
374 double x = (bits.ToUnsignedInt(57, 16) / 100.0) - 180;
375 double y = (bits.ToUnsignedInt(73, 15) / 100.0) - 180;
376 position = AisPoint(x, y);
377
378 utc_month = bits.ToUnsignedInt(88, 4);
379 utc_day = bits.ToUnsignedInt(92, 6);
380 utc_hour = bits.ToUnsignedInt(98, 5);
381 utc_min = bits.ToUnsignedInt(102, 3) * 10;
382 cog = bits.ToUnsignedInt(106, 7) * 5;
383 sog = bits.ToUnsignedInt(113, 5) * 0.5;
384 heading = bits.ToUnsignedInt(118, 7) *5; // Assume this is true degrees????
385 pressure = bits.ToUnsignedInt(125, 11) / 10. + 900;
386 rel_pressure = bits.ToUnsignedInt(136, 10) / 10. -50;
387 pressure_tendency = bits.ToUnsignedInt(146, 4);
388 wind_dir = bits.ToUnsignedInt(150, 7) * 5;
389 wind_speed_ms = bits.ToUnsignedInt(157, 8) * 0.5; // m/s
390 wind_dir_rel = bits.ToUnsignedInt(165, 7) * 5;
391 wind_speed_rel = bits.ToUnsignedInt(172, 8) * 0.5; // m/s
392 wind_gust_speed = bits.ToUnsignedInt(180, 8) * 0.5; // m/s
393 wind_gust_dir = bits.ToUnsignedInt(188, 7) * 5;
394 // 0C = 273.15 Kelvin
395 // TODO(schwehr): change this to celsius
396 air_temp_raw = bits.ToUnsignedInt(195, 10);
397 humidity = bits.ToUnsignedInt(205, 7);
398 water_temp_raw = bits.ToUnsignedInt(212, 9); // TODO(schwehr): Change to C.
399
400 auto pow2 = [](unsigned int val) { return val * val; };
401 horz_viz = pow2(bits.ToUnsignedInt(221, 6)) * 13.073; // m
402 wx[0] = bits.ToUnsignedInt(227, 9); // current
403 wx[1] = bits.ToUnsignedInt(236, 5); // past 1
404 wx[2] = bits.ToUnsignedInt(241, 5); // past 2
405 cloud_total = bits.ToUnsignedInt(246, 4) * 10;
406 cloud_low = bits.ToUnsignedInt(250, 4);
407 cloud_low_type = bits.ToUnsignedInt(254, 6);
408 cloud_middle_type = bits.ToUnsignedInt(260, 6);
409 cloud_high_type = bits.ToUnsignedInt(266, 6);
410 alt_lowest_cloud_base = pow2(bits.ToUnsignedInt(272, 7)) * 0.16;
411 wave_period = bits.ToUnsignedInt(279, 5); // s
412 wave_height = bits.ToUnsignedInt(284, 6) * 0.5; // m
413 swell_dir = bits.ToUnsignedInt(290, 6) * 10;
414 swell_period = bits.ToUnsignedInt(296, 5); // s
415 swell_height = bits.ToUnsignedInt(301, 6) * 0.5; // m
416 swell_dir_2 = bits.ToUnsignedInt(307, 6) * 10;
417 swell_period_2 = bits.ToUnsignedInt(313, 5); // s
418 swell_height_2 = bits.ToUnsignedInt(318, 6) * 0.5; // m
419 ice_thickness = bits.ToUnsignedInt(324, 7) / 100.; // m. Network is cm,
420 ice_accretion = bits.ToUnsignedInt(331, 3);
421 ice_accretion_cause = bits.ToUnsignedInt(334, 3);
422 sea_ice_concentration = bits.ToUnsignedInt(337, 5);
423 amt_type_ice = bits.ToUnsignedInt(342, 4);
424 ice_situation = bits.ToUnsignedInt(346, 5);
425 ice_devel = bits.ToUnsignedInt(351, 5);
426 bearing_ice_edge = bits.ToUnsignedInt(356, 4) * 45;
427 }
428
429 assert(bits.GetRemaining() == 0);
430 status = AIS_OK;
431 }
432
433 // See ais8_1_22.cpp
434 // No 8_1_23
435
436 // IMO Circ 289 - Extended ship static and voyage-related
437 // See also Circ 236
438 Ais8_1_24::Ais8_1_24(const char *nmea_payload, const size_t pad)
439 : Ais8(nmea_payload, pad), link_id(0), air_draught(0.0), last_port(),
440 next_ports(), solas_status(), ice_class(0), shaft_power(0), vhf(0),
441 lloyds_ship_type(), gross_tonnage(0), laden_ballast(0), heavy_oil(0),
442 light_oil(0), diesel(0), bunker_oil(0), persons(0), spare2(0) {
443 assert(dac == 1);
444 assert(fi == 24);
445
446 if (!CheckStatus()) {
447 return;
448 }
449 if (num_bits != 360) {
450 status = AIS_ERR_BAD_BIT_COUNT;
451 return;
452 }
453
454 bits.SeekTo(56);
455 link_id = bits.ToUnsignedInt(56, 10);
456 air_draught = bits.ToUnsignedInt(66, 13) / 10.; // m
457 last_port = bits.ToString(79, 30);
458 next_ports[0] = bits.ToString(109, 30);
459 next_ports[1] = bits.ToString(139, 30);
460
461 // TODO(schwehr): enum list of param types
462 // 0 NA, 1 operational, 2 SNAFU, 3 no data
463 for (size_t equip_num = 0; equip_num < 26; equip_num++) {
464 solas_status[equip_num] = bits.ToUnsignedInt(169 + 2 * equip_num, 2);
465 }
466 ice_class = bits.ToUnsignedInt(221, 4);
467 shaft_power = bits.ToUnsignedInt(225, 18); // horses
468 vhf = bits.ToUnsignedInt(243, 12);
469 lloyds_ship_type = bits.ToString(255, 42);
470 gross_tonnage = bits.ToUnsignedInt(297, 18);
471 laden_ballast = bits.ToUnsignedInt(315, 2);
472 heavy_oil = bits.ToUnsignedInt(317, 2);
473 light_oil = bits.ToUnsignedInt(319, 2);
474 diesel = bits.ToUnsignedInt(321, 2);
475 bunker_oil = bits.ToUnsignedInt(323, 14); // tonnes
476 persons = bits.ToUnsignedInt(337, 13);
477 spare2 = bits.ToUnsignedInt(350, 10);
478
479 assert(bits.GetRemaining() == 0);
480 status = AIS_OK;
481 }
482
483
484 // No 8_1_25
485 // See ais8_1_26.cpp
486
487 // IMO Circ 289 - Route information
488 // See also Circ 236
489 Ais8_1_27::Ais8_1_27(const char *nmea_payload, const size_t pad)
490 : Ais8(nmea_payload, pad), link_id(0), sender_type(0), route_type(0),
491 utc_month(0), utc_day(0), utc_hour(0), utc_min(0), duration(0) {
492 assert(dac == 1);
493 assert(fi == 27);
494
495 if (!CheckStatus()) {
496 return;
497 }
498
499 const size_t num_waypoints = (num_bits - 117) / 55;
500 const size_t extra_bits = (num_bits - 117) % 55;
501
502 if (extra_bits || num_waypoints > 16) {
503 status = AIS_ERR_BAD_BIT_COUNT;
504 return;
505 }
506
507 bits.SeekTo(56);
508 link_id = bits.ToUnsignedInt(56, 10);
509 sender_type = bits.ToUnsignedInt(66, 3);
510 route_type = bits.ToUnsignedInt(69, 5);
511 utc_month = bits.ToUnsignedInt(74, 4);
512 utc_day = bits.ToUnsignedInt(78, 5);
513 utc_hour = bits.ToUnsignedInt(83, 5);
514 utc_min = bits.ToUnsignedInt(88, 6);
515 duration = bits.ToUnsignedInt(94, 18);
516 // TODO(schwehr): manage the case where num_waypoints does not match
517 // const size_t num_waypoints_stated = bits.ToUnsignedInt(112, 5);
518 for (size_t waypoint_num = 0; waypoint_num < num_waypoints; waypoint_num++) {
519 const size_t start = 117 + 55*waypoint_num;
520 waypoints.push_back(bits.ToAisPoint(start, 55));
521 }
522
523 assert(bits.GetRemaining() == 0);
524 status = AIS_OK;
525 }
526
527 // No 8_1_28
528
529 // IMO Circ 289 - Text description
530 // See also Circ 236
531 Ais8_1_29::Ais8_1_29(const char *nmea_payload, const size_t pad)
532 : Ais8(nmea_payload, pad), link_id(0), spare2(0) {
533 assert(dac == 1);
534 assert(fi == 29);
535
536 if (!CheckStatus()) {
537 return;
538 }
539 if (num_bits < 72 || num_bits > 1032) {
540 status = AIS_ERR_BAD_BIT_COUNT;
541 return;
542 }
543
544 bits.SeekTo(56);
545 link_id = bits.ToUnsignedInt(56, 10);
546 size_t text_bits = ((num_bits - 66) / 6) * 6;
547 text = bits.ToString(66, text_bits);
548 const size_t spare2_bits = num_bits - 66 - text_bits;
549 if (spare2_bits) {
550 const size_t start = 66 + text_bits;
551 spare2 = bits.ToUnsignedInt(start, spare2_bits);
552 } else {
553 spare2 = 0;
554 }
555
556 assert(bits.GetRemaining() == 0);
557 status = AIS_OK;
558 }
559
560 // IMO Circ 289 - Meteorological and Hydrographic data
561 // See also Circ 236
562 Ais8_1_31::Ais8_1_31(const char *nmea_payload, const size_t pad)
563 : Ais8(nmea_payload, pad), position_accuracy(0), utc_day(0), utc_hour(0),
564 utc_min(0), wind_ave(0), wind_gust(0), wind_dir(0), wind_gust_dir(0),
565 air_temp(0.0), rel_humid(0), dew_point(0.0), air_pres(0.0),
566 air_pres_trend(0), horz_vis(0.0), water_level(0.0),
567 water_level_trend(0), surf_cur_speed(0.0), surf_cur_dir(0),
568 cur_speed_2(0.0), cur_dir_2(0), cur_depth_2(0), cur_speed_3(0.0),
569 cur_dir_3(0), cur_depth_3(0), wave_height(0.0), wave_period(0),
570 wave_dir(0), swell_height(0.0), swell_period(0), swell_dir(0),
571 sea_state(0), water_temp(0.0), precip_type(0), salinity(0.0),
572 ice(0), spare2(0) {
573 assert(dac == 1);
574 assert(fi == 31);
575
576 if (!CheckStatus()) {
577 return;
578 }
579 if (num_bits != 360) {
580 status = AIS_ERR_BAD_BIT_COUNT;
581 return;
582 }
583
584 bits.SeekTo(56);
585 position = bits.ToAisPoint(56, 49);
586 position_accuracy = bits[105];
587 utc_day = bits.ToUnsignedInt(106, 5);
588 utc_hour = bits.ToUnsignedInt(111, 5);
589 utc_min = bits.ToUnsignedInt(116, 6);
590
591 wind_ave = bits.ToUnsignedInt(122, 7); // kts
592 wind_gust = bits.ToUnsignedInt(129, 7); // kts
593 wind_dir = bits.ToUnsignedInt(136, 9);
594 wind_gust_dir = bits.ToUnsignedInt(145, 9);
595 air_temp = bits.ToInt(154, 11) / 10.; // C
596 rel_humid = bits.ToUnsignedInt(165, 7);
597 dew_point = bits.ToInt(172, 10)/ 10.; // TODO(schwehr): How is this mapped?
598 air_pres = (bits.ToUnsignedInt(182, 9) + 800) / 100.0; // Pa
599 air_pres_trend = bits.ToUnsignedInt(191, 2);
600
601 horz_vis = bits.ToUnsignedInt(193, 8) / 10.; // NM
602 water_level = bits.ToUnsignedInt(201, 12) / 100. - 10; // m
603 water_level_trend = bits.ToUnsignedInt(213, 2);
604
605 surf_cur_speed = bits.ToUnsignedInt(215, 8) / 10.;
606 surf_cur_dir = bits.ToUnsignedInt(223, 9);
607 cur_speed_2 = bits.ToUnsignedInt(232, 8) / 10.; // kts
608 cur_dir_2 = bits.ToUnsignedInt(240, 9);
609 cur_depth_2 = bits.ToUnsignedInt(249, 5); // m
610 cur_speed_3 = bits.ToUnsignedInt(254, 8) / 10.; // kts
611 cur_dir_3 = bits.ToUnsignedInt(262, 9);
612 cur_depth_3 = bits.ToUnsignedInt(271, 5); // m
613
614 wave_height = bits.ToUnsignedInt(276, 8); // m
615
616 wave_period = bits.ToUnsignedInt(284, 6);
617 wave_dir = bits.ToUnsignedInt(290, 9);
618 swell_height = bits.ToUnsignedInt(299, 8) / 10.;
619 swell_period = bits.ToUnsignedInt(307, 6);
620 swell_dir = bits.ToUnsignedInt(313, 9);
621 sea_state = bits.ToUnsignedInt(322, 4); // beaufort scale - Table 1.2
622 water_temp = bits.ToInt(326, 10) / 10.;
623 precip_type = bits.ToUnsignedInt(336, 3);
624 salinity = bits.ToUnsignedInt(339, 9) / 10.;
625 ice = bits.ToUnsignedInt(348, 2); // yes/no/undef/unknown
626 spare2 = bits.ToUnsignedInt(350, 10);
627
628 assert(bits.GetRemaining() == 0);
629 status = AIS_OK;
630 }
631
632
633 } // namespace libais