diff --git a/ground/gcs/src/experimental/USB_UPLOAD_TOOL/SSP/port.cpp b/ground/gcs/src/experimental/USB_UPLOAD_TOOL/SSP/port.cpp index 839d0aabd..12f39463d 100644 --- a/ground/gcs/src/experimental/USB_UPLOAD_TOOL/SSP/port.cpp +++ b/ground/gcs/src/experimental/USB_UPLOAD_TOOL/SSP/port.cpp @@ -33,8 +33,7 @@ port::port(QString name, bool debug) : mstatus(port::closed), debug(debug) { timer.start(); - sport = new QSerialPort(); - sport->setPortName(name); + sport = new QSerialPort(name, this); if (sport->open(QIODevice::ReadWrite)) { if (sport->setBaudRate(QSerialPort::Baud57600) && sport->setDataBits(QSerialPort::Data8) diff --git a/ground/gcs/src/experimental/USB_UPLOAD_TOOL/SSP/port.h b/ground/gcs/src/experimental/USB_UPLOAD_TOOL/SSP/port.h index 1edd8fc52..5525d400e 100644 --- a/ground/gcs/src/experimental/USB_UPLOAD_TOOL/SSP/port.h +++ b/ground/gcs/src/experimental/USB_UPLOAD_TOOL/SSP/port.h @@ -37,7 +37,9 @@ class QSerialPort; -class port { +class port : public QObject { + Q_OBJECT; + public: enum portstatus { open, closed, error }; diff --git a/ground/gcs/src/experimental/USB_UPLOAD_TOOL/dfu.cpp b/ground/gcs/src/experimental/USB_UPLOAD_TOOL/dfu.cpp index 8d4033f1a..369d13653 100644 --- a/ground/gcs/src/experimental/USB_UPLOAD_TOOL/dfu.cpp +++ b/ground/gcs/src/experimental/USB_UPLOAD_TOOL/dfu.cpp @@ -50,7 +50,7 @@ DFUObject::DFUObject(bool _debug, bool _use_serial, QString portname) : { numberOfDevices = 0; serialhandle = NULL; - info = NULL; + port *info = NULL; qRegisterMetaType("Status"); @@ -82,6 +82,11 @@ DFUObject::DFUObject(bool _debug, bool _use_serial, QString portname) : return; } + // transfer ownership of port to serialhandle thread + info->moveToThread(serialhandle); + connect(serialhandle, SIGNAL(finished()), info, SLOT(deleteLater())); + + // start the serialhandle thread serialhandle->start(); } else { /* @@ -142,7 +147,6 @@ DFUObject::~DFUObject() { if (use_serial) { delete serialhandle; - delete info; } else { /* if (hidHandle) { diff --git a/ground/gcs/src/experimental/USB_UPLOAD_TOOL/dfu.h b/ground/gcs/src/experimental/USB_UPLOAD_TOOL/dfu.h index 92b94e6be..7fa93daeb 100644 --- a/ground/gcs/src/experimental/USB_UPLOAD_TOOL/dfu.h +++ b/ground/gcs/src/experimental/USB_UPLOAD_TOOL/dfu.h @@ -40,7 +40,6 @@ #define BUF_LEN 64 // serial -class port; class qsspt; // usb @@ -190,7 +189,6 @@ private: int RWFlags; // Serial - port *info; qsspt *serialhandle; // USB