ios蓝牙适配
This commit is contained in:
1 parent
d8927ceca5
commit
99540eb1fd
6 files changed
+84
-41
No files matched your search
@@ -245,12 +245,12 @@ public class BluetoothDeviceScript : MonoBehaviour
|
||||
else if (message.Length >= deviceDiscoveredService.Length && message.Substring (0, deviceDiscoveredService.Length) == deviceDiscoveredService)
|
||||
{
|
||||
if (parts.Length >= 3 && DiscoveredServiceAction != null)
|
||||
DiscoveredServiceAction (parts[1], parts[2]);
|
||||
DiscoveredServiceAction (parts[1], FullUUID(parts[2]));
|
||||
}
|
||||
else if (message.Length >= deviceDiscoveredCharacteristic.Length && message.Substring (0, deviceDiscoveredCharacteristic.Length) == deviceDiscoveredCharacteristic)
|
||||
{
|
||||
if (parts.Length >= 4 && DiscoveredCharacteristicAction != null)
|
||||
DiscoveredCharacteristicAction (parts[1], parts[2], parts[3]);
|
||||
DiscoveredCharacteristicAction (parts[1], FullUUID(parts[2]), FullUUID(parts[3]));
|
||||
}
|
||||
else if (message.Length >= deviceDidWriteCharacteristic.Length && message.Substring (0, deviceDidWriteCharacteristic.Length) == deviceDidWriteCharacteristic)
|
||||
{
|
||||
@@ -264,11 +264,11 @@ public class BluetoothDeviceScript : MonoBehaviour
|
||||
if (DidUpdateNotificationStateForCharacteristicAction != null && DidUpdateNotificationStateForCharacteristicAction.ContainsKey (parts[1]))
|
||||
{
|
||||
var characteristicAction = DidUpdateNotificationStateForCharacteristicAction[parts[1]];
|
||||
if (characteristicAction != null && characteristicAction.ContainsKey (parts[2]))
|
||||
if (characteristicAction != null && characteristicAction.ContainsKey (FullUUID(parts[2])))
|
||||
{
|
||||
var action = characteristicAction[parts[2]];
|
||||
var action = characteristicAction[FullUUID(parts[2])];
|
||||
if (action != null)
|
||||
action (parts[2]);
|
||||
action (FullUUID(parts[2]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,9 +277,9 @@ public class BluetoothDeviceScript : MonoBehaviour
|
||||
var characteristicAction = DidUpdateNotificationStateForCharacteristicWithDeviceAddressAction[parts[1]];
|
||||
if (characteristicAction != null && characteristicAction.ContainsKey (parts[2]))
|
||||
{
|
||||
var action = characteristicAction[parts[2]];
|
||||
var action = characteristicAction[FullUUID(parts[2])];
|
||||
if (action != null)
|
||||
action (parts[1], parts[2]);
|
||||
action (parts[1], FullUUID(parts[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -287,7 +287,7 @@ public class BluetoothDeviceScript : MonoBehaviour
|
||||
else if (message.Length >= deviceDidUpdateValueForCharacteristic.Length && message.Substring (0, deviceDidUpdateValueForCharacteristic.Length) == deviceDidUpdateValueForCharacteristic)
|
||||
{
|
||||
if (parts.Length >= 4)
|
||||
OnBluetoothData (parts[1], parts[2], parts[3]);
|
||||
OnBluetoothData (parts[1], FullUUID(parts[2]), parts[3]);
|
||||
}
|
||||
else if (message.Length >= deviceRequestMtu.Length && message.Substring(0, deviceRequestMtu.Length) == deviceRequestMtu)
|
||||
{
|
||||
@@ -303,6 +303,12 @@ public class BluetoothDeviceScript : MonoBehaviour
|
||||
}
|
||||
}
|
||||
}
|
||||
public static string FullUUID(string uuid)
|
||||
{
|
||||
if (uuid.Length == 4)
|
||||
return "0000" + uuid + "-0000-1000-8000-00805F9B34FB";
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void OnBluetoothData (string base64Data)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user