From eb2efcd86f00510124a775e5346ffad545e321c3 Mon Sep 17 00:00:00 2001 From: Wootak Date: Thu, 2 Apr 2020 10:13:13 +0900 Subject: [PATCH] [Bluetooth][TCSACR-311] Add new StartLeScan API (#1507) --- .../Interop/Interop.Bluetooth.cs | 3 +++ .../Tizen.Network.Bluetooth/BluetoothAdapter.cs | 31 ++++++++++++++++++++++ .../BluetoothEnumerations.cs | 20 ++++++++++++++ .../BluetoothLeAdapterImpl.cs | 12 +++++++++ 4 files changed, 66 insertions(+) diff --git a/src/Tizen.Network.Bluetooth/Interop/Interop.Bluetooth.cs b/src/Tizen.Network.Bluetooth/Interop/Interop.Bluetooth.cs index d3bcaea..1c9cfad 100644 --- a/src/Tizen.Network.Bluetooth/Interop/Interop.Bluetooth.cs +++ b/src/Tizen.Network.Bluetooth/Interop/Interop.Bluetooth.cs @@ -231,6 +231,9 @@ internal static partial class Interop [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_stop_scan")] public static extern int StopScan(); + [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_set_scan_mode")] + public static extern int SetLeScanMode(BluetoothLeScanMode mode); + [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_service_uuids")] public static extern int GetScanResultServiceUuid(ref BluetoothLeScanDataStruct scanData, BluetoothLePacketType packetType, ref IntPtr uuids, ref int count); diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAdapter.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAdapter.cs index 2cb8354..12ff128 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAdapter.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAdapter.cs @@ -638,6 +638,37 @@ namespace Tizen.Network.Bluetooth } /// + /// Starts the Bluetooth LE scan operation with scan mode. + /// + /// + /// The Bluetooth must be enabled. + /// The result of the operation StartLeScan. + /// The LE scan mode. + /// 7 + /// http://tizen.org/feature/network.bluetooth.le + /// Thrown when the Bluetooth LE is not supported. + /// Thrown when the Bluetooth LE is not enabled + /// or the Start LE scan is failed. + /// Thrown when the permission is denied. + static public void StartLeScan(BluetoothLeScanMode mode) + { + if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize) + { + BluetoothLeImplAdapter.Instance.SetScanMode(mode); + int ret = BluetoothLeImplAdapter.Instance.StartScan(); + if (ret != (int)BluetoothError.None) + { + Log.Error(Globals.LogTag, "Failed to start the le scan operation, Error - " + (BluetoothError)ret); + BluetoothErrorFactory.ThrowBluetoothException(ret); + } + } + else + { + BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled); + } + } + + /// /// Stops the Bluetooth LE scan operation. /// /// diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothEnumerations.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothEnumerations.cs index b3b6a66..a57f495 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothEnumerations.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothEnumerations.cs @@ -1061,6 +1061,26 @@ namespace Tizen.Network.Bluetooth } /// + /// Enumeration for the Bluetooth LE scan mode. + /// + /// 7 + public enum BluetoothLeScanMode + { + /// + /// Balanced mode of power consumption and connection latency + /// + Balanced, + /// + /// Low connection latency but high power consumption + /// + LowLatency, + /// + /// Low power consumption but high connection latency + /// + LowEnergy + } + + /// /// Enumeration for the integer type for GATT handle's values. /// /// 3 diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothLeAdapterImpl.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothLeAdapterImpl.cs index b15bb85..bfd7c2f 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothLeAdapterImpl.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothLeAdapterImpl.cs @@ -201,6 +201,18 @@ namespace Tizen.Network.Bluetooth return ret; } + internal int SetScanMode(BluetoothLeScanMode mode) + { + int ret = (int)BluetoothError.None; + + ret = Interop.Bluetooth.SetLeScanMode(mode); + if (ret != (int)BluetoothError.None) { + Log.Error (Globals.LogTag, "Failed to set LE scan mode - " + (BluetoothError)ret); + BluetoothErrorFactory.ThrowBluetoothException (ret); + } + return ret; + } + internal IList GetLeScanResultServiceUuids(BluetoothLeScanData scanData, BluetoothLePacketType packetType) { if (!BluetoothAdapter.IsBluetoothEnabled || !Globals.IsInitialize) -- 2.7.4