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 207 Lines • ▼ Show 20 Line(s) | |||||
218 | 218 | | |||
219 | bool AtCore::initSerial(const QString &port, int baud, bool disableROC) | 219 | bool AtCore::initSerial(const QString &port, int baud, bool disableROC) | ||
220 | { | 220 | { | ||
221 | if (disableROC) { | 221 | if (disableROC) { | ||
222 | disableResetOnConnect(port); | 222 | disableResetOnConnect(port); | ||
223 | } | 223 | } | ||
224 | 224 | | |||
225 | d->serial = new SerialLayer(port, baud); | 225 | d->serial = new SerialLayer(port, baud); | ||
226 | connect(serial(), &SerialLayer::serialError, this, &AtCore::handleSerialError); | ||||
226 | if (serialInitialized() && d->serial->isWritable()) { | 227 | if (serialInitialized() && d->serial->isWritable()) { | ||
227 | setState(AtCore::CONNECTING); | 228 | setState(AtCore::CONNECTING); | ||
228 | connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); | 229 | connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); | ||
229 | d->serialTimer->stop(); | 230 | d->serialTimer->stop(); | ||
230 | return true; | 231 | return true; | ||
231 | } else { | 232 | } else { | ||
232 | qCDebug(ATCORE_CORE) << "Failed to open device for Read / Write."; | 233 | qCDebug(ATCORE_CORE) << "Failed to open device for Read / Write."; | ||
233 | emit atcoreMessage(tr("Failed to open device in read/write mode.")); | 234 | emit atcoreMessage(tr("Failed to open device in read/write mode.")); | ||
▲ Show 20 Lines • Show All 162 Lines • ▼ Show 20 Line(s) | 395 | if (firmwarePlugin()->name() != QStringLiteral("Grbl")) { | |||
396 | d->tempTimer->stop(); | 397 | d->tempTimer->stop(); | ||
397 | } | 398 | } | ||
398 | //Attempt to unload the firmware plugin. | 399 | //Attempt to unload the firmware plugin. | ||
399 | QString name = firmwarePlugin()->name(); | 400 | QString name = firmwarePlugin()->name(); | ||
400 | QString msg = d->pluginLoader.unload() ? QStringLiteral("closed.") : QStringLiteral("Failed to close."); | 401 | QString msg = d->pluginLoader.unload() ? QStringLiteral("closed.") : QStringLiteral("Failed to close."); | ||
401 | qCDebug(ATCORE_CORE) << QStringLiteral("Firmware plugin %1 %2").arg(name, msg); | 402 | qCDebug(ATCORE_CORE) << QStringLiteral("Firmware plugin %1 %2").arg(name, msg); | ||
402 | } | 403 | } | ||
403 | //Do not reset the connect on disconnect when closing this will cause a reset on connect for the next connection. | 404 | //Do not reset the connect on disconnect when closing this will cause a reset on connect for the next connection. | ||
405 | disconnect(serial(), &SerialLayer::serialError, this, &AtCore::handleSerialError); | ||||
404 | serial()->close(); | 406 | serial()->close(); | ||
405 | //Clear our copy of the sdcard filelist | 407 | //Clear our copy of the sdcard filelist | ||
406 | clearSdCardFileList(); | 408 | clearSdCardFileList(); | ||
407 | setState(AtCore::DISCONNECTED); | 409 | setState(AtCore::DISCONNECTED); | ||
408 | d->serialTimer->start(); | 410 | d->serialTimer->start(); | ||
409 | } | 411 | } | ||
410 | } | 412 | } | ||
411 | 413 | | |||
▲ Show 20 Lines • Show All 377 Lines • ▼ Show 20 Line(s) | 785 | //should work on all unix' | |||
789 | connect(&process, &QProcess::errorOccurred, this, [this, &process] { | 791 | connect(&process, &QProcess::errorOccurred, this, [this, &process] { | ||
790 | qCDebug(ATCORE_CORE) << "Stty Error:" << process.errorString(); | 792 | qCDebug(ATCORE_CORE) << "Stty Error:" << process.errorString(); | ||
791 | }); | 793 | }); | ||
792 | 794 | | |||
793 | #elif Q_OS_WIN | 795 | #elif Q_OS_WIN | ||
794 | //TODO: Disable hangup on windows. | 796 | //TODO: Disable hangup on windows. | ||
795 | #endif | 797 | #endif | ||
796 | } | 798 | } | ||
799 | | ||||
800 | void AtCore::handleSerialError(QSerialPort::SerialPortError error) | ||||
801 | { | ||||
802 | QString errorString; | ||||
803 | | ||||
804 | switch (error) { | ||||
805 | case (QSerialPort::DeviceNotFoundError): | ||||
806 | errorString = tr("Device not found"); | ||||
807 | break; | ||||
808 | case (QSerialPort::WriteError): | ||||
809 | errorString = tr("Unable to write to device"); | ||||
810 | break; | ||||
811 | case (QSerialPort::ReadError): | ||||
812 | errorString = tr("Unable to read from device"); | ||||
813 | break; | ||||
814 | case (QSerialPort::ResourceError): | ||||
815 | case (QSerialPort::TimeoutError): | ||||
816 | errorString = tr("The device no longer available"); | ||||
817 | closeConnection(); | ||||
818 | break; | ||||
819 | case (QSerialPort::UnsupportedOperationError): | ||||
820 | errorString = tr("Device does not support opperation"); | ||||
821 | break; | ||||
822 | case (QSerialPort::UnknownError): | ||||
823 | errorString = tr("Unknown Error"); | ||||
824 | break; | ||||
825 | default: | ||||
826 | //Not Directly processed errors | ||||
827 | //QSerialPort::NoError, No error has happened | ||||
828 | //QSerialPort::PermissionError), Already handled. | ||||
829 | //QSerialPort::OpenError), Already handled. | ||||
830 | //QSerialPort::NotOpenError, SerialLayer destroyed if not connected. | ||||
831 | //QSerialPort::ParityError, Obsolete. Qt Docs "We strongly advise against using it in new code." | ||||
832 | //QSerialPort::FramingError, Obsolete. Qt Docs "We strongly advise against using it in new code." | ||||
833 | //QSerialPort::BreakConditionError, Obsolete. Qt Docs "We strongly advise against using it in new code." | ||||
834 | return; | ||||
835 | };//End of Switch | ||||
836 | qCDebug(ATCORE_CORE) << "SerialError:" << errorString; | ||||
837 | emit atcoreMessage(QStringLiteral("SerialError: %1").arg(errorString)); | ||||
838 | } |