From 00969c770c1eb736813e7c637f62e851487ab5bc Mon Sep 17 00:00:00 2001 From: dahanzimin <353767514@qq.com> Date: Wed, 5 Nov 2025 13:23:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=201.=20AGS10=E7=9A=84TVOC=20?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=B8=BA=E5=87=86=E5=A4=87=E5=B0=B1=E7=BB=AA?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20=20=20=20=20=202.=20ntp=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=A4=9A=E6=AC=A1=E8=8E=B7=E5=8F=96=E6=97=B6=E9=97=B4=20=20=20?= =?UTF-8?q?=20=20=203.=20mini=E7=9A=84=E5=90=8C=E6=AD=A5=E8=AE=AF=E9=A3=9E?= =?UTF-8?q?function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../micropython/origin/build/lib/ags10.py | 7 ++-- .../micropython/origin/build/lib/ntptime.py | 36 +++++++++++-------- .../origin/build/lib/mini_xunfei.py | 4 +++ 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/boards/default_src/micropython/origin/build/lib/ags10.py b/boards/default_src/micropython/origin/build/lib/ags10.py index 2ee81bca..249c1451 100644 --- a/boards/default_src/micropython/origin/build/lib/ags10.py +++ b/boards/default_src/micropython/origin/build/lib/ags10.py @@ -17,9 +17,10 @@ class AGS10: def __init__(self, i2c_bus, address=0x1A, delay=1000): self._i2c = i2c_bus self._addr = address - self._voc = None + self._voc = 0 self._delay = delay self._star = 0 + self.ready = 0 def _crc8(self, buf, is_byte=False): '''Perform CRC check on the data''' @@ -76,8 +77,8 @@ class AGS10: if time.ticks_diff(time.ticks_ms(), self._star) >= self._delay: self._star = time.ticks_ms() _buf = self._rreg(_AGS10_ADC) - if (_buf[0] & 0x01) == 0: - self._voc = int.from_bytes(_buf[1:4], 'big') + self._voc = int.from_bytes(_buf[1:4], 'big') + self.ready = not (_buf[0] & 0x01) return self._voc / 1000 def read(self, hcho_mw=30.033 , co2_mv=0.853, co2_base=400): diff --git a/boards/default_src/micropython/origin/build/lib/ntptime.py b/boards/default_src/micropython/origin/build/lib/ntptime.py index 7474eec6..cce0a4b0 100644 --- a/boards/default_src/micropython/origin/build/lib/ntptime.py +++ b/boards/default_src/micropython/origin/build/lib/ntptime.py @@ -6,21 +6,27 @@ import ustruct as struct # NTP_DELTA (date(2000, 1, 1) - date(1900, 1, 1)).days * 24*60*60 NTP_DELTA=3155673600 -def time(host="pool.ntp.org", utc=28800): - NTP_QUERY = bytearray(48) - NTP_QUERY[0] = 0x1B - addr = socket.getaddrinfo(host, 123)[0][-1] - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - try: - s.settimeout(1) - res = s.sendto(NTP_QUERY, addr) - msg = s.recv(48) - finally: - del addr - s.close() - gc.collect() - val = struct.unpack("!I", msg[40:44])[0] - return utime.gmtime(val - NTP_DELTA + utc) +def time(host="pool.ntp.org", utc=28800, times=5): + for _ in range(times): + try: + NTP_QUERY = bytearray(48) + NTP_QUERY[0] = 0x1B + addr = socket.getaddrinfo(host, 123)[0][-1] + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + try: + s.settimeout(1) + res = s.sendto(NTP_QUERY, addr) + msg = s.recv(48) + finally: + del addr + s.close() + gc.collect() + val = struct.unpack("!I", msg[40:44])[0] + return utime.gmtime(val - NTP_DELTA + utc) + except Exception as e: + error = e + utime.sleep(0.1) + raise OSError('Error fetching network time', error) # There's currently no timezone support in MicroPython, and the RTC is set in UTC time. def settime(times): diff --git a/boards/default_src/micropython_esp32c2/origin/build/lib/mini_xunfei.py b/boards/default_src/micropython_esp32c2/origin/build/lib/mini_xunfei.py index 3692c1da..1d51a73f 100644 --- a/boards/default_src/micropython_esp32c2/origin/build/lib/mini_xunfei.py +++ b/boards/default_src/micropython_esp32c2/origin/build/lib/mini_xunfei.py @@ -244,6 +244,10 @@ class LLM_WebSocket(Ws_Param): if "reasoning_content" in text and reas: print("reasoning: ", text["reasoning_content"]) #回调 + if "tool_calls" in text: + function = text['tool_calls'][0]['function'] + if str(function['name']) in self._function[0] and function['arguments']: + self._function[0][function['name']](json.loads(function['arguments'])) if "function_call" in text: if str(text['function_call']['name']) in self._function[0] and text['function_call']['arguments']: self._function[0][text['function_call']['name']](json.loads(text['function_call']['arguments']))