IBluetoothDeviceInfo[] DoDiscoverDevices( int maxDevices, bool authenticated, bool remembered, bool unknown, bool discoverableOnly, BluetoothClient.LiveDiscoveryCallback liveDiscoHandler, object liveDiscoState) { Console.WriteLine("DoDiscoverDevices"); var discoTime = DateTime.UtcNow; List <IBluetoothDeviceInfo> known = new List <IBluetoothDeviceInfo>(); // hack often GC fodder var bus = _fcty.BluezDbus; known = bus.GetDeviceList_OnDefaultAdapter(); // List <IBluetoothDeviceInfo> inquired = null; if (discoverableOnly || unknown) { inquired = new List <IBluetoothDeviceInfo>(); double td = InquiryLength.TotalSeconds; const double Multiplier = 1.25d; td /= Multiplier; int t = (int)td; StackConsts.IREQ_int flags = StackConsts.IREQ_int.IREQ_CACHE_FLUSH; // var TypeofItem = typeof(Structs.inquiry_info); var SizeofItem = Marshal.SizeOf(TypeofItem); IntPtr pii = BluezUtils.malloc(maxDevices * SizeofItem); try { Console.WriteLine("Gonna hci_inquiry num_rsp: {0}, t: {1} ({2} was {3}) ", maxDevices, t, td, InquiryLength); // TO-DO LAP/IAC: var lap = InquiryAccessCode; //var stackTrace = new StackTrace(); //var msg = "Gonna hci_inquiry at: " + stackTrace; //Debug.WriteLine(msg); //Console.WriteLine(msg); int num = NativeMethods.hci_inquiry(_fcty.DevId, t, maxDevices, IntPtr.Zero, ref pii, flags); Console.WriteLine("inquiry num=" + num); //BluezUtils.CheckAndThrow((BluezError)num, "hci_inquiry"); BluezUtils.Assert((BluezError)num, "hci_inquiry"); // IntPtr pCur = pii; for (int i = 0; i < num; i++) { var cur = (Structs.inquiry_info)Marshal.PtrToStructure(pCur, TypeofItem); var bdi = BluezDeviceInfo.CreateFromInquiry(_fcty, cur); inquired.Add(bdi); pCur = PointerAdd(pCur, SizeofItem); }//for } finally { BluezUtils.free(pii); } } // var merged = BluetoothClient.DiscoverDevicesMerge( authenticated, remembered, unknown, known, inquired, discoverableOnly, discoTime); return(merged.ToArray()); }
//---- internal BluezRadio(BluezFactory fcty, int dd) { _dd = dd; Debug.Assert(fcty != null, "ArgNull"); _fcty = fcty; BluezError ret; var bdaddr = BluezUtils.FromBluetoothAddress(BluetoothAddress.None); ret = NativeMethods.hci_read_bd_addr(_dd, bdaddr, _fcty.StackTimeout); //TODO BluezUtils.CheckAndThrow(ret, "hci_read_bd_addr"); BluezUtils.Assert(ret, "hci_read_bd_addr"); if (BluezUtils.IsSuccess(ret)) { _addr = BluezUtils.ToBluetoothAddress(bdaddr); Console.WriteLine("Radio SUCCESS, addr: " + _addr); } else { // NEVER used EXCEPT in the debugger if we skip the CheckandThrow above. _addr = BluetoothAddress.None; Console.WriteLine("Radio FAIL, addr: " + _addr); } _nameTmp = new byte[250]; // // First find _objectPath. In the future we'll be passed this. var ax = _fcty.BluezDbus.FindAdapter(_addr, out _objectPath); Debug.Assert(_objectPath != null, "BluezRadio..ctor NOT _objectPath!=null"); //-- // Set Adapter. _adapter = GetAdapter(_objectPath); Console.WriteLine("Got adapter at .ctor.3."); // var prop = GetProperties(); string addrDt = (string)prop[PropertyName.Address]; var addrD = BluetoothAddress.Parse(addrDt); Utils.MiscUtils.AssertEquals(addrD, _addr); Console.WriteLine("Check DONE Radio..ctor. " + addrD + " vs " + _addr); }
//-- void ReadVersions() { if (_doneVersions) { return; } var vers = new Structs.hci_version(HciVersion.Unknown); var ret = NativeMethods.hci_read_local_version(_dd, ref vers, _fcty.StackTimeout); BluezUtils.Assert(ret, "hci_read_local_version"); if (BluezUtils.IsSuccess(ret)) { _versions = vers; } _doneVersions = true; // Always set, as unlikely to work second time if failed first time. // var arr = new byte[8]; ret = NativeMethods.hci_read_local_features(_dd, arr, _fcty.StackTimeout); if (BluezUtils.IsSuccess(ret)) { _lmpFeatures = (LmpFeatures)BitConverter.ToInt64(arr, 0); } }