| 1 | // A - GNSS broacast - |
| 2 | // TODO(schwehr): only partially coded - need to finish |
| 3 | // http://www.itu.int/rec/R-REC-M.823/en |
| 4 | // http://www.iala-aism.org/iala/publications/documentspdf/doc_348_eng.pdf |
| 5 | |
| 6 | // In 823, 30 bit words = 24 bits data followed by 6 parity bits. |
| 7 | // Parity bits are left out of the AIS payload? |
| 8 | |
| 9 | #include "ais.h" |
| 10 | |
| 11 | namespace libais { |
| 12 | |
| 13 | Ais17::Ais17(const char *nmea_payload, const size_t pad) |
| 14 | : AisMsg(nmea_payload, pad), spare(0), spare2(0), gnss_type(0), z_cnt(0), |
| 15 | station(0), seq(0), health(0) { |
| 16 | if (!CheckStatus()) { |
| 17 | return; |
| 18 | } |
| 19 | if (num_bits != 80 && (num_bits < 120 || num_bits > 816)) { |
| 20 | status = AIS_ERR_BAD_BIT_COUNT; |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | assert(message_id == 17); |
| 25 | |
| 26 | bits.SeekTo(38); |
| 27 | spare = bits.ToUnsignedInt(38, 2); |
| 28 | |
| 29 | position = bits.ToAisPoint(40, 35); |
| 30 | spare2 = bits.ToUnsignedInt(75, 5); |
| 31 | |
| 32 | // Spec states that there might be no data. |
| 33 | if (num_bits == 80) { |
| 34 | gnss_type = -1; |
| 35 | station = -1; |
| 36 | z_cnt = -1; |
| 37 | seq = -1; |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | gnss_type = bits.ToUnsignedInt(80, 6); |
| 42 | station = bits.ToUnsignedInt(86, 10); |
| 43 | z_cnt = bits.ToUnsignedInt(96, 13); |
| 44 | seq = bits.ToUnsignedInt(109, 3); |
| 45 | bits.SeekRelative(5); |
| 46 | health = bits.ToUnsignedInt(117, 3); |
| 47 | |
| 48 | // TODO(schwehr): Implement parsing the payload. |
| 49 | |
| 50 | // TODO(schwehr): Add assert(bits.GetRemaining() == 0); |
| 51 | |
| 52 | status = AIS_OK; // TODO(schwehr): Not really okay yet. |
| 53 | } |
| 54 | |
| 55 | |
| 56 | ostream& operator<< (ostream &o, const Ais17 &m) { |
| 57 | return o << "[" << m.message_id << "]: " << m.mmsi |
| 58 | << " " << m.position << " t:" |
| 59 | << m.gnss_type << ", z:" << m.z_cnt |
| 60 | << ", d s:" << m.station << ", seq:" |
| 61 | << m.seq << ", h:" << m.health; |
| 62 | } |
| 63 | |
| 64 | } // namespace libais |