diff --git a/ground/src/app/app.pro b/ground/src/app/app.pro index 30b7d4c46..5b74f8fed 100644 --- a/ground/src/app/app.pro +++ b/ground/src/app/app.pro @@ -10,8 +10,8 @@ SOURCES += main.cpp include(../rpath.pri) win32 { - CONFIG(debug, debug|release):LIBS *= -lExtensionSystemd -lAggregationd - else:LIBS *= -lExtensionSystem -lAggregation + CONFIG(debug, debug|release):LIBS *= -lExtensionSystemd -lAggregationd -lQExtSerialPortd + else:LIBS *= -lExtensionSystem -lAggregation -lQExtSerialPort RC_FILE = openpilotgcs.rc target.path = /bin diff --git a/ground/src/plugins/coreplugin/connectionmanager.cpp b/ground/src/plugins/coreplugin/connectionmanager.cpp index 25421d0df..500b7acb2 100644 --- a/ground/src/plugins/coreplugin/connectionmanager.cpp +++ b/ground/src/plugins/coreplugin/connectionmanager.cpp @@ -37,6 +37,8 @@ #include "fancytabwidget.h" #include "fancyactionbar.h" #include "mainwindow.h" +#include "qextserialport/src/qextserialenumerator.h" +#include "qextserialport/src/qextserialport.h" #include #include @@ -137,7 +139,23 @@ void ConnectionManager::onConnectPressed() if(m_connectionDevice.connection) { QIODevice *ioDev = m_connectionDevice.connection->openDevice(m_connectionDevice.devName); - + /*QextSerialPort *ioDev = new QextSerialPort("COM5"); + ioDev->setBaudRate(BAUD57600); + ioDev->setFlowControl(FLOW_OFF);*/ + ioDev->open(QIODevice::ReadWrite); + /*if(ioDev->isOpen()) + ioDev->putChar('M');*/ + QList ports = QextSerialEnumerator::getPorts(); + qDebug() << "List of ports:"; + for (int i = 0; i < ports.size(); i++) { + qDebug() << "port name:" << ports.at(i).portName; + qDebug() << "friendly name:" << ports.at(i).friendName; + qDebug() << "physical name:" << ports.at(i).physName; + qDebug() << "enumerator name:" << ports.at(i).enumName; + qDebug() << "vendor ID:" << QString::number(ports.at(i).vendorID, 16); + qDebug() << "product ID:" << QString::number(ports.at(i).productID, 16); + qDebug() << "==================================="; + } if(ioDev) { emit deviceConnected(ioDev); diff --git a/ground/src/plugins/coreplugin/coreplugin_dependencies.pri b/ground/src/plugins/coreplugin/coreplugin_dependencies.pri index 8b548e717..db9796287 100644 --- a/ground/src/plugins/coreplugin/coreplugin_dependencies.pri +++ b/ground/src/plugins/coreplugin/coreplugin_dependencies.pri @@ -1,2 +1,3 @@ include(../../libs/extensionsystem/extensionsystem.pri) include(../../libs/utils/utils.pri) +include(../../libs/qextserialport/qextserialport.pri) diff --git a/ground/src/plugins/rawhid/pjrc_rawhid_win.cpp b/ground/src/plugins/rawhid/pjrc_rawhid_win.cpp index e1f84ba82..bbebd9504 100644 --- a/ground/src/plugins/rawhid/pjrc_rawhid_win.cpp +++ b/ground/src/plugins/rawhid/pjrc_rawhid_win.cpp @@ -36,7 +36,7 @@ #include #include -#define printf //qDebug +#define printf qDebug typedef struct hid_struct hid_t; struct hid_struct { @@ -167,7 +167,7 @@ int pjrc_rawhid::open(int max, int vid, int pid, int usage_page, int usage) int pjrc_rawhid::receive(int num, void *buf, int len, int timeout) { hid_t *hid; - unsigned char tmpbuf[516]; + unsigned char tmpbuf[516]={0}; OVERLAPPED ov; DWORD n, r; @@ -213,11 +213,11 @@ return_error: int pjrc_rawhid::send(int num, void *buf, int len, int timeout) { hid_t *hid; - unsigned char tmpbuf[516]; + unsigned char tmpbuf[64]={0}; OVERLAPPED ov; DWORD n, r; - if (sizeof(tmpbuf) < len + 1) return -1; + if (sizeof(tmpbuf) < (len + 1)) return -1; hid = get_hid(num); if (!hid || !hid->open) return -1; EnterCriticalSection(&tx_mutex); @@ -226,7 +226,7 @@ int pjrc_rawhid::send(int num, void *buf, int len, int timeout) ov.hEvent = tx_event; tmpbuf[0] = 0; memcpy(tmpbuf + 1, buf, len); - if (!WriteFile(hid->handle, tmpbuf, len + 1, NULL, &ov)) { + if (!WriteFile(hid->handle, tmpbuf, 64, NULL, &ov)) { if (GetLastError() != ERROR_IO_PENDING) goto return_error; r = WaitForSingleObject(tx_event, timeout); if (r == WAIT_TIMEOUT) goto return_timeout; @@ -343,9 +343,12 @@ static void hid_close(hid_t *hid) static void print_win32_err(void) { char buf[256]; + char temp[256]; DWORD err; err = GetLastError(); - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, (WCHAR*)buf, sizeof(buf), NULL); - printf("err %ld: %s\n", err, buf); + //FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, (WCHAR*)buf, sizeof(buf), NULL); + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), (WCHAR*)buf, sizeof(buf), NULL); + WideCharToMultiByte( CP_ACP, 0, (WCHAR*)buf, sizeof(buf), temp, sizeof(temp), NULL, NULL ); + printf("err %ld: %s\n", err, temp); }