| 1 | // Class A shipdata |
| 2 | |
| 3 | #include "ais.h" |
| 4 | |
| 5 | namespace libais { |
| 6 | |
| 7 | Ais5::Ais5(const char *nmea_payload, const size_t pad) |
| 8 | : AisMsg(nmea_payload, pad), ais_version(0), imo_num(0), |
| 9 | type_and_cargo(0), dim_a(0), dim_b(0), dim_c(0), dim_d(0), |
| 10 | fix_type(0), eta_month(0), eta_day(0), eta_hour(0), eta_minute(0), |
| 11 | draught(0.0), dte(0), spare(0) { |
| 12 | if (!CheckStatus()) { |
| 13 | return; |
| 14 | } |
| 15 | if (pad != 2 || num_chars != 71) { |
| 16 | status = AIS_ERR_BAD_BIT_COUNT; |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | assert(message_id == 5); |
| 21 | |
| 22 | bits.SeekTo(38); |
| 23 | ais_version = bits.ToUnsignedInt(38, 2); |
| 24 | imo_num = bits.ToUnsignedInt(40, 30); |
| 25 | callsign = bits.ToString(70, 42); |
| 26 | |
| 27 | name = bits.ToString(112, 120); |
| 28 | |
| 29 | type_and_cargo = bits.ToUnsignedInt(232, 8); |
| 30 | dim_a = bits.ToUnsignedInt(240, 9); |
| 31 | dim_b = bits.ToUnsignedInt(249, 9); |
| 32 | dim_c = bits.ToUnsignedInt(258, 6); |
| 33 | dim_d = bits.ToUnsignedInt(264, 6); |
| 34 | fix_type = bits.ToUnsignedInt(270, 4); |
| 35 | eta_month = bits.ToUnsignedInt(274, 4); |
| 36 | eta_day = bits.ToUnsignedInt(278, 5); |
| 37 | eta_hour = bits.ToUnsignedInt(283, 5); |
| 38 | eta_minute = bits.ToUnsignedInt(288, 6); |
| 39 | draught = bits.ToUnsignedInt(294, 8) / 10.; |
| 40 | destination = bits.ToString(302, 120); |
| 41 | dte = bits[422]; |
| 42 | spare = bits[423]; |
| 43 | |
| 44 | assert(bits.GetRemaining() == 0); |
| 45 | status = AIS_OK; |
| 46 | } |
| 47 | |
| 48 | ostream& operator<< (ostream& o, const Ais5 &msg) { |
| 49 | return o << 5 << ": " << msg.mmsi << " \"" << msg.name << "\" " |
| 50 | << msg.type_and_cargo << " " << msg.dim_a + msg.dim_b |
| 51 | << "x" << msg.dim_c + msg.dim_d << "x" << msg.draught << "m"; |
| 52 | } |
| 53 | |
| 54 | } // namespace libais |