mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 08:49:52 +03:00
update eModbus to 1.7.2, #2254
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
#endif
|
||||
#include <vector>
|
||||
|
||||
#include <Arduino.h> // for millis()
|
||||
#include <Arduino.h> // for millis()
|
||||
|
||||
#if defined(ESP32)
|
||||
#include <AsyncTCP.h>
|
||||
@@ -29,64 +29,64 @@ using std::lock_guard;
|
||||
#endif
|
||||
|
||||
class ModbusServerTCPasync : public ModbusServer {
|
||||
private:
|
||||
class mb_client {
|
||||
friend class ModbusServerTCPasync;
|
||||
|
||||
public:
|
||||
mb_client(ModbusServerTCPasync * s, AsyncClient * c);
|
||||
~mb_client();
|
||||
private:
|
||||
class mb_client {
|
||||
friend class ModbusServerTCPasync;
|
||||
|
||||
public:
|
||||
mb_client(ModbusServerTCPasync* s, AsyncClient* c);
|
||||
~mb_client();
|
||||
|
||||
private:
|
||||
void onData(uint8_t * data, size_t len);
|
||||
void onPoll();
|
||||
void onDisconnect();
|
||||
void addResponseToOutbox(ModbusMessage * response);
|
||||
void handleOutbox();
|
||||
ModbusServerTCPasync * server;
|
||||
AsyncClient * client;
|
||||
uint32_t lastActiveTime;
|
||||
ModbusMessage * message;
|
||||
Modbus::Error error;
|
||||
std::queue<ModbusMessage *> outbox;
|
||||
#if USE_MUTEX
|
||||
std::mutex obLock; // outbox protection
|
||||
#endif
|
||||
};
|
||||
private:
|
||||
void onData(uint8_t* data, size_t len);
|
||||
void onPoll();
|
||||
void onDisconnect();
|
||||
void addResponseToOutbox(ModbusMessage* response);
|
||||
void handleOutbox();
|
||||
ModbusServerTCPasync* server;
|
||||
AsyncClient* client;
|
||||
uint32_t lastActiveTime;
|
||||
ModbusMessage* message;
|
||||
Modbus::Error error;
|
||||
std::queue<ModbusMessage*> outbox;
|
||||
#if USE_MUTEX
|
||||
std::mutex obLock; // outbox protection
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
ModbusServerTCPasync();
|
||||
public:
|
||||
// Constructor
|
||||
ModbusServerTCPasync();
|
||||
|
||||
// Destructor: closes the connections
|
||||
~ModbusServerTCPasync();
|
||||
// Destructor: closes the connections
|
||||
~ModbusServerTCPasync();
|
||||
|
||||
// activeClients: return number of clients currently employed
|
||||
uint16_t activeClients();
|
||||
// activeClients: return number of clients currently employed
|
||||
uint16_t activeClients();
|
||||
|
||||
// start: create task with TCP server to accept requests
|
||||
bool start(uint16_t port, uint8_t max_clients, uint32_t timeout, int coreID = -1);
|
||||
// start: create task with TCP server to accept requests
|
||||
bool start(uint16_t port, uint8_t maxClients, uint32_t timeout, int coreID = -1);
|
||||
|
||||
// stop: drop all connections and kill server task
|
||||
bool stop();
|
||||
// stop: drop all connections and kill server task
|
||||
bool stop();
|
||||
|
||||
// isRunning: return true is server is running
|
||||
bool isRunning();
|
||||
|
||||
// isRunning: return true is server is running
|
||||
bool isRunning();
|
||||
protected:
|
||||
inline void isInstance() { }
|
||||
void onClientConnect(AsyncClient* client);
|
||||
void onClientDisconnect(mb_client* client);
|
||||
|
||||
protected:
|
||||
inline void isInstance() {
|
||||
}
|
||||
void onClientConnect(AsyncClient * client);
|
||||
void onClientDisconnect(mb_client * client);
|
||||
|
||||
AsyncServer * server;
|
||||
std::list<mb_client *> clients;
|
||||
uint8_t maxNoClients;
|
||||
uint32_t idle_timeout;
|
||||
#if USE_MUTEX
|
||||
std::mutex cListLock; // client list protection
|
||||
#endif
|
||||
AsyncServer* server;
|
||||
std::list<mb_client*> clients;
|
||||
uint8_t maxNoClients;
|
||||
uint32_t idle_timeout;
|
||||
#if USE_MUTEX
|
||||
std::mutex cListLock; // client list protection
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user