Debian Codegraph @

src/libais/ais.h

raw symbols SCIP
1 // -*- c++ -*-
2
3 // TODO(schwehr): Create an archive of messages that do not decode.
4
5 #ifndef LIBAIS_AIS_H_
6 #define LIBAIS_AIS_H_
7
8 #include <array>
9 #include <bitset>
10 #include <cassert>
11 #include <cstring>
12 #include <string>
13 #include <iostream>
14 #include <vector>
15
16 using std::bitset;
17 using std::ostream;
18 using std::string;
19 using std::vector;
20
21 #define LIBAIS_VERSION_MAJOR 0
22 #define LIBAIS_VERSION_MINOR 15
23
24 extern "C" {
25 // For configuration scripts to detect libais and the version numbers.
26 int LibAisVersionMajor();
27 int LibAisVersionMinor();
28 }
29
30 namespace libais {
31
32 // Returns the text in the nth field starting with the first field being 0.
33 // Empty delim_str is not allowed.
34 string GetNthField(const string &str, const size_t n, const string &delim_str);
35
36 // Returns the number of pad bits in an AIS AIVDM NMEA string.
37 // Returns -1 if there is an error.
38 int GetPad(const string &nmea_str);
39
40 // Returns the armored payload of an AIS AIVDM NMEA string.
41 // Returns an empty string if there was an error.
42 string GetBody(const string &nmea_str);
43
44
45 // Note: Needs to be kept in sync with AIS_STATUS_STRINGS list in ais.cpp.
46 enum AIS_STATUS {
47 AIS_UNINITIALIZED, // Message is not yet completely decoded.
48 AIS_OK,
49 AIS_ERR_BAD_BIT_COUNT,
50 AIS_ERR_BAD_NMEA_CHR,
51 AIS_ERR_BAD_PTR,
52 AIS_ERR_UNKNOWN_MSG_TYPE,
53 AIS_ERR_MSG_NOT_IMPLEMENTED,
54 AIS_ERR_MSG_SUB_NOT_IMPLEMENTED,
55 AIS_ERR_EXPECTED_STRING,
56 AIS_ERR_BAD_MSG_CONTENT,
57 AIS_ERR_MSG_TOO_LONG,
58 AIS_ERR_BAD_SUB_MSG,
59 AIS_ERR_BAD_SUB_SUB_MSG,
60 AIS_STATUS_NUM_CODES
61 };
62
63 extern const char *const AIS_STATUS_STRINGS[AIS_STATUS_NUM_CODES];
64
65 // Designated Area Codes (DAC) / Maritime Identification Digits define
66 // which country controls a subset of the submessage spaces within
67 // AIS "binary" messages 6, 8, 25, and 26. See:
68 // http://www.itu.int/online/mms/glad/cga_mids.sh?lng=E
69 // http://en.wikipedia.org/w/index.php?title=Maritime_identification_digits
70 // River Information System (RIS):
71 // ECE-TRANS-SC3-2006-10r-RIS.pdf
72
73 enum Dac {
74 AIS_DAC_0_TEST = 0,
75 AIS_DAC_1_INTERNATIONAL,
76 AIS_DAC_200_RIS = 200,
77 AIS_DAC_201_ALBANIA = 201,
78 AIS_DAC_202_ANDORRA = 202,
79 AIS_DAC_203_AUSTRIA = 203,
80 AIS_DAC_204_AZORES = 204,
81 AIS_DAC_205_BELGIUM = 205,
82 AIS_DAC_206_BELARUS = 206,
83 AIS_DAC_207_BULGARIA = 207,
84 AIS_DAC_208_VATICAN_CITY_STATE = 208,
85 AIS_DAC_209_CYPRUS = 209,
86 AIS_DAC_210_CYPRUS = 210,
87 AIS_DAC_211_GERMANY = 211,
88 AIS_DAC_212_CYPRUS = 212,
89 AIS_DAC_213_GEORGIA = 213,
90 AIS_DAC_214_MOLDOVA = 214,
91 AIS_DAC_215_MALTA = 215,
92 AIS_DAC_216_ARMENIA = 216,
93 AIS_DAC_218_GERMANY = 218,
94 AIS_DAC_219_DENMARK = 219,
95 AIS_DAC_220_DENMARK = 220,
96 AIS_DAC_224_SPAIN = 224,
97 AIS_DAC_225_SPAIN = 225,
98 AIS_DAC_226_FRANCE = 226,
99 AIS_DAC_227_FRANCE = 227,
100 AIS_DAC_228_FRANCE = 228,
101 AIS_DAC_229_MALTA = 229,
102 AIS_DAC_230_FINLAND = 230,
103 AIS_DAC_231_FAROE_ISLANDS = 231,
104 AIS_DAC_232_UNITED_KINGDOM_OF_GREAT_BRITAIN_AND_NORTHERN_IRELAND = 232,
105 AIS_DAC_233_UNITED_KINGDOM_OF_GREAT_BRITAIN_AND_NORTHERN_IRELAND = 233,
106 AIS_DAC_234_UNITED_KINGDOM_OF_GREAT_BRITAIN_AND_NORTHERN_IRELAND = 234,
107 AIS_DAC_235_UNITED_KINGDOM_OF_GREAT_BRITAIN_AND_NORTHERN_IRELAND = 235,
108 AIS_DAC_236_GIBRALTAR = 236,
109 AIS_DAC_237_GREECE = 237,
110 AIS_DAC_238_CROATIA = 238,
111 AIS_DAC_239_GREECE = 239,
112 AIS_DAC_240_GREECE = 240,
113 AIS_DAC_241_GREECE = 241,
114 AIS_DAC_242_MOROCCO = 242,
115 AIS_DAC_243_HUNGARY = 243,
116 AIS_DAC_244_NETHERLANDS = 244,
117 AIS_DAC_245_NETHERLANDS = 245,
118 AIS_DAC_246_NETHERLANDS = 246,
119 AIS_DAC_247_ITALY = 247,
120 AIS_DAC_248_MALTA = 248,
121 AIS_DAC_249_MALTA = 249,
122 AIS_DAC_250_IRELAND = 250,
123 AIS_DAC_251_ICELAND = 251,
124 AIS_DAC_252_LIECHTENSTEIN = 252,
125 AIS_DAC_253_LUXEMBOURG = 253,
126 AIS_DAC_254_MONACO = 254,
127 AIS_DAC_255_MADEIRA = 255,
128 AIS_DAC_256_MALTA = 256,
129 AIS_DAC_257_NORWAY = 257,
130 AIS_DAC_258_NORWAY = 258,
131 AIS_DAC_259_NORWAY = 259,
132 AIS_DAC_261_POLAND = 261,
133 AIS_DAC_262_MONTENEGRO = 262,
134 AIS_DAC_263_PORTUGAL = 263,
135 AIS_DAC_264_ROMANIA = 264,
136 AIS_DAC_265_SWEDEN = 265,
137 AIS_DAC_266_SWEDEN = 266,
138 AIS_DAC_267_SLOVAKIA = 267,
139 AIS_DAC_268_SAN_MARINO = 268,
140 AIS_DAC_269_SWITZERLAND = 269,
141 AIS_DAC_270_CZECH_REPUBLIC = 270,
142 AIS_DAC_271_TURKEY = 271,
143 AIS_DAC_272_UKRAINE = 272,
144 AIS_DAC_273_RUSSIAN_FEDERATION = 273,
145 AIS_DAC_274_MACEDONIA = 274,
146 AIS_DAC_275_LATVIA = 275,
147 AIS_DAC_276_ESTONIA = 276,
148 AIS_DAC_277_LITHUANIA = 277,
149 AIS_DAC_278_SLOVENIA = 278,
150 AIS_DAC_279_SERBIA = 279,
151 AIS_DAC_301_ANGUILLA = 301,
152 AIS_DAC_303_ALASKA = 303,
153 AIS_DAC_304_ANTIGUA_AND_BARBUDA = 304,
154 AIS_DAC_305_ANTIGUA_AND_BARBUDA = 305,
155 AIS_DAC_306_NETHERLANDS_ANTILLES = 306,
156 AIS_DAC_307_ARUBA = 307,
157 AIS_DAC_308_BAHAMAS = 308,
158 AIS_DAC_309_BAHAMAS = 309,
159 AIS_DAC_310_BERMUDA = 310,
160 AIS_DAC_311_BAHAMAS = 311,
161 AIS_DAC_312_BELIZE = 312,
162 AIS_DAC_314_BARBADOS = 314,
163 AIS_DAC_316_CANADA = 316,
164 AIS_DAC_319_CAYMAN_ISLANDS = 319,
165 AIS_DAC_321_COSTA_RICA = 321,
166 AIS_DAC_323_CUBA = 323,
167 AIS_DAC_325_DOMINICA = 325,
168 AIS_DAC_327_DOMINICAN_REPUBLIC = 327,
169 AIS_DAC_329_GUADELOUPE = 329,
170 AIS_DAC_330_GRENADA = 330,
171 AIS_DAC_331_GREENLAND = 331,
172 AIS_DAC_332_GUATEMALA = 332,
173 AIS_DAC_334_HONDURAS = 334,
174 AIS_DAC_336_HAITI = 336,
175 AIS_DAC_338_UNITED_STATES_OF_AMERICA = 338,
176 AIS_DAC_339_JAMAICA = 339,
177 AIS_DAC_341_SAINT_KITTS_AND_NEVIS = 341,
178 AIS_DAC_343_SAINT_LUCIA = 343,
179 AIS_DAC_345_MEXICO = 345,
180 AIS_DAC_347_MARTINIQUE = 347,
181 AIS_DAC_348_MONTSERRAT = 348,
182 AIS_DAC_350_NICARAGUA = 350,
183 AIS_DAC_351_PANAMA = 351,
184 AIS_DAC_352_PANAMA = 352,
185 AIS_DAC_353_PANAMA = 353,
186 AIS_DAC_354_PANAMA = 354,
187 AIS_DAC_355_PANAMA = 355,
188 AIS_DAC_356_PANAMA = 356,
189 AIS_DAC_357_PANAMA = 357,
190 AIS_DAC_358_PUERTO_RICO = 358,
191 AIS_DAC_359_EL_SALVADOR = 359,
192 AIS_DAC_361_SAINT_PIERRE_AND_MIQUELON = 361,
193 AIS_DAC_362_TRINIDAD_AND_TOBAGO = 362,
194 AIS_DAC_364_TURKS_AND_CAICOS_ISLANDS = 364,
195 AIS_DAC_366_UNITED_STATES_OF_AMERICA = 366,
196 AIS_DAC_367_UNITED_STATES_OF_AMERICA = 367,
197 AIS_DAC_368_UNITED_STATES_OF_AMERICA = 368,
198 AIS_DAC_369_UNITED_STATES_OF_AMERICA = 369,
199 AIS_DAC_370_PANAMA = 370,
200 AIS_DAC_371_PANAMA = 371,
201 AIS_DAC_372_PANAMA = 372,
202 AIS_DAC_373_PANAMA = 373,
203 AIS_DAC_375_SAINT_VINCENT_AND_THE_GRENADINES = 375,
204 AIS_DAC_376_SAINT_VINCENT_AND_THE_GRENADINES = 376,
205 AIS_DAC_377_SAINT_VINCENT_AND_THE_GRENADINES = 377,
206 AIS_DAC_378_BRITISH_VIRGIN_ISLANDS = 378,
207 AIS_DAC_379_UNITED_STATES_VIRGIN_ISLANDS = 379,
208 AIS_DAC_401_AFGHANISTAN = 401,
209 AIS_DAC_403_SAUDI_ARABIA = 403,
210 AIS_DAC_405_BANGLADESH = 405,
211 AIS_DAC_408_BAHRAIN = 408,
212 AIS_DAC_410_BHUTAN = 410,
213 AIS_DAC_412_CHINA = 412,
214 AIS_DAC_413_CHINA = 413,
215 AIS_DAC_414_CHINA = 414,
216 AIS_DAC_416_TAIWAN = 416,
217 AIS_DAC_417_SRI_LANKA = 417,
218 AIS_DAC_419_INDIA = 419,
219 AIS_DAC_422_IRAN = 422,
220 AIS_DAC_423_AZERBAIJAN = 423,
221 AIS_DAC_425_IRAQ = 425,
222 AIS_DAC_428_ISRAEL = 428,
223 AIS_DAC_431_JAPAN = 431,
224 AIS_DAC_432_JAPAN = 432,
225 AIS_DAC_434_TURKMENISTAN = 434,
226 AIS_DAC_436_KAZAKHSTAN = 436,
227 AIS_DAC_437_UZBEKISTAN = 437,
228 AIS_DAC_438_JORDAN = 438,
229 AIS_DAC_440_KOREA = 440,
230 AIS_DAC_441_KOREA = 441,
231 AIS_DAC_443_STATE_OF_PALESTINE = 443,
232 AIS_DAC_445_DEMOCRATIC_PEOPLES_REPUBLIC_OF_KOREA = 445,
233 AIS_DAC_447_KUWAIT = 447,
234 AIS_DAC_450_LEBANON = 450,
235 AIS_DAC_451_KYRGYZ_REPUBLIC = 451,
236 AIS_DAC_453_MACAO = 453,
237 AIS_DAC_455_MALDIVES = 455,
238 AIS_DAC_457_MONGOLIA = 457,
239 AIS_DAC_459_NEPAL = 459,
240 AIS_DAC_461_OMAN = 461,
241 AIS_DAC_463_PAKISTAN = 463,
242 AIS_DAC_466_QATAR = 466,
243 AIS_DAC_468_SYRIAN_ARAB_REPUBLIC = 468,
244 AIS_DAC_470_UNITED_ARAB_EMIRATES = 470,
245 AIS_DAC_472_TAJIKISTAN = 472,
246 AIS_DAC_473_YEMEN = 473,
247 AIS_DAC_475_YEMEN = 475,
248 AIS_DAC_477_HONG_KONG = 477,
249 AIS_DAC_478_BOSNIA_AND_HERZEGOVINA = 478,
250 AIS_DAC_501_ADELIE_LAND = 501,
251 AIS_DAC_503_AUSTRALIA = 503,
252 AIS_DAC_506_MYANMAR = 506,
253 AIS_DAC_508_BRUNEI_DARUSSALAM = 508,
254 AIS_DAC_510_MICRONESIA = 510,
255 AIS_DAC_511_PALAU = 511,
256 AIS_DAC_512_NEW_ZEALAND = 512,
257 AIS_DAC_514_CAMBODIA = 514,
258 AIS_DAC_515_CAMBODIA = 515,
259 AIS_DAC_516_CHRISTMAS_ISLAND = 516,
260 AIS_DAC_518_COOK_ISLANDS = 518,
261 AIS_DAC_520_FIJI = 520,
262 AIS_DAC_523_COCOS = 523,
263 AIS_DAC_525_INDONESIA = 525,
264 AIS_DAC_529_KIRIBATI = 529,
265 AIS_DAC_531_LAO_PEOPLES_DEMOCRATIC_REPUBLIC = 531,
266 AIS_DAC_533_MALAYSIA = 533,
267 AIS_DAC_536_NORTHERN_MARIANA_ISLANDS = 536,
268 AIS_DAC_538_MARSHALL_ISLANDS = 538,
269 AIS_DAC_540_NEW_CALEDONIA = 540,
270 AIS_DAC_542_NIUE = 542,
271 AIS_DAC_544_NAURU = 544,
272 AIS_DAC_546_FRENCH_POLYNESIA = 546,
273 AIS_DAC_548_PHILIPPINES = 548,
274 AIS_DAC_553_PAPUA_NEW_GUINEA = 553,
275 AIS_DAC_555_PITCAIRN_ISLAND = 555,
276 AIS_DAC_557_SOLOMON_ISLANDS = 557,
277 AIS_DAC_559_AMERICAN_SAMOA = 559,
278 AIS_DAC_561_SAMOA = 561,
279 AIS_DAC_563_SINGAPORE = 563,
280 AIS_DAC_564_SINGAPORE = 564,
281 AIS_DAC_565_SINGAPORE = 565,
282 AIS_DAC_566_SINGAPORE = 566,
283 AIS_DAC_567_THAILAND = 567,
284 AIS_DAC_570_TONGA = 570,
285 AIS_DAC_572_TUVALU = 572,
286 AIS_DAC_574_VIETNAM = 574,
287 AIS_DAC_576_VANUATU = 576,
288 AIS_DAC_577_VANUATU = 577,
289 AIS_DAC_578_WALLIS_AND_FUTUNA_ISLANDS = 578,
290 AIS_DAC_601_SOUTH_AFRICA = 601,
291 AIS_DAC_603_ANGOLA = 603,
292 AIS_DAC_605_ALGERIA = 605,
293 AIS_DAC_607_SAINT_PAUL_AND_AMSTERDAM_ISLANDS = 607,
294 AIS_DAC_608_ASCENSION_ISLAND = 608,
295 AIS_DAC_609_BURUNDI = 609,
296 AIS_DAC_610_BENIN = 610,
297 AIS_DAC_611_BOTSWANA = 611,
298 AIS_DAC_612_CENTRAL_AFRICAN_REPUBLIC = 612,
299 AIS_DAC_613_CAMEROON = 613,
300 AIS_DAC_615_CONGO = 615,
301 AIS_DAC_616_COMOROS = 616,
302 AIS_DAC_617_CABO_VERDE = 617,
303 AIS_DAC_618_CROZET_ARCHIPELAGO = 618,
304 AIS_DAC_619_COTE_DIVOIRE = 619,
305 AIS_DAC_620_COMOROS = 620,
306 AIS_DAC_621_DJIBOUTI = 621,
307 AIS_DAC_622_EGYPT = 622,
308 AIS_DAC_624_ETHIOPIA = 624,
309 AIS_DAC_625_ERITREA = 625,
310 AIS_DAC_626_GABONESE_REPUBLIC = 626,
311 AIS_DAC_627_GHANA = 627,
312 AIS_DAC_629_GAMBIA = 629,
313 AIS_DAC_630_GUINEABISSAU = 630,
314 AIS_DAC_631_EQUATORIAL_GUINEA = 631,
315 AIS_DAC_632_GUINEA = 632,
316 AIS_DAC_633_BURKINA_FASO = 633,
317 AIS_DAC_634_KENYA = 634,
318 AIS_DAC_635_KERGUELEN_ISLANDS = 635,
319 AIS_DAC_636_LIBERIA = 636,
320 AIS_DAC_637_LIBERIA = 637,
321 AIS_DAC_638_SOUTH_SUDAN = 638,
322 AIS_DAC_642_LIBYA = 642,
323 AIS_DAC_644_LESOTHO = 644,
324 AIS_DAC_645_MAURITIUS = 645,
325 AIS_DAC_647_MADAGASCAR = 647,
326 AIS_DAC_649_MALI = 649,
327 AIS_DAC_650_MOZAMBIQUE = 650,
328 AIS_DAC_654_MAURITANIA = 654,
329 AIS_DAC_655_MALAWI = 655,
330 AIS_DAC_656_NIGER = 656,
331 AIS_DAC_657_NIGERIA = 657,
332 AIS_DAC_659_NAMIBIA = 659,
333 AIS_DAC_660_REUNION = 660,
334 AIS_DAC_661_RWANDA = 661,
335 AIS_DAC_662_SUDAN = 662,
336 AIS_DAC_663_SENEGAL = 663,
337 AIS_DAC_664_SEYCHELLES = 664,
338 AIS_DAC_665_SAINT_HELENA = 665,
339 AIS_DAC_666_SOMALIA = 666,
340 AIS_DAC_667_SIERRA_LEONE = 667,
341 AIS_DAC_668_SAO_TOME_AND_PRINCIPE = 668,
342 AIS_DAC_669_SWAZILAND = 669,
343 AIS_DAC_670_CHAD = 670,
344 AIS_DAC_671_TOGOLESE_REPUBLIC = 671,
345 AIS_DAC_672_TUNISIA = 672,
346 AIS_DAC_674_TANZANIA = 674,
347 AIS_DAC_675_UGANDA = 675,
348 AIS_DAC_676_DEMOCRATIC_REPUBLIC_OF_THE_CONGO = 676,
349 AIS_DAC_677_TANZANIA = 677,
350 AIS_DAC_678_ZAMBIA = 678,
351 AIS_DAC_679_ZIMBABWE = 679,
352 AIS_DAC_701_ARGENTINE_REPUBLIC = 701,
353 AIS_DAC_710_BRAZIL = 710,
354 AIS_DAC_720_BOLIVIA = 720,
355 AIS_DAC_725_CHILE = 725,
356 AIS_DAC_730_COLOMBIA = 730,
357 AIS_DAC_735_ECUADOR = 735,
358 AIS_DAC_740_FALKLAND_ISLANDS = 740,
359 AIS_DAC_745_GUIANA = 745,
360 AIS_DAC_750_GUYANA = 750,
361 AIS_DAC_755_PARAGUAY = 755,
362 AIS_DAC_760_PERU = 760,
363 AIS_DAC_765_SURINAME = 765,
364 AIS_DAC_770_URUGUAY = 770,
365 AIS_DAC_775_VENEZUELA = 775
366 };
367
368 class AisPoint {
369 public:
370 double lng_deg;
371 double lat_deg;
372
373 AisPoint();
374 AisPoint(double lng_deg_, double lat_deg_);
375 };
376 ostream& operator<< (ostream &o, const AisPoint &position);
377
378 //////////////////////////////////////////////////////////////////////
379 // Support class for decoding
380 //////////////////////////////////////////////////////////////////////
381 static const int MAX_BITS = 1192;
382
383 class AisBitset : protected bitset<MAX_BITS> {
384 public:
385 AisBitset();
386
387 AIS_STATUS ParseNmeaPayload(const char *nmea_payload, int pad);
388
389 int GetNumBits() const { return num_bits; }
390 int GetNumChars() const { return num_chars; }
391 int GetPosition() const { return current_position; }
392 int GetRemaining() const { return num_bits - current_position; }
393
394 const AisBitset& SeekRelative(int d) const;
395 const AisBitset& SeekTo(size_t pos) const;
396
397 bool operator[](size_t pos) const;
398
399 unsigned int ToUnsignedInt(const size_t start, const size_t len) const;
400 int ToInt(const size_t start, const size_t len) const;
401 string ToString(const size_t start, const size_t len) const;
402
403 const AisPoint ToAisPoint(const size_t start, const size_t point_size) const;
404
405 // Visible for testing.
406 static bitset<6> Reverse(const bitset<6> &bits);
407
408 protected:
409 int num_bits;
410 int num_chars;
411
412 static bool nmea_ord_initialized_;
413 static bitset<6> nmea_ord_[128];
414 static const char bits_to_char_tbl_[];
415
416 static void InitNmeaOrd();
417
418 private:
419 // This will help uncover dicontinuities when querying sequential bits, i.e.
420 // when we query a bit sequence that is not in direct succession of the
421 // previous one. In the future, we may use this to automatically determine
422 // the next read location.
423 // This field is also used to determine the number of remaining bits after the
424 // last read position.
425 // That being said, the 'start' argument in all the 'To...' methods above is
426 // redundant and the only purpose is to discover typos in the bit positions in
427 // each message's parse method, i.e. debugging.
428 mutable int current_position;
429 };
430
431 class AisMsg {
432 public:
433 int message_id;
434 int repeat_indicator;
435 int mmsi;
436
437 // TODO(schwehr): make status private and have accessors.
438 bool had_error() const { return status != AIS_OK; }
439 AIS_STATUS get_error() const { return status; }
440
441 virtual ~AisMsg() {}
442
443 protected:
444 AIS_STATUS status; // AIS_OK or error code
445 int num_chars; // Number of characters in the nmea_payload.
446 size_t num_bits; // Number of bits in the nmea_payload.
447 AisBitset bits; // The bitset that was constructed out of the nmea_payload.
448
449 AisMsg() : status(AIS_UNINITIALIZED), num_chars(0), num_bits(0), bits() {}
450 AisMsg(const char *nmea_payload, const size_t pad);
451
452 // Returns true if the msg is in a good state "so far", i.e. either AIS_OK or
453 // AIS_UNINITIALIZED.
454 bool CheckStatus() const;
455 };
456
457 // TODO(schwehr): factor out commstate from all messages?
458 class Ais1_2_3 : public AisMsg {
459 public:
460 int nav_status;
461 bool rot_over_range;
462 int rot_raw;
463 float rot;
464 float sog; // Knots.
465 int position_accuracy;
466 AisPoint position;
467 float cog; // Degrees.
468 int true_heading;
469 // TODO(schwehr): What about a leap second when timestamp 60 may be valid?
470 int timestamp;
471 int special_manoeuvre;
472 int spare;
473 bool raim;
474
475 // COMM state SOTDMA msgs 1 and 2
476 int sync_state; // SOTDMA and ITDMA
477 bool slot_timeout_valid;
478 int slot_timeout;
479
480 // Based on slot_timeout which ones are valid
481 bool received_stations_valid;
482 int received_stations;
483
484 bool slot_number_valid;
485 int slot_number;
486
487 bool utc_valid;
488 int utc_hour;
489 int utc_min;
490 int utc_spare;
491
492 bool slot_offset_valid;
493 int slot_offset;
494
495 // ITDMA - msg type 3
496 bool slot_increment_valid;
497 int slot_increment;
498
499 bool slots_to_allocate_valid;
500 int slots_to_allocate;
501
502 bool keep_flag_valid;
503 bool keep_flag; // 3.3.7.3.2 Annex 2 ITDMA. Table 20
504
505 Ais1_2_3(const char *nmea_payload, const size_t pad);
506 };
507 ostream& operator<< (ostream &o, const Ais1_2_3 &msg);
508
509 // 4 bsreport and 11 utc date response
510 class Ais4_11 : public AisMsg {
511 public:
512 int year;
513 int month;
514 int day;
515 int hour;
516 int minute;
517 int second;
518 int position_accuracy;
519 AisPoint position;
520 int fix_type;
521 int transmission_ctl;
522 int spare;
523 bool raim;
524
525 // COMM state SOTDMA msgs 1 and 2
526 int sync_state;
527 int slot_timeout;
528
529 // Based on slot_timeout which ones are valid
530 bool received_stations_valid;
531 int received_stations;
532
533 bool slot_number_valid;
534 int slot_number;
535
536 bool utc_valid;
537 int utc_hour;
538 int utc_min;
539 int utc_spare;
540
541 bool slot_offset_valid;
542 int slot_offset;
543
544 // **NO** ITDMA
545 Ais4_11(const char *nmea_payload, const size_t pad);
546 };
547 ostream& operator<< (ostream &o, const Ais4_11 &msg);
548
549 class Ais5 : public AisMsg {
550 public:
551 int ais_version;
552 int imo_num;
553 string callsign;
554 string name;
555 int type_and_cargo;
556 int dim_a;
557 int dim_b;
558 int dim_c;
559 int dim_d;
560 int fix_type;
561 int eta_month;
562 int eta_day;
563 int eta_hour;
564 int eta_minute;
565 float draught; // present static draft. m
566 string destination;
567 int dte;
568 int spare;
569
570 Ais5(const char *nmea_payload, const size_t pad);
571 };
572 ostream& operator<< (ostream &o, const Ais5 &msg);
573
574 // AIS Binary Broadcast message ... parent to many
575 class Ais6 : public AisMsg {
576 public:
577 int seq; // sequence number
578 int mmsi_dest;
579 bool retransmit;
580 int spare;
581 int dac; // dac+fi = app id
582 int fi;
583
584 // TODO(schwehr): how to make Ais6 protected?
585 Ais6(const char *nmea_payload, const size_t pad);
586
587 protected:
588 Ais6() {}
589 };
590 ostream& operator<< (ostream &o, const Ais6 &msg);
591
592 // http://www.e-navigation.nl/content/monitoring-aids-navigation
593 // Zeni Lite Buoy Co., Ltd buoy status.
594 class Ais6_0_0 : public Ais6 {
595 public:
596 int sub_id;
597 float voltage;
598 float current;
599 bool dc_power_supply; // False is AC.
600 bool light_on;
601 bool battery_low;
602 bool off_position;
603 int spare2;
604
605 Ais6_0_0(const char *nmea_payload, const size_t pad);
606 };
607 ostream& operator<< (ostream &o, const Ais6_0_0 &msg);
608
609 // Text message. ITU 1371-1
610 class Ais6_1_0 : public Ais6 {
611 public:
612 bool ack_required;
613 int msg_seq;
614 string text;
615 int spare2;
616
617 Ais6_1_0(const char *nmea_payload, const size_t pad);
618 };
619 ostream& operator<< (ostream &o, const Ais6_1_0 &msg);
620
621 // Application ack. ITU 1371-1
622 class Ais6_1_1 : public Ais6 {
623 public:
624 int ack_dac;
625 int msg_seq;
626 int spare2;
627
628 Ais6_1_1(const char *nmea_payload, const size_t pad);
629 };
630 ostream& operator<< (ostream &o, const Ais6_1_1 &msg);
631
632 // Interrogation for a DAC/FI. ITU 1371-1
633 class Ais6_1_2 : public Ais6 {
634 public:
635 int req_dac;
636 int req_fi;
637 // TODO(schwehr): spare2?
638
639 Ais6_1_2(const char *nmea_payload, const size_t pad);
640 };
641 ostream& operator<< (ostream &o, const Ais6_1_2 &msg);
642
643 // Capability interogation. ITU 1371-1
644 class Ais6_1_3 : public Ais6 {
645 public:
646 unsigned int req_dac;
647 unsigned int spare2;
648 unsigned int spare3;
649 unsigned int spare4;
650
651 Ais6_1_3(const char *nmea_payload, const size_t pad);
652 };
653 ostream& operator<< (ostream &o, const Ais6_1_3 &msg);
654
655 // Capability interogation reply. ITU 1371-1
656 // 5.4 International function message 4: Capability reply
657 class Ais6_1_4 : public Ais6 {
658 public:
659 int ack_dac;
660 std::array<int, 64> capabilities;
661 std::array<int, 64> cap_reserved;
662 // 126 bits of spare. So dumb.
663 int spare2;
664 int spare3;
665 int spare4;
666 int spare5;
667
668 Ais6_1_4(const char *nmea_payload, const size_t pad);
669 };
670 ostream& operator<< (ostream &o, const Ais6_1_4 &msg);
671
672 // International function message 5: Application ack to addr binary message.
673 class Ais6_1_5 : public Ais6 {
674 public:
675 // TODO(schwehr): How to handle the sequence number and retransmit flag?
676 int ack_dac;
677 int ack_fi;
678 int seq_num;
679 bool ai_available; // TODO(schwehr): AI? Is this the dac/fi being acked?
680 int ai_response;
681 int spare;
682 int spare2;
683
684 Ais6_1_5(const char *nmea_payload, const size_t pad);
685 };
686
687 // IMO Circ 236 Dangerous cargo indication
688 // Not to be transmitted after 2012-Jan-01
689 class Ais6_1_12 : public Ais6 {
690 public:
691 string last_port;
692 int utc_month_dep; // actual time of departure
693 int utc_day_dep;
694 int utc_hour_dep;
695 int utc_min_dep;
696 string next_port;
697 int utc_month_next; // estimated arrival
698 int utc_day_next;
699 int utc_hour_next;
700 int utc_min_next;
701 string main_danger;
702 string imo_cat;
703 int un;
704 int value; // TODO(schwehr): units?
705 int value_unit;
706 int spare2;
707
708 Ais6_1_12(const char *nmea_payload, const size_t pad);
709 };
710 ostream& operator<< (ostream &o, const Ais6_1_12 &msg);
711
712
713 class Ais6_1_14_Window {
714 public:
715 AisPoint position;
716 int utc_hour_from;
717 int utc_min_from;
718 int utc_hour_to;
719 int utc_min_to;
720 int cur_dir;
721 float cur_speed;
722 };
723
724
725 // IMO Circ 236 Tidal window
726 // Not to be transmitted after 2012-Jan-01
727 class Ais6_1_14 : public Ais6 {
728 public:
729 int utc_month;
730 int utc_day;
731 vector<Ais6_1_14_Window> windows;
732
733 Ais6_1_14(const char *nmea_payload, const size_t pad);
734 };
735 ostream& operator<< (ostream &o, const Ais6_1_14 &msg);
736
737
738 // IMO Circ 289 Clearance time to enter port
739 class Ais6_1_18 : public Ais6 {
740 public:
741 int link_id;
742 int utc_month;
743 int utc_day;
744 int utc_hour;
745 int utc_min;
746 string port_berth;
747 string dest;
748 AisPoint position;
749 std::array<int, 2> spare2; // 32 bits per spare
750
751 Ais6_1_18(const char *nmea_payload, const size_t pad);
752 };
753 ostream& operator<< (ostream &o, const Ais6_1_18 &msg);
754
755
756 // IMO Circ 289 Berthing data
757 class Ais6_1_20 : public Ais6 {
758 public:
759 int link_id;
760 int length;
761 float depth;
762 int mooring_position;
763 int utc_month;
764 int utc_day;
765 int utc_hour;
766 int utc_min;
767 bool services_known;
768 // TODO(schwehr): enum of service types
769 std::array<int, 26> services;
770 string name;
771 AisPoint position;
772
773 Ais6_1_20(const char *nmea_payload, const size_t pad);
774 };
775 ostream& operator<< (ostream &o, const Ais6_1_20 &msg);
776
777 class Ais6_1_25_Cargo {
778 public:
779 int code_type;
780 bool imdg_valid; // also set with BC
781 int imdg;
782 bool spare_valid;
783 int spare; // imdg or dc or marpols
784 bool un_valid;
785 int un;
786 bool bc_valid;
787 int bc;
788 bool marpol_oil_valid;
789 int marpol_oil;
790 bool marpol_cat_valid;
791 int marpol_cat;
792
793 Ais6_1_25_Cargo();
794 // TODO(schwehr): Add a constructor from an AisBitset.
795 };
796
797 // IMO Circ 289 Dangerous cargo indication 2
798 // Replaces 8_1_12?
799 class Ais6_1_25 : public Ais6 {
800 public:
801 int amount_unit;
802 int amount;
803
804 vector<Ais6_1_25_Cargo> cargos; // 0 to 17 cargo entries
805
806 Ais6_1_25(const char *nmea_payload, const size_t pad);
807 };
808 ostream& operator<< (ostream &o, const Ais6_1_25 &msg);
809
810 // TODO(schwehr): Addressed sensor report 6_1_26.
811 // TODO(schwehr): IMO Circ 289 Route information 6_1_28.
812 // TODO(schwehr): IMO Circ 289 Text description 6_1_30.
813
814 // IMO Circ 289
815 // Warning: The bit encoding for 6_1_14_Window and 6_1_32 on
816 // the wire has x and y in a different order.
817 // TODO(schwehr): Reuse Ais6_1_14_Window
818 class Ais6_1_32_Window {
819 public:
820 AisPoint position;
821 int from_utc_hour;
822 int from_utc_min;
823 int to_utc_hour;
824 int to_utc_min;
825 int cur_dir;
826 float cur_speed; // knots
827
828 Ais6_1_32_Window();
829 };
830
831
832 // IMO Circ 289 Tidal window
833 class Ais6_1_32 : public Ais6 {
834 public:
835 int utc_month;
836 int utc_day;
837 vector<Ais6_1_32_Window> windows;
838
839 Ais6_1_32(const char *nmea_payload, const size_t pad);
840 };
841 ostream& operator<< (ostream &o, const Ais6_1_32 &msg);
842
843 // Number of persons on board. ITU 1371-1
844 class Ais6_1_40 : public Ais6 {
845 public:
846 int persons;
847 int spare2;
848
849 Ais6_1_40(const char *nmea_payload, const size_t pad);
850 };
851 ostream& operator<< (ostream &o, const Ais6_1_40 &msg);
852
853 //////////////////////////////////////////////////////////////////////
854
855 // 7 and 13 are ACKs for msg 6 and 12
856 class Ais7_13 : public AisMsg {
857 public:
858 int spare;
859
860 vector<int> dest_mmsi;
861 vector<int> seq_num;
862
863 Ais7_13(const char *nmea_payload, const size_t pad);
864 };
865 ostream& operator<< (ostream &o, const Ais7_13 &msg);
866
867 // AIS Binary Broadcast message ... parent to many
868 class Ais8 : public AisMsg {
869 public:
870 int spare;
871 // TODO(schwehr): seq? // ITU M.R. 1371-3 Anex 2 5.3.1
872 int dac; // dac+fi = app id
873 int fi;
874
875 // TODO(schwehr): make Ais8 protected
876 Ais8(const char *nmea_payload, const size_t pad);
877
878 protected:
879 Ais8() {}
880 };
881 ostream& operator<< (ostream &o, const Ais8 &msg);
882
883 // Text telegram ITU 1371-1
884 class Ais8_1_0 : public Ais8 {
885 public:
886 bool ack_required;
887 int msg_seq;
888 string text;
889 int spare2;
890
891 Ais8_1_0(const char *nmea_payload, size_t pad);
892 };
893 ostream& operator<< (ostream &o, const Ais8_1_0 &msg);
894
895 // 8_1_1 No message
896 // 8_1_2 No message
897 // 8_1_3 No message
898 // 8_1_4 No message
899
900 // IMO Circ 289 met hydro - Not to be transmitted after 2013-Jan-01
901 // See also IMO Circ 236
902 class Ais8_1_11 : public Ais8 {
903 public:
904 AisPoint position;
905 int day;
906 int hour;
907 int minute;
908 int wind_ave; // kts
909 int wind_gust; // kts
910 int wind_dir;
911 int wind_gust_dir;
912 float air_temp; // C
913 int rel_humid;
914 float dew_point;
915 float air_pres;
916 int air_pres_trend;
917 float horz_vis; // NM
918 float water_level; // m
919 int water_level_trend;
920 float surf_cur_speed;
921 int surf_cur_dir;
922 float cur_speed_2; // kts
923 int cur_dir_2;
924 int cur_depth_2; // m
925 float cur_speed_3; // kts
926 int cur_dir_3;
927 int cur_depth_3; // m
928 float wave_height; // m
929 int wave_period;
930 int wave_dir;
931 float swell_height;
932 int swell_period;
933 int swell_dir;
934 int sea_state; // beaufort scale
935 float water_temp;
936 int precip_type;
937 float salinity; // Part per mil (1/1000).
938 int ice; // yes/no/undef/unknown
939 int spare2;
940 int extended_water_level; // OHMEX uses this for extra water level precision
941
942 Ais8_1_11(const char *nmea_payload, size_t pad);
943 };
944 ostream& operator<< (ostream &o, const Ais8_1_11 &msg);
945
946
947 // IMO Circ 236 Fairway closed - Not to be transmitted after 2012-Jan-01
948 class Ais8_1_13 : public Ais8 {
949 public:
950 string reason;
951 string location_from;
952 string location_to;
953 int radius;
954 int units;
955 // TODO(schwehr): utc? warning: day/month out of order
956 int day_from;
957 int month_from;
958 int hour_from;
959 int minute_from;
960
961 int day_to;
962 int month_to;
963 int hour_to;
964 int minute_to;
965 int spare2;
966
967 Ais8_1_13(const char *nmea_payload, const size_t pad);
968 };
969 ostream& operator<< (ostream &o, const Ais8_1_13 &msg);
970
971 // IMO Circ 236 Extended ship static and voyage data
972 // Not to be transmitted after 2012-Jan-01
973 class Ais8_1_15 : public Ais8 {
974 public:
975 float air_draught;
976 int spare2;
977
978 Ais8_1_15(const char *nmea_payload, const size_t pad);
979 };
980 ostream& operator<< (ostream &o, const Ais8_1_15 &msg);
981
982 // IMO Circ 236 Number of persons on board
983 class Ais8_1_16 : public Ais8 {
984 public:
985 int persons;
986 int spare2;
987
988 Ais8_1_16(const char *nmea_payload, const size_t pad);
989 };
990 ostream& operator<< (ostream &o, const Ais8_1_16 &msg);
991
992 class Ais8_1_17_Target {
993 public:
994 int type;
995 string id;
996 int spare;
997 AisPoint position;
998 int cog;
999 int timestamp;
1000 int sog;
1001
1002 Ais8_1_17_Target();
1003 };
1004
1005 // IMO Circ 236 VTS Generated/synthetic targets
1006 class Ais8_1_17 : public Ais8 {
1007 public:
1008 vector<Ais8_1_17_Target> targets;
1009
1010 Ais8_1_17(const char *nmea_payload, const size_t pad);
1011 };
1012 ostream& operator<< (ostream &o, const Ais8_1_17 &msg);
1013
1014 // No 8_1_18
1015
1016 // IMO Circ 289 Marine traffic signal
1017 class Ais8_1_19 : public Ais8 {
1018 public:
1019 int link_id;
1020 string name;
1021 AisPoint position; // funny bit count
1022 int status;
1023 int signal;
1024 int utc_hour_next;
1025 int utc_min_next;
1026 int next_signal;
1027 std::array<int, 4> spare2;
1028
1029 Ais8_1_19(const char *nmea_payload, const size_t pad);
1030 };
1031 ostream& operator<< (ostream &o, const Ais8_1_19 &msg);
1032
1033 // No message 8_1_20
1034
1035 // IMO Circ 289 Weather observation report from ship
1036 class Ais8_1_21 : public Ais8 {
1037 public:
1038 int type_wx_report;
1039
1040 // TYPE 0
1041 string location;
1042 AisPoint position; // 25, 24 bits
1043 int utc_day;
1044 int utc_hour;
1045 int utc_min;
1046 // wx - use wx[0]
1047 float horz_viz; // nautical miles
1048 int humidity; // %
1049 int wind_speed; // ave knots
1050 int wind_dir;
1051 float pressure; // hPa - float needed for type 1
1052 int pressure_tendency;
1053 float air_temp; // C
1054 float water_temp; // C
1055 int wave_period; // s
1056 float wave_height;
1057 int wave_dir;
1058 float swell_height; // m
1059 int swell_dir;
1060 int swell_period; // s
1061 int spare2;
1062
1063 // TYPE 1 - !@#$!!!!!
1064 // x, y
1065 int utc_month;
1066 // utc_day, hour, min
1067 int cog;
1068 float sog;
1069 int heading; // Assume this is true degrees????
1070 // pressure defined in type 0
1071 float rel_pressure; // 3 hour hPa
1072 // pressure_tendenc defined in type 0
1073 // wind_dir defined in type 0
1074 float wind_speed_ms; // m/s
1075 int wind_dir_rel;
1076 float wind_speed_rel; // m/s
1077 float wind_gust_speed; // m/s
1078 int wind_gust_dir;
1079 int air_temp_raw; // TODO(schwehr): Convert this to C. Kelvin makes no sense
1080 // humidity defined in type 0
1081 // sea_temp_k
1082 int water_temp_raw; // TODO(schwehr): fix this
1083 // hor_viz
1084 int wx[3]; // current, past 1, past 2
1085 int cloud_total;
1086 int cloud_low;
1087 int cloud_low_type;
1088 int cloud_middle_type;
1089 int cloud_high_type;
1090 float alt_lowest_cloud_base;
1091 // wave_period
1092 // wave_height
1093 // swell_dir
1094 // swell_period
1095 // swell_height
1096 int swell_dir_2;
1097 int swell_period_2;
1098 float swell_height_2;
1099 float ice_thickness; // Network is cm, storing m.
1100 int ice_accretion;
1101 int ice_accretion_cause;
1102 int sea_ice_concentration;
1103 int amt_type_ice;
1104 int ice_situation;
1105 int ice_devel;
1106 int bearing_ice_edge;
1107
1108 Ais8_1_21(const char *nmea_payload, const size_t pad);
1109 };
1110 ostream& operator<< (ostream &o, const Ais8_1_21 &msg);
1111
1112
1113 const size_t AIS8_1_22_NUM_NAMES = 128;
1114 const size_t AIS8_1_22_SUBAREA_SIZE = 87;
1115 extern const char *ais8_1_22_notice_names[AIS8_1_22_NUM_NAMES];
1116
1117 enum Ais8_1_22_AreaShapeEnum {
1118 AIS8_1_22_SHAPE_ERROR = -1,
1119 AIS8_1_22_SHAPE_CIRCLE = 0, // OR Point.
1120 AIS8_1_22_SHAPE_RECT = 1,
1121 AIS8_1_22_SHAPE_SECTOR = 2,
1122 AIS8_1_22_SHAPE_POLYLINE = 3,
1123 AIS8_1_22_SHAPE_POLYGON = 4,
1124 AIS8_1_22_SHAPE_TEXT = 5,
1125 AIS8_1_22_SHAPE_RESERVED_6 = 6,
1126 AIS8_1_22_SHAPE_RESERVED_7 = 7
1127 };
1128
1129 extern const char *ais8_1_22_shape_names[8];
1130
1131 // Sub-Areas for the Area Notice class
1132
1133 class Ais8_1_22_SubArea {
1134 public:
1135 virtual Ais8_1_22_AreaShapeEnum getType() const = 0;
1136 virtual ~Ais8_1_22_SubArea() {}
1137 };
1138
1139 Ais8_1_22_SubArea*
1140 ais8_1_22_subarea_factory(const AisBitset &bs,
1141 const size_t offset);
1142
1143 // or Point if radius is 0
1144 class Ais8_1_22_Circle : public Ais8_1_22_SubArea {
1145 public:
1146 AisPoint position; // Longitude and latitude.
1147 // Going to assume that the precision is not useful.
1148 int precision; // How many decimal places for x and y.
1149 int radius_m;
1150 unsigned int spare; // 18 bits.
1151
1152 Ais8_1_22_Circle(const AisBitset &bs, const size_t offset);
1153 ~Ais8_1_22_Circle() {}
1154 Ais8_1_22_AreaShapeEnum getType() const {return AIS8_1_22_SHAPE_CIRCLE;}
1155 };
1156
1157 class Ais8_1_22_Rect : public Ais8_1_22_SubArea {
1158 public:
1159 AisPoint position; // Longitude and latitude.
1160 int precision; // How many decimal places for x and y. Useless.
1161 int e_dim_m; // East dimension in meters.
1162 int n_dim_m;
1163 int orient_deg; // Orientation in degrees from true north.
1164 unsigned int spare; // 5 bits.
1165
1166 Ais8_1_22_Rect(const AisBitset &bs, const size_t offset);
1167 ~Ais8_1_22_Rect() {}
1168 Ais8_1_22_AreaShapeEnum getType() const {return AIS8_1_22_SHAPE_RECT;}
1169 };
1170
1171 class Ais8_1_22_Sector : public Ais8_1_22_SubArea {
1172 public:
1173 AisPoint position; // Longitude and latitude.
1174 // TODO(schwehr): precision in IMO, but not RTCM. Double check.
1175 int precision; // How many decimal places for x and y?
1176 int radius_m;
1177 int left_bound_deg;
1178 int right_bound_deg;
1179
1180 Ais8_1_22_Sector(const AisBitset &bs, const size_t offset);
1181 ~Ais8_1_22_Sector() {}
1182 Ais8_1_22_AreaShapeEnum getType() const {return AIS8_1_22_SHAPE_SECTOR;}
1183 };
1184
1185 // Or Waypoint
1186 // Must have a point before on the VDL
1187 // TODO(schwehr): do I bring in the prior point x, y, precision?
1188 class Ais8_1_22_Polyline : public Ais8_1_22_SubArea {
1189 public:
1190 // TODO(schwehr): int precision; // How many decimal places for x and y.
1191
1192 // Up to 4 points
1193 vector<float> angles;
1194 vector<float> dists_m;
1195 unsigned int spare; // 2 bit.
1196
1197 Ais8_1_22_Polyline(const AisBitset &bs, const size_t offset);
1198 ~Ais8_1_22_Polyline() {}
1199 Ais8_1_22_AreaShapeEnum getType() const {return AIS8_1_22_SHAPE_POLYLINE;}
1200 };
1201
1202 // TODO(schwehr): Bring in the prior point? And do we fold the sub area data
1203 // into one polygon if there are more than one?
1204 class Ais8_1_22_Polygon : public Ais8_1_22_SubArea {
1205 public:
1206 // TODO(schwehr): int precision; // How many decimal places for x and y.
1207
1208 // Up to 4 points in a first message, but aggregated if multiple sub areas
1209 vector<float> angles;
1210 vector<float> dists_m;
1211 unsigned int spare; // 2 bit
1212
1213 Ais8_1_22_Polygon(const AisBitset &bs, const size_t offset);
1214 ~Ais8_1_22_Polygon() {}
1215 Ais8_1_22_AreaShapeEnum getType() const {return AIS8_1_22_SHAPE_POLYGON;}
1216 };
1217
1218
1219 class Ais8_1_22_Text : public Ais8_1_22_SubArea {
1220 public:
1221 string text;
1222 // TODO(schwehr): spare?
1223
1224 Ais8_1_22_Text(const AisBitset &bs, const size_t offset);
1225 ~Ais8_1_22_Text() {}
1226 Ais8_1_22_AreaShapeEnum getType() const {return AIS8_1_22_SHAPE_TEXT;}
1227 };
1228
1229 // Area Notice class
1230
1231 class Ais8_1_22 : public Ais8 {
1232 public:
1233 int link_id; // 10 bit id to match up text blocks.
1234 int notice_type; // Area type / Notice Description.
1235 int month; // These are in UTC.
1236 int day;
1237 int hour;
1238 int minute;
1239 int duration_minutes; // Time from the start until the notice expires.
1240
1241 // 1 or more sub messages
1242 vector<Ais8_1_22_SubArea *> sub_areas;
1243
1244 Ais8_1_22(const char *nmea_payload, const size_t pad);
1245 ~Ais8_1_22();
1246 };
1247 ostream& operator<< (ostream& o, Ais8_1_22 const& msg);
1248
1249 // No message 8_1_23
1250
1251 // IMO Circ 289 Extended ship static and voyage-related
1252 class Ais8_1_24 : public Ais8 {
1253 public:
1254 int link_id;
1255 float air_draught; // m
1256 string last_port;
1257 std::array<std::string, 2> next_ports;
1258
1259 // TODO(schwehr): enum list of param types
1260 std::array<int, 26> solas_status; // 0 NA, 1 operational, 2 SNAFU, 3 no data
1261 int ice_class;
1262 int shaft_power; // horses
1263 int vhf;
1264 string lloyds_ship_type;
1265 int gross_tonnage;
1266 int laden_ballast;
1267 int heavy_oil;
1268 int light_oil;
1269 int diesel;
1270 int bunker_oil; // tonnes
1271 int persons;
1272 int spare2;
1273
1274 Ais8_1_24(const char *nmea_payload, const size_t pad);
1275 };
1276 ostream& operator<< (ostream &o, const Ais8_1_24 &msg);
1277
1278 // No message 8_1_25
1279
1280 const size_t AIS8_1_26_REPORT_SIZE = 112;
1281
1282 enum Ais8_1_26_SensorEnum {
1283 AIS8_1_26_SENSOR_ERROR = -1,
1284 AIS8_1_26_SENSOR_LOCATION = 0,
1285 AIS8_1_26_SENSOR_STATION = 1,
1286 AIS8_1_26_SENSOR_WIND = 2,
1287 AIS8_1_26_SENSOR_WATER_LEVEL = 3,
1288 AIS8_1_26_SENSOR_CURR_2D = 4,
1289 AIS8_1_26_SENSOR_CURR_3D = 5,
1290 AIS8_1_26_SENSOR_HORZ_FLOW = 6,
1291 AIS8_1_26_SENSOR_SEA_STATE = 7,
1292 AIS8_1_26_SENSOR_SALINITY = 8,
1293 AIS8_1_26_SENSOR_WX = 9,
1294 AIS8_1_26_SENSOR_AIR_DRAUGHT = 10,
1295 AIS8_1_26_SENSOR_RESERVED_11 = 11,
1296 AIS8_1_26_SENSOR_RESERVED_12 = 12,
1297 AIS8_1_26_SENSOR_RESERVED_13 = 13,
1298 AIS8_1_26_SENSOR_RESERVED_14 = 14,
1299 AIS8_1_26_SENSOR_RESERVED_15 = 15,
1300 };
1301
1302 class Ais8_1_26_SensorReport {
1303 public:
1304 int report_type;
1305 int utc_day;
1306 int utc_hr;
1307 int utc_min;
1308 int site_id; // aka link_id
1309
1310 virtual Ais8_1_26_SensorEnum getType() const = 0;
1311 virtual ~Ais8_1_26_SensorReport() {}
1312 };
1313
1314 Ais8_1_26_SensorReport*
1315 ais8_1_26_sensor_report_factory(const AisBitset &bs,
1316 const size_t offset);
1317
1318 class Ais8_1_26_Location : public Ais8_1_26_SensorReport {
1319 public:
1320 AisPoint position;
1321 float z; // alt in m from MSL
1322 int owner;
1323 int timeout;
1324 int spare;
1325
1326 Ais8_1_26_Location(const AisBitset &bs, const size_t offset);
1327 Ais8_1_26_Location() {}
1328 Ais8_1_26_SensorEnum getType() const { return AIS8_1_26_SENSOR_LOCATION; }
1329 };
1330
1331 class Ais8_1_26_Station : public Ais8_1_26_SensorReport {
1332 public:
1333 string name;
1334 int spare;
1335
1336 Ais8_1_26_Station(const AisBitset &bs, const size_t offset);
1337 Ais8_1_26_Station() {}
1338 Ais8_1_26_SensorEnum getType() const {return AIS8_1_26_SENSOR_STATION;}
1339 };
1340
1341 class Ais8_1_26_Wind : public Ais8_1_26_SensorReport {
1342 public:
1343 int wind_speed; // knots
1344 int wind_gust; // knots
1345 int wind_dir;
1346 int wind_gust_dir;
1347 int sensor_type;
1348 int wind_forecast; // knots
1349 int wind_gust_forecast; // knots
1350 int wind_dir_forecast;
1351 int utc_day_forecast;
1352 int utc_hour_forecast;
1353 int utc_min_forecast;
1354 int duration;
1355 int spare;
1356
1357 Ais8_1_26_Wind(const AisBitset &bs, const size_t offset);
1358 Ais8_1_26_Wind() {}
1359 Ais8_1_26_SensorEnum getType() const {return AIS8_1_26_SENSOR_WIND;}
1360 };
1361
1362 class Ais8_1_26_WaterLevel : public Ais8_1_26_SensorReport {
1363 public:
1364 int type;
1365 float level; // m. assuming it is being stored at 0.01 m inc.
1366 int trend;
1367 int vdatum;
1368 int sensor_type;
1369 int forecast_type;
1370 float level_forecast;
1371 int utc_day_forecast;
1372 int utc_hour_forecast;
1373 int utc_min_forecast;
1374 int duration; // minutes
1375 int spare;
1376
1377 Ais8_1_26_WaterLevel(const AisBitset &bs, const size_t offset);
1378 Ais8_1_26_WaterLevel() {}
1379 Ais8_1_26_SensorEnum getType() const {return AIS8_1_26_SENSOR_WATER_LEVEL;}
1380 };
1381
1382 class Ais8_1_26_Curr2D_Current {
1383 public:
1384 float speed; // knots
1385 int dir;
1386 int depth; // m
1387 };
1388
1389 class Ais8_1_26_Curr2D : public Ais8_1_26_SensorReport {
1390 public:
1391 Ais8_1_26_Curr2D_Current currents[3];
1392 int type;
1393 int spare;
1394
1395 Ais8_1_26_Curr2D(const AisBitset &bs, const size_t offset);
1396 Ais8_1_26_Curr2D() {}
1397 Ais8_1_26_SensorEnum getType() const {return AIS8_1_26_SENSOR_CURR_2D;}
1398 };
1399
1400 class Ais8_1_26_Curr3D_Current {
1401 public:
1402 float north;
1403 float east;
1404 float up;
1405 int depth; // m
1406 };
1407
1408 class Ais8_1_26_Curr3D : public Ais8_1_26_SensorReport {
1409 public:
1410 Ais8_1_26_Curr3D_Current currents[2];
1411 int type;
1412 int spare;
1413
1414 Ais8_1_26_Curr3D(const AisBitset &bs, const size_t offset);
1415 Ais8_1_26_Curr3D() {}
1416 Ais8_1_26_SensorEnum getType() const {return AIS8_1_26_SENSOR_CURR_3D;}
1417 };
1418
1419 class Ais8_1_26_HorzFlow_Current {
1420 public:
1421 int bearing; // deg
1422 int dist; // m
1423 float speed; // knots
1424 int dir; // deg
1425 int level; // m
1426 };
1427
1428 class Ais8_1_26_HorzFlow : public Ais8_1_26_SensorReport {
1429 public:
1430 Ais8_1_26_HorzFlow_Current currents[2];
1431 int spare;
1432
1433 Ais8_1_26_HorzFlow(const AisBitset &bs, const size_t offset);
1434 Ais8_1_26_HorzFlow() {}
1435 Ais8_1_26_SensorEnum getType() const {return AIS8_1_26_SENSOR_HORZ_FLOW;}
1436 };
1437
1438 class Ais8_1_26_SeaState : public Ais8_1_26_SensorReport {
1439 public:
1440 float swell_height;
1441 int swell_period; // seconds
1442 int swell_dir; // deg
1443 int sea_state;
1444 int swell_sensor_type;
1445 float water_temp; // C
1446 float water_temp_depth; // m
1447 int water_sensor_type;
1448 float wave_height;
1449 int wave_period; // seconds
1450 int wave_dir; // deg
1451 int wave_sensor_type;
1452 float salinity;
1453
1454 Ais8_1_26_SeaState(const AisBitset &bs, const size_t offset);
1455 Ais8_1_26_SeaState() {}
1456 Ais8_1_26_SensorEnum getType() const {return AIS8_1_26_SENSOR_SEA_STATE;}
1457 };
1458
1459 class Ais8_1_26_Salinity : public Ais8_1_26_SensorReport {
1460 public:
1461 float water_temp; // C
1462 float conductivity; // siemens/m
1463 float pressure; // decibars
1464 float salinity; // 0/00 ppt
1465 int salinity_type;
1466 int sensor_type;
1467 int spare[2];
1468
1469 Ais8_1_26_Salinity(const AisBitset &bs, const size_t offset);
1470 Ais8_1_26_Salinity() {}
1471 Ais8_1_26_SensorEnum getType() const {return AIS8_1_26_SENSOR_SALINITY;}
1472 };
1473
1474 class Ais8_1_26_Wx : public Ais8_1_26_SensorReport {
1475 public:
1476 float air_temp; // C
1477 int air_temp_sensor_type;
1478 int precip;
1479 float horz_vis; // nm
1480 float dew_point; // C
1481 int dew_point_type;
1482 float air_pressure; // Pascals (Pa).
1483 int air_pressure_trend;
1484 int air_pressor_type;
1485 float salinity; // 0/00 ppt
1486 int spare;
1487
1488 Ais8_1_26_Wx(const AisBitset &bs, const size_t offset);
1489 Ais8_1_26_Wx() {}
1490 Ais8_1_26_SensorEnum getType() const {return AIS8_1_26_SENSOR_WX;}
1491 };
1492
1493 class Ais8_1_26_AirDraught : public Ais8_1_26_SensorReport {
1494 public:
1495 float draught;
1496 float gap;
1497 float forecast_gap;
1498 int trend;
1499 int utc_day_forecast;
1500 int utc_hour_forecast;
1501 int utc_min_forecast;
1502 int spare;
1503
1504 Ais8_1_26_AirDraught(const AisBitset &bs, const size_t offset);
1505 Ais8_1_26_AirDraught() {}
1506 Ais8_1_26_SensorEnum getType() const {return AIS8_1_26_SENSOR_AIR_DRAUGHT;}
1507 };
1508
1509 // IMO Circ 289 Environmental
1510 class Ais8_1_26 : public Ais8 {
1511 public:
1512 vector<Ais8_1_26_SensorReport *> reports;
1513
1514 Ais8_1_26(const char *nmea_payload, const size_t pad);
1515 ~Ais8_1_26();
1516 };
1517 ostream& operator<< (ostream &o, const Ais8_1_26 &msg);
1518
1519
1520 // IMO Circ 289 Route information
1521 class Ais8_1_27 : public Ais8 {
1522 public:
1523 int link_id;
1524 int sender_type;
1525 int route_type;
1526 int utc_month;
1527 int utc_day;
1528 int utc_hour;
1529 int utc_min;
1530 int duration;
1531 vector<AisPoint> waypoints;
1532
1533 Ais8_1_27(const char *nmea_payload, const size_t pad);
1534 };
1535 ostream& operator<< (ostream &o, const Ais8_1_27 &msg);
1536
1537
1538 // No message 8_1_28
1539
1540
1541 // IMO Circ 289 Text description
1542 class Ais8_1_29 : public Ais8 {
1543 public:
1544 int link_id;
1545 string text;
1546 int spare2;
1547
1548 Ais8_1_29(const char *nmea_payload, const size_t pad);
1549 };
1550 ostream& operator<< (ostream &o, const Ais8_1_29 &msg);
1551
1552
1553 // No message 8_1_30
1554
1555 // IMO Circ 289 Meteorological and Hydrographic data
1556 // Section 1, Table 1.1
1557 // TODO(schwehr): is this exactly the same as 8_1_11 or has anything changed?
1558 // x,y swapped.
1559 class Ais8_1_31 : public Ais8 {
1560 public:
1561 AisPoint position; // Opposite the bit order of 8_1_11
1562 int position_accuracy; // New field
1563 int utc_day;
1564 int utc_hour;
1565 int utc_min;
1566 int wind_ave; // kts
1567 int wind_gust; // kts
1568 int wind_dir;
1569 int wind_gust_dir;
1570 float air_temp; // C
1571 int rel_humid;
1572 float dew_point;
1573 float air_pres; // Pascals (Pa).
1574 int air_pres_trend;
1575 float horz_vis; // NM
1576 float water_level; // m
1577 int water_level_trend;
1578
1579 float surf_cur_speed;
1580 int surf_cur_dir;
1581 float cur_speed_2; // kts
1582 int cur_dir_2;
1583 int cur_depth_2; // m
1584 float cur_speed_3; // kts
1585 int cur_dir_3;
1586 int cur_depth_3; // m
1587
1588 float wave_height; // m
1589 int wave_period;
1590 int wave_dir;
1591 float swell_height; // m
1592 int swell_period;
1593 int swell_dir;
1594 int sea_state; // beaufort scale - Table 1.2
1595 float water_temp;
1596 int precip_type;
1597 float salinity;
1598 int ice; // yes/no/undef/unknown
1599 int spare2;
1600
1601 Ais8_1_31(const char *nmea_payload, const size_t pad);
1602 };
1603 ostream& operator<< (ostream &o, const Ais8_1_31 &msg);
1604
1605 // TODO(schwehr): Persons on board ITU 1371-1 8_1_40.
1606
1607 // ECE-TRANS-SC3-2006-10e-RIS.pdf - River Information System
1608 // Inland ship static and voyage related data
1609 class Ais8_200_10 : public Ais8 {
1610 public:
1611 string eu_id; // European Vessel ID - 8 characters
1612 float length; // m
1613 float beam; // m
1614 int ship_type;
1615 int haz_cargo;
1616 float draught;
1617 int loaded;
1618 // Sensor quality.
1619 int speed_qual;
1620 int course_qual;
1621 int heading_qual;
1622 int spare2;
1623
1624 Ais8_200_10(const char *nmea_payload, const size_t pad);
1625 };
1626
1627 // http://www.ris.eu/docs/File/536/vessel_traking_and_tracing_standard_ed1-2_ccnr_23-apr_2013_en.pdf
1628 // ETA at lock/bridge/terminal
1629 class Ais8_200_21 : public Ais8 {
1630 public:
1631 string country; // UN country code 0 = not available = default
1632 string location; // UN location code 0 = not available = default
1633 string section; // Fairway section number 0 = not available = default
1634 string terminal; // Terminal code 0 = not available = default
1635 string hectometre; // Fairway hectometre 0 = not available = default
1636 // Examples for previous fields. See:
1637 // http://www.ris.eu/docs/File/427/implementation_location_code_austria.pdf
1638
1639 // ETA at lock/bridge/terminal - Estimated Time of Arrival; MMDDHHMM UTC
1640 int eta_month; // 1 - 12; 0 = not available = default
1641 int eta_day; // 1 - 31; 0 = not available = default
1642 int eta_hour; // 0 - 23; 24 = not available = default
1643 int eta_minute; // 0 - 59; 60 = not available = default
1644 int tugboats; // 0 - 6, 7 = unknown = default
1645 // Maximum present static air draught 0
1646 float air_draught; // 4000 (rest not used), in 1/100m, 0 = not used
1647 int spare2; // 5 bits Not used, should be set to zero.
1648
1649 Ais8_200_21(const char *nmea_payload, const size_t pad);
1650 };
1651
1652 // vessel_traking_and_tracing_standard_ed1-2_ccnr_23-apr_2013_en.pdf
1653 // RTA at lock/bridge/terminal
1654 class Ais8_200_22 : public Ais8 {
1655 public:
1656 string country; // UN country code 0 = not available
1657 string location; // UN location code 0 = not available
1658 string section; // Fairway section number 0 = not available
1659 string terminal; // Terminal code 0 = not available
1660 string hectometre; // Fairway hectometre 0 = not available
1661 // Examples for previous fields. See:
1662 // http://www.ris.eu/docs/File/427/implementation_location_code_austria.pdf
1663
1664 // RTA at lock/bridge/terminal - Recommended Time of Arrival; MMDDHHMM UTC
1665 int rta_month; // 0 = not available
1666 int rta_day; // 0 = not available
1667 int rta_hour; // 24 = not available
1668 int rta_minute; // 60 = not available
1669 int lock_status; // Lock/bridge/terminal status
1670 // 0 = operational
1671 // 1 = limited operation
1672 // 2 = out of order
1673 // 3 = not available
1674 int spare2; // Spare
1675
1676 Ais8_200_22(const char *nmea_payload, const size_t pad);
1677 };
1678
1679 // ECE-TRANS-SC3-2006-10e-RIS.pdf - River Information System
1680 // EMMA warning
1681 class Ais8_200_23 : public Ais8 {
1682 public:
1683 int utc_year_start;
1684 int utc_month_start;
1685 int utc_day_start;
1686 int utc_year_end;
1687 int utc_month_end;
1688 int utc_day_end;
1689 int utc_hour_start;
1690 int utc_min_start;
1691 int utc_hour_end;
1692 int utc_min_end;
1693 AisPoint position1;
1694 AisPoint position2;
1695 int type;
1696 int min;
1697 int max;
1698 int classification;
1699 int wind_dir; // EMMA CODE
1700 int spare2;
1701
1702 Ais8_200_23(const char *nmea_payload, const size_t pad);
1703 };
1704
1705 // ECE-TRANS-SC3-2006-10e-RIS.pdf - River Information System
1706 // Water Level
1707 class Ais8_200_24 : public Ais8 {
1708 public:
1709 // UN 2 letter code. See Comtrade Country Code and Name.
1710 // https://unstats.un.org/unsd/tradekb/Knowledgebase/50377/Comtrade-Country-Code-and-Name
1711 string country;
1712 std::array<int, 4> gauge_ids;
1713 std::array<float, 4> levels; // m
1714
1715 Ais8_200_24(const char *nmea_payload, const size_t pad);
1716 };
1717
1718 // ECE-TRANS-SC3-2006-10e-RIS.pdf - River Information System
1719 // Signal status
1720 class Ais8_200_40 : public Ais8 {
1721 public:
1722 AisPoint position;
1723 int form;
1724 int dir; // degrees
1725 int stream_dir;
1726 int status_raw;
1727 // TODO(schwehr): int status[9]; // WTF is the encoding for this?
1728 int spare2;
1729
1730 Ais8_200_40(const char *nmea_payload, const size_t pad);
1731 };
1732
1733 // ECE-TRANS-SC3-2006-10e-RIS.pdf - River Information System
1734 // Number of persons on board
1735 class Ais8_200_55 : public Ais8 {
1736 public:
1737 int crew;
1738 int passengers;
1739 int yet_more_personnel;
1740 std::array<int, 3> spare2; // 51 spare bits.
1741
1742 Ais8_200_55(const char *nmea_payload, const size_t pad);
1743 };
1744
1745 enum Ais8_366_22_AreaShapeEnum {
1746 AIS8_366_22_SHAPE_ERROR = -1,
1747 AIS8_366_22_SHAPE_CIRCLE = 0,
1748 AIS8_366_22_SHAPE_RECT = 1,
1749 AIS8_366_22_SHAPE_SECTOR = 2,
1750 AIS8_366_22_SHAPE_POLYLINE = 3,
1751 AIS8_366_22_SHAPE_POLYGON = 4,
1752 AIS8_366_22_SHAPE_TEXT = 5,
1753 AIS8_366_22_SHAPE_RESERVED_6 = 6,
1754 AIS8_366_22_SHAPE_RESERVED_7 = 7
1755 };
1756
1757 extern const char *shape_names[8];
1758
1759 class Ais8_366_22_SubArea {
1760 public:
1761 virtual Ais8_366_22_AreaShapeEnum getType() = 0;
1762 virtual ~Ais8_366_22_SubArea() { }
1763 };
1764
1765 Ais8_366_22_SubArea*
1766 ais8_366_22_subarea_factory(const AisBitset &bs,
1767 const size_t offset);
1768
1769 // or Point if radius is 0
1770 class Ais8_366_22_Circle : public Ais8_366_22_SubArea {
1771 public:
1772 AisPoint position;
1773 // TODO(schwehr): int precision
1774 int radius_m;
1775 unsigned int spare;
1776
1777 Ais8_366_22_Circle(const AisBitset &bs, const size_t offset);
1778 ~Ais8_366_22_Circle() {}
1779 Ais8_366_22_AreaShapeEnum getType() {return AIS8_366_22_SHAPE_CIRCLE;}
1780 };
1781
1782 class Ais8_366_22_Rect : public Ais8_366_22_SubArea {
1783 public:
1784 AisPoint position; // longitude and latitude
1785 // TODO(schwehr): int precision
1786 int e_dim_m; // East dimension in meters
1787 int n_dim_m;
1788 int orient_deg; // Orientation in degrees from true north
1789 unsigned int spare; // 5 bits
1790
1791 Ais8_366_22_Rect(const AisBitset &bs, const size_t offset);
1792 ~Ais8_366_22_Rect() {}
1793 Ais8_366_22_AreaShapeEnum getType() {return AIS8_366_22_SHAPE_RECT;}
1794 };
1795
1796 class Ais8_366_22_Sector : public Ais8_366_22_SubArea {
1797 public:
1798 AisPoint position;
1799 // TODO(schwehr): int precision
1800 int radius_m;
1801 int left_bound_deg;
1802 int right_bound_deg;
1803 // TODO(schwehr): spare?
1804
1805 Ais8_366_22_Sector(const AisBitset &bs, const size_t offset);
1806 ~Ais8_366_22_Sector() {}
1807 Ais8_366_22_AreaShapeEnum getType() {return AIS8_366_22_SHAPE_SECTOR;}
1808 };
1809
1810 // Or Waypoint
1811 // Must have a point before on the VDL, but pulled together here.
1812 class Ais8_366_22_Polyline : public Ais8_366_22_SubArea {
1813 public:
1814 AisPoint position; // longitude and latitude
1815 // TODO(schwehr): precision
1816
1817 // Up to 4 points
1818 vector<float> angles;
1819 vector<float> dists_m;
1820 unsigned int spare;
1821
1822 Ais8_366_22_Polyline(const AisBitset &bs, const size_t offset);
1823 ~Ais8_366_22_Polyline() {}
1824 Ais8_366_22_AreaShapeEnum getType() {return AIS8_366_22_SHAPE_POLYLINE;}
1825 };
1826
1827 class Ais8_366_22_Polygon : public Ais8_366_22_SubArea {
1828 public:
1829 AisPoint position; // longitude and latitude
1830 // TODO(schwehr): precision?
1831
1832 // Up to 4 points in a first message, but aggregated if multiple sub areas
1833 vector<float> angles;
1834 vector<float> dists_m;
1835 unsigned int spare;
1836
1837 Ais8_366_22_Polygon(const AisBitset &bs, const size_t offset);
1838 ~Ais8_366_22_Polygon() {}
1839 Ais8_366_22_AreaShapeEnum getType() {return AIS8_366_22_SHAPE_POLYGON;}
1840 };
1841
1842 class Ais8_366_22_Text : public Ais8_366_22_SubArea {
1843 public:
1844 string text;
1845 unsigned int spare; // 3 bits
1846
1847 Ais8_366_22_Text(const AisBitset &bs, const size_t offset);
1848 ~Ais8_366_22_Text() {}
1849 Ais8_366_22_AreaShapeEnum getType() {return AIS8_366_22_SHAPE_TEXT;}
1850 };
1851
1852 class Ais8_366_22 : public Ais8 {
1853 public:
1854 // Common block at the front
1855 int link_id; // 10 bit id to match up text blocks
1856 int notice_type; // area_type / Notice Description
1857 int month; // These really are in utc
1858 int day;
1859 int utc_hour;
1860 int utc_minute;
1861 int duration_minutes; // Time from the start until the notice expires
1862 // 1 or more sub messages
1863
1864 vector<Ais8_366_22_SubArea *> sub_areas;
1865
1866 Ais8_366_22(const char *nmea_payload, const size_t pad);
1867 ~Ais8_366_22();
1868 };
1869 ostream& operator<< (ostream& o, Ais8_366_22 const& msg);
1870
1871 const size_t AIS8_366_22_NUM_NAMES = 128;
1872 extern const char *ais8_366_22_notice_names[AIS8_366_22_NUM_NAMES];
1873
1874 // 366 34 - Kurt older whale message 2008-2010
1875 // TODO(schwehr): Ais8_366_34
1876
1877 // USCG Blue Force encrypted message.
1878 class Ais8_366_56 : public Ais8 {
1879 public:
1880 vector<unsigned char> encrypted;
1881
1882 Ais8_366_56(const char *nmea_payload, const size_t pad);
1883 };
1884
1885 class Ais8_367_22_SubArea {
1886 public:
1887 virtual Ais8_366_22_AreaShapeEnum getType() const = 0;
1888 virtual ~Ais8_367_22_SubArea() { }
1889 };
1890
1891 Ais8_367_22_SubArea*
1892 ais8_367_22_subarea_factory(const AisBitset &bs,
1893 const size_t offset);
1894
1895 class Ais8_367_22_Circle : public Ais8_367_22_SubArea {
1896 public:
1897 AisPoint position;
1898 int precision;
1899 int radius_m;
1900 unsigned int spare;
1901
1902 Ais8_367_22_Circle(const AisBitset &bs, const size_t offset);
1903 ~Ais8_367_22_Circle() {}
1904 Ais8_366_22_AreaShapeEnum getType() const {return AIS8_366_22_SHAPE_CIRCLE;}
1905 };
1906
1907 class Ais8_367_22_Rect : public Ais8_367_22_SubArea {
1908 public:
1909 AisPoint position;
1910 int precision;
1911 int e_dim_m;
1912 int n_dim_m;
1913 int orient_deg;
1914 unsigned int spare;
1915
1916 Ais8_367_22_Rect(const AisBitset &bs, const size_t offset);
1917 ~Ais8_367_22_Rect() {}
1918 Ais8_366_22_AreaShapeEnum getType() const {return AIS8_366_22_SHAPE_RECT;}
1919 };
1920
1921 class Ais8_367_22_Sector : public Ais8_367_22_SubArea {
1922 public:
1923 AisPoint position;
1924 int precision;
1925 int radius_m;
1926 int left_bound_deg;
1927 int right_bound_deg;
1928 int spare;
1929
1930 Ais8_367_22_Sector(const AisBitset &bs, const size_t offset);
1931 ~Ais8_367_22_Sector() {}
1932 Ais8_366_22_AreaShapeEnum getType() const {return AIS8_366_22_SHAPE_SECTOR;}
1933 };
1934
1935 // Polyline or Polygon
1936 class Ais8_367_22_Poly : public Ais8_367_22_SubArea {
1937 public:
1938 Ais8_366_22_AreaShapeEnum shape;
1939 AisPoint position;
1940 int precision;
1941
1942 // Up to 4 points
1943 vector<float> angles;
1944 vector<float> dists_m;
1945 unsigned int spare;
1946
1947 Ais8_367_22_Poly(const AisBitset &bs, const size_t offset,
1948 Ais8_366_22_AreaShapeEnum area_shape);
1949 ~Ais8_367_22_Poly() {}
1950 Ais8_366_22_AreaShapeEnum getType() const {return shape;}
1951 };
1952
1953 class Ais8_367_22_Text : public Ais8_367_22_SubArea {
1954 public:
1955 string text;
1956 unsigned int spare; // 3 bits
1957
1958 Ais8_367_22_Text(const AisBitset &bs, const size_t offset);
1959 ~Ais8_367_22_Text() {}
1960 Ais8_366_22_AreaShapeEnum getType() const {return AIS8_366_22_SHAPE_TEXT;}
1961 };
1962
1963 class Ais8_367_22 : public Ais8 {
1964 public:
1965 int version;
1966 int link_id;
1967 int notice_type;
1968 int month;
1969 int day;
1970 int hour;
1971 int minute;
1972 int duration_minutes;
1973 int spare2;
1974
1975 vector<Ais8_367_22_SubArea *> sub_areas;
1976
1977 Ais8_367_22(const char *nmea_payload, const size_t pad);
1978 ~Ais8_367_22();
1979 };
1980 ostream& operator<< (ostream& o, Ais8_367_22 const& msg);
1981
1982 class Ais9 : public AisMsg {
1983 public:
1984 int alt; // m above sea level
1985 int sog;
1986 int position_accuracy;
1987 AisPoint position;
1988 float cog;
1989 int timestamp;
1990 int alt_sensor;
1991 int spare;
1992 int dte;
1993 int spare2;
1994 int assigned_mode;
1995 bool raim;
1996 int commstate_flag;
1997
1998 int sync_state; // In both SOTDMA and ITDMA
1999
2000 // SOTDMA
2001 bool slot_timeout_valid;
2002 int slot_timeout;
2003
2004 // Based on slot_timeout which ones are valid
2005 bool received_stations_valid;
2006 int received_stations;
2007
2008 bool slot_number_valid;
2009 int slot_number;
2010
2011 bool utc_valid;
2012 int utc_hour;
2013 int utc_min;
2014 int utc_spare;
2015
2016 bool slot_offset_valid;
2017 int slot_offset;
2018
2019 // ITDMA
2020 bool slot_increment_valid;
2021 int slot_increment;
2022
2023 bool slots_to_allocate_valid;
2024 int slots_to_allocate;
2025
2026 bool keep_flag_valid;
2027 bool keep_flag;
2028
2029 Ais9(const char *nmea_payload, const size_t pad);
2030 };
2031 ostream& operator<< (ostream &o, const Ais9 &msg);
2032
2033 // 10 ":" - UTC and date inquiry
2034 class Ais10 : public AisMsg {
2035 public:
2036 int spare;
2037 int dest_mmsi;
2038 int spare2;
2039
2040 Ais10(const char *nmea_payload, const size_t pad);
2041 };
2042 ostream& operator<< (ostream &o, const Ais10 &msg);
2043
2044 // 11 ';' - See 4_11
2045
2046 // 12 - '<' - Addressed safety related text.
2047 class Ais12 : public AisMsg {
2048 public:
2049 int seq_num;
2050 int dest_mmsi;
2051 bool retransmitted;
2052 int spare;
2053 string text;
2054 int spare2;
2055
2056 Ais12(const char *nmea_payload, const size_t pad);
2057 };
2058 ostream& operator<< (ostream &o, const Ais12 &msg);
2059
2060 // 13 '=' - See 7
2061
2062 // 14 - '>' - Safety broadcast text.
2063 class Ais14 : public AisMsg {
2064 public:
2065 int spare;
2066 string text;
2067 int spare2;
2068
2069 Ais14(const char *nmea_payload, const size_t pad);
2070 };
2071 ostream& operator<< (ostream &o, const Ais14 &msg);
2072
2073 // 15 - '?' - Interrogation
2074 class Ais15 : public AisMsg {
2075 public:
2076 int spare;
2077 int mmsi_1;
2078 int msg_1_1;
2079 int slot_offset_1_1;
2080
2081 int spare2;
2082 int dest_msg_1_2;
2083 int slot_offset_1_2;
2084
2085 int spare3;
2086 int mmsi_2;
2087 int msg_2;
2088 int slot_offset_2;
2089 int spare4;
2090
2091 Ais15(const char *nmea_payload, const size_t pad);
2092 };
2093 ostream& operator<< (ostream &o, const Ais15 &msg);
2094
2095 // 16 - '@' - Assigned mode command
2096 class Ais16 : public AisMsg {
2097 public:
2098 int spare;
2099 int dest_mmsi_a;
2100 int offset_a;
2101 int inc_a;
2102 int dest_mmsi_b;
2103 int offset_b;
2104 int inc_b;
2105 int spare2;
2106
2107 Ais16(const char *nmea_payload, const size_t pad);
2108 };
2109 ostream& operator<< (ostream &o, const Ais16 &msg);
2110
2111 // ITU-R M.823 http://www.itu.int/rec/R-REC-M.823/en
2112 // 17 - 'A' - GNSS broacast - TODO(schwehr): only partially coded
2113 class Ais17 : public AisMsg {
2114 public:
2115 int spare;
2116 AisPoint position;
2117 int spare2;
2118 int gnss_type;
2119 int z_cnt;
2120 int station;
2121 int seq;
2122 // N - do not need to store this
2123 int health;
2124 // TODO(schwehr): Handle payload
2125
2126 Ais17(const char *nmea_payload, const size_t pad);
2127 };
2128 ostream& operator<< (ostream &o, const Ais17 &msg);
2129
2130
2131 // 18 - 'B' - Class B position report
2132 class Ais18 : public AisMsg {
2133 public:
2134 int spare;
2135 float sog;
2136 int position_accuracy;
2137 AisPoint position; // Long and lat
2138 float cog;
2139 int true_heading;
2140 int timestamp;
2141 int spare2;
2142 int unit_flag; // 0 is SOTDMA, 1 is Carrier Sense (CS).
2143 int display_flag;
2144 int dsc_flag;
2145 int band_flag;
2146 int m22_flag;
2147 int mode_flag;
2148 bool raim;
2149 int commstate_flag;
2150
2151 // SOTDMA
2152 int sync_state;
2153 bool slot_timeout_valid;
2154 int slot_timeout;
2155
2156 // Based on slot_timeout which ones are valid
2157 bool received_stations_valid;
2158 int received_stations;
2159
2160 bool slot_number_valid;
2161 int slot_number;
2162
2163 bool utc_valid;
2164 int utc_hour;
2165 int utc_min;
2166 int utc_spare;
2167
2168 bool slot_offset_valid;
2169 int slot_offset;
2170
2171 // ITDMA
2172 bool slot_increment_valid;
2173 int slot_increment;
2174
2175 bool slots_to_allocate_valid;
2176 int slots_to_allocate;
2177
2178 bool keep_flag_valid;
2179 bool keep_flag;
2180
2181 // If commstate set to 1 for Carrier Sense (CS) devices, there is no
2182 // state and the commstate region is supposed to be filled with this value:
2183 // 1100000000000000110
2184 bool commstate_cs_fill_valid;
2185 int commstate_cs_fill;
2186
2187 Ais18(const char *nmea_payload, const size_t pad);
2188 };
2189 ostream& operator<< (ostream &o, const Ais18 &msg);
2190
2191 // 19 - 'C' - Class B extended ship and position
2192 class Ais19 : public AisMsg {
2193 public:
2194 int spare;
2195 float sog;
2196 int position_accuracy;
2197 AisPoint position; // Long and lat
2198 float cog;
2199 int true_heading;
2200 int timestamp;
2201 int spare2;
2202 string name;
2203 int type_and_cargo;
2204 int dim_a;
2205 int dim_b;
2206 int dim_c;
2207 int dim_d;
2208 int fix_type;
2209 bool raim;
2210 int dte;
2211 int assigned_mode;
2212 int spare3;
2213
2214 Ais19(const char *nmea_payload, const size_t pad);
2215 };
2216 ostream& operator<< (ostream &o, const Ais19 &msg);
2217
2218 // 20 - 'D' - Data link management
2219 // TODO(schwehr): consider a vector
2220 class Ais20 : public AisMsg {
2221 public:
2222 int spare;
2223 int offset_1;
2224 int num_slots_1;
2225 int timeout_1;
2226 int incr_1;
2227
2228 bool group_valid_2;
2229 int offset_2;
2230 int num_slots_2;
2231 int timeout_2;
2232 int incr_2;
2233
2234 bool group_valid_3;
2235 int offset_3;
2236 int num_slots_3;
2237 int timeout_3;
2238 int incr_3;
2239
2240 bool group_valid_4;
2241 int offset_4;
2242 int num_slots_4;
2243 int timeout_4;
2244 int incr_4;
2245
2246 int spare2;
2247
2248 Ais20(const char *nmea_payload, const size_t pad);
2249 };
2250 ostream& operator<< (ostream &o, const Ais20 &msg);
2251
2252 // 21 - 'E' - Aids to navigation report
2253 class Ais21 : public AisMsg {
2254 public:
2255 int aton_type;
2256 string name;
2257 int position_accuracy;
2258 AisPoint position;
2259 int dim_a;
2260 int dim_b;
2261 int dim_c;
2262 int dim_d;
2263 int fix_type;
2264 int timestamp;
2265 bool off_pos;
2266 int aton_status;
2267 bool raim;
2268 bool virtual_aton;
2269 bool assigned_mode;
2270 int spare;
2271 // Extended name goes on the end of name
2272 int spare2;
2273
2274 Ais21(const char *nmea_payload, const size_t pad);
2275 };
2276 ostream& operator<< (ostream &o, const Ais21 &msg);
2277
2278 // 22 - 'F' - Channel Management
2279 class Ais22 : public AisMsg {
2280 public:
2281 int spare;
2282 int chan_a;
2283 int chan_b;
2284 int txrx_mode;
2285 bool power_low;
2286
2287 // if addressed false, then geographic position
2288 bool pos_valid;
2289 AisPoint position1;
2290 AisPoint position2;
2291
2292 // if addressed is true
2293 bool dest_valid;
2294 int dest_mmsi_1;
2295 int dest_mmsi_2;
2296
2297 int chan_a_bandwidth;
2298 int chan_b_bandwidth;
2299 int zone_size;
2300
2301 int spare2; // Lame that they make a huge spare here. Bad bad bad
2302
2303 Ais22(const char *nmea_payload, const size_t pad);
2304 };
2305 ostream& operator<< (ostream &o, const Ais22 &msg);
2306
2307 // 23 - 'G' - Group Assignment Command
2308 class Ais23 : public AisMsg {
2309 public:
2310 int spare;
2311 AisPoint position1;
2312 AisPoint position2;
2313 int station_type;
2314 int type_and_cargo;
2315
2316 int spare2; // 22 bits of spare here? what were people thinking?
2317
2318 int txrx_mode;
2319 int interval_raw; // raw value, not sec
2320 int quiet;
2321 int spare3;
2322
2323 Ais23(const char *nmea_payload, const size_t pad);
2324 };
2325 ostream& operator<< (ostream &o, const Ais23 &msg);
2326
2327 // 24 - 'H' - Class B Static Data report
2328 class Ais24 : public AisMsg {
2329 public:
2330 int part_num;
2331
2332 // Part A
2333 string name;
2334
2335 // Part B
2336 int type_and_cargo;
2337 string vendor_id;
2338 string callsign;
2339 int dim_a;
2340 int dim_b;
2341 int dim_c;
2342 int dim_d;
2343 int spare;
2344
2345 // Part C - Not defined by ITU 1371-5
2346 // Part D - Not defined by ITU 1371-5
2347
2348 Ais24(const char *nmea_payload, const size_t pad);
2349 };
2350 ostream& operator<< (ostream &o, const Ais24 &msg);
2351
2352 // 25 - 'I' - Single slot binary message - addressed or broadcast
2353 // TODO(schwehr): handle payload
2354 class Ais25 : public AisMsg {
2355 public:
2356 bool use_app_id; // if false, payload is unstructured binary.
2357
2358 bool dest_mmsi_valid;
2359 int dest_mmsi; // only valid if addressed
2360 // If unstructured:
2361 // TODO(schwehr): vector<unsigned char> payload;
2362
2363 int dac; // valid if use_app_id is true
2364 int fi;
2365
2366 Ais25(const char *nmea_payload, const size_t pad);
2367 };
2368 ostream& operator<< (ostream &o, const Ais25 &msg);
2369
2370 // 26 - 'J' - Multi slot binary message with comm state
2371 // TODO(schwehr): handle payload
2372 class Ais26 : public AisMsg {
2373 public:
2374 bool use_app_id; // if false, payload is unstructured binary
2375
2376 bool dest_mmsi_valid;
2377 int dest_mmsi; // only valid if addressed
2378
2379 int dac; // valid it use_app_id
2380 int fi;
2381
2382 // TODO(schwehr): vector<unsigned char> payload; // If unstructured. Yuck.
2383
2384 int commstate_flag; // 0 - SOTDMA, 1 - TDMA
2385
2386 // SOTDMA
2387 int sync_state;
2388 bool slot_timeout_valid;
2389 int slot_timeout;
2390
2391 // Based on slot_timeout which ones are valid
2392 bool received_stations_valid;
2393 int received_stations;
2394
2395 bool slot_number_valid;
2396 int slot_number;
2397
2398 bool utc_valid;
2399 int utc_hour;
2400 int utc_min;
2401 int utc_spare;
2402
2403 bool slot_offset_valid;
2404 int slot_offset;
2405
2406 // ITDMA
2407 bool slot_increment_valid;
2408 int slot_increment;
2409
2410 bool slots_to_allocate_valid;
2411 int slots_to_allocate;
2412
2413 bool keep_flag_valid;
2414 bool keep_flag;
2415
2416 Ais26(const char *nmea_payload, const size_t pad);
2417 };
2418 ostream& operator<< (ostream &o, const Ais26 &msg);
2419
2420 // 27 - 'K' - Long-range position report - e.g. for satellite receivers
2421 class Ais27 : public AisMsg {
2422 public:
2423 int position_accuracy;
2424 bool raim;
2425 int nav_status;
2426 AisPoint position;
2427 int sog; // Knots.
2428 int cog; // Degrees.
2429 bool gnss; // warning: bits in AIS are flipped sense
2430 int spare;
2431
2432 Ais27(const char *nmea_payload, const size_t pad);
2433 };
2434 ostream& operator<< (ostream &o, const Ais27 &msg);
2435
2436 } // namespace libais
2437
2438 #endif // LIBAIS_AIS_H_