📄 bluetoothpn.cxx
字号:
// // Start the definition of the Help+About window. This window will be displayed // whenever the user uses the Help+About menu item. // { Fl_Window* o = btHelpMenuAboutItemWindow = new Fl_Window(344, 155, "Bluetooth Neighborhood About"); w = o; o->labeltype(FL_NORMAL_LABEL); o->user_data((void*)(this)); btHelpMenuAboutItem1 = new Fl_Box(30, 5, 290, 25, "RidgeRun\'s Bluetooth Piconet Neighborhood"); btHelpMenuAboutItem2 = new Fl_Box(30, 30, 290, 25, "Written By: Marcus Smith"); btHelpMenuAboutItem3 = new Fl_Box(100, 55, 135, 25, "January 26, 2001"); // // Define the "OK" button on the Help+About window // { Fl_Return_Button* o = btHelpMenuAboutItemWindowOKButton = new Fl_Return_Button(130, 85, 75, 25, "OK"); o->box(FL_ROUND_UP_BOX); o->down_box(FL_ROUND_DOWN_BOX); o->callback((Fl_Callback*)cb_btHelpMenuAboutItemWindowOKButton); } // // Set this new window to be modal and end the window definition // o->set_modal(); o->end(); } // End of Help+About window // // Start definition of the window displayed if the ttyBTC Bluetooth control tty can't be opened. // This occurs when the Axis "bt.o" module is not loaded. // { Fl_Window* o = btErrorCantFindBTDriverWindow = new Fl_Window(344, 155, "Can\'t find BT driver"); w = o; o->user_data((void*)(this)); new Fl_Box(15, 5, 310, 30, "Error: Can\'t find Bluetooth device"); new Fl_Box(15, 35, 310, 30, "Is bt.o installed?"); // // Define the "OK" button on this window. // { Fl_Button* o = new Fl_Button(130, 85, 75, 25, "OK"); o->box(FL_ROUND_UP_BOX); o->down_box(FL_ROUND_DOWN_BOX); o->callback((Fl_Callback*)cb_OK); } // // Set this new window to be modal and end the window definition // o->set_modal(); o->end(); } // End of ttyBTC error opening window // // Start the definition of the window displayed if the initial HCI inquiry (or // baseband discovery) fails. // { Fl_Window* o = btErrorHCIInquiry = new Fl_Window(344, 155, "Can\'t issue a HCI Inquiry"); w = o; o->user_data((void*)(this)); new Fl_Box(70, 10, 205, 25, "Can\'t issue a HCI Inquiry"); new Fl_Box(65, 35, 205, 25, "Please check bt.o"); // // Define the "OK" button on this window. // { Fl_Button* o = new Fl_Button(130, 85, 75, 25, "OK"); o->box(FL_ROUND_UP_BOX); o->down_box(FL_ROUND_DOWN_BOX); o->callback((Fl_Callback*)cb_OK1); } // // Set this new window to be modal and end the window definition // o->set_modal(); o->end(); } // // Start the definition of a window displayed while the HCI inquiry and SDP discovery(s) are // taking place. // { Fl_Window* o = btScanForBluetoothDevicesInProgressWindow = new Fl_Window(236, 123, "Scanning for devices......"); w = o; o->user_data((void*)(this)); btScanForBluetoothDevicesProgressWindowLine1 = new Fl_Box(10, 5, 225, 25, "Searching For Bluetooth Devices"); btScanForBluetoothDevicesInProgressClock = new Fl_Clock(180, 40, 50, 50); btScanForBluetoothDevicesProgressWindowLine2 = new Fl_Box(40, 55, 115, 25, "Please Wait....."); // // Set this new window to be modal and end the window definition // o->set_modal(); o->end(); } // End of "Scanning for devices...." window} // End of BTNeighborhood constructor//// This function is called whenever an outside influence calls "show()"// on the BTNeighborhood window.//void BTNeighborhood::show(int argc, char **argv){ // // In this case, just call show on the main window // btMainWindow->show(argc, argv); // // After showing, initiate a baseband discovery. Find capabilities of // each device found. // btScanForBluetoothDevices();} // End of BTNeighborhood::show()//// This function exists because fltk was not cooperating when I wanted to// display a "please wait..." window when issuing the blocking ioctl() was// called. fltk seem single threaded, because even when I called window->show()// before the ioctl() call, the window would not show. I needed to split out// the ioctl() calls into another thread so the fltk event loop could be entered// while the ioctl() was running. This allow for a nice window to be displayed// when the ioctl() will block for some time.//// Why is this function not a function of BTNeighborhood? Because I could not// get it to work as a member function of a class allocated in another thread.// I tried defining it static, thinking that this would remove any threading// problems, but it still did not work.//void *ioctlCall(void *notused){ int index; inquiry_results *inq_res; /*-----------------------------------------------------*/ /* Allocate the storage for the return data. */ /* Data structure overhead + BT address bytes (6 per) */ /* times 10 maximum addresses. I should check this in */ /* the bluetooth specification. */ /*-----------------------------------------------------*/ inq_res = (inquiry_results*) malloc(sizeof(inquiry_results) + (MAX_BT_DEVICES * BT_ADDRESS_SIZE)); inq_res->nbr_of_units = MAX_BT_DEVICES; inq_res->inq_time = 5; /*-----------------------------------------------------*/ /* Issue the ioctl. */ /*-----------------------------------------------------*/ if (ioctl(bt_cfd, HCIINQUIRY, inq_res) < 0) { btErrorHCIInquiry->show(); close(bt_cfd); return NULL; } // // Hide the "in progress" window, since the ioctls are done // btScanForBluetoothDevicesInProgressWindow -> hide(); /*-----------------------------------------------------*/ /* For the number of peers found, print their BD addrs */ /*-----------------------------------------------------*/ treeWidget->clear(); treeWidget->traverse_start(); for (index = 0; index < inq_res->nbr_of_units; index++) { char tmpString[80]; /*------------------------------------------------------------*/ /* For each device found, change a button label and enable it */ /*------------------------------------------------------------*/ sprintf(tmpString, "%02x:%02x:%02x:%02x:%02x:%02x", inq_res->bd_addr[0+6*index],inq_res->bd_addr[1+6*index], inq_res->bd_addr[2+6*index],inq_res->bd_addr[3+6*index], inq_res->bd_addr[4+6*index],inq_res->bd_addr[5+6*index]); // // Add this found bluetooth device to the toggle tree. // treeWidget->add_next(tmpString, 1, bluetoothIcon); } // // Update the toggle tree view height. // treeWidget->update_height(); // // Free inquiry memory // free(inq_res); // // Close the ttyBTC control channel. // close(bt_cfd); pthread_exit(0);}//// Function: btScanForBluetoothDevices()// This function will scan for available bluetooth// devices that are within range. Those bluetooth devices// found are enumerated in a ToggleTree.//void BTNeighborhood::btScanForBluetoothDevices(){ int index; /*-----------------------------------------------------*/ /* Open the bluetooth control tty. */ /*-----------------------------------------------------*/ if ((bt_cfd = open(BT_CONTROL_TTY, O_RDWR)) < 0 ) { btErrorCantFindBTDriverWindow->show(); return; } tcflush(bt_cfd, TCIOFLUSH); // // Place a window up while the ioctls are taking place. // btScanForBluetoothDevicesInProgressWindow -> show(); if ( pthread_create(&pthread, NULL, ioctlCall, NULL ) == 0 ) { }} // End of btScanForBluetoothDevices() */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -