| 1 | // Msg 22 - F - Channel Management |
| 2 | |
| 3 | #include "ais.h" |
| 4 | |
| 5 | namespace libais { |
| 6 | |
| 7 | Ais22::Ais22(const char *nmea_payload, const size_t pad) |
| 8 | : AisMsg(nmea_payload, pad), spare(0), chan_a(0), chan_b(0), txrx_mode(0), |
| 9 | power_low(false), pos_valid(false), dest_valid(false), dest_mmsi_1(0), |
| 10 | dest_mmsi_2(0), chan_a_bandwidth(0), chan_b_bandwidth(0), zone_size(0), |
| 11 | spare2(0) { |
| 12 | if (!CheckStatus()) { |
| 13 | return; |
| 14 | } |
| 15 | if (pad != 0 || num_chars != 28) { |
| 16 | status = AIS_ERR_BAD_BIT_COUNT; |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | assert(message_id == 22); |
| 21 | |
| 22 | spare = bits.SeekTo(38).ToUnsignedInt(38, 2); |
| 23 | |
| 24 | chan_a = bits.ToUnsignedInt(40, 12); |
| 25 | chan_b = bits.ToUnsignedInt(52, 12); |
| 26 | txrx_mode = bits.ToUnsignedInt(64, 4); |
| 27 | power_low = bits[68]; |
| 28 | |
| 29 | // WARNING: OUT OF ORDER DECODE |
| 30 | bits.SeekTo(139); |
| 31 | bool addressed = bits[139]; |
| 32 | |
| 33 | bits.SeekTo(69); |
| 34 | if (!addressed) { |
| 35 | // geographic position |
| 36 | // TODO(schwehr): For all implementations in libais, set the valid flag |
| 37 | // after setting all of the data members. |
| 38 | pos_valid = true; |
| 39 | // TODO(schwehr): Confirm this is correct! |
| 40 | position1 = bits.ToAisPoint(69, 35); |
| 41 | position2 = bits.ToAisPoint(104, 35); |
| 42 | } else { |
| 43 | dest_valid = true; |
| 44 | dest_mmsi_1 = bits.ToUnsignedInt(69, 30); |
| 45 | // 5 spare bits |
| 46 | bits.SeekRelative(5); |
| 47 | dest_mmsi_2 = bits.ToUnsignedInt(104, 30); |
| 48 | // 5 spare bits |
| 49 | bits.SeekRelative(5); |
| 50 | } |
| 51 | |
| 52 | // OUT OF ORDER: addressed is earlier before |
| 53 | bits.SeekRelative(1); |
| 54 | chan_a_bandwidth = bits[140]; |
| 55 | chan_b_bandwidth = bits[141]; |
| 56 | zone_size = bits.ToUnsignedInt(142, 3); |
| 57 | |
| 58 | spare2 = bits.ToUnsignedInt(145, 23); |
| 59 | |
| 60 | assert(bits.GetRemaining() == 0); |
| 61 | status = AIS_OK; |
| 62 | } |
| 63 | |
| 64 | } // namespace libais |