Skip to content

Commit

Permalink
Merge branch 'floitsch/ble-extended-scan.10.more-fields' into floitsc…
Browse files Browse the repository at this point in the history
…h/ble-extended-scan.20.active-scan
  • Loading branch information
floitsch committed Nov 25, 2024
2 parents e59206a + 5702e48 commit cba16fe
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/ble/ble.toit
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion lib/ble/local.toit
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions lib/ble/remote.toit
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 26 additions & 0 deletions tests/byte-array-test.toit
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ main:
test-to-string
test-hash-code
test-construction
test-reverse

test-basic:
2.repeat:
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/hw/esp32/ble4-shared.toit
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion tests/hw/esp32/ble6-advertise-shared.toit
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cba16fe

Please sign in to comment.