[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);
}
/// <summary>
+ /// Starts the Bluetooth LE scan operation with scan mode.
+ /// </summary>
+ /// <remarks>
+ /// The Bluetooth must be enabled.
+ /// </remarks>The result of the operation StartLeScan.
+ /// <param name="mode">The LE scan mode.</param>
+ /// <since_tizen> 7 </since_tizen>
+ /// <feature>http://tizen.org/feature/network.bluetooth.le</feature>
+ /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
+ /// or the Start LE scan is failed.</exception>
+ /// <exception cref="PermissionDeniedException">Thrown when the permission is denied.</exception>
+ 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);
+ }
+ }
+
+ /// <summary>
/// Stops the Bluetooth LE scan operation.
/// </summary>
/// <remarks>
}
/// <summary>
+ /// Enumeration for the Bluetooth LE scan mode.
+ /// </summary>
+ /// <since_tizen> 7 </since_tizen>
+ public enum BluetoothLeScanMode
+ {
+ /// <summary>
+ /// Balanced mode of power consumption and connection latency
+ /// </summary>
+ Balanced,
+ /// <summary>
+ /// Low connection latency but high power consumption
+ /// </summary>
+ LowLatency,
+ /// <summary>
+ /// Low power consumption but high connection latency
+ /// </summary>
+ LowEnergy
+ }
+
+ /// <summary>
/// Enumeration for the integer type for GATT handle's values.
/// </summary>
/// <since_tizen> 3 </since_tizen>
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<string> GetLeScanResultServiceUuids(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
{
if (!BluetoothAdapter.IsBluetoothEnabled || !Globals.IsInitialize)