|
36 | 36 | // If uuid128 is NULL, this is a Bluetooth SIG 16-bit UUID. |
37 | 37 | // If uuid128 is not NULL, it's a 128-bit (16-byte) UUID, with bytes 12 and 13 zero'd out, where |
38 | 38 | // the 16-bit part goes. Those 16 bits are passed in uuid16. |
39 | | -void common_hal_bleio_uuid_construct(bleio_uuid_obj_t *self, uint32_t uuid16, const uint8_t uuid128[]) { |
40 | | - //FIX self->nrf_ble_uuid.uuid = uuid16; |
41 | | - // if (uuid128 == NULL) { |
42 | | - // self->nrf_ble_uuid.type = BLE_UUID_TYPE_BLE; |
43 | | - // } else { |
44 | | - // ble_uuid128_t vs_uuid; |
45 | | - // memcpy(vs_uuid.uuid128, uuid128, sizeof(vs_uuid.uuid128)); |
46 | | - |
47 | | - // // Register this vendor-specific UUID. Bytes 12 and 13 will be zero. |
48 | | - // check_nrf_error(sd_ble_uuid_vs_add(&vs_uuid, &self->nrf_ble_uuid.type)); |
49 | | - // vm_used_ble = true; |
50 | | - // } |
| 39 | +void common_hal_bleio_uuid_construct(bleio_uuid_obj_t *self, uint32_t uuid16, const uint8_t uuid128[16]) { |
| 40 | + self->size = uuid128 == NULL ? 16 : 128; |
| 41 | + self->uuid16 = uuid16; |
| 42 | + if (uuid128) { |
| 43 | + memcpy(self->uuid128, uuid128, 16); |
| 44 | + self->uuid128[12] = uuid16 & 0xff; |
| 45 | + self->uuid128[13] = uuid16 >> 8; |
| 46 | + } else { |
| 47 | + memset(self->uuid128, 0, 16); |
| 48 | + } |
51 | 49 | } |
52 | 50 |
|
53 | 51 | uint32_t common_hal_bleio_uuid_get_size(bleio_uuid_obj_t *self) { |
54 | | - //FIX return self->nrf_ble_uuid.type == BLE_UUID_TYPE_BLE ? 16 : 128; |
55 | | - return 0; |
| 52 | + return self->size; |
56 | 53 | } |
57 | 54 |
|
58 | 55 | uint32_t common_hal_bleio_uuid_get_uuid16(bleio_uuid_obj_t *self) { |
59 | | - //FIX return self->nrf_ble_uuid.uuid; |
60 | | - return 0; |
| 56 | + return self->uuid16; |
61 | 57 | } |
62 | 58 |
|
63 | 59 | void common_hal_bleio_uuid_get_uuid128(bleio_uuid_obj_t *self, uint8_t uuid128[16]) { |
64 | | - //FIX uint8_t length; |
65 | | - //FIX check_nrf_error(sd_ble_uuid_encode(&self->nrf_ble_uuid, &length, uuid128)); |
| 60 | + memcpy(uuid128, self->uuid128, 16); |
66 | 61 | } |
67 | 62 |
|
68 | 63 | void common_hal_bleio_uuid_pack_into(bleio_uuid_obj_t *self, uint8_t* buf) { |
69 | | - //FIX if (self->nrf_ble_uuid.type == BLE_UUID_TYPE_BLE) { |
70 | | - // buf[0] = self->nrf_ble_uuid.uuid & 0xff; |
71 | | - // buf[1] = self->nrf_ble_uuid.uuid >> 8; |
72 | | - // } else { |
73 | | - // common_hal_bleio_uuid_get_uuid128(self, buf); |
74 | | - // } |
| 64 | + if (self->size == 16) { |
| 65 | + buf[0] = self->uuid16 & 0xff; |
| 66 | + buf[1] = self->uuid16 >> 8; |
| 67 | + } else { |
| 68 | + common_hal_bleio_uuid_get_uuid128(self, buf); |
| 69 | + } |
75 | 70 | } |
76 | | - |
77 | | -//FIX |
78 | | -// void bleio_uuid_construct_from_nrf_ble_uuid(bleio_uuid_obj_t *self, ble_uuid_t *nrf_ble_uuid) { |
79 | | -// if (nrf_ble_uuid->type == BLE_UUID_TYPE_UNKNOWN) { |
80 | | -// mp_raise_bleio_BluetoothError(translate("Unexpected nrfx uuid type")); |
81 | | -// } |
82 | | -// self->nrf_ble_uuid.uuid = nrf_ble_uuid->uuid; |
83 | | -// self->nrf_ble_uuid.type = nrf_ble_uuid->type; |
84 | | -// } |
85 | | - |
86 | | -// // Fill in a ble_uuid_t from my values. |
87 | | -// void bleio_uuid_convert_to_nrf_ble_uuid(bleio_uuid_obj_t *self, ble_uuid_t *nrf_ble_uuid) { |
88 | | -// nrf_ble_uuid->uuid = self->nrf_ble_uuid.uuid; |
89 | | -// nrf_ble_uuid->type = self->nrf_ble_uuid.type; |
90 | | -// } |
0 commit comments