mirror of
https://github.com/Show-maket/EthernetMaket.git
synced 2025-05-04 15:20:18 +00:00
56 lines
1.8 KiB
C++
56 lines
1.8 KiB
C++
#ifndef __MAKET_TCP_H__
|
|
#define __MAKET_TCP_H__
|
|
|
|
#include <list>
|
|
#include <functional>
|
|
#include "../util/config.h"
|
|
|
|
class EthernetMaketClient : public EthernetClient {
|
|
protected:
|
|
uint32_t lastActivityTime = 0; // Время последней активности
|
|
const uint16_t timeout = 300; // Таймаут неактивности в миллисекундах
|
|
uint32_t startConnectionTime = 0;
|
|
const uint16_t connectionTimeout = 350;
|
|
uint32_t stopStartTime = 0; // Время начала состояния CONNECT_IDLE
|
|
const uint32_t stopTimeout = 300; // Таймаут для закрытия сокета в состоянии CONNECT_IDLE
|
|
|
|
std::function<void()> onSendSuccess = []() {};
|
|
|
|
bool isNonBlocking = true; // Флаг для определения режима подключения
|
|
|
|
uint8_t* dataPtr = nullptr;
|
|
uint16_t dataSize = 0;
|
|
IPAddress dstIP;
|
|
uint16_t dstPort;
|
|
|
|
bool dataWrite();
|
|
|
|
static std::list<EthernetMaketClient*>& getInstances(); // Ленивое создание списка
|
|
|
|
void tick_();
|
|
|
|
public:
|
|
ConnectionStatusSimple connectStatus = CONNECT_IDLE;
|
|
EthernetMaketClient();
|
|
EthernetMaketClient(uint8_t sock);
|
|
~EthernetMaketClient();
|
|
|
|
ConnectionStatusSimple connectNonBlock(IPAddress ip, uint16_t port);
|
|
void startConnection(IPAddress ip, uint16_t port, bool nonBlock = true);
|
|
|
|
void dataWrite(uint8_t* data, uint16_t dataSize, bool override = false);
|
|
// bool send(uint8_t* data, uint16_t dataSize, IPAddress ip, uint16_t port);
|
|
|
|
void disconnect();
|
|
void close();
|
|
void stop();
|
|
bool isConnected() const;
|
|
|
|
static void tick();
|
|
|
|
void setOnSendSuccess(const std::function<void()>& callback);
|
|
void resetOnSendSuccess();
|
|
};
|
|
|
|
#endif // __MAKET_TCP_H__
|