Commit af9f2479 authored by lm's avatar lm

Fixed line end handling in communication console, allowed to use enter for sending

parent 04ecfa68
...@@ -38,6 +38,9 @@ release { ...@@ -38,6 +38,9 @@ release {
QMAKE_POST_LINK += echo "Copying files" QMAKE_POST_LINK += echo "Copying files"
# Turn off serial port warnings
DEFINES += _TTY_NOWARN_
#QMAKE_POST_LINK += && cp -rf $$BASEDIR/models $$TARGETDIR/debug/. #QMAKE_POST_LINK += && cp -rf $$BASEDIR/models $$TARGETDIR/debug/.
#QMAKE_POST_LINK += && cp -rf $$BASEDIR/models $$TARGETDIR/release/. #QMAKE_POST_LINK += && cp -rf $$BASEDIR/models $$TARGETDIR/release/.
......
...@@ -179,18 +179,18 @@ void SerialLink::writeBytes(const char* data, qint64 size) ...@@ -179,18 +179,18 @@ void SerialLink::writeBytes(const char* data, qint64 size)
if (b > 0) if (b > 0)
{ {
qDebug() << "Serial link " << this->getName() << "transmitted" << b << "bytes:"; // qDebug() << "Serial link " << this->getName() << "transmitted" << b << "bytes:";
// Increase write counter // Increase write counter
bitsSentTotal += size * 8; bitsSentTotal += size * 8;
int i; // int i;
for (i=0; i<size; i++) // for (i=0; i<size; i++)
{ // {
unsigned char v =data[i]; // unsigned char v =data[i];
qDebug("%02x ", v); // qDebug("%02x ", v);
} // }
qDebug("\n"); // qDebug("\n");
} }
else else
{ {
......
...@@ -115,6 +115,8 @@ DebugConsole::DebugConsole(QWidget *parent) : ...@@ -115,6 +115,8 @@ DebugConsole::DebugConsole(QWidget *parent) :
connect(m_ui->specialComboBox, SIGNAL(highlighted(QString)), this, SLOT(specialSymbolSelected(QString))); connect(m_ui->specialComboBox, SIGNAL(highlighted(QString)), this, SLOT(specialSymbolSelected(QString)));
// Set add button invisible if auto add checkbox is checked // Set add button invisible if auto add checkbox is checked
connect(m_ui->specialCheckBox, SIGNAL(clicked(bool)), m_ui->addSymbolButton, SLOT(setHidden(bool))); connect(m_ui->specialCheckBox, SIGNAL(clicked(bool)), m_ui->addSymbolButton, SLOT(setHidden(bool)));
// Allow to send via return
connect(m_ui->sendText, SIGNAL(returnPressed()), this, SLOT(sendBytes()));
hold(false); hold(false);
...@@ -205,7 +207,8 @@ void DebugConsole::setAutoHold(bool hold) ...@@ -205,7 +207,8 @@ void DebugConsole::setAutoHold(bool hold)
void DebugConsole::receiveTextMessage(int id, int component, int severity, QString text) void DebugConsole::receiveTextMessage(int id, int component, int severity, QString text)
{ {
Q_UNUSED(severity); Q_UNUSED(severity);
m_ui->receiveText->appendHtml(QString("<font color=\"%1\">(MAV%2:%3) %4</font>").arg(UASManager::instance()->getUASForId(id)->getColor().name(), QString::number(id), QString::number(component), text)); m_ui->receiveText->appendHtml(QString("<font color=\"%1\">(MAV%2:%3) %4</font>\n").arg(UASManager::instance()->getUASForId(id)->getColor().name(), QString::number(id), QString::number(component), text));
//m_ui->receiveText->appendPlainText("");
} }
void DebugConsole::updateTrafficMeasurements() void DebugConsole::updateTrafficMeasurements()
...@@ -293,14 +296,13 @@ void DebugConsole::receiveBytes(LinkInterface* link, QByteArray bytes) ...@@ -293,14 +296,13 @@ void DebugConsole::receiveBytes(LinkInterface* link, QByteArray bytes)
{ {
switch (byte) switch (byte)
{ {
// Catch line feed // Accept line feed and tab
// case (unsigned char)'\n': case (unsigned char)'\n':
// m_ui->receiveText->appendPlainText(str); case (unsigned char)'\t':
// str = ""; str.append(byte);
// break; break;
// Catch carriage return and line feed // Catch and ignore carriage return
case (unsigned char)0xD: case (unsigned char)'\r':
case (unsigned char)0xA:
// Ignore // Ignore
break; break;
default: default:
...@@ -330,8 +332,14 @@ void DebugConsole::receiveBytes(LinkInterface* link, QByteArray bytes) ...@@ -330,8 +332,14 @@ void DebugConsole::receiveBytes(LinkInterface* link, QByteArray bytes)
} }
} }
if (lineBuffer.length() > 0) m_ui->receiveText->appendPlainText(lineBuffer); if (lineBuffer.length() > 0)
lineBuffer.clear(); {
m_ui->receiveText->insertPlainText(lineBuffer);
// Ensure text area scrolls correctly
m_ui->receiveText->ensureCursorVisible();
lineBuffer.clear();
}
} }
else if (link == currLink && holdOn) else if (link == currLink && holdOn)
...@@ -595,6 +603,7 @@ void DebugConsole::hexModeEnabled(bool mode) ...@@ -595,6 +603,7 @@ void DebugConsole::hexModeEnabled(bool mode)
m_ui->receiveText->clear(); m_ui->receiveText->clear();
m_ui->sendText->clear(); m_ui->sendText->clear();
m_ui->sentText->clear(); m_ui->sentText->clear();
commandHistory.clear();
} }
/** /**
...@@ -640,12 +649,12 @@ void DebugConsole::setConnectionState(bool connected) ...@@ -640,12 +649,12 @@ void DebugConsole::setConnectionState(bool connected)
if(connected) if(connected)
{ {
m_ui->connectButton->setText(tr("Disconn.")); m_ui->connectButton->setText(tr("Disconn."));
m_ui->receiveText->appendHtml(QString("<font color=\"%1\">%2</font>").arg(QGC::colorGreen.name(), tr("Link %1 is connected.").arg(currLink->getName()))); m_ui->receiveText->appendHtml(QString("<font color=\"%1\">%2</font>\n").arg(QGC::colorGreen.name(), tr("Link %1 is connected.").arg(currLink->getName())));
} }
else else
{ {
m_ui->connectButton->setText(tr("Connect")); m_ui->connectButton->setText(tr("Connect"));
m_ui->receiveText->appendHtml(QString("<font color=\"%1\">%2</font>").arg(QGC::colorYellow.name(), tr("Link %1 is unconnected.").arg(currLink->getName()))); m_ui->receiveText->appendHtml(QString("<font color=\"%1\">%2</font>\n").arg(QGC::colorYellow.name(), tr("Link %1 is unconnected.").arg(currLink->getName())));
} }
} }
...@@ -665,6 +674,67 @@ void DebugConsole::handleConnectButton() ...@@ -665,6 +674,67 @@ void DebugConsole::handleConnectButton()
} }
} }
void DebugConsole::keyPressEvent(QKeyEvent * event)
{
if (event->key() == Qt::Key_Up)
{
qDebug() << "UP KEY PRESSED";
cycleCommandHistory(true);
}
else if (event->key() == Qt::Key_Down)
{
qDebug() << "DOWN KEY PRESSED";
cycleCommandHistory(false);
}
else if (event->key() == Qt::Key_Enter)
{
this->sendBytes();
}
else
{
QWidget::keyPressEvent(event);
}
}
void DebugConsole::cycleCommandHistory(bool up)
{
// Store current command if we're not in history yet
if (commandIndex == commandHistory.length())
{
currCommand = m_ui->sendText->text();
}
if (up)
{
// UP
commandIndex--;
if (commandIndex >= 0)
{
m_ui->sendText->setText(commandHistory.at(commandIndex));
}
// If the index
}
else
{
// DOWN
commandIndex++;
if (commandIndex < commandHistory.length())
{
m_ui->sendText->setText(commandHistory.at(commandIndex));
}
// If the index is at history length, load the last current command
}
// If we are too far down or too far up, wrap around to current command
if (commandIndex < 0 || commandIndex > commandHistory.length())
{
commandIndex = commandHistory.length();
m_ui->sendText->setText(currCommand);
}
}
void DebugConsole::changeEvent(QEvent *e) void DebugConsole::changeEvent(QEvent *e)
{ {
QWidget::changeEvent(e); QWidget::changeEvent(e);
......
...@@ -36,6 +36,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -36,6 +36,7 @@ This file is part of the QGROUNDCONTROL project
#include <QList> #include <QList>
#include <QByteArray> #include <QByteArray>
#include <QTimer> #include <QTimer>
#include <QKeyEvent>
#include "LinkInterface.h" #include "LinkInterface.h"
...@@ -102,8 +103,15 @@ protected: ...@@ -102,8 +103,15 @@ protected:
QByteArray symbolNameToBytes(const QString& symbol); QByteArray symbolNameToBytes(const QString& symbol);
/** @brief Convert a symbol byte to the name */ /** @brief Convert a symbol byte to the name */
QString bytesToSymbolNames(const QByteArray& b); QString bytesToSymbolNames(const QByteArray& b);
/** @brief Handle keypress events */
void keyPressEvent(QKeyEvent * event);
/** @brief Cycle through the command history */
void cycleCommandHistory(bool up);
QList<LinkInterface*> links; QList<LinkInterface*> links;
QStringList commandHistory;
QString currCommand;
int commandIndex;
LinkInterface* currLink; LinkInterface* currLink;
bool holdOn; ///< Hold current view, ignore new data bool holdOn; ///< Hold current view, ignore new data
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment