1 /****************************************************************************** 2 * 3 * Project: OpenCPN 4 * Purpose: AIS Decoder Object 5 * Author: David Register 6 * 7 *************************************************************************** 8 * Copyright (C) 2010 by David S. Register * 9 * * 10 * This program is free software; you can redistribute it and/or modify * 11 * it under the terms of the GNU General Public License as published by * 12 * the Free Software Foundation; either version 2 of the License, or * 13 * (at your option) any later version. * 14 * * 15 * This program is distributed in the hope that it will be useful, * 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 18 * GNU General Public License for more details. * 19 * * 20 * You should have received a copy of the GNU General Public License * 21 * along with this program; if not, write to the * 22 * Free Software Foundation, Inc., * 23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 24 *************************************************************************** 25 * 26 */ 27 28 #ifndef __AIS_H__ 29 #define __AIS_H__ 30 31 #include "wx/wxprec.h" 32 33 #ifndef WX_PRECOMP 34 #include "wx/wx.h" 35 #endif //precompiled headers 36 37 #include <wx/datetime.h> 38 #include <wx/listctrl.h> 39 #include <wx/spinctrl.h> 40 #include <wx/aui/aui.h> 41 #include <wx/wxhtml.h> 42 43 #include <vector> 44 45 #include "wx/sound.h" 46 47 #include "dychart.h" 48 #include "chart1.h" 49 #include "navutil.h" 50 #include "OCPN_Sound.h" 51 #include "AIS_Bitstring.h" 52 #include "AISTargetListDialog.h" 53 54 // Constants 55 #ifndef PI 56 #define PI 3.1415926535897931160E0 /* pi */ 57 #endif 58 59 60 61 #define TIMER_AIS_MSEC 998 62 #define TIMER_AIS_AUDIO_MSEC 2000 63 64 #define AIS_TARGETDATA_MAX_CANVAS 6 65 66 enum { 67 tlTRK = 0, 68 tlNAME, 69 tlCALL, 70 tlMMSI, 71 tlCLASS, 72 tlTYPE, 73 tlNAVSTATUS, 74 tlBRG, 75 tlRNG, 76 tlCOG, 77 tlSOG, 78 tlCPA, 79 tlTCPA 80 };// AISTargetListCtrl Columns; 81 82 typedef enum AIS_Error 83 { 84 AIS_NoError = 0, 85 AIS_Partial, 86 AIS_NMEAVDX_TOO_LONG, 87 AIS_NMEAVDX_CHECKSUM_BAD, 88 AIS_NMEAVDX_BAD, 89 AIS_NO_SERIAL, 90 AIS_NO_TCP, 91 AIS_GENERIC_ERROR, 92 AIS_INCOMPLETE_MULTIPART 93 }_AIS_Error; 94 95 96 // Describe NavStatus variable 97 typedef enum ais_nav_status 98 { 99 UNDERWAY_USING_ENGINE = 0, 100 AT_ANCHOR, 101 NOT_UNDER_COMMAND, 102 RESTRICTED_MANOEUVRABILITY, 103 CONSTRAINED_BY_DRAFT, 104 MOORED, 105 AGROUND, 106 FISHING, 107 UNDERWAY_SAILING, 108 HSC, 109 WIG, 110 RESERVED_11, 111 RESERVED_12, 112 RESERVED_13, 113 RESERVED_14, 114 UNDEFINED, 115 ATON_VIRTUAL, 116 ATON_VIRTUAL_ONPOSITION, 117 ATON_VIRTUAL_OFFPOSITION, 118 ATON_REAL, 119 ATON_REAL_ONPOSITION, 120 ATON_REAL_OFFPOSITION 121 122 }_ais_nav_status; 123 124 125 // Describe Transponder Class 126 typedef enum ais_transponder_class 127 { 128 AIS_CLASS_A = 0, 129 AIS_CLASS_B, 130 AIS_ATON, // Aid to Navigation pjotrc 2010/02/01 131 AIS_BASE, // Base station 132 AIS_GPSG_BUDDY, // GpsGate Buddy object 133 AIS_DSC, // DSC target 134 AIS_SART, // SART 135 AIS_ARPA, // ARPA radar target 136 AIS_APRS // APRS position report 137 }_ais_transponder_class; 138 139 // Describe AIS Alert state 140 typedef enum ais_alert_type 141 { 142 AIS_NO_ALERT = 0, 143 AIS_ALERT_SET, 144 145 }_ais_alarm_type; 146 147 class AISTargetTrackPoint 148 { 149 public: 150 double m_lat; 151 double m_lon; 152 time_t m_time; 153 }; 154 155 156 WX_DECLARE_LIST(AISTargetTrackPoint, AISTargetTrackList); 157 158 159 160 // IMO Circ. 289 Area Notices, based on libais 161 const size_t AIS8_001_22_NUM_NAMES=128; 162 const size_t AIS8_001_22_SUBAREA_SIZE=87; 163 164 extern wxString ais8_001_22_notice_names[]; 165 166 enum Ais8_001_22_AreaShapeEnum 167 { 168 AIS8_001_22_SHAPE_ERROR = -1, 169 AIS8_001_22_SHAPE_CIRCLE = 0, // OR Point 170 AIS8_001_22_SHAPE_RECT = 1, 171 AIS8_001_22_SHAPE_SECTOR = 2, 172 AIS8_001_22_SHAPE_POLYLINE = 3, 173 AIS8_001_22_SHAPE_POLYGON = 4, 174 AIS8_001_22_SHAPE_TEXT = 5, 175 AIS8_001_22_SHAPE_RESERVED_6 = 6, 176 AIS8_001_22_SHAPE_RESERVED_7 = 7 177 }; 178 179 struct Ais8_001_22_SubArea 180 { 181 int shape; 182 float longitude, latitude; 183 int radius_m; 184 int e_dim_m; // East dimension in meters 185 int n_dim_m; 186 int orient_deg; // Orientation in degrees from true north 187 int left_bound_deg; 188 int right_bound_deg; 189 float angles[4]; 190 float dists_m[4]; 191 wxString text; 192 }; 193 194 //WX_DECLARE_LIST(Ais8_001_22_SubArea, Ais8_001_22_SubAreaList); 195 typedef std::vector<Ais8_001_22_SubArea> Ais8_001_22_SubAreaList; 196 197 struct Ais8_001_22 198 { 199 int link_id; // 10 bit id to match up text blocks 200 int notice_type; // area_type / Notice Description 201 int month; // These are in UTC 202 int day; // UTC! 203 int hour; // UTC! 204 int minute; 205 int duration_minutes; // Time from the start until the notice expires 206 wxDateTime start_time; 207 wxDateTime expiry_time; 208 Ais8_001_22_SubAreaList sub_areas; 209 }; 210 211 212 // key is link_id, which should be unique for a given mmsi 213 WX_DECLARE_HASH_MAP( int, Ais8_001_22, wxIntegerHash, wxIntegerEqual, AIS_Area_Notice_Hash ); 214 215 216 //--------------------------------------------------------------------------------- 217 // 218 // AIS_Decoder Helpers 219 // 220 //--------------------------------------------------------------------------------- 221 WX_DEFINE_SORTED_ARRAY(AIS_Target_Data *, ArrayOfAISTarget); 222 223 224 // Implement the AISTargetList as a wxHashMap 225 226 WX_DECLARE_HASH_MAP( int, AIS_Target_Data*, wxIntegerHash, wxIntegerEqual, AIS_Target_Hash ); 227 228 wxString trimAISField( char *data ); 229 wxString ais_get_status(int index); 230 wxString ais_get_type(int index); 231 wxString ais_get_short_type(int index); 232 233 void AISDrawAreaNotices (ocpnDC& dc, ViewPort &vp, ChartCanvas *cp ); 234 void AISDraw(ocpnDC& dc, ViewPort &vp, ChartCanvas *cp ); 235 bool AnyAISTargetsOnscreen( ChartCanvas *cc, ViewPort &vp ); 236 237 238 WX_DECLARE_HASH_MAP( int, wxString, wxIntegerHash, wxIntegerEqual, AIS_Target_Name_Hash ); 239 240 #endif 241