diff --git a/src/ebusd/baseloop.cpp b/src/ebusd/baseloop.cpp index 715b8221..afd2b94e 100644 --- a/src/ebusd/baseloop.cpp +++ b/src/ebusd/baseloop.cpp @@ -57,7 +57,7 @@ BaseLoop::BaseLoop() const long dumpRawMaxSize = A.getOptVal("dumpsize"); // create Port - m_port = new Port(A.getOptVal("device"), A.getOptVal("nodevicecheck"), logRaw, &L, dumpRaw, dumpRawFile, dumpRawMaxSize); + m_port = new Port(A.getOptVal("device"), A.getOptVal("nodevicecheck"), logRaw, &BaseLoop::logRaw, dumpRaw, dumpRawFile, dumpRawMaxSize); m_port->open(); if (m_port->isOpen() == false) @@ -164,6 +164,10 @@ void BaseLoop::start() } } +void BaseLoop::logRaw(const unsigned char byte) { + L.log(bus, event, "%02x", byte); +} + string BaseLoop::decodeMessage(const string& data) { ostringstream result; @@ -186,18 +190,20 @@ string BaseLoop::decodeMessage(const string& data) result << "command not found"; break; - /*case ct_get: - if (cmd.size() < 3 || cmd.size() > 4) { - result << "usage: 'get class cmd (sub)'"; + case ct_get: + if (cmd.size() < 2 || cmd.size() > 4) { + result << "usage: 'get [class] cmd' or 'get class cmd sub'"; break; } - message = m_messages->find(cmd[1], cmd[2], true, false); + if (cmd.size() == 2) + message = m_messages->find("", cmd[1], false); + else + message = m_messages->find(cmd[1], cmd[2], false); if (message != NULL) { - // polling data - if (strcasecmp(m_commands->getCmdType(index).c_str(), "P") == 0) { + /*if (message->getPollPriority() > 0) // get polldata polldata = m_commands->getPollData(index); if (polldata != "") { @@ -213,12 +219,12 @@ string BaseLoop::decodeMessage(const string& data) } break; - } + }*/ - string busCommand(A.getOptVal("address")); + /*string busCommand(A.getOptVal("address")); busCommand += m_commands->getBusCommand(index); transform(busCommand.begin(), busCommand.end(), busCommand.begin(), ::tolower); - + m_busHandler-> BusMessage* message = new BusMessage(busCommand, false, false); L.log(bas, trace, " msg: %s", busCommand.c_str()); // send message @@ -238,13 +244,13 @@ string BaseLoop::decodeMessage(const string& data) result << message->getResultCodeCStr(); } - delete message; + delete message;*/ } else { result << "ebus command not found"; } - break;*/ + break; /*case ct_set: if (cmd.size() != 4) { diff --git a/src/ebusd/baseloop.h b/src/ebusd/baseloop.h index b058130a..c6aab310 100644 --- a/src/ebusd/baseloop.h +++ b/src/ebusd/baseloop.h @@ -51,16 +51,22 @@ class BaseLoop public: /** - * @brief construct the baseloop and creates messaging, network and busloop subsystems. + * @brief Construct the base loop and create messaging, network and bus handling subsystems. */ BaseLoop(); /** - * @brief destructor. + * @brief Destructor. */ ~BaseLoop(); + /** + * @brief Read the configuration files from the specified path. + * @param path the path from which to read the files. + * @param extension the filename extension of the files to read. + */ result_t readConfigFiles(const string path, const string extension); + /** * @brief start baseloop instance. */ @@ -72,6 +78,12 @@ public: */ void addMessage(NetMessage* message) { m_netQueue.add(message); } + /** + * @brief Create a log message for a retrieved raw data byte. + * @param param byte the retrieved raw data byte. + */ + static void logRaw(const unsigned char byte); + private: /** the @a DataFieldTemplates instance. */ diff --git a/src/ebusd/bushandler.cpp b/src/ebusd/bushandler.cpp index 5e1d06ad..5c527cb5 100644 --- a/src/ebusd/bushandler.cpp +++ b/src/ebusd/bushandler.cpp @@ -22,6 +22,7 @@ #include "data.h" #include "result.h" #include "symbol.h" +#include "logger.h" #include "appl.h" #include #include diff --git a/src/lib/ebus/port.cpp b/src/lib/ebus/port.cpp index f5b052fc..08defe83 100644 --- a/src/lib/ebus/port.cpp +++ b/src/lib/ebus/port.cpp @@ -30,7 +30,6 @@ #include #include #include -#include "logger.h" #ifdef HAVE_PPOLL #include @@ -252,10 +251,10 @@ void DeviceNetwork::closeDevice() } -Port::Port(const string deviceName, const bool noDeviceCheck, const bool logRaw, Logger* loggerRaw, +Port::Port(const string deviceName, const bool noDeviceCheck, const bool logRaw, void (*logRawFunc)(const unsigned char byte), const bool dumpRaw, const char* dumpRawFile, const long dumpRawMaxSize) : m_deviceName(deviceName), m_noDeviceCheck(noDeviceCheck), - m_logRaw(logRaw), m_loggerRaw(loggerRaw), + m_logRaw(logRaw), m_logRawFunc(logRawFunc), m_dumpRawFile(dumpRawFile), m_dumpRawMaxSize(dumpRawMaxSize) { m_device = NULL; @@ -275,8 +274,8 @@ unsigned char Port::byte() { unsigned char byte = m_device->getByte(); - if (m_logRaw == true && m_loggerRaw != NULL) - m_loggerRaw->log(bus, event, "%02x", byte); + if (m_logRaw == true && m_logRawFunc != NULL) + (*m_logRawFunc)(byte); if (m_dumpRaw == true && m_dumpRawStream.is_open() == true) { m_dumpRawStream.write((char*)&byte, 1); diff --git a/src/lib/ebus/port.h b/src/lib/ebus/port.h index 9b833894..124dd147 100644 --- a/src/lib/ebus/port.h +++ b/src/lib/ebus/port.h @@ -26,7 +26,6 @@ #include #include #include -#include "logger.h" #include "result.h" using namespace std; @@ -203,8 +202,13 @@ public: * @brief constructs a new instance and determine device type. * @param deviceName to determine device type. * @param noDeviceCheck en-/disable device check. + * @param logRaw whether logging of raw data is enabled. + * @param logRawFunc a function to call for logging raw data, or NULL. + * @param dumpRaw whether dumping of raw data to a file is enabled. + * @param dumpRawFile the name of the file to dump raw data to. + * @param dumpRawMaxSize the maximum size of @a m_dumpFile. */ - Port(const string deviceName, const bool noDeviceCheck, const bool logRaw, Logger* loggerRaw, + Port(const string deviceName, const bool noDeviceCheck, const bool logRaw, void (*logRawFunc)(const unsigned char byte), const bool dumpRaw, const char* dumpRawFile, const long dumpRawMaxSize); /** @@ -307,8 +311,8 @@ private: /** whether logging of raw data is enabled. */ bool m_logRaw; - /** the @a Logger used for logging of raw data, or NULL. */ - Logger* m_loggerRaw; + /** a function to call for logging raw data, or NULL. */ + void (*m_logRawFunc)(const unsigned char byte); /** whether dumping of raw data to a file is enabled. */ bool m_dumpRaw; diff --git a/src/lib/ebus/test/Makefile.am b/src/lib/ebus/test/Makefile.am index 4570f354..ac8369f7 100755 --- a/src/lib/ebus/test/Makefile.am +++ b/src/lib/ebus/test/Makefile.am @@ -10,8 +10,7 @@ noinst_PROGRAMS = test_port \ test_message test_port_SOURCES = test_port.cpp -test_port_LDADD = $(top_srcdir)/src/lib/utils/libutils.a \ - $(top_srcdir)/src/lib/ebus/libebus.a +test_port_LDADD = $(top_srcdir)/src/lib/ebus/libebus.a test_symbol_SOURCES = test_symbol.cpp test_symbol_LDADD = $(top_srcdir)/src/lib/ebus/libebus.a