documentation for class BaseLoop added; most enum types adapted.
This commit is contained in:
+13
-13
@@ -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
@@ -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);
|
||||
|
||||
};
|
||||
|
||||
+13
-8
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -25,7 +25,9 @@
|
||||
#include <vector>
|
||||
|
||||
/** available file endings / types. */
|
||||
enum FileType { CSV };
|
||||
enum FileType {
|
||||
ft_csv
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief base class for config files.
|
||||
|
||||
@@ -232,9 +232,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 +243,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
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
int main() {
|
||||
|
||||
std::string dir("test");
|
||||
ConfigCommands config(dir, CSV);
|
||||
ConfigCommands config(dir, ft_csv);
|
||||
|
||||
Commands* commands = config.getCommands();
|
||||
|
||||
|
||||
@@ -137,6 +137,7 @@ public:
|
||||
|
||||
/**
|
||||
* @brief start listening of tcp socket.
|
||||
* @return result of low level functions.
|
||||
*/
|
||||
int start();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user