mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-13 05:53:06 +01:00
handle receiving and distributing on NMEA messages
This commit is contained in:
@@ -175,7 +175,7 @@ void GwSocketServer::begin(){
|
||||
MDNS.addService("_nmea-0183","_tcp",config->getInt(config->serverPort));
|
||||
|
||||
}
|
||||
void GwSocketServer::loop()
|
||||
void GwSocketServer::loop(bool handleRead)
|
||||
{
|
||||
WiFiClient client = server->available(); // listen for incoming clients
|
||||
|
||||
@@ -228,7 +228,7 @@ void GwSocketServer::loop()
|
||||
}
|
||||
else
|
||||
{
|
||||
client->read();
|
||||
if (handleRead) client->read();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -245,12 +245,6 @@ bool GwSocketServer::readMessages(GwBufferWriter *writer){
|
||||
}
|
||||
void GwSocketServer::sendToClients(const char *buf,int source){
|
||||
int len=strlen(buf);
|
||||
char buffer[len+2];
|
||||
memcpy(buffer,buf,len);
|
||||
buffer[len]=0x0d;
|
||||
len++;
|
||||
buffer[len]=0x0a;
|
||||
len++;
|
||||
int sourceIndex=source-minId;
|
||||
for (int i = 0; i < maxClients; i++)
|
||||
{
|
||||
@@ -258,7 +252,7 @@ void GwSocketServer::sendToClients(const char *buf,int source){
|
||||
gwClientPtr client = clients[i];
|
||||
if (! client->hasClient()) continue;
|
||||
if ( client->client->connected() ) {
|
||||
bool rt=client->enqueue((uint8_t*)buffer,len);
|
||||
bool rt=client->enqueue((uint8_t*)buf,len);
|
||||
if (!rt){
|
||||
LOG_DEBUG(GwLog::DEBUG,"overflow in send to %s",client->remoteIp.c_str());
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class GwSocketServer{
|
||||
GwSocketServer(const GwConfigHandler *config,GwLog *logger,int minId);
|
||||
~GwSocketServer();
|
||||
void begin();
|
||||
void loop();
|
||||
void loop(bool handleRead=true);
|
||||
void sendToClients(const char *buf,int sourceId);
|
||||
int numClients();
|
||||
bool readMessages(GwBufferWriter *writer);
|
||||
|
||||
Reference in New Issue
Block a user