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 "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
45class Position {
46public:
47 enum class Type { NE, NW, SE, SW, Undef };
48
50 Position(double _lat, double _lon, Type t);
51
53 Position(double _lat, double _lon);
54
56 Position();
57
58
59 bool IsValid() const { return type != Type::Undef; }
60
62 std::string to_string() const;
63
64 const double lat; // signed value
65 const double lon; // signed value
66 const Type type;
67
73 static Position ParseGGA(const std::string gga);
74
75private:
76 std::string TypeToStr(const Type t) const;
77
79 Type LatLongToType(double lat, double lon);
80
82 double TypeToLat(Type t, double lat);
83
85 double TypeToLong(Type t, double lon);
86
87};
88
90class AppMsg : public KeyProvider {
91public:
92 enum class Type;
93 AppMsg(AppMsg::Type t)
94 : type(t), name(TypeToString(t)), source(NavAddr()), prio(0){};
95
96 virtual std::string key() const { return std::string("@!appmsg-") + name; }
97
98 std::string GetKey() const { return key(); }
99
100 std::string TypeToString(const Type t) const;
101
102 const Type type;
103 const std::string name; // Must be unique, probably using TypeToString().
104 NavAddr source;
105 unsigned short prio; // Initially 0, modified using set_priority
106
107protected:
108 AppMsg(AppMsg::Type tp, const std::string& nm, NavAddr src)
109 : type(tp), name(nm), source(src), prio(0){};
110};
111
112enum class AppMsg::Type {
113 BasicNavData,
114 GPSWatchdog,
115 GnssFix,
116 AisData,
118 CustomMsg,
119 Undef
120};
121
126class DataPrioNeeded : public AppMsg {
127public:
128 AppMsg::Type what;
129 std::vector<NavAddr> sources;
130};
131
133class GnssFix : public AppMsg {
134public:
135 enum class Quality { none, gnss, differential };
136
137 GnssFix(Position p, time_t t, Quality q = Quality::none, int s_used = -1)
138 : AppMsg(AppMsg::Type::GnssFix, "gnss-fix", NavAddr()),
139 pos(p),
140 time(t),
141 quality(q),
142 satellites_used(s_used){};
143 virtual ~GnssFix() = default;
144
145 std::string to_string() const {
146 std::stringstream buf;
147 buf << pos.to_string() << " " << TimeToString(time);
148 return buf.str();
149 }
150
151 Position pos;
152 const time_t time;
153 Quality quality;
154 int satellites_used;
155};
156
161class BasicNavDataMsg : public AppMsg {
162public:
163 BasicNavDataMsg(double lat, double lon, double SOG, double COG, double VAR,
164 double HDT, 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 time(t){};
172
174 : AppMsg(AppMsg::Type::BasicNavData, "basic-nav-data", NavAddr()),
175 sog(0),
176 cog(0),
177 var(0),
178 hdt(0),
179 time(0){};
180
181 virtual ~BasicNavDataMsg() = default;
182
183 const Position pos;
184 const double sog;
185 const double cog;
186 const double var;
187 const double hdt;
188 const time_t time;
189};
190
192class GPSWatchdogMsg : public AppMsg {
193public:
194 enum class WDSource { position, velocity, heading, var, sats };
195
196 GPSWatchdogMsg(WDSource _source, int value)
197 : AppMsg(AppMsg::Type::GPSWatchdog, "gps-watchdog", NavAddr()),
198 gps_watchdog(value),
199 wd_source(_source){};
200
201 virtual ~GPSWatchdogMsg() = default;
202
203 const int gps_watchdog;
204 const WDSource wd_source;
205};
206
208class AisData : public AppMsg {
209public:
210 time_t time;
211 Position pos;
212 float sog; // Speed over ground, knots.
213 float cog; // Course over ground, 0..360 degrees.
214 float heading; // Magnetic sensor, 0..360 degrees.
215 float rate_of_turn; // Degrees per minute, "-" means bow turns to port.
216 uint8_t type; // https://api.vtexplorer.com/docs/ref-aistypes.html
217 std::string name;
218 std::string callsign;
219 std::string dest; // Destination port
220 int length;
221 int beam;
222 int draft;
223 uint8_t status; // https://api.vtexplorer.com/docs/ref-navstat.html
224};
225
230class CustomMsg : public AppMsg {
231 CustomMsg(const std::string s, std::shared_ptr<const void> ptr)
232 : AppMsg(Type::CustomMsg, "custom", NavAddr()), id(s), payload(ptr) {}
233
234 std::string key() const override {
235 return std::string("@##_appmsg-custom-") + id;
236 }
237
238 const std::string id; // Must be unique.
239 std::shared_ptr<const void> payload;
240};
241
242#endif // APP_MSG_H
AIS data point for a vessel.
Definition: comm_appmsg.h:208
Message withg decoded values, available on AppMsgBus.
Definition: comm_appmsg.h:90
std::string GetKey() const
Return key used to listen and notify.
Definition: comm_appmsg.h:98
Global heartbeat message with decoded values for position, speed course, etc.
Definition: comm_appmsg.h:161
A generic message containing a const pointer to basically anything, the pointer neds to be casted to ...
Definition: comm_appmsg.h:230
Issued when there are multiple sources providing 'what' with priority == 0.
Definition: comm_appmsg.h:126
Watchdog message, normally created in CommBridge from wxTimer events.
Definition: comm_appmsg.h:192
GPS, Galileo, etc.
Definition: comm_appmsg.h:133
Interface implemented by classes which listens.
Definition: observable.h:54
Where messages are sent to or received from.
Definition: comm_navmsg.h:136
GNSS Lat/Long container.
Definition: comm_appmsg.h:45
Position()
Construct a (0,0) position, type == Undef.
Definition: comm_appmsg.cpp:77
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.
Definition: comm_appmsg.cpp:79