26#ifndef _DRIVER_NAVMSG_H
27#define _DRIVER_NAVMSG_H
35#include <netinet/in.h>
38#include "observable.h"
44 N2kPGN(uint64_t _pgn) { pgn = _pgn; }
46 std::string to_string()
const {
64 N2kName(uint64_t name) { value.Name = name; }
66 std::string to_string()
const {
72 static uint64_t Parse(
const std::string& s) {
92 uint32_t UnicNumberAndManCode;
94 unsigned char DeviceInstance;
95 unsigned char DeviceFunction;
96 unsigned char DeviceClass;
97 unsigned char IndustryGroupAndSystemInstance;
103 void SetUniqueNumber(uint32_t _UniqueNumber) {
104 value.UnicNumberAndManCode =
105 (value.UnicNumberAndManCode & 0xffe00000) | (_UniqueNumber & 0x1fffff);
107 void SetManufacturerCode(uint16_t _ManufacturerCode) {
108 value.UnicNumberAndManCode =
109 (value.UnicNumberAndManCode & 0x1fffff) |
110 (((
unsigned long)(_ManufacturerCode & 0x7ff)) << 21);
112 void SetDeviceInstance(
unsigned char _DeviceInstance) {
113 value.DeviceInstance = _DeviceInstance;
115 void SetDeviceFunction(
unsigned char _DeviceFunction) {
116 value.DeviceFunction = _DeviceFunction;
118 void SetDeviceClass(
unsigned char _DeviceClass) {
119 value.DeviceClass = ((_DeviceClass & 0x7f) << 1);
121 void SetIndustryGroup(
unsigned char _IndustryGroup) {
122 value.IndustryGroupAndSystemInstance =
123 (value.IndustryGroupAndSystemInstance & 0x0f) | (_IndustryGroup << 4) |
126 void SetSystemInstance(
unsigned char _SystemInstance) {
127 value.IndustryGroupAndSystemInstance =
128 (value.IndustryGroupAndSystemInstance & 0xf0) |
129 (_SystemInstance & 0x0f);
132 uint64_t GetName()
const {
return value.Name; }
138 enum class Bus { N0183, Signalk, N2000, Onenet, TestBus, Undef };
140 NavAddr(Bus b,
const std::string& i) : bus(b),
iface(i){};
143 std::string to_string()
const {
144 return NavAddr::BusToString(bus) +
" " +
iface;
146 static std::string BusToString(Bus b);
147 static Bus StringToBus(
const std::string& s);
159 std::string to_string()
const {
return iface; }
169 :
NavAddr(NavAddr::Bus::N2000,
iface), name(0), address(_address){};
171 std::string to_string()
const {
return name.to_string(); }
174 unsigned char address;
187 :
NavAddr(NavAddr::Bus::TestBus,
"Test"), name(output_path){};
189 const std::string name;
197 virtual std::string key()
const = 0;
199 virtual std::string to_string()
const {
200 return NavAddr::BusToString(bus) +
" " + key();
203 std::string
GetKey()
const {
return key(); }
205 const NavAddr::Bus bus;
207 std::shared_ptr<const NavAddr> source;
210 NavMsg(
const NavAddr::Bus& _bus, std::shared_ptr<const NavAddr> src)
211 : bus(_bus), source(src){};
220 :
NavMsg(NavAddr::Bus::N2000, std::make_shared<NavAddr>()), PGN(_pgn) {}
222 Nmea2000Msg(
const uint64_t _pgn, std::shared_ptr<const NavAddr> src)
223 :
NavMsg(NavAddr::Bus::N2000, src), PGN(_pgn) {}
225 Nmea2000Msg(
const uint64_t _pgn,
const std::vector<unsigned char>& _payload,
226 std::shared_ptr<const NavAddr> src)
227 :
NavMsg(NavAddr::Bus::N2000, src), PGN(_pgn), payload(_payload) {}
231 std::string key()
const {
return std::string(
"n2000-") + PGN.to_string(); };
237 std::vector<unsigned char> payload;
243 Nmea0183Msg(
const std::string&
id,
const std::string& _payload,
244 std::shared_ptr<const NavAddr> src)
245 :
NavMsg(NavAddr::Bus::N0183, src),
251 :
NavMsg(NavAddr::Bus::Undef, std::make_shared<const NavAddr>()) {}
254 :
Nmea0183Msg(
id.size() <= 3 ? std::string(
"??") +
id :
id,
"",
255 std::make_shared<const NavAddr>()) {}
258 :
NavMsg(NavAddr::Bus::N0183, other.source),
267 std::string to_string()
const {
273 static const char*
const prefix =
"n0183-";
274 return std::string(prefix) +
type;
286 :
NavMsg(NavAddr::Bus::Undef, std::make_shared<const NavAddr>()) {}
288 SignalkMsg(std::string _context_self, std::string _context,
289 std::string _raw_message)
290 :
NavMsg(NavAddr::Bus::Signalk,
291 std::make_shared<const NavAddr>(NavAddr::Bus::Signalk,
"")),
292 context_self(_context_self),
294 raw_message(_raw_message){};
300 std::string context_self;
302 std::string raw_message;
304 std::vector<std::string> errors;
305 std::vector<std::string> warnings;
306 std::string key()
const {
return std::string(
"signalK"); };
313 :
NavMsg(NavAddr::Bus::Undef, std::make_shared<const NavAddr>()) {}
317 std::string key()
const {
return "navmsg-undef"; }
Interface implemented by classes which listens.
NMEA0183 sent/received address, an interface.
NMEA2000 sent/received address, an address (possibly wildcard)
There is only support for a single signalK bus.
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.
std::string GetKey() const
Return key used to listen and notify.
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 parsed, raw SignalK message.
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
NMEA2000 message discriminator.