2017-10-21 06:11:49 +01:00
|
|
|
#include "isobufferbuffer.h"
|
|
|
|
|
2018-11-05 23:15:48 +00:00
|
|
|
isoBufferBuffer::isoBufferBuffer(uint32_t length)
|
|
|
|
: bufferLength(length)
|
2017-10-21 06:11:49 +01:00
|
|
|
{
|
2018-11-05 23:15:48 +00:00
|
|
|
mid = bufferLength/2;
|
|
|
|
buffer = (char *) malloc((bufferLength * 3) / 2);
|
2017-10-21 06:11:49 +01:00
|
|
|
}
|
|
|
|
|
2018-11-05 23:15:48 +00:00
|
|
|
void isoBufferBuffer::add(std::string newString)
|
|
|
|
{
|
|
|
|
for (char& newChar : newString)
|
|
|
|
add(newChar);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-21 06:11:49 +01:00
|
|
|
void isoBufferBuffer::add(char newChar){
|
|
|
|
buffer[ptr] = newChar;
|
2018-11-05 23:15:48 +00:00
|
|
|
|
|
|
|
if(ptr < mid)
|
|
|
|
buffer[ptr + bufferLength] = newChar;
|
|
|
|
|
|
|
|
if (ptr >= bufferLength)
|
2017-10-21 06:11:49 +01:00
|
|
|
ptr = 0;
|
|
|
|
else ptr++;
|
2018-11-05 23:15:48 +00:00
|
|
|
|
|
|
|
numCharsInBuffer = std::min(numCharsInBuffer + 1, mid);
|
|
|
|
}
|
|
|
|
|
2018-11-05 23:55:45 +00:00
|
|
|
void isoBufferBuffer::add(uint8_t newByte)
|
|
|
|
{
|
|
|
|
char newString[5];
|
|
|
|
sprintf(newString, "0x%02hhx", newByte);
|
|
|
|
add(newString);
|
|
|
|
}
|
|
|
|
|
2018-11-05 23:15:48 +00:00
|
|
|
uint32_t isoBufferBuffer::getNumCharsInBuffer()
|
|
|
|
{
|
|
|
|
return numCharsInBuffer;
|
2017-10-21 06:11:49 +01:00
|
|
|
}
|
|
|
|
|
2018-11-05 23:15:48 +00:00
|
|
|
char *isoBufferBuffer::get(uint32_t length){
|
|
|
|
if (length > mid)
|
|
|
|
qFatal("isoBuffer::get; length requested is too high.");
|
|
|
|
if(ptr < mid)
|
|
|
|
return &buffer[ptr + bufferLength - length];
|
|
|
|
else
|
|
|
|
return &buffer[ptr - length];
|
2017-10-21 06:11:49 +01:00
|
|
|
}
|