46 virtual void Notify(std::shared_ptr<const NavMsg> message) {}
52static vector<unsigned char> HexToChar(
string hex) {
53 if (hex.size() % 2 == 1) hex = string(
"0") + hex;
54 vector<unsigned char> chars;
55 for (
size_t i = 0; i < hex.size(); i += 2) {
56 istringstream ss(hex.substr(i, 2));
58 ss >> std::hex >> ival;
59 chars.push_back(
static_cast<unsigned char>(ival));
64static shared_ptr<const NavMsg> LineToMessage(
const string& line,
65 std::shared_ptr<NavAddr> src) {
67 NavAddr::Bus bus = NavAddr::StringToBus(words[0]);
69 case NavAddr::Bus::N2000:
71 N2kName name(N2kName::Parse(words[2]));
72 vector<unsigned char> payload(HexToChar(words[3]));
75 return make_shared<NullNavMsg>();
78 case NavAddr::Bus::N0183:
80 const string id(words[2]);
81 return make_shared<Nmea0183Msg>(
id, words[3], src);
85 std::cerr <<
"Cannot parse line: \"" << line <<
"\"\n" << flush;
86 return make_shared<NullNavMsg>();
89 return make_shared<NullNavMsg>();
98 if (input_path !=
"") {
99 ifstream f(input_path);
101 while (getline(f, line)) {
102 auto msg = LineToMessage(line, GetAddress());
103 if (msg->bus != NavAddr::Bus::Undef) listener.Notify(msg);
111std::shared_ptr<NavAddr> FileCommDriver::GetAddress() {
112 return std::make_shared<NavAddr>(
NavAddrTest(output_path));
115bool FileCommDriver::SendMessage(std::shared_ptr<const NavMsg> msg,
116 std::shared_ptr<const NavAddr> addr) {
118 f.open(output_path, ios::app);
120 wxLogWarning(
"Cannot open file %s for writing", output_path.c_str());
123 f << msg->to_string();
Common interface for all drivers.
Interface for handling incoming messages.
Read and write data to/from files test driver
FileCommDriver(const std::string &opath, const std::string &ipath, DriverListener &l)
An instance which can write to file and play data from another.
Where messages are sent to or received from.
Communication driver layer.
Test driver which reads and writes data to/from files.
Driver registration container, a singleton.
std::vector< std::string > split(const char *token_string, const std::string &delimiter)
Return vector of items in s separated by delimiter.
Miscellaneous utilities, many of which string related.
N2k uses CAN which defines the basic properties of messages.