diff --git a/lib/ble/ble.toit b/lib/ble/ble.toit index bf05e3a27..49e62fb1c 100644 --- a/lib/ble/ble.toit +++ b/lib/ble/ble.toit @@ -668,7 +668,7 @@ class DataBlock: return at + data.size + 2 /** - Converts this datablock to a raw byte array. + Converts this data block to a raw byte array. */ to-raw -> ByteArray: result := ByteArray data.size + 2 diff --git a/lib/ble/local.toit b/lib/ble/local.toit index bf694dbcb..1e023b03a 100644 --- a/lib/ble/local.toit +++ b/lib/ble/local.toit @@ -62,8 +62,11 @@ class Peripheral extends Resource_: --interval/Duration=DEFAULT-INTERVAL --connection-mode/int=BLE-CONNECT-MODE-NONE: if system.platform == system.PLATFORM-MACOS: + if scan-response: throw "UNSUPPORTED" + data.data-blocks.do: | block/DataBlock | + if not block.is-name and not block.is-services and not block.is-flags: + throw "UNSUPPORTED" if interval != DEFAULT-INTERVAL or connection-mode != BLE-CONNECT-MODE-NONE: throw "INVALID_ARGUMENT" - data.manufacturer-specific: throw "INVALID_ARGUMENT" services := data.services raw-service-classes := Array_ services.size null diff --git a/lib/ble/remote.toit b/lib/ble/remote.toit index b5dac1605..60010e792 100644 --- a/lib/ble/remote.toit +++ b/lib/ble/remote.toit @@ -83,24 +83,24 @@ class Central extends Resource_: BleUuid raw-service-classes[it] discovery = RemoteScannedDevice - next[0] - next[1] - --is-connectable=next[6] - --is-scan-response=false - AdvertisementData - --name=next[2] - --services=service-classes - --manufacturer-specific=(next[4] ? next[4] : #[]) - --flags=next[5] - --connectable=next[6] - --check-size=false + next[0] + next[1] + --is-connectable=next[6] + --is-scan-response=false + AdvertisementData + --name=next[2] + --services=service-classes + --manufacturer-specific=(next[4] ? next[4] : #[]) + --flags=next[5] + --connectable=next[6] + --check-size=false else: discovery = RemoteScannedDevice - next[0] - next[1] - --is-connectable=next[3] - --is-scan-response=next[4] - AdvertisementData.raw next[2] --connectable=next[3] + next[0] + next[1] + --is-connectable=next[3] + --is-scan-response=next[4] + AdvertisementData.raw next[2] --connectable=next[3] block.call discovery finally: diff --git a/tests/byte-array-test.toit b/tests/byte-array-test.toit index 41c3dd7fc..639ae93d7 100644 --- a/tests/byte-array-test.toit +++ b/tests/byte-array-test.toit @@ -26,6 +26,7 @@ main: test-to-string test-hash-code test-construction + test-reverse test-basic: 2.repeat: @@ -314,3 +315,28 @@ test-construction -> none: ba = ByteArray 5 expect-equals #[0, 0, 0, 0, 0] ba + +test-reverse -> none: + SIZES := [ + 0, + 1, + 2, + 3, + 5, + 100, + 101, + 1000, + 1001, + 1023, + 1024, + 1025, + ] + SIZES.do: | size/int | + bytes := ByteArray size: random 256 + reversed := bytes.reverse + expect-equals size reversed.size + size.repeat: | i | + expect-equals bytes[size - i - 1] reversed[i] + copy := bytes.copy + copy.reverse --in-place + expect-bytes-equal reversed copy diff --git a/tests/hw/esp32/ble4-shared.toit b/tests/hw/esp32/ble4-shared.toit index 5a05dd8a6..378c44035 100644 --- a/tests/hw/esp32/ble4-shared.toit +++ b/tests/hw/esp32/ble4-shared.toit @@ -15,7 +15,7 @@ import monitor import .ble-util -TEST-SERVICE ::= BleUuid "df451d2d-e899-4346-a8fd-bca9cbfebc0b" +TEST-SERVICE ::= BleUuid "650a73d3-d7fd-4d08-b734-d11e25b0856d" TEST-CHARACTERISTIC ::= BleUuid "77d0b04e-bf49-4048-a4cd-fb46be32ebd0" TEST-CHARACTERISTIC-CALLBACK ::= BleUuid "1a1bb179-c006-4217-a57b-342e24eca694" diff --git a/tests/hw/esp32/ble6-advertise-shared.toit b/tests/hw/esp32/ble6-advertise-shared.toit index 3202a342a..f83b8302c 100644 --- a/tests/hw/esp32/ble6-advertise-shared.toit +++ b/tests/hw/esp32/ble6-advertise-shared.toit @@ -148,7 +148,6 @@ main-central: expect-equals [TEST-SERVICE] data.services expect-equals "Test" data.name - test-data address characteristic --central=central --no-is-connectable: | data/AdvertisementData | blocks := data.data-blocks expect-equals 0 blocks.size