Casper 4 månader sedan
förälder
incheckning
84f57f80d4

+ 46 - 0
sri-server-bg03/Dockerfile

@@ -0,0 +1,46 @@
+#FROM ubuntu:20.04
+FROM docker.m.daocloud.io/ubuntu:20.04
+ENV DEBIAN_FRONTEND=noninteractive
+#FROM docker.m.daocloud.io/ubuntu:18.04
+
+RUN echo "Debug Tools:" \
+    && apt-get update \
+    && apt-get install -y inetutils-ping iproute2 net-tools wget unzip git bash
+
+RUN echo "Install Python v3.8:" \
+    && apt-get update \
+    && apt-get install -y  \
+        python3-dev \
+        python3-pip \
+        python3-setuptools \
+        python3-wheel \
+    && pip3 config set global.index-url https://mirror.baidu.com/pypi/simple \
+    && pip3 config set global.extra-index-url https://pypi.tuna.tsinghua.edu.cn/simple \
+    && pip3 install --upgrade --quiet pip setuptools \
+    && python3 --version
+
+RUN echo "部署:安装protobuf" \
+    && apt update \
+    && apt install -y protobuf-compiler python3-protobuf \
+    && protoc --version
+
+#RUN echo "Install Python Requirements:" \
+#    && pip3 install --default-timeout=1800 --no-cache-dir \
+#        # --- for base --- \
+#        cython==3.0.0a9 \
+#        pyinstaller==4.10 \
+#        # --- for libraries --- \
+#        pycrypto==2.6.1 \
+#        paramiko==2.7.2 \
+#        apscheduler==3.7.0 \
+#        # --- for client --- \
+#        requests==2.25.1 \
+#        redis==3.5.3 \
+#        pymongo==3.11.2 \
+#        influxdb==5.3.1 \
+#        pymysql==0.9.3 \
+#        peewee==3.17.0 \
+#        SQLAlchemy==1.4.30 \
+#        paho-mqtt==1.6.1 \
+#    && echo "End."
+

+ 60 - 0
sri-server-bg03/README-usage.bash

@@ -0,0 +1,60 @@
+## USAGE
+
+sudo docker logs -f sri-dino-pyserver01  # 查看日志
+
+echo "操作:代码更新" \
+&& project_path="/home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01" \
+&& cd ${project_path} \
+&& sudo docker-compose --file compose.yml restart \
+&& sudo docker-compose --file compose.yml logs --follow
+
+echo "操作:停服更新" \
+&& project_path="/home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01" \
+&& cd ${project_path} \
+&& sudo docker-compose --file compose.yml down \
+&& sudo docker-compose --file compose.yml up --detach \
+&& sudo docker-compose --file compose.yml logs --follow
+
+echo "操作:构建调试" \
+&& project_path="/home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01" \
+&& cd ${project_path} \
+&& sudo docker-compose --file compose.yml down \
+&& sudo docker-compose --file compose.yml up --detach --build \
+&& sudo docker exec -it sri-dino-pyserver01 bash
+
+echo "操作:启动调试环境" \
+&& project_path="/home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01" \
+&& cd ${project_path} \
+&& sudo docker-compose --file compose.yml down \
+&& sudo docker-compose --file compose.yml up --detach \
+&& sudo docker exec -it sri-dino-pyserver01 bash
+
+echo "操作:重启调试环境" \
+&& project_path="/home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01" \
+&& cd ${project_path} \
+&& sudo docker-compose --file compose.yml restart \
+&& sudo docker exec -it sri-dino-pyserver01 bash
+
+echo "操作:进入调试环境" \
+&& project_path="/home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01" \
+&& cd ${project_path} \
+&& sudo docker exec -it sri-dino-pyserver01 bash
+
+echo "操作:初装启动" \
+&& project_path="/home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01" \
+&& cd ${project_path} \
+&& sudo docker-compose --file compose.yml down \
+&& sudo docker-compose --file compose.yml up --detach --build \
+&& sudo docker-compose --file compose.yml logs --follow
+
+echo "操作:开发调试" \
+&& project_path="/home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01" \
+&& cd ${project_path} \
+&& sudo docker-compose --file compose.yml down \
+&& sudo docker-compose --file compose.yml up --detach \
+&& sudo docker exec -it sri-dino-pyserver01 bash
+
+echo "操作:跟踪日志" \
+&& project_path="/home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01" \
+&& cd ${project_path} \
+&& sudo docker-compose --file compose.yml logs --follow

+ 6 - 0
sri-server-bg03/README.md

@@ -0,0 +1,6 @@
+## DINO产品服务端程序开发
+
+#### INFO
+
+* 用途:实验室环境egoserver服务平替
+* 状态:进行中(2024年9月)

+ 39 - 0
sri-server-bg03/compose.yml

@@ -0,0 +1,39 @@
+version: '3.5'
+services:
+
+    sri-dino-pyserver01:
+
+        # --- building ---
+        image: sri-dino-pyserver01:2024
+        build:
+            context: ./
+            dockerfile: ./Dockerfile
+        environment:
+            TZ: Asia/Shanghai
+
+        # --- binding ---
+        volumes:
+            - /home:/home
+#        networks:
+#            - sri_network
+#        ports:
+#            - "20916:20916"
+#            - "20917:20917"
+        network_mode: host
+
+        # --- running ---
+        container_name: sri-dino-pyserver01
+
+        # --- for debug ---
+#        working_dir: /home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01
+#        stdin_open: true
+#        tty: true
+
+        # --- for release ---
+        working_dir: /home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01
+        command: bash run.sh
+        restart: always
+
+#networks:
+#    sri_network:
+#        external: true

+ 15 - 0
sri-server-bg03/hub.py

@@ -0,0 +1,15 @@
+import sys
+import importlib
+
+sys.path.append('../sri-pysdk')
+
+methods = importlib.import_module(f"xlib")
+
+
+class Global(object):
+    pb = importlib.import_module(f"protobuf.protocol_pb2")
+
+    # emqx = importlib.import_module(f"xclient.xmqtt").Client(host='10.10.61.229', port=41883)
+
+    # mdb = importlib.import_module(f"xclient.xmongo").Client(host='58.34.94.178', port=7030, database='bg',
+    #                                                         username='admin', password='admin')

+ 72 - 0
sri-server-bg03/lib/ConnectionTest2004.py

@@ -0,0 +1,72 @@
+"""
+echo "执行:进入调试" \
+&& project_path="/home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01" \
+&& cd ${project_path} \
+&& sudo docker exec -it sri-dino-pyserver01 bash
+
+python3 /home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01/lib/ConnectionTest.py
+"""
+import socket
+import struct
+import traceback
+import time
+
+import sys
+import importlib
+
+# --- for linux
+sys.path.append('/home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01')
+sys.path.append('/home/sri/repositories/repositories/sri-project.demo-py/3rdparty')
+# host, port = '127.0.0.1', 20916
+host, port = '127.0.0.1', 20917
+
+# --- for windows
+# sys.path.append(r'E:\casper\repositories\repositories\sri-project.demo-py\sri-server-bg03')
+# sys.path.append(r'E:\casper\repositories\repositories\sri-project.demo-py\3rdparty')
+# host, port = '58.34.94.178', 20916
+# host, port = '58.34.94.178', 20916
+# host, port = '58.34.94.178', 20917
+
+# --- import
+protobuf = importlib.import_module(f"xprotobuf.protocol_pb2")
+methods = importlib.import_module(f"xlib")
+
+
+def test():
+    head_sequence = '<hh'  # 字节序规则
+    head_size = struct.calcsize(head_sequence)
+
+    try:
+        client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        # client.bind(('localhost', port))
+        client.connect((host, port))
+
+        # --- send 2004
+        object = protobuf.Offer()
+        object.index = 1
+        object.peer = 1000004
+        object.type = 'offer'
+        object.sdp = 'aabbcc'
+        head = 2004, object.ByteSize()
+        head_bytestream = struct.pack(head_sequence, *head)
+        body_bytestream = object.SerializeToString()
+        send_bytestream = head_bytestream + body_bytestream
+        print(f"Sent data: {send_bytestream}")
+        client.sendall(send_bytestream)
+
+        # 等待接收
+        while True:
+            pass
+
+
+    except Exception as exception:
+
+        print(f"#exception: {exception.__class__.__name__}")
+        print(f"#traceback: {traceback.format_exc()}")
+
+    finally:
+        client.close()
+
+
+if __name__ == "__main__":
+    test()

+ 64 - 0
sri-server-bg03/lib/ConnectionTest2008.py

@@ -0,0 +1,64 @@
+"""
+echo "执行:进入调试" \
+&& project_path="/home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01" \
+&& cd ${project_path} \
+&& sudo docker exec -it sri-dino-pyserver01 bash
+
+python3 /home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01/lib/ConnectionTest.py
+"""
+import socket
+import struct
+import traceback
+import time
+
+import sys
+import importlib
+
+# --- for linux
+sys.path.append('/home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01')
+sys.path.append('/home/sri/repositories/repositories/sri-project.demo-py/3rdparty')
+# host, port = '127.0.0.1', 20916
+host, port = '127.0.0.1', 20917
+
+# --- for windows
+# sys.path.append(r'E:\casper\repositories\repositories\sri-project.demo-py\sri-server-bg03')
+# sys.path.append(r'E:\casper\repositories\repositories\sri-project.demo-py\3rdparty')
+# host, port = '58.34.94.178', 20916
+# host, port = '58.34.94.178', 20916
+# host, port = '58.34.94.178', 20917
+
+# --- import
+protobuf = importlib.import_module(f"xprotobuf.protocol_pb2")
+methods = importlib.import_module(f"xlib")
+
+
+def test():
+    head_sequence = '<hh'  # 字节序规则
+    head_size = struct.calcsize(head_sequence)
+
+    try:
+        client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        # client.bind(('localhost', port))
+        client.connect((host, port))
+
+        # --- send 2008
+        head = 2008, 0
+        head_bytestream = struct.pack(head_sequence, *head)
+        send_bytestream = head_bytestream
+        print(f"Sent data: {send_bytestream}")
+        client.sendall(send_bytestream)
+
+        while True:
+            pass
+
+    except Exception as exception:
+
+        print(f"#exception: {exception.__class__.__name__}")
+        print(f"#traceback: {traceback.format_exc()}")
+
+    finally:
+        client.close()
+
+
+if __name__ == "__main__":
+    test()

+ 110 - 0
sri-server-bg03/lib/ConnectionTest4008.py

@@ -0,0 +1,110 @@
+"""
+echo "执行:进入调试" \
+&& project_path="/home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01" \
+&& cd ${project_path} \
+&& sudo docker exec -it sri-dino-pyserver01 bash
+
+python3 /home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01/lib/ConnectionTest.py
+"""
+import socket
+import struct
+import traceback
+import time
+
+import sys
+import importlib
+
+# --- for linux
+sys.path.append('/home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01')
+sys.path.append('/home/sri/repositories/repositories/sri-project.demo-py/3rdparty')
+# host, port = '127.0.0.1', 20916
+host, port = '127.0.0.1', 20917
+
+# --- for windows
+# sys.path.append(r'E:\casper\repositories\repositories\sri-project.demo-py\sri-server-bg03')
+# sys.path.append(r'E:\casper\repositories\repositories\sri-project.demo-py\3rdparty')
+# host, port = '58.34.94.178', 20916
+# host, port = '58.34.94.178', 20916
+# host, port = '58.34.94.178', 20917
+
+# --- import
+protobuf = importlib.import_module(f"xprotobuf.protocol_pb2")
+methods = importlib.import_module(f"xlib")
+
+
+def test():
+    head_sequence = '<hh'  # 字节序规则
+    head_size = struct.calcsize(head_sequence)
+
+    try:
+        client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        # client.bind(('localhost', port))
+        client.connect((host, port))
+
+        # --- send 2000
+        object = protobuf.CSSign()
+        object.account = 'admin'
+        object.password = '123456'
+        head = protobuf.CS_Sign, object.ByteSize()
+        head_bytestream = struct.pack(head_sequence, *head)
+        body_bytestream = object.SerializeToString()
+        send_bytestream = head_bytestream + body_bytestream
+        print(f"Sent data: {send_bytestream}")
+        client.sendall(send_bytestream)
+
+        # 等待接收
+        count = 0
+        while True:
+
+            # --- 解析数据头
+            head_bytestream = client.recv(head_size)
+            if not head_bytestream:
+                continue
+            command_id, body_length = struct.unpack(head_sequence, head_bytestream)
+            methods.debug_log('ConnectionTest64', f"Received values: {command_id, body_length}")
+
+            # --- 解析数据体 4000
+            # body_bytestream = client.recv(body_length)
+            # object = protobuf.SCSign()
+            # object.ParseFromString(body_bytestream)
+            # methods.debug_log('ConnectionTest70', f"Received Response:")
+            # methods.debug_log('ConnectionTest70', f"#ret: {object.ret}")
+            # methods.debug_log('ConnectionTest70', f"#uid: {object.uid}")
+            # methods.debug_log('ConnectionTest70', f"#uid: {object.name}")
+
+            # --- 解析数据体 4008
+            body_bytestream = client.recv(body_length)
+            object = protobuf.SCRobot()
+            object.ParseFromString(body_bytestream)
+            print(f'#################### {type(object.robot)}')
+            print(f'-------------------- {object.robot[0].rid}')
+            print(f'-------------------- {object.robot[0].name}')
+            print(f'-------------------- {object.robot[0].type}')
+            print(f'-------------------- {object.robot[0].state}')
+            print(f'-------------------- {object.robot[1].rid}')
+            print(f'-------------------- {object.robot[1].name}')
+            print(f'-------------------- {object.robot[1].type}')
+            print(f'-------------------- {object.robot[1].state}')
+
+            # --- debug
+            count += 1
+            print(f"count: {count}")
+
+            # --- 发送1次就退出
+            # break
+
+            # --- 发送1次后等待
+            continue
+
+
+    except Exception as exception:
+
+        print(f"#exception: {exception.__class__.__name__}")
+        print(f"#traceback: {traceback.format_exc()}")
+
+    finally:
+        client.close()
+
+
+if __name__ == "__main__":
+    test()

+ 381 - 0
sri-server-bg03/lib/Connection_a1.py

@@ -0,0 +1,381 @@
+# from hub import methods, Global
+
+import threading
+import socket
+import struct
+import time
+# import cv2
+# import base64
+# import asyncio
+
+import sys
+import importlib
+
+sys.path.append('/home/server/repositories/repositories/sri-project.demo-py/sri-server-bg03')
+protobuf = importlib.import_module(f"protobuf.protocol_pb2")
+sys.path.append('/home/server/repositories/repositories/sri-project.demo-py/3rdparty')
+methods = importlib.import_module(f"xlib")
+
+
+class Connection(object):
+    """"""
+
+    tcp_server = None
+    tcp_client = None
+    all_connection_dict = {}  # {<ipv4>: (socket, update_at, type)} | {<连接id>: (socket对象, 最后一次请求时间, 客户端类型)}
+
+    @classmethod
+    def get_method_by_command_id(cls, command_id):
+        """获取方法名"""
+        fn_dict = {
+            protobuf.CS_Sign: cls.f1,  # 建立webrtc邀请
+        }
+        return fn_dict.get(command_id)
+
+    @classmethod
+    def f1(cls):
+        pass
+
+    # @classmethod
+    # def run_forever(cls):
+    #     """
+    #     调用协程方法
+    #     """
+    #     tasks = [cls.check_send()]
+    #     _loop = asyncio.new_event_loop()
+    #     asyncio.set_event_loop(_loop)
+    #     loop = asyncio.get_event_loop()
+    #     loop.run_until_complete(asyncio.wait(tasks))
+
+    # @classmethod
+    # async def check_send(cls):
+    #
+    #     # --- define ---
+    #     last_send_id = str()
+    #
+    #     while True:
+    #
+    #         try:
+    #             # --- fill face_type_name_dict ---
+    #             """
+    #             face_type_name_dict = {<type_uuid>: <name>}
+    #             """
+    #             face_type_name_dict = dict()
+    #             for item in Global.mdb.get_all('FaceType'):
+    #                 uuid = str(item.get('_id'))
+    #                 face_type_name_dict[uuid] = item.get('name')
+    #
+    #             # --- debug ---
+    #             # methods.debug_log(f"LineManage", f"m-21: run at {methods.now_string()} "
+    #             #                                  f"| {len(cls.line_dict.values())}")
+    #             # await asyncio.sleep(3)
+    #             # await asyncio.sleep(0.5)
+    #
+    #             # --- get send_data ---
+    #             """
+    #             send_data = {
+    #                 send_id: 数据id
+    #                 send_list: 数据列表
+    #             }
+    #             """
+    #             send_data = Global.rdb.get_one(key='send_data')
+    #             # send_data = db0.get_one(key='send_data')
+    #
+    #             # --- check ---
+    #             if not send_data:
+    #                 continue
+    #
+    #             # --- check ---
+    #             send_id = send_data.get('send_id')
+    #             if not send_id:
+    #                 continue
+    #
+    #             # --- check ---
+    #             if send_id == last_send_id:
+    #                 continue
+    #
+    #             # --- check ---
+    #             send_list = send_data.get('send_list')
+    #             if send_list is None or len(send_list) == 0:
+    #                 continue
+    #
+    #             # --- debug ---
+    #             # await asyncio.sleep(3)
+    #             # await asyncio.sleep(0.5)
+    #             methods.debug_log(f"LineManage", f"m-74: run at {methods.now_string()} "
+    #                                              f"| send count is {len(send_list)} "
+    #                                              f"| online count is {len(cls.line_dict.values())}")
+    #
+    #             # --- update ---
+    #             last_send_id = send_id
+    #
+    #             # --- send ---
+    #             for line_id in list(cls.line_dict.keys()):
+    #
+    #                 try:
+    #
+    #                     # --- check ---
+    #                     if not cls.check_line_is_live(line_id):
+    #                         methods.debug_log(f"LineManage", f"m-56: websocket link broken.")
+    #                         cls.line_dict.pop(line_id)
+    #                         continue
+    #
+    #                     # --- send ---
+    #                     """
+    #                     send_list = [
+    #                         {
+    #                             base_face_uuid: 底库人脸id
+    #                             snap_face_image: 抓拍人脸
+    #                             base_face_image_path: 底库人脸路径
+    #                             face_similarity: 相似度
+    #                         }
+    #                     ]
+    #                     """
+    #                     for data in send_list:
+    #
+    #                         # --- check ---
+    #                         if data.get('snap_face_image') is None:
+    #                             continue
+    #
+    #                         # --- define ---
+    #                         """
+    #                         send_dict = {
+    #                             input_face_b64: 抓拍人脸图像
+    #                             face_uuid: 人脸id
+    #                             face_name: 人脸名称
+    #                             known_face_b64: 底库人脸图像
+    #                             face_similarity: 相似度
+    #                             face_type_name_list: 人员类型
+    #                         }
+    #                         """
+    #                         send_dict = dict(
+    #                             input_face_b64=cls.image_to_b64(data.get('snap_face_image')),
+    #                             # input_face_b64=str(),
+    #                             known_face_b64=str(),
+    #                             face_uuid=str(),
+    #                             face_name=str(),
+    #                             face_similarity=data.get('face_similarity'),
+    #                             face_type_name_list=list(),
+    #                         )
+    #
+    #                         # --- fill known_face_b64 ---
+    #                         base_face_image_path = data.get('base_face_image_path')
+    #                         if base_face_image_path and methods.is_file(base_face_image_path):
+    #                             frame = cv2.imread(base_face_image_path)
+    #                             if frame is not None:
+    #                                 _, image = cv2.imencode('.jpg', frame)
+    #                                 base64_data = base64.b64encode(image)  # byte to b64 byte
+    #                                 s = base64_data.decode()  # byte to str
+    #                                 send_dict['known_face_b64'] = f'data:image/jpeg;base64,{s}'
+    #
+    #                         # --- fill face_uuid and face_name ---
+    #                         """
+    #                         Face: 陌生人脸表
+    #                         Face.face_name: 人脸名称
+    #                         """
+    #                         face_uuid = data.get('base_face_uuid')
+    #                         if face_uuid:
+    #                             send_dict['face_uuid'] = face_uuid
+    #                             face = Global.mdb.get_one_by_id('Face', face_uuid)
+    #                             if face and face.get('face_name'):
+    #                                 send_dict['face_name'] = face.get('face_name')
+    #
+    #                             # --- fill face_type_name_list ---
+    #                             face_type_uuid_list = face.get('face_type_uuid_list')
+    #                             if face_type_uuid_list:
+    #                                 send_dict['face_type_name_list'] = [face_type_name_dict.get(i)
+    #                                                                     for i in face_type_uuid_list
+    #                                                                     if face_type_name_dict.get(i)]
+    #
+    #                         # --- send ---
+    #                         # methods.debug_log(f"LineManage", f"m-153: send_dict is {send_dict}")
+    #                         line = cls.line_dict.get(line_id)
+    #                         send_json = methods.json_dumps(send_dict)
+    #                         await line.send_text(send_json)
+    #                         # await asyncio.sleep(0.1)
+    #
+    #                 except Exception as exception:
+    #
+    #                     # --- check ---
+    #                     if not cls.check_line_is_live(line_id):
+    #                         cls.line_dict.pop(line_id)
+    #
+    #                     if exception.__class__.__name__ == 'RuntimeError':
+    #                         methods.debug_log(f"LineManage", f"m-170: {cls.get_line_state()}")
+    #                     else:
+    #                         methods.debug_log('LineManage', f"m-172: exception | {exception}")
+    #                         methods.debug_log('LineManage', f"m-172: traceback | {methods.trace_log()}")
+    #
+    #         except Exception as exception:
+    #
+    #             methods.debug_log('LineManage', f"m-179: exception | {exception}")
+    #             methods.debug_log('LineManage', f"m-179: traceback | {methods.trace_log()}")
+    #             methods.debug_log('LineManage', f"m-179: wait 1 minutes try again!")
+    #             await asyncio.sleep(60)
+
+    # @classmethod
+    # def get_line_total(cls):
+    #     count = 0
+    #     for k, v in cls.line_dict.items():
+    #         count += 1
+    #     return count
+
+    # @classmethod
+    # def check_line_is_live(cls, line_id):
+    #     d1 = {
+    #         0: 'CONNECTING',
+    #         1: 'CONNECTED',
+    #         2: 'DISCONNECTED',
+    #     }
+    #     line = cls.line_dict.get(line_id)
+    #     if line and d1.get(line.client_state.value) != 'DISCONNECTED':
+    #         return True
+    #     else:
+    #         return False
+
+    # @classmethod
+    # def get_line_state(cls):
+    #     d1 = {
+    #         0: 'CONNECTING',
+    #         1: 'CONNECTED',
+    #         2: 'DISCONNECTED',
+    #     }
+    #     d2 = dict()  # {<line_id>: <state>}
+    #     for line_id, line in cls.line_dict.items():
+    #         state = d1.get(line.client_state.value)
+    #         _id = line_id[-6:]
+    #         d2[_id] = state
+    #     return d2
+
+    # @staticmethod
+    # def image_to_b64(image):
+    #     frame = numpy_method.to_array(image)  # list to numpy array
+    #     _, image = cv2.imencode('.jpg', frame)
+    #     base64_data = base64.b64encode(image)
+    #     s = base64_data.decode()
+    #     return f'data:image/jpeg;base64,{s}'
+
+    @classmethod
+    def create_tcp_server(cls, host='0.0.0.0', port=20916):
+        cls.tcp_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        cls.tcp_server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+        cls.tcp_server.bind((host, port))
+        cls.tcp_server.listen(10)  # 设置可处理的未处理连接请求的最大数量
+        methods.debug_log('Connection.260', f"Server listening on {host}:{port}")
+
+    @classmethod
+    def start_listener(cls):
+
+        cls.create_tcp_server()
+        head_sequence = '<hh'  # 字节序规则
+        head_size = struct.calcsize(head_sequence)
+
+        while True:
+
+            try:
+                # --- 等待连接 ---
+                client, ipv4 = cls.tcp_server.accept()
+                # cls.clients[ipv4] = client, 时间戳, 客户端类型
+                methods.debug_log('Connection.260', f"Connected by {ipv4}")
+
+                # --- 解析数据头
+                head_bytestream = client.recv(head_size)
+                if not head_bytestream:
+                    continue
+                command_id, body_length = struct.unpack(head_sequence, head_bytestream)
+                methods.debug_log('Connection.284', f"Received values: {command_id, body_length}")
+
+                # --- debug ---
+                # command_id, body_length = struct.unpack('<hh', head_bytestream)
+                # methods.debug_log('Connection.1', f"Received values: {command_id, body_length}")
+                # command_id, body_length = struct.unpack('<HH', head_bytestream)
+                # methods.debug_log('Connection.2', f"Received values: {command_id, body_length}")
+                # command_id, body_length = struct.unpack('>hh', head_bytestream)
+                # methods.debug_log('Connection.5', f"Received values: {command_id, body_length}")
+                # command_id, body_length = struct.unpack('>HH', head_bytestream)
+                # methods.debug_log('Connection.6', f"Received values: {command_id, body_length}")
+                # command_id, body_length = struct.unpack('@hh', head_bytestream)
+                # methods.debug_log('Connection.9', f"Received values: {command_id, body_length}")
+                # command_id, body_length = struct.unpack('@HH', head_bytestream)
+                # methods.debug_log('Connection.10', f"Received values: {command_id, body_length}")
+                # command_id, body_length = struct.unpack('=hh', head_bytestream)
+                # methods.debug_log('Connection.13', f"Received values: {command_id, body_length}")
+                # command_id, body_length = struct.unpack('=HH', head_bytestream)
+                # methods.debug_log('Connection.14', f"Received values: {command_id, body_length}")
+
+                # command_id, body_length = struct.unpack('<ii', head_bytestream)
+                # methods.debug_log('Connection.3', f"Received values: {command_id, body_length}")
+                # command_id, body_length = struct.unpack('<II', head_bytestream)
+                # methods.debug_log('Connection.4', f"Received values: {command_id, body_length}")
+                # command_id, body_length = struct.unpack('>ii', head_bytestream)
+                # methods.debug_log('Connection.7', f"Received values: {command_id, body_length}")
+                # command_id, body_length = struct.unpack('>II', head_bytestream)
+                # methods.debug_log('Connection.8', f"Received values: {command_id, body_length}")
+                # command_id, body_length = struct.unpack('@ii', head_bytestream)
+                # methods.debug_log('Connection.11', f"Received values: {command_id, body_length}")
+                # command_id, body_length = struct.unpack('@II', head_bytestream)
+                # methods.debug_log('Connection.12', f"Received values: {command_id, body_length}")
+                # command_id, body_length = struct.unpack('=ii', head_bytestream)
+                # methods.debug_log('Connection.15', f"Received values: {command_id, body_length}")
+                # command_id, body_length = struct.unpack('=II', head_bytestream)
+                # methods.debug_log('Connection.16', f"Received values: {command_id, body_length}")
+
+                # --- 解析数据体
+                if command_id == protobuf.CS_KeepAlive:
+                    continue
+                elif command_id == protobuf.CS_Sign:
+                    # --- 接收请求数据
+                    body_bytestream = client.recv(body_length)
+                    object = protobuf.CSSign()
+                    object.ParseFromString(body_bytestream)
+                    print(f"Received Response: account={object.account}, password={object.password}")
+
+                    # --- 发送返回数据
+                    object = protobuf.SCSign()
+                    object.ret = True
+                    object.uid = 112233
+                    object.cid = 223344
+                    object.name = 'aabbcc'
+                    command_id = protobuf.SC_Sign
+                    body_length = object.ByteSize()
+                    head_bytestream = struct.pack(head_sequence, command_id, body_length)
+                    body_bytestream = object.SerializeToString()
+                    send_bytestream = head_bytestream + body_bytestream
+                    client.sendall(send_bytestream)
+                    print(f"Sent data: {send_bytestream}")
+
+                    # --- test ---
+                    # for _ in range(10):
+                    #     for i in range(3)[::-1]:
+                    #         methods.debug_log('SRIConnection.58', f"sleep {i}s! | [{ipv4}]")
+                    #         time.sleep(1)
+                    #     methods.debug_log('SRIConnection.58', f"send re_send_data | [{ipv4}]")
+                    #     client.sendall(send_bytestream)
+
+
+            except Exception as exception:
+
+                methods.debug_log('Connection.287', f"#exception: {exception}")
+                methods.debug_log('Connection.287', f"#traceback: {methods.trace_log()}")
+
+            finally:
+                client.close()
+
+    @classmethod
+    def run(cls, background_is=True):
+        thread_list = [
+            threading.Thread(target=cls.start_listener),  # 人脸检测 deepstream facenet
+        ]
+        for thread in thread_list:
+            thread.setDaemon(True)
+            thread.start()
+        if background_is:
+            return
+        for thread in thread_list:
+            thread.join()
+
+
+if __name__ == '__main__':
+    print(protobuf.CS_Offer)
+
+    Connection.run(background_is=False)

+ 602 - 0
sri-server-bg03/lib/Connection_d1.py

@@ -0,0 +1,602 @@
+"""
+todo
+    1、存在消息被异步多次处理的问题
+"""
+# from hub import methods, Global
+
+import struct
+import asyncio
+import time
+import socket
+
+import sys
+import importlib
+
+# --- for linux
+sys.path.append('/home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01')
+sys.path.append('/home/sri/repositories/repositories/sri-project.demo-py/sri-pysdk')
+
+protobuf = importlib.import_module(f"xprotobuf.protocol_pb2")
+methods = importlib.import_module(f"xlib")
+clients = {}  # {<ipv4>: (socket, update_at, type)} | {<连接id>: (socket对象, 最后一次请求时间, 客户端类型)}
+serial_rid_dict = {
+    '65F7171A-5585-46C7-A9D6-967ABA9EB223': 1000000,
+    '7AF3F619-5067-4EE0-A710-89A6CB097EFE': 1000001,
+    'ECB93A87-560B-4022-8C5F-CBF9FE1E596A': 1000002,
+    'C0D14B6F-0FF0-4B68-877D-D2CB886FCD0E': 1000002,
+    'E537DDFB-6E3E-4E1A-AD18-AC21393BE300': 1000004,  # 正在使用
+}
+account_uid_dict = {
+    'ego': 3
+}
+
+
+class SRIConnection(asyncio.Protocol):
+    """"""
+
+    head_sequence = '<hh'  # 字节序规则
+    head_size = struct.calcsize(head_sequence)
+    message_data = b''
+
+    def connection_made(self, client):
+        """
+        建立客户端连接
+        """
+        peername = client.get_extra_info('peername')
+        self.connection_id = f"{peername[0].replace('.', '')}-{peername[1]}"  # 12700130000 客户端id
+        self.client = client
+        # self.data = b''
+        self.client_type = None
+        self.client_info = None
+        self.update_at = methods.now_ts()
+        clients[self.connection_id] = self
+
+        # 获取底层 socket
+        # sock = self.client.get_extra_info('socket')
+
+        # 查看缓冲区大小
+        # recv_buffer_size = sock.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF)
+        # send_buffer_size = sock.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF)
+        # methods.debug_log(f'{self.connection_id}|SRIConnection70', f"Receive buffer size: {recv_buffer_size}")
+        # methods.debug_log(f'{self.connection_id}|SRIConnection70', f"Send buffer size: {send_buffer_size}")
+
+    def connection_lost(self, exc):
+        """
+        关闭连接
+        """
+        methods.debug_log(f"{self.connection_id}|SRIConnection085", f"连接已关闭")
+
+        # --- 处理车端掉线,通知所有舱端
+        if self.client_type == 'vehicle':
+            """
+            SCDelRobot: 消息体
+            SCDelRobot.peer: int32
+            SCDelRobot.egotype: int32
+            """
+            o2 = protobuf.SCDelRobot()
+            o2.peer = self.client_info.get('rid')  # 车端唯一标识
+            o2.egotype = self.client_info.get('egotype')
+            re_command_id = protobuf.SC_NotifyDel  # 4017
+            re_body_length = o2.ByteSize()
+            re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+            re_body_data = o2.SerializeToString()
+            re_send_data = re_head_data + re_body_data
+            methods.debug_log(f"{self.connection_id}|SRIConnection085", f"re_command_id: {re_command_id}")
+            for item in clients.values():
+                if item.client_type == 'cockpit':
+                    item.client.write(re_send_data)
+
+        # --- clean
+        if self.connection_id in clients:
+            del clients[self.connection_id]
+
+    def data_received(self, data):
+        """
+        消息处理
+        """
+        # methods.debug_log(f'{self.connection_id}|SRIConnection96', f"data length: {len(data)}")
+        asyncio.create_task(self.handle_data(data))
+
+    async def handle_data(self, data):
+        """
+        消息处理
+        """
+        # methods.debug_log(f'{self.connection_id}|SRIConnection102', f"data length: {len(data)}")
+        loop = asyncio.get_running_loop()
+        await loop.run_in_executor(None, self.process_data, data)
+
+    def process_data(self, data):
+        """
+        消息处理
+        """
+        try:
+            methods.debug_log(f"{self.connection_id}|SRIConnection114", f"receive: {len(data)}, message: {repr(data)}")
+            self.message_data += data  # 执行了这个以后
+
+            methods.debug_log(f"{self.connection_id}|SRIConnection114", f"--- 1")
+            methods.debug_log(f"{self.connection_id}|SRIConnection114", f"--- 2")
+            methods.debug_log(f"{self.connection_id}|SRIConnection114", f"--- 3")
+
+            count = 0
+            while True:
+
+                # --- print
+                count += 1
+                methods.debug_log(f"{self.connection_id}|SRIConnection123",
+                                  f"---------------------------------- while count: {count}")
+
+                # 确保有足够的字节来处理消息头
+                if len(self.message_data) < self.head_size:
+                    break
+
+                # 获取消息头
+                head_data = self.message_data[:self.head_size]
+                command_id, body_length = struct.unpack(self.head_sequence, head_data)
+                methods.debug_log(f'{self.connection_id}|SRIConnection130',
+                                  f"command_id: {command_id}, body_length: {body_length}")
+
+                # 检查命令ID是否有效
+                if not (2000 <= command_id < 5000):
+                    self.message_data = b''  # 清空无效数据
+                    break
+
+                # 检查完整消息是否接收完毕
+                total_length = self.head_size + body_length
+                if len(self.message_data) < total_length:
+                    break  # 数据不完整,等待更多数据
+
+                # 调用相应处理方法
+                method = getattr(self, f'message{command_id}', None)
+                if method:
+                    method(self.message_data[self.head_size:total_length])  # 处理完整消息
+                else:
+                    methods.debug_log(f"{self.connection_id}|SRIConnectionError",
+                                      f"No handler for command_id: {command_id}")
+
+                # 移除已处理的消息
+                self.message_data = self.message_data[total_length:]
+
+        except Exception as exception:
+            methods.debug_log(f"{self.connection_id}|SRIConnection132", f"#exception: {exception}")
+            methods.debug_log(f"{self.connection_id}|SRIConnection123", f"#traceback: {methods.trace_log()}")
+
+    def message2008(self, body_data):
+        # methods.debug_log(f"{self.connection_id}|SRIConnection80", f"message: 2008")
+        pass
+
+    def message2009(self, body_data):
+
+        # --- 监听 2009
+        """
+        CSAdd: 消息体
+        CSAdd.serial: string
+        CSAdd.type: int32 EgoType::Car | EgoType::None EgoType::User EgoType::Car
+        CSAdd.name: string
+        """
+        object0 = protobuf.CSAdd()
+        object0.ParseFromString(body_data)
+        methods.debug_log(f"{self.connection_id}|SRIConnection90", f"#serial: {object0.serial}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection90", f"#name: {object0.name}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection90", f"#type: {object0.type}")
+
+        # --- update ---
+        self.client_type = 'vehicle'
+        self.client_info = {
+            'rid': serial_rid_dict.get(object0.serial),
+            'name': object0.name,
+            'serial': object0.serial,
+            'egotype': 2,  # 车端类型
+        }
+
+        # --- send 4016
+        """
+        SCAddRobot: 消息体
+        SCAddRobot.robot: Robot
+        Robot: 消息体
+        Robot.rid: int32
+        Robot.name: string
+        Robot.type: int32
+        Robot.state: RobotState Offline Online Busy
+        """
+        o1 = protobuf.Robot()
+        o1.rid = self.client_info.get('rid')
+        o1.name = object0.name
+        o1.type = 2  # 0 EgoType::None 1 EgoType::User 2 EgoType::Car
+        o1.state = protobuf.Robot.Online
+        o2 = protobuf.SCAddRobot()
+        o2.robot.CopyFrom(o1)
+        re_command_id = protobuf.SC_NotifyAdd  # 4016
+        re_body_length = o2.ByteSize()
+        re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+        re_body_data = o2.SerializeToString()
+        re_send_data = re_head_data + re_body_data
+        methods.debug_log(f"{self.connection_id}|SRIConnection136", f"sendmessage: {re_command_id}")
+
+        # --- send 4016 发送全部舱端
+        for item in clients.values():
+            if item.client_type == 'cockpit':
+                item.client.write(re_send_data)
+
+        # --- send 4007  todo 凯强说并未用到
+        # o1 = protobuf.SCAdd()
+        # o1.ret = True
+        # o1.uid = 112233  # todo 这个uid,应该是哪个舱端永辉在操作这个车 | 但是现在还没有人操控车
+        # o1.name = object0.name
+        # re_command_id = protobuf.SC_Add  # 4007
+        # re_body_length = o1.ByteSize()
+        # re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+        # re_body_data = o1.SerializeToString()
+        # re_send_data = re_head_data + re_body_data
+        # methods.debug_log(f"{self.connection_id} | SRIConnection150", f"re_command_id: {re_command_id}")
+        # self.client.write(re_send_data)
+
+    def message2000(self, body_data):
+
+        # --- 解析消息体
+        object = protobuf.CSSign()
+        object.ParseFromString(body_data)
+        methods.debug_log(f"{self.connection_id}|SRIConnection162", f"#account: {object.account}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection162", f"#password: {object.password}")
+
+        # --- update ---
+        self.client_type = 'cockpit'
+        self.client_info = {
+            'uid': 3,  # 对应数据库里的ego的id
+            'name': 'ego',  # 对应数据库里
+            'egotype': 1,  # 舱端类型
+        }
+
+        # --- send 4000
+        object = protobuf.SCSign()
+        object.ret = True
+        object.uid = self.client_info.get('uid')
+        object.name = self.client_info.get('name')
+        re_command_id = protobuf.SC_Sign  # 4000
+        re_body_length = object.ByteSize()
+        re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+        re_body_data = object.SerializeToString()
+        re_send_data = re_head_data + re_body_data
+        methods.debug_log(f"{self.connection_id}|SRIConnection175", f"re_command_id: {re_command_id}")
+        self.client.write(re_send_data)
+
+    def message2010(self, body_data):
+
+        # --- send 4008 发送全部车端信息列表
+        """
+        Robot: 消息体
+        Robot.rid: string
+        Robot.name: string
+        Robot.type: int32 EgoType::Car | EgoType::None EgoType::User EgoType::Car
+        Robot.state: enum Offline Online Busy
+        """
+        o2 = protobuf.SCRobot()
+        for item in clients.values():
+            if item.client_type and item.client_type == 'vehicle':
+                o1 = protobuf.Robot()
+                o1.rid = item.client_info.get('rid')
+                o1.name = item.client_info.get('name')
+                o1.type = 2  # EgoType::Car
+                o1.state = protobuf.Robot.RobotState.Value('Online')
+                o2.robot.add().CopyFrom(o1)
+
+        re_command_id = protobuf.SC_Robot  # 4008
+        re_body_length = o2.ByteSize()
+        re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+        re_body_data = o2.SerializeToString()
+        re_send_data = re_head_data + re_body_data
+        methods.debug_log(f"{self.connection_id}|SRIConnection217", f"re_command_id: {re_command_id}")
+        self.client.write(re_send_data)
+
+    def message2001(self, body_data):
+
+        # --- 解析消息体
+        """
+        CSReq: 消息体
+        CSReq.peer: int32(rid,车端唯一标识)
+        CSReq.index: int32(相机位置,RenderPosition)
+        CSReq.egotype: int32(终端类型,舱端/车端)
+        """
+        o1 = protobuf.CSReq()
+        o1.ParseFromString(body_data)
+        methods.debug_log(f"{self.connection_id}|SRIConnection299.message2001", f"#peer: {o1.peer}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection299.message2001", f"#peer: {o1.index}")
+        # methods.debug_log(f"{self.connection_id}|SRIConnection235.message2001",
+        #                   f"#=============================index: {o1.index}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection299.message2001", f"#egotype: {o1.egotype}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection299.message2001", f"#uid: {self.client_info.get('uid')}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection299.message2001", f"#rid: {self.client_info.get('rid')}")
+
+        # --- send 4009 指定车端
+        for item in clients.values():
+            if item.client_info.get('rid') and item.client_info.get('rid') == o1.peer:
+                """
+                CSReq: 消息体
+                CSReq.peer: int32(rid,车端唯一标识)
+                CSReq.index: int32(相机位置,RenderPosition)
+                CSReq.egotype: int32(终端类型,舱端/车端)
+                """
+                o2 = protobuf.CSReq()
+                o2.peer = self.client_info.get('uid')
+                o2.index = o1.index
+                o2.egotype = o1.egotype
+                re_command_id = protobuf.SC_NotifyReq  # 4009
+                re_body_length = o2.ByteSize()
+                re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+                re_body_data = o2.SerializeToString()
+                re_send_data = re_head_data + re_body_data
+                methods.debug_log(f"{self.connection_id}|SRIConnection217", f"re_command_id: {re_command_id}")
+                item.client.write(re_send_data)
+
+    def message2002(self, body_data):
+
+        # --- 解析消息体
+        """
+        CSRep: 消息体
+        CSRep.desc: VideoDesc
+        CSRep.peer: int32
+        CSRep.index: int32
+        CSRep.egotype: int32
+        """
+        o1 = protobuf.CSRep()
+        o1.ParseFromString(body_data)
+        methods.debug_log(f"{self.connection_id}|SRIConnection319", f"#desc: {o1.desc}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection319", f"#peer: {o1.peer}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection319", f"#index: {o1.index}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection319", f"#egotype: {o1.egotype}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection235", f"#uid: {self.client_info.get('uid')}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection235", f"#rid: {self.client_info.get('rid')}")
+
+        # --- send 4010 通知指定舱端
+        for item in clients.values():
+            if item.client_info.get('uid') and item.client_info.get('uid') == o1.peer:
+                o2 = protobuf.CSRep()
+                o2.desc = o1.desc
+                o2.peer = self.client_info.get('rid')
+                o2.index = o1.index
+                o2.egotype = o1.egotype
+                re_command_id = protobuf.SC_NotifyRep  # 4010
+                re_body_length = o2.ByteSize()
+                re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+                re_body_data = o2.SerializeToString()
+                re_send_data = re_head_data + re_body_data
+                methods.debug_log(f"{self.connection_id}|SRIConnection217", f"re_command_id: {re_command_id}")
+                item.client.write(re_send_data)
+
+    def message2004(self, body_data):
+
+        # --- 解析消息体
+        """
+        Offer: 消息体
+        Offer.index: int32
+        Offer.peer: int32(车端rid)
+        Offer.type: string
+        Offer.sdp: string
+        """
+        object = protobuf.Offer()
+        object.ParseFromString(body_data)
+        methods.debug_log(f"{self.connection_id}|SRIConnection348", f"#peer: {object.peer}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection348", f"#uid: {self.client_info.get('uid')}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection348", f"#rid: {self.client_info.get('rid')}")
+
+        # --- send 4012 指定车端
+        for item in clients.values():
+            if item.client_info.get('rid') and item.client_info.get('rid') == object.peer:
+                o1 = protobuf.Offer()
+                o1.index = object.index
+                o1.peer = self.client_info.get('uid')  # 将舱端id赋值到指定车端对象
+                o1.type = object.type
+                o1.sdp = object.sdp
+                re_command_id = protobuf.SC_NotifyOffer  # 4012
+                re_body_length = o1.ByteSize()
+                re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+                re_body_data = o1.SerializeToString()
+                re_send_data = re_head_data + re_body_data
+                methods.debug_log(f"{self.connection_id}|SRIConnection341", f"re_command_id: {re_command_id}")
+                item.client.write(re_send_data)
+
+    def message2005(self, body_data):
+
+        # --- 解析消息体
+        """
+        Answer: 消息体
+        Answer.index: int32
+        Answer.peer: int32(舱端uid)
+        Answer.type: string
+        Answer.sdp: string
+        """
+        object = protobuf.Answer()
+        object.ParseFromString(body_data)
+        methods.debug_log(f"{self.connection_id}|SRIConnection411", f"#peer: {object.peer}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection411", f"#uid: {self.client_info.get('uid')}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection411", f"#rid: {self.client_info.get('rid')}")
+
+        # --- send 4011 指定舱端
+        count = 0
+        for item in clients.values():
+
+            count += 1
+            methods.debug_log(f"{self.connection_id}|SRIConnection428",
+                              f"[{count}]item.client_info: {item.client_info}")
+
+            if item.client_info.get('uid') and item.client_info.get('uid') == object.peer:
+                o1 = protobuf.Answer()
+                o1.index = object.index
+                o1.peer = self.client_info.get('rid')  # 将车端id赋值到指定舱端对象,
+                o1.type = object.type
+                o1.sdp = object.sdp
+                re_command_id = protobuf.SC_NotifyAnswer  # 4011
+                re_body_length = o1.ByteSize()
+                re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+                re_body_data = o1.SerializeToString()
+                re_send_data = re_head_data + re_body_data
+                methods.debug_log(f"{self.connection_id}|SRIConnection428", f"re_command_id: {re_command_id}")
+                methods.debug_log(f"{self.connection_id}|SRIConnection428",
+                                  f"=====================================================-----index: {o1.index}")
+                item.client.write(re_send_data)
+
+    def message2006(self, body_data):
+
+        # --- 解析消息体
+        """
+        Candidate: 消息体
+        Candidate.index: int32
+        Candidate.peer: int32(车端rid)
+        Candidate.type: string
+        Candidate.candidate: string
+        Candidate.sdpMLineIndex: int32
+        Candidate.sdpMid: string
+        Candidate.egotype: int32
+        """
+        object = protobuf.Candidate()
+        object.ParseFromString(body_data)
+        methods.debug_log(f"{self.connection_id}|SRIConnection413", f"#peer: {object.peer}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection413", f"#candidate.in: {object.candidate}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection413", f"#uid: {self.client_info.get('uid')}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection413", f"#rid: {self.client_info.get('rid')}")
+
+        for item in clients.values():
+
+            # --- send 4013 舱端到车端
+            if item.client_info.get('rid') and item.client_info.get('rid') == object.peer:
+                o1 = protobuf.Candidate()
+                o1.index = object.index
+                o1.peer = self.client_info.get('uid')  # 将舱端id赋值到指定车端对象,
+                o1.type = object.type
+                o1.candidate = object.candidate
+                o1.sdpMLineIndex = object.sdpMLineIndex
+                o1.sdpMid = object.sdpMid
+                o1.egotype = object.egotype
+                re_command_id = protobuf.SC_NotifyCandidate  # 4013
+                re_body_length = o1.ByteSize()
+                re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+                re_body_data = o1.SerializeToString()
+                re_send_data = re_head_data + re_body_data
+                methods.debug_log(f"{self.connection_id}|SRIConnection409", f"re_command_id: {re_command_id}")
+                methods.debug_log(f"{self.connection_id}|SRIConnection409", f"#candidate.out: {o1.candidate}")
+                item.client.write(re_send_data)
+
+            # --- send 4013 车端到舱端
+            if item.client_info.get('uid') and item.client_info.get('uid') == object.peer:
+                o1 = protobuf.Candidate()
+                o1.index = object.index
+                o1.peer = self.client_info.get('rid')  # 将车端id赋值到指定舱端对象,
+                o1.type = object.type
+                o1.candidate = object.candidate
+                o1.sdpMLineIndex = object.sdpMLineIndex
+                o1.sdpMid = object.sdpMid
+                o1.egotype = object.egotype
+                re_command_id = protobuf.SC_NotifyCandidate  # 4013
+                re_body_length = o1.ByteSize()
+                re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+                re_body_data = o1.SerializeToString()
+                re_send_data = re_head_data + re_body_data
+                methods.debug_log(f"{self.connection_id}|SRIConnection426", f"re_command_id: {re_command_id}")
+                methods.debug_log(f"{self.connection_id}|SRIConnection426", f"#candidate.out: {o1.candidate}")
+                item.client.write(re_send_data)
+
+    def message2007(self, body_data):
+
+        # --- 解析消息体
+        """
+        Leave: 消息体
+        Leave.peer: int32(车端rid)
+        Leave.egotype: int32
+        """
+        o1 = protobuf.Leave()
+        o1.ParseFromString(body_data)
+        methods.debug_log(f"{self.connection_id}|SRIConnection497", f"#peer: {o1.peer}")
+
+        # --- send 4009 指定车端
+        for item in clients.values():
+            if item.client_info.get('rid') and item.client_info.get('rid') == o1.peer:
+                """
+                Leave: 消息体
+                Leave.peer: int32(车端rid)
+                Leave.egotype: int32
+                """
+                o2 = protobuf.Leave()
+                o2.peer = self.client_info.get('uid')
+                o2.egotype = o1.egotype
+                re_command_id = protobuf.SC_NotifyLeave  # 4014
+                re_body_length = o2.ByteSize()
+                re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+                re_body_data = o2.SerializeToString()
+                re_send_data = re_head_data + re_body_data
+                methods.debug_log(f"{self.connection_id}|SRIConnection515", f"re_command_id: {re_command_id}")
+                item.client.write(re_send_data)
+
+    def message2014(self, body_data):
+
+        # --- 解析消息体
+        """
+        message CSState
+        {
+            UserState state=1;
+            int32 uid=2;
+        };
+        """
+        o1 = protobuf.CSState()
+        o1.ParseFromString(body_data)
+        methods.debug_log(f"{self.connection_id}|SRIConnection530", f"#state: {o1.state}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection530", f"#uid: {o1.uid}")
+
+        # --- send 4016 发送全部舱端
+        for item in clients.values():
+            if item.client_type == 'cockpit':
+                """
+                message SCState
+                {
+                    UserState state=1;
+                    int32 uid=2;
+                };
+                """
+                o2 = protobuf.SCState()
+                o2.state = o1.state
+                o2.uid = self.client_info.get('rid')
+                re_command_id = protobuf.SC_State  # 4022
+                re_body_length = o2.ByteSize()
+                re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+                re_body_data = o2.SerializeToString()
+                re_send_data = re_head_data + re_body_data
+                methods.debug_log(f"{self.connection_id}|SRIConnection551", f"re_command_id: {re_command_id}")
+                item.client.write(re_send_data)
+
+    @staticmethod
+    async def check_clients():
+        """
+        剔除掉线连接
+        """
+        count = 0
+        while True:
+            count += 1
+            print(f"#count: {count}", flush=True)
+
+            now_at = methods.now_ts()
+
+            for connection_id in list(clients.keys()):
+                object = clients.get(connection_id)
+                print(f"#client: {object.client}, #update_at: {object.update_at}, #client_type: {object.client_type}",
+                      flush=True)
+
+            await asyncio.sleep(3)  # 发送消息的间隔时间
+
+    @staticmethod
+    async def run():
+        """
+        """
+        # --- define ---
+        loop = asyncio.get_running_loop()
+        server = await loop.create_server(
+            lambda: SRIConnection(),
+            '0.0.0.0', 20917
+        )
+
+        # --- start ---
+        async with server:
+            print("Server listening on 0.0.0.0:20917", flush=True)
+            # await loop.create_task(SRIConnection.check_clients())
+            await server.serve_forever()
+
+
+if __name__ == '__main__':
+    asyncio.run(SRIConnection.run())

+ 628 - 0
sri-server-bg03/lib/Connection_e1.py

@@ -0,0 +1,628 @@
+"""
+"""
+# from hub import methods, Global
+
+import struct
+import asyncio
+import time
+import socket
+
+import sys
+import importlib
+
+# --- for linux
+sys.path.append('/home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01')
+sys.path.append('/home/sri/repositories/repositories/sri-project.demo-py/sri-pysdk')
+
+protobuf = importlib.import_module(f"xprotobuf.protocol_pb2")
+methods = importlib.import_module(f"xlib")
+clients = {}  # {<ipv4>: (socket, update_at, type)} | {<连接id>: (socket对象, 最后一次请求时间, 客户端类型)}
+serial_rid_dict = {
+    '65F7171A-5585-46C7-A9D6-967ABA9EB223': 1000000,
+    '7AF3F619-5067-4EE0-A710-89A6CB097EFE': 1000001,
+    'ECB93A87-560B-4022-8C5F-CBF9FE1E596A': 1000002,
+    'C0D14B6F-0FF0-4B68-877D-D2CB886FCD0E': 1000002,
+    'E537DDFB-6E3E-4E1A-AD18-AC21393BE300': 1000004,  # 正在使用
+}
+account_uid_dict = {
+    'ego': 3
+}
+# live_relationship = {}  # {<id-1>id-2>: True}
+
+
+class SRIConnection(asyncio.Protocol):
+    """"""
+
+    head_sequence = '<hh'  # 字节序规则
+    head_size = struct.calcsize(head_sequence)
+    message_data = b''
+
+    def __init__(self):
+        self.lock = asyncio.Lock()  # 初始化锁
+
+    def connection_made(self, client):
+        """
+        建立客户端连接
+        """
+        peername = client.get_extra_info('peername')
+        # self.connection_id = f"{peername[0].replace('.', '')}-{peername[1]}"  # 12700130000 客户端id
+        self.connection_id = int(f"{peername[0].replace('.', '')}")
+        self.client = client
+        # self.data = b''
+        self.client_type = None
+        self.client_info = None
+        self.update_at = methods.now_ts()
+        clients[self.connection_id] = self
+
+        # 获取底层 socket
+        # sock = self.client.get_extra_info('socket')
+
+        # 查看缓冲区大小
+        # recv_buffer_size = sock.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF)
+        # send_buffer_size = sock.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF)
+        # methods.debug_log(f'{self.connection_id}|SRIConnection70', f"Receive buffer size: {recv_buffer_size}")
+        # methods.debug_log(f'{self.connection_id}|SRIConnection70', f"Send buffer size: {send_buffer_size}")
+
+    def connection_lost(self, exc):
+        """
+        关闭连接
+        """
+        methods.debug_log(f"{self.connection_id}|SRIConnection085", f"连接已关闭")
+
+        # --- 处理车端掉线,通知所有舱端
+        if self.client_type == 'vehicle':
+            """
+            SCDelRobot: 消息体
+            SCDelRobot.peer: int32
+            SCDelRobot.egotype: int32
+            """
+            o2 = protobuf.SCDelRobot()
+            o2.peer = self.client_info.get('connection_id')  # 车端id
+            o2.egotype = self.client_info.get('egotype')
+            re_command_id = protobuf.SC_NotifyDel  # 4017
+            re_body_length = o2.ByteSize()
+            re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+            re_body_data = o2.SerializeToString()
+            re_send_data = re_head_data + re_body_data
+            methods.debug_log(f"{self.connection_id}|SRIConnection085", f"re_command_id: {re_command_id}")
+            for item in clients.values():
+                if item.client_type == 'cockpit':
+                    item.client.write(re_send_data)
+
+        # --- 处理舱端掉线,通知所有车端
+        if self.client_type == 'cockpit':
+            """
+            Leave: 消息体
+            Leave.peer: int32(车端rid)
+            Leave.egotype: int32
+            """
+            o2 = protobuf.Leave()
+            o2.peer = self.client_info.get('connection_id')  # 舱端id
+            o2.egotype = 1  # 客户端类型
+            re_command_id = protobuf.SC_NotifyLeave  # 4014
+            re_body_length = o2.ByteSize()
+            re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+            re_body_data = o2.SerializeToString()
+            re_send_data = re_head_data + re_body_data
+            methods.debug_log(f"{self.connection_id}|SRIConnection515", f"re_command_id: {re_command_id}")
+            for item in clients.values():
+                if item.client_type == 'vehicle':
+                    item.client.write(re_send_data)
+
+        # --- clean
+        if self.connection_id in clients:
+            del clients[self.connection_id]
+
+        # --- clean live_relationship
+        # keys = [key for key in live_relationship.keys() if self.connection_id in key]
+        # for key in keys:
+        #     del live_relationship[key]
+
+    def data_received(self, data):
+        """
+        消息处理
+        """
+        asyncio.create_task(self.handle_data(data))
+
+    async def handle_data(self, data):
+        """
+        消息处理
+        """
+        # --- before
+        # loop = asyncio.get_running_loop()
+        # await loop.run_in_executor(None, self.process_data, data)
+
+        # async with self.lock:  # 加入锁,确保只有一个任务在处理数据
+        #     await self.process_data(data)
+
+        async with self.lock:  # 加入锁,确保只有一个任务在处理数据
+            loop = asyncio.get_running_loop()
+            await loop.run_in_executor(None, self.process_data, data)  # 调用非异步函数
+
+    def process_data(self, data):
+        """
+        消息处理
+        """
+        try:
+            # methods.debug_log(f"{self.connection_id}|SRIConnection114", f"receive: {len(data)}, message: {repr(data)}")
+            self.message_data += data  # 执行了这个以后
+
+            # methods.debug_log(f"{self.connection_id}|SRIConnection114", f"--- 1")
+            # methods.debug_log(f"{self.connection_id}|SRIConnection114", f"--- 2")
+            # methods.debug_log(f"{self.connection_id}|SRIConnection114", f"--- 3")
+
+            # count = 0
+            while True:
+
+                # --- print
+                # count += 1
+                # methods.debug_log(f"{self.connection_id}|SRIConnection123",
+                #                   f"---------------------------------- while count: {count}")
+
+                # 确保有足够的字节来处理消息头
+                if len(self.message_data) < self.head_size:
+                    break
+
+                # 获取消息头
+                head_data = self.message_data[:self.head_size]
+                command_id, body_length = struct.unpack(self.head_sequence, head_data)
+                methods.debug_log(f'{self.connection_id}|SRIConnection130',
+                                  f"command_id: {command_id}, body_length: {body_length}")
+
+                # 检查命令ID是否有效
+                if not (2000 <= command_id < 5000):
+                    self.message_data = b''  # 清空无效数据
+                    break
+
+                # 检查完整消息是否接收完毕
+                total_length = self.head_size + body_length
+                if len(self.message_data) < total_length:
+                    break  # 数据不完整,等待更多数据
+
+                # 调用相应处理方法
+                method = getattr(self, f'message{command_id}', None)
+                if method:
+                    method(self.message_data[self.head_size:total_length])  # 处理完整消息
+                else:
+                    methods.debug_log(f"{self.connection_id}|SRIConnectionError",
+                                      f"No handler for command_id: {command_id}")
+
+                # 移除已处理的消息
+                self.message_data = self.message_data[total_length:]
+
+        except Exception as exception:
+            methods.debug_log(f"{self.connection_id}|SRIConnection132", f"#exception: {exception}")
+            methods.debug_log(f"{self.connection_id}|SRIConnection123", f"#traceback: {methods.trace_log()}")
+
+    def message2008(self, body_data):
+        # methods.debug_log(f"{self.connection_id}|SRIConnection80", f"message: 2008")
+        pass
+
+    def message2009(self, body_data):
+
+        # --- 监听 2009
+        """
+        CSAdd: 消息体
+        CSAdd.serial: string
+        CSAdd.type: int32 EgoType::Car | EgoType::None EgoType::User EgoType::Car
+        CSAdd.name: string
+        """
+        object0 = protobuf.CSAdd()
+        object0.ParseFromString(body_data)
+        methods.debug_log(f"{self.connection_id}|SRIConnection90", f"#serial: {object0.serial}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection90", f"#name: {object0.name}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection90", f"#type: {object0.type}")
+
+        # --- update ---
+        self.client_type = 'vehicle'
+        self.client_info = {
+            'connection_id': self.connection_id,
+            'rid': serial_rid_dict.get(object0.serial),
+            'name': object0.name,
+            'serial': object0.serial,
+            'egotype': 2,  # 客户端类型
+        }
+
+        """
+        SCAddRobot: 消息体
+        SCAddRobot.robot: Robot
+        Robot: 消息体
+        Robot.rid: int32
+        Robot.name: string
+        Robot.type: int32
+        Robot.state: RobotState Offline Online Busy
+        """
+        o1 = protobuf.Robot()
+        # o1.rid = self.client_info.get('rid')
+        o1.rid = self.client_info.get('connection_id')
+        o1.name = object0.name
+        o1.type = 2  # 0 EgoType::None 1 EgoType::User 2 EgoType::Car
+        o1.state = protobuf.Robot.Online
+        o2 = protobuf.SCAddRobot()
+        o2.robot.CopyFrom(o1)
+        re_command_id = protobuf.SC_NotifyAdd  # 4016
+        re_body_length = o2.ByteSize()
+        re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+        re_body_data = o2.SerializeToString()
+        re_send_data = re_head_data + re_body_data
+
+        # --- send 4016 发送全部舱端
+        for item in clients.values():
+            if item.client_type == 'cockpit':
+                methods.debug_log(f"{self.connection_id}|SRIConnection136", f"re_command_id: {re_command_id}")
+                item.client.write(re_send_data)
+
+        # --- send 4007  todo 凯强说并未用到
+        # o1 = protobuf.SCAdd()
+        # o1.ret = True
+        # o1.uid = 112233  # todo 这个uid,应该是哪个舱端永辉在操作这个车 | 但是现在还没有人操控车
+        # o1.name = object0.name
+        # re_command_id = protobuf.SC_Add  # 4007
+        # re_body_length = o1.ByteSize()
+        # re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+        # re_body_data = o1.SerializeToString()
+        # re_send_data = re_head_data + re_body_data
+        # methods.debug_log(f"{self.connection_id} | SRIConnection150", f"re_command_id: {re_command_id}")
+        # self.client.write(re_send_data)
+
+    def message2000(self, body_data):
+
+        # --- 解析消息体
+        object = protobuf.CSSign()
+        object.ParseFromString(body_data)
+        methods.debug_log(f"{self.connection_id}|SRIConnection162", f"#account: {object.account}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection162", f"#password: {object.password}")
+
+        # --- update ---
+        self.client_type = 'cockpit'
+        self.client_info = {
+            'connection_id': self.connection_id,
+            'uid': 3,  # 对应数据库里的ego的id
+            'name': 'ego',  # 对应数据库里
+            'egotype': 1,  # 舱端类型
+        }
+
+        # --- send 4000
+        object = protobuf.SCSign()
+        object.ret = True
+        # object.uid = self.client_info.get('uid')
+        object.uid = self.client_info.get('connection_id')
+        object.name = self.client_info.get('name')
+        re_command_id = protobuf.SC_Sign  # 4000
+        re_body_length = object.ByteSize()
+        re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+        re_body_data = object.SerializeToString()
+        re_send_data = re_head_data + re_body_data
+        methods.debug_log(f"{self.connection_id}|SRIConnection175", f"re_command_id: {re_command_id}")
+        self.client.write(re_send_data)
+
+    def message2010(self, body_data):
+
+        # --- send 4008 发送全部车端信息列表
+        """
+        Robot: 消息体
+        Robot.rid: string
+        Robot.name: string
+        Robot.type: int32 EgoType::Car | EgoType::None EgoType::User EgoType::Car
+        Robot.state: enum Offline Online Busy
+        """
+        # --- 获取全部在线车辆列表
+        o2 = protobuf.SCRobot()
+        for item in clients.values():
+            if item.client_type and item.client_type == 'vehicle':
+                o1 = protobuf.Robot()
+                # o1.rid = item.client_info.get('rid')
+                o1.rid = item.client_info.get('connection_id')
+                o1.name = item.client_info.get('name')
+                o1.type = 2  # EgoType::Car
+                o1.state = protobuf.Robot.RobotState.Value('Online')
+                o2.robot.add().CopyFrom(o1)
+
+        re_command_id = protobuf.SC_Robot  # 4008
+        re_body_length = o2.ByteSize()
+        re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+        re_body_data = o2.SerializeToString()
+        re_send_data = re_head_data + re_body_data
+        methods.debug_log(f"{self.connection_id}|SRIConnection306", f"re_command_id: {re_command_id}")
+        self.client.write(re_send_data)
+
+    def message2001(self, body_data):
+
+        # --- 解析消息体
+        """
+        CSReq: 消息体
+        CSReq.peer: int32(rid,车端唯一标识)
+        CSReq.index: int32(相机位置,RenderPosition)
+        CSReq.egotype: int32(终端类型,舱端/车端)
+        """
+        o1 = protobuf.CSReq()
+        o1.ParseFromString(body_data)
+        methods.debug_log(f"{self.connection_id}|SRIConnection299.message2001", f"#peer: {o1.peer}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection299.message2001", f"#index: {o1.index}")
+        # methods.debug_log(f"{self.connection_id}|SRIConnection299.message2001", f"#uid: {self.client_info.get('uid')}")
+        # methods.debug_log(f"{self.connection_id}|SRIConnection299.message2001", f"#rid: {self.client_info.get('rid')}")
+
+        # --- send 4009 指定车端
+        for item in clients.values():
+            if item.client_info.get('connection_id') == o1.peer:
+                """
+                CSReq: 消息体
+                CSReq.peer: int32(rid,车端唯一标识)
+                CSReq.index: int32(相机位置,RenderPosition)
+                CSReq.egotype: int32(终端类型,舱端/车端)
+                """
+                o2 = protobuf.CSReq()
+                o2.peer = self.client_info.get('connection_id')  # 舱端id
+                o2.index = o1.index
+                o2.egotype = o1.egotype
+                re_command_id = protobuf.SC_NotifyReq  # 4009
+                re_body_length = o2.ByteSize()
+                re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+                re_body_data = o2.SerializeToString()
+                re_send_data = re_head_data + re_body_data
+                methods.debug_log(f"{self.connection_id}|SRIConnection217", f"re_command_id: {re_command_id}")
+                item.client.write(re_send_data)
+
+    def message2002(self, body_data):
+
+        # --- 解析消息体
+        """
+        CSRep: 消息体
+        CSRep.desc: VideoDesc
+        CSRep.peer: int32
+        CSRep.index: int32
+        CSRep.egotype: int32
+        """
+        o1 = protobuf.CSRep()
+        o1.ParseFromString(body_data)
+        methods.debug_log(f"{self.connection_id}|SRIConnection319", f"#peer: {o1.peer}")
+        # methods.debug_log(f"{self.connection_id}|SRIConnection235", f"#uid: {self.client_info.get('uid')}")
+        # methods.debug_log(f"{self.connection_id}|SRIConnection235", f"#rid: {self.client_info.get('rid')}")
+
+        # --- send 4010 指定舱端
+        for item in clients.values():
+            if item.client_info.get('connection_id') == o1.peer:
+                o2 = protobuf.CSRep()
+                o2.desc = o1.desc
+                o2.peer = self.client_info.get('connection_id')  # 车端id
+                o2.index = o1.index
+                o2.egotype = o1.egotype
+                re_command_id = protobuf.SC_NotifyRep  # 4010
+                re_body_length = o2.ByteSize()
+                re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+                re_body_data = o2.SerializeToString()
+                re_send_data = re_head_data + re_body_data
+                methods.debug_log(f"{self.connection_id}|SRIConnection217", f"re_command_id: {re_command_id}")
+                item.client.write(re_send_data)
+
+    def message2004(self, body_data):
+
+        # --- 解析消息体
+        """
+        Offer: 消息体
+        Offer.index: int32
+        Offer.peer: int32(车端rid)
+        Offer.type: string
+        Offer.sdp: string
+        """
+        object = protobuf.Offer()
+        object.ParseFromString(body_data)
+        methods.debug_log(f"{self.connection_id}|SRIConnection348", f"#peer: {object.peer}")
+        # methods.debug_log(f"{self.connection_id}|SRIConnection348", f"#uid: {self.client_info.get('uid')}")
+        # methods.debug_log(f"{self.connection_id}|SRIConnection348", f"#rid: {self.client_info.get('rid')}")
+
+        # --- send 4012 指定车端
+        for item in clients.values():
+            if item.client_info.get('connection_id') == object.peer:
+                o1 = protobuf.Offer()
+                o1.index = object.index
+                o1.peer = self.client_info.get('connection_id')  # 舱端id
+                o1.type = object.type
+                o1.sdp = object.sdp
+                re_command_id = protobuf.SC_NotifyOffer  # 4012
+                re_body_length = o1.ByteSize()
+                re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+                re_body_data = o1.SerializeToString()
+                re_send_data = re_head_data + re_body_data
+                methods.debug_log(f"{self.connection_id}|SRIConnection341", f"re_command_id: {re_command_id}")
+                item.client.write(re_send_data)
+
+    def message2005(self, body_data):
+
+        # --- 解析消息体
+        """
+        Answer: 消息体
+        Answer.index: int32
+        Answer.peer: int32(舱端uid)
+        Answer.type: string
+        Answer.sdp: string
+        """
+        object = protobuf.Answer()
+        object.ParseFromString(body_data)
+        methods.debug_log(f"{self.connection_id}|SRIConnection411", f"#peer: {object.peer}")
+        # methods.debug_log(f"{self.connection_id}|SRIConnection411", f"#uid: {self.client_info.get('uid')}")
+        # methods.debug_log(f"{self.connection_id}|SRIConnection411", f"#rid: {self.client_info.get('rid')}")
+
+        # --- send 4011 指定舱端
+        for item in clients.values():
+
+            if item.client_info.get('connection_id') == object.peer:
+                o1 = protobuf.Answer()
+                o1.index = object.index
+                o1.peer = self.client_info.get('connection_id')  # 车端id
+                o1.type = object.type
+                o1.sdp = object.sdp
+                re_command_id = protobuf.SC_NotifyAnswer  # 4011
+                re_body_length = o1.ByteSize()
+                re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+                re_body_data = o1.SerializeToString()
+                re_send_data = re_head_data + re_body_data
+                methods.debug_log(f"{self.connection_id}|SRIConnection428", f"re_command_id: {re_command_id}")
+                methods.debug_log(f"{self.connection_id}|SRIConnection428", f"#index: {o1.index}")
+                item.client.write(re_send_data)
+
+    def message2006(self, body_data):
+
+        # --- 解析消息体
+        """
+        Candidate: 消息体
+        Candidate.index: int32
+        Candidate.peer: int32(车端rid)
+        Candidate.type: string
+        Candidate.candidate: string
+        Candidate.sdpMLineIndex: int32
+        Candidate.sdpMid: string
+        Candidate.egotype: int32
+        """
+        object = protobuf.Candidate()
+        object.ParseFromString(body_data)
+        methods.debug_log(f"{self.connection_id}|SRIConnection413", f"#peer: {object.peer}")
+        # methods.debug_log(f"{self.connection_id}|SRIConnection413", f"#uid: {self.client_info.get('uid')}")
+        # methods.debug_log(f"{self.connection_id}|SRIConnection413", f"#rid: {self.client_info.get('rid')}")
+
+        for item in clients.values():
+
+            # --- send 4013 舱端到车端
+            if item.client_info.get('connection_id') == object.peer:
+                o1 = protobuf.Candidate()
+                o1.index = object.index
+                o1.peer = self.client_info.get('connection_id')  # 舱端id,
+                o1.type = object.type
+                o1.candidate = object.candidate
+                o1.sdpMLineIndex = object.sdpMLineIndex
+                o1.sdpMid = object.sdpMid
+                o1.egotype = object.egotype
+                re_command_id = protobuf.SC_NotifyCandidate  # 4013
+                re_body_length = o1.ByteSize()
+                re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+                re_body_data = o1.SerializeToString()
+                re_send_data = re_head_data + re_body_data
+                methods.debug_log(f"{self.connection_id}|SRIConnection409", f"re_command_id: {re_command_id}")
+                item.client.write(re_send_data)
+
+            # --- send 4013 车端到舱端
+            if item.client_info.get('connection_id') == object.peer:
+                o1 = protobuf.Candidate()
+                o1.index = object.index
+                o1.peer = self.client_info.get('connection_id')  # 车端id,
+                o1.type = object.type
+                o1.candidate = object.candidate
+                o1.sdpMLineIndex = object.sdpMLineIndex
+                o1.sdpMid = object.sdpMid
+                o1.egotype = object.egotype
+                re_command_id = protobuf.SC_NotifyCandidate  # 4013
+                re_body_length = o1.ByteSize()
+                re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+                re_body_data = o1.SerializeToString()
+                re_send_data = re_head_data + re_body_data
+                methods.debug_log(f"{self.connection_id}|SRIConnection426", f"re_command_id: {re_command_id}")
+                # methods.debug_log(f"{self.connection_id}|SRIConnection426", f"#candidate.out: {o1.candidate}")
+                item.client.write(re_send_data)
+
+    def message2007(self, body_data):
+
+        # --- 解析消息体
+        """
+        Leave: 消息体
+        Leave.peer: int32(车端rid)
+        Leave.egotype: int32
+        """
+        o1 = protobuf.Leave()
+        o1.ParseFromString(body_data)
+        methods.debug_log(f"{self.connection_id}|SRIConnection497", f"#peer: {o1.peer}")
+
+        # --- send 4009 指定车端
+        for item in clients.values():
+            if item.client_info.get('connection_id') == o1.peer:
+                """
+                Leave: 消息体
+                Leave.peer: int32(车端rid)
+                Leave.egotype: int32
+                """
+                o2 = protobuf.Leave()
+                o2.peer = self.client_info.get('connection_id')  # 舱端id
+                o2.egotype = o1.egotype
+                re_command_id = protobuf.SC_NotifyLeave  # 4014
+                re_body_length = o2.ByteSize()
+                re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+                re_body_data = o2.SerializeToString()
+                re_send_data = re_head_data + re_body_data
+                methods.debug_log(f"{self.connection_id}|SRIConnection515", f"re_command_id: {re_command_id}")
+                item.client.write(re_send_data)
+
+    def message2014(self, body_data):
+
+        # --- 解析消息体
+        """
+        message CSState
+        {
+            UserState state=1;
+            int32 uid=2;
+        };
+        """
+        o1 = protobuf.CSState()
+        o1.ParseFromString(body_data)
+        methods.debug_log(f"{self.connection_id}|SRIConnection530", f"----------------- #state: {o1.state}")
+        methods.debug_log(f"{self.connection_id}|SRIConnection530", f"#uid: {o1.uid}")
+
+        # --- send 4016 发送全部舱端
+        for item in clients.values():
+            if item.client_type == 'cockpit':
+                """
+                message SCState
+                {
+                    UserState state=1;
+                    int32 uid=2;
+                };
+                """
+                o2 = protobuf.SCState()
+                o2.state = o1.state
+                # o2.uid = self.client_info.get('uid')
+                o2.uid = o1.uid  # todo 文磊这边发送过来的车端id
+                re_command_id = protobuf.SC_State  # 4022
+                re_body_length = o2.ByteSize()
+                re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
+                re_body_data = o2.SerializeToString()
+                re_send_data = re_head_data + re_body_data
+                methods.debug_log(f"{self.connection_id}|SRIConnection551", f"re_command_id: {re_command_id}")
+                item.client.write(re_send_data)
+
+    @staticmethod
+    async def check_clients():
+        """
+        剔除掉线连接
+        """
+        count = 0
+        while True:
+            count += 1
+            print(f"#count: {count}", flush=True)
+
+            now_at = methods.now_ts()
+
+            for connection_id in list(clients.keys()):
+                object = clients.get(connection_id)
+                print(f"#client: {object.client}, #update_at: {object.update_at}, #client_type: {object.client_type}",
+                      flush=True)
+
+            await asyncio.sleep(3)  # 发送消息的间隔时间
+
+    @staticmethod
+    async def run():
+        """
+        """
+        # --- define ---
+        loop = asyncio.get_running_loop()
+        server = await loop.create_server(
+            lambda: SRIConnection(),
+            '0.0.0.0', 20917
+        )
+
+        # --- start ---
+        async with server:
+            print("Server listening on 0.0.0.0:20917", flush=True)
+            # await loop.create_task(SRIConnection.check_clients())
+            await server.serve_forever()
+
+
+if __name__ == '__main__':
+    asyncio.run(SRIConnection.run())

+ 25 - 0
sri-server-bg03/main.py

@@ -0,0 +1,25 @@
+# from app import generate_app
+# app = generate_app()
+
+from lib.Connection_d1 import SRIConnection
+
+import asyncio
+
+
+def main():
+    asyncio.run(SRIConnection.run())
+
+    # 监听mqtt消息服务
+    # from lib.MessageListener import MessageListener
+    # MessageListener.run_background(background_is=False)
+
+    # 给websocket发数据的
+    # from factories.line_manage import LineManage
+    # LineManage.run_background()
+
+    # websocket服务 与 api服务
+    # app.run(address='0.0.0.0', port=5042, debug=True)
+
+
+if __name__ == '__main__':
+    main()

+ 7 - 0
sri-server-bg03/run.sh

@@ -0,0 +1,7 @@
+#!/bin/bash
+
+echo "执行:启动" \
+&& python3 lib/Connection_e1.py
+
+#echo "执行:启动" \
+#&& python3 main.py

+ 89 - 0
sri-server-bg03/test/代码调用流程说明.md

@@ -0,0 +1,89 @@
+## 舱端请求
+
+- qt舱端接收4010(SC_NotifyRep)消息后,创建offer,返回2004(CS_Offer)消息流程
+    - SocketClient::Start 定义了接收4010(SC_NotifyRep)消息时,触发SocketClient::OnNotifyRep
+    - SocketClient::OnNotifyRep 调用了 CEgoClient::OnVideoRep
+    - CEgoClient::OnVideoRep 触发了 CEgoWindow::OnNotifyRep
+    - CEgoWindow::OnNotifyRep 调用了 CPeerConnection::CreateOffer
+    - CPeerConnection::CreateOffer 调用了 mrsPeerConnectionCreateOffer
+    - mrsPeerConnectionCreateOffer 会触发 CPeerConnection::LocalSdpReadytoSendCallback
+    - CPeerConnection::LocalSdpReadytoSendCallback 调用了 CPeerConnection::OnLocalSdpReadytoSend
+    - CPeerConnection::OnLocalSdpReadytoSend 调用了 SocketClient::WriteOffer
+    - SocketClient::WriteOffer 向服务端发送2004(CS_Offer)消息
+
+---
+
+## 服务器端监听
+
+- 服务器端,监听2001(CS_Req),发送4009/4001,给车端
+    - CUserSocket::InitFnDirector 定义了接收2001(CS_Req)消息时,触发 CUserSocket::OnReqVideo
+        - CUserSocket::OnReqVideo 调用了 RemoNet::VideoDesc CUserManager::ConnectPeerVideo
+        - RemoNet::VideoDesc CUserManager::ConnectPeerVideo 调用了 CUserSocket::ReqVideo
+        - CUserSocket::ReqVideo 发送了4009(SC_NotifyReq)消息给车端
+    - CUserSocket::OnReqVideo 发送了4001(SC_Req)消息给车端 (注:4001消息是车端舱端都没有用到的)
+
+- 服务器端,监听2002(CS_Rep)消息,返回4010(SC_NotifyRep)消息流程
+    - SocketClient::InitFnDirector 定义了接收2002(CS_Rep)消息时,触发 CUserSocket::OnRepVideo
+    - CUserSocket::OnRepVideo 调用了 CUserManager::GetInstance().ReplyPeerVideo
+    - CUserManager::ReplyPeerVideo 调用了 CUserSocket::RepVideo
+    - CUserSocket::RepVideo 发送了4010(SC_NotifyRep)消息
+
+- 服务器端,监听舱端2004(CS_Offer)消息,发送4012(SC_NotifyOffer)给车端
+    - CUserSocket::InitFnDirector 定义了接收2004(CS_Offer)消息时,触发 CUserSocket::OnOffer
+    - CUserSocket::OnOffer 会调用 CUserManager::GetInstance().NotifyOffer
+    - CUserManager::GetInstance().NotifyOffer 会调用 CUserSocket::NotifyOffer
+    - CUserSocket::NotifyOffer 发送4012(SC_NotifyOffer)消息,给车端
+
+- 服务器端,监听2005(CS_Answer)消息,发送4011(SC_NotifyAnswer),给舱端
+    - CUserSocket::InitFnDirector 定义了接收2005(CS_Answer)消息时,触发 CUserSocket::OnAnswer
+    - CUserSocket::OnAnswer 调用了 CUserManager::GetInstance().NotifyAnswer
+    - CUserManager::GetInstance().NotifyAnswer 调用了 CUserSocket::NotifyAnswer
+    - CUserSocket::NotifyAnswer 发送4011(SC_NotifyAnswer)消息给舱端
+
+- 服务器端,监听车端2009(CS_Add)消息
+    - CUserSocket::InitFnDirector 定义了监听2009(CS_Add)消息,触发 CUserSocket::OnAdd
+    - CUserSocket::OnAdd 发送了4016(SC_NotifyAdd)给全部舱端
+    - CUserSocket::OnAdd 发送了4007(SC_Add)返回给车端执行结果
+
+- 服务器端,监听舱端2000(CS_Sign)消息
+    - CUserSocket::InitFnDirector 定义了监听2000(CS_Sign)消息,触发 CUserSocket::OnSigin
+    - CUserSocket::OnSigin 发送了4000(SC_Sign)返回给舱端执行结果
+
+---
+
+## 车端监听
+
+- 车端监听4012(SC_NotifyOffer)消息,发送2005(CS_Answer)消息流程
+    - SocketClient::Start 中定义了,如果接收到4012消息(SC_NotifyOffer)后,会调用SocketClient::OnNotifyOffer;
+    - SocketClient::OnNotifyOffer 调用了 CMessageQueue::OnVideoOffer
+        - CMessageQueue::OnVideoOffer 调用了 CMessageQueue::InitPeerConnection,建立pc对象
+        - CMessageQueue::OnVideoOffer 调用了 CPeerConnection::SetRemoteDescription
+        - CMessageQueue::OnVideoOffer 调用了 CPeerConnection::CreateAnswer
+            - CPeerConnection::CreateAnswer 会调用 mrsPeerConnectionCreateAnswer
+            - mrsPeerConnectionCreateAnswer 会触发 CPeerConnection::LocalSdpReadytoSendCallback
+            - CPeerConnection::LocalSdpReadytoSendCallback 调用了 CPeerConnection::OnLocalSdpReadytoSend
+            - CPeerConnection::OnLocalSdpReadytoSend 调用了 SocketClient::WriteAnswer
+            - SocketClient::WriteAnswer 向服务端发送了2005(CS_Answer)消息
+
+
+- 车端监听4009(SC_NotifyReq)消息,发送2002消息流程
+    - SocketClient::Start 中定义了,如果接收到4009消息(SC_NotifyReq),会调用SocketClient::OnNotifyReq
+    - SocketClient::OnNotifyReq 调用了 CMessageQueue::OnVideoReq
+    - CMessageQueue::OnVideoReq 触发了 CMessageQueue::OnNotifyReq
+    - CMessageQueue::OnNotifyReq 创建了 CPeerConnection 对象,放置在全局列表中
+    - CMessageQueue::OnNotifyReq 调用了 SocketClient::WriteVideoRep,发送了2002(CS_Rep)消息
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 196 - 0
sri-server-bg03/test/接口参数说明.md

@@ -0,0 +1,196 @@
+## 2008 存活请求
+
+~~~
+# --- test 2008 ---
+服务器地址/端口:58.34.94.178/20917
+# --- 请求 ---
+无
+# --- 返回 ---
+无
+~~~
+
+## 2000 舱端登录认证
+
+~~~
+# --- test 2000 ---
+
+服务器地址/端口:58.34.94.178/20917
+
+# --- 请求 ---
+
+消息头:CS_Sign 2000
+消息体:
+message CSSign
+{
+string account=1;
+string password=2;
+};
+
+# --- 返回 ---
+
+消息头:SC_Sign 4000
+消息体:
+message SCSign
+{
+bool ret=1;
+int32 uid=2;
+int32 cid=3;
+string name=4;
+};
+~~~
+
+## 2009 车端上线
+
+~~~
+
+# --- test 2009 ---
+
+服务器地址/端口:58.34.94.178/20917
+
+# --- 请求 ---
+
+消息头:CS_Add 2009
+消息体:
+message CSAdd
+{
+string serial=1;
+int32 type=2;
+string name=3;
+};
+
+# --- 返回1 ---
+
+消息头:SC_NotifyAdd 4016
+消息体:
+message Robot
+{
+enum RobotState
+{
+Offline=0;
+Online=1;
+Busy=2;
+};
+int32 rid=1;
+string name=2;
+int32 type=3;
+RobotState state=4;
+};
+message SCAddRobot
+{
+Robot robot=1;
+};
+
+# --- 返回2 ---
+
+消息头:SC_Add 4007
+消息体:
+message SCAdd
+{
+bool ret=1;
+int32 uid=2;
+int32 cid=3;
+string name=4;
+};
+~~~
+
+## 2004 发送offer
+
+~~~
+# --- test 2004 ---
+
+服务器地址/端口:58.34.94.178/20917
+
+# --- 请求 ---
+
+消息头:CS_Offer 2004
+消息体:
+message Offer
+{
+int32 index=1;
+int32 peer=2;
+string type=3;
+string sdp=4;
+};
+
+# --- 返回 ---
+
+消息头:SC_NotifyOffer 4012
+消息体:
+message Offer
+{
+int32 index=1;
+int32 peer=2;
+string type=3;
+string sdp=4;
+};
+~~~
+
+## 2005 发送answer
+
+~~~
+# --- test 2005 ---
+
+服务器地址/端口:58.34.94.178/20917
+
+# --- 请求 ---
+
+消息头:CS_Answer 2005
+消息体:
+message Answer
+{
+int32 index=1;
+int32 peer=2;
+string type=3;
+string sdp=4;
+};
+
+# --- 返回 ---
+
+消息头:SC_NotifyAnswer 4011
+消息体:
+message Answer
+{
+int32 index=1;
+int32 peer=2;
+string type=3;
+string sdp=4;
+};
+~~~
+
+## 2006 发送candidate
+
+~~~
+# --- test 2006 ---
+
+服务器地址/端口:58.34.94.178/20917
+
+# --- 请求 ---
+
+消息头:CS_Candidate 2006
+消息体:
+message Candidate
+{
+int32 index=1;
+int32 peer=2;
+string type=3;
+string candidate=4;
+int32 sdpMLineIndex =5;
+string sdpMid =6;
+int32 egotype=7;
+};
+
+# --- 返回 ---
+
+消息头:SC_NotifyCandidate 4013
+消息体:
+message Candidate
+{
+int32 index=1;
+int32 peer=2;
+string type=3;
+string candidate=4;
+int32 sdpMLineIndex =5;
+string sdpMid =6;
+int32 egotype=7;
+};
+~~~

+ 56 - 0
sri-server-bg03/test/接口流程说明.md

@@ -0,0 +1,56 @@
+## 心跳检查流程
+
+| 次序 | 发送端 | 消息体                | 接收端 | 备注     |
+|----|-----|--------------------|-----|--------|
+| 0  | 车端  | 2008(CS_KeepAlive) | 服务端 | 发送存活状态 |
+
+## 车端上线流程
+
+| 次序  | 发送端 | 消息体                | 接收端 | 备注       |
+|-----|-----|--------------------|-----|----------|
+| 1   | 车端  | 2009(CS_Add)       | 服务端 | 车端上线     |
+| 2-1 | 服务端 | 4007(SC_Add)       | 车端  | 返回上线结果   |
+| 2-2 | 服务端 | 4016(SC_NotifyAdd) | 舱端  | 通知舱端车端下线 |
+| 2-2 | 服务端 | 4017               | 舱端  | 通知舱端车端下线 |
+
+## 舱端上线流程
+
+| 次序 | 发送端 | 消息体            | 接收端 | 备注         |
+|----|-----|----------------|-----|------------|
+| 1  | 舱端  | 2000(CS_Sign)  | 服务端 | 舱端登录       |
+| 2  | 服务端 | 4000(SC_Sign)  | 舱端  | 返回登录结果是否成功 |
+| 3  | 舱端  | 2010(CS_Robot) | 服务端 | 请求全部车端信息   |
+| 4  | 服务器 | 4008(SC_Robot) | 舱端  | 返回全部车端信息   |
+
+## 视频通道建立流程
+
+| 次序  | 发送端 | 消息体  | 接收端 | 备注             |
+|-----|-----|------|-----|----------------|
+| 1-1 | 舱端  | 2014 | 服务器 | 状态改变           |
+| 1-2 | 服务器 | 4022 | 舱端  | 通知全部舱端状态改变     |
+| 2-1 | 舱端  | 2001 | 服务端 | 请求视频           |
+| 2-2 | 服务器 | 4009 | 车端  | 转发给车(发送给车用户id) |
+| 2-3 | 车端  | 2002 | 服务器 | 响应视频请求         |
+| 2-4 | 服务器 | 4010 | 舱端  | 转发给舱           |
+| 2-5 | 舱端  | 2004 | 服务器 | 发送offer        |
+| 2-6 | 服务器 | 4012 | 车端  | 转发offer        |
+| 2-7 | 车端  | 2005 | 服务器 | 发送answer       |
+| 2-8 | 服务器 | 4011 | 舱端  | 转发answer       |
+| 3-1 | 舱端  | 2006 | 服务器 | 发送candidate    |
+| 3-2 | 服务器 | 4013 | 车端  | 转发candidate    |
+| 3-3 | 车端  | 2006 | 服务器 | 发送candidate    |
+| 3-4 | 服务器 | 4013 | 舱端  | 转发candidate    |
+
+## 视频通道断开流程
+
+| 次序 | 发送端 | 消息体  | 接收端 | 备注         |
+|----|-----|------|-----|------------|
+| 1  | 舱端  | 2007 | 服务器 | 舱端断开按钮     |
+| 1  | 服务器 | 4014 | 车端  | 通知指定车端     |
+| 1  | 舱端  | 2014 | 服务器 | 状态改变       |
+| 2  | 服务器 | 4022 | 舱端  | 通知全部舱端状态改变 |
+   
+   
+
+   
+   

+ 20 - 0
sri-server-bg03/xprotobuf/README-usage.md

@@ -0,0 +1,20 @@
+## NOTE
+
+#### ubuntu下安装python的protobuf
+
+```
+# 生成工具安装
+apt update && apt install protobuf-compiler -y
+# 版本
+protoc --version
+# 生成
+cd /home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01/xprotobuf
+protoc --python_out=. protocol.proto
+
+# 部署运行
+apt install python3-protobuf
+
+# 其他
+sudo chmod -R 777 /home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01/xprotobuf
+
+```

+ 471 - 0
sri-server-bg03/xprotobuf/mwl0914-protocol.proto

@@ -0,0 +1,471 @@
+syntax="proto3";
+package RemoNet;
+enum CSMessage
+{
+
+  CS_NONE=0;
+  CS_Sign=2000;
+  CS_Req=2001;
+  CS_Rep=2002;
+  CS_CancelReq=2003;
+  CS_Offer=2004;
+  CS_Answer=2005;
+  CS_Candidate=2006;
+  CS_Leave=2007;
+  CS_KeepAlive=2008;
+  CS_Add=2009;
+  CS_Robot=2010;
+  CS_CloseVideo=2011;
+  CS_MoveBegin=2012;
+  CS_MoveEnd=2013;
+  CS_State=2014;
+  CS_SwitchDriver=2015;
+  CS_MoveRet=2016;
+  CS_SyncTime=2017;
+  
+};
+enum SCMessage
+{
+  SC_NONE=0;
+  SC_Sign=4000;
+  SC_Req=4001;
+
+  SC_Rep=4002;
+  SC_Cancel=4003;
+  SC_Offer=4004;
+  SC_Answer=4005;
+  SC_Candidate=4006;
+  SC_Add =4007; 
+  SC_Robot=4008; 
+  SC_NotifyReq=4009;
+  SC_NotifyRep=4010;
+  SC_NotifyAnswer=4011;
+  SC_NotifyOffer=4012;
+  SC_NotifyCandidate=4013;
+  SC_NotifyLeave=4014;
+  SC_NotifyCancel=4015;
+  SC_NotifyAdd=4016;
+  SC_NotifyDel=4017;
+  SC_NotifyCloseVideo=4018;
+  SC_KickOff=4019;
+  SC_MoveBegin=4020;
+  SC_MoveEnd=4021;
+  SC_State=4022;
+  SC_SwitchDriver=4023;
+  SC_MoveRet=4024;
+  SC_NotifyState=4025;
+  SC_SyncTime=4026;
+  
+  
+};
+enum CCMessage
+{
+   CC_None=0;
+   CC_Text=8000;
+   CC_CAN=8001;
+   CC_IMU=8002;
+   CC_ASKDATACHANNEL=8003;
+   CC_Manipulation=8004;
+   CC_Radar=8005;
+   CC_Switch=8006;
+   CC_Ping=8007;
+   CC_SensorStop=8008;
+   CC_StopACK=8009;
+   CC_Lidar=8010;
+   CC_CANMSG=8011;
+   CC_STATE=8012;
+   CC_NDTPOS=8013;
+   
+ 
+    
+};
+enum VideoDesc
+{
+	OK=0;
+	Busy=1;
+	Reject=2;
+	NoFound=3;
+	IsVideoing=4;
+
+};
+message SwitchDriver
+{
+int32 peer=1;
+};
+message NDTPos
+{
+  float x  =1;
+  float y  =2;
+  float z  =3;
+  float rx =4;
+  float ry =5;
+  float rz =6;
+  float rw =7;
+};
+message CSMoveBegin
+{
+int32 peer=1;
+int32 area=2;
+int32 no=3;
+};
+enum MoveDesc
+{
+   Move_OK=0;
+   Move_Encode_Fail=1;
+   Move_Unknow_Faile=2;
+};
+message MoveRet
+{
+   MoveDesc desc=1;
+   int32 peer=2;
+};
+message CSMoveEnd
+{
+   int32 area=1;
+   int32 no=2;
+   int32 uid=3;
+};
+message SCMoveBegin
+{
+   int32 uid=1;
+   int32 area=2;
+   int32 no=3;
+   float x=4;
+   float y=5;
+};
+message SCMoveEnd
+{
+  int32 area=1;
+  int32 no=2;
+  int32 uid=3;
+};
+message CSAdd
+{
+   string serial=1;
+   int32  type=2;
+   string name=3;
+   int32  car=4;
+ 
+};
+message SCAdd
+{
+  bool  ret=1;
+  int32 uid=2;
+  
+  string name=3;
+  int32 car=4;
+};
+message SCKickOff
+{
+};
+enum UserState
+{
+   Offline=0;
+   Idle=1;
+   Remote=2;
+   Automotive=3;
+   AskRemote=4;
+};
+ 
+message CSState
+{
+  UserState state=1;
+  int32 uid=2;
+};
+message SCState
+{
+ UserState state=1;
+ int32 uid=2;
+};
+message Robot
+{
+   int32 rid=1;
+   string name=2;
+   int32  type=3;
+   UserState state=4;
+   int32  carType=5;
+    
+};
+message CSRobot
+{
+};
+message SCRobot
+{
+ repeated Robot robot=1;
+};
+
+message CSSign
+{
+  string account=1;
+  string password=2;
+ 
+  
+};
+message SCSign
+{
+    bool  ret=1;
+    int32 uid=2;
+    string name=3;
+};
+ 
+
+message CSReq
+{
+   int32 peer=1;
+   
+   int32 index=2;
+   int32 egotype=3;
+  
+};
+message SCReq
+{
+    VideoDesc desc=1;
+    int32 peer=2;
+    int32 egotype=3;
+   
+};
+message CSRep
+{
+ 
+   VideoDesc desc=1;
+   int32 peer=2;
+   int32 index=3;
+    int32 egotype=4;
+};
+message SCRep
+{
+  
+   VideoDesc desc=1;
+     int32 index=2;
+	 int32 egotype=3;
+   int32 peer=4;
+   
+};
+
+message Offer
+{
+  int32 index=1;
+  int32 peer=2;
+  string type=3;
+  string sdp=4;
+  
+};
+
+message Answer
+{
+  int32 index=1;
+  int32 peer=2;
+  string type=3;
+  string sdp=4;
+  
+};
+
+message Candidate
+{
+   int32 index=1;
+   int32 peer=2;
+   string type=3;
+   string candidate=4;
+   int32 sdpMLineIndex =5;
+   string sdpMid =6;
+   int32 egotype=7;
+};
+message Leave
+{
+   int32 peer=1;
+   int32 egotype=2;
+};
+ message Close
+{
+int32 peer=1;
+int32 egotype=2;
+int32 index=3;
+};
+ 
+message TestTextReq
+{
+  string text=1;
+};
+message SyncTime
+{
+  	int32 tm_sec =1;   // seconds after the minute - [0, 60] including leap second
+    int32 tm_min =2;   // minutes after the hour - [0, 59]
+    int32 tm_hour =3;  // hours since midnight - [0, 23]
+    int32 tm_mday =4;  // day of the month - [1, 31]
+    int32 tm_mon =5;   // months since January - [0, 11]
+    int32 tm_year =6;  // years since 1900
+	
+	int32 tm_wday =7;  // days since Sunday - [0, 6]
+    int32 tm_yday =8;  // days since January 1 - [0, 365]
+    int32 tm_isdst =9; // daylight savings time flag
+	bool  update_time=10;
+};
+message CCAskDataChannel
+{
+   
+
+};
+
+message IMuMessage
+{
+
+   float rx=1; 
+   float ry=2;
+  // float rz=3;
+};
+
+
+message CCPing
+{
+  int64 tick=1;
+  double temp=2;
+};
+/*
+message radar_info
+{
+ .. int32 index=1;
+  int32 range=2;
+ // int32 azimuth=3;
+ // float verl=4;
+ // int32 count=5;
+ // int32 snr=6;
+}
+*/
+ 
+message radar_node
+{
+    int32 id =1;
+	int32 range=2;
+};
+message CCRadarMessage
+{
+   int32 radar0=1;
+   int32 radar1=2;
+   int32 radar2=3;
+   int32 radar3=4;
+   int32 radar4=5;
+   int32 radar5=6;
+   int32 radar6=7;
+   int32 radar7=8;
+};   
+message CCSensor
+{
+   repeated radar_node node=1;
+   int32 left_encode=2;
+   int32 right_encode=3;
+};
+
+message CCSwitch
+{
+   bool front=1;
+};
+message State
+{
+   /*
+   int32 work_pressure=1;//工作系统压力
+   int32 brake_pressure=2; //制动系统压力
+   
+   int32 gearbox_oil_temp=3;//变速箱油温
+   int32 gearbox_oil_pressure=4; //变速箱油压
+   int32 engine_rpm=5;//发动机转速
+   int32 speed=6;
+  // int32 gear=7;
+   int32 engine_pressure=8;
+   int32 cold_water=9;
+   int32 steer_angle=10;
+   int32 left_lock=11;
+   int32 right_lock=12;
+   */
+
+   ///////////////////////////////////////////////////////状态参数
+   int32 engine_speed = 1;//发动机转速
+   int32 travel_speed = 2;//行驶速度
+   int32 fuel_level = 3;//燃油油位
+   int32 engine_temperature = 4;//发动机水温
+   int32 hydraulic_oil_temperature = 5;//液压油油温
+   int32 main_pump_1_pressure = 6;//主泵1压力
+   int32 main_pump_2_pressure = 7;//主泵2压力
+   int32 hand_gear = 8;//手挡挡位----改为水箱水位
+   int32 actual_gear = 9;//实际挡位----改为发动机机油压力
+   float gripper_height = 10;//抓具高度
+   float amplitude = 11;//幅度
+   int32 boom_angle = 12;//动臂角度
+   int32 stick_angle = 13;//斗杆角度
+   ///////////////////////////////////////////////////////报警信息
+   int32 idle_protection = 14;//怠速保护
+   int32 front_toggle = 15;//前轮对中-----新增的
+   int32 back_toggle = 16;//后轮对中-----新增的
+   bytes error_Buff = 17;//报警信息-----由原来的15改为17
+
+   int32 interlock = 18;//启动联锁
+   int32 safety_switch = 19;//安全开关阀异常
+   int32 arm_lift_pilot = 20;//大臂提升先导比例阀异常
+   int32 arm_lowering_pilot = 21;//大臂下降先导比例阀异常
+   int32 lever_lifting_pilot = 22;//斗杆提升先导比例阀异常
+   int32 rod_lowering_pilot = 23;//斗杆下降先导比例阀异常
+   int32 left_rotary_pilot = 24;//左回转先导比例阀异常
+   int32 right_rotary_pilot = 25;//右回转先导比例阀异常
+   int32 grab_open_pilot = 26;//抓斗开启先导比例阀异常
+   int32 grab_close_pilot = 27;//抓斗闭合先导比例阀异常
+   int32 safety_valves = 28;//安全开关阀
+
+   //增加 0x384
+	int32 function_code =29 ;  //功能码
+	int32 main_add =30;        //主地址
+	int32 sub_add =31;         //次地址
+	int32 paramter=32 ;        //参数值
+
+    //增加0x28b  
+   int32 engine_spn =33;        //发动机实时故障SPN
+   int32 engine_fmi =34;       //发动机实时故障FMI
+   int32 engine_num =35;        //发动机故障次数
+
+   //增加0x28f
+   bytes all_Buff =36;
+   
+};
+message LidarPoint
+{
+ optional double timestamp = 1; 
+ optional uint32 seq = 2;
+ optional string frame_id = 3;
+ optional uint32 height=4;
+ optional uint32 width=5;
+ optional bool is_dense=6;
+ optional bool is_left=7;
+ repeated float data = 8;
+};
+message SensorStop
+{
+};
+message StopAck
+{
+};
+/*
+message CCManipulation
+{
+  bytes sensor=1;
+  bytes  car=2;
+};
+*/
+message can_net_frame
+{
+   sint32 dlc =1;
+   int32 canid =2;
+   bytes data=3;
+};
+message CCCanMsg
+{
+    repeated can_net_frame frams=1;
+};
+ 
+message SCAddRobot
+{
+   Robot robot=1;
+};
+message SCDelRobot
+{
+   int32 peer=1;
+   int32 egotype=2;
+};
+

+ 459 - 0
sri-server-bg03/xprotobuf/mwl0927-protocol.proto

@@ -0,0 +1,459 @@
+syntax="proto3";
+package RemoNet;
+enum CSMessage
+{
+
+  CS_NONE=0;
+  CS_Sign=2000;
+  CS_Req=2001;
+  CS_Rep=2002;
+  CS_CancelReq=2003;
+  CS_Offer=2004;
+  CS_Answer=2005;
+  CS_Candidate=2006;
+  CS_Leave=2007;
+  CS_KeepAlive=2008;
+  CS_Add=2009;
+  CS_Robot=2010;
+  CS_CloseVideo=2011;
+  CS_MoveBegin=2012;
+  CS_MoveEnd=2013;
+  CS_State=2014;
+  CS_SwitchDriver=2015;
+  CS_MoveRet=2016;
+  CS_SyncTime=2017;
+  
+};
+enum SCMessage
+{
+  SC_NONE=0;
+  SC_Sign=4000;
+  SC_Req=4001;
+
+  SC_Rep=4002;
+  SC_Cancel=4003;
+  SC_Offer=4004;
+  SC_Answer=4005;
+  SC_Candidate=4006;
+  SC_Add =4007; 
+  SC_Robot=4008; 
+  SC_NotifyReq=4009;
+  SC_NotifyRep=4010;
+  SC_NotifyAnswer=4011;
+  SC_NotifyOffer=4012;
+  SC_NotifyCandidate=4013;
+  SC_NotifyLeave=4014;
+  SC_NotifyCancel=4015;
+  SC_NotifyAdd=4016;
+  SC_NotifyDel=4017;
+  SC_NotifyCloseVideo=4018;
+  SC_KickOff=4019;
+  SC_MoveBegin=4020;
+  SC_MoveEnd=4021;
+  SC_State=4022;
+  SC_SwitchDriver=4023;
+  SC_MoveRet=4024;
+  SC_NotifyState=4025;
+  SC_SyncTime=4026;
+  
+  
+};
+enum CCMessage
+{
+   CC_None=0;
+   CC_Text=8000;
+   CC_CAN=8001;
+   CC_IMU=8002;
+   CC_ASKDATACHANNEL=8003;
+   CC_Manipulation=8004;
+   CC_Radar=8005;
+   CC_Switch=8006;
+   CC_Ping=8007;
+   CC_SensorStop=8008;
+   CC_StopACK=8009;
+   CC_Lidar=8010;
+   CC_CANMSG=8011;
+   CC_STATE=8012;
+   CC_NDTPOS=8013;
+   
+ 
+    
+};
+enum VideoDesc
+{
+	OK=0;
+	Busy=1;
+	Reject=2;
+	NoFound=3;
+	IsVideoing=4;
+
+};
+message SwitchDriver
+{
+int32 peer=1;
+};
+message NDTPos
+{
+  float x  =1;
+  float y  =2;
+  float z  =3;
+  float rx =4;
+  float ry =5;
+  float rz =6;
+  float rw =7;
+};
+message CSMoveBegin
+{
+int32 peer=1;
+int32 area=2;
+int32 no=3;
+};
+enum MoveDesc
+{
+   Move_OK=0;
+   Move_Encode_Fail=1;
+   Move_Unknow_Faile=2;
+};
+message MoveRet
+{
+   MoveDesc desc=1;
+   int32 peer=2;
+};
+message CSMoveEnd
+{
+   int32 area=1;
+   int32 no=2;
+   int32 uid=3;
+};
+message SCMoveBegin
+{
+   int32 uid=1;
+   int32 area=2;
+   int32 no=3;
+   float x=4;
+   float y=5;
+};
+message SCMoveEnd
+{
+  int32 area=1;
+  int32 no=2;
+  int32 uid=3;
+};
+message CSAdd
+{
+   string serial=1;
+   int32  type=2;
+   string name=3;
+   int32  car=4;
+ 
+};
+message SCAdd
+{
+  bool  ret=1;
+  int32 uid=2;
+  
+  string name=3;
+  int32 car=4;
+};
+message SCKickOff
+{
+};
+enum UserState
+{
+   Offline=0;
+   Idle=1;
+   Remote=2;
+   Automotive=3;
+   AskRemote=4;
+};
+ 
+message CSState
+{
+    UserState state=1;
+    int32 uid=2;
+};
+message SCState
+{
+ UserState state=1;
+ int32 uid=2;
+};
+message Robot
+{
+   int32 rid=1;
+   string name=2;
+   int32  type=3;
+   UserState state=4;
+   int32  carType=5;
+    
+};
+message CSRobot
+{
+};
+message SCRobot
+{
+ repeated Robot robot=1;
+};
+
+message CSSign
+{
+  string account=1;
+  string password=2;
+ 
+  
+};
+message SCSign
+{
+  bool  ret=1;
+  int32 uid=2;
+  
+  string name=3;
+  
+};
+ 
+
+message CSReq
+{
+   int32 peer=1;
+   
+   int32 index=2;
+   int32 egotype=3;
+  
+};
+message SCReq
+{
+    VideoDesc desc=1;
+    int32 peer=2;
+    int32 egotype=3;
+   
+};
+message CSRep
+{
+ 
+   VideoDesc desc=1;
+   int32 peer=2;
+   int32 index=3;
+    int32 egotype=4;
+};
+message SCRep
+{
+  
+   VideoDesc desc=1;
+     int32 index=2;
+	 int32 egotype=3;
+   int32 peer=4;
+   
+};
+
+message Offer
+{
+  int32 index=1;
+  int32 peer=2;
+  string type=3;
+  string sdp=4;
+  
+};
+
+message Answer
+{
+  int32 index=1;
+  int32 peer=2;
+  string type=3;
+  string sdp=4;
+  
+};
+
+message Candidate
+{
+   int32 index=1;
+   int32 peer=2;
+   string type=3;
+   string candidate=4;
+   int32 sdpMLineIndex =5;
+   string sdpMid =6;
+   int32 egotype=7;
+};
+message Leave
+{
+   int32 peer=1;
+   int32 egotype=2;
+};
+ message Close
+{
+int32 peer=1;
+int32 egotype=2;
+int32 index=3;
+};
+ 
+message TestTextReq
+{
+  string text=1;
+};
+message SyncTime
+{
+  	int32 tm_sec =1;   // seconds after the minute - [0, 60] including leap second
+    int32 tm_min =2;   // minutes after the hour - [0, 59]
+    int32 tm_hour =3;  // hours since midnight - [0, 23]
+    int32 tm_mday =4;  // day of the month - [1, 31]
+    int32 tm_mon =5;   // months since January - [0, 11]
+    int32 tm_year =6;  // years since 1900
+	
+	int32 tm_wday =7;  // days since Sunday - [0, 6]
+    int32 tm_yday =8;  // days since January 1 - [0, 365]
+    int32 tm_isdst =9; // daylight savings time flag
+	bool  update_time=10;
+};
+message CCAskDataChannel
+{
+   
+
+};
+
+message IMuMessage
+{
+
+   float rx=1; 
+   float ry=2;
+  // float rz=3;
+};
+
+
+message CCPing
+{
+  int64 tick=1;
+  double temp=2;
+};
+/*
+message radar_info
+{
+ .. int32 index=1;
+  int32 range=2;
+ // int32 azimuth=3;
+ // float verl=4;
+ // int32 count=5;
+ // int32 snr=6;
+}
+*/
+ 
+message radar_node
+{
+    int32 id =1;
+	int32 range=2;
+};
+message CCRadarMessage
+{
+   int32 radar0=1;
+   int32 radar1=2;
+   int32 radar2=3;
+   int32 radar3=4;
+   int32 radar4=5;
+   int32 radar5=6;
+   int32 radar6=7;
+   int32 radar7=8;
+};   
+message CCSensor
+{
+   repeated radar_node node=1;
+   int32 left_encode=2;
+   int32 right_encode=3;
+};
+
+message CCSwitch
+{
+   bool front=1;
+};
+message State
+{
+   /*
+   int32 work_pressure=1;//工作系统压力
+   int32 brake_pressure=2; //制动系统压力
+   
+   int32 gearbox_oil_temp=3;//变速箱油温
+   int32 gearbox_oil_pressure=4; //变速箱油压
+   int32 engine_rpm=5;//发动机转速
+   int32 speed=6;
+  // int32 gear=7;
+   int32 engine_pressure=8;
+   int32 cold_water=9;
+   int32 steer_angle=10;
+   int32 left_lock=11;
+   int32 right_lock=12;
+   */
+
+   ///////////////////////////////////////////////////////状态参数
+   int32 engine_speed = 1;//发动机转速
+   int32 travel_speed = 2;//行驶速度
+   int32 fuel_level = 3;//燃油油位
+   int32 engine_temperature = 4;//发动机水温
+   int32 hydraulic_oil_temperature = 5;//液压油油温
+   int32 main_pump_1_pressure = 6;//主泵1压力
+   int32 main_pump_2_pressure = 7;//主泵2压力
+   int32 hand_gear = 8;//手挡挡位----改为水箱水位
+   int32 actual_gear = 9;//实际挡位----改为发动机机油压力
+   float gripper_height = 10;//抓具高度
+   float amplitude = 11;//幅度
+   int32 boom_angle = 12;//动臂角度
+   int32 stick_angle = 13;//斗杆角度
+   ///////////////////////////////////////////////////////报警信息
+   int32 idle_protection = 14;//怠速保护
+   int32 front_toggle = 15;//前轮对中-----新增的
+   int32 back_toggle = 16;//后轮对中-----新增的
+   bytes error_Buff = 17;//报警信息-----由原来的15改为17
+
+   int32 interlock = 18;//启动联锁
+   int32 safety_switch = 19;//安全开关阀异常
+   int32 arm_lift_pilot = 20;//大臂提升先导比例阀异常
+   int32 arm_lowering_pilot = 21;//大臂下降先导比例阀异常
+   int32 lever_lifting_pilot = 22;//斗杆提升先导比例阀异常
+   int32 rod_lowering_pilot = 23;//斗杆下降先导比例阀异常
+   int32 left_rotary_pilot = 24;//左回转先导比例阀异常
+   int32 right_rotary_pilot = 25;//右回转先导比例阀异常
+   int32 grab_open_pilot = 26;//抓斗开启先导比例阀异常
+   int32 grab_close_pilot = 27;//抓斗闭合先导比例阀异常
+   int32 safety_valves = 28;//安全开关阀
+   
+};
+message LidarPoint
+{
+ optional double timestamp = 1; 
+ optional uint32 seq = 2;
+ optional string frame_id = 3;
+ optional uint32 height=4;
+ optional uint32 width=5;
+ optional bool is_dense=6;
+ optional bool is_left=7;
+ repeated float data = 8;
+};
+message SensorStop
+{
+};
+message StopAck
+{
+};
+/*
+message CCManipulation
+{
+  bytes sensor=1;
+  bytes  car=2;
+};
+*/
+message can_net_frame
+{
+   sint32 dlc =1;
+   int32 canid =2;
+   bytes data=3;
+};
+message CCCanMsg
+{
+    repeated can_net_frame frams=1;
+};
+ 
+message SCAddRobot
+{
+   Robot robot=1;
+};
+message SCDelRobot
+{
+   int32 peer=1;
+   int32 egotype=2;
+};
+

+ 441 - 0
sri-server-bg03/xprotobuf/protocol.proto

@@ -0,0 +1,441 @@
+syntax="proto3";
+package RemoNet;
+enum CSMessage
+{
+  CS_NONE=0;
+  CS_Sign=2000;
+  CS_Req=2001;
+  CS_Rep=2002;
+  CS_CancelReq=2003;
+  CS_Offer=2004;
+  CS_Answer=2005;
+  CS_Candidate=2006;
+  CS_Leave=2007;
+  CS_KeepAlive=2008;
+  CS_Add=2009;
+  CS_Robot=2010;
+  CS_CloseVideo=2011;
+  CS_State=2014;
+};
+enum SCMessage
+{
+  SC_NONE=0;
+  SC_Sign=4000;
+  SC_Req=4001;
+
+  SC_Rep=4002;
+  SC_Cancel=4003;
+  SC_Offer=4004;
+  SC_Answer=4005;
+  SC_Candidate=4006;
+  SC_Add=4007;
+  SC_Robot=4008; 
+  SC_NotifyReq=4009;
+  SC_NotifyRep=4010;
+  SC_NotifyAnswer=4011;
+  SC_NotifyOffer=4012;
+  SC_NotifyCandidate=4013;
+  SC_NotifyLeave=4014;
+  SC_NotifyCancel=4015;
+  SC_NotifyAdd=4016;
+  SC_NotifyDel=4017;
+  SC_NotifyCloseVideo=4018;
+  SC_KickOff=4019;
+  SC_State=4022;
+  
+};
+enum CCMessage
+{
+   CC_None=0;
+   CC_Text=8000;
+   CC_CAN=8001;
+   CC_IMU=8002;
+   CC_ASKDATACHANNEL=8003;
+   CC_Manipulation=8004;
+   CC_Radar=8005;
+   CC_Switch=8006;
+   CC_Ping=8007;
+   CC_SensorStop=8008;
+   CC_StopACK=8009;
+   CC_LIDARDATA=8010;
+   CC_CANMSG=8011;
+   CC_STATE=8012;
+   CC_RobotAnalog=8017;
+   CC_BootReq=8013;
+   CC_StartupReq=8014;
+   CC_BootRep=8015;
+   CC_StartupRep=8016;
+ //  CC_FrontLight=8017;
+ //  CC_Wiper=8018;
+ //  CC_BackLight=8019;
+};
+enum VideoDesc
+{
+	OK=0;
+	Busy=1;
+	Reject=2;
+	NoFound=3;
+	IsVideoing=4;
+
+};
+message CSAdd
+{
+    string serial=1;
+    int32  type=2;
+    string name=3;
+};
+message SCAdd
+{
+    bool  ret=1;
+    int32 uid=2;
+    int32 cid=3;
+    string name=4;
+};
+message SCKickOff
+{
+};
+message Robot
+{
+    enum RobotState
+    {
+        Offline=0;
+        Online=1;
+        Busy=2;
+    };
+    int32 rid=1;
+    string name=2;
+    int32  type=3;
+    RobotState state=4;
+};
+message CSRobot
+{
+};
+message SCRobot
+{
+ repeated Robot robot=1;
+};
+
+message CSSign
+{
+    string account=1;
+    string password=2;
+};
+
+message SCSign
+{
+    bool  ret=1;
+    int32 uid=2;
+    string name=3;
+};
+
+message CSReq
+{
+   int32 peer=1;
+   int32 index=2;
+   int32 egotype=3;
+};
+message SCReq
+{
+    VideoDesc desc=1;
+    int32 peer=2;
+    int32 egotype=3;
+   
+};
+message CSRep
+{
+ 
+   VideoDesc desc=1;
+   int32 peer=2;
+   int32 index=3;
+    int32 egotype=4;
+};
+message SCRep
+{
+  
+   VideoDesc desc=1;
+     int32 index=2;
+	 int32 egotype=3;
+   int32 peer=4;
+   
+};
+
+message Offer
+{
+    int32 index=1;
+    int32 peer=2;
+    string type=3;
+    string sdp=4;
+};
+
+message Answer
+{
+    int32 index=1;
+    int32 peer=2;
+    string type=3;
+    string sdp=4;
+};
+
+message Candidate
+{
+    int32 index=1;
+    int32 peer=2;
+    string type=3;
+    string candidate=4;
+    int32 sdpMLineIndex =5;
+    string sdpMid =6;
+    int32 egotype=7;
+};
+message Leave
+{
+   int32 peer=1;
+   int32 egotype=2;
+};
+ message Close
+{
+int32 peer=1;
+int32 egotype=2;
+int32 index=3;
+};
+ 
+message TestTextReq
+{
+  string text=1;
+};
+message CanMessage
+{
+   
+   int32 head=1;
+   int32 canid=2;
+   bytes data=3;
+};
+message CCCanMesage
+{
+   bool islidar=1;
+   repeated CanMessage message=2;
+};
+message Wiper
+{
+  bool ret=1;
+};
+message FrontLight
+{
+  bool ret=1;
+};
+message BackLight
+{
+  bool ret=1;
+};
+message CCAskDataChannel
+{
+};
+message IMuMessage
+{
+
+   float rx=1; 
+   float ry=2;
+  // float rz=3;
+};
+message CCPing
+{
+  int64 tick=1;
+};
+message CCRadarMessage
+{
+   int32 radar0=1;
+   int32 radar1=2;
+   int32 radar2=3;
+   int32 radar3=4;
+   int32 radar4=5;
+   int32 radar5=6;
+   int32 radar6=7;
+   int32 radar7=8;
+};
+enum Gears
+{
+   Null=0; //todo 关键字占用,None改为Null
+   N=1;
+   D=2;
+   R=3;
+};
+//挂挡
+enum Gears_D
+{
+   None_d=0;
+   D_1=1;
+   D_2=2;
+   D_3=3;
+   D_4=4;
+};
+//左右转向灯
+enum DirectionLight
+{
+  RightLight=0;
+  LeftLight=1;
+  OffLight=2;
+};
+message CCRobotAnalog
+{
+  int32  steer=1;
+  int32  arm=2;  //举升臂
+  int32  bucket=3; //翻斗
+  int32  throttle=4; //油门
+  int32  brake=5;  //刹车
+ // bool   bootstrap=6; //钥匙一档上电
+ // bool   startup=7;   //钥匙二档启动
+  bool   emergency=8; //急停
+  bool   resume=9;// 急停反转
+  Gears  gears=10;
+  bool   frontlight=11;
+  bool   backlight=12;
+  bool   wipe=13;
+  DirectionLight directionlight=14;//左右转向灯
+  bool   buzzer=15;//车鸣笛
+  Gears_D gears_d=16;//挂挡
+};
+message CCBootStrapReq
+{
+
+}
+message CCBooStrapRep
+{
+    bool ret=1;
+}
+message CCStartupReq
+{
+    
+}
+message CCStartupRep
+{
+   bool ret=1;
+}
+message CCSwitch
+{
+   bool front=1;
+};
+//todo 不支持optional
+//message LidarPoint
+//{
+// optional double timestamp = 1;
+// optional uint32 seq = 2;
+// optional string frame_id = 3;
+// optional uint32 height=4;
+// optional uint32 width=5;
+// optional bool is_dense=6;
+// optional bool is_left=7;
+// repeated float data = 8;
+//};
+message SensorStop
+{
+};
+message StopAck
+{
+};
+message CCManipulation
+{
+  bytes sensor=1;
+  bytes  car=2;
+};
+message SCAddRobot
+{
+   Robot robot=1;
+};
+message SCDelRobot
+{
+   int32 peer=1;
+   int32 egotype=2;
+};
+
+message State
+{
+   
+   /*
+   int32 work_pressure=1;//工作系统压力
+   int32 brake_pressure=2; //制动系统压力
+   int32 gearbox_oil_temp=3;//变速箱油温
+   int32 gearbox_oil_pressure=4; //变速箱油压
+   int32 engine_rpm=5;//发动机转速
+   int32 speed=6;
+   int32 engine_pressure=8;
+   int32 cold_water=9;
+   int32 steer_angle=10;
+   int32 left_lock=11;
+   int32 right_lock=12;
+   */
+   ///////////////////////////////////////////////////////状态参数
+   int32 engine_speed = 1;//发动机转速
+   int32 travel_speed = 2;//行驶速度
+   int32 fuel_level = 3;//燃油油位
+   int32 engine_temperature = 4;//发动机水温
+   int32 hydraulic_oil_temperature = 5;//液压油油温
+   int32 main_pump_1_pressure = 6;//主泵1压力
+   int32 main_pump_2_pressure = 7;//主泵2压力
+   int32 hand_gear = 8;//水箱水位
+   int32 actual_gear = 9;//发动机机油压力
+   float gripper_height = 10;//抓具高度
+   float amplitude = 11;//幅度
+   int32 boom_angle = 12;//动臂角度
+   int32 stick_angle = 13;//斗杆角度
+   ///////////////////////////////////////////////////////报警信息
+   int32 idle_protection = 14;//怠速保护
+   int32 front_toggle = 15;//前轮对中
+   int32 back_toggle = 16;//后轮对中
+   bytes error_Buff = 17;//报警信息
+   int32 interlock = 18;//启动联锁
+   int32 safety_switch = 19;//安全开关阀异常
+   int32 arm_lift_pilot = 20;//大臂提升先导比例阀异常
+   int32 arm_lowering_pilot = 21;//大臂下降先导比例阀异常
+   int32 lever_lifting_pilot = 22;//斗杆提升先导比例阀异常
+   int32 rod_lowering_pilot = 23;//斗杆下降先导比例阀异常
+   int32 left_rotary_pilot = 24;//左回转先导比例阀异常
+   int32 right_rotary_pilot = 25;//右回转先导比例阀异常
+   int32 grab_open_pilot = 26;//抓斗开启先导比例阀异常
+   int32 grab_close_pilot = 27;//抓斗闭合先导比例阀异常
+   int32 safety_valves = 28;//安全开关阀
+
+    //增加 0x384
+	int32 function_code =29 ;  //功能码
+	int32 main_add =30;        //主地址
+	int32 sub_add =31;         //次地址
+	int32 paramter=32 ;        //参数值
+
+   //增加0x28b  
+   int32 engine_spn =33;        //发动机实时故障SPN
+   int32 engine_fmi =34;       //发动机实时故障FMI
+   int32 engine_num =35;        //发动机故障次数
+
+   //增加0x28f
+   bytes all_Buff = 36;    //0x28f 信息  
+};
+
+message can_net_frame
+{
+   sint32 dlc =1;
+   int32 canid =2;
+   bytes data=3;
+};
+
+message CCCanMsg
+{
+    repeated can_net_frame frams=1;
+};
+
+enum UserState
+{
+   Offline=0;
+   Idle=1;
+   Remote=2;
+   Automotive=3;
+   AskRemote=4;
+};
+
+message SCState
+{
+    UserState state=1;
+    int32 uid=2;
+};
+
+message CSState
+{
+    UserState state=1;
+    int32 uid=2;
+};

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 22 - 0
sri-server-bg03/xprotobuf/protocol_pb2.py


Vissa filer visades inte eftersom för många filer har ändrats