当前位置: 首页>>代码示例>>Python>>正文


Python socket.BTPROTO_HCI属性代码示例

本文整理汇总了Python中socket.BTPROTO_HCI属性的典型用法代码示例。如果您正苦于以下问题:Python socket.BTPROTO_HCI属性的具体用法?Python socket.BTPROTO_HCI怎么用?Python socket.BTPROTO_HCI使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在socket的用法示例。


在下文中一共展示了socket.BTPROTO_HCI属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: open_dev

# 需要导入模块: import socket [as 别名]
# 或者: from socket import BTPROTO_HCI [as 别名]
def open_dev(bt_device_id):
    """Open hci device socket."""
    # pylint: disable=no-member
    sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI)

    # Unlike Linux, FreeBSD has separate numbering depending on hardware
    # (ubt - USB bluetooth - is the most common, so convert numbers to that)
    if not isinstance(bt_device_id, str):
        bt_device_id = 'ubt{}hci'.format(bt_device_id)

    # Python's BTPROTO_HCI address parsing is busted: https://bugs.python.org/issue41130
    adr = SockaddrHci(ctypes.sizeof(SockaddrHci), socket.AF_BLUETOOTH, bt_device_id.ljust(32, '\0').encode('utf-8'))
    if libc.bind(sock.fileno(), ctypes.pointer(adr), ctypes.sizeof(SockaddrHci)) != 0:
        raise ConnectionError(ctypes.get_errno(), os.strerror(ctypes.get_errno()))
    if libc.connect(sock.fileno(), ctypes.pointer(adr), ctypes.sizeof(SockaddrHci)) != 0:
        raise ConnectionError(ctypes.get_errno(), os.strerror(ctypes.get_errno()))
    # pylint: enable=no-member

    fltr = HciRawFilter(0, NG_HCI_EVENT_MASK_LE)
    if libc.setsockopt(sock.fileno(),
                       SOL_HCI_RAW, SOL_HCI_RAW_FILTER,
                       ctypes.pointer(fltr), ctypes.sizeof(HciRawFilter)) != 0:
        raise ConnectionError(ctypes.get_errno(), os.strerror(ctypes.get_errno()))

    return sock 
开发者ID:citruz,项目名称:beacontools,代码行数:27,代码来源:freebsd.py

示例2: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import BTPROTO_HCI [as 别名]
def __init__(self, device_id=0):
        self.device_id = device_id
        self._keep_running = True
        self._socket = None
        self._socket_on_data_user_callback = None
        self._socket_on_started = None
        self._socket_poll_thread = None
        self._l2sockets = {}

        self._socket = BluetoothSocket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI)
        
    
        #self._socket = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI)
        #self._socket = BluetoothUserSocket()
        #self._socket = bluetooth.bluez._gethcisock(0)

        self._socket.setblocking(0)
        self.__r, self.__w = os.pipe()
        self._r = os.fdopen(self.__r, 'rU')
        self._w = os.fdopen(self.__w, 'w') 
开发者ID:Adam-Langley,项目名称:pybleno,代码行数:22,代码来源:BluetoothHCI.py

示例3: hci_devinfo

# 需要导入模块: import socket [as 别名]
# 或者: from socket import BTPROTO_HCI [as 别名]
def hci_devinfo(adapter=0):
    # Get Bluetooth device information
    # Takes an adapter number, returns raw data from ioctl
    # FIXME(MR) this function is a complete hack
    # but Python doesn't even dream of offering Bluetooth ioctl's
    dd = BluetoothSocket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI)
    dev_info = struct.pack('<H', adapter) + "\x00" * 90
    try:
        r = fcntl.ioctl(dd, 0x800448d3, dev_info) # HCIGETDEVINFO, tested on x64 Linux only
        return r
    except IOError as e:
        # XXX is there a more Pythonic way of doing this?
        if e[0] == 19:
            raise TypeError("No such Bluetooth adapter")
        else:
            raise e 
开发者ID:Adam-Langley,项目名称:pybleno,代码行数:18,代码来源:BluetoothSocket.py

示例4: create_bt_socket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import BTPROTO_HCI [as 别名]
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

########### 
开发者ID:frawau,项目名称:aioblescan,代码行数:38,代码来源:aioblescan.py

示例5: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import BTPROTO_HCI [as 别名]
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)) 
开发者ID:medbenali,项目名称:CyberScan,代码行数:10,代码来源:bluetooth.py

示例6: toggle_device

# 需要导入模块: import socket [as 别名]
# 或者: from socket import BTPROTO_HCI [as 别名]
def toggle_device(dev_id, enable):
    """
    Power ON or OFF a bluetooth device.

    :param dev_id: Device id.
    :type dev_id: ``int``
    :param enable: Whether to enable of disable the device.
    :type enable: ``bool``
    """
    hci_sock = socket.socket(socket.AF_BLUETOOTH,
                             socket.SOCK_RAW,
                             socket.BTPROTO_HCI)
    # print("Power %s bluetooth device %d" % ('ON' if enable else 'OFF', dev_id))
    # di = struct.pack("HbBIBBIIIHHHH10I", dev_id, *((0,) * 22))
    # fcntl.ioctl(hci_sock.fileno(), bluez.HCIGETDEVINFO, di)
    req_str = struct.pack("H", dev_id)
    request = array.array("b", req_str)
    try:
        fcntl.ioctl(hci_sock.fileno(),
                    bluez.HCIDEVUP if enable else bluez.HCIDEVDOWN,
                    request[0])
    except IOError as e:
        if e.errno == EALREADY:
            pass
            # print("Bluetooth device %d is already %s" % (
            #       dev_id, 'enabled' if enable else 'disabled'))
        else:
            raise
    finally:
        hci_sock.close()


# Types of bluetooth scan 
开发者ID:hexway,项目名称:apple_bleee,代码行数:35,代码来源:bluetooth_utils.py

示例7: set_scan

# 需要导入模块: import socket [as 别名]
# 或者: from socket import BTPROTO_HCI [as 别名]
def set_scan(dev_id, scan_type):
    """
    Set scan type on a given bluetooth device.

    :param dev_id: Device id.
    :type dev_id: ``int``
    :param scan_type: One of
        ``'noscan'``
        ``'iscan'``
        ``'pscan'``
        ``'piscan'``
    :type scan_type: ``str``
    """
    hci_sock = socket.socket(socket.AF_BLUETOOTH,
                             socket.SOCK_RAW,
                             socket.BTPROTO_HCI)
    if scan_type == "noscan":
        dev_opt = SCAN_DISABLED
    elif scan_type == "iscan":
        dev_opt = SCAN_INQUIRY
    elif scan_type == "pscan":
        dev_opt = SCAN_PAGE
    elif scan_type == "piscan":
        dev_opt = SCAN_PAGE | SCAN_INQUIRY
    else:
        raise ValueError("Unknown scan type %r" % scan_type)

    req_str = struct.pack("HI", dev_id, dev_opt)
    # print("Set scan type %r to bluetooth device %d" % (scan_type, dev_id))
    try:
        fcntl.ioctl(hci_sock.fileno(), bluez.HCISETSCAN, req_str)
    finally:
        hci_sock.close() 
开发者ID:hexway,项目名称:apple_bleee,代码行数:35,代码来源:bluetooth_utils.py

示例8: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import BTPROTO_HCI [as 别名]
def __init__(self, iface=0x10000, type=None):
        if WINDOWS:
            warning("Not available on Windows")
            return
        s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI)  # noqa: E501
        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  # noqa: E501
        s.bind((iface,))
        self.ins = self.outs = s
#        s.connect((peer,0)) 
开发者ID:secdev,项目名称:scapy,代码行数:13,代码来源:bluetooth.py

示例9: toggle_device

# 需要导入模块: import socket [as 别名]
# 或者: from socket import BTPROTO_HCI [as 别名]
def toggle_device(dev_id, enable):
    """
    Power ON or OFF a bluetooth device.

    :param dev_id: Device id.
    :type dev_id: ``int``
    :param enable: Whether to enable of disable the device.
    :type enable: ``bool``
    """
    hci_sock = socket.socket(socket.AF_BLUETOOTH,
                             socket.SOCK_RAW,
                             socket.BTPROTO_HCI)
    print("Power %s bluetooth device %d" % ('ON' if enable else 'OFF', dev_id))
    # di = struct.pack("HbBIBBIIIHHHH10I", dev_id, *((0,) * 22))
    # fcntl.ioctl(hci_sock.fileno(), bluez.HCIGETDEVINFO, di)
    req_str = struct.pack("H", dev_id)
    request = array.array("b", req_str)
    try:
        fcntl.ioctl(hci_sock.fileno(),
                    bluez.HCIDEVUP if enable else bluez.HCIDEVDOWN,
                    request[0])
    except IOError as e:
        if e.errno == EALREADY:
            print("Bluetooth device %d is already %s" % (
                  dev_id, 'enabled' if enable else 'disabled'))
        else:
            raise
    finally:
        hci_sock.close()


# Types of bluetooth scan 
开发者ID:colin-guyon,项目名称:py-bluetooth-utils,代码行数:34,代码来源:bluetooth_utils.py

示例10: set_scan

# 需要导入模块: import socket [as 别名]
# 或者: from socket import BTPROTO_HCI [as 别名]
def set_scan(dev_id, scan_type):
    """
    Set scan type on a given bluetooth device.

    :param dev_id: Device id.
    :type dev_id: ``int``
    :param scan_type: One of
        ``'noscan'``
        ``'iscan'``
        ``'pscan'``
        ``'piscan'``
    :type scan_type: ``str``
    """
    hci_sock = socket.socket(socket.AF_BLUETOOTH,
                             socket.SOCK_RAW,
                             socket.BTPROTO_HCI)
    if scan_type == "noscan":
        dev_opt = SCAN_DISABLED
    elif scan_type == "iscan":
        dev_opt = SCAN_INQUIRY
    elif scan_type == "pscan":
        dev_opt = SCAN_PAGE
    elif scan_type == "piscan":
        dev_opt = SCAN_PAGE | SCAN_INQUIRY
    else:
        raise ValueError("Unknown scan type %r" % scan_type)

    req_str = struct.pack("HI", dev_id, dev_opt)
    print("Set scan type %r to bluetooth device %d" % (scan_type, dev_id))
    try:
        fcntl.ioctl(hci_sock.fileno(), bluez.HCISETSCAN, req_str)
    finally:
        hci_sock.close() 
开发者ID:colin-guyon,项目名称:py-bluetooth-utils,代码行数:35,代码来源:bluetooth_utils.py

示例11: bind_l2

# 需要导入模块: import socket [as 别名]
# 或者: from socket import BTPROTO_HCI [as 别名]
def bind_l2(self, psm, bdaddr, cid=0, addr_type=BDAddr.TYPE_BREDR):
        sa_str = self._sockaddr_l2(psm, bdaddr, cid, addr_type)
        self._bind(sa_str)

    # bind to BTPROTO_HCI socket 
开发者ID:Adam-Langley,项目名称:pybleno,代码行数:7,代码来源:BluetoothSocket.py

示例12: connect_l2

# 需要导入模块: import socket [as 别名]
# 或者: from socket import BTPROTO_HCI [as 别名]
def connect_l2(self, psm, bdaddr, cid=0, addr_type=BDAddr.TYPE_BREDR):
        sa_str = self._sockaddr_l2(psm, bdaddr, cid, addr_type)
        self._connect(sa_str)

    # connect to BTPROTO_HCI socket 
开发者ID:Adam-Langley,项目名称:pybleno,代码行数:7,代码来源:BluetoothSocket.py

示例13: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import BTPROTO_HCI [as 别名]
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)) 
开发者ID:phaethon,项目名称:kamene,代码行数:10,代码来源:bluetooth.py

示例14: open

# 需要导入模块: import socket [as 别名]
# 或者: from socket import BTPROTO_HCI [as 别名]
def open(self):
        self._socket = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI)
        self._socket.bind((self.device_id,))
        self._socket_poll_thread = threading.Thread(target=self._socket_poller, name='HCISocketPoller')
        self._socket_poll_thread.setDaemon(True)
        self._socket_poll_thread.start()
        self.device = self.get_device_info() 
开发者ID:TheCellule,项目名称:python-bleson,代码行数:9,代码来源:linux_adapter.py


注:本文中的socket.BTPROTO_HCI属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。