Changeset View
Changeset View
Standalone View
Standalone View
src/core/atcore.cpp
Show First 20 Lines • Show All 794 Lines • ▼ Show 20 Line(s) | 794 | connect(&process, &QProcess::errorOccurred, this, [&process] { | |||
---|---|---|---|---|---|
795 | qCDebug(ATCORE_CORE) << "Stty Error:" << process.errorString(); | 795 | qCDebug(ATCORE_CORE) << "Stty Error:" << process.errorString(); | ||
796 | }); | 796 | }); | ||
797 | 797 | | |||
798 | #elif defined(Q_OS_WIN) | 798 | #elif defined(Q_OS_WIN) | ||
799 | //TODO: Disable hangup on windows. | 799 | //TODO: Disable hangup on windows. | ||
800 | #endif | 800 | #endif | ||
801 | } | 801 | } | ||
802 | 802 | | |||
803 | void AtCore::handleSerialError(QSerialPort::SerialPortError error) | 803 | 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… | |||||
804 | { | 804 | { | ||
805 | QString errorString; | 805 | QString errorString; | ||
806 | 806 | | |||
807 | switch (error) { | 807 | switch (error) { | ||
808 | case (QSerialPort::DeviceNotFoundError): | 808 | case (QSerialPort::DeviceNotFoundError): | ||
809 | errorString = tr("Device not found"); | 809 | errorString = tr("Device not found"); | ||
810 | break; | 810 | break; | ||
tcanabrava: Const | |||||
811 | case (QSerialPort::WriteError): | 811 | case (QSerialPort::WriteError): | ||
812 | errorString = tr("Unable to write to device"); | 812 | errorString = tr("Unable to write to device"); | ||
813 | break; | 813 | break; | ||
814 | case (QSerialPort::ReadError): | 814 | 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… | |||||
815 | errorString = tr("Unable to read from device"); | 815 | errorString = tr("Unable to read from device"); | ||
816 | break; | 816 | break; | ||
817 | case (QSerialPort::ResourceError): | 817 | case (QSerialPort::ResourceError): | ||
818 | case (QSerialPort::TimeoutError): | 818 | case (QSerialPort::TimeoutError): | ||
819 | errorString = tr("The device no longer available"); | 819 | errorString = tr("The device no longer available"); | ||
820 | closeConnection(); | 820 | closeConnection(); | ||
821 | break; | 821 | break; | ||
822 | case (QSerialPort::UnsupportedOperationError): | 822 | case (QSerialPort::UnsupportedOperationError): | ||
823 | errorString = tr("Device does not support the operation"); | 823 | errorString = tr("Device does not support the operation"); | ||
824 | break; | 824 | break; | ||
825 | case (QSerialPort::UnknownError): | 825 | case (QSerialPort::UnknownError): | ||
826 | errorString = tr("Unknown Error"); | 826 | errorString = tr("Unknown Error"); | ||
827 | break; | 827 | break; | ||
828 | default: | 828 | 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 | |||||
829 | //Not Directly processed errors | 829 | //Not Directly processed errors | ||
830 | //QSerialPort::NoError, No error has happened | 830 | //QSerialPort::NoError, No error has happened | ||
831 | //QSerialPort::PermissionError), Already handled. | 831 | //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 | |||||
832 | //QSerialPort::OpenError), Already handled. | 832 | //QSerialPort::OpenError), Already handled. | ||
833 | //QSerialPort::NotOpenError, SerialLayer destroyed if not connected. | 833 | //QSerialPort::NotOpenError, SerialLayer destroyed if not connected. | ||
834 | //QSerialPort::ParityError, Obsolete. Qt Docs "We strongly advise against using it in new code." | 834 | //QSerialPort::ParityError, Obsolete. Qt Docs "We strongly advise against using it in new code." | ||
835 | //QSerialPort::FramingError, Obsolete. Qt Docs "We strongly advise against using it in new code." | 835 | //QSerialPort::FramingError, Obsolete. Qt Docs "We strongly advise against using it in new code." | ||
836 | //QSerialPort::BreakConditionError, Obsolete. Qt Docs "We strongly advise against using it in new code." | 836 | //QSerialPort::BreakConditionError, Obsolete. Qt Docs "We strongly advise against using it in new code." | ||
837 | return; | 837 | return; | ||
838 | };//End of Switch | 838 | };//End of Switch | ||
839 | qCDebug(ATCORE_CORE) << "SerialError:" << errorString; | 839 | qCDebug(ATCORE_CORE) << "SerialError:" << errorString; | ||
840 | emit atcoreMessage(QStringLiteral("SerialError: %1").arg(errorString)); | 840 | emit atcoreMessage(QStringLiteral("SerialError: %1").arg(errorString)); | ||
841 | } | 841 | } | ||
842 | | ||||
843 | bool AtCore::toSd(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… | |||||
844 | { | ||||
845 | //Do a few sanity checks before attempting to write to SD. | ||||
846 | //Can't write an empty fileName. | ||||
847 | if (fileName.isEmpty()) { | ||||
848 | qCDebug(ATCORE_CORE) << "Sd Write Failed: Empty fileName."; | ||||
patrickelectric: This should be a warning or a critical. | |||||
849 | return false; | ||||
850 | } | ||||
851 | //Can not write if plugin doesn't have Sd Support. | ||||
852 | if (!d->firmwarePlugin->isSdSupported()) { | ||||
853 | qCDebug(ATCORE_CORE) << "Sd Write Failed: Firmware plugin does not support Sd functions."; | ||||
854 | return false; | ||||
855 | } | ||||
856 | | ||||
857 | //If the card is not mounted try to read the file list and mount it. | ||||
858 | if (!d->sdCardMounted) { | ||||
859 | getSDFileList(); | ||||
860 | if (!d->sdCardMounted) { | ||||
861 | qCDebug(ATCORE_CORE) << "Sd Write Failed unable to mount Sd Card"; | ||||
862 | return false; | ||||
863 | } | ||||
864 | } | ||||
865 | // Be sure the printer is IDLE | ||||
866 | if (d->printerState == AtCore::DISCONNECTED) { | ||||
867 | qCDebug(ATCORE_CORE) << "No Device Connected."; | ||||
868 | return false; | ||||
patrickelectric: or not connected | |||||
869 | } else if (d->printerState != AtCore::IDLE) { | ||||
870 | qCDebug(ATCORE_CORE) << "Sd Write Failed: Device is Busy"; | ||||
871 | return false; | ||||
872 | } | ||||
patrickelectric: QFileInfo.fileName() | |||||
873 | | ||||
874 | //Process without thread. | ||||
875 | QFile *file = new QFile(fileName); | ||||
876 | if (!file->open(QFile::ReadOnly)) { | ||||
877 | qCDebug(ATCORE_CORE) << "Sd Write Failed unable to read file"; | ||||
878 | return false; | ||||
879 | } | ||||
880 | | ||||
881 | bool restoreTimer = d->tempTimer->isActive(); | ||||
882 | int timerTime = 0; | ||||
patrickelectric: You need to check if file isReadable() | |||||
883 | if (restoreTimer) { | ||||
884 | timerTime = d->tempTimer->interval(); | ||||
patrickelectric: Need to check if was able to open it | |||||
885 | d->tempTimer->stop(); | ||||
886 | } | ||||
887 | | ||||
888 | QString fname = QFileInfo(fileName).fileName(); | ||||
889 | QTextStream *txtStream = new QTextStream(file); | ||||
890 | const qint64 filesize = file->size(); | ||||
patrickelectric: uint64_t | |||||
rizzitello: file->size returns type qint64 | |||||
891 | float progress = 0; | ||||
patrickelectric: int | |||||
892 | qint64 stillSize = filesize; | ||||
patrickelectric: uint64_t | |||||
rizzitello: fileSize of type qint64 so avoid warning. | |||||
893 | QString cline; | ||||
894 | | ||||
895 | setState(AtCore::BUSY); | ||||
896 | emit sdWriteChanged(true); | ||||
897 | pushCommand(GCode::toCommand(GCode::M28, fname)); | ||||
898 | | ||||
899 | while (!txtStream->atEnd()) { | ||||
900 | if (state() == AtCore::STOP) { | ||||
901 | txtStream->setString(new QString()); | ||||
902 | progress = 100; | ||||
903 | } else { | ||||
904 | cline = txtStream->readLine(); | ||||
905 | stillSize -= cline.size() + 1; //remove read chars | ||||
906 | progress = float(filesize - stillSize) * 100 / float(filesize); | ||||
907 | } | ||||
908 | pushCommand(cline); | ||||
909 | processQueue(); | ||||
patrickelectric: Category | |||||
910 | serial()->waitForBytesWritten(); | ||||
911 | emit sdWriteProgressChanged(progress); | ||||
912 | qCDebug(ATCORE_CORE) << "Progress:" << progress << "Current Line:" << cline; | ||||
913 | } | ||||
914 | | ||||
915 | pushCommand(GCode::toCommand(GCode::M29, fname)); | ||||
916 | | ||||
917 | file->close(); | ||||
918 | emit sdWriteChanged(false); | ||||
919 | getSDFileList(); | ||||
920 | serial()->flush(); | ||||
921 | setState(AtCore::IDLE); | ||||
922 | if (restoreTimer) { | ||||
923 | d->tempTimer->start(timerTime); | ||||
924 | } | ||||
925 | return true; | ||||
926 | } |
It’s good to say “could not mount se card” somehow, instead of just returning false. Same for the other checks