本文整理匯總了Python中bluetooth._bluetooth.HCI_FILTER屬性的典型用法代碼示例。如果您正苦於以下問題:Python _bluetooth.HCI_FILTER屬性的具體用法?Python _bluetooth.HCI_FILTER怎麽用?Python _bluetooth.HCI_FILTER使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類bluetooth._bluetooth
的用法示例。
在下文中一共展示了_bluetooth.HCI_FILTER屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_connection_cancel
# 需要導入模塊: from bluetooth import _bluetooth [as 別名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 別名]
def create_connection_cancel(self, cmd_params:dict) -> dict:
'''
cmd_params -- {
'BD_ADDR': str
}
'''
dd = hci_open_dev(self.devid)
bin_cmd_params = bytes.fromhex(cmd_params['BD_ADDR'].replace(':', '')[::-1])
flt = hci_filter_new()
hci_filter_set_ptype(flt, HCI_EVENT_PKT)
hci_filter_set_event(flt, EVT_CMD_COMPLETE)
hci_filter_set_opcode(
flt, cmd_opcode_pack(OGF_LINK_CTL, OCF_CREATE_CONN_CANCEL))
dd.setsockopt(SOL_HCI, HCI_FILTER, flt)
hci_send_cmd(dd, OGF_LINK_CTL, OCF_CREATE_CONN_CANCEL, bin_cmd_params)
event_params = dd.recv(3+EVT_CMD_COMPLETE_SIZE+7)[3:]
num_hci_cmd_pkts, cmd_opcode, status, \
bdaddr = struct.unpack('<BHB6s', event_params)
hci_close_dev(dd.fileno())
return event_params
示例2: reset
# 需要導入模塊: from bluetooth import _bluetooth [as 別名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 別名]
def reset(self) -> dict:
dd = hci_open_dev(self.devid)
flt = hci_filter_new()
hci_filter_set_ptype(flt, HCI_EVENT_PKT)
hci_filter_set_event(flt, EVT_CMD_COMPLETE)
hci_filter_set_opcode(flt, cmd_opcode_pack(OGF_HOST_CTL, OCF_RESET))
dd.setsockopt(SOL_HCI, HCI_FILTER, flt)
hci_send_cmd(dd, OGF_HOST_CTL, OCF_RESET)
event_params = dd.recv(3+EVT_CMD_COMPLETE_SIZE+1)[3:]
num_hci_cmd_pkts, cmd_opcode, status = struct.unpack('<BHB', event_params)
event_params = {
'Num_HCI_Command_Packets': num_hci_cmd_pkts,
'Command_Opcode': cmd_opcode,
'Status': status
}
hci_close_dev(dd.fileno())
return event_params
示例3: write_scan_enable
# 需要導入模塊: from bluetooth import _bluetooth [as 別名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 別名]
def write_scan_enable(self, cmd_params={'Scan_Enable': 0x00}) -> dict:
dd = hci_open_dev(self.devid)
bin_cmd_params = cmd_params['Scan_Enable'].to_bytes(1, 'little')
flt = hci_filter_new()
hci_filter_set_ptype(flt, HCI_EVENT_PKT)
hci_filter_set_event(flt, EVT_CMD_COMPLETE)
hci_filter_set_opcode(
flt, cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE))
dd.setsockopt(SOL_HCI, HCI_FILTER, flt)
hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE, bin_cmd_params)
event_params = dd.recv(3+EVT_CMD_COMPLETE_SIZE+1)[3:]
num_hci_cmd_pkts, cmd_opcode, status = struct.unpack('<BHB', event_params)
event_params = {
'Num_HCI_Command_Packets': num_hci_cmd_pkts,
'Command_Opcode': cmd_opcode,
'Status': status
}
hci_close_dev(dd.fileno())
return event_params
示例4: write_inquiry_mode
# 需要導入模塊: from bluetooth import _bluetooth [as 別名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 別名]
def write_inquiry_mode(self, cmd_params={'Inquiry_Mode': 0x00}) -> dict:
dd = hci_open_dev(self.devid)
bin_cmd_params = cmd_params['Inquiry_Mode'].to_bytes(1, 'little')
flt = hci_filter_new()
hci_filter_set_ptype(flt, HCI_EVENT_PKT)
hci_filter_set_event(flt, EVT_CMD_COMPLETE)
hci_filter_set_opcode(
flt, cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_INQUIRY_MODE))
dd.setsockopt(SOL_HCI, HCI_FILTER, flt)
hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_INQUIRY_MODE, bin_cmd_params)
event_params = dd.recv(3+EVT_CMD_COMPLETE_SIZE+1)[3:]
num_hci_cmd_pkts, cmd_opcode, status = struct.unpack('<BHB', event_params)
event_params = {
'Num_HCI_Command_Packets': num_hci_cmd_pkts,
'Command_Opcode': cmd_opcode,
'Status': status
}
hci_close_dev(dd.fileno())
return event_params
示例5: read_page_timeout
# 需要導入模塊: from bluetooth import _bluetooth [as 別名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 別名]
def read_page_timeout(self) -> dict:
dd = hci_open_dev(self.devid)
flt = hci_filter_new()
hci_filter_set_ptype(flt, HCI_EVENT_PKT)
hci_filter_set_event(flt, EVT_CMD_COMPLETE)
hci_filter_set_opcode(
flt, cmd_opcode_pack(OGF_HOST_CTL, OCF_READ_PAGE_TIMEOUT))
dd.setsockopt(SOL_HCI, HCI_FILTER, flt)
hci_send_cmd(dd, OGF_HOST_CTL, OCF_READ_PAGE_TIMEOUT)
event_params = dd.recv(3+EVT_CMD_COMPLETE_SIZE+3)[3:]
num_hci_cmd_pkts, cmd_opcode, status, page_timeout = struct.unpack('<BHBH', event_params)
event_params = {
'Num_HCI_Command_Packets': num_hci_cmd_pkts,
'Command_Opcode': cmd_opcode,
'Status': status,
'Page_Timeout': page_timeout
}
hci_close_dev(dd.fileno())
return event_params
示例6: write_page_timeout
# 需要導入模塊: from bluetooth import _bluetooth [as 別名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 別名]
def write_page_timeout(self, cmd_params={'Page_Timeout': 0x2000}) -> dict:
dd = hci_open_dev(self.devid)
bin_cmd_params = cmd_params['Page_Timeout'].to_bytes(2, 'little')
flt = hci_filter_new()
hci_filter_set_ptype(flt, HCI_EVENT_PKT)
hci_filter_set_event(flt, EVT_CMD_COMPLETE)
hci_filter_set_opcode(
flt, cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_PAGE_TIMEOUT))
dd.setsockopt(SOL_HCI, HCI_FILTER, flt)
hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_PAGE_TIMEOUT, bin_cmd_params)
event_params = dd.recv(3+EVT_CMD_COMPLETE_SIZE+3)[3:]
num_hci_cmd_pkts, cmd_opcode, status = struct.unpack('<BHB', event_params)
event_params = {
'Num_HCI_Command_Packets': num_hci_cmd_pkts,
'Command_Opcode': cmd_opcode,
'Status': status
}
hci_close_dev(dd.fileno())
return event_params
示例7: write_authentication_enable
# 需要導入模塊: from bluetooth import _bluetooth [as 別名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 別名]
def write_authentication_enable(self, cmd_params={'Authentication_Enable': 0x00}) -> dict:
dd = hci_open_dev(self.devid)
bin_cmd_params = cmd_params['Authentication_Enable'].to_bytes(1, 'little')
flt = hci_filter_new()
hci_filter_set_ptype(flt, HCI_EVENT_PKT)
hci_filter_set_event(flt, EVT_CMD_COMPLETE)
hci_filter_set_opcode(
flt, cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_AUTH_ENABLE))
dd.setsockopt(SOL_HCI, HCI_FILTER, flt)
hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_AUTH_ENABLE, bin_cmd_params)
event_params = dd.recv(3+EVT_CMD_COMPLETE_SIZE+3)[3:]
num_hci_cmd_pkts, cmd_opcode, status = struct.unpack('<BHB', event_params)
event_params = {
'Num_HCI_Command_Packets': num_hci_cmd_pkts,
'Command_Opcode': cmd_opcode,
'Status': status
}
hci_close_dev(dd.fileno())
return event_params
示例8: read_class_of_device
# 需要導入模塊: from bluetooth import _bluetooth [as 別名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 別名]
def read_class_of_device(self) -> dict:
dd = hci_open_dev(self.devid)
flt = hci_filter_new()
hci_filter_set_ptype(flt, HCI_EVENT_PKT)
hci_filter_set_event(flt, EVT_CMD_COMPLETE)
hci_filter_set_opcode(
flt, cmd_opcode_pack(OGF_HOST_CTL, OCF_READ_CLASS_OF_DEV))
dd.setsockopt(SOL_HCI, HCI_FILTER, flt)
hci_send_cmd(dd, OGF_HOST_CTL, OCF_READ_CLASS_OF_DEV)
event_params = dd.recv(3+HCI_MAX_EVENT_SIZE)[3:]
num_hci_cmd_pkts, cmd_opcode, status, cod = struct.unpack('<BHB3s', event_params)
event_params = {
'Num_HCI_Command_Packets': num_hci_cmd_pkts,
'Command_Opcode': cmd_opcode,
'Status': status,
'Class_Of_Device': cod[::-1]
}
hci_close_dev(dd.fileno())
return event_params
示例9: le_set_advertising_enable
# 需要導入模塊: from bluetooth import _bluetooth [as 別名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 別名]
def le_set_advertising_enable(self, cmd_params={'Advertising_Enable': 0x00}) -> dict:
dd = hci_open_dev(self.devid)
bin_cmd_params = cmd_params['Advertising_Enable'].to_bytes(1, 'little')
flt = hci_filter_new()
hci_filter_set_ptype(flt, HCI_EVENT_PKT)
hci_filter_set_event(flt, EVT_CMD_COMPLETE)
hci_filter_set_opcode(
flt, cmd_opcode_pack(OGF_LE_CTL, OCF_LE_SET_ADVERTISING_ENABLE))
dd.setsockopt(SOL_HCI, HCI_FILTER, flt)
hci_send_cmd(dd, OGF_LE_CTL, OCF_LE_SET_ADVERTISING_ENABLE, bin_cmd_params)
event_params = dd.recv(3+EVT_CMD_COMPLETE_SIZE+1)[3:]
num_hci_cmd_pkts, cmd_opcode, status = struct.unpack('<BHB', event_params)
event_params = {
'Num_HCI_Command_Packets': num_hci_cmd_pkts,
'Command_Opcode': cmd_opcode,
'Status': status
}
hci_close_dev(dd.fileno())
return event_params
示例10: set_bt_name
# 需要導入模塊: from bluetooth import _bluetooth [as 別名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 別名]
def set_bt_name(payload, src_hci, src, dst):
# Create raw HCI sock to set our BT name
raw_sock = bt.hci_open_dev(bt.hci_devid(src_hci))
flt = bt.hci_filter_new()
bt.hci_filter_all_ptypes(flt)
bt.hci_filter_all_events(flt)
raw_sock.setsockopt(bt.SOL_HCI, bt.HCI_FILTER, flt)
# Send raw HCI command to our controller to change the BT name (first 3 bytes are padding for alignment)
raw_sock.sendall(binascii.unhexlify('01130cf8cccccc') + payload.ljust(MAX_BT_NAME, b'\x00'))
raw_sock.close()
#time.sleep(1)
time.sleep(0.1)
# Connect to BNEP to "refresh" the name (does auth)
bnep = bluetooth.BluetoothSocket(bluetooth.L2CAP)
bnep.bind((src, 0))
bnep.connect((dst, BNEP_PSM))
bnep.close()
# Close ACL connection
os.system('hcitool dc %s' % (dst,))
#time.sleep(1)
示例11: read_local_bdaddr
# 需要導入模塊: from bluetooth import _bluetooth [as 別名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 別名]
def read_local_bdaddr(hci_sock):
old_filter = hci_sock.getsockopt( _bt.SOL_HCI, _bt.HCI_FILTER, 14)
flt = _bt.hci_filter_new()
opcode = _bt.cmd_opcode_pack(_bt.OGF_INFO_PARAM,
_bt.OCF_READ_BD_ADDR)
_bt.hci_filter_set_ptype(flt, _bt.HCI_EVENT_PKT)
_bt.hci_filter_set_event(flt, _bt.EVT_CMD_COMPLETE);
_bt.hci_filter_set_opcode(flt, opcode)
hci_sock.setsockopt( _bt.SOL_HCI, _bt.HCI_FILTER, flt )
_bt.hci_send_cmd(hci_sock, _bt.OGF_INFO_PARAM, _bt.OCF_READ_BD_ADDR )
pkt = hci_sock.recv(255)
status,raw_bdaddr = struct.unpack("xxxxxxB6s", pkt)
assert status == 0
t = [ "%X" % ord(b) for b in raw_bdaddr ]
t.reverse()
bdaddr = ":".join(t)
# restore old filter
hci_sock.setsockopt( _bt.SOL_HCI, _bt.HCI_FILTER, old_filter )
return bdaddr
示例12: inquiry_cancel
# 需要導入模塊: from bluetooth import _bluetooth [as 別名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 別名]
def inquiry_cancel(self) -> dict:
'''
Return -- {
'Num_HCI_Command_Packets': int,
'Command_Opcode': int,
'Status': int
}
'''
dd = hci_open_dev(self.devid)
flt = hci_filter_new()
hci_filter_set_ptype(flt, HCI_EVENT_PKT)
hci_filter_set_event(flt, EVT_CMD_COMPLETE)
hci_filter_set_opcode(
flt, cmd_opcode_pack(OGF_LINK_CTL, OCF_INQUIRY_CANCEL))
dd.setsockopt(SOL_HCI, HCI_FILTER, flt)
hci_send_cmd(dd, OGF_LINK_CTL, OCF_INQUIRY_CANCEL)
event_params = dd.recv(3+EVT_CMD_COMPLETE_SIZE+1)[3:]
num_hci_cmd_pkts, cmd_opcode, status = struct.unpack('<BHB', event_params)
event_params = {
'Num_HCI_Command_Packets': num_hci_cmd_pkts,
'Command_Opcode': cmd_opcode,
'Status': status
}
hci_close_dev(dd.fileno())
return event_params
示例13: exit_periodic_inquiry_mode
# 需要導入模塊: from bluetooth import _bluetooth [as 別名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 別名]
def exit_periodic_inquiry_mode(self) -> dict:
'''
Return -- {
'Num_HCI_Command_Packets': int,
'Command_Opcode': int,
'Status': int
}
'''
dd = hci_open_dev(self.devid)
flt = hci_filter_new()
hci_filter_set_ptype(flt, HCI_EVENT_PKT)
hci_filter_set_event(flt, EVT_CMD_COMPLETE)
hci_filter_set_opcode(
flt, cmd_opcode_pack(OGF_LINK_CTL, OCF_EXIT_PERIODIC_INQUIRY))
dd.setsockopt(SOL_HCI, HCI_FILTER, flt)
hci_send_cmd(dd, OGF_LINK_CTL, OCF_EXIT_PERIODIC_INQUIRY)
event_params = dd.recv(3+EVT_CMD_COMPLETE_SIZE+1)[3:]
num_hci_cmd_pkts, cmd_opcode, status = struct.unpack('<BHB', event_params)
event_params = {
'Num_HCI_Command_Packets': num_hci_cmd_pkts,
'Command_Opcode': cmd_opcode,
'Status': status
}
hci_close_dev(dd.fileno())
return status
示例14: disconnect
# 需要導入模塊: from bluetooth import _bluetooth [as 別名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 別名]
def disconnect(self, cmd_params:dict) -> dict:
'''
cmd_params -- {
'Connection_Handle': int, 2 bytes,
'Reason': int, 1 bytes
}
'''
dd = hci_open_dev(self.devid)
flt = hci_filter_new()
hci_filter_clear(flt)
hci_filter_set_ptype(flt, HCI_EVENT_PKT)
hci_filter_set_event(flt, EVT_DISCONN_COMPLETE)
dd.setsockopt(SOL_HCI, HCI_FILTER, flt)
bin_cmd_params = cmd_params['Connection_Handle'].to_bytes(2, 'little') + \
cmd_params['Reason'].to_bytes(1, 'little')
hci_send_cmd(dd, OGF_LINK_CTL, OCF_DISCONNECT, bin_cmd_params)
# Receive and exclude HCI packet type (1 B)
event_params = dd.recv(3+EVT_DISCONN_COMPLETE_SIZE)[3:]
status, conn_handle, reason, = struct.unpack(
'<BHB', event_params)
event_params = {
'Status': status,
'Connection_Handle': conn_handle,
'Reason': reason
}
hci_close_dev(dd.fileno())
return event_params
示例15: read_remote_extended_features
# 需要導入模塊: from bluetooth import _bluetooth [as 別名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 別名]
def read_remote_extended_features(self, cmd_params:dict) -> dict:
'''
cmd_params -- {
'Connection_Handle': 0x0000 to 0x0EFF,
'Page_Number': int
}
'''
dd = hci_open_dev(self.devid)
bin_cmd_params = cmd_params[
'Connection_Handle'].to_bytes(2, 'little') + \
cmd_params['Page_Number'].to_bytes(1, 'little')
flt = hci_filter_new()
hci_filter_set_ptype(flt, HCI_EVENT_PKT)
hci_filter_set_event(flt, EVT_READ_REMOTE_EXT_FEATURES_COMPLETE)
dd.setsockopt(SOL_HCI, HCI_FILTER, flt)
hci_send_cmd(dd, OGF_LINK_CTL, OCF_READ_REMOTE_EXT_FEATURES,
bin_cmd_params)
while True:
event_params = dd.recv(3 + \
EVT_READ_REMOTE_EXT_FEATURES_COMPLETE_SIZE)[3:]
status, conn_handle, page_num, max_page_num, ext_lmp_features = \
struct.unpack('<BHBB8s', event_params)
event_params = {
'Status': status,
'Connection_Handle': conn_handle,
'Page_Number': page_num,
'Maximum_Page_Number': max_page_num,
'Extended_LMP_Features': ext_lmp_features
}
if event_params['Connection_Handle'] == cmd_params['Connection_Handle'] and \
event_params['Page_Number'] == cmd_params['Page_Number']:
break
hci_close_dev(dd.fileno())
return event_params