|
|
@@ -53,6 +53,7 @@ public class BluetoothAim : MonoBehaviour
|
|
|
bool canConnect = true;
|
|
|
[SerializeField] Text textUI;
|
|
|
public BluetoothStatusEnum status = BluetoothStatusEnum.Connect;
|
|
|
+ int dataCount = 0;
|
|
|
public bool hasData = false;
|
|
|
public long hasDataTime;
|
|
|
public static bool scanLock = false; //防止同时扫描冲突
|
|
|
@@ -103,6 +104,7 @@ public class BluetoothAim : MonoBehaviour
|
|
|
void OnDisconnect()
|
|
|
{
|
|
|
curMac = null;
|
|
|
+ dataCount = 0;
|
|
|
hasData = false;
|
|
|
canConnect = true;
|
|
|
SetStatus(BluetoothStatusEnum.ConnectFail);
|
|
|
@@ -232,10 +234,13 @@ public class BluetoothAim : MonoBehaviour
|
|
|
if (status != BluetoothStatusEnum.ConnectSuccess) return;
|
|
|
// logger.Log(String.Join(",", value));
|
|
|
if (!hasData) {
|
|
|
+ hasData = true;
|
|
|
hasDataTime = JCUnityLib.TimeUtils.GetTimestamp();
|
|
|
+ }
|
|
|
+ dataCount++;
|
|
|
+ if (curMac == null && dataCount < 500) {
|
|
|
UploadMacAddress(value);
|
|
|
}
|
|
|
- hasData = true;
|
|
|
byte[] bytes = value;
|
|
|
// Log(String.Join(",", bytes));
|
|
|
BluetoothClient.UploadData(0, bytes);
|
|
|
@@ -573,6 +578,15 @@ public class BluetoothAim : MonoBehaviour
|
|
|
foreach (var c in mac.ToCharArray()) {
|
|
|
if (Array.IndexOf(validChars, c) == -1) return false;
|
|
|
}
|
|
|
+ if (mac.Length != 19) return false;
|
|
|
+ string macNoneFrame = mac.Substring(1, mac.Length - 2);
|
|
|
+ string[] macNoneFrameSplits = macNoneFrame.Split(':');
|
|
|
+ if (macNoneFrameSplits.Length != 6) return false;
|
|
|
+ foreach (var item in macNoneFrameSplits) {
|
|
|
+ if (item.Length != 2) return false;
|
|
|
+ foreach (var c in item.ToCharArray())
|
|
|
+ if (Array.IndexOf(validChars, c) < 3) return false;
|
|
|
+ }
|
|
|
return true;
|
|
|
}
|
|
|
}
|