Merge pull request #1 from yuhu-/master

merge
This commit is contained in:
John
2014-10-14 21:45:28 +02:00
3 changed files with 50 additions and 27 deletions
+28 -10
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,8 +79,13 @@ 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();
if (data.size() == 0 && m_logAutoSyn == true)
L.log(bus, trace, "%s", "aa");
if (data.size() != 0) {
L.log(bus, trace, "%s", data.c_str()); L.log(bus, trace, "%s", data.c_str());
int index = m_commands->storeCycData(data); int index = m_commands->storeCycData(data);
@@ -97,11 +106,14 @@ void* EBusLoop::run()
tmp += (*m_commands)[index][2]; tmp += (*m_commands)[index][2];
L.log(bus, event, " cycle [%d] %s", index, tmp.c_str()); 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);
} }
} }
@@ -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) { if (busResult == RESULT_ERR_BUS_LOST) {
L.log(bus, trace, " getBus failure"); L.log(bus, trace, " getBus failure");
if (lookbusretries >= m_lookbusretries) { if (lookbusretries >= m_lookbusretries) {
L.log(bus, event, " getBus failed - command deleted"); L.log(bus, event, " getBus failed - command deleted");
m_bus->delCommand(); m_bus->delCommand();
lookbusretries = 0; lookbusretries = 0;
busCommandActive = false;
pollCommandActive = false;
}else { }else {
lookbusretries++; lookbusretries++;
} }
} }
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;
}; };
+7 -3
View File
@@ -52,8 +52,8 @@ void define_args()
"\tnumber retries send ebus command (2)", "\tnumber retries send ebus command (2)",
Appl::type_int, Appl::opt_mandatory); Appl::type_int, Appl::opt_mandatory);
A.addItem("p_lookbusretries", Appl::Param(5), "", "lookbusretries", A.addItem("p_lookbusretries", Appl::Param(2), "", "lookbusretries",
"number retries to look ebus (5)", "number retries to look ebus (2)",
Appl::type_int, Appl::opt_mandatory); Appl::type_int, Appl::opt_mandatory);
A.addItem("p_recvtimeout", Appl::Param(15000), "", "recvtimeout", A.addItem("p_recvtimeout", Appl::Param(15000), "", "recvtimeout",
@@ -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);