接入蓝牙基本结构

This commit is contained in:
suntao committed 2021-06-04 13:22:59 +08:00
1 parent 84e8b50bbf
commit 2f84f70a5f
152 files changed
+6426 -56

No files matched your search

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Ble
{
/// <summary>
/// rouvy里的 WinBlePeripheralInfo类
/// </summary>
public class BleDeviceProxy
{
public string Address { get; set; }
public string Name { get; set; }
public int Rssi { get; set; }
public List<Guid> Services { get; set; }
public BleDeviceProxy()
{
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 33bb64404b5022f4d888be258a6b970a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,409 @@
using Assets.Scripts.Ble.Scan;
using Assets.Scripts.Ble.Win;
using Assets.Scripts.Devices.Ant;
using Assets.Scripts.Devices.Ble;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Assets.Scripts.Ble
{
public sealed class BleWinHwInterface
{
private static BleWinHwInterface hwInterface;
private WclBleMainThread wclBleMainThread;
private readonly Dictionary<string, BleAdvertisementInfo> pCache = new Dictionary<string, BleAdvertisementInfo>();
private Action<BleAdvertisementInfo> _discoveredCallback;
private Dictionary<BlePeripheralInfo, Action<BleWinHwInterface, BlePeripheralInfo, BleResponse>> callbacks = new Dictionary<BlePeripheralInfo, Action<BleWinHwInterface, BlePeripheralInfo, BleResponse>>();
private Dictionary<BlePeripheralInfo, Action<BleWinHwInterface, BlePeripheralInfo, BleResponse<List<BleServiceInfo>>>> servicesCallbacks = new Dictionary<BlePeripheralInfo, Action<BleWinHwInterface, BlePeripheralInfo, BleResponse<List<BleServiceInfo>>>>();
//private Dictionary<BlePeripheralInfo, Action<BleWinHwInterface, BleServiceInfo, BleResponse<List<BleCharacteristicInfo>>>> characteristicsCallbacks = new Dictionary<BlePeripheralInfo, Action<BleWinHwInterface, BleServiceInfo, BleResponse<List<BleCharacteristicInfo>>>>();
private Dictionary<BlePeripheralInfo, Action<BleWinHwInterface, BleCharacteristicInfo, BleResponse>> characteristicNotificationCallbacks = new Dictionary<BlePeripheralInfo, Action<BleWinHwInterface, BleCharacteristicInfo, BleResponse>>();
private Dictionary<BleCharacteristicInfo, CharacteristicReadCallback> characteristicReadCallbacks = new Dictionary<BleCharacteristicInfo, CharacteristicReadCallback>();
private Dictionary<BleServiceInfo, CharacteristicsDiscoveredCallback> characteristicsDiscoveredCallbacks = new Dictionary<BleServiceInfo, CharacteristicsDiscoveredCallback>();
private CharacteristicReadCallback characteristicReadEvent;
public event CharacteristicReadCallback CharacteristicReadEvent
{
add
{
this.characteristicReadEvent += value;
}
remove
{
this.characteristicReadEvent -= value;
}
}
private BluetoothStateChangedCallback bluetoothStateChanged;
public event BluetoothStateChangedCallback BluetoothStateChangedEvent
{
add
{
this.bluetoothStateChanged += value;
}
remove
{
this.bluetoothStateChanged -= value;
}
}
private BleState nativeState;
public BleState BleState
{
get
{
return this.nativeState;
}
private set
{
if(this.nativeState != value)
{
this.nativeState = value;
this.bluetoothStateChanged?.Invoke(this, this.nativeState);
}
}
}
private PeripheralDisconnectedCallback peripheralDisconnectedEvent;
public event PeripheralDisconnectedCallback PeripheralDisconnectedEvent
{
add
{
this.peripheralDisconnectedEvent += value;
}
remove
{
this.peripheralDisconnectedEvent -= value;
}
}
private BleWinHwInterface()
{
wclBleMainThread = new WclBleMainThread();
wclBleMainThread.ManagerStatusChanged += ManagerStatusChanged;
wclBleMainThread.ScanInfoReceived += WatcherScanInfoReceived;
//wclBleMainThread.gatt
wclBleMainThread.Start();
}
private void WatcherScanInfoReceived(WclBleMainThread sender, long address, string name, int rssi, CPPBridge.WclBleAdvertisementType packetType, Guid? service)
{
//Debug.Log($"address:{ address }, name:{ name }, service:{ (service == null ? "" : service.Value.ToString()) }");
if (!string.IsNullOrWhiteSpace(name))
{
if (pCache.ContainsKey(address.ToString()))
{
((pCache[address.ToString()].Peripheral) as WinBlePeripheralInfo).SetName(name);
}
}
//Debug.Log("service:" + service.ToString()+",name:" + name);
if (service.HasValue && ServiceUuids.Services.Select(s => s.IdGuid).Any(x => x.Equals(service.Value)))
{
SensorType sensor = SensorType.None;
List<Guid> services = null;
if (service != null)
{
services = new List<Guid> { service.Value };
foreach(var item in ServiceUuids.Services)
{
if(item.IdGuid != service.Value)
{
continue;
}
if(item.IdByteArray == ServiceUuids.Ftms)
{
sensor = SensorType.Trainer;
}
else if(item.IdByteArray == ServiceUuids.HeartRate)
{
sensor = SensorType.HeartRate;
}
else if(item.IdByteArray == ServiceUuids.CyclingPower)
{
sensor = SensorType.Power;
}
}
};
if (!pCache.ContainsKey(address.ToString())) {
var device = new BleAdvertisementInfo(new WinBlePeripheralInfo(address.ToString(), name), rssi, true, services, null, sensor);
pCache.Add(address.ToString(), device);
WclBleGattThread gattClient = this.SetUpGattClient(device.Peripheral);
//this.ConnectInternal(gattClient);
}
_discoveredCallback?.Invoke(pCache[address.ToString()]);
}
}
private WclBleGattThread SetUpGattClient(BlePeripheralInfo peripheral)
{
WclBleGattThread wclBleGattThread = this.wclBleMainThread.CreateGattThread(peripheral);
wclBleGattThread.GattConnected += this.GattConnected;
wclBleGattThread.GattDisconnected += this.GattDisconnected;
wclBleGattThread.GattServicesDiscovered += this.GattServicesDiscovered;
wclBleGattThread.GattCharacteristicsDiscovered += this.GattCharacteristicsDiscovered;
wclBleGattThread.GattCharacteristicSubscribed += this.GattCharacteristicSubscribed;
wclBleGattThread.GattCharacteristicRead += this.GattCharacteristicRead;
wclBleGattThread.GattCharacteristicWrote += this.GattCharacteristicWrote;
wclBleGattThread.GattCharacteristicChanged += this.GattCharacteristicChanged;
wclBleGattThread.Start();
return wclBleGattThread;
}
internal void ConnectPeripheral(BlePeripheralInfo info, Action<BleWinHwInterface, BlePeripheralInfo, BleResponse> callback)
{
this.callbacks.Add(info, callback);
WclBleGattThread wclBleGattThread = this.wclBleMainThread.GetGattThread(info);
if(wclBleGattThread == null)
{
wclBleGattThread = this.SetUpGattClient(info);
this.ConnectInternal(wclBleGattThread);
return;
}
else
{
this.ConnectInternal(wclBleGattThread);
}
}
private void ConnectInternal(WclBleGattThread gattClient)
{
int num = gattClient.Connect();
Debug.Log("连接设备返回" + num);
}
internal void DisconnectPeripheral(BlePeripheralInfo peripheral, Action callback)
{
var gattThread = this.wclBleMainThread.GetGattThread(peripheral);
if(gattThread != null)
{
this.callbacks.Remove(peripheral);
this.servicesCallbacks.Remove(peripheral);
this.characteristicNotificationCallbacks.Remove(peripheral);
gattThread.Discounect();
callback?.Invoke();
}
}
public static BleWinHwInterface GetInterface()
{
if(hwInterface == null)
{
hwInterface = new BleWinHwInterface();
}
return hwInterface;
}
public void StartScan(Action<BleAdvertisementInfo> discoveredCallBack)
{
_discoveredCallback = discoveredCallBack;
this.wclBleMainThread.StartWatcher();
}
private void ManagerStatusChanged(WclBleMainThread sender, WclBleManagerStatus status)
{
this.BleState = BleWinHwInterface.StateFromNativeState(status);
Debug.Log("win hw:" + status);
}
private void GattConnected(WclBleGattThread gattClient, BleResponse response)
{
Debug.Log($"gatt connected { response.ToString() }");
this.callbacks[gattClient.Peripheral].Invoke(this, gattClient.Peripheral, response);
}
private void GattDisconnected(WclBleGattThread gattClient, BleResponse response)
{
Debug.Log("gatt disconnected");
}
private void GattServicesDiscovered(WclBleGattThread gattClient, BleResponse<List<BleServiceInfo>> response)
{
Debug.Log("services discovered");
//this.callbacks[gattClient.Peripheral].Invoke(this, gattClient.Peripheral, response);
foreach (var item in response.Data)
{
Debug.Log(item.ToString());
}
if (this.servicesCallbacks.ContainsKey(gattClient.Peripheral))
{
this.servicesCallbacks[gattClient.Peripheral].Invoke(this, gattClient.Peripheral, response);
}
}
private void GattCharacteristicsDiscovered(WclBleGattThread gattClient, BleServiceInfo service, BleResponse<List<BleCharacteristicInfo>> response)
{
Debug.Log("characteristics discovered");
if (this.characteristicsDiscoveredCallbacks.ContainsKey(service))
{
this.characteristicsDiscoveredCallbacks[service].Invoke(this, service, response);
}
}
private void GattCharacteristicSubscribed(WclBleGattThread gattClient, BleCharacteristicInfo characteristic, BleResponse response)
{
Debug.Log("characteristics subscribed");
if (this.characteristicNotificationCallbacks.ContainsKey(gattClient.Peripheral))
{
this.characteristicNotificationCallbacks[gattClient.Peripheral].Invoke(this, characteristic, response);
}
}
private void GattCharacteristicRead(WclBleGattThread gattClient, BleCharacteristicInfo characteristic, BleResponse<byte[]> response)
{
Debug.Log("characteristic read");
if (this.characteristicReadCallbacks.ContainsKey(characteristic))
{
this.characteristicReadCallbacks[characteristic].Invoke(this, characteristic, response);
this.characteristicReadCallbacks.Remove(characteristic);
}
this.characteristicReadEvent.Invoke(this, characteristic, response);
}
private void GattCharacteristicWrote(WclBleGattThread gattClient, BleCharacteristicInfo characteristic, BleResponse<BleCharacteristicWriteType> response)
{
Debug.Log("characteristic wrote");
}
private void GattCharacteristicChanged(WclBleGattThread gattClient, BleCharacteristicInfo characteristic, BleResponse<byte[]> response)
{
Debug.Log("characteristic changed");
if(this.wclBleMainThread.GetGattThread(characteristic.Peripheral) != null)
{
this.characteristicReadEvent.Invoke(this, characteristic, response);
}
}
public void DiscoverServices(BlePeripheralInfo peripheral, Action<BleWinHwInterface, BlePeripheralInfo, BleResponse<List<BleServiceInfo>>> callback)
{
WclBleGattThread gattThread = this.wclBleMainThread.GetGattThread(peripheral);
if(gattThread == null)
{
return;
}
this.servicesCallbacks.Add(peripheral, callback);
int num = gattThread.DiscoverServices();
if (WclBleErrors.IsSuccessCode(num))
{
return;
}
BleResponse<List<BleServiceInfo>> response = new BleResponse<List<BleServiceInfo>>
{
IsSuccess = false,
Error = new BleHwInterfaceError(new int?(num), "WclBleGattClientErrorDomain", string.Format("Error discovering services - {0}", num))
};
this.GattServicesDiscovered(gattThread, response);
}
public void DiscoverCharacteristic(BleServiceInfo service, CharacteristicsDiscoveredCallback callback)
{
WclBleGattThread gattThread = this.wclBleMainThread.GetGattThread(service.Peripheral);
if(gattThread == null)
{
return;
}
this.characteristicsDiscoveredCallbacks.Add(service, callback);
int num = gattThread.DiscoverCharacteristics(service);
if (WclBleErrors.IsSuccessCode(num))
{
return;
}
BleResponse<List<BleCharacteristicInfo>> response = new BleResponse<List<BleCharacteristicInfo>>
{
IsSuccess = false,
Error = new BleHwInterfaceError(new int?(num), "WclBleGattClientErrorDomain", string.Format("Error discovering characteristics - {0}", num))
};
this.GattCharacteristicsDiscovered(gattThread, service, response);
}
public void SubscribeCharacteristic(BleCharacteristicInfo characteristic, Action<BleWinHwInterface, BleCharacteristicInfo, BleResponse> callback)
{
WclBleGattThread gattThread = this.wclBleMainThread.GetGattThread(characteristic.Peripheral);
this.characteristicNotificationCallbacks.Add(gattThread.Peripheral, callback);
int num = gattThread.SubscribeCharacteristic(characteristic);
if (WclBleErrors.IsSuccessCode(num))
{
return;
}
BleResponse<List<BleServiceInfo>> response = new BleResponse<List<BleServiceInfo>>
{
IsSuccess = false,
Error = new BleHwInterfaceError(new int?(num), "WclBleGattClientErrorDomain", string.Format("Error subscribing characteristic - {0}", num))
};
this.GattCharacteristicSubscribed(gattThread, characteristic, response);
}
public void Dispose()
{
this.wclBleMainThread.Dispose();
this.wclBleMainThread = null;
hwInterface = null;
}
public void ReadCharacteristic(BleCharacteristicInfo characteristic, CharacteristicReadCallback callback)
{
WclBleGattThread gattThread = this.wclBleMainThread.GetGattThread(characteristic.Peripheral);
if(gattThread == null)
{
return;
}
this.characteristicReadCallbacks.Add(characteristic, callback);
int num = gattThread.ReadCharacteristicValue(characteristic);
if (WclBleErrors.IsSuccessCode(num))
{
return;
}
}
private static BleState StateFromNativeState(WclBleManagerStatus status)
{
switch (status)
{
case WclBleManagerStatus.RadioOff:
return BleState.Off;
case WclBleManagerStatus.RadioOn:
return BleState.On;
case WclBleManagerStatus.Unknown:
return BleState.Unknown;
default:
return BleState.Unavailable;
}
}
private class WinBlePeripheralInfo : BlePeripheralInfo
{
// Token: 0x06003F35 RID: 16181 RVA: 0x000E9FBF File Offset: 0x000E81BF
public WinBlePeripheralInfo(string address, string name) : base(address, name)
{
}
// Token: 0x06003F36 RID: 16182 RVA: 0x000E9FC9 File Offset: 0x000E81C9
public void SetName(string name)
{
base.Name = name;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8749d096f14d0ea44ad8ab90a45d70f1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a5379f968d8a33a4fa0f222d169164d4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Ble.Win.CPPBridge
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal struct GattCharacteristic
{
// Token: 0x04001350 RID: 4944
[MarshalAs(UnmanagedType.U2)]
public ushort ServiceHandle;
// Token: 0x04001351 RID: 4945
public GattUuid Uuid;
// Token: 0x04001352 RID: 4946
[MarshalAs(UnmanagedType.U2)]
public ushort Handle;
// Token: 0x04001353 RID: 4947
[MarshalAs(UnmanagedType.U2)]
public ushort ValueHandle;
// Token: 0x04001354 RID: 4948
[MarshalAs(UnmanagedType.Bool)]
public bool IsBroadcastable;
// Token: 0x04001355 RID: 4949
[MarshalAs(UnmanagedType.Bool)]
public bool IsReadable;
// Token: 0x04001356 RID: 4950
[MarshalAs(UnmanagedType.Bool)]
public bool IsWritable;
// Token: 0x04001357 RID: 4951
[MarshalAs(UnmanagedType.Bool)]
public bool IsWritableWithoutResponse;
// Token: 0x04001358 RID: 4952
[MarshalAs(UnmanagedType.Bool)]
public bool IsSignedWritable;
// Token: 0x04001359 RID: 4953
[MarshalAs(UnmanagedType.Bool)]
public bool IsNotifiable;
// Token: 0x0400135A RID: 4954
[MarshalAs(UnmanagedType.Bool)]
public bool IsIndicatable;
// Token: 0x0400135B RID: 4955
[MarshalAs(UnmanagedType.Bool)]
public bool HasExtendedProperties;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7e3cd838ef790974db97b48787131436
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Ble.Win.CPPBridge
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal struct GattCharacteristics
{
// Token: 0x0400135C RID: 4956
[MarshalAs(UnmanagedType.U1)]
public byte Count;
// Token: 0x0400135D RID: 4957
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 255)]
public GattCharacteristic[] Chars;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 34261dc02869ee243a7168adabe60fc9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Ble.Win.CPPBridge
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal struct GattService
{
// Token: 0x0400135E RID: 4958
public GattUuid Uuid;
// Token: 0x0400135F RID: 4959
[MarshalAs(UnmanagedType.U2)]
public ushort Handle;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2daabe73d2950c243a1a6a872bd74445
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Ble.Win.CPPBridge
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal struct GattServices
{
// Token: 0x04001360 RID: 4960
[MarshalAs(UnmanagedType.U1)]
public byte Count;
// Token: 0x04001361 RID: 4961
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 255)]
public GattService[] Services;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fb895de0d5e252c4e9cf793690ddf39c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Ble.Win.CPPBridge
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal struct GattUuid
{
// Token: 0x06002139 RID: 8505 RVA: 0x000896C8 File Offset: 0x000878C8
public override string ToString()
{
if (!this.IsShortUuid)
{
return string.Format("{0:D}", this.LongUuid);
}
return string.Format("0x{0:X}", this.ShortUuid);
}
// Token: 0x04001362 RID: 4962
[MarshalAs(UnmanagedType.Bool)]
public bool IsShortUuid;
// Token: 0x04001363 RID: 4963
[MarshalAs(UnmanagedType.U2)]
public ushort ShortUuid;
// Token: 0x04001364 RID: 4964
public Guid LongUuid;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 980c29814813f4c419759b2b0f6158eb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Ble.Win.CPPBridge
{
internal static class GattUuidExtension
{
// Token: 0x0600213A RID: 8506 RVA: 0x000896FD File Offset: 0x000878FD
public static Guid WclShortGuidToGuid(this ushort shortUuid)
{
return new Guid("0000XXXX-0000-1000-8000-00805F9B34FB".Replace("XXXX", shortUuid.ToString("X4")));
}
// Token: 0x0600213B RID: 8507 RVA: 0x0008971F File Offset: 0x0008791F
public static Guid WclGuidToNormalizedGuid(this GattUuid uuid)
{
if (uuid.IsShortUuid)
{
return new Guid("0000XXXX-0000-1000-8000-00805F9B34FB".Replace("XXXX", uuid.ShortUuid.ToString("X4")));
}
return uuid.LongUuid;
}
// Token: 0x04001365 RID: 4965
public const string GuidTemplate = "0000XXXX-0000-1000-8000-00805F9B34FB";
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9a96dd52c07e9f749806d13f85953f1c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
using System;
using System.Runtime.InteropServices;
namespace Assets.Scripts.Ble.CPPBridge
{
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = false)]
internal delegate void WCL_NOTIFY_EVENT([MarshalAs(UnmanagedType.SysInt)][In] IntPtr sender);
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 857859a8d81c3474d98b6f9a08158d1c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Ble.CPPBridge
{
internal enum WclBleAdvertisementType
{
// Token: 0x0400136D RID: 4973
ConnectableUndirected,
// Token: 0x0400136E RID: 4974
ConnectableDirected,
// Token: 0x0400136F RID: 4975
ScannableUndirected,
// Token: 0x04001370 RID: 4976
NonConnectableUndirected,
// Token: 0x04001371 RID: 4977
ScanResponse,
// Token: 0x04001372 RID: 4978
Unknown
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: da17e15eaae28fb4aaa037e484e6563b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Ble.Win.CPPBridge
{
internal enum WclBleGattClientState
{
// Token: 0x04001374 RID: 4980
Disconnected,
// Token: 0x04001375 RID: 4981
Preparing,
// Token: 0x04001376 RID: 4982
Connecting,
// Token: 0x04001377 RID: 4983
Connected,
// Token: 0x04001378 RID: 4984
Disconnecting
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0ba37be1c32d2744fb72633ab646ca6e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,11 @@
using Assets.Scripts.Ble;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Devices.Ble.Win
{
internal delegate void GattConnected(WclBleGattThread gatt, BleResponse response);
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4daa321f84b44e14a8784f7470afefe2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,11 @@
using Assets.Scripts.Devices.Ble;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Ble.Win
{
internal delegate void GattDisconnected(WclBleGattThread gatt, BleResponse response);
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6d6d9e75965935a47a46eb30e0faf550
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,11 @@
using Assets.Scripts.Devices.Ble;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Ble.Win
{
internal delegate void GattServicesDiscovered(WclBleGattThread gatt, BleResponse<List<BleServiceInfo>> response);
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3d817b05c3d2f464b97cefe9f618803a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Ble
{
public class ServiceUuid
{
public Guid IdGuid { get; }
public byte[] IdByteArray { get; }
public bool IsCycling { get; }
public ServiceUuid(Guid idGuid, byte[] idByteArray, bool isCycling)
{
// ISSUE: reference to a compiler-generated field
this.IdByteArray = idByteArray;
// ISSUE: reference to a compiler-generated field
this.IdGuid = idGuid;
// ISSUE: reference to a compiler-generated field
this.IsCycling = isCycling;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 219f9436857f49e40a86f16c35aafca5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,343 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Ble
{
public static class ServiceUuids
{
public static readonly byte[] GenericAccessService = new byte[2]
{
(byte) 24,
(byte) 0
};
public static readonly byte[] DeviceInformation = new byte[2]
{
(byte) 24,
(byte) 10
};
public static readonly byte[] Battery = new byte[2]
{
(byte) 24,
(byte) 15
};
public static readonly byte[] CyclingPower = new byte[2]
{
(byte) 24,
(byte) 24
};
public static readonly byte[] CyclingSpeedCadence = new byte[2]
{
(byte) 24,
(byte) 22
};
public static readonly byte[] HeartRate = new byte[2]
{
(byte) 24,
(byte) 13
};
public static readonly byte[] Ftms = new byte[2]
{
(byte) 24,
(byte) 38
};
public static readonly byte[] KineticInRide = new byte[16]
{
(byte) 233,
(byte) 65,
(byte) 1,
(byte) 0,
(byte) 180,
(byte) 52,
(byte) 68,
(byte) 107,
(byte) 181,
(byte) 204,
(byte) 54,
(byte) 89,
(byte) 47,
(byte) 196,
(byte) 199,
(byte) 36
};
public static readonly byte[] KineticSmartControl = new byte[16]
{
(byte) 233,
(byte) 65,
(byte) 2,
(byte) 0,
(byte) 180,
(byte) 52,
(byte) 68,
(byte) 107,
(byte) 181,
(byte) 204,
(byte) 54,
(byte) 89,
(byte) 47,
(byte) 196,
(byte) 199,
(byte) 36
};
public static readonly byte[] TacxBle = new byte[16]
{
(byte) 110,
(byte) 64,
(byte) 254,
(byte) 193,
(byte) 181,
(byte) 163,
(byte) 243,
(byte) 147,
(byte) 224,
(byte) 169,
(byte) 229,
(byte) 14,
(byte) 36,
(byte) 220,
(byte) 202,
(byte) 158
};
public static readonly byte[] Elite = new byte[16]
{
(byte) 52,
(byte) 123,
(byte) 0,
(byte) 1,
(byte) 118,
(byte) 53,
(byte) 64,
(byte) 139,
(byte) 137,
(byte) 24,
(byte) 143,
(byte) 243,
(byte) 148,
(byte) 156,
(byte) 229,
(byte) 146
};
public static readonly byte[] PowerBeam = new byte[16]
{
(byte) 192,
(byte) 244,
(byte) 1,
(byte) 58,
(byte) 168,
(byte) 55,
(byte) 65,
(byte) 101,
(byte) 186,
(byte) 185,
(byte) 101,
(byte) 78,
(byte) 247,
(byte) 7,
(byte) 71,
(byte) 198
};
public static readonly byte[][] CyclingRelatedServices = new byte[9][]
{
ServiceUuids.CyclingPower,
ServiceUuids.CyclingSpeedCadence,
ServiceUuids.HeartRate,
ServiceUuids.KineticInRide,
ServiceUuids.KineticSmartControl,
ServiceUuids.TacxBle,
ServiceUuids.Elite,
ServiceUuids.PowerBeam,
ServiceUuids.Ftms,
};
public static readonly IReadOnlyList<ServiceUuid> Services = (IReadOnlyList<ServiceUuid>)new List<ServiceUuid>()
{
new ServiceUuid(new Guid("0000180A-0000-1000-8000-00805F9B34FB"), ServiceUuids.DeviceInformation, false),
new ServiceUuid(new Guid("0000180F-0000-1000-8000-00805F9B34FB"), ServiceUuids.Battery, false),
new ServiceUuid(new Guid("00001818-0000-1000-8000-00805F9B34FB"), ServiceUuids.CyclingPower, true),
new ServiceUuid(new Guid("00001816-0000-1000-8000-00805F9B34FB"), ServiceUuids.CyclingSpeedCadence, true),
new ServiceUuid(new Guid("0000180D-0000-1000-8000-00805F9B34FB"), ServiceUuids.HeartRate, true),
new ServiceUuid(new Guid("00001826-0000-1000-8000-00805F9B34FB"), ServiceUuids.Ftms, true),
new ServiceUuid(new Guid("000141e9-34b4-6b44-b5cc-36592fc4c724"), ServiceUuids.KineticInRide, true),
new ServiceUuid(new Guid("000241e9-34b4-6b44-b5cc-36592fc4c724"), ServiceUuids.KineticSmartControl, true),
new ServiceUuid(new Guid("6e40fec1-b5a3-f393-e0a9-e50e24dcca9e"), ServiceUuids.TacxBle, true),
new ServiceUuid(new Guid("01007b34-3576-8b40-8918-8ff3949ce592"), ServiceUuids.Elite, true),
new ServiceUuid(new Guid("3a01f4c0-37a8-6541-bab9-654ef70747c6"), ServiceUuids.PowerBeam, true),
};
public static readonly IReadOnlyList<ServiceUuid> CyclingServices = ServiceUuids.Services.Where(s => s.IsCycling).ToList();
public static ServiceUuid Get(byte[] type)
{
return ServiceUuids.Services.Single(s => s.IdByteArray == type);
}
public static class Characteristics
{
/// <summary>
/// Heart Rate Measurement
/// </summary>
public static Guid HrMeasurement = new Guid("00002A37-0000-1000-8000-00805F9B34FB");
// Token: 0x040028D4 RID: 10452
public static Guid BodySensorLocation = new Guid("00002A38-0000-1000-8000-00805F9B34FB");
// Token: 0x040028D5 RID: 10453
public static Guid CscMeasurement = new Guid("00002A5B-0000-1000-8000-00805F9B34FB");
// Token: 0x040028D6 RID: 10454
public static Guid CscFeature = new Guid("00002A5C-0000-1000-8000-00805F9B34FB");
// Token: 0x040028D7 RID: 10455
public static Guid SensorLocation = new Guid("00002A5D-0000-1000-8000-00805F9B34FB");
// Token: 0x040028D8 RID: 10456
public static Guid ScControlPoint = new Guid("00002A55-0000-1000-8000-00805F9B34FB");
// Token: 0x040028D9 RID: 10457
public static Guid CyclingPowerMeasurement = new Guid("00002A63-0000-1000-8000-00805F9B34FB");
// Token: 0x040028DA RID: 10458
public static Guid CyclingPowerVector = new Guid("00002A64-0000-1000-8000-00805F9B34FB");
// Token: 0x040028DB RID: 10459
public static Guid CyclingPowerFeature = new Guid("00002A65-0000-1000-8000-00805F9B34FB");
// Token: 0x040028DC RID: 10460
public static Guid CyclingPowerControlPoint = new Guid("00002A66-0000-1000-8000-00805F9B34FB");
// Token: 0x040028DD RID: 10461
public static Guid FitnessMachineFeature = new Guid("00002ACC-0000-1000-8000-00805F9B34FB");
// Token: 0x040028DE RID: 10462
public static Guid FitnessMachineControlPoint = new Guid("00002AD9-0000-1000-8000-00805F9B34FB");
// Token: 0x040028DF RID: 10463
public static Guid IndoorBikeData = new Guid("00002AD2-0000-1000-8000-00805F9B34FB");
// Token: 0x040028E0 RID: 10464
public static Guid FitnessMachineStatus = new Guid("00002ADA-0000-1000-8000-00805F9B34FB");
// Token: 0x040028E1 RID: 10465
public static Guid FirmwareRevision = new Guid("00002A26-0000-1000-8000-00805F9B34FB");
// Token: 0x040028E2 RID: 10466
public static Guid HardwareRevision = new Guid("00002A27-0000-1000-8000-00805F9B34FB");
// Token: 0x040028E3 RID: 10467
public static Guid SoftwareRevision = new Guid("00002A28-0000-1000-8000-00805F9B34FB");
// Token: 0x040028E4 RID: 10468
public static Guid ManufactureNameString = new Guid("00002A29-0000-1000-8000-00805F9B34FB");
// Token: 0x040028E5 RID: 10469
public static Guid ModelNumber = new Guid("00002A24-0000-1000-8000-00805F9B34FB");
// Token: 0x040028E6 RID: 10470
public static Guid SerialNumber = new Guid("00002A25-0000-1000-8000-00805F9B34FB");
// Token: 0x040028E7 RID: 10471
public static Guid PnPId = new Guid("00002A50-0000-1000-8000-00805F9B34FB");
// Token: 0x040028E8 RID: 10472
public static Guid BatteryLevel = new Guid("00002A19-0000-1000-8000-00805F9B34FB");
// Token: 0x040028E9 RID: 10473
public static Guid RscMeasurement = new Guid("00002A53-0000-1000-8000-00805F9B34FB");
// Token: 0x040028EA RID: 10474
public static Guid RscFeature = new Guid("00002A54-0000-1000-8000-00805F9B34FB");
// Token: 0x040028EB RID: 10475
public static Guid CycleOpsControlPoint = new Guid("CA31A533-A858-4DC7-A650-FDEB6DAD4C14");
// Token: 0x040028EC RID: 10476
public static Guid CycleOpsFtmsSystemWeight = new Guid("0D18A170-5498-11E9-8647-D663BD873D93");
// Token: 0x040028ED RID: 10477
public static Guid EliteBreak = new Guid("347B0010-7635-408B-8918-8FF3949CE592");
// Token: 0x040028EE RID: 10478
public static Guid EliteOutOfRange = new Guid("347B0011-7635-408B-8918-8FF3949CE592");
// Token: 0x040028EF RID: 10479
public static Guid EliteSystemWeight = new Guid("347B0018-7635-408B-8918-8FF3949CE592");
// Token: 0x040028F0 RID: 10480
public static Guid EliteTrainerCapabilities = new Guid("347B0019-7635-408B-8918-8FF3949CE592");
// Token: 0x040028F1 RID: 10481
public static Guid StagesRead = new Guid("0C46BEB0-9C22-48FF-AE0E-C6EAE1A2F4E5");
// Token: 0x040028F2 RID: 10482
public static Guid StagesWrite = new Guid("0C46BEB1-9C22-48FF-AE0E-C6EAE1A2F4E5");
// Token: 0x040028F3 RID: 10483
public static Guid TacxFecRead = new Guid("6E40FEC2-B5A3-F393-E0A9-E50E24DCCA9E");
// Token: 0x040028F4 RID: 10484
public static Guid TacxFecWrite = new Guid("6E40FEC3-B5A3-F393-E0A9-E50E24DCCA9E");
// Token: 0x040028F5 RID: 10485
public static Guid TechnoGymStSimulation = new Guid("58094966-498C-470D-8051-37E617A13895");
// Token: 0x040028F6 RID: 10486
public static Guid WahooControlPoint = new Guid("A026E005-0A7D-4AB3-97FA-F1500F9FEB8B");
// Token: 0x040028F7 RID: 10487
public static Guid WattbikeAtomRead = new Guid("B4CC1224-BC02-4CAE-ADB9-1217AD2860D1");
// Token: 0x040028F8 RID: 10488
public static Guid WattbikeAtomWrite = new Guid("B4CC1225-BC02-4CAE-ADB9-1217AD2860D1");
// Token: 0x040028F9 RID: 10489
public static Guid WattbikeAtomXRead = new Guid("BABF1724-CEDB-444C-88C3-C672C7A59806");
// Token: 0x040028FA RID: 10490
public static Guid WattbikeAtomXWrite = new Guid("BABF1725-CEDB-444C-88C3-C672C7A59806");
// Token: 0x040028FB RID: 10491
public static Guid FitnessMachineTrainingStatus = new Guid("00002AD3-0000-1000-8000-00805F9B34FB");
// Token: 0x040028FC RID: 10492
public static Guid FitnessMachineSupportedResistanceLevelRange = new Guid("00002AD6-0000-1000-8000-00805F9B34FB");
// Token: 0x040028FD RID: 10493
public static Guid FitnessMachineSupportedPowerRange = new Guid("00002AD8-0000-1000-8000-00805F9B34FB");
// Token: 0x040028FE RID: 10494
public static Guid GemFwUpdate = new Guid("A026E002-0A7D-4AB3-97FA-F1500F9FEB8B");
// Token: 0x040028FF RID: 10495
public static Guid GemFwUpdate4 = new Guid("A026E004-0A7D-4AB3-97FA-F1500F9FEB8B");
// Token: 0x04002900 RID: 10496
public static Guid WahooA = new Guid("A026E00A-0A7D-4AB3-97FA-F1500F9FEB8B");
// Token: 0x04002901 RID: 10497
public static Guid Wahoo23 = new Guid("A026E023-0A7D-4AB3-97FA-F1500F9FEB8B");
// Token: 0x04002902 RID: 10498
public static Guid Wahoo37 = new Guid("A026E037-0A7D-4AB3-97FA-F1500F9FEB8B");
// Token: 0x04002903 RID: 10499
public static Guid WahooFitnessType = new Guid("A026E01F-0A7D-4AB3-97FA-F1500F9FEB8B");
// Token: 0x04002904 RID: 10500
public static Guid WahooFitnessState = new Guid("A026E01E-0A7D-4AB3-97FA-F1500F9FEB8B");
// Token: 0x04002905 RID: 10501
public static Guid WahooFitnessStateName = new Guid("A026E020-0A7D-4AB3-97FA-F1500F9FEB8B");
// Token: 0x04002906 RID: 10502
public static Guid WahooFitnessMeasurement = new Guid("A026E01D-0A7D-4AB3-97FA-F1500F9FEB8B");
// Token: 0x04002907 RID: 10503
public static Guid WahooFitnessWorkoutProgramName = new Guid("A026E01B-0A7D-4AB3-97FA-F1500F9FEB8B");
// Token: 0x04002908 RID: 10504
public static Guid WahooFitnessSensorMeasurementInput = new Guid("A026E016-0A7D-4AB3-97FA-F1500F9FEB8B");
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c595e469b7e8ef744bf1d32496bbb15d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 037f3eff461a68d40bdf5880692fc0cf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,302 @@
using Assets.Scripts.Ble.Win.CPPBridge;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Assets.Scripts.Ble.Win
{
internal class WclBleGattClient
{
public WclBleGattClient(long address, IntPtr radio)
{
this.gattAddress = address;
this.rPtr = radio;
this.CConnectEvent = new WclBleGattClient.GATTCLIENT_CONNECT(this.OnConnected);
this.CDisconnectEvent = new WclBleGattClient.GATTCLIENT_DISCONNECT(this.OnDisconnected);
this.FCharacteristicChangedEvent = new WclBleGattClient.GATTCLIENT_ONCHANGED(this.OnCharacteristicChanged);
this.mPtr = WclBleGattClient.WCLGattClientCreate(this.CConnectEvent, this.CDisconnectEvent, this.FCharacteristicChangedEvent);
}
// Token: 0x06002086 RID: 8326
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I4)]
private static extern int WCLGattClientConnect([MarshalAs(UnmanagedType.SysInt)][In] IntPtr Client, [MarshalAs(UnmanagedType.SysInt)][In] IntPtr Radio, [MarshalAs(UnmanagedType.I8)][In] long Address);
// Token: 0x06002087 RID: 8327
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.SysInt)]
private static extern IntPtr WCLGattClientCreate([MarshalAs(UnmanagedType.FunctionPtr)][In] WclBleGattClient.GATTCLIENT_CONNECT OnConnect, [MarshalAs(UnmanagedType.FunctionPtr)][In] WclBleGattClient.GATTCLIENT_DISCONNECT OnDisconnect, [MarshalAs(UnmanagedType.FunctionPtr)][In] WclBleGattClient.GATTCLIENT_ONCHANGED OnChanged);
// Token: 0x06002088 RID: 8328
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
private static extern void WCLGattClientDestroy([MarshalAs(UnmanagedType.SysInt)][In] IntPtr Client);
// Token: 0x06002089 RID: 8329
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I4)]
private static extern int WCLGattClientDisconnect([MarshalAs(UnmanagedType.SysInt)][In] IntPtr Client);
// Token: 0x0600208A RID: 8330
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
private static extern void WCLGattClientFreeMem([MarshalAs(UnmanagedType.SysInt)][In] IntPtr pMem);
// Token: 0x0600208B RID: 8331
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I4)]
private static extern int WCLGattClientGetCharacteristics([MarshalAs(UnmanagedType.SysInt)][In] IntPtr Client, [In] ref GattService Service, [In][Out] ref GattCharacteristics Chars);
// Token: 0x0600208C RID: 8332
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I4)]
private static extern int WCLGattClientGetServices([MarshalAs(UnmanagedType.SysInt)][In] IntPtr Client, [In][Out] ref GattServices Services);
// Token: 0x0600208D RID: 8333
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.U4)]
private static extern WclBleGattClientState WCLGattClientGetState([MarshalAs(UnmanagedType.SysInt)][In] IntPtr Client);
// Token: 0x0600208E RID: 8334
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I4)]
private static extern int WCLGattClientReadCharacteristicValue([MarshalAs(UnmanagedType.SysInt)][In] IntPtr Client, [In] ref GattCharacteristic Char, [MarshalAs(UnmanagedType.SysInt)][In][Out] ref IntPtr ppValue, [MarshalAs(UnmanagedType.U4)][In][Out] ref uint pSize);
// Token: 0x0600208F RID: 8335
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I4)]
private static extern int WCLGattClientSubscribeCharacteristic([MarshalAs(UnmanagedType.SysInt)][In] IntPtr Client, [In] ref GattCharacteristic Char);
// Token: 0x06002090 RID: 8336
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I4)]
private static extern int WCLGattClientUnsubscribeCharacteristic([MarshalAs(UnmanagedType.SysInt)][In] IntPtr Client, [In] ref GattCharacteristic Char);
// Token: 0x06002091 RID: 8337
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I4)]
private static extern int WCLGattClientWriteCharacteristicValue([MarshalAs(UnmanagedType.SysInt)][In] IntPtr Client, [In] ref GattCharacteristic Char, [MarshalAs(UnmanagedType.SysInt)][In] IntPtr pValue, [MarshalAs(UnmanagedType.U4)][In] uint Size);
// Token: 0x170005D4 RID: 1492
// (get) Token: 0x06002092 RID: 8338 RVA: 0x00087790 File Offset: 0x00085990
public WclBleGattClientState State
{
get
{
return WclBleGattClient.WCLGattClientGetState(this.mPtr);
}
}
// Token: 0x06002093 RID: 8339 RVA: 0x000877A4 File Offset: 0x000859A4
public void Connect()
{
if (this.mPtr != IntPtr.Zero)
{
int num = WclBleGattClient.WCLGattClientConnect(this.mPtr, this.rPtr, this.gattAddress);
if (num != 0)
{
this.OnConnected(this.mPtr, num);
}
}
}
// Token: 0x06002094 RID: 8340 RVA: 0x000877F4 File Offset: 0x000859F4
public void Disconnect()
{
if (this.mPtr != IntPtr.Zero)
{
//WclBleGattClient.log.Info("Disconnect called", Array.Empty<object>());
int num = WclBleGattClient.WCLGattClientDisconnect(this.mPtr);
//WclBleGattClient.log.Info(string.Format("Disconnect {0:X} response {1}", this.gattAddress, num), Array.Empty<object>());
}
}
// Token: 0x06002095 RID: 8341 RVA: 0x00087864 File Offset: 0x00085A64
public int DiscoverCharacteristics(GattService service, out GattCharacteristics characteristics)
{
characteristics = new GattCharacteristics
{
Count = 0,
Chars = new GattCharacteristic[255]
};
return WclBleGattClient.WCLGattClientGetCharacteristics(this.mPtr, ref service, ref characteristics);
}
// Token: 0x06002096 RID: 8342 RVA: 0x000878B0 File Offset: 0x00085AB0
public int DiscoverServices(out GattServices services)
{
services = new GattServices
{
Count = 0,
Services = new GattService[255]
};
return WclBleGattClient.WCLGattClientGetServices(this.mPtr, ref services);
}
// Token: 0x06002097 RID: 8343 RVA: 0x000878F8 File Offset: 0x00085AF8
public int ReadCharacteristicValue(GattCharacteristic characteristic, out byte[] value)
{
value = null;
IntPtr zero = IntPtr.Zero;
uint num = 0U;
int num2 = WclBleGattClient.WCLGattClientReadCharacteristicValue(this.mPtr, ref characteristic, ref zero, ref num);
if (num2 == 0 && zero != IntPtr.Zero && num > 0U)
{
value = new byte[num];
Marshal.Copy(zero, value, 0, (int)num);
WclBleGattClient.WCLGattClientFreeMem(zero);
}
return num2;
}
// Token: 0x06002098 RID: 8344 RVA: 0x00087953 File Offset: 0x00085B53
public int SubscribeCharacteristic(GattCharacteristic characteristic)
{
return WclBleGattClient.WCLGattClientSubscribeCharacteristic(this.mPtr, ref characteristic);
}
// Token: 0x06002099 RID: 8345 RVA: 0x00087968 File Offset: 0x00085B68
public int WriteCharacteristic(GattCharacteristic characteristic, byte[] value)
{
IntPtr intPtr;
try
{
intPtr = Marshal.AllocHGlobal(value.Length);
}
catch
{
intPtr = IntPtr.Zero;
}
if (intPtr == IntPtr.Zero)
{
return 65537;
}
Marshal.Copy(value, 0, intPtr, value.Length);
int result = WclBleGattClient.WCLGattClientWriteCharacteristicValue(this.mPtr, ref characteristic, intPtr, (uint)value.Length);
Marshal.FreeHGlobal(intPtr);
return result;
}
// Token: 0x0600209A RID: 8346 RVA: 0x000879D4 File Offset: 0x00085BD4
public void Dispose()
{
WclBleGattClient.WCLGattClientDestroy(this.mPtr);
this.mPtr = IntPtr.Zero;
this.rPtr = IntPtr.Zero;
this.CConnectEvent = null;
this.CDisconnectEvent = null;
this.FCharacteristicChangedEvent = null;
}
// Token: 0x0600209B RID: 8347 RVA: 0x00087A0C File Offset: 0x00085C0C
private void OnCharacteristicChanged(IntPtr sender, ushort handle, IntPtr pValue, uint valueLen)
{
//Debug.Log("char changed");
if (pValue != IntPtr.Zero && valueLen > 0U)
{
byte[] array = new byte[valueLen];
Marshal.Copy(pValue, array, 0, (int)valueLen);
try
{
WclBleGattClient.GattCharacteristicChanged characteristicChanged = this.CharacteristicChanged;
if (characteristicChanged != null)
{
characteristicChanged(this, handle, array);
}
}
catch (Exception arg)
{
//WclBleGattClient.log.Error(string.Format("GattConnection characteristic changed callback processing error - {0}", arg), Array.Empty<object>());
}
}
}
// Token: 0x0600209C RID: 8348 RVA: 0x00087A80 File Offset: 0x00085C80
private void OnConnected(IntPtr client, int error)
{
try
{
WclBleGattClient.GattConnectionChanged connected = this.Connected;
if (connected != null)
{
connected(this, error);
}
}
catch (Exception arg)
{
//WclBleGattClient.log.Error(string.Format("GattConnection connect callback processing error - {0}", arg), Array.Empty<object>());
Debug.LogError(arg);
}
}
// Token: 0x0600209D RID: 8349 RVA: 0x00087AD0 File Offset: 0x00085CD0
private void OnDisconnected(IntPtr client, int reason)
{
try
{
WclBleGattClient.GattConnectionChanged disconnected = this.Disconnected;
if (disconnected != null)
{
disconnected(this, reason);
}
}
catch (Exception arg)
{
//WclBleGattClient.log.Error(string.Format("GattConnection disconnect callback processing error - {0}", arg), Array.Empty<object>());
}
}
// Token: 0x0400130B RID: 4875
public WclBleGattClient.GattCharacteristicChanged CharacteristicChanged;
// Token: 0x0400130C RID: 4876
public WclBleGattClient.GattConnectionChanged Connected;
// Token: 0x0400130D RID: 4877
public WclBleGattClient.GattConnectionChanged Disconnected;
// Token: 0x0400130F RID: 4879
private WclBleGattClient.GATTCLIENT_CONNECT CConnectEvent;
// Token: 0x04001310 RID: 4880
private WclBleGattClient.GATTCLIENT_DISCONNECT CDisconnectEvent;
// Token: 0x04001311 RID: 4881
private WclBleGattClient.GATTCLIENT_ONCHANGED FCharacteristicChangedEvent;
// Token: 0x04001312 RID: 4882
private readonly long gattAddress;
// Token: 0x04001313 RID: 4883
private IntPtr mPtr;
// Token: 0x04001314 RID: 4884
private IntPtr rPtr;
// Token: 0x020008FB RID: 2299
// (Invoke) Token: 0x06003F5A RID: 16218
public delegate void GattCharacteristicChanged(WclBleGattClient connection, ushort handle, byte[] value);
// Token: 0x020008FC RID: 2300
// (Invoke) Token: 0x06003F5E RID: 16222
public delegate void GattConnectionChanged(WclBleGattClient connection, int error);
// Token: 0x020008FD RID: 2301
// (Invoke) Token: 0x06003F62 RID: 16226
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = false)]
private delegate void GATTCLIENT_CONNECT([MarshalAs(UnmanagedType.SysInt)][In] IntPtr Sender, [MarshalAs(UnmanagedType.I4)][In] int Error);
// Token: 0x020008FE RID: 2302
// (Invoke) Token: 0x06003F66 RID: 16230
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = false)]
private delegate void GATTCLIENT_DISCONNECT([MarshalAs(UnmanagedType.SysInt)][In] IntPtr Sender, [MarshalAs(UnmanagedType.I4)][In] int Reason);
// Token: 0x020008FF RID: 2303
// (Invoke) Token: 0x06003F6A RID: 16234
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = false)]
private delegate void GATTCLIENT_ONCHANGED([MarshalAs(UnmanagedType.SysInt)][In] IntPtr Sender, [MarshalAs(UnmanagedType.U2)][In] ushort Handle, [MarshalAs(UnmanagedType.SysInt)][In] IntPtr Value, [MarshalAs(UnmanagedType.U4)][In] uint ValueLen);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c6d5039e76dd26d40a81e37ae83d2587
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,403 @@
using Assets.Scripts.Ble.Win;
using Assets.Scripts.Ble.Win.CPPBridge;
using Assets.Scripts.Devices.Ble;
using Assets.Scripts.Devices.Ble.Win;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Assets.Scripts.Ble
{
internal class WclBleGattThread
{
public delegate void GattCharacteristicChangedDelegate(WclBleGattThread gattClient, BleCharacteristicInfo characteristic, BleResponse<byte[]> response);
public delegate void GattCharacteristicReadDelegate(WclBleGattThread gattClient, BleCharacteristicInfo characteristic, BleResponse<byte[]> response);
public delegate void GattCharacteristicsDiscoveredDelegate(WclBleGattThread gattClient, BleServiceInfo service, BleResponse<List<BleCharacteristicInfo>> response);
public delegate void GattCharacteristicSubscribedDelegate(WclBleGattThread gattClient, BleCharacteristicInfo characteristic, BleResponse response);
public delegate void GattCharacteristicWroteDelegate(WclBleGattThread gattClient, BleCharacteristicInfo characteristic, BleResponse<BleCharacteristicWriteType> response);
private WclBleGattThread.GattCharacteristicChangedDelegate gattCharacteristicChanged;
private WclBleGattThread.GattCharacteristicReadDelegate gattCharacteristicRead;
// Token: 0x0400131E RID: 4894
private WclBleGattThread.GattCharacteristicsDiscoveredDelegate gattCharacteristicsDiscovered;
// Token: 0x0400131F RID: 4895
private WclBleGattThread.GattCharacteristicSubscribedDelegate gattCharacteristicsSubscribed;
private GattConnected gattConnected;
// Token: 0x04001322 RID: 4898
private GattDisconnected gattDisconnected;
private GattServicesDiscovered gattServicesDiscovered;
public event WclBleGattThread.GattCharacteristicChangedDelegate GattCharacteristicChanged
{
add
{
this.gattCharacteristicChanged += value;
}
remove
{
this.gattCharacteristicChanged -= value;
}
}
// Token: 0x14000039 RID: 57
// (add) Token: 0x060020AE RID: 8366 RVA: 0x00087BB3 File Offset: 0x00085DB3
// (remove) Token: 0x060020AF RID: 8367 RVA: 0x00087BC7 File Offset: 0x00085DC7
public event WclBleGattThread.GattCharacteristicReadDelegate GattCharacteristicRead
{
add
{
this.gattCharacteristicRead += value;
}
remove
{
this.gattCharacteristicRead -= value;
}
}
// Token: 0x1400003A RID: 58
// (add) Token: 0x060020B0 RID: 8368 RVA: 0x00087BDB File Offset: 0x00085DDB
// (remove) Token: 0x060020B1 RID: 8369 RVA: 0x00087BEF File Offset: 0x00085DEF
public event WclBleGattThread.GattCharacteristicsDiscoveredDelegate GattCharacteristicsDiscovered
{
add
{
this.gattCharacteristicsDiscovered += value;
}
remove
{
this.gattCharacteristicsDiscovered -= value;
}
}
// Token: 0x1400003B RID: 59
// (add) Token: 0x060020B2 RID: 8370 RVA: 0x00087C03 File Offset: 0x00085E03
// (remove) Token: 0x060020B3 RID: 8371 RVA: 0x00087C17 File Offset: 0x00085E17
public event WclBleGattThread.GattCharacteristicSubscribedDelegate GattCharacteristicSubscribed
{
add
{
this.gattCharacteristicsSubscribed += value;
}
remove
{
this.gattCharacteristicsSubscribed -= value;
}
}
private WclBleGattThread.GattCharacteristicWroteDelegate gattCharacteristicWrote;
public event WclBleGattThread.GattCharacteristicWroteDelegate GattCharacteristicWrote
{
add
{
this.gattCharacteristicWrote += value;
}
remove
{
this.gattCharacteristicWrote -= value;
}
}
// Token: 0x1400003D RID: 61
// (add) Token: 0x060020B6 RID: 8374 RVA: 0x00087C53 File Offset: 0x00085E53
// (remove) Token: 0x060020B7 RID: 8375 RVA: 0x00087C67 File Offset: 0x00085E67
public event GattConnected GattConnected
{
add
{
this.gattConnected += value;
}
remove
{
this.gattConnected -= value;
}
}
// Token: 0x1400003E RID: 62
// (add) Token: 0x060020B8 RID: 8376 RVA: 0x00087C7B File Offset: 0x00085E7B
// (remove) Token: 0x060020B9 RID: 8377 RVA: 0x00087C8F File Offset: 0x00085E8F
public event GattDisconnected GattDisconnected
{
add
{
this.gattDisconnected += value;
}
remove
{
this.gattDisconnected -= value;
}
}
// Token: 0x1400003F RID: 63
// (add) Token: 0x060020BA RID: 8378 RVA: 0x00087CA3 File Offset: 0x00085EA3
// (remove) Token: 0x060020BB RID: 8379 RVA: 0x00087CB7 File Offset: 0x00085EB7
public event GattServicesDiscovered GattServicesDiscovered
{
add
{
this.gattServicesDiscovered += value;
}
remove
{
this.gattServicesDiscovered -= value;
}
}
private readonly Dictionary<BleCharacteristicInfo, GattCharacteristic> charMapping = new Dictionary<BleCharacteristicInfo, GattCharacteristic>();
private readonly Dictionary<BleServiceInfo, GattService> servicesMapping = new Dictionary<BleServiceInfo, GattService>();
private readonly Dictionary<ushort, BleCharacteristicInfo> subscribedCharHandles = new Dictionary<ushort, BleCharacteristicInfo>();
private WclBleGattClient gatt;
private IntPtr rPtr;
private BlePeripheralInfo _bleDevice;
private readonly long address;
public BlePeripheralInfo Peripheral { get; }
internal WclBleGattThread(BlePeripheralInfo bleDevice, IntPtr radio)
{
this.Peripheral = bleDevice;
this.rPtr = radio;
_bleDevice = bleDevice;
//this.address = long.Parse(_bleDevice.Address, System.Globalization.NumberStyles.HexNumber);
this.address = long.Parse(_bleDevice.Address);
}
public bool Start()
{
this.SetUpWorkerThread();
return true;
}
private void SetUpWorkerThread()
{
this.gatt = new WclBleGattClient(this.address, this.rPtr)
{
Connected = new WclBleGattClient.GattConnectionChanged(this.OnConnected),
Disconnected = new WclBleGattClient.GattConnectionChanged(this.OnDisconnected),
CharacteristicChanged = new WclBleGattClient.GattCharacteristicChanged(this.OnCharacteristicChanged)
};
}
private void OnCharacteristicChanged(WclBleGattClient connection, ushort handle, byte[] value)
{
if (!this.subscribedCharHandles.ContainsKey(handle)) {
return;
}
BleCharacteristicInfo characteristic = this.subscribedCharHandles[handle];
BleResponse<byte[]> response = new BleResponse<byte[]>
{
IsSuccess = true,
Data = value
};
this.gattCharacteristicChanged?.Invoke(this, characteristic, response);
}
private void OnCharacteristicRead(BleCharacteristicInfo characteristic, int result, byte[] data)
{
BleResponse<byte[]> response = new BleResponse<byte[]>
{
IsSuccess = WclBleErrors.IsSuccessCode(result)
};
if (response.IsSuccess)
{
response.Data = data;
}
else
{
response.Error = new BleHwInterfaceError(new int?(result), "WclBleGattClientErrorDomain", "Error when reading value");
}
this.gattCharacteristicRead.Invoke(this, characteristic, response);
}
private void OnCharacteristicsDiscovered(BleServiceInfo service, int result, GattCharacteristics characteristics)
{
BleResponse<List<BleCharacteristicInfo>> response = new BleResponse<List<BleCharacteristicInfo>>
{
IsSuccess = WclBleErrors.IsSuccessCode(result)
};
if (response.IsSuccess)
{
response.Data = this.ProcessCharacteristics(service, characteristics);
}
else
{
// response.Error = new BleHwInterfaceError(new int?(result), "WclBleGattClientErrorDomain", "Error when reading BLE services");
}
this.gattCharacteristicsDiscovered(this, service, response);
}
private void OnConnected(WclBleGattClient sender, int error)
{
BleResponse response = new BleResponse
{
IsSuccess = WclBleErrors.IsSuccessCode(error)
};
this.gattConnected?.Invoke(this, response);
}
private void OnDisconnected(WclBleGattClient sender, int reason)
{
BleResponse response = new BleResponse
{
IsSuccess = true,
Error = new BleHwInterfaceError(new int?(reason), "WclBleGattClientErrorDomain", string.Format("GATT disconnect reason is - {0}", reason))
};
this.gattDisconnected?.Invoke(this, response);
}
public int Connect()
{
this.gatt.Connect();
return WclBleErrors.WCL_E_SUCCESS;
}
public int Discounect()
{
this.gatt.Disconnect();
return WclBleErrors.WCL_E_SUCCESS;
}
public int DiscoverServices()
{
GattServices services;
int result = this.gatt.DiscoverServices(out services);
this.OnServicesDiscovered(result, services);
return WclBleErrors.WCL_E_SUCCESS;
}
private void OnServicesDiscovered(int result, GattServices services)
{
BleResponse<List<BleServiceInfo>> response = new BleResponse<List<BleServiceInfo>>
{
IsSuccess = WclBleErrors.IsSuccessCode(result)
};
if (response.IsSuccess)
{
response.Data = this.ProcessServices(services);
}
else
{
response.Error = new BleHwInterfaceError(new int?(result), "WclBleGattClientErrorDomain", "Error when reading BLE services");
}
gattServicesDiscovered(this, response);
}
private List<BleCharacteristicInfo> ProcessCharacteristics(BleServiceInfo service, GattCharacteristics characteristics)
{
List<BleCharacteristicInfo> list = new List<BleCharacteristicInfo>((int)characteristics.Count);
for (int i = 0; i < (int)characteristics.Count; i++)
{
GattCharacteristic gattCharacteristic = characteristics.Chars[i];
WclBleGattThread.WinBleCharacteristicInfo winBleCharacteristicInfo = new WclBleGattThread.WinBleCharacteristicInfo(service, gattCharacteristic.Uuid.WclGuidToNormalizedGuid());
this.charMapping[winBleCharacteristicInfo] = gattCharacteristic;
list.Add(winBleCharacteristicInfo);
}
return list;
}
private List<BleServiceInfo> ProcessServices(GattServices services)
{
List<BleServiceInfo> list = new List<BleServiceInfo>((int)services.Count);
for (int i = 0; i < (int)services.Count; i++)
{
GattService gattService = services.Services[i];
WclBleGattThread.WinBleServiceInfo winBleServiceInfo = new WclBleGattThread.WinBleServiceInfo(this._bleDevice, gattService.Uuid.WclGuidToNormalizedGuid());
this.servicesMapping[winBleServiceInfo] = gattService;
list.Add(winBleServiceInfo);
}
return list;
}
public int DiscoverCharacteristics(BleServiceInfo service)
{
GattService ns = this.servicesMapping[service];
GattCharacteristics characteristics;
int result = this.gatt.DiscoverCharacteristics(ns, out characteristics);
this.OnCharacteristicsDiscovered(service, result, characteristics);
return WclBleErrors.WCL_E_SUCCESS;
}
public int ReadCharacteristicValue(BleCharacteristicInfo characteristic)
{
if (!charMapping.ContainsKey(characteristic))
{
return WclBleErrors.WCL_E_CONNECTION_NOT_ACTIVE;
}
GattCharacteristic nCh = this.charMapping[characteristic];
byte[] data;
int result = this.gatt.ReadCharacteristicValue(nCh, out data);
this.OnCharacteristicRead(characteristic, result, data);
return WclBleErrors.WCL_E_SUCCESS;
}
public int SubscribeCharacteristic(BleCharacteristicInfo characteristic)
{
if (!this.charMapping.ContainsKey(characteristic))
{
return WclBleErrors.WCL_E_CONNECTION_NOT_ACTIVE;
}
GattCharacteristic nCh = this.charMapping[characteristic];
int result = this.gatt.SubscribeCharacteristic(nCh);
this.OnCharacteristicsSubscribed(characteristic, nCh, result);
return WclBleErrors.WCL_E_SUCCESS;
}
private void OnCharacteristicsSubscribed(BleCharacteristicInfo characteristic, GattCharacteristic nCharacteristic, int result)
{
Debug.Log("char subscribed");
BleResponse response = new BleResponse
{
IsSuccess = WclBleErrors.IsSuccessCode(result)
};
if (response.IsSuccess)
{
this.subscribedCharHandles[nCharacteristic.Handle] = characteristic;
}
else
{
response.Error = new BleHwInterfaceError(new int?(result), "WclBleGattClientErrorDomain", "Error when subscribing Characteristics");
}
this.gattCharacteristicsSubscribed(this, characteristic, response);
}
private class WinBleCharacteristicInfo : BleCharacteristicInfo
{
// Token: 0x06003F85 RID: 16261 RVA: 0x000EA274 File Offset: 0x000E8474
public WinBleCharacteristicInfo(BleServiceInfo service, Guid id) : base(id, service, (BleCharacteristicProperties)0)
{
}
}
private class WinBleServiceInfo : BleServiceInfo
{
// Token: 0x06003F86 RID: 16262 RVA: 0x000EA27F File Offset: 0x000E847F
public WinBleServiceInfo(BlePeripheralInfo peripheral, Guid id) : base(id, peripheral)
{
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 39de45743ce824f4ea156708d5ce5e66
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,163 @@
using Assets.Scripts.Ble.CPPBridge;
using Assets.Scripts.Devices.Ble;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
namespace Assets.Scripts.Ble
{
internal class WclBleMainThread
{
internal delegate void ManagerStatusChangedCallback(WclBleMainThread thread, WclBleManagerStatus status);
private WclBleMainThread.ManagerStatusChangedCallback managerStatusChanged;
public event WclBleMainThread.ManagerStatusChangedCallback ManagerStatusChanged
{
add
{
this.managerStatusChanged += value;
}
remove
{
this.managerStatusChanged -= value;
}
}
private WclBleManager wclBleManager;
private WclBleWatcher wclWatcher;
private readonly object locker = new object();
private readonly Dictionary<BlePeripheralInfo, WclBleGattThread> gattClients = new Dictionary<BlePeripheralInfo, WclBleGattThread>();
internal WclBleMainThread()
{
}
private Thread wThread;
public bool Start()
{
//this.wThread = new Thread(new ThreadStart(this.SetUpWorkerThread));
//this.wThread.Start();
//Task.Run(() =>
//{
// this.SetUpWorkerThread();
//});
SetUpWorkerThread();
return true;
}
private void SetUpWorkerThread()
{
wclBleManager = new WclBleManager
{
ManagerStatusChanged = new WclBleManager.ManagerStatusChangedCallback(this.OnManagerStatusChanged)
};
var num = wclBleManager.Open();
if (num != 0)
{
Debug.LogWarning(string.Format("WCL BLE open failed: 0x{0:X8}", num));
}
wclWatcher = new WclBleWatcher
{
InfoPacketReceived = new WclBleWatcher.InfoPacketReceivedEvent(OnInfoPacketReceived),
UuidPacketReceived = new WclBleWatcher.UuidPacketReceivedEvent(OnUuidPacketReceived)
};
//Debug.Log("bbb");
}
private void OnManagerStatusChanged(WclBleManager manager, WclBleManagerStatus status)
{
//Debug.Log(status);
//WclBleMainThread.SafeInvoke(this.managerStatusChanged, this, status);
this.managerStatusChanged(this, status);
}
private void OnInfoPacketReceived(object sender, long address, long timestamp, sbyte rssi, string name, WclBleAdvertisementType packetType, byte flags)
{
this.scanInfoReceived(this, address, name, rssi, packetType, null);
}
// Token: 0x060020E7 RID: 8423 RVA: 0x000889ED File Offset: 0x00086BED
private void OnUuidPacketReceived(object sender, long address, long timestamp, sbyte rssi, Guid uuid)
{
this.scanInfoReceived(this, address, null, rssi, WclBleAdvertisementType.Unknown, new Guid?(uuid));
}
private static void SafeInvoke(WclBleMainThread.ManagerStatusChangedCallback callback, WclBleMainThread thread, WclBleManagerStatus status)
{
callback.Method.Invoke(callback.Target, new object[] {
thread,
status,
});
}
public void Dispose()
{
wclBleManager.Dispose();
}
public string Test()
{
return wclBleManager.Test();
}
public WclBleGattThread GetGattThread(BlePeripheralInfo info)
{
lock (locker)
{
if (this.gattClients.ContainsKey(info))
{
return this.gattClients[info];
}
return null;
}
}
public bool StartWatcher()
{
this.wclWatcher.StartScan(this.wclBleManager.Radio);
return true;
}
public WclBleGattThread CreateGattThread(BlePeripheralInfo info)
{
lock (locker)
{
if (gattClients.ContainsKey(info))
{
throw new ArgumentException("gatt thread 已经创建");
}
WclBleGattThread wclBleGattThread = new WclBleGattThread(info, this.wclBleManager.Radio);
this.gattClients[info] = wclBleGattThread;
return wclBleGattThread;
}
}
public event WclBleMainThread.WclAdvertisementPacketDelegate ScanInfoReceived
{
add
{
this.scanInfoReceived += value;
}
remove
{
this.scanInfoReceived -= value;
}
}
private WclBleMainThread.WclAdvertisementPacketDelegate scanInfoReceived;
public delegate void WclAdvertisementPacketDelegate(WclBleMainThread sender, long address, string name, int rssi, WclBleAdvertisementType packetType, Guid? service);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1a6d20f12634ae6478884e4f302c6622
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,195 @@
using Assets.Scripts.Ble.CPPBridge;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Assets.Scripts.Ble
{
internal class WclBleManager
{
// Token: 0x06002170 RID: 8560
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.SysInt)]
private static extern IntPtr WCLManagerCreate([MarshalAs(UnmanagedType.FunctionPtr)][In] WclBleManager.WCL_MANAGER_STATUS_CHANGED Initialize, [MarshalAs(UnmanagedType.FunctionPtr)][In] WclBleManager.WCL_MANAGER_STATUS_CHANGED StatusCHanges, [MarshalAs(UnmanagedType.FunctionPtr)][In] WCL_NOTIFY_EVENT beforeClose);
// Token: 0x06002171 RID: 8561
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
private static extern void WCLManagerDestroy([MarshalAs(UnmanagedType.SysInt)][In] IntPtr manager);
// Token: 0x06002172 RID: 8562
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I4)]
private static extern int WCLManagerOpen([MarshalAs(UnmanagedType.SysInt)][In] IntPtr manager);
// Token: 0x06002173 RID: 8563
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I4)]
private static extern int WCLManagerClose([MarshalAs(UnmanagedType.SysInt)][In] IntPtr manager);
// Token: 0x06002174 RID: 8564
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool WCLManagerGetActive([MarshalAs(UnmanagedType.SysInt)][In] IntPtr manager);
// Token: 0x06002175 RID: 8565
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.SysInt)]
private static extern IntPtr WCLManagerGetRadio([MarshalAs(UnmanagedType.SysInt)][In] IntPtr manager);
// Token: 0x06002176 RID: 8566 RVA: 0x0008B181 File Offset: 0x00089381
private void OnInitialized(IntPtr sender, WclBleManagerStatus status)
{
//if (WclBleManager.Info)
//{
// WclBleManager.log.Info(string.Format("WCLBleManger initialized with state {0}", status), Array.Empty<object>());
//}
this.BleStatus = status;
}
// Token: 0x06002177 RID: 8567 RVA: 0x0008B1B0 File Offset: 0x000893B0
private void OnBeforeClose(IntPtr sender)
{
//if (WclBleManager.Info)
//{
// WclBleManager.log.Info("Closing WCLBleManager -> BeforeClose called", Array.Empty<object>());
//}
}
// Token: 0x06002178 RID: 8568 RVA: 0x0008B1CD File Offset: 0x000893CD
private void OnStatusChanges(IntPtr sender, WclBleManagerStatus status)
{
//if (WclBleManager.Info)
//{
Debug.Log(string.Format("WCLBleManger state changed -> new state {0}", status));
//}
//System.IO.File.WriteAllText("d:/demo.log", status.ToString());
this.BleStatus = status;
}
// Token: 0x170005F4 RID: 1524
// (get) Token: 0x06002179 RID: 8569 RVA: 0x0008B1FC File Offset: 0x000893FC
public bool Active
{
get
{
return WclBleManager.WCLManagerGetActive(this.mPtr);
}
}
// Token: 0x170005F5 RID: 1525
// (get) Token: 0x0600217A RID: 8570 RVA: 0x0008B20F File Offset: 0x0008940F
public IntPtr Radio
{
get
{
return WclBleManager.WCLManagerGetRadio(this.mPtr);
}
}
// Token: 0x170005F6 RID: 1526
// (get) Token: 0x0600217B RID: 8571 RVA: 0x0008B222 File Offset: 0x00089422
// (set) Token: 0x0600217C RID: 8572 RVA: 0x0008B22A File Offset: 0x0008942A
public WclBleManagerStatus BleStatus
{
get
{
return this.nativeStatus;
}
private set
{
if (this.nativeStatus != value)
{
this.nativeStatus = value;
WclBleManager.SafeInvoke(this.ManagerStatusChanged, this, this.nativeStatus);
}
}
}
// Token: 0x170005F7 RID: 1527
// (get) Token: 0x0600217D RID: 8573 RVA: 0x0008B24E File Offset: 0x0008944E
//public WclBleWatcher BleWatcher { get; }
// Token: 0x0600217E RID: 8574 RVA: 0x0008B258 File Offset: 0x00089458
public WclBleManager()
{
this.CInitialized = new WclBleManager.WCL_MANAGER_STATUS_CHANGED(this.OnInitialized);
this.CStatusChanged = new WclBleManager.WCL_MANAGER_STATUS_CHANGED(this.OnStatusChanges);
this.CBeforeClose = new WCL_NOTIFY_EVENT(this.OnBeforeClose);
this.mPtr = WclBleManager.WCLManagerCreate(this.CInitialized, this.CStatusChanged, this.CBeforeClose);
}
// Token: 0x0600217F RID: 8575 RVA: 0x0008B2BE File Offset: 0x000894BE
public int Open()
{
return WclBleManager.WCLManagerOpen(this.mPtr);
}
// Token: 0x06002180 RID: 8576 RVA: 0x0008B2D1 File Offset: 0x000894D1
public int Close()
{
return WclBleManager.WCLManagerClose(this.mPtr);
}
// Token: 0x06002181 RID: 8577 RVA: 0x0008B2E4 File Offset: 0x000894E4
public void Dispose()
{
//if (WclBleManager.Debug)
//{
// WclBleManager.log.Debug("WclBleManger disposed", Array.Empty<object>());
//}
WclBleManager.WCLManagerDestroy(this.mPtr);
this.mPtr = IntPtr.Zero;
this.CInitialized = null;
this.CBeforeClose = null;
this.CStatusChanged = null;
}
public string Test()
{
return "";
}
// Token: 0x06002182 RID: 8578 RVA: 0x0008B337 File Offset: 0x00089537
private static void SafeInvoke(WclBleManager.ManagerStatusChangedCallback callback, WclBleManager manager, WclBleManagerStatus status)
{
//ExceptionUtils.SafeInvoke(callback, new object[]
//{
// manager,
// status
//}, WclBleManager.log);
callback(manager, status);
}
// Token: 0x04001390 RID: 5008
public WclBleManager.ManagerStatusChangedCallback ManagerStatusChanged;
// Token: 0x04001391 RID: 5009
private IntPtr mPtr;
// Token: 0x04001392 RID: 5010
private WclBleManager.WCL_MANAGER_STATUS_CHANGED CInitialized;
// Token: 0x04001393 RID: 5011
private WclBleManager.WCL_MANAGER_STATUS_CHANGED CStatusChanged;
// Token: 0x04001394 RID: 5012
private WCL_NOTIFY_EVENT CBeforeClose;
// Token: 0x04001395 RID: 5013
private WclBleManagerStatus nativeStatus;
// Token: 0x0200093C RID: 2364
// (Invoke) Token: 0x06004079 RID: 16505
internal delegate void ManagerStatusChangedCallback(WclBleManager manager, WclBleManagerStatus status);
// Token: 0x0200093D RID: 2365
// (Invoke) Token: 0x0600407D RID: 16509
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = false)]
internal delegate void WCL_MANAGER_STATUS_CHANGED([MarshalAs(UnmanagedType.SysInt)][In] IntPtr sender, WclBleManagerStatus status);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5c4b3ea90154c9e4b9cc0446bc75717b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Ble
{
internal enum WclBleManagerStatus
{
// Token: 0x04001339 RID: 4921
HardwareNotFound,
// Token: 0x0400133A RID: 4922
UnsupportedRadio,
// Token: 0x0400133B RID: 4923
RadioOff,
// Token: 0x0400133C RID: 4924
RadioOn,
// Token: 0x0400133D RID: 4925
Unknown
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9eb1abc2338676b4b8a7588b06c9f6cc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,201 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using Assets.Scripts.Ble.CPPBridge;
using UnityEngine;
namespace Assets.Scripts.Ble
{
internal class WclBleWatcher
{
internal WclBleWatcher()
{
this.CStarted = new WCL_NOTIFY_EVENT(this.OnStart);
this.CStopped = new WCL_NOTIFY_EVENT(this.OnStop);
this.CUuidPacketReceived = new WclBleWatcher.WCL_ADV_UUID_PKT_EVENT(this.OnUuidPacketReceived);
this.CInfoPackageReceived = new WclBleWatcher.WCL_ADV_INFO_PKT_EVENT(this.OnInfoPacketReceived);
this.mPtr = WclBleWatcher.WCLWatcherCreate(this.CInfoPackageReceived, this.CStarted, this.CStopped, this.CUuidPacketReceived);
}
// Token: 0x170005E5 RID: 1509
// (get) Token: 0x06002127 RID: 8487 RVA: 0x00089426 File Offset: 0x00087626
public bool Active
{
get
{
//base.CheckDisposed();
return WclBleWatcher.WCLWatcherGetActive(this.mPtr);
}
}
// Token: 0x0600212A RID: 8490
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.SysInt)]
private static extern IntPtr WCLWatcherCreate([MarshalAs(UnmanagedType.FunctionPtr)][In] WclBleWatcher.WCL_ADV_INFO_PKT_EVENT InfoPacketReceived, [MarshalAs(UnmanagedType.FunctionPtr)][In] WCL_NOTIFY_EVENT Started, [MarshalAs(UnmanagedType.FunctionPtr)][In] WCL_NOTIFY_EVENT Stopped, [MarshalAs(UnmanagedType.FunctionPtr)][In] WclBleWatcher.WCL_ADV_UUID_PKT_EVENT UidPacketReceived);
// Token: 0x0600212B RID: 8491
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
private static extern void WCLWatcherDestroy([MarshalAs(UnmanagedType.SysInt)][In] IntPtr Watcher);
// Token: 0x0600212C RID: 8492
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool WCLWatcherGetActive([MarshalAs(UnmanagedType.SysInt)][In] IntPtr Watcher);
// Token: 0x0600212D RID: 8493
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I4)]
private static extern int WCLWatcherStart([MarshalAs(UnmanagedType.SysInt)][In] IntPtr Watcher, [MarshalAs(UnmanagedType.SysInt)][In] IntPtr Radio);
// Token: 0x0600212E RID: 8494
[DllImport("WclBlePluginCPP.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I4)]
private static extern int WCLWatcherStop([MarshalAs(UnmanagedType.SysInt)][In] IntPtr Watcher);
// Token: 0x0600212F RID: 8495 RVA: 0x00089464 File Offset: 0x00087664
public void StartScan(IntPtr radio)
{
if (!this.Active)
{
int num = WclBleWatcher.WCLWatcherStart(this.mPtr, radio);
//if (WclBleWatcher.Info)
{
Debug.Log(string.Format("BLE watcher started with result {0}", num));
}
}
}
// Token: 0x06002130 RID: 8496 RVA: 0x000894B4 File Offset: 0x000876B4
public bool StopScan()
{
if (this.Active)
{
int num = WclBleWatcher.WCLWatcherStop(this.mPtr);
Debug.Log(string.Format("BLE watcher stopped with result {0}", num));
return num == 0;
}
return false;
}
// Token: 0x06002131 RID: 8497 RVA: 0x00089508 File Offset: 0x00087708
public void Dispose()
{
WclBleWatcher.WCLWatcherDestroy(this.mPtr);
this.mPtr = IntPtr.Zero;
this.CInfoPackageReceived = null;
this.CUuidPacketReceived = null;
this.CStarted = null;
this.CStopped = null;
Debug.Log("BLE watcher disposed");
}
// Token: 0x06002132 RID: 8498 RVA: 0x00089564 File Offset: 0x00087764
private void OnInfoPacketReceived(IntPtr sender, long address, long timestamp, sbyte rssi, string name, WclBleAdvertisementType packetType, byte flags)
{
//Debug.Log($"address:{ address }, name:{ name }, rssi:{ rssi }, type:{ packetType }");
//delegate
//{
// WclBleWatcher.SafeInvoke(this.InfoPacketReceived, this, address, timestamp, rssi, name, packetType, flags);
//}.OnUIThreadAsync();
this.InfoPacketReceived(this, address, timestamp, rssi, name, packetType, flags);
}
// Token: 0x06002133 RID: 8499 RVA: 0x000895BC File Offset: 0x000877BC
private void OnUuidPacketReceived(IntPtr sender, long address, long timestamp, sbyte rssi, Guid uuid)
{
//Debug.Log($"uuid:{ uuid.ToString() }, address:{ address }, rssi:{ rssi }");
//delegate
//{
// WclBleWatcher.SafeInvoke(this.UuidPacketReceived, this, address, timestamp, rssi, uuid);
//}.OnUIThreadAsync();
this.UuidPacketReceived(this, address, timestamp, rssi, uuid);
}
// Token: 0x06002134 RID: 8500 RVA: 0x000895F9 File Offset: 0x000877F9
private void OnStart(IntPtr Sender)
{
Debug.Log("watcher started");
}
// Token: 0x06002135 RID: 8501 RVA: 0x0008960F File Offset: 0x0008780F
private void OnStop(IntPtr Sender)
{
Debug.Log("Watcher closed");
}
// Token: 0x06002136 RID: 8502 RVA: 0x00089628 File Offset: 0x00087828
private static void SafeInvoke(WclBleWatcher.InfoPacketReceivedEvent callback, object sender, long address, long timestamp, sbyte rssi, string name, WclBleAdvertisementType packetType, byte flags)
{
//ExceptionUtils.SafeInvoke(callback, new object[]
//{
// sender,
// address,
// timestamp,
// rssi,
// name,
// packetType,
// flags
//}, WclBleWatcher.log);
}
// Token: 0x06002137 RID: 8503 RVA: 0x0008967F File Offset: 0x0008787F
private static void SafeInvoke(WclBleWatcher.UuidPacketReceivedEvent callback, object sender, long address, long timestamp, sbyte rssi, Guid uuid)
{
//ExceptionUtils.SafeInvoke(callback, new object[]
//{
// sender,
// address,
// timestamp,
// rssi,
// uuid
//}, WclBleWatcher.log);
}
// Token: 0x04001348 RID: 4936
public WclBleWatcher.InfoPacketReceivedEvent InfoPacketReceived;
// Token: 0x04001349 RID: 4937
public WclBleWatcher.UuidPacketReceivedEvent UuidPacketReceived;
// Token: 0x0400134B RID: 4939
private WclBleWatcher.WCL_ADV_INFO_PKT_EVENT CInfoPackageReceived;
// Token: 0x0400134C RID: 4940
private WCL_NOTIFY_EVENT CStarted;
// Token: 0x0400134D RID: 4941
private WCL_NOTIFY_EVENT CStopped;
// Token: 0x0400134E RID: 4942
private WclBleWatcher.WCL_ADV_UUID_PKT_EVENT CUuidPacketReceived;
// Token: 0x0400134F RID: 4943
private IntPtr mPtr;
// Token: 0x02000919 RID: 2329
// (Invoke) Token: 0x06003FB3 RID: 16307
public delegate void InfoPacketReceivedEvent(object Sender, long Address, long Timestamp, sbyte Rssi, string Name, WclBleAdvertisementType PacketType, byte Flags);
// Token: 0x0200091A RID: 2330
// (Invoke) Token: 0x06003FB7 RID: 16311
public delegate void UuidPacketReceivedEvent(object Sender, long Address, long Timestamp, sbyte Rssi, Guid Uuid);
// Token: 0x0200091B RID: 2331
// (Invoke) Token: 0x06003FBB RID: 16315
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = false)]
private delegate void WCL_ADV_INFO_PKT_EVENT([MarshalAs(UnmanagedType.SysInt)][In] IntPtr Sender, [MarshalAs(UnmanagedType.I8)][In] long Address, [MarshalAs(UnmanagedType.I8)][In] long Timestamp, [MarshalAs(UnmanagedType.I1)][In] sbyte Rssi, [MarshalAs(UnmanagedType.LPWStr)][In] string Name, [MarshalAs(UnmanagedType.U4)][In] WclBleAdvertisementType PacketType, [MarshalAs(UnmanagedType.U1)][In] byte Flags);
// Token: 0x0200091C RID: 2332
// (Invoke) Token: 0x06003FBF RID: 16319
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = false)]
private delegate void WCL_ADV_UUID_PKT_EVENT([MarshalAs(UnmanagedType.SysInt)][In] IntPtr Sender, [MarshalAs(UnmanagedType.I8)][In] long Address, [MarshalAs(UnmanagedType.I8)][In] long Timestamp, [MarshalAs(UnmanagedType.I1)][In] sbyte Rssi, [In] Guid Uuid);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4edd43fac4981e04b833e77483087f81
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: