diff --git a/ChangeLog b/ChangeLog index 99b0b980..9b71cbac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ ebusd - ChangeLog ----------------- +2014-10-06 Roland Jax +* class CYCData deleted; functionality is moved into libebus. + 2014-10-03 Roland Jax * class Logger: minor name changes. * class CYCData: delCommands fixed. diff --git a/Makefile.am b/Makefile.am index 94473ffb..1220e389 100644 --- a/Makefile.am +++ b/Makefile.am @@ -15,7 +15,6 @@ ebusd_SOURCES = lib/appl.cpp \ src/connection.cpp \ src/network.cpp \ src/ebusloop.cpp \ - src/cycdata.cpp \ src/baseloop.cpp \ src/main.cpp diff --git a/README b/README index 16b25948..cc0a85ff 100644 --- a/README +++ b/README @@ -13,16 +13,18 @@ Features - collect data of cycle messages * tcp socket multi session server (daemon commands) - - get fetch data from ebus participant - - set adjust data of ebus participant - - cyc fetch data from collected cycle messages - - hex send given hex value to ebus (ZZ PB SB NN Dx) - - dump toggle dump on/off - - logarea change log area - - loglevel change log level - - stop stop daemon - - quit close connection - - help print help page + - get fetch data from ebus participant + - set adjust data of ebus participant + - cyc fetch data from collected cycle messages + - hex send given hex value to ebus (ZZ PB SB NN Dx) + - dump toggle dump on/off + - log areas change log areas + - log level change log level + - config list not implemented yes + - config reload reload ebus configuration + - stop stop daemon + - quit close connection + - help print help page Dependency diff --git a/lib/logger.cpp b/lib/logger.cpp index 155a7edc..9319b1a5 100644 --- a/lib/logger.cpp +++ b/lib/logger.cpp @@ -28,7 +28,7 @@ #include #include -static const char* AreaNames[Size_of_Areas] = { "bas", "net", "bus", "cyc" }; +static const char* AreaNames[Size_of_Areas] = { "bas", "net", "bus", }; static const char* LevelNames[Size_of_Level] = { "error", "event", "trace", "debug" }; int calcAreas(const std::string areas) @@ -232,6 +232,5 @@ void* LogInstance::run() void LogInstance::stop() { m_messages.add(new LogMessage(LogMessage(bas, error, "", LogMessage::End))); - // TODO: Improve this method usleep(100000); } diff --git a/lib/logger.h b/lib/logger.h index 91dd5485..94af4e93 100644 --- a/lib/logger.h +++ b/lib/logger.h @@ -28,7 +28,7 @@ #include #include -enum Areas { bas=1, net=2, bus=4, cyc=8, all=15, Size_of_Areas=4 }; +enum Areas { bas=1, net=2, bus=4, all=7, Size_of_Areas=3 }; enum Level { error=0, event, trace, debug, Size_of_Level }; int calcAreas(const std::string areas); diff --git a/src/baseloop.cpp b/src/baseloop.cpp index 6d7cf104..80888ac9 100644 --- a/src/baseloop.cpp +++ b/src/baseloop.cpp @@ -29,16 +29,13 @@ BaseLoop::BaseLoop() // create Commands DB m_commands = ConfigCommands(A.getParam("p_ebusconfdir"), CSV).getCommands(); L.log(bas, debug, "ebus configuration dir: %s", A.getParam("p_ebusconfdir")); - L.log(bas, event, "commands DB with %d entries created", m_commands->size()); + L.log(bas, event, "commands DB with %d entries created", m_commands->sizeCmd()); + L.log(bas, event, " data DB with %d entries created", m_commands->sizeData()); // create EBusLoop - m_ebusloop = new EBusLoop(); + m_ebusloop = new EBusLoop(m_commands); m_ebusloop->start("ebusloop"); - // create CYCData - m_cycdata = new CYCData(m_ebusloop, m_commands); - m_cycdata->start("cycdata"); - // create Network m_network = new Network(A.getParam("p_localhost")); m_network->addQueue(&m_queue); @@ -51,12 +48,6 @@ BaseLoop::~BaseLoop() if (m_network != NULL) delete m_network; - // free CYCData - if (m_cycdata != NULL) { - m_cycdata->stop(); - delete m_cycdata; - } - // free EBusLoop if (m_ebusloop != NULL) { m_ebusloop->stop(); @@ -232,7 +223,7 @@ std::string BaseLoop::decodeMessage(const std::string& data) if (index >= 0) { // get cycdata - cycdata = m_cycdata->getData(index); + cycdata = m_commands->getData(index); if (cycdata != "") { // decode data Command* command = new Command(index, (*m_commands)[index], cycdata); @@ -329,22 +320,21 @@ std::string BaseLoop::decodeMessage(const std::string& data) // ToDo: ... if (strcasecmp(cmd[1].c_str(), "list") == 0) { - result << "done"; + result << "not implemented yet"; break; } if (strcasecmp(cmd[1].c_str(), "reload") == 0) { - m_cycdata->delCommands(); delete m_commands; // create Commands DB m_commands = ConfigCommands(A.getParam("p_ebusconfdir"), CSV).getCommands(); L.log(bas, debug, "ebus configuration dir: %s", A.getParam("p_ebusconfdir")); - L.log(bas, event, "commands DB with %d entries created", m_commands->size()); + L.log(bas, event, "commands DB with %d entries created", m_commands->sizeCmd()); + L.log(bas, event, " data DB with %d entries created", m_commands->sizeData()); - // add commands to cycDB - m_cycdata->addCommands(m_commands); + m_ebusloop->newCommands(m_commands); result << "done"; break; @@ -359,8 +349,8 @@ std::string BaseLoop::decodeMessage(const std::string& data) << " get - fetch ebus data 'get class cmd (sub)'" << std::endl << " set - set ebus values 'set class cmd value'" << std::endl << " cyc - fetch cycle data 'cyc class cmd (sub)'" << std::endl - << " hex - send given hex value 'hex type value' (value: ZZPBSBNNDx)" << std::endl << std::endl - << " dump - change dump state 'dump state' (state: on|off)" << std::endl << std::endl + << " hex - send given hex value 'hex type value' (value: ZZPBSBNNDx)" << std::endl << std::endl + << " dump - change dump state 'dump state' (state: on|off)" << std::endl << std::endl << " log - change log areas 'log areas area,area,..' (areas: bas|net|bus|cyc|all)" << std::endl << " - change log level 'log level level' (level: error|event|trace|debug)" << std::endl << std::endl << " config - list ebus configuration 'config list'" << std::endl diff --git a/src/baseloop.h b/src/baseloop.h index 4b40bfec..52316681 100644 --- a/src/baseloop.h +++ b/src/baseloop.h @@ -23,7 +23,6 @@ #include "libebus.h" #include "network.h" #include "ebusloop.h" -#include "cycdata.h" using namespace libebus; @@ -41,7 +40,6 @@ public: private: Commands* m_commands; - CYCData* m_cycdata; EBusLoop* m_ebusloop; Network* m_network; diff --git a/src/cycdata.cpp b/src/cycdata.cpp deleted file mode 100644 index 8ba74214..00000000 --- a/src/cycdata.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) Roland Jax 2012-2014 - * - * This file is part of ebusd. - * - * ebusd is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ebusd is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ebusd. If not, see http://www.gnu.org/licenses/. - */ - -#include "cycdata.h" -#include "logger.h" -#include - -extern LogInstance& L; - -void* CYCData::run() -{ - bool skipfirst = false; - - for (;;) { - std::string data = m_ebusloop->getData(); - - if (skipfirst == true) { - L.log(cyc, trace, "%s", data.c_str()); - - int index = findData(data); - - if (index >= 0) { - std::string tmp; - tmp += (*m_commands)[index][0]; - tmp += " "; - tmp += (*m_commands)[index][1]; - tmp += " "; - tmp += (*m_commands)[index][2]; - L.log(cyc, event, " [%d] %s", index, tmp.c_str()); - storeData(index, data); - } - } - - skipfirst = true; - - if (m_stop == true) - return NULL; - } - - return NULL; -} - -std::string CYCData::getData(int index) -{ - mapCI_t iter = m_cycDB.find(index); - if (iter != m_cycDB.end()) - return iter->second->getData(); - else - return ""; -} - -int CYCData::findData(const std::string& data) const -{ - // no commands defined - if (m_cycDB.size() == 0) { - L.log(cyc, debug, " no commands defined"); - return -2; - } - - // search skipped - string too short - if (data.length() < 10) { - L.log(cyc, debug, " search skipped - string too short"); - return -3; - } - - // prepare string for searching command - std::string search(data.substr(2, 8 + strtol(data.substr(8,2).c_str(), NULL, 16) * 2)); - - std::size_t index; - mapCI_t i = m_cycDB.begin(); - - // walk through commands - for (index = 0; i != m_cycDB.end(); i++, index++) { - cmd_t cmd = i->second->getCommand(); - // prepare string for defined command - std::string command(cmd[5]); - command += cmd[6]; - std::stringstream sstr; - sstr << std::setw(2) << std::hex << std::setfill('0') << cmd[7]; - command += sstr.str(); - command += cmd[8]; - - // skip wrong search string length - if (command.length() > search.length()) - continue; - - if (strcasecmp(command.c_str(), search.substr(0,command.length()).c_str()) == 0) - return i->first; - - } - - // command not found - L.log(cyc, debug, " command not found"); - return -1; -} - -void CYCData::storeData(int index, std::string data) -{ - mapCI_t iter = m_cycDB.find(index); - - if (iter != m_cycDB.end()) { - iter->second->setData(data); - L.log(cyc, debug, " [%d] data saved", index); - } -} - -void CYCData::addCommands(Commands* commands) -{ - m_commands = commands; - - for (size_t index = 0; index < commands->size(); index++) { - if (strcasecmp((*m_commands)[index][0].c_str(),"cyc") == 0) { - Command* cmd = new Command(index, (*m_commands)[index]); - m_cycDB.insert(pair_t(index, cmd)); - } - } - - L.log(cyc, trace, "%d cycle commands added", m_cycDB.size()); -} - -void CYCData::delCommands() -{ - for (mapCI_t iter = m_cycDB.begin(); iter != m_cycDB.end(); ++iter) - delete iter->second; - - m_cycDB.clear(); -} - diff --git a/src/cycdata.h b/src/cycdata.h deleted file mode 100644 index 19c8ff64..00000000 --- a/src/cycdata.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) Roland Jax 2012-2014 - * - * This file is part of ebusd. - * - * ebusd is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ebusd is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ebusd. If not, see http://www.gnu.org/licenses/. - */ - -#ifndef CYCDATA_H_ -#define CYCDATA_H_ - -#include "libebus.h" -#include "ebusloop.h" -#include - -using namespace libebus; - - -typedef std::map map_t; -typedef map_t::const_iterator mapCI_t; -typedef std::pair pair_t; - -class CYCData : public Thread -{ - -public: - CYCData(EBusLoop* ebusloop, Commands* commands) - : m_ebusloop(ebusloop), m_stop(false) - { addCommands(commands); } - ~CYCData() { delCommands(); } - - void* run(); - void stop() { m_stop = true; } - - std::string getData(int index); - - void addCommands(Commands* commands); - void delCommands(); - -private: - EBusLoop* m_ebusloop; - Commands* m_commands; - map_t m_cycDB; - bool m_stop; - - int findData(const std::string& data) const; - void storeData(int index, std::string data); - -}; - -#endif // CYCDATA_H_ diff --git a/src/ebusloop.cpp b/src/ebusloop.cpp index 914bf62e..3698daf7 100644 --- a/src/ebusloop.cpp +++ b/src/ebusloop.cpp @@ -24,7 +24,7 @@ extern LogInstance& L; extern Appl& A; -EBusLoop::EBusLoop() : m_stop(false) +EBusLoop::EBusLoop(Commands* commands) : m_commands(commands), m_stop(false) { m_deviceName = A.getParam("p_device"); @@ -68,8 +68,29 @@ void* EBusLoop::run() // new cyc message arrived if (busResult == 2) { std::string data = m_bus->getCycData(); - L.log(bus, debug, "%s", data.c_str()); - m_cycBuffer.add(data); + L.log(bus, trace, "%s", data.c_str()); + + int index = m_commands->storeData(data); + + if (index == -1) { + L.log(bus, debug, " command not found"); + + } else if (index == -2) { + L.log(bus, debug, " no commands defined"); + + } else if (index == -3) { + L.log(bus, debug, " search skipped - string too short"); + + } else { + std::string tmp; + tmp += (*m_commands)[index][0]; + tmp += " "; + tmp += (*m_commands)[index][1]; + tmp += " "; + tmp += (*m_commands)[index][2]; + L.log(bus, event, " [%d] %s", index, tmp.c_str()); + } + } // add new bus command to send diff --git a/src/ebusloop.h b/src/ebusloop.h index 44efc05c..fcc1980b 100644 --- a/src/ebusloop.h +++ b/src/ebusloop.h @@ -31,23 +31,23 @@ class EBusLoop : public Thread { public: - EBusLoop(); + EBusLoop(Commands* commands); ~EBusLoop(); void* run(); void stop() { m_stop = true; } - std::string getData() { return m_cycBuffer.remove(); } - void addBusCommand(BusCommand* busCommand) { m_sendBuffer.add(busCommand); } BusCommand* getBusCommand() { return m_recvBuffer.remove(); } void dump(const bool dumpState) { m_bus->setDumpState(dumpState); } + void newCommands(Commands* commands) { m_commands = commands; } + private: + Commands* m_commands; std::string m_deviceName; Bus* m_bus; - WQueue m_cycBuffer; bool m_stop; WQueue m_sendBuffer; WQueue m_recvBuffer;