Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Assets/CoreBluetooth/Samples/12_Debug/SampleDebug_Central.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ public void DidReadRSSI(CBPeripheral peripheral, int rssi, CBError error)
}
}

public void DidUpdateName(CBPeripheral peripheral)
{
Debug.Log($"[DidUpdateName] {peripheral}");
}

public void OnClickWrite()
{
if (_peripheral == null)
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void DidWriteValueForCharacteristic(CBPeripheral peripheral, CBCharacteristic ch
void IsReadyToSendWriteWithoutResponse(CBPeripheral peripheral) { }
void DidUpdateNotificationStateForCharacteristic(CBPeripheral peripheral, CBCharacteristic characteristic, CBError error) { }
void DidReadRSSI(CBPeripheral peripheral, int rssi, CBError error) { }
void DidUpdateName(CBPeripheral peripheral) { }
}

/// <summary>
Expand Down Expand Up @@ -247,6 +248,12 @@ void INativePeripheralDelegate.DidReadRSSI(int rssi, CBError error)
Delegate?.DidReadRSSI(this, rssi, error);
}

void INativePeripheralDelegate.DidUpdateName()
{
if (_disposed) return;
Delegate?.DidUpdateName(this);
}

public override string ToString()
{
return $"CBPeripheral: identifier = {Identifier}, name = {Name}, state = {State}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ int serviceUUIDsCount
internal delegate void CB4UPeripheralIsReadyToSendWriteWithoutResponseHandler(IntPtr peripheralPtr);
internal delegate void CB4UPeripheralDidUpdateNotificationStateForCharacteristicHandler(IntPtr peripheralPtr, IntPtr serviceUUIDPtr, IntPtr characteristicUUIDPtr, int notificationState, int errorCode);
internal delegate void CB4UPeripheralDidReadRSSIHandler(IntPtr peripheralPtr, int rssi, int errorCode);
internal delegate void CB4UPeripheralDidUpdateNameHandler(IntPtr peripheralPtr);

[DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
internal static extern void cb4u_peripheral_register_handlers(
Expand All @@ -87,7 +88,8 @@ internal static extern void cb4u_peripheral_register_handlers(
CB4UPeripheralDidWriteValueForCharacteristicHandler didWriteValueForCharacteristicHandler,
CB4UPeripheralIsReadyToSendWriteWithoutResponseHandler isReadyToSendWriteWithoutResponseHandler,
CB4UPeripheralDidUpdateNotificationStateForCharacteristicHandler didUpdateNotificationStateForCharacteristicHandler,
CB4UPeripheralDidReadRSSIHandler didReadRSSIHandler
CB4UPeripheralDidReadRSSIHandler didReadRSSIHandler,
CB4UPeripheralDidUpdateNameHandler didUpdateNameHandler
);

[DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ void DidWriteValueForCharacteristic(string serviceUUID, string characteristicUUI
void IsReadyToSendWriteWithoutResponse() { }
void DidUpdateNotificationStateForCharacteristic(string serviceUUID, string characteristicUUID, bool enabled, CBError error) { }
void DidReadRSSI(int rssi, CBError error) { }
void DidUpdateName() { }
}

internal class SafeNativePeripheralHandle : SafeHandle
Expand All @@ -36,7 +37,8 @@ void RegisterHandlers()
DidWriteValueForCharacteristic,
IsReadyToSendWriteWithoutResponse,
DidUpdateNotificationStateForCharacteristic,
DidReadRSSI
DidReadRSSI,
DidUpdateName
);
}

Expand Down Expand Up @@ -141,5 +143,11 @@ internal static void DidReadRSSI(IntPtr peripheralPtr, int rssi, int errorCode)
CBError.CreateOrNullFromCode(errorCode)
);
}

[AOT.MonoPInvokeCallback(typeof(NativeMethods.CB4UPeripheralDidUpdateNameHandler))]
internal static void DidUpdateName(IntPtr peripheralPtr)
{
GetDelegate(peripheralPtr)?.DidUpdateName();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class CB4UPeripheral : NSObject {
public var isReadyToSendWriteWithoutResponseHandler: CB4UPeripheralIsReadyToSendWriteWithoutResponseHandler?
public var didUpdateNotificationStateForCharacteristicHandler: CB4UPeripheralDidUpdateNotificationStateForCharacteristicHandler?
public var didReadRSSIHandler: CB4UPeripheralDidReadRSSIHandler?
public var didUpdateNameHandler: CB4UPeripheralDidUpdateNameHandler?

let success: Int32 = 0
let serviceNotFound: Int32 = -2
Expand Down Expand Up @@ -173,4 +174,8 @@ extension CB4UPeripheral : CBPeripheralDelegate {
public func peripheral(_ peripheral: CBPeripheral, didReadRSSI RSSI: NSNumber, error: Error?) {
didReadRSSIHandler?(selfPointer(), Int32(RSSI.intValue), errorToCode(error))
}

public func peripheralDidUpdateName(_ peripheral: CBPeripheral) {
didUpdateNameHandler?(selfPointer())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public typealias CB4UPeripheralDidWriteValueForCharacteristicHandler = @conventi
public typealias CB4UPeripheralIsReadyToSendWriteWithoutResponseHandler = @convention(c) (UnsafeRawPointer) -> Void
public typealias CB4UPeripheralDidUpdateNotificationStateForCharacteristicHandler = @convention(c) (UnsafeRawPointer, UnsafePointer<CChar>, UnsafePointer<CChar>, Int32, Int32) -> Void
public typealias CB4UPeripheralDidReadRSSIHandler = @convention(c) (UnsafeRawPointer, Int32, Int32) -> Void
public typealias CB4UPeripheralDidUpdateNameHandler = @convention(c) (UnsafeRawPointer) -> Void

@_cdecl("cb4u_peripheral_register_handlers")
public func cb4u_peripheral_register_handlers(
Expand All @@ -129,7 +130,8 @@ public func cb4u_peripheral_register_handlers(
_ didWriteValueForCharacteristicHandler: @escaping CB4UPeripheralDidWriteValueForCharacteristicHandler,
_ isReadyToSendWriteWithoutResponseHandler: @escaping CB4UPeripheralIsReadyToSendWriteWithoutResponseHandler,
_ didUpdateNotificationStateForCharacteristicHandler: @escaping CB4UPeripheralDidUpdateNotificationStateForCharacteristicHandler,
_ didReadRSSIHandler: @escaping CB4UPeripheralDidReadRSSIHandler
_ didReadRSSIHandler: @escaping CB4UPeripheralDidReadRSSIHandler,
_ didUpdateNameHandler: @escaping CB4UPeripheralDidUpdateNameHandler
) {
let instance = Unmanaged<CB4UPeripheral>.fromOpaque(peripheralPtr).takeUnretainedValue()

Expand All @@ -140,6 +142,7 @@ public func cb4u_peripheral_register_handlers(
instance.isReadyToSendWriteWithoutResponseHandler = isReadyToSendWriteWithoutResponseHandler
instance.didUpdateNotificationStateForCharacteristicHandler = didUpdateNotificationStateForCharacteristicHandler
instance.didReadRSSIHandler = didReadRSSIHandler
instance.didUpdateNameHandler = didUpdateNameHandler
}

@_cdecl("cb4u_peripheral_identifier")
Expand Down