Isobufferbuffer integration (#62)

* Update all code to use the new isoBufferBuffer interface, and remove the old one; also rename isoBufferBuffer::add(uint8_t) to insert_hex

* remove unnecessary include directive from isobuffer.h

* Remove 'Legacy Interface' comment from isoBufferBuffer header and implementation, move insert_hex closer to other insert functions in the header and implementation

* Remove TODO comment of a finished task
This commit is contained in:
Sebastián Mestre 2018-12-30 20:02:04 -03:00 committed by Chris Esposito
parent 0e97d4c150
commit 4499db10bf
6 changed files with 25 additions and 62 deletions

View File

@ -32,8 +32,7 @@ void i2cDecoder::reset()
{ {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
delete serialBuffer; serialBuffer->clear();
serialBuffer = new isoBufferBuffer(I2C_BUFFER_LENGTH);
} }
} }
@ -150,15 +149,15 @@ void i2cDecoder::decodeAddress(edge sdaEdge, edge sclEdge)
{ {
qDebug() << "Finished Address Decode"; qDebug() << "Finished Address Decode";
if (currentBitStream & 0b0000000000000010) if (currentBitStream & 0b0000000000000010)
serialBuffer->add("READ: "); serialBuffer->insert("READ: ");
else else
serialBuffer->add("WRITE: "); serialBuffer->insert("WRITE: ");
serialBuffer->add((uint8_t)((currentBitStream & 0b0000000111111100) >> 2)); serialBuffer->insert_hex((uint8_t)((currentBitStream & 0b0000000111111100) >> 2));
serialBuffer->add(' '); serialBuffer->insert(' ');
if (currentBitStream & 0b0000000000000001) if (currentBitStream & 0b0000000000000001)
serialBuffer->add("(NACK)"); serialBuffer->insert("(NACK)");
consoleStateInvalid = true; consoleStateInvalid = true;
@ -183,11 +182,11 @@ void i2cDecoder::decodeData(edge sdaEdge, edge sclEdge)
{ {
qDebug() << "Finished Data byte Decode"; qDebug() << "Finished Data byte Decode";
serialBuffer->add((uint8_t)((currentBitStream & 0b0000000111111110) >> 1)); serialBuffer->insert_hex((uint8_t)((currentBitStream & 0b0000000111111110) >> 1));
serialBuffer->add(' '); serialBuffer->insert(' ');
if (currentBitStream & 0b0000000000000001) if (currentBitStream & 0b0000000000000001)
serialBuffer->add("(NACK)"); serialBuffer->insert("(NACK)");
consoleStateInvalid = true; consoleStateInvalid = true;
@ -208,7 +207,7 @@ void i2cDecoder::startCondition()
void i2cDecoder::stopCondition() void i2cDecoder::stopCondition()
{ {
state = transmissionState::idle; state = transmissionState::idle;
serialBuffer->add('\n'); serialBuffer->insert('\n');
qDebug() << "I2C STOP"; qDebug() << "I2C STOP";
} }
@ -217,8 +216,7 @@ void i2cDecoder::updateConsole(){
if (!consoleStateInvalid) if (!consoleStateInvalid)
return; return;
uint32_t numCharsInBuffer = serialBuffer->getNumCharsInBuffer(); console->setPlainText(QString::fromLocal8Bit(serialBuffer->begin(), serialBuffer->size()));
console->setPlainText(QString::fromLocal8Bit(serialBuffer->get(numCharsInBuffer), numCharsInBuffer));
if(sda->serialAutoScroll){ if(sda->serialAutoScroll){
QTextCursor c = console->textCursor(); QTextCursor c = console->textCursor();
c.movePosition(QTextCursor::End); c.movePosition(QTextCursor::End);

View File

@ -29,7 +29,7 @@ enum class edge: uint8_t
constexpr uint8_t addressBitStreamLength = 9; constexpr uint8_t addressBitStreamLength = 9;
constexpr uint8_t dataBitStreamLength = 9; constexpr uint8_t dataBitStreamLength = 9;
constexpr uint32_t I2C_BUFFER_LENGTH = 8192; constexpr uint32_t I2C_BUFFER_LENGTH = 4096;
class i2cDecoder : public QObject class i2cDecoder : public QObject
{ {

View File

@ -12,7 +12,6 @@
#include "xmega.h" #include "xmega.h"
#include "desktop_settings.h" #include "desktop_settings.h"
#include "isobufferbuffer.h"
#include "genericusbdriver.h" #include "genericusbdriver.h"
class isoDriver; class isoDriver;

View File

@ -22,12 +22,6 @@
* half of the allocated buffer, which is a notable improvement. * half of the allocated buffer, which is a notable improvement.
*/ */
// TODO: go through the usages of this class and:
// 1. adapt code to use the new interface and remove the old one
// 2. adjust the size of the requested buffer to accomodate
// the improved memory efficiency of the new algorithm
isoBufferBuffer::isoBufferBuffer(uint32_t length) isoBufferBuffer::isoBufferBuffer(uint32_t length)
: m_data(std::make_unique<char[]>(length*2)) : m_data(std::make_unique<char[]>(length*2))
, m_capacity(length) , m_capacity(length)
@ -59,6 +53,13 @@ void isoBufferBuffer::insert(std::string const & s)
insert(c); insert(c);
} }
void isoBufferBuffer::insert_hex(uint8_t x)
{
char str[5];
sprintf(str, "0x%02hhx", x);
insert((char const *)str);
}
char const* isoBufferBuffer::query(uint32_t count) const char const* isoBufferBuffer::query(uint32_t count) const
{ {
if (count > m_capacity) if (count > m_capacity)
@ -97,31 +98,3 @@ uint32_t isoBufferBuffer::capacity() const
} }
// Legacy Interface Implementation
void isoBufferBuffer::add(std::string const & newString)
{
insert(newString);
}
void isoBufferBuffer::add(char newChar)
{
insert(newChar);
}
void isoBufferBuffer::add(uint8_t newByte)
{
char newString[5];
sprintf(newString, "0x%02hhx", newByte);
insert((char const *)newString);
}
uint32_t isoBufferBuffer::getNumCharsInBuffer()
{
return size();
}
char const * isoBufferBuffer::get(uint32_t length)
{
return query(length);
}

View File

@ -30,6 +30,7 @@ public:
void insert(char c); void insert(char c);
void insert(char const * s); void insert(char const * s);
void insert(std::string const & s); void insert(std::string const & s);
void insert_hex(uint8_t x);
char const * query(uint32_t length) const; char const * query(uint32_t length) const;
// TODO?: add ability to get a copy of the content // TODO?: add ability to get a copy of the content
@ -42,13 +43,6 @@ public:
uint32_t size() const; uint32_t size() const;
uint32_t capacity() const; uint32_t capacity() const;
// Legacy Interface
void add(uint8_t newByte);
void add(char newChar);
void add(std::string const & newString);
char const *get(uint32_t length);
uint32_t getNumCharsInBuffer();
private: private:
std::unique_ptr<char[]> m_data; std::unique_ptr<char[]> m_data;
uint32_t m_capacity; uint32_t m_capacity;

View File

@ -14,7 +14,7 @@ uartStyleDecoder::uartStyleDecoder(QObject *parent_in) : QObject(parent_in)
updateTimer->start(CONSOLE_UPDATE_TIMER_PERIOD); updateTimer->start(CONSOLE_UPDATE_TIMER_PERIOD);
connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateConsole())); connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateConsole()));
serialBuffer = new isoBufferBuffer(SERIAL_BUFFER_LENGTH * 2); serialBuffer = new isoBufferBuffer(SERIAL_BUFFER_LENGTH);
if(parent->channel == 1) console = parent->console1; if(parent->channel == 1) console = parent->console1;
else if(parent->channel == 2) console = parent->console2; else if(parent->channel == 2) console = parent->console2;
@ -31,10 +31,9 @@ uartStyleDecoder::~uartStyleDecoder()
void uartStyleDecoder::updateConsole(){ void uartStyleDecoder::updateConsole(){
std::lock_guard<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
if(!newUartSymbol) return; if(!newUartSymbol) return;
//qDebug() << numCharsInBuffer; //qDebug() << serialBuffer->size();
uint32_t numCharsInBuffer = serialBuffer->getNumCharsInBuffer(); console->setPlainText(QString::fromLocal8Bit(serialBuffer->begin(), serialBuffer->size()));
console->setPlainText(QString::fromLocal8Bit(serialBuffer->get(numCharsInBuffer), numCharsInBuffer));
if(parent->serialAutoScroll){ if(parent->serialAutoScroll){
//http://stackoverflow.com/questions/21059678/how-can-i-set-auto-scroll-for-a-qtgui-qtextedit-in-pyqt4 DANKON //http://stackoverflow.com/questions/21059678/how-can-i-set-auto-scroll-for-a-qtgui-qtextedit-in-pyqt4 DANKON
QTextCursor c = console->textCursor(); QTextCursor c = console->textCursor();
@ -195,10 +194,10 @@ void uartStyleDecoder::decodeDatabit(int mode){
} }
if (parityCheckFailed) if (parityCheckFailed)
{ {
serialBuffer->add("\n<ERROR: Following character contains parity error>\n"); serialBuffer->insert("\n<ERROR: Following character contains parity error>\n");
parityCheckFailed = false; parityCheckFailed = false;
} }
serialBuffer->add(tempchar); serialBuffer->insert(tempchar);
} }
char uartStyleDecoder::decode_baudot(short symbol){ char uartStyleDecoder::decode_baudot(short symbol){