37#include <wx/jsonreader.h> 
   47using NavMsgPtr = shared_ptr<const NavMsg>;
 
   49static string NextWord(std::string& line) {
 
   50  if (line.empty()) 
return "";
 
   51  size_t space_pos = line.find(
" ");
 
   52  if (space_pos == string::npos) space_pos = line.size();
 
   53  string word(line.substr(0, space_pos));
 
   58static unsigned HexNibbleValue(
char c) {
 
   60  if (c >= 
'0' && c <= 
'9') 
return c - 
'0';
 
   61  if (c >= 
'a' && c <= 
'f') 
return 10 + c - 
'a';
 
   65static unsigned char HexByteValue(
const string& text) {
 
   67  if (text.size() == 1) {
 
   68    value = HexNibbleValue(text[0]);
 
   70    value = 16 * HexNibbleValue(text[0]) + HexNibbleValue(text[1]);
 
   72  return static_cast<unsigned char>(value);
 
   75static NavMsgPtr Parse2000(
const std::string& iface, 
const string& type,
 
   76                           const std::string& msg) {
 
   77  vector<unsigned char> payload;
 
   79  for (
const auto& 
byte : hexbytes) payload.push_back(HexByteValue(byte));
 
   83  } 
catch (invalid_argument&) {
 
   86  return make_shared<Nmea2000Msg>(
 
   87      pgn, payload, make_shared<NavAddr2000>(iface, 
N2kName(pgn)));
 
   90static NavMsgPtr Parse0183(
const string& iface, 
const string& type,
 
   92  return make_shared<Nmea0183Msg>(type, msg, make_shared<NavAddr0183>(iface));
 
   95static NavMsgPtr ParseSignalk(
const string& iface, 
const string& type,
 
   99  int err_count = reader.
Parse(msg, &root);
 
  101  if (err_count == 0) {
 
  104  return make_shared<SignalkMsg>(type, context, msg, iface);
 
  108  int space_count = count(msg.begin(), msg.end(), 
' ');
 
  109  if (space_count < 3) {
 
  112  std::string msg_(msg);
 
  114  auto iface = NextWord(msg_);
 
  115  auto type = NextWord(msg_);
 
  117  if (protocol == 
"nmea2000") 
return Parse2000(
iface, type, msg_);
 
  118  if (protocol == 
"nmea0183") 
return Parse0183(
iface, type, msg_);
 
  119  if (protocol == 
"signalk") 
return ParseSignalk(
iface, type, msg_);
 
 
const std::string iface
Physical device for 0183, else a unique string.
static std::shared_ptr< const NavMsg > ParsePluginMessage(const std::string &msg)
Parse a string as provided by plugin and convert to a navmsg.
int Parse(const wxString &doc, wxJSONValue *val)
Parse the JSON document.
The JSON value class implementation.
bool HasMember(unsigned index) const
Return TRUE if the object contains an element at the specified index.
wxString AsString() const
Return the stored value as a wxWidget's string.
Loopback driver, treat sent messages as received.
Raw, undecoded messages definitions.
std::string tolower(const std::string &input)
Return copy of s with all characters converted to lower case.
std::vector< std::string > split(const char *token_string, const std::string &delimiter)
Return vector of items in s separated by delimiter.
std::string ltrim(const std::string &arg)
Strip possibly leading space characters in s.
Miscellaneous utilities, many of which string related.
N2k uses CAN which defines the basic properties of messages.