Changeset View
Changeset View
Standalone View
Standalone View
src/core/atcore.cpp
Show All 30 Lines | |||||
31 | #include <QTime> | 31 | #include <QTime> | ||
32 | #include <QTimer> | 32 | #include <QTimer> | ||
33 | #include <QThread> | 33 | #include <QThread> | ||
34 | #include <QMetaEnum> | 34 | #include <QMetaEnum> | ||
35 | #include <QProcess> | 35 | #include <QProcess> | ||
36 | 36 | | |||
37 | #include "atcore.h" | 37 | #include "atcore.h" | ||
38 | #include "atcore_version.h" | 38 | #include "atcore_version.h" | ||
39 | #include "copythread.h" | ||||
39 | #include "seriallayer.h" | 40 | #include "seriallayer.h" | ||
40 | #include "gcodecommands.h" | 41 | #include "gcodecommands.h" | ||
41 | #include "printthread.h" | 42 | #include "printthread.h" | ||
42 | #include "atcore_default_folders.h" | 43 | #include "atcore_default_folders.h" | ||
43 | 44 | | |||
44 | Q_LOGGING_CATEGORY(ATCORE_PLUGIN, "org.kde.atelier.core.plugin") | 45 | Q_LOGGING_CATEGORY(ATCORE_PLUGIN, "org.kde.atelier.core.plugin") | ||
45 | Q_LOGGING_CATEGORY(ATCORE_CORE, "org.kde.atelier.core") | 46 | Q_LOGGING_CATEGORY(ATCORE_CORE, "org.kde.atelier.core") | ||
46 | /** | 47 | /** | ||
▲ Show 20 Lines • Show All 745 Lines • ▼ Show 20 Line(s) | 792 | connect(&process, &QProcess::errorOccurred, this, [this, &process] { | |||
792 | qCDebug(ATCORE_CORE) << "Stty Error:" << process.errorString(); | 793 | qCDebug(ATCORE_CORE) << "Stty Error:" << process.errorString(); | ||
793 | }); | 794 | }); | ||
794 | 795 | | |||
795 | #elif Q_OS_WIN | 796 | #elif Q_OS_WIN | ||
796 | //TODO: Disable hangup on windows. | 797 | //TODO: Disable hangup on windows. | ||
797 | #endif | 798 | #endif | ||
798 | } | 799 | } | ||
799 | 800 | | |||
800 | void AtCore::handleSerialError(QSerialPort::SerialPortError error) | 801 | void AtCore::handleSerialError(QSerialPort::SerialPortError error) | ||
tcanabrava: It’s good to say “could not mount se card” somehow, instead of just returning false. Same for… | |||||
801 | { | 802 | { | ||
802 | QString errorString; | 803 | QString errorString; | ||
803 | 804 | | |||
804 | switch (error) { | 805 | switch (error) { | ||
805 | case (QSerialPort::DeviceNotFoundError): | 806 | case (QSerialPort::DeviceNotFoundError): | ||
806 | errorString = tr("Device not found"); | 807 | errorString = tr("Device not found"); | ||
807 | break; | 808 | break; | ||
tcanabrava: Const | |||||
808 | case (QSerialPort::WriteError): | 809 | case (QSerialPort::WriteError): | ||
809 | errorString = tr("Unable to write to device"); | 810 | errorString = tr("Unable to write to device"); | ||
810 | break; | 811 | break; | ||
811 | case (QSerialPort::ReadError): | 812 | case (QSerialPort::ReadError): | ||
patrickelectric: QUrl::filename | |||||
fileName is a QString and we have no other QUrl in this object. if we add that we should do so in another patch. rizzitello: fileName is a QString and we have no other QUrl in this object. if we add that we should do so… | |||||
812 | errorString = tr("Unable to read from device"); | 813 | errorString = tr("Unable to read from device"); | ||
813 | break; | 814 | break; | ||
814 | case (QSerialPort::ResourceError): | 815 | case (QSerialPort::ResourceError): | ||
815 | case (QSerialPort::TimeoutError): | 816 | case (QSerialPort::TimeoutError): | ||
816 | errorString = tr("The device no longer available"); | 817 | errorString = tr("The device no longer available"); | ||
817 | closeConnection(); | 818 | closeConnection(); | ||
818 | break; | 819 | break; | ||
819 | case (QSerialPort::UnsupportedOperationError): | 820 | case (QSerialPort::UnsupportedOperationError): | ||
820 | errorString = tr("Device does not support opperation"); | 821 | errorString = tr("Device does not support opperation"); | ||
821 | break; | 822 | break; | ||
822 | case (QSerialPort::UnknownError): | 823 | case (QSerialPort::UnknownError): | ||
823 | errorString = tr("Unknown Error"); | 824 | errorString = tr("Unknown Error"); | ||
824 | break; | 825 | break; | ||
825 | default: | 826 | default: | ||
How do we poke the thread to see it’s state? I’d store the variable in the class or something tcanabrava: How do we poke the thread to see it’s state? I’d store the variable in the class or something | |||||
826 | //Not Directly processed errors | 827 | //Not Directly processed errors | ||
827 | //QSerialPort::NoError, No error has happened | 828 | //QSerialPort::NoError, No error has happened | ||
828 | //QSerialPort::PermissionError), Already handled. | 829 | //QSerialPort::PermissionError), Already handled. | ||
This needs to be adjusted to return true after the thread has finished rizzitello: This needs to be adjusted to return true after the thread has finished | |||||
829 | //QSerialPort::OpenError), Already handled. | 830 | //QSerialPort::OpenError), Already handled. | ||
830 | //QSerialPort::NotOpenError, SerialLayer destroyed if not connected. | 831 | //QSerialPort::NotOpenError, SerialLayer destroyed if not connected. | ||
831 | //QSerialPort::ParityError, Obsolete. Qt Docs "We strongly advise against using it in new code." | 832 | //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::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 | //QSerialPort::BreakConditionError, Obsolete. Qt Docs "We strongly advise against using it in new code." | ||
834 | return; | 835 | return; | ||
835 | };//End of Switch | 836 | };//End of Switch | ||
836 | qCDebug(ATCORE_CORE) << "SerialError:" << errorString; | 837 | qCDebug(ATCORE_CORE) << "SerialError:" << errorString; | ||
837 | emit atcoreMessage(QStringLiteral("SerialError: %1").arg(errorString)); | 838 | emit atcoreMessage(QStringLiteral("SerialError: %1").arg(errorString)); | ||
838 | } | 839 | } | ||
840 | | ||||
841 | bool AtCore::writeFiletoSd(const QString &fileName) | ||||
I belive this function shouldn't return bool, tcanabrava: I belive this function shouldn't return bool,
it should return enum class Reason { Success… | |||||
842 | { | ||||
843 | //Do a few sanity checks before attempting to write to SD. | ||||
844 | | ||||
845 | //Can't write an empty fileName. | ||||
846 | if (fileName.isEmpty()) { | ||||
patrickelectric: This should be a warning or a critical. | |||||
847 | qCDebug(ATCORE_CORE) << "Sd Write Failed: Empty fileName."; | ||||
848 | return false; | ||||
849 | } | ||||
850 | //Can not write if plugin doesn't have Sd Support. | ||||
851 | if (!d->firmwarePlugin->isSdSupported()) { | ||||
852 | qCDebug(ATCORE_CORE) << "Sd Write Failed: Firmware plugin does not support Sd functions."; | ||||
853 | return false; | ||||
854 | } | ||||
855 | | ||||
856 | //If the card is not mounted try to read the file list and mount it. | ||||
857 | if (!d->sdCardMounted) { | ||||
858 | getSDFileList(); | ||||
859 | if (!d->sdCardMounted) { | ||||
860 | qCDebug(ATCORE_CORE) << "Sd Write Failed unable to mount Sd Card"; | ||||
861 | return false; | ||||
862 | } | ||||
863 | } | ||||
864 | // Be sure the printer is IDLE | ||||
865 | if (d->printerState != AtCore::IDLE) { | ||||
866 | qCDebug(ATCORE_CORE) << "Sd Write Failed: Device is Busy"; | ||||
patrickelectric: or not connected | |||||
867 | return false; | ||||
868 | } | ||||
869 | | ||||
870 | const QString fname = fileName.mid(fileName.lastIndexOf(QStringLiteral("/")) + 1, fileName.length()); | ||||
patrickelectric: QFileInfo.fileName() | |||||
871 | | ||||
872 | //Process the gcode with a copyThread. | ||||
873 | QThread *thread = new QThread(); | ||||
874 | CopyThread *copyThread = new CopyThread(this, fileName); | ||||
875 | copyThread->moveToThread(thread); | ||||
876 | | ||||
877 | connect(copyThread, &CopyThread::copyProgressChanged, this, &AtCore::sdWriteProgressChanged, Qt::QueuedConnection); | ||||
878 | connect(thread, &QThread::started, copyThread, &CopyThread::start); | ||||
879 | connect(copyThread, &CopyThread::finished, thread, &QThread::quit); | ||||
880 | connect(thread, &QThread::finished, copyThread, &CopyThread::deleteLater); | ||||
patrickelectric: You need to check if file isReadable() | |||||
881 | | ||||
882 | connect(copyThread, &CopyThread::nextCommand, this, [this, ©Thread](const QString & nextLine) { | ||||
patrickelectric: Need to check if was able to open it | |||||
883 | serial()->pushCommand(nextLine.toLocal8Bit()); | ||||
884 | copyThread->processJob(); | ||||
885 | }); | ||||
886 | | ||||
887 | if (!thread->isRunning()) { | ||||
888 | thread->start(); | ||||
patrickelectric: uint64_t | |||||
rizzitello: file->size returns type qint64 | |||||
889 | } | ||||
patrickelectric: int | |||||
890 | | ||||
patrickelectric: uint64_t | |||||
rizzitello: fileSize of type qint64 so avoid warning. | |||||
891 | return true; | ||||
892 | } | ||||
patrickelectric: Category |
It’s good to say “could not mount se card” somehow, instead of just returning false. Same for the other checks