Browse Source

Merge branch 'dev-python' of gitlab.pubdata.cn:liangyibo/CameraMachine into dev-python

zhangyh 8 months ago
parent
commit
ea503e62d2

+ 3 - 1
python/.gitignore

@@ -3,4 +3,6 @@ venv/
 *.log
 *.log.*
 resources/
-custom_plugins/
+custom_plugins/
+*.db
+*.pdf

BIN
python/database.db


+ 89 - 0
python/docs/socket命令.md

@@ -0,0 +1,89 @@
+## 智慧拍 socket 命令说明
+### Socket 连接信息
+    * 本地: ws://10.56.42.176:7074/ws
+    * 打包后: ws://127.0.0.1:7074/ws
+#### 统一响应示例说明
+* code:为0时代表成功操作
+* msg:为接口执行命令时的提示信息
+* status:-1连接失败  0未连接 1连接中  2链接成功  3端口占用
+* msg_type:mcu为设备控制,blue_tooth为蓝牙控制
+* data:为返回的数据信息,无实际交互需求时,前端可忽略
+```python
+{
+    "code": 0,
+    "msg": "开始识别接口:COM8",
+    "status": 1,
+    "data": {
+        "_type": "show_info",
+        "plugins_mode": "auto_select_com",
+        "data": {
+            "text": "开始识别接口:COM8"
+        }
+    },
+    "msg_type": "mcu"
+}
+```
+### 设备连接
+*  type 
+    * 值为connect_mcu时,为连接mcu设备操作
+    * 值为connect_bluetooth时,为连接蓝牙遥控器
+* data:可以忽略为null
+#### 请求示例
+```python
+{"data":null,"type":"connect_mcu"}
+```
+_<mark>以下操作前必须保证设备已连接!!!<mark>_
+### 初始化mcu设备
+_<mark>目前连接设备后,后端会自动进行设备初始化操作,如无特殊需求可忽略<mark>_
+*  type 固定为 init_mcu
+* data:可以忽略为null
+#### 请求示例
+```python
+{"data":null,"type":"init_mcu"}
+```
+### 单独控制设备得某一个功能运行命令
+_(该命令用于单独自定义配置中某一项的单独调整测试,不进行任何存储操作)_
+
+* type 为control_mcu时,为设备得单独控制 
+* data中的 device_name释义:
+  *  camera_high_motor:相机高度;步长1;最小0;最大400
+  *  camera_steering:相机倾角;步长0.1,最小-40;最大40
+  *  camera_steering:相机倾角
+  * turntable_steering:转盘角度;步长1;最小-720;最大720
+  * turntable_position_motor:转盘位置;步长1,最小0;最大800
+  * overturn_steering:翻转,当device_name为当前类型时,value可以忽略或传递任意值,后端不做任何处理
+  * take_picture:拍照测试;当device_name为当前类型时,value为0或者大于0的数值;提交对焦次数参数
+  * laser_position:激光开关;当device_name为当前类型时,value为0或者1;0为关   1为开
+* value为设备得控制值,参考上述的最大最小值进行处理
+#### 请求示例
+```python
+{
+    "data": {
+        "device_name": "camera_high_motor",
+        "value": 200
+    },
+    "type": "control_mcu"
+}
+```
+
+
+### 执行拍摄任务
+* type 为run_mcu时,为设备拍照动作连贯执行
+* data中的 action参数释义:
+    * 执行左脚程序 : 为用户配置【执行左脚程序】,其状态必须至少有一条为true,否则不会运行并且报错无可用参数
+    * 执行右脚程序 : 为用户配置【执行右脚程序】,其状态必须至少有一条为true,否则不会运行并且报错无可用参数
+* data中的 goods_art_no参数释义:
+    * 商品货号,必须存在且为字符串形式传递
+#### 请求示例
+```python
+{
+    "data": {
+        "action": "执行左脚程序",
+        "goods_art_no": "1234556"
+    },
+    "type": "run_mcu"
+}
+```
+
+
+### 未完待续.....

+ 2 - 0
python/mcu/BlueToothMode.py

@@ -48,12 +48,14 @@ class BlueToothMode(BaseClass,metaclass=SingletonType):
 
     async def scan_for_esp32(self):
         """扫描附近的BLE设备,并寻找ESP32"""
+        # print("打印连接状态", self.connect_state)
         if self.connect_state == True:
             return
         # self.sendSocketMessage(
         #     code=0, msg="遥控设备V2 未连接", data=None, device_status=-1
         # )
         # print("Scanning for ESP32 devices...*****************")
+        # print("打印连接状态2", self.connect_state)
         try:
             devices = await BleakScanner.discover()
         except BaseException as e:

+ 16 - 4
python/mcu/DeviceControl.py

@@ -9,6 +9,7 @@ from collections import defaultdict
 import threading
 import settings
 from .ProgramItem import ProgramItem
+from .capture.module_digicam import DigiCam
 
 # mcu命令
 class DeviceControl(BaseClass, metaclass=SingletonType):
@@ -1104,12 +1105,23 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
                 )
             case "overturn_steering":
                 # 翻板舵机中位
-                self.to_device_move(
+                self.to_deal_device(
                     device_name="overturn_steering",
-                    value=value,
-                    _is_debug=_is_debug,
-                    is_deviation=0,
                 )
+            case "laser_position":
+                self.to_deal_device(
+                    device_name="laser_position",
+                    value=0 if value <= 0 else 1
+                )
+            case "take_picture":
+                capture_one = DigiCam()
+                try:
+                    capture_one.getCaptureFolderPath()
+                    if value > 0:
+                        capture_one.auto_focus()
+                    capture_one.run_capture_action("Capture")
+                except:
+                    self.sendSocketMessage(1,"digicam未初始化,请检查",device_status=-1)
             case "to_deal_device":
                 self.to_deal_device(device_name, value=value, _type=0, times=1)
             case _:

+ 51 - 1
python/mcu/RemoteControlV2.py

@@ -1,13 +1,13 @@
 # module_remote_control_v2
 
 
+import json
 import time, asyncio
 import settings
 from .SerialIns import SerialIns
 from .BaseClass import BaseClass
 from sockets.connect_manager import ConnectionManager
 
-
 # from .BlueToothMode import BlueToothMode
 class RemoteControlV2(BaseClass):
     # sign_data = Signal(dict)
@@ -25,6 +25,7 @@ class RemoteControlV2(BaseClass):
         self.bluetooth_address = ""
         self.connect_state = False
         self.is_running = False
+        self.goods_art_no = None
 
     def to_connect_com(self, port_name, is_test=False):
         if self.connect_state:
@@ -142,6 +143,9 @@ class RemoteControlV2(BaseClass):
             flag = "接收器已连接 {}".format(
                 "蓝牙" if self.bluetooth_address else "串口"
             )
+            self.sendSocketMessage(code=0, msg="遥控设备V2 打开蓝牙成功", data=None,device_status=2)
+            self.connect_state = True
+            self.is_running = True
         else:
             flag = "接收器未连接"
             device_status = -1
@@ -204,6 +208,7 @@ class RemoteControlV2(BaseClass):
             bar_code = receive_data[1:].decode()
             bar_code = bar_code.replace("\r", "")
             bar_code = bar_code.replace("\n", "")
+            self.goods_art_no = bar_code
             message = {"_type": 0, "plugins_mode": "remote_control", "data": bar_code}
             print(message)
             self.sendSocketMessage(code=0, msg="", data=message, device_status=2)
@@ -214,6 +219,51 @@ class RemoteControlV2(BaseClass):
             data = {"button_value": button_value}
             message = {"_type": 9, "plugins_mode": "remote_control", "data": data}
             print(message)
+            if button_value in [1,2]:
+                # 扫描货号
+                print("收到货号信息", self.goods_art_no)
+                if self.goods_art_no == None or self.goods_art_no =="":
+                    self.sendSocketMessage(
+                        code=1, msg="货号信息不能为空", data=None, device_status=-1
+                    )
+                    return
+                control_program = (
+                    "执行左脚程序" if button_value == 1 else "执行右脚程序"
+                )
+                input_data = {
+                    "data": {
+                        "action": control_program,
+                        "goods_art_no": self.goods_art_no,
+                    },
+                    "type": "run_mcu",
+                }
+                # loop = asyncio.get_event_loop()
+                # session = SqlQuery()
+                # crud = CRUD(DeviceConfig)
+                # condtions = {"mode_type": control_program, "action_status": True}
+                # all_devices = crud.read_all(
+                #     session, conditions=condtions, order_by="action_index", ascending=True
+                # )
+                # if len(all_devices) == 0:
+                #     self.sendSocketMessage(
+                #         code=1,
+                #         msg=f"当前没有可用配置",
+                #         data=input_data,
+                #         device_status=2,
+                #     )
+                #     return
+                # action_list = [device.model_dump() for device in all_devices]
+                # print("action_list", action_list)
+                # loop.create_task(
+                #     device_ctrl.run_mcu_config(action_list, self.goods_art_no),
+                #     name="run_mcu_config",
+                # )
+                self.sendSocketMessage(
+                    code=0,
+                    msg=f"准备执行[{control_program}]",
+                    data=input_data,
+                    device_status=2,
+                )
             self.sendSocketMessage(code=0, msg="", data=message, device_status=2)
             if settings.IS_DEBUG:
                 print("收到按键", button_value)

+ 2 - 5
python/mcu/capture/capture_basic_mode.py

@@ -38,15 +38,12 @@ class CaptureBasic():
 
     def getCaptureFolderPath(self) -> Image:
         """获取预览图"""
-        try:
-            response = httpGetHandler(
+        response = httpGetHandler(
             url=self.base_host,
             params={"slc": "get", "param1": "session.folder"},
             headers={},
             )
-            return response.text
-        except:
-          return None
+        return response.text
 
     def run_capture_action(self,command):
         '''执行capture动作'''

+ 6 - 2
python/sockets/message_handler.py

@@ -38,6 +38,7 @@ async def handlerSend(
         case "connect_bluetooth":
             blue_tooth = BlueToothMode(websocket_manager=manager)
             # await  blue_tooth.main_func()
+            print("连接蓝牙信息")
             loop.create_task(blue_tooth.main_func(), name="blue_tooth")
             # loop.close()
         case "init_mcu":
@@ -57,13 +58,16 @@ async def handlerSend(
         case "run_mcu":
             action_info = data.get("action", "执行左脚程序")
             goods_art_no = data.get("goods_art_no", None)
-            if goods_art_no == None:
+            if goods_art_no == None or goods_art_no =="":
                 data = manager.jsonMessage(code=1, msg="goods_art_no不能为空")
                 await manager.send_personal_message(data, websocket)
                 return
             session = SqlQuery()
             crud = CRUD(DeviceConfig)
-            all_devices = crud.read_all(session, conditions={"mode_type": action_info})
+            condtions = {"mode_type": action_info, "action_status": True}
+            all_devices = crud.read_all(
+                session, conditions=condtions, order_by="action_index", ascending=True
+            )
             if len(all_devices) == 0:
                 data = manager.jsonMessage(code=1, msg="当前没有可用配置")
                 await manager.send_personal_message(data, websocket)