OpenCPN Partial API docs
Loading...
Searching...
No Matches
ais_decoder.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_DECODER_H__
26#define _AIS_DECODER_H__
27
28#include <map>
29#include <unordered_map>
30#include <memory>
31#include <vector>
32
33#include <wx/datetime.h>
34#include <wx/event.h>
35#include <wx/string.h>
36
37#include "rapidjson/fwd.h"
38#include "model/ais_bitstring.h"
39#include "model/ais_defs.h"
40#include "model/ais_target_data.h"
41#include "model/comm_navmsg.h"
42#include "model/ocpn_types.h"
43#include "model/select.h"
44#include "model/track.h"
45#include "observable_evtvar.h"
46
47class AisDecoder; // forward
48class ArrayOfMmsiProperties; // forward
49
50// AISTargetAlertDialog in gui layer
51extern wxEvtHandler *g_pais_alert_dialog_active;
52
53extern Select *pSelectAIS;
54extern wxString AISTargetNameFileName;
55extern AisDecoder *g_pAIS;
56extern ArrayOfMmsiProperties g_MMSI_Props_Array;
57extern int g_OwnShipmmsi;
58
59enum AISAudioSoundType {
60 AISAUDIO_NONE,
61 AISAUDIO_CPA,
62 AISAUDIO_SART,
63 AISAUDIO_DSC
64};
65
67public:
68 MmsiProperties() {};
69 MmsiProperties(int mmsi) {
70 Init();
71 MMSI = mmsi;
72 }
73 MmsiProperties(wxString &spec);
74
76
77 wxString Serialize();
78
79 void Init(void);
80 int MMSI;
81 int TrackType;
82 bool m_bignore;
83 bool m_bMOB;
84 bool m_bVDM;
85 bool m_bFollower;
86 bool m_bPersistentTrack;
87 wxString m_ShipName;
88};
89
90WX_DEFINE_ARRAY_PTR(MmsiProperties *, ArrayOfMmsiProperties);
91
93 std::function<bool()> confirm_stop_track;
94 std::function<int()> get_target_mmsi;
96 : confirm_stop_track([]() { return true; }),
97 get_target_mmsi([]() { return 0; }) {}
98};
99
100class AisDecoder : public wxEvtHandler {
101public:
103
104 ~AisDecoder(void);
105
106 AisError DecodeN0183(const wxString &str);
107 std::unordered_map<int, std::shared_ptr<AisTargetData>> &GetTargetList(void) {
108 return AISTargetList;
109 }
110 std::unordered_map<int, std::shared_ptr<AisTargetData>> &
111 GetAreaNoticeSourcesList(void) {
112 return AIS_AreaNotice_Sources;
113 }
114 std::shared_ptr<AisTargetData> Get_Target_Data_From_MMSI(int mmsi);
115 int GetNumTargets(void) { return m_n_targets; }
116 bool IsAISSuppressed(void) { return m_bSuppressed; }
117 bool IsAISAlertGeneral(void) { return m_bGeneralAlert; }
118 AisError DecodeSingleVDO(const wxString &str, GenericPosDatEx *pos,
119 wxString *acc);
120 void DeletePersistentTrack(Track *track);
121 std::map<int, Track *> m_persistent_tracks;
122 bool AIS_AlertPlaying(void) { return m_bAIS_AlertPlaying; };
123
129
132
135
138
141
144
145private:
146 void OnActivate(wxActivateEvent &event);
147 void OnTimerAIS(wxTimerEvent &event);
148 void OnTimerDSC(wxTimerEvent &event);
149
150 bool NMEACheckSumOK(const wxString &str);
151 bool Parse_VDXBitstring(AisBitstring *bstr,
152 std::shared_ptr<AisTargetData> ptd);
153 void UpdateAllCPA(void);
154 void UpdateOneCPA(AisTargetData *ptarget);
155 void UpdateAllAlarms(void);
156 void UpdateAllTracks(void);
157 void UpdateOneTrack(AisTargetData *ptarget);
158 void BuildERIShipTypeHash(void);
159 std::shared_ptr<AisTargetData> ProcessDSx(const wxString &str,
160 bool b_take_dsc = false);
161
162 wxString DecodeDSEExpansionCharacters(wxString dseData);
163 void getAISTarget(long mmsi, std::shared_ptr<AisTargetData> &pTargetData,
164 std::shared_ptr<AisTargetData> &pStaleTarget,
165 bool &bnewtarget, int &last_report_ticks, wxDateTime &now);
166 void getMmsiProperties(std::shared_ptr<AisTargetData> &pTargetData);
167 void handleUpdate(std::shared_ptr<AisTargetData> pTargetData, bool bnewtarget,
168 const rapidjson::Value &update);
169 void updateItem(std::shared_ptr<AisTargetData> pTargetData, bool bnewtarget,
170 const rapidjson::Value &item, wxString &sfixtime) const;
171 void CommitAISTarget(std::shared_ptr<AisTargetData> pTargetData,
172 const wxString &str, bool message_valid,
173 bool new_target);
174 void InitCommListeners(void);
175 bool HandleN0183_AIS(std::shared_ptr<const Nmea0183Msg> n0183_msg);
176 void HandleSignalK(std::shared_ptr<const SignalkMsg> sK_msg);
177
178 bool HandleN2K_129038(std::shared_ptr<const Nmea2000Msg> n2k_msg);
179 bool HandleN2K_129039(std::shared_ptr<const Nmea2000Msg> n2k_msg);
180 bool HandleN2K_129041(std::shared_ptr<const Nmea2000Msg> n2k_msg);
181 bool HandleN2K_129794(std::shared_ptr<const Nmea2000Msg> n2k_msg);
182 bool HandleN2K_129809(std::shared_ptr<const Nmea2000Msg> n2k_msg);
183 bool HandleN2K_129810(std::shared_ptr<const Nmea2000Msg> n2k_msg);
184 bool HandleN2K_129793(std::shared_ptr<const Nmea2000Msg> n2k_msg);
185
186 wxString m_signalk_selfid;
187 std::unordered_map<int, std::shared_ptr<AisTargetData>> AISTargetList;
188 std::unordered_map<int, std::shared_ptr<AisTargetData>>
189 AIS_AreaNotice_Sources;
190 AIS_Target_Name_Hash *AISTargetNamesC;
191 AIS_Target_Name_Hash *AISTargetNamesNC;
192
193 ObservableListener listener_N0183_VDM;
194 ObservableListener listener_N0183_FRPOS;
195 ObservableListener listener_N0183_CDDSC;
196 ObservableListener listener_N0183_CDDSE;
197 ObservableListener listener_N0183_TLL;
198 ObservableListener listener_N0183_TTM;
199 ObservableListener listener_N0183_OSD;
200 ObservableListener listener_N0183_WPL;
201 ObservableListener listener_SignalK;
202
203 ObservableListener listener_N2K_129038;
204 ObservableListener listener_N2K_129039;
205 ObservableListener listener_N2K_129041;
206 ObservableListener listener_N2K_129794;
207 ObservableListener listener_N2K_129809;
208 ObservableListener listener_N2K_129810;
209 ObservableListener listener_N2K_129793;
210
211 bool m_busy;
212 wxTimer TimerAIS;
213 wxFrame *m_parent_frame;
214 AisDecoderCallbacks m_callbacks;
215
216 int nsentences;
217 int isentence;
218 wxString sentence_accumulator;
219 bool m_OK;
220
221 std::shared_ptr<AisTargetData> m_pLatestTargetData;
222
223 bool m_bAIS_Audio_Alert_On;
224 wxTimer m_AIS_Audio_Alert_Timer;
225 int m_n_targets;
226 bool m_bSuppressed;
227 bool m_bGeneralAlert;
228 std::shared_ptr<AisTargetData> m_ptentative_dsctarget;
229 wxTimer m_dsc_timer;
230 wxString m_dsc_last_string;
231 std::vector<int> m_MMSI_MismatchVec;
232
233 bool m_bAIS_AlertPlaying;
234 DECLARE_EVENT_TABLE()
235};
236
237#endif // _AIS_DECODER_H__
EventVar plugin_msg
A JSON message should be sent.
EventVar new_track
Notified on new track creation.
EventVar new_ais_wp
Notified when new AIS wp is created.
EventVar info_update
Notified when AIS user dialogs should update.
EventVar delete_track
Notified when about to delete track.
EventVar touch_state
Notified when gFrame->TouchAISActive() should be invoked.
Generic event handling between MVC Model and Controller based on a shared EventVar variable.
Keeps listening over it's lifespan, removes itself on destruction.
Definition observable.h:131
Represents a track, which is a series of connected track points.
Definition track.h:79
Raw, undecoded messages definitions.
A generic position and navigation data structure.
Definition ocpn_types.h:74