mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
tidy up TODOs
This commit is contained in:
@@ -7,27 +7,30 @@
|
||||
// #undef LOCAL_LOG_LEVEL
|
||||
#include "Logging.h"
|
||||
|
||||
ModbusClientTCPasync::ModbusClientTCPasync(IPAddress address, uint16_t port, uint16_t queueLimit) :
|
||||
ModbusClient(),
|
||||
txQueue(),
|
||||
rxQueue(),
|
||||
MTA_client(),
|
||||
MTA_timeout(DEFAULTTIMEOUT),
|
||||
MTA_idleTimeout(DEFAULTIDLETIME),
|
||||
MTA_qLimit(queueLimit),
|
||||
MTA_maxInflightRequests(queueLimit),
|
||||
MTA_lastActivity(0),
|
||||
MTA_state(DISCONNECTED),
|
||||
MTA_host(address),
|
||||
MTA_port(port)
|
||||
{
|
||||
ModbusClientTCPasync::ModbusClientTCPasync(IPAddress address, uint16_t port, uint16_t queueLimit)
|
||||
: ModbusClient()
|
||||
, txQueue()
|
||||
, rxQueue()
|
||||
, MTA_client()
|
||||
, MTA_timeout(DEFAULTTIMEOUT)
|
||||
, MTA_idleTimeout(DEFAULTIDLETIME)
|
||||
, MTA_qLimit(queueLimit)
|
||||
, MTA_maxInflightRequests(queueLimit)
|
||||
, MTA_lastActivity(0)
|
||||
, MTA_state(DISCONNECTED)
|
||||
, MTA_host(address)
|
||||
, MTA_port(port) {
|
||||
// attach all handlers on async tcp events
|
||||
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.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.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);
|
||||
|
||||
// disable nagle algorithm ref Modbus spec
|
||||
@@ -97,8 +100,7 @@ void ModbusClientTCPasync::setMaxInflightRequests(uint32_t maxInflightRequests)
|
||||
}
|
||||
|
||||
// Remove all pending request from queue
|
||||
void ModbusClientTCPasync::clearQueue()
|
||||
{
|
||||
void ModbusClientTCPasync::clearQueue() {
|
||||
LOCK_GUARD(lock1, qLock);
|
||||
LOCK_GUARD(lock2, sLock);
|
||||
// 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) {
|
||||
HEXDUMP_V("Enqueue", request.data(), request.size());
|
||||
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
|
||||
re->head.transactionID = messageCount++;
|
||||
re->head.len = request.size();
|
||||
@@ -246,9 +249,7 @@ void ModbusClientTCPasync::onPacket(uint8_t* data, size_t length) {
|
||||
transactionID = (data[0] << 8) | data[1];
|
||||
protocolID = (data[2] << 8) | data[3];
|
||||
messageLength = (data[4] << 8) | data[5];
|
||||
if (protocolID == 0 &&
|
||||
length >= (uint32_t)messageLength + 6 &&
|
||||
messageLength < 256) {
|
||||
if (protocolID == 0 && length >= (uint32_t)messageLength + 6 && messageLength < 256) {
|
||||
response = new ModbusMessage(messageLength);
|
||||
response->add(&data[6], messageLength);
|
||||
LOG_D("packet validated (len:%d)\n", messageLength);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/**
|
||||
* TODO:
|
||||
* - verwendete libs in readme hinzufügen
|
||||
* TODO: verwendete libs in readme hinzufügen
|
||||
*/
|
||||
#include "modbus.h"
|
||||
#include "modbus_entity_parameters.hpp"
|
||||
|
||||
Reference in New Issue
Block a user