mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2026-02-11 07:03:07 +01:00
make birectional channels the default, clean up some channel handling
This commit is contained in:
@@ -249,3 +249,16 @@ unsigned long GwChannel::countTx(){
|
|||||||
if (! countOut) return 0UL;
|
if (! countOut) return 0UL;
|
||||||
return countOut->getGlobal();
|
return countOut->getGlobal();
|
||||||
}
|
}
|
||||||
|
String GwChannel::typeString(int type){
|
||||||
|
switch (type){
|
||||||
|
case GWSERIAL_TYPE_UNI:
|
||||||
|
return "UNI";
|
||||||
|
case GWSERIAL_TYPE_BI:
|
||||||
|
return "BI";
|
||||||
|
case GWSERIAL_TYPE_RX:
|
||||||
|
return "RX";
|
||||||
|
case GWSERIAL_TYPE_TX:
|
||||||
|
return "TX";
|
||||||
|
}
|
||||||
|
return "UNKNOWN";
|
||||||
|
}
|
||||||
@@ -77,7 +77,8 @@ class GwChannel{
|
|||||||
if (maxSourceId < 0) return source == sourceId;
|
if (maxSourceId < 0) return source == sourceId;
|
||||||
return (source >= sourceId && source <= maxSourceId);
|
return (source >= sourceId && source <= maxSourceId);
|
||||||
}
|
}
|
||||||
String getMode(){return impl->getMode();}
|
static String typeString(int type);
|
||||||
|
String getMode(){return typeString(impl->getType());}
|
||||||
int getMinId(){return sourceId;};
|
int getMinId(){return sourceId;};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "GwBuffer.h"
|
#include "GwBuffer.h"
|
||||||
|
#include "GwChannelModes.h"
|
||||||
class GwChannelInterface{
|
class GwChannelInterface{
|
||||||
public:
|
public:
|
||||||
virtual void loop(bool handleRead,bool handleWrite)=0;
|
virtual void loop(bool handleRead,bool handleWrite)=0;
|
||||||
virtual void readMessages(GwMessageFetcher *writer)=0;
|
virtual void readMessages(GwMessageFetcher *writer)=0;
|
||||||
virtual size_t sendToClients(const char *buffer, int sourceId, bool partial=false)=0;
|
virtual size_t sendToClients(const char *buffer, int sourceId, bool partial=false)=0;
|
||||||
virtual Stream * getStream(bool partialWrites){ return NULL;}
|
virtual Stream * getStream(bool partialWrites){ return NULL;}
|
||||||
virtual String getMode(){return "UNKNOWN";}
|
virtual int getType(){ return GWSERIAL_TYPE_BI;} //return the numeric type
|
||||||
virtual int getType()=0; //return the numeric type
|
|
||||||
};
|
};
|
||||||
23
lib/hardware/GwChannelModes.h
Normal file
23
lib/hardware/GwChannelModes.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
This code is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
This code is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
defines for the channel modes(types)
|
||||||
|
*/
|
||||||
|
#ifndef _GWCHANNELMODES_H
|
||||||
|
#define _GWCHANNELMODES_H
|
||||||
|
#define GWSERIAL_TYPE_UNI 1
|
||||||
|
#define GWSERIAL_TYPE_BI 2
|
||||||
|
#define GWSERIAL_TYPE_RX 3
|
||||||
|
#define GWSERIAL_TYPE_TX 4
|
||||||
|
#define GWSERIAL_TYPE_UNK 0
|
||||||
|
#endif
|
||||||
@@ -20,11 +20,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#ifndef _GWHARDWARE_H
|
#ifndef _GWHARDWARE_H
|
||||||
#define _GWHARDWARE_H
|
#define _GWHARDWARE_H
|
||||||
#define GWSERIAL_TYPE_UNI 1
|
#include "GwChannelModes.h"
|
||||||
#define GWSERIAL_TYPE_BI 2
|
|
||||||
#define GWSERIAL_TYPE_RX 3
|
|
||||||
#define GWSERIAL_TYPE_TX 4
|
|
||||||
#define GWSERIAL_TYPE_UNK 0
|
|
||||||
#include <GwConfigItem.h>
|
#include <GwConfigItem.h>
|
||||||
#include <HardwareSerial.h>
|
#include <HardwareSerial.h>
|
||||||
#include "GwAppInfo.h"
|
#include "GwAppInfo.h"
|
||||||
|
|||||||
@@ -66,19 +66,6 @@ GwSerial::~GwSerial()
|
|||||||
if (lock != nullptr) vSemaphoreDelete(lock);
|
if (lock != nullptr) vSemaphoreDelete(lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
String GwSerial::getMode(){
|
|
||||||
switch (type){
|
|
||||||
case GWSERIAL_TYPE_UNI:
|
|
||||||
return "UNI";
|
|
||||||
case GWSERIAL_TYPE_BI:
|
|
||||||
return "BI";
|
|
||||||
case GWSERIAL_TYPE_RX:
|
|
||||||
return "RX";
|
|
||||||
case GWSERIAL_TYPE_TX:
|
|
||||||
return "TX";
|
|
||||||
}
|
|
||||||
return "UNKNOWN";
|
|
||||||
}
|
|
||||||
int GwSerial::getType() {
|
int GwSerial::getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ class GwSerial : public GwChannelInterface{
|
|||||||
virtual Stream *getStream(bool partialWrites);
|
virtual Stream *getStream(bool partialWrites);
|
||||||
bool getAvailableWrite(){return availableWrite;}
|
bool getAvailableWrite(){return availableWrite;}
|
||||||
virtual void begin(unsigned long baud, uint32_t config=SERIAL_8N1, int8_t rxPin=-1, int8_t txPin=-1)=0;
|
virtual void begin(unsigned long baud, uint32_t config=SERIAL_8N1, int8_t rxPin=-1, int8_t txPin=-1)=0;
|
||||||
virtual String getMode() override;
|
|
||||||
virtual int getType() override;
|
virtual int getType() override;
|
||||||
friend GwSerialStream;
|
friend GwSerialStream;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include "GwBuffer.h"
|
#include "GwBuffer.h"
|
||||||
#include "GwSocketConnection.h"
|
#include "GwSocketConnection.h"
|
||||||
#include "GwSocketHelper.h"
|
#include "GwSocketHelper.h"
|
||||||
#include "GwHardware.h"
|
|
||||||
|
|
||||||
GwSocketServer::GwSocketServer(const GwConfigHandler *config, GwLog *logger, int minId)
|
GwSocketServer::GwSocketServer(const GwConfigHandler *config, GwLog *logger, int minId)
|
||||||
{
|
{
|
||||||
@@ -187,5 +186,3 @@ int GwSocketServer::numClients()
|
|||||||
GwSocketServer::~GwSocketServer()
|
GwSocketServer::~GwSocketServer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int GwSocketServer::getType() {return GWSERIAL_TYPE_BI;}
|
|
||||||
@@ -27,6 +27,5 @@ class GwSocketServer: public GwChannelInterface{
|
|||||||
virtual size_t sendToClients(const char *buf,int sourceId, bool partialWrite=false);
|
virtual size_t sendToClients(const char *buf,int sourceId, bool partialWrite=false);
|
||||||
int numClients();
|
int numClients();
|
||||||
virtual void readMessages(GwMessageFetcher *writer);
|
virtual void readMessages(GwMessageFetcher *writer);
|
||||||
virtual int getType() override;
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <ESPmDNS.h>
|
#include <ESPmDNS.h>
|
||||||
#include "GwSocketHelper.h"
|
#include "GwSocketHelper.h"
|
||||||
#include "GwHardware.h"
|
|
||||||
|
|
||||||
class ResolveArgs{
|
class ResolveArgs{
|
||||||
public:
|
public:
|
||||||
@@ -293,5 +292,3 @@ GwTcpClient::ResolvedAddress GwTcpClient::getResolved(){
|
|||||||
GWSYNCHRONIZED(locker);
|
GWSYNCHRONIZED(locker);
|
||||||
return resolvedAddress;
|
return resolvedAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GwTcpClient::getType(){return GWSERIAL_TYPE_BI;}
|
|
||||||
@@ -53,5 +53,4 @@ public:
|
|||||||
virtual void readMessages(GwMessageFetcher *writer);
|
virtual void readMessages(GwMessageFetcher *writer);
|
||||||
bool isConnected();
|
bool isConnected();
|
||||||
String getError(){return error;}
|
String getError(){return error;}
|
||||||
virtual int getType() override;
|
|
||||||
};
|
};
|
||||||
@@ -5,8 +5,6 @@
|
|||||||
#include "GwSocketConnection.h"
|
#include "GwSocketConnection.h"
|
||||||
#include "GwSocketHelper.h"
|
#include "GwSocketHelper.h"
|
||||||
#include "GWWifi.h"
|
#include "GWWifi.h"
|
||||||
#include "GwHardware.h"
|
|
||||||
|
|
||||||
|
|
||||||
GwUdpReader::GwUdpReader(const GwConfigHandler *config, GwLog *logger, int minId)
|
GwUdpReader::GwUdpReader(const GwConfigHandler *config, GwLog *logger, int minId)
|
||||||
{
|
{
|
||||||
@@ -165,5 +163,4 @@ size_t GwUdpReader::sendToClients(const char *buf, int source,bool partial)
|
|||||||
|
|
||||||
GwUdpReader::~GwUdpReader()
|
GwUdpReader::~GwUdpReader()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
int GwUdpReader::getType(){return GWSERIAL_TYPE_BI;}
|
|
||||||
@@ -41,6 +41,5 @@ class GwUdpReader: public GwChannelInterface{
|
|||||||
virtual void loop(bool handleRead=true,bool handleWrite=true);
|
virtual void loop(bool handleRead=true,bool handleWrite=true);
|
||||||
virtual size_t sendToClients(const char *buf,int sourceId, bool partialWrite=false);
|
virtual size_t sendToClients(const char *buf,int sourceId, bool partialWrite=false);
|
||||||
virtual void readMessages(GwMessageFetcher *writer);
|
virtual void readMessages(GwMessageFetcher *writer);
|
||||||
virtual int getType() override;
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -5,7 +5,6 @@
|
|||||||
#include "GwSocketConnection.h"
|
#include "GwSocketConnection.h"
|
||||||
#include "GwSocketHelper.h"
|
#include "GwSocketHelper.h"
|
||||||
#include "GWWifi.h"
|
#include "GWWifi.h"
|
||||||
#include "GwHardware.h"
|
|
||||||
|
|
||||||
GwUdpWriter::WriterSocket::WriterSocket(GwLog *l,int p,const String &src,const String &dst, SourceMode sm) :
|
GwUdpWriter::WriterSocket::WriterSocket(GwLog *l,int p,const String &src,const String &dst, SourceMode sm) :
|
||||||
sourceMode(sm), source(src), destination(dst), port(p),logger(l)
|
sourceMode(sm), source(src), destination(dst), port(p),logger(l)
|
||||||
@@ -202,5 +201,3 @@ size_t GwUdpWriter::sendToClients(const char *buf, int source,bool partial)
|
|||||||
GwUdpWriter::~GwUdpWriter()
|
GwUdpWriter::~GwUdpWriter()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int GwUdpWriter::getType() {return GWSERIAL_TYPE_BI;}
|
|
||||||
@@ -69,6 +69,5 @@ class GwUdpWriter: public GwChannelInterface{
|
|||||||
virtual void loop(bool handleRead=true,bool handleWrite=true);
|
virtual void loop(bool handleRead=true,bool handleWrite=true);
|
||||||
virtual size_t sendToClients(const char *buf,int sourceId, bool partialWrite=false);
|
virtual size_t sendToClients(const char *buf,int sourceId, bool partialWrite=false);
|
||||||
virtual void readMessages(GwMessageFetcher *writer);
|
virtual void readMessages(GwMessageFetcher *writer);
|
||||||
virtual int getType() override;
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user