Merge branch 'master' of git://github.com/yuhu-/ebusd

This commit is contained in:
john30
2014-11-22 10:08:42 +01:00
19 changed files with 2547 additions and 77 deletions
+3
View File
@@ -23,3 +23,6 @@ Makefile.in
/src/lib/ebus/test/test_encode
/src/lib/ebus/test/test_symbol
/src/lib/ebus/test/test_data
/docs/Doxyfile
/docs/doxyfile.stamp
/docs/html
+6 -1
View File
@@ -1,4 +1,9 @@
SUBDIRS = src/lib/utils src/lib/ebus src/lib/ebus/test src/ebusd src/ebusctl
SUBDIRS = docs \
src/lib/utils \
src/lib/ebus \
src/lib/ebus/test \
src/ebusd \
src/ebusctl
distclean-local:
-rm -rf autom4te.cache
+15 -2
View File
@@ -10,22 +10,35 @@ AC_CHECK_HEADERS([arpa/inet.h \
poll.h \
pthread.h \
sys/ioctl.h \
sys/select.h \
termios.h])
AC_CHECK_LIB([pthread], [pthread_setname_np],
AC_DEFINE([HAVE_PTHREAD_SETNAME_NP], [1], ["Define to 1 if pthread has pthread_setname_np"]),
AC_MSG_RESULT([Could not find pthread_setname_np in pthread]))
AC_DEFINE([HAVE_PTHREAD_SETNAME_NP], [1], ["Define to 1 if pthread has pthread_setname_np."]),
AC_MSG_RESULT([Could not find pthread_setname_np in pthread.]))
AC_CHECK_FUNC([pselect], [AC_DEFINE(HAVE_PSELECT, [1], [Define to 1 if pselect() is available.])])
AC_CHECK_FUNC([ppoll], [AC_DEFINE(HAVE_PPOLL, [1], [Define to 1 if ppoll() is available.])])
AC_CONFIG_AUX_DIR([build])
AC_CONFIG_SRCDIR([src/ebusd/ebusd.cpp])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile
docs/Makefile
src/lib/utils/Makefile
src/lib/ebus/Makefile
src/lib/ebus/test/Makefile
src/ebusd/Makefile
src/ebusctl/Makefile])
AC_CHECK_PROGS([HAVE_DOXYGEN], [doxygen])
if test -z "$HAVE_DOXYGEN";
then AC_MSG_WARN([Doxygen not found - continuing without Doxygen support.])
fi
AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$HAVE_DOXYGEN"])
AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([docs/Doxyfile])])
AM_INIT_AUTOMAKE([1.11 -Wall -Werror foreign])
AM_PROG_AR
+2280
View File
File diff suppressed because it is too large Load Diff
+15
View File
@@ -0,0 +1,15 @@
if HAVE_DOXYGEN
doxyfile.stamp:
$(HAVE_DOXYGEN) Doxyfile
echo Timestamp > doxyfile.stamp
CLEANFILES = doxyfile.stamp
all-local: doxyfile.stamp
distclean-local:
-rm -f Makefile.in
-rm -rf html
endif
+13 -13
View File
@@ -28,7 +28,7 @@ extern Appl& A;
BaseLoop::BaseLoop()
{
// create commands DB
m_commands = ConfigCommands(A.getOptVal<const char*>("ebusconfdir"), CSV).getCommands();
m_commands = ConfigCommands(A.getOptVal<const char*>("ebusconfdir"), ft_csv).getCommands();
L.log(bas, trace, "ebus configuration dir: %s", A.getOptVal<const char*>("ebusconfdir"));
L.log(bas, event, "commands DB: %d ", m_commands->sizeCmdDB());
L.log(bas, event, " cycle DB: %d ", m_commands->sizeCycDB());
@@ -112,11 +112,11 @@ std::string BaseLoop::decodeMessage(const std::string& data)
return "command missing";
switch (getCase(cmd[0])) {
case notfound:
case ct_invalid:
result << "command not found";
break;
case get:
case ct_get:
if (cmd.size() < 3 || cmd.size() > 4) {
result << "usage: 'get class cmd (sub)'";
break;
@@ -176,7 +176,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
break;
case set:
case ct_set:
if (cmd.size() != 4) {
result << "usage: 'set class cmd value'";
break;
@@ -231,7 +231,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
break;
case cyc:
case ct_cyc:
if (cmd.size() < 3 || cmd.size() > 4) {
result << "usage: 'cyc class cmd (sub)'";
break;
@@ -259,7 +259,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
break;
case hex:
case ct_hex:
if (cmd.size() != 2) {
result << "usage: 'hex value' (value: ZZPBSBNNDx)";
break;
@@ -289,7 +289,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
break;
case scan:
case ct_scan:
if (cmd.size() == 1) {
m_busloop->scan();
result << "done";
@@ -315,7 +315,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
<< " 'scan result'";
break;
case log:
case ct_log:
if (cmd.size() != 3 ) {
result << "usage: 'log areas area,area,..' (areas: bas|net|bus|cyc|all)" << std::endl
<< " 'log level level' (level: error|event|trace|debug)";
@@ -340,7 +340,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
break;
case raw:
case ct_raw:
if (cmd.size() != 1) {
result << "usage: 'raw'";
break;
@@ -350,7 +350,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
result << "done";
break;
case dump:
case ct_dump:
if (cmd.size() != 1) {
result << "usage: 'dump'";
break;
@@ -360,7 +360,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
result << "done";
break;
case reload:
case ct_reload:
if (cmd.size() != 1) {
result << "usage: 'reload'";
break;
@@ -368,7 +368,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
{
// create commands DB
Commands* commands = ConfigCommands(A.getOptVal<const char*>("ebusconfdir"), CSV).getCommands();
Commands* commands = ConfigCommands(A.getOptVal<const char*>("ebusconfdir"), ft_csv).getCommands();
L.log(bas, trace, "ebus configuration dir: %s", A.getOptVal<const char*>("ebusconfdir"));
L.log(bas, event, "commands DB: %d ", m_commands->sizeCmdDB());
L.log(bas, event, " cycle DB: %d ", m_commands->sizeCycDB());
@@ -382,7 +382,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
break;
}
case help:
case ct_help:
result << "commands:" << std::endl
<< " get - fetch ebus data 'get class cmd (sub)'" << std::endl
<< " set - set ebus values 'set class cmd value'" << std::endl
+60 -26
View File
@@ -24,54 +24,88 @@
#include "network.h"
#include "busloop.h"
/** possible client commands */
enum CommandType {
ct_get, // get ebus data
ct_set, // set ebus value
ct_cyc, // fetch cycle data
ct_hex, // send hex value
ct_scan, // scan ebus
ct_log, // logger settings
ct_raw, // toggle log raw data
ct_dump, // toggle dump state
ct_reload, // reload ebus configuration
ct_help, // print commands
ct_invalid, // invalid
};
/**
* @brief class baseloop which handle client messages.
*/
class BaseLoop
{
public:
/**
* @brief construct the baseloop and creates commads, network and busloop subsystems.
*/
BaseLoop();
/**
* @brief destructor.
*/
~BaseLoop();
/**
* @brief start baseloop instance.
*/
void start();
/**
* @brief add a new network message to internal message queue.
* @param message the network message.
*/
void addMessage(NetMessage* message) { m_netQueue.add(message); }
private:
/** the commands instance */
Commands* m_commands;
/** the busloop instance */
BusLoop* m_busloop;
/** the network instance */
Network* m_network;
/** queue for network messages */
WQueue<NetMessage*> m_netQueue;
enum ClientCommand {
get, // get ebus data
set, // set ebus value
cyc, // fetch cycle data
hex, // send hex value
scan, // scan ebus
log, // logger settings
raw, // toggle log raw data
dump, // toggle dump state
reload, // reload ebus configuration
help, // print commands
notfound
};
ClientCommand getCase(const std::string& item)
/**
* @brief compare client command with defined.
* @param item the client command to compare.
* @return the founded client command type.
*/
CommandType getCase(const std::string& item)
{
if (strcasecmp(item.c_str(), "GET") == 0) return get;
if (strcasecmp(item.c_str(), "SET") == 0) return set;
if (strcasecmp(item.c_str(), "CYC") == 0) return cyc;
if (strcasecmp(item.c_str(), "HEX") == 0) return hex;
if (strcasecmp(item.c_str(), "SCAN") == 0) return scan;
if (strcasecmp(item.c_str(), "LOG") == 0) return log;
if (strcasecmp(item.c_str(), "RAW") == 0) return raw;
if (strcasecmp(item.c_str(), "DUMP") == 0) return dump;
if (strcasecmp(item.c_str(), "RELOAD") == 0) return reload;
if (strcasecmp(item.c_str(), "HELP") == 0) return help;
if (strcasecmp(item.c_str(), "GET") == 0) return ct_get;
if (strcasecmp(item.c_str(), "SET") == 0) return ct_set;
if (strcasecmp(item.c_str(), "CYC") == 0) return ct_cyc;
if (strcasecmp(item.c_str(), "HEX") == 0) return ct_hex;
if (strcasecmp(item.c_str(), "SCAN") == 0) return ct_scan;
if (strcasecmp(item.c_str(), "LOG") == 0) return ct_log;
if (strcasecmp(item.c_str(), "RAW") == 0) return ct_raw;
if (strcasecmp(item.c_str(), "DUMP") == 0) return ct_dump;
if (strcasecmp(item.c_str(), "RELOAD") == 0) return ct_reload;
if (strcasecmp(item.c_str(), "HELP") == 0) return ct_help;
return notfound;
return ct_invalid;
}
/**
* @brief decode and execute client message
* @param data the data string to decode
* @return result string to send back to client
*/
std::string decodeMessage(const std::string& data);
};
+5 -5
View File
@@ -308,25 +308,25 @@ void BusLoop::analyseCycData()
static bool skipfirst = false;
if (skipfirst == true) {
L.log(bus, trace, "%s", m_sstr.getDataStr().c_str());
L.log(cyc, trace, "%s", m_sstr.getDataStr().c_str());
int index = m_commands->storeCycData(m_sstr.getDataStr());
if (index == -1) {
L.log(bus, debug, " command not found");
L.log(cyc, debug, " command not found");
}
else if (index == -2) {
L.log(bus, debug, " no commands defined");
L.log(cyc, debug, " no commands defined");
}
else if (index == -3) {
L.log(bus, debug, " search skipped - string too short");
L.log(cyc, debug, " search skipped - string too short");
}
else {
std::string tmp;
tmp += (*m_commands)[index][1];
tmp += " ";
tmp += (*m_commands)[index][2];
L.log(bus, event, " cycle [%4d] %s", index, tmp.c_str());
L.log(cyc, event, " cycle [%4d] %s", index, tmp.c_str());
}
// collect Slave address
+13 -8
View File
@@ -30,8 +30,13 @@
/** the maximum time [us] allowed for retrieving a byte from an addressed slave */
#define RECV_TIMEOUT 10000
/** possible command types */
enum CommandType { invalid, broadcast, masterMaster, masterSlave };
/** possible bus command types */
enum BusCommandType {
invalid, // invalid command type
broadcast, // broadcast
masterMaster, // master - master
masterSlave, // master - slave
};
/**
* @brief class for data/message transfer between baseloop and busloop.
@@ -41,7 +46,7 @@ class BusMessage
public:
/**
* @brief constructs a new bus message instance and determine command type.
* @brief construct a new bus message instance and determine command type.
* @param command the command data to write on bus.
* @param poll true if message type is polling.
* @param scan true if message type is scanning.
@@ -58,10 +63,10 @@ public:
}
/**
* @brief get the command type.
* @return the command type.
* @brief get the bus command type.
* @return the bus command type.
*/
CommandType getType() const { return m_type; }
BusCommandType getType() const { return m_type; }
/**
* @brief get the command string.
@@ -124,8 +129,8 @@ public:
void sendSignal() { pthread_cond_signal(&m_cond); }
private:
/** the command type */
CommandType m_type;
/** the bus command type */
BusCommandType m_type;
/** true if message is of type polling */
bool m_poll;
+91 -6
View File
@@ -17,11 +17,19 @@
* along with ebusd. If not, see http://www.gnu.org/licenses/.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "network.h"
#include "logger.h"
#include "appl.h"
#include <cstring>
#ifdef HAVE_PPOLL
#include <poll.h>
#endif
extern Logger& L;
extern Appl& A;
@@ -32,14 +40,17 @@ void* Connection::run()
{
m_running = true;
int ret, nfds = 2;
struct pollfd fds[nfds];
int ret;
struct timespec tdiff;
// set select timeout 10 secs
tdiff.tv_sec = 10;
tdiff.tv_nsec = 0;
#ifdef HAVE_PPOLL
int nfds = 2;
struct pollfd fds[nfds];
memset(fds, 0, sizeof(fds));
fds[0].fd = m_notify.notifyFD();
@@ -47,21 +58,55 @@ void* Connection::run()
fds[1].fd = m_socket->getFD();
fds[1].events = POLLIN;
#else
#ifdef HAVE_PSELECT
int maxfd;
fd_set checkfds;
FD_ZERO(&checkfds);
FD_SET(m_notify.notifyFD(), &checkfds);
FD_SET(m_socket->getFD(), &checkfds);
(m_notify.notifyFD() > m_socket->getFD()) ?
(maxfd = m_notify.notifyFD()) : (maxfd = m_socket->getFD());
#endif
#endif
for (;;) {
#ifdef HAVE_PPOLL
// wait for new fd event
ret = ppoll(fds, nfds, &tdiff, NULL);
#else
#ifdef HAVE_PSELECT
// set readfds to inital checkfds
fd_set readfds = checkfds;
// wait for new fd event
ret = pselect(maxfd + 1, &readfds, NULL, NULL, &tdiff, NULL);
#endif
#endif
if (ret == 0) {
if (ret == 0)
continue;
}
#ifdef HAVE_PPOLL
// new data from notify
if (fds[0].revents & POLLIN)
break;
// new data from socket
if (fds[1].revents & POLLIN) {
#else
#ifdef HAVE_PSELECT
// new data from notify
if (FD_ISSET(m_notify.notifyFD(), &readfds))
break;
// new data from socket
if (FD_ISSET(m_socket->getFD(), &readfds)) {
#endif
#endif
char data[256];
size_t datalen;
@@ -139,14 +184,17 @@ void* Network::run()
m_running = true;
int ret, nfds = 2;
struct pollfd fds[nfds];
int ret;
struct timespec tdiff;
// set select timeout 1 secs
tdiff.tv_sec = 1;
tdiff.tv_nsec = 0;
#ifdef HAVE_PPOLL
int nfds = 2;
struct pollfd fds[nfds];
memset(fds, 0, sizeof(fds));
fds[0].fd = m_notify.notifyFD();
@@ -154,16 +202,40 @@ void* Network::run()
fds[1].fd = m_tcpServer->getFD();
fds[1].events = POLLIN;
#else
#ifdef HAVE_PSELECT
int maxfd;
fd_set checkfds;
FD_ZERO(&checkfds);
FD_SET(m_notify.notifyFD(), &checkfds);
FD_SET(m_tcpServer->getFD(), &checkfds);
(m_notify.notifyFD() > m_tcpServer->getFD()) ?
(maxfd = m_notify.notifyFD()) : (maxfd = m_tcpServer->getFD());
#endif
#endif
for (;;) {
#ifdef HAVE_PPOLL
// wait for new fd event
ret = ppoll(fds, nfds, &tdiff, NULL);
#else
#ifdef HAVE_PSELECT
// set readfds to inital checkfds
fd_set readfds = checkfds;
// wait for new fd event
ret = pselect(maxfd + 1, &readfds, NULL, NULL, &tdiff, NULL);
#endif
#endif
if (ret == 0) {
cleanConnections();
continue;
}
#ifdef HAVE_PPOLL
// new data from notify
if (fds[0].revents & POLLIN) {
m_running = false;
@@ -172,6 +244,19 @@ void* Network::run()
// new data from socket
if (fds[1].revents & POLLIN) {
#else
#ifdef HAVE_PSELECT
// new data from notify
if (FD_ISSET(m_notify.notifyFD(), &readfds)) {
m_running = false;
break;
}
// new data from socket
if (FD_ISSET(m_tcpServer->getFD(), &readfds)) {
#endif
#endif
TCPSocket* socket = m_tcpServer->newSocket();
if (socket == NULL)
continue;
+1 -1
View File
@@ -60,7 +60,7 @@ void ConfigCommands::setType(const FileType type)
delete m_configfile;
switch (type) {
case CSV:
case ft_csv:
m_configfile = new ConfigFileCSV();
m_extension = "csv";
break;
+3 -1
View File
@@ -25,7 +25,9 @@
#include <vector>
/** available file endings / types. */
enum FileType { CSV };
enum FileType {
ft_csv
};
/**
* @brief base class for config files.
+26 -6
View File
@@ -17,6 +17,10 @@
* along with ebusd. If not, see http://www.gnu.org/licenses/.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "port.h"
#include <cstdlib>
#include <cstring>
@@ -24,7 +28,10 @@
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <netdb.h>
#ifdef HAVE_PPOLL
#include <poll.h>
#endif
bool Device::isOpen()
{
@@ -64,20 +71,33 @@ ssize_t Device::recvBytes(const long timeout, size_t maxCount)
return -1; // TODO RESULT_ERR_DEVICE
if (timeout > 0) {
int ret, nfds = 1;
struct pollfd fds[nfds];
int ret;
struct timespec tdiff;
// set select timeout
tdiff.tv_sec = 0;
tdiff.tv_nsec = timeout*1000;
#ifdef HAVE_PPOLL
int nfds = 1;
struct pollfd fds[nfds];
memset(fds, 0, sizeof(fds));
fds[0].fd = m_fd;
fds[0].events = POLLIN;
ret = ppoll(fds, nfds, &tdiff, NULL);
#else
#ifdef HAVE_PSELECT
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(m_fd, &readfds);
ret = pselect(m_fd + 1, &readfds, NULL, NULL, &tdiff, NULL);
#endif
#endif
if (ret == -1) return -1; // TODO RESULT_ERR_DEVICE
if (ret == 0) return -2; // TODO RESULT_ERR_TIMEOUT
@@ -232,9 +252,9 @@ Port::Port(const std::string deviceName, const bool noDeviceCheck)
if (strchr(deviceName.c_str(), '/') == NULL &&
strchr(deviceName.c_str(), ':') != NULL)
setType(NETWORK);
setType(dt_network);
else
setType(SERIAL);
setType(dt_serial);
}
void Port::setType(const DeviceType type)
@@ -243,10 +263,10 @@ void Port::setType(const DeviceType type)
delete m_device;
switch (type) {
case SERIAL:
case dt_serial:
m_device = new DeviceSerial();
break;
case NETWORK:
case dt_network:
m_device = new DeviceNetwork();
break;
};
+4 -1
View File
@@ -26,7 +26,10 @@
#include <unistd.h>
/** available device types. */
enum DeviceType { SERIAL, NETWORK };
enum DeviceType {
dt_serial,
dt_network,
};
/** max bytes write to bus. */
#define MAX_WRITE_SIZE 1
+1 -1
View File
@@ -51,7 +51,7 @@ void readCSV(std::istream& is, Commands& commands){
int main()
{
Commands* commands = ConfigCommands("test", CSV).getCommands();
Commands* commands = ConfigCommands("test", ft_csv).getCommands();
std::cout << "Commands: " << commands->sizeCmdDB() << std::endl;
//~ std::string data("g ci password pin1");
+1 -1
View File
@@ -27,7 +27,7 @@
int main() {
std::string dir("test");
ConfigCommands config(dir, CSV);
ConfigCommands config(dir, ft_csv);
Commands* commands = config.getCommands();
+6 -3
View File
@@ -29,11 +29,14 @@
#include <unistd.h>
/** static char array with logging area names */
static const char* AreaNames[Size_of_Areas] = { "bas", "net", "bus" };
static const char* AreaNames[Size_of_Areas] = { "bas", "net", "bus", "cyc" };
/** static char array with logging level names */
static const char* LevelNames[Size_of_Level] = { "error", "event", "trace", "debug" };
/** inline function of log2 */
inline double Log2(double n) { return log(n) / log(2); }
int calcAreas(const std::string areas)
{
int m_areas = 0;
@@ -120,7 +123,7 @@ void* LogSink::run()
void LogConsole::write(const LogMessage& message) const
{
std::cout << message.getTime() << " ["
<< AreaNames[(int)log2(message.getArea())] << " "
<< AreaNames[(int)Log2(message.getArea())] << " "
<< LevelNames[message.getLevel()] << "] "
<< message.getText() << std::endl;
}
@@ -133,7 +136,7 @@ void LogFile::write(const LogMessage& message) const
if (file.is_open() == true) {
file << message.getTime() << " ["
<< AreaNames[(int)log2(message.getArea())] << " "
<< AreaNames[(int)Log2(message.getArea())] << " "
<< LevelNames[message.getLevel()] << "] "
<< message.getText() << std::endl;
file.close();
+3 -2
View File
@@ -33,8 +33,9 @@ enum AreasType {
bas=1, // basis
net=2, // network
bus=4, // ebus
all=7, // type for all subsystems
Size_of_Areas=3, // number of possible areas
cyc=8, // cycle
all=15, // type for all subsystems
Size_of_Areas=4, // number of possible areas
};
/** available logging levels */
+1
View File
@@ -137,6 +137,7 @@ public:
/**
* @brief start listening of tcp socket.
* @return result of low level functions.
*/
int start();