tidy up TODOs

This commit is contained in:
proddy
2024-09-09 17:46:13 +02:00
parent 5fae9872e6
commit 54d8c5ad8f
2 changed files with 294 additions and 294 deletions

View File

@@ -7,27 +7,30 @@
// #undef LOCAL_LOG_LEVEL // #undef LOCAL_LOG_LEVEL
#include "Logging.h" #include "Logging.h"
ModbusClientTCPasync::ModbusClientTCPasync(IPAddress address, uint16_t port, uint16_t queueLimit) : ModbusClientTCPasync::ModbusClientTCPasync(IPAddress address, uint16_t port, uint16_t queueLimit)
ModbusClient(), : ModbusClient()
txQueue(), , txQueue()
rxQueue(), , rxQueue()
MTA_client(), , MTA_client()
MTA_timeout(DEFAULTTIMEOUT), , MTA_timeout(DEFAULTTIMEOUT)
MTA_idleTimeout(DEFAULTIDLETIME), , MTA_idleTimeout(DEFAULTIDLETIME)
MTA_qLimit(queueLimit), , MTA_qLimit(queueLimit)
MTA_maxInflightRequests(queueLimit), , MTA_maxInflightRequests(queueLimit)
MTA_lastActivity(0), , MTA_lastActivity(0)
MTA_state(DISCONNECTED), , MTA_state(DISCONNECTED)
MTA_host(address), , MTA_host(address)
MTA_port(port) , MTA_port(port) {
{
// attach all handlers on async tcp events // attach all handlers on async tcp events
MTA_client.onConnect([](void * i, AsyncClient * c) { (static_cast<ModbusClientTCPasync *>(i))->onConnected(); }, this); MTA_client.onConnect([](void * i, AsyncClient * c) { (static_cast<ModbusClientTCPasync *>(i))->onConnected(); }, this);
MTA_client.onDisconnect([](void * i, AsyncClient * c) { (static_cast<ModbusClientTCPasync *>(i))->onDisconnected(); }, this); MTA_client.onDisconnect([](void * i, AsyncClient * c) { (static_cast<ModbusClientTCPasync *>(i))->onDisconnected(); }, this);
MTA_client.onError([](void * i, AsyncClient * c, int8_t error) { (static_cast<ModbusClientTCPasync *>(i))->onACError(c, error); }, this); MTA_client.onError([](void * i, AsyncClient * c, int8_t error) { (static_cast<ModbusClientTCPasync *>(i))->onACError(c, error); }, this);
// MTA_client.onTimeout([](void* i, AsyncClient* c, uint32_t time) { (static_cast<ModbusClientTCPasync*>(i))->onTimeout(time); }, this); // MTA_client.onTimeout([](void* i, AsyncClient* c, uint32_t time) { (static_cast<ModbusClientTCPasync*>(i))->onTimeout(time); }, this);
// MTA_client.onAck([](void* i, AsyncClient* c, size_t len, uint32_t time) { (static_cast<ModbusClientTCPasync*>(i))->onAck(len, time); }, this); // MTA_client.onAck([](void* i, AsyncClient* c, size_t len, uint32_t time) { (static_cast<ModbusClientTCPasync*>(i))->onAck(len, time); }, this);
MTA_client.onData([](void* i, AsyncClient* c, void* data, size_t len) { (static_cast<ModbusClientTCPasync*>(i))->onPacket(static_cast<uint8_t*>(data), len); }, this); MTA_client.onData([](void * i,
AsyncClient * c,
void * data,
size_t len) { (static_cast<ModbusClientTCPasync *>(i))->onPacket(static_cast<uint8_t *>(data), len); },
this);
MTA_client.onPoll([](void * i, AsyncClient * c) { (static_cast<ModbusClientTCPasync *>(i))->onPoll(); }, this); MTA_client.onPoll([](void * i, AsyncClient * c) { (static_cast<ModbusClientTCPasync *>(i))->onPoll(); }, this);
// disable nagle algorithm ref Modbus spec // disable nagle algorithm ref Modbus spec
@@ -97,8 +100,7 @@ void ModbusClientTCPasync::setMaxInflightRequests(uint32_t maxInflightRequests)
} }
// Remove all pending request from queue // Remove all pending request from queue
void ModbusClientTCPasync::clearQueue() void ModbusClientTCPasync::clearQueue() {
{
LOCK_GUARD(lock1, qLock); LOCK_GUARD(lock1, qLock);
LOCK_GUARD(lock2, sLock); LOCK_GUARD(lock2, sLock);
// Delete all elements from queues // Delete all elements from queues
@@ -152,7 +154,8 @@ bool ModbusClientTCPasync::addToQueue(int32_t token, ModbusMessage request, bool
if (txQueue.size() + rxQueue.size() < MTA_qLimit) { if (txQueue.size() + rxQueue.size() < MTA_qLimit) {
HEXDUMP_V("Enqueue", request.data(), request.size()); HEXDUMP_V("Enqueue", request.data(), request.size());
RequestEntry * re = new RequestEntry(token, request, syncReq); RequestEntry * re = new RequestEntry(token, request, syncReq);
if (!re) return false; //TODO: proper error returning in case allocation fails if (!re)
return false; // TODO: proper error returning in case allocation fails
// inject proper transactionID // inject proper transactionID
re->head.transactionID = messageCount++; re->head.transactionID = messageCount++;
re->head.len = request.size(); re->head.len = request.size();
@@ -246,9 +249,7 @@ void ModbusClientTCPasync::onPacket(uint8_t* data, size_t length) {
transactionID = (data[0] << 8) | data[1]; transactionID = (data[0] << 8) | data[1];
protocolID = (data[2] << 8) | data[3]; protocolID = (data[2] << 8) | data[3];
messageLength = (data[4] << 8) | data[5]; messageLength = (data[4] << 8) | data[5];
if (protocolID == 0 && if (protocolID == 0 && length >= (uint32_t)messageLength + 6 && messageLength < 256) {
length >= (uint32_t)messageLength + 6 &&
messageLength < 256) {
response = new ModbusMessage(messageLength); response = new ModbusMessage(messageLength);
response->add(&data[6], messageLength); response->add(&data[6], messageLength);
LOG_D("packet validated (len:%d)\n", messageLength); LOG_D("packet validated (len:%d)\n", messageLength);

View File

@@ -1,6 +1,5 @@
/** /**
* TODO: * TODO: verwendete libs in readme hinzufügen
* - verwendete libs in readme hinzufügen
*/ */
#include "modbus.h" #include "modbus.h"
#include "modbus_entity_parameters.hpp" #include "modbus_entity_parameters.hpp"