mirror of https://github.com/EspoTek/Labrador.git
IsoBufferBuffer cleaned
This commit is contained in:
parent
bdf1055157
commit
b19900e9a0
|
@ -7,6 +7,7 @@ i2cDecoder::i2cDecoder(isoBuffer* sda_in, isoBuffer* scl_in) :
|
|||
sda(sda_in),
|
||||
scl(scl_in)
|
||||
{
|
||||
serialBuffer = new isoBufferBuffer(I2C_BUFFER_LENGTH);
|
||||
}
|
||||
|
||||
void i2cDecoder::reset()
|
||||
|
@ -22,6 +23,12 @@ void i2cDecoder::reset()
|
|||
|
||||
serialPtr_bit = sda->back * 8;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
delete serialBuffer;
|
||||
serialBuffer = new isoBufferBuffer(I2C_BUFFER_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -196,3 +203,18 @@ void i2cDecoder::dataByteCompleted(uint8_t byte, bool ACKed)
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
void i2cDecoder::updateConsole(){
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
if (!consoleStateInvalid)
|
||||
return;
|
||||
|
||||
uint32_t numCharsInBuffer = serialBuffer->getNumCharsInBuffer();
|
||||
console->setPlainText(QString::fromLocal8Bit(serialBuffer->get(numCharsInBuffer), numCharsInBuffer));
|
||||
if(sda->serialAutoScroll){
|
||||
QTextCursor c = console->textCursor();
|
||||
c.movePosition(QTextCursor::End);
|
||||
console->setTextCursor(c);
|
||||
}
|
||||
consoleStateInvalid = false;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include <QObject>
|
||||
#include "isobuffer.h"
|
||||
#include "isobufferbuffer.h"
|
||||
#include <mutex>
|
||||
|
||||
namespace i2c
|
||||
{
|
||||
|
@ -24,6 +26,7 @@ enum class edge: uint8_t
|
|||
};
|
||||
|
||||
constexpr uint8_t addressBitStreamLength = 9;
|
||||
constexpr uint32_t I2C_BUFFER_LENGTH = 8192;
|
||||
|
||||
class i2cDecoder : public QObject
|
||||
{
|
||||
|
@ -33,6 +36,9 @@ public:
|
|||
// misc
|
||||
isoBuffer* sda;
|
||||
isoBuffer* scl;
|
||||
QPlainTextEdit* console;
|
||||
isoBufferBuffer* serialBuffer = nullptr;
|
||||
std::mutex mutex;
|
||||
|
||||
// State vars
|
||||
uint8_t currentSdaValue = 0;
|
||||
|
@ -41,6 +47,7 @@ public:
|
|||
uint8_t previousSclValue = 0;
|
||||
uint64_t serialPtr_bit = 0;
|
||||
transmissionState state = transmissionState::unknown;
|
||||
bool consoleStateInvalid;
|
||||
|
||||
// Data Transmission
|
||||
uint8_t currentBitIndex = 0;
|
||||
|
@ -59,10 +66,9 @@ public:
|
|||
void stopCondition();
|
||||
void dataByteCompleted(uint8_t byte, bool ACKed);
|
||||
void reset();
|
||||
|
||||
signals:
|
||||
public slots:
|
||||
|
||||
void updateConsole();
|
||||
};
|
||||
|
||||
} // Namespace i2c
|
||||
|
|
|
@ -1,25 +1,42 @@
|
|||
#include "isobufferbuffer.h"
|
||||
|
||||
isoBufferBuffer::isoBufferBuffer(int length)
|
||||
isoBufferBuffer::isoBufferBuffer(uint32_t length)
|
||||
: bufferLength(length)
|
||||
{
|
||||
bufferLength = length;
|
||||
mid = length/2;
|
||||
buffer = (char *) malloc((length * 3) / 2);
|
||||
mid = bufferLength/2;
|
||||
buffer = (char *) malloc((bufferLength * 3) / 2);
|
||||
}
|
||||
|
||||
void isoBufferBuffer::add(std::string newString)
|
||||
{
|
||||
for (char& newChar : newString)
|
||||
add(newChar);
|
||||
}
|
||||
|
||||
|
||||
void isoBufferBuffer::add(char newChar){
|
||||
buffer[ptr] = newChar;
|
||||
if(ptr<mid){
|
||||
buffer[ptr+bufferLength] = newChar;
|
||||
}
|
||||
if (ptr >= bufferLength){
|
||||
|
||||
if(ptr < mid)
|
||||
buffer[ptr + bufferLength] = newChar;
|
||||
|
||||
if (ptr >= bufferLength)
|
||||
ptr = 0;
|
||||
}
|
||||
else ptr++;
|
||||
|
||||
numCharsInBuffer = std::min(numCharsInBuffer + 1, mid);
|
||||
}
|
||||
|
||||
char *isoBufferBuffer::get(int 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];
|
||||
uint32_t isoBufferBuffer::getNumCharsInBuffer()
|
||||
{
|
||||
return numCharsInBuffer;
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
|
|
@ -5,18 +5,22 @@
|
|||
|
||||
#include <QDebug>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
class isoBufferBuffer
|
||||
{
|
||||
public:
|
||||
isoBufferBuffer(int length);
|
||||
isoBufferBuffer(uint32_t length);
|
||||
void add(char newChar);
|
||||
char *get(int length);
|
||||
void add(std::string newString);
|
||||
char *get(uint32_t length);
|
||||
uint32_t getNumCharsInBuffer();
|
||||
private:
|
||||
int bufferLength;
|
||||
int mid;
|
||||
int ptr;
|
||||
uint32_t bufferLength;
|
||||
uint32_t mid;
|
||||
uint32_t ptr;
|
||||
char *buffer;
|
||||
uint32_t numCharsInBuffer = 0;
|
||||
};
|
||||
|
||||
#endif // ISOBUFFERBUFFER_H
|
||||
|
|
|
@ -12,7 +12,7 @@ uartStyleDecoder::uartStyleDecoder(QObject *parent_in) : QObject(parent_in)
|
|||
updateTimer->start(CONSOLE_UPDATE_TIMER_PERIOD);
|
||||
connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateConsole()));
|
||||
|
||||
serialBuffer = new isoBufferBuffer(SERIAL_BUFFER_LENGTH*2);
|
||||
serialBuffer = new isoBufferBuffer(SERIAL_BUFFER_LENGTH * 2);
|
||||
|
||||
if(parent->channel == 1) console = parent->console1;
|
||||
else if(parent->channel == 2) console = parent->console2;
|
||||
|
@ -31,6 +31,7 @@ void uartStyleDecoder::updateConsole(){
|
|||
if(!newUartSymbol) return;
|
||||
//qDebug() << numCharsInBuffer;
|
||||
|
||||
uint32_t numCharsInBuffer = serialBuffer->getNumCharsInBuffer();
|
||||
console->setPlainText(QString::fromLocal8Bit(serialBuffer->get(numCharsInBuffer), numCharsInBuffer));
|
||||
if(parent->serialAutoScroll){
|
||||
//http://stackoverflow.com/questions/21059678/how-can-i-set-auto-scroll-for-a-qtgui-qtextedit-in-pyqt4 DANKON
|
||||
|
@ -117,7 +118,6 @@ unsigned char uartStyleDecoder::getNextUartBit(){
|
|||
void uartStyleDecoder::decodeNextUartBit(unsigned char bitValue)
|
||||
{
|
||||
if(dataBit_current == dataBit_max){
|
||||
if(numCharsInBuffer<SERIAL_BUFFER_LENGTH) numCharsInBuffer++;
|
||||
decodeDatabit(dataBit_max+1);
|
||||
currentUartSymbol = 0;
|
||||
dataBit_current = 0;
|
||||
|
|
|
@ -29,7 +29,6 @@ private:
|
|||
bool jitterCompensationProcedure(double baudRate, unsigned char current_bit);
|
||||
QPlainTextEdit *console;
|
||||
isoBufferBuffer *serialBuffer;
|
||||
int numCharsInBuffer = 0;
|
||||
void decodeDatabit(int mode);
|
||||
char decode_baudot(short symbol);
|
||||
std::mutex mutex;
|
||||
|
|
Loading…
Reference in New Issue