Changeset View
Changeset View
Standalone View
Standalone View
src/core/atcore.cpp
1 | /* AtCore | 1 | /* AtCore | ||
---|---|---|---|---|---|
2 | Copyright (C) <2016> | 2 | Copyright (C) <2016 - 2018> | ||
3 | 3 | | |||
4 | Authors: | 4 | Authors: | ||
5 | Tomaz Canabrava <tcanabrava@kde.org> | 5 | Tomaz Canabrava <tcanabrava@kde.org> | ||
6 | Chris Rizzitello <rizzitello@kde.org> | 6 | Chris Rizzitello <rizzitello@kde.org> | ||
7 | Patrick José Pereira <patrickjp@kde.org> | 7 | Patrick José Pereira <patrickjp@kde.org> | ||
8 | Lays Rodrigues <lays.rodrigues@kde.org> | 8 | Lays Rodrigues <lays.rodrigues@kde.org> | ||
9 | 9 | | |||
10 | This library is free software; you can redistribute it and/or | 10 | This library is free software; you can redistribute it and/or | ||
▲ Show 20 Lines • Show All 202 Lines • ▼ Show 20 Line(s) | 212 | } else { | |||
213 | qCDebug(ATCORE_CORE) << "Plugin:" << fwName << ": Not found."; | 213 | qCDebug(ATCORE_CORE) << "Plugin:" << fwName << ": Not found."; | ||
214 | emit atcoreMessage(tr("No plugin found for %1.").arg(fwName)); | 214 | emit atcoreMessage(tr("No plugin found for %1.").arg(fwName)); | ||
215 | } | 215 | } | ||
216 | } | 216 | } | ||
217 | 217 | | |||
218 | bool AtCore::initSerial(const QString &port, int baud) | 218 | bool AtCore::initSerial(const QString &port, int baud) | ||
219 | { | 219 | { | ||
220 | d->serial = new SerialLayer(port, baud); | 220 | d->serial = new SerialLayer(port, baud); | ||
221 | connect(serial(), &SerialLayer::serialError, this, &AtCore::handleSerialError); | ||||
221 | if (serialInitialized() && d->serial->isWritable()) { | 222 | if (serialInitialized() && d->serial->isWritable()) { | ||
222 | setState(AtCore::CONNECTING); | 223 | setState(AtCore::CONNECTING); | ||
223 | connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); | 224 | connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); | ||
224 | d->serialTimer->stop(); | 225 | d->serialTimer->stop(); | ||
225 | return true; | 226 | return true; | ||
226 | } else { | 227 | } else { | ||
227 | qCDebug(ATCORE_CORE) << "Failed to open device for Read / Write."; | 228 | qCDebug(ATCORE_CORE) << "Failed to open device for Read / Write."; | ||
228 | emit atcoreMessage(tr("Failed to open device in read/write mode.")); | 229 | emit atcoreMessage(tr("Failed to open device in read/write mode.")); | ||
▲ Show 20 Lines • Show All 161 Lines • ▼ Show 20 Line(s) | 390 | if (firmwarePlugin()->name() != QStringLiteral("Grbl")) { | |||
390 | disconnect(d->tempTimer, &QTimer::timeout, this, &AtCore::checkTemperature); | 391 | disconnect(d->tempTimer, &QTimer::timeout, this, &AtCore::checkTemperature); | ||
391 | d->tempTimer->stop(); | 392 | d->tempTimer->stop(); | ||
392 | } | 393 | } | ||
393 | //Attempt to unload the firmware plugin. | 394 | //Attempt to unload the firmware plugin. | ||
394 | QString name = firmwarePlugin()->name(); | 395 | QString name = firmwarePlugin()->name(); | ||
395 | QString msg = d->pluginLoader.unload() ? QStringLiteral("closed.") : QStringLiteral("Failed to close."); | 396 | QString msg = d->pluginLoader.unload() ? QStringLiteral("closed.") : QStringLiteral("Failed to close."); | ||
396 | qCDebug(ATCORE_CORE) << QStringLiteral("Firmware plugin %1 %2").arg(name, msg); | 397 | qCDebug(ATCORE_CORE) << QStringLiteral("Firmware plugin %1 %2").arg(name, msg); | ||
397 | } | 398 | } | ||
399 | disconnect(serial(), &SerialLayer::serialError, this, &AtCore::handleSerialError); | ||||
398 | serial()->close(); | 400 | serial()->close(); | ||
399 | //Clear our copy of the sdcard filelist | 401 | //Clear our copy of the sdcard filelist | ||
400 | clearSdCardFileList(); | 402 | clearSdCardFileList(); | ||
401 | setState(AtCore::DISCONNECTED); | 403 | setState(AtCore::DISCONNECTED); | ||
402 | d->serialTimer->start(); | 404 | d->serialTimer->start(); | ||
403 | } | 405 | } | ||
404 | } | 406 | } | ||
405 | 407 | | |||
▲ Show 20 Lines • Show All 359 Lines • ▼ Show 20 Line(s) | |||||
765 | void AtCore::sdCardPrintStatus() | 767 | void AtCore::sdCardPrintStatus() | ||
766 | { | 768 | { | ||
767 | //One request for the Sd Job status in the queue at a time. | 769 | //One request for the Sd Job status in the queue at a time. | ||
768 | if (d->commandQueue.contains(GCode::toCommand(GCode::M27))) { | 770 | if (d->commandQueue.contains(GCode::toCommand(GCode::M27))) { | ||
769 | return; | 771 | return; | ||
770 | } | 772 | } | ||
771 | pushCommand(GCode::toCommand(GCode::M27)); | 773 | pushCommand(GCode::toCommand(GCode::M27)); | ||
772 | } | 774 | } | ||
775 | | ||||
776 | void AtCore::handleSerialError(QSerialPort::SerialPortError error) | ||||
777 | { | ||||
778 | QString errorString; | ||||
779 | | ||||
780 | switch (error) { | ||||
781 | case (QSerialPort::DeviceNotFoundError): | ||||
782 | errorString = tr("Device not found"); | ||||
783 | break; | ||||
784 | case (QSerialPort::WriteError): | ||||
785 | errorString = tr("Unable to write to device"); | ||||
786 | break; | ||||
787 | case (QSerialPort::ReadError): | ||||
788 | errorString = tr("Unable to read from device"); | ||||
789 | break; | ||||
790 | case (QSerialPort::ResourceError): | ||||
791 | case (QSerialPort::TimeoutError): | ||||
792 | errorString = tr("The device no longer available"); | ||||
793 | closeConnection(); | ||||
794 | break; | ||||
795 | case (QSerialPort::UnsupportedOperationError): | ||||
796 | errorString = tr("Device does not support opperation"); | ||||
797 | break; | ||||
798 | case (QSerialPort::UnknownError): | ||||
799 | errorString = tr("Unknown Error"); | ||||
800 | break; | ||||
801 | default: | ||||
802 | //Not Directly processed errors | ||||
803 | //QSerialPort::NoError, No error has happened | ||||
804 | //QSerialPort::PermissionError), Already handled. | ||||
805 | //QSerialPort::OpenError), Already handled. | ||||
806 | //QSerialPort::NotOpenError, SerialLayer destroyed if not connected. | ||||
807 | //QSerialPort::ParityError, Obsolete. Qt Docs "We strongly advise against using it in new code." | ||||
808 | //QSerialPort::FramingError, Obsolete. Qt Docs "We strongly advise against using it in new code." | ||||
809 | //QSerialPort::BreakConditionError, Obsolete. Qt Docs "We strongly advise against using it in new code." | ||||
810 | return; | ||||
811 | };//End of Switch | ||||
812 | qCDebug(ATCORE_CORE) << "SerialError:" << errorString; | ||||
813 | emit atcoreMessage(QStringLiteral("SerialError: %1").arg(errorString)); | ||||
814 | } |