mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-13 05:53:06 +01:00
intermediate: introduce an abstract channel
This commit is contained in:
@@ -96,7 +96,7 @@ size_t GwSerial::sendToClients(const char *buf,int sourceId,bool partial){
|
||||
}
|
||||
return enqueued;
|
||||
}
|
||||
void GwSerial::loop(bool handleRead){
|
||||
void GwSerial::loop(bool handleRead,bool handleWrite){
|
||||
write();
|
||||
if (! isInitialized()) return;
|
||||
if (! handleRead) return;
|
||||
@@ -116,10 +116,10 @@ void GwSerial::loop(bool handleRead){
|
||||
serial->readBytes(buffer,available);
|
||||
}
|
||||
}
|
||||
bool GwSerial::readMessages(GwMessageFetcher *writer){
|
||||
if (! isInitialized()) return false;
|
||||
if (! allowRead) return false;
|
||||
return writer->handleBuffer(readBuffer);
|
||||
void GwSerial::readMessages(GwMessageFetcher *writer){
|
||||
if (! isInitialized()) return;
|
||||
if (! allowRead) return;
|
||||
writer->handleBuffer(readBuffer);
|
||||
}
|
||||
|
||||
void GwSerial::flush(){
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
#include "HardwareSerial.h"
|
||||
#include "GwLog.h"
|
||||
#include "GwBuffer.h"
|
||||
#include "GwChannelInterface.h"
|
||||
class GwSerialStream;
|
||||
class GwSerial{
|
||||
class GwSerial : public GwChannelInterface{
|
||||
private:
|
||||
GwBuffer *buffer;
|
||||
GwBuffer *readBuffer=NULL;
|
||||
@@ -23,11 +24,11 @@ class GwSerial{
|
||||
~GwSerial();
|
||||
int setup(int baud,int rxpin,int txpin);
|
||||
bool isInitialized();
|
||||
size_t sendToClients(const char *buf,int sourceId,bool partial=false);
|
||||
void loop(bool handleRead=true);
|
||||
bool readMessages(GwMessageFetcher *writer);
|
||||
virtual size_t sendToClients(const char *buf,int sourceId,bool partial=false);
|
||||
virtual void loop(bool handleRead=true,bool handleWrite=true);
|
||||
virtual void readMessages(GwMessageFetcher *writer);
|
||||
void flush();
|
||||
Stream *getStream(bool partialWrites);
|
||||
virtual Stream *getStream(bool partialWrites);
|
||||
friend GwSerialStream;
|
||||
};
|
||||
#endif
|
||||
Reference in New Issue
Block a user