limit number of handled telegrams per loop and wait time for #843
This commit is contained in:
+11
-10
@@ -451,10 +451,10 @@ void KnxHandler::sendGlobalValue(global_t index, unsigned int value, bool respon
|
|||||||
}
|
}
|
||||||
|
|
||||||
result_t KnxHandler::receiveTelegram(int maxlen, knx_transfer_t* typ, uint8_t *buf, int *recvlen,
|
result_t KnxHandler::receiveTelegram(int maxlen, knx_transfer_t* typ, uint8_t *buf, int *recvlen,
|
||||||
knx_addr_t *src, knx_addr_t *dest) {
|
knx_addr_t *src, knx_addr_t *dest, bool wait) {
|
||||||
struct timespec tdiff = {
|
struct timespec tdiff = {
|
||||||
.tv_sec = 2,
|
.tv_sec = wait ? 2 : 0, // 2 seconds when waiting
|
||||||
.tv_nsec = 0,
|
.tv_nsec = wait ? 0 : 1000, // 1 milliseond when not waiting
|
||||||
};
|
};
|
||||||
if (!m_con->isConnected()) {
|
if (!m_con->isConnected()) {
|
||||||
return RESULT_ERR_GENERIC_IO;
|
return RESULT_ERR_GENERIC_IO;
|
||||||
@@ -919,18 +919,19 @@ void KnxHandler::run() {
|
|||||||
knx_addr_t src, dest;
|
knx_addr_t src, dest;
|
||||||
knx_transfer_t typ;
|
knx_transfer_t typ;
|
||||||
// APDU data starting with octet 6 according to spec, contains 2 bits of application layer
|
// APDU data starting with octet 6 according to spec, contains 2 bits of application layer
|
||||||
result_t res = RESULT_OK;
|
// limit number of read telegrams in order to give back control to outer loop for checking updates etc
|
||||||
do {
|
for (int count = 0; count < 10; count++) {
|
||||||
res = receiveTelegram(sizeof(data), &typ, data, &len, &src, &dest);
|
// wait for telegram on first iteration only
|
||||||
|
result_t res = receiveTelegram(sizeof(data), &typ, data, &len, &src, &dest, count == 0);
|
||||||
if (res != RESULT_OK) {
|
if (res != RESULT_OK) {
|
||||||
if (res == RESULT_ERR_GENERIC_IO) {
|
if (res == RESULT_ERR_GENERIC_IO) {
|
||||||
m_con->close();
|
m_con->close();
|
||||||
}
|
}
|
||||||
} else {
|
break;
|
||||||
needsWait = false;
|
|
||||||
handleReceivedTelegram(typ, src, dest, len, data);
|
|
||||||
}
|
}
|
||||||
} while (res == RESULT_OK);
|
needsWait = false;
|
||||||
|
handleReceivedTelegram(typ, src, dest, len, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!m_updatedMessages.empty()) {
|
if (!m_updatedMessages.empty()) {
|
||||||
m_messages->lock();
|
m_messages->lock();
|
||||||
|
|||||||
@@ -170,11 +170,12 @@ class KnxHandler : public DataSink, public DataSource, public WaitThread {
|
|||||||
* @param recvlen pointer to a variable in which to store the actually received length.
|
* @param recvlen pointer to a variable in which to store the actually received length.
|
||||||
* @param src pointer to a variable in which to store the source address.
|
* @param src pointer to a variable in which to store the source address.
|
||||||
* @param dest pointer to a variable in which to store the destination group address.
|
* @param dest pointer to a variable in which to store the destination group address.
|
||||||
|
* @param wait true to wait up to 2 seconds for a new telegram, false to not wait.
|
||||||
* @return the result code, either RESULT_OK on success, RESULT_ERR_GENERIC_IO on I/O error (e.g. socket closed),
|
* @return the result code, either RESULT_OK on success, RESULT_ERR_GENERIC_IO on I/O error (e.g. socket closed),
|
||||||
* or RESULT_ERR_TIMEOUT if no data is available.
|
* or RESULT_ERR_TIMEOUT if no data is available.
|
||||||
*/
|
*/
|
||||||
result_t receiveTelegram(int maxlen, knx_transfer_t* typ, uint8_t *buf, int *recvlen, knx_addr_t *src,
|
result_t receiveTelegram(int maxlen, knx_transfer_t* typ, uint8_t *buf, int *recvlen, knx_addr_t *src,
|
||||||
knx_addr_t *dest);
|
knx_addr_t *dest, bool wait = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle a received KNX telegram.
|
* Handle a received KNX telegram.
|
||||||
|
|||||||
Reference in New Issue
Block a user