1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-14 06:23:07 +01:00

intermediate: udp reader

This commit is contained in:
andreas
2024-11-08 21:00:25 +01:00
parent b0d5e27b5a
commit 82f5e17987
10 changed files with 406 additions and 24 deletions

View File

@@ -21,7 +21,7 @@ GwBuffer::~GwBuffer(){
}
void GwBuffer::reset(String reason)
{
LOG_DEBUG(GwLog::LOG,"reseting buffer %s, reason %s",this->name.c_str(),reason.c_str());
if (! reason.isEmpty())LOG_DEBUG(GwLog::LOG,"reseting buffer %s, reason %s",this->name.c_str(),reason.c_str());
writePointer = buffer;
readPointer = buffer;
lp("reset");
@@ -33,6 +33,16 @@ size_t GwBuffer::freeSpace()
}
return readPointer - writePointer - 1;
}
size_t GwBuffer::continousSpace() const{
if (readPointer <= writePointer){
return bufferSize-offset(writePointer);
}
return readPointer-writePointer-1;
}
void GwBuffer::moveWp(size_t offset){
if (offset > continousSpace()) return;
writePointer+=offset;
}
size_t GwBuffer::usedSpace()
{
if (readPointer <= writePointer)

View File

@@ -33,7 +33,7 @@ class GwBuffer{
uint8_t *buffer;
uint8_t *writePointer;
uint8_t *readPointer;
size_t offset(uint8_t* ptr){
size_t offset(uint8_t* ptr) const{
return (size_t)(ptr-buffer);
}
GwLog *logger;
@@ -54,6 +54,9 @@ class GwBuffer{
* find the first occurance of x in the buffer, -1 if not found
*/
int findChar(char x);
uint8_t *getWp(){return writePointer;}
size_t continousSpace() const; //free space from wp
void moveWp(size_t offset); //move the wp forward
};
#endif