1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-16 15:33:05 +01:00

restructure buffer handling, better buffer logging

This commit is contained in:
wellenvogel
2021-12-02 17:10:50 +01:00
parent 9dcb98bb51
commit cd1fefad52
5 changed files with 115 additions and 185 deletions

View File

@@ -5,13 +5,6 @@
#include "GwLog.h"
class GwBuffer;
class GwBufferWriter{
public:
int id=0; //can be set be users
virtual int write(const uint8_t *buffer,size_t len)=0;
virtual void done(){}
virtual ~GwBufferWriter(){};
};
class GwMessageFetcher{
public:
@@ -44,9 +37,10 @@ class GwBuffer{
return (size_t)(ptr-buffer);
}
GwLog *logger;
String name;
void lp(const char *fkt,int p=0);
public:
GwBuffer(GwLog *logger,size_t bufferSize);
GwBuffer(GwLog *logger,size_t bufferSize,String name);
~GwBuffer();
void reset(String reason="");
size_t freeSpace();
@@ -56,16 +50,10 @@ class GwBuffer{
int read();
int peek();
size_t fetchData(int maxLen,GwBufferHandleFunction handler, void *param);
/**
* write some data to the buffer writer
* return an error if the buffer writer returned < 0
*/
WriteStatus fetchData(GwBufferWriter *writer, int maxLen=-1,bool errorIf0 = true);
/**
* find the first occurance of x in the buffer, -1 if not found
*/
int findChar(char x);
WriteStatus fetchMessage(GwBufferWriter *writer,char delimiter,bool emptyIfFull=true);
};
#endif