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
32#include <wx/datetime.h>
33#include "rapidjson/fwd.h"
34#include <wx/event.h>
35#include <wx/string.h>
36
37#include "ais_bitstring.h"
38#include "ais_defs.h"
39#include "ais_target_data.h"
40#include "comm_navmsg.h"
41#include "observable_evtvar.h"
42#include "ocpn_types.h"
43#include "track.h"
44
45
46enum AISAudioSoundType {
47 AISAUDIO_NONE,
48 AISAUDIO_CPA,
49 AISAUDIO_SART,
50 AISAUDIO_DSC
51};
52
54public:
56 MmsiProperties(int mmsi) {
57 Init();
58 MMSI = mmsi;
59 }
60 MmsiProperties(wxString &spec);
61
63
64 wxString Serialize();
65
66 void Init(void);
67 int MMSI;
68 int TrackType;
69 bool m_bignore;
70 bool m_bMOB;
71 bool m_bVDM;
72 bool m_bFollower;
73 bool m_bPersistentTrack;
74 wxString m_ShipName;
75};
76
77WX_DEFINE_ARRAY_PTR(MmsiProperties *, ArrayOfMmsiProperties);
78
80 std::function<bool()> confirm_stop_track;
81 AisDecoderCallbacks() : confirm_stop_track([]() { return true; } ) {}
82};
83
84class AisDecoder : public wxEvtHandler {
85public:
87
88 ~AisDecoder(void);
89
90 AisError DecodeN0183(const wxString &str);
91 std::unordered_map<int, std::shared_ptr <AisTargetData>> &GetTargetList(void) {
92 return AISTargetList;
93 }
94 std::unordered_map<int, std::shared_ptr <AisTargetData>> &GetAreaNoticeSourcesList(void) {
95 return AIS_AreaNotice_Sources;
96 }
97 std::shared_ptr<AisTargetData> Get_Target_Data_From_MMSI(int mmsi);
98 int GetNumTargets(void) { return m_n_targets; }
99 bool IsAISSuppressed(void) { return m_bSuppressed; }
100 bool IsAISAlertGeneral(void) { return m_bGeneralAlert; }
101 AisError DecodeSingleVDO(const wxString &str, GenericPosDatEx *pos,
102 wxString *acc);
103 void DeletePersistentTrack(Track *track);
104 std::map<int, Track *> m_persistent_tracks;
105 bool AIS_AlertPlaying(void) { return m_bAIS_AlertPlaying; };
106
112
115
118
121
124
127
128private:
129 void OnActivate(wxActivateEvent &event);
130 void OnTimerAIS(wxTimerEvent &event);
131 void OnTimerDSC(wxTimerEvent &event);
132
133 bool NMEACheckSumOK(const wxString &str);
134 bool Parse_VDXBitstring(AisBitstring *bstr, std::shared_ptr<AisTargetData> ptd);
135 void UpdateAllCPA(void);
136 void UpdateOneCPA(AisTargetData *ptarget);
137 void UpdateAllAlarms(void);
138 void UpdateAllTracks(void);
139 void UpdateOneTrack(AisTargetData *ptarget);
140 void BuildERIShipTypeHash(void);
141 std::shared_ptr<AisTargetData> ProcessDSx(const wxString &str, bool b_take_dsc = false);
142
143 wxString DecodeDSEExpansionCharacters(wxString dseData);
144 void getAISTarget(long mmsi, std::shared_ptr<AisTargetData> &pTargetData,
145 std::shared_ptr<AisTargetData> &pStaleTarget, bool &bnewtarget,
146 int &last_report_ticks, wxDateTime &now);
147 void getMmsiProperties(std::shared_ptr<AisTargetData> &pTargetData);
148 void handleUpdate(std::shared_ptr<AisTargetData> pTargetData, bool bnewtarget,
149 const rapidjson::Value &update);
150 void updateItem(std::shared_ptr<AisTargetData> pTargetData, bool bnewtarget,
151 const rapidjson::Value &item, wxString &sfixtime) const;
152 void CommitAISTarget( std::shared_ptr<AisTargetData> pTargetData,
153 const wxString &str, bool message_valid,
154 bool new_target);
155 void InitCommListeners(void);
156 bool HandleN0183_AIS( std::shared_ptr <const Nmea0183Msg> n0183_msg );
157 void HandleSignalK(std::shared_ptr<const SignalkMsg> sK_msg);
158
159 bool HandleN2K_129038( std::shared_ptr<const Nmea2000Msg> n2k_msg );
160 bool HandleN2K_129039( std::shared_ptr<const Nmea2000Msg> n2k_msg );
161 bool HandleN2K_129041( std::shared_ptr<const Nmea2000Msg> n2k_msg );
162 bool HandleN2K_129794( std::shared_ptr<const Nmea2000Msg> n2k_msg );
163 bool HandleN2K_129809( std::shared_ptr<const Nmea2000Msg> n2k_msg );
164 bool HandleN2K_129810( std::shared_ptr<const Nmea2000Msg> n2k_msg );
165 bool HandleN2K_129793( std::shared_ptr<const Nmea2000Msg> n2k_msg );
166
167 wxString m_signalk_selfid;
168 std::unordered_map<int, std::shared_ptr<AisTargetData>> AISTargetList;
169 std::unordered_map<int, std::shared_ptr<AisTargetData>> AIS_AreaNotice_Sources;
170 AIS_Target_Name_Hash *AISTargetNamesC;
171 AIS_Target_Name_Hash *AISTargetNamesNC;
172
173 ObservableListener listener_N0183_VDM;
174 ObservableListener listener_N0183_FRPOS;
175 ObservableListener listener_N0183_CDDSC;
176 ObservableListener listener_N0183_CDDSE;
177 ObservableListener listener_N0183_TLL;
178 ObservableListener listener_N0183_TTM;
179 ObservableListener listener_N0183_OSD;
180 ObservableListener listener_SignalK;
181
182 ObservableListener listener_N2K_129038;
183 ObservableListener listener_N2K_129039;
184 ObservableListener listener_N2K_129041;
185 ObservableListener listener_N2K_129794;
186 ObservableListener listener_N2K_129809;
187 ObservableListener listener_N2K_129810;
188 ObservableListener listener_N2K_129793;
189
190 bool m_busy;
191 wxTimer TimerAIS;
192 wxFrame *m_parent_frame;
193 AisDecoderCallbacks m_callbacks;
194
195 int nsentences;
196 int isentence;
197 wxString sentence_accumulator;
198 bool m_OK;
199
200 std::shared_ptr<AisTargetData> m_pLatestTargetData;
201
202 bool m_bAIS_Audio_Alert_On;
203 wxTimer m_AIS_Audio_Alert_Timer;
204 int m_n_targets;
205 bool m_bSuppressed;
206 bool m_bGeneralAlert;
207 std::shared_ptr<AisTargetData> m_ptentative_dsctarget;
208 wxTimer m_dsc_timer;
209 wxString m_dsc_last_string;
210 std::vector<int> m_MMSI_MismatchVec;
211
212 bool m_bAIS_AlertPlaying;
213 DECLARE_EVENT_TABLE()
214};
215
216#endif // _AIS_DECODER_H__
EventVar plugin_msg
A JSON message should be sent.
Definition: ais_decoder.h:126
EventVar new_track
Notified on new track creation.
Definition: ais_decoder.h:120
EventVar new_ais_wp
Notified when new AIS wp is created.
Definition: ais_decoder.h:117
EventVar info_update
Notified when AIS user dialogs should update.
Definition: ais_decoder.h:111
EventVar delete_track
Notified when about to delete track.
Definition: ais_decoder.h:123
EventVar touch_state
Notified when gFrame->TouchAISActive() should be invoked.
Definition: ais_decoder.h:114
Generic event handling between between two parties like MVC Model and Controller using a shared Event...
Keeps listening over it's lifespan, removes itself on destruction.
Definition: observable.h:143
Definition: track.h:79