From d487f58c6be4ed22f735d12861b59b85c3a924b9 Mon Sep 17 00:00:00 2001
From: yincheng.zhong <634916154@qq.com>
Date: 星期六, 20 十二月 2025 21:53:25 +0800
Subject: [PATCH] HTTP下载路径文件成功,解析路径文件成功,CRC用的软件,硬件解析不对。准备改BOOT

---
 python/realtime_control.py |  129 +++++++++++-------------------------------
 1 files changed, 34 insertions(+), 95 deletions(-)

diff --git a/python/realtime_control.py b/python/realtime_control.py
index 3eb5ba0..17ab062 100644
--- a/python/realtime_control.py
+++ b/python/realtime_control.py
@@ -351,13 +351,14 @@
             info_scroll.setMinimumWidth(320)
             right_layout.addWidget(info_scroll, stretch=1)
 
-            self.path_browse_btn.clicked.connect(self._browse_path_file)
-            self.path_load_btn.clicked.connect(self._load_path_from_ui)
-            self.origin_update_btn.clicked.connect(self._update_origin_from_ui)
-            self.port_refresh_btn.clicked.connect(lambda: self._refresh_serial_ports(initial=False))
-            self.serial_toggle_btn.clicked.connect(self._toggle_serial_connection)
-            self.start_button.clicked.connect(self._start_control)
-            self.stop_button.clicked.connect(self._stop_control)
+            if self.controller is not None:
+                self.path_browse_btn.clicked.connect(self._browse_path_file)
+                self.path_load_btn.clicked.connect(self._load_path_from_ui)
+                self.origin_update_btn.clicked.connect(self._update_origin_from_ui)
+                self.port_refresh_btn.clicked.connect(lambda: self._refresh_serial_ports(initial=False))
+                self.serial_toggle_btn.clicked.connect(self._toggle_serial_connection)
+                self.start_button.clicked.connect(self._start_control)
+                self.stop_button.clicked.connect(self._stop_control)
 
         def _apply_saved_values(self):
             path_file = self.gui_state.get("path_file", "")
@@ -541,69 +542,16 @@
             self.port_combo.blockSignals(False)
 
         def _toggle_serial_connection(self):
-            if self.controller.is_connected():
-                if self.controller.is_running():
-                    QtWidgets.QMessageBox.warning(self, "涓插彛", "璇峰厛鍋滄杩愬姩鎺у埗锛屽啀鍏抽棴涓插彛銆�")
-                    return
-                self.controller.disconnect()
-                QtWidgets.QMessageBox.information(self, "涓插彛", "涓插彛宸插叧闂��")
-            else:
-                port = self.port_combo.currentText().strip()
-                if not port:
-                    QtWidgets.QMessageBox.warning(self, "涓插彛", "娌℃湁鍙敤涓插彛锛岃鍏堣繛鎺ヨ澶囥��")
-                    return
-                try:
-                    self.controller.set_port(port)
-                except RuntimeError as exc:
-                    QtWidgets.QMessageBox.warning(self, "涓插彛", str(exc))
-                    return
-                if not self.controller.connect():
-                    QtWidgets.QMessageBox.warning(self, "涓插彛", "涓插彛鎵撳紑澶辫触锛岃妫�鏌ヨ繛鎺ャ��")
-                    return
-                self._save_state({"serial_port": port})
-                QtWidgets.QMessageBox.information(self, "涓插彛", f"涓插彛 {port} 宸叉墦寮�銆�")
-            self._update_serial_ui()
-            self._update_control_buttons()
+            QtWidgets.QMessageBox.warning(self, "涓插彛", "HITL 妯″紡涓嬭鎿嶄綔鐢变豢鐪熷櫒鎺у埗")
 
         def _start_control(self):
-            if self._is_control_running():
-                return
-            if not self.controller.mower_ctrl:
-                QtWidgets.QMessageBox.warning(self, "鎺у埗", "璇峰厛鍔犺浇璺緞鏂囦欢銆�")
-                return
-            if not self.controller.is_connected():
-                QtWidgets.QMessageBox.warning(self, "鎺у埗", "璇峰厛鎵撳紑涓插彛銆�")
-                return
-
-            self.start_button.setEnabled(False)
-            self.stop_button.setEnabled(True)
-
-            def control_entry():
-                try:
-                    self.controller.run()
-                except Exception as exc:
-                    print(f"[ERROR] 鎺у埗绾跨▼寮傚父: {exc}")
-                    QtCore.QMetaObject.invokeMethod(
-                        self,
-                        "_show_error_message",
-                        QtCore.Qt.QueuedConnection,
-                        QtCore.Q_ARG(str, f"鎺у埗绾跨▼寮傚父: {exc}"),
-                    )
-                finally:
-                    QtCore.QMetaObject.invokeMethod(self, "_on_control_finished", QtCore.Qt.QueuedConnection)
-
-            self.control_thread = threading.Thread(target=control_entry, daemon=True)
-            self.control_thread.start()
-            self._update_control_buttons()
+            QtWidgets.QMessageBox.warning(self, "鎺у埗", "HITL 妯″紡涓嬭閫氳繃浠跨湡鍣ㄥ惎鍔�")
 
         def _stop_control(self):
-            if not self._is_control_running():
-                return
-            self.controller.stop()
-            self.stop_button.setEnabled(False)
+            QtWidgets.QMessageBox.warning(self, "鎺у埗", "HITL 妯″紡涓嬭閫氳繃浠跨湡鍣ㄥ仠姝�")
 
         def _is_control_running(self) -> bool:
-            return bool(self.control_thread and self.control_thread.is_alive())
+            return False
 
         def _save_state(self, updates: Dict[str, str]):
             self.gui_state.update(updates)
@@ -611,32 +559,23 @@
                 self.persist_state_cb(updates)
 
         def _update_serial_ui(self):
-            connected = self.controller.is_connected()
-            self.serial_toggle_btn.setText("鍏抽棴涓插彛" if connected else "鎵撳紑涓插彛")
-            self.port_combo.setEnabled(not connected)
-            self.port_refresh_btn.setEnabled(not connected)
+            self.serial_toggle_btn.setEnabled(False)
+            self.port_combo.setEnabled(False)
+            self.port_refresh_btn.setEnabled(False)
 
         def _update_control_buttons(self):
-            can_start = bool(self.controller.mower_ctrl and self.controller.is_connected() and not self._is_control_running())
-            self.start_button.setEnabled(can_start)
-            self.stop_button.setEnabled(self._is_control_running())
+            self.start_button.setEnabled(False)
+            self.stop_button.setEnabled(False)
 
         @QtCore.pyqtSlot()
         def _on_control_finished(self):
-            self.control_thread = None
-            self._update_control_buttons()
-            self.stop_button.setEnabled(False)
+            pass
 
         @QtCore.pyqtSlot(str)
         def _show_error_message(self, message: str):
             QtWidgets.QMessageBox.warning(self, "閿欒", message)
 
         def closeEvent(self, event):
-            self._stop_control()
-            if self.control_thread:
-                self.control_thread.join(timeout=3.0)
-            if self.controller.is_connected():
-                self.controller.disconnect()
             super().closeEvent(event)
 else:
     QtRealtimeDashboard = None
@@ -926,7 +865,7 @@
     def disconnect(self):
         """鏂紑杩炴帴"""
         if self.receiver:
-            self.receiver.disconnect()
+        self.receiver.disconnect()
             self.receiver = None
         self.cmd_sender = None
     
@@ -1160,7 +1099,7 @@
             
             if self._stop_event.is_set():
                 return
-
+            
             print("[INFO] 寮�濮嬫帶鍒跺惊鐜�")
             
             while not self._stop_event.is_set():
@@ -1219,7 +1158,7 @@
                             # 鏁板瑙掑害杞湴鐞嗚搴︼細heading_err_deg
                             # 娉ㄦ剰 control_output['info']['heading_err'] 鏄姬搴�
                             heading_err_deg = math.degrees(control_info.get('heading_err', 0))
-
+                            
                             print(f"[LOG] POS_ENU: {x:.3f}, {y:.3f}, {z:.3f} | "
                                   f"ATT(H/P/R): {gps_heading:.2f}掳, {gps_pitch:.2f}掳, {gps_roll:.2f}掳 | "
                                   f"CTRL: S={status}, F={forward_signal}, T={turn_signal}, Err={xte:.2f}m")
@@ -1272,10 +1211,10 @@
             self._stop_event.clear()
             # 鍙戦�佸仠姝㈠懡浠� (涓綅鍊�)
             if self.cmd_sender:
-                print("[INFO] 鍙戦�佸仠姝㈠懡浠�...")
-                for _ in range(5):
-                    self.cmd_sender.send_control_command(1500, 1500)
-                    time.sleep(0.02)
+            print("[INFO] 鍙戦�佸仠姝㈠懡浠�...")
+            for _ in range(5):
+                self.cmd_sender.send_control_command(1500, 1500)
+                time.sleep(0.02)
             
             # 鎵撳嵃鏈�缁堢粺璁�
             print("\n========== 鏈�缁堢粺璁� ==========")
@@ -1284,7 +1223,7 @@
                 print(f"GPS鏁版嵁鍖�: {receiver.gps_count}")
                 print(f"IMU鏁版嵁鍖�: {receiver.imu_count}")
             if self.cmd_sender:
-                print(f"鍛戒护鍙戦��: {self.cmd_sender.get_stats()}")
+            print(f"鍛戒护鍙戦��: {self.cmd_sender.get_stats()}")
             if receiver:
                 print(f"閿欒璁℃暟: {receiver.error_count}")
             print("==============================\n")
@@ -1313,7 +1252,7 @@
         origin_alt_m=None,
         gui_bridge=gui_bridge,
     )
-
+    
     # 棰勫姞杞借矾寰勬枃浠讹紙鑻ュ瓨鍦級
     candidate_path = path_file or DEFAULT_PATH_FILE
     if candidate_path and Path(candidate_path).exists():
@@ -1336,13 +1275,13 @@
         # 鏃燪t鐜鏃讹紝娌跨敤鏃х殑鍛戒护琛屽伐浣滄祦
         if not controller.path_points and Path(DEFAULT_PATH_FILE).exists():
             controller.load_path(DEFAULT_PATH_FILE)
-        if not controller.connect():
-            print("[ERROR] 涓插彛杩炴帴澶辫触锛岄��鍑�")
-            return
-        try:
-            controller.run()
-        finally:
-            controller.disconnect()
+    if not controller.connect():
+        print("[ERROR] 涓插彛杩炴帴澶辫触锛岄��鍑�")
+        return
+    try:
+        controller.run()
+    finally:
+        controller.disconnect()
 
 
 if __name__ == "__main__":

--
Gitblit v1.10.0