diff --git a/configure.ac b/configure.ac index 37d4ab21..c9a30b66 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ AC_INIT([ebusd], [0.5.0], [ebusd@liwest.at], [ebusd], [https://github.com/yuhu-/ AC_PROG_CXX AC_CONFIG_AUX_DIR([build]) -AC_CONFIG_SRCDIR([src/ebusd/main.cpp]) +AC_CONFIG_SRCDIR([src/ebusd/ebusd.cpp]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/lib/ebus/Makefile diff --git a/src/ebusd/Makefile.am b/src/ebusd/Makefile.am index 742edf10..bf57211a 100644 --- a/src/ebusd/Makefile.am +++ b/src/ebusd/Makefile.am @@ -15,7 +15,7 @@ ebusd_SOURCES = message.h \ ebusloop.h \ baseloop.cpp \ baseloop.h \ - main.cpp + ebusd.cpp ebusd_LDADD = $(top_srcdir)/src/lib/utils/libutils.a \ $(top_srcdir)/src/lib/ebus/libebus.a \ diff --git a/src/ebusd/main.cpp b/src/ebusd/ebusd.cpp similarity index 96% rename from src/ebusd/main.cpp rename to src/ebusd/ebusd.cpp index 459c5579..6aa90d8c 100644 --- a/src/ebusd/main.cpp +++ b/src/ebusd/ebusd.cpp @@ -60,7 +60,11 @@ void define_args() Appl::type_int, Appl::opt_mandatory); A.addItem("p_recvtimeout", Appl::Param(15000), "", "recvtimeout", - "receive timeout in 'us' (15000)\n", + "receive timeout in 'us' (15000)", + Appl::type_long, Appl::opt_mandatory); + + A.addItem("p_acquiretime", Appl::Param(4200), "", "acquiretime", + "waiting time for bus acquire in 'us' (4200)\n", Appl::type_long, Appl::opt_mandatory); A.addItem("p_pollinterval", Appl::Param(5), "", "pollinterval", diff --git a/src/ebusd/ebusloop.cpp b/src/ebusd/ebusloop.cpp index 6a2f04ab..793a0f4a 100644 --- a/src/ebusd/ebusloop.cpp +++ b/src/ebusd/ebusloop.cpp @@ -45,6 +45,8 @@ EBusLoop::EBusLoop(Commands* commands) m_sendRetries = A.getParam("p_sendretries"); m_lockRetries = A.getParam("p_lockretries"); + + m_acquireTime = A.getParam("p_acquiretime"); } EBusLoop::~EBusLoop() @@ -111,18 +113,18 @@ void* EBusLoop::run() busCommand->setResult(std::string(), RESULT_OK); } else { + sendRetries = 0; L.log(bus, event, " send retry failed", sendRetries); if (busCommand->isPoll() == true) delete m_sendBuffer.remove(); else busCommand->sendSignal(); - - sendRetries = 0; } } else { sendRetries = 0; + if (busCommand->isPoll() == true) { m_commands->storePolData(busCommand->getMessageStr().c_str()); // TODO use getResult() delete busCommand; @@ -138,14 +140,14 @@ void* EBusLoop::run() L.log(bus, trace, " acquire bus failed"); if (lockRetries >= m_lockRetries) { + lockRetries = 0; L.log(bus, event, " lock bus failed"); + BusCommand* busCommand = m_sendBuffer.remove(); if (busCommand->isPoll() == true) delete busCommand; else busCommand->sendSignal(); - - lockRetries = 0; } else { lockRetries++; @@ -294,6 +296,9 @@ int EBusLoop::acquireBus() return RESULT_ERR_SEND; } + // wait ~4200 usec for receive + usleep(m_acquireTime); + // receive 1 byte - must be QQ numRecv = m_port->recv(0); diff --git a/src/ebusd/ebusloop.h b/src/ebusd/ebusloop.h index 1605451e..95c9731d 100644 --- a/src/ebusd/ebusloop.h +++ b/src/ebusd/ebusloop.h @@ -71,6 +71,7 @@ private: long m_recvTimeout; int m_sendRetries; int m_lockRetries; + long m_acquireTime; unsigned char fetchByte(); void collectCycData(const int numRecv);