DFBJMRK9gEd 发表于 2021-3-28 11:34:14

maix dock m1w mqtt时如何修改底层check_msg():使得在没有消息pass

本帖最后由 DFBJMRK9gEd 于 2021-3-28 11:36 编辑

大佬看看 能不能救一下

DFBJMRK9gEd 发表于 2021-3-28 11:48:24

def wait_msg(self):
      res = self.sock.read(1)
      self.sock.setblocking(True)
      if res is None:
            return None
      if res == b"":
            raise OSError(-1)
      if res == b"\xd0":# PINGRESP
            sz = self.sock.read(1)
            assert sz == 0
            return None
      op = res
      if op & 0xf0 != 0x30:
            return op
      sz = self._recv_len()
      topic_len = self.sock.read(2)
      topic_len = (topic_len << 8) | topic_len
      topic = self.sock.read(topic_len)
      sz -= topic_len + 2
      if op & 6:
            pid = self.sock.read(2)
            pid = pid << 8 | pid
            sz -= 2
      msg = self.sock.read(sz)
      self.cb(topic, msg)
      if op & 6 == 2:
            pkt = bytearray(b"\x40\x02\0\0")
            struct.pack_into("!H", pkt, 2, pid)
            self.sock.write(pkt)
      elif op & 6 == 4:
            assert 0

    # Checks whether a pending message from server is available.
    # If not, returns immediately with None. Otherwise, does
    # the same processing as wait_msg.
    def check_msg(self):
      self.sock.setblocking(False)
      return self.wait_msg()

DFBJMRK9gEd 发表于 2021-3-28 11:56:50

      if res == b"":
            return None
修改这两句
页: [1]
查看完整版本: maix dock m1w mqtt时如何修改底层check_msg():使得在没有消息pass