|
@@ -18,6 +18,8 @@ namespace SmartBowSDK
|
|
|
|
|
|
|
|
private int _receivedDataCount = 0;
|
|
private int _receivedDataCount = 0;
|
|
|
public string macAddress = null;
|
|
public string macAddress = null;
|
|
|
|
|
+ //设备固件版本
|
|
|
|
|
+ public string deviceVersion = null;
|
|
|
|
|
|
|
|
public BluetoothStatusEnum bluetoothStatus;
|
|
public BluetoothStatusEnum bluetoothStatus;
|
|
|
|
|
|
|
@@ -64,6 +66,7 @@ namespace SmartBowSDK
|
|
|
_characteristicWrite = null;
|
|
_characteristicWrite = null;
|
|
|
_receivedDataCount = 0;
|
|
_receivedDataCount = 0;
|
|
|
macAddress = null;
|
|
macAddress = null;
|
|
|
|
|
+ deviceVersion = null;
|
|
|
_battery = 0;
|
|
_battery = 0;
|
|
|
moduleInited = false;
|
|
moduleInited = false;
|
|
|
}
|
|
}
|
|
@@ -283,7 +286,11 @@ namespace SmartBowSDK
|
|
|
if (helper != _bluetoothHelper) return;
|
|
if (helper != _bluetoothHelper) return;
|
|
|
if (bluetoothStatus != BluetoothStatusEnum.Connected) return;
|
|
if (bluetoothStatus != BluetoothStatusEnum.Connected) return;
|
|
|
byte[] bytes = value;
|
|
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);
|
|
smartBowHelper.aimHandler.OnDataReceived(bytes);
|
|
|
}
|
|
}
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -439,7 +446,8 @@ namespace SmartBowSDK
|
|
|
string myConnectedHandlerID = Guid.NewGuid().ToString();
|
|
string myConnectedHandlerID = Guid.NewGuid().ToString();
|
|
|
_connectedHandlerID = myConnectedHandlerID;
|
|
_connectedHandlerID = myConnectedHandlerID;
|
|
|
yield return new WaitForSecondsRealtime(BluetoothWindows.IsWindows() ? 0.3f : 2.2f);
|
|
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)
|
|
while (cmds.Count > 0)
|
|
|
{
|
|
{
|
|
|
if (bluetoothStatus != BluetoothStatusEnum.Connected || myConnectedHandlerID != _connectedHandlerID) yield break;
|
|
if (bluetoothStatus != BluetoothStatusEnum.Connected || myConnectedHandlerID != _connectedHandlerID) yield break;
|
|
@@ -634,6 +642,47 @@ namespace SmartBowSDK
|
|
|
return true;
|
|
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 记录的设备处理部分
|
|
#region 记录的设备处理部分
|