From c170e3560bc958f4233a0193b45504846698812e Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 30 Jul 2012 16:04:25 +0200 Subject: [PATCH] Some VT100 hacks, fixed MAVLink inclusion path --- images/style-mission.css | 6 +++-- qgroundcontrol.pro | 2 +- src/comm/QGCMAVLink.h | 16 ++++-------- src/ui/DebugConsole.cc | 55 +++++++++++++++++++++++++++++++++++++--- src/ui/DebugConsole.h | 4 +++ 5 files changed, 65 insertions(+), 18 deletions(-) diff --git a/images/style-mission.css b/images/style-mission.css index a1f78db1c..51147fb02 100644 --- a/images/style-mission.css +++ b/images/style-mission.css @@ -34,13 +34,15 @@ border: 1px solid #777777; } QTextEdit { -border: 1px solid #777777; + border: 1px solid #777777; border-radius: 2px; } QPlainTextEdit { -border: 1px solid #777777; + border: 1px solid #777777; border-radius: 2px; + font-family: "Monospace"; + font: large; } QComboBox { diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 0f20b3361..e0872cc3f 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -111,7 +111,7 @@ isEmpty(MAVLINK_CONF) { INCLUDEPATH += $$MAVLINKPATH/common } else { INCLUDEPATH += $$MAVLINKPATH/$$MAVLINK_CONF - DEFINES += 'MAVLINK_CONF="$${MAVLINK_CONF}.h"' + #DEFINES += 'MAVLINK_CONF="$${MAVLINK_CONF}.h"' DEFINES += $$sprintf('QGC_USE_%1_MESSAGES', $$upper($$MAVLINK_CONF)) } diff --git a/src/comm/QGCMAVLink.h b/src/comm/QGCMAVLink.h index 684aeebca..b9808ddaf 100644 --- a/src/comm/QGCMAVLink.h +++ b/src/comm/QGCMAVLink.h @@ -30,19 +30,13 @@ This file is part of the QGROUNDCONTROL project #ifndef QGCMAVLINK_H #define QGCMAVLINK_H -#include <../../mavlink/include/mavlink/v1.0/mavlink_types.h> +#include -#ifdef QGC_USE_PIXHAWK_MESSAGES -#include <../../mavlink/include/mavlink/v1.0/pixhawk/pixhawk.h> //please do not delete this. -#else -#include <../../mavlink/include/mavlink/v1.0/common/mavlink.h> -#endif - -#ifdef MAVLINK_CONF -#define MY_MACRO(x) -#include MY_MACRO(MAVLINK_CONF) +//#ifdef MAVLINK_CONF +//#define MY_MACRO(x) +//#include MY_MACRO(MAVLINK_CONF) //#include MAVLINK_CONF -#endif +//#endif #endif // QGCMAVLINK_H diff --git a/src/ui/DebugConsole.cc b/src/ui/DebugConsole.cc index 004c0fb09..c9de5b42c 100644 --- a/src/ui/DebugConsole.cc +++ b/src/ui/DebugConsole.cc @@ -74,12 +74,13 @@ DebugConsole::DebugConsole(QWidget *parent) : m_ui->receiveText->setMaximumBlockCount(500); // Allow to wrap everywhere m_ui->receiveText->setWordWrapMode(QTextOption::WrapAnywhere); +// // Set monospace font +// m_ui->receiveText->setFontFamily("Monospace"); // Enable 10 Hz output //connect(&lineBufferTimer, SIGNAL(timeout()), this, SLOT(showData())); //lineBufferTimer.setInterval(100); // 100 Hz //lineBufferTimer.start(); - loadSettings(); // Enable traffic measurements @@ -392,20 +393,65 @@ void DebugConsole::receiveBytes(LinkInterface* link, QByteArray bytes) // Convert to ASCII for readability if (convertToAscii) { - if ((byte <= 32) || (byte > 126)) + if (escReceived) + { + if (escIndex < sizeof(escBytes)) + { + escBytes[escIndex] = byte; + //qDebug() << "GOT BYTE ESC:" << byte; + if (/*escIndex == 1 && */escBytes[escIndex] == 0x48) + { + // Handle sequence + // for this one, clear all text + m_ui->receiveText->clear(); + escReceived = false; + } + else if (/*escIndex == 1 && */escBytes[escIndex] == 0x4b) + { + // Handle sequence + // for this one, do nothing + escReceived = false; + } + else if (byte == 0x5b) + { + // Do nothing, this is still a valid escape sequence + } + else + { + escReceived = false; + } + } + else + { + // Obviously something went wrong, reset + escReceived = false; + escIndex = 0; + } + } + else if ((byte <= 32) || (byte > 126)) { switch (byte) { case (unsigned char)'\n': // Accept line feed - if (lastByte != '\r') // Do not break line again for CR+LF + if (lastByte != '\r') // Do not break line again for LF+CR str.append(byte); // only break line for single LF or CR bytes break; case (unsigned char)' ': // space of any type means don't add another on hex output case (unsigned char)'\t': // Accept tab case (unsigned char)'\r': // Catch and carriage return - str.append(byte); + if (lastByte != '\n') // Do not break line again for CR+LF + str.append(byte); // only break line for single LF or CR bytes lastSpace = 1; break; + /* VT100 emulation (partially */ + case 0x1b: // ESC received + escReceived = true; + escIndex = 0; + //qDebug() << "GOT ESC"; + break; + case 0x08: // BS (backspace) received + // Do nothing for now + break; default: // Append replacement character (box) if char is not ASCII // str.append(QChar(QChar::ReplacementCharacter)); QString str2; @@ -414,6 +460,7 @@ void DebugConsole::receiveBytes(LinkInterface* link, QByteArray bytes) else str2.sprintf(" 0x%02x ", byte); str.append(str2); lastSpace = 1; + escReceived = false; break; } } diff --git a/src/ui/DebugConsole.h b/src/ui/DebugConsole.h index 252e7ee38..d369cc8b1 100644 --- a/src/ui/DebugConsole.h +++ b/src/ui/DebugConsole.h @@ -121,6 +121,10 @@ protected: bool autoHold; ///< Auto-hold mode sets view into hold if the data rate is too high int bytesToIgnore; ///< Number of bytes to ignore char lastByte; ///< The last received byte + bool escReceived; ///< True if received ESC char in ASCII mode + int escIndex; ///< Index of bytes since ESC was received + char escBytes[5]; ///< Escape-following bytes + bool terminalReceived; ///< Terminal sequence received QList sentBytes; ///< Transmitted bytes, per transmission QByteArray holdBuffer; ///< Buffer where bytes are stored during hold-enable QString lineBuffer; ///< Buffere where bytes are stored before writing them out -- 2.22.0