22 #ifndef _DRIVER_NAVMSG_H
23 #define _DRIVER_NAVMSG_H
33 #include <netinet/in.h>
36 #include "observable.h"
41 N2kPGN(uint64_t _pgn) { pgn = _pgn; }
43 std::string to_string()
const {
61 N2kName(uint64_t name) { value.Name = name; }
63 std::string to_string()
const {
69 static uint64_t Parse(
const std::string& s) {
89 uint32_t UnicNumberAndManCode;
91 unsigned char DeviceInstance;
92 unsigned char DeviceFunction;
93 unsigned char DeviceClass;
94 unsigned char IndustryGroupAndSystemInstance;
100 void SetUniqueNumber(uint32_t _UniqueNumber) {
101 value.UnicNumberAndManCode =
102 (value.UnicNumberAndManCode & 0xffe00000) | (_UniqueNumber & 0x1fffff);
104 void SetManufacturerCode(uint16_t _ManufacturerCode) {
105 value.UnicNumberAndManCode =
106 (value.UnicNumberAndManCode & 0x1fffff) |
107 (((
unsigned long)(_ManufacturerCode & 0x7ff)) << 21);
109 void SetDeviceInstance(
unsigned char _DeviceInstance) {
110 value.DeviceInstance = _DeviceInstance;
112 void SetDeviceFunction(
unsigned char _DeviceFunction) {
113 value.DeviceFunction = _DeviceFunction;
115 void SetDeviceClass(
unsigned char _DeviceClass) {
116 value.DeviceClass = ((_DeviceClass & 0x7f) << 1);
118 void SetIndustryGroup(
unsigned char _IndustryGroup) {
119 value.IndustryGroupAndSystemInstance =
120 (value.IndustryGroupAndSystemInstance & 0x0f) | (_IndustryGroup << 4) |
123 void SetSystemInstance(
unsigned char _SystemInstance) {
124 value.IndustryGroupAndSystemInstance =
125 (value.IndustryGroupAndSystemInstance & 0xf0) |
126 (_SystemInstance & 0x0f);
129 uint64_t GetName()
const {
return value.Name; }
135 enum class Bus { N0183, Signalk, N2000, Onenet,
Plugin, TestBus, Undef };
137 NavAddr(Bus b,
const std::string& i) : bus(b),
iface(i){};
140 std::string to_string()
const {
141 return NavAddr::BusToString(bus) +
" " +
iface;
143 static std::string BusToString(Bus b);
144 static Bus StringToBus(
const std::string& s);
155 std::string to_string()
const {
return iface; }
164 :
NavAddr(NavAddr::Bus::N2000,
iface), name(0), address(_address){};
166 std::string to_string()
const {
return name.to_string(); }
169 unsigned char address;
174 const std::string id;
176 :
NavAddr(NavAddr::Bus::Plugin,
"Plugin"), id(_id) {}
184 std::string to_string()
const {
return NavAddr::to_string(); }
190 :
NavAddr(NavAddr::Bus::TestBus,
"Test"), name(output_path){};
192 const std::string name;
200 virtual std::string key()
const = 0;
202 virtual std::string to_string()
const {
203 return NavAddr::BusToString(bus) +
" " + key();
206 std::string GetKey()
const {
return key(); }
208 const NavAddr::Bus bus;
210 std::shared_ptr<const NavAddr> source;
213 NavMsg(
const NavAddr::Bus& _bus, std::shared_ptr<const NavAddr> src)
214 : bus(_bus), source(src){};
223 :
NavMsg(NavAddr::Bus::N2000, std::make_shared<NavAddr>()), PGN(_pgn) {}
225 Nmea2000Msg(
const uint64_t _pgn, std::shared_ptr<const NavAddr> src)
226 :
NavMsg(NavAddr::Bus::N2000, src), PGN(_pgn) {}
228 Nmea2000Msg(
const uint64_t _pgn,
const std::vector<unsigned char>& _payload,
229 std::shared_ptr<const NavAddr> src)
230 :
NavMsg(NavAddr::Bus::N2000, src), PGN(_pgn), payload(_payload) {}
232 Nmea2000Msg(
const uint64_t _pgn,
const std::vector<unsigned char>& _payload,
233 std::shared_ptr<const NavAddr> src,
int _priority)
234 :
NavMsg(NavAddr::Bus::N2000, src), PGN(_pgn), payload(_payload),
235 priority(_priority) {}
239 std::string key()
const {
return std::string(
"n2000-") + PGN.to_string(); };
245 std::vector<unsigned char> payload;
252 Nmea0183Msg(
const std::string&
id,
const std::string& _payload,
253 std::shared_ptr<const NavAddr> src)
254 :
NavMsg(NavAddr::Bus::N0183, src),
260 :
NavMsg(NavAddr::Bus::Undef, std::make_shared<const NavAddr>()) {}
263 :
Nmea0183Msg(
id.size() <= 3 ? std::string(
"??") +
id :
id,
"",
264 std::make_shared<const NavAddr>()) {}
267 :
NavMsg(NavAddr::Bus::N0183, other.source),
276 std::string to_string()
const {
282 static const char*
const prefix =
"n0183-";
283 return std::string(prefix) +
type;
295 :
NavMsg(NavAddr::Bus::Undef, std::make_shared<const NavAddr>()) {}
297 PluginMsg(
const std::string& _name,
const std::string& _dest_host,
298 const std::string& msg)
299 :
NavMsg(NavAddr::Bus::Plugin,
300 std::make_shared<const NavAddr>(NavAddr::Bus::Plugin,
"")),
305 PluginMsg(
const std::string& _name,
const std::string& msg)
310 const std::string name;
311 const std::string message;
314 std::string key()
const {
return std::string(
"plug.json-") + name; };
322 :
NavMsg(NavAddr::Bus::Undef, std::make_shared<const NavAddr>()) {}
324 SignalkMsg(std::string _context_self, std::string _context,
325 std::string _raw_message, std::string _iface)
326 :
NavMsg(NavAddr::Bus::Signalk,
327 std::make_shared<const NavAddr>(NavAddr::Bus::Signalk, _iface)),
328 context_self(_context_self),
330 raw_message(_raw_message){};
336 std::string context_self;
338 std::string raw_message;
340 std::string key()
const {
return std::string(
"signalK"); };
347 :
NavMsg(NavAddr::Bus::Undef, std::make_shared<const NavAddr>()) {}
351 std::string key()
const {
return "navmsg-undef"; }
Interface implemented by classes which listens.
Where messages are sent to or received from.
const std::string iface
Physical device for 0183, else a unique string.
Actual data sent between application and transport layer.
A regular Nmea0183 message.
const std::string type
For example 'GGA'.
const std::string talker
For example 'GP'.
const std::string payload
Complete NMEA0183 sentence, also prefix.
static std::string MessageKey(const char *type="ALL")
Return key which should be used to listen to given message type.
See: https://github.com/OpenCPN/OpenCPN/issues/2729#issuecomment-1179506343.
std::string to_string() const
Print "bus key id payload".
An invalid message, error return value.
A plugin to plugin json message over the REST interface.
const std::string dest_host
hostname, ip address or 'localhost'
Plugin ABI encapsulation.
A parsed SignalK message over ipv4.
N2k uses CAN which defines the basic properties of messages.
uint32_t GetNumber() const
21 bits
uint16_t GetManufacturer() const
9 bits
uint8_t GetDevClass() const
7 bits
uint8_t GetDevFunc() const
8 bits
uint8_t GetIndustryGroup() const
4 bits
uint8_t GetDevInstanceHigh() const
5 bits
uint8_t GetDevInstanceLow() const
3 bits
uint8_t GetSysInstance() const
4 bits