diff options
| author | Joe Bakalor <jmbakalor@gmail.com> | 2019-11-05 11:06:18 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-05 11:06:18 -0500 |
| commit | ba83a4a2ac815e76cd752db05e3269450021954e (patch) | |
| tree | 611864e312d825c2abb85df4d3a9cb88aa382faa /shared-module/_bleio/ScanEntry.c | |
| parent | 8ab3ef44dddbb82d623dd557461b2b77cf607283 (diff) | |
| parent | 01bf9321692d00da8628b7b230be3b03665eff82 (diff) | |
Merge pull request #1 from adafruit/master
Update base
Diffstat (limited to 'shared-module/_bleio/ScanEntry.c')
| -rw-r--r-- | shared-module/_bleio/ScanEntry.c | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/shared-module/_bleio/ScanEntry.c b/shared-module/_bleio/ScanEntry.c index 8dfa17f31..785209c4a 100644 --- a/shared-module/_bleio/ScanEntry.c +++ b/shared-module/_bleio/ScanEntry.c @@ -37,9 +37,50 @@ mp_obj_t common_hal_bleio_scanentry_get_address(bleio_scanentry_obj_t *self) { } mp_obj_t common_hal_bleio_scanentry_get_advertisement_bytes(bleio_scanentry_obj_t *self) { - return self->data; + return MP_OBJ_FROM_PTR(self->data); } mp_int_t common_hal_bleio_scanentry_get_rssi(bleio_scanentry_obj_t *self) { return self->rssi; } + +bool common_hal_bleio_scanentry_get_connectable(bleio_scanentry_obj_t *self) { + return self->connectable; +} + +bool common_hal_bleio_scanentry_get_scan_response(bleio_scanentry_obj_t *self) { + return self->scan_response; +} + +bool bleio_scanentry_data_matches(const uint8_t* data, size_t len, const uint8_t* prefixes, size_t prefixes_length, bool any) { + if (prefixes_length == 0) { + return true; + } + size_t i = 0; + while(i < prefixes_length) { + uint8_t prefix_length = prefixes[i]; + i += 1; + size_t j = 0; + while (j < len) { + uint8_t structure_length = data[j]; + j += 1; + if (structure_length == 0) { + break; + } + if (structure_length >= prefix_length && memcmp(data + j, prefixes + i, prefix_length) == 0) { + if (any) { + return true; + } + } else if (!any) { + return false; + } + j += structure_length; + } + i += prefix_length; + } + return !any; +} + +bool common_hal_bleio_scanentry_matches(bleio_scanentry_obj_t *self, const uint8_t* prefixes, size_t prefixes_len, bool all) { + return bleio_scanentry_data_matches(self->data->data, self->data->len, prefixes, prefixes_len, !all); +} |
