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 "ais.h"
29 #include "OCPN_SignalKEvent.h"
30 #include <map>
31 
32 #define TRACKTYPE_DEFAULT       0
33 #define TRACKTYPE_ALWAYS        1
34 #define TRACKTYPE_NEVER         2
35 
36 class MMSIProperties
37 {
38 public:
MMSIProperties()39     MMSIProperties(){};
MMSIProperties(int mmsi)40     MMSIProperties( int mmsi ){ Init(); MMSI = mmsi; }
41     MMSIProperties( wxString &spec );
42 
43     ~MMSIProperties();
44 
45     wxString Serialize();
46 
47     void Init( void );
48     int         MMSI;
49     int         TrackType;
50     bool        m_bignore;
51     bool        m_bMOB;
52     bool        m_bVDM;
53     bool        m_bFollower;
54     bool        m_bPersistentTrack;
55     wxString    m_ShipName;
56 };
57 
58 WX_DEFINE_ARRAY_PTR(MMSIProperties *, ArrayOfMMSIProperties);
59 
60 class AIS_Decoder : public wxEvtHandler
61 {
62 
63 public:
64     AIS_Decoder(wxFrame *parent);
65 
66     ~AIS_Decoder(void);
67 
68     void OnEvtAIS(OCPN_DataStreamEvent& event);
69     void OnEvtSignalK(OCPN_SignalKEvent& event);
70     AIS_Error Decode(const wxString& str);
GetTargetList(void)71     AIS_Target_Hash *GetTargetList(void) {return AISTargetList;}
GetAreaNoticeSourcesList(void)72     AIS_Target_Hash *GetAreaNoticeSourcesList(void) {return AIS_AreaNotice_Sources;}
73     AIS_Target_Data *Get_Target_Data_From_MMSI(int mmsi);
GetNumTargets(void)74     int GetNumTargets(void){ return m_n_targets;}
IsAISSuppressed(void)75     bool IsAISSuppressed(void){ return m_bSuppressed; }
IsAISAlertGeneral(void)76     bool IsAISAlertGeneral(void) { return m_bGeneralAlert; }
77     AIS_Error DecodeSingleVDO( const wxString& str, GenericPosDatEx *pos, wxString *acc );
78     void DeletePersistentTrack( Track *track );
79     std::map<int, Track*> m_persistent_tracks;
AIS_AlertPlaying(void)80     bool AIS_AlertPlaying(void) { return m_bAIS_AlertPlaying; };
81 
82 private:
83 
84     void OnActivate(wxActivateEvent& event);
85     void OnTimerAIS(wxTimerEvent& event);
86     void OnSoundFinishedAISAudio(wxCommandEvent& event);
87     void OnTimerDSC( wxTimerEvent& event );
88 
89     bool NMEACheckSumOK(const wxString& str);
90     bool Parse_VDXBitstring(AIS_Bitstring *bstr, AIS_Target_Data *ptd);
91     void UpdateAllCPA(void);
92     void UpdateOneCPA(AIS_Target_Data *ptarget);
93     void UpdateAllAlarms(void);
94     void UpdateAllTracks(void);
95     void UpdateOneTrack(AIS_Target_Data *ptarget);
96     void BuildERIShipTypeHash(void);
97     AIS_Target_Data *ProcessDSx( const wxString& str, bool b_take_dsc = false );
98     void SendJSONMsg( AIS_Target_Data *pTarget );
99 
100     void getAISTarget(long mmsi, AIS_Target_Data *&pTargetData, AIS_Target_Data *&pStaleTarget, bool &bnewtarget,
101                       int &last_report_ticks, wxDateTime &now);
102 
103     void handleUpdate(AIS_Target_Data *pTargetData, bool bnewtarget, wxJSONValue &update);
104     void updateItem(AIS_Target_Data *pTargetData, bool bnewtarget, wxJSONValue &item, wxString &sfixtime) const;
105 
106     wxString m_signalk_selfid;
107     AIS_Target_Hash *AISTargetList;
108     AIS_Target_Hash *AIS_AreaNotice_Sources;
109     AIS_Target_Name_Hash *AISTargetNamesC;
110     AIS_Target_Name_Hash *AISTargetNamesNC;
111 
112     bool              m_busy;
113     wxTimer           TimerAIS;
114     wxFrame           *m_parent_frame;
115 
116     int               nsentences;
117     int               isentence;
118     wxString          sentence_accumulator;
119     bool              m_OK;
120 
121     AIS_Target_Data   *m_pLatestTargetData;
122 
123     bool             m_bAIS_Audio_Alert_On;
124     wxTimer          m_AIS_Audio_Alert_Timer;
125     OcpnSound*       m_AIS_Sound;
126     int              m_n_targets;
127     bool             m_bSuppressed;
128     bool             m_bGeneralAlert;
129     AIS_Target_Data  *m_ptentative_dsctarget;
130     wxTimer          m_dsc_timer;
131     wxString         m_dsc_last_string;
132     std::vector<int> m_MMSI_MismatchVec;
133 
134     bool             m_bAIS_AlertPlaying;
135 DECLARE_EVENT_TABLE()
136 
137 };
138 
139 #endif
140