#include "UartEditor.h"
|
#include "UartEditor.h"
|
#include "moc_UartEditor.h"
|
#include "moc_UartEditor.h"
|
|
|
#include <QtWidgets/QScrollBar>
|
#include <QtWidgets/QScrollBar>
|
#include <memory>
|
#include <memory>
|
|
|
namespace debugger {
|
namespace debugger {
|
|
|
UartEditor::UartEditor(IGui *igui, QWidget *parent) : QPlainTextEdit(parent) {
|
UartEditor::UartEditor(IGui *igui, QWidget *parent) : QPlainTextEdit(parent) {
|
igui_ = igui;
|
igui_ = igui;
|
uart_ = 0;
|
uart_ = 0;
|
|
|
clear();
|
clear();
|
QFont font("Courier");
|
QFont font("Courier");
|
font.setStyleHint(QFont::Monospace);
|
font.setStyleHint(QFont::Monospace);
|
font.setPointSize(8);
|
font.setPointSize(8);
|
font.setFixedPitch(true);
|
font.setFixedPitch(true);
|
setFont(font);
|
setFont(font);
|
|
|
ensureCursorVisible();
|
ensureCursorVisible();
|
|
|
/** Set background color */
|
/** Set background color */
|
QPalette p = palette();
|
QPalette p = palette();
|
p.setColor(QPalette::Active, QPalette::Base, Qt::lightGray);
|
p.setColor(QPalette::Active, QPalette::Base, Qt::lightGray);
|
p.setColor(QPalette::Inactive, QPalette::Base, Qt::lightGray);
|
p.setColor(QPalette::Inactive, QPalette::Base, Qt::lightGray);
|
setPalette(p);
|
setPalette(p);
|
|
|
/** */
|
/** */
|
RISCV_mutex_init(&mutexStr_);
|
RISCV_mutex_init(&mutexStr_);
|
prevSymb_ = 0;
|
prevSymb_ = 0;
|
|
|
connect(this, SIGNAL(signalNewData()), this, SLOT(slotUpdateByData()));
|
connect(this, SIGNAL(signalNewData()), this, SLOT(slotUpdateByData()));
|
AttributeType serial_name;
|
const AttributeType *cfg = igui_->getpConfig();
|
igui_->getWidgetsAttribute("Serial", &serial_name);
|
const AttributeType &serial_name = (*cfg)["Serial"];
|
if (serial_name.is_string()) {
|
if (serial_name.is_string()) {
|
uart_ = static_cast<ISerial *>
|
uart_ = static_cast<ISerial *>
|
(RISCV_get_service_iface(serial_name.to_string(), IFACE_SERIAL));
|
(RISCV_get_service_iface(serial_name.to_string(), IFACE_SERIAL));
|
if (uart_) {
|
if (uart_) {
|
uart_->registerRawListener(static_cast<IRawListener *>(this));
|
uart_->registerRawListener(static_cast<IRawListener *>(this));
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
UartEditor::~UartEditor() {
|
UartEditor::~UartEditor() {
|
if (uart_) {
|
if (uart_) {
|
uart_->unregisterRawListener(static_cast<IRawListener *>(this));
|
uart_->unregisterRawListener(static_cast<IRawListener *>(this));
|
}
|
}
|
RISCV_mutex_destroy(&mutexStr_);
|
RISCV_mutex_destroy(&mutexStr_);
|
}
|
}
|
|
|
void UartEditor::keyPressEvent(QKeyEvent *e) {
|
void UartEditor::keyPressEvent(QKeyEvent *e) {
|
char symb = keyevent2char(e);
|
char symb = keyevent2char(e);
|
if (uart_) {
|
if (uart_) {
|
uart_->writeData(&symb, 1);
|
uart_->writeData(&symb, 1);
|
}
|
}
|
}
|
}
|
|
|
void UartEditor::closeEvent(QCloseEvent *event_) {
|
void UartEditor::closeEvent(QCloseEvent *event_) {
|
AttributeType tmp;
|
AttributeType tmp;
|
emit signalClose(this, tmp);
|
emit signalClose(this, tmp);
|
event_->accept();
|
event_->accept();
|
}
|
}
|
|
|
void UartEditor::updateData(const char *buf, int buflen) {
|
void UartEditor::updateData(const char *buf, int buflen) {
|
RISCV_mutex_lock(&mutexStr_);
|
RISCV_mutex_lock(&mutexStr_);
|
while (buflen--) {
|
while (buflen--) {
|
// Zephyr kernel scan symbol '\n' and after it adds the extra
|
// Zephyr kernel scan symbol '\n' and after it adds the extra
|
// symbol '\r', which I'm removing here.
|
// symbol '\r', which I'm removing here.
|
if (prevSymb_ == '\n' && buf[0] == '\r') {
|
if (prevSymb_ == '\n' && buf[0] == '\r') {
|
buf++;
|
buf++;
|
continue;
|
continue;
|
}
|
}
|
strOutput_ += buf[0];
|
strOutput_ += buf[0];
|
prevSymb_ = buf[0];
|
prevSymb_ = buf[0];
|
buf++;
|
buf++;
|
}
|
}
|
RISCV_mutex_unlock(&mutexStr_);
|
RISCV_mutex_unlock(&mutexStr_);
|
|
|
emit signalNewData();
|
emit signalNewData();
|
}
|
}
|
|
|
void UartEditor::slotPostInit(AttributeType *cfg) {
|
|
if (uart_) {
|
|
/* To avoid double registration */
|
|
return;
|
|
}
|
|
uart_ = static_cast<ISerial *>
|
|
(RISCV_get_service_iface((*cfg)["Serial"].to_string(), IFACE_SERIAL));
|
|
if (uart_) {
|
|
uart_->registerRawListener(static_cast<IRawListener *>(this));
|
|
}
|
|
}
|
|
|
|
void UartEditor::slotUpdateByData() {
|
void UartEditor::slotUpdateByData() {
|
if (!strOutput_.size()) {
|
if (!strOutput_.size()) {
|
return;
|
return;
|
}
|
}
|
|
|
RISCV_mutex_lock(&mutexStr_);
|
RISCV_mutex_lock(&mutexStr_);
|
moveCursor(QTextCursor::End);
|
moveCursor(QTextCursor::End);
|
QTextCursor cursor = textCursor();
|
QTextCursor cursor = textCursor();
|
cursor.insertText(strOutput_);
|
cursor.insertText(strOutput_);
|
strOutput_.clear();
|
strOutput_.clear();
|
RISCV_mutex_unlock(&mutexStr_);
|
RISCV_mutex_unlock(&mutexStr_);
|
|
|
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
}
|
}
|
|
|
char UartEditor::keyevent2char(QKeyEvent *e) {
|
char UartEditor::keyevent2char(QKeyEvent *e) {
|
wchar_t w1[8];
|
wchar_t w1[8];
|
char s1[8];
|
char s1[8];
|
int w1_sz = e->text().toWCharArray(w1);
|
int w1_sz = e->text().toWCharArray(w1);
|
wcstombs(s1, w1, w1_sz);
|
wcstombs(s1, w1, w1_sz);
|
return s1[0];
|
return s1[0];
|
}
|
}
|
|
|
} // namespace debugger
|
} // namespace debugger
|
|
|