优化后端和前端
This commit is contained in:
@@ -411,6 +411,10 @@ def mqtt_control_payload(
|
||||
"data": frame.data.hex(" ").upper(),
|
||||
"repeat": 1,
|
||||
"intervalMs": 0,
|
||||
# Vehicle state is consumed asynchronously from can/state by the
|
||||
# Cognitive Agent. Do not serialize Android's command worker on a
|
||||
# per-command response wait as well.
|
||||
"expectResponse": False,
|
||||
"responseTimeoutMs": bounded_timeout_ms,
|
||||
},
|
||||
ensure_ascii=False,
|
||||
@@ -788,14 +792,19 @@ class MqttCanTransport:
|
||||
)
|
||||
if int(getattr(result, "rc", 0)) != 0:
|
||||
raise CanGatewayError(f"MQTT CAN publish failed with code {result.rc}")
|
||||
if hasattr(result, "wait_for_publish"):
|
||||
published = result.wait_for_publish(timeout=2.0)
|
||||
if published is False:
|
||||
raise CanGatewayError("MQTT CAN publish confirmation timed out")
|
||||
# Paho already accepted the payload into its network-loop queue when
|
||||
# publish() returns rc == MQTT_ERR_SUCCESS. Waiting here serializes
|
||||
# every repeated CAN frame and previously added up to two seconds per
|
||||
# frame. Observe an already-available acknowledgement without ever
|
||||
# blocking the control pipeline.
|
||||
is_published = getattr(result, "is_published", None)
|
||||
broker_confirmed = bool(is_published()) if callable(is_published) else False
|
||||
return {
|
||||
"topic": self.settings.control_topic,
|
||||
"qos": self.settings.qos,
|
||||
"retain": False,
|
||||
"delivery_status": "published" if broker_confirmed else "queued",
|
||||
"message_id": getattr(result, "mid", None),
|
||||
"payload": json.loads(raw_payload),
|
||||
}
|
||||
|
||||
@@ -876,7 +885,7 @@ class MqttCanBus:
|
||||
|
||||
@property
|
||||
def published_messages(self) -> tuple[dict[str, Any], ...]:
|
||||
"""Return this bus view's confirmed MQTT publications in send order."""
|
||||
"""Return this bus view's accepted MQTT publications in send order."""
|
||||
|
||||
return tuple(deepcopy(self._published_messages))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user