Skip to content

Commit

Permalink
Fixed line end handling in communication console, allowed to use ente…
Browse files Browse the repository at this point in the history
…r for sending
  • Loading branch information
pixhawk-students committed Jan 26, 2011
1 parent 04ecfa6 commit af9f247
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 21 deletions.
3 changes: 3 additions & 0 deletions qgroundcontrol.pri
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ release {

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/release/.

Expand Down
16 changes: 8 additions & 8 deletions src/comm/SerialLink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,18 @@ void SerialLink::writeBytes(const char* data, qint64 size)
if (b > 0)
{

qDebug() << "Serial link " << this->getName() << "transmitted" << b << "bytes:";
// qDebug() << "Serial link " << this->getName() << "transmitted" << b << "bytes:";

// Increase write counter
bitsSentTotal += size * 8;

int i;
for (i=0; i<size; i++)
{
unsigned char v =data[i];
qDebug("%02x ", v);
}
qDebug("\n");
// int i;
// for (i=0; i<size; i++)
// {
// unsigned char v =data[i];
// qDebug("%02x ", v);
// }
// qDebug("\n");
}
else
{
Expand Down
96 changes: 83 additions & 13 deletions src/ui/DebugConsole.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ DebugConsole::DebugConsole(QWidget *parent) :
connect(m_ui->specialComboBox, SIGNAL(highlighted(QString)), this, SLOT(specialSymbolSelected(QString)));
// Set add button invisible if auto add checkbox is checked
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);

Expand Down Expand Up @@ -205,7 +207,8 @@ void DebugConsole::setAutoHold(bool hold)
void DebugConsole::receiveTextMessage(int id, int component, int severity, QString text)
{
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()
Expand Down Expand Up @@ -293,14 +296,13 @@ void DebugConsole::receiveBytes(LinkInterface* link, QByteArray bytes)
{
switch (byte)
{
// Catch line feed
// case (unsigned char)'\n':
// m_ui->receiveText->appendPlainText(str);
// str = "";
// break;
// Catch carriage return and line feed
case (unsigned char)0xD:
case (unsigned char)0xA:
// Accept line feed and tab
case (unsigned char)'\n':
case (unsigned char)'\t':
str.append(byte);
break;
// Catch and ignore carriage return
case (unsigned char)'\r':
// Ignore
break;
default:
Expand Down Expand Up @@ -330,8 +332,14 @@ void DebugConsole::receiveBytes(LinkInterface* link, QByteArray bytes)
}

}
if (lineBuffer.length() > 0) m_ui->receiveText->appendPlainText(lineBuffer);
lineBuffer.clear();
if (lineBuffer.length() > 0)
{
m_ui->receiveText->insertPlainText(lineBuffer);
// Ensure text area scrolls correctly
m_ui->receiveText->ensureCursorVisible();
lineBuffer.clear();
}


}
else if (link == currLink && holdOn)
Expand Down Expand Up @@ -595,6 +603,7 @@ void DebugConsole::hexModeEnabled(bool mode)
m_ui->receiveText->clear();
m_ui->sendText->clear();
m_ui->sentText->clear();
commandHistory.clear();
}

/**
Expand Down Expand Up @@ -640,12 +649,12 @@ void DebugConsole::setConnectionState(bool connected)
if(connected)
{
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
{
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())));
}
}

Expand All @@ -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)
{
QWidget::changeEvent(e);
Expand Down
8 changes: 8 additions & 0 deletions src/ui/DebugConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ This file is part of the QGROUNDCONTROL project
#include <QList>
#include <QByteArray>
#include <QTimer>
#include <QKeyEvent>

#include "LinkInterface.h"

Expand Down Expand Up @@ -102,8 +103,15 @@ public slots:
QByteArray symbolNameToBytes(const QString& symbol);
/** @brief Convert a symbol byte to the name */
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;
QStringList commandHistory;
QString currCommand;
int commandIndex;
LinkInterface* currLink;

bool holdOn; ///< Hold current view, ignore new data
Expand Down

0 comments on commit af9f247

Please sign in to comment.