# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2015-10-10 14:47:28 # Node ID 9add38e39c0adb927630677ee0196bac884e27ae # Parent 91504904883a633cd8e8eb71a3008f2d92115d9a refactored sendCommand signal to carry QByteArray instead of QString+mode diff --git a/commandpanel.cpp b/commandpanel.cpp --- a/commandpanel.cpp +++ b/commandpanel.cpp @@ -47,7 +47,7 @@ void CommandPanel::newCommand() connect(command, &CommandWidget::sendCommand, this, &CommandPanel::sendCommand); } -void CommandPanel::sendCommand(QString command, bool ascii) +void CommandPanel::sendCommand(QByteArray command) { if (!serialPort->isOpen()) { @@ -55,19 +55,8 @@ void CommandPanel::sendCommand(QString c return; } - if (ascii) + if (serialPort->write(command) < 0) { - qDebug() << "Sending" << command; - if (serialPort->write(command.toLatin1()) < 0) - { - qCritical() << "Send command failed!"; - } - } - else - { - if (serialPort->write(QByteArray::fromHex(command.toLatin1())) < 0) - { - qCritical() << "Send command failed!"; - } + qCritical() << "Send command failed!"; } } diff --git a/commandpanel.h b/commandpanel.h --- a/commandpanel.h +++ b/commandpanel.h @@ -22,6 +22,7 @@ #include #include +#include #include "commandwidget.h" @@ -43,7 +44,7 @@ private: private slots: void newCommand(); - void sendCommand(QString command, bool ascii); + void sendCommand(QByteArray command); }; #endif // COMMANDPANEL_H diff --git a/commandwidget.cpp b/commandwidget.cpp --- a/commandwidget.cpp +++ b/commandwidget.cpp @@ -57,7 +57,12 @@ void CommandWidget::onSendClicked() return; } - if (!isASCIIMode()) // hex mode + if (isASCIIMode()) + { + qDebug() << "Sending:" << command; + emit sendCommand(command.toLatin1()); + } + else // hex mode { command = command.remove(' '); // check if nibbles are missing @@ -65,13 +70,14 @@ void CommandWidget::onSendClicked() { qWarning() << "HEX command is missing a nibble at the end!"; ui->leCommand->setFocus(Qt::OtherFocusReason); + // highlight the byte that is missing a nibble (last byte obviously) int textSize = ui->leCommand->text().size(); ui->leCommand->setSelection(textSize-1, textSize); return; } + qDebug() << "Sending HEX:" << command; + emit sendCommand(QByteArray::fromHex(command.toLatin1())); } - - emit sendCommand(command, ui->pbASCII->isChecked()); } void CommandWidget::onASCIIToggled(bool checked) diff --git a/commandwidget.h b/commandwidget.h --- a/commandwidget.h +++ b/commandwidget.h @@ -21,7 +21,7 @@ #define COMMANDWIDGET_H #include -#include +#include namespace Ui { class CommandWidget; @@ -42,12 +42,10 @@ signals: // // in case of hex mode, command text should be a hexadecimal // string containing hexadecimal characters only (not even spaces) - void sendCommand(QString command, bool ascii); + void sendCommand(QByteArray command); private: Ui::CommandWidget *ui; - QString storedAsciiText; - QString storedHexText; bool isASCIIMode(); // true: ascii mode, false hex mode