|
|
@@ -8,6 +8,8 @@ using SmartBowSDK;
|
|
|
using System.Collections;
|
|
|
using UnityEngine.SceneManagement;
|
|
|
using BleWinHelper = SmartBowSDK_BleWinHelper.BleWinHelper;
|
|
|
+using SmartBowSDK.CMD;
|
|
|
+using System.Linq;
|
|
|
|
|
|
/* 蓝牙瞄准模块 */
|
|
|
/* 管理1p和2p蓝牙连接,脚本外调用逻辑如果同时连接1p和2p设备,以前的逻辑还是以1p为主,如果只连2p,则使用2p数据*/
|
|
|
@@ -100,6 +102,18 @@ public class BluetoothAim : MonoBehaviour
|
|
|
|
|
|
//首页初始化时候调用一次连接
|
|
|
public bool bStartConnect = false;
|
|
|
+ private void Awake()
|
|
|
+ {
|
|
|
+#if UNITY_ANDROID
|
|
|
+ if (CommonConfig.bUseCMD)
|
|
|
+ {
|
|
|
+ SmartBowLogger.isDebug = true;
|
|
|
+ this.isUseCompanionDeviceManager = true;
|
|
|
+ InitCMDManager();
|
|
|
+ }
|
|
|
+
|
|
|
+#endif
|
|
|
+ }
|
|
|
void Start()
|
|
|
{
|
|
|
ins = this;
|
|
|
@@ -120,7 +134,6 @@ public class BluetoothAim : MonoBehaviour
|
|
|
BleWinHelper.RegisterTo(gameObject, firstBluetoothWindows, "1P");
|
|
|
}
|
|
|
#endif
|
|
|
-
|
|
|
}
|
|
|
|
|
|
void OnDestroy()
|
|
|
@@ -128,6 +141,9 @@ public class BluetoothAim : MonoBehaviour
|
|
|
//删除ble。1p,2p 都删除
|
|
|
DisconnectBleHelper();
|
|
|
DisconnectSmartBowHelper2P();
|
|
|
+
|
|
|
+ if (CommonConfig.bUseCMD)
|
|
|
+ ClearCMDManager();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -201,6 +217,11 @@ public class BluetoothAim : MonoBehaviour
|
|
|
BowCamera.isTouchMode = true;
|
|
|
DestroyWhenDisconenct();
|
|
|
if (AimHandler.ins) AimHandler.ins.SetMsOldDefault();
|
|
|
+
|
|
|
+ if (isUseCompanionDeviceManager)
|
|
|
+ {
|
|
|
+ cmdManager.Disconnect();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
float notUserDoConnectTime = 0;
|
|
|
@@ -296,7 +317,14 @@ public class BluetoothAim : MonoBehaviour
|
|
|
//ConnectBleByUDP();
|
|
|
firstBluetoothWindows.Connect();
|
|
|
#else
|
|
|
- ConnectBleHelper();
|
|
|
+ if(isUseCompanionDeviceManager)
|
|
|
+ {
|
|
|
+ ConnectCMD();
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ ConnectBleHelper();
|
|
|
+ }
|
|
|
+
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
@@ -415,24 +443,25 @@ public class BluetoothAim : MonoBehaviour
|
|
|
}
|
|
|
foreach (BluetoothDevice device in nearbyDevices)
|
|
|
{
|
|
|
- Log("发现设备 " + device.DeviceName);
|
|
|
- if (AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.HOUYIPRO)
|
|
|
+ int firstPlayerType = AimHandler.ins.GetAimDeviceInfo(BluetoothPlayer.FIRST_PLAYER).type;
|
|
|
+ Log("发现设备:" + device.DeviceName + ",设备类型:"+ firstPlayerType);
|
|
|
+ if (firstPlayerType == (int)AimDeviceType.HOUYIPRO)
|
|
|
{ //需要判断是否是红外弓箭
|
|
|
if (TryConnectDevice(targetDeviceNameHOUYIPro, device.DeviceName, "HOUYIPRO")) return;
|
|
|
}
|
|
|
- else if (AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.ARTEMISPRO)
|
|
|
+ else if (firstPlayerType == (int)AimDeviceType.ARTEMISPRO)
|
|
|
{ //需要判断是否是ARTEMISPro弓箭
|
|
|
if (TryConnectDevice(targetDeviceNameARTEMISPro, device.DeviceName, "ARTEMISPRO")) return;
|
|
|
}
|
|
|
- else if (AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.Gun)
|
|
|
+ else if (firstPlayerType == (int)AimDeviceType.Gun)
|
|
|
{
|
|
|
if (TryConnectDevice(targetDeviceNameGun, device.DeviceName, "Pistol")) return;
|
|
|
}
|
|
|
- else if (AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.PistolM17)
|
|
|
+ else if (firstPlayerType == (int)AimDeviceType.PistolM17)
|
|
|
{
|
|
|
if (TryConnectDevice(targetDeviceNameGun_M17, device.DeviceName, "PistolM17")) return;
|
|
|
}
|
|
|
- else if (AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.RifleM416)
|
|
|
+ else if (firstPlayerType == (int)AimDeviceType.RifleM416)
|
|
|
{
|
|
|
if (TryConnectDevice(targetDeviceNameGun_M416, device.DeviceName, "RifleM416")) return;
|
|
|
}
|
|
|
@@ -819,6 +848,11 @@ public class BluetoothAim : MonoBehaviour
|
|
|
|
|
|
public void WriteData(string data)
|
|
|
{
|
|
|
+ if (isUseCompanionDeviceManager)
|
|
|
+ {
|
|
|
+ cmdManager.WriteString(data);
|
|
|
+ return;
|
|
|
+ }
|
|
|
//Debug.Log("WriteData:" + data);
|
|
|
#if UNITY_STANDALONE_WIN || UNITY_EDITOR
|
|
|
//BleUDP.ins.SendMsg(data);
|
|
|
@@ -829,9 +863,15 @@ public class BluetoothAim : MonoBehaviour
|
|
|
ch.setService(bluetoothService.getName());
|
|
|
bluetoothHelper.WriteCharacteristic(ch, data);
|
|
|
#endif
|
|
|
+
|
|
|
}
|
|
|
public void WriteByteData(byte[] data)
|
|
|
{
|
|
|
+ if (isUseCompanionDeviceManager)
|
|
|
+ {
|
|
|
+ cmdManager.WriteBytes(data);
|
|
|
+ return;
|
|
|
+ }
|
|
|
#if UNITY_STANDALONE_WIN || UNITY_EDITOR
|
|
|
firstBluetoothWindows.WriteByte(data);
|
|
|
#else
|
|
|
@@ -858,12 +898,13 @@ public class BluetoothAim : MonoBehaviour
|
|
|
{
|
|
|
SideTipView.ShowTip("Mac获取成功:" + mac, Color.white);
|
|
|
//需要增加一个判断,判断是否对应的mac设备。不是需要进行重新连接
|
|
|
- if (!AimHandler.ins.aimDeviceInfo.bInitMac)
|
|
|
+ AimDeviceInfo firstPlayer = AimHandler.ins.GetAimDeviceInfo(BluetoothPlayer.FIRST_PLAYER);
|
|
|
+ if (!firstPlayer.bInitMac)
|
|
|
{
|
|
|
Debug.Log("设置设备mac:" + mac);
|
|
|
AimHandler.ins.SetAimDeviceMac(mac);
|
|
|
}
|
|
|
- else if (AimHandler.ins.aimDeviceInfo.mac != mac)
|
|
|
+ else if (firstPlayer.mac != mac)
|
|
|
{
|
|
|
Debug.Log("设备不一样,断开连接");
|
|
|
DoConnect();
|
|
|
@@ -935,7 +976,19 @@ public class BluetoothAim : MonoBehaviour
|
|
|
{
|
|
|
|
|
|
smartBowHelper2P = SmartBowHelper.NewInstance();
|
|
|
- smartBowHelper2P.SetFilters(targetDeviceName2P);
|
|
|
+#if UNITY_ANDROID
|
|
|
+ if (CommonConfig.bUseCMD)
|
|
|
+ {
|
|
|
+ //使用CMD API连接,这个只支持Android
|
|
|
+ smartBowHelper2P.UseCompanionDeviceManager(true);
|
|
|
+ }
|
|
|
+#endif
|
|
|
+ if (isUseCompanionDeviceManager) {
|
|
|
+ smartBowHelper2P.SetFilters(ToRegex(targetDeviceName2P));
|
|
|
+ } else {
|
|
|
+ smartBowHelper2P.SetFilters(targetDeviceName2P);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
smartBowHelper2P.OnBluetoothModuleInited += () =>
|
|
|
{
|
|
|
@@ -943,12 +996,13 @@ public class BluetoothAim : MonoBehaviour
|
|
|
//判断是否是同一个mac
|
|
|
//需要增加一个判断,判断是否对应的mac设备。不是需要进行重新连接
|
|
|
string mac = smartBowHelper2P.GetMacAddress();
|
|
|
- if (!AimHandler.ins.aimDeviceInfo.bInitMac)
|
|
|
+ AimDeviceInfo secondPlayer = AimHandler.ins.GetAimDeviceInfo(BluetoothPlayer.SECOND_PLAYER);
|
|
|
+ if (!secondPlayer.bInitMac)
|
|
|
{
|
|
|
Debug.Log("smartBowHelper2P 设置设备mac:" + mac);
|
|
|
AimHandler.ins.SetAimDeviceMac(mac);
|
|
|
}
|
|
|
- else if (AimHandler.ins.aimDeviceInfo.mac != mac)
|
|
|
+ else if (secondPlayer.mac != mac)
|
|
|
{
|
|
|
Debug.Log("设备不一样,断开连接");
|
|
|
DoConnect2P();
|
|
|
@@ -971,6 +1025,14 @@ public class BluetoothAim : MonoBehaviour
|
|
|
|
|
|
//}
|
|
|
};
|
|
|
+ smartBowHelper2P.OnCMDState += (state, message) =>
|
|
|
+ {
|
|
|
+ userDoConnect2P = false;
|
|
|
+ doConnect2P = false;
|
|
|
+ canConnect2P = true;
|
|
|
+ DisconnectSmartBowHelper2P();
|
|
|
+ PopupMgr.ins.ShowTip(message);
|
|
|
+ };
|
|
|
smartBowHelper2P.OnBluetoothError += (error, message) =>
|
|
|
{
|
|
|
Debug.Log("smartBowHelper2P error:" + error);
|
|
|
@@ -1284,7 +1346,7 @@ public class BluetoothAim : MonoBehaviour
|
|
|
{
|
|
|
|
|
|
// status != BluetoothStatusEnum.ConnectSuccess
|
|
|
- Debug.LogWarning("onCancelAllConnecting 1:" + status);
|
|
|
+ //Debug.LogWarning("onCancelAllConnecting 1:" + status);
|
|
|
#if UNITY_STANDALONE_WIN || UNITY_EDITOR
|
|
|
|
|
|
//BleUDP.ins != null
|
|
|
@@ -1298,12 +1360,13 @@ public class BluetoothAim : MonoBehaviour
|
|
|
// BleUDP.ins.Disconnect();
|
|
|
firstBluetoothWindows.Disconnect();
|
|
|
SetStatus(_bluetoothStatus);
|
|
|
- Debug.LogWarning("onCancelAllConnecting 3:" + status);
|
|
|
+ //Debug.LogWarning("onCancelAllConnecting 3:" + status);
|
|
|
}
|
|
|
#else
|
|
|
- if (bluetoothHelper != null && status == BluetoothStatusEnum.Connecting)
|
|
|
+ //bluetoothHelper != null &&
|
|
|
+ if (status == BluetoothStatusEnum.Connecting)
|
|
|
{
|
|
|
- Debug.LogWarning("onCancelAllConnecting 2:" + status);
|
|
|
+ //Debug.LogWarning("onCancelAllConnecting 2:" + status);
|
|
|
userDoConnect = false;
|
|
|
doConnect = false;
|
|
|
OnDisconnect();
|
|
|
@@ -1520,7 +1583,6 @@ public class BluetoothAim : MonoBehaviour
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
#region 用户1 window ble 连接和部分共用代码
|
|
|
void OnConnected_windows1()
|
|
|
{
|
|
|
@@ -1683,4 +1745,257 @@ public class BluetoothAim : MonoBehaviour
|
|
|
PlayerPrefs.Save();
|
|
|
}
|
|
|
#endregion
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ #region 使用CompanionDeviceManager API 管理连接
|
|
|
+
|
|
|
+ public bool isUseCompanionDeviceManager { get; set; } = false;//默认用原本蓝牙扫描连接
|
|
|
+
|
|
|
+ private CMDManager cmdManager;
|
|
|
+ private bool isCMDScanning = false;
|
|
|
+ private string CmdName = "";
|
|
|
+ private string CmdMac = "";
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 初始化 CompanionDeviceManager 连接
|
|
|
+ /// </summary>
|
|
|
+ public void InitCMDManager()
|
|
|
+ {
|
|
|
+ if (cmdManager != null) return;
|
|
|
+
|
|
|
+ cmdManager = new CMDManager();
|
|
|
+ cmdManager.SetUUIDs(targetDeviceService, targetDeviceCharacteristicWrite, targetDeviceCharacteristicNotify);
|
|
|
+ cmdManager.OnCMDDeviceFound += OnCMDScanFound;
|
|
|
+ cmdManager.OnCMDScanFailed += OnCMDScanFailed;
|
|
|
+
|
|
|
+ cmdManager.OnCMDBLEConnected += OnCMDBLEConnected;
|
|
|
+ cmdManager.OnCMDBLEDisconnected += OnCMDBLEDisconnected;
|
|
|
+ cmdManager.OnCMDBLEReady += OnCMDBLEReady;
|
|
|
+ cmdManager.OnCMDBLENotify += OnCMDBLENotify;
|
|
|
+
|
|
|
+ cmdManager.OnPermissionDenied += OnCMDPermissionDenied;
|
|
|
+ cmdManager.OnPermissionDontAsk += OnCMDPermissionDontAsk;
|
|
|
+
|
|
|
+
|
|
|
+ SmartBowLogger.Log(this, "CMDManager 已初始化。");
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 清空 CompanionDeviceManager 信息
|
|
|
+ /// </summary>
|
|
|
+ public void ClearCMDManager()
|
|
|
+ {
|
|
|
+ if (cmdManager != null)
|
|
|
+ {
|
|
|
+ cmdManager.Cleanup(); // 调用 CMDManager 内部彻底清理方法
|
|
|
+
|
|
|
+ cmdManager.OnCMDDeviceFound -= OnCMDScanFound;
|
|
|
+ cmdManager.OnCMDScanFailed -= OnCMDScanFailed;
|
|
|
+
|
|
|
+ cmdManager.OnCMDBLEConnected -= OnCMDBLEConnected;
|
|
|
+ cmdManager.OnCMDBLEDisconnected -= OnCMDBLEDisconnected;
|
|
|
+ cmdManager.OnCMDBLEReady -= OnCMDBLEReady;
|
|
|
+ cmdManager.OnCMDBLENotify -= OnCMDBLENotify;
|
|
|
+
|
|
|
+ cmdManager.OnPermissionDenied -= OnCMDPermissionDenied;
|
|
|
+ cmdManager.OnPermissionDontAsk -= OnCMDPermissionDontAsk;
|
|
|
+ cmdManager = null;
|
|
|
+
|
|
|
+ SmartBowLogger.Log(this, "CMDManager 已清除。");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 使用CompanionDeviceManager连接,仅是 Android 平台
|
|
|
+ /// </summary>
|
|
|
+ public void ConnectCMD()
|
|
|
+ {
|
|
|
+
|
|
|
+ if (isCMDScanning) return;
|
|
|
+ PopupMgr.ins.ClearAllTip();
|
|
|
+ if (Application.platform == RuntimePlatform.Android)
|
|
|
+ {
|
|
|
+ if (!BluetoothHelperAndroid_SDK.IsBluetoothEnabled())
|
|
|
+ {
|
|
|
+ HandleConnectException(TextAutoLanguage2.GetTextByKey("ble-exception1"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ //_bluetoothHelper.ScanNearbyDevices();
|
|
|
+ //".*"
|
|
|
+ AimDeviceInfo firstPlayer = AimHandler.ins.GetAimDeviceInfo(BluetoothPlayer.FIRST_PLAYER);
|
|
|
+ if (firstPlayer.bInitMac)
|
|
|
+ {
|
|
|
+ SmartBowLogger.Log(this, $"CMD ConnectMac:{firstPlayer.mac}");
|
|
|
+ cmdManager.ConnectMac(FormatMacWithColon(firstPlayer.mac));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ string regex = ToRegex(targetDeviceNameAxis);
|
|
|
+ int firstPlayerType = firstPlayer.type;
|
|
|
+ Log("1P设备类型:" + firstPlayerType);
|
|
|
+ if (firstPlayerType == (int)AimDeviceType.HOUYIPRO)
|
|
|
+ { //需要判断是否是红外弓箭
|
|
|
+ ToRegex(targetDeviceNameHOUYIPro);
|
|
|
+ }
|
|
|
+ else if (firstPlayerType == (int)AimDeviceType.ARTEMISPRO)
|
|
|
+ { //需要判断是否是ARTEMISPro弓箭
|
|
|
+ ToRegex(targetDeviceNameARTEMISPro);
|
|
|
+ }
|
|
|
+ else if (firstPlayerType == (int)AimDeviceType.Gun)
|
|
|
+ {
|
|
|
+ ToRegex(targetDeviceNameGun);
|
|
|
+ }
|
|
|
+ else if (firstPlayerType == (int)AimDeviceType.PistolM17)
|
|
|
+ {
|
|
|
+ ToRegex(targetDeviceNameGun_M17);
|
|
|
+ }
|
|
|
+ else if (firstPlayerType == (int)AimDeviceType.RifleM416)
|
|
|
+ {
|
|
|
+ ToRegex(targetDeviceNameGun_M416);
|
|
|
+ }
|
|
|
+ SmartBowLogger.Log(this, $"CMD StartScan:{regex}");
|
|
|
+ cmdManager.StartScan(regex);
|
|
|
+ }
|
|
|
+ isCMDScanning = true;
|
|
|
+ SetStatus(BluetoothStatusEnum.Connecting);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ //HandleConnectError(BluetoothError.Unknown, e.ToString());
|
|
|
+ SetStatus(BluetoothStatusEnum.ConnectFail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 把 "A | B | C" 格式的设备名称转成正则 (A|B|C)
|
|
|
+ /// 自动去掉空格
|
|
|
+ /// </summary>
|
|
|
+ string ToRegex(string names)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(names))
|
|
|
+ return "";
|
|
|
+
|
|
|
+ var parts = names.Split('|');
|
|
|
+ for (int i = 0; i < parts.Length; i++)
|
|
|
+ parts[i] = parts[i].Trim(); // 去掉空格
|
|
|
+
|
|
|
+ return "(" + string.Join("|", parts) + ")";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * mac.Where(c => Uri.IsHexDigit(c))遍历 mac 字符串中的每一个字符 c。
|
|
|
+ * Uri.IsHexDigit(c) 会判断这个字符是否是 16 进制数字(0-9、A-F、a-f)。
|
|
|
+ * 所以这一步会 过滤掉所有非 16 进制的字符,比如 -、:、空格等。
|
|
|
+ * string.Concat(...)
|
|
|
+ * 将过滤后的字符重新拼接成一个新的字符串。
|
|
|
+ * .ToUpper()
|
|
|
+ * 将整个字符串转成大写。
|
|
|
+ */
|
|
|
+ string FormatMacWithColon(string mac)
|
|
|
+ {
|
|
|
+ var hex = string.Concat(mac.Where(c => Uri.IsHexDigit(c))).ToUpper();
|
|
|
+ return string.Join(":", Enumerable.Range(0, hex.Length / 2)
|
|
|
+ .Select(i => hex.Substring(i * 2, 2)));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void OnCMDScanFound(string name, string mac)
|
|
|
+ {
|
|
|
+ //MAC = D3:5C:89:57:68:DE
|
|
|
+ SmartBowLogger.Log(this, $"[SmartBow] CMD 扫描到设备 MAC = " + mac);
|
|
|
+ // 监听蓝牙准备就绪
|
|
|
+ CmdMac = mac;
|
|
|
+ CmdName = name;
|
|
|
+ //扫描之后也是这里直接连接
|
|
|
+ StartCoroutine(DelayConnect(FormatMacWithColon(CmdMac)));
|
|
|
+ }
|
|
|
+ private IEnumerator DelayConnect(string mac)
|
|
|
+ {
|
|
|
+ yield return new WaitForSeconds(0.3f);
|
|
|
+ cmdManager.ConnectMac(FormatMacWithColon(mac));
|
|
|
+ }
|
|
|
+ private void OnCMDScanFailed(CMDScanState state,string reason)
|
|
|
+ {
|
|
|
+ SmartBowLogger.Log(this, $"[SmartBow] CMD OnCMDScanFailed,"+ reason);
|
|
|
+ OnDisconnect();
|
|
|
+ isCMDScanning = false;
|
|
|
+ userDoConnect = false;
|
|
|
+ canConnect = true;
|
|
|
+ SetStatus(BluetoothStatusEnum.ConnectFail);
|
|
|
+
|
|
|
+ //if (_scanCanRetryCount > 0)
|
|
|
+ //{
|
|
|
+ // _scanCanRetryCount--;
|
|
|
+ // isCMDScanning = false;
|
|
|
+ //}
|
|
|
+ //else
|
|
|
+ //{
|
|
|
+ // userDoConnect = false;
|
|
|
+ // canConnect = true;
|
|
|
+ // SetStatus(BluetoothStatusEnum.ConnectFail);
|
|
|
+ //}
|
|
|
+ //smartBowHelper.InvokeOnBluetoothError(BluetoothError.CMDScanError, reason);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnCMDBLEDisconnected()
|
|
|
+ {
|
|
|
+ SmartBowLogger.Log(this, $"[SmartBow] CMD OnCMDBLEDisconnected.");
|
|
|
+ OnDisconnect();
|
|
|
+ isCMDScanning = false;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 连接上准备好
|
|
|
+ /// </summary>
|
|
|
+ private void OnCMDBLEConnected()
|
|
|
+ {
|
|
|
+ SmartBowLogger.Log(this, $"[SmartBow] CMD OnCMDBLEConnected.");
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 获取到特征值时候触发
|
|
|
+ /// </summary>
|
|
|
+ private void OnCMDBLEReady()
|
|
|
+ {
|
|
|
+ Log("连接成功\n" + CmdName);
|
|
|
+ isCMDScanning = false;
|
|
|
+ SetStatus(BluetoothStatusEnum.ConnectSuccess);
|
|
|
+ SetMainConnectDeviceType();
|
|
|
+ BowCamera.isTouchMode = false;
|
|
|
+ if (CommonConfig.EnableDecryption && NeedDecryption)
|
|
|
+ {
|
|
|
+ // 这里验证指令,开始请求授权
|
|
|
+ // 启动轮询协程
|
|
|
+ StartCoroutine(PollingCoroutine());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ SmartBowLogger.Log(this, $"InitWhenConenct:"+ status);
|
|
|
+ if (status != BluetoothStatusEnum.ConnectSuccess) return;
|
|
|
+ InitWhenConenct();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnCMDBLENotify(byte[] value)
|
|
|
+ {
|
|
|
+ //long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ //SmartBowLogger.Log(this,$"[CMDBleManager→Unity] NotifyArrived: {BitConverter.ToString(value)} | t={now} | size={value.Length}");
|
|
|
+ OnCharacteristicChanged(null, value, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void OnCMDPermissionDenied(string perm)
|
|
|
+ {
|
|
|
+ SmartBowLogger.LogError(this, $"[App] 用户拒绝权限:{perm}");
|
|
|
+
|
|
|
+ HandleConnectException(TextAutoLanguage2.GetTextByKey("CMDDenied"));
|
|
|
+ }
|
|
|
+ public void OnCMDPermissionDontAsk(string perm)
|
|
|
+ {
|
|
|
+ SmartBowLogger.LogError(this, $"[App] 用户永久拒绝权限:{perm}");
|
|
|
+ HandleConnectException(TextAutoLanguage2.GetTextByKey("CMDDontAsk"));
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
}
|