status_t LocalDevice::SetDeviceClass(DeviceClass deviceClass) { int8 bt_status = BT_ERROR; if (fMessenger == NULL) return bt_status; BluetoothCommand<typed_command(hci_write_dev_class)> setDeviceClass(OGF_CONTROL_BASEBAND, OCF_WRITE_CLASS_OF_DEV); setDeviceClass->dev_class[0] = deviceClass.Record() & 0xFF; setDeviceClass->dev_class[1] = (deviceClass.Record() & 0xFF00) >> 8; setDeviceClass->dev_class[2] = (deviceClass.Record() & 0xFF0000) >> 16; BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); BMessage reply; request.AddInt32("hci_id", fHid); request.AddData("raw command", B_ANY_TYPE, setDeviceClass.Data(), setDeviceClass.Size()); request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_WRITE_CLASS_OF_DEV)); if (fMessenger->SendMessage(&request, &reply) == B_OK) reply.FindInt8("status", &bt_status); return bt_status; }
void NewDevice::slotSelectionChanged(QListViewItem* item) { if (item->parent() != NULL) { m_selectionOK = true; m_modelValue = item->text(0); m_manufacturerValue = item->parent()->text(0); if (m_nameEdit->text() == QString::null) { m_nameEdit->setText("New device"); } m_nameEdit->setSelection(0, m_nameEdit->text().length()); m_nameEdit->setFocus(); DeviceClass* dc = _app->searchDeviceClass(m_manufacturerValue, m_modelValue); assert(dc); m_addressSpin->setRange(1, 513 - dc->channels()->count()); m_channelsSpin->setValue(dc->channels()->count()); m_ok->setEnabled(true); } else { m_ok->setEnabled(false); m_selectionOK = false; m_manufacturerValue = QString(""); m_modelValue = QString(""); m_nameEdit->setText(QString("")); m_channelsSpin->setValue(0); } }
void NewDevice::showManufacturers() { m_manufacturer->clear(); QList <DeviceClass> dclist(_app->doc()->deviceClassList()); for (DeviceClass* dc = dclist.first(); dc != NULL; dc = dclist.next()) { QPixmap pm(_app->settings()->getPixmapPath() + QString("dmx.xpm")); bool alreadyAdded = false; for (int i = 0; i < m_manufacturer->count(); i++) { alreadyAdded = false; if (m_manufacturer->text(i) == dc->manufacturer()) { alreadyAdded = true; break; } } if (alreadyAdded == false) { m_manufacturer->insertItem(pm, dc->manufacturer()); } } slotManufacturerActivated(m_manufacturer->currentItem()); }
DeviceClass* Doc::searchDeviceClass(const t_deviceclass_id id) { for (DeviceClass* d = m_deviceClassList.first(); d != NULL; d = m_deviceClassList.next()) { if (d->id() == id) { return d; } } return NULL; }
DeviceClass* Doc::searchDeviceClass(const QString &manufacturer, const QString &model) { for (DeviceClass* d = m_deviceClassList.first(); d != NULL; d = m_deviceClassList.next()) { if (d->manufacturer() == manufacturer && d->model() == model) { return d; } } return NULL; }
DeviceClass* Doc::searchDeviceClassByID(int id) { for (DeviceClass* d = m_deviceClassList.first(); d != NULL; d = m_deviceClassList.next()) { if (d->id() == id) { return d; } } return NULL; }
DeviceClass* Doc::searchDeviceClass(unsigned long id) { for (DeviceClass* d = m_deviceClassList.first(); d != NULL; d = m_deviceClassList.next()) { if (d->id() == id) { return d; } } return NULL; }
void NewDevice::fillTree() { QListViewItem* parent = NULL; QListViewItem* newItem = NULL; QPtrList <DeviceClass> *dl = _app->deviceClassList(); QPixmap pm(PIXMAPS + QString("/dmx.xpm")); QString config; bool treeOpen = false; if (_app->settings()->get("NewDeviceTreeOpen", config) != -1 && config == Settings::trueValue()) { treeOpen = true; } else { treeOpen = false; } m_tree->clear(); for (DeviceClass* dc = dl->first(); dc != NULL; dc = dl->next()) { bool alreadyAdded = false; for (QListViewItem* i = m_tree->firstChild(); i != NULL; i = i->nextSibling()) { if (i->text(0) == dc->manufacturer()) { alreadyAdded = true; parent = i; break; } } if (alreadyAdded == false) { parent = new QListViewItem(m_tree, dc->manufacturer()); parent->setOpen(treeOpen); } parent->setPixmap(0, QPixmap(PIXMAPS + QString("/global.xpm"))); newItem = new QListViewItem(parent, dc->model()); newItem->setPixmap(0, pm); newItem->setText(1,dc->type()); } }
bool Doc::readDeviceClasses() { DeviceClass* dc = NULL; QString path = QString::null; QString dir; _app->settings()->get(KEY_SYSTEM_DIR, dir); dir += QString("/") + DEVICECLASSPATH + QString("/"); QDir d(dir); d.setFilter(QDir::Files); d.setNameFilter("*.deviceclass"); if (d.exists() == false || d.isReadable() == false) { QMessageBox::warning(_app, "QLC", "Unable to open or read from device directory! Check settings and permissions."); return false; } QStringList dirlist(d.entryList()); QStringList::Iterator it; QList <QString> list; // Our stringlist that contains the files' contents // Put a slash to the end of the directory name if it isn't there if (dir.right(1) != QString("/")) { dir = dir + QString("/"); } // Go thru all files for (it = dirlist.begin(); it != dirlist.end(); ++it) { path = dir + *it; FileHandler::readFileToList(path, list); dc = createDeviceClass(list); if (dc != NULL) { dc->setFile(path); m_deviceClassList.append(dc); } // 03-Jan-2002 / HJu // The list wasn't cleared between files while (list.isEmpty() == false) { list.first(); delete list.take(); } } return true; }
bool BluetoothSettingsView::_SetDeviceClass(uint8 major, uint8 minor, uint16 service) { bool haveRun = true; DeviceClass devClass; devClass.SetRecord(major, minor, service); if (ActiveLocalDevice != NULL) ActiveLocalDevice->SetDeviceClass(devClass); else haveRun = false; return haveRun; }
bool DeviceClassesProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { Q_UNUSED(sourceParent) DeviceClass *deviceClass = m_deviceClasses->get(sourceRow); // filter auto devices if (deviceClass->createMethods().count() == 1 && deviceClass->createMethods().contains("CreateMethodAuto")) return false; if (!m_vendorId.isNull() && deviceClass->vendorId() == m_vendorId) return true; return false; }
void App::slotFileNew() { DeviceClass* dc = new DeviceClass(); ASSERT(dc); // Set default manufacturer and model dc->setManufacturer(QString("Manufacturer")); dc->setModel(QString("Model")); DeviceClassEditor* editor = new DeviceClassEditor(m_workspace, dc); connect(editor, SIGNAL(closed(DeviceClassEditor*)), this, SLOT(slotEditorClosed(DeviceClassEditor*))); editor->init(); editor->setCaption("New Device Class*"); // Set temporary window caption editor->show(); }
void DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod) { BString classString; printf("\t%s: Device %s discovered.\n",__FUNCTION__, bdaddrUtils::ToString(btDevice->GetBluetoothAddress())); cod.GetServiceClass(classString); classString << " |"; cod.GetMajorDeviceClass(classString); classString << " |"; cod.GetMinorDeviceClass(classString); printf("\t\t%s: \n", classString.String()); }
static void DumpInfo(LocalDevice* device) { printf("[LocalDevice] %s\t%s\n", (device->GetFriendlyName()).String(), bdaddrUtils::ToString(device->GetBluetoothAddress())); BString classString; DeviceClass cod = device->GetDeviceClass(); cod.GetServiceClass(classString); classString << " |"; cod.GetMajorDeviceClass(classString); classString << " |"; cod.GetMinorDeviceClass(classString); printf("\t\t%s: \n", classString.String()); }
void NewDevice::fillTree() { QListViewItem* parent = NULL; QListViewItem* newItem = NULL; QPtrList <DeviceClass> *dl = _app->deviceClassList(); QString path; _app->settings()->get("SystemPath", path); path += QString("/") + PIXMAPPATH; QPixmap pm(path + QString("/dmx.xpm")); QString tree; _app->settings()->get("NewDeviceTreeOpen", tree); bool treeOpen = (tree == Settings::trueValue()) ? true : false; m_tree->clear(); for (DeviceClass* dc = dl->first(); dc != NULL; dc = dl->next()) { bool alreadyAdded = false; for (QListViewItem* i = m_tree->firstChild(); i != NULL; i = i->nextSibling()) { if (i->text(0) == dc->manufacturer()) { alreadyAdded = true; parent = i; break; } } if (alreadyAdded == false) { parent = new QListViewItem(m_tree, dc->manufacturer()); parent->setOpen(treeOpen); } parent->setPixmap(0, QPixmap(path + QString("/global.xpm"))); newItem = new QListViewItem(parent, dc->model()); newItem->setPixmap(0, pm); newItem->setText(1,dc->type()); } }
void NewDevice::fillTree() { QListViewItem* parent = NULL; QListViewItem* newItem = NULL; QList <DeviceClass> dclist(_app->doc()->deviceClassList()); QPixmap pm(_app->settings()->pixmapPath() + QString("dmx.xpm")); m_tree->clear(); for (DeviceClass* dc = dclist.first(); dc != NULL; dc = dclist.next()) { bool alreadyAdded = false; for (QListViewItem* i = m_tree->firstChild(); i != NULL; i = i->nextSibling()) { if (i->text(0) == dc->manufacturer()) { alreadyAdded = true; parent = i; break; } } if (alreadyAdded == false) { parent = new QListViewItem(m_tree, dc->manufacturer()); if (_app->settings()->newDeviceTreeOpen() == true) { parent->setOpen(true); } } parent->setPixmap(0, QPixmap(_app->settings()->pixmapPath() + QString("global.xpm"))); newItem = new QListViewItem(parent, dc->model()); newItem->setPixmap(0, pm); newItem->setText(1,dc->type()); } }
void NewDevice::showModels(QString mfg) { m_model->clear(); QList <DeviceClass> dclist(_app->doc()->deviceClassList()); for (DeviceClass* dc = dclist.first(); dc != NULL; dc = dclist.next()) { if (mfg == dc->manufacturer()) { if (dc->protocol() == DeviceClass::DMX512) { QPixmap pm(_app->settings()->getPixmapPath() + QString("dmx.xpm")); m_model->insertItem(pm, dc->model()); } else { m_model->insertItem(dc->model()); } } } slotModelActivated(m_model->currentItem()); }
JsonReply *DeviceHandler::PairDevice(const QVariantMap ¶ms) { DeviceClassId deviceClassId(params.value("deviceClassId").toString()); DeviceClass deviceClass = GuhCore::instance()->findDeviceClass(deviceClassId); DeviceManager::DeviceError status; PairingTransactionId pairingTransactionId = PairingTransactionId::createPairingTransactionId(); if (params.contains("deviceDescriptorId")) { DeviceDescriptorId deviceDescriptorId(params.value("deviceDescriptorId").toString()); status = GuhCore::instance()->pairDevice(pairingTransactionId, deviceClassId, deviceDescriptorId); } else { ParamList deviceParams = JsonTypes::unpackParams(params.value("deviceParams").toList()); status = GuhCore::instance()->pairDevice(pairingTransactionId, deviceClassId, deviceParams); } QVariantMap returns; returns.insert("deviceError", JsonTypes::deviceErrorToString(status)); if (status == DeviceManager::DeviceErrorNoError) { returns.insert("displayMessage", deviceClass.pairingInfo()); returns.insert("pairingTransactionId", pairingTransactionId.toString()); returns.insert("setupMethod", JsonTypes::setupMethod().at(deviceClass.setupMethod())); } return createReply(returns); }
DeviceClass* Doc::createDeviceClass(QList<QString> &list) { QString entry; QString manufacturer; QString model; QString t; DeviceClass* dc = new DeviceClass(); for (QString *s = list.first(); s != NULL; s = list.next()) { if (*s == QString("Entry")) { entry = *(list.next()); if (entry == QString("Device Class")) { dc->createInfo(list); } else if (entry == QString("Channel")) { dc->createChannel(list); } else if (entry == QString("Function")) { dc->createFunction(list); } } else { // Unknown keyword (at this time) list.next(); } } if (dc->channels()->count() == 0) { QString msg; msg.sprintf("No channels specified for device class \"" + dc->manufacturer() + QString(" ") + dc->model() + QString("\".\n") + "Use the device class editor to add one or more channels."); QMessageBox::warning(_app, IDS_APP_NAME_SHORT, msg); } return dc; }
QString HttpDaemon::generateWebPage() { DeviceClass deviceClass = m_plugin->supportedDevices().first(); QString body = QString( "<html>" "<body>" "<h1>Mock device Controller</h1>\n" "<hr>" "<h2>Device Information</h2>" "Name: %1<br>" "ID: %2<br>" "DeviceClass ID: %3<br>").arg(m_device->paramValue("name").toString()).arg(m_device->id().toString()).arg(deviceClass.id().toString()); body.append("<hr>"); body.append("<h2>States</h2>"); body.append("<table>"); for (int i = 0; i < deviceClass.stateTypes().count(); ++i) { body.append("<tr>"); body.append("<form action=\"/setstate\" method=\"get\">"); const StateType &stateType = deviceClass.stateTypes().at(i); body.append("<td>" + stateType.name() + "</td>"); body.append(QString("<td><input type='input'' name='%1' value='%2'></td>").arg(stateType.id().toString()).arg(m_device->states().at(i).value().toString())); body.append("<td><input type=submit value='Set State'/></td>"); body.append("</form>"); body.append("</tr>"); } body.append("</table>"); body.append("<hr>"); body.append("<h2>Events</h2>"); body.append("<table>"); for (int i = 0; i < deviceClass.eventTypes().count(); ++i) { const EventType &eventType = deviceClass.eventTypes().at(i); body.append(QString( "<tr>" "<form action=\"/generateevent\" method=\"get\">" "<td>%1<input type='hidden' name='eventtypeid' value='%2'/></td>" "<td>").arg(eventType.name()).arg(eventType.id().toString())); if (!eventType.name().endsWith(" changed")) { body.append("<input type='submit' value='Generate'/>"); } body.append("</td>" "</form>" "</tr>" ); } body.append("</table>"); body.append("<hr>"); body.append("<h2>Actions</h2>"); body.append("<table border=2px>"); body.append("<tr><td>Name</td><td>Type ID</td><td>Timestamp</td></tr>"); for (int i = 0; i < m_actionList.count(); ++i) { ActionTypeId actionTypeId = ActionTypeId(m_actionList.at(i).first); QDateTime timestamp = m_actionList.at(i).second; QString actionName; foreach (const ActionType &at, deviceClass.actionTypes()) { if (at.id() == actionTypeId) { actionName = at.name(); break; } } body.append(QString( "<tr>" "<td>%1</td>" "<td>%2</td>" "<td>%3</td>" "</tr>" ).arg(actionName).arg(actionTypeId.toString()).arg(timestamp.toString())); } body.append("</table>"); body.append("</body></html>\n"); return generateHeader() + body; }
void DevicePluginIntertechno::radioData(const QList<int> &rawData) { // filter right here a wrong signal length if(rawData.length() != 49){ return; } QList<Device*> deviceList = deviceManager()->findConfiguredDevices(intertechnoRemote); if(deviceList.isEmpty()){ return; } int delay = rawData.first()/31; QByteArray binCode; // ======================================= // average 314 if(delay > 300 && delay < 400){ // go trough all 48 timings (without sync signal) for(int i = 1; i <= 48; i+=2 ){ int div; int divNext; // if short if(rawData.at(i) <= 700){ div = 1; }else{ div = 3; } // if long if(rawData.at(i+1) < 700){ divNext = 1; }else{ divNext = 3; } // _ // if we have | |___ = 0 -> in 4 delays => 1000 // _ // if we have ___| | = 1 -> in 4 delays => 0001 if(div == 1 && divNext == 3){ binCode.append('0'); }else if(div == 3 && divNext == 1){ binCode.append('1'); }else{ return; } } }else{ return; } // ======================================= // Check nibble 16-19, must be 0001 if(binCode.mid(16,4) != "0001"){ return; } // ======================================= // Get family code QString familyCode; bool ok; QByteArray familyCodeBin = binCode.left(8); int famiyCodeInt = familyCodeBin.toInt(&ok,2); if(!ok){ return; } switch (famiyCodeInt) { case 0b00000000: familyCode = "A"; break; case 0b01000000: familyCode = "B"; break; case 0b00010000: familyCode = "C"; break; case 0b01010000: familyCode = "D"; break; case 0b00000100: familyCode = "E"; break; case 0b01000100: familyCode = "F"; break; case 0b00010100: familyCode = "G"; break; case 0b01010100: familyCode = "H"; break; case 0b00000001: familyCode = "I"; break; case 0b01000001: familyCode = "J"; break; case 0b00010001: familyCode = "K"; break; case 0b01010001: familyCode = "L"; break; case 0b00000101: familyCode = "M"; break; case 0b01000101: familyCode = "N"; break; case 0b00010101: familyCode = "O"; break; case 0b01010101: familyCode = "P"; break; default: return; } // ======================================= // Get button code QString buttonCode; QByteArray buttonCodeBin = binCode.mid(8,8); int buttonCodeInt = buttonCodeBin.toInt(&ok,2); if(!ok){ return; } switch (buttonCodeInt) { case 0b00000000: buttonCode = "1"; break; case 0b01000000: buttonCode = "2"; break; case 0b00010000: buttonCode = "3"; break; case 0b01010000: buttonCode = "4"; break; case 0b00000100: buttonCode = "5"; break; case 0b01000100: buttonCode = "6"; break; case 0b00010100: buttonCode = "7"; break; case 0b01010100: buttonCode = "8"; break; case 0b00000001: buttonCode = "9"; break; case 0b01000001: buttonCode = "10"; break; case 0b00010001: buttonCode = "11"; break; case 0b01010001: buttonCode = "12"; break; case 0b00000101: buttonCode = "13"; break; case 0b01000101: buttonCode = "14"; break; case 0b00010101: buttonCode = "15"; break; case 0b01010101: buttonCode = "16"; break; default: return; } // ======================================= // get power status -> On = 0100, Off = 0001 bool power; if(binCode.right(4).toInt(0,2) == 5){ power = true; }else if(binCode.right(4).toInt(0,2) == 4){ power = false; }else{ return; } qDebug() << "family code = " << familyCode << "button code =" << buttonCode << power; // =================================================== Device *device = 0; foreach (Device *dev, deviceList) { if (dev->paramValue("familyCode").toString() == familyCode) { // Yippie! We found the device. device = dev; break; } } if (!device) { qWarning() << "couldn't find any configured device for intertech familyCode:" << familyCode; return; } ParamList params; Param powerParam("power", power); params.append(powerParam); // FIXME: find a better way to get to the remote DeviceClass DeviceClass deviceClass = supportedDevices().first(); foreach (const EventType &eventType, deviceClass.eventTypes()) { if (eventType.name() == buttonCode) { qDebug() << "emit event " << pluginName() << familyCode << eventType.name() << power; Event event = Event(eventType.id(), device->id(), params); emit emitEvent(event); return; } } }
void BluetoothSettingsView::MessageReceived(BMessage* message) { DeviceClass devClass; switch (message->what) { case kMsgLocalSwitched: { LocalDevice* lDevice; if (message->FindPointer("LocalDevice", (void**) &lDevice) == B_OK) { // Device integrity should be rechecked fExtDeviceView->SetLocalDevice(lDevice); fExtDeviceView->SetEnabled(true); ActiveLocalDevice = lDevice; } } break; case kMsgSetDeviceClassDesktop: { devClass.SetRecord(1, 1, 0x72); if (ActiveLocalDevice != NULL) ActiveLocalDevice->SetDeviceClass(devClass); break; } case kMsgSetDeviceClassServer: { devClass.SetRecord(1, 2, 0x72); if (ActiveLocalDevice != NULL) ActiveLocalDevice->SetDeviceClass(devClass); break; } case kMsgSetDeviceClassLaptop: { devClass.SetRecord(1, 3, 0x72); if (ActiveLocalDevice != NULL) ActiveLocalDevice->SetDeviceClass(devClass); break; } case kMsgSetDeviceClassHandheld: { devClass.SetRecord(1, 4, 0x72); if (ActiveLocalDevice != NULL) ActiveLocalDevice->SetDeviceClass(devClass); break; } case kMsgSetDeviceClassSmartPhone: { devClass.SetRecord(2, 3, 0x72); if (ActiveLocalDevice != NULL) ActiveLocalDevice->SetDeviceClass(devClass); break; } case kMsgRefresh: _BuildLocalDevicesMenu(); fLocalDevicesMenu->SetTargetForItems(this); break; default: BView::MessageReceived(message); } }
DMXDevice* Doc::createDevice(QList<QString> &list) { QString name = QString::null; QString manufacturer = QString::null; QString model = QString::null; QString t = QString::null; int address = 0; unsigned long id = 0; for (QString* s = list.next(); s != NULL; s = list.next()) { if (*s == QString("Entry")) { s = list.prev(); break; } else if (*s == QString("Name")) { name = *(list.next()); } else if (*s == QString("Manufacturer")) { manufacturer = *(list.next()); } else if (*s == QString("Model")) { model = *(list.next()); } else if (*s == QString("ID")) { id = list.next()->toULong(); } else if (*s == QString("Address")) { t = *(list.next()); address = t.toInt(); } else { // Unknown keyword list.next(); } } if (id == 0 || manufacturer == QString::null || manufacturer == QString::null) { QString msg; msg = QString("Unable to add device \"" + name + QString("\" because device (class) information is missing.")); QMessageBox::critical(_app, IDS_APP_NAME_SHORT, msg); return NULL; } else { DeviceClass* dc = searchDeviceClass(manufacturer, model); if (dc == NULL) { QString msg; msg = QString("Unable to add device \"" + name + "\"." + "\nNo device class description found for " + manufacturer + QString(" ") + model); QMessageBox::critical(_app, IDS_APP_NAME_SHORT, msg); return NULL; } else { if (dc->channels()->count() == 0) { QString msg; msg = QString("No channels specified for device class \"" + dc->manufacturer() + QString(" ") + dc->model() + QString("\".\n") + QString("Unable to load device \"") + name + QString("\" to workspace")); QMessageBox::warning(_app, IDS_APP_NAME_SHORT, msg); return NULL; } else { DMXDevice* d = new DMXDevice(address, dc, name, id); return d; } } } }