pass log function instead of Logger to avoid dependencies, started decodeMessage for get

This commit is contained in:
john30
2014-12-01 22:14:01 +01:00
parent 3b99ca0b4d
commit 671aa54468
6 changed files with 46 additions and 25 deletions
+18 -12
View File
@@ -57,7 +57,7 @@ BaseLoop::BaseLoop()
const long dumpRawMaxSize = A.getOptVal<long>("dumpsize");
// create Port
m_port = new Port(A.getOptVal<const char*>("device"), A.getOptVal<bool>("nodevicecheck"), logRaw, &L, dumpRaw, dumpRawFile, dumpRawMaxSize);
m_port = new Port(A.getOptVal<const char*>("device"), A.getOptVal<bool>("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<const char*>("address"));
/*string busCommand(A.getOptVal<const char*>("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) {
+14 -2
View File
@@ -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. */
+1
View File
@@ -22,6 +22,7 @@
#include "data.h"
#include "result.h"
#include "symbol.h"
#include "logger.h"
#include "appl.h"
#include <string>
#include <vector>
+4 -5
View File
@@ -30,7 +30,6 @@
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <netdb.h>
#include "logger.h"
#ifdef HAVE_PPOLL
#include <poll.h>
@@ -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);
+8 -4
View File
@@ -26,7 +26,6 @@
#include <unistd.h>
#include <iostream>
#include <fstream>
#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;
+1 -2
View File
@@ -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