From df1c11d5eed0e16199848939450850801046bc02 Mon Sep 17 00:00:00 2001 From: Florian Loitsch Date: Tue, 26 Nov 2024 10:10:11 +0100 Subject: [PATCH] Cleanups in the BLE library. (#2644) Better names... --- examples/ble/advertise.toit | 4 +- examples/ble/connect.toit | 8 +- examples/ble/scan.toit | 6 +- ...ovision__examples__ble-provision.toit.gold | 3 + .../toit-provision__src__provision.toit.gold | 3 + .../toit-provision__src__src___ble.toit.gold | 3 + ...oit-provision__src__src___config.toit.gold | 3 + .../toit-provision__src__src___rpc.toit.gold | 3 + .../toit-provision__src__src___scan.toit.gold | 3 + ...t-provision__src__src___security.toit.gold | 3 + ...it-provision__src__src___session.toit.gold | 3 + ...it-provision__src__src___version.toit.gold | 3 + lib/ble/ble.toit | 113 +++++++++--------- lib/ble/local.toit | 8 +- lib/ble/remote.toit | 111 ++++++++++++++--- tests/ble-advertisement-test.toit | 31 +++-- .../sdk/examples__ble__advertise.toit.gold | 6 + .../gold/sdk/examples__ble__connect.toit.gold | 6 + .../sdk/examples__ble__heart_rate.toit.gold | 9 ++ .../gold/sdk/examples__ble__scan.toit.gold | 6 + tests/health/gold/sdk/lib__ble__ble.toit.gold | 6 + .../health/gold/sdk/lib__ble__local.toit.gold | 6 + .../gold/sdk/lib__ble__remote.toit.gold | 6 + .../tests__ble-advertisement-test.toit.gold | 9 +- .../sdk/tests__hw__esp32__ble-util.toit.gold | 6 + .../tests__hw__esp32__ble1-board1.toit.gold | 6 + .../tests__hw__esp32__ble1-board2.toit.gold | 6 + .../tests__hw__esp32__ble1-shared.toit.gold | 6 + .../tests__hw__esp32__ble2-board1.toit.gold | 6 + .../tests__hw__esp32__ble2-board2.toit.gold | 6 + .../tests__hw__esp32__ble2-shared.toit.gold | 6 + .../tests__hw__esp32__ble3-board1.toit.gold | 6 + .../tests__hw__esp32__ble3-board2.toit.gold | 6 + .../tests__hw__esp32__ble3-shared.toit.gold | 6 + .../tests__hw__esp32__ble4-board1.toit.gold | 6 + .../tests__hw__esp32__ble4-board2.toit.gold | 6 + .../tests__hw__esp32__ble4-shared.toit.gold | 6 + .../tests__hw__esp32__ble5-board1.toit.gold | 6 + .../tests__hw__esp32__ble5-board2.toit.gold | 6 + .../tests__hw__esp32__ble5-shared.toit.gold | 6 + ...hw__esp32__ble6-advertise-board1.toit.gold | 6 + ...hw__esp32__ble6-advertise-board2.toit.gold | 6 + ...hw__esp32__ble6-advertise-shared.toit.gold | 6 + tests/hw/esp32/ble-util.toit | 2 +- tests/hw/esp32/ble1-shared.toit | 2 +- tests/hw/esp32/ble2-shared.toit | 2 +- tests/hw/esp32/ble3-shared.toit | 2 +- tests/hw/esp32/ble4-shared.toit | 2 +- tests/hw/esp32/ble5-shared.toit | 2 +- tests/hw/esp32/ble6-advertise-shared.toit | 49 ++++---- 50 files changed, 400 insertions(+), 137 deletions(-) create mode 100644 external/gold/toit-provision__examples__ble-provision.toit.gold create mode 100644 external/gold/toit-provision__src__provision.toit.gold create mode 100644 external/gold/toit-provision__src__src___ble.toit.gold create mode 100644 external/gold/toit-provision__src__src___config.toit.gold create mode 100644 external/gold/toit-provision__src__src___rpc.toit.gold create mode 100644 external/gold/toit-provision__src__src___scan.toit.gold create mode 100644 external/gold/toit-provision__src__src___security.toit.gold create mode 100644 external/gold/toit-provision__src__src___session.toit.gold create mode 100644 external/gold/toit-provision__src__src___version.toit.gold create mode 100644 tests/health/gold/sdk/examples__ble__advertise.toit.gold create mode 100644 tests/health/gold/sdk/examples__ble__connect.toit.gold create mode 100644 tests/health/gold/sdk/examples__ble__heart_rate.toit.gold create mode 100644 tests/health/gold/sdk/examples__ble__scan.toit.gold create mode 100644 tests/health/gold/sdk/lib__ble__ble.toit.gold create mode 100644 tests/health/gold/sdk/lib__ble__local.toit.gold create mode 100644 tests/health/gold/sdk/lib__ble__remote.toit.gold create mode 100644 tests/health/gold/sdk/tests__hw__esp32__ble-util.toit.gold create mode 100644 tests/health/gold/sdk/tests__hw__esp32__ble1-board1.toit.gold create mode 100644 tests/health/gold/sdk/tests__hw__esp32__ble1-board2.toit.gold create mode 100644 tests/health/gold/sdk/tests__hw__esp32__ble1-shared.toit.gold create mode 100644 tests/health/gold/sdk/tests__hw__esp32__ble2-board1.toit.gold create mode 100644 tests/health/gold/sdk/tests__hw__esp32__ble2-board2.toit.gold create mode 100644 tests/health/gold/sdk/tests__hw__esp32__ble2-shared.toit.gold create mode 100644 tests/health/gold/sdk/tests__hw__esp32__ble3-board1.toit.gold create mode 100644 tests/health/gold/sdk/tests__hw__esp32__ble3-board2.toit.gold create mode 100644 tests/health/gold/sdk/tests__hw__esp32__ble3-shared.toit.gold create mode 100644 tests/health/gold/sdk/tests__hw__esp32__ble4-board1.toit.gold create mode 100644 tests/health/gold/sdk/tests__hw__esp32__ble4-board2.toit.gold create mode 100644 tests/health/gold/sdk/tests__hw__esp32__ble4-shared.toit.gold create mode 100644 tests/health/gold/sdk/tests__hw__esp32__ble5-board1.toit.gold create mode 100644 tests/health/gold/sdk/tests__hw__esp32__ble5-board2.toit.gold create mode 100644 tests/health/gold/sdk/tests__hw__esp32__ble5-shared.toit.gold create mode 100644 tests/health/gold/sdk/tests__hw__esp32__ble6-advertise-board1.toit.gold create mode 100644 tests/health/gold/sdk/tests__hw__esp32__ble6-advertise-board2.toit.gold create mode 100644 tests/health/gold/sdk/tests__hw__esp32__ble6-advertise-shared.toit.gold diff --git a/examples/ble/advertise.toit b/examples/ble/advertise.toit index 3cf4dd0ba..8ecdcc6ea 100644 --- a/examples/ble/advertise.toit +++ b/examples/ble/advertise.toit @@ -10,13 +10,13 @@ main: adapter := ble.Adapter peripheral := adapter.peripheral - data := ble.AdvertisementData + data := ble.Advertisement --name="Toit device" --services=[BATTERY-SERVICE] --manufacturer-specific=#[0xFF, 0xFF, 't', 'o', 'i', 't'] if false: // An equivalent way to create the data would use data blocks. - data = ble.AdvertisementData [ + data = ble.Advertisement [ ble.DataBlock.name "Toit device", ble.DataBlock.services-16 [BATTERY-SERVICE], // The company-id is not included here, as its default is #[0xFF, 0xFF]. diff --git a/examples/ble/connect.toit b/examples/ble/connect.toit index c27f394a5..cb12ecae6 100644 --- a/examples/ble/connect.toit +++ b/examples/ble/connect.toit @@ -12,15 +12,15 @@ SCAN-DURATION ::= Duration --s=3 find-with-service central/ble.Central service/ble.BleUuid: central.scan --duration=SCAN-DURATION: | device/ble.RemoteScannedDevice | if device.data.contains-service service: - return device.address + return device.identifier throw "no device found" main: adapter := ble.Adapter central := adapter.central - address := find-with-service central BATTERY-SERVICE - remote-device := central.connect address + identifier := find-with-service central BATTERY-SERVICE + remote-device := central.connect identifier // Discover the battery service. services := remote-device.discover-services [BATTERY-SERVICE] battery-service/ble.RemoteService := services.first @@ -33,4 +33,4 @@ main: value := battery-level-characteristic.read battery-level := value[0] - print "Battery level of $address: $battery-level%" + print "Battery level of $identifier: $battery-level%" diff --git a/examples/ble/scan.toit b/examples/ble/scan.toit index d90601f3f..5acee84f3 100644 --- a/examples/ble/scan.toit +++ b/examples/ble/scan.toit @@ -11,10 +11,10 @@ main: adapter := ble.Adapter central := adapter.central - addresses := [] + identifiers := [] central.scan --duration=SCAN-DURATION: | device/ble.RemoteScannedDevice | if device.data.contains-service BATTERY-SERVICE: - addresses.add device.address + identifiers.add device.identifier - print addresses + print identifiers diff --git a/external/gold/toit-provision__examples__ble-provision.toit.gold b/external/gold/toit-provision__examples__ble-provision.toit.gold new file mode 100644 index 000000000..71e6e4cea --- /dev/null +++ b/external/gold/toit-provision__examples__ble-provision.toit.gold @@ -0,0 +1,3 @@ +/src_/ble.toit:55:12: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + ble.AdvertisementData + ^~~~~~~~~~~~~~~~~~ diff --git a/external/gold/toit-provision__src__provision.toit.gold b/external/gold/toit-provision__src__provision.toit.gold new file mode 100644 index 000000000..9d65a75bc --- /dev/null +++ b/external/gold/toit-provision__src__provision.toit.gold @@ -0,0 +1,3 @@ +toit-provision/src/src_/ble.toit:55:12: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + ble.AdvertisementData + ^~~~~~~~~~~~~~~~~~ diff --git a/external/gold/toit-provision__src__src___ble.toit.gold b/external/gold/toit-provision__src__src___ble.toit.gold new file mode 100644 index 000000000..9d65a75bc --- /dev/null +++ b/external/gold/toit-provision__src__src___ble.toit.gold @@ -0,0 +1,3 @@ +toit-provision/src/src_/ble.toit:55:12: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + ble.AdvertisementData + ^~~~~~~~~~~~~~~~~~ diff --git a/external/gold/toit-provision__src__src___config.toit.gold b/external/gold/toit-provision__src__src___config.toit.gold new file mode 100644 index 000000000..9d65a75bc --- /dev/null +++ b/external/gold/toit-provision__src__src___config.toit.gold @@ -0,0 +1,3 @@ +toit-provision/src/src_/ble.toit:55:12: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + ble.AdvertisementData + ^~~~~~~~~~~~~~~~~~ diff --git a/external/gold/toit-provision__src__src___rpc.toit.gold b/external/gold/toit-provision__src__src___rpc.toit.gold new file mode 100644 index 000000000..9d65a75bc --- /dev/null +++ b/external/gold/toit-provision__src__src___rpc.toit.gold @@ -0,0 +1,3 @@ +toit-provision/src/src_/ble.toit:55:12: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + ble.AdvertisementData + ^~~~~~~~~~~~~~~~~~ diff --git a/external/gold/toit-provision__src__src___scan.toit.gold b/external/gold/toit-provision__src__src___scan.toit.gold new file mode 100644 index 000000000..9d65a75bc --- /dev/null +++ b/external/gold/toit-provision__src__src___scan.toit.gold @@ -0,0 +1,3 @@ +toit-provision/src/src_/ble.toit:55:12: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + ble.AdvertisementData + ^~~~~~~~~~~~~~~~~~ diff --git a/external/gold/toit-provision__src__src___security.toit.gold b/external/gold/toit-provision__src__src___security.toit.gold new file mode 100644 index 000000000..9d65a75bc --- /dev/null +++ b/external/gold/toit-provision__src__src___security.toit.gold @@ -0,0 +1,3 @@ +toit-provision/src/src_/ble.toit:55:12: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + ble.AdvertisementData + ^~~~~~~~~~~~~~~~~~ diff --git a/external/gold/toit-provision__src__src___session.toit.gold b/external/gold/toit-provision__src__src___session.toit.gold new file mode 100644 index 000000000..9d65a75bc --- /dev/null +++ b/external/gold/toit-provision__src__src___session.toit.gold @@ -0,0 +1,3 @@ +toit-provision/src/src_/ble.toit:55:12: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + ble.AdvertisementData + ^~~~~~~~~~~~~~~~~~ diff --git a/external/gold/toit-provision__src__src___version.toit.gold b/external/gold/toit-provision__src__src___version.toit.gold new file mode 100644 index 000000000..9d65a75bc --- /dev/null +++ b/external/gold/toit-provision__src__src___version.toit.gold @@ -0,0 +1,3 @@ +toit-provision/src/src_/ble.toit:55:12: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + ble.AdvertisementData + ^~~~~~~~~~~~~~~~~~ diff --git a/lib/ble/ble.toit b/lib/ble/ble.toit index 7d08ea0f7..d1ae277ba 100644 --- a/lib/ble/ble.toit +++ b/lib/ble/ble.toit @@ -678,14 +678,29 @@ class DataBlock: return result /** -Advertisement data as either sent by advertising or received through scanning. - -The size of an advertisement packet is limited to 31 bytes. This includes the name - and bytes that are required to structure the packet. +Deprecated. Use $Advertisement instead. */ -class AdvertisementData: - /** The $DataBlock fields of this instance. */ - data-blocks/List // Of DataBlock. +class AdvertisementData extends Advertisement: + /** + Deprecated. Use the $Advertisement.constructor instead. The argument $manufacturer-data has + been renamed to 'manufacturer-specific', and $service-classes has been renamed to 'services'. + */ + constructor + --name/string?=null + --service-classes/List=[] + --manufacturer-data/io.Data=#[] + --.connectable=false + --flags/int=0 + --check-size/bool=true: + super + --name=name + --services=service-classes + --manufacturer-specific=manufacturer-data.byte-size > 0 ? manufacturer-data : null + --flags=flags + --check-size=check-size + + constructor.raw_ bytes/ByteArray? --.connectable: + super.raw bytes /** Whether connections are allowed. @@ -694,54 +709,58 @@ class AdvertisementData: */ connectable/bool + /** + Advertised service classes as a list of $BleUuid. + + Deprecated. Use $Advertisement.services instead. + */ + service-classes -> List: return services + + /** + Manufacturer data as a byte array. + + For backwards compatibility, returns an empty byte array if no manufacturer data is present. + + Returns the concatenation of the manufacturer-id and the manufacturer-specific data. + + Deprecated. Use $Advertisement.manufacturer-specific instead. + */ + manufacturer-data -> ByteArray: + data-blocks.do: | block/DataBlock | + if block.is-manufacturer-specific: return block.data.copy + return ByteArray 0 + +/** +Advertisement data as either sent by advertising or received through scanning. + +The size of an advertisement packet is limited to 31 bytes. This includes the name + and bytes that are required to structure the packet. +*/ +class Advertisement: + /** The $DataBlock fields of this instance. */ + data-blocks/List // Of DataBlock. + /** Constructs an advertisement data packet with the given data blocks. Advertisement packets are limited to 31 data bytes. If $check-size is true, then the size of the data blocks is checked to ensure that the packet size does not exceed 31 bytes. - - The $connectable parameter is only used to set the deprecated field of the same name. - It is safe to ignore it if the field is not used. */ - constructor .data-blocks --.connectable/bool=false --check-size/bool=true: + constructor .data-blocks --check-size/bool=true: if check-size and size > 31: throw "PACKET_SIZE_EXCEEDED" /** Constructs an advertisement data packet from the $raw data. Advertisement packets are limited to 31 data bytes. - - The $connectable parameter is only used to set the deprecated field of the same name. - It is safe to ignore it if the field is not used. */ - constructor.raw raw/ByteArray? --.connectable/bool=false: + constructor.raw raw/ByteArray?: data-blocks = raw ? DataBlock.decode raw : [] - /** - Deprecated. Use the $(constructor --services --manufacturer-specific) instead. - */ - constructor - --name/string?=null - --service-classes/List - --manufacturer-data/io.Data=#[] - --connectable/bool=false - --flags/int=0 - --check-size/bool=true: - return AdvertisementData - --name=name - --services=service-classes - --manufacturer-specific=manufacturer-data.byte-size > 0 ? manufacturer-data : null - --connectable=connectable - --flags=flags - --check-size=check-size - /** Constructs an advertisement packet. - The $connectable parameter is only used to set the deprecated field of the same name. - It is safe to ignore it if the field is not used. - If the $services parameter is not empty, then the list is split into 16-bit, 32-bit, and 128-bit UUIDs. Each of the lists that isn't empty is then encoded into the advertisement data. @@ -750,7 +769,6 @@ class AdvertisementData: --name/string?=null --services/List=[] --manufacturer-specific/io.Data?=null - --.connectable=false --flags/int?=null --check-size/bool=true: blocks := [] @@ -784,13 +802,6 @@ class AdvertisementData: if block.is-name: return block.name return null - /** - Advertised service classes as a list of $BleUuid. - - Deprecated. Use $services instead. - */ - service-classes -> List: return services - /** Advertised services as a list of $BleUuid. @@ -830,20 +841,6 @@ class AdvertisementData: if block.is-tx-power-level: return block.tx-power-level return null - /** - Manufacturer data as a byte array. - - For backwards compatibility, returns an empty byte array if no manufacturer data is present. - - Returns the concatenation of the manufacturer-id and the manufacturer-specific data. - - Deprecated. Use $manufacturer-specific instead. - */ - manufacturer-data -> ByteArray: - data-blocks.do: | block/DataBlock | - if block.is-manufacturer-specific: return block.data.copy - return ByteArray 0 - /** Calls the given $block with the first field of manufacturer specific data. diff --git a/lib/ble/local.toit b/lib/ble/local.toit index 1e023b03a..d82b6a093 100644 --- a/lib/ble/local.toit +++ b/lib/ble/local.toit @@ -57,8 +57,8 @@ class Peripheral extends Resource_: Throws if the adapter does not allow configuration of $interval or $connection-mode. */ start-advertise - data/AdvertisementData - --scan-response/AdvertisementData?=null + data/Advertisement + --scan-response/Advertisement?=null --interval/Duration=DEFAULT-INTERVAL --connection-mode/int=BLE-CONNECT-MODE-NONE: if system.platform == system.PLATFORM-MACOS: @@ -104,8 +104,8 @@ class Peripheral extends Resource_: Sets the connection-mode to $BLE-CONNECT-MODE-UNDIRECTIONAL. */ start-advertise - data/AdvertisementData - --scan-response/AdvertisementData?=null + data/Advertisement + --scan-response/Advertisement?=null --interval/Duration=DEFAULT-INTERVAL --allow-connections/True: start-advertise data --scan-response=scan-response --interval=interval --connection-mode=BLE-CONNECT-MODE-UNDIRECTIONAL diff --git a/lib/ble/remote.toit b/lib/ble/remote.toit index 70ce17cd3..c424c946e 100644 --- a/lib/ble/remote.toit +++ b/lib/ble/remote.toit @@ -27,15 +27,15 @@ class Central extends Resource_: close_ /** - Connects to the remote device with the given $address. + Connects to the remote device with the given $identifier. Connections cannot be established while a scan is ongoing. If $secure is true, the connections is secured and the remote peer is bonded. */ - connect address/any --secure/bool=false -> RemoteDevice: - remote-device := RemoteDevice.private_ this address secure + connect identifier/any --secure/bool=false -> RemoteDevice: + remote-device := RemoteDevice.private_ this identifier secure remotes-devices_.add remote-device return remote-device @@ -104,25 +104,33 @@ class Central extends Resource_: service-classes.add BleUuid raw-service-classes[it] + identifier := next[0] + rssi := next[1] discovery = RemoteScannedDevice - next[0] - next[1] + identifier + rssi --is-connectable=next[6] --is-scan-response=false + --address-bytes=null + --address-type=null AdvertisementData --name=next[2] - --services=service-classes - --manufacturer-specific=(next[4] ? next[4] : #[]) + --service-classes=service-classes + --manufacturer-data=(next[4] ? next[4] : #[]) --flags=next[5] --connectable=next[6] --check-size=false else: + identifier := next[0] + rssi := next[1] discovery = RemoteScannedDevice - next[0] - next[1] + identifier + rssi --is-connectable=next[3] --is-scan-response=next[4] - AdvertisementData.raw next[2] --connectable=next[3] + --address-type=identifier[0] + --address-bytes=identifier[1..] + AdvertisementData.raw_ next[2] --connectable=next[3] block.call discovery finally: @@ -130,7 +138,7 @@ class Central extends Resource_: resource-state_.wait-for-state COMPLETED-EVENT_ /** - Returns a list of device addresses that have been bonded. The elements + Returns a list of device identifiers that have been bonded. The elements of the list can be used as arguments to $connect. NOTE: Not implemented on MacOS. @@ -142,10 +150,64 @@ class Central extends Resource_: A remote device discovered by a scanning. */ class RemoteScannedDevice: + /** + A globally fixed address that has been registered with IEEE. + */ + static ADDRESS-TYPE-PUBLIC := 0 + /** + A random static address. + + A random address that is not changed for the lifetime of the device. + */ + static ADDRESS-TYPE-RANDOM := 1 + /** + A resolvable private address. + + A random address that can be resolved to a public or static + ($ADDRESS-TYPE-RANDOM) address using a pre-shared key. + */ + static ADDRESS-TYPE-PUBLIC_IDENTITY := 2 + /** + A non-resolvable private address. + + An address that changes periodically and cannot be resolved to a public + or static address. + */ + static ADDRESS-TYPE-RANDOM_IDENTITY := 3 + /** The BLE address of the remote device. + + Deprecated: Use $identifier instead. */ - address/any + address -> any: return identifier + + /** + The identifier of the remote device. + + The identifier is platform dependent and must be used to $Central.connect to the device. + */ + identifier/Object + + /** + The address of the remote device. + + Not all platforms support this field. + */ + address-bytes/ByteArray? + + /** + The type of the address. + + Not all platforms support this field. + + The type is one of the following: + - 0: Public: $ADDRESS_TYPE_PUBLIC + - 1: Random: $ADDRESS_TYPE_RANDOM + - 2: Public Identity: $ADDRESS_TYPE_PUBLIC_IDENTITY + - 3: Random Identity: $ADDRESS_TYPE_RANDOM_IDENTITY + */ + address-type/int? /** The RSSI measured for the remote device. @@ -168,15 +230,19 @@ class RemoteScannedDevice: is-scan-response/bool /** - Constructs a remote device with the given $address, $rssi, and $data. + Constructs a remote device. */ - constructor .address .rssi .data --.is-connectable --.is-scan-response: + constructor .identifier .rssi .data + --.is-connectable + --.is-scan-response + --.address-bytes + --.address-type: /** See $super. */ stringify -> string: - return "$address (rssi: $rssi dBm)" + return "$identifier (rssi: $rssi dBm)" class RemoteDescriptor extends RemoteReadWriteElement_ implements Attribute: characteristic/RemoteCharacteristic @@ -445,13 +511,22 @@ class RemoteDevice extends Resource_: The address of the remote device the client is connected to. The type of the address is platform dependent. + + Deprecated. Use $identifier instead. + */ + address -> any: return identifier + + /** + The identifier of the remote device the client is connected to. + + The type of the identifier is platform dependent. */ - address/any + identifier/Object discovered-services_/List := [] - constructor.private_ .manager .address secure/bool: - device-resource := ble-connect_ manager.resource_ address secure + constructor.private_ .manager .identifier secure/bool: + device-resource := ble-connect_ manager.resource_ identifier secure super device-resource state := resource-state_.wait-for-state CONNECTED-EVENT_ | CONNECT-FAILED-EVENT_ if state & CONNECT-FAILED-EVENT_ != 0: diff --git a/tests/ble-advertisement-test.toit b/tests/ble-advertisement-test.toit index 7209248e8..198961170 100644 --- a/tests/ble-advertisement-test.toit +++ b/tests/ble-advertisement-test.toit @@ -250,7 +250,7 @@ test-data-blocks: expect-equals #[0x01, 0x02, 0x03] data test-advertisement-packets: - packet := AdvertisementData [DataBlock.flags BLE-ADVERTISE-FLAGS-BREDR-UNSUPPORTED] + packet := Advertisement [DataBlock.flags BLE-ADVERTISE-FLAGS-BREDR-UNSUPPORTED] expect-equals #[ 0x02, 0x01, 0x04, ] @@ -259,11 +259,10 @@ test-advertisement-packets: expect packet.services.is-empty expect-equals 0x04 packet.flags packet.manufacturer-specific: unreachable - expect-equals #[] packet.manufacturer-data expect-equals [] packet.services - expect-equals packet.to-raw (AdvertisementData.raw packet.to-raw).to-raw + expect-equals packet.to-raw (Advertisement.raw packet.to-raw).to-raw - packet = AdvertisementData [ + packet = Advertisement [ DataBlock.flags --limited-discovery, DataBlock.name "foobar", DataBlock.manufacturer-specific #[0x01, 0x02, 0x03], @@ -274,19 +273,19 @@ test-advertisement-packets: 0x06, 0xff, 0xff, 0xff, 0x01, 0x02, 0x03, // Manufacturer specific ] packet.to-raw - expect-equals packet.to-raw (AdvertisementData.raw packet.to-raw).to-raw + expect-equals packet.to-raw (Advertisement.raw packet.to-raw).to-raw // 27 bytes are fine. - packet = AdvertisementData [ + packet = Advertisement [ DataBlock.manufacturer-specific (ByteArray 27), ] expect-throw "PACKET_SIZE_EXCEEDED": - AdvertisementData [ + Advertisement [ DataBlock.manufacturer-specific (ByteArray 28) ] // We can ignore the check. - packet = AdvertisementData --no-check-size [ + packet = Advertisement --no-check-size [ DataBlock.manufacturer-specific (ByteArray 28) ] @@ -306,7 +305,7 @@ test-real-world-examples: 0x1b, 0xff, // Manufacturer Specific. ] + company-id + manufacturer-data - packet := AdvertisementData [ + packet := Advertisement [ DataBlock.flags --general-discovery --bredr-supported=false, DataBlock.manufacturer-specific --company-id=company-id manufacturer-data ] @@ -317,7 +316,7 @@ test-real-world-examples: data) expect-equals real packet.to-raw - expect-equals real (AdvertisementData.raw packet.to-raw).to-raw + expect-equals real (Advertisement.raw packet.to-raw).to-raw real = #[ @@ -326,7 +325,7 @@ test-real-world-examples: 0x05, 0x12, 0x06, 0x00, 0x14, 0x00, // Slave connection interval range. ] - packet = AdvertisementData [ + packet = Advertisement [ DataBlock.flags --limited-discovery --bredr-supported=false, DataBlock.tx-power-level -4, DataBlock 0x12 #[0x06, 0x00, 0x14, 0x00], @@ -335,7 +334,7 @@ test-real-world-examples: expect-equals -4 packet.tx-power-level expect-equals real packet.to-raw - expect-equals real (AdvertisementData.raw packet.to-raw).to-raw + expect-equals real (Advertisement.raw packet.to-raw).to-raw expect-equals 3 packet.data-blocks.size @@ -345,20 +344,20 @@ test-real-world-examples: ] uuid := BleUuid "6e400001-b5a3-f393-e0a9-e50e24dcca9e" - packet = AdvertisementData [ + packet = Advertisement [ DataBlock.services-128 [uuid], ] expect-equals [uuid] packet.services expect-equals real packet.to-raw - expect-equals real (AdvertisementData.raw packet.to-raw).to-raw + expect-equals real (Advertisement.raw packet.to-raw).to-raw real = #[ 0x11, 0x07, 0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0, 0x93, 0xf3, 0xa3, 0xb5, 0x01, 0x00, 0x40, 0x6e, // Services. 0x0c, 0x09, 0x4e, 0x6f, 0x72, 0x64, 0x69, 0x63, 0x5f, 0x55, 0x41, 0x52, 0x54, // Name. ] - packet = AdvertisementData [ + packet = Advertisement [ DataBlock.services-128 [uuid], DataBlock.name "Nordic_UART", ] @@ -366,4 +365,4 @@ test-real-world-examples: expect-equals "Nordic_UART" packet.name expect-equals real packet.to-raw - expect-equals real (AdvertisementData.raw packet.to-raw).to-raw + expect-equals real (Advertisement.raw packet.to-raw).to-raw diff --git a/tests/health/gold/sdk/examples__ble__advertise.toit.gold b/tests/health/gold/sdk/examples__ble__advertise.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/examples__ble__advertise.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/examples__ble__connect.toit.gold b/tests/health/gold/sdk/examples__ble__connect.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/examples__ble__connect.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/examples__ble__heart_rate.toit.gold b/tests/health/gold/sdk/examples__ble__heart_rate.toit.gold new file mode 100644 index 000000000..6d015353a --- /dev/null +++ b/tests/health/gold/sdk/examples__ble__heart_rate.toit.gold @@ -0,0 +1,9 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ +examples/ble/heart_rate.toit:38:7: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData --name="Toit heart rate demo" + ^~~~~~~~~~~~~~~~~ diff --git a/tests/health/gold/sdk/examples__ble__scan.toit.gold b/tests/health/gold/sdk/examples__ble__scan.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/examples__ble__scan.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/lib__ble__ble.toit.gold b/tests/health/gold/sdk/lib__ble__ble.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/lib__ble__ble.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/lib__ble__local.toit.gold b/tests/health/gold/sdk/lib__ble__local.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/lib__ble__local.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/lib__ble__remote.toit.gold b/tests/health/gold/sdk/lib__ble__remote.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/lib__ble__remote.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/tests__ble-advertisement-test.toit.gold b/tests/health/gold/sdk/tests__ble-advertisement-test.toit.gold index 540f3d9d6..8878de07b 100644 --- a/tests/health/gold/sdk/tests__ble-advertisement-test.toit.gold +++ b/tests/health/gold/sdk/tests__ble-advertisement-test.toit.gold @@ -1,3 +1,6 @@ -tests/ble-advertisement-test.toit:262:28: warning: Deprecated 'AdvertisementData.manufacturer-data'. Use 'manufacturer-specific' instead - expect-equals #[] packet.manufacturer-data - ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/tests__hw__esp32__ble-util.toit.gold b/tests/health/gold/sdk/tests__hw__esp32__ble-util.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/tests__hw__esp32__ble-util.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/tests__hw__esp32__ble1-board1.toit.gold b/tests/health/gold/sdk/tests__hw__esp32__ble1-board1.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/tests__hw__esp32__ble1-board1.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/tests__hw__esp32__ble1-board2.toit.gold b/tests/health/gold/sdk/tests__hw__esp32__ble1-board2.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/tests__hw__esp32__ble1-board2.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/tests__hw__esp32__ble1-shared.toit.gold b/tests/health/gold/sdk/tests__hw__esp32__ble1-shared.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/tests__hw__esp32__ble1-shared.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/tests__hw__esp32__ble2-board1.toit.gold b/tests/health/gold/sdk/tests__hw__esp32__ble2-board1.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/tests__hw__esp32__ble2-board1.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/tests__hw__esp32__ble2-board2.toit.gold b/tests/health/gold/sdk/tests__hw__esp32__ble2-board2.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/tests__hw__esp32__ble2-board2.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/tests__hw__esp32__ble2-shared.toit.gold b/tests/health/gold/sdk/tests__hw__esp32__ble2-shared.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/tests__hw__esp32__ble2-shared.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/tests__hw__esp32__ble3-board1.toit.gold b/tests/health/gold/sdk/tests__hw__esp32__ble3-board1.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/tests__hw__esp32__ble3-board1.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/tests__hw__esp32__ble3-board2.toit.gold b/tests/health/gold/sdk/tests__hw__esp32__ble3-board2.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/tests__hw__esp32__ble3-board2.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/tests__hw__esp32__ble3-shared.toit.gold b/tests/health/gold/sdk/tests__hw__esp32__ble3-shared.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/tests__hw__esp32__ble3-shared.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/tests__hw__esp32__ble4-board1.toit.gold b/tests/health/gold/sdk/tests__hw__esp32__ble4-board1.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/tests__hw__esp32__ble4-board1.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/tests__hw__esp32__ble4-board2.toit.gold b/tests/health/gold/sdk/tests__hw__esp32__ble4-board2.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/tests__hw__esp32__ble4-board2.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/tests__hw__esp32__ble4-shared.toit.gold b/tests/health/gold/sdk/tests__hw__esp32__ble4-shared.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/tests__hw__esp32__ble4-shared.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/tests__hw__esp32__ble5-board1.toit.gold b/tests/health/gold/sdk/tests__hw__esp32__ble5-board1.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/tests__hw__esp32__ble5-board1.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/tests__hw__esp32__ble5-board2.toit.gold b/tests/health/gold/sdk/tests__hw__esp32__ble5-board2.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/tests__hw__esp32__ble5-board2.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/tests__hw__esp32__ble5-shared.toit.gold b/tests/health/gold/sdk/tests__hw__esp32__ble5-shared.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/tests__hw__esp32__ble5-shared.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/tests__hw__esp32__ble6-advertise-board1.toit.gold b/tests/health/gold/sdk/tests__hw__esp32__ble6-advertise-board1.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/tests__hw__esp32__ble6-advertise-board1.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/tests__hw__esp32__ble6-advertise-board2.toit.gold b/tests/health/gold/sdk/tests__hw__esp32__ble6-advertise-board2.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/tests__hw__esp32__ble6-advertise-board2.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/health/gold/sdk/tests__hw__esp32__ble6-advertise-shared.toit.gold b/tests/health/gold/sdk/tests__hw__esp32__ble6-advertise-shared.toit.gold new file mode 100644 index 000000000..8878de07b --- /dev/null +++ b/tests/health/gold/sdk/tests__hw__esp32__ble6-advertise-shared.toit.gold @@ -0,0 +1,6 @@ +/ble/remote.toit:116:15: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData + ^~~~~~~~~~~~~~~~~ +/ble/remote.toit:133:32: warning: Class 'AdvertisementData' is deprecated. Use 'Advertisement' instead + AdvertisementData.raw_ next[2] --connectable=next[3] + ^~~~~ diff --git a/tests/hw/esp32/ble-util.toit b/tests/hw/esp32/ble-util.toit index 2368e9d04..21f9491d0 100644 --- a/tests/hw/esp32/ble-util.toit +++ b/tests/hw/esp32/ble-util.toit @@ -8,6 +8,6 @@ find-device-with-service central/Central service/BleUuid -> any: central.scan --duration=(Duration --s=3): | device/RemoteScannedDevice | if device.data.contains-service service: print "Found device with service $service: $device" - return device.address + return device.identifier throw "No device found with service $service" diff --git a/tests/hw/esp32/ble1-shared.toit b/tests/hw/esp32/ble1-shared.toit index 61600c38f..e49a97185 100644 --- a/tests/hw/esp32/ble1-shared.toit +++ b/tests/hw/esp32/ble1-shared.toit @@ -73,7 +73,7 @@ main-peripheral --iteration/int: seen-handles.add-all [read-only.handle, read-only-callback.handle, notify.handle, indicate.handle, write-only.handle, write-only-with-response.handle] expect-equals 6 seen-handles.size - advertisement := AdvertisementData + advertisement := Advertisement --name="Test" --services=[SERVICE-TEST] peripheral.start-advertise --connection-mode=BLE-CONNECT-MODE-UNDIRECTIONAL advertisement diff --git a/tests/hw/esp32/ble2-shared.toit b/tests/hw/esp32/ble2-shared.toit index 893aa591c..5faed359f 100644 --- a/tests/hw/esp32/ble2-shared.toit +++ b/tests/hw/esp32/ble2-shared.toit @@ -41,7 +41,7 @@ main-peripheral: peripheral.deploy - advertisement := AdvertisementData + advertisement := Advertisement --name="Test" --services=[SERVICE-TEST] peripheral.start-advertise --connection-mode=BLE-CONNECT-MODE-UNDIRECTIONAL advertisement diff --git a/tests/hw/esp32/ble3-shared.toit b/tests/hw/esp32/ble3-shared.toit index 1b452c762..27e52a5ce 100644 --- a/tests/hw/esp32/ble3-shared.toit +++ b/tests/hw/esp32/ble3-shared.toit @@ -92,7 +92,7 @@ main-peripheral: peripheral.deploy print "Deployed $UUIDS.size services" - advertisement := AdvertisementData + advertisement := Advertisement --name="Test" --services=[first-service.uuid] peripheral.start-advertise --connection-mode=BLE-CONNECT-MODE-UNDIRECTIONAL advertisement diff --git a/tests/hw/esp32/ble4-shared.toit b/tests/hw/esp32/ble4-shared.toit index 378c44035..35dfca92a 100644 --- a/tests/hw/esp32/ble4-shared.toit +++ b/tests/hw/esp32/ble4-shared.toit @@ -49,7 +49,7 @@ main-peripheral: break descriptor.set-value data - advertisement := AdvertisementData + advertisement := Advertisement --name="Test" --services=[TEST-SERVICE] peripheral.start-advertise --connection-mode=BLE-CONNECT-MODE-UNDIRECTIONAL advertisement diff --git a/tests/hw/esp32/ble5-shared.toit b/tests/hw/esp32/ble5-shared.toit index fcca96522..e6e63c374 100644 --- a/tests/hw/esp32/ble5-shared.toit +++ b/tests/hw/esp32/ble5-shared.toit @@ -40,7 +40,7 @@ main-peripheral: break characteristic.set-value data - advertisement := AdvertisementData + advertisement := Advertisement --name="Test" --services=[TEST-SERVICE] peripheral.start-advertise --connection-mode=BLE-CONNECT-MODE-UNDIRECTIONAL advertisement diff --git a/tests/hw/esp32/ble6-advertise-shared.toit b/tests/hw/esp32/ble6-advertise-shared.toit index e6dc6a9b9..b6c7650ee 100644 --- a/tests/hw/esp32/ble6-advertise-shared.toit +++ b/tests/hw/esp32/ble6-advertise-shared.toit @@ -50,22 +50,22 @@ main-peripheral: else: throw "Unexpected data: $data" - advertisement := AdvertisementData + advertisement := Advertisement --name="Test" --services=[TEST-SERVICE] peripheral.start-advertise --allow-connections advertisement next-semaphore.down peripheral.stop-advertise - advertisement = AdvertisementData [] + advertisement = Advertisement [] peripheral.start-advertise advertisement next-semaphore.down peripheral.stop-advertise advertise := : | blocks scan-response-blocks | - advertisement = AdvertisementData blocks + advertisement = Advertisement blocks scan-response := scan-response-blocks - ? AdvertisementData scan-response-blocks + ? Advertisement scan-response-blocks : null peripheral.start-advertise advertisement @@ -110,23 +110,26 @@ main-peripheral: print "done" -scan address/ByteArray --central/Central -> RemoteScannedDevice: +scan identifier/ByteArray --central/Central -> RemoteScannedDevice: central.scan --duration=(Duration --s=3): | device/RemoteScannedDevice | - if device.address == address: + if device.identifier == identifier: return device throw "Device not found" central-test-counter := 0 test-data - address/any + identifier/any characteristic/RemoteCharacteristic --central/Central --is-connectable/bool=true [block]: - remote-scanned := scan address --central=central + remote-scanned := scan identifier --central=central + expect remote-scanned.address-bytes is ByteArray + expect-equals 6 (remote-scanned.address-bytes as ByteArray).size + expect-equals RemoteScannedDevice.ADDRESS-TYPE-PUBLIC remote-scanned.address-type expect-not remote-scanned.is-scan-response - expect-equals address remote-scanned.address + expect-equals identifier remote-scanned.identifier expect-equals is-connectable remote-scanned.is-connectable block.call remote-scanned.data characteristic.write #[central-test-counter++] @@ -135,9 +138,9 @@ main-central: adapter := Adapter central := adapter.central - address := find-device-with-service central TEST-SERVICE + identifier := find-device-with-service central TEST-SERVICE - remote-device := central.connect address + remote-device := central.connect identifier all-services := remote-device.discover-services services := remote-device.discovered-services @@ -148,21 +151,21 @@ main-central: characteristics.do: | found/RemoteCharacteristic | if found.uuid == TEST-CHARACTERISTIC: characteristic = found - test-data address characteristic --central=central: | data/AdvertisementData | + test-data identifier characteristic --central=central: | data/Advertisement | blocks := data.data-blocks expect-equals 2 blocks.size expect-equals [TEST-SERVICE] data.services expect-equals "Test" data.name - test-data address characteristic --central=central --no-is-connectable: | data/AdvertisementData | + test-data identifier characteristic --central=central --no-is-connectable: | data/Advertisement | blocks := data.data-blocks expect-equals 0 blocks.size - test-data address characteristic --central=central: | data/AdvertisementData | + test-data identifier characteristic --central=central: | data/Advertisement | blocks := data.data-blocks expect-equals 0 blocks.size - test-data address characteristic --central=central: | data/AdvertisementData | + test-data identifier characteristic --central=central: | data/Advertisement | blocks := data.data-blocks expect-equals 2 blocks.size expect-equals 0x06 data.flags @@ -171,13 +174,13 @@ main-central: expect-equals MANUFACTURER-DATA data id) - test-data address characteristic --central=central: | data/AdvertisementData | + test-data identifier characteristic --central=central: | data/Advertisement | blocks := data.data-blocks expect-equals 2 blocks.size expect-equals "Test" data.name expect-equals [TEST-SERVICE] data.services - test-data address characteristic --central=central: | data/AdvertisementData | + test-data identifier characteristic --central=central: | data/Advertisement | blocks := data.data-blocks expect-equals 1 blocks.size expect-equals #[0xff, 0xff] @@ -187,15 +190,15 @@ main-central: // Check that active/passive scanning works. central.scan --duration=(Duration --s=2): | device/RemoteScannedDevice | - if device.address == address: + if device.identifier == identifier: // Without doing an active scan we don't get a scan response. expect-not device.is-scan-response - advertisement/AdvertisementData? := null - scan-response/AdvertisementData? := null + advertisement/Advertisement? := null + scan-response/Advertisement? := null while true: // Use a loop to be able to break out of the block. central.scan --duration=(Duration --s=3) --active: | device/RemoteScannedDevice | - if device.address == address: + if device.identifier == identifier: if device.is-scan-response: scan-response = device.data else: @@ -212,11 +215,11 @@ main-central: // Test limited scanning. central.scan --duration=(Duration --s=1) --limited-only: | device/RemoteScannedDevice | - if device.address == address: unreachable + if device.identifier == identifier: unreachable // But we should find the device with general scanning. while true: // Use a loop to be able to break out of the block. central.scan --duration=(Duration --s=3): | device/RemoteScannedDevice | - if device.address == address: break + if device.identifier == identifier: break unreachable characteristic.write #[central-test-counter++]