1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-16 07:23:07 +01:00

introduce tcp client

This commit is contained in:
wellenvogel
2021-12-29 19:52:08 +01:00
parent 31798e3bec
commit 0ba05accdc
4 changed files with 283 additions and 67 deletions

View File

@@ -0,0 +1,38 @@
#pragma once
#include "GwSocketConnection.h"
class GwTcpClient
{
static const unsigned long CON_TIMEOUT=10;
GwSocketConnection *connection = NULL;
IPAddress remoteAddress;
uint16_t port = 0;
unsigned long connectStart=0;
GwLog *logger;
int sourceId;
bool configured=false;
public:
typedef enum
{
C_DISABLED = 0,
C_INITIALIZED = 1,
C_CONNECTING = 2,
C_CONNECTED = 3
} State;
private:
State state = C_DISABLED;
void stop();
void startConnection();
void checkConnection();
bool hasConfig();
public:
GwTcpClient(GwLog *logger);
~GwTcpClient();
void begin(int sourceId,IPAddress address, uint16_t port,bool allowRead);
void loop(bool handleRead=true,bool handleWrite=true);
void sendToClients(const char *buf,int sourceId);
bool readMessages(GwMessageFetcher *writer);
bool isConnected();
};