class BaseLoop, EBusLoop: polling functionality implemented.
This commit is contained in:
@@ -1,3 +1,2 @@
|
||||
# type;class;cmd;comment;msg type;ZZ;PBSB;NN;D1D2D3;elements;sub;part;position;datatype;factor;unit;valid;comment;sub;part;position;datatype;factor;unit;valid;comment;sub;part;position;datatype;factor;unit;valid;comment;sub;part;position;datatype;factor;unit;valid;comment
|
||||
cyc;broad;date_time_temp;Datum, Uhrzeit und Aussentempertur;BR;FE;0700;9;-;4;temp;md;1,2;d2b;1.0;°C;-;Temperatur;day;md;8;bdy;-;-;-;Wochentag;date;md;6,7,9;bda;-;-;-;Datum;time;md;5,4,3;bti;-;-;-;Uhrzeit
|
||||
|
||||
# type (r/p;w;c);class;cmd;comment;msg type;ZZ;PBSB;NN;D1D2D3;elements;sub;part;position;datatype;factor;unit;valid;comment;sub;part;position;datatype;factor;unit;valid;comment;sub;part;position;datatype;factor;unit;valid;comment;sub;part;position;datatype;factor;unit;valid;comment
|
||||
c;broad;date_time_temp;Datum, Uhrzeit und Aussentempertur;BR;FE;700;9;-;4;temp;md;1,2;d2b;1.0;°C;-;Temperatur;day;md;8;bdy;-;-;-;Wochentag;date;md;6,7,9;bda;-;-;-;Datum;time;md;5,4,3;bti;-;-;-;Uhrzeit
|
||||
|
||||
|
+31
-10
@@ -28,9 +28,10 @@ BaseLoop::BaseLoop()
|
||||
{
|
||||
// create Commands DB
|
||||
m_commands = ConfigCommands(A.getParam<const char*>("p_ebusconfdir"), CSV).getCommands();
|
||||
L.log(bas, debug, "ebus configuration dir: %s", A.getParam<const char*>("p_ebusconfdir"));
|
||||
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());
|
||||
L.log(bas, trace, "ebus configuration dir: %s", A.getParam<const char*>("p_ebusconfdir"));
|
||||
L.log(bas, event, "commands DB: %d ", m_commands->sizeCmdDB());
|
||||
L.log(bas, event, " cycle DB: %d ", m_commands->sizeCycDB());
|
||||
L.log(bas, event, " polling DB: %d ", m_commands->sizePolDB());
|
||||
|
||||
// create EBusLoop
|
||||
m_ebusloop = new EBusLoop(m_commands);
|
||||
@@ -98,7 +99,7 @@ void BaseLoop::start()
|
||||
std::string BaseLoop::decodeMessage(const std::string& data)
|
||||
{
|
||||
std::ostringstream result;
|
||||
std::string cycdata;
|
||||
std::string cycdata, polldata;
|
||||
int index;
|
||||
|
||||
// prepare data
|
||||
@@ -127,7 +128,26 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
||||
|
||||
if (index >= 0) {
|
||||
|
||||
std::string type = m_commands->getType(index);
|
||||
// polling data
|
||||
if (strcasecmp(m_commands->getCmdType(index).c_str(), "P") == 0) {
|
||||
// get polldata
|
||||
polldata = m_commands->getPolData(index);
|
||||
if (polldata != "") {
|
||||
// decode data
|
||||
Command* command = new Command(index, (*m_commands)[index], polldata);
|
||||
|
||||
// return result
|
||||
result << command->calcResult(cmd);
|
||||
|
||||
delete command;
|
||||
} else {
|
||||
result << "no data stored";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
std::string type = m_commands->getEbusType(index);
|
||||
std::string ebusCommand(A.getParam<const char*>("p_address"));
|
||||
ebusCommand += m_commands->getEbusCommand(index);
|
||||
std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower);
|
||||
@@ -168,7 +188,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
||||
|
||||
if (index >= 0) {
|
||||
|
||||
std::string type = m_commands->getType(index);
|
||||
std::string type = m_commands->getEbusType(index);
|
||||
std::string ebusCommand(A.getParam<const char*>("p_address"));
|
||||
ebusCommand += m_commands->getEbusCommand(index);
|
||||
|
||||
@@ -223,7 +243,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
||||
|
||||
if (index >= 0) {
|
||||
// get cycdata
|
||||
cycdata = m_commands->getData(index);
|
||||
cycdata = m_commands->getCycData(index);
|
||||
if (cycdata != "") {
|
||||
// decode data
|
||||
Command* command = new Command(index, (*m_commands)[index], cycdata);
|
||||
@@ -327,9 +347,10 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
||||
if (strcasecmp(cmd[1].c_str(), "RELOAD") == 0) {
|
||||
// create Commands DB
|
||||
Commands* commands = ConfigCommands(A.getParam<const char*>("p_ebusconfdir"), CSV).getCommands();
|
||||
L.log(bas, debug, "ebus configuration dir: %s", A.getParam<const char*>("p_ebusconfdir"));
|
||||
L.log(bas, event, "commands DB with %d entries created", commands->sizeCmd());
|
||||
L.log(bas, event, " data DB with %d entries created", commands->sizeData());
|
||||
L.log(bas, trace, "ebus configuration dir: %s", A.getParam<const char*>("p_ebusconfdir"));
|
||||
L.log(bas, event, "commands DB: %d ", m_commands->sizeCmdDB());
|
||||
L.log(bas, event, " cycle DB: %d ", m_commands->sizeCycDB());
|
||||
L.log(bas, event, " polling DB: %d ", m_commands->sizePolDB());
|
||||
|
||||
delete m_commands;
|
||||
m_commands = commands;
|
||||
|
||||
+47
-21
@@ -37,7 +37,7 @@ EBusLoop::EBusLoop(Commands* commands) : m_commands(commands), m_stop(false)
|
||||
|
||||
m_retries = A.getParam<int>("p_retries");
|
||||
|
||||
m_pollInterval = 5.0;
|
||||
m_pollInterval = A.getParam<int>("p_pollinterval");
|
||||
|
||||
m_bus->connect();
|
||||
|
||||
@@ -63,6 +63,7 @@ void* EBusLoop::run()
|
||||
time_t start, end;
|
||||
time(&start);
|
||||
double pollDelta = 0.0;
|
||||
bool pollCommandActive = false;
|
||||
|
||||
for (;;) {
|
||||
if (m_bus->isConnected() == true) {
|
||||
@@ -75,7 +76,7 @@ void* EBusLoop::run()
|
||||
std::string data = m_bus->getCycData();
|
||||
L.log(bus, trace, "%s", data.c_str());
|
||||
|
||||
int index = m_commands->storeData(data);
|
||||
int index = m_commands->storeCycData(data);
|
||||
|
||||
if (index == -1) {
|
||||
L.log(bus, debug, " command not found");
|
||||
@@ -88,12 +89,10 @@ void* EBusLoop::run()
|
||||
|
||||
} 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());
|
||||
L.log(bus, event, " cycle [%d] %s", index, tmp.c_str());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -108,24 +107,45 @@ void* EBusLoop::run()
|
||||
busCommandActive = true;
|
||||
}
|
||||
|
||||
// check polling delta
|
||||
time(&end);
|
||||
pollDelta = difftime(end, start);
|
||||
// add new polling command
|
||||
if (m_commands->sizePolDB() > 0) {
|
||||
// check polling delta
|
||||
time(&end);
|
||||
pollDelta = difftime(end, start);
|
||||
|
||||
// add new polling command to send
|
||||
if (busResult == 4 && busCommandActive == false && pollDelta >= m_pollInterval) {
|
||||
L.log(bus, trace, "%.f seconds elapsed - polling next value", pollDelta);
|
||||
// add new polling command to send
|
||||
if (busResult == 4 && busCommandActive == false && pollDelta >= m_pollInterval) {
|
||||
L.log(bus, trace, "polling Intervall reached");
|
||||
|
||||
//~ BusCommand* busCommand = m_sendBuffer.remove();
|
||||
// fetch new polling command
|
||||
int index = m_commands->nextPolCommand();
|
||||
if (index < 0) {
|
||||
L.log(bus, error, "polling index out of range");
|
||||
time(&start);
|
||||
continue;
|
||||
}
|
||||
|
||||
//~ L.log(bus, debug, " type: %s msg: %s",
|
||||
//~ busCommand->getType().c_str(), busCommand->getCommand().c_str());
|
||||
//~ m_bus->addCommand(busCommand);
|
||||
//~ L.log(bus, debug, " addCommand success");
|
||||
//~ busCommandActive = true;
|
||||
std::string tmp;
|
||||
tmp += (*m_commands)[index][1];
|
||||
tmp += " ";
|
||||
tmp += (*m_commands)[index][2];
|
||||
L.log(bus, event, " polling [%d] %s", index, tmp.c_str());
|
||||
|
||||
std::string type = m_commands->getEbusType(index);
|
||||
std::string ebusCommand(A.getParam<const char*>("p_address"));
|
||||
ebusCommand += m_commands->getEbusCommand(index);
|
||||
std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower);
|
||||
|
||||
L.log(bus, trace, " type: %s msg: %s", type.c_str(), ebusCommand.c_str());
|
||||
|
||||
BusCommand* busCommand = new BusCommand(type, ebusCommand);
|
||||
m_bus->addCommand(busCommand);
|
||||
L.log(bus, debug, " addCommand success");
|
||||
busCommandActive = true;
|
||||
pollCommandActive = true;
|
||||
|
||||
time(&start);
|
||||
}
|
||||
|
||||
time(&start);
|
||||
}
|
||||
|
||||
// send bus command
|
||||
@@ -142,8 +162,14 @@ void* EBusLoop::run()
|
||||
m_bus->addCommand(busCommand);
|
||||
} else {
|
||||
retries = 0;
|
||||
// ToDo: check for poll event
|
||||
m_recvBuffer.add(busCommand);
|
||||
if (pollCommandActive == true) {
|
||||
m_commands->storePolData(busCommand->getResult().c_str());
|
||||
delete busCommand;
|
||||
pollCommandActive = false;
|
||||
} else {
|
||||
m_recvBuffer.add(busCommand);
|
||||
}
|
||||
|
||||
busCommandActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,10 @@ void define_args()
|
||||
"receive timeout in 'us' (15000)\n",
|
||||
Appl::type_long, Appl::opt_mandatory);
|
||||
|
||||
A.addItem("p_pollinterval", Appl::Param(5), "", "pollinterval",
|
||||
"polling interval in 's' (5)\n",
|
||||
Appl::type_int, Appl::opt_mandatory);
|
||||
|
||||
A.addItem("p_ebusconfdir", Appl::Param("/etc/ebusd"), "e", "ebusconfdir",
|
||||
"directory for ebus configuration (/etc/ebusd)\n",
|
||||
Appl::type_string, Appl::opt_mandatory);
|
||||
|
||||
Reference in New Issue
Block a user