def from_c(cls, event): passkey_display = event.evt.gap_evt.params.passkey_display passkey = "".join(chr(c) for c in util.uint8_array_to_list(passkey_display.passkey, 6)) match_request = bool(passkey_display.match_request) return cls(conn_handle=event.evt.gap_evt.conn_handle, passkey=passkey, match_request=match_request)
def from_c(cls, adv_report_evt): ad_list = util.uint8_array_to_list(adv_report_evt.data, adv_report_evt.dlen) ble_adv_data = cls() ble_adv_data.raw_bytes = bytes(ad_list) index = 0 while index < len(ad_list): ad_len = ad_list[index] # If the length field is zero, skip it (probably padded zeros at the end of the payload) if ad_len == 0: index += 1 continue try: ad_type = ad_list[index + 1] offset = index + 2 key = BLEAdvData.Types(ad_type) ble_adv_data.records[key] = ad_list[offset:offset + ad_len - 1] except ValueError: logger.error( 'Invalid advertising data type: 0x{:02X}'.format(ad_type)) pass except IndexError: logger.error('Invalid advertising data: {}'.format(ad_list)) return ble_adv_data index += (ad_len + 1) return ble_adv_data
def from_c(cls, event): hvx_evt = event.evt.gattc_evt.params.hvx return cls(conn_handle=event.evt.gattc_evt.conn_handle, status=BLEGattStatusCode(event.evt.gattc_evt.gatt_status), error_handle=event.evt.gattc_evt.error_handle, attr_handle=hvx_evt.handle, hvx_type=BLEGattHVXType(hvx_evt.type), data=util.uint8_array_to_list(hvx_evt.data, hvx_evt.len))
def from_c(cls, event): read_rsp = event.evt.gattc_evt.params.read_rsp return cls(conn_handle=event.evt.gattc_evt.conn_handle, status=BLEGattStatusCode(event.evt.gattc_evt.gatt_status), error_handle=event.evt.gattc_evt.error_handle, attr_handle=read_rsp.handle, offset=read_rsp.offset, data=util.uint8_array_to_list(read_rsp.data, read_rsp.len))
def from_auth_request(cls, conn_handle, write_event): attr_handle = write_event.handle uuid = BLEUUID.from_c(write_event.uuid) write_operand = BLEGattsWriteOperation(write_event.op) auth_required = bool(write_event.auth_required) offset = write_event.offset data = util.uint8_array_to_list(write_event.data, write_event.len) return cls(conn_handle, attr_handle, uuid, write_operand, auth_required, offset, data)
def from_c(cls, event): write_rsp_evt = event.evt.gattc_evt.params.write_rsp return cls(conn_handle=event.evt.gattc_evt.conn_handle, status=BLEGattStatusCode(event.evt.gattc_evt.gatt_status), error_handle=event.evt.gattc_evt.error_handle, attr_handle=write_rsp_evt.handle, write_op=BLEGattWriteOperation(write_rsp_evt.write_op), offset=write_rsp_evt.offset, data=util.uint8_array_to_list(write_rsp_evt.data, write_rsp_evt.len))
def from_c(cls, adv_report_evt): ad_list = util.uint8_array_to_list(adv_report_evt.data, adv_report_evt.dlen) ble_adv_data = cls() index = 0 while index < len(ad_list): ad_len = ad_list[index] try: ad_type = ad_list[index + 1] offset = index + 2 key = BLEAdvData.Types(ad_type) ble_adv_data.records[key] = ad_list[offset:offset + ad_len - 1] except ValueError: logger.error( 'Invalid advertising data type: 0x{:02X}'.format(ad_type)) pass except IndexError: logger.error('Invalid advertising data: {}'.format(ad_list)) return ble_adv_data index += (ad_len + 1) return ble_adv_data
def from_c(cls, params): offset = params.offset value = bytearray(util.uint8_array_to_list(params.p_value, params.len)) return cls(value, offset)
def from_c(cls, gattc_write_params): return cls(write_op=BLEGattWriteOperation(gattc_write_params.write_op), flags=gattc_write_params.flags, handle=gattc_write_params.handle, data=util.uint8_array_to_list(gattc_write_params.p_value, gattc_write_params.len))
def from_c(cls, key): key_data = bytearray(util.uint8_array_to_list(key.csrk, cls.KEY_LENGTH)) return cls(key_data)
def from_c(cls, id_key): irk = bytearray( util.uint8_array_to_list(id_key.id_info.irk, cls.KEY_LENGTH)) addr = BLEGapAddr.from_c(id_key.id_addr_info) return cls(irk, addr)
def from_c(cls, info): ltk = bytearray(util.uint8_array_to_list(info.ltk, cls.KEY_LENGTH)) lesc = info.lesc auth = info.auth return cls(ltk, lesc, auth)
def from_c(cls, master_id): rand = bytearray(util.uint8_array_to_list(master_id.rand, cls.RAND_LEN)) ediv = master_id.ediv return cls(ediv, rand)
def from_c(cls, addr): addr_list = util.uint8_array_to_list(addr.addr, driver.BLE_GAP_ADDR_LEN) addr_list.reverse() return cls(addr_type=BLEGapAddrTypes(addr.addr_type), addr=addr_list)
def from_uuid128(cls, uuid128): uuid = util.uint8_array_to_list(uuid128.uuid, 16) return cls.from_array(uuid)