@@ -113,18 +113,40 @@ bool common_hal_bleio_adapter_get_enabled(bleio_adapter_obj_t *self) {
113
113
}
114
114
115
115
bleio_address_obj_t * common_hal_bleio_adapter_get_address (bleio_adapter_obj_t * self ) {
116
- return NULL ;
116
+ uint8_t address_bytes [6 ];
117
+ uint8_t address_type = BLE_ADDR_RANDOM ;
118
+ ble_hs_id_infer_auto (0 , & address_type );
119
+ int result = ble_hs_id_copy_addr (address_type , address_bytes , NULL );
120
+ if (result != 0 ) {
121
+ return NULL ;
122
+ }
123
+
124
+ bleio_address_obj_t * address = m_new_obj (bleio_address_obj_t );
125
+ address -> base .type = & bleio_address_type ;
126
+ common_hal_bleio_address_construct (address , address_bytes , BLEIO_ADDRESS_TYPE_RANDOM_STATIC );
127
+ return address ;
117
128
}
118
129
119
130
bool common_hal_bleio_adapter_set_address (bleio_adapter_obj_t * self , bleio_address_obj_t * address ) {
120
- return false;
131
+ if (address -> type != BLEIO_ADDRESS_TYPE_RANDOM_STATIC ) {
132
+ return false;
133
+ }
134
+ mp_buffer_info_t bufinfo ;
135
+ if (!mp_get_buffer (address -> bytes , & bufinfo , MP_BUFFER_READ )) {
136
+ return false;
137
+ }
138
+ int result = ble_hs_id_set_rnd (bufinfo .buf );
139
+ return result == 0 ;
121
140
}
122
141
123
142
mp_obj_str_t * common_hal_bleio_adapter_get_name (bleio_adapter_obj_t * self ) {
124
- return NULL ;
143
+ const char * name = ble_svc_gap_device_name ();
144
+
145
+ return mp_obj_new_str (name , strlen (name ));
125
146
}
126
147
127
148
void common_hal_bleio_adapter_set_name (bleio_adapter_obj_t * self , const char * name ) {
149
+ ble_svc_gap_device_name_set (name );
128
150
}
129
151
130
152
static int _scan_event (struct ble_gap_event * event , void * scan_results_in ) {
0 commit comments