Exemple #1
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    setWindowTitle(QString("XKSimulator %1").arg(getVersionString()));

    m_serial = new SerialPort();
    connect(m_serial, SIGNAL(serialError(QString)), this, SLOT(serialError(QString)));
    connect(m_serial, SIGNAL(serialStatus(QString)), this, SLOT(serialStatus(QString)));

    m_error = new QLabel("");
    statusBar()->addWidget(m_error);

    m_enum = new QextSerialEnumerator();
#ifdef Q_OS_WIN
    connect(m_enum, SIGNAL(deviceDiscovered(QextPortInfo)), this, SLOT(deviceDiscovered(QextPortInfo)));
    connect(m_enum, SIGNAL(deviceRemoved(QextPortInfo)), this, SLOT(deviceRemoved(QextPortInfo)));

    m_enum->setUpNotifications();
#endif

    m_gpsTimer = new QTimer(this);
    connect(m_gpsTimer, SIGNAL(timeout()), this, SLOT(gpsTimer()));

    // Load the application settings (not the command settings)
    loadAppSettings();

    // Load the list of available serial ports
    loadComPorts();

    m_serial->open(m_tty);                                        // Open the selected serial port
}
Exemple #2
0
BtLocalDevice::BtLocalDevice(QObject *parent) :
    QObject(parent), securityFlags(QBluetooth::NoSecurity)
{
    localDevice = new QBluetoothLocalDevice(this);
    connect(localDevice, SIGNAL(error(QBluetoothLocalDevice::Error)),
            this, SIGNAL(error(QBluetoothLocalDevice::Error)));
    connect(localDevice, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode)),
            this, SIGNAL(hostModeStateChanged()));
    connect(localDevice, SIGNAL(pairingFinished(QBluetoothAddress,QBluetoothLocalDevice::Pairing)),
            this, SLOT(pairingFinished(QBluetoothAddress,QBluetoothLocalDevice::Pairing)));
    connect(localDevice, SIGNAL(deviceConnected(QBluetoothAddress)),
            this, SLOT(connected(QBluetoothAddress)));
    connect(localDevice, SIGNAL(deviceDisconnected(QBluetoothAddress)),
            this, SLOT(disconnected(QBluetoothAddress)));
    connect(localDevice, SIGNAL(pairingDisplayConfirmation(QBluetoothAddress,QString)),
            this, SLOT(pairingDisplayConfirmation(QBluetoothAddress,QString)));

    if (localDevice->isValid()) {
        deviceAgent = new QBluetoothDeviceDiscoveryAgent(this);
        connect(deviceAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
                this, SLOT(deviceDiscovered(QBluetoothDeviceInfo)));
        connect(deviceAgent, SIGNAL(finished()),
                this, SLOT(discoveryFinished()));
        connect(deviceAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)),
                this, SLOT(discoveryError(QBluetoothDeviceDiscoveryAgent::Error)));
        connect(deviceAgent, SIGNAL(canceled()),
                this, SLOT(discoveryCanceled()));

        serviceAgent = new QBluetoothServiceDiscoveryAgent(this);
        connect(serviceAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)),
                this, SLOT(serviceDiscovered(QBluetoothServiceInfo)));
        connect(serviceAgent, SIGNAL(finished()),
                this, SLOT(serviceDiscoveryFinished()));
        connect(serviceAgent, SIGNAL(canceled()),
                this, SLOT(serviceDiscoveryCanceled()));
        connect(serviceAgent, SIGNAL(error(QBluetoothServiceDiscoveryAgent::Error)),
                this, SLOT(serviceDiscoveryError(QBluetoothServiceDiscoveryAgent::Error)));

        socket = new QBluetoothSocket(SOCKET_PROTOCOL, this);
        connect(socket, SIGNAL(stateChanged(QBluetoothSocket::SocketState)),
                this, SLOT(socketStateChanged(QBluetoothSocket::SocketState)));
        connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)),
                this, SLOT(socketError(QBluetoothSocket::SocketError)));
        connect(socket, SIGNAL(connected()), this, SLOT(socketConnected()));
        connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
        connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
        setSecFlags(socket->preferredSecurityFlags());

        server = new QBluetoothServer(SOCKET_PROTOCOL, this);
        connect(server, SIGNAL(newConnection()), this, SLOT(serverNewConnection()));
        connect(server, SIGNAL(error(QBluetoothServer::Error)),
                this, SLOT(serverError(QBluetoothServer::Error)));
    } else {
        deviceAgent = 0;
        serviceAgent = 0;
        socket = 0;
        server = 0;
    }
}
Exemple #3
0
void Nushabe::startDeviceDiscovery()
{
    // Create a discovery agent and connect to its signals
    QBluetoothDeviceDiscoveryAgent *discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this);
    connect(discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
            this, SLOT(deviceDiscovered(QBluetoothDeviceInfo)));
    discoveryAgent->start();
}
/**
 * \brief Constructor
 *
 * \note
 *
 */
RawHIDConnection::RawHIDConnection()
{
    RawHidHandle  = NULL;
    enablePolling = true;

    m_usbMonitor  = USBMonitor::instance();

#ifndef __APPLE__
    connect(m_usbMonitor, SIGNAL(deviceDiscovered(USBPortInfo)), this, SLOT(onDeviceConnected()));
    connect(m_usbMonitor, SIGNAL(deviceRemoved(USBPortInfo)), this, SLOT(onDeviceDisconnected()));
#else
    connect(m_usbMonitor, SIGNAL(deviceDiscovered()), this, SLOT(onDeviceConnected()));
    connect(m_usbMonitor, SIGNAL(deviceRemoved()), this, SLOT(onDeviceDisconnected()));
#endif
}
Connect_Bluetooth::Connect_Bluetooth(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Connect_Bluetooth)
{
    ui->setupUi(this);

    discoveryAgent = new QBluetoothDeviceDiscoveryAgent();

    connect(ui->inquiryType, SIGNAL(toggled(bool)), this, SLOT(setGeneralUnlimited(bool)));
    connect(ui->scan, SIGNAL(clicked()), this, SLOT(startScan()));

    connect(discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
            this, SLOT(addDevice(QBluetoothDeviceInfo)));
    connect(discoveryAgent, SIGNAL(finished()), this, SLOT(scanFinished()));

    connect(ui->list, SIGNAL(itemActivated(QListWidgetItem*)),
            this, SLOT(itemActivated(QListWidgetItem*)));

    /*
    connect(localDevice, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode)),
            this, SLOT(hostModeStateChanged(QBluetoothLocalDevice::HostMode)));

    hostModeStateChanged(localDevice->hostMode());
    // add context menu for devices to be able to pair device
    ui->list->setContextMenuPolicy(Qt::CustomContextMenu);
    */




}
void ConnectionWaiter::quit()
{
    disconnect(USBMonitor::instance(), SIGNAL(deviceDiscovered(USBPortInfo)), this, SLOT(deviceEvent()));
    disconnect(USBMonitor::instance(), SIGNAL(deviceRemoved(USBPortInfo)), this, SLOT(deviceEvent()));
    timer.stop();
    eventLoop.exit();
}
bool QextSerialEnumerator::matchAndDispatchChangedDevice(const QString & deviceID, const GUID & guid, WPARAM wParam)
{
    bool rv = false;
    DWORD dwFlag = (DBT_DEVICEARRIVAL == wParam) ? DIGCF_PRESENT : DIGCF_ALLCLASSES;
    HDEVINFO devInfo;
    if( (devInfo = SetupDiGetClassDevs(&guid,NULL,NULL,dwFlag)) != INVALID_HANDLE_VALUE )
    {
        SP_DEVINFO_DATA spDevInfoData;
        spDevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
        for(int i=0; SetupDiEnumDeviceInfo(devInfo, i, &spDevInfoData); i++)
        {
            DWORD nSize=0 ;
            TCHAR buf[MAX_PATH];
            if ( SetupDiGetDeviceInstanceId(devInfo, &spDevInfoData, buf, MAX_PATH, &nSize) &&
                    deviceID.contains(TCHARToQString(buf))) // we found a match
            {
                rv = true;
                QextPortInfo info;
                info.productID = info.vendorID = 0;
                getDeviceDetailsWin( &info, devInfo, &spDevInfoData, wParam );
                if( wParam == DBT_DEVICEARRIVAL )
                    emit deviceDiscovered(info);
                else if( wParam == DBT_DEVICEREMOVECOMPLETE )
                    emit deviceRemoved(info);
                break;
            }
        }
        SetupDiDestroyDeviceInfoList(devInfo);
    }
    return rv;
}
SerialManagerView::SerialManagerView(QWidget *parent)
    : QWidget(parent)

{

    /// Timer for Polling
    timer = new QTimer(this);
    timer->setInterval(1000);


    PortSettings settings = {BAUD115200, DATA_8, PAR_NONE, STOP_1, FLOW_OFF, 10};
    port = new QextSerialPort(QLatin1String("/dev/tty.usbmodem622"), settings, QextSerialPort::Polling);


    connect(timer, SIGNAL(timeout()), SLOT(onReadyRead()));
    /// protocoles
    connect(port, SIGNAL(readyRead()), SLOT(onReadyRead()));

    /// Enumerator
    ///
    enumerator = new QextSerialEnumerator(this);
    enumerator->setUpNotifications();
    connect(enumerator, SIGNAL(deviceDiscovered(QextPortInfo)), SLOT(onPortAddedOrRemoved()));
    connect(enumerator, SIGNAL(deviceRemoved(QextPortInfo)), SLOT(onPortAddedOrRemoved()));


    message = new QLineEdit(this);



    setupGUI();


}
SerialPortControl::SerialPortControl(QObject *parent) :
    QObject(parent)
{
    serialPort = new QextSerialPort(QextSerialPort::EventDriven, this);
    serialEnum = new QextSerialEnumerator;
    //The following only works in OSX and Win. For other OSs use refresh button:
    serialEnum->setUpNotifications();
    buffer = new QByteArray;
    buffer->clear();
    input = new QByteArray;
    input->clear();


    //Inicializamos a los valores por defecto:
    this->set_baudRate (BAUD9600);
    this->set_dataBits (DATA_8);
    this->set_parityBits (PAR_NONE);
    this->set_stopBits (STOP_1);
    this->set_flowControl (FLOW_OFF);
    this->set_openMode (QIODevice::ReadWrite);

    connect (serialPort, SIGNAL(readyRead()), this, SLOT(onDataAvailable()));
    connect (serialEnum, SIGNAL(deviceDiscovered(QextPortInfo)) ,this
             ,SLOT(devicesListModified()));
    connect (serialEnum, SIGNAL(deviceRemoved(QextPortInfo))    ,this
             ,SLOT(devicesListModified()));
}
Exemple #10
0
DialogBare::DialogBare(QWidget *parent) :
    QWidget(parent),
    loading(false),
    ui(new Ui::DialogBare),
    worker(NULL),
    boardFoundWidget(NULL)
{
    ui->setupUi(this);

    foreach (QextPortInfo info, QextSerialEnumerator::getPorts())
        if (!info.portName.isEmpty())
            ui->portBox->addItem(info.portName);
    //make sure user can input their own port name!
    ui->portBox->setEditable(true);

//    ui->led->turnOff();

    PortSettings settings = {BAUD9600, DATA_8, PAR_NONE, STOP_1, FLOW_OFF, 10};
    port = new QextSerialPort(ui->portBox->currentText(), settings, QextSerialPort::Polling);

    enumerator = new QextSerialEnumerator(this);
    enumerator->setUpNotifications();

    ui->boardComboBox->addItem("PX4FMU v1.6+", 5);
    ui->boardComboBox->addItem("PX4FLOW v1.1+", 6);
    ui->boardComboBox->addItem("PX4IO v1.3+", 7);
    ui->boardComboBox->addItem("PX4 board #8", 8);
    ui->boardComboBox->addItem("PX4 board #9", 9);
    ui->boardComboBox->addItem("PX4 board #10", 10);
    ui->boardComboBox->addItem("PX4 board #11", 11);

    connect(ui->portBox, SIGNAL(editTextChanged(QString)), SLOT(onPortNameChanged(QString)));
    connect(ui->flashButton, SIGNAL(clicked()), SLOT(onUploadButtonClicked()));
    connect(ui->scanButton, SIGNAL(clicked()), SLOT(onDetect()));
    connect(ui->selectFileButton, SIGNAL(clicked()), SLOT(onFileSelectRequested()));
    connect(ui->cancelButton, SIGNAL(clicked()), SLOT(onCancelButtonClicked()));

    connect(ui->advancedCheckBox, SIGNAL(clicked(bool)), this, SLOT(onToggleAdvancedMode(bool)));

    connect(enumerator, SIGNAL(deviceDiscovered(QextPortInfo)), SLOT(onPortAddedOrRemoved()));
    connect(enumerator, SIGNAL(deviceRemoved(QextPortInfo)), SLOT(onPortAddedOrRemoved()));

    setWindowTitle(tr("QUpgrade Firmware Upload / Configuration Tool"));

    // Adjust the size
    const int screenHeight = qMin(1000, QApplication::desktop()->height() - 100);

    resize(700, qMax(screenHeight, 550));

    // load settings
    loadSettings();

    // Set up initial state
    if (!lastFilename.isEmpty()) {
        ui->flashButton->setEnabled(true);
    } else {
        ui->flashButton->setEnabled(false);
    }
}
/*
  A device has been discovered via IOKit.
  Create a QextPortInfo if possible, and emit the signal indicating that we've found it.
*/
void QextSerialEnumerator::onDeviceDiscoveredOSX( io_object_t service )
{
    QextPortInfo info;
    info.vendorID = 0;
    info.productID = 0;
    if( getServiceDetailsOSX( service, &info ) )
        emit deviceDiscovered( info );
}
BluetoothConnection::BluetoothConnection(QObject *parent) : QObject(parent)
{
    this->discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this);

    connect(this->discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),this, SLOT(vDeviceDiscovered(QBluetoothDeviceInfo)));
    connect(this->discoveryAgent, SIGNAL(finished()), this, SLOT(vDiscoveryFinished()));
    connect(this->discoveryAgent, SIGNAL(canceled()), this, SLOT(vDiscoveryFinished()));
}
void QDeclarativeBluetoothDiscoveryModel::deviceDiscovered(const QBluetoothDeviceInfo &device)
{
    //qDebug() << "Device discovered" << device.address().toString() << device.name();

    beginInsertRows(QModelIndex(),d->m_devices.count(), d->m_devices.count());
    d->m_devices.append(device);
    endInsertRows();
    emit deviceDiscovered(device.address().toString());
}
bool QUsbHidEnumerator::matchAndDispatchChangedDevice(const QString & deviceID, const GUID & guid, WPARAM wParam)
{
    bool rv = false;
    DWORD dwFlag = (DBT_DEVICEARRIVAL == wParam) ? DIGCF_PRESENT : DIGCF_ALLCLASSES;
    dwFlag |= DIGCF_INTERFACEDEVICE;
    HDEVINFO devInfo;
    QString s;
    if(m_vid && m_pid){
        s = QString("VID_%1&PID_%2").arg((ulong)m_vid,4,16,QChar('0')).arg((ulong)m_pid,4,16,QChar('0'));
    }else if(m_vid){
        s = QString("VID_%1").arg((ulong)m_vid,4,16,QChar('0'));
    }else if(m_pid){
        s = QString("PID_%1").arg((ulong)m_pid,4,16,QChar('0'));
    }
    QRegExp idRx(s.toUpper());
    if( (devInfo = SetupDiGetClassDevs(&guid,NULL,NULL,dwFlag)) != INVALID_HANDLE_VALUE )
    {
        SP_INTERFACE_DEVICE_DATA ifData;
        ifData.cbSize=sizeof(ifData);
        for(int i=0; SetupDiEnumDeviceInterfaces(devInfo, NULL, &guid, i, &ifData); i++)
        {
            DWORD needed;
            SetupDiGetDeviceInterfaceDetail(devInfo, &ifData, NULL, 0, &needed, NULL);
            PSP_INTERFACE_DEVICE_DETAIL_DATA detail=(PSP_INTERFACE_DEVICE_DETAIL_DATA)new BYTE[needed];
            detail->cbSize=sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
            SP_DEVINFO_DATA did={sizeof(SP_DEVINFO_DATA)};
            if (SetupDiGetDeviceInterfaceDetail(devInfo, &ifData, detail, needed, NULL, &did)){
                QString path = TCHARToQString(detail->DevicePath);
                if(deviceID.toUpper().contains(path.toUpper())){
                    rv = true;
                    QUsbHidInfo info;
                    info.path = path;
                    bool ready = false;
                    if(m_vid || m_pid){
                        ready = (info.path.toUpper().contains(idRx));
                    }else{
                        ready = true;
                    }
                    if(ready){
                        info.productID = info.vendorID = info.version = 0;
                        getDeviceDetailsWin( &info, devInfo, &did, wParam );
                        if( wParam == DBT_DEVICEARRIVAL )
                            emit deviceDiscovered(info);
                        else if( wParam == DBT_DEVICEREMOVECOMPLETE )
                            emit deviceRemoved(info);
                    }
                    break;
                }
            }
            delete [] detail;
        }
        SetupDiDestroyDeviceInfoList(devInfo);
    }
    return rv;
}
int ConnectionWaiter::exec()
{
    connect(USBMonitor::instance(), SIGNAL(deviceDiscovered(USBPortInfo)), this, SLOT(deviceEvent()));
    connect(USBMonitor::instance(), SIGNAL(deviceRemoved(USBPortInfo)), this, SLOT(deviceEvent()));

    connect(&timer, SIGNAL(timeout()), this, SLOT(perform()));
    timer.start(1000);

    emit timeChanged(0);
    eventLoop.exec();

    return result;
}
/*!
  Informs that our request has been prosessed and the data is available to be used.
*/
void BluetoothLinkManagerDeviceDiscoverer::RunL()
{
    qDebug() << __PRETTY_FUNCTION__ << iStatus.Int();
    switch (iStatus.Int()) {
    case KErrNone:  // found device
        if (m_pendingCancel && !m_pendingStart) {
            m_pendingCancel = false;
            emit canceled();
        } else {
            m_pendingCancel = false;
            m_pendingStart = false;
            // get next (possible) discovered device
            m_hostResolver.Next(m_entry, iStatus);
            SetActive();
            emit deviceDiscovered(currentDeviceDataToQBluetoothDeviceInfo());
        }
        break;
    case KErrHostResNoMoreResults:  // done with search
        if (m_pendingCancel && !m_pendingStart){  // search was canceled prior to finishing
            m_pendingCancel = false;
            m_pendingStart = false;
            emit canceled();
        }
        else if (m_pendingStart){  // search was restarted just prior to finishing
            m_pendingStart = false;
            m_pendingCancel = false;
            startDiscovery(m_discoveryType);
        } else {  // search completed normally
            m_pendingStart = false;
            m_pendingCancel = false;
            emit deviceDiscoveryComplete();
        }
        break;
    case KErrCancel:  // user canceled search
        if (m_pendingStart){  // user activated search after cancel
            m_pendingStart = false;
            m_pendingCancel = false;
            startDiscovery(m_discoveryType);
        } else {  // standard user cancel case
            m_pendingCancel = false;
            emit canceled();
        }
        break;
    default:
        m_pendingStart = false;
        m_pendingCancel = false;
        setError(iStatus.Int());
    }
}
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    this->setWindowIcon(QIcon(":res/123.png"));
    mdi = new QMdiArea(this);
    this->setCentralWidget(mdi);
    QDockWidget* dock = new QDockWidget(tr("Script log"),this);
    dock->setObjectName(tr("ScriptLogDock"));
    logText = new QTextEdit(dock);
    logText->setReadOnly(true);
    logText->setLineWrapMode(QTextEdit::NoWrap);
    dock->setWidget(logText);
    this->addDockWidget(Qt::BottomDockWidgetArea, dock);
    if(hidenum == 0){
        hidenum = new QUsbHidEnumerator(this);
    }
    if(hid == 0){
        hid = new QUsbHid(this);
    }
    connect(hidenum, SIGNAL(deviceDiscovered(QUsbHidInfo)), this, SLOT(devconnect(QUsbHidInfo)));
    connect(hidenum, SIGNAL(deviceRemoved(QUsbHidInfo)), this, SLOT(devdisconnect(QUsbHidInfo)));
    connect(hid, SIGNAL(readyRead()), this, SLOT(readyReadData()));
    hidenum->setUpNotifications(0x250,0x250);

    QList<QUsbHidInfo> devs = QUsbHid::enumDevices(0x250,0x250);
    if(devs.size()){
        hidpath = devs.at(0).path;
    }
    QMenu* menu = 0;
    QList<QAction*> list = menuBar()->actions();
    foreach(QAction* act, list){
        if( act->text().contains(tr("help"),Qt::CaseInsensitive) ){
            menu = act->menu();
        }
    }

    if(menu == 0){
        menu = menuBar()->addMenu(tr("&Help"));
    }
    menu->addAction(dock->toggleViewAction());
    menu->addSeparator();
    QAction* act = menu->addAction(tr("&About..."));
    connect(act,SIGNAL(triggered()),this,SLOT(my_about()));
    act = menu->addAction(tr("Send"));
    connect(act,SIGNAL(triggered()),this,SLOT(my_send()));
    this->setWindowTitle(QString::fromLocal8Bit("Tool Box"));

    //test_hid_devices(this);
}
int QextSerialEnumerator::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: deviceDiscovered((*reinterpret_cast< const QextPortInfo(*)>(_a[1]))); break;
        case 1: deviceRemoved((*reinterpret_cast< const QextPortInfo(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 2;
    }
    return _id;
}
    LRESULT QextSerialEnumerator::onDeviceChangeWin( WPARAM wParam, LPARAM lParam )
    {
        if ( DBT_DEVICEARRIVAL == wParam || DBT_DEVICEREMOVECOMPLETE == wParam )
        {
            PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR)lParam;
            if( pHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE )
            {
                PDEV_BROADCAST_DEVICEINTERFACE pDevInf = (PDEV_BROADCAST_DEVICEINTERFACE)pHdr;
                QString devId = TCHARToQString(pDevInf->dbcc_name);
                // devId: \\?\USB#Vid_04e8&Pid_503b#0002F9A9828E0F06#{a5dcbf10-6530-11d2-901f-00c04fb951ed}
                devId.remove("\\\\?\\"); // USB#Vid_04e8&Pid_503b#0002F9A9828E0F06#{a5dcbf10-6530-11d2-901f-00c04fb951ed}
                devId.remove(QRegExp("#\\{(.+)\\}")); // USB#Vid_04e8&Pid_503b#0002F9A9828E0F06
                devId.replace("#", "\\"); // USB\Vid_04e8&Pid_503b\0002F9A9828E0F06
                devId = devId.toUpper();
                //qDebug() << "devname:" << devId;

                DWORD dwFlag = DBT_DEVICEARRIVAL == wParam ? (DIGCF_ALLCLASSES | DIGCF_PRESENT) : DIGCF_ALLCLASSES;
                HDEVINFO hDevInfo = SetupDiGetClassDevs(&GUID_DEVCLASS_PORTS,NULL,NULL,dwFlag);
                SP_DEVINFO_DATA spDevInfoData;
                spDevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);

                for(int i=0; SetupDiEnumDeviceInfo(hDevInfo, i, &spDevInfoData); i++)
                {
                    DWORD nSize=0 ;
                    TCHAR buf[MAX_PATH];
                    if ( !SetupDiGetDeviceInstanceId(hDevInfo, &spDevInfoData, buf, sizeof(buf), &nSize) )
                        qDebug() << "SetupDiGetDeviceInstanceId():" << GetLastError();
                    if( devId == TCHARToQString(buf) ) // we found a match
                    {
                        QextPortInfo info;
                        getDeviceDetailsWin( &info, hDevInfo, &spDevInfoData, wParam );
                        if( wParam == DBT_DEVICEARRIVAL )
                            emit deviceDiscovered(info);
                        else if( wParam == DBT_DEVICEREMOVECOMPLETE )
                            emit deviceRemoved(info);
                        break;
                    }
                }
                SetupDiDestroyDeviceInfoList(hDevInfo);
            }
        }
        return 0;
    }
Exemple #20
0
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->onPortChanged();
    PortSettings usart_settings = {USART_BAUD_RATE,
                                   USART_BIT_TYPE,
                                   USART_PARITY_TYPE,
                                   USART_STOP_BITS_TYPE,
                                   USART_FLOW_TYPE,
                                   10};
    usartport=new QextSerialPort(ui->comboBox_port->currentText(),usart_settings,QextSerialPort::EventDriven);
    usartdevice_enumerator=new QextSerialEnumerator(this);
    usartdevice_enumerator->setUpNotifications();

    connect(usartport,SIGNAL(readyRead()),this,SLOT(onreceived()));
    connect(usartdevice_enumerator,SIGNAL(deviceDiscovered(QextPortInfo)),this,SLOT(onPortChanged()));
    connect(usartdevice_enumerator,SIGNAL(deviceRemoved(QextPortInfo)),this,SLOT(onPortChanged()));
}
/*
 Scans the USB system for boards and reports whether boards have been attached/removed.
*/
UsbMonitor::UsbMonitor(MainWindow* mw) : QThread()
{
  mainWindow = mw;
  qRegisterMetaType<BoardType::Type>("BoardType::Type"); // silly Qt thing to communicate via signal across a thread
  connect(this, SIGNAL(newBoards(QStringList, BoardType::Type)),
                       mainWindow, SLOT(onUsbDeviceArrived(QStringList, BoardType::Type)));
  connect(this, SIGNAL(boardsRemoved(QString)), mainWindow, SLOT(onDeviceRemoved(QString)));
  connect( &enumerator, SIGNAL(deviceDiscovered(QextPortInfo)), this, SLOT(onDeviceDiscovered(QextPortInfo)));
  connect( &enumerator, SIGNAL(deviceTerminated(QextPortInfo)), this, SLOT(onDeviceTerminated(QextPortInfo)));
  #ifdef Q_OS_MAC
  enumerator.setUpNotifications();
  #elif (defined Q_OS_WIN)
  QList<QextPortInfo> ports = enumerator.getPorts();
  if( ports.count())
  {
    QStringList boards;
    foreach( QextPortInfo port, ports )
      onDeviceDiscovered( port );
  }
  enumerator.setUpNotifications();
  #endif
}
void QextSerialEnumerator::setUpNotifications( )
{
    #ifdef QT_GUI_LIB
    if(notificationWidget)
        return;
    notificationWidget = new QextSerialRegistrationWidget(this);

    DEV_BROADCAST_DEVICEINTERFACE dbh;
    ZeroMemory(&dbh, sizeof(dbh));
    dbh.dbcc_size = sizeof(dbh);
    dbh.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
    CopyMemory(&dbh.dbcc_classguid, &GUID_DEVCLASS_PORTS, sizeof(GUID));
    if( RegisterDeviceNotification( notificationWidget->winId( ), &dbh, DEVICE_NOTIFY_WINDOW_HANDLE ) == NULL)
        qWarning() << "RegisterDeviceNotification failed:" << GetLastError();
    // setting up notifications doesn't tell us about devices already connected
    // so get those manually
    foreach( QextPortInfo port, getPorts() )
      emit deviceDiscovered( port );
    #else
    qWarning("QextSerialEnumerator: GUI not enabled - can't register for device notifications.");
    #endif // QT_GUI_LIB
}
DeviceDiscoveryDialog::DeviceDiscoveryDialog(QWidget *parent)
:   QDialog(parent), localDevice(new QBluetoothLocalDevice),
    ui(new Ui_DeviceDiscovery)
{
    ui->setupUi(this);

    /*
     * In case of multiple Bluetooth adapters it is possible to set adapter
     * which will be used. Example code:
     *
     * QBluetoothAddress address("XX:XX:XX:XX:XX:XX");
     * discoveryAgent = new QBluetoothDeviceDiscoveryAgent(address);
     *
     **/

    discoveryAgent = new QBluetoothDeviceDiscoveryAgent();

    connect(ui->inquiryType, SIGNAL(toggled(bool)), this, SLOT(setGeneralUnlimited(bool)));
    connect(ui->scan, SIGNAL(clicked()), this, SLOT(startScan()));

    connect(discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
            this, SLOT(addDevice(QBluetoothDeviceInfo)));
    connect(discoveryAgent, SIGNAL(finished()), this, SLOT(scanFinished()));

    connect(ui->list, SIGNAL(itemActivated(QListWidgetItem*)),
            this, SLOT(itemActivated(QListWidgetItem*)));

    connect(localDevice, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode)),
            this, SLOT(hostModeStateChanged(QBluetoothLocalDevice::HostMode)));

    hostModeStateChanged(localDevice->hostMode());
    // add context menu for devices to be able to pair device
    ui->list->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(ui->list, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(displayPairingMenu(QPoint)));
    connect(localDevice, SIGNAL(pairingFinished(QBluetoothAddress,QBluetoothLocalDevice::Pairing))
        , this, SLOT(pairingDone(QBluetoothAddress,QBluetoothLocalDevice::Pairing)));

}
/*!
    Starts device discovery.
*/
void QBluetoothServiceDiscoveryAgentPrivate::startDeviceDiscovery()
{
    Q_Q(QBluetoothServiceDiscoveryAgent);

    if (!deviceDiscoveryAgent) {
#ifdef QT_BLUEZ_BLUETOOTH
        deviceDiscoveryAgent = new QBluetoothDeviceDiscoveryAgent(m_deviceAdapterAddress, q);
#else
        deviceDiscoveryAgent = new QBluetoothDeviceDiscoveryAgent(q);
#endif
        QObject::connect(deviceDiscoveryAgent, SIGNAL(finished()),
                         q, SLOT(_q_deviceDiscoveryFinished()));
        QObject::connect(deviceDiscoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
                         q, SLOT(_q_deviceDiscovered(QBluetoothDeviceInfo)));
        QObject::connect(deviceDiscoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)),
                         q, SLOT(_q_deviceDiscoveryError(QBluetoothDeviceDiscoveryAgent::Error)));

    }

    setDiscoveryState(DeviceDiscovery);

    deviceDiscoveryAgent->start();
}
void QDeclarativeBluetoothDiscoveryModel::setRunning(bool running)
{
    if (!d->m_componentCompleted) {
        d->m_runningRequested = running;
        return;
    }

    if (d->m_running == running)
        return;

    d->m_running = running;

    if (!running) {
        if (d->m_deviceAgent)
            d->m_deviceAgent->stop();
        if (d->m_serviceAgent)
            d->m_serviceAgent->stop();
    } else {
        clearModel();
        d->m_error = NoError;
        if (d->m_discoveryMode == DeviceDiscovery) {
            if (!d->m_deviceAgent) {
                d->m_deviceAgent = new QBluetoothDeviceDiscoveryAgent(this);
                connect(d->m_deviceAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)), this, SLOT(deviceDiscovered(QBluetoothDeviceInfo)));
                connect(d->m_deviceAgent, SIGNAL(finished()), this, SLOT(finishedDiscovery()));
                connect(d->m_deviceAgent, SIGNAL(canceled()), this, SLOT(finishedDiscovery()));
                connect(d->m_deviceAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)), this, SLOT(errorDeviceDiscovery(QBluetoothDeviceDiscoveryAgent::Error)));
            }
            d->m_deviceAgent->start();
        } else {
            if (!d->m_serviceAgent) {
                d->m_serviceAgent = new QBluetoothServiceDiscoveryAgent(this);
                connect(d->m_serviceAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)), this, SLOT(serviceDiscovered(QBluetoothServiceInfo)));
                connect(d->m_serviceAgent, SIGNAL(finished()), this, SLOT(finishedDiscovery()));
                connect(d->m_serviceAgent, SIGNAL(canceled()), this, SLOT(finishedDiscovery()));
                connect(d->m_serviceAgent, SIGNAL(error(QBluetoothServiceDiscoveryAgent::Error)), this, SLOT(errorDiscovery(QBluetoothServiceDiscoveryAgent::Error)));
            }

            d->m_serviceAgent->setRemoteAddress(QBluetoothAddress(d->m_remoteAddress));
            d->m_serviceAgent->clear();

            if (!d->m_uuid.isEmpty())
                d->m_serviceAgent->setUuidFilter(QBluetoothUuid(d->m_uuid));

            if (discoveryMode() == FullServiceDiscovery)  {
                //qDebug() << "Full Discovery";
                d->m_serviceAgent->start(QBluetoothServiceDiscoveryAgent::FullDiscovery);
            } else {
                //qDebug() << "Minimal Discovery";
                d->m_serviceAgent->start(QBluetoothServiceDiscoveryAgent::MinimalDiscovery);
            }

            // we could not start service discovery
            if (!d->m_serviceAgent->isActive()) {
                d->m_running = false;
                errorDiscovery(d->m_serviceAgent->error());
                return;
            }
        }
    }

    emit runningChanged();
}
Exemple #26
0
Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);

    //! [0]
    foreach (QextPortInfo info, QextSerialEnumerator::getPorts())
        ui->portBox->addItem(info.portName);
    //make sure user can input their own port name!
    ui->portBox->setEditable(true);

    ui->baudRateBox->addItem("1200", BAUD1200);
    ui->baudRateBox->addItem("2400", BAUD2400);
    ui->baudRateBox->addItem("4800", BAUD4800);
    ui->baudRateBox->addItem("9600", BAUD9600);
    ui->baudRateBox->addItem("19200", BAUD19200);
    ui->baudRateBox->setCurrentIndex(3);

    ui->parityBox->addItem("NONE", PAR_NONE);
    ui->parityBox->addItem("ODD", PAR_ODD);
    ui->parityBox->addItem("EVEN", PAR_EVEN);

    ui->dataBitsBox->addItem("5", DATA_5);
    ui->dataBitsBox->addItem("6", DATA_6);
    ui->dataBitsBox->addItem("7", DATA_7);
    ui->dataBitsBox->addItem("8", DATA_8);
    ui->dataBitsBox->setCurrentIndex(3);

    ui->stopBitsBox->addItem("1", STOP_1);
    ui->stopBitsBox->addItem("2", STOP_2);

    ui->queryModeBox->addItem("Polling", QextSerialPort::Polling);
    ui->queryModeBox->addItem("EventDriven", QextSerialPort::EventDriven);
    //! [0]

    ui->led->turnOff();

    timer = new QTimer(this);
    timer->setInterval(40);
    //! [1]
    PortSettings settings = {BAUD9600, DATA_8, PAR_NONE, STOP_1, FLOW_OFF, 10};
    port = new QextSerialPort(ui->portBox->currentText(), settings, QextSerialPort::Polling);
    //! [1]

    enumerator = new QextSerialEnumerator(this);
    enumerator->setUpNotifications();

    connect(ui->baudRateBox, SIGNAL(currentIndexChanged(int)), SLOT(onBaudRateChanged(int)));
    connect(ui->parityBox, SIGNAL(currentIndexChanged(int)), SLOT(onParityChanged(int)));
    connect(ui->dataBitsBox, SIGNAL(currentIndexChanged(int)), SLOT(onDataBitsChanged(int)));
    connect(ui->stopBitsBox, SIGNAL(currentIndexChanged(int)), SLOT(onStopBitsChanged(int)));
    connect(ui->queryModeBox, SIGNAL(currentIndexChanged(int)), SLOT(onQueryModeChanged(int)));
    connect(ui->timeoutBox, SIGNAL(valueChanged(int)), SLOT(onTimeoutChanged(int)));
    connect(ui->portBox, SIGNAL(editTextChanged(QString)), SLOT(onPortNameChanged(QString)));
    connect(ui->openCloseButton, SIGNAL(clicked()), SLOT(onOpenCloseButtonClicked()));
    connect(ui->sendButton, SIGNAL(clicked()), SLOT(onSendButtonClicked()));
    connect(timer, SIGNAL(timeout()), SLOT(onReadyRead()));
    connect(port, SIGNAL(readyRead()), SLOT(onReadyRead()));

    connect(enumerator, SIGNAL(deviceDiscovered(QextPortInfo)), SLOT(onPortAddedOrRemoved()));
    connect(enumerator, SIGNAL(deviceRemoved(QextPortInfo)), SLOT(onPortAddedOrRemoved()));

    setWindowTitle(tr("QextSerialPort Demo"));
}
Exemple #27
0
Dialog::Dialog(QWidget *parent) :
    QWidget(parent),
    loading(false),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);

    foreach (QextPortInfo info, QextSerialEnumerator::getPorts())
        if (!info.portName.isEmpty())
            ui->portBox->addItem(info.portName);
    //make sure user can input their own port name!
    ui->portBox->setEditable(true);

//    ui->led->turnOff();

    PortSettings settings = {BAUD9600, DATA_8, PAR_NONE, STOP_1, FLOW_OFF, 10};
    port = new QextSerialPort(ui->portBox->currentText(), settings, QextSerialPort::Polling);

    enumerator = new QextSerialEnumerator(this);
    enumerator->setUpNotifications();

    ui->boardComboBox->addItem("PX4FMU v1.6+", 5);
    ui->boardComboBox->addItem("PX4FLOW v1.1+", 6);
    ui->boardComboBox->addItem("PX4IO v1.3+", 7);
    ui->boardComboBox->addItem("PX4 board #8", 8);
    ui->boardComboBox->addItem("PX4 board #9", 9);
    ui->boardComboBox->addItem("PX4 board #10", 10);
    ui->boardComboBox->addItem("PX4 board #11", 11);

    connect(ui->portBox, SIGNAL(editTextChanged(QString)), SLOT(onPortNameChanged(QString)));
    connect(ui->flashButton, SIGNAL(clicked()), SLOT(onUploadButtonClicked()));
    connect(ui->selectFileButton, SIGNAL(clicked()), SLOT(onFileSelectRequested()));
    connect(ui->cancelButton, SIGNAL(clicked()), SLOT(onCancelButtonClicked()));

    // disable JavaScript for Windows for faster startup
#ifdef Q_OS_WIN
    QWebSettings *webViewSettings = ui->webView->settings();
    webViewSettings->setAttribute(QWebSettings::JavascriptEnabled, false);
#endif

    connect(ui->webView->page(), SIGNAL(downloadRequested(const QNetworkRequest&)), this, SLOT(onDownloadRequested(const QNetworkRequest&)));
    ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);

    connect(ui->webView->page(), SIGNAL(linkClicked(const QUrl&)), this, SLOT(onLinkClicked(const QUrl&)));

    connect(ui->prevButton, SIGNAL(clicked()), ui->webView, SLOT(back()));
    connect(ui->homeButton, SIGNAL(clicked()), this, SLOT(onHomeRequested()));

    connect(ui->advancedCheckBox, SIGNAL(clicked(bool)), this, SLOT(onToggleAdvancedMode(bool)));

    connect(enumerator, SIGNAL(deviceDiscovered(QextPortInfo)), SLOT(onPortAddedOrRemoved()));
    connect(enumerator, SIGNAL(deviceRemoved(QextPortInfo)), SLOT(onPortAddedOrRemoved()));

    setWindowTitle(tr("QUpgrade Firmware Upload / Configuration Tool"));

    // Adjust the size
    const int screenHeight = qMin(1000, QApplication::desktop()->height() - 100);

    resize(700, qMax(screenHeight, 550));

    // about:blank shouldn't be part of the history
    ui->webView->history()->clear();
    onHomeRequested();

    // load settings
    loadSettings();

    // Set up initial state
    if (!lastFilename.isEmpty()) {
        ui->flashButton->setEnabled(true);
    } else {
        ui->flashButton->setEnabled(false);
    }
}
Exemple #28
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    offcount = 0;
    datadisp = new DataDisplay(this);
//    this->setWindowFlags(Qt::WindowStaysOnTopHint);
//    this->setAttribute(Qt::WA_TranslucentBackground, true);

    setWindowTitle(tr("TMT Actuator Test Station Software"));
    ui->enccomboBox->addItem("10 seconds");
    ui->enccomboBox->addItem("25 seconds");
    ui->enccomboBox->addItem("50 seconds");
    ui->enccomboBox->addItem("100 seconds");

    ui->offcomboBox->addItem("1 mm");
    ui->offcomboBox->addItem("3 mm");
    ui->offcomboBox->addItem("6 mm");

    ui->vcmcomboBox->addItem("20 seconds");
    ui->vcmcomboBox->addItem("40 seconds");
    ui->vcmcomboBox->addItem("80 seconds");
    ui->vcmcomboBox->addItem("100 seconds");

    ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
//    ui->customPlot->setBackground(Qt::transparent);
    ui->customPlot->legend->setVisible(true);
    ui->customPlot->legend->setFont(QFont("Helvetica", 7));
    ui->customPlot->axisRect()->setBackground(Qt::darkGray);
    ui->customPlot->axisRect()->setupFullAxesBox();

    ui->customPlot->addGraph(); // blue line
    ui->customPlot->graph(0)->setName("Encoder Count vs. Time");
    ui->customPlot->graph(0)->setPen(QPen(Qt::blue));
    ui->customPlot->graph(0)->setLineStyle(QCPGraph::lsLine);
    ui->customPlot->graph(0)->setAntialiasedFill(false);

    ui->customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
    ui->customPlot->xAxis->setDateTimeFormat("hh:mm:ss");
    ui->customPlot->xAxis->setAutoTickStep(true);
    ui->customPlot->xAxis->setTickStep(1);

    ui->customPlot_1->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);

    ui->customPlot_1->legend->setVisible(true);
    ui->customPlot_1->legend->setFont(QFont("Helvetica", 7));
    ui->customPlot_1->axisRect()->setBackground(Qt::darkGray);
    ui->customPlot_1->axisRect()->setupFullAxesBox();

    ui->customPlot_1->addGraph(); // blue line
    ui->customPlot_1->graph(0)->setName("Sensor Data vs. Time");
    ui->customPlot_1->graph(0)->setPen(QPen(Qt::green));
    ui->customPlot_1->graph(0)->setLineStyle(QCPGraph::lsLine);
    ui->customPlot_1->graph(0)->setAntialiasedFill(false);

    ui->customPlot_1->xAxis->setTickLabelType(QCPAxis::ltDateTime);
    ui->customPlot_1->xAxis->setDateTimeFormat("hh:mm:ss");
    ui->customPlot_1->xAxis->setAutoTickStep(true);

    foreach (QextPortInfo info, QextSerialEnumerator::getPorts())
    ui->portBox->addItem(info.portName);

    ui->portBox->setEditable(true);

    ui->baudRateBox->addItem("9600", BAUD9600);
    ui->baudRateBox->addItem("115200", BAUD115200);
    ui->baudRateBox->setCurrentIndex(2);

    ui->parityBox->addItem("NONE", PAR_NONE);
    ui->parityBox->addItem("ODD", PAR_ODD);
    ui->parityBox->addItem("EVEN", PAR_EVEN);

    ui->dataBitsBox->addItem("5", DATA_5);
    ui->dataBitsBox->addItem("6", DATA_6);
    ui->dataBitsBox->addItem("7", DATA_7);
    ui->dataBitsBox->addItem("8", DATA_8);
    ui->dataBitsBox->setCurrentIndex(3);

    ui->stopBitsBox->addItem("1", STOP_1);
    ui->stopBitsBox->addItem("2", STOP_2);

    ui->queryModeBox->addItem("POLLING", QextSerialPort::Polling);
    ui->queryModeBox->addItem("EVENT DRIVEN", QextSerialPort::EventDriven);

    timer = new QTimer(this);
    timer->setInterval(40);

    PortSettings settings = {BAUD115200, DATA_8, PAR_NONE, STOP_1, FLOW_OFF, 10};
    port = new QextSerialPort(ui->portBox->currentText(), settings, QextSerialPort::Polling);

    enumerator = new QextSerialEnumerator(this);
    enumerator->setUpNotifications();

    connect(ui->connect_Button, SIGNAL(clicked()), SLOT(run()));
    connect(ui->disconnect_Button, SIGNAL(clicked()), SLOT(disconnectClient()));
    connect(ui->stop_Button, SIGNAL(clicked()), SLOT(stopplot()));
    connect(ui->reset_window_Button, SIGNAL(clicked()), SLOT(resetfun()));
    connect(ui->enc_test_run_Button, SIGNAL(clicked()), SLOT(encoderfun()));
    connect(ui->enc_test_run_Button, SIGNAL(clicked()), SLOT(showdatadisp()));
    connect(ui->off_up_Button, SIGNAL(clicked()), SLOT(offloaderfun()));
    connect(ui->off_down_Button, SIGNAL(clicked()), SLOT(offloaderfun_1()));
    connect(ui->vcm_test_run_Button, SIGNAL(clicked()), SLOT(vcmfun()));
    connect(ui->vcm_test_run_Button, SIGNAL(clicked()), SLOT(showdatadisp()));
    connect(ui->reset_drive_board_Button, SIGNAL(clicked()), SLOT(resetdrivefun()));
    connect(ui->save_plot_Button, SIGNAL(clicked()), SLOT(saveplot_fun()));

    connect(ui->baudRateBox, SIGNAL(currentIndexChanged(int)), SLOT(onBaudRateChanged(int)));
    connect(ui->parityBox, SIGNAL(currentIndexChanged(int)), SLOT(onParityChanged(int)));
    connect(ui->dataBitsBox, SIGNAL(currentIndexChanged(int)), SLOT(onDataBitsChanged(int)));
    connect(ui->stopBitsBox, SIGNAL(currentIndexChanged(int)), SLOT(onStopBitsChanged(int)));
    connect(ui->portBox, SIGNAL(editTextChanged(QString)), SLOT(onPortNameChanged(QString)));

    connect(ui->openCloseButton, SIGNAL(clicked()), SLOT(onOpenCloseButtonClicked()));
    connect(ui->sendButton, SIGNAL(clicked()), SLOT(onSendButtonClicked()));
    connect(ui->aboutButton, SIGNAL(clicked()), SLOT(about_fun()));

    connect(timer, SIGNAL(timeout()), SLOT(onReadyRead()));
    connect(port, SIGNAL(readyRead()), SLOT(onReadyRead()));
    connect(enumerator, SIGNAL(deviceDiscovered(QextPortInfo)), SLOT(onPortAddedOrRemoved()));
    connect(enumerator, SIGNAL(deviceRemoved(QextPortInfo)), SLOT(onPortAddedOrRemoved()));
}
void DeviceDiscoveryBroadcastReceiver::onReceive(JNIEnv *env, jobject context, jobject intent)
{
    Q_UNUSED(context);
    Q_UNUSED(env);

    QAndroidJniObject intentObject(intent);
    const QString action = intentObject.callObjectMethod("getAction", "()Ljava/lang/String;").toString();

    qCDebug(QT_BT_ANDROID) << "DeviceDiscoveryBroadcastReceiver::onReceive() - event:" << action;

    if (action == valueForStaticField(JavaNames::BluetoothAdapter,
                                      JavaNames::ActionDiscoveryFinished).toString()) {
        emit finished();
    } else if (action == valueForStaticField(JavaNames::BluetoothAdapter,
               JavaNames::ActionDiscoveryStarted).toString()) {

    } else if (action == valueForStaticField(JavaNames::BluetoothDevice,
               JavaNames::ActionFound).toString()) {
        //get BluetoothDevice
        QAndroidJniObject keyExtra = valueForStaticField(JavaNames::BluetoothDevice,
                                     JavaNames::ExtraDevice);
        const QAndroidJniObject bluetoothDevice =
            intentObject.callObjectMethod("getParcelableExtra",
                                          "(Ljava/lang/String;)Landroid/os/Parcelable;",
                                          keyExtra.object<jstring>());

        if (!bluetoothDevice.isValid())
            return;

        const QString deviceName = bluetoothDevice.callObjectMethod<jstring>("getName").toString();
        const QBluetoothAddress deviceAddress(bluetoothDevice.callObjectMethod<jstring>("getAddress").toString());
        keyExtra = valueForStaticField(JavaNames::BluetoothDevice,
                                       JavaNames::ExtraRssi);

        int rssi = intentObject.callMethod<jshort>("getShortExtra",
                   "(Ljava/lang/String;S)S",
                   keyExtra.object<jstring>(),
                   0);
        const QAndroidJniObject bluetoothClass = bluetoothDevice.callObjectMethod("getBluetoothClass",
                "()Landroid/bluetooth/BluetoothClass;");
        if (!bluetoothClass.isValid())
            return;
        int classType = bluetoothClass.callMethod<jint>("getDeviceClass");


        static QList<qint32> services;
        if (services.count() == 0)
            services << QBluetoothDeviceInfo::PositioningService
                     << QBluetoothDeviceInfo::NetworkingService
                     << QBluetoothDeviceInfo::RenderingService
                     << QBluetoothDeviceInfo::CapturingService
                     << QBluetoothDeviceInfo::ObjectTransferService
                     << QBluetoothDeviceInfo::AudioService
                     << QBluetoothDeviceInfo::TelephonyService
                     << QBluetoothDeviceInfo::InformationService;

        //Matching BluetoothClass.Service values
        qint32 result = 0;
        qint32 current = 0;
        for (int i = 0; i < services.count(); i++) {
            current = services.at(i);
            int id = (current << 16);
            if (bluetoothClass.callMethod<jboolean>("hasService", "(I)Z", id))
                result |= current;
        }

        result = result << 13;
        classType |= result;

        QBluetoothDeviceInfo info(deviceAddress, deviceName, classType);
        info.setRssi(rssi);

        emit deviceDiscovered(info);
    }
}
Exemple #30
0
Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);

    //! [0]
    foreach (QextPortInfo info, QextSerialEnumerator::getPorts())
        ui->portBox->addItem(info.portName);
    //make sure user can input their own port name!
    ui->portBox->setEditable(true);

    ui->baudRateBox->addItem("1200", BAUD1200);
    ui->baudRateBox->addItem("2400", BAUD2400);
    ui->baudRateBox->addItem("4800", BAUD4800);
    ui->baudRateBox->addItem("9600", BAUD9600);
    ui->baudRateBox->addItem("19200", BAUD19200);
    ui->baudRateBox->addItem("115200", BAUD115200);
    ui->baudRateBox->setCurrentIndex(5);

    ui->parityBox->addItem("NONE", PAR_NONE);
    ui->parityBox->addItem("ODD", PAR_ODD);
    ui->parityBox->addItem("EVEN", PAR_EVEN);

    ui->dataBitsBox->addItem("5", DATA_5);
    ui->dataBitsBox->addItem("6", DATA_6);
    ui->dataBitsBox->addItem("7", DATA_7);
    ui->dataBitsBox->addItem("8", DATA_8);
    ui->dataBitsBox->setCurrentIndex(3);

    ui->stopBitsBox->addItem("1", STOP_1);
    ui->stopBitsBox->addItem("2", STOP_2);

    ui->queryModeBox->addItem("Polling", QextSerialPort::Polling);
    ui->queryModeBox->addItem("EventDriven", QextSerialPort::EventDriven);
    //! [0]

    ui->led_SerialOnOff->turnOff();
    ui->led_MavlinkStatus->turnOff();
    ui->led_Tx->turnOff();
    ui->led_Rx->turnOff();

    timer = new QTimer(this);
    timer->setInterval(40);

    timer_colck = new QTimer(this);
    connect(timer_colck, SIGNAL(timeout()), this, SLOT(onClockLabelUpdate()));
    timer_colck->start(1000);

    //! [1]
    PortSettings settings = {BAUD9600, DATA_8, PAR_NONE, STOP_1, FLOW_OFF, 10};
    port = new QextSerialPort(ui->portBox->currentText(), settings, QextSerialPort::Polling);
    //! [1]

    enumerator = new QextSerialEnumerator(this);
    enumerator->setUpNotifications();

    connect(ui->baudRateBox, SIGNAL(currentIndexChanged(int)), SLOT(onBaudRateChanged(int)));
    connect(ui->parityBox, SIGNAL(currentIndexChanged(int)), SLOT(onParityChanged(int)));
    connect(ui->dataBitsBox, SIGNAL(currentIndexChanged(int)), SLOT(onDataBitsChanged(int)));
    connect(ui->stopBitsBox, SIGNAL(currentIndexChanged(int)), SLOT(onStopBitsChanged(int)));
    connect(ui->queryModeBox, SIGNAL(currentIndexChanged(int)), SLOT(onQueryModeChanged(int)));
    connect(ui->timeoutBox, SIGNAL(valueChanged(int)), SLOT(onTimeoutChanged(int)));
    connect(ui->portBox, SIGNAL(editTextChanged(QString)), SLOT(onPortNameChanged(QString)));
    connect(ui->openCloseButton, SIGNAL(clicked()), SLOT(onOpenCloseButtonClicked()));

    connect(timer, SIGNAL(timeout()), SLOT(onReadyRead()));
    connect(port, SIGNAL(readyRead()), SLOT(onReadyRead()));

    connect(enumerator, SIGNAL(deviceDiscovered(QextPortInfo)), SLOT(onPortAddedOrRemoved()));
    connect(enumerator, SIGNAL(deviceRemoved(QextPortInfo)), SLOT(onPortAddedOrRemoved()));

    ui->tb_hexview->setRowCount(1);
    ui->tb_hexview->setColumnCount(1);
    ui->tb_hexview->setItem(0, 0, new QTableWidgetItem(" "));

    QDateTime local(QDateTime::currentDateTime());
    ui->label_13->setText(local.toString());

    ui->progressBar_Status->setValue(100);

    setWindowTitle("OpenCR Firmware Downloader v1.0");
}