daemon option --lockcounter added; m_busLocked replaced with m_lockCounter.

This commit is contained in:
Roland Jax
2014-11-08 11:37:44 +01:00
parent e4544a98ad
commit ca6c6c04bb
4 changed files with 30 additions and 25 deletions
+24 -23
View File
@@ -25,7 +25,7 @@ extern LogInstance& L;
extern Appl& A; extern Appl& A;
EBusLoop::EBusLoop(Commands* commands) EBusLoop::EBusLoop(Commands* commands)
: m_commands(commands), m_stop(false), m_busLocked(false), m_priorRetry(false) : m_commands(commands), m_stop(false), m_lockCounter(0), m_priorRetry(false)
{ {
m_port = new Port(A.getParam<const char*>("p_device"), A.getParam<bool>("p_nodevicecheck")); m_port = new Port(A.getParam<const char*>("p_device"), A.getParam<bool>("p_nodevicecheck"));
m_port->open(); m_port->open();
@@ -70,7 +70,7 @@ void* EBusLoop::run()
if (m_port->isOpen() == true) { if (m_port->isOpen() == true) {
ssize_t numBytes; ssize_t numBytes;
// add poll command - timer reached // add poll command
if (m_commands->sizePolDB() > 0) { if (m_commands->sizePolDB() > 0) {
// check polling delta // check polling delta
time(&pollEnd); time(&pollEnd);
@@ -95,7 +95,7 @@ void* EBusLoop::run()
collectCycData(numBytes); collectCycData(numBytes);
// send command // send command
if (m_sstr.size() == 0 && m_busLocked == false && m_sendBuffer.size() > 0) { if (m_sstr.size() == 0 && m_lockCounter == 0 && m_sendBuffer.size() > 0) {
// acquire Bus // acquire Bus
int busResult = acquireBus(); int busResult = acquireBus();
@@ -129,9 +129,11 @@ void* EBusLoop::run()
} }
lockRetries = 0; lockRetries = 0;
m_lockCounter = A.getParam<int>("p_lockcounter");
} }
else { else if (busResult == RESULT_ERR_BUS_LOST) {
L.log(bus, trace, " acquire bus failed"); L.log(bus, trace, " acquire bus failed");
if (lockRetries >= m_lockRetries) { if (lockRetries >= m_lockRetries) {
L.log(bus, event, " lock bus failed"); L.log(bus, event, " lock bus failed");
BusCommand* busCommand = m_sendBuffer.remove(); BusCommand* busCommand = m_sendBuffer.remove();
@@ -147,6 +149,7 @@ void* EBusLoop::run()
L.log(bus, trace, " lock retry %d", lockRetries); L.log(bus, trace, " lock retry %d", lockRetries);
} }
m_lockCounter = A.getParam<int>("p_lockcounter");
} }
} }
@@ -198,32 +201,30 @@ void EBusLoop::collectCycData(const int numRecv)
// fetch byte // fetch byte
unsigned char byte = fetchByte(); unsigned char byte = fetchByte();
// collect cycle data if (byte == SYN) {
if (byte != SYN)
m_sstr.push_back(byte, true, false);
// unlock bus // analyse cycle data
if (byte == SYN && m_busLocked == true) { if (m_sstr.size() > 0) {
m_busLocked = false;
L.log(bus, trace, " bus unlocked");
}
// analyse cycle data analyseCycData();
if (byte == SYN && m_sstr.size() > 0) {
analyseCycData(); if (m_sstr.size() == 1 && m_lockCounter == 0 && m_priorRetry == false)
m_lockCounter++;
if (m_sstr.size() == 1) { else if (m_lockCounter > 0)
if (m_priorRetry == true) m_lockCounter--;
m_priorRetry = false;
else { m_sstr.clear();
m_busLocked = true;
L.log(bus, trace, " bus locked");
}
} }
m_sstr.clear(); else if (m_lockCounter > 0)
m_lockCounter--;
} }
// collect cycle data
else
m_sstr.push_back(byte, true, false);
} }
} }
+1 -1
View File
@@ -61,7 +61,7 @@ private:
bool m_stop; bool m_stop;
bool m_busLocked; int m_lockCounter;
bool m_priorRetry; bool m_priorRetry;
WQueue<BusCommand*> m_sendBuffer; WQueue<BusCommand*> m_sendBuffer;
+4
View File
@@ -55,6 +55,10 @@ void define_args()
"number retries to lock ebus (2)", "number retries to lock ebus (2)",
Appl::type_int, Appl::opt_mandatory); Appl::type_int, Appl::opt_mandatory);
A.addItem("p_lockcounter", Appl::Param(5), "", "lockcounter",
"number of SYN to unlock send function (5)",
Appl::type_int, Appl::opt_mandatory);
A.addItem("p_recvtimeout", Appl::Param(15000), "", "recvtimeout", A.addItem("p_recvtimeout", Appl::Param(15000), "", "recvtimeout",
"receive timeout in 'us' (15000)\n", "receive timeout in 'us' (15000)\n",
Appl::type_long, Appl::opt_mandatory); Appl::type_long, Appl::opt_mandatory);
+1 -1
View File
@@ -60,7 +60,7 @@ bool Device::isValid()
ssize_t Device::sendBytes(const unsigned char* buffer, size_t nbytes) ssize_t Device::sendBytes(const unsigned char* buffer, size_t nbytes)
{ {
if (isValid() == false) if (isValid() == false)
return -1; return -1; // TODO RESULT_ERR_DEVICE
// write bytes to device // write bytes to device
return write(m_fd, buffer, nbytes); return write(m_fd, buffer, nbytes);