Browse Source

feat(mcu): 添加一键下降功能并集成钉钉机器人通知

- 在 DeviceControl 类中新增 one_key_down 方法实现设备一键下降功能
- 集成钉钉机器人通知功能,在抠图处理超时或失败时发送异常消息
- 在消息处理器中添加对 one_key_down 指令的处理逻辑
- 更新单拍指令处理流程并优化调试信息输出
- 移除临时文件中的测试代码并替换为钉钉消息发送功能
rambo 1 tuần trước cách đây
mục cha
commit
2e76d819dc

+ 16 - 0
python/mcu/DeviceControl.py

@@ -207,6 +207,22 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
 
         return item_value
 
+    def one_key_down(self):
+        cmd = [0x55, 0x55, 0x69, 0x96, 0x00, 0x03, 0x00, 0xC8, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01,
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+               0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+               0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+               0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+               0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
+               0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x02]
+        # self.add_send_data_queue(cmd)
+        buf = bytearray(b"")
+        buf.extend(cmd)
+        # 55 55 02 5a 01 a4
+        if self.serial_ins.serial_handle is not None:
+            print("one_key_down buf  {}".format(self.serial_ins.change_hex_to_int(buf)))
+            self.serial_ins.serial_handle.write(buf)
+
     def get_device_info(self):
         if not self.init_state:
             self.sendSocketMessage(code=1, msg="mcu设备未初始化", device_status=4)

+ 4 - 0
python/service/base_deal.py

@@ -24,6 +24,7 @@ import copy, asyncio
 from settings import sendSocketMessage
 from utils.common import message_queue
 from logger import logger
+from .online_request.ding_robot import sendDingMsg
 
 
 def sendAsyncMessage(msg="", goods_arts=[], status="", progress={}):
@@ -676,6 +677,7 @@ class BaseDealImage(object):
                                 callback_func(
                                     "货号图{} 抠图处理超时~".format(file_name)
                                 )
+                                sendDingMsg(f"抠图服务:{cutout_mode_str}", f"货号图{file_name} 抠图处理超时~")
                                 error_goods_art_no_folder.append(folder_path)
                                 im = None
                             except BaseException as e:
@@ -684,12 +686,14 @@ class BaseDealImage(object):
                                         file_name, e
                                     )
                                 )
+                                sendDingMsg(f"抠图服务:{cutout_mode_str}", f"货号图{file_name} 抠图处理失败,原因:{e}")
                                 error_goods_art_no_folder.append(folder_path)
                                 im = None
                             if not im:
                                 callback_func(
                                     "货号图{} 抠图处理失败~".format(file_name)
                                 )
+                                sendDingMsg(f"抠图服务:{cutout_mode_str}", f"货号图{file_name} 抠图处理失败")
                                 error_goods_art_no_folder.append(folder_path)
                                 continue
                             else:

+ 17 - 0
python/service/online_request/ding_robot.py

@@ -0,0 +1,17 @@
+import requests
+
+url = "https://oapi.dingtalk.com/robot/send?access_token=2add07f31eb0245fa45eed86101253363813b5e70c4d55d0aeb0df2f8b421372"
+
+
+def sendDingMsg(error_type, error_message):
+    # 'Content-Type' => 'application/json'
+    headers = {
+        "Content-Type": "application/json"
+    }
+    data = {
+        "text": {
+            "content": f"【拍照机】异常-{error_type}\n{error_message}"
+        },
+        "msgtype": "text"
+    }
+    requests.post(url, json=data, headers=headers)

+ 7 - 1
python/sockets/message_handler.py

@@ -349,14 +349,15 @@ async def handlerSend(
                 name="run_mcu_single",
             )
         case "handler_take_picture":
+            print("收到单拍指令", 'handler_take_picture')
             if data is None:
                 PointName = "A"
             else:
                 PointName = data.get("point_name", "A")
+            print("收到单拍指令", PointName)
             device_ctrl = DeviceControl(
                 websocket_manager=manager, smart_shooter=smart_shooter
             )
-            print("收到单拍指令", 'handler_take_picture')
             await device_ctrl.controlDevice("laser_position", 0)
             blue_tooth = BlueToothMode(
                 websocket_manager=manager, smart_shooter=smart_shooter
@@ -807,6 +808,11 @@ async def handlerSend(
                 data=dynamic_configs,
             )
             await manager.send_personal_message(data, websocket)
+        case "one_key_down":
+            device_ctrl = DeviceControl(
+                websocket_manager=manager, smart_shooter=smart_shooter
+            )
+            device_ctrl.one_key_down()
         case "get_dynamic_config_signle":
             device_ctrl = DeviceControl(
                 websocket_manager=manager, smart_shooter=smart_shooter

+ 2 - 7
python/temp.py

@@ -24,11 +24,6 @@ import zmq, json
 # json_msg = __send_tcp_message(req_socket,req)
 # cameraInfo = json_msg.get("CameraInfo")
 # print("cameraInfo",json_msg)
-from service.remove_bg_ali import RemoveUltraBackground
-import settings
+from service.online_request.ding_robot import sendDingMsg
 
-settings.USER_TOKEN = "c2f44c4c1171b84d13ee21f770fd32e773b910f2"
-r = RemoveUltraBackground()
-path = r"C:\Users\15001\Desktop\miniso\hb\原始图\hb(1).JPG"
-out_path = "{}._no_bg-out.png".format(path)
-r.get_image_cut(path, out_file_path=out_path)
+sendDingMsg("抠图异常", "抠图异常!!!")