Browse Source

解决多舱空闲舱退出,导致正在连接的车端收到退出消息的问题

Casper 2 weeks ago
parent
commit
c7c9d62259
1 changed files with 146 additions and 118 deletions
  1. 146 118
      sri-server-bg03/lib/Connection_e1.py

+ 146 - 118
sri-server-bg03/lib/Connection_e1.py

@@ -27,7 +27,7 @@ account_uid_dict = {
 class SRIConnection(asyncio.Protocol):
     """"""
 
-    head_sequence = '<hh'  # 字节序规则
+    head_sequence = '<hh'  # <: 小端字节序 h: 短整型/short/2字节
     head_size = struct.calcsize(head_sequence)
     message_data = b''
 
@@ -44,8 +44,12 @@ class SRIConnection(asyncio.Protocol):
         self.connection_id = int(f"{peername[0].replace('.', '')}")  # 客户端id(局域网情况)
         self.client = client
         # self.data = b''
-        self.client_type = None
+        self.client_type = ''  # 连接类型 vehicle 车端 cockpit 舱端
         self.client_info = None
+        self.client_info = {
+            'local_connection_id': 0,  # 本端id
+            'remote_connection_id': 0,  # 对端id
+        }  # 连接信息
         self.update_at = methods.now_ts()
         clients[self.connection_id] = self
 
@@ -55,7 +59,7 @@ class SRIConnection(asyncio.Protocol):
         data = item.get('args', {})
 
         # --- set VehicleStatus ---
-        data[str(self.connection_id)] = 2
+        data[str(self.connection_id)] = 2  # 车辆状态 1 离线 2 在线空闲 3 现场驾驶中 4 远程驾驶中
         update_dict = {'args': data}
         Global.mdb.update_one('GlobalVariable', unique_dict, update_dict)
 
@@ -65,15 +69,15 @@ class SRIConnection(asyncio.Protocol):
         # 查看缓冲区大小
         # 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}")
+        # methods.debug_log(f'{self.connection_id}|Connection_e1:70', f"Receive buffer size: {recv_buffer_size}")
+        # methods.debug_log(f'{self.connection_id}|Connection_e1:70', f"Send buffer size: {send_buffer_size}")
 
     def connection_lost(self, exc):
         """
         关闭连接
         """
-        methods.debug_log(f"{self.connection_id}|SRIConnection|65", f"连接已关闭")
-        methods.debug_log(f"{self.connection_id}|SRIConnection|65", f"clients: len{clients}")
+        methods.debug_log(f"{self.connection_id}|Connection_e1:65", f"连接已关闭")
+        methods.debug_log(f"{self.connection_id}|Connection_e1:65", f"clients: len{clients.keys()}")
 
         # --- get VehicleStatus ---
         unique_dict = {'name': 'VehicleStatus'}
@@ -81,7 +85,7 @@ class SRIConnection(asyncio.Protocol):
         data = item.get('args', {})
 
         # --- set VehicleStatus ---
-        data[str(self.connection_id)] = 1
+        data[str(self.connection_id)] = 1  # 车辆状态 1 离线 2 在线空闲 3 现场驾驶中 4 远程驾驶中
         update_dict = {'args': data}
         Global.mdb.update_one('GlobalVariable', unique_dict, update_dict)
 
@@ -93,19 +97,19 @@ class SRIConnection(asyncio.Protocol):
             SCDelRobot.egotype: int32
             """
             o2 = protobuf.SCDelRobot()
-            o2.peer = self.client_info.get('connection_id')  # 车端id
+            o2.peer = self.client_info.get('local_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}|SRIConnection102", f"re_command_id: {re_command_id}")
+            methods.debug_log(f"{self.connection_id}|Connection_e1:102", 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: 消息体
@@ -113,17 +117,24 @@ class SRIConnection(asyncio.Protocol):
             Leave.egotype: int32
             """
             o2 = protobuf.Leave()
-            o2.peer = self.client_info.get('connection_id')  # 舱端id
+            o2.peer = self.client_info.get('local_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}")
+            methods.debug_log(f"{self.connection_id}|Connection_e1:515", f"re_command_id: {re_command_id}")  # 4014
+
+            # --- 筛选指定车端
             for item in clients.values():
-                if item.client_type == 'vehicle':
-                    item.client.write(re_send_data)
+                if item.client_type != 'vehicle':
+                    continue
+                # 判断当前id是否是需要被断开的id
+                if self.client_info.get('local_connection_id') != item.client_info.get('remote_connection_id'):
+                    continue
+                # 发送断开信号给车端
+                item.client.write(re_send_data)
 
         # --- clean
         if self.connection_id in clients:
@@ -160,19 +171,19 @@ class SRIConnection(asyncio.Protocol):
         消息处理
         """
         try:
-            # methods.debug_log(f"{self.connection_id}|SRIConnection114", f"receive: {len(data)}, message: {repr(data)}")
+            # methods.debug_log(f"{self.connection_id}|Connection_e1:114", 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")
+            # methods.debug_log(f"{self.connection_id}|Connection_e1:114", f"--- 1")
+            # methods.debug_log(f"{self.connection_id}|Connection_e1:114", f"--- 2")
+            # methods.debug_log(f"{self.connection_id}|Connection_e1:114", f"--- 3")
 
             # count = 0
             while True:
 
                 # --- print
                 # count += 1
-                # methods.debug_log(f"{self.connection_id}|SRIConnection123",
+                # methods.debug_log(f"{self.connection_id}|Connection_e1:123",
                 #                   f"---------------------------------- while count: {count}")
 
                 # 确保有足够的字节来处理消息头
@@ -183,10 +194,10 @@ class SRIConnection(asyncio.Protocol):
                 head_data = self.message_data[:self.head_size]
                 command_id, body_length = struct.unpack(self.head_sequence, head_data)
                 if command_id not in [2008]:
-                    methods.debug_log(f'{self.connection_id}|SRIConnection.166',
+                    methods.debug_log(f'{self.connection_id}|Connection_e1:166',
                                       f"command_id: {command_id}, body_length: {body_length}")
                 # else:
-                #     methods.debug_log(f'{self.connection_id}|SRIConnection.169',
+                #     methods.debug_log(f'{self.connection_id}|Connection_e1:.169',
                 #                       f"command_id: {command_id}, body_length: {body_length}")
 
                 # 检查命令ID是否有效
@@ -204,21 +215,24 @@ class SRIConnection(asyncio.Protocol):
                 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}")
+                    methods.debug_log(f"{self.connection_id}|Connection_e1:211",
+                                      f"error212: 没有找到'{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()}")
+            methods.debug_log(f"{self.connection_id}|Connection_e1:132", f"#exception: {exception}")
+            methods.debug_log(f"{self.connection_id}|Connection_e1:123", f"#traceback: {methods.trace_log()}")
 
     def message2008(self, body_data):
-        # methods.debug_log(f"{self.connection_id}|SRIConnection80", f"message: 2008")
+        # methods.debug_log(f"{self.connection_id}|Connection_e1:80", f"message: 2008")
         pass
 
     def message2009(self, body_data):
+        """
+        车端上线
+        """
 
         # --- 监听 2009
         """
@@ -229,19 +243,20 @@ class SRIConnection(asyncio.Protocol):
         """
         object0 = protobuf.CSAdd()
         object0.ParseFromString(body_data)
-        methods.debug_log(f"{self.connection_id}|SRIConnection219", 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}")
+        methods.debug_log(f"{self.connection_id}|Connection_e1:219", f"serial: {object0.serial}")
+        # methods.debug_log(f"{self.connection_id}|Connection_e1:90", f"#name: {object0.name}")
+        # methods.debug_log(f"{self.connection_id}|Connection_e1:90", f"#type: {object0.type}")
 
         # --- update ---
         self.client_type = 'vehicle'
         self.client_info = {
-            'connection_id': self.connection_id,
+            'local_connection_id': self.connection_id,
             'rid': serial_rid_dict.get(object0.serial),
             'name': object0.name,
             'serial': object0.serial,
-            'egotype': 2,  # 客户端类型
+            'egotype': 2,  # 客户端类型 0 EgoType::None 1 EgoType::User 2 EgoType::Car
         }
+        methods.debug_log(f"{self.connection_id}|Connection_e1:259", f"client_info: {self.client_info}")
 
         """
         SCAddRobot: 消息体
@@ -254,9 +269,9 @@ class SRIConnection(asyncio.Protocol):
         """
         o1 = protobuf.Robot()
         # o1.rid = self.client_info.get('rid')
-        o1.rid = self.client_info.get('connection_id')
+        o1.rid = self.client_info.get('local_connection_id')
         o1.name = object0.name
-        o1.type = 2  # 0 EgoType::None 1 EgoType::User 2 EgoType::Car
+        o1.type = 2  # 客户端类型 0 EgoType::None 1 EgoType::User 2 EgoType::Car
         o1.state = protobuf.Robot.Online
         o2 = protobuf.SCAddRobot()
         o2.robot.CopyFrom(o1)
@@ -269,7 +284,7 @@ class SRIConnection(asyncio.Protocol):
         # --- 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}")
+                methods.debug_log(f"{self.connection_id}|Connection_e1:136", f"re_command_id: {re_command_id}")
                 item.client.write(re_send_data)
 
         # --- send 4007  todo 凯强说并未用到
@@ -282,49 +297,55 @@ class SRIConnection(asyncio.Protocol):
         # 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}")
+        # methods.debug_log(f"{self.connection_id} | Connection_e1:150", f"re_command_id: {re_command_id}")
         # self.client.write(re_send_data)
 
     def message2000(self, body_data):
 
-        # --- 解析消息体 2000
+        # --- 监听 2000
         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}")
+        methods.debug_log(f"{self.connection_id}|Connection_e1:293", f"account: {object.account}")
+        methods.debug_log(f"{self.connection_id}|Connection_e1:293", f"password: {object.password}")
 
-        # --- update ---
+        # --- check ---
         ret = True
         if object.account == "Ego" and object.password != '123456':
             ret = False
 
         # --- check ---
-        user = Global.mdb.get_one('UserInfo', {'username': object.account})
+        ret = True
         name = ''
         uuid = ''
-        if not user:
-            ret = False
-        elif not check_password_hash(user.get('password'), object.password):
-            ret = False
-        elif user.get('state') and int(user.get('state')) == 1:
-            ret = False
+        if object.account in ['Ego', 'test003']:
+            if object.password not in ['123456']:
+                ret = False
         else:
-            name = user.get('name')
-            uuid = str(user.get('_id'))
-            ret = True
+            user = Global.mdb.get_one('UserInfo', {'username': object.account})
+            if not user:
+                ret = False
+            elif not check_password_hash(user.get('password'), object.password):
+                ret = False
+            elif user.get('state') and int(user.get('state')) == 1:
+                ret = False
+            else:
+                name = user.get('name')
+                uuid = str(user.get('_id'))
+                ret = True
+        methods.debug_log(f"{self.connection_id}|Connection_e1:293", f"用户'{object.account}'登录认证结果: {ret}")
 
         # --- update ---
         if ret:
             self.client_type = 'cockpit'
             self.client_info = {
-                'connection_id': self.connection_id,
+                'local_connection_id': self.connection_id,  # 连接id
                 'uid': 3,  # 对应数据库里的ego的id
                 'name': object.account,  # 对应数据库里
                 'egotype': 1,  # 舱端类型
                 'user_uuid': uuid,  # 用户id
             }
 
-        # --- send 4000
+        # --- 发送 4000
         object = protobuf.SCSign()
         object.ret = ret  # 返回结果
         object.uid = self.connection_id
@@ -335,12 +356,12 @@ class SRIConnection(asyncio.Protocol):
         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}")
+        methods.debug_log(f"{self.connection_id}|Connection_e1:352", f"re_command_id: {re_command_id}")
         self.client.write(re_send_data)
 
     def message2010(self, body_data):
 
-        # --- send 4008 发送全部车端信息列表
+        # --- 监听 2010 发送 4008 发送全部车端信息列表
         """
         Robot: 消息体
         Robot.rid: string
@@ -354,23 +375,24 @@ class SRIConnection(asyncio.Protocol):
             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.rid = item.client_info.get('local_connection_id')
                 o1.name = item.client_info.get('name')
-                o1.type = 2  # EgoType::Car
+                o1.type = 2  # 客户端类型 0 EgoType::None 1 EgoType::User 2 EgoType::Car
                 o1.state = protobuf.Robot.RobotState.Value('Online')
                 o2.robot.add().CopyFrom(o1)
 
-        re_command_id = protobuf.SC_Robot  # 4008
+        # --- 发送 4008
+        re_command_id = protobuf.SC_Robot
         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}")
+        methods.debug_log(f"{self.connection_id}|Connection_e1:306", f"re_command_id: {re_command_id}")
         self.client.write(re_send_data)
 
     def message2001(self, body_data):
 
-        # --- 解析消息体
+        # --- 监听 2001
         """
         CSReq: 消息体
         CSReq.peer: int32(rid,车端唯一标识)
@@ -379,14 +401,14 @@ class SRIConnection(asyncio.Protocol):
         """
         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')}")
+        methods.debug_log(f"{self.connection_id}|Connection_e1:299.message2001", f"#peer: {o1.peer}")
+        methods.debug_log(f"{self.connection_id}|Connection_e1:299.message2001", f"#index: {o1.index}")
+        # methods.debug_log(f"{self.connection_id}|Connection_e1:299.message2001", f"#uid: {self.client_info.get('uid')}")
+        # methods.debug_log(f"{self.connection_id}|Connection_e1:299.message2001", f"#rid: {self.client_info.get('rid')}")
 
         # --- send 4009 指定车端
         for item in clients.values():
-            if item.client_info.get('connection_id') == o1.peer:
+            if item.client_info.get('local_connection_id') == o1.peer:
                 """
                 CSReq: 消息体
                 CSReq.peer: int32(rid,车端唯一标识)
@@ -394,7 +416,7 @@ class SRIConnection(asyncio.Protocol):
                 CSReq.egotype: int32(终端类型,舱端/车端)
                 """
                 o2 = protobuf.CSReq()
-                o2.peer = self.client_info.get('connection_id')  # 舱端id
+                o2.peer = self.client_info.get('local_connection_id')  # 舱端id
                 o2.index = o1.index
                 o2.egotype = o1.egotype
                 re_command_id = protobuf.SC_NotifyReq  # 4009
@@ -402,12 +424,12 @@ class SRIConnection(asyncio.Protocol):
                 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}")
+                methods.debug_log(f"{self.connection_id}|Connection_e1:217", f"re_command_id: {re_command_id}")
                 item.client.write(re_send_data)
 
     def message2002(self, body_data):
 
-        # --- 解析消息体
+        # --- 监听 2002
         """
         CSRep: 消息体
         CSRep.desc: VideoDesc
@@ -417,16 +439,16 @@ class SRIConnection(asyncio.Protocol):
         """
         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')}")
+        methods.debug_log(f"{self.connection_id}|Connection_e1:319", f"peer: {o1.peer}")
+        # methods.debug_log(f"{self.connection_id}|Connection_e1:235", f"#uid: {self.client_info.get('uid')}")
+        # methods.debug_log(f"{self.connection_id}|Connection_e1:235", f"#rid: {self.client_info.get('rid')}")
 
         # --- send 4010 指定舱端
         for item in clients.values():
-            if item.client_info.get('connection_id') == o1.peer:
+            if item.client_info.get('local_connection_id') == o1.peer:
                 o2 = protobuf.CSRep()
                 o2.desc = o1.desc
-                o2.peer = self.client_info.get('connection_id')  # 车端id
+                o2.peer = self.client_info.get('local_connection_id')  # 车端id
                 o2.index = o1.index
                 o2.egotype = o1.egotype
                 re_command_id = protobuf.SC_NotifyRep  # 4010
@@ -434,12 +456,12 @@ class SRIConnection(asyncio.Protocol):
                 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}")
+                methods.debug_log(f"{self.connection_id}|Connection_e1:217", f"re_command_id: {re_command_id}")
                 item.client.write(re_send_data)
 
     def message2004(self, body_data):
 
-        # --- 解析消息体
+        # --- 监听舱端 2004
         """
         Offer: 消息体
         Offer.index: int32
@@ -449,29 +471,35 @@ class SRIConnection(asyncio.Protocol):
         """
         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')}")
+        methods.debug_log(f"{self.connection_id}|Connection_e1:348", f"车端id: {object.peer}")
+        # methods.debug_log(f"{self.connection_id}|Connection_e1:348", f"uid: {self.client_info.get('uid')}")
+        # methods.debug_log(f"{self.connection_id}|Connection_e1:348", f"rid: {self.client_info.get('rid')}")
 
-        # --- send 4012 指定车端
+        # --- 删选指定车端
         for item in clients.values():
-            if item.client_info.get('connection_id') == object.peer:
+            if item.client_info.get('local_connection_id') == object.peer:
                 o1 = protobuf.Offer()
                 o1.index = object.index
-                o1.peer = self.client_info.get('connection_id')  # 舱端id
+                o1.peer = self.client_info.get('local_connection_id')  # 舱端id
                 o1.type = object.type
                 o1.sdp = object.sdp
+
+                # --- 设置
+                self.client_info['remote_connection_id'] = object.peer  # 车端id
+                item.client_info['remote_connection_id'] = self.client_info.get('local_connection_id')  # 舱端id
+
+                # --- 发送 4012
                 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}")
+                methods.debug_log(f"{self.connection_id}|Connection_e1:341", f"re_command_id: {re_command_id}")
                 item.client.write(re_send_data)
 
     def message2005(self, body_data):
 
-        # --- 解析消息体
+        # --- 监听 2005
         """
         Answer: 消息体
         Answer.index: int32
@@ -481,17 +509,17 @@ class SRIConnection(asyncio.Protocol):
         """
         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')}")
+        methods.debug_log(f"{self.connection_id}|Connection_e1:411", f"peer: {object.peer}")
+        # methods.debug_log(f"{self.connection_id}|Connection_e1:411", f"uid: {self.client_info.get('uid')}")
+        # methods.debug_log(f"{self.connection_id}|Connection_e1:411", f"rid: {self.client_info.get('rid')}")
 
         # --- send 4011 指定舱端
         for item in clients.values():
 
-            if item.client_info.get('connection_id') == object.peer:
+            if item.client_info.get('local_connection_id') == object.peer:
                 o1 = protobuf.Answer()
                 o1.index = object.index
-                o1.peer = self.client_info.get('connection_id')  # 车端id
+                o1.peer = self.client_info.get('local_connection_id')  # 车端id
                 o1.type = object.type
                 o1.sdp = object.sdp
                 re_command_id = protobuf.SC_NotifyAnswer  # 4011
@@ -499,8 +527,8 @@ class SRIConnection(asyncio.Protocol):
                 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}")
+                methods.debug_log(f"{self.connection_id}|Connection_e1:428", f"re_command_id: {re_command_id}")
+                methods.debug_log(f"{self.connection_id}|Connection_e1:428", f"index: {o1.index}")
                 item.client.write(re_send_data)
 
         # --- get VehicleStatus ---
@@ -509,13 +537,13 @@ class SRIConnection(asyncio.Protocol):
         data = item.get('args', {})
 
         # --- set VehicleStatus ---
-        data[str(self.connection_id)] = 4
+        data[str(self.connection_id)] = 4  # 车辆状态 1 离线 2 在线空闲 3 现场驾驶中 4 远程驾驶中
         update_dict = {'args': data}
         Global.mdb.update_one('GlobalVariable', unique_dict, update_dict)
 
     def message2006(self, body_data):
 
-        # --- 解析消息体
+        # --- 监听 2006
         """
         Candidate: 消息体
         Candidate.index: int32
@@ -528,17 +556,17 @@ class SRIConnection(asyncio.Protocol):
         """
         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')}")
+        # methods.debug_log(f"{self.connection_id}|Connection_e1:413", f"peer: {object.peer}")
+        # methods.debug_log(f"{self.connection_id}|Connection_e1:413", f"uid: {self.client_info.get('uid')}")
+        # methods.debug_log(f"{self.connection_id}|Connection_e1:413", f"rid: {self.client_info.get('rid')}")
 
         for item in clients.values():
 
             # --- send 4013 舱端到车端
-            if item.client_info.get('connection_id') == object.peer:
+            if item.client_info.get('local_connection_id') == object.peer:
                 o1 = protobuf.Candidate()
                 o1.index = object.index
-                o1.peer = self.client_info.get('connection_id')  # 舱端id,
+                o1.peer = self.client_info.get('local_connection_id')  # 舱端id,
                 o1.type = object.type
                 o1.candidate = object.candidate
                 o1.sdpMLineIndex = object.sdpMLineIndex
@@ -549,14 +577,14 @@ class SRIConnection(asyncio.Protocol):
                 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}|Connection_e1:409", f"re_command_id: {re_command_id}")
                 item.client.write(re_send_data)
 
             # --- send 4013 车端到舱端
-            if item.client_info.get('connection_id') == object.peer:
+            if item.client_info.get('local_connection_id') == object.peer:
                 o1 = protobuf.Candidate()
                 o1.index = object.index
-                o1.peer = self.client_info.get('connection_id')  # 车端id,
+                o1.peer = self.client_info.get('local_connection_id')  # 车端id,
                 o1.type = object.type
                 o1.candidate = object.candidate
                 o1.sdpMLineIndex = object.sdpMLineIndex
@@ -567,13 +595,13 @@ class SRIConnection(asyncio.Protocol):
                 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}")
+                # methods.debug_log(f"{self.connection_id}|Connection_e1:426", f"re_command_id: {re_command_id}")
+                # methods.debug_log(f"{self.connection_id}|Connection_e1:426", f"candidate.out: {o1.candidate}")
                 item.client.write(re_send_data)
 
     def message2007(self, body_data):
 
-        # --- 解析消息体 2007
+        # --- 监听 2007
         """
         Leave: 消息体
         Leave.peer: int32(车端rid)
@@ -581,30 +609,30 @@ class SRIConnection(asyncio.Protocol):
         """
         o1 = protobuf.Leave()
         o1.ParseFromString(body_data)
-        methods.debug_log(f"{self.connection_id}|SRIConnection497", f"#peer: {o1.peer}")
+        methods.debug_log(f"{self.connection_id}|Connection_e1:497", f"peer: {o1.peer}")
 
         # --- send 4009 指定车端
         for item in clients.values():
-            if item.client_info.get('connection_id') == o1.peer:
+            if item.client_info.get('local_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.peer = self.client_info.get('local_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}")
+                methods.debug_log(f"{self.connection_id}|Connection_e1:515", f"re_command_id: {re_command_id}")
                 item.client.write(re_send_data)
 
     def message2014(self, body_data):
 
-        # --- 解析消息体 2014
+        # --- 监听 2014
         """
         message CSState
         {
@@ -614,8 +642,8 @@ class SRIConnection(asyncio.Protocol):
         """
         o1 = protobuf.CSState()
         o1.ParseFromString(body_data)
-        methods.debug_log(f"{self.connection_id}|SRIConnection|572", f"#state: {o1.state}")
-        methods.debug_log(f"{self.connection_id}|SRIConnection|572", f"#uid: {o1.uid}")
+        methods.debug_log(f"{self.connection_id}|Connection_e1:572", f"state: {o1.state}")
+        methods.debug_log(f"{self.connection_id}|Connection_e1:572", f"uid: {o1.uid}")
 
         # --- send 4016 发送全部舱端
         for item in clients.values():
@@ -637,16 +665,16 @@ class SRIConnection(asyncio.Protocol):
                 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}")
+                methods.debug_log(f"{self.connection_id}|Connection_e1:551", f"re_command_id: {re_command_id}")
                 item.client.write(re_send_data)
 
         # --- send 6011 指发送车端操作用户的id
         for item in clients.values():
             if not item.client_info:
                 continue
-            if not item.client_info.get('connection_id'):
+            if not item.client_info.get('local_connection_id'):
                 continue
-            if item.client_info.get('connection_id') == o1.uid:
+            if item.client_info.get('local_connection_id') == o1.uid:
                 """
                 Leave: 消息体
                 Leave.peer: int32(车端rid)
@@ -661,7 +689,7 @@ class SRIConnection(asyncio.Protocol):
                 re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)
                 re_body_data = o3.SerializeToString()
                 re_send_data = re_head_data + re_body_data
-                methods.debug_log(f"{self.connection_id}|SRIConnection611", f"re_command_id: {re_command_id}")
+                methods.debug_log(f"{self.connection_id}|Connection_e1:664", f"re_command_id: {re_command_id}")
                 item.client.write(re_send_data)
 
     @staticmethod
@@ -672,14 +700,14 @@ class SRIConnection(asyncio.Protocol):
         count = 0
         while True:
             count += 1
-            print(f"#count: {count}", flush=True)
+            print(f"Connection_e1:689|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)
+                print(f"Connection_e1:689|client: {object.client}, update_at: {object.update_at}, "
+                      f"client_type: {object.client_type}", flush=True)
 
             await asyncio.sleep(3)  # 发送消息的间隔时间
 
@@ -696,8 +724,8 @@ class SRIConnection(asyncio.Protocol):
 
         # --- start ---
         async with server:
-            print(f"Server listening on 0.0.0.0:{Global.egoserver_port}", flush=True)
-            # await loop.create_task(SRIConnection.check_clients())
+            print(f"Connection_e1:713|Server listening on 0.0.0.0:{Global.egoserver_port}", flush=True)
+            # await loop.create_task(Connection_e1:.check_clients())
             await server.serve_forever()