|
|
@@ -7,6 +7,7 @@ using DG.Tweening;
|
|
|
/* 蓝牙瞄准模块 */
|
|
|
public class BluetoothAim : MonoBehaviour
|
|
|
{
|
|
|
+ SBLogger logger = new SBLogger(typeof(BluetoothAim).Name);
|
|
|
readonly string targetDeviceName = "Bbow_20210501";
|
|
|
|
|
|
string targetDeviceService {
|
|
|
@@ -161,25 +162,29 @@ public class BluetoothAim : MonoBehaviour
|
|
|
Log("连接成功\n" + helper.getDeviceName());
|
|
|
SetStatus(BluetoothStatusEnum.ConnectSuccess);
|
|
|
BowCamera.isTouchMode = false;
|
|
|
+ logger.Log("连接成功");
|
|
|
foreach (BluetoothHelperService service in helper.getGattServices())
|
|
|
{
|
|
|
-
|
|
|
+ logger.Log("待检测的服务名:" + service.getName());
|
|
|
if (service.getName().ToLower().StartsWith(targetDeviceService))
|
|
|
{
|
|
|
bluetoothService = service;
|
|
|
-
|
|
|
+ logger.Warn("匹配的服务名:" + service.getName());
|
|
|
foreach (BluetoothHelperCharacteristic characteristic in service.getCharacteristics())
|
|
|
{
|
|
|
+ logger.Log("待检测的特征:" + characteristic.getName());
|
|
|
if (characteristic.getName().ToLower().StartsWith(targetDeviceCharacteristicWrite))
|
|
|
{
|
|
|
characteristicWrite = characteristic;
|
|
|
+ logger.Warn("匹配的写入特征:" + characteristic.getName());
|
|
|
}
|
|
|
else if (characteristic.getName().ToLower().StartsWith(targetDeviceCharacteristicNotify))
|
|
|
{
|
|
|
-
|
|
|
+ logger.Warn("匹配的订阅特征(准备):" + characteristic.getName());
|
|
|
BluetoothHelperCharacteristic ch = new BluetoothHelperCharacteristic(characteristic.getName());
|
|
|
ch.setService(bluetoothService.getName());
|
|
|
bluetoothHelper.Subscribe(ch);
|
|
|
+ logger.Warn("匹配的订阅特征(完成):" + characteristic.getName());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -200,6 +205,7 @@ public class BluetoothAim : MonoBehaviour
|
|
|
};
|
|
|
bluetoothHelper.OnCharacteristicChanged += (helper, value, characteristic) =>
|
|
|
{
|
|
|
+ logger.Log(String.Join(",", value));
|
|
|
if (!hasData) {
|
|
|
hasDataTime = JC.CS.Utility.GetTimestamp();
|
|
|
UploadMacAddress(value);
|
|
|
@@ -499,6 +505,7 @@ public class BluetoothAim : MonoBehaviour
|
|
|
|
|
|
public void WriteData(string data)
|
|
|
{
|
|
|
+ logger.Log("发送CMD(准备):" + data);
|
|
|
#if UNITY_STANDALONE_WIN || UNITY_EDITOR
|
|
|
BleUDP.ins.SendMsg(data);
|
|
|
#else
|
|
|
@@ -507,6 +514,7 @@ public class BluetoothAim : MonoBehaviour
|
|
|
ch.setService(bluetoothService.getName());
|
|
|
bluetoothHelper.WriteCharacteristic(ch, data);
|
|
|
#endif
|
|
|
+ logger.Log("发送CMD(完成):" + data);
|
|
|
}
|
|
|
|
|
|
void Log(string text)
|