OpenCPN Partial API docs
ais_target_data.h
1 /***************************************************************************
2  *
3  * Project: OpenCPN
4  *
5  ***************************************************************************
6  * Copyright (C) 2010 by David S. Register *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
22  ***************************************************************************
23  */
24 
25 #ifndef _AIS_TARGET_DATA_H__
26 #define _AIS_TARGET_DATA_H__
27 
28 #include <functional>
29 #include <memory>
30 #include <vector>
31 #include <unordered_map>
32 
33 #include <wx/datetime.h>
34 #include <wx/intl.h>
35 #include <wx/string.h>
36 
37 #include "model/meteo_points.h"
38 #include "model/navutil_base.h"
39 
40 #define SHIP_NAME_LEN 35
41 #define DESTINATION_LEN 21
42 #define CALL_SIGN_LEN 8
43 #define EURO_VIN_LEN 9
44 
45 #define AIS_TARGETDATA_MAX_CANVAS 6
46 
47 void make_hash_ERI(int key, const wxString& description);
48 void clear_hash_ERI(void);
49 
50 typedef enum ais_nav_status {
51  UNDERWAY_USING_ENGINE = 0,
52  AT_ANCHOR,
53  NOT_UNDER_COMMAND,
54  RESTRICTED_MANOEUVRABILITY,
55  CONSTRAINED_BY_DRAFT,
56  MOORED,
57  AGROUND,
58  FISHING,
59  UNDERWAY_SAILING,
60  HSC,
61  WIG,
62  RESERVED_11,
63  RESERVED_12,
64  RESERVED_13,
65  RESERVED_14,
66  UNDEFINED,
67  ATON_VIRTUAL,
68  ATON_VIRTUAL_ONPOSITION,
69  ATON_VIRTUAL_OFFPOSITION,
70  ATON_REAL,
71  ATON_REAL_ONPOSITION,
72  ATON_REAL_OFFPOSITION
73 
74 } _ais_nav_status;
75 
76 
77 // Describe Transponder Class
78 typedef enum ais_transponder_class {
79  AIS_CLASS_A = 0,
80  AIS_CLASS_B,
81  AIS_ATON, // Aid to Navigation pjotrc 2010/02/01
82  AIS_BASE, // Base station
83  AIS_GPSG_BUDDY, // GpsGate Buddy object
84  AIS_DSC, // DSC target
85  AIS_SART, // SART
86  AIS_ARPA, // ARPA radar target
87  AIS_APRS, // APRS position report
88  AIS_METEO // Meteorological and Hydrographic data
89 } _ais_transponder_class;
90 
91 
92 // Describe AIS Alert state
93 typedef enum ais_alert_type {
94  AIS_NO_ALERT = 0,
95  AIS_ALERT_SET,
96  AIS_ALERT_NO_DIALOG_SET
97 
98 } _ais_alarm_type;
99 
101 public:
102  double m_lat;
103  double m_lon;
104  time_t m_time;
105 };
106 
107 enum Ais8_001_22_AreaShapeEnum {
108  AIS8_001_22_SHAPE_ERROR = -1,
109  AIS8_001_22_SHAPE_CIRCLE = 0, // OR Point
110  AIS8_001_22_SHAPE_RECT = 1,
111  AIS8_001_22_SHAPE_SECTOR = 2,
112  AIS8_001_22_SHAPE_POLYLINE = 3,
113  AIS8_001_22_SHAPE_POLYGON = 4,
114  AIS8_001_22_SHAPE_TEXT = 5,
115  AIS8_001_22_SHAPE_RESERVED_6 = 6,
116  AIS8_001_22_SHAPE_RESERVED_7 = 7
117 };
118 
120  int shape;
121  float longitude, latitude;
122  int radius_m;
123  int e_dim_m; // East dimension in meters
124  int n_dim_m;
125  int orient_deg; // Orientation in degrees from true north
126  int left_bound_deg;
127  int right_bound_deg;
128  float angles[4];
129  float dists_m[4];
130  wxString text;
131 };
132 
133 typedef std::vector<Ais8_001_22_SubArea> Ais8_001_22_SubAreaList;
134 
135 struct Ais8_001_22 {
136  int link_id; // 10 bit id to match up text blocks
137  int notice_type; // area_type / Notice Description
138  int month; // These are in UTC
139  int day; // UTC!
140  int hour; // UTC!
141  int minute;
142  int duration_minutes; // Time from the start until the notice expires
143  wxDateTime start_time;
144  wxDateTime expiry_time;
145  Ais8_001_22_SubAreaList sub_areas;
146 };
147 
149  std::function<double(double)> get_mag;
150  AisTargetCallbacks(): get_mag([](double a) { return toMagnetic(a); }) {}
151 };
152 
153 
155 friend class AisTargetDataMaker;
156 
157 public:
159  ~AisTargetData();
160 
161  wxString BuildQueryResult(void);
162  wxString GetRolloverString(void);
163  wxString Get_vessel_type_string(bool b_short = false);
164  wxString Get_class_string(bool b_short = false);
165  wxString GetFullName(void);
166  wxString GetCountryCode(bool b_CntryLongStr);
167  wxString GetNatureofDistress(int dscnature);
168  void Toggle_AIS_CPA(void);
169  void ToggleShowTrack(void);
170  void CloneFrom(AisTargetData* q);
171  bool IsValidMID(int);
172 
173  int MID;
174  int MMSI;
175  ais_transponder_class Class;
176  int NavStatus;
177  int SyncState;
178  int SlotTO;
179  double SOG;
180  double COG;
181  double HDG;
182  double Lon;
183  double Lat;
184  int ROTAIS;
185  int ROTIND;
186  char CallSign[CALL_SIGN_LEN]; // includes terminator
187  char ShipName[SHIP_NAME_LEN];
188  char ShipNameExtension[15];
189  unsigned char ShipType;
190  int IMO;
191 
192  int DimA;
193  int DimB;
194  int DimC;
195  int DimD;
196 
197  double Euro_Length; // Extensions for European Inland AIS
198  double Euro_Beam;
199  double Euro_Draft;
200  char Euro_VIN[EURO_VIN_LEN]; // includes terminator
201  int UN_shiptype;
202  bool b_isEuroInland;
203  bool b_hasInlandDac; // intermediate storage for EU Inland. SignalK
204  bool b_blue_paddle;
205  int blue_paddle;
206 
207  int ETA_Mo;
208  int ETA_Day;
209  int ETA_Hr;
210  int ETA_Min;
211 
212  double Draft;
213 
214  char Destination[DESTINATION_LEN];
215 
216  time_t PositionReportTicks;
217  time_t LastPositionReportTicks;
218  time_t StaticReportTicks;
219 
220  int RecentPeriod;
221  bool b_active;
222  bool b_lost;
223  bool b_removed;
224  ais_alert_type n_alert_state;
225  bool b_suppress_audio;
226  bool b_positionDoubtful;
227  bool b_positionOnceValid;
228  bool b_nameValid;
229  bool b_isFollower;
230  bool b_isDSCtarget; // DSC flag to a possible simultaneous AIS target
231  int m_dscNature;
232  int m_dscTXmmsi; // MMSI for the DSC relay issuer
233  long dsc_NatureOfDistress;
234 
235  // MMSI Properties
236  bool b_NoTrack;
237  bool b_OwnShip;
238  bool b_PersistTrack; // For AIS target query
239  bool b_mPropPersistTrack; // For mmsi_prop
240 
241  int m_utc_hour;
242  int m_utc_min;
243  int m_utc_sec;
244  wxString m_date_string;
245 
246  wxDateTime m_ack_time;
247  bool b_in_ack_timeout;
248 
249  double Range_NM;
250  double Brg;
251 
252  wxString MSG_14_text;
253 
254  // Per target collision parameters
255  bool bCPA_Valid;
256  double TCPA; // Minutes
257  double CPA; // Nautical Miles
258  bool b_show_AIS_CPA; // TR 2012.06.28: Show AIS-CPA
259  bool b_show_track;
260 
261  AisMeteoData met_data;
262  std::vector<AISTargetTrackPoint> m_ptrack;
263 
264  std::unordered_map<int, Ais8_001_22> area_notices;
265  bool b_SarAircraftPosnReport;
266  int altitude; // Metres, from special position report(9)
267  bool b_nameFromCache;
268  float importance;
269  short last_scale[AIS_TARGETDATA_MAX_CANVAS]; // where
270  // AIS_TARGETDATA_MAX_CANVAS is
271  // the max number of chartcanvas
272 
273 private:
274  AisTargetCallbacks m_callbacks;
275 };
276 
283 public:
284  static AisTargetDataMaker& GetInstance() {
285  static AisTargetDataMaker instance;
286  return instance;
287  }
288 
289  AisTargetDataMaker(const AisTargetDataMaker&) = delete;
290  AisTargetDataMaker& operator=(const AisTargetDataMaker&) = delete;
291 
292 
293  std::shared_ptr<AisTargetData> GetTargetData() { return std::make_shared<AisTargetData>(m_callbacks); }
294  void SetCallbacks(AisTargetCallbacks callbacks) { m_callbacks = callbacks; }
295 
296 private:
297  AisTargetDataMaker() : m_callbacks(AisTargetCallbacks()) {}
298  AisTargetCallbacks m_callbacks;
299 };
300 
301 
302 wxString trimAISField(char *data);
303 wxString ais_get_status(int index);
304 
305 wxString ais_get_type(int index);
306 wxString ais_get_short_type(int index);
307 
308 #endif
Singleton factory.
Meteo points are Meteorological and Hydrographic data received by NMEA0183 (AIS) VDM message 8 dac:00...
Definition: meteo_points.h:29