void BTAdaptor::searchBtDevices () { // Connect to the signal DeviceFound to obtain the list of devices QDBusConnection bus = QDBusConnection::systemBus (); bool success = bus.connect ("org.bluez", mAdapterPath, "org.bluez.Adapter", "DeviceFound", this, SLOT (deviceFound(QString,QMap<QString,QVariant>))); if (!success) { qDebug() << "Failure in connecting dbus signal"; return; } QDBusMessage msg = QDBusMessage::createMethodCall ("org.bluez", mAdapterPath, "org.bluez.Adapter", "StartDiscovery"); QDBusMessage reply = bus.call (msg); if (reply.type () == QDBusMessage::ErrorMessage) { qWarning() << "Error in dbus call to search for devices"; return ; } }
void MainWindow::deviceHasRule(QString usbId) { qDebug() << Q_FUNC_INFO << usbId; bool deviceInList = false; for(int row=0;row<ui->deviceTable->rowCount();row++) { if(ui->deviceTable->item(row, 4)->text() == usbId) { ui->deviceTable->item(row, 0)->setCheckState(Qt::Checked); deviceInList = true; } } if(!deviceInList) { deviceFound("", "", "", usbId); deviceHasRule(usbId); } }
//Read information about the found devices void BluetoothConnection::vDeviceDiscovered(const QBluetoothDeviceInfo &device) { //qDebug() << "Found new device:" << device.name() << '(' << device.address().toString() << ')'; emit deviceFound(device.name(), device.address().toString()); /* qDebug() << "Discovered service on" << serviceInfo.device().name() << serviceInfo.device().address().toString(); qDebug() << "\tService name:" << serviceInfo.serviceName(); qDebug() << "\tDescription:" << serviceInfo.attribute(QBluetoothServiceInfo::ServiceDescription).toString(); qDebug() << "\tProvider:" << serviceInfo.attribute(QBluetoothServiceInfo::ServiceProvider).toString(); qDebug() << "\tL2CAP protocol service multiplexer:" << serviceInfo.protocolServiceMultiplexer(); qDebug() << "\tRFCOMM server channel:" << serviceInfo.serverChannel(); */ }
void Sbs2EmocapDataReader::turnReceiveUdpDataOff() { QObject::disconnect(sbs2NetworkHandler,SIGNAL(rawDataReceived(QUdpSocket*)),this,SLOT(udpDataReceived(QUdpSocket*))); if (sbs2NetworkHandler != 0) delete sbs2NetworkHandler; sbs2NetworkHandler = 0; if (readOnlyFromNetwork) { } else { QObject::connect(sbs2EmocapMounter,SIGNAL(deviceFound(QMap<QString,QVariant>)),this,SLOT(deviceFound(QMap<QString,QVariant>))); QObject::connect(sbs2EmocapMounter,SIGNAL(deviceLost()),this,SLOT(deviceLost())); sbs2EmocapMounter->start(); } }
void Sbs2EmocapDataReader::turnReceiveUdpDataOn(QString address, int port) { Sbs2DataReader::turnReceiveUdpDataOn(address, port); if (sbs2EmocapMounter != 0) { QObject::disconnect(sbs2EmocapMounter,SIGNAL(deviceFound(QMap<QString,QVariant>)),this,SLOT(deviceFound(QMap<QString,QVariant>))); QObject::disconnect(sbs2EmocapMounter,SIGNAL(deviceLost()),this,SLOT(deviceLost())); sbs2EmocapMounter->invalidate(); } running = 0; if (sbs2NetworkHandler != 0) delete sbs2NetworkHandler; sbs2NetworkHandler = new Sbs2NetworkHandler(this); sbs2NetworkHandler->turnReceiveRawDataOn(address,port); QObject::connect(sbs2NetworkHandler,SIGNAL(rawDataReceived(QUdpSocket*)),this,SLOT(udpDataReceived(QUdpSocket*))); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); if(ruleFile.canWriteFile()) { connect(&udev, SIGNAL(deviceFound(QString,QString,QString,QString)), this, SLOT(deviceFound(QString,QString,QString,QString))); connect(&ruleFile, SIGNAL(deviceHasRule(QString)), this, SLOT(deviceHasRule(QString))); updateTable(); ui->deviceTable->resizeColumnsToContents(); updateTimer.setSingleShot(false); updateTimer.setInterval(2000); connect(&updateTimer, SIGNAL(timeout()), this, SLOT(updateTable())); updateTimer.start(); } else { QMessageBox *mb = new QMessageBox(this); mb->setModal(true); mb->setText("Unable to open rule file. Make sure you run this application as root."); mb->exec(); } }
Sbs2EmocapDataReader::Sbs2EmocapDataReader(Sbs2Callback *sbs2Callback_, int readOnlyFromNetwork_, QObject *parent):Sbs2DataReader(sbs2Callback_,readOnlyFromNetwork_,parent) { for (int i=0; i< bufferSize; ++i) { sbs2Packets.append(new Sbs2EmocapPacket(this)); } if (!readOnlyFromNetwork) //read from the local device { sbs2EmotivDecryptor = new Sbs2EmotivDecryptor(this); sbs2EmocapMounter = Sbs2EmocapMounter::New(this); QObject::connect(sbs2EmocapMounter,SIGNAL(deviceFound(QMap<QString,QVariant>)),this,SLOT(deviceFound(QMap<QString,QVariant>))); QObject::connect(sbs2EmocapMounter,SIGNAL(deviceLost()),this,SLOT(deviceLost())); sbs2EmocapMounter->start(); } else //receive packets from remote host, we do nothing, waiting for turnOn { sbs2EmocapMounter = 0; } }
Sbs2DataReader::Sbs2DataReader(Sbs2Callback *sbs2Callback_, int readOnlyFromNetwork_, QObject *parent):QObject(parent), sbs2Callback(sbs2Callback_) { framesRead = 0; currentIndex = 0; bufferIndex = 0; bufferSize = 256; running = 0; testDummyRead = 0; readOnlyFromNetwork = readOnlyFromNetwork_; lastReceiveRawDataCounter = 0; QObject::connect(this,SIGNAL(deviceFoundSignal(QMap<QString,QVariant>)),sbs2Callback, SLOT(deviceFound(QMap<QString,QVariant>))); }
void QWurthScanner::deviceDataReceieved() { receieveBuffer.append(port.readAll()); //dumpData(receieveBuffer); switch (currentCommand.type) { case ReadBarcodes: if (barcodeReadState == ReadHeader) { if (receieveBuffer.length() >= 11) { if (receieveBuffer.mid(2, 7) == "@MemoSc") { barcodesToReceieve = ((unsigned char)receieveBuffer.at(9) << 8) + (unsigned char)receieveBuffer.at(10); barcodeReadState = ReadCodes; receieveBuffer = receieveBuffer.mid(11); //strip out header //qWarning() << "receieve %1 barcodes" << barcodesToReceieve; } else { qWarning() << tr("Malformed readbarcode response: %1").arg(QString(receieveBuffer.mid(2, 7))); } } else if (receieveBuffer.length() == 1) { if (receieveBuffer.at(0) == 5) { // no stored barcodes emit barcodesReceieved(readedBarcodes); //qWarning() << "no barcodes"; startSendPackets(); } } } if (barcodeReadState == ReadCodes) { while (receieveBuffer.length()) { unsigned char codeLength = receieveBuffer.at(0); if (receieveBuffer.length() >= codeLength+1) { /* * receieved barcode block's first character is the barcode type * A -> EAN * B -> RSS14? */ readedBarcodes.append(receieveBuffer.mid(2, codeLength-1)); receieveBuffer = receieveBuffer.mid(codeLength+1); barcodesToReceieve--; if (barcodesToReceieve == 0) { emit barcodesReceieved(readedBarcodes); readedBarcodes.clear(); barcodeReadState = ReadHeader; if (receieveBuffer.length() > 1) { qWarning() << tr("%1 characters left after parsing barcodes").arg(receieveBuffer.length()-1); } startSendPackets(); break; } } else { break; } } } break; case ClearBarodes: if (receieveBuffer.length() >= 5) { QString response = "\x02\x1b@C\x1a"; if (receieveBuffer.mid(0, 5) == response) { currentCommand.type = Idle; } else { qWarning() << "clearbuffer malformed answer!" << receieveBuffer.mid(0, 5) << response; } timeoutTimer.stop(); receieveBuffer.clear(); startSendPackets(); } break; case QueryDevice: if (receieveBuffer.length() >= 25) { QString deviceName = receieveBuffer.mid(5); emit deviceFound(deviceName); timeoutTimer.stop(); receieveBuffer.clear(); startSendPackets(); } break; case PowerDownDevice: if (receieveBuffer.length() >= 5) { QString answer = receieveBuffer.mid(0, 5); if (answer == "\x02\x1b@P\x09") { timeoutTimer.stop(); receieveBuffer.clear(); startSendPackets(); } else { qWarning() << "malformed answer came to the powerdown query:" << answer; } } break; case Idle: qWarning() << "data receieved in idle state..."; dumpData(receieveBuffer); receieveBuffer.clear(); break; } }