mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-16 07:23:07 +01:00
intermediate: udp reader
This commit is contained in:
45
lib/socketserver/GwUdpReader.h
Normal file
45
lib/socketserver/GwUdpReader.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef _GWUDPREADER_H
|
||||
#define _GWUDPREADER_H
|
||||
#include "GWConfig.h"
|
||||
#include "GwLog.h"
|
||||
#include "GwBuffer.h"
|
||||
#include "GwChannelInterface.h"
|
||||
#include <memory>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
class GwUdpReader: public GwChannelInterface{
|
||||
public:
|
||||
using UType=enum{
|
||||
T_ALL=0,
|
||||
T_AP=1,
|
||||
T_STA=2,
|
||||
T_MCALL=4,
|
||||
T_MCAP=5,
|
||||
T_MCSTA=6,
|
||||
T_UNKNOWN=-1
|
||||
};
|
||||
private:
|
||||
const GwConfigHandler *config;
|
||||
GwLog *logger;
|
||||
int minId;
|
||||
int port;
|
||||
int fd=-1;
|
||||
struct sockaddr_in listenA;
|
||||
String listenIp;
|
||||
String currentStationIp;
|
||||
struct in_addr apAddr;
|
||||
struct in_addr staAddr;
|
||||
UType type=T_UNKNOWN;
|
||||
void createAndBind();
|
||||
bool setStationAdd(const String &sta);
|
||||
GwBuffer *buffer=nullptr;
|
||||
public:
|
||||
GwUdpReader(const GwConfigHandler *config,GwLog *logger,int minId);
|
||||
~GwUdpReader();
|
||||
void begin();
|
||||
virtual void loop(bool handleRead=true,bool handleWrite=true);
|
||||
virtual size_t sendToClients(const char *buf,int sourceId, bool partialWrite=false);
|
||||
virtual void readMessages(GwMessageFetcher *writer);
|
||||
};
|
||||
#endif
|
||||
Reference in New Issue
Block a user