diff --git a/src/ui/DebugConsole.cc b/src/ui/DebugConsole.cc index 820b7d3400954d68c100cfc7e89f4ccc8722f7a8..d802acca9ee011979f588548d3453d0ac679719a 100644 --- a/src/ui/DebugConsole.cc +++ b/src/ui/DebugConsole.cc @@ -113,6 +113,8 @@ DebugConsole::DebugConsole(QWidget *parent) : connect(m_ui->addSymbolButton, SIGNAL(clicked()), this, SLOT(appendSpecialSymbol())); // Connect Checkbox 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))); hold(false); @@ -341,46 +343,92 @@ void DebugConsole::receiveBytes(LinkInterface* link, QByteArray bytes) QByteArray DebugConsole::symbolNameToBytes(const QString& text) { QByteArray b; - if (text == "LF") + if (text.contains("CR+LF")) { + b.append(static_cast(0x0D)); b.append(static_cast(0x0A)); } - else if (text == "FF") + else if (text.contains("LF")) { - b.append(static_cast(0x0C)); + b.append(static_cast(0x0A)); } - else if (text == "CR") + else if (text.contains("FF")) { - b.append(static_cast(0x0D)); + b.append(static_cast(0x0C)); } - else if (text == "CR+LF") + else if (text.contains("CR")) { b.append(static_cast(0x0D)); - b.append(static_cast(0x0A)); } - else if (text == "TAB") + else if (text.contains("TAB")) { b.append(static_cast(0x09)); } - else if (text == "NUL") + else if (text.contains("NUL")) { b.append(static_cast(0x00)); } - else if (text == "ESC") + else if (text.contains("ESC")) { b.append(static_cast(0x1B)); } - else if (text == "~") + else if (text.contains("~")) { b.append(static_cast(0x7E)); } - else if (text == "") + else if (text.contains("")) { b.append(static_cast(0x20)); } return b; } +QString DebugConsole::bytesToSymbolNames(const QByteArray& b) +{ + QString text; + if (b.size() > 1 && b.contains(0x0D) && b.contains(0x0A)) + { + text = ""; + } + else if (b.contains(0x0A)) + { + text = ""; + } + else if (b.contains(0x0C)) + { + text = ""; + } + else if (b.contains(0x0D)) + { + text = ""; + } + else if (b.contains(0x09)) + { + text = ""; + } + else if (b.contains((char)0x00)) + { + text == ""; + } + else if (b.contains(0x1B)) + { + text = ""; + } + else if (b.contains(0x7E)) + { + text = "<~>"; + } + else if (b.contains(0x20)) + { + text = ""; + } + else + { + text.append(b); + } + return text; +} + void DebugConsole::specialSymbolSelected(const QString& text) { Q_UNUSED(text); @@ -426,10 +474,27 @@ void DebugConsole::sendBytes() return; } + QString transmitUnconverted = m_ui->sendText->text(); + QByteArray specialSymbol; + // Append special symbol if checkbox is checked if (m_ui->specialCheckBox->isChecked()) { - appendSpecialSymbol(m_ui->specialComboBox->currentText()); + // Get auto-add special symbols + specialSymbol = symbolNameToBytes(m_ui->specialComboBox->currentText()); + + // Convert them if needed + if (!convertToAscii) + { + QString specialSymbolConverted; + for (int i = 0; i < specialSymbol.length(); i++) + { + QString add(" 0x%1"); + specialSymbolConverted.append(add.arg(static_cast(specialSymbol.at(i)), 2, 16, QChar('0'))); + } + specialSymbol.clear(); + specialSymbol.append(specialSymbolConverted); + } } QByteArray transmit; @@ -438,13 +503,27 @@ void DebugConsole::sendBytes() if (convertToAscii) { // ASCII text is not converted - transmit = m_ui->sendText->text().toLatin1(); - feedback = transmit; + transmit = transmitUnconverted.toLatin1(); + // Auto-add special symbol handling + transmit.append(specialSymbol); + + QString translated; + + // Replace every occurence of a special symbol with its text name + for (int i = 0; i < transmit.size(); ++i) + { + QByteArray specialChar; + specialChar.append(transmit.at(i)); + translated.append(bytesToSymbolNames(specialChar)); + } + + feedback.append(translated); } else { // HEX symbols are converted to bytes - QString str = m_ui->sendText->text().toLatin1(); + QString str = transmitUnconverted.toLatin1(); + str.append(specialSymbol); str.remove(' '); str.remove("0x"); str.simplified(); @@ -485,16 +564,16 @@ void DebugConsole::sendBytes() if (ok && m_ui->sendText->text().toLatin1().size() > 0) { // Transmit only if conversion succeeded -// int transmitted = - currLink->writeBytes(transmit, transmit.size()); -// if (transmit.size() == transmitted) -// { - m_ui->sentText->setText(tr("Sent: ") + feedback); -// } -// else -// { -// m_ui->sentText->setText(tr("Error during sending: Transmitted only %1 bytes instead of %2.").arg(transmitted, transmit.size())); -// } + // int transmitted = + currLink->writeBytes(transmit, transmit.size()); + // if (transmit.size() == transmitted) + // { + m_ui->sentText->setText(tr("Sent: ") + feedback); + // } + // else + // { + // m_ui->sentText->setText(tr("Error during sending: Transmitted only %1 bytes instead of %2.").arg(transmitted, transmit.size())); + // } } else if (m_ui->sendText->text().toLatin1().size() > 0) { diff --git a/src/ui/DebugConsole.h b/src/ui/DebugConsole.h index a441d84f446466c7fea48481fa98598e4cdff6f3..cfc4ad91eeb3e003472dfd976bd09ea9a417bcf6 100644 --- a/src/ui/DebugConsole.h +++ b/src/ui/DebugConsole.h @@ -98,7 +98,10 @@ public slots: protected: void changeEvent(QEvent *e); + /** @brief Convert a symbol name to the byte representation */ QByteArray symbolNameToBytes(const QString& symbol); + /** @brief Convert a symbol byte to the name */ + QString bytesToSymbolNames(const QByteArray& b); QList links; LinkInterface* currLink; diff --git a/src/ui/DebugConsole.ui b/src/ui/DebugConsole.ui index bb32e331b16ab6ed5d4e99bbf7febc7f65513a32..e7245d5edae4dfc86dc429c7a6f5a4ad9223a319 100644 --- a/src/ui/DebugConsole.ui +++ b/src/ui/DebugConsole.ui @@ -6,7 +6,7 @@ 0 0 - 466 + 566 190 @@ -171,11 +171,6 @@ TAB - - - NUL - - ESC