PUGE 1 hónapja
szülő
commit
f1daa1b90f
2 módosított fájl, 101 hozzáadás és 34 törlés
  1. 52 13
      三一平台.py
  2. 49 21
      控制vm虚拟机.py

+ 52 - 13
三一平台.py

@@ -303,6 +303,10 @@ class MainWindow(QMainWindow):
         self.is_processing_scan = False  # 是否正在处理扫码任务
         self.scan_timer = QTimer()  # 定时器用于间隔执行
         self.scan_timer.timeout.connect(self.process_next_scan)
+        self.current_scan_plate = None  # 当前等待发送2001的车牌
+        self.wait_timeout_timer = QTimer()  # 等待超时定时器
+        self.wait_timeout_timer.setSingleShot(True)  # 单次触发
+        self.wait_timeout_timer.timeout.connect(self.on_wait_timeout)
         
         # WebSocket相关
         self.ws_client = None
@@ -608,11 +612,19 @@ class MainWindow(QMainWindow):
             # 外部WebSocket发来的开车命令
             car_plate = data.get('value', '')
             if car_plate:
-                self.add_log(f"📤 收到外部WebSocket开车命令,车辆: {car_plate}")
-                # 发送2001指令
-                self.send_cmd_to_vehicle(car_plate, "2001")
-                # 继续处理下一辆车
-                self.process_next_scan()
+                # 检查是否是当前等待的车牌
+                if car_plate == self.current_scan_plate:
+                    self.add_log(f"📤 收到外部WebSocket开车命令,车辆: {car_plate}")
+                    # 停止超时定时器
+                    self.wait_timeout_timer.stop()
+                    # 发送2001指令
+                    self.send_cmd_to_vehicle(car_plate, "2001")
+                    # 清空当前车牌
+                    self.current_scan_plate = None
+                    # 继续处理下一辆车
+                    self.process_next_scan()
+                else:
+                    self.add_log(f"⚠️ 收到开车命令但车辆 {car_plate} 不在等待列表中(当前等待: {self.current_scan_plate})")
             else:
                 self.add_log(f"⚠️ 收到开车命令但车牌为空")
         
@@ -640,6 +652,8 @@ class MainWindow(QMainWindow):
         # 初始化队列
         self.scan_task_queue = scan_vehicles.copy()
         self.is_processing_scan = True
+        self.current_scan_plate = None
+        self.wait_timeout_timer.stop()  # 重置超时定时器
         
         self.add_log(f"🚀 开始扫码任务,共 {len(scan_vehicles)} 辆车")
         self.add_log(f"📋 车辆列表: {', '.join(scan_vehicles)}")
@@ -656,6 +670,7 @@ class MainWindow(QMainWindow):
             self.scan_task_queue = []
             self.current_scan_plate = None
             self.scan_timer.stop()
+            self.wait_timeout_timer.stop()
             return
         
         if not self.scan_task_queue:
@@ -665,6 +680,7 @@ class MainWindow(QMainWindow):
             self.statusBar().showMessage("扫码任务全部完成")
             self.scan_timer.stop()
             self.current_scan_plate = None
+            self.wait_timeout_timer.stop()
             return
         
         # 取出第一个车辆
@@ -675,18 +691,40 @@ class MainWindow(QMainWindow):
         # 执行测试发车(标记为来自扫码任务)
         self.on_test_drive(car_plate, from_scan=True)
         
-        # 启动定时器,1分钟后发送指令2001,然后处理下一辆
-        # 使用 QTimer.singleShot 单次定时器,传入当前车牌
-        self.add_log(f"⏳ 等待外部WebSocket通知发送2001指令到: {car_plate}")
+        # 等待外部WebSocket通知发送2001指令
+        self.add_log(f"⏳ 等待外部WebSocket通知发送2001指令到: {car_plate},超时时间2分钟")
+        
+        # 启动超时定时器(2分钟)
+        self.wait_timeout_timer.start(120000)  # 2分钟 = 120000毫秒
 
-    def send_2001_and_next(self, car_plate):
-        """发送2001指令给指定车辆,然后继续处理下一个"""
-        self.add_log(f"📤 发送指令 2001 到车辆: {car_plate}")
-        self.send_cmd_to_vehicle(car_plate, "2001")
+    def on_wait_timeout(self):
+        """等待超时处理"""
+        if not self.current_scan_plate:
+            return
         
-        # 发送完指令后,继续处理下一辆(立即执行,不再等待)
+        car_plate = self.current_scan_plate
+        self.add_log(f"⏰ 等待超时(2分钟),未收到 {car_plate} 的WebSocket通知")
+        
+        # 取消该车辆的扫码勾选
+        for row in range(self.table.rowCount()):
+            plate_item = self.table.item(row, 3)
+            if plate_item and plate_item.text() == car_plate:
+                scan_checkbox = self.table.cellWidget(row, 1)
+                if scan_checkbox:
+                    scan_checkbox.setChecked(False)
+                    self.car_scan_state[car_plate] = False
+                    self.add_log(f"❌ 已取消 {car_plate} 的扫码勾选(超时)")
+                    break
+        
+        # 清空当前车牌
+        self.current_scan_plate = None
+        
+        # 继续处理下一辆
+        self.add_log(f"⏭️ 继续处理下一辆车...")
         self.process_next_scan()
 
+
+
     def check_scan_complete(self):
         """检查扫码任务是否完成"""
         if not self.scan_task_queue and self.is_processing_scan:
@@ -1141,6 +1179,7 @@ class MainWindow(QMainWindow):
         
         # 停止扫码任务
         self.scan_timer.stop()
+        self.wait_timeout_timer.stop()  # 停止超时定时器
         self.is_processing_scan = False
         self.scan_task_queue = []
         self.current_scan_plate = None

+ 49 - 21
控制vm虚拟机.py

@@ -615,7 +615,7 @@ class VmControlGUI:
                 current_time = time.time()
                 if current_time - last_key2_time >= random.uniform(interval_min, interval_max):
                     self.log("发送: 2 (数字2) [暂停延续中]")
-                    self.press_key(0x32, False)
+                    self.press_key(0x62, False)
                     last_key2_time = current_time
             
             self.log(f"⏳ 延续结束,执行停止序列(2次)")
@@ -714,7 +714,7 @@ class VmControlGUI:
                 current_time = time.time()
                 if current_time - last_key2_time >= random.uniform(interval_min, interval_max):
                     self.log("发送: 2 (数字2)")
-                    self.press_key(0x32, False)
+                    self.press_key(0x62, False)
                     last_key2_time = current_time
             
             # ===== 收到停止指令后,继续执行10-30秒 =====
@@ -735,7 +735,7 @@ class VmControlGUI:
                 current_time = time.time()
                 if current_time - last_key2_time >= random.uniform(interval_min, interval_max):
                     self.log("发送: 2 (数字2) [停止延迟中]")
-                    self.press_key(0x32, False)
+                    self.press_key(0x62, False)
                     last_key2_time = current_time
             
             self.log(f"⏳ 延迟结束,开始执行停止序列")
@@ -906,17 +906,17 @@ class VmControlGUI:
         try:
             # 按键名称映射
             key_name_map = {
-                0x68: b"8",
-                0x62: b"2",
-                0x25: b"left",
-                0x20: b"space",
-                0x26: b"up",
-                0x28: b"down",
-                0x27: b"right",
-                0x1B: b"esc",
-                0xBB: b"=",
-                0xBD: b"-",
-                0x32: b"2",
+                0x68: b"num8",      # 小键盘8
+                0x62: b"num2",      # 小键盘2
+                0x25: b"left",      # 左箭头
+                0x20: b"space",     # 空格
+                0x26: b"up",        # 上箭头
+                0x28: b"down",      # 下箭头
+                0x27: b"right",     # 右箭头
+                0x1B: b"esc",       # ESC
+                0xBB: b"=",         # = 号
+                0xBD: b"-",         # - 号
+                0x32: b"2",         # 主键盘2(如果确实需要主键盘的)
             }
             
             if self.ghost_available:
@@ -1000,12 +1000,36 @@ class VmControlGUI:
         self.log("测试完成")
         self.log("=" * 50)
 
+    def click_at_current_position(self):
+        """在当前鼠标位置点击左键"""
+        try:
+            if self.ghost_available:
+                # 幽灵键鼠:获取当前坐标并点击
+                x = getmousex()
+                y = getmousey()
+                ret = movemouseto(x, y)
+                if ret == 1:
+                    ret = pressandreleasemousebutton(1)  # 左键
+                    return ret == 1
+                return False
+            else:
+                # 系统API:获取当前位置并点击
+                x, y = win32api.GetCursorPos()
+                win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
+                time.sleep(0.05)
+                win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
+                return True
+        except Exception as e:
+            self.log(f"鼠标左键点击失败: {e}")
+            return False
+
     def loop_worker(self):
+        # 按键定义:(类型, 键码/标识, 扩展标志, 名称)
         keys = [
-            (0x68, True, "小键盘8"),
-            (0x62, True, "小键盘2"),
-            (0x25, False, "左键"),
-            (0x20, False, "空格"),
+            ("keyboard", 0x68, True, "小键盘8"),      # 小键盘8
+            ("keyboard", 0x62, True, "小键盘2"),      # 小键盘2
+            ("mouse", None, None, "鼠标左键"),         # 鼠标左键(原来的0x25左箭头改成鼠标左键)
+            ("keyboard", 0x20, False, "空格"),         # 空格
         ]
 
         key_min = int(self.key_interval_min.get()) / 1000.0
@@ -1023,7 +1047,7 @@ class VmControlGUI:
         self.log("=" * 50)
         self.log("🚀 脚本A循环开始!")
         self.log(f"使用: {'幽灵键鼠' if self.ghost_available else '系统API'}")
-        self.log(f"按键: 小键盘8 -> 小键盘2 -> 左键 -> 空格")
+        self.log(f"按键: 小键盘8 -> 小键盘2 -> 鼠标左键 -> 空格")
         self.log("=" * 50)
 
         # 只在开始前执行一次鼠标点击激活窗口
@@ -1046,12 +1070,16 @@ class VmControlGUI:
                     break
 
                 # 执行一轮按键
-                for key_code, extended, key_name in keys:
+                for key_type, key_code, extended, key_name in keys:
                     if self.stop_flag:
                         break
                     
                     self.log(f"发送: {key_name}")
-                    self.press_key(key_code, extended)
+                    
+                    if key_type == "mouse":
+                        self.click_at_current_position()
+                    else:
+                        self.press_key(key_code, extended)
                     total_keys += 1
                     
                     interval = random.uniform(key_min, key_max)