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


Python ubinascii.hexlify方法代码示例

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


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

示例1: subscribe

# 需要导入模块: import ubinascii [as 别名]
# 或者: from ubinascii import hexlify [as 别名]
def subscribe(self, topic, qos=0):
        assert self.cb is not None, "Subscribe callback is not set"
        self.sock.setblocking(True)
        pkt = bytearray(b"\x82\0\0\0")
        self.pid += 1
        struct.pack_into("!BH", pkt, 1, 2 + 2 + len(topic) + 1, self.pid)
        #print(hex(len(pkt)), hexlify(pkt, ":"))
        self.sock.write(pkt)
        self._send_str(topic)
        self.sock.write(qos.to_bytes(1, "little"))
        # print("simple --> wait socket msg")
        while 1:
            op = self.wait_msg()
            if op == 0x90:
                resp = self.sock.read(4)
                #print(resp)
                assert resp[1] == pkt[2] and resp[2] == pkt[3]
                if resp[3] == 0x80:
                    raise MQTTException(resp[3])
                # print("simple --> wait socket finish")                
                return 
开发者ID:m5stack,项目名称:UIFlow-Code,代码行数:23,代码来源:simple.py

示例2: subscribe

# 需要导入模块: import ubinascii [as 别名]
# 或者: from ubinascii import hexlify [as 别名]
def subscribe(self, topic, qos=0):
        assert self.cb is not None, "Subscribe callback is not set"
        pkt = bytearray(b"\x82\0\0\0")
        self.pid += 1
        struct.pack_into("!BH", pkt, 1, 2 + 2 + len(topic) + 1, self.pid)
        #print(hex(len(pkt)), hexlify(pkt, ":"))
        self.sock.write(pkt)
        self._send_str(topic)
        self.sock.write(qos.to_bytes(1))
        while 1:
            op = self.wait_msg()
            if op == 0x90:
                resp = self.sock.read(4)
                #print(resp)
                assert resp[1] == pkt[2] and resp[2] == pkt[3]
                if resp[3] == 0x80:
                    raise MQTTException(resp[3])
                return

    # Wait for a single incoming MQTT message and process it.
    # Subscribed messages are delivered to a callback previously
    # set by .set_callback() method. Other (internal) MQTT
    # messages processed internally. 
开发者ID:ayoy,项目名称:upython-aq-monitor,代码行数:25,代码来源:mqtt.py

示例3: getDeviceDiscovery

# 需要导入模块: import ubinascii [as 别名]
# 或者: from ubinascii import hexlify [as 别名]
def getDeviceDiscovery():
    from pysmartnode import config
    mf = "espressif" if platform in ("esp8266", "esp32", "esp32_LoBo") else "None"
    if platform != "linux":
        import network
        s = network.WLAN(network.STA_IF)
        mac = ',"connections": [["mac", "{!s}"]]'.format(
            ubinascii.hexlify(s.config("mac"), ":").decode())
    else:
        mac = ""
    return DISCOVERY_DEVICE_BASE.format(getDeviceID(),
                                        config.VERSION,
                                        mf,
                                        os.uname().sysname if platform != "linux" else "linux",
                                        config.DEVICE_NAME if config.DEVICE_NAME is not None else getDeviceID(),
                                        mac) 
开发者ID:kevinkk525,项目名称:pysmartnode,代码行数:18,代码来源:sys_vars.py

示例4: _hashlist

# 需要导入模块: import ubinascii [as 别名]
# 或者: from ubinascii import hexlify [as 别名]
def _hashlist(root):
    if root.endswith("/"):
        root = root[0:-1]  # strip slash
    try:
        st = os.stat(root)
    except:
        # print("noaccess",root) - does not exist, so don't print
        return
    if st[0] & 0x4000:  # stat.S_IFDIR
        print("<dir>", root)
        l = os.listdir(root)
        for f in l:
            gc.collect()
            p = root + "/" + f
            _hashlist(p)
    else:
        h = sha256()
        hf = open(root, "rb")
        while True:
            b = hf.read(40)
            if len(b) == 0: break
            h.update(b)
        print(ubinascii.hexlify(h.digest()).decode(), root)
        hf.close() 
开发者ID:ulno,项目名称:ulnoiot-upy,代码行数:26,代码来源:hashlist.py

示例5: subscribe

# 需要导入模块: import ubinascii [as 别名]
# 或者: from ubinascii import hexlify [as 别名]
def subscribe(self, topic, qos=0):
        assert self.cb is not None, "Subscribe callback is not set"
        pkt = bytearray(b"\x82\0\0\0")
        self.pid += 1
        struct.pack_into("!BH", pkt, 1, 2 + 2 + len(topic) + 1, self.pid)
        #print(hex(len(pkt)), hexlify(pkt, ":"))
        self.sock.write(pkt)
        self._send_str(topic)
        self.sock.write(qos.to_bytes(1, "little"))
        while 1:
            op = self.wait_msg()
            if op == 0x90:
                resp = self.sock.read(4)
                #print(resp)
                assert resp[1] == pkt[2] and resp[2] == pkt[3]
                if resp[3] == 0x80:
                    raise MQTTException(resp[3])
                return

    # Wait for a single incoming MQTT message and process it.
    # Subscribed messages are delivered to a callback previously
    # set by .set_callback() method. Other (internal) MQTT
    # messages processed internally. 
开发者ID:digidotcom,项目名称:xbee-micropython,代码行数:25,代码来源:simple.py

示例6: inspect

# 需要导入模块: import ubinascii [as 别名]
# 或者: from ubinascii import hexlify [as 别名]
def inspect(f, nbytes=16):
    import stm
    import array
    import ubinascii
    @micropython.asm_thumb
    def dummy():
        pass
    if type(f) != type(dummy):
        raise ValueError('expecting an inline-assembler function')
    baddr = bytes(array.array('O', [f]))
    addr = baddr[0] | baddr[1] << 8 | baddr[2] << 16 | baddr[3] << 24
    print('function object at: 0x%08x' % addr)
    print('number of args: %u' % stm.mem32[addr + 4])
    code_addr = stm.mem32[addr + 8]
    print('machine code at: 0x%08x' % code_addr)
    print('----------')
    print('import binascii')
    print("with open('code.bin', 'wb') as f:")
    import ubinascii
    hex_str = ubinascii.hexlify(bytearray([stm.mem8[code_addr + i] for i in range(nbytes)]))
    print("    f.write(binascii.unhexlify(%s))" % hex_str)
    print('----------') 
开发者ID:dhylands,项目名称:upy-examples,代码行数:24,代码来源:extract_byte_code.py

示例7: auth_mode_nvs_key

# 需要导入模块: import ubinascii [as 别名]
# 或者: from ubinascii import hexlify [as 别名]
def auth_mode_nvs_key(self, ssid):
        """Hack to get a short representation of a WiFi SSID in order to
        squeeze it into a NVRAM key with a maximum length of 15 characters.
        
        Fixme: Review this.

        :param ssid: 

        """
        import hashlib
        import ubinascii
        try:
            hashfun = hashlib.sha512
        except AttributeError:
            hashfun = hashlib.sha256
        digest = ubinascii.hexlify(hashfun(ssid).digest()).decode()
        identifier = 'wa.{}'.format(digest[15:27])
        return identifier 
开发者ID:hiveeyes,项目名称:terkin-datalogger,代码行数:20,代码来源:wifi.py

示例8: encode_ieee11073

# 需要导入模块: import ubinascii [as 别名]
# 或者: from ubinascii import hexlify [as 别名]
def encode_ieee11073(value, precision=2):
    """Binary representation of float value as IEEE-11073:20601 32-bit FLOAT for
    implementing the BLE GATT "Temperature Measurement 2A1C" characteristic.

    -- https://community.hiveeyes.org/t/convenient-ble-gatts-ess-with-micropython/2413/3

    print('Adding Temperature Measurement')
    payload = bytearray([0b00000000]) + float_ieee11073(42.42)
    service.characteristic(uuid=0x2A1C, value=payload)

    :param value:
    :param precision:  (Default value = 2)

    >>> ubinascii.hexlify(encode_ieee11073(42.42))
    b'921000fe'
    """

    # FIXME: Sanity checks dearly required.
    return int(value * (10 ** precision)).to_bytes(3, 'little', True) + pack('<b', -precision) 
开发者ID:hiveeyes,项目名称:terkin-datalogger,代码行数:21,代码来源:util.py

示例9: get

# 需要导入模块: import ubinascii [as 别名]
# 或者: from ubinascii import hexlify [as 别名]
def get(self, filename):
        """Retrieve the contents of the specified file and return its contents
        as a byte string.
        """
        # Open the file and read it a few bytes at a time and print out the
        # raw bytes.  Be careful not to overload the UART buffer so only write
        # a few bytes at a time, and don't use print since it adds newlines and
        # expects string data.
        command = """
            import sys
            import ubinascii
            with open('{0}', 'rb') as infile:
                while True:
                    result = infile.read({1})
                    if result == b'':
                        break
                    len = sys.stdout.write(ubinascii.hexlify(result))
        """.format(
            filename, BUFFER_SIZE
        )
        self._pyboard.enter_raw_repl()
        try:
            out = self._pyboard.exec_(textwrap.dedent(command))
        except PyboardError as ex:
            # Check if this is an OSError #2, i.e. file doesn't exist and
            # rethrow it as something more descriptive.
            try:
                if ex.args[2].decode("utf-8").find("OSError: [Errno 2] ENOENT") != -1:
                    raise RuntimeError("No such file: {0}".format(filename))
                else:
                    raise ex
            except UnicodeDecodeError:
                raise ex
        self._pyboard.exit_raw_repl()
        return binascii.unhexlify(out) 
开发者ID:scientifichackers,项目名称:ampy,代码行数:37,代码来源:files.py

示例10: get_eui

# 需要导入模块: import ubinascii [as 别名]
# 或者: from ubinascii import hexlify [as 别名]
def get_eui():
    id = ubinascii.hexlify(unique_id()).decode()
    return mac2eui(id) 
开发者ID:Wei1234c,项目名称:SX127x_driver_for_MicroPython_on_ESP8266,代码行数:5,代码来源:oled_test.py

示例11: __init__

# 需要导入模块: import ubinascii [as 别名]
# 或者: from ubinascii import hexlify [as 别名]
def __init__(self, channel, config):
        self.channel = channel
        self.subscriptions = {}
        # Config defaults:
        # 4 repubs, delay of 10 secs between (response_time).
        # Initially clean session.
        config['subs_cb'] = self.subs_cb
        config['wifi_coro'] = self.wifi_han
        config['connect_coro'] = self.conn_han
        config['client_id'] = ubinascii.hexlify(unique_id())
        super().__init__(config)

    # Get NTP time or 0 on any error. 
开发者ID:peterhinch,项目名称:micropython-mqtt,代码行数:15,代码来源:mqtt.py

示例12: cam_write_register_set

# 需要导入模块: import ubinascii [as 别名]
# 或者: from ubinascii import hexlify [as 别名]
def cam_write_register_set(i, addr, set):
    for el in set:
        raddr = el[0]
        val = bytes([el[1]])
        if (raddr == 0xff and val == b'\xff'):
            return
        #print("writing byte %s to addr %x register addr %x" % \
        #   (ubinascii.hexlify(val), addr, raddr))
        i.writeto_mem(addr, raddr, val) 
开发者ID:namato,项目名称:micropython-ov2640,代码行数:11,代码来源:ov2640.py

示例13: cam_spi_write

# 需要导入模块: import ubinascii [as 别名]
# 或者: from ubinascii import hexlify [as 别名]
def cam_spi_write(address, value, hspi, cspin):
    cspin.off()
    modebit = b'\x80'
    d = bytes([address[0] | modebit[0], value[0]])
    #print("bytes %s" % ubinascii.hexlify(d))
    #print (ubd.hex())
    hspi.write(d)
    cspin.on() 
开发者ID:namato,项目名称:micropython-ov2640,代码行数:10,代码来源:ov2640.py

示例14: publish

# 需要导入模块: import ubinascii [as 别名]
# 或者: from ubinascii import hexlify [as 别名]
def publish(self, topic, msg, retain=False, qos=0):
        pkt = bytearray(b"\x30\0\0\0")
        pkt[0] |= qos << 1 | retain
        sz = 2 + len(topic) + len(msg)
        if qos > 0:
            sz += 2
        assert sz < 2097152
        i = 1
        while sz > 0x7f:
            pkt[i] = (sz & 0x7f) | 0x80
            sz >>= 7
            i += 1
        pkt[i] = sz
        #print(hex(len(pkt)), hexlify(pkt, ":"))
        self.sock.write(pkt, i + 1)
        self._send_str(topic)
        if qos > 0:
            self.pid += 1
            pid = self.pid
            struct.pack_into("!H", pkt, 0, pid)
            self.sock.write(pkt, 2)
        self.sock.write(msg)
        if qos == 1:
            while 1:
                op = self.wait_msg()
                if op == 0x40:
                    sz = self.sock.read(1)
                    assert sz == b"\x02"
                    rcv_pid = self.sock.read(2)
                    rcv_pid = rcv_pid[0] << 8 | rcv_pid[1]
                    if pid == rcv_pid:
                        return
        elif qos == 2:
            assert 0 
开发者ID:m5stack,项目名称:UIFlow-Code,代码行数:36,代码来源:simple.py

示例15: set_time

# 需要导入模块: import ubinascii [as 别名]
# 或者: from ubinascii import hexlify [as 别名]
def set_time(rtc_time):
    rtc = None
    try:
        # Pyboard (pyboard doesn't have machine.RTC()).
        # The pyb.RTC.datetime function takes the arguments in the order:
        # (year, month, day, weekday, hour, minute, second, subseconds)
        # http://docs.micropython.org/en/latest/library/pyb.RTC.html#pyb.RTC.datetime
        import pyb
        rtc = pyb.RTC()
        rtc.datetime(rtc_time)
    except:
        try:
            import pycom
            # PyCom's machine.RTC takes its arguments in a slightly different order
            # than the official machine.RTC.
            # (year, month, day, hour, minute, second[, microsecond[, tzinfo]])
            # https://docs.pycom.io/firmwareapi/pycom/machine/rtc/#rtc-init-datetime-none-source-rtc-internal-rc
            rtc_time2 = (rtc_time[0], rtc_time[1], rtc_time[2], rtc_time[4], rtc_time[5], rtc_time[6])
            import machine
            rtc = machine.RTC()
            rtc.init(rtc_time2)
        except:
            try:
                # The machine.RTC documentation was incorrect and doesn't agree with the code, so no link
                # is presented here. The order of the arguments is the same as the pyboard.
                import machine
                rtc = machine.RTC()
                try:
                    # ESP8266 uses rtc.datetime() rather than rtc.init()
                    rtc.datetime(rtc_time)
                except:
                    # ESP32 (at least Loboris port) uses rtc.init()
                    rtc.init(rtc_time)
            except:
                pass


# 0x0D's sent from the host get transformed into 0x0A's, and 0x0A sent to the
# host get converted into 0x0D0A when using sys.stdin. sys.tsin.buffer does
# no transformations, so if that's available, we use it, otherwise we need
# to use hexlify in order to get unaltered data. 
开发者ID:dhylands,项目名称:rshell,代码行数:43,代码来源:main.py


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