Quellcode durchsuchen

修改communication模块为tyc开发的模块

339075217 vor 3 Jahren
Ursprung
Commit
784c1c6404

+ 7 - 0
.gitignore

@@ -14,3 +14,10 @@
 *.exp
 *.cache
 *.resources
+*.mp4
+*.config
+*.db
+*.CopyComplete
+*.json
+*.png
+

+ 9 - 11
unnormalized_node/unnormalized_node/Form1.cs

@@ -45,14 +45,13 @@ namespace UnNomalized_node
             //读取配置
             tool.json_file_operation.Instance.json_file_operation_init("./unnoralized_node_settings.json");
             //初始化通讯及数据单例
-            unnormalized_communication.Instance.unnormalized_communication_init();
+            unnormalized_communication.Instance.Communicator_Init();
             //连接
             JArray connect_string = tool.json_file_operation.Instance.read_json_jarray("communication_connect");
             foreach (var connect in connect_string)
             {
-                unnormalized_communication.Instance.communication_connect(connect.ToString());
+                unnormalized_communication.Instance.Connect(connect.ToString());
             }
-            unnormalized_communication.Instance.communication_run();
 
             string ip = tool.json_file_operation.Instance.read_json_string("camera_ip");
             string user = tool.json_file_operation.Instance.read_json_string("camera_user");
@@ -60,11 +59,11 @@ namespace UnNomalized_node
             int port = int.Parse(tool.json_file_operation.Instance.read_json_string("camera_port"));
 
             //添加LED屏
-            BroadcastBoardManager.Instance.AddSquareScreen(
+            /*BroadcastBoardManager.Instance.AddSquareScreen(
                 int.Parse(tool.json_file_operation.Instance.read_json_string("ternimalNumber")),
                 Encoding.Default.GetBytes(tool.json_file_operation.Instance.read_json_string("led_screen_ip")),
                                                                 5005, ONNONLed5KSDKD.Led5kSDK.bx_5k_card_type.BX_6K3, 2, 0);
-            BroadcastBoardManager.Instance.squareBoardList[0].UpdateStatus(BroadcastSquareBoard.Entrance_statu.ENTRANCE_NOSIGNAL, false);
+            BroadcastBoardManager.Instance.squareBoardList[0].UpdateStatus(BroadcastSquareBoard.Entrance_statu.ENTRANCE_NOSIGNAL, false);*/
             m_hk_camera = new HKVSCamera(pictureBox_camera);
             if (m_hk_camera.init())
             {
@@ -109,7 +108,7 @@ namespace UnNomalized_node
             {
                 //m_hk_camera.Camera.draw_image_to_wnd(pictureBox_camera.Handle);
                 //跟新led
-                update_led_screen();
+                //update_led_screen();
                 Thread.Sleep(100);
             }
             
@@ -125,14 +124,14 @@ namespace UnNomalized_node
 
 
             //显示车辆信息
-            string car_info_str = "  ";
+            string car_info_str = " ";
             TimedData<Message.Ground_status_msg> lidar_statu = communication_data.Instance.lidar_statu;
             Message.Locate_information locate_info = lidar_statu.Value.LocateInformationRealtime;
             //
             if (m_form_arrow.m_last_moving_statu.STATU != null)
             {
                 Message.Ground_status_msg statu = m_form_arrow.m_last_moving_statu.STATU;
-                car_info_str += string.Format("最近静止X:{0:0.000}m Y:{1:0.000}m 角度:{2:0.00}°" +
+                car_info_str += string.Format("静止X:{0:0.000}m Y:{1:0.000}m 角度:{2:0.00}°" +
                             "轴距:{3:0.000}m 车宽:{4:0.000}m 前轮角:{5:0.00}°", statu.LocateInformationRealtime.LocateX,
                             statu.LocateInformationRealtime.LocateY, statu.LocateInformationRealtime.LocateAngle,
                             statu.LocateInformationRealtime.LocateWheelBase, statu.LocateInformationRealtime.LocateWheelWidth,
@@ -148,7 +147,7 @@ namespace UnNomalized_node
                     if (locate_info != null)
                     {
 
-                        car_info_str += string.Format("\n 当前实时X:{0:0.000}m Y:{1:0.000}m 角度:{2:0.00}°" +
+                        car_info_str += string.Format("\n 实时X:{0:0.000}m Y:{1:0.000}m 角度:{2:0.00}°" +
                             "轴距:{3:0.000}m 车宽:{4:0.000}m 前轮角:{5:0.00}°", locate_info.LocateX,
                             locate_info.LocateY, locate_info.LocateAngle,
                             locate_info.LocateWheelBase, locate_info.LocateWheelWidth,
@@ -159,7 +158,6 @@ namespace UnNomalized_node
 
             }
             
-
             //更新投影仪提示箭头
 
             label_car_info.Text = car_info_str;
@@ -274,7 +272,7 @@ namespace UnNomalized_node
             }
             m_hk_camera.release();
             
-            unnormalized_communication.Instance.communication_uninit();
+            unnormalized_communication.Instance.Communicator_UnInit();
             communication_data.Instance.Release();
             m_form_arrow.Close();
         }

+ 32 - 45
unnormalized_node/unnormalized_node/FormArrow.cs

@@ -271,26 +271,25 @@ namespace UnNomalized_node
             terminal_status_msg terminal_statu = communication_data.Instance.terminal_statu.Value;
             int border_statu = lidar_statu.Value.BorderStatus;
             bool is_moving = ((border_statu >> 11) & 0x01) > 0;
-           //当前状态
-            if(lidar_statu.Value.GroundStatus== Ground_statu.CarCorrect|| 
-                lidar_statu.Value.GroundStatus == Ground_statu.CarBorderReached)
+
+            //运动状态清除数据
+            if(is_moving)
             {
-                if(is_moving)
-                {
-                    //运动正确
-                    m_last_moving_statu.reset();
-                }
-                else
+                m_last_moving_statu.reset();
+            }
+            else
+            {
+                //当前静止状态
+                switch(lidar_statu.Value.GroundStatus)
                 {
-                    //静止正确
-                    //若有上次的静止测量正确状态且无超界,则当前不可能出现 前后左右,旋转角、轴距、车宽的超界,只可能出现方向盘超界
-                    if (lidar_statu.Value.GroundStatus == Ground_statu.CarBorderReached)
-                    {
-                        int new_border = border_statu;
-                        if (m_last_moving_statu.STATU != null)
+                    case Ground_statu.CarCorrect:
+                        m_last_moving_statu.STATU= lidar_statu.Value;
+                        break;
+                    case Ground_statu.CarBorderReached:
+                        if(m_last_moving_statu.STATU != null)
                         {
-                            //将不可能出现的超界位变成0
-
+                            //上一刻静止且数据正确,当前静止,不可能出现超界,将超界清除
+                            int new_border = border_statu;
                             new_border = (new_border & (~(0x01 << 0)));
                             new_border = (new_border & (~(0x01 << 1)));
                             new_border = (new_border & (~(0x01 << 2)));
@@ -300,35 +299,21 @@ namespace UnNomalized_node
                             new_border = (new_border & (~(0x01 << 8)));
                             new_border = (new_border & (~(0x01 << 9)));
                             lidar_statu.Value.BorderStatus = new_border;
-                            
                         }
-                    } 
-                    m_last_moving_statu.STATU = lidar_statu.Value;
-
-                    
-                }
-              
-            }
-            else if(lidar_statu.Value.GroundStatus != Ground_statu.Nothing)
-            {
-                if (is_moving)
-                {
-                    //运动且失败
-                    m_last_moving_statu.reset();
-                }
-                else
-                {
-                    //静止且失败,显示上次静止成功数据,不显示光电 没有则不处理
-                    if (m_last_moving_statu.STATU != null)
-                    {
-                        lidar_statu = m_last_moving_statu.STATU;
-                    }
+                        break;
+                    case Ground_statu.Nothing:
+                        // 当前静止无车,清除上一时刻数据
+                        m_last_moving_statu.reset();
+                        break;
+                    case Ground_statu.Noise:
+                        if (m_last_moving_statu.STATU != null)
+                        {
+                            //上一时刻静止且正确,当前噪声,不显示当前数据,显示上一正确数据
+                            lidar_statu = m_last_moving_statu.STATU;
+                        }
+                        break;
                 }
             }
-            else
-            {
-                m_last_moving_statu.reset();
-            }
 
             //先判断光电开关运动状态下才显示光电
             if (is_moving &&terminal_statu.IdStruct != null)
@@ -374,10 +359,12 @@ namespace UnNomalized_node
                 {
                     case Ground_statu.Nothing:
                         Set_arrow(FormArrow.Car_statu.eNodata);
+                        //清除号牌
+                        communication_data.Instance.car_license.Set_timeout_ms(0);
                         break;
                     case Ground_statu.Noise:
-                        /*if (m_last_lidar_statu != Car_statu.eOK)
-                            Set_arrow(FormArrow.Car_statu.eNoise);*/
+                        if (m_last_lidar_statu == Car_statu.eDisconnect)
+                            Set_arrow(FormArrow.Car_statu.eNoise);
                         break;
                     case Ground_statu.CarCorrect:
                         Set_arrow(Car_statu.eOK);

+ 6 - 7
unnormalized_node/unnormalized_node/bin/x86/Debug/unnoralized_node_settings.json

@@ -1,18 +1,17 @@
 {
 
   "communication_connect": [
-    "tcp://192.168.1.181:30009", //终端
+    "tcp://192.168.1.184:30009", //终端
     "tcp://192.168.1.233:30010", //地面雷达
     "tcp://192.168.1.233:30008" //车位管理
   ],
 
-  "ternimalNumber": "1", //终端号
-  "unit_id": "0",       //单元号
-  "led_screen_ip": "192.168.1.161",
+  "ternimalNumber": "4", //终端号
+  "unit_id": "2", //单元号
+  "led_screen_ip": "192.168.1.164",
+  "numberMachine_ip": "192.168.1.154",
   "city": "武汉",
-  "numberMachine_ip": "192.168.1.151",
-
-  "camera_ip": "192.168.1.141",
+  "camera_ip": "192.168.1.144",
   "camera_user": "admin",
   "camera_password": "zx123456",
   "camera_port": "8000"

+ 6 - 6
unnormalized_node/unnormalized_node/bin/x86/Release/unnoralized_node_settings.json

@@ -1,17 +1,17 @@
 {
 
   "communication_connect": [
-    "tcp://192.168.1.181:30009", //终端
+    "tcp://192.168.1.184:30009", //终端
     "tcp://192.168.1.233:30010", //地面雷达
     "tcp://192.168.1.233:30008" //车位管理
   ],
 
-  "ternimalNumber": "1", //终端号
-  "unit_id": "0",
-  "led_screen_ip": "192.168.1.161",
+  "ternimalNumber": "3", //终端号
+  "unit_id": "2",
+  "led_screen_ip": "192.168.1.164",
   "city": "武汉",
-  "numberMachine_ip": "192.168.1.151",
-  "camera_ip": "192.168.1.141",
+  "numberMachine_ip": "192.168.1.154",
+  "camera_ip": "192.168.1.144",
   "camera_user": "admin",
   "camera_password": "zx123456",
   "camera_port": "8000"

+ 468 - 0
unnormalized_node/unnormalized_node/communication/Communicator.cs

@@ -0,0 +1,468 @@
+using NNanomsg;
+using NNanomsg.Protocols;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using Google.Protobuf;
+using Message;
+
+namespace Communication
+{
+    class MsgStamped
+    {
+        public DateTime receive_time;
+        public ByteString msg;
+        public Base_info header;
+
+        public MsgStamped()
+        {
+            receive_time = DateTime.Now;
+            msg = ByteString.Empty;
+        }
+
+        public MsgStamped(byte[] bytes)
+        {
+            receive_time = DateTime.Now;
+            msg = ByteString.CopyFrom(bytes);
+        }
+
+        public MsgStamped(ByteString msg)
+        {
+            receive_time = DateTime.Now;
+            this.msg = msg;
+        }
+
+        public MsgStamped(ByteString msg, Base_info header)
+        {
+            receive_time = DateTime.Now;
+            this.msg = msg;
+            this.header = header;
+            if(this.header.TimeoutMs <= 0)
+            {
+                this.header.TimeoutMs = 5000;
+            }
+        }
+    }
+
+    enum CommunicatorStatus
+    {
+        COMMUNICATION_UNKNOW = 0,           //通信状态 未知
+        COMMUNICATION_READY = 1,            //通信状态 正常
+
+        COMMUNICATION_FAULT = 3,         //通信状态 错误
+    }
+
+    enum CheckExecuterReturn
+    {
+        MSG_TIMEOUT = 0, // 消息超时
+        EXECUTER_READY = 1, // 执行器就绪
+        EXECUTER_BUSY = 2, // 执行器正忙
+        EXECUTER_FAULT = 3, // 执行器错误
+    }
+
+    class Communicator
+    {
+        /// <summary>
+        /// 实例退出标记
+        /// </summary>
+        public bool mb_exit;
+        /// <summary>
+        /// 初始化标记
+        /// </summary>
+        public bool mb_initialized;
+        /// <summary>
+        /// 消息超时时间
+        /// </summary>
+        public int m_timeout_milli = 2000;
+        /// <summary>
+        /// 通信类当前状态
+        /// </summary>
+        public CommunicatorStatus m_status;
+
+        /// <summary>
+        /// 单例锁对象
+        /// </summary>
+        protected readonly static object lockObj = new object();
+        /// <summary>
+        /// 单例
+        /// </summary>
+        protected static Communicator instance = null;
+        /// <summary>
+        /// 接收解析锁
+        /// </summary>
+        protected object m_receive_lock;
+        /// <summary>
+        /// 发送锁
+        /// </summary>
+        protected object m_send_lock;
+        /// <summary>
+        /// 发送队列
+        /// </summary>
+        protected Queue<MsgStamped> m_send_queue;
+        /// <summary>
+        /// 接收队列
+        /// </summary>
+        protected Queue<MsgStamped> m_receive_queue;
+        /// <summary>
+        /// 发送线程
+        /// </summary>
+        protected Thread m_thread_send;
+        /// <summary>
+        /// 接收线程
+        /// </summary>
+        protected Thread m_thread_receive;
+        /// <summary>
+        /// 解析接收string到protobuf消息
+        /// </summary>
+        protected Thread m_thread_decode_receive;
+        /// <summary>
+        /// nanomsg 通信句柄
+        /// </summary>
+        protected BusSocket m_socket;
+        /// <summary>
+        /// nnxx生成id队列
+        /// </summary>
+        protected Queue<NanomsgEndpoint> nanomsgEndpoints_queue;
+
+        /// <summary>
+        /// 构造函数
+        /// </summary>
+        /// <param name="server_ip"></param>
+        /// <param name="server_port"></param>
+        protected Communicator()
+        {
+            mb_exit = false;
+            mb_initialized = false;
+            m_receive_lock = new object();
+            m_send_lock = new object();
+            m_receive_queue = new Queue<MsgStamped>();
+            m_send_queue = new Queue<MsgStamped>();
+            nanomsgEndpoints_queue = new Queue<NanomsgEndpoint>();
+            m_status = CommunicatorStatus.COMMUNICATION_UNKNOW;
+        }
+
+        /// <summary>
+        /// 析构函数
+        /// </summary>
+        ~Communicator()
+        {
+            mb_exit = true;
+            if (m_thread_send != null)
+            {
+                m_thread_send.Join();
+            }
+            if (m_thread_receive != null)
+            {
+                m_thread_receive.Join();
+            }
+            if (m_thread_decode_receive != null)
+            {
+                m_thread_decode_receive.Join();
+            }
+        }
+
+        /// <summary>
+        /// 单例访问
+        /// </summary>
+        public static Communicator GetInstance()
+        {
+            if (instance == null)
+            {
+                lock (lockObj)
+                {
+                    if (instance == null)
+                    {
+                        instance = new Communicator();
+                    }
+                }
+            }
+            return instance;
+        }
+
+        /// <summary>
+        /// 初始化
+        /// </summary>
+        /// <returns></returns>
+        public bool Init()
+        {
+            try
+            {
+                if (!mb_initialized)
+                {
+                    mb_exit = false;
+                    mb_initialized = true;
+                    m_socket = new BusSocket();
+                    m_thread_receive = new Thread(new ParameterizedThreadStart(Receive_thread_function));
+                    m_thread_send = new Thread(new ParameterizedThreadStart(Send_thread_function));
+                    m_thread_decode_receive = new Thread(new ParameterizedThreadStart(Decode_thread_function));
+                    m_thread_receive.Start(this);
+                    m_thread_send.Start(this);
+                    m_thread_decode_receive.Start(this);
+                    m_status = CommunicatorStatus.COMMUNICATION_READY;
+                    return true;
+                }
+                else
+                {
+                    return false;
+                }
+            }
+            catch (Exception ex) { Console.WriteLine(ex.StackTrace); return false; }
+        }
+
+        /// <summary>
+        /// 反初始化
+        /// </summary>
+        /// <returns></returns>
+        public bool Uninit()
+        {
+            m_status = CommunicatorStatus.COMMUNICATION_UNKNOW;
+            mb_exit = true;
+            if (m_thread_receive != null)
+                m_thread_receive.Join();
+            if (m_thread_send != null)
+                m_thread_send.Join();
+            if (m_thread_decode_receive != null)
+                m_thread_decode_receive.Join();
+            if(m_socket!=null)
+            {
+                while(nanomsgEndpoints_queue.Count>0)
+                {
+                    NanomsgEndpoint nnep = nanomsgEndpoints_queue.Dequeue();
+                    m_socket.Shutdown(nnep);
+                }
+                m_socket.Dispose();
+            }
+            mb_initialized = false;
+            return true;
+        }
+
+        /// <summary>
+        /// 连接
+        /// </summary>
+        /// <param name="server_address"></param>
+        /// <returns></returns>
+        public bool Connect(string server_address)
+        {
+            if (m_socket == null)
+                return false;
+            NanomsgEndpoint end_point = m_socket.Connect(server_address);
+            return true;
+        }
+
+        /// <summary>
+        /// 绑定本地端口监听
+        /// </summary>
+        /// <param name="self_address"></param>
+        /// <returns></returns>
+        public bool Bind(string self_address)
+        {
+            if (m_socket == null)
+                return false;
+            NanomsgEndpoint end_point = m_socket.Bind(self_address);
+            return true;
+        }
+
+        /// <summary>
+        /// 发送消息
+        /// </summary>
+        /// <returns></returns>
+        public bool Send_msg(ByteString bs)
+        {
+            lock(m_send_lock)
+            {
+                m_send_queue.Enqueue(new MsgStamped(bs));
+            }
+            return true;
+        }
+
+        /// <summary>
+        /// 检查消息
+        /// </summary>
+        /// <param name="header"></param>
+        /// <returns></returns>
+        public virtual bool CheckMsg(Base_info header)
+        {
+            return true;
+            /*if (header.HasMsgType && header.HasSender && header.HasTimeoutMs
+                && header.MsgType == Message_type.EBaseMsg && header.Sender == Message.Communicator.EMain)
+                return true;
+            else
+                return false;*/
+        }
+
+        /// <summary>
+        /// 检查执行器状态
+        /// </summary>
+        /// <param name="header"></param>
+        /// <param name="receiveTime"></param>
+        /// <returns></returns>
+        public virtual CheckExecuterReturn CheckExecuter(Base_info header, DateTime receiveTime)
+        {
+            if ((DateTime.Now - receiveTime).Milliseconds > header.TimeoutMs)
+                return CheckExecuterReturn.MSG_TIMEOUT;
+            else
+                return CheckExecuterReturn.EXECUTER_READY;
+        }
+
+        /// <summary>
+        /// 执行消息
+        /// </summary>
+        /// <param name="msgStamped"></param>
+        /// <returns></returns>
+        public virtual bool ExecuteMsg(MsgStamped msgStamped)
+        {
+
+            return true;
+        }
+        
+        /// <summary>
+        /// 接收线程函数
+        /// </summary>
+        /// <param name="handle"></param>
+        private static void Receive_thread_function(object handle)
+        {
+            if (handle == null)
+                return;
+            Communicator comm = (Communicator)handle;
+            while (!comm.mb_exit)
+            {
+                try
+                {
+                    if (!comm.mb_initialized || comm.m_socket == null)
+                        continue;
+                    byte[] data = comm.m_socket.ReceiveImmediate();
+                    if (data != null && data.Length > 0 && comm.m_receive_queue != null)
+                    {
+                        // 解析头
+                        Base_msg base_msg = Base_msg.Parser.ParseFrom(data);
+                        //Console.WriteLine(base_msg.ToString());
+                        if (!comm.CheckMsg(base_msg.BaseInfo))
+                            continue;
+                        lock (comm.m_receive_lock)
+                        {
+                            comm.m_receive_queue.Enqueue(new MsgStamped(ByteString.CopyFrom(data), base_msg.BaseInfo));
+                        }
+                    }
+                }
+                catch (Exception ex) { Console.WriteLine(ex.StackTrace); }
+                Thread.Sleep(1);
+            }
+            Console.WriteLine("receive thread exit");
+        }
+
+        /// <summary>
+        /// 发送线程函数
+        /// </summary>
+        /// <param name="handle"></param>
+        private static void Send_thread_function(object handle)
+        {
+            if (handle == null)
+                return;
+            Communicator comm = (Communicator)handle;
+            while (!comm.mb_exit)
+            {
+                try
+                {
+                    if (!comm.mb_initialized || comm.m_socket == null)
+                        continue;
+                    lock (comm.m_send_lock)
+                    {
+                        if(comm.m_send_queue.Count > 0)
+                        {
+                            MsgStamped msg_stamped = comm.m_send_queue.Dequeue();
+                            comm.m_socket.Send(msg_stamped.msg.ToByteArray());
+                        }
+                    }
+                    //Console.WriteLine("msg sent");
+                }
+                catch (Exception ex) { Console.WriteLine(ex.StackTrace); }
+                Thread.Sleep(1);
+            }
+            Console.WriteLine("send thread exit");
+        }
+
+        /// <summary>
+        /// 解析线程函数
+        /// </summary>
+        /// <param name="handle"></param>
+        private static void Decode_thread_function(object handle)
+        {
+            if (handle == null)
+                return;
+            Communicator comm = (Communicator)handle;
+            while (!comm.mb_exit)
+            {
+                try
+                {
+                    DateTime current_time = DateTime.Now;
+
+                    if (!comm.mb_initialized)
+                        continue;
+                    MsgStamped msg_stamped = null;
+                    lock (comm.m_receive_lock)
+                    {
+                        if (comm.m_receive_queue.Count > 0)
+                        {
+                            msg_stamped = comm.m_receive_queue.Dequeue();
+                        }
+                        else
+                        {
+                            continue;
+                        }
+                        CheckExecuterReturn ret = comm.CheckExecuter(msg_stamped.header, msg_stamped.receive_time);
+                        if (ret == CheckExecuterReturn.MSG_TIMEOUT)
+                        {
+                            continue;
+                        }else if(ret == CheckExecuterReturn.EXECUTER_BUSY || ret == CheckExecuterReturn.EXECUTER_FAULT)
+                        {
+                            comm.m_receive_queue.Enqueue(msg_stamped);
+                        }else if(ret == CheckExecuterReturn.EXECUTER_READY)
+                        {
+                            comm.ExecuteMsg(msg_stamped);
+                        }
+                    }
+
+                    // 解析
+                    //comm.Decode_msg(msg_stamped.msg);
+                    //Console.WriteLine("msg parsed");
+                }
+                catch (Exception ex) { Console.WriteLine(ex.StackTrace); }
+                Thread.Sleep(1);
+            }
+            Console.WriteLine("decode thread exit");
+        }
+
+        ///// <summary>
+        ///// 解析string到protobuf消息
+        ///// </summary>
+        //private void Decode_msg(ByteString msg)
+        //{
+        //    if (msg == null)
+        //        return;
+        //    Base_msg base_msg = Base_msg.Parser.ParseFrom(msg);
+        //    switch(base_msg.BaseInfo.MsgType)
+        //    {
+        //        case Message_type.EParkspaceAllocationStatusMsg:
+        //            Parkspace_allocation_status_msg parkspace_status_msg = Parkspace_allocation_status_msg.Parser.ParseFrom(msg);
+        //            break;
+        //        case Message_type.EParkspaceForceUpdateResponseMsg:
+        //            Console.WriteLine("update response");
+        //            Parkspace_force_update_response_msg parkspace_force_update_msg = Parkspace_force_update_response_msg.Parser.ParseFrom(msg);
+        //            Console.WriteLine(parkspace_force_update_msg.ToString());
+        //            break;
+        //        case Message_type.EGroundStatusMsg:
+        //            Console.WriteLine("get ground status.....");
+        //            Ground_status_msg ground_status_msg = Ground_status_msg.Parser.ParseFrom(msg);
+        //            Console.WriteLine(ground_status_msg.ToString());
+        //            break;
+        //        default:
+        //            Console.WriteLine("unrecognized message received");
+        //            break;
+        //    }
+        //}
+
+    }
+}

+ 22 - 32
unnormalized_node/unnormalized_node/communication/unnormalized_communication.cs

@@ -7,7 +7,7 @@ using System.Threading.Tasks;
 using Message;
 namespace UnNomalized_node.communication
 {
-    class unnormalized_communication :Communication_socket_base
+    class unnormalized_communication : Communication.Communicator
     {
         /// <summary>
         /// 单例
@@ -30,46 +30,30 @@ namespace UnNomalized_node.communication
         {
            
         }
-        public void unnormalized_communication_init()
+        public void Communicator_Init()
         {
-            base.communication_init();
+            base.Init();
         }
-        public void unnormalized_communication_uninit()
+        public void Communicator_UnInit()
         {
-            base.communication_uninit();
+            base.Uninit();
         }
         //重载检查消息--检查是否给终端的消息
-        public override bool check_msg(byte[] msg)
-        {
-            return true;
-            //Message.Base_info base_Info = Message.Base_msg.Parser.ParseFrom(msg).BaseInfo;
-            //if (base_Info.Receiver == Message.Communicator.ETerminor ||
-            //    base_Info.Receiver == Message.Communicator.EEmpty||
-            //    base_Info.Receiver == Message.Communicator.EMain)//消息类型为空一般表示状态消息
-            //{
-            //    return true;
-            //}
-            //else
-            //{
-            //    //无效的消息
-            //    return false;
-            //}
-        }
+        
         //重载检查执行者状态
-        public override bool check_executer(byte[] msg)
+        /*public override bool check_executer(byte[] msg)
         {
             return true;
-        }
+        }*/
         //重载处理消息
-        public override void execute_msg(byte[] msg)
+        public override bool ExecuteMsg(Communication.MsgStamped msgStamped)
         {
-            Message.Message_type type = Message.Base_msg.Parser.ParseFrom(msg).BaseInfo.MsgType;
-            switch (type)
+            switch (msgStamped.header.MsgType)
             {
                 //雷达状态消息
                 case Message.Message_type.EGroundStatusMsg:
                     {
-                        Message.Ground_status_msg t_ground_status_msg = Message.Ground_status_msg.Parser.ParseFrom(msg);
+                        Message.Ground_status_msg t_ground_status_msg = Message.Ground_status_msg.Parser.ParseFrom(msgStamped.msg);
                         communication_data.Instance.lidar_statu = t_ground_status_msg;
 
                         /*if (t_ground_status_msg.IdStruct.TerminalId == communication_data.Instance.TerminalID)
@@ -83,13 +67,13 @@ namespace UnNomalized_node.communication
                 //车位状态消息
                 case Message.Message_type.EParkspaceAllocationStatusMsg:
                     {
-                        Message.Parkspace_allocation_status_msg t_parkspace_status_msg = Message.Parkspace_allocation_status_msg.Parser.ParseFrom(msg);
+                        Message.Parkspace_allocation_status_msg t_parkspace_status_msg = Message.Parkspace_allocation_status_msg.Parser.ParseFrom(msgStamped.msg);
                         communication_data.Instance.parkspace_statu = t_parkspace_status_msg;
                     }
                     break;
                 case Message.Message_type.ETerminalStatusMsg:
                     {
-                        Message.terminal_status_msg t_terminal_statu_msg = Message.terminal_status_msg.Parser.ParseFrom(msg);
+                        Message.terminal_status_msg t_terminal_statu_msg = Message.terminal_status_msg.Parser.ParseFrom(msgStamped.msg);
                         communication_data.Instance.terminal_statu = t_terminal_statu_msg;
 
                         /*if (t_terminal_statu_msg.IdStruct.TerminalId == communication_data.Instance.ID)
@@ -102,11 +86,17 @@ namespace UnNomalized_node.communication
                 default:
                     break;
             }
+            return true;
         }
+        /*public override void execute_msg(byte[] msg)
+        {
+            Message.Message_type type = Message.Base_msg.Parser.ParseFrom(msg).BaseInfo.MsgType;
+            
+        }*/
         //封装发送消息
-        public override void encapsulate_msg(byte[] msg)
+        /*public override void send_msg(byte[] msg)
         {
-            base.encapsulate_msg(msg);
-        }
+            base.Send_msg(msg);
+        }*/
     }
 }

+ 2 - 2
unnormalized_node/unnormalized_node/communication_data.cs

@@ -177,7 +177,7 @@ namespace UnNomalized_node
                     error.ErrorDescription += "单片机断开\n";
                 }
                 msg.StatuCode = error;
-                communication.unnormalized_communication.Instance.encapsulate_msg(msg.ToByteArray());
+                communication.unnormalized_communication.Instance.Send_msg(msg.ToByteString());
                 Thread.Sleep(100);
             }
         }
@@ -190,7 +190,7 @@ namespace UnNomalized_node
                 if(number!=null&&number!="")
                 {
                     m_timed_car_license = number;
-                    m_timed_car_license.Set_timeout_ms(10 * 60 * 1000);
+                    m_timed_car_license.Set_timeout_ms(int.MaxValue);
                 }
                 Thread.Sleep(500);
             }

+ 5 - 1
unnormalized_node/unnormalized_node/message/TimedData.cs

@@ -12,6 +12,7 @@ namespace UnNomalized_node.message
         private Data_type m_data;
         private DateTime m_time_point;
         private double m_time_out_ms = 3000;
+        private object m_lock = new object();
         public TimedData(Data_type data)
         {
             m_data = data;
@@ -42,7 +43,10 @@ namespace UnNomalized_node.message
         }
         public void Set_timeout_ms(int ms=1000)
         {
-            m_time_out_ms = ms;
+            lock (m_lock)
+            {
+                m_time_out_ms = ms;
+            }
         }
     }
 }

+ 4 - 0
unnormalized_node/unnormalized_node/obj/x86/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs

@@ -0,0 +1,4 @@
+// <autogenerated />
+using System;
+using System.Reflection;
+[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]

+ 4 - 0
unnormalized_node/unnormalized_node/obj/x86/Release/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs

@@ -0,0 +1,4 @@
+// <autogenerated />
+using System;
+using System.Reflection;
+[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]

+ 1 - 0
unnormalized_node/unnormalized_node/unnormalized_node.csproj

@@ -112,6 +112,7 @@
     <Compile Include="CHCNetSDK.cs" />
     <Compile Include="communication\communication_socket_base.cs" />
     <Compile Include="communication\communication_socket_tcp_base.cs" />
+    <Compile Include="communication\Communicator.cs" />
     <Compile Include="communication\unnormalized_communication.cs" />
     <Compile Include="communication_data.cs" />
     <Compile Include="Form1.cs">