mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-14 06:23:07 +01:00
intermediate: restructure serial handling
This commit is contained in:
@@ -40,10 +40,10 @@ class GwSerialStream: public Stream{
|
||||
|
||||
|
||||
|
||||
GwSerial::GwSerial(GwLog *logger, Stream *s, int id,bool allowRead):serial(s)
|
||||
GwSerial::GwSerial(GwLog *logger, GwSerial::SerialWrapperBase *s, bool allowRead):serial(s)
|
||||
{
|
||||
LOG_DEBUG(GwLog::DEBUG,"creating GwSerial %p id %d",this,id);
|
||||
this->id=id;
|
||||
this->id=s->getId();
|
||||
this->logger = logger;
|
||||
String bufName="Ser(";
|
||||
bufName+=String(id);
|
||||
|
||||
@@ -16,11 +16,27 @@ class GwSerial : public GwChannelInterface{
|
||||
int id=-1;
|
||||
int overflows=0;
|
||||
size_t enqueue(const uint8_t *data, size_t len,bool partial=false);
|
||||
Stream *serial;
|
||||
bool availableWrite=false; //if this is false we will wait for availabkleWrite until we flush again
|
||||
public:
|
||||
class SerialWrapperBase{
|
||||
public:
|
||||
virtual void begin(GwLog* logger,unsigned long baud, uint32_t config=SERIAL_8N1, int8_t rxPin=-1, int8_t txPin=-1)=0;
|
||||
virtual int getId()=0;
|
||||
virtual int available(){return getStream()->available();}
|
||||
size_t readBytes(uint8_t *buffer, size_t length){
|
||||
return getStream()->readBytes(buffer,length);
|
||||
}
|
||||
virtual int availableForWrite(void){
|
||||
return getStream()->availableForWrite();
|
||||
}
|
||||
size_t write(const uint8_t *buffer, size_t size){
|
||||
return getStream()->write(buffer,size);
|
||||
}
|
||||
private:
|
||||
virtual Stream *getStream()=0;
|
||||
};
|
||||
static const int bufferSize=200;
|
||||
GwSerial(GwLog *logger,Stream *stream,int id,bool allowRead=true);
|
||||
GwSerial(GwLog *logger,SerialWrapperBase *stream,bool allowRead=true);
|
||||
~GwSerial();
|
||||
bool isInitialized();
|
||||
virtual size_t sendToClients(const char *buf,int sourceId,bool partial=false);
|
||||
@@ -30,5 +46,7 @@ class GwSerial : public GwChannelInterface{
|
||||
virtual Stream *getStream(bool partialWrites);
|
||||
bool getAvailableWrite(){return availableWrite;}
|
||||
friend GwSerialStream;
|
||||
private:
|
||||
SerialWrapperBase *serial;
|
||||
};
|
||||
#endif
|
||||
Reference in New Issue
Block a user