41#include <wx/datetime.h>
45#include <wx/textfile.h>
47#include <wx/tokenzr.h>
48#include <wx/filename.h>
52#include "rapidjson/document.h"
53#include "rapidjson/writer.h"
54#include "rapidjson/stringbuffer.h"
62#include "model/geodesic.h"
74static const long long lNaN = 0xfff8000000000000;
75#define NAN (*(double *)&lNaN)
78wxEvtHandler *g_pais_alert_dialog_active;
82wxString GetShipNameFromFile(
int);
106EVT_TIMER(TIMER_AIS1, AisDecoder::OnTimerAIS)
107EVT_TIMER(TIMER_DSC, AisDecoder::OnTimerDSC)
110static constexpr
double ms_to_knot_factor = 1.9438444924406;
116static
bool b_firstrx;
117static
int first_rx_ticks;
119static
double arpa_ref_hdg = NAN;
121static inline
double GeodesicRadToDeg(
double rads) {
122 return rads * 180.0 / M_PI;
125static inline double MS2KNOTS(
double ms) {
return ms * 1.9438444924406; }
127static bool isBuoyMmsi(
unsigned msi) {
132 int mid = msi / 1000000;
135 if ((mid > 200 && mid < 799) || (mid >= 800 && mid < 880) || mid >= 970) {
143int AisMeteoNewMmsi(
int,
int,
int,
int,
int);
147 AIS_Target_Name_Hash *AISTargetNamesC,
148 AIS_Target_Name_Hash *AISTargetNamesNC,
long mmsi);
149static void BuildERIShipTypeHash() {
150 make_hash_ERI(8000, _(
"Vessel, type unknown"));
151 make_hash_ERI(8150, _(
"Freightbarge"));
152 make_hash_ERI(8160, _(
"Tankbarge"));
153 make_hash_ERI(8163, _(
"Tankbarge, dry cargo as if liquid (e.g. cement)"));
154 make_hash_ERI(8450, _(
"Service vessel, police patrol, port service"));
155 make_hash_ERI(8430, _(
"Pushboat, single"));
156 make_hash_ERI(8510, _(
"Object, not otherwise specified"));
157 make_hash_ERI(8470, _(
"Object, towed, not otherwise specified"));
158 make_hash_ERI(8490, _(
"Bunkership"));
159 make_hash_ERI(8010, _(
"Motor freighter"));
160 make_hash_ERI(8020, _(
"Motor tanker"));
161 make_hash_ERI(8021, _(
"Motor tanker, liquid cargo, type N"));
162 make_hash_ERI(8022, _(
"Motor tanker, liquid cargo, type C"));
163 make_hash_ERI(8023, _(
"Motor tanker, dry cargo as if liquid (e.g. cement)"));
164 make_hash_ERI(8030, _(
"Container vessel"));
165 make_hash_ERI(8040, _(
"Gas tanker"));
166 make_hash_ERI(8050, _(
"Motor freighter, tug"));
167 make_hash_ERI(8060, _(
"Motor tanker, tug"));
168 make_hash_ERI(8070, _(
"Motor freighter with one or more ships alongside"));
169 make_hash_ERI(8080, _(
"Motor freighter with tanker"));
170 make_hash_ERI(8090, _(
"Motor freighter pushing one or more freighters"));
171 make_hash_ERI(8100, _(
"Motor freighter pushing at least one tank-ship"));
172 make_hash_ERI(8110, _(
"Tug, freighter"));
173 make_hash_ERI(8120, _(
"Tug, tanker"));
174 make_hash_ERI(8130, _(
"Tug freighter, coupled"));
175 make_hash_ERI(8140, _(
"Tug, freighter/tanker, coupled"));
176 make_hash_ERI(8161, _(
"Tankbarge, liquid cargo, type N"));
177 make_hash_ERI(8162, _(
"Tankbarge, liquid cargo, type C"));
178 make_hash_ERI(8170, _(
"Freightbarge with containers"));
179 make_hash_ERI(8180, _(
"Tankbarge, gas"));
180 make_hash_ERI(8210, _(
"Pushtow, one cargo barge"));
181 make_hash_ERI(8220, _(
"Pushtow, two cargo barges"));
182 make_hash_ERI(8230, _(
"Pushtow, three cargo barges"));
183 make_hash_ERI(8240, _(
"Pushtow, four cargo barges"));
184 make_hash_ERI(8250, _(
"Pushtow, five cargo barges"));
185 make_hash_ERI(8260, _(
"Pushtow, six cargo barges"));
186 make_hash_ERI(8270, _(
"Pushtow, seven cargo barges"));
187 make_hash_ERI(8280, _(
"Pushtow, eight cargo barges"));
188 make_hash_ERI(8290, _(
"Pushtow, nine or more barges"));
189 make_hash_ERI(8310, _(
"Pushtow, one tank/gas barge"));
191 _(
"Pushtow, two barges at least one tanker or gas barge"));
193 _(
"Pushtow, three barges at least one tanker or gas barge"));
195 _(
"Pushtow, four barges at least one tanker or gas barge"));
197 _(
"Pushtow, five barges at least one tanker or gas barge"));
199 _(
"Pushtow, six barges at least one tanker or gas barge"));
201 _(
"Pushtow, seven barges at least one tanker or gas barge"));
203 _(
"Pushtow, eight barges at least one tanker or gas barge"));
205 8390, _(
"Pushtow, nine or more barges at least one tanker or gas barge"));
206 make_hash_ERI(8400, _(
"Tug, single"));
207 make_hash_ERI(8410, _(
"Tug, one or more tows"));
208 make_hash_ERI(8420, _(
"Tug, assisting a vessel or linked combination"));
209 make_hash_ERI(8430, _(
"Pushboat, single"));
210 make_hash_ERI(8440, _(
"Passenger ship, ferry, cruise ship, red cross ship"));
211 make_hash_ERI(8441, _(
"Ferry"));
212 make_hash_ERI(8442, _(
"Red cross ship"));
213 make_hash_ERI(8443, _(
"Cruise ship"));
214 make_hash_ERI(8444, _(
"Passenger ship without accommodation"));
215 make_hash_ERI(8460, _(
"Vessel, work maintenance craft, floating derrick, "
216 "cable-ship, buoy-ship, dredge"));
217 make_hash_ERI(8480, _(
"Fishing boat"));
218 make_hash_ERI(8500, _(
"Barge, tanker, chemical"));
219 make_hash_ERI(1500, _(
"General cargo Vessel maritime"));
220 make_hash_ERI(1510, _(
"Unit carrier maritime"));
221 make_hash_ERI(1520, _(
"Bulk carrier maritime"));
222 make_hash_ERI(1530, _(
"Tanker"));
223 make_hash_ERI(1540, _(
"Liquified gas tanker"));
224 make_hash_ERI(1850, _(
"Pleasure craft, longer than 20 metres"));
225 make_hash_ERI(1900, _(
"Fast ship"));
226 make_hash_ERI(1910, _(
"Hydrofoil"));
233static wxString DecodeDSEExpansionCharacters(
const wxString &dseData) {
234 static constexpr std::string_view lookupTable =
235 "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ.,-/ ";
237 bool invalid =
false;
239 for (
size_t i = 0; i < dseData.length(); i += 2) {
240 wxString pair = dseData.Mid(i, 2);
241 if (pair.length() != 2 || !wxIsdigit(pair[0]) || !wxIsdigit(pair[1])) {
245 size_t code = (pair[0] -
'0') * 10 + (pair[1] -
'0');
246 if (code >= lookupTable.size()) {
250 result.append(1, lookupTable[code]);
254 "DSE station information with invalid expansion data ignored "
261static void getMmsiProperties(std::shared_ptr<AisTargetData> &pTargetData) {
265 pTargetData->b_isFollower = props->m_bFollower;
266 pTargetData->b_mPropPersistTrack = props->m_bPersistentTrack;
267 if (TRACKTYPE_NEVER == props->TrackType) {
268 pTargetData->b_show_track =
false;
269 }
else if (TRACKTYPE_ALWAYS == props->TrackType) {
270 pTargetData->b_show_track =
true;
281 const std::shared_ptr<AisTargetData> &ptd) {
282 bool parse_result =
false;
283 bool b_posn_report =
false;
285 wxDateTime now = wxDateTime::Now();
287 int message_ID = bstr->
GetInt(1, 6);
288 ptd->MID = message_ID;
291 int met_mmsi = ptd->MMSI;
294 ptd->MMSI = bstr->
GetInt(9, 30);
296 switch (message_ID) {
302 ptd->NavStatus = bstr->
GetInt(39, 4);
303 ptd->SOG = 0.1 * (bstr->
GetInt(51, 10));
305 int lon = bstr->
GetInt(62, 28);
306 if (lon & 0x08000000)
308 double lon_tentative = lon / 600000.;
310 int lat = bstr->
GetInt(90, 27);
311 if (lat & 0x04000000)
313 double lat_tentative = lat / 600000.;
315 if ((lon_tentative <= 180.) &&
319 ptd->Lon = lon_tentative;
320 ptd->Lat = lat_tentative;
321 ptd->b_positionDoubtful =
false;
322 ptd->b_positionOnceValid =
true;
323 ptd->LastPositionReportTicks = ptd->PositionReportTicks;
324 ptd->PositionReportTicks = now.GetTicks();
326 ptd->b_positionDoubtful =
true;
329 ptd->COG = 0.1 * (bstr->
GetInt(117, 12));
330 ptd->HDG = 1.0 * (bstr->
GetInt(129, 9));
332 ptd->ROTAIS = bstr->
GetInt(43, 8);
333 double rot_dir = 1.0;
335 if (ptd->ROTAIS == 128)
337 else if ((ptd->ROTAIS & 0x80) == 0x80) {
338 ptd->ROTAIS = ptd->ROTAIS - 256;
342 ptd->ROTIND = wxRound(rot_dir * pow((((
double)ptd->ROTAIS) / 4.733),
345 ptd->m_utc_sec = bstr->
GetInt(138, 6);
347 if ((1 == message_ID) ||
350 ptd->SyncState = bstr->
GetInt(151, 2);
351 ptd->SlotTO = bstr->
GetInt(153, 2);
352 if ((ptd->SlotTO == 1) && (ptd->SyncState == 0))
354 ptd->m_utc_hour = bstr->
GetInt(155, 5);
356 ptd->m_utc_min = bstr->
GetInt(160, 7);
358 if ((ptd->m_utc_hour < 24) && (ptd->m_utc_min < 60) &&
359 (ptd->m_utc_sec < 60)) {
360 wxDateTime rx_time(ptd->m_utc_hour, ptd->m_utc_min, ptd->m_utc_sec);
361 rx_ticks = rx_time.GetTicks();
363 first_rx_ticks = rx_ticks;
371 ptd->blue_paddle = bstr->
GetInt(144, 2);
372 ptd->b_blue_paddle = (ptd->blue_paddle == 2);
374 if (!ptd->b_isDSCtarget) ptd->Class = AIS_CLASS_A;
377 int mmsi_start = ptd->MMSI / 10000000;
379 if (mmsi_start == 97) {
380 ptd->Class = AIS_SART;
381 ptd->StaticReportTicks =
396 b_posn_report =
true;
397 ptd->b_VDM_secure_Pos =
true;
406 ptd->SOG = 0.1 * (bstr->
GetInt(47, 10));
408 int lon = bstr->
GetInt(58, 28);
409 if (lon & 0x08000000)
411 double lon_tentative = lon / 600000.;
413 int lat = bstr->
GetInt(86, 27);
414 if (lat & 0x04000000)
416 double lat_tentative = lat / 600000.;
418 if ((lon_tentative <= 180.) &&
422 ptd->Lon = lon_tentative;
423 ptd->Lat = lat_tentative;
424 ptd->b_positionDoubtful =
false;
425 ptd->b_positionOnceValid =
true;
426 ptd->LastPositionReportTicks = ptd->PositionReportTicks;
427 ptd->PositionReportTicks = now.GetTicks();
429 ptd->b_positionDoubtful =
true;
431 ptd->COG = 0.1 * (bstr->
GetInt(113, 12));
432 ptd->HDG = 1.0 * (bstr->
GetInt(125, 9));
434 ptd->m_utc_sec = bstr->
GetInt(134, 6);
436 if (!ptd->b_isDSCtarget) {
437 if (!isBuoyMmsi(ptd->MMSI))
438 ptd->Class = AIS_CLASS_B;
440 ptd->Class = AIS_BUOY;
443 b_posn_report =
true;
444 ptd->b_VDM_secure_Pos =
true;
452 ptd->SOG = 0.1 * (bstr->
GetInt(47, 10));
453 int lon = bstr->
GetInt(58, 28);
454 if (lon & 0x08000000)
456 double lon_tentative = lon / 600000.;
458 int lat = bstr->
GetInt(86, 27);
459 if (lat & 0x04000000)
461 double lat_tentative = lat / 600000.;
463 if ((lon_tentative <= 180.) &&
467 ptd->Lon = lon_tentative;
468 ptd->Lat = lat_tentative;
469 ptd->b_positionDoubtful =
false;
470 ptd->b_positionOnceValid =
true;
471 ptd->LastPositionReportTicks = ptd->PositionReportTicks;
472 ptd->PositionReportTicks = now.GetTicks();
474 ptd->b_positionDoubtful =
true;
476 ptd->COG = 0.1 * (bstr->
GetInt(113, 12));
477 ptd->HDG = 1.0 * (bstr->
GetInt(125, 9));
478 ptd->m_utc_sec = bstr->
GetInt(134, 6);
480 bstr->GetStr(144, 120, &ptd->ShipName[0], SHIP_NAME_LEN);
481 ptd->b_nameValid =
true;
482 if (!ptd->b_isDSCtarget) {
483 ptd->ShipType = (
unsigned char)bstr->
GetInt(264, 8);
485 ptd->DimA = bstr->
GetInt(272, 9);
486 ptd->DimB = bstr->
GetInt(281, 9);
487 ptd->DimC = bstr->
GetInt(290, 6);
488 ptd->DimD = bstr->
GetInt(296, 6);
490 if (!ptd->b_isDSCtarget) {
492 if (!isBuoyMmsi(ptd->MMSI))
493 ptd->Class = AIS_CLASS_B;
495 ptd->Class = AIS_BUOY;
498 b_posn_report =
true;
499 ptd->b_VDM_secure_Pos =
true;
511 if (ptd->b_VDM_secure_Pos)
break;
516 int bitCorrection = 10;
520 double lon_tentative = 181.;
521 double lat_tentative = 91.;
524 printf(
"AIS Message 27 - received:\r\n");
525 printf(
"MMSI : %i\r\n", ptd->MMSI);
531 ptd->Class == AIS_CLASS_A ? bstr->
GetInt(41, 4) : UNDEFINED;
533 int lon = bstr->
GetInt(45, 18);
534 int lat = bstr->
GetInt(63, 17);
540 if (lat >= (0x4000000 >> bitCorrection)) {
541 lat_tentative = (0x8000000 >> bitCorrection) - lat;
546 if (lon >= (0x8000000 >> bitCorrection)) {
547 lon_tentative = (0x10000000 >> bitCorrection) - lon;
552 lat_tentative = lat_tentative / resolution / 60.0;
553 lon_tentative = lon_tentative / resolution / 60.0;
556 printf(
"Latitude : %f\r\n", lat_tentative);
557 printf(
"Longitude : %f\r\n", lon_tentative);
561 int positionLatency = bstr->
GetInt(95, 1);
563 if ((lon_tentative <= 180.) &&
567 ptd->Lon = lon_tentative;
568 ptd->Lat = lat_tentative;
569 ptd->b_positionDoubtful =
false;
570 ptd->b_positionOnceValid =
true;
571 if (positionLatency == 0) {
574 printf(
"Low latency position report.\r\n");
576 ptd->LastPositionReportTicks = ptd->PositionReportTicks;
577 ptd->PositionReportTicks = now.GetTicks();
580 ptd->b_positionDoubtful =
true;
582 ptd->SOG = 1.0 * (bstr->
GetInt(80, 6));
583 ptd->COG = 1.0 * (bstr->
GetInt(85, 9));
585 b_posn_report =
true;
591 if (bstr->GetBitCount() >= 424) {
593 if (!ptd->b_isDSCtarget) ptd->Class = AIS_CLASS_A;
599 int AIS_version_indicator = bstr->
GetInt(39, 2);
600 if (AIS_version_indicator < 4) {
601 ptd->IMO = bstr->
GetInt(41, 30);
603 bstr->GetStr(71, 42, &ptd->CallSign[0], 7);
604 bstr->GetStr(113, 120, &ptd->ShipName[0], SHIP_NAME_LEN);
605 ptd->b_nameValid =
true;
606 if (!ptd->b_isDSCtarget) {
607 ptd->ShipType = (
unsigned char)bstr->
GetInt(233, 8);
610 ptd->DimA = bstr->
GetInt(241, 9);
611 ptd->DimB = bstr->
GetInt(250, 9);
612 ptd->DimC = bstr->
GetInt(259, 6);
613 ptd->DimD = bstr->
GetInt(265, 6);
615 ptd->ETA_Mo = bstr->
GetInt(275, 4);
616 ptd->ETA_Day = bstr->
GetInt(279, 5);
617 ptd->ETA_Hr = bstr->
GetInt(284, 5);
618 ptd->ETA_Min = bstr->
GetInt(289, 6);
620 ptd->Draft = (double)(bstr->
GetInt(295, 8)) / 10.0;
622 bstr->GetStr(303, 120, &ptd->Destination[0], DESTINATION_LEN - 1);
624 ptd->StaticReportTicks = now.GetTicks();
635 if (!ptd->b_positionOnceValid)
break;
637 int part_number = bstr->
GetInt(39, 2);
638 if (0 == part_number) {
639 bstr->GetStr(41, 120, &ptd->ShipName[0], SHIP_NAME_LEN);
640 ptd->b_nameValid =
true;
643 }
else if (1 == part_number) {
644 if (!ptd->b_isDSCtarget) {
645 ptd->ShipType = (
unsigned char)bstr->
GetInt(41, 8);
647 bstr->GetStr(91, 42, &ptd->CallSign[0], 7);
649 ptd->DimA = bstr->
GetInt(133, 9);
650 ptd->DimB = bstr->
GetInt(142, 9);
651 ptd->DimC = bstr->
GetInt(151, 6);
652 ptd->DimD = bstr->
GetInt(157, 6);
659 ptd->Class = AIS_BASE;
661 ptd->m_utc_hour = bstr->
GetInt(62, 5);
662 ptd->m_utc_min = bstr->
GetInt(67, 6);
663 ptd->m_utc_sec = bstr->
GetInt(73, 6);
665 int lon = bstr->
GetInt(80, 28);
666 if (lon & 0x08000000)
668 double lon_tentative = lon / 600000.;
670 int lat = bstr->
GetInt(108, 27);
671 if (lat & 0x04000000)
673 double lat_tentative = lat / 600000.;
675 if ((lon_tentative <= 180.) &&
679 ptd->Lon = lon_tentative;
680 ptd->Lat = lat_tentative;
681 ptd->b_positionDoubtful =
false;
682 ptd->b_positionOnceValid =
true;
683 ptd->LastPositionReportTicks = ptd->PositionReportTicks;
684 ptd->PositionReportTicks = now.GetTicks();
686 ptd->b_positionDoubtful =
true;
693 b_posn_report =
true;
699 ptd->SOG = bstr->
GetInt(51, 10);
701 int lon = bstr->
GetInt(62, 28);
702 if (lon & 0x08000000)
704 double lon_tentative = lon / 600000.;
706 int lat = bstr->
GetInt(90, 27);
707 if (lat & 0x04000000)
709 double lat_tentative = lat / 600000.;
711 if ((lon_tentative <= 180.) &&
715 ptd->Lon = lon_tentative;
716 ptd->Lat = lat_tentative;
717 ptd->b_positionDoubtful =
false;
718 ptd->b_positionOnceValid =
true;
719 ptd->LastPositionReportTicks = ptd->PositionReportTicks;
720 ptd->PositionReportTicks = now.GetTicks();
722 ptd->b_positionDoubtful =
true;
725 ptd->COG = 0.1 * (bstr->
GetInt(117, 12));
727 int alt_tent = bstr->
GetInt(39, 12);
728 ptd->altitude = alt_tent;
730 ptd->b_SarAircraftPosnReport =
true;
733 b_posn_report =
true;
739 ptd->ShipType = (
unsigned char)bstr->
GetInt(39, 5);
745 ptd->DimA = bstr->
GetInt(220, 9);
746 ptd->DimB = bstr->
GetInt(229, 9);
747 ptd->DimC = bstr->
GetInt(238, 6);
748 ptd->DimD = bstr->
GetInt(244, 6);
751 ptd->m_utc_sec = bstr->
GetInt(254, 6);
753 int offpos = bstr->
GetInt(260, 1);
754 int virt = bstr->
GetInt(270, 1);
757 ptd->NavStatus = ATON_VIRTUAL;
759 ptd->NavStatus = ATON_REAL;
760 if (ptd->m_utc_sec <= 59 ) {
762 if (offpos) ptd->NavStatus += 1;
765 bstr->GetStr(44, 120, &ptd->ShipName[0], SHIP_NAME_LEN);
768 if (bstr->GetBitCount() > 276) {
769 int nx = ((bstr->GetBitCount() - 272) / 6) * 6;
770 bstr->GetStr(273, nx, &ptd->ShipNameExtension[0], 14);
771 ptd->ShipNameExtension[14] = 0;
773 ptd->ShipNameExtension[0] = 0;
776 ptd->b_nameValid =
true;
780 ptd->Class = AIS_ATON;
782 int lon = bstr->
GetInt(165, 28);
784 if (lon & 0x08000000)
786 double lon_tentative = lon / 600000.;
788 int lat = bstr->
GetInt(193, 27);
790 if (lat & 0x04000000)
792 double lat_tentative = lat / 600000.;
794 if ((lon_tentative <= 180.) &&
798 ptd->Lon = lon_tentative;
799 ptd->Lat = lat_tentative;
800 ptd->b_positionDoubtful =
false;
801 ptd->b_positionOnceValid =
true;
802 ptd->LastPositionReportTicks = ptd->PositionReportTicks;
803 ptd->PositionReportTicks = now.GetTicks();
805 ptd->b_positionDoubtful =
true;
807 b_posn_report =
true;
812 int dac = bstr->
GetInt(41, 10);
813 int fi = bstr->
GetInt(51, 6);
819 ptd->b_isEuroInland =
true;
821 bstr->GetStr(57, 48, &ptd->Euro_VIN[0], 8);
822 ptd->Euro_Length = ((double)bstr->
GetInt(105, 13)) / 10.0;
823 ptd->Euro_Beam = ((double)bstr->
GetInt(118, 10)) / 10.0;
824 ptd->UN_shiptype = bstr->
GetInt(128, 14);
825 ptd->Euro_Draft = ((double)bstr->
GetInt(145, 11)) / 100.0;
829 if (dac == 1 || dac == 366)
833 if (bstr->GetBitCount() >= 111) {
835 an.link_id = bstr->
GetInt(57, 10);
836 an.notice_type = bstr->
GetInt(67, 7);
837 an.month = bstr->
GetInt(74, 4);
838 an.day = bstr->
GetInt(78, 5);
839 an.hour = bstr->
GetInt(83, 5);
840 an.minute = bstr->
GetInt(88, 6);
841 an.duration_minutes = bstr->
GetInt(94, 18);
843 wxDateTime now_ = wxDateTime::Now();
846 an.start_time.Set(an.day, wxDateTime::Month(an.month - 1),
847 now_.GetYear(), an.hour, an.minute);
852 if (an.start_time > now_ + wxTimeSpan::Hours(48))
853 an.start_time.Set(an.day, wxDateTime::Month(an.month - 1),
854 now_.GetYear() - 1, an.hour, an.minute);
857 an.start_time + wxTimeSpan::Minutes(an.duration_minutes);
862 if (an.expiry_time < now_ - wxTimeSpan::Hours(24)) {
863 an.start_time.Set(an.day, wxDateTime::Month(an.month - 1),
864 now_.GetYear() + 1, an.hour, an.minute);
866 an.start_time + wxTimeSpan::Minutes(an.duration_minutes);
871 int subarea_len = 87;
874 float pos_scale = 60000.0;
882 pos_scale = 600000.0;
887 int subarea_count = (bstr->GetBitCount() - 111) / subarea_len;
888 for (
int i = 0; i < subarea_count; ++i) {
889 int base = 111 + i * subarea_len;
891 sa.shape = bstr->
GetInt(base + 1, 3);
892 int scale_factor = 1;
893 if (sa.shape == AIS8_001_22_SHAPE_TEXT) {
896 bstr->GetStr(base + 4, subarea_len - 3, t, 14);
897 sa.text = wxString(t, wxConvUTF8);
899 int scale_multipliers[4] = {1, 10, 100, 1000};
900 scale_factor = scale_multipliers[bstr->
GetInt(base + 4, 2)];
902 case AIS8_001_22_SHAPE_SECTOR:
903 sa.left_bound_deg = bstr->
GetInt(
904 base + 6 + lon_len + lat_len + prec_size + 12, 9);
905 sa.right_bound_deg = bstr->
GetInt(
906 base + 6 + lon_len + lat_len + prec_size + 12 + 9, 9);
907 case AIS8_001_22_SHAPE_CIRCLE:
909 bstr->
GetInt(base + 6 + lon_len + lat_len + 3, 12) *
912 case AIS8_001_22_SHAPE_RECT:
914 bstr->
GetInt(base + 6, lon_len,
true) / pos_scale;
916 bstr->
GetInt(base + 6 + lon_len, lat_len,
true) /
919 bstr->
GetInt(base + 6 + lon_len + lat_len + prec_size,
924 base + 6 + lon_len + lat_len + prec_size + 8, 8) *
926 sa.orient_deg = bstr->
GetInt(
927 base + 6 + lon_len + lat_len + prec_size + 8 + 8, 9);
929 case AIS8_001_22_SHAPE_POLYLINE:
930 case AIS8_001_22_SHAPE_POLYGON:
931 for (
int j = 0; j < 4; ++j) {
932 sa.angles[j] = bstr->
GetInt(base + 6 + j * 20, 10) * 0.5;
934 bstr->
GetInt(base + 16 + j * 20, 10) * scale_factor;
938 an.sub_areas.push_back(sa);
940 ptd->area_notices[an.link_id] = an;
947 if (bstr->GetBitCount() >= 360) {
949 if (met_mmsi != 666) ptd->MMSI = met_mmsi;
952 double lon_tentative = 181.;
953 double lat_tentative = 91.;
955 int lon = bstr->
GetInt(57, 25);
956 int lat = bstr->
GetInt(82, 24);
958 if (lon & 0x01000000)
960 lon_tentative = lon / 60000.;
962 if (lat & 0x00800000)
964 lat_tentative = lat / 60000.;
966 ptd->Lon = lon_tentative;
967 ptd->Lat = lat_tentative;
970 wxString x = ptd->ShipName;
971 if (x.Find(
"METEO") == wxNOT_FOUND) {
973 wxString slat = wxString::Format(
"%0.3f", lat_tentative);
974 wxString slon = wxString::Format(
"%0.3f", lon_tentative);
977 wxString nameID =
"METEO ";
978 nameID << wxString::Format(
"%0.3f", abs(id1) + abs(id2)).Right(3);
979 strncpy(ptd->ShipName, nameID, SHIP_NAME_LEN - 1);
982 ptd->met_data.pos_acc = bstr->
GetInt(106, 1);
983 ptd->met_data.day = bstr->
GetInt(107, 5);
984 ptd->met_data.hour = bstr->
GetInt(112, 5);
985 ptd->met_data.minute = bstr->
GetInt(117, 6);
986 ptd->met_data.wind_kn = bstr->
GetInt(123, 7);
987 ptd->met_data.wind_gust_kn = bstr->
GetInt(130, 7);
988 ptd->met_data.wind_dir = bstr->
GetInt(137, 9);
989 ptd->met_data.wind_gust_dir = bstr->
GetInt(146, 9);
991 int tmp = bstr->
GetInt(155, 11);
992 if (tmp & 0x00000400)
994 ptd->met_data.air_temp = tmp / 10.;
995 ptd->met_data.rel_humid = bstr->
GetInt(166, 7);
996 int dew = bstr->
GetInt(173, 10);
997 if (dew & 0x00000200)
999 ptd->met_data.dew_point = dew / 10.;
1004 ptd->met_data.airpress = bstr->
GetInt(183, 9) + 799;
1005 ptd->met_data.airpress_tend = bstr->
GetInt(192, 2);
1007 int horVis = bstr->
GetInt(194, 8);
1008 if (horVis & 0x80u) {
1010 ptd->met_data.hor_vis_GT =
true;
1012 ptd->met_data.hor_vis_GT =
false;
1014 ptd->met_data.hor_vis = horVis / 10.0;
1016 ptd->met_data.water_lev_dev = (bstr->
GetInt(202, 12) / 100.) - 10.;
1017 ptd->met_data.water_lev_trend = bstr->
GetInt(214, 2);
1018 ptd->met_data.current = bstr->
GetInt(216, 8) / 10.;
1019 ptd->met_data.curr_dir = bstr->
GetInt(224, 9);
1020 ptd->met_data.wave_height = bstr->
GetInt(277, 8) / 10.;
1021 ptd->met_data.wave_period = bstr->
GetInt(285, 6);
1022 ptd->met_data.wave_dir = bstr->
GetInt(291, 9);
1023 ptd->met_data.swell_height = bstr->
GetInt(300, 8) / 10;
1024 ptd->met_data.swell_per = bstr->
GetInt(308, 6);
1025 ptd->met_data.swell_dir = bstr->
GetInt(314, 9);
1026 ptd->met_data.seastate = bstr->
GetInt(323, 4);
1028 int wt = bstr->
GetInt(327, 10);
1029 if (wt & 0x00000200)
1031 ptd->met_data.water_temp = wt / 10.;
1033 ptd->met_data.precipitation = bstr->
GetInt(337, 3);
1034 ptd->met_data.salinity = bstr->
GetInt(340, 9) / 10.;
1035 ptd->met_data.ice = bstr->
GetInt(349, 2);
1037 ptd->Class = AIS_METEO;
1041 ptd->b_NoTrack =
true;
1042 ptd->b_show_track =
false;
1043 ptd->b_positionDoubtful =
false;
1044 ptd->b_positionOnceValid =
true;
1045 b_posn_report =
true;
1046 ptd->LastPositionReportTicks = ptd->PositionReportTicks;
1047 ptd->PositionReportTicks = now.GetTicks();
1048 ptd->b_nameValid =
true;
1050 parse_result =
true;
1056 if (dac == 367 && fi == 33) {
1060 const int size = bstr->GetBitCount();
1063 if (met_mmsi != 666) ptd->MMSI = met_mmsi;
1064 const int startbits = 56;
1065 const int slotsize = 112;
1066 const int slots_count = (size - startbits) / slotsize;
1068 for (
int slot = 0; slot < slots_count; slot++) {
1069 slotbit = slot * slotsize;
1070 int type = bstr->
GetInt(slotbit + 57, 4);
1071 ptd->met_data.hour = bstr->
GetInt(slotbit + 66, 5);
1072 ptd->met_data.minute = bstr->
GetInt(slotbit + 71, 6);
1073 int Site_ID = bstr->
GetInt(slotbit + 77, 7);
1076 if (!ptd->b_nameValid) {
1077 wxString nameID =
"METEO Site: ";
1079 strncpy(ptd->ShipName, nameID, SHIP_NAME_LEN - 1);
1080 ptd->b_nameValid =
true;
1084 int lon = bstr->
GetInt(slotbit + 90, 28);
1085 if (lon & 0x08000000)
1087 ptd->Lon = lon / 600000.;
1089 int lat = bstr->
GetInt(slotbit + 118, 27);
1090 if (lat & 0x04000000)
1092 ptd->Lat = lat / 600000.;
1093 ptd->b_positionOnceValid =
true;
1095 }
else if (type == 1) {
1096 bstr->GetStr(slotbit + 84, 84, &ptd->ShipName[0], SHIP_NAME_LEN);
1097 ptd->b_nameValid =
true;
1099 }
else if (type == 2) {
1101 int descr = bstr->
GetInt(slotbit + 116, 3);
1102 if (descr == 1 || descr == 2) {
1103 ptd->met_data.wind_kn = bstr->
GetInt(slotbit + 84, 7);
1104 ptd->met_data.wind_gust_kn = bstr->
GetInt(slotbit + 91, 7);
1105 ptd->met_data.wind_dir = bstr->
GetInt(slotbit + 98, 9);
1106 ptd->met_data.wind_gust_dir = bstr->
GetInt(slotbit + 107, 9);
1109 }
else if (type == 3) {
1111 int descr = bstr->
GetInt(slotbit + 108, 3);
1112 if (descr == 1 || descr == 2) {
1113 int wltype = bstr->
GetInt(slotbit + 84, 1);
1114 int wl = bstr->
GetInt(slotbit + 85, 16);
1115 if (wl & 0x00004000)
1119 ptd->met_data.water_level = wl / 100.;
1121 ptd->met_data.water_lev_dev = wl / 100.;
1123 ptd->met_data.water_lev_trend = bstr->
GetInt(slotbit + 101, 2);
1124 ptd->met_data.vertical_ref = bstr->
GetInt(slotbit + 103, 5);
1126 }
else if (type == 6) {
1127 ptd->met_data.current = bstr->
GetInt(slotbit + 102, 8) / 10.0;
1128 ptd->met_data.curr_dir = bstr->
GetInt(slotbit + 110, 9);
1129 }
else if (type == 7) {
1131 bstr->
GetInt(slotbit + 111, 3);
1132 if (swell_descr == 1 || swell_descr == 2) {
1133 ptd->met_data.swell_height =
1134 bstr->
GetInt(slotbit + 84, 8) / 10.0;
1135 ptd->met_data.swell_per = bstr->
GetInt(slotbit + 92, 6);
1136 ptd->met_data.swell_dir = bstr->
GetInt(slotbit + 98, 9);
1138 ptd->met_data.seastate = bstr->
GetInt(slotbit + 107, 4);
1139 int wt_descr = bstr->
GetInt(slotbit + 131, 3);
1140 if (wt_descr == 1 || wt_descr == 2)
1141 ptd->met_data.water_temp =
1142 bstr->
GetInt(slotbit + 114, 10) / 10. - 10.;
1144 int wawe_descr = bstr->
GetInt(slotbit + 157, 3);
1145 if (wawe_descr == 1 || wawe_descr == 2) {
1146 ptd->met_data.wave_height =
1147 bstr->
GetInt(slotbit + 134, 8) / 10.0;
1148 ptd->met_data.wave_period = bstr->
GetInt(slotbit + 142, 6);
1149 ptd->met_data.wave_dir = bstr->
GetInt(slotbit + 148, 9);
1151 ptd->met_data.salinity = bstr->
GetInt(slotbit + 160, 9 / 10.0);
1153 }
else if (type == 8) {
1154 ptd->met_data.water_temp =
1155 bstr->
GetInt(slotbit + 84, 10) / 10.0 - 10.0;
1156 ptd->met_data.salinity = bstr->
GetInt(slotbit + 120, 9) / 10.0;
1158 }
else if (type == 9) {
1159 int tmp = bstr->
GetInt(slotbit + 84, 11);
1160 if (tmp & 0x00000400)
1162 ptd->met_data.air_temp = tmp / 10.;
1163 int pp, precip = bstr->
GetInt(slotbit + 98, 2);
1174 ptd->met_data.precipitation = pp;
1175 ptd->met_data.hor_vis = bstr->
GetInt(slotbit + 100, 8) / 10.0;
1176 ptd->met_data.dew_point =
1177 bstr->
GetInt(slotbit + 108, 10) / 10.0 - 20.0;
1178 ptd->met_data.airpress = bstr->
GetInt(slotbit + 121, 9) + 799;
1179 ptd->met_data.airpress_tend = bstr->
GetInt(slotbit + 130, 2);
1180 ptd->met_data.salinity = bstr->
GetInt(slotbit + 135, 9) / 10.0;
1182 }
else if (type == 11) {
1184 int descr = bstr->
GetInt(slotbit + 113, 3);
1185 if (descr == 1 || descr == 2) {
1186 ptd->met_data.wind_kn = bstr->
GetInt(slotbit + 84, 7);
1187 ptd->met_data.wind_gust_kn = bstr->
GetInt(slotbit + 91, 7);
1188 ptd->met_data.wind_dir = bstr->
GetInt(slotbit + 98, 9);
1193 if (ptd->b_positionOnceValid) {
1194 ptd->Class = AIS_METEO;
1198 ptd->b_NoTrack =
true;
1199 ptd->b_show_track =
false;
1200 ptd->b_positionDoubtful =
false;
1201 b_posn_report =
true;
1202 ptd->LastPositionReportTicks = ptd->PositionReportTicks;
1203 ptd->PositionReportTicks = now.GetTicks();
1204 ptd->b_nameValid =
true;
1206 parse_result =
true;
1216 char msg_14_text[968];
1217 if (bstr->GetBitCount() > 40) {
1218 int nx = ((bstr->GetBitCount() - 40) / 6) * 6;
1219 int nd = bstr->GetStr(41, nx, msg_14_text, 968);
1221 nd = wxMin(nd, 967);
1222 msg_14_text[nd] = 0;
1223 ptd->MSG_14_text = wxString(msg_14_text, wxConvUTF8);
1225 parse_result =
true;
1238 if (b_posn_report) ptd->b_lost =
false;
1240 if (
true == parse_result) {
1242 if (!ptd->b_active && !ptd->b_positionDoubtful && b_posn_report)
1243 ptd->b_active =
true;
1246 return parse_result;
1250 : m_signalk_selfid(
""), m_callbacks(callbacks) {
1252 AISTargetNamesC =
new AIS_Target_Name_Hash;
1253 AISTargetNamesNC =
new AIS_Target_Name_Hash;
1255 if (g_benableAISNameCache) {
1259 AIS_Target_Name_Hash *HashFile = AISTargetNamesNC;
1260 wxString line = infile.GetFirstLine();
1261 while (!infile.Eof()) {
1262 if (line.IsSameAs(
"+++==Confirmed Entry's==+++"))
1263 HashFile = AISTargetNamesC;
1265 if (line.IsSameAs(
"+++==Non Confirmed Entry's==+++"))
1266 HashFile = AISTargetNamesNC;
1268 wxStringTokenizer tokenizer(line,
",");
1269 int mmsi = wxAtoi(tokenizer.GetNextToken());
1270 wxString name = tokenizer.GetNextToken().Trim();
1271 (*HashFile)[mmsi] = name;
1274 line = infile.GetNextLine();
1281 BuildERIShipTypeHash();
1283 g_pais_alert_dialog_active =
nullptr;
1284 m_bAIS_Audio_Alert_On =
false;
1288 m_bAIS_AlertPlaying =
false;
1290 TimerAIS.SetOwner(
this, TIMER_AIS1);
1291 TimerAIS.Start(TIMER_AIS_MSEC, wxTIMER_CONTINUOUS);
1293 m_ptentative_dsctarget =
nullptr;
1294 m_dsc_timer.SetOwner(
this, TIMER_DSC);
1301 InitCommListeners();
1304AisDecoder::~AisDecoder() {
1314 wxString content =
"+++==Confirmed Entry's==+++";
1315 AIS_Target_Name_Hash::iterator it;
1316 for (it = AISTargetNamesC->begin(); it != AISTargetNamesC->end(); ++it) {
1317 content.append(
"\r\n");
1318 content.append(wxString::Format(
"%i", it->first));
1319 content.append(
",").append(it->second);
1321 content.append(
"\r\n");
1322 content.append(
"+++==Non Confirmed Entry's==+++");
1323 for (it = AISTargetNamesNC->begin(); it != AISTargetNamesNC->end(); ++it) {
1324 content.append(
"\r\n");
1325 content.append(wxString::Format(
"%i", it->first));
1326 content.append(
",").append(it->second);
1328 outfile.Write(content);
1332 AISTargetNamesC->clear();
1333 delete AISTargetNamesC;
1334 AISTargetNamesNC->clear();
1335 delete AISTargetNamesNC;
1340 m_AIS_Audio_Alert_Timer.Stop();
1345 "First message[1, 2] ticks: %d Last Message [1,2]ticks %d Difference: "
1347 first_rx_ticks, rx_ticks, rx_ticks - first_rx_ticks);
1351bool IsTargetOnTheIgnoreList(
const int &mmsi) {
1356 if (props->m_bignore) {
1364void AisDecoder::InitCommListeners() {
1369 Nmea0183Msg n0183_msg_VDM(
"VDM");
1370 listener_N0183_VDM.Listen(n0183_msg_VDM,
this, EVT_N0183_VDM);
1371 Bind(EVT_N0183_VDM, [&](
const ObservedEvt &ev) {
1373 auto n0183_msg = std::static_pointer_cast<const Nmea0183Msg>(ptr);
1374 HandleN0183_AIS(n0183_msg);
1378 Nmea0183Msg n0183_msg_FRPOS(
"FRPOS");
1379 listener_N0183_FRPOS.Listen(n0183_msg_FRPOS,
this, EVT_N0183_FRPOS);
1381 Bind(EVT_N0183_FRPOS, [&](
const ObservedEvt &ev) {
1383 auto n0183_msg = std::static_pointer_cast<const Nmea0183Msg>(ptr);
1384 HandleN0183_AIS(n0183_msg);
1388 Nmea0183Msg n0183_msg_CDDSC(
"CDDSC");
1389 listener_N0183_CDDSC.Listen(n0183_msg_CDDSC,
this, EVT_N0183_CDDSC);
1390 Bind(EVT_N0183_CDDSC, [&](
const ObservedEvt &ev) {
1392 auto n0183_msg = std::static_pointer_cast<const Nmea0183Msg>(ptr);
1393 HandleN0183_AIS(n0183_msg);
1397 Nmea0183Msg n0183_msg_CDDSE(
"CDDSE");
1398 listener_N0183_CDDSE.Listen(n0183_msg_CDDSE,
this, EVT_N0183_CDDSE);
1399 Bind(EVT_N0183_CDDSE, [&](
const ObservedEvt &ev) {
1401 auto n0183_msg = std::static_pointer_cast<const Nmea0183Msg>(ptr);
1402 HandleN0183_AIS(n0183_msg);
1406 Nmea0183Msg n0183_msg_TLL(
"TLL");
1407 listener_N0183_TLL.Listen(n0183_msg_TLL,
this, EVT_N0183_TLL);
1409 Bind(EVT_N0183_TLL, [&](
const ObservedEvt &ev) {
1411 auto n0183_msg = std::static_pointer_cast<const Nmea0183Msg>(ptr);
1412 HandleN0183_AIS(n0183_msg);
1416 Nmea0183Msg n0183_msg_ttm(
"TTM");
1417 listener_N0183_TTM.Listen(n0183_msg_ttm,
this, EVT_N0183_TTM);
1418 Bind(EVT_N0183_TTM, [&](
const ObservedEvt &ev) {
1420 auto n0183_msg = std::static_pointer_cast<const Nmea0183Msg>(ptr);
1421 HandleN0183_AIS(n0183_msg);
1425 Nmea0183Msg n0183_msg_OSD(
"OSD");
1426 listener_N0183_OSD.Listen(n0183_msg_OSD,
this, EVT_N0183_OSD);
1427 Bind(EVT_N0183_OSD, [&](
const ObservedEvt &ev) {
1429 auto n0183_msg = std::static_pointer_cast<const Nmea0183Msg>(ptr);
1430 HandleN0183_AIS(n0183_msg);
1434 Nmea0183Msg n0183_msg_WPL(
"WPL");
1435 listener_N0183_WPL.Listen(n0183_msg_WPL,
this, EVT_N0183_WPL);
1436 Bind(EVT_N0183_WPL, [&](
const ObservedEvt &ev) {
1438 auto n0183_msg = std::static_pointer_cast<const Nmea0183Msg>(ptr);
1439 HandleN0183_AIS(n0183_msg);
1444 listener_SignalK.Listen(sk_msg,
this, EVT_SIGNALK);
1445 Bind(EVT_SIGNALK, [&](
const ObservedEvt &ev) {
1446 HandleSignalK(obs::UnpackEvtPointer<SignalkMsg>(ev));
1451 Nmea2000Msg n2k_msg_129038(
static_cast<uint64_t
>(129038));
1452 listener_N2K_129038.Listen(n2k_msg_129038,
this, EVT_N2K_129038);
1453 Bind(EVT_N2K_129038, [&](
const ObservedEvt &ev) {
1454 HandleN2K_129038(obs::UnpackEvtPointer<Nmea2000Msg>(ev));
1459 Nmea2000Msg n2k_msg_129039(
static_cast<uint64_t
>(129039));
1460 listener_N2K_129039.Listen(n2k_msg_129039,
this, EVT_N2K_129039);
1461 Bind(EVT_N2K_129039, [&](
const ObservedEvt &ev) {
1462 HandleN2K_129039(obs::UnpackEvtPointer<Nmea2000Msg>(ev));
1467 Nmea2000Msg n2k_msg_129041(
static_cast<uint64_t
>(129041));
1468 listener_N2K_129041.Listen(n2k_msg_129041,
this, EVT_N2K_129041);
1469 Bind(EVT_N2K_129041, [&](
const ObservedEvt &ev) {
1470 HandleN2K_129041(obs::UnpackEvtPointer<Nmea2000Msg>(ev));
1475 Nmea2000Msg n2k_msg_129794(
static_cast<uint64_t
>(129794));
1476 listener_N2K_129794.Listen(n2k_msg_129794,
this, EVT_N2K_129794);
1477 Bind(EVT_N2K_129794, [&](
const ObservedEvt &ev) {
1478 HandleN2K_129794(obs::UnpackEvtPointer<Nmea2000Msg>(ev));
1483 Nmea2000Msg n2k_msg_129809(
static_cast<uint64_t
>(129809));
1484 listener_N2K_129809.Listen(n2k_msg_129809,
this, EVT_N2K_129809);
1485 Bind(EVT_N2K_129809, [&](
const ObservedEvt &ev) {
1486 HandleN2K_129809(obs::UnpackEvtPointer<Nmea2000Msg>(ev));
1491 Nmea2000Msg n2k_msg_129810(
static_cast<uint64_t
>(129810));
1492 listener_N2K_129810.Listen(n2k_msg_129810,
this, EVT_N2K_129810);
1493 Bind(EVT_N2K_129810, [&](
const ObservedEvt &ev) {
1494 HandleN2K_129810(obs::UnpackEvtPointer<Nmea2000Msg>(ev));
1499 Nmea2000Msg n2k_msg_129793(
static_cast<uint64_t
>(129793));
1500 listener_N2K_129793.Listen(n2k_msg_129793,
this, EVT_N2K_129793);
1501 Bind(EVT_N2K_129793, [&](
const ObservedEvt &ev) {
1502 HandleN2K_129793(obs::UnpackEvtPointer<Nmea2000Msg>(ev));
1506bool AisDecoder::HandleN0183_AIS(
const N0183MsgPtr &n0183_msg) {
1507 std::string str = n0183_msg->payload;
1508 wxString sentence(str.c_str());
1509 DecodeN0183(sentence);
1514bool AisDecoder::HandleN2K_129038(
const N2000MsgPtr &n2k_msg) {
1515 std::vector<unsigned char> v = n2k_msg->payload;
1518 tN2kAISRepeat Repeat;
1529 tN2kAISNavStatus NavStat = N2kaisns_Under_Way_Motoring;
1530 tN2kAISTransceiverInformation AISTransceiverInformation;
1532 if (ParseN2kPGN129038(v, MessageID, Repeat, UserID, Latitude, Longitude,
1533 Accuracy, RAIM, Seconds, COG, SOG, Heading, ROT,
1534 NavStat, AISTransceiverInformation)) {
1535 unsigned mmsi = UserID;
1537 if (mmsi ==
g_OwnShipmmsi || IsTargetOnTheIgnoreList(mmsi))
return false;
1541 std::shared_ptr<AisTargetData> pTargetData =
nullptr;
1542 bool bnewtarget =
false;
1544 auto it = AISTargetList.find(mmsi);
1545 if (it == AISTargetList.end())
1547 pTargetData = AisTargetDataMaker::GetInstance().GetTargetData();
1551 pTargetData = it->second;
1554 wxDateTime now = wxDateTime::Now();
1558 pTargetData->MMSI = mmsi;
1559 pTargetData->MID = MessageID;
1560 pTargetData->MMSI = mmsi;
1561 pTargetData->Class = AIS_CLASS_A;
1563 if (97 == pTargetData->MMSI / 10000000) {
1564 pTargetData->Class = AIS_SART;
1566 pTargetData->StaticReportTicks = now.GetTicks();
1568 pTargetData->NavStatus =
static_cast<ais_nav_status
>(NavStat);
1569 if (!N2kIsNA(SOG)) pTargetData->SOG = MS2KNOTS(SOG);
1570 if (!N2kIsNA(COG)) pTargetData->COG = GeodesicRadToDeg(COG);
1571 if (!N2kIsNA(Heading)) pTargetData->HDG = GeodesicRadToDeg(Heading);
1572 if (!N2kIsNA(Longitude)) pTargetData->Lon = Longitude;
1573 if (!N2kIsNA(Latitude)) pTargetData->Lat = Latitude;
1575 pTargetData->ROTAIS = ROT;
1587 pTargetData->b_OwnShip =
1588 AISTransceiverInformation ==
1589 tN2kAISTransceiverInformation::N2kaisown_information_not_broadcast;
1590 pTargetData->b_active =
true;
1591 pTargetData->b_lost =
false;
1592 pTargetData->b_positionOnceValid =
true;
1593 pTargetData->LastPositionReportTicks = pTargetData->PositionReportTicks;
1594 pTargetData->PositionReportTicks = now.GetTicks();
1596 pSelectAIS->DeleteSelectablePoint((
void *)(
long)mmsi, SELTYPE_AISTARGET);
1597 CommitAISTarget(pTargetData,
"",
true, bnewtarget);
1606bool AisDecoder::HandleN2K_129039(
const N2000MsgPtr &n2k_msg) {
1607 std::vector<unsigned char> v = n2k_msg->payload;
1622 tN2kAISRepeat Repeat;
1632 tN2kAISTransceiverInformation AISTransceiverInformation;
1634 bool DSC, Band, Msg22, State, Display;
1637 if (ParseN2kPGN129039(v, MessageID, Repeat, UserID, Latitude, Longitude,
1638 Accuracy, RAIM, Seconds, COG, SOG,
1639 AISTransceiverInformation, Heading, Unit, Display, DSC,
1640 Band, Msg22, Mode, State)) {
1641 uint32_t mmsi = UserID;
1643 if (mmsi ==
g_OwnShipmmsi || IsTargetOnTheIgnoreList(mmsi))
return false;
1647 std::shared_ptr<AisTargetData> pTargetData =
nullptr;
1648 bool bnewtarget =
false;
1650 auto it = AISTargetList.find(mmsi);
1651 if (it == AISTargetList.end())
1653 pTargetData = AisTargetDataMaker::GetInstance().GetTargetData();
1657 pTargetData = it->second;
1660 wxDateTime now = wxDateTime::Now();
1664 pTargetData->MMSI = mmsi;
1665 pTargetData->MID = MessageID;
1666 if (!isBuoyMmsi(mmsi))
1667 pTargetData->Class = AIS_CLASS_B;
1669 pTargetData->Class = AIS_BUOY;
1671 pTargetData->NavStatus = UNDEFINED;
1672 if (!N2kIsNA(SOG)) pTargetData->SOG = MS2KNOTS(SOG);
1673 if (!N2kIsNA(COG)) pTargetData->COG = GeodesicRadToDeg(COG);
1674 if (!N2kIsNA(Heading)) pTargetData->HDG = GeodesicRadToDeg(Heading);
1675 if (!N2kIsNA(Longitude)) pTargetData->Lon = Longitude;
1676 if (!N2kIsNA(Latitude)) pTargetData->Lat = Latitude;
1678 pTargetData->b_positionOnceValid =
true;
1679 pTargetData->b_active =
true;
1680 pTargetData->b_lost =
false;
1681 pTargetData->LastPositionReportTicks = pTargetData->PositionReportTicks;
1682 pTargetData->PositionReportTicks = now.GetTicks();
1683 pTargetData->b_OwnShip =
1684 AISTransceiverInformation ==
1685 tN2kAISTransceiverInformation::N2kaisown_information_not_broadcast;
1687 pSelectAIS->DeleteSelectablePoint((
void *)(
long)mmsi, SELTYPE_AISTARGET);
1688 CommitAISTarget(pTargetData,
"",
true, bnewtarget);
1698bool AisDecoder::HandleN2K_129041(
const N2000MsgPtr &n2k_msg) {
1699 std::vector<unsigned char> v = n2k_msg->payload;
1701 tN2kAISAtoNReportData data;
1704 struct tN2kAISAtoNReportData {
1706 tN2kAISRepeat Repeat;
1715 double PositionReferenceStarboard ;
1716 double PositionReferenceTrueNorth;
1717 tN2kAISAtoNType AtoNType;
1718 bool OffPositionIndicator;
1719 bool VirtualAtoNFlag;
1720 bool AssignedModeFlag;
1721 tN2kGNSStype GNSSType;
1723 tN2kAISTransceiverInformation AISTransceiverInformation;
1724 char AtoNName[34 + 1];
1727 if (ParseN2kPGN129041(v, data)) {
1728 uint32_t mmsi = data.UserID;
1730 if (mmsi ==
g_OwnShipmmsi || IsTargetOnTheIgnoreList(mmsi))
return false;
1734 std::shared_ptr<AisTargetData> pTargetData =
nullptr;
1735 bool bnewtarget =
false;
1737 auto it = AISTargetList.find(mmsi);
1738 if (it == AISTargetList.end())
1740 pTargetData = AisTargetDataMaker::GetInstance().GetTargetData();
1744 pTargetData = it->second;
1748 pTargetData->MMSI = mmsi;
1750 wxDateTime now = wxDateTime::Now();
1753 int offpos = data.OffPositionIndicator;
1754 int virt = data.VirtualAtoNFlag;
1757 pTargetData->NavStatus = ATON_VIRTUAL;
1759 pTargetData->NavStatus = ATON_REAL;
1761 pTargetData->m_utc_sec = data.Seconds;
1763 if (pTargetData->m_utc_sec <= 59) {
1764 pTargetData->NavStatus += 1;
1765 if (offpos) pTargetData->NavStatus += 1;
1768 data.AtoNName[34] = 0;
1769 strncpy(pTargetData->ShipName, data.AtoNName, SHIP_NAME_LEN - 1);
1770 pTargetData->ShipName[
sizeof(pTargetData->ShipName) - 1] =
'\0';
1771 pTargetData->b_nameValid =
true;
1772 pTargetData->MID = 124;
1774 pTargetData->ShipType = data.AtoNType;
1775 pTargetData->Class = AIS_ATON;
1777 if (!N2kIsNA(data.Longitude)) pTargetData->Lon = data.Longitude;
1778 if (!N2kIsNA(data.Latitude)) pTargetData->Lat = data.Latitude;
1779 pTargetData->b_positionDoubtful =
false;
1780 pTargetData->b_positionOnceValid =
true;
1781 pTargetData->LastPositionReportTicks = pTargetData->PositionReportTicks;
1782 pTargetData->PositionReportTicks = now.GetTicks();
1786 pSelectAIS->DeleteSelectablePoint((
void *)(
long)mmsi, SELTYPE_AISTARGET);
1787 CommitAISTarget(pTargetData,
"",
true, bnewtarget);
1789 touch_state.Notify();
1796bool AisDecoder::HandleN2K_129794(
const N2000MsgPtr &n2k_msg) {
1797 std::vector<unsigned char> v = n2k_msg->payload;
1800 tN2kAISRepeat Repeat;
1804 char Name[SHIP_NAME_LEN];
1813 char Destination[DESTINATION_LEN];
1814 tN2kAISVersion AISversion;
1815 tN2kGNSStype GNSStype;
1817 tN2kAISTranceiverInfo AISinfo;
1819 if (ParseN2kPGN129794(v, MessageID, Repeat, UserID, IMOnumber, Callsign, Name,
1820 VesselType, Length, Beam, PosRefStbd, PosRefBow,
1821 ETAdate, ETAtime, Draught, Destination, AISversion,
1822 GNSStype, DTE, AISinfo)) {
1823 uint32_t mmsi = UserID;
1825 if (mmsi ==
g_OwnShipmmsi || IsTargetOnTheIgnoreList(mmsi))
return false;
1829 std::shared_ptr<AisTargetData> pTargetData =
nullptr;
1830 bool bnewtarget =
false;
1832 auto it = AISTargetList.find(mmsi);
1833 if (it == AISTargetList.end())
1835 pTargetData = AisTargetDataMaker::GetInstance().GetTargetData();
1839 pTargetData = it->second;
1843 pTargetData->MMSI = mmsi;
1844 strncpy(pTargetData->ShipName, Name, SHIP_NAME_LEN - 1);
1845 pTargetData->ShipName[
sizeof(pTargetData->ShipName) - 1] =
'\0';
1846 Name[
sizeof(Name) - 1] = 0;
1847 pTargetData->b_nameValid =
true;
1848 pTargetData->MID = 124;
1850 pTargetData->b_OwnShip =
1852 tN2kAISTranceiverInfo::N2kaisti_Own_information_not_broadcast;
1854 pTargetData->DimA = PosRefBow;
1855 pTargetData->DimB = Length - PosRefBow;
1856 pTargetData->DimC = Beam - PosRefStbd;
1857 pTargetData->DimD = PosRefStbd;
1858 pTargetData->Draft = Draught;
1859 pTargetData->IMO = IMOnumber;
1860 strncpy(pTargetData->CallSign, Callsign, CALL_SIGN_LEN - 1);
1861 pTargetData->CallSign[
sizeof(pTargetData->CallSign) - 1] =
'\0';
1862 pTargetData->ShipType = (
unsigned char)VesselType;
1863 strncpy(pTargetData->Destination, Destination, DESTINATION_LEN - 1);
1864 pTargetData->Destination[
sizeof(pTargetData->Destination) - 1] =
'\0';
1865 Destination[
sizeof(Destination) - 1] = 0;
1867 if (!N2kIsNA(ETAdate) && !N2kIsNA(ETAtime)) {
1868 long secs = (ETAdate * 24 * 3600) + wxRound(ETAtime);
1869 wxDateTime t((time_t)secs);
1871 wxDateTime tz = t.ToUTC();
1872 pTargetData->ETA_Mo = tz.GetMonth() + 1;
1873 pTargetData->ETA_Day = tz.GetDay();
1874 pTargetData->ETA_Hr = tz.GetHour();
1875 pTargetData->ETA_Min = tz.GetMinute();
1879 pSelectAIS->DeleteSelectablePoint((
void *)(
long)mmsi, SELTYPE_AISTARGET);
1880 CommitAISTarget(pTargetData,
"",
true, bnewtarget);
1888bool AisDecoder::HandleN2K_129809(
const N2000MsgPtr &n2k_msg) {
1889 std::vector<unsigned char> v = n2k_msg->payload;
1892 tN2kAISRepeat Repeat;
1896 if (ParseN2kPGN129809(v, MessageID, Repeat, UserID, Name)) {
1897 unsigned mmsi = UserID;
1899 if (mmsi ==
g_OwnShipmmsi || IsTargetOnTheIgnoreList(mmsi))
return false;
1903 std::shared_ptr<AisTargetData> pTargetData =
nullptr;
1904 bool bnewtarget =
false;
1906 auto it = AISTargetList.find(mmsi);
1907 if (it == AISTargetList.end())
1909 pTargetData = AisTargetDataMaker::GetInstance().GetTargetData();
1913 pTargetData = it->second;
1917 pTargetData->MMSI = mmsi;
1918 Name[
sizeof(Name) - 1] = 0;
1919 strncpy(pTargetData->ShipName, Name, SHIP_NAME_LEN - 1);
1920 pTargetData->b_nameValid =
true;
1921 pTargetData->MID = 124;
1923 pSelectAIS->DeleteSelectablePoint((
void *)(
long)mmsi, SELTYPE_AISTARGET);
1924 CommitAISTarget(pTargetData,
"",
true, bnewtarget);
1934bool AisDecoder::HandleN2K_129810(
const N2000MsgPtr &n2k_msg) {
1935 std::vector<unsigned char> v = n2k_msg->payload;
1938 tN2kAISRepeat Repeat;
1947 uint32_t MothershipID;
1949 if (ParseN2kPGN129810(v, MessageID, Repeat, UserID, VesselType, Vendor,
1950 Callsign, Length, Beam, PosRefStbd, PosRefBow,
1952 unsigned mmsi = UserID;
1954 if (mmsi ==
g_OwnShipmmsi || IsTargetOnTheIgnoreList(mmsi))
return false;
1958 std::shared_ptr<AisTargetData> pTargetData =
nullptr;
1959 bool bnewtarget =
false;
1961 auto it = AISTargetList.find(mmsi);
1962 if (it == AISTargetList.end())
1964 pTargetData = AisTargetDataMaker::GetInstance().GetTargetData();
1968 pTargetData = it->second;
1972 pTargetData->MMSI = mmsi;
1973 pTargetData->DimA = PosRefBow;
1974 pTargetData->DimB = Length - PosRefBow;
1975 pTargetData->DimC = Beam - PosRefStbd;
1976 pTargetData->DimD = PosRefStbd;
1977 strncpy(pTargetData->CallSign, Callsign, CALL_SIGN_LEN - 1);
1978 pTargetData->CallSign[
sizeof(pTargetData->CallSign) - 1] =
'\0';
1979 pTargetData->ShipType = (
unsigned char)VesselType;
1981 pSelectAIS->DeleteSelectablePoint((
void *)(
long)mmsi, SELTYPE_AISTARGET);
1982 CommitAISTarget(pTargetData,
"",
true, bnewtarget);
1991bool AisDecoder::HandleN2K_129793(
const N2000MsgPtr &n2k_msg) {
1992 std::vector<unsigned char> v = n2k_msg->payload;
1995 tN2kAISRepeat Repeat;
1999 unsigned int SecondsSinceMidnight;
2000 unsigned int DaysSinceEpoch;
2002 if (ParseN2kPGN129793(v, MessageID, Repeat, UserID, Longitude, Latitude,
2003 SecondsSinceMidnight, DaysSinceEpoch)) {
2004 wxDateTime now = wxDateTime::Now();
2010 std::shared_ptr<AisTargetData> pTargetData =
nullptr;
2011 bool bnewtarget =
false;
2013 auto it = AISTargetList.find(mmsi);
2014 if (it == AISTargetList.end())
2016 pTargetData = AisTargetDataMaker::GetInstance().GetTargetData();
2020 pTargetData = it->second;
2024 pTargetData->MMSI = mmsi;
2025 pTargetData->Class = AIS_BASE;
2027 if (!N2kIsNA(Longitude)) pTargetData->Lon = Longitude;
2028 if (!N2kIsNA(Latitude)) pTargetData->Lat = Latitude;
2029 pTargetData->b_positionDoubtful =
false;
2030 pTargetData->b_positionOnceValid =
true;
2031 pTargetData->LastPositionReportTicks = pTargetData->PositionReportTicks;
2032 pTargetData->PositionReportTicks = now.GetTicks();
2036 pSelectAIS->DeleteSelectablePoint((
void *)(
long)mmsi, SELTYPE_AISTARGET);
2037 CommitAISTarget(pTargetData,
"",
true, bnewtarget);
2056void AisDecoder::HandleSignalK(
const SignalKMsgPtr &sK_msg) {
2057 rapidjson::Document root;
2059 root.Parse(sK_msg->raw_message);
2061 if (root.HasParseError())
return;
2063 if (root.HasMember(
"self")) {
2069 if (m_signalk_selfid.IsEmpty()) {
2074 int meteo_SiteID = 0;
2075 if (root.HasMember(
"context") && root[
"context"].IsString()) {
2076 wxString context = root[
"context"].GetString();
2077 if (context == m_signalk_selfid) {
2079 wxLogMessage(
"** Ignore context own ship..");
2083 wxString mmsi_string;
2084 if (context.StartsWith(
"vessels.urn:mrn:imo:mmsi:", &mmsi_string) ||
2085 context.StartsWith(
"atons.urn:mrn:imo:mmsi:", &mmsi_string) ||
2086 context.StartsWith(
"aircraft.urn:mrn:imo:mmsi:", &mmsi_string)) {
2089 if (mmsi_string.ToLong(&mmsi)) {
2094 }
else if (context.StartsWith(
"meteo.urn:mrn:imo:mmsi:", &mmsi_string)) {
2096 origin_mmsi = wxAtoi(wxString(mmsi_string).BeforeFirst(
':'));
2097 meteo_SiteID = wxAtoi(
'1' + wxString(mmsi_string).AfterFirst(
':'));
2100 int meteo_mmsi = AisMeteoNewMmsi(origin_mmsi, 0, 0, 999, meteo_SiteID);
2111 if (g_pMUX && g_pMUX->IsLogActive()) {
2113 logmsg.Printf(
"AIS :MMSI: %ld", mmsi);
2118 if (IsTargetOnTheIgnoreList(mmsi))
return;
2124 wxLogDebug(
"AisDecoder::OnEvtSignalK: %s", root.dump().c_str(); );
2126 std::shared_ptr<AisTargetData> pTargetData =
nullptr;
2127 std::shared_ptr<AisTargetData> pStaleTarget =
nullptr;
2128 bool bnewtarget =
false;
2129 int last_report_ticks;
2131 getAISTarget(mmsi, pTargetData, pStaleTarget, bnewtarget, last_report_ticks,
2134 pTargetData->MMSI = mmsi;
2135 getMmsiProperties(pTargetData);
2136 if (root.HasMember(
"updates") && root[
"updates"].IsArray()) {
2137 for (rapidjson::Value::ConstValueIterator itr = root[
"updates"].Begin();
2138 itr != root[
"updates"].End(); ++itr) {
2139 handleUpdate(pTargetData, bnewtarget, *itr);
2144 if (97 == mmsi / 10000000) {
2145 pTargetData->Class = AIS_SART;
2146 }
else if (1994 == mmsi / 100000) {
2148 pTargetData->Class = AIS_METEO;
2149 pTargetData->met_data.original_mmsi = origin_mmsi;
2150 pTargetData->met_data.stationID = meteo_SiteID;
2153 wxString met_name = pTargetData->ShipName;
2154 if (met_name.Find(
"METEO") == wxNOT_FOUND) {
2157 s_id << meteo_SiteID;
2158 id1 = wxAtoi(s_id.Mid(1, 3));
2159 id2 = wxAtoi(s_id.Mid(4, 3));
2160 met_name =
"METEO ";
2161 met_name << wxString::Format(
"%03d", (id1 + id2)).Right(3);
2162 strncpy(pTargetData->ShipName, met_name, SHIP_NAME_LEN - 1);
2164 pTargetData->b_nameValid =
true;
2165 pTargetData->MID = 123;
2166 pTargetData->COG = -1.;
2167 pTargetData->HDG = 511;
2168 pTargetData->SOG = -1.;
2169 pTargetData->b_NoTrack =
true;
2170 pTargetData->b_show_track =
false;
2172 pTargetData->b_OwnShip =
false;
2173 AISTargetList[pTargetData->MMSI] = pTargetData;
2177void AisDecoder::handleUpdate(
const std::shared_ptr<AisTargetData> &pTargetData,
2178 bool bnewtarget,
const rapidjson::Value &update) {
2179 wxString sfixtime =
"";
2181 if (update.HasMember(
"timestamp")) {
2182 sfixtime = update[
"timestamp"].GetString();
2184 if (update.HasMember(
"values") && update[
"values"].IsArray()) {
2185 for (rapidjson::Value::ConstValueIterator itr = update[
"values"].Begin();
2186 itr != update[
"values"].End(); ++itr) {
2187 updateItem(pTargetData, bnewtarget, *itr, sfixtime);
2190 wxDateTime now = wxDateTime::Now();
2191 pTargetData->m_utc_hour = now.ToUTC().GetHour();
2192 pTargetData->m_utc_min = now.ToUTC().GetMinute();
2193 pTargetData->m_utc_sec = now.ToUTC().GetSecond();
2195 pTargetData->b_active =
true;
2196 pTargetData->b_lost =
false;
2198 if (pTargetData->b_positionOnceValid) {
2199 long mmsi_long = pTargetData->MMSI;
2201 pSelectAIS->AddSelectablePoint(pTargetData->Lat, pTargetData->Lon,
2202 (
void *)mmsi_long, SELTYPE_AISTARGET);
2203 pSel->SetUserData(pTargetData->MMSI);
2205 UpdateOneCPA(pTargetData.get());
2206 if (pTargetData->b_show_track) UpdateOneTrack(pTargetData.get());
2209void AisDecoder::updateItem(
const std::shared_ptr<AisTargetData> &pTargetData,
2210 bool bnewtarget,
const rapidjson::Value &item,
2211 wxString &sfixtime)
const {
2212 if (item.HasMember(
"path") && item.HasMember(
"value")) {
2213 const wxString &update_path = item[
"path"].GetString();
2214 if (update_path ==
"navigation.position") {
2215 if (item[
"value"].HasMember(
"latitude") &&
2216 item[
"value"].HasMember(
"longitude")) {
2217 wxDateTime now = wxDateTime::Now();
2219 double lat = item[
"value"][
"latitude"].GetDouble();
2220 double lon = item[
"value"][
"longitude"].GetDouble();
2221 pTargetData->LastPositionReportTicks = pTargetData->PositionReportTicks;
2222 pTargetData->PositionReportTicks = now.GetTicks();
2223 pTargetData->StaticReportTicks = now.GetTicks();
2224 pTargetData->Lat = lat;
2225 pTargetData->Lon = lon;
2226 pTargetData->b_positionOnceValid =
true;
2227 pTargetData->b_positionDoubtful =
false;
2234 }
else if (update_path ==
"navigation.speedOverGround" &&
2235 item[
"value"].IsNumber()) {
2236 pTargetData->SOG = item[
"value"].GetDouble() * ms_to_knot_factor;
2237 }
else if (update_path ==
"navigation.courseOverGroundTrue" &&
2238 item[
"value"].IsNumber()) {
2239 pTargetData->COG = GEODESIC_RAD2DEG(item[
"value"].GetDouble());
2240 }
else if (update_path ==
"navigation.headingTrue" &&
2241 item[
"value"].IsNumber()) {
2242 pTargetData->HDG = GEODESIC_RAD2DEG(item[
"value"].GetDouble());
2243 }
else if (update_path ==
"navigation.rateOfTurn" &&
2244 item[
"value"].IsNumber()) {
2245 double deg_min = item[
"value"].GetDouble() * 180.0 / M_PI * 60.0;
2246 double rot = 4.733 * sqrt(fabs(deg_min));
2247 int rotais = wxRound(rot);
2248 if (rotais > 126) rotais = 126;
2249 pTargetData->ROTAIS = deg_min < 0 ? -rotais : rotais;
2250 pTargetData->ROTIND = wxRound(deg_min);
2251 }
else if (update_path ==
"design.aisShipType") {
2252 if (item[
"value"].HasMember(
"id")) {
2253 if (!pTargetData->b_isDSCtarget) {
2254 pTargetData->ShipType = item[
"value"][
"id"].GetUint();
2257 }
else if (update_path ==
"atonType") {
2258 if (item[
"value"].HasMember(
"id")) {
2259 pTargetData->ShipType = item[
"value"][
"id"].GetUint();
2261 }
else if (update_path ==
"virtual") {
2262 if (item[
"value"].GetBool()) {
2263 pTargetData->NavStatus = ATON_VIRTUAL;
2265 pTargetData->NavStatus = ATON_REAL;
2267 }
else if (update_path ==
"offPosition") {
2268 if (item[
"value"].GetBool()) {
2269 if (ATON_REAL == pTargetData->NavStatus) {
2270 pTargetData->NavStatus = ATON_REAL_OFFPOSITION;
2271 }
else if (ATON_VIRTUAL == pTargetData->NavStatus) {
2272 pTargetData->NavStatus = ATON_VIRTUAL_OFFPOSITION;
2275 }
else if (update_path ==
"design.draft") {
2276 if (item[
"value"].HasMember(
"maximum") &&
2277 item[
"value"][
"maximum"].IsNumber()) {
2278 pTargetData->Draft = item[
"value"][
"maximum"].GetDouble();
2279 pTargetData->Euro_Draft = item[
"value"][
"maximum"].GetDouble();
2281 if (item[
"value"].HasMember(
"current") &&
2282 item[
"value"][
"current"].IsNumber()) {
2283 double draft = item[
"value"][
"current"].GetDouble();
2285 pTargetData->Draft = draft;
2286 pTargetData->Euro_Draft = draft;
2289 }
else if (update_path ==
"design.length") {
2290 if (pTargetData->DimB == 0) {
2291 if (item[
"value"].HasMember(
"overall")) {
2292 if (item[
"value"][
"overall"].IsNumber()) {
2293 pTargetData->Euro_Length = item[
"value"][
"overall"].GetDouble();
2294 pTargetData->DimA = item[
"value"][
"overall"].GetDouble();
2296 pTargetData->DimB = 0;
2299 }
else if (update_path ==
"sensors.ais.class") {
2300 wxString aisclass = item[
"value"].GetString();
2301 if (aisclass ==
"A") {
2302 if (!pTargetData->b_isDSCtarget) pTargetData->Class = AIS_CLASS_A;
2303 }
else if (aisclass ==
"B") {
2304 if (!pTargetData->b_isDSCtarget) {
2305 if (!isBuoyMmsi(pTargetData->MMSI))
2306 pTargetData->Class = AIS_CLASS_B;
2308 pTargetData->Class = AIS_BUOY;
2311 pTargetData->NavStatus = UNDEFINED;
2313 }
else if (aisclass ==
"BASE") {
2314 pTargetData->Class = AIS_BASE;
2315 }
else if (aisclass ==
"ATON") {
2316 pTargetData->Class = AIS_ATON;
2318 }
else if (update_path ==
"sensors.ais.fromBow") {
2319 if (pTargetData->DimB == 0 && pTargetData->DimA != 0) {
2320 int length = pTargetData->DimA;
2321 if (item[
"value"].IsNumber()) {
2322 pTargetData->DimA = item[
"value"].GetDouble();
2323 pTargetData->DimB = length - item[
"value"].GetDouble();
2326 }
else if (update_path ==
"design.beam") {
2327 if (pTargetData->DimD == 0) {
2328 if (item[
"value"].IsNumber()) {
2329 pTargetData->Euro_Beam = item[
"value"].GetDouble();
2330 pTargetData->DimC = item[
"value"].GetDouble();
2332 pTargetData->DimD = 0;
2334 }
else if (update_path ==
"sensors.ais.fromCenter") {
2335 if (pTargetData->DimD == 0 && pTargetData->DimC != 0) {
2336 int beam = pTargetData->DimC;
2337 int center = beam / 2;
2338 if (item[
"value"].IsNumber()) {
2341 pTargetData->DimC = center + item[
"value"].GetDouble();
2342 pTargetData->DimD = beam - pTargetData->DimC;
2345 }
else if (update_path ==
"navigation.state") {
2346 wxString state = item[
"value"].GetString();
2347 if (state ==
"motoring") {
2348 pTargetData->NavStatus = UNDERWAY_USING_ENGINE;
2349 }
else if (state ==
"anchored") {
2350 pTargetData->NavStatus = AT_ANCHOR;
2351 }
else if (state ==
"not under command") {
2352 pTargetData->NavStatus = NOT_UNDER_COMMAND;
2353 }
else if (state ==
"restricted manouverability") {
2354 pTargetData->NavStatus = RESTRICTED_MANOEUVRABILITY;
2355 }
else if (state ==
"constrained by draft") {
2356 pTargetData->NavStatus = CONSTRAINED_BY_DRAFT;
2357 }
else if (state ==
"moored") {
2358 pTargetData->NavStatus = MOORED;
2359 }
else if (state ==
"aground") {
2360 pTargetData->NavStatus = AGROUND;
2361 }
else if (state ==
"fishing") {
2362 pTargetData->NavStatus = FISHING;
2363 }
else if (state ==
"sailing") {
2364 pTargetData->NavStatus = UNDERWAY_SAILING;
2365 }
else if (state ==
"hazardous material high speed") {
2366 pTargetData->NavStatus = HSC;
2367 }
else if (state ==
"hazardous material wing in ground") {
2368 pTargetData->NavStatus = WIG;
2369 }
else if (state ==
"ais-sart") {
2370 pTargetData->NavStatus = RESERVED_14;
2372 pTargetData->NavStatus = UNDEFINED;
2374 }
else if (update_path ==
"navigation.destination.commonName") {
2375 const wxString &destination = item[
"value"].GetString();
2376 pTargetData->Destination[0] =
'\0';
2377 strncpy(pTargetData->Destination, destination.c_str(),
2378 DESTINATION_LEN - 1);
2379 }
else if (update_path ==
"navigation.destination.eta") {
2380 const wxString &eta = item[
"value"].GetString();
2385 pTargetData->ETA_Mo = tz.GetMonth() + 1;
2386 pTargetData->ETA_Day = tz.GetDay();
2387 pTargetData->ETA_Hr = tz.GetHour();
2388 pTargetData->ETA_Min = tz.GetMinute();
2390 }
else if (update_path ==
"navigation.specialManeuver") {
2391 if (strcmp(
"not available", item[
"value"].GetString()) != 0 &&
2392 pTargetData->IMO < 1) {
2393 const wxString &bluesign = item[
"value"].GetString();
2394 if (
"not engaged" == bluesign) {
2395 pTargetData->blue_paddle = 1;
2397 if (
"engaged" == bluesign) {
2398 pTargetData->blue_paddle = 2;
2400 pTargetData->b_blue_paddle =
2401 pTargetData->blue_paddle == 2 ? true :
false;
2403 }
else if (update_path ==
"sensors.ais.designatedAreaCode") {
2404 if (item[
"value"].GetInt() == 200) {
2405 pTargetData->b_hasInlandDac =
true;
2407 }
else if (update_path ==
"sensors.ais.functionalId") {
2408 if (item[
"value"].GetInt() == 10 && pTargetData->b_hasInlandDac) {
2410 pTargetData->b_isEuroInland =
true;
2414 }
else if (update_path ==
"environment.date") {
2415 const wxString &issued = item[
"value"].GetString();
2420 pTargetData->met_data.day = tz.GetDay();
2421 pTargetData->met_data.hour = tz.GetHour();
2422 pTargetData->met_data.minute = tz.GetMinute();
2424 }
else if (update_path ==
"environment.wind.averageSpeed" &&
2425 item[
"value"].IsNumber()) {
2426 pTargetData->met_data.wind_kn = MS2KNOTS(item[
"value"].GetDouble());
2427 }
else if (update_path ==
"environment.wind.gust" &&
2428 item[
"value"].IsNumber()) {
2429 pTargetData->met_data.wind_gust_kn = MS2KNOTS(item[
"value"].GetDouble());
2430 }
else if (update_path ==
"environment.wind.directionTrue" &&
2431 item[
"value"].IsNumber()) {
2432 pTargetData->met_data.wind_dir =
2433 GEODESIC_RAD2DEG(item[
"value"].GetDouble());
2434 }
else if (update_path ==
"environment.wind.gustDirectionTrue" &&
2435 item[
"value"].IsNumber()) {
2436 pTargetData->met_data.wind_gust_dir =
2437 GEODESIC_RAD2DEG(item[
"value"].GetDouble());
2438 }
else if (update_path ==
"environment.outside.temperature" &&
2439 item[
"value"].IsNumber()) {
2440 pTargetData->met_data.air_temp = KelvinToC(item[
"value"].GetDouble());
2441 }
else if (update_path ==
"environment.outside.relativeHumidity" &&
2442 item[
"value"].IsNumber()) {
2443 pTargetData->met_data.rel_humid = item[
"value"].GetDouble();
2444 }
else if (update_path ==
"environment.outside.dewPointTemperature" &&
2445 item[
"value"].IsNumber()) {
2446 pTargetData->met_data.dew_point = KelvinToC(item[
"value"].GetDouble());
2447 }
else if (update_path ==
"environment.outside.pressure" &&
2448 item[
"value"].IsNumber()) {
2449 pTargetData->met_data.airpress =
2450 static_cast<int>(item[
"value"].GetDouble() / 100);
2451 }
else if (update_path ==
"environment.water.level" &&
2452 item[
"value"].IsNumber()) {
2453 pTargetData->met_data.water_lev_dev = item[
"value"].GetDouble();
2454 }
else if (update_path ==
"environment.water.current.drift" &&
2455 item[
"value"].IsNumber()) {
2456 pTargetData->met_data.current = MS2KNOTS(item[
"value"].GetDouble());
2457 }
else if (update_path ==
"environment.water.current.set" &&
2458 item[
"value"].IsNumber()) {
2459 pTargetData->met_data.curr_dir =
2460 GEODESIC_RAD2DEG(item[
"value"].GetDouble());
2461 }
else if (update_path ==
"environment.water.levelTendencyValue" &&
2462 item[
"value"].IsNumber()) {
2463 pTargetData->met_data.water_lev_trend =
2464 static_cast<int>(item[
"value"].GetDouble());
2465 }
else if (update_path ==
"environment.water.levelTendency") {
2467 }
else if (update_path ==
"environment.water.waves.significantHeight" &&
2468 item[
"value"].IsNumber()) {
2469 pTargetData->met_data.wave_height = item[
"value"].GetDouble();
2470 }
else if (update_path ==
"environment.water.waves.period" &&
2471 item[
"value"].IsNumber()) {
2472 pTargetData->met_data.wave_period =
2473 static_cast<int>(item[
"value"].GetDouble());
2474 }
else if (update_path ==
"environment.water.waves.directionTrue" &&
2475 item[
"value"].IsNumber()) {
2476 pTargetData->met_data.wave_dir =
2477 GEODESIC_RAD2DEG(item[
"value"].GetDouble());
2478 }
else if (update_path ==
"environment.water.swell.height" &&
2479 item[
"value"].IsNumber()) {
2480 pTargetData->met_data.swell_height = item[
"value"].GetDouble();
2481 }
else if (update_path ==
"environment.water.swell.period" &&
2482 item[
"value"].IsNumber()) {
2483 pTargetData->met_data.swell_per =
2484 static_cast<int>(item[
"value"].GetDouble());
2485 }
else if (update_path ==
"environment.water.swell.directionTrue" &&
2486 item[
"value"].IsNumber()) {
2487 pTargetData->met_data.swell_dir =
2488 GEODESIC_RAD2DEG(item[
"value"].GetDouble());
2489 }
else if (update_path ==
"environment.water.temperature" &&
2490 item[
"value"].IsNumber()) {
2491 pTargetData->met_data.water_temp = KelvinToC(item[
"value"].GetDouble());
2492 }
else if (update_path ==
"environment.water.salinity" &&
2493 item[
"value"].IsNumber()) {
2494 pTargetData->met_data.salinity = item[
"value"].GetDouble();
2495 }
else if (update_path ==
"environment.water.ice") {
2497 }
else if (update_path ==
"environment.water.iceValue" &&
2498 item[
"value"].IsNumber()) {
2499 pTargetData->met_data.ice =
static_cast<int>(item[
"value"].GetDouble());
2500 }
else if (update_path ==
"environment.water.seaStateValue" &&
2501 item[
"value"].IsNumber()) {
2502 pTargetData->met_data.seastate =
2503 static_cast<int>(item[
"value"].GetDouble());
2504 }
else if (update_path ==
"environment.water.seaState") {
2506 }
else if (update_path ==
"environment.outside.precipitation") {
2508 }
else if (update_path ==
"environment.outside.precipitationValue" &&
2509 item[
"value"].IsNumber()) {
2510 pTargetData->met_data.precipitation =
2511 static_cast<int>(item[
"value"].GetDouble());
2512 }
else if (update_path ==
"environment.outside.pressureTendencyValue" &&
2513 item[
"value"].IsNumber()) {
2514 pTargetData->met_data.airpress_tend =
2515 static_cast<int>(item[
"value"].GetDouble());
2516 }
else if (update_path ==
"environment.outside.pressureTendency") {
2518 }
else if (update_path ==
"environment.outside.horizontalVisibility" &&
2519 item[
"value"].IsNumber()) {
2520 pTargetData->met_data.hor_vis =
2521 GEODESIC_METERS2NM(item[
"value"].GetDouble());
2522 }
else if (update_path ==
2523 "environment.outside.horizontalVisibility.overRange") {
2524 pTargetData->met_data.hor_vis_GT = item[
"value"].GetBool();
2525 }
else if (update_path.empty()) {
2526 if (item[
"value"].HasMember(
"name")) {
2527 const wxString &name = item[
"value"][
"name"].GetString();
2528 strncpy(pTargetData->ShipName, name.c_str(), SHIP_NAME_LEN - 1);
2529 pTargetData->b_nameValid =
true;
2530 pTargetData->MID = 123;
2531 }
else if (item[
"value"].HasMember(
"registrations")) {
2532 const wxString &imo = item[
"value"][
"registrations"][
"imo"].GetString();
2533 pTargetData->IMO = wxAtoi(imo.Right(7));
2534 }
else if (item[
"value"].HasMember(
"communication")) {
2535 const wxString &callsign =
2536 item[
"value"][
"communication"][
"callsignVhf"].GetString();
2537 strncpy(pTargetData->CallSign, callsign.c_str(), 7);
2539 if (item[
"value"].HasMember(
"mmsi") &&
2540 1994 != (pTargetData->MMSI) / 100000) {
2542 wxString tmp = item[
"value"][
"mmsi"].GetString();
2543 if (tmp.ToLong(&mmsi)) {
2544 pTargetData->MMSI = mmsi;
2546 if (97 == mmsi / 10000000) {
2547 pTargetData->Class = AIS_SART;
2549 if (111 == mmsi / 1000000) {
2550 pTargetData->b_SarAircraftPosnReport =
true;
2553 AISshipNameCache(pTargetData.get(), AISTargetNamesC, AISTargetNamesNC,
2558 wxLogMessage(wxString::Format(
2559 "** AisDecoder::updateItem: unhandled path %s", update_path));
2561 rapidjson::StringBuffer buffer;
2562 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
2563 item.Accept(writer);
2564 wxString msg(
"update: ");
2565 msg.append(buffer.GetString());
2575AisError AisDecoder::DecodeSingleVDO(
const wxString &str, GenericPosDatEx *pos,
2576 wxString *accumulator) {
2578 if (str.Len() > 128)
return AIS_NMEAVDX_TOO_LONG;
2580 if (!NMEACheckSumOK(str))
return AIS_NMEAVDX_CHECKSUM_BAD;
2582 if (!pos)
return AIS_GENERIC_ERROR;
2584 if (!accumulator)
return AIS_GENERIC_ERROR;
2587 if (!str.Mid(1, 5).IsSameAs(
"AIVDO"))
return AIS_GENERIC_ERROR;
2590 wxStringTokenizer tkz(str,
",");
2593 token = tkz.GetNextToken();
2595 token = tkz.GetNextToken();
2596 int nsentences = atoi(token.mb_str());
2598 token = tkz.GetNextToken();
2599 int isentence = atoi(token.mb_str());
2601 token = tkz.GetNextToken();
2602 token = tkz.GetNextToken();
2604 wxString string_to_parse;
2605 string_to_parse.Clear();
2618 if ((1 == nsentences) && (1 == isentence)) {
2619 string_to_parse = tkz.GetNextToken();
2622 else if (nsentences > 1) {
2623 if (1 == isentence) {
2624 *accumulator = tkz.GetNextToken();
2628 accumulator->Append(tkz.GetNextToken());
2631 if (isentence == nsentences) {
2632 string_to_parse = *accumulator;
2636 if (string_to_parse.IsEmpty() &&
2638 return AIS_INCOMPLETE_MULTIPART;
2642 if (string_to_parse.Len() >= AIS_MAX_MESSAGE_LEN) {
2643 accumulator->Clear();
2644 return AIS_NMEAVDX_TOO_LONG;
2648 AisBitstring strbit(string_to_parse.mb_str());
2653 auto TargetData = AisTargetDataMaker::GetInstance().GetTargetData();
2655 bool bdecode_result = Parse_VDXBitstring(&strbit, TargetData);
2657 if (bdecode_result) {
2658 switch (TargetData->MID) {
2663 if (!TargetData->b_positionDoubtful) {
2664 pos->
kLat = TargetData->Lat;
2665 pos->
kLon = TargetData->Lon;
2671 if (TargetData->COG == 360.0)
2674 pos->
kCog = TargetData->COG;
2676 if (TargetData->SOG > 102.2)
2679 pos->
kSog = TargetData->SOG;
2681 if ((
int)TargetData->HDG == 511)
2684 pos->
kHdt = TargetData->HDG;
2692 return AIS_GENERIC_ERROR;
2697 return AIS_GENERIC_ERROR;
2705AisError AisDecoder::DecodeN0183(
const wxString &str) {
2706 AisError ret = AIS_GENERIC_ERROR;
2707 wxString string_to_parse;
2709 double gpsg_lat, gpsg_lon, gpsg_mins, gpsg_degs;
2710 double gpsg_cog, gpsg_sog, gpsg_utc_time;
2711 int gpsg_utc_hour = 0;
2712 int gpsg_utc_min = 0;
2713 int gpsg_utc_sec = 0;
2714 char gpsg_name_str[21];
2717 bool bdecode_result =
false;
2724 long arpa_tgt_num = 0;
2725 double arpa_sog = 0.;
2726 double arpa_cog = 0.;
2727 double arpa_lat = 0.;
2728 double arpa_lon = 0.;
2729 double arpa_dist = 0.;
2730 double arpa_brg = 0.;
2731 wxString arpa_brgunit;
2732 wxString arpa_status;
2733 wxString arpa_distunit;
2734 wxString arpa_cogunit;
2735 double arpa_mins, arpa_degs;
2736 double arpa_utc_time;
2737 int arpa_utc_hour = 0;
2738 int arpa_utc_min = 0;
2739 int arpa_utc_sec = 0;
2740 char arpa_name_str[21];
2741 bool arpa_lost =
true;
2742 bool arpa_nottracked =
false;
2744 double aprs_lat = 0.;
2745 double aprs_lon = 0.;
2746 char aprs_name_str[21];
2747 double aprs_mins, aprs_degs;
2749 std::shared_ptr<AisTargetData> pTargetData =
nullptr;
2750 std::shared_ptr<AisTargetData> pStaleTarget =
nullptr;
2751 bool bnewtarget =
false;
2752 int last_report_ticks;
2756 if (str.Len() > 128)
return AIS_NMEAVDX_TOO_LONG;
2758 if (!NMEACheckSumOK(str)) {
2759 return AIS_NMEAVDX_CHECKSUM_BAD;
2761 if (str.Mid(1, 2).IsSameAs(
"CD")) {
2764 }
else if (str.Mid(3, 3).IsSameAs(
"TTM")) {
2768 wxStringTokenizer tkz(str,
",*");
2771 token = tkz.GetNextToken();
2772 token = tkz.GetNextToken();
2773 token.ToLong(&arpa_tgt_num);
2774 token = tkz.GetNextToken();
2775 token.ToDouble(&arpa_dist);
2776 token = tkz.GetNextToken();
2777 token.ToDouble(&arpa_brg);
2778 arpa_brgunit = tkz.GetNextToken();
2779 if (arpa_brgunit ==
"R") {
2780 if (std::isnan(arpa_ref_hdg)) {
2781 if (!std::isnan(
gHdt))
2786 arpa_brg += arpa_ref_hdg;
2787 if (arpa_brg >= 360.) arpa_brg -= 360.;
2789 token = tkz.GetNextToken();
2790 token.ToDouble(&arpa_sog);
2791 token = tkz.GetNextToken();
2792 token.ToDouble(&arpa_cog);
2793 arpa_cogunit = tkz.GetNextToken();
2794 if (arpa_cogunit ==
"R") {
2795 if (std::isnan(arpa_ref_hdg)) {
2796 if (!std::isnan(
gHdt))
2801 arpa_cog += arpa_ref_hdg;
2802 if (arpa_cog >= 360.) arpa_cog -= 360.;
2804 token = tkz.GetNextToken();
2805 token = tkz.GetNextToken();
2807 arpa_distunit = tkz.GetNextToken();
2808 token = tkz.GetNextToken();
2809 if (token ==
"") token = wxString::Format(
"ARPA %ld", arpa_tgt_num);
2810 int len = wxMin(token.Length(), 20);
2811 strncpy(arpa_name_str, token.mb_str(), len);
2812 arpa_name_str[len] = 0;
2813 arpa_status = tkz.GetNextToken();
2814 if (arpa_status !=
"L") {
2816 }
else if (arpa_status !=
"")
2817 arpa_nottracked =
true;
2818 wxString arpa_reftarget = tkz.GetNextToken();
2819 if (tkz.HasMoreTokens()) {
2820 token = tkz.GetNextToken();
2821 token.ToDouble(&arpa_utc_time);
2822 arpa_utc_hour = (int)(arpa_utc_time / 10000.0);
2823 arpa_utc_min = (int)(arpa_utc_time / 100.0) - arpa_utc_hour * 100;
2825 (int)arpa_utc_time - arpa_utc_hour * 10000 - arpa_utc_min * 100;
2827 arpa_utc_hour = wxDateTime::Now().ToUTC().GetHour();
2828 arpa_utc_min = wxDateTime::Now().ToUTC().GetMinute();
2829 arpa_utc_sec = wxDateTime::Now().ToUTC().GetSecond();
2832 if (arpa_distunit ==
"K") {
2835 }
else if (arpa_distunit ==
"S") {
2840 mmsi = arpa_mmsi = 199200000 + arpa_tgt_num;
2844 }
else if (str.Mid(3, 3).IsSameAs(
"TLL")) {
2847 wxStringTokenizer tkz(str,
",*");
2850 wxString aprs_tll_str = tkz.GetNextToken();
2851 token = tkz.GetNextToken();
2852 token.ToLong(&arpa_tgt_num);
2853 token = tkz.GetNextToken();
2854 token.ToDouble(&arpa_lat);
2855 arpa_degs = (int)(arpa_lat / 100.0);
2856 arpa_mins = arpa_lat - arpa_degs * 100.0;
2857 arpa_lat = arpa_degs + arpa_mins / 60.0;
2858 token = tkz.GetNextToken();
2859 if (token.Mid(0, 1).Contains(
"S") ==
true ||
2860 token.Mid(0, 1).Contains(
"s") ==
true)
2861 arpa_lat = 0. - arpa_lat;
2862 token = tkz.GetNextToken();
2863 token.ToDouble(&arpa_lon);
2864 arpa_degs = (int)(arpa_lon / 100.0);
2865 arpa_mins = arpa_lon - arpa_degs * 100.0;
2866 arpa_lon = arpa_degs + arpa_mins / 60.0;
2867 token = tkz.GetNextToken();
2868 if (token.Mid(0, 1).Contains(
"W") ==
true ||
2869 token.Mid(0, 1).Contains(
"w") ==
true)
2870 arpa_lon = 0. - arpa_lon;
2871 token = tkz.GetNextToken();
2872 if (token ==
"") token = wxString::Format(
"ARPA %d", arpa_tgt_num);
2873 int len = wxMin(token.Length(), 20);
2874 strncpy(arpa_name_str, token.mb_str(), len);
2875 arpa_name_str[len] = 0;
2876 token = tkz.GetNextToken();
2877 token.ToDouble(&arpa_utc_time);
2878 arpa_utc_hour = (int)(arpa_utc_time / 10000.0);
2879 arpa_utc_min = (int)(arpa_utc_time / 100.0) - arpa_utc_hour * 100;
2881 (int)arpa_utc_time - arpa_utc_hour * 10000 - arpa_utc_min * 100;
2886 if (arpa_status !=
"L")
2888 else if (arpa_status !=
"")
2889 arpa_nottracked =
true;
2890 wxString arpa_reftarget = tkz.GetNextToken();
2891 mmsi = arpa_mmsi = 199200000 + arpa_tgt_num;
2895 }
else if (str.Mid(3, 3).IsSameAs(
"OSD")) {
2897 wxStringTokenizer tkz(str,
",*");
2900 token = tkz.GetNextToken();
2901 token = tkz.GetNextToken();
2902 token.ToDouble(&arpa_ref_hdg);
2912 }
else if (g_bWplUsePosition && str.Mid(3, 3).IsSameAs(
"WPL")) {
2914 wxStringTokenizer tkz(str,
",*");
2917 token = tkz.GetNextToken();
2918 token = tkz.GetNextToken();
2919 token.ToDouble(&aprs_lat);
2920 aprs_degs = (int)(aprs_lat / 100.0);
2921 aprs_mins = aprs_lat - aprs_degs * 100.0;
2922 aprs_lat = aprs_degs + aprs_mins / 60.0;
2923 token = tkz.GetNextToken();
2924 if (token.Mid(0, 1).Contains(
"S") ==
true ||
2925 token.Mid(0, 1).Contains(
"s") ==
true)
2926 aprs_lat = 0. - aprs_lat;
2927 token = tkz.GetNextToken();
2928 token.ToDouble(&aprs_lon);
2929 aprs_degs = (int)(aprs_lon / 100.0);
2930 aprs_mins = aprs_lon - aprs_degs * 100.0;
2931 aprs_lon = aprs_degs + aprs_mins / 60.0;
2932 token = tkz.GetNextToken();
2933 if (token.Mid(0, 1).Contains(
"W") ==
true ||
2934 token.Mid(0, 1).Contains(
"w") ==
true)
2935 aprs_lon = 0. - aprs_lon;
2936 token = tkz.GetNextToken();
2937 int len = wxMin(token.Length(), 20);
2938 strncpy(aprs_name_str, token.mb_str(), len + 1);
2939 if (0 == g_WplAction) {
2941 aprs_name_str[len] = 0;
2942 for (i = 0; i < len; i++) {
2944 hash += (int)(aprs_name_str[i]);
2945 while (hash >= 100000) hash = hash / 100000;
2947 mmsi = aprs_mmsi = 199300000 + hash;
2951 }
else if (1 == g_WplAction) {
2953 new RoutePoint(aprs_lat, aprs_lon,
"", aprs_name_str,
"",
false);
2954 pWP->m_bIsolatedMark =
true;
2955 InsertWpt(pWP,
true);
2957 }
else if (str.Mid(1, 5).IsSameAs(
"FRPOS")) {
2961 wxStringTokenizer tkz(str,
",*");
2964 token = tkz.GetNextToken();
2966 token = tkz.GetNextToken();
2967 token.ToDouble(&gpsg_lat);
2968 gpsg_degs = (int)(gpsg_lat / 100.0);
2969 gpsg_mins = gpsg_lat - gpsg_degs * 100.0;
2970 gpsg_lat = gpsg_degs + gpsg_mins / 60.0;
2972 token = tkz.GetNextToken();
2973 if (token.Mid(0, 1).Contains(
"S") ==
true ||
2974 token.Mid(0, 1).Contains(
"s") ==
true)
2975 gpsg_lat = 0. - gpsg_lat;
2977 token = tkz.GetNextToken();
2978 token.ToDouble(&gpsg_lon);
2979 gpsg_degs = (int)(gpsg_lon / 100.0);
2980 gpsg_mins = gpsg_lon - gpsg_degs * 100.0;
2981 gpsg_lon = gpsg_degs + gpsg_mins / 60.0;
2983 token = tkz.GetNextToken();
2984 if (token.Mid(0, 1).Contains(
"W") ==
true ||
2985 token.Mid(0, 1).Contains(
"w") ==
true)
2986 gpsg_lon = 0. - gpsg_lon;
2988 token = tkz.GetNextToken();
2991 token = tkz.GetNextToken();
2992 token.ToDouble(&gpsg_sog);
2994 token = tkz.GetNextToken();
2995 token.ToDouble(&gpsg_cog);
2997 token = tkz.GetNextToken();
3000 token = tkz.GetNextToken();
3001 token.ToDouble(&gpsg_utc_time);
3002 gpsg_utc_hour = (int)(gpsg_utc_time / 10000.0);
3003 gpsg_utc_min = (int)(gpsg_utc_time / 100.0) - gpsg_utc_hour * 100;
3005 (int)gpsg_utc_time - gpsg_utc_hour * 10000 - gpsg_utc_min * 100;
3009 token = tkz.GetNextToken();
3010 int i, len, hash = 0;
3011 len = wxMin(wxStrlen(token), 20);
3012 strncpy(gpsg_name_str, token.mb_str(), len);
3013 gpsg_name_str[len] = 0;
3014 for (i = 0; i < len; i++) {
3016 hash += (int)(token[i]);
3017 while (hash >= 100000) hash = hash / 100000;
3020 gpsg_mmsi = 199000000 + hash;
3022 }
else if (!str.Mid(3, 2).IsSameAs(
"VD")) {
3023 return AIS_NMEAVDX_BAD;
3029 string_to_parse.Clear();
3031 if (str.Mid(3, 2).IsSameAs(
"VD")) {
3032 wxStringTokenizer tkz(str,
",");
3035 token = tkz.GetNextToken();
3037 token = tkz.GetNextToken();
3038 nsentences = atoi(token.mb_str());
3040 token = tkz.GetNextToken();
3041 isentence = atoi(token.mb_str());
3043 token = tkz.GetNextToken();
3044 long lsequence_id = 0;
3045 token.ToLong(&lsequence_id);
3047 token = tkz.GetNextToken();
3049 token.ToLong(&lchannel);
3054 if ((1 == nsentences) && (1 == isentence)) {
3055 string_to_parse = tkz.GetNextToken();
3058 else if (nsentences > 1) {
3059 if (1 == isentence) {
3060 sentence_accumulator = tkz.GetNextToken();
3064 sentence_accumulator += tkz.GetNextToken();
3067 if (isentence == nsentences) {
3068 string_to_parse = sentence_accumulator;
3073 if (mmsi || (!string_to_parse.IsEmpty() &&
3074 (string_to_parse.Len() < AIS_MAX_MESSAGE_LEN))) {
3076 wxCharBuffer abuf = string_to_parse.ToUTF8();
3078 return AIS_GENERIC_ERROR;
3080 AisBitstring strbit(abuf.data());
3083 if (!mmsi) mmsi = strbit.GetInt(9, 30);
3084 long mmsi_long = mmsi;
3087 int origin_mmsi = 0;
3088 int messID = strbit.GetInt(1, 6);
3090 if (messID < 0 || messID > 63)
return AIS_GENERIC_ERROR;
3092 int dac = strbit.GetInt(41, 10);
3093 int fi = strbit.GetInt(51, 6);
3095 int met_lon, met_lat;
3096 if (dac == 001 && fi == 31) {
3098 met_lon = strbit.GetInt(57, 25);
3099 met_lat = strbit.GetInt(82, 24);
3100 mmsi = AisMeteoNewMmsi(mmsi, met_lat, met_lon, 25, 0);
3103 }
else if (dac == 367 && fi == 33) {
3105 const int size = strbit.GetBitCount();
3106 if (size < 168)
return AIS_GENERIC_ERROR;
3107 const int startb = 56;
3108 const int slot_size = 112;
3109 const int extra_bits = (size - startb) % slot_size;
3110 if (extra_bits > 0)
return AIS_GENERIC_ERROR;
3112 int mes_type = strbit.GetInt(57, 4);
3113 int site_ID = strbit.GetInt(77, 7);
3114 if (mes_type == 0) {
3116 met_lon = strbit.GetInt(90, 28);
3117 met_lat = strbit.GetInt(118, 27);
3118 mmsi = AisMeteoNewMmsi(mmsi, met_lat, met_lon, 28, site_ID);
3123 int x_mmsi = AisMeteoNewMmsi(mmsi, 91, 181, 0, site_ID);
3129 return AIS_GENERIC_ERROR;
3138 auto it = AISTargetList.find(mmsi);
3139 if (it == AISTargetList.end())
3141 pTargetData = AisTargetDataMaker::GetInstance().GetTargetData();
3146 pTargetData->MMSI = mmsi;
3147 pTargetData->met_data.original_mmsi = origin_mmsi;
3150 pTargetData = it->second;
3153 pStaleTarget = pTargetData;
3155 pTargetData->MMSI = mmsi;
3156 pTargetData->met_data.original_mmsi = origin_mmsi;
3161 if (mmsi ==
static_cast<unsigned>(props->MMSI)) {
3163 if (TRACKTYPE_NEVER == props->TrackType) {
3164 pTargetData->b_show_track =
false;
3165 }
else if (TRACKTYPE_ALWAYS == props->TrackType) {
3166 pTargetData->b_show_track =
true;
3171 if (props->m_bignore)
return AIS_NoError;
3174 else if (props->m_bVDM) {
3176 if (str.Mid(3, 9).IsSameAs(
"VDM,1,1,,")) {
3177 int message_ID = strbit.GetInt(1, 6);
3180 if ((message_ID <= 3) || (message_ID == 18)) {
3182 pTargetData->b_OwnShip =
true;
3184 wxString aivdostr = str;
3185 aivdostr.replace(1, 5,
"AIVDO");
3186 unsigned char calculated_checksum = 0;
3187 wxString::iterator j;
3188 for (j = aivdostr.begin() + 1; j != aivdostr.end() && *j !=
'*';
3190 calculated_checksum ^=
static_cast<unsigned char>(*j);
3193 if (j <= aivdostr.end() - 3)
3196 wxString::Format(_(
"%02X"), calculated_checksum));
3198 gps_watchdog_timeout_ticks =
3201 std::string full_sentence = aivdostr.ToStdString();
3202 auto address = std::make_shared<NavAddr0183>(
"virtual");
3205 auto msg = std::make_shared<const Nmea0183Msg>(
3206 "AIVDO", full_sentence, address);
3207 NavMsgBus::GetInstance().
Notify(std::move(msg));
3217 wxDateTime now = wxDateTime::Now();
3221 last_report_ticks = pStaleTarget->PositionReportTicks;
3223 last_report_ticks = now.GetTicks();
3227 pSelectAIS->DeleteSelectablePoint((
void *)mmsi_long, SELTYPE_AISTARGET);
3231 pTargetData->LastPositionReportTicks = pTargetData->PositionReportTicks;
3232 pTargetData->PositionReportTicks = now.GetTicks();
3233 pTargetData->StaticReportTicks = now.GetTicks();
3234 pTargetData->m_utc_hour = gpsg_utc_hour;
3235 pTargetData->m_utc_min = gpsg_utc_min;
3236 pTargetData->m_utc_sec = gpsg_utc_sec;
3237 pTargetData->m_date_string = gpsg_date;
3238 pTargetData->MMSI = gpsg_mmsi;
3239 pTargetData->NavStatus = 0;
3240 pTargetData->Lat = gpsg_lat;
3241 pTargetData->Lon = gpsg_lon;
3242 pTargetData->b_positionOnceValid =
true;
3243 pTargetData->COG = gpsg_cog;
3244 pTargetData->SOG = gpsg_sog;
3245 pTargetData->ShipType = 52;
3246 pTargetData->Class = AIS_GPSG_BUDDY;
3247 memcpy(pTargetData->ShipName, gpsg_name_str,
sizeof(gpsg_name_str));
3248 pTargetData->b_nameValid =
true;
3249 pTargetData->b_active =
true;
3250 pTargetData->b_lost =
false;
3252 bdecode_result =
true;
3253 }
else if (arpa_mmsi) {
3254 pTargetData->m_utc_hour = arpa_utc_hour;
3255 pTargetData->m_utc_min = arpa_utc_min;
3256 pTargetData->m_utc_sec = arpa_utc_sec;
3257 pTargetData->MMSI = arpa_mmsi;
3258 pTargetData->NavStatus = 15;
3259 if (str.Mid(3, 3).IsSameAs(
"TLL")) {
3262 (now.GetTicks() - pTargetData->PositionReportTicks);
3263 if (age_of_last > 0) {
3264 ll_gc_ll_reverse(pTargetData->Lat, pTargetData->Lon, arpa_lat,
3265 arpa_lon, &pTargetData->COG, &pTargetData->SOG);
3266 pTargetData->SOG = pTargetData->SOG * 3600 / age_of_last;
3269 pTargetData->Lat = arpa_lat;
3270 pTargetData->Lon = arpa_lon;
3271 }
else if (str.Mid(3, 3).IsSameAs(
"TTM")) {
3272 if (arpa_dist != 0.)
3273 ll_gc_ll(
gLat,
gLon, arpa_brg, arpa_dist, &pTargetData->Lat,
3277 pTargetData->COG = arpa_cog;
3278 pTargetData->SOG = arpa_sog;
3280 pTargetData->LastPositionReportTicks = pTargetData->PositionReportTicks;
3281 pTargetData->PositionReportTicks = now.GetTicks();
3282 pTargetData->StaticReportTicks = now.GetTicks();
3283 pTargetData->b_positionOnceValid =
true;
3284 pTargetData->ShipType = 55;
3285 pTargetData->Class = AIS_ARPA;
3287 memcpy(pTargetData->ShipName, arpa_name_str,
sizeof(arpa_name_str));
3288 if (arpa_status !=
"Q")
3289 pTargetData->b_nameValid =
true;
3291 pTargetData->b_nameValid =
false;
3292 pTargetData->b_active = !arpa_lost;
3293 pTargetData->b_lost = arpa_nottracked;
3295 bdecode_result =
true;
3296 }
else if (aprs_mmsi) {
3297 pTargetData->m_utc_hour = now.GetHour();
3298 pTargetData->m_utc_min = now.GetMinute();
3299 pTargetData->m_utc_sec = now.GetSecond();
3300 pTargetData->MMSI = aprs_mmsi;
3301 pTargetData->NavStatus = 15;
3303 int age_of_last = (now.GetTicks() - pTargetData->PositionReportTicks);
3304 if (age_of_last > 0) {
3305 ll_gc_ll_reverse(pTargetData->Lat, pTargetData->Lon, aprs_lat,
3306 aprs_lon, &pTargetData->COG, &pTargetData->SOG);
3307 pTargetData->SOG = pTargetData->SOG * 3600 / age_of_last;
3310 pTargetData->LastPositionReportTicks = pTargetData->PositionReportTicks;
3311 pTargetData->PositionReportTicks = now.GetTicks();
3312 pTargetData->StaticReportTicks = now.GetTicks();
3313 pTargetData->Lat = aprs_lat;
3314 pTargetData->Lon = aprs_lon;
3315 pTargetData->b_positionOnceValid =
true;
3316 pTargetData->ShipType = 56;
3317 pTargetData->Class = AIS_APRS;
3318 memcpy(pTargetData->ShipName, aprs_name_str,
sizeof(aprs_name_str));
3319 pTargetData->b_nameValid =
true;
3320 pTargetData->b_active =
true;
3321 pTargetData->b_lost =
false;
3323 bdecode_result =
true;
3327 Parse_VDXBitstring(&strbit, pTargetData);
3331 getMmsiProperties(pTargetData);
3334 pTargetData->RecentPeriod =
3335 pTargetData->PositionReportTicks - last_report_ticks;
3340 pTargetData =
nullptr;
3345 CommitAISTarget(pTargetData, str, bdecode_result, bnewtarget);
3350 if ((n_msgs % 10000) == 0)
3351 printf(
"n_msgs %10d m_n_targets: %6d n_msg1: %10d n_msg5+24: %10d \n",
3352 n_msgs, m_n_targets, n_msg1, n_msg5 + n_msg24);
3358void AisDecoder::CommitAISTarget(
3359 const std::shared_ptr<AisTargetData> &pTargetData,
const wxString &str,
3360 bool message_valid,
bool new_target) {
3361 m_pLatestTargetData = pTargetData;
3363 if (!str.IsEmpty()) {
3364 if (str.Mid(3, 3).IsSameAs(
"VDO"))
3365 pTargetData->b_OwnShip =
true;
3367 pTargetData->b_OwnShip =
false;
3370 if (!pTargetData->b_OwnShip) {
3372 if (0 == m_persistent_tracks.count(pTargetData->MMSI)) {
3374 pTargetData->b_PersistTrack =
false;
3379 pTargetData->b_mPropPersistTrack = props->m_bPersistentTrack;
3386 pTargetData->b_NoTrack =
false;
3391 if (message_valid) {
3393 if (pTargetData->MMSI) {
3394 AISshipNameCache(pTargetData.get(), AISTargetNamesC, AISTargetNamesNC,
3397 AISTargetList[pTargetData->MMSI] =
3400 if (!pTargetData->area_notices.empty()) {
3401 auto it = AIS_AreaNotice_Sources.find(pTargetData->MMSI);
3402 if (it == AIS_AreaNotice_Sources.end())
3403 AIS_AreaNotice_Sources[pTargetData->MMSI] = pTargetData;
3408 if (!pTargetData->b_OwnShip) {
3409 if (pTargetData->b_positionOnceValid) {
3410 long mmsi_long = pTargetData->MMSI;
3411 SelectItem *pSel =
pSelectAIS->AddSelectablePoint(
3412 pTargetData->Lat, pTargetData->Lon, (
void *)mmsi_long,
3414 pSel->SetUserData(pTargetData->MMSI);
3418 UpdateOneCPA(pTargetData.get());
3421 if (pTargetData->b_show_track) UpdateOneTrack(pTargetData.get());
3424 plugin_msg_evt.Notify(std::make_shared<AisTargetData>(*pTargetData),
"");
3434 if (!pTargetData->b_OwnShip) {
3435 if (pTargetData->b_positionOnceValid) {
3436 long mmsi_long = pTargetData->MMSI;
3437 SelectItem *pSel =
pSelectAIS->AddSelectablePoint(
3438 pTargetData->Lat, pTargetData->Lon, (
void *)mmsi_long,
3440 pSel->SetUserData(pTargetData->MMSI);
3447void AisDecoder::getAISTarget(
long mmsi,
3448 std::shared_ptr<AisTargetData> &pTargetData,
3449 std::shared_ptr<AisTargetData> &pStaleTarget,
3450 bool &bnewtarget,
int &last_report_ticks,
3452 now = wxDateTime::Now();
3453 auto it = AISTargetList.find(mmsi);
3454 if (it == AISTargetList.end())
3456 pTargetData = AisTargetDataMaker::GetInstance().GetTargetData();
3460 pTargetData = it->second;
3461 pStaleTarget = pTargetData;
3468 last_report_ticks = pStaleTarget->PositionReportTicks;
3470 last_report_ticks = now.GetTicks();
3474 pSelectAIS->DeleteSelectablePoint((
void *)mmsi, SELTYPE_AISTARGET);
3477std::shared_ptr<AisTargetData> AisDecoder::ProcessDSx(
const wxString &str,
3479 double dsc_lat = 0.;
3480 double dsc_lon = 0.;
3481 double dsc_mins, dsc_degs, dsc_tmp, dsc_addr;
3483 double dse_lat = 0.;
3484 double dse_lon = 0.;
3485 long dsc_fmt, dsc_quadrant, dsc_cat, dsc_nature;
3488 int dsc_tx_mmsi = 0;
3490 double dse_cog = 0.;
3491 double dse_sog = 0.;
3492 wxString dse_shipName =
"";
3497 std::shared_ptr<AisTargetData> pTargetData =
nullptr;
3501 wxStringTokenizer tkz(str,
",*");
3504 token = tkz.GetNextToken();
3506 if (str.Mid(3, 3).IsSameAs(
"DSC")) {
3507 m_dsc_last_string = str;
3509 token = tkz.GetNextToken();
3513 token = tkz.GetNextToken();
3515 if (dsc_fmt == 12 || dsc_fmt == 16) {
3516 dsc_mmsi = wxAtoi(token.Mid(0, 9));
3518 token.ToDouble(&dsc_addr);
3519 dsc_mmsi = 0 - (int)(dsc_addr / 10);
3522 token = tkz.GetNextToken();
3523 token.ToLong(&dsc_cat);
3525 token = tkz.GetNextToken();
3526 if (!token.IsSameAs(
"")) {
3527 token.ToLong(&dsc_nature);
3531 token = tkz.GetNextToken();
3533 token = tkz.GetNextToken();
3534 token.ToDouble(&dsc_tmp);
3536 token = tkz.GetNextToken();
3537 token = tkz.GetNextToken();
3538 if (dsc_fmt == 16 && dsc_cat == 12 && !token.IsSameAs(
"")) {
3540 dsc_tx_mmsi = dsc_mmsi;
3541 dsc_mmsi = wxAtoi(token.Mid(0, 9));
3543 token = tkz.GetNextToken();
3544 if (dsc_fmt == 16 && dsc_cat == 12) {
3545 if (!token.IsSameAs(
"")) {
3546 token.ToLong(&dsc_nature);
3550 token = tkz.GetNextToken();
3551 token = tkz.GetNextToken();
3553 dsc_quadrant = (int)(dsc_tmp / 1000000000.0);
3555 if (dsc_quadrant > 3)
3558 dsc_lat = (int)(dsc_tmp / 100000.0);
3559 dsc_lon = dsc_tmp - dsc_lat * 100000.0;
3560 dsc_lat = dsc_lat - dsc_quadrant * 10000;
3561 dsc_degs = (int)(dsc_lat / 100.0);
3562 dsc_mins = dsc_lat - dsc_degs * 100.0;
3563 dsc_lat = dsc_degs + dsc_mins / 60.0;
3565 dsc_degs = (int)(dsc_lon / 100.0);
3566 dsc_mins = dsc_lon - dsc_degs * 100.0;
3567 dsc_lon = dsc_degs + dsc_mins / 60.0;
3568 switch (dsc_quadrant) {
3584 if (dsc_fmt != 02) mmsi = (int)dsc_mmsi;
3586 }
else if (str.Mid(3, 3).IsSameAs(
"DSE")) {
3587 token = tkz.GetNextToken();
3588 token = tkz.GetNextToken();
3589 token = tkz.GetNextToken();
3590 token = tkz.GetNextToken();
3591 dse_mmsi = wxAtoi(token.Mid(
3597 token = tkz.GetNextToken();
3600 token.ToDouble(&dse_tmp);
3601 dse_lat = (int)(dse_tmp / 10000.0);
3602 dse_lon = (int)(dse_tmp - dse_lat * 10000.0);
3603 dse_lat = dse_lat / 600000.0;
3604 dse_lon = dse_lon / 600000.0;
3607 while (tkz.HasMoreTokens()) {
3608 dseSymbol = tkz.GetNextToken();
3609 token = tkz.GetNextToken();
3610 if (dseSymbol.IsSameAs(
"00")) {
3611 token.ToDouble(&dse_tmp);
3612 dse_lat = (int)(dse_tmp / 10000.0);
3613 dse_lon = (int)(dse_tmp - dse_lat * 10000.0);
3614 dse_lat = dse_lat / 600000.0;
3615 dse_lon = dse_lon / 600000.0;
3616 }
else if (dseSymbol.IsSameAs(
"01")) {
3617 }
else if (dseSymbol.IsSameAs(
"02")) {
3618 token.ToDouble(&dse_tmp);
3619 dse_sog = dse_tmp / 10.0;
3620 }
else if (dseSymbol.IsSameAs(
"03")) {
3621 token.ToDouble(&dse_tmp);
3622 dse_cog = dse_tmp / 10.0;
3623 }
else if (dseSymbol.IsSameAs(
"04")) {
3624 dse_shipName = DecodeDSEExpansionCharacters(token);
3625 }
else if (dseSymbol.IsSameAs(
"05")) {
3626 }
else if (dseSymbol.IsSameAs(
"06")) {
3629 mmsi = abs((
int)dse_mmsi);
3633 wxDateTime now = wxDateTime::Now();
3635 int last_report_ticks = now.GetTicks();
3638 auto it = AISTargetList.find(mmsi);
3639 std::shared_ptr<AisTargetData> pStaleTarget =
nullptr;
3640 if (it == AISTargetList.end()) {
3642 pStaleTarget = it->second;
3643 last_report_ticks = pStaleTarget->PositionReportTicks;
3649 m_ptentative_dsctarget = AisTargetDataMaker::GetInstance().GetTargetData();
3651 m_ptentative_dsctarget->PositionReportTicks = now.GetTicks();
3652 m_ptentative_dsctarget->StaticReportTicks = now.GetTicks();
3654 m_ptentative_dsctarget->MMSI = mmsi;
3655 m_ptentative_dsctarget->NavStatus =
3657 m_ptentative_dsctarget->Lat = dsc_lat;
3658 m_ptentative_dsctarget->Lon = dsc_lon;
3659 m_ptentative_dsctarget->b_positionOnceValid =
true;
3660 m_ptentative_dsctarget->COG = 0;
3661 m_ptentative_dsctarget->SOG = 0;
3662 m_ptentative_dsctarget->ShipType = dsc_fmt;
3663 m_ptentative_dsctarget->Class = AIS_DSC;
3664 m_ptentative_dsctarget->b_isDSCtarget =
true;
3665 m_ptentative_dsctarget->b_nameValid =
true;
3666 if (dsc_fmt == 12 || (dsc_fmt == 16 && dsc_cat == 12)) {
3667 snprintf(m_ptentative_dsctarget->ShipName, SHIP_NAME_LEN,
"DISTRESS %u",
3669 m_ptentative_dsctarget->m_dscNature = int(dsc_nature);
3670 m_ptentative_dsctarget->m_dscTXmmsi = dsc_tx_mmsi;
3672 snprintf(m_ptentative_dsctarget->ShipName, SHIP_NAME_LEN,
"POSITION %u",
3676 m_ptentative_dsctarget->b_active =
true;
3677 m_ptentative_dsctarget->b_lost =
false;
3678 m_ptentative_dsctarget->RecentPeriod =
3679 m_ptentative_dsctarget->PositionReportTicks - last_report_ticks;
3682 if (!b_take_dsc) m_dsc_timer.Start(1000, wxTIMER_ONE_SHOT);
3687 if (dse_mmsi || b_take_dsc) {
3688 if (m_ptentative_dsctarget) {
3694 m_ptentative_dsctarget->Lat =
3695 m_ptentative_dsctarget->Lat +
3696 ((m_ptentative_dsctarget->Lat) >= 0 ? dse_lat : -dse_lat);
3697 m_ptentative_dsctarget->Lon =
3698 m_ptentative_dsctarget->Lon +
3699 ((m_ptentative_dsctarget->Lon) >= 0 ? dse_lon : -dse_lon);
3700 if (!dse_shipName.empty()) {
3701 memset(m_ptentative_dsctarget->ShipName,
'\0', SHIP_NAME_LEN);
3702 snprintf(m_ptentative_dsctarget->ShipName, SHIP_NAME_LEN,
"%s",
3703 dse_shipName.ToAscii().data());
3705 m_ptentative_dsctarget->COG = dse_cog;
3706 m_ptentative_dsctarget->SOG = dse_sog;
3710 m_ptentative_dsctarget->RecentPeriod =
3711 m_ptentative_dsctarget->PositionReportTicks - last_report_ticks;
3716 auto found = AISTargetList.find(mmsi);
3717 if (found == AISTargetList.end()) {
3718 pTargetData = m_ptentative_dsctarget;
3720 pTargetData = found->second;
3721 std::vector<AISTargetTrackPoint> ptrack =
3722 std::move(pTargetData->m_ptrack);
3723 pTargetData->CloneFrom(
3724 m_ptentative_dsctarget
3727 pTargetData->m_ptrack =
3734 m_ptentative_dsctarget =
nullptr;
3736 m_pLatestTargetData = pTargetData;
3738 AISTargetList[pTargetData->MMSI] =
3741 long mmsi_long = pTargetData->MMSI;
3745 pSelectAIS->DeleteSelectablePoint((
void *)mmsi_long, SELTYPE_AISTARGET);
3748 pSelectAIS->AddSelectablePoint(pTargetData->Lat, pTargetData->Lon,
3749 (
void *)mmsi_long, SELTYPE_AISTARGET);
3750 pSel->SetUserData(pTargetData->MMSI);
3753 UpdateOneCPA(pTargetData.get());
3756 if (pTargetData->b_show_track) UpdateOneTrack(pTargetData.get());
3763bool AisDecoder::NMEACheckSumOK(
const wxString &str_in) {
3764 unsigned char checksum_value = 0;
3765 int sentence_hex_sum;
3767 wxCharBuffer buf = str_in.ToUTF8();
3768 if (!buf.data())
return false;
3770 char str_ascii[AIS_MAX_MESSAGE_LEN + 1];
3771 strncpy(str_ascii, buf.data(), AIS_MAX_MESSAGE_LEN);
3772 str_ascii[AIS_MAX_MESSAGE_LEN] =
'\0';
3774 int string_length = strlen(str_ascii);
3776 int payload_length = 0;
3777 while ((payload_length < string_length) &&
3778 (str_ascii[payload_length] !=
'*'))
3781 if (payload_length == string_length)
3786 while (index < payload_length) {
3787 checksum_value ^= str_ascii[index];
3791 if (string_length > 4) {
3793 scanstr[0] = str_ascii[payload_length + 1];
3794 scanstr[1] = str_ascii[payload_length + 2];
3796 sscanf(scanstr,
"%2x", &sentence_hex_sum);
3798 if (sentence_hex_sum == checksum_value)
return true;
3804void AisDecoder::UpdateAllCPA() {
3806 for (
const auto &it : GetTargetList()) {
3807 std::shared_ptr<AisTargetData> td = it.second;
3809 if (
nullptr != td) UpdateOneCPA(td.get());
3813void AisDecoder::UpdateAllTracks() {
3814 for (
const auto &it : GetTargetList()) {
3815 std::shared_ptr<AisTargetData> td = it.second;
3816 if (td) UpdateOneTrack(td.get());
3821void AisDecoder::UpdateOneTrack(AisTargetData *ptarget) {
3822 if (!ptarget->b_positionOnceValid)
return;
3824 if (!ptarget->m_ptrack.empty()) {
3825 const AISTargetTrackPoint &LastTrackpoint = ptarget->m_ptrack.back();
3826 if (fabs(LastTrackpoint.m_lat - ptarget->Lat) > .1 ||
3827 fabs(LastTrackpoint.m_lon - ptarget->Lon) > .1) {
3830 ptarget->m_ptrack.pop_back();
3831 ptarget->b_positionDoubtful =
true;
3838 if ((ptarget->PositionReportTicks - ptarget->LastPositionReportTicks) > 2) {
3840 AISTargetTrackPoint ptrackpoint;
3841 ptrackpoint.m_lat = ptarget->Lat;
3842 ptrackpoint.m_lon = ptarget->Lon;
3843 ptrackpoint.m_time = wxDateTime::Now().GetTicks();
3845 ptarget->m_ptrack.push_back(ptrackpoint);
3847 if (ptarget->b_PersistTrack || ptarget->b_mPropPersistTrack) {
3849 if (0 == m_persistent_tracks.count(ptarget->MMSI)) {
3851 t->SetName(wxString::Format(
3852 "AIS %s (%u) %s %s", ptarget->GetFullName().c_str(), ptarget->MMSI,
3853 wxDateTime::Now().FormatISODate().c_str(),
3854 wxDateTime::Now().FormatISOTime().c_str()));
3857 m_persistent_tracks[ptarget->MMSI] = t;
3859 t = m_persistent_tracks[ptarget->MMSI];
3861 TrackPoint *tp = t->GetLastPoint();
3862 vector2D point(ptrackpoint.m_lon, ptrackpoint.m_lat);
3864 t->AddNewPoint(point, wxDateTime(ptrackpoint.m_time).ToUTC());
3867 pSelect->AddSelectableTrackSegment(tp->m_lat, tp->m_lon, tp1->m_lat,
3868 tp1->m_lon, tp, tp1, t);
3878 wxDateTime::Now().GetTicks() - (time_t)(g_AISShowTracks_Mins * 60);
3880 ptarget->m_ptrack.erase(
3881 std::remove_if(ptarget->m_ptrack.begin(), ptarget->m_ptrack.end(),
3882 [=](
const AISTargetTrackPoint &track) {
3883 return track.m_time < test_time;
3885 ptarget->m_ptrack.end());
3890void AisDecoder::DeletePersistentTrack(
const Track *track) {
3891 for (
auto it = m_persistent_tracks.begin(); it != m_persistent_tracks.end();
3893 if (it->second == track) {
3894 unsigned mmsi = it->first;
3895 m_persistent_tracks.erase(it);
3897 if (0 == m_persistent_tracks.count(mmsi)) {
3901 if (props->m_bPersistentTrack) {
3905 std::shared_ptr<AisTargetData> td =
3906 Get_Target_Data_From_MMSI(mmsi);
3908 props->m_bPersistentTrack =
false;
3909 td->b_mPropPersistTrack =
false;
3911 if (!m_callbacks.confirm_stop_track()) {
3912 props->m_bPersistentTrack =
true;
3924void AisDecoder::UpdateAllAlarms() {
3925 m_bGeneralAlert =
false;
3928 for (
const auto &it : GetTargetList()) {
3929 std::shared_ptr<AisTargetData> td = it.second;
3933 if (!m_bGeneralAlert) {
3935 if ((td->CPA < g_CPAWarn_NM) && (td->TCPA > 0) &&
3936 (td->Class != AIS_ATON) && (td->Class != AIS_BASE))
3937 m_bGeneralAlert =
true;
3940 if (g_bAIS_CPA_Alert_Suppress_Moored && (td->SOG <= g_ShowMoored_Kts))
3941 m_bGeneralAlert =
false;
3944 if ((g_bCPAMax) && (td->Range_NM > g_CPAMax_NM))
3945 m_bGeneralAlert =
false;
3948 if ((g_bTCPA_Max) && (td->TCPA > g_TCPA_Max)) m_bGeneralAlert =
false;
3951 if (td->Class == AIS_SART && td->NavStatus == 14)
3952 m_bGeneralAlert =
true;
3955 if ((td->Class == AIS_DSC) &&
3956 ((td->ShipType == 12) || (td->ShipType == 16)))
3957 m_bGeneralAlert =
true;
3960 ais_alert_type this_alarm = AIS_NO_ALERT;
3963 if (td->Class == AIS_SART && td->NavStatus == 14)
3964 this_alarm = AIS_ALERT_SET;
3967 if ((td->Class == AIS_DSC) &&
3968 ((td->ShipType == 12) || (td->ShipType == 16)))
3969 this_alarm = AIS_ALERT_SET;
3971 if (g_bCPAWarn && td->b_active && td->b_positionOnceValid &&
3972 (td->Class != AIS_SART) && (td->Class != AIS_DSC)) {
3975 if ((g_bHideMoored) && (td->SOG <= g_ShowMoored_Kts)) {
3976 td->n_alert_state = AIS_NO_ALERT;
3982 if (g_bAIS_CPA_Alert_Suppress_Moored &&
3983 (td->SOG <= g_ShowMoored_Kts)) {
3984 td->n_alert_state = AIS_NO_ALERT;
3990 if (td->Range_NM > g_CPAMax_NM) {
3991 td->n_alert_state = AIS_NO_ALERT;
3996 if ((td->CPA < g_CPAWarn_NM) && (td->TCPA > 0) &&
3997 (td->Class != AIS_ATON) && (td->Class != AIS_BASE) &&
3998 (td->Class != AIS_METEO)) {
4000 if (td->TCPA < g_TCPA_Max) {
4001 if (td->b_isFollower)
4002 this_alarm = AIS_ALERT_NO_DIALOG_SET;
4004 this_alarm = AIS_ALERT_SET;
4007 if (td->b_isFollower)
4008 this_alarm = AIS_ALERT_NO_DIALOG_SET;
4010 this_alarm = AIS_ALERT_SET;
4017 if (td->Class == AIS_SART) {
4018 if (td->b_in_ack_timeout) {
4019 wxTimeSpan delta = wxDateTime::Now() - td->m_ack_time;
4021 if (delta.GetMinutes() >= 10) td->b_in_ack_timeout =
false;
4023 }
else if (g_bAIS_ACK_Timeout ||
4024 ((td->Class == AIS_DSC) &&
4025 ((td->ShipType == 12) || (td->ShipType == 16)))) {
4026 if (td->b_in_ack_timeout) {
4027 wxTimeSpan delta = wxDateTime::Now() - td->m_ack_time;
4028 if (delta.GetMinutes() > g_AckTimeout_Mins)
4029 td->b_in_ack_timeout =
false;
4035 if (td->b_in_ack_timeout) {
4036 if (this_alarm == AIS_NO_ALERT) td->b_in_ack_timeout =
false;
4040 td->n_alert_state = this_alarm;
4045void AisDecoder::UpdateOneCPA(AisTargetData *ptarget) {
4046 ptarget->Range_NM = -1.;
4052 ptarget->Lat_projected = ptarget->Lat;
4053 ptarget->Lon_projected = ptarget->Lon;
4054 if (ptarget->PositionReportTicks > 0 && ptarget->SOG > 0.0 &&
4055 ptarget->SOG < 102.2 && ptarget->COG >= 0.0 && ptarget->COG < 360.0) {
4056 wxDateTime now = wxDateTime::Now();
4058 const time_t report_age = now.GetTicks() - ptarget->PositionReportTicks;
4059 if (report_age > 0) {
4060 ll_gc_ll(ptarget->Lat, ptarget->Lon, ptarget->COG,
4061 ptarget->SOG * (report_age / 3600.0), &ptarget->Lat_projected,
4062 &ptarget->Lon_projected);
4072 DistanceBearingMercator(ptarget->Lat_projected, ptarget->Lon_projected,
gLat,
4074 ptarget->Range_NM = dist;
4077 if (dist <= 1e-5) ptarget->Brg = -1.0;
4079 if (!ptarget->b_positionOnceValid || !
bGPSValid) {
4080 ptarget->bCPA_Valid =
false;
4084 if (ptarget->Class == AIS_METEO) {
4085 ptarget->bCPA_Valid =
false;
4094 if (ptarget->b_OwnShip) {
4096 ptarget->TCPA = -100;
4097 ptarget->bCPA_Valid =
false;
4101 double cpa_calc_ownship_cog =
gCog;
4102 double cpa_calc_target_cog = ptarget->COG;
4105 if (std::isnan(
gSog) || (
gSog > 102.2)) {
4106 ptarget->bCPA_Valid =
false;
4111 if (std::isnan(
gCog) ||
gCog == 360.0) {
4113 cpa_calc_ownship_cog =
4117 ptarget->bCPA_Valid =
false;
4123 if (ptarget->COG == 360.0) {
4124 if (ptarget->SOG > 102.2) {
4125 ptarget->bCPA_Valid =
false;
4127 }
else if (ptarget->SOG < .01) {
4128 cpa_calc_target_cog = 0.;
4131 ptarget->bCPA_Valid =
false;
4137 double v0 =
gSog * 1852.;
4138 double v1 = ptarget->SOG * 1852.;
4140 if ((v0 < 1e-6) && (v1 < 1e-6)) {
4144 ptarget->bCPA_Valid =
false;
4151 double east1 = (ptarget->Lon_projected -
gLon) * 60 * 1852;
4152 double north1 = (ptarget->Lat_projected -
gLat) * 60 * 1852;
4154 double east = east1 * (cos(
gLat * PI / 180.));
4156 double north = north1;
4159 double cosa = cos((90. - cpa_calc_ownship_cog) * PI / 180.);
4160 double sina = sin((90. - cpa_calc_ownship_cog) * PI / 180.);
4161 double cosb = cos((90. - cpa_calc_target_cog) * PI / 180.);
4162 double sinb = sin((90. - cpa_calc_target_cog) * PI / 180.);
4165 double fc = (v0 * cosa) - (v1 * cosb);
4166 double fs = (v0 * sina) - (v1 * sinb);
4168 double d = (fc * fc) + (fs * fs);
4176 tcpa = ((fc * east) + (fs * north)) / d;
4179 ptarget->TCPA = tcpa * 60.;
4184 double OwnshipLatCPA, OwnshipLonCPA, TargetLatCPA, TargetLonCPA;
4186 ll_gc_ll(
gLat,
gLon, cpa_calc_ownship_cog,
gSog * tcpa, &OwnshipLatCPA,
4188 ll_gc_ll(ptarget->Lat_projected, ptarget->Lon_projected,
4189 cpa_calc_target_cog, ptarget->SOG * tcpa, &TargetLatCPA,
4193 ptarget->CPA = DistGreatCircle(OwnshipLatCPA, OwnshipLonCPA, TargetLatCPA,
4196 ptarget->bCPA_Valid =
true;
4198 if (ptarget->TCPA < 0) ptarget->bCPA_Valid =
false;
4202void AisDecoder::OnTimerDSC(wxTimerEvent &event) {
4205 if (m_ptentative_dsctarget) {
4206 ProcessDSx(m_dsc_last_string,
true);
4210void AisDecoder::OnTimerAIS(wxTimerEvent &event) {
4215 wxDateTime now = wxDateTime::Now();
4218 std::unordered_map<int, std::shared_ptr<AisTargetData>> ¤t_targets =
4221 auto it = current_targets.begin();
4222 std::vector<int> remove_array;
4224 while (it != current_targets.end()) {
4228 current_targets.erase(it);
4233 std::shared_ptr<AisTargetData> xtd = it->second;
4235 int target_posn_age = now.GetTicks() - xtd->PositionReportTicks;
4236 int target_static_age = now.GetTicks() - xtd->StaticReportTicks;
4248 double removelost_Mins = fmax(g_RemoveLost_Mins, g_MarkLost_Mins);
4250 if (g_bInlandEcdis && (xtd->Class != AIS_ARPA)) {
4251 double iECD_LostTimeOut = 0.0;
4255 if (xtd->Class == AIS_CLASS_A) {
4256 if ((xtd->NavStatus == MOORED) || (xtd->NavStatus == AT_ANCHOR)) {
4258 iECD_LostTimeOut = 18 * 60;
4260 iECD_LostTimeOut = 60;
4262 iECD_LostTimeOut = 60;
4263 }
else if (xtd->Class == AIS_CLASS_B) {
4265 iECD_LostTimeOut = 18 * 60;
4267 iECD_LostTimeOut = 180;
4268 }
else if (xtd->Class == AIS_ATON || xtd->Class == AIS_BASE)
4269 iECD_LostTimeOut = 18 * 60;
4271 if ((target_posn_age > iECD_LostTimeOut) &&
4272 (xtd->Class != AIS_GPSG_BUDDY))
4273 xtd->b_active =
false;
4275 removelost_Mins = (2 * iECD_LostTimeOut) / 60.;
4277 }
else if (g_bMarkLost) {
4278 if ((target_posn_age > g_MarkLost_Mins * 60) &&
4279 (xtd->Class != AIS_GPSG_BUDDY) && (xtd->Class != AIS_SART))
4280 xtd->b_active =
false;
4283 if (xtd->Class == AIS_SART || xtd->Class == AIS_METEO)
4284 removelost_Mins = 18.0;
4288 if (g_bRemoveLost || g_bInlandEcdis) {
4290 (xtd->Class == AIS_ARPA &&
4292 if (((target_posn_age > removelost_Mins * 60) &&
4293 (xtd->Class != AIS_GPSG_BUDDY)) ||
4298 xtd->b_positionOnceValid =
false;
4306 long mmsi_long = xtd->MMSI;
4307 pSelectAIS->DeleteSelectablePoint((
void *)mmsi_long, SELTYPE_AISTARGET);
4312 if (target_static_age > removelost_Mins * 60 * 3 || b_arpalost) {
4313 xtd->b_removed =
true;
4315 remove_array.push_back(xtd->MMSI);
4324 if (xtd->MMSI == props->MMSI) {
4325 if (props->m_bignore) {
4326 remove_array.push_back(xtd->MMSI);
4327 xtd->b_removed =
true;
4336 remove_array.push_back(xtd->MMSI);
4337 xtd->b_removed =
true;
4345 for (
unsigned int i = 0; i < remove_array.size(); i++) {
4346 auto itd = current_targets.find(remove_array[i]);
4347 if (itd != current_targets.end()) {
4348 std::shared_ptr<AisTargetData> td = itd->second;
4349 current_targets.erase(itd);
4358 m_bSuppressed =
false;
4359 if (g_bAIS_CPA_Alert_Suppress_Moored || g_bHideMoored ||
4360 (g_bShowScaled && g_bAllowShowScaled))
4361 m_bSuppressed =
true;
4363 m_bAIS_Audio_Alert_On =
false;
4372 std::shared_ptr<AisTargetData> palert_target =
nullptr;
4374 if (!g_pais_alert_dialog_active) {
4376 double tcpa_min = 1e6;
4377 double sart_range = 1e6;
4378 std::shared_ptr<AisTargetData> palert_target_cpa =
nullptr;
4379 std::shared_ptr<AisTargetData> palert_target_sart =
nullptr;
4380 std::shared_ptr<AisTargetData> palert_target_dsc =
nullptr;
4382 for (it = current_targets.begin(); it != current_targets.end(); ++it) {
4383 std::shared_ptr<AisTargetData> td = it->second;
4385 if ((td->Class != AIS_SART) && (td->Class != AIS_DSC)) {
4386 if (g_bAIS_CPA_Alert && td->b_active) {
4387 if ((AIS_ALERT_SET == td->n_alert_state) && !td->b_in_ack_timeout) {
4388 if (td->TCPA < tcpa_min) {
4389 tcpa_min = td->TCPA;
4390 palert_target_cpa = td;
4394 }
else if ((td->Class == AIS_DSC) &&
4395 ((td->ShipType == 12) || (td->ShipType == 16))) {
4397 if ((AIS_ALERT_SET == td->n_alert_state) && !td->b_in_ack_timeout) {
4398 palert_target_dsc = td;
4401 td->b_isDSCtarget =
false;
4406 else if (td->Class == AIS_SART) {
4408 if ((AIS_ALERT_SET == td->n_alert_state) && !td->b_in_ack_timeout) {
4409 if (td->Range_NM < sart_range) {
4410 tcpa_min = sart_range;
4411 palert_target_sart = td;
4421 palert_target = palert_target_cpa;
4423 if (palert_target_sart) {
4424 palert_target = palert_target_sart;
4427 if (palert_target_dsc) {
4428 palert_target = palert_target_dsc;
4432 palert_target = Get_Target_Data_From_MMSI(m_callbacks.get_target_mmsi());
4435 if (palert_target)
info_update.Notify(palert_target,
"");
4437 TimerAIS.Start(TIMER_AIS_MSEC, wxTIMER_CONTINUOUS);
4440std::shared_ptr<AisTargetData> AisDecoder::Get_Target_Data_From_MMSI(
4442 if (AISTargetList.find(mmsi) == AISTargetList.end())
return nullptr;
4443 return AISTargetList[mmsi];
4450MmsiProperties::MmsiProperties(wxString &spec) {
4452 wxStringTokenizer tkz(spec,
";");
4455 s = tkz.GetNextToken();
4460 s = tkz.GetNextToken();
4462 if (s.Upper() ==
"ALWAYS")
4463 TrackType = TRACKTYPE_ALWAYS;
4464 else if (s.Upper() ==
"NEVER")
4465 TrackType = TRACKTYPE_NEVER;
4468 s = tkz.GetNextToken();
4470 if (s.Upper() ==
"IGNORE") m_bignore =
true;
4473 s = tkz.GetNextToken();
4475 if (s.Upper() ==
"MOB") m_bMOB =
true;
4478 s = tkz.GetNextToken();
4480 if (s.Upper() ==
"VDM") m_bVDM =
true;
4483 s = tkz.GetNextToken();
4485 if (s.Upper() ==
"FOLLOWER") m_bFollower =
true;
4488 s = tkz.GetNextToken();
4490 if (s.Upper() ==
"PERSIST") m_bPersistentTrack =
true;
4493 s = tkz.GetNextToken();
4495 m_ShipName = s.Upper();
4499MmsiProperties::~MmsiProperties() =
default;
4501void MmsiProperties::Init() {
4503 TrackType = TRACKTYPE_DEFAULT;
4507 m_bFollower =
false;
4508 m_bPersistentTrack =
false;
4512wxString MmsiProperties::Serialize() {
4516 sMMSI.Printf(
"%d", MMSI);
4520 if (TRACKTYPE_ALWAYS == TrackType)
4522 else if (TRACKTYPE_NEVER == TrackType)
4543 sMMSI <<
"Follower";
4547 if (m_bPersistentTrack) {
4552 if (m_ShipName ==
"") {
4553 m_ShipName = GetShipNameFromFile(MMSI);
4555 sMMSI << m_ShipName;
4559void AISshipNameCache(AisTargetData *pTargetData,
4560 AIS_Target_Name_Hash *AISTargetNamesC,
4561 AIS_Target_Name_Hash *AISTargetNamesNC,
long mmsi) {
4562 if (g_benableAISNameCache) {
4563 wxString ship_name =
"";
4566 if (!pTargetData->b_nameValid) {
4567 AIS_Target_Name_Hash::iterator it = AISTargetNamesC->find(mmsi);
4568 if (it != AISTargetNamesC->end()) {
4569 ship_name = (*AISTargetNamesC)[mmsi].Left(20);
4570 strncpy(pTargetData->ShipName, ship_name.mb_str(),
4571 ship_name.length() + 1);
4572 pTargetData->b_nameValid =
true;
4573 pTargetData->b_nameFromCache =
true;
4574 }
else if (!g_bUseOnlyConfirmedAISName) {
4575 it = AISTargetNamesNC->find(mmsi);
4576 if (it != AISTargetNamesNC->end()) {
4577 ship_name = (*AISTargetNamesNC)[mmsi].Left(20);
4578 strncpy(pTargetData->ShipName, ship_name.mb_str(),
4579 ship_name.length() + 1);
4580 pTargetData->b_nameValid =
true;
4581 pTargetData->b_nameFromCache =
true;
4586 else if ((pTargetData->MID == 5) || (pTargetData->MID == 24) ||
4587 (pTargetData->MID == 19) ||
4588 (pTargetData->MID == 123) ||
4589 (pTargetData->MID == 124)) {
4591 pTargetData->b_nameFromCache =
false;
4592 ship_name = trimAISField(pTargetData->ShipName);
4593 AIS_Target_Name_Hash::iterator itC = AISTargetNamesC->find(mmsi);
4594 AIS_Target_Name_Hash::iterator itNC = AISTargetNamesNC->find(mmsi);
4596 AISTargetNamesC->end()) {
4597 if ((*AISTargetNamesC)[mmsi] ==
4599 if (itNC != AISTargetNamesNC->end()) {
4601 AISTargetNamesNC->erase(itNC);
4604 if (itNC != AISTargetNamesNC->end()) {
4606 if ((*AISTargetNamesNC)[mmsi] ==
4609 (*AISTargetNamesC)[mmsi] = ship_name;
4611 AISTargetNamesNC->erase(itNC);
4614 (*AISTargetNamesNC)[mmsi] = ship_name;
4616 if (g_bUseOnlyConfirmedAISName)
4617 strncpy(pTargetData->ShipName, (*AISTargetNamesC)[mmsi].mb_str(),
4618 (*AISTargetNamesC)[mmsi].Left(20).Length() + 1);
4620 (*AISTargetNamesNC)[mmsi] = ship_name;
4625 AISTargetNamesNC->end()) {
4626 if ((*AISTargetNamesNC)[mmsi] ==
4629 (*AISTargetNamesC)[mmsi] = ship_name;
4631 AISTargetNamesNC->erase(itNC);
4633 (*AISTargetNamesNC)[mmsi] = ship_name;
4636 (*AISTargetNamesNC)[mmsi] = ship_name;
4638 if (g_bUseOnlyConfirmedAISName) {
4639 pTargetData->ShipName[SHIP_NAME_LEN - 1] =
'\0';
4640 strncpy(pTargetData->ShipName,
"Unknown ",
4648wxString GetShipNameFromFile(
int nmmsi) {
4650 if (g_benableAISNameCache) {
4654 while (getline(infile, line)) {
4655 wxStringTokenizer tokenizer(wxString::FromUTF8(line.c_str()),
",");
4656 if (nmmsi == wxAtoi(tokenizer.GetNextToken())) {
4657 name = tokenizer.GetNextToken().Trim();
4660 tokenizer.GetNextToken();
4668void AisDecoder::UpdateMMSItoNameFile(
const wxString &mmsi,
4669 const wxString &name) {
4673 std::map<wxString, wxString> mmsi_name_map;
4679 while (getline(infile, line)) {
4680 wxStringTokenizer tokenizer(wxString::FromUTF8(line.c_str()),
",");
4681 wxString file_mmsi = tokenizer.GetNextToken();
4682 wxString file_name = tokenizer.GetNextToken().Trim();
4683 mmsi_name_map[file_mmsi] = file_name;
4689 mmsi_name_map[mmsi] = name.Upper();
4694 for (
const auto &pair : mmsi_name_map) {
4695 std::string line = std::string(pair.first.mb_str()) +
"," +
4696 std::string(pair.second.mb_str()) +
"\n";
4703wxString AisDecoder::GetMMSItoNameEntry(
const wxString &mmsi) {
4704 return GetShipNameFromFile(wxAtoi(mmsi));
4708int AisMeteoNewMmsi(
int orig_mmsi,
int m_lat,
int m_lon,
int lon_bits = 0,
4712 if ((!lon_bits || lon_bits == 999) && siteID) {
4715 auto &points = AisMeteoPoints::GetInstance().GetPoints();
4716 if (points.size()) {
4717 for (
const auto &point : points) {
4719 if (siteID == point.siteID && orig_mmsi == point.orig_mmsi) {
4721 new_mmsi = point.mmsi;
4727 if (!found && !lon_bits) {
4732 double lon_tentative = 181.;
4733 double lat_tentative = 91.;
4735 if (lon_bits == 25) {
4736 if (m_lon & 0x01000000)
4737 m_lon |= 0xFE000000;
4738 lon_tentative = m_lon / 60000.;
4740 if (m_lat & 0x00800000)
4741 m_lat |= 0xFF000000;
4742 lat_tentative = m_lat / 60000.;
4744 }
else if (lon_bits == 28) {
4745 if (m_lon & 0x08000000)
4746 m_lon |= 0xf0000000;
4747 lon_tentative = m_lon / 600000.;
4749 if (m_lat & 0x04000000)
4750 m_lat |= 0xf8000000;
4751 lat_tentative = m_lat / 600000.;
4756 wxString slon = wxString::Format(
"%0.3f", lon_tentative);
4757 wxString slat = wxString::Format(
"%0.3f", lat_tentative);
4765 static int nextMeteommsi = 199400000;
4766 auto &points = AisMeteoPoints::GetInstance().GetPoints();
4768 if (lon_bits != 999 && !points.empty()) {
4769 wxString t_lat, t_lon;
4770 for (
const auto &point : points) {
4772 if (slat.IsSameAs(point.lat) && slon.IsSameAs(point.lon)) {
4774 new_mmsi = point.mmsi;
4783 points.emplace_back(
4784 AisMeteoPoint(nextMeteommsi, slat, slon, siteID, orig_mmsi));
4785 new_mmsi = nextMeteommsi;
Select * pSelectAIS
Global instance.
wxString AISTargetNameFileName
Global instance.
ArrayOfMmsiProperties g_MMSI_Props_Array
Global instance.
unsigned g_OwnShipmmsi
Global instance.
AisDecoder * g_pAIS
Global instance.
Class AisDecoder and helpers.
Select * pSelectAIS
Global instance.
wxString AISTargetNameFileName
Global instance.
ArrayOfMmsiProperties g_MMSI_Props_Array
Global instance.
unsigned g_OwnShipmmsi
Global instance.
Global state for AIS decoder.
int GetInt(int sp, int len, bool signed_flag=false)
sp is starting bit, 1-based
obs::EventVar info_update
Notified when AIS user dialogs should update.
obs::EventVar plugin_msg_evt
A JSON message should be sent.
obs::EventVar touch_state
Notified when gFrame->TouchAISActive() should be invoked.
obs::EventVar new_track
Notified on new track creation.
Process incoming AIS messages.
void LogInputMessage(const std::shared_ptr< const NavMsg > &msg, bool is_filtered, bool is_error, const wxString &error_msg="") const
Logs an input message with context information.
void Notify(std::shared_ptr< const NavMsg > message)
Accept message received by driver, make it available for upper layers.
Custom event class for OpenCPN's notification system.
std::shared_ptr< const void > GetSharedPtr() const
Gets the event's payload data.
Raw messages layer, supports sending and recieving navmsg messages.
int g_iSpeedFormat
User-selected speed unit format for display and input.
int g_iDistanceFormat
User-selected distance (horizontal) unit format for display and input.
Global variables stored in configuration file.
GUI constant definitions.
Meteo points are Meteorological and Hydrographic data received by NMEA0183 (AIS) VDM message 8 dac:00...
Multiplexer class and helpers.
const wxChar * ParseGPXDateTime(wxDateTime &dt, const wxChar *datetime)
This function parses a string containing a GPX time representation and returns a wxDateTime containin...
double fromUsrDistance(double usr_distance, int unit, int default_val)
Convert distance from user units to nautical miles.
Navigation Utility Functions without GUI dependencies.
bool bGPSValid
Indicate whether the Global Navigation Satellite System (GNSS) has a valid position.
double gHdt
True heading in degrees (0-359.99).
double gLat
Vessel's current latitude in decimal degrees.
double gCog
Course over ground in degrees (0-359.99).
double gSog
Speed over ground in knots.
double gLon
Vessel's current longitude in decimal degrees.
Position, course, speed, etc.
Waypoint or mark abstraction.
Route * pAISMOBRoute
Global instance.
Select * pSelect
Global instance.
Selected route, segment, waypoint, etc.
double kCog
Course over ground in degrees.
double kHdt
True heading in degrees.
double kHdm
Magnetic heading in degrees.
double kLat
Latitude in decimal degrees.
double kSog
Speed over ground in knots.
double kVar
Magnetic variation in degrees.
double kLon
Longitude in decimal degrees.
std::vector< Track * > g_TrackList
Global instance.
Recorded track abstraction.