| 1 | // ? - Interrogation |
| 2 | |
| 3 | #include "ais.h" |
| 4 | |
| 5 | namespace libais { |
| 6 | |
| 7 | Ais15::Ais15(const char *nmea_payload, const size_t pad) |
| 8 | : AisMsg(nmea_payload, pad), spare(0), mmsi_1(0), msg_1_1(0), |
| 9 | slot_offset_1_1(0), spare2(0), dest_msg_1_2(0), slot_offset_1_2(0), |
| 10 | spare3(0), mmsi_2(0), msg_2(0), slot_offset_2(0), spare4(0) { |
| 11 | if (!CheckStatus()) { |
| 12 | return; |
| 13 | } |
| 14 | // TODO(schwehr): verify the pad makes sense for each size |
| 15 | if (num_chars != 15 && num_chars != 18 && num_chars != 27) { |
| 16 | // 88-160 bits |
| 17 | status = AIS_ERR_BAD_BIT_COUNT; |
| 18 | return; |
| 19 | } |
| 20 | |
| 21 | // 160 / 6 = 26.66 |
| 22 | assert(message_id == 15); |
| 23 | |
| 24 | bits.SeekTo(38); |
| 25 | spare = bits.ToUnsignedInt(38, 2); |
| 26 | mmsi_1 = bits.ToUnsignedInt(40, 30); // Destination ID 1 |
| 27 | msg_1_1 = bits.ToUnsignedInt(70, 6); |
| 28 | slot_offset_1_1 = bits.ToUnsignedInt(76, 12); |
| 29 | |
| 30 | // TODO(schwehr): set remaining fields to -1 |
| 31 | if (num_chars <= 15) { |
| 32 | assert(bits.GetRemaining() == 0); |
| 33 | status = AIS_OK; |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | spare2 = bits.ToUnsignedInt(88, 2); |
| 38 | dest_msg_1_2 = bits.ToUnsignedInt(90, 6); |
| 39 | // Failing test here. Getting bits [96..108], but num_bits is 104 (+4 pad). |
| 40 | // Context (http://catb.org/gpsd/AIVDM.html): |
| 41 | // "One station is interrogated for two message types, Length is 110 bits. |
| 42 | // There is a design error in the standard here; according to the <[ITU1371]> |
| 43 | // requirement for padding to 8 bits, this should have been 112 with a 4-bit |
| 44 | // trailing spare field, and decoders should be prepared to handle that length |
| 45 | // as well." |
| 46 | slot_offset_1_2 = bits.ToUnsignedInt(96, 12); |
| 47 | |
| 48 | // TODO(schwehr): set remaining fields to -1 |
| 49 | if (num_chars <= 18) { |
| 50 | // TODO(schwehr): Crashes: assert(bits.GetRemaining() == 0); |
| 51 | status = AIS_OK; |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | spare3 = bits.ToUnsignedInt(108, 2); |
| 56 | mmsi_2 = bits.ToUnsignedInt(110, 30); |
| 57 | msg_2 = bits.ToUnsignedInt(140, 6); |
| 58 | slot_offset_2 = bits.ToUnsignedInt(146, 12); |
| 59 | spare4 = bits.ToUnsignedInt(158, 2); |
| 60 | |
| 61 | assert(bits.GetRemaining() == 0); |
| 62 | |
| 63 | status = AIS_OK; |
| 64 | } |
| 65 | |
| 66 | } // namespace libais |