OpenCPN Partial API docs
Loading...
Searching...
No Matches
comm_appmsg.h
1/***************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: Decoded messages definitions. These messages are handled by the
5 * ApgMsgBus defined in comm_appmsg_bus.h.
6 * Author: David Register, Alec Leamas
7 *
8 ***************************************************************************
9 * Copyright (C) 2022 by David Register, Alec Leamas *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License for more details. *
20 * *
21 * You should have received a copy of the GNU General Public License *
22 * along with this program; if not, write to the *
23 * Free Software Foundation, Inc., *
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
25 **************************************************************************/
26
27#ifndef _APP_MSG_H
28#define _APP_MSG_H
29
30#include <memory>
31#include <iomanip>
32
33#include <wx/event.h>
34
35#include "model/comm_driver.h"
36#include "observable.h"
37
38double PosPartsToDegrees(float degrees, float minutes, float percent_of_minute);
39
40std::string DegreesToString(double degrees);
41
42std::string TimeToString(const time_t time);
43
44class Position {
45public:
46 enum class Type { NE, NW, SE, SW, Undef };
47
49 Position(double _lat, double _lon, Type t);
50
52 Position(double _lat, double _lon);
53
55 Position();
56
57 bool IsValid() const { return type != Type::Undef; }
58
60 std::string to_string() const;
61
62 const double lat; // signed value
63 const double lon; // signed value
64 const Type type;
65
71 static Position ParseGGA(const std::string gga);
72
73private:
74 std::string TypeToStr(const Type t) const;
75
77 Type LatLongToType(double lat, double lon);
78
80 double TypeToLat(Type t, double lat);
81
83 double TypeToLong(Type t, double lon);
84};
85
86class AppMsg : public KeyProvider {
87public:
88 enum class Type;
89 AppMsg(AppMsg::Type t)
90 : type(t), name(TypeToString(t)), source(NavAddr()), prio(0) {};
91
92 virtual std::string key() const { return std::string("@!appmsg-") + name; }
93
94 std::string GetKey() const { return key(); }
95
96 std::string TypeToString(const Type t) const;
97
98 const Type type;
99 const std::string name; // Must be unique, probably using TypeToString().
100 NavAddr source;
101 unsigned short prio; // Initially 0, modified using set_priority
102
103protected:
104 AppMsg(AppMsg::Type tp, const std::string& nm, NavAddr src)
105 : type(tp), name(nm), source(src), prio(0) {};
106};
107
108enum class AppMsg::Type {
109 BasicNavData,
110 GPSWatchdog,
111 GnssFix,
112 AisData,
114 CustomMsg,
115 Undef
116};
117
122class DataPrioNeeded : public AppMsg {
123public:
124 AppMsg::Type what;
125 std::vector<NavAddr> sources;
126};
127
129class GnssFix : public AppMsg {
130public:
131 enum class Quality { none, gnss, differential };
132
133 GnssFix(Position p, time_t t, Quality q = Quality::none, int s_used = -1)
134 : AppMsg(AppMsg::Type::GnssFix, "gnss-fix", NavAddr()),
135 pos(p),
136 time(t),
137 quality(q),
138 satellites_used(s_used) {};
139 virtual ~GnssFix() = default;
140
141 std::string to_string() const {
142 std::stringstream buf;
143 buf << pos.to_string() << " " << TimeToString(time);
144 return buf.str();
145 }
146
147 Position pos;
148 const time_t time;
149 Quality quality;
150 int satellites_used;
151};
152
153// bitmask defining update validity of BasicNavDataMsg members
154#define POS_UPDATE (int)(1)
155#define COG_UPDATE (int)(1 << 1)
156#define SOG_UPDATE (int)(1 << 2)
157#define VAR_UPDATE (int)(1 << 3)
158#define HDT_UPDATE (int)(1 << 4)
159#define POS_VALID (int)(1 << 5)
160
161class BasicNavDataMsg : public AppMsg {
162public:
163 BasicNavDataMsg(double lat, double lon, double SOG, double COG, double VAR,
164 double HDT, int valid_flag, time_t t)
165 : AppMsg(AppMsg::Type::BasicNavData, "basic-nav-data", NavAddr()),
166 pos(lat, lon),
167 sog(SOG),
168 cog(COG),
169 var(VAR),
170 hdt(HDT),
171 vflag(valid_flag),
172 time(t) {};
173
175 : AppMsg(AppMsg::Type::BasicNavData, "basic-nav-data", NavAddr()),
176 sog(0),
177 cog(0),
178 var(0),
179 hdt(0),
180 vflag(0),
181 time(0),
182 set_time() {};
183
184 virtual ~BasicNavDataMsg() = default;
185
186 const Position pos;
187 const double sog;
188 const double cog;
189 const double var;
190 const double hdt;
191 const int vflag;
192 const time_t time;
193 struct timespec set_time;
194};
195
196class GPSWatchdogMsg : public AppMsg {
197public:
198 enum class WDSource { position, velocity, heading, var, sats };
199
200 GPSWatchdogMsg(WDSource _source, int value)
201 : AppMsg(AppMsg::Type::GPSWatchdog, "gps-watchdog", NavAddr()),
202 gps_watchdog(value),
203 wd_source(_source) {};
204
205 virtual ~GPSWatchdogMsg() = default;
206
207 const int gps_watchdog;
208 const WDSource wd_source;
209};
210
212class AisData : public AppMsg {
213public:
214 time_t time;
215 Position pos;
216 float sog; // Speed over ground, knots.
217 float cog; // Course over ground, 0..360 degrees.
218 float heading; // Magnetic sensor, 0..360 degrees.
219 float rate_of_turn; // Degrees per minute, "-" means bow turns to port.
220 uint8_t type; // https://api.vtexplorer.com/docs/ref-aistypes.html
221 std::string name;
222 std::string callsign;
223 std::string dest; // Destination port
224 int length;
225 int beam;
226 int draft;
227 uint8_t status; // https://api.vtexplorer.com/docs/ref-navstat.html
228};
229
234class CustomMsg : public AppMsg {
235 CustomMsg(const std::string s, std::shared_ptr<const void> ptr)
236 : AppMsg(Type::CustomMsg, "custom", NavAddr()), id(s), payload(ptr) {}
237
238 std::string key() const override {
239 return std::string("@##_appmsg-custom-") + id;
240 }
241
242 const std::string id; // Must be unique.
243 std::shared_ptr<const void> payload;
244};
245
246#endif // APP_MSG_H
AIS data point for a vessel.
A generic message containing a const pointer to basically anything, the pointer neds to be casted to ...
Issued when there are multiple sources providing 'what' with priority == 0.
GPS, Galileo, etc.
Interface implemented by classes which listens.
Definition observable.h:55
Where messages are sent to or received from.
Position()
Construct a (0,0) position, type == Undef.
static Position ParseGGA(const std::string gga)
Parse a GGA string like "5800.588,N,01145.776,E" as present in GGA and other n0183 messages.
std::string to_string() const
Return utf string like 65°25,11N 21°12,01E.
Communication driver layer.