daemon option: --logautosyn added.

This commit is contained in:
Roland Jax
2014-10-14 18:05:08 +02:00
parent f332bf7c14
commit 19f5900c8a
3 changed files with 42 additions and 25 deletions
+36 -24
View File
@@ -41,6 +41,8 @@ EBusLoop::EBusLoop(Commands* commands) : m_commands(commands), m_stop(false)
m_pollInterval = A.getParam<int>("p_pollinterval"); m_pollInterval = A.getParam<int>("p_pollinterval");
m_logAutoSyn = A.getParam<bool>("p_logautosyn");
m_bus->connect(); m_bus->connect();
if (m_bus->isConnected() == false) if (m_bus->isConnected() == false)
@@ -63,8 +65,10 @@ void* EBusLoop::run()
int retries = 0; int retries = 0;
int lookbusretries = 0; int lookbusretries = 0;
bool busCommandActive = false; bool busCommandActive = false;
time_t start, end;
time(&start); // polling
time_t pollStart, pollEnd;
time(&pollStart);
double pollDelta = 0.0; double pollDelta = 0.0;
bool pollCommandActive = false; bool pollCommandActive = false;
@@ -75,33 +79,41 @@ void* EBusLoop::run()
busResult = m_bus->proceed(); busResult = m_bus->proceed();
// new cyc message arrived // new cyc message arrived
if (busResult == RESULT_SYN) { if (busResult == RESULT_SYN || busResult == RESULT_BUS_LOCKED) {
std::string data = m_bus->getCycData(); std::string data = m_bus->getCycData();
L.log(bus, trace, "%s", data.c_str());
int index = m_commands->storeCycData(data); if (data.size() == 0 && m_logAutoSyn == true)
L.log(bus, trace, "%s", "aa");
if (index == -1) { if (data.size() != 0) {
L.log(bus, debug, " command not found"); L.log(bus, trace, "%s", data.c_str());
} else if (index == -2) { int index = m_commands->storeCycData(data);
L.log(bus, debug, " no commands defined");
} else if (index == -3) { if (index == -1) {
L.log(bus, debug, " search skipped - string too short"); L.log(bus, debug, " command not found");
} else { } else if (index == -2) {
std::string tmp; L.log(bus, debug, " no commands defined");
tmp += (*m_commands)[index][1];
tmp += " "; } else if (index == -3) {
tmp += (*m_commands)[index][2]; L.log(bus, debug, " search skipped - string too short");
L.log(bus, event, " cycle [%d] %s", index, tmp.c_str());
} else {
std::string tmp;
tmp += (*m_commands)[index][1];
tmp += " ";
tmp += (*m_commands)[index][2];
L.log(bus, event, " cycle [%d] %s", index, tmp.c_str());
}
} }
if (busResult == RESULT_BUS_LOCKED)
L.log(bus, trace, "bus locked");
} }
// add new bus command to send // add new bus command to send
if (busResult == RESULT_AUTO_SYN && busCommandActive == false && m_sendBuffer.size() != 0) { if (busResult == RESULT_SYN && busCommandActive == false && m_sendBuffer.size() != 0) {
BusCommand* busCommand = m_sendBuffer.remove(); BusCommand* busCommand = m_sendBuffer.remove();
L.log(bus, debug, " type: %s msg: %s", L.log(bus, debug, " type: %s msg: %s",
busCommand->getTypeCStr(), busCommand->getCommand().c_str()); busCommand->getTypeCStr(), busCommand->getCommand().c_str());
@@ -113,17 +125,17 @@ void* EBusLoop::run()
// add new polling command // add new polling command
if (m_commands->sizePolDB() > 0) { if (m_commands->sizePolDB() > 0) {
// check polling delta // check polling delta
time(&end); time(&pollEnd);
pollDelta = difftime(end, start); pollDelta = difftime(pollEnd, pollStart);
// add new polling command to send // add new polling command to send
if (busResult == RESULT_AUTO_SYN && busCommandActive == false && pollDelta >= m_pollInterval) { if (busResult == RESULT_SYN && busCommandActive == false && pollDelta >= m_pollInterval) {
L.log(bus, trace, "polling Intervall reached"); L.log(bus, trace, "polling Intervall reached");
int index = m_commands->nextPolCommand(); int index = m_commands->nextPolCommand();
if (index < 0) { if (index < 0) {
L.log(bus, error, "polling index out of range"); L.log(bus, error, "polling index out of range");
time(&start); time(&pollStart);
continue; continue;
} }
@@ -145,7 +157,7 @@ void* EBusLoop::run()
busCommandActive = true; busCommandActive = true;
pollCommandActive = true; pollCommandActive = true;
time(&start); time(&pollStart);
} }
} }
@@ -192,7 +204,7 @@ void* EBusLoop::run()
} }
if (busResult == RESULT_ERR_SEND) if (busResult == RESULT_ERR_SEND)
L.log(bus, event, " getBus error"); L.log(bus, event, " getBus send error");
} else { } else {
sleep(10); sleep(10);
+1
View File
@@ -54,6 +54,7 @@ private:
int m_retries; int m_retries;
int m_lookbusretries; int m_lookbusretries;
double m_pollInterval; double m_pollInterval;
bool m_logAutoSyn;
}; };
+5 -1
View File
@@ -89,9 +89,13 @@ void define_args()
Appl::type_string, Appl::opt_mandatory); Appl::type_string, Appl::opt_mandatory);
A.addItem("p_loglevel", Appl::Param("trace"), "", "loglevel", A.addItem("p_loglevel", Appl::Param("trace"), "", "loglevel",
"\tlog level - error|event|trace|debug (event)\n", "\tlog level - error|event|trace|debug (event)",
Appl::type_string, Appl::opt_mandatory); Appl::type_string, Appl::opt_mandatory);
A.addItem("p_logautosyn", Appl::Param(false), "", "logautosyn",
"log AUTO-SYN bytes\n",
Appl::type_bool, Appl::opt_none);
A.addItem("p_dump", Appl::Param(false), "D", "dump", A.addItem("p_dump", Appl::Param(false), "D", "dump",
"\tenable dump", "\tenable dump",
Appl::type_bool, Appl::opt_none); Appl::type_bool, Appl::opt_none);