+42
-24
@@ -41,6 +41,8 @@ EBusLoop::EBusLoop(Commands* commands) : m_commands(commands), m_stop(false)
|
||||
|
||||
m_pollInterval = A.getParam<int>("p_pollinterval");
|
||||
|
||||
m_logAutoSyn = A.getParam<bool>("p_logautosyn");
|
||||
|
||||
m_bus->connect();
|
||||
|
||||
if (m_bus->isConnected() == false)
|
||||
@@ -63,8 +65,10 @@ void* EBusLoop::run()
|
||||
int retries = 0;
|
||||
int lookbusretries = 0;
|
||||
bool busCommandActive = false;
|
||||
time_t start, end;
|
||||
time(&start);
|
||||
|
||||
// polling
|
||||
time_t pollStart, pollEnd;
|
||||
time(&pollStart);
|
||||
double pollDelta = 0.0;
|
||||
bool pollCommandActive = false;
|
||||
|
||||
@@ -75,33 +79,41 @@ void* EBusLoop::run()
|
||||
busResult = m_bus->proceed();
|
||||
|
||||
// new cyc message arrived
|
||||
if (busResult == RESULT_SYN) {
|
||||
if (busResult == RESULT_SYN || busResult == RESULT_BUS_LOCKED) {
|
||||
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) {
|
||||
L.log(bus, debug, " command not found");
|
||||
if (data.size() != 0) {
|
||||
L.log(bus, trace, "%s", data.c_str());
|
||||
|
||||
} else if (index == -2) {
|
||||
L.log(bus, debug, " no commands defined");
|
||||
int index = m_commands->storeCycData(data);
|
||||
|
||||
} else if (index == -3) {
|
||||
L.log(bus, debug, " search skipped - string too short");
|
||||
if (index == -1) {
|
||||
L.log(bus, debug, " command not found");
|
||||
|
||||
} 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());
|
||||
} else if (index == -2) {
|
||||
L.log(bus, debug, " no commands defined");
|
||||
|
||||
} else if (index == -3) {
|
||||
L.log(bus, 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 [%d] %s", index, tmp.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if (busResult == RESULT_BUS_LOCKED)
|
||||
L.log(bus, trace, "bus locked");
|
||||
}
|
||||
|
||||
// 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();
|
||||
L.log(bus, debug, " type: %s msg: %s",
|
||||
busCommand->getTypeCStr(), busCommand->getCommand().c_str());
|
||||
@@ -113,17 +125,17 @@ void* EBusLoop::run()
|
||||
// add new polling command
|
||||
if (m_commands->sizePolDB() > 0) {
|
||||
// check polling delta
|
||||
time(&end);
|
||||
pollDelta = difftime(end, start);
|
||||
time(&pollEnd);
|
||||
pollDelta = difftime(pollEnd, pollStart);
|
||||
|
||||
// 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");
|
||||
|
||||
int index = m_commands->nextPolCommand();
|
||||
if (index < 0) {
|
||||
L.log(bus, error, "polling index out of range");
|
||||
time(&start);
|
||||
time(&pollStart);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -145,7 +157,7 @@ void* EBusLoop::run()
|
||||
busCommandActive = true;
|
||||
pollCommandActive = true;
|
||||
|
||||
time(&start);
|
||||
time(&pollStart);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -180,19 +192,25 @@ void* EBusLoop::run()
|
||||
}
|
||||
}
|
||||
|
||||
// get bus retry
|
||||
if (busResult == RESULT_BUS_PRIOR_RETRY)
|
||||
L.log(bus, trace, " getBus prior retry");
|
||||
|
||||
if (busResult == RESULT_ERR_BUS_LOST) {
|
||||
L.log(bus, trace, " getBus failure");
|
||||
if (lookbusretries >= m_lookbusretries) {
|
||||
L.log(bus, event, " getBus failed - command deleted");
|
||||
m_bus->delCommand();
|
||||
lookbusretries = 0;
|
||||
busCommandActive = false;
|
||||
pollCommandActive = false;
|
||||
}else {
|
||||
lookbusretries++;
|
||||
}
|
||||
}
|
||||
|
||||
if (busResult == RESULT_ERR_SEND)
|
||||
L.log(bus, event, " getBus error");
|
||||
L.log(bus, event, " getBus send error");
|
||||
|
||||
} else {
|
||||
sleep(10);
|
||||
|
||||
@@ -54,6 +54,7 @@ private:
|
||||
int m_retries;
|
||||
int m_lookbusretries;
|
||||
double m_pollInterval;
|
||||
bool m_logAutoSyn;
|
||||
|
||||
};
|
||||
|
||||
|
||||
+7
-3
@@ -52,8 +52,8 @@ void define_args()
|
||||
"\tnumber retries send ebus command (2)",
|
||||
Appl::type_int, Appl::opt_mandatory);
|
||||
|
||||
A.addItem("p_lookbusretries", Appl::Param(5), "", "lookbusretries",
|
||||
"number retries to look ebus (5)",
|
||||
A.addItem("p_lookbusretries", Appl::Param(2), "", "lookbusretries",
|
||||
"number retries to look ebus (2)",
|
||||
Appl::type_int, Appl::opt_mandatory);
|
||||
|
||||
A.addItem("p_recvtimeout", Appl::Param(15000), "", "recvtimeout",
|
||||
@@ -89,9 +89,13 @@ void define_args()
|
||||
Appl::type_string, Appl::opt_mandatory);
|
||||
|
||||
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);
|
||||
|
||||
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",
|
||||
"\tenable dump",
|
||||
Appl::type_bool, Appl::opt_none);
|
||||
|
||||
Reference in New Issue
Block a user