1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

Fixes the "halt" and "rescue" problems

This commit is contained in:
zedamota 2011-11-28 12:12:26 +00:00
parent 54bd0af16d
commit 5bc1a10774
8 changed files with 111 additions and 25 deletions

View File

@ -7,9 +7,11 @@ HEADERS += rawhid_global.h \
rawhid.h \
pjrc_rawhid.h \
rawhid_const.h \
usbmonitor.h
usbmonitor.h \
usbsignalfilter.h
SOURCES += rawhidplugin.cpp \
rawhid.cpp
rawhid.cpp \
usbsignalfilter.cpp
FORMS +=
RESOURCES +=
DEFINES += RAWHID_LIBRARY

View File

@ -31,7 +31,7 @@
#include "rawhid_global.h"
#include "rawhid.h"
#include "usbmonitor.h"
#include "usbsignalfilter.h"
#include "coreplugin/iconnection.h"
#include <extensionsystem/iplugin.h>

View File

@ -202,5 +202,4 @@ private:
#endif
};
#endif // USBMONITOR_H

View File

@ -78,6 +78,15 @@ USBMonitor::~USBMonitor()
QList<USBPortInfo> USBMonitor::availableDevices(int vid, int pid, int bcdDeviceMSB, int bcdDeviceLSB)
{
QList<USBPortInfo> allPorts = availableDevices();
qDebug()<<"USBMonitor::availableDevices list off all ports:";
qDebug()<<"USBMonitor::availableDevices total ports:"<<allPorts.length();
foreach (USBPortInfo info, allPorts) {
qDebug()<<"----------";
qDebug()<<"bcdDevice:"<<info.bcdDevice;
qDebug()<<"devicePath:"<<info.devicePath;
qDebug()<<"product:"<<info.product;
}
qDebug()<<"END OF LIST";
QList<USBPortInfo> thePortsWeWant;
qDebug()<<"USBMonitor::availableDevices bcdLSB="<<bcdDeviceLSB;
foreach (USBPortInfo port, allPorts) {
@ -86,6 +95,15 @@ QList<USBPortInfo> USBMonitor::availableDevices(int vid, int pid, int bcdDeviceM
( (port.bcdDevice&0x00ff) ==bcdDeviceLSB || bcdDeviceLSB==-1))
thePortsWeWant.append(port);
}
qDebug()<<"USBMonitor::availableDevices list off matching ports vid pid bcdMSD bcdLSD:"<<vid<<pid<<bcdDeviceMSB<<bcdDeviceLSB;
qDebug()<<"USBMonitor::availableDevices total matching ports:"<<thePortsWeWant.length();
foreach (USBPortInfo info, thePortsWeWant) {
qDebug()<<"----------";
qDebug()<<"bcdDevice:"<<info.bcdDevice;
qDebug()<<"devicePath:"<<info.devicePath;
qDebug()<<"product:"<<info.product;
}
qDebug()<<"END OF LIST";
return thePortsWeWant;
}
@ -160,6 +178,7 @@ bool USBRegistrationWidget::winEvent( MSG* message, long* result )
#endif
bool USBMonitor::matchAndDispatchChangedDevice(const QString & deviceID, const GUID & guid, WPARAM wParam)
{
qDebug()<<"USB_MONITOR matchAndDispatchChangedDevice deviceID="<<deviceID;
bool rv = false;
DWORD dwFlag = (DBT_DEVICEARRIVAL == wParam) ? DIGCF_PRESENT : DIGCF_ALLCLASSES;
HDEVINFO devInfo;
@ -178,10 +197,7 @@ bool USBMonitor::matchAndDispatchChangedDevice(const QString & deviceID, const G
info.devicePath=deviceID;
if( wParam == DBT_DEVICEARRIVAL )
{
qDebug()<<"INSERTION";
QEventLoop m_eventloop;
QTimer::singleShot(1000,&m_eventloop, SLOT(quit()));
m_eventloop.exec();
qDebug()<<"USB_MONITOR INSERTION";
if(infoFromHandle(guid,info,devInfo,i)!=1)
{
qDebug()<<"USB_MONITOR infoFromHandle failed on matchAndDispatchChangedDevice";
@ -189,11 +205,20 @@ bool USBMonitor::matchAndDispatchChangedDevice(const QString & deviceID, const G
}
bool m_break=false;
foreach (USBPortInfo m_info, knowndevices) {
if(m_info.serialNumber==info.serialNumber && m_info.productID==info.productID)
if(m_info.serialNumber==info.serialNumber && m_info.productID==info.productID && m_info.bcdDevice==info.bcdDevice && m_info.devicePath==info.devicePath)
{
qDebug()<<"USB_MONITOR device already present don't emit signal";
m_break=true;
}
}
if(m_break)
break;
if(info.bcdDevice==0 || info.product.isEmpty())
{
qDebug()<<"USB_MONITOR empty information on device not emiting signal";
break;
}
knowndevices.append(info);
qDebug()<<"USB_MONITOR emit device discovered on device:"<<info.product<<info.bcdDevice;
emit deviceDiscovered(info);
@ -208,13 +233,18 @@ bool USBMonitor::matchAndDispatchChangedDevice(const QString & deviceID, const G
if(knowndevices[x].devicePath==deviceID)
{
USBPortInfo temp=knowndevices.at(x);
knowndevices.removeAt(x);
qDebug()<<"USB_MONITOR emit device removed on device:"<<temp.product<<temp.bcdDevice;
emit deviceRemoved(temp);
found=true;
break;
}
}
if(!found)
{
qDebug()<<"USB_MONITOR emit device removed on unknown device";
emit deviceRemoved(info);
}
}
break;

View File

@ -0,0 +1,22 @@
#include "usbsignalfilter.h"
#include <QDebug>
void USBSignalFilter::m_deviceDiscovered(USBPortInfo port)
{
if((port.vendorID==m_vid || m_vid==-1) && (port.productID==m_pid || m_pid==-1) && ((port.bcdDevice>>8)==m_boardModel || m_boardModel==-1) &&
( (port.bcdDevice&0x00ff) ==m_runState || m_runState==-1))
{
qDebug()<<"USBSignalFilter emit device discovered";
emit deviceDiscovered();
}
}
USBSignalFilter::USBSignalFilter(int vid, int pid, int boardModel, int runState):
m_vid(vid),
m_pid(pid),
m_boardModel(boardModel),
m_runState(runState)
{
connect(USBMonitor::instance(),SIGNAL(deviceDiscovered(USBPortInfo)),this,SLOT(m_deviceDiscovered(USBPortInfo)));
}

View File

@ -0,0 +1,21 @@
#ifndef USBSIGNALFILTER_H
#define USBSIGNALFILTER_H
#include <QObject>
#include "usbmonitor.h"
class RAWHID_EXPORT USBSignalFilter : public QObject
{
Q_OBJECT
private:
int m_vid;
int m_pid;
int m_boardModel;
int m_runState;
signals:
void deviceDiscovered();
private slots:
void m_deviceDiscovered(USBPortInfo port);
public:
USBSignalFilter(int vid, int pid, int boardModel, int runState);
};
#endif // USBSIGNALFILTER_H

View File

@ -80,30 +80,41 @@ DFUObject::DFUObject(bool _debug,bool _use_serial,QString portname):
}
else
{
mready = false;
QEventLoop m_eventloop;
QTimer::singleShot(200,&m_eventloop, SLOT(quit()));
m_eventloop.exec();
QList<USBPortInfo> devices;
devices = USBMonitor::instance()->availableDevices(0x20a0,-1,-1,USBMonitor::Bootloader);
if (devices.length()==1) {
hidHandle.open(1,devices.first().vendorID,devices.first().productID,0,0);
if (devices.length()==1 && hidHandle.open(1,devices.first().vendorID,devices.first().productID,0,0)==1) {
qDebug()<<"OP_DFU detected first time";
mready=true;
} else {
// Wait for the board to appear on the USB bus:
connect(USBMonitor::instance(), SIGNAL(deviceDiscovered(USBPortInfo)),&m_eventloop, SLOT(quit()));
QTimer::singleShot(15000,&m_eventloop, SLOT(quit()));
m_eventloop.exec();
disconnect(USBMonitor::instance(), SIGNAL(deviceDiscovered(USBPortInfo)),&m_eventloop, SLOT(quit()));
devices = USBMonitor::instance()->availableDevices(0x20a0,-1,-1,USBMonitor::Bootloader);
if (devices.length()==1) {
QTimer::singleShot(1000,&m_eventloop, SLOT(quit()));
m_eventloop.exec();
hidHandle.open(1,devices.first().vendorID,devices.first().productID,0,0);
qDebug()<<"OP_DFU detected after delay";
}
else {
qDebug() << devices.length() << " device(s) detected, don't know what to do!";
mready = false;
USBSignalFilter filter(0x20a0,-1,-1,USBMonitor::Bootloader);
connect(&filter, SIGNAL(deviceDiscovered()),&m_eventloop, SLOT(quit()));
for(int x=0;x<4;++x)
{
qDebug()<<"OP_DFU trying to detect bootloader:"<<x;
if(x==0)
QTimer::singleShot(10000,&m_eventloop, SLOT(quit()));
else
QTimer::singleShot(2000,&m_eventloop, SLOT(quit()));
m_eventloop.exec();
devices = USBMonitor::instance()->availableDevices(0x20a0,-1,-1,USBMonitor::Bootloader);
if (devices.length()==1) {
if(hidHandle.open(1,devices.first().vendorID,devices.first().productID,0,0)==1)
{
qDebug()<<"OP_DFU detected after delay";
mready=true;
break;
}
}
else {
qDebug() << devices.length() << " device(s) detected, don't know what to do!";
mready = false;
}
}
}

View File

@ -4,6 +4,7 @@
#include <QByteArray>
#include <rawhid/pjrc_rawhid.h>
#include <rawhid/usbmonitor.h>
#include <rawhid/usbsignalfilter.h>
#include <QDebug>
#include <QFile>
#include <QThread>