Commit 2c486689 authored by Don Gagne's avatar Don Gagne

Merge pull request #975 from DonLakeFlyer/UpgradeErrors

Better error reporting during Firmware Upgrade
parents a16ca740 d7257ad4
......@@ -755,6 +755,8 @@ QString QextSerialPort::errorString()
return tr("Permission denied");
case E_AGAIN:
return tr("Device is already locked");
case E_OS_SPECIFIC:
return tr("OS error: %1").arg(d->lastOSErrString);
default:
return tr("Unknown error: %1").arg(d->lastErr);
}
......
......@@ -68,6 +68,7 @@
#define E_FILE_NOT_FOUND 15
#define E_PERMISSION_DENIED 16
#define E_AGAIN 17
#define E_OS_SPECIFIC 18 // Error did not translate, os error code in lastOSErr
enum BaudRateType
{
......@@ -201,7 +202,7 @@ public:
bool canReadLine() const;
QByteArray readAll();
ulong lastError() const;
ulong lastError() const; ulong lastOpenOSError() const;
ulong lineStatus();
QString errorString();
......
......@@ -197,6 +197,8 @@ public:
QextReadBuffer readBuffer;
int settingsDirtyFlags;
ulong lastErr;
ulong lastOSErr;
QString lastOSErrString;
QextSerialPort::QueryMode queryMode;
// platform specific members
......
......@@ -155,6 +155,11 @@ void QextSerialPortPrivate::translateError(ulong error)
case EAGAIN:
lastErr = E_AGAIN;
break;
default:
lastOSErr = error;
lastOSErrString = strerror(error);
lastErr = E_OS_SPECIFIC;
break;
}
}
......
......@@ -106,6 +106,7 @@ bool QextSerialPortPrivate::open_sys(QIODevice::OpenMode mode)
if (queryMode == QextSerialPort::EventDriven) {
if (!SetCommMask(handle, EV_TXEMPTY | EV_RXCHAR | EV_DSR)) {
QESP_WARNING()<<"failed to set Comm Mask. Error code:"<<GetLastError();
translateError(GetLastError());
return false;
}
winEventNotifier = new QWinEventNotifier(overlap.hEvent, q);
......@@ -115,6 +116,7 @@ bool QextSerialPortPrivate::open_sys(QIODevice::OpenMode mode)
}
return true;
}
translateError(GetLastError());
return false;
}
......@@ -159,30 +161,18 @@ qint64 QextSerialPortPrivate::bytesAvailable_sys() const
*/
void QextSerialPortPrivate::translateError(ulong error)
{
if (error & CE_BREAK) {
lastErr = E_BREAK_CONDITION;
}
else if (error & CE_FRAME) {
lastErr = E_FRAMING_ERROR;
}
else if (error & CE_IOE) {
lastErr = E_IO_ERROR;
}
else if (error & CE_MODE) {
lastErr = E_INVALID_FD;
}
else if (error & CE_OVERRUN) {
lastErr = E_BUFFER_OVERRUN;
}
else if (error & CE_RXPARITY) {
lastErr = E_RECEIVE_PARITY_ERROR;
}
else if (error & CE_RXOVER) {
lastErr = E_RECEIVE_OVERFLOW;
}
else if (error & CE_TXFULL) {
lastErr = E_TRANSMIT_OVERFLOW;
}
lastOSErr = error;
lastErr = E_OS_SPECIFIC;
char buf[256];
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
buf, sizeof(buf),
NULL);
lastOSErrString = buf;
}
/*
......@@ -212,8 +202,8 @@ qint64 QextSerialPortPrivate::readData_sys(char *data, qint64 maxSize)
if (!failed)
return (qint64)bytesRead;
lastErr = E_READ_FAILED;
return -1;
translateError(GetLastError());
return -1;
}
/*
......@@ -257,7 +247,7 @@ qint64 QextSerialPortPrivate::writeData_sys(const char *data, qint64 maxSize)
if (!failed)
return (qint64)bytesWritten;
lastErr = E_WRITE_FAILED;
translateError(GetLastError());
return -1;
}
......
This diff is collapsed.
......@@ -43,9 +43,6 @@ public:
/// @brief Returns the error message associated with the last failed call to one of the bootloader
/// utility routine below.
QString errorString(void) { return _errorString; }
static const bool warnOnError = true; ///< call qWarning to log error message on error
static const bool noWarnOnError = false; ///< Don't call qWarning on error
/// @brief Write a byte to the port
/// @param port Port to write to
......@@ -58,13 +55,12 @@ public:
/// @brief Read a set of bytes from the port
/// @param data Read bytes into this buffer
/// @param maxSize Number of bytes to read
/// @param warnOnError true: Log error using qWarning
/// @param readTimeout Msecs to wait for bytes to become available on port
bool read(QextSerialPort* port, uint8_t* data, qint64 maxSize, bool warnOnError, int readTimeout = _readTimout);
bool read(QextSerialPort* port, uint8_t* data, qint64 maxSize, int readTimeout = _readTimout);
/// @brief Read a PROTO_SYNC command response from the bootloader
/// @param responseTimeout Msecs to wait for response bytes to become available on port
bool getCommandResponse(QextSerialPort* port, bool warnOnError, const int responseTimeout = _responseTimeout);
bool getCommandResponse(QextSerialPort* port, const int responseTimeout = _responseTimeout);
/// @brief Send a PROTO_GET_DEVICE command to retrieve a value from the bootloader
/// @param param Value to retrieve using INFO_BOARD_* enums
......@@ -74,7 +70,7 @@ public:
/// @brief Send a command to the bootloader
/// @param cmd Command to send using PROTO_* enums
/// @return true: Command sent and valid sync response returned
bool sendCommand(QextSerialPort* port, uint8_t cmd, bool warnOnError, int responseTimeout = _responseTimeout);
bool sendCommand(QextSerialPort* port, uint8_t cmd, int responseTimeout = _responseTimeout);
/// @brief Program the board with the specified firmware
bool program(QextSerialPort* port, const QString& firmwareFilename);
......
......@@ -102,11 +102,6 @@ void PX4FirmwareUpgradeThreadWorker::_findBoardOnce(void)
portName = info.systemLocation();
portDescription = info.description();
#ifdef Q_OS_WIN
// Stupid windows fixes
portName.prepend("\\\\.\\");
#endif
_closeFind();
emit foundBoard(_findBoardFirstAttempt, portName, portDescription);
return;
......@@ -121,10 +116,10 @@ void PX4FirmwareUpgradeThreadWorker::_findBoardOnce(void)
void PX4FirmwareUpgradeThreadWorker::findBootloader(const QString portName, int msecTimeout)
{
connect(_timerRetry, &QTimer::timeout, this, &PX4FirmwareUpgradeThreadWorker::_findBootloaderOnce);
Q_UNUSED(msecTimeout);
// Once the port shows up, we only try to connect to the bootloader a single time
_portName = portName;
_timerTimeout->start(msecTimeout);
_elapsed.start();
_findBootloaderOnce();
}
......@@ -144,28 +139,16 @@ void PX4FirmwareUpgradeThreadWorker::_findBootloaderOnce(void)
qDebug() << "Found bootloader";
emit foundBootloader(bootloaderVersion, boardID, flashSize);
return;
} else {
_closeFind();
_bootloaderPort->close();
_bootloaderPort->deleteLater();
_bootloaderPort = NULL;
qDebug() << "Bootloader Get Board Info error:" << _bootloader->errorString();
emit error(commandBootloader, _bootloader->errorString());
return;
}
} else {
_closeFind();
_bootloaderPort->close();
_bootloaderPort->deleteLater();
_bootloaderPort = NULL;
qDebug() << "Bootloader sync failed";
emit bootloaderSyncFailed();
return;
}
}
emit updateProgress(_elapsed.elapsed(), _timerTimeout->interval());
_timerRetry->start();
_closeFind();
_bootloaderPort->close();
_bootloaderPort->deleteLater();
_bootloaderPort = NULL;
qDebug() << "Bootloader error:" << _bootloader->errorString();
emit error(commandBootloader, _bootloader->errorString());
}
void PX4FirmwareUpgradeThreadWorker::_closeFind(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment