diff --git a/src/core/atcore.h b/src/core/atcore.h --- a/src/core/atcore.h +++ b/src/core/atcore.h @@ -155,13 +155,6 @@ */ QStringList portSpeeds() const; - /** - * @brief Main access to the serialLayer - * @return Current serialLayer - * @sa initSerial(),serialPorts(),closeConnection() - */ - SerialLayer *serial() const; - /** * @brief Close the current serial connection * @sa initSerial(),serial(),serialPorts(),AtCore::close() @@ -303,6 +296,12 @@ */ void sdCardFileListChanged(const QStringList &fileList); + /** + * @brief pushedCommand via serialLayer connect this to your log to see send commands + * @param comm: the command sent. + */ + void pushedCommand(const QByteArray &comm); + public slots: /** @@ -490,6 +489,12 @@ */ void newMessage(const QByteArray &message); + /** + * @brief Connect to SerialLayer::pushedCommand + * @param command: newCommand. + */ + void newCommand(const QByteArray &command); + /** * @brief Search for firmware string in message. * A Helper function for Firmware detection diff --git a/src/core/atcore.cpp b/src/core/atcore.cpp --- a/src/core/atcore.cpp +++ b/src/core/atcore.cpp @@ -111,11 +111,6 @@ return versionString; } -SerialLayer *AtCore::serial() const -{ - return d->serial; -} - IFirmware *AtCore::firmwarePlugin() const { return d->firmwarePlugin; @@ -200,8 +195,8 @@ //Plugin was loaded successfully. d->firmwarePlugin = qobject_cast(d->pluginLoader.instance()); firmwarePlugin()->init(this); - disconnect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); - connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::newMessage); + disconnect(d->serial, &SerialLayer::receivedCommand, this, &AtCore::findFirmware); + connect(d->serial, &SerialLayer::receivedCommand, this, &AtCore::newMessage); connect(firmwarePlugin(), &IFirmware::readyForCommand, this, &AtCore::processQueue); d->ready = true; // ready on new firmware load if (firmwarePlugin()->name() != QStringLiteral("Grbl")) { @@ -223,10 +218,11 @@ } d->serial = new SerialLayer(port, baud); - connect(serial(), &SerialLayer::serialError, this, &AtCore::handleSerialError); + connect(d->serial, &SerialLayer::serialError, this, &AtCore::handleSerialError); if (serialInitialized() && d->serial->isWritable()) { - setState(AtCore::STATES::CONNECTING); - connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); + setState(AtCore::CONNECTING); + connect(d->serial, &SerialLayer::pushedCommand, this, &AtCore::newCommand); + connect(d->serial, &SerialLayer::receivedCommand, this, &AtCore::findFirmware); d->serialTimer->stop(); return true; } else { @@ -246,7 +242,7 @@ QString AtCore::connectedPort() const { - return serial()->portName(); + return d->serial->portName(); } QStringList AtCore::serialPorts() const @@ -322,6 +318,11 @@ emit receivedMessage(d->lastMessage); } +void AtCore::newCommand(const QByteArray &command) +{ + emit pushedCommand(command); +} + void AtCore::setRelativePosition() { pushCommand(GCode::toCommand(GCode::GCommands::G91)); @@ -394,7 +395,7 @@ } if (firmwarePluginLoaded()) { disconnect(firmwarePlugin(), &IFirmware::readyForCommand, this, &AtCore::processQueue); - disconnect(serial(), &SerialLayer::receivedCommand, this, &AtCore::newMessage); + disconnect(d->serial, &SerialLayer::receivedCommand, this, &AtCore::newMessage); if (firmwarePlugin()->name() != QStringLiteral("Grbl")) { disconnect(d->tempTimer, &QTimer::timeout, this, &AtCore::checkTemperature); d->tempTimer->stop(); @@ -405,8 +406,9 @@ qCDebug(ATCORE_CORE) << QStringLiteral("Firmware plugin %1 %2").arg(name, msg); } //Do not reset the connect on disconnect when closing this will cause a reset on connect for the next connection. - disconnect(serial(), &SerialLayer::serialError, this, &AtCore::handleSerialError); - serial()->close(); + disconnect(d->serial, &SerialLayer::serialError, this, &AtCore::handleSerialError); + disconnect(d->serial, &SerialLayer::pushedCommand, this, &AtCore::newMessage); + d->serial->close(); //Clear our copy of the sdcard filelist clearSdCardFileList(); setState(AtCore::STATES::DISCONNECTED); @@ -462,7 +464,7 @@ } } //push command through serial to bypass atcore's queue. - serial()->pushCommand(GCode::toCommand(GCode::MCommands::M112).toLocal8Bit()); + d->serial->pushCommand(GCode::toCommand(GCode::MCommands::M112).toLocal8Bit()); } void AtCore::stopSdPrint() @@ -479,7 +481,7 @@ { if (serialInitialized()) { qCDebug(ATCORE_CORE) << "Sending " << GCode::description(GCode::MCommands::M115); - serial()->pushCommand(GCode::toCommand(GCode::MCommands::M115).toLocal8Bit()); + d->serial->pushCommand(GCode::toCommand(GCode::MCommands::M115).toLocal8Bit()); } else { qCDebug(ATCORE_CORE) << "There is no open device to send commands"; } @@ -668,9 +670,9 @@ QString text = d->commandQueue.takeAt(0); if (firmwarePluginLoaded()) { - serial()->pushCommand(firmwarePlugin()->translate(text)); + d->serial->pushCommand(firmwarePlugin()->translate(text)); } else { - serial()->pushCommand(text.toLocal8Bit()); + d->serial->pushCommand(text.toLocal8Bit()); } d->ready = false; } @@ -705,7 +707,7 @@ QStringList AtCore::portSpeeds() const { - return serial()->validBaudRates(); + return d->serial->validBaudRates(); } void AtCore::disableMotors(uint delay) diff --git a/src/widgets/logwidget.h b/src/widgets/logwidget.h --- a/src/widgets/logwidget.h +++ b/src/widgets/logwidget.h @@ -45,7 +45,7 @@ void appendRLog(const QByteArray &bmsg); /** - * @brief Connect to AtCore::SerialLayer::pushedCommand + * @brief Connect to AtCore::pushedCommand * @param bmsg: Message */ void appendSLog(const QByteArray &bmsg); diff --git a/testclient/mainwindow.cpp b/testclient/mainwindow.cpp --- a/testclient/mainwindow.cpp +++ b/testclient/mainwindow.cpp @@ -429,7 +429,7 @@ if (core->state() == AtCore::DISCONNECTED) { if (core->initSerial(comboPort->currentText(), comboBAUD->currentText().toInt(), cbReset->isChecked())) { connect(core, &AtCore::receivedMessage, logWidget, &LogWidget::appendRLog); - connect(core->serial(), &SerialLayer::pushedCommand, logWidget, &LogWidget::appendSLog); + connect(core, &AtCore::pushedCommand, logWidget, &LogWidget::appendSLog); logWidget->appendLog(tr("Serial connected")); if (!comboPlugin->currentText().contains(tr("Autodetect"))) { core->loadFirmwarePlugin(comboPlugin->currentText()); @@ -441,7 +441,7 @@ } } else { disconnect(core, &AtCore::receivedMessage, logWidget, &LogWidget::appendRLog); - disconnect(core->serial(), &SerialLayer::pushedCommand, logWidget, &LogWidget::appendSLog); + disconnect(core, &AtCore::pushedCommand, logWidget, &LogWidget::appendSLog); core->closeConnection(); core->setState(AtCore::DISCONNECTED); logWidget->appendLog(tr("Disconnected"));