Răsfoiți Sursa

1.新增获取固件版本数据
2.新增获取蓝牙设备设备接口,添加默认过滤设备名称
3.新增上膛等部分反馈接口

slambb 1 lună în urmă
părinte
comite
f98246dde2

+ 11 - 0
SmartBowSDK/AimHandler_SDK.cs

@@ -93,9 +93,20 @@ namespace SmartBowSDK
                 }
                 else if (bytes[0] == 0x5C)
                 {
+                    //弹夹变化
                     smartBowHelper.shootChecker.UpdateTheMagazine(bytes);
 
                 }
+                else if (bytes[0] == 0x60) {
+                    //枪械是否上膛
+                    smartBowHelper.shootChecker.UpdateChamberState(bytes);
+
+                }
+                else if (bytes[0] == 0x5E)
+                {
+                    //接收到系统数据
+                    smartBowHelper.shootChecker.UpdateDeviceAndSysInfo(bytes);
+                }
                 return;
             }
             m_axisHandler.Update(bytes);

+ 51 - 2
SmartBowSDK/BluetoothAim_SDK.cs

@@ -18,6 +18,8 @@ namespace SmartBowSDK
 
         private int _receivedDataCount = 0;
         public string macAddress = null;
+        //设备固件版本
+        public string deviceVersion = null;
 
         public BluetoothStatusEnum bluetoothStatus;
 
@@ -64,6 +66,7 @@ namespace SmartBowSDK
                 _characteristicWrite = null;
                 _receivedDataCount = 0;
                 macAddress = null;
+                deviceVersion = null;
                 _battery = 0;
                 moduleInited = false;
             }
@@ -283,7 +286,11 @@ namespace SmartBowSDK
             if (helper != _bluetoothHelper) return;
             if (bluetoothStatus != BluetoothStatusEnum.Connected) return;
             byte[] bytes = value;
-            if (macAddress == null && _receivedDataCount++ < 500) ParseMacAddress(value);
+            if (_receivedDataCount++ < 500) { //旧的逻辑
+                if (macAddress == null) ParseMacAddress(value);
+                //固件版本号
+                if (deviceVersion == null) ParseDeviceVersion(value);
+            }
             smartBowHelper.aimHandler.OnDataReceived(bytes);
         }
         /// <summary>
@@ -439,7 +446,8 @@ namespace SmartBowSDK
             string myConnectedHandlerID = Guid.NewGuid().ToString();
             _connectedHandlerID = myConnectedHandlerID;
             yield return new WaitForSecondsRealtime(BluetoothWindows.IsWindows() ? 0.3f : 2.2f);
-            Queue<string> cmds = new Queue<string>(new string[] { "M", "b", "b", "1" });
+            //获取Mac地址 获取设备固件版本号 获取设备信息(设备类型,系统类型) 获取初始电量 开启发送逻辑
+            Queue<string> cmds = new Queue<string>(new string[] { "M","V","I", "b", "b", "1"});
             while (cmds.Count > 0)
             {
                 if (bluetoothStatus != BluetoothStatusEnum.Connected || myConnectedHandlerID != _connectedHandlerID) yield break;
@@ -634,6 +642,47 @@ namespace SmartBowSDK
             return true;
         }
 
+        #region 校验固件版本信息
+        bool CheckIsVersionValid(string version)
+        {
+            if (string.IsNullOrEmpty(version)) return false;
+            if (!version.StartsWith("{")) return false;
+            if (!version.EndsWith("}")) return false;
+
+            // 去掉 { 和 }
+            string versionInner = version.Substring(1, version.Length - 2);
+
+            // 固件版本格式 Vx.y.z
+            if (!versionInner.StartsWith("V")) return false;
+
+            string[] parts = versionInner.Substring(1).Split('.');
+            if (parts.Length != 3) return false;
+
+            foreach (var part in parts)
+            {
+                if (!int.TryParse(part, out _)) return false;
+            }
+
+            return true;
+        }
+
+        void ParseDeviceVersion(byte[] bytes)
+        {
+            string version = System.Text.Encoding.ASCII.GetString(bytes);
+            if (version != null) version = version.Trim();
+
+            if (CheckIsVersionValid(version))
+            {
+                deviceVersion = version;
+                SmartBowLogger.Log(this, "DeviceVersion解析成功:" + version);
+            }
+            else
+            {
+                SmartBowLogger.LogWarning(this, "DeviceVersion解析失败");
+            }
+        }
+
+        #endregion
 
 
         #region 记录的设备处理部分

+ 2 - 2
SmartBowSDK/BluetoothDecryptor.cs

@@ -97,7 +97,7 @@ public class BluetoothDecryptor
         //Debug.Log("checksumStart: " + checksumStart + ",对应16进制=" + checksumStart.ToString("X"));
 
         // 打印原始加密数据
-        Debug.Log("Original Data: " + System.BitConverter.ToString(bytes));
+        // Debug.Log("Original Data: " + System.BitConverter.ToString(bytes));
         //Debug.Log("Original Encrypted Data: " + System.BitConverter.ToString(encryptedData));
         // 解密数据
         byte[] decryptedData = AUTHOR_ImprovedDecrypt(encryptedData, dataLength);
@@ -118,7 +118,7 @@ public class BluetoothDecryptor
         responseData[5] = checksum; // 累加和校验
         responseData[6] = 0x5D; // 结束码
         // 将应答数据转换为字符串
-        Debug.Log("Original Response Data: " + System.BitConverter.ToString(responseData));
+        //Debug.Log("Original Response Data: " + System.BitConverter.ToString(responseData));
        // string responseString = System.BitConverter.ToString(responseData).Replace("-", "");
         //Debug.Log("Response Data: " + responseString);
         return responseData;

+ 11 - 1
SmartBowSDK/BluetoothDeviceConfig.cs

@@ -13,7 +13,17 @@ namespace SmartBowSDK
         {
             BluetoothDeviceConfig config = new BluetoothDeviceConfig();
             //两个设备匹配
-            config.deviceName = "Bbow_20210501 | HOUYI Pro | Pistol | Pistol M9";
+            config.deviceName  = string.Join(" | ", new[] {
+                "Bbow_20210501",
+                "HOUYI Pro",
+                "Pistol",
+                "Pistol M9",
+                "Pistol M17",
+                "Rifle M416",
+                "ARTEMIS Pro",//游戏弓
+                "APOLLO", //KIT
+                "WDF-Baseball"//棒球
+            });
             if (Application.platform == RuntimePlatform.Android)
             {
                 config.service = "0000fff0";

+ 27 - 2
SmartBowSDK/BluetoothStatusEnum.cs

@@ -29,17 +29,42 @@
         /// <summary>
         /// 弹夹上膛
         /// </summary>
-        MagazineLoading
+        MagazineLoading,
 
-    }
+        /// <summary>
+        /// 枪械上膛状态
+        /// </summary>
+        Chambered,
+
+        /// <summary>
+        /// 枪械未上膛状态
+        /// </summary>
+        ChamberEmpty,
 
+    }
 
+    /// <summary>
+    /// 当前连接的蓝牙信息
+    /// </summary>
     public enum BluetoothDeviceType
     {
         NONE = -1,
         HOUYIPro = 0,
         ARTEMISPro = 1,
         Pistol1 = 2,
+        PistolM9 = 3,
+        APOLLO = 4,
+        PistolM17 = 5,
+        RifleM416 = 6
+    }
+    /// <summary>
+    /// 终端连接时候的系统类型
+    /// </summary>
+    public enum ConnectPlatform { 
+        NONE = 0,
+        PHONE = 1,
+        PC = 2,
+        VR = 3
     }
 
     /// <summary>

+ 80 - 5
SmartBowSDK/ShootChecker_SDK.cs

@@ -25,6 +25,11 @@ namespace SmartBowSDK
         /// </summary>
         private int _lastShootID = -1;
 
+        //记录当前的蓝牙设备信息
+        private BluetoothDeviceType bluetoothDeviceType = BluetoothDeviceType.NONE;
+        //记录连接的设备系统信息
+        private ConnectPlatform connectPlatform = ConnectPlatform.NONE;
+
         /// <summary>
         /// 当收到红外数据时
         /// </summary>
@@ -76,14 +81,84 @@ namespace SmartBowSDK
         /// <param name="bytes"></param>
         public void UpdateTheMagazine(byte[] bytes)
         {
-            Debug.Log("切换弹夹后:" + System.BitConverter.ToString(bytes));
-            if (bytes[1] == 0x00 )
+            SmartBowLogger.Log(this, "切换弹夹后:" + System.BitConverter.ToString(bytes));
+            BluetoothDeviceType temp = bluetoothDeviceType != BluetoothDeviceType.NONE ?
+                bluetoothDeviceType : BluetoothDeviceType.Pistol1;
+            if (bytes[1] == 0x00)
+            {
+                smartBowHelper.InvokeOnBleDevice(temp, BluetoothDeviceStatus.MagazineSeparation);
+            }
+            else if (bytes[1] == 0x01)
+            {
+                smartBowHelper.InvokeOnBleDevice(temp, BluetoothDeviceStatus.MagazineLoading);
+            }
+        }
+        /// <summary>
+        /// 0x00 未上膛,0x01 已上膛
+        /// </summary>
+        /// <param name="bytes"></param>
+        public void UpdateChamberState(byte[] bytes)
+        {
+            SmartBowLogger.Log(this, "操作上膛状态:" + System.BitConverter.ToString(bytes));
+            BluetoothDeviceType temp = bluetoothDeviceType != BluetoothDeviceType.NONE ?
+                bluetoothDeviceType : BluetoothDeviceType.Pistol1;
+            if (bytes[1] == 0x00)
+            {
+                smartBowHelper.InvokeOnBleDevice(temp, BluetoothDeviceStatus.ChamberEmpty);
+            }
+            else if (bytes[1] == 0x01)
+            {
+                smartBowHelper.InvokeOnBleDevice(temp, BluetoothDeviceStatus.Chambered);
+            }
+        }
+        /// <summary>
+        /// 记录当前获得的设备连接数据
+        /// </summary>
+        /// <param name="bytes"></param>
+        public void UpdateDeviceAndSysInfo(byte[] bytes)
+        {
+            //Debug.Log("接收到系统数据:" + System.BitConverter.ToString(bytes));
+            //设备类型
+            switch (bytes[1])
             {
-                smartBowHelper.InvokeOnBleDevice(BluetoothDeviceType.Pistol1, BluetoothDeviceStatus.MagazineSeparation);
+                case 0x01:
+                    bluetoothDeviceType = BluetoothDeviceType.HOUYIPro;
+                    break;
+                case 0x02:
+                    bluetoothDeviceType = BluetoothDeviceType.ARTEMISPro;
+                    break;
+                case 0x03:
+                    bluetoothDeviceType = BluetoothDeviceType.PistolM9;
+                    break;
+                case 0x04:
+                    bluetoothDeviceType = BluetoothDeviceType.APOLLO;
+                    break;
+                case 0x05:
+                    bluetoothDeviceType = BluetoothDeviceType.PistolM17;
+                    break;
+                case 0x06:
+                    bluetoothDeviceType = BluetoothDeviceType.RifleM416;
+                    break;
             }
-            else if(bytes[1] == 0x01) {
-                smartBowHelper.InvokeOnBleDevice(BluetoothDeviceType.Pistol1, BluetoothDeviceStatus.MagazineLoading);
+
+            // 系统类型
+            switch (bytes[2])
+            {
+                case 0x01:
+                    connectPlatform = ConnectPlatform.PHONE;
+                    break;
+                case 0x02:
+                    connectPlatform = ConnectPlatform.PC;
+                    break;
+                case 0x03:
+                    connectPlatform = ConnectPlatform.VR;
+                    break;
             }
+            SmartBowLogger.Log(this, "设备类型:" + bluetoothDeviceType.ToString());
+            SmartBowLogger.Log(this, "系统类型:" + connectPlatform.ToString());
+
+            //初始化时候回调数据
+            smartBowHelper.InvokeOnDeviceAndSystemInfoEvent(connectPlatform, bluetoothDeviceType);
         }
     }
 }

+ 28 - 2
SmartBowSDK/SmartBowHelper.cs

@@ -418,7 +418,15 @@ namespace SmartBowSDK
         {
             return bluetoothAim.macAddress;
         }
-
+        /// <summary>
+        /// 获取硬件固件版本
+        /// Tip:需要模块初始化完成才能获取
+        /// </summary>
+        /// <returns>如果返回null则是获取失败</returns>
+        public string GetDeviceVersion()
+        {
+            return bluetoothAim.deviceVersion;
+        }
         /// <summary>
         /// 获取电量
         /// Tip:需要模块初始化完成才能获取
@@ -687,7 +695,25 @@ namespace SmartBowSDK
                 Debug.LogError(e);
             }
         }
-
+        /// <summary>
+        /// 监听设备状态和连接的设备平台信息
+        /// </summary>
+        public DeviceAndSystemInfoEvent OnDeviceAndSystemInfoEvent;
+        /// <summary>
+        /// 硬件对应的事件初始化回调
+        /// </summary>
+        public delegate void DeviceAndSystemInfoEvent(ConnectPlatform connectPlatform,BluetoothDeviceType bleDeviceType);
+        internal void InvokeOnDeviceAndSystemInfoEvent(ConnectPlatform connectPlatform, BluetoothDeviceType bleDeviceType)
+        {
+            try
+            {
+                OnDeviceAndSystemInfoEvent?.Invoke(connectPlatform, bleDeviceType);
+            }
+            catch (Exception e)
+            {
+                Debug.LogError(e);
+            }
+        }
         #region 6轴部分接口
         /// <summary>
         /// 6轴数据重置初始位置数据