Quellcode durchsuchen

```
feat(DeviceControl): 添加设备名称映射和改进MCU通信日志

添加了设备ID到中文名称的映射字典,便于理解设备控制命令。
优化了MCU数据接收的日志输出,增加命令类型识别和设备运动回执信息。
将MCU循环间隔从1秒调整为0.05秒以提高响应速度。

fix(SerialIns): 添加原始数据打印功能

在串口数据接收过程中添加原始数据的十六进制打印,
便于调试串口通信问题。

refactor(DeviceControl): 清理冗余代码和注释

移除了多个to_device_move调用中的重复参数,
删除了无用的注释代码块。
```

rambo vor 1 Woche
Ursprung
Commit
a92836305e
2 geänderte Dateien mit 63 neuen und 28 gelöschten Zeilen
  1. 62 27
      python/mcu/DeviceControl.py
  2. 1 1
      python/mcu/SerialIns.py

+ 62 - 27
python/mcu/DeviceControl.py

@@ -78,7 +78,18 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             "mp3_player": 8,
             "mcu": 99,
         }
-
+        self.device_name_dict_mapping = {
+            0:"相机角度",
+            1:"相机高度",
+            2:"转盘角度",
+            3:"翻板角度",
+            4:"激光灯位置",
+            5:"蜂鸣器",
+            6:"split",
+            7:"转盘位置",
+            8:"播放音频",
+            99:"mcu命令",
+        }
         # 最近的mcu基础信息,用于获取数据状态检查
         self.last_mcu_info_data = {
             "num": 0,
@@ -196,7 +207,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
         print("MCU 开始循环~")
         logger.info("MCU 开始循环~")
         while 1:
-            await asyncio.sleep(1)
+            await asyncio.sleep(0.05)
             if not self.serial_ins or not self.connect_state:
                 break
             try:
@@ -411,6 +422,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             if self.send_data_queue:
                 # self.sendSocketMessage(msg="正在发送命令", device_status=1)
                 data = self.send_data_queue.pop(0)
+                print("\033[1;32;40m 正在发送命令 \033[0m",data)
                 self.serial_ins.write_cmd(data)
                 # self.sendSocketMessage(msg="命令发送完成", device_status=2)
             else:
@@ -453,10 +465,40 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
         return
     def print_mcu_noraml_data(self, receive_data):
         # 扫码数据
+        print("接收到255数据:", receive_data)
         try:
+            command_mapping = {
+                1:"设备运动",
+                2:"初始化设备",  # 初始化设备
+                3:"处理其他设备",  # 处理其他设备
+                29:"获取所有信息",  # 获取所有信息
+                40:"设置偏移量",  # 设置偏移量
+                41:"读取偏移量",  # 读取偏移量
+                91:"信号转发处理",  # 信号转发处理
+                92:"信号转发返回",  # 信号转发返回
+                44:"获取其他信息",  # 获取其他信息
+                43:"RGB灯的处理与通讯",  ## RGB灯的处理与通讯
+                45:"设置其他信息",  # 设置其他信息
+                47:"查询遥控器电量",  # 查询遥控器电量
+                48:"设置转盘通讯方式 1、串口、2、无线、3 混合",  # 
+                93:"停止运行mcu",  # 停止运行mcu
+                90:"连接MCU",# 连接MCU
+            }
+            # command = int(receive_data[0])
+            command = int(receive_data[1])
+            command_text = command_mapping[command]
+            # receive_data_temp = receive_data[2:]
             receive_data_temp_text = " ".join([hex(x) for x in receive_data])
-            print("255  print_mcu_noraml_data:", receive_data_temp_text)
-            logger.info("255  print_mcu_noraml_data:%s", receive_data_temp_text)
+            # print("255  command_text:", command_text)
+            if command_text in ["设备运动","处理其他设备"]:
+                device_id = int(receive_data[2])
+                device_value = int(receive_data[3])
+                device_name_info = self.device_name_dict_mapping[device_id]
+                message_info = {"设备名称":device_name_info,"运动值":device_value}
+                print("【设备运动】消息回执:", message_info)
+                logger.info("设备运动消息回执:%s", message_info)
+            print("接收设备消息回执:", command_text)
+            logger.info("接收设备消息回执:%s", receive_data_temp_text)
         except BaseException as e:
             print("255 error {}".format(e))
             logger.info("255 error %s", e)
@@ -556,14 +598,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             return False
         if not receive_data:
             return False
-        # print("receive_data", receive_data)
-        # 数据 结构 command,按命令解析
-        # command 0(9) 相机高度1-2  相机角度3-4  转盘角度5-6 灯光状态7  激光指示器状态8,运行状态9
         command = receive_data[0]
-        # receive_data_temp = receive_data[2:]
-        # receive_data_temp_text = " ".join([hex(x) for x in receive_data_temp])
-        # print("command",command)
-        # print("receive_data", receive_data_temp_text)
         if command in self.deal_code_func_dict:
             self.deal_code_func_dict[command](receive_data)
 
@@ -1467,11 +1502,10 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
                 self.to_device_move(
                     device_name=device_name,
                     value=float(value),
-                    # max_speed=1400,
-                    # up_speed=400,
-                    # down_speed=100,
-                    # _is_debug=_is_debug,
-                    # is_deviation=is_deviation,
+                )
+                self.to_device_move(
+                    device_name=device_name,
+                    value=float(value),
                 )
             case "camera_steering":
                 print(device_name, value)
@@ -1479,27 +1513,30 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
                 self.to_device_move(
                     device_name=device_name,
                     value=float(value),
-                    # _is_debug=_is_debug,
-                    # is_deviation=0,
+                )
+                self.to_device_move(
+                    device_name=device_name,
+                    value=float(value),
                 )
             case "turntable_steering":
                 # 转盘舵机
                 self.to_device_move(
                     device_name=device_name,
                     value=float(value),
-                    # _is_debug=_is_debug,
-                    # is_deviation=0,
+                )
+                self.to_device_move(
+                    device_name=device_name,
+                    value=float(value),
                 )
             case "turntable_position_motor":
                 # 转盘舵机
                 self.to_device_move(
                     device_name=device_name,
                     value=float(value),
-                    # max_speed=1400,
-                    # up_speed=400,
-                    # down_speed=100,
-                    # _is_debug=_is_debug,
-                    # is_deviation=is_deviation,
+                )
+                self.to_device_move(
+                    device_name=device_name,
+                    value=float(value),
                 )
             case "overturn_steering":
                 # 翻板舵机中位
@@ -1524,8 +1561,6 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
                 self.to_deal_device(device_name, value=value, _type=0, times=1)
             case _:
                 pass
-            # case "photograph":
-            #     self.photograph(goods_art_no=None)
 
     def checkDevice(self):
         print("检查设备是否运行中")

+ 1 - 1
python/mcu/SerialIns.py

@@ -224,7 +224,7 @@ class SerialIns(object):
 
             if len(self.receive_data) < 4:
                 break
-
+            print("read ori ", self.change_hex_to_int(self.receive_data))
             if self.receive_data[0] == 0x55 and self.receive_data[1] == 0x55:
                 # print("read ori ", self.change_hex_to_int(self.receive_data))
                 data_len = self.receive_data[2]