documentation for class BaseLoop added; most enum types adapted.

This commit is contained in:
Roland Jax
2014-11-20 18:43:07 +01:00
parent b806210cfa
commit 835c901da6
10 changed files with 101 additions and 56 deletions
+13 -13
View File
@@ -28,7 +28,7 @@ extern Appl& A;
BaseLoop::BaseLoop() BaseLoop::BaseLoop()
{ {
// create commands DB // 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, trace, "ebus configuration dir: %s", A.getOptVal<const char*>("ebusconfdir"));
L.log(bas, event, "commands DB: %d ", m_commands->sizeCmdDB()); L.log(bas, event, "commands DB: %d ", m_commands->sizeCmdDB());
L.log(bas, event, " cycle DB: %d ", m_commands->sizeCycDB()); 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"; return "command missing";
switch (getCase(cmd[0])) { switch (getCase(cmd[0])) {
case notfound: case ct_invalid:
result << "command not found"; result << "command not found";
break; break;
case get: case ct_get:
if (cmd.size() < 3 || cmd.size() > 4) { if (cmd.size() < 3 || cmd.size() > 4) {
result << "usage: 'get class cmd (sub)'"; result << "usage: 'get class cmd (sub)'";
break; break;
@@ -176,7 +176,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
break; break;
case set: case ct_set:
if (cmd.size() != 4) { if (cmd.size() != 4) {
result << "usage: 'set class cmd value'"; result << "usage: 'set class cmd value'";
break; break;
@@ -231,7 +231,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
break; break;
case cyc: case ct_cyc:
if (cmd.size() < 3 || cmd.size() > 4) { if (cmd.size() < 3 || cmd.size() > 4) {
result << "usage: 'cyc class cmd (sub)'"; result << "usage: 'cyc class cmd (sub)'";
break; break;
@@ -259,7 +259,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
break; break;
case hex: case ct_hex:
if (cmd.size() != 2) { if (cmd.size() != 2) {
result << "usage: 'hex value' (value: ZZPBSBNNDx)"; result << "usage: 'hex value' (value: ZZPBSBNNDx)";
break; break;
@@ -289,7 +289,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
break; break;
case scan: case ct_scan:
if (cmd.size() == 1) { if (cmd.size() == 1) {
m_busloop->scan(); m_busloop->scan();
result << "done"; result << "done";
@@ -315,7 +315,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
<< " 'scan result'"; << " 'scan result'";
break; break;
case log: case ct_log:
if (cmd.size() != 3 ) { if (cmd.size() != 3 ) {
result << "usage: 'log areas area,area,..' (areas: bas|net|bus|cyc|all)" << std::endl result << "usage: 'log areas area,area,..' (areas: bas|net|bus|cyc|all)" << std::endl
<< " 'log level level' (level: error|event|trace|debug)"; << " 'log level level' (level: error|event|trace|debug)";
@@ -340,7 +340,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
break; break;
case raw: case ct_raw:
if (cmd.size() != 1) { if (cmd.size() != 1) {
result << "usage: 'raw'"; result << "usage: 'raw'";
break; break;
@@ -350,7 +350,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
result << "done"; result << "done";
break; break;
case dump: case ct_dump:
if (cmd.size() != 1) { if (cmd.size() != 1) {
result << "usage: 'dump'"; result << "usage: 'dump'";
break; break;
@@ -360,7 +360,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
result << "done"; result << "done";
break; break;
case reload: case ct_reload:
if (cmd.size() != 1) { if (cmd.size() != 1) {
result << "usage: 'reload'"; result << "usage: 'reload'";
break; break;
@@ -368,7 +368,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
{ {
// create commands DB // 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, trace, "ebus configuration dir: %s", A.getOptVal<const char*>("ebusconfdir"));
L.log(bas, event, "commands DB: %d ", m_commands->sizeCmdDB()); L.log(bas, event, "commands DB: %d ", m_commands->sizeCmdDB());
L.log(bas, event, " cycle DB: %d ", m_commands->sizeCycDB()); L.log(bas, event, " cycle DB: %d ", m_commands->sizeCycDB());
@@ -382,7 +382,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
break; break;
} }
case help: case ct_help:
result << "commands:" << std::endl result << "commands:" << std::endl
<< " get - fetch ebus data 'get class cmd (sub)'" << std::endl << " get - fetch ebus data 'get class cmd (sub)'" << std::endl
<< " set - set ebus values 'set class cmd value'" << std::endl << " set - set ebus values 'set class cmd value'" << std::endl
+60 -26
View File
@@ -24,54 +24,88 @@
#include "network.h" #include "network.h"
#include "busloop.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 class BaseLoop
{ {
public: public:
/**
* @brief construct the baseloop and creates commads, network and busloop subsystems.
*/
BaseLoop(); BaseLoop();
/**
* @brief destructor.
*/
~BaseLoop(); ~BaseLoop();
/**
* @brief start baseloop instance.
*/
void start(); 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); } void addMessage(NetMessage* message) { m_netQueue.add(message); }
private: private:
/** the commands instance */
Commands* m_commands; Commands* m_commands;
/** the busloop instance */
BusLoop* m_busloop; BusLoop* m_busloop;
/** the network instance */
Network* m_network; Network* m_network;
/** queue for network messages */
WQueue<NetMessage*> m_netQueue; WQueue<NetMessage*> m_netQueue;
enum ClientCommand { /**
get, // get ebus data * @brief compare client command with defined.
set, // set ebus value * @param item the client command to compare.
cyc, // fetch cycle data * @return the founded client command type.
hex, // send hex value */
scan, // scan ebus CommandType getCase(const std::string& item)
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)
{ {
if (strcasecmp(item.c_str(), "GET") == 0) return get; if (strcasecmp(item.c_str(), "GET") == 0) return ct_get;
if (strcasecmp(item.c_str(), "SET") == 0) return set; if (strcasecmp(item.c_str(), "SET") == 0) return ct_set;
if (strcasecmp(item.c_str(), "CYC") == 0) return cyc; if (strcasecmp(item.c_str(), "CYC") == 0) return ct_cyc;
if (strcasecmp(item.c_str(), "HEX") == 0) return hex; if (strcasecmp(item.c_str(), "HEX") == 0) return ct_hex;
if (strcasecmp(item.c_str(), "SCAN") == 0) return scan; if (strcasecmp(item.c_str(), "SCAN") == 0) return ct_scan;
if (strcasecmp(item.c_str(), "LOG") == 0) return log; if (strcasecmp(item.c_str(), "LOG") == 0) return ct_log;
if (strcasecmp(item.c_str(), "RAW") == 0) return raw; if (strcasecmp(item.c_str(), "RAW") == 0) return ct_raw;
if (strcasecmp(item.c_str(), "DUMP") == 0) return dump; if (strcasecmp(item.c_str(), "DUMP") == 0) return ct_dump;
if (strcasecmp(item.c_str(), "RELOAD") == 0) return reload; if (strcasecmp(item.c_str(), "RELOAD") == 0) return ct_reload;
if (strcasecmp(item.c_str(), "HELP") == 0) return help; 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); std::string decodeMessage(const std::string& data);
}; };
+13 -8
View File
@@ -30,8 +30,13 @@
/** the maximum time [us] allowed for retrieving a byte from an addressed slave */ /** the maximum time [us] allowed for retrieving a byte from an addressed slave */
#define RECV_TIMEOUT 10000 #define RECV_TIMEOUT 10000
/** possible command types */ /** possible bus command types */
enum CommandType { invalid, broadcast, masterMaster, masterSlave }; enum BusCommandType {
invalid, // invalid command type
broadcast, // broadcast
masterMaster, // master - master
masterSlave, // master - slave
};
/** /**
* @brief class for data/message transfer between baseloop and busloop. * @brief class for data/message transfer between baseloop and busloop.
@@ -41,7 +46,7 @@ class BusMessage
public: 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 command the command data to write on bus.
* @param poll true if message type is polling. * @param poll true if message type is polling.
* @param scan true if message type is scanning. * @param scan true if message type is scanning.
@@ -58,10 +63,10 @@ public:
} }
/** /**
* @brief get the command type. * @brief get the bus command type.
* @return the command type. * @return the bus command type.
*/ */
CommandType getType() const { return m_type; } BusCommandType getType() const { return m_type; }
/** /**
* @brief get the command string. * @brief get the command string.
@@ -124,8 +129,8 @@ public:
void sendSignal() { pthread_cond_signal(&m_cond); } void sendSignal() { pthread_cond_signal(&m_cond); }
private: private:
/** the command type */ /** the bus command type */
CommandType m_type; BusCommandType m_type;
/** true if message is of type polling */ /** true if message is of type polling */
bool m_poll; bool m_poll;
+1 -1
View File
@@ -60,7 +60,7 @@ void ConfigCommands::setType(const FileType type)
delete m_configfile; delete m_configfile;
switch (type) { switch (type) {
case CSV: case ft_csv:
m_configfile = new ConfigFileCSV(); m_configfile = new ConfigFileCSV();
m_extension = "csv"; m_extension = "csv";
break; break;
+3 -1
View File
@@ -25,7 +25,9 @@
#include <vector> #include <vector>
/** available file endings / types. */ /** available file endings / types. */
enum FileType { CSV }; enum FileType {
ft_csv
};
/** /**
* @brief base class for config files. * @brief base class for config files.
+4 -4
View File
@@ -232,9 +232,9 @@ Port::Port(const std::string deviceName, const bool noDeviceCheck)
if (strchr(deviceName.c_str(), '/') == NULL && if (strchr(deviceName.c_str(), '/') == NULL &&
strchr(deviceName.c_str(), ':') != NULL) strchr(deviceName.c_str(), ':') != NULL)
setType(NETWORK); setType(dt_network);
else else
setType(SERIAL); setType(dt_serial);
} }
void Port::setType(const DeviceType type) void Port::setType(const DeviceType type)
@@ -243,10 +243,10 @@ void Port::setType(const DeviceType type)
delete m_device; delete m_device;
switch (type) { switch (type) {
case SERIAL: case dt_serial:
m_device = new DeviceSerial(); m_device = new DeviceSerial();
break; break;
case NETWORK: case dt_network:
m_device = new DeviceNetwork(); m_device = new DeviceNetwork();
break; break;
}; };
+4 -1
View File
@@ -26,7 +26,10 @@
#include <unistd.h> #include <unistd.h>
/** available device types. */ /** available device types. */
enum DeviceType { SERIAL, NETWORK }; enum DeviceType {
dt_serial,
dt_network,
};
/** max bytes write to bus. */ /** max bytes write to bus. */
#define MAX_WRITE_SIZE 1 #define MAX_WRITE_SIZE 1
+1 -1
View File
@@ -51,7 +51,7 @@ void readCSV(std::istream& is, Commands& commands){
int main() int main()
{ {
Commands* commands = ConfigCommands("test", CSV).getCommands(); Commands* commands = ConfigCommands("test", ft_csv).getCommands();
std::cout << "Commands: " << commands->sizeCmdDB() << std::endl; std::cout << "Commands: " << commands->sizeCmdDB() << std::endl;
//~ std::string data("g ci password pin1"); //~ std::string data("g ci password pin1");
+1 -1
View File
@@ -27,7 +27,7 @@
int main() { int main() {
std::string dir("test"); std::string dir("test");
ConfigCommands config(dir, CSV); ConfigCommands config(dir, ft_csv);
Commands* commands = config.getCommands(); Commands* commands = config.getCommands();
+1
View File
@@ -137,6 +137,7 @@ public:
/** /**
* @brief start listening of tcp socket. * @brief start listening of tcp socket.
* @return result of low level functions.
*/ */
int start(); int start();