| 1 | // Msg 21 - ATON status - 'E' |
| 2 | |
| 3 | #include "ais.h" |
| 4 | |
| 5 | namespace libais { |
| 6 | |
| 7 | Ais21::Ais21(const char *nmea_payload, const size_t pad) |
| 8 | : AisMsg(nmea_payload, pad), aton_type(0), position_accuracy(0), dim_a(0), |
| 9 | dim_b(0), dim_c(0), dim_d(0), fix_type(0), timestamp(0), off_pos(false), |
| 10 | aton_status(0), raim(false), virtual_aton(false), assigned_mode(false), |
| 11 | spare(0), spare2(0) { |
| 12 | assert(message_id == 21); |
| 13 | |
| 14 | // TODO(schwehr): make this more careful than 272-360 |
| 15 | if (num_bits != 268 && (num_bits < 272 || num_bits > 360)) { |
| 16 | status = AIS_ERR_BAD_BIT_COUNT; |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | AisBitset bs; |
| 21 | const AIS_STATUS r = bs.ParseNmeaPayload(nmea_payload, pad); |
| 22 | if (r != AIS_OK) { |
| 23 | status = r; |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | bs.SeekTo(38); |
| 28 | aton_type = bs.ToUnsignedInt(38, 5); |
| 29 | name = bs.ToString(43, 120); |
| 30 | position_accuracy = bs[163]; |
| 31 | position = bs.ToAisPoint(164, 55); |
| 32 | dim_a = bs.ToUnsignedInt(219, 9); |
| 33 | dim_b = bs.ToUnsignedInt(228, 9); |
| 34 | dim_c = bs.ToUnsignedInt(237, 6); |
| 35 | dim_d = bs.ToUnsignedInt(243, 6); |
| 36 | fix_type = bs.ToUnsignedInt(249, 4); |
| 37 | timestamp = bs.ToUnsignedInt(253, 6); |
| 38 | off_pos = bs[259]; |
| 39 | aton_status = bs.ToUnsignedInt(260, 8); |
| 40 | if (num_bits == 268) { |
| 41 | // Non-standard small message. |
| 42 | assert(bs.GetRemaining() == 0); |
| 43 | status = AIS_OK; |
| 44 | return; |
| 45 | } |
| 46 | raim = bs[268]; |
| 47 | virtual_aton = bs[269]; |
| 48 | assigned_mode = bs[270]; |
| 49 | spare = bs[271]; |
| 50 | |
| 51 | const size_t extra_chars = bs.GetRemaining() / 6; |
| 52 | const size_t extra_bits = bs.GetRemaining() % 6; |
| 53 | |
| 54 | if (extra_chars > 0) { |
| 55 | name += bs.ToString(272, extra_chars * 6); |
| 56 | } |
| 57 | |
| 58 | if (extra_bits > 0) { |
| 59 | spare2 = bs.ToUnsignedInt(272 + extra_chars * 6, extra_bits); |
| 60 | } else { |
| 61 | spare2 = 0; |
| 62 | } |
| 63 | |
| 64 | assert(bs.GetRemaining() == 0); |
| 65 | status = AIS_OK; |
| 66 | } |
| 67 | |
| 68 | } // namespace libais |