cpp sdk更新
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
"""Fast MCU client using native LowState decrypt/parse.
|
||||
"""Fast MCU client using native LowState decrypt/parse and UDP drain.
|
||||
|
||||
The public shape mirrors go1_pro_sdk.connection.MCUClient for deployment code,
|
||||
while keeping the receive hot path out of pure Python.
|
||||
"""
|
||||
import socket
|
||||
import time
|
||||
|
||||
from fast_lowcmd import FastLowCmdBuilder, default_state_path
|
||||
from go1_fast_lowcmd import FastNativeMCUClient
|
||||
from go1_pro_sdk import MCU_IP, MCU_PORT
|
||||
from go1_pro_sdk.utils.constants import RCVBUF_SIZE
|
||||
|
||||
@@ -127,16 +127,19 @@ class FastMCUClient:
|
||||
raise ValueError("FastMCUClient currently supports only little-endian Blowfish state")
|
||||
self.mcu_ip = mcu_ip
|
||||
self.mcu_port = mcu_port
|
||||
self.builder = FastLowCmdBuilder(state_path or default_state_path())
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
sock.setblocking(False)
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, RCVBUF_SIZE)
|
||||
sock.bind(("", local_port))
|
||||
self.sock = sock
|
||||
self.local_port = sock.getsockname()[1]
|
||||
resolved_state_path = state_path or default_state_path()
|
||||
self.builder = FastLowCmdBuilder(resolved_state_path)
|
||||
self._native = FastNativeMCUClient(
|
||||
resolved_state_path,
|
||||
mcu_ip,
|
||||
int(mcu_port),
|
||||
int(local_port),
|
||||
int(RCVBUF_SIZE),
|
||||
endian,
|
||||
)
|
||||
self.local_port = self._native.local_port()
|
||||
self._last_state = None
|
||||
self.backend = "cpp_lowcmd_cpp_lowstate"
|
||||
self.backend = "cpp_lowcmd_cpp_lowstate_cpp_udp"
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
@@ -145,27 +148,16 @@ class FastMCUClient:
|
||||
self.close()
|
||||
|
||||
def close(self):
|
||||
if self.sock:
|
||||
self.sock.close()
|
||||
self.sock = None
|
||||
native = getattr(self, "_native", None)
|
||||
if native is not None:
|
||||
native.close()
|
||||
self._native = None
|
||||
|
||||
def send_raw(self, raw_cipher):
|
||||
self.sock.sendto(raw_cipher, (self.mcu_ip, self.mcu_port))
|
||||
return len(raw_cipher)
|
||||
return self._native.send_raw(raw_cipher)
|
||||
|
||||
def recv_latest(self):
|
||||
last_data = None
|
||||
while True:
|
||||
try:
|
||||
data, _ = self.sock.recvfrom(2048)
|
||||
last_data = data
|
||||
except (BlockingIOError, socket.timeout):
|
||||
break
|
||||
|
||||
if last_data is None:
|
||||
return None
|
||||
|
||||
fields = self.builder.decrypt_lowstate(last_data)
|
||||
fields = self._native.recv_latest_fields()
|
||||
if fields is None:
|
||||
return None
|
||||
self._last_state = FastLowState(fields)
|
||||
|
||||
Reference in New Issue
Block a user