我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用socket.HCI_FILTER。
def __init__(self, iface=0x10000, type=None): s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI) s.setsockopt(socket.SOL_HCI, socket.HCI_DATA_DIR,1) s.setsockopt(socket.SOL_HCI, socket.HCI_TIME_STAMP,1) s.setsockopt(socket.SOL_HCI, socket.HCI_FILTER, struct.pack("IIIh2x", 0xffffffffL,0xffffffffL,0xffffffffL,0)) #type mask, event mask, event mask, opcode s.bind((iface,)) self.ins = self.outs = s # s.connect((peer,0))
def set_filter(self, data): self._socket.setsockopt(socket.SOL_HCI, socket.HCI_FILTER, data)
def __init__(self, iface=0x10000, type=None): s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI) s.setsockopt(socket.SOL_HCI, socket.HCI_DATA_DIR,1) s.setsockopt(socket.SOL_HCI, socket.HCI_TIME_STAMP,1) s.setsockopt(socket.SOL_HCI, socket.HCI_FILTER, struct.pack("IIIh2x", 0xffffffff,0xffffffff,0xffffffff,0)) #type mask, event mask, event mask, opcode s.bind((iface,)) self.ins = self.outs = s # s.connect((peer,0))
def create_bt_socket(interface=0): exceptions = [] sock = None try: sock = socket.socket(family=socket.AF_BLUETOOTH, type=socket.SOCK_RAW, proto=socket.BTPROTO_HCI) sock.setblocking(False) sock.setsockopt(socket.SOL_HCI, socket.HCI_FILTER, pack("IIIh2x", 0xffffffff,0xffffffff,0xffffffff,0)) #type mask, event mask, event mask, opcode try: sock.bind((interface,)) except OSError as exc: exc = OSError( exc.errno, 'error while attempting to bind on ' 'interface {!r}: {}'.format( interface, exc.strerror)) exceptions.append(exc) except OSError as exc: if sock is not None: sock.close() exceptions.append(exc) except: if sock is not None: sock.close() raise if len(exceptions) == 1: raise exceptions[0] elif len(exceptions) > 1: model = str(exceptions[0]) if all(str(exc) == model for exc in exceptions): raise exceptions[0] raise OSError('Multiple exceptions: {}'.format( ', '.join(str(exc) for exc in exceptions))) return sock ###########