コード例 #1
0
        internal int GetScanResultAppearance(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
        {
            if (!BluetoothAdapter.IsBluetoothEnabled || !Globals.IsInitialize)
            {
                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
            }

            int appearance = -1;
            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct(scanData);

            int ret = Interop.Bluetooth.GetScanResultAppearance(ref scanDataStruct, packetType, out appearance);

            if (ret == (int)BluetoothError.NoData)
            {
                Log.Info(Globals.LogTag, "No Appearance in " + packetType);
                Marshal.FreeHGlobal(scanDataStruct.AdvData);
                Marshal.FreeHGlobal(scanDataStruct.ScanData);
                return(-1);
            }
            else if (ret != (int)BluetoothError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get Appearance value- " + (BluetoothError)ret);
                Marshal.FreeHGlobal(scanDataStruct.AdvData);
                Marshal.FreeHGlobal(scanDataStruct.ScanData);
                BluetoothErrorFactory.ThrowBluetoothException(ret);
            }

            Marshal.FreeHGlobal(scanDataStruct.AdvData);
            Marshal.FreeHGlobal(scanDataStruct.ScanData);
            return(appearance);
        }
コード例 #2
0
        internal string GetLeScanResultDeviceName(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
        {
            if (!BluetoothAdapter.IsBluetoothEnabled || !Globals.IsInitialize)
            {
                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
            }

            string deviceName;
            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct(scanData);

            int ret = Interop.Bluetooth.GetLeScanResultDeviceName(ref scanDataStruct, packetType, out deviceName);

            if (ret == (int)BluetoothError.NoData)
            {
                Log.Info(Globals.LogTag, "No DeviceName in " + packetType);
                Marshal.FreeHGlobal(scanDataStruct.AdvData);
                Marshal.FreeHGlobal(scanDataStruct.ScanData);
                return(null);
            }
            else if (ret != (int)BluetoothError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get Device name- " + (BluetoothError)ret);
                Marshal.FreeHGlobal(scanDataStruct.AdvData);
                Marshal.FreeHGlobal(scanDataStruct.ScanData);
                BluetoothErrorFactory.ThrowBluetoothException(ret);
            }

            Log.Info(Globals.LogTag, "DeviceName: " + deviceName);
            Marshal.FreeHGlobal(scanDataStruct.AdvData);
            Marshal.FreeHGlobal(scanDataStruct.ScanData);
            return(deviceName);
        }
コード例 #3
0
        internal int GetScanResultTxPowerLevel(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
        {
            if (!BluetoothAdapter.IsBluetoothEnabled || !Globals.IsInitialize)
            {
                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
            }

            int powerLevel = -1;
            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct(scanData);

            int ret = Interop.Bluetooth.GetScanResultTxPowerLevel(ref scanDataStruct, packetType, out powerLevel);

            if (ret == (int)BluetoothError.NoData)
            {
                Log.Info(Globals.LogTag, "No TxPowerLevel data in " + packetType);
                Marshal.FreeHGlobal(scanDataStruct.AdvData);
                Marshal.FreeHGlobal(scanDataStruct.ScanData);
                return(-1);
            }
            else if (ret != (int)BluetoothError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get tx power level- " + (BluetoothError)ret);
                Marshal.FreeHGlobal(scanDataStruct.AdvData);
                Marshal.FreeHGlobal(scanDataStruct.ScanData);
                BluetoothErrorFactory.ThrowBluetoothException(ret);
            }

            Log.Info(Globals.LogTag, "TxPowerLevel: " + powerLevel);
            Marshal.FreeHGlobal(scanDataStruct.AdvData);
            Marshal.FreeHGlobal(scanDataStruct.ScanData);
            return(powerLevel);
        }
コード例 #4
0
        internal IList <string> GetScanResultSvcSolicitationUuids(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
        {
            IntPtr uuidListArray;
            int    count;

            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct(scanData);

            int ret = Interop.Bluetooth.GetScaResultSvcSolicitationUuids(ref scanDataStruct, packetType, out uuidListArray, out count);

            if (ret != (int)BluetoothError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get service solicitation uuids " + (BluetoothError)ret);
                return(null);
            }

            IntPtr[] uuidList = new IntPtr[count];
            Marshal.Copy(uuidListArray, uuidList, 0, count);
            IList <string> list = new List <string>();

            foreach (IntPtr uuids in uuidList)
            {
                list.Add(Marshal.PtrToStringAnsi(uuids));
                Interop.Libc.Free(uuids);
            }

            Interop.Libc.Free(uuidListArray);
            return(list);
        }
コード例 #5
0
        internal ManufacturerData GetScanResultManufacturerData(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
        {
            int    dataId     = 0;
            int    dataLength = 0;
            IntPtr manufData;

            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct(scanData);
            ManufacturerData          data           = new ManufacturerData();

            int ret = Interop.Bluetooth.GetScanResultManufacturerData(ref scanDataStruct, packetType, out dataId,
                                                                      out manufData, out dataLength);

            if (ret != (int)BluetoothError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get Manufacturer data - " + (BluetoothError)ret);
                return(null);
            }

            data.Id         = dataId;
            data.DataLength = dataLength;
            if (data.DataLength > 0)
            {
                data.Data = new byte[data.DataLength];
                Marshal.Copy(manufData, data.Data, 0, data.DataLength);
            }

            return(data);
        }
コード例 #6
0
        internal IList <string> GetLeScanResultServiceUuids(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
        {
            IntPtr uuidListArray = IntPtr.Zero;
            int    count         = -1;

            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct(scanData);

            int ret = Interop.Bluetooth.GetScanResultServiceUuid(ref scanDataStruct, packetType,
                                                                 ref uuidListArray, ref count);

            if (ret != (int)BluetoothError.None)
            {
                Log.Info(Globals.LogTag, "Failed to service uuids list- " + (BluetoothError)ret);
                return(null);
            }

            Log.Info(Globals.LogTag, "count of uuids :  " + count);

            IntPtr[] uuidList = new IntPtr[count];
            Marshal.Copy(uuidListArray, uuidList, 0, count);
            IList <string> list = new List <string>();

            foreach (IntPtr uuids in uuidList)
            {
                list.Add(Marshal.PtrToStringAnsi(uuids));
                Interop.Libc.Free(uuids);
            }

            Interop.Libc.Free(uuidListArray);
            return(list);
        }
コード例 #7
0
        internal int GetScanResultAppearance(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
        {
            int appearance;

            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct(scanData);

            int ret = Interop.Bluetooth.GetScanResultAppearance(ref scanDataStruct, packetType, out appearance);

            if (ret != (int)BluetoothError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get Appearance value- " + (BluetoothError)ret);
            }
            return(appearance);
        }
コード例 #8
0
        internal int GetScanResultTxPowerLevel(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
        {
            int powerLevel = -1;
            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct(scanData);

            int ret = Interop.Bluetooth.GetScanResultTxPowerLevel(ref scanDataStruct, packetType, out powerLevel);

            if (ret != (int)BluetoothError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get tx power level- " + (BluetoothError)ret);
            }
            Log.Info(Globals.LogTag, "TxPowerLevel is --- " + powerLevel);
            return(powerLevel);
        }
コード例 #9
0
        internal string GetLeScanResultDeviceName(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
        {
            string deviceName;

            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct(scanData);

            int ret = Interop.Bluetooth.GetLeScanResultDeviceName(ref scanDataStruct, packetType, out deviceName);

            if (ret != (int)BluetoothError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get Device name- " + (BluetoothError)ret);
                return(null);
            }
            Log.Info(Globals.LogTag, "Device name " + deviceName);
            return(deviceName);
        }
コード例 #10
0
        internal ManufacturerData GetScanResultManufacturerData(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
        {
            if (!BluetoothAdapter.IsBluetoothEnabled || !Globals.IsInitialize)
            {
                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
            }

            int    dataId     = 0;
            int    dataLength = 0;
            IntPtr manufData;
            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct(scanData);

            int ret = Interop.Bluetooth.GetScanResultManufacturerData(ref scanDataStruct, packetType, out dataId, out manufData, out dataLength);

            if (ret == (int)BluetoothError.NoData)
            {
                Log.Info(Globals.LogTag, "No ManufacturerData in " + packetType);
                Marshal.FreeHGlobal(scanDataStruct.AdvData);
                Marshal.FreeHGlobal(scanDataStruct.ScanData);
                return(null);
            }
            else if (ret != (int)BluetoothError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get Manufacturer data - " + (BluetoothError)ret);
                Marshal.FreeHGlobal(scanDataStruct.AdvData);
                Marshal.FreeHGlobal(scanDataStruct.ScanData);
                BluetoothErrorFactory.ThrowBluetoothException(ret);
            }

            Log.Info(Globals.LogTag, "Count of ManufacturerData: " + dataLength);

            ManufacturerData data = new ManufacturerData();

            data.Id         = dataId;
            data.DataLength = dataLength;
            if (data.DataLength > 0)
            {
                data.Data = new byte[data.DataLength];
                Marshal.Copy(manufData, data.Data, 0, data.DataLength);
            }

            Interop.Libc.Free(manufData);
            Marshal.FreeHGlobal(scanDataStruct.AdvData);
            Marshal.FreeHGlobal(scanDataStruct.ScanData);
            return(data);
        }
コード例 #11
0
        internal IList <BluetoothLeServiceData> GetScanResultServiceDataList(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
        {
            if (!BluetoothAdapter.IsBluetoothEnabled || !Globals.IsInitialize)
            {
                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
            }

            IntPtr serviceListArray;

            _serviceListCount = 0;
            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct(scanData);

            int ret = Interop.Bluetooth.GetScanResultServiceDataList(ref scanDataStruct, packetType, out serviceListArray, out _serviceListCount);

            if (ret == (int)BluetoothError.NoData)
            {
                Log.Info(Globals.LogTag, "No ServiceDataList in " + packetType);
                Marshal.FreeHGlobal(scanDataStruct.AdvData);
                Marshal.FreeHGlobal(scanDataStruct.ScanData);
                return(null);
            }
            else if (ret != (int)BluetoothError.None)
            {
                Log.Info(Globals.LogTag, "Failed to get Service Data List, Error - " + (BluetoothError)ret);
                Marshal.FreeHGlobal(scanDataStruct.AdvData);
                Marshal.FreeHGlobal(scanDataStruct.ScanData);
                BluetoothErrorFactory.ThrowBluetoothException(ret);
            }

            Log.Info(Globals.LogTag, "Count of ServiceDataList: " + _serviceListCount);

            IList <BluetoothLeServiceData> list = new List <BluetoothLeServiceData>();
            int sizePointerToABC = Marshal.SizeOf(new BluetoothLeServiceDataStruct());

            for (int i = 0; i < _serviceListCount; i++)
            {
                var svc = (BluetoothLeServiceDataStruct)Marshal.PtrToStructure(new IntPtr(serviceListArray.ToInt32() + (i * sizePointerToABC)), typeof(BluetoothLeServiceDataStruct));
                list.Add(BluetoothUtils.ConvertStructToLeServiceData(svc));
            }

            Interop.Bluetooth.FreeServiceDataList(serviceListArray, _serviceListCount);
            Marshal.FreeHGlobal(scanDataStruct.AdvData);
            Marshal.FreeHGlobal(scanDataStruct.ScanData);
            return(list);
        }
コード例 #12
0
        internal IList <string> GetScanResultSvcSolicitationUuids(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
        {
            if (!BluetoothAdapter.IsBluetoothEnabled || !Globals.IsInitialize)
            {
                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
            }

            IntPtr uuidListArray;
            int    count;
            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct(scanData);

            int ret = Interop.Bluetooth.GetScanResultSvcSolicitationUuids(ref scanDataStruct, packetType, out uuidListArray, out count);

            if (ret == (int)BluetoothError.NoData)
            {
                Log.Info(Globals.LogTag, "No ServiceSolicitationUuids in " + packetType);
                Marshal.FreeHGlobal(scanDataStruct.AdvData);
                Marshal.FreeHGlobal(scanDataStruct.ScanData);
                return(null);
            }
            else if (ret != (int)BluetoothError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get service solicitation uuids " + (BluetoothError)ret);
                Marshal.FreeHGlobal(scanDataStruct.AdvData);
                Marshal.FreeHGlobal(scanDataStruct.ScanData);
                BluetoothErrorFactory.ThrowBluetoothException(ret);
            }

            Log.Info(Globals.LogTag, "Count of ServiceSolicitationUuids: " + count);

            IList <string> list = new List <string>();

            IntPtr[] uuidList = new IntPtr[count];
            Marshal.Copy(uuidListArray, uuidList, 0, count);
            foreach (IntPtr uuids in uuidList)
            {
                list.Add(Marshal.PtrToStringAnsi(uuids));
                Interop.Libc.Free(uuids);
            }

            Interop.Libc.Free(uuidListArray);
            Marshal.FreeHGlobal(scanDataStruct.AdvData);
            Marshal.FreeHGlobal(scanDataStruct.ScanData);
            return(list);
        }
コード例 #13
0
        internal IList <BluetoothLeServiceData> GetScanResultServiceDataList(BluetoothLeScanData scanData,
                                                                             BluetoothLePacketType packetType, out int serviceCount)
        {
            int    ret = 0;
            IntPtr serviceListArray;

            _serviceListCount = 0;

            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct(scanData);

            ret = Interop.Bluetooth.GetScanResultServiceDataList(ref scanDataStruct, packetType, out serviceListArray, out _serviceListCount);
            Log.Info(Globals.LogTag, "ServiceListCount :  " + _serviceListCount + " PacketType : " + packetType + " Error: " + (BluetoothError)ret);
            if (ret != (int)BluetoothError.None)
            {
                Log.Info(Globals.LogTag, "Failed to get Service Data List, Error - " + (BluetoothError)ret);
                serviceCount = 0;
                Marshal.FreeHGlobal(serviceListArray);
                Marshal.FreeHGlobal(scanDataStruct.AdvData);
                Marshal.FreeHGlobal(scanDataStruct.ScanData);
                return(null);
            }

            BluetoothLeServiceDataStruct[] svcList = new BluetoothLeServiceDataStruct[_serviceListCount];
            int sizePointerToABC = Marshal.SizeOf(new BluetoothLeServiceDataStruct());

            for (int i = 0; i < _serviceListCount; i++)
            {
                svcList[i] = (BluetoothLeServiceDataStruct)Marshal.PtrToStructure(new IntPtr(serviceListArray.ToInt32() + (i * sizePointerToABC)), typeof(BluetoothLeServiceDataStruct));
                Log.Info(Globals.LogTag, " Uuid : " + svcList[i].ServiceUuid + "length :  " + svcList[i].ServiceDataLength);

                _list.Add(BluetoothUtils.ConvertStructToLeServiceData(svcList[i]));
            }

            serviceCount = _serviceListCount;

            Interop.Libc.Free(serviceListArray);
            Marshal.FreeHGlobal(scanDataStruct.AdvData);
            Marshal.FreeHGlobal(scanDataStruct.ScanData);
            return(_list);
        }
コード例 #14
0
ファイル: BluetoothStructs.cs プロジェクト: yunmiha/TizenFX
        internal static BluetoothLeScanData ConvertStructToLeScanData(BluetoothLeScanDataStruct structScanData)
        {
            BluetoothLeScanData scanData = new BluetoothLeScanData();

            scanData.RemoteAddress = structScanData.RemoteAddress;
            scanData.AddressType   = structScanData.AddressType;
            scanData.Rssi          = structScanData.Rssi;

            if (structScanData.AdvDataLength > 0)
            {
                scanData.AdvDataLength = structScanData.AdvDataLength;
                scanData.AdvData       = new byte[scanData.AdvDataLength];
                Marshal.Copy(structScanData.AdvData, scanData.AdvData, 0, scanData.AdvDataLength);
            }

            if (structScanData.ScanDataLength > 0)
            {
                scanData.ScanDataLength = structScanData.ScanDataLength;
                scanData.ScanData       = new byte[scanData.ScanDataLength];
                Marshal.Copy(structScanData.ScanData, scanData.ScanData, 0, scanData.ScanDataLength);
            }
            return(scanData);
        }
コード例 #15
0
ファイル: BluetoothStructs.cs プロジェクト: yunmiha/TizenFX
        internal static BluetoothLeScanDataStruct ConvertLeScanDataToStruct(BluetoothLeScanData scanData)
        {
            BluetoothLeScanDataStruct scanDataStruct = new BluetoothLeScanDataStruct();

            scanDataStruct.RemoteAddress = scanData.RemoteAddress;
            scanDataStruct.AddressType   = scanData.AddressType;
            scanDataStruct.Rssi          = scanData.Rssi;

            if (scanData.AdvDataLength > 0)
            {
                scanDataStruct.AdvDataLength = scanData.AdvDataLength;
                scanDataStruct.AdvData       = Marshal.AllocHGlobal(scanData.AdvDataLength);
                Marshal.Copy(scanData.AdvData, 0, scanDataStruct.AdvData, scanData.AdvDataLength);
            }

            if (scanData.ScanDataLength > 0)
            {
                scanDataStruct.ScanDataLength = scanData.ScanDataLength;
                scanDataStruct.ScanData       = Marshal.AllocHGlobal(scanData.ScanDataLength);
                Marshal.Copy(scanData.ScanData, 0, scanDataStruct.ScanData, scanData.ScanDataLength);
            }

            return(scanDataStruct);
        }