| 1 | // River Information Systems ECE-TRANS-SC3-2006-10r-RIS.pdf |
| 2 | // http://www.unece.org/fileadmin/DAM/trans/doc/finaldocs/sc3/ECE-TRANS-SC3-176e.pdf |
| 3 | |
| 4 | #include "ais.h" |
| 5 | |
| 6 | namespace libais { |
| 7 | |
| 8 | // Inland ship static and voyage related data |
| 9 | Ais8_200_10::Ais8_200_10(const char *nmea_payload, const size_t pad) |
| 10 | : Ais8(nmea_payload, pad), length(0.0), beam(0.0), ship_type(0), |
| 11 | haz_cargo(0), draught(0.0), loaded(0), speed_qual(0), course_qual(0), |
| 12 | heading_qual(0), spare2(0) { |
| 13 | assert(dac == 200); |
| 14 | assert(fi == 10); |
| 15 | |
| 16 | if (!CheckStatus()) { |
| 17 | return; |
| 18 | } |
| 19 | if (num_bits != 168) { |
| 20 | status = AIS_ERR_BAD_BIT_COUNT; |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | bits.SeekTo(56); |
| 25 | eu_id = bits.ToString(56, 48); |
| 26 | length = bits.ToUnsignedInt(104, 13) / 10.; // m |
| 27 | beam = bits.ToUnsignedInt(117, 10) / 10.; // m |
| 28 | ship_type = bits.ToUnsignedInt(127, 14); |
| 29 | haz_cargo = bits.ToUnsignedInt(141, 3); |
| 30 | draught = bits.ToUnsignedInt(144, 11) / 10.; // m |
| 31 | loaded = bits.ToUnsignedInt(155, 2); |
| 32 | speed_qual = bits[157]; |
| 33 | course_qual = bits[158]; |
| 34 | heading_qual = bits[159]; |
| 35 | spare2 = bits.ToUnsignedInt(160, 8); |
| 36 | |
| 37 | assert(bits.GetRemaining() == 0); |
| 38 | status = AIS_OK; |
| 39 | } |
| 40 | |
| 41 | // ETA report |
| 42 | Ais8_200_21::Ais8_200_21(const char *nmea_payload, const size_t pad) |
| 43 | : Ais8(nmea_payload, pad), eta_month(0), eta_day(0), eta_hour(0), |
| 44 | eta_minute(0), tugboats(0), air_draught(0.0) // TODO : add missing fields |
| 45 | { |
| 46 | assert(dac == 200); |
| 47 | assert(fi == 21); |
| 48 | |
| 49 | if (!CheckStatus()) { |
| 50 | return; |
| 51 | } |
| 52 | if (num_bits != 248) { |
| 53 | status = AIS_ERR_BAD_BIT_COUNT; |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | bits.SeekTo(88); |
| 58 | // UN country code 12 bits |
| 59 | country = bits.ToString(88, 12); |
| 60 | |
| 61 | // UN location code 18 bits |
| 62 | location = bits.ToString(100, 18); |
| 63 | |
| 64 | // Fairway section number 30 bits |
| 65 | section = bits.ToString(118, 30); |
| 66 | |
| 67 | // Terminal code 30 bits |
| 68 | terminal = bits.ToString(148, 30); |
| 69 | |
| 70 | // Fairway hectometre 30 bits |
| 71 | hectometre = bits.ToString(178, 30); |
| 72 | |
| 73 | // ETA at lock/bridge/terminal 20 bits |
| 74 | eta_month = bits.ToUnsignedInt(208, 4); |
| 75 | eta_day = bits.ToUnsignedInt(212, 5); |
| 76 | eta_hour = bits.ToUnsignedInt(217, 5); |
| 77 | eta_minute = bits.ToUnsignedInt(223, 6); |
| 78 | |
| 79 | // Number of assisting tugboats 3 bits |
| 80 | tugboats = bits.ToUnsignedInt(229, 3); |
| 81 | |
| 82 | // Maximum present static air draught 12 bits |
| 83 | air_draught = bits.ToUnsignedInt(231, 12) / 10.; // m |
| 84 | |
| 85 | // Spare 5 bits |
| 86 | spare2 = bits.ToUnsignedInt(243, 5); |
| 87 | |
| 88 | assert(bits.GetRemaining() == 0); |
| 89 | status = AIS_OK; |
| 90 | } |
| 91 | |
| 92 | // RTA report |
| 93 | Ais8_200_22::Ais8_200_22(const char *nmea_payload, const size_t pad) |
| 94 | : Ais8(nmea_payload, pad), rta_month(0), rta_day(0), rta_hour(0), |
| 95 | rta_minute(0) // TODO : add missing fields |
| 96 | { |
| 97 | assert(dac == 200); |
| 98 | assert(fi == 22); |
| 99 | |
| 100 | if (!CheckStatus()) { |
| 101 | return; |
| 102 | } |
| 103 | if (num_bits != 232) { |
| 104 | status = AIS_ERR_BAD_BIT_COUNT; |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | bits.SeekTo(88); |
| 109 | // UN country code 12 bits |
| 110 | country = bits.ToString(88, 12); |
| 111 | |
| 112 | // UN location code 18 bits |
| 113 | location = bits.ToString(100, 18); |
| 114 | |
| 115 | // Fairway section number 30 bits |
| 116 | section = bits.ToString(118, 30); |
| 117 | |
| 118 | // Terminal code 30 bits |
| 119 | terminal = bits.ToString(148, 30); |
| 120 | |
| 121 | // Fairway hectometre 30 bits |
| 122 | hectometre = bits.ToString(178, 30); |
| 123 | |
| 124 | // RTA at lock/bridge/terminal 20 bits |
| 125 | rta_month = bits.ToUnsignedInt(208, 4); |
| 126 | rta_day = bits.ToUnsignedInt(212, 5); |
| 127 | rta_hour = bits.ToUnsignedInt(217, 5); |
| 128 | rta_minute = bits.ToUnsignedInt(223, 6); |
| 129 | |
| 130 | // Lock/bridge/terminal status 2 bits |
| 131 | lock_status = bits.ToUnsignedInt(229, 2); |
| 132 | |
| 133 | // Spare 2 bits |
| 134 | spare2 = bits.ToUnsignedInt(231, 2); |
| 135 | |
| 136 | assert(bits.GetRemaining() == 0); |
| 137 | status = AIS_OK; |
| 138 | } |
| 139 | |
| 140 | // River Information Systems ECE-TRANS-SC3-2006-10r-RIS.pdf |
| 141 | Ais8_200_23::Ais8_200_23(const char *nmea_payload, const size_t pad) |
| 142 | : Ais8(nmea_payload, pad), utc_year_start(0), utc_month_start(0), |
| 143 | utc_day_start(0), utc_year_end(0), utc_month_end(0), utc_day_end(0), |
| 144 | utc_hour_start(0), utc_min_start(0), utc_hour_end(0), utc_min_end(0), |
| 145 | type(0), min(0), max(0), classification(0), wind_dir(0), spare2(0) { |
| 146 | assert(dac == 200); |
| 147 | assert(fi == 23); |
| 148 | |
| 149 | if (!CheckStatus()) { |
| 150 | return; |
| 151 | } |
| 152 | if (num_bits != 256) { |
| 153 | status = AIS_ERR_BAD_BIT_COUNT; |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | bits.SeekTo(56); |
| 158 | |
| 159 | // TODO(schwehr): Figure out the correct bits & test against actual messages. |
| 160 | |
| 161 | // The total for the bit column in table 2.11 of ECE/TRANS/SC.3/2006/10 |
| 162 | // add up to 256. However, start date and end date fields are lists with |
| 163 | // totals of 17 bits each, but within the details, the spec refers to 18 bits |
| 164 | // for each. It is likely the year should be one less bit. |
| 165 | utc_year_start = bits.ToUnsignedInt(56, 8); |
| 166 | utc_month_start = bits.ToUnsignedInt(65, 4); |
| 167 | utc_day_start = bits.ToUnsignedInt(69, 5); |
| 168 | |
| 169 | utc_year_end = bits.ToUnsignedInt(73, 8); |
| 170 | utc_month_end = bits.ToUnsignedInt(82, 4); |
| 171 | utc_day_end = bits.ToUnsignedInt(86, 5); |
| 172 | |
| 173 | utc_hour_start = bits.ToUnsignedInt(90, 5); |
| 174 | utc_min_start = bits.ToUnsignedInt(95, 6); |
| 175 | utc_hour_end = bits.ToUnsignedInt(101, 5); |
| 176 | utc_min_end = bits.ToUnsignedInt(106, 6); |
| 177 | |
| 178 | position1 = bits.ToAisPoint(112, 55); |
| 179 | position2 = bits.ToAisPoint(167, 55); |
| 180 | |
| 181 | type = bits.ToUnsignedInt(222, 4); |
| 182 | // TODO(schwehr): Handle the sign bit for min and max. |
| 183 | min = bits.ToUnsignedInt(226, 9); |
| 184 | max = bits.ToUnsignedInt(235, 9); |
| 185 | classification = bits.ToUnsignedInt(244, 2); |
| 186 | wind_dir = bits.ToUnsignedInt(246, 4); |
| 187 | spare2 = bits.ToUnsignedInt(250, 6); |
| 188 | |
| 189 | // TODO(schwehr): The above bit counts can't work. |
| 190 | assert(bits.GetRemaining() == 0); |
| 191 | status = AIS_OK; |
| 192 | } |
| 193 | |
| 194 | |
| 195 | // River Information Systems ECE-TRANS-SC3-2006-10r-RIS.pdf |
| 196 | // Water level |
| 197 | Ais8_200_24::Ais8_200_24(const char *nmea_payload, const size_t pad) |
| 198 | : Ais8(nmea_payload, pad) { |
| 199 | assert(dac == 200); |
| 200 | assert(fi == 24); |
| 201 | |
| 202 | if (!CheckStatus()) { |
| 203 | return; |
| 204 | } |
| 205 | if (num_bits != 168) { |
| 206 | status = AIS_ERR_BAD_BIT_COUNT; |
| 207 | return; |
| 208 | } |
| 209 | |
| 210 | bits.SeekTo(56); |
| 211 | country = bits.ToString(56, 12); |
| 212 | for (size_t i = 0; i < 4; i++) { |
| 213 | size_t start = 68 + 25*i; |
| 214 | gauge_ids[i] = bits.ToUnsignedInt(start, 11); |
| 215 | const int sign = bits[start + 11] ? 1 : -1; // 0 negative, 1 pos |
| 216 | // ERROR: the spec has a bit listing mistake |
| 217 | levels[i] = sign * bits.ToUnsignedInt(start + 12, 13); |
| 218 | } |
| 219 | |
| 220 | assert(bits.GetRemaining() == 0); |
| 221 | status = AIS_OK; |
| 222 | } |
| 223 | |
| 224 | // River Information Systems ECE-TRANS-SC3-2006-10r-RIS.pdf |
| 225 | Ais8_200_40::Ais8_200_40(const char *nmea_payload, const size_t pad) |
| 226 | : Ais8(nmea_payload, pad), form(0), dir(0), stream_dir(0), status_raw(0), |
| 227 | spare2(0) { |
| 228 | assert(dac == 200); |
| 229 | assert(fi == 40); |
| 230 | |
| 231 | if (!CheckStatus()) { |
| 232 | return; |
| 233 | } |
| 234 | if (num_bits != 168) { |
| 235 | status = AIS_ERR_BAD_BIT_COUNT; |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | bits.SeekTo(56); |
| 240 | position = bits.ToAisPoint(56, 55); |
| 241 | form = bits.ToUnsignedInt(111, 4); |
| 242 | dir = bits.ToUnsignedInt(115, 9); // degrees |
| 243 | stream_dir = bits.ToUnsignedInt(124, 3); |
| 244 | status_raw = bits.ToUnsignedInt(127, 30); |
| 245 | // TODO(schwehr): Convert the status_raw to the 9 signal lights. |
| 246 | // Appears to be a base 10 setup where each of 9 digits range from 0 to 7 |
| 247 | // for the light level. |
| 248 | spare2 = bits.ToUnsignedInt(157, 11); |
| 249 | |
| 250 | assert(bits.GetRemaining() == 0); |
| 251 | status = AIS_OK; |
| 252 | } |
| 253 | |
| 254 | |
| 255 | // River Information Systems ECE-TRANS-SC3-2006-10r-RIS.pdf |
| 256 | // |
| 257 | // TODO(schwehr): Search the logs for the various possible sizes and make |
| 258 | // tests based on those messages. |
| 259 | Ais8_200_55::Ais8_200_55(const char *nmea_payload, const size_t pad) |
| 260 | : Ais8(nmea_payload, pad), crew(0), passengers(0), yet_more_personnel(0) { |
| 261 | assert(dac == 200); |
| 262 | assert(fi == 55); |
| 263 | |
| 264 | if (!CheckStatus()) { |
| 265 | return; |
| 266 | } |
| 267 | |
| 268 | // The specification says that there are 51 spare bits, but it is possible |
| 269 | // that some transmitters may leave off the spare bits. |
| 270 | if (num_bits != 88 && num_bits != 136 && num_bits != 168) { |
| 271 | status = AIS_ERR_BAD_BIT_COUNT; |
| 272 | return; |
| 273 | } |
| 274 | |
| 275 | bits.SeekTo(56); |
| 276 | crew = bits.ToUnsignedInt(56, 8); |
| 277 | passengers = bits.ToUnsignedInt(64, 13); |
| 278 | yet_more_personnel = bits.ToUnsignedInt(77, 8); |
| 279 | |
| 280 | if (num_bits == 88) { |
| 281 | spare2[0] = bits.ToUnsignedInt(85, 3); |
| 282 | } else if (num_bits == 136) { |
| 283 | spare2[0] = bits.ToUnsignedInt(85, 32); |
| 284 | spare2[1] = bits.ToUnsignedInt(117, 19); |
| 285 | } else { |
| 286 | spare2[0] = bits.ToUnsignedInt(85, 32); |
| 287 | spare2[1] = bits.ToUnsignedInt(117, 32); |
| 288 | spare2[2] = bits.ToUnsignedInt(149, 19); |
| 289 | } |
| 290 | |
| 291 | assert(bits.GetRemaining() == 0); |
| 292 | status = AIS_OK; |
| 293 | } |
| 294 | |
| 295 | } // namespace libais |