Przeglądaj źródła

修改进度消息为map

zx 4 lat temu
rodzic
commit
12aecce3ba

+ 2 - 2
communication/communication_message.h

@@ -50,8 +50,8 @@ public:
         ePickup_command_request_msg=0x43,       //取车请求消息
         ePickup_command_response_msg=0x44,       //取车请求反馈消息
 
-        eStoring_process_statu_msg=0x90,      //停车进度条消息
-        ePicking_process_statu_msg=0x91,        //取车进度消息
+        eProcess_statu_map_msg=0x90,      //停车进度条消息
+
 	};
 
 //通讯单元

+ 11 - 13
dispatch/dispatch_communicator.cpp

@@ -3,7 +3,7 @@
 //
 
 #include "dispatch_communicator.h"
-
+#include "uniq_key.h"
 
 Dispatch_communicator::~Dispatch_communicator(){}
 
@@ -18,7 +18,7 @@ Error_manager Dispatch_communicator::dispatch_request(message::Dispatch_request_
     if(request.base_info().sender()!=message::eMain||request.base_info().receiver()!=message::eDispatch)
         return Error_manager(ERROR,MINOR_ERROR,"dispatch request invalid");
 
-    if(m_response_table.find(request)==true)
+    if(m_response_table.find(request.command_info().time())==true)
         return Error_manager(ERROR,MAJOR_ERROR," dispatch request repeated");
     //设置超时,若没有设置,默认300000  五分钟
     int timeout=request.base_info().has_timeout_ms()?request.base_info().timeout_ms():300000;
@@ -37,6 +37,7 @@ Error_manager Dispatch_communicator::dispatch_request(message::Dispatch_request_
     code=encapsulate_msg(&message);
     if(code!=SUCCESS)
         return code;
+    m_response_table[request.command_info().time()]=message::Dispatch_response_msg();
     //循环查询请求是否被处理
     auto start_time=std::chrono::system_clock::now();
     double time=0;
@@ -44,7 +45,7 @@ Error_manager Dispatch_communicator::dispatch_request(message::Dispatch_request_
         //查询到记录
         message::Dispatch_response_msg response;
         ///查询是否存在,并且删除该记录,
-        if(m_response_table.find(request,response))
+        if(m_response_table.find(request.command_info().time(),response))
         {
             //判断是否接收到回应,若回应信息被赋值则证明有回应
             if (response.has_base_info() && response.has_command_info())
@@ -63,7 +64,7 @@ Error_manager Dispatch_communicator::dispatch_request(message::Dispatch_request_
                                          "dispatch response basemsg info error");
                 }
                 result = response;
-                m_response_table.erase(request);
+                m_response_table.erase(request.command_info().time());
                 return SUCCESS;
 
             }
@@ -81,7 +82,7 @@ Error_manager Dispatch_communicator::dispatch_request(message::Dispatch_request_
         usleep(1000);
     }while(time<double(timeout));
 
-    m_response_table.erase(request);
+    m_response_table.erase(request.command_info().time());
     return Error_manager(RESPONSE_TIMEOUT,MINOR_ERROR,"dispatch request timeout");
 }
 /*
@@ -90,9 +91,9 @@ Error_manager Dispatch_communicator::dispatch_request(message::Dispatch_request_
 Error_manager Dispatch_communicator::cancel_request(message::Dispatch_request_msg& request)
 {
     message::Dispatch_response_msg t_response;
-    if(m_response_table.find(request,t_response))
+    if(m_response_table.find(request.command_info().time(),t_response))
     {
-        m_response_table.erase(request);
+        m_response_table.erase(request.command_info().time());
     }
     return SUCCESS;
 }
@@ -163,13 +164,10 @@ Error_manager Dispatch_communicator::encapsulate_msg(Communication_message* mess
             {
                 code=Error_manager(ERROR,CRITICAL_ERROR,"request message parse failed");
             }
-            m_response_table[request]=message::Dispatch_response_msg();
+
             //发送请求
             code= Communication_socket_base::encapsulate_msg(message);
-            if(code!=SUCCESS)
-            {
-                m_response_table.erase(request);
-            }
+
             break;
         }
         default:
@@ -194,7 +192,7 @@ Error_manager Dispatch_communicator::execute_msg(Communication_message* p_msg)
             response.ParseFromString(p_msg->get_message_buf());
             message::Dispatch_request_msg request=create_request_by_response(response);
             ///查询请求表是否存在,并且更新
-            if(m_response_table.find_update(request,response)==false)
+            if(m_response_table.find_update(request.command_info().time(),response)==false)
             {
                 return Error_manager(ERROR,NEGLIGIBLE_ERROR,"dispatch response without request");
             }

+ 1 - 1
dispatch/dispatch_communicator.h

@@ -54,7 +54,7 @@ protected:
     message::Dispatch_request_msg create_request_by_response(message::Dispatch_response_msg& msg);
 
 private:
-    thread_safe_map<message::Dispatch_request_msg,message::Dispatch_response_msg>          m_response_table;
+    thread_safe_map<std::string,message::Dispatch_response_msg>          m_response_table;
 
     //停车调度模块状态
     thread_safe_map<int,message::Dispatch_status_msg>                     m_storing_dispatch_statu_msg_map;

+ 1 - 1
lidar_locate/Locate_communicator.h

@@ -61,7 +61,7 @@ protected:
     thread_safe_map<message::Measure_request_msg,message::Measure_response_msg>          m_response_table;
 
 
-    thread_safe_map<int ,message::Measure_status_msg >                                        m_measure_statu_msg_map;
+    thread_safe_map<int ,message::Measure_status_msg >                                          m_measure_statu_msg_map;
     thread_safe_map<int ,std::chrono::system_clock::time_point>		                            m_statu_recv_time_map;
 };
 

+ 14 - 16
message/message_base.pb.cc

@@ -383,7 +383,7 @@ void AddDescriptorsImpl() {
       "eight\030\007 \001(\002\0223\n\020parkspace_status\030\010 \001(\0162\031."
       "message.Parkspace_status\022#\n\010car_info\030\t \001"
       "(\0132\021.message.Car_info\022\022\n\nentry_time\030\n \001("
-      "\t\022\022\n\nleave_time\030\013 \001(\t*\276\006\n\014Message_type\022\r"
+      "\t\022\022\n\nleave_time\030\013 \001(\t*\231\006\n\014Message_type\022\r"
       "\n\teBase_msg\020\000\022\020\n\014eCommand_msg\020\001\022\026\n\022eLoca"
       "te_status_msg\020\021\022\027\n\023eLocate_request_msg\020\022"
       "\022\030\n\024eLocate_response_msg\020\023\022\030\n\024eDispatch_"
@@ -402,22 +402,21 @@ void AddDescriptorsImpl() {
       "c_response_msg\020;\022\036\n\032eStore_command_reque"
       "st_msg\020A\022\037\n\033eStore_command_response_msg\020"
       "B\022\037\n\033ePickup_command_request_msg\020C\022 \n\034eP"
-      "ickup_command_response_msg\020D\022\037\n\032eStoring"
-      "_process_statu_msg\020\220\001\022\037\n\032ePicking_proces"
-      "s_statu_msg\020\221\001*f\n\014Communicator\022\n\n\006eEmpty"
-      "\020\000\022\t\n\005eMain\020\001\022\016\n\teTerminor\020\200\002\022\017\n\neParksp"
-      "ace\020\200\004\022\016\n\teMeasurer\020\200\006\022\016\n\teDispatch\020\200\010*#"
-      "\n\005Event\022\014\n\010eStoring\020\001\022\014\n\010ePicking\020\002*e\n\013E"
-      "rror_level\022\n\n\006NORMAL\020\000\022\024\n\020NEGLIGIBLE_ERR"
-      "OR\020\001\022\017\n\013MINOR_ERROR\020\002\022\017\n\013MAJOR_ERROR\020\003\022\022"
-      "\n\016CRITICAL_ERROR\020\004*q\n\020Parkspace_status\022\024"
-      "\n\020eParkspace_empty\020\000\022\027\n\023eParkspace_occup"
-      "ied\020\001\022\030\n\024eParkspace_reserverd\020\002\022\024\n\020ePark"
-      "space_error\020\003*(\n\tDirection\022\014\n\010eForward\020\001"
-      "\022\r\n\teBackward\020\002"
+      "ickup_command_response_msg\020D\022\033\n\026eProcess"
+      "_statu_map_msg\020\220\001*f\n\014Communicator\022\n\n\006eEm"
+      "pty\020\000\022\t\n\005eMain\020\001\022\016\n\teTerminor\020\200\002\022\017\n\nePar"
+      "kspace\020\200\004\022\016\n\teMeasurer\020\200\006\022\016\n\teDispatch\020\200"
+      "\010*#\n\005Event\022\014\n\010eStoring\020\001\022\014\n\010ePicking\020\002*e"
+      "\n\013Error_level\022\n\n\006NORMAL\020\000\022\024\n\020NEGLIGIBLE_"
+      "ERROR\020\001\022\017\n\013MINOR_ERROR\020\002\022\017\n\013MAJOR_ERROR\020"
+      "\003\022\022\n\016CRITICAL_ERROR\020\004*q\n\020Parkspace_statu"
+      "s\022\024\n\020eParkspace_empty\020\000\022\027\n\023eParkspace_oc"
+      "cupied\020\001\022\030\n\024eParkspace_reserverd\020\002\022\024\n\020eP"
+      "arkspace_error\020\003*(\n\tDirection\022\014\n\010eForwar"
+      "d\020\001\022\r\n\teBackward\020\002"
   };
   ::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
-      descriptor, 2255);
+      descriptor, 2218);
   ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
     "message_base.proto", &protobuf_RegisterTypes);
 }
@@ -464,7 +463,6 @@ bool Message_type_IsValid(int value) {
     case 67:
     case 68:
     case 144:
-    case 145:
       return true;
     default:
       return false;

+ 2 - 3
message/message_base.pb.h

@@ -116,12 +116,11 @@ enum Message_type {
   eStore_command_response_msg = 66,
   ePickup_command_request_msg = 67,
   ePickup_command_response_msg = 68,
-  eStoring_process_statu_msg = 144,
-  ePicking_process_statu_msg = 145
+  eProcess_statu_map_msg = 144
 };
 bool Message_type_IsValid(int value);
 const Message_type Message_type_MIN = eBase_msg;
-const Message_type Message_type_MAX = ePicking_process_statu_msg;
+const Message_type Message_type_MAX = eProcess_statu_map_msg;
 const int Message_type_ARRAYSIZE = Message_type_MAX + 1;
 
 const ::google::protobuf::EnumDescriptor* Message_type_descriptor();

+ 1 - 3
message/message_base.proto

@@ -37,9 +37,7 @@ enum Message_type
 
 
 
-    eStoring_process_statu_msg=0x90;        //停车进度条消息
-    ePicking_process_statu_msg=0x91;        //取车进度消息
-
+    eProcess_statu_map_msg=0x90;        //停取车进度条消息
 
 }
 

Plik diff jest za duży
+ 1010 - 292
message/process_message.pb.cc


Plik diff jest za duży
+ 651 - 307
message/process_message.pb.h


+ 14 - 6
message/process_message.proto

@@ -76,10 +76,10 @@ message Waitfor_leave_step_statu
 }
 
 //停车流程进度消息
-message Storing_process_statu_msg
+message Storing_process_statu
 {
-    required Base_info                  base_info=1;
-    required int32                      terminal_id=2;              //终端id
+    required int32                      terminal_id=1;              //终端id
+    required string                     license=2;                  //车牌号
     required Alloc_space_step_statu     alloc_space_step=3;
     required Measure_step_statu         measure_step=4;
     required Dispatch_store_step_statu  dispatch_step=5;
@@ -88,12 +88,20 @@ message Storing_process_statu_msg
 }
 
 //取车流程进度消息
-message Picking_process_statu_msg
+message Picking_process_statu
 {
-    required Base_info                  base_info=1;
-    required int32                      terminal_id=2;              //终端id
+    required int32                      terminal_id=1;              //终端id
+    required string                     license=2;
     required Check_space_step_statu     check_space_step=3;
     required Dispatch_pick_step_statu   dispatch_step=4;
     required Release_space_step_statu   release_space_step=5;
     required Waitfor_leave_step_statu   waitfor_leave=6;
 }
+
+message Process_statu_map_msg
+{
+    required Base_info                  base_info=1;
+    map<string,Storing_process_statu> storing_process_msg_map=2;
+    map<string,Picking_process_statu> picking_process_msg_map=3;
+}
+

+ 37 - 97
system/PickupProcessTask.cpp

@@ -10,60 +10,29 @@
 #include "system_communicator.h"
 
 PickupProcessTask::PickupProcessTask(unsigned int terminal_id)
-    :m_publish_statu_thread(nullptr)
 {
     m_terminor_id=terminal_id;
 
-    message::Base_info base_info;
-    base_info.set_msg_type(message::eStoring_process_statu_msg);
-    base_info.set_sender(message::eMain);
-    base_info.set_receiver(message::eEmpty);
-    m_picking_process_statu_msg.mutable_base_info()->CopyFrom(base_info);
-    m_picking_process_statu_msg.set_terminal_id(terminal_id);
     reset_process_statu();
 }
 PickupProcessTask::~PickupProcessTask()
 {
-    //退出线程
-    m_publish_exit_condition.set_pass_ever(true);
-    if(m_publish_statu_thread!= nullptr)
-    {
-        if(m_publish_statu_thread->joinable())
-        {
-            m_publish_statu_thread->join();
-        }
-        delete m_publish_statu_thread;
-        m_publish_statu_thread=nullptr;
-    }
+
 }
 Error_manager PickupProcessTask::init_task(message::Command_info command_info, message::Car_info car_info)
 {
     m_command_info=command_info;
     m_car_info=car_info;
 
-    message::Base_info base_info;
-    base_info.set_msg_type(message::ePicking_process_statu_msg);
-    base_info.set_sender(message::eMain);
-    base_info.set_receiver(message::eEmpty);
-
-    m_picking_process_statu_msg.mutable_base_info()->CopyFrom(base_info);
-    reset_process_statu();
-
-    ///创建状态发布线程
-    if(m_publish_statu_thread== nullptr)
-    {
-        m_publish_exit_condition.reset(false, false, false);
-        m_publish_statu_thread=new std::thread(publish_thread_func,this);
-    }
 
     if(is_ready()) {
         reset_process_statu();
-        return SUCCESS;
     }
     else
     {
         return Error_manager(ERROR,MINOR_ERROR,"终端未准备!!!");
     }
+
 }
 
 /*
@@ -84,10 +53,11 @@ void PickupProcessTask::reset_process_statu()
     waitfor_leave_step.set_step_statu(message::eWaiting);
 
     std::lock_guard<std::mutex> lock(m_picking_statu_lock);
-    m_picking_process_statu_msg.mutable_check_space_step()->CopyFrom(check_step);
-    m_picking_process_statu_msg.mutable_dispatch_step()->CopyFrom(pick_step);
-    m_picking_process_statu_msg.mutable_release_space_step()->CopyFrom(release_step);
-    m_picking_process_statu_msg.mutable_waitfor_leave()->CopyFrom(waitfor_leave_step);
+    m_picking_process_statu.mutable_check_space_step()->CopyFrom(check_step);
+    m_picking_process_statu.mutable_dispatch_step()->CopyFrom(pick_step);
+    m_picking_process_statu.mutable_release_space_step()->CopyFrom(release_step);
+    m_picking_process_statu.mutable_waitfor_leave()->CopyFrom(waitfor_leave_step);
+    m_picking_process_statu.set_license(m_car_info.license());
 
 
 
@@ -99,12 +69,12 @@ void PickupProcessTask::reset_process_statu()
 bool PickupProcessTask::is_ready()
 {
     std::lock_guard<std::mutex> lock(m_picking_statu_lock);
-    bool cond_check_space = m_picking_process_statu_msg.check_space_step().step_statu()==message::eWaiting
-                            ||m_picking_process_statu_msg.check_space_step().step_statu()==message::eComplete;
-    bool cond_dispatch = m_picking_process_statu_msg.dispatch_step().step_statu()==message::eWaiting
-                         ||m_picking_process_statu_msg.dispatch_step().step_statu()==message::eComplete;
-    bool cond_release_space = m_picking_process_statu_msg.release_space_step().step_statu()==message::eWaiting
-                              ||m_picking_process_statu_msg.release_space_step().step_statu()==message::eComplete;
+    bool cond_check_space = m_picking_process_statu.check_space_step().step_statu()==message::eWaiting
+                            ||m_picking_process_statu.check_space_step().step_statu()==message::eComplete;
+    bool cond_dispatch = m_picking_process_statu.dispatch_step().step_statu()==message::eWaiting
+                         ||m_picking_process_statu.dispatch_step().step_statu()==message::eComplete;
+    bool cond_release_space = m_picking_process_statu.release_space_step().step_statu()==message::eWaiting
+                              ||m_picking_process_statu.release_space_step().step_statu()==message::eComplete;
     return cond_check_space && cond_dispatch && cond_release_space;
 }
 
@@ -116,7 +86,7 @@ Error_manager PickupProcessTask::search_space()
     //更新状态
     {
         std::lock_guard<std::mutex> lock(m_picking_statu_lock);
-        m_picking_process_statu_msg.mutable_check_space_step()->set_step_statu(message::eWorking);
+        m_picking_process_statu.mutable_check_space_step()->set_step_statu(message::eWorking);
     }
 
     /*
@@ -126,8 +96,8 @@ Error_manager PickupProcessTask::search_space()
         ||m_car_info.has_license()==false)
     {
         std::lock_guard<std::mutex> lock(m_picking_statu_lock);
-        m_picking_process_statu_msg.mutable_check_space_step()->set_step_statu(message::eError);
-        m_picking_process_statu_msg.mutable_check_space_step()->set_description("查询车位请求汽车信息错误");
+        m_picking_process_statu.mutable_check_space_step()->set_step_statu(message::eError);
+        m_picking_process_statu.mutable_check_space_step()->set_description("查询车位请求汽车信息错误");
         return Error_manager(INVALID_MESSAGE,CRITICAL_ERROR,"查询车位请求汽车信息错误");
     }
 
@@ -138,8 +108,8 @@ Error_manager PickupProcessTask::search_space()
     std::lock_guard<std::mutex> lock(m_picking_statu_lock);
     if(code!=SUCCESS)
     {
-        m_picking_process_statu_msg.mutable_check_space_step()->set_description(code.get_error_description());
-        m_picking_process_statu_msg.mutable_check_space_step()->set_step_statu(message::eError);
+        m_picking_process_statu.mutable_check_space_step()->set_description(code.get_error_description());
+        m_picking_process_statu.mutable_check_space_step()->set_step_statu(message::eError);
         return code;
     }
 
@@ -158,12 +128,12 @@ Error_manager PickupProcessTask::search_space()
     code = Parkspace_communicator::get_instance_pointer()->search_request(request,m_parcspace_search_response_msg);
     if(code==SUCCESS)
     {
-        m_picking_process_statu_msg.mutable_check_space_step()->mutable_space_info()->CopyFrom(m_parcspace_search_response_msg.car_position());
-        m_picking_process_statu_msg.mutable_check_space_step()->set_step_statu(message::eComplete);
+        m_picking_process_statu.mutable_check_space_step()->mutable_space_info()->CopyFrom(m_parcspace_search_response_msg.car_position());
+        m_picking_process_statu.mutable_check_space_step()->set_step_statu(message::eComplete);
     }
     else {
-        m_picking_process_statu_msg.mutable_check_space_step()->set_step_statu(message::eError);
-        m_picking_process_statu_msg.mutable_check_space_step()->set_description(code.get_error_description());
+        m_picking_process_statu.mutable_check_space_step()->set_step_statu(message::eError);
+        m_picking_process_statu.mutable_check_space_step()->set_description(code.get_error_description());
     }
     return code;
 }
@@ -180,8 +150,8 @@ void PickupProcessTask::Main()
             //更新状态
             {
                 std::lock_guard<std::mutex> lock(m_picking_statu_lock);
-                m_picking_process_statu_msg.mutable_dispatch_step()->set_step_statu(message::eWorking);
-                m_picking_process_statu_msg.mutable_dispatch_step()->mutable_space_info()->CopyFrom(
+                m_picking_process_statu.mutable_dispatch_step()->set_step_statu(message::eWorking);
+                m_picking_process_statu.mutable_dispatch_step()->mutable_space_info()->CopyFrom(
                         m_parcspace_search_response_msg.car_position());
             }
             //开始工作
@@ -195,11 +165,11 @@ void PickupProcessTask::Main()
                             <<", 车位序号:"<<m_parcspace_search_response_msg.car_position().index()
                             <<", 车牌号:"<<m_car_info.license()
                             <<", 库内车牌号:"<<m_parcspace_search_response_msg.car_position().car_info().license();
-                m_picking_process_statu_msg.mutable_dispatch_step()->set_step_statu(message::eError);
-                m_picking_process_statu_msg.mutable_dispatch_step()->set_description(code.get_error_description());
+                m_picking_process_statu.mutable_dispatch_step()->set_step_statu(message::eError);
+                m_picking_process_statu.mutable_dispatch_step()->set_description(code.get_error_description());
                 break;
             }
-            m_picking_process_statu_msg.mutable_dispatch_step()->set_step_statu(message::eComplete);
+            m_picking_process_statu.mutable_dispatch_step()->set_step_statu(message::eComplete);
             LOG(WARNING)<<"取车调度成功,取车终端:"<<m_terminor_id<<"指令id:"<<m_command_info.place()
                         <<", 车位id:"<<m_parcspace_search_response_msg.car_position().parkspace_id()
                         <<", 车位楼层:"<<m_parcspace_search_response_msg.car_position().floor()
@@ -213,20 +183,20 @@ void PickupProcessTask::Main()
             //更新状态
             {
                 std::lock_guard<std::mutex> lock(m_picking_statu_lock);
-                m_picking_process_statu_msg.mutable_release_space_step()->set_step_statu(message::eWorking);
-                m_picking_process_statu_msg.mutable_release_space_step()->mutable_space_info()->CopyFrom(
+                m_picking_process_statu.mutable_release_space_step()->set_step_statu(message::eWorking);
+                m_picking_process_statu.mutable_release_space_step()->mutable_space_info()->CopyFrom(
                         m_parcspace_search_response_msg.car_position());
             }
             code=release_space_step();
             std::lock_guard<std::mutex> lock(m_picking_statu_lock);
             if(code!=SUCCESS)
             {
-                m_picking_process_statu_msg.mutable_release_space_step()->set_step_statu(message::eError);
-                m_picking_process_statu_msg.mutable_release_space_step()->set_description(code.get_error_description());
+                m_picking_process_statu.mutable_release_space_step()->set_step_statu(message::eError);
+                m_picking_process_statu.mutable_release_space_step()->set_description(code.get_error_description());
                 LOG(ERROR)<<"取车释放车位失败:"<<code.get_error_description();
                 break;
             }
-            m_picking_process_statu_msg.mutable_release_space_step()->set_step_statu(message::eComplete);
+            m_picking_process_statu.mutable_release_space_step()->set_step_statu(message::eComplete);
         }
         //第三步,等待车辆离开
         case 2:
@@ -234,19 +204,19 @@ void PickupProcessTask::Main()
             //更新状态
             {
                 std::lock_guard<std::mutex> lock(m_picking_statu_lock);
-                m_picking_process_statu_msg.mutable_waitfor_leave()->set_step_statu(message::eWorking);
-                m_picking_process_statu_msg.mutable_waitfor_leave()->mutable_car_info()->CopyFrom(m_car_info);
+                m_picking_process_statu.mutable_waitfor_leave()->set_step_statu(message::eWorking);
+                m_picking_process_statu.mutable_waitfor_leave()->mutable_car_info()->CopyFrom(m_car_info);
             }
             //等待离开
             code=wait_for_leave_step();
             std::lock_guard<std::mutex> lock(m_picking_statu_lock);
             if(code!=SUCCESS)
             {
-                m_picking_process_statu_msg.mutable_waitfor_leave()->set_step_statu(message::eError);
-                m_picking_process_statu_msg.mutable_waitfor_leave()->set_description(code.get_error_description());
+                m_picking_process_statu.mutable_waitfor_leave()->set_step_statu(message::eError);
+                m_picking_process_statu.mutable_waitfor_leave()->set_description(code.get_error_description());
                 break;
             }
-            m_picking_process_statu_msg.mutable_waitfor_leave()->set_step_statu(message::eComplete);
+            m_picking_process_statu.mutable_waitfor_leave()->set_step_statu(message::eComplete);
         }
     }
 
@@ -351,33 +321,3 @@ Error_manager PickupProcessTask::release_space_step()
         return Error_manager(FAILED,MINOR_ERROR,"取车流程parkspace release response error_code error");
 }
 
-/*
- * 发布状态线程
- */
-void PickupProcessTask::publish_thread_func(PickupProcessTask* ptask)
-{
-    if(ptask)
-    {
-        ptask->publish_step_status();
-    }
-}
-void PickupProcessTask::publish_step_status()
-{
-    //未收到退出信号
-    while(false==m_publish_exit_condition.wait_for_ex(std::chrono::milliseconds(50)))
-    {
-        /*
-         * 通过communicator 发布状态
-         */
-        if(System_communicator::get_instance_pointer())
-        {
-            if(m_picking_process_statu_msg.has_base_info()==true)
-            {
-                std::lock_guard<std::mutex> lock(m_picking_statu_lock);
-                System_communicator::get_instance_pointer()->post_entrance_statu(m_picking_process_statu_msg);
-            }
-
-        }
-
-    }
-}

+ 1 - 8
system/PickupProcessTask.h

@@ -48,19 +48,12 @@ protected:
      */
     void reset_process_statu();
 
-    /*
-     * 发布进度
-     */
-    static void publish_thread_func(PickupProcessTask* p_commander);
-    void publish_step_status();
 
 protected:
     message::Command_info                m_command_info;
     unsigned int                m_terminor_id;
     message::Car_info           m_car_info;          //当前流程的车辆信息
 
-    std::thread*                    m_publish_statu_thread;             //广播状态线程
-    Thread_condition				m_publish_exit_condition;			//发送的条件变量
 private:
     //查询到的车位信息
     message::Parkspace_search_response_msg                  m_parcspace_search_response_msg;
@@ -69,7 +62,7 @@ private:
 
     //取车车位的进度状态
     std::mutex                                              m_picking_statu_lock;
-    message::Picking_process_statu_msg                      m_picking_process_statu_msg;
+    message::Picking_process_statu                    m_picking_process_statu;
 
 };
 

+ 52 - 105
system/StoreProcessTask.cpp

@@ -9,34 +9,17 @@
 #include "process_message.pb.h"
 #include "command_manager.h"
 #include "system_communicator.h"
+#include "uniq_key.h"
 
 StoreProcessTask::StoreProcessTask(unsigned int terminor_id)
-    :m_publish_statu_thread(nullptr)
 {
     m_terminor_id=terminor_id;
 
-    message::Base_info base_info;
-    base_info.set_msg_type(message::eStoring_process_statu_msg);
-    base_info.set_sender(message::eMain);
-    base_info.set_receiver(message::eEmpty);
-    m_storing_process_statu_msg.mutable_base_info()->CopyFrom(base_info);
-    m_storing_process_statu_msg.set_terminal_id(terminor_id);
     reset_process_statu();
 }
 
 StoreProcessTask::~StoreProcessTask()
 {
-    //退出线程
-    m_publish_exit_condition.set_pass_ever(true);
-    if(m_publish_statu_thread!= nullptr)
-    {
-        if(m_publish_statu_thread->joinable())
-        {
-            m_publish_statu_thread->join();
-        }
-        delete m_publish_statu_thread;
-        m_publish_statu_thread=nullptr;
-    }
 }
 
 Error_manager StoreProcessTask::init_task(message::Command_info command_info,
@@ -48,13 +31,6 @@ Error_manager StoreProcessTask::init_task(message::Command_info command_info,
     m_car_info=car_info;
     m_locate_info=locate_info;
 
-    ///创建状态发布线程
-    if(m_publish_statu_thread== nullptr)
-    {
-        m_publish_exit_condition.reset(false, false, false);
-        m_publish_statu_thread=new std::thread(publish_thread_func,this);
-    }
-
     if(is_ready()) {
         reset_process_statu();
         return SUCCESS;
@@ -127,6 +103,8 @@ Error_manager StoreProcessTask::dispatch_step()
     request.mutable_base_info()->CopyFrom(base_info);
 
     request.mutable_command_info()->CopyFrom(m_command_info);
+    std::string key=create_key();
+    request.mutable_command_info()->set_time(key);
     request.set_terminal_id(m_terminor_id);
     request.set_dispatch_motion_direction(message::E_STORE_CAR);
     request.set_parkspace_id(m_parcspace_alloc_response_msg.allocated_space_info().parkspace_id());
@@ -163,11 +141,12 @@ void StoreProcessTask::reset_process_statu()
     release_step.set_step_statu(message::eWaiting);
 
     std::lock_guard<std::mutex> lock(m_storing_statu_lock);
-    m_storing_process_statu_msg.mutable_alloc_space_step()->CopyFrom(alloc_step);
-    m_storing_process_statu_msg.mutable_measure_step()->CopyFrom(measure_step);
-    m_storing_process_statu_msg.mutable_dispatch_step()->CopyFrom(store_step);
-    m_storing_process_statu_msg.mutable_confirm_space_step()->CopyFrom(confirm_step);
-    m_storing_process_statu_msg.mutable_failed_release_space_step()->CopyFrom(release_step);
+    m_storing_process_statu.mutable_alloc_space_step()->CopyFrom(alloc_step);
+    m_storing_process_statu.mutable_measure_step()->CopyFrom(measure_step);
+    m_storing_process_statu.mutable_dispatch_step()->CopyFrom(store_step);
+    m_storing_process_statu.mutable_confirm_space_step()->CopyFrom(confirm_step);
+    m_storing_process_statu.mutable_failed_release_space_step()->CopyFrom(release_step);
+    m_storing_process_statu.set_license(m_car_info.license());
 
 }
 
@@ -177,16 +156,16 @@ void StoreProcessTask::reset_process_statu()
 bool StoreProcessTask::is_ready()
 {
     std::lock_guard<std::mutex> lock(m_storing_statu_lock);
-    bool cond_alloc_space = m_storing_process_statu_msg.alloc_space_step().step_statu()==message::eWaiting
-                            ||m_storing_process_statu_msg.alloc_space_step().step_statu()==message::eComplete;
-    bool cond_measure = m_storing_process_statu_msg.measure_step().step_statu()==message::eWaiting
-                            ||m_storing_process_statu_msg.measure_step().step_statu()==message::eComplete;
-    bool cond_dispatch = m_storing_process_statu_msg.dispatch_step().step_statu()==message::eWaiting
-                            ||m_storing_process_statu_msg.dispatch_step().step_statu()==message::eComplete;
-    bool cond_confirm_space = m_storing_process_statu_msg.confirm_space_step().step_statu()==message::eWaiting
-                            ||m_storing_process_statu_msg.confirm_space_step().step_statu()==message::eComplete;
-    bool cond_release_space = m_storing_process_statu_msg.failed_release_space_step().step_statu()==message::eWaiting
-                            ||m_storing_process_statu_msg.failed_release_space_step().step_statu()==message::eComplete;
+    bool cond_alloc_space = m_storing_process_statu.alloc_space_step().step_statu()==message::eWaiting
+                            ||m_storing_process_statu.alloc_space_step().step_statu()==message::eComplete;
+    bool cond_measure = m_storing_process_statu.measure_step().step_statu()==message::eWaiting
+                            ||m_storing_process_statu.measure_step().step_statu()==message::eComplete;
+    bool cond_dispatch = m_storing_process_statu.dispatch_step().step_statu()==message::eWaiting
+                            ||m_storing_process_statu.dispatch_step().step_statu()==message::eComplete;
+    bool cond_confirm_space = m_storing_process_statu.confirm_space_step().step_statu()==message::eWaiting
+                            ||m_storing_process_statu.confirm_space_step().step_statu()==message::eComplete;
+    bool cond_release_space = m_storing_process_statu.failed_release_space_step().step_statu()==message::eWaiting
+                            ||m_storing_process_statu.failed_release_space_step().step_statu()==message::eComplete;
     return cond_alloc_space && cond_measure && cond_dispatch && cond_confirm_space && cond_release_space;
 }
 
@@ -198,8 +177,8 @@ Error_manager StoreProcessTask::alloc_space()
     //更新车位分配步骤状态
     {
         std::lock_guard<std::mutex> lock(m_storing_statu_lock);
-        m_storing_process_statu_msg.mutable_alloc_space_step()->mutable_car_info()->CopyFrom(m_car_info);
-        m_storing_process_statu_msg.mutable_alloc_space_step()->set_step_statu(message::eWorking);
+        m_storing_process_statu.mutable_alloc_space_step()->mutable_car_info()->CopyFrom(m_car_info);
+        m_storing_process_statu.mutable_alloc_space_step()->set_step_statu(message::eWorking);
     }
 
     /*
@@ -208,8 +187,8 @@ Error_manager StoreProcessTask::alloc_space()
     if(m_locate_info.has_locate_height()==false||m_locate_info.has_locate_width()==false)
     {
         std::lock_guard<std::mutex> lock(m_storing_statu_lock);
-        m_storing_process_statu_msg.mutable_alloc_space_step()->set_step_statu(message::eError);
-        m_storing_process_statu_msg.mutable_alloc_space_step()->set_description("停车请求缺少车辆高度和宽度信息");
+        m_storing_process_statu.mutable_alloc_space_step()->set_step_statu(message::eError);
+        m_storing_process_statu.mutable_alloc_space_step()->set_description("停车请求缺少车辆高度和宽度信息");
         return Error_manager(FAILED,MINOR_ERROR,"停车请求缺少车辆高度和宽度信息");
     }
     /*
@@ -219,8 +198,8 @@ Error_manager StoreProcessTask::alloc_space()
     if(code!=SUCCESS)
     {
         std::lock_guard<std::mutex> lock(m_storing_statu_lock);
-        m_storing_process_statu_msg.mutable_alloc_space_step()->set_step_statu(message::eError);
-        m_storing_process_statu_msg.mutable_alloc_space_step()->set_description(code.get_error_description());
+        m_storing_process_statu.mutable_alloc_space_step()->set_step_statu(message::eError);
+        m_storing_process_statu.mutable_alloc_space_step()->set_description(code.get_error_description());
         return code;
     }
 
@@ -243,8 +222,8 @@ Error_manager StoreProcessTask::alloc_space()
     std::lock_guard<std::mutex> lock(m_storing_statu_lock);
     if(code!=SUCCESS)
     {
-        m_storing_process_statu_msg.mutable_alloc_space_step()->set_step_statu(message::eError);
-        m_storing_process_statu_msg.mutable_alloc_space_step()->set_description(code.get_error_description());
+        m_storing_process_statu.mutable_alloc_space_step()->set_step_statu(message::eError);
+        m_storing_process_statu.mutable_alloc_space_step()->set_description(code.get_error_description());
         return code;
     }
 
@@ -253,18 +232,18 @@ Error_manager StoreProcessTask::alloc_space()
         message::Car_info alloc_car_info=m_parcspace_alloc_response_msg.allocated_space_info().car_info();
         if(alloc_car_info.license()!=m_car_info.license())
         {
-            m_storing_process_statu_msg.mutable_alloc_space_step()->set_step_statu(message::eError);
-            m_storing_process_statu_msg.mutable_alloc_space_step()->set_description("分配车位反馈的车辆信息不匹配");
+            m_storing_process_statu.mutable_alloc_space_step()->set_step_statu(message::eError);
+            m_storing_process_statu.mutable_alloc_space_step()->set_description("分配车位反馈的车辆信息不匹配");
             return Error_manager(ERROR,MINOR_ERROR,"分配车位反馈的车辆信息不匹配");
         }
 
-        m_storing_process_statu_msg.mutable_alloc_space_step()->set_step_statu(message::eComplete);
+        m_storing_process_statu.mutable_alloc_space_step()->set_step_statu(message::eComplete);
         return SUCCESS;
     }
     else
     {
-        m_storing_process_statu_msg.mutable_alloc_space_step()->set_step_statu(message::eError);
-        m_storing_process_statu_msg.mutable_alloc_space_step()->set_description("分配车位反馈结果错误");
+        m_storing_process_statu.mutable_alloc_space_step()->set_step_statu(message::eError);
+        m_storing_process_statu.mutable_alloc_space_step()->set_description("分配车位反馈结果错误");
         return Error_manager(FAILED,MINOR_ERROR,"分配车位反馈结果错误");
     }
 }
@@ -383,7 +362,7 @@ void StoreProcessTask::Main()
             //更新状态信息
             {
                 std::lock_guard<std::mutex> lock(m_storing_statu_lock);
-                m_storing_process_statu_msg.mutable_measure_step()->set_step_statu(message::eWorking);
+                m_storing_process_statu.mutable_measure_step()->set_step_statu(message::eWorking);
             }
             //开始定位
             code=locate_step();
@@ -393,14 +372,14 @@ void StoreProcessTask::Main()
             if(code!=SUCCESS)
             {
                 //更新进度状态
-                m_storing_process_statu_msg.mutable_measure_step()->set_step_statu(message::eError);
-                m_storing_process_statu_msg.mutable_measure_step()->set_description(code.get_error_description());
+                m_storing_process_statu.mutable_measure_step()->set_step_statu(message::eError);
+                m_storing_process_statu.mutable_measure_step()->set_description(code.get_error_description());
                 LOG(ERROR)<<"测量失败:"<<code.get_error_description();
                 break;
             }
             //更新状态信息
-            m_storing_process_statu_msg.mutable_measure_step()->mutable_locate_info()->CopyFrom(m_measure_response_msg.locate_information());
-            m_storing_process_statu_msg.mutable_measure_step()->set_step_statu(message::eComplete);
+            m_storing_process_statu.mutable_measure_step()->mutable_locate_info()->CopyFrom(m_measure_response_msg.locate_information());
+            m_storing_process_statu.mutable_measure_step()->set_step_statu(message::eComplete);
         }
         //第二步,调度
         case 1:
@@ -408,10 +387,10 @@ void StoreProcessTask::Main()
             //更新状态信息
             {
                 std::lock_guard<std::mutex> lock(m_storing_statu_lock);
-                m_storing_process_statu_msg.mutable_dispatch_step()->set_step_statu(message::eWorking);
-                m_storing_process_statu_msg.mutable_dispatch_step()->mutable_locate_info()->CopyFrom(
+                m_storing_process_statu.mutable_dispatch_step()->set_step_statu(message::eWorking);
+                m_storing_process_statu.mutable_dispatch_step()->mutable_locate_info()->CopyFrom(
                         m_measure_response_msg.locate_information());
-                m_storing_process_statu_msg.mutable_dispatch_step()->mutable_space_info()->CopyFrom(
+                m_storing_process_statu.mutable_dispatch_step()->mutable_space_info()->CopyFrom(
                         m_parcspace_alloc_response_msg.allocated_space_info());
             }
             //开始调度
@@ -421,13 +400,13 @@ void StoreProcessTask::Main()
             std::lock_guard<std::mutex> lock(m_storing_statu_lock);
             if(code!=SUCCESS)
             {
-                m_storing_process_statu_msg.mutable_dispatch_step()->set_step_statu(message::eError);
-                m_storing_process_statu_msg.mutable_dispatch_step()->set_description(code.get_error_description());
+                m_storing_process_statu.mutable_dispatch_step()->set_step_statu(message::eError);
+                m_storing_process_statu.mutable_dispatch_step()->set_description(code.get_error_description());
                 LOG(ERROR)<<"调度失败:"<<code.get_error_description();
                 break;
             }
             //更新状态信息
-            m_storing_process_statu_msg.mutable_dispatch_step()->set_step_statu(message::eComplete);
+            m_storing_process_statu.mutable_dispatch_step()->set_step_statu(message::eComplete);
         }
         //第三步,占据车位
         case 2:
@@ -435,8 +414,8 @@ void StoreProcessTask::Main()
             //更新状态信息
             {
                 std::lock_guard<std::mutex> lock(m_storing_statu_lock);
-                m_storing_process_statu_msg.mutable_confirm_space_step()->set_step_statu(message::eWorking);
-                m_storing_process_statu_msg.mutable_confirm_space_step()->mutable_space_info()->CopyFrom(
+                m_storing_process_statu.mutable_confirm_space_step()->set_step_statu(message::eWorking);
+                m_storing_process_statu.mutable_confirm_space_step()->mutable_space_info()->CopyFrom(
                         m_parcspace_alloc_response_msg.allocated_space_info());
             }
             //开始工作
@@ -444,15 +423,15 @@ void StoreProcessTask::Main()
             std::lock_guard<std::mutex> lock(m_storing_statu_lock);
             if(code!=SUCCESS)
             {
-                m_storing_process_statu_msg.mutable_confirm_space_step()->set_step_statu(message::eError);
-                m_storing_process_statu_msg.mutable_confirm_space_step()->set_description(code.get_error_description());
+                m_storing_process_statu.mutable_confirm_space_step()->set_step_statu(message::eError);
+                m_storing_process_statu.mutable_confirm_space_step()->set_description(code.get_error_description());
                 LOG(ERROR)<<"指令:"<<m_command_info.place()<<",终端号:"<<m_terminor_id<<"停车流程:"<<code.get_error_description()<<
                 " 车位id :"<<m_parcspace_alloc_response_msg.allocated_space_info().parkspace_id()
                 <<",车牌:"<<m_car_info.license();
                 break;
             }
             //更新状态信息
-            m_storing_process_statu_msg.mutable_confirm_space_step()->set_step_statu(message::eComplete);
+            m_storing_process_statu.mutable_confirm_space_step()->set_step_statu(message::eComplete);
         }
         //第四步,打印...  日志 .... 记录.....
         case 3:
@@ -474,59 +453,27 @@ void StoreProcessTask::Main()
     //失败,清理车位
     {
         std::lock_guard<std::mutex> lock(m_storing_statu_lock);
-        m_storing_process_statu_msg.mutable_failed_release_space_step()->set_step_statu(message::eWorking);
+        m_storing_process_statu.mutable_failed_release_space_step()->set_step_statu(message::eWorking);
     }
     code=release_space_step();
 
     std::lock_guard<std::mutex> lock(m_storing_statu_lock);
     if(code!=SUCCESS)
     {
-        m_storing_process_statu_msg.mutable_failed_release_space_step()->set_step_statu(message::eError);
-        m_storing_process_statu_msg.mutable_failed_release_space_step()->set_description(code.get_error_description());
+        m_storing_process_statu.mutable_failed_release_space_step()->set_step_statu(message::eError);
+        m_storing_process_statu.mutable_failed_release_space_step()->set_description(code.get_error_description());
         LOG(ERROR)<<"致命故障,停车失败,清理车位故障:"<<code.get_error_description();
 
     }
     else
     {
-        m_storing_process_statu_msg.mutable_failed_release_space_step()->set_step_statu(message::eComplete);
+        m_storing_process_statu.mutable_failed_release_space_step()->set_step_statu(message::eComplete);
     }
     /*
     *   流程异常,此处应暂停系统,待管理员介入
     */
 }
 
-/*
- * 发布状态线程
- */
-void StoreProcessTask::publish_thread_func(StoreProcessTask* ptask)
-{
-    if(ptask)
-    {
-        ptask->publish_step_status();
-    }
-}
-void StoreProcessTask::publish_step_status()
-{
-    //未收到退出信号
-    while(false==m_publish_exit_condition.wait_for_ex(std::chrono::milliseconds(50)))
-    {
-        /*
-         * 通过communicator 发布状态
-         */
-        if(System_communicator::get_instance_pointer())
-        {
-            if(m_storing_process_statu_msg.has_base_info()==true)
-            {
-                std::lock_guard<std::mutex> lock(m_storing_statu_lock);
-                System_communicator::get_instance_pointer()->post_entrance_statu(m_storing_process_statu_msg);
-            }
-
-        }
-
-    }
-}
-
-
 /*
      * 初始化 接收到的消息
      */

+ 1 - 11
system/StoreProcessTask.h

@@ -62,12 +62,6 @@ protected:
     void reset_recv_msg();
 
 
-    /*
-     * 发布进度
-     */
-    static void publish_thread_func(StoreProcessTask* p_commander);
-    void publish_step_status();
-
 protected:
     message::Command_info       m_command_info;
     unsigned int                m_terminor_id;
@@ -83,11 +77,7 @@ protected:
     message::Dispatch_response_msg                  m_dispatch_response_msg;        //调度模块的反馈数据
 
     std::mutex                                      m_storing_statu_lock;
-    message::Storing_process_statu_msg              m_storing_process_statu_msg;    //停车流程进度信息
-
-private:
-    std::thread*                    m_publish_statu_thread;             //广播状态线程
-    Thread_condition				m_publish_exit_condition;			//发送的条件变量
+    message::Storing_process_statu                  m_storing_process_statu;    //停车流程进度信息
 
 };
 

+ 79 - 22
system/command_manager.cpp

@@ -11,7 +11,8 @@
 #include "system_communicator.h"
 
 Command_manager::Command_manager()
-    :m_thread_queue_process(nullptr)
+    :m_thread_queue_process(nullptr),
+    m_publish_statu_thread(nullptr)
 {
 
 }
@@ -24,6 +25,18 @@ Command_manager::~Command_manager()
         m_thread_queue_process->Stop();
     }
 
+    //退出线程
+    m_publish_exit_condition.set_pass_ever(true);
+    if(m_publish_statu_thread!= nullptr)
+    {
+        if(m_publish_statu_thread->joinable())
+        {
+            m_publish_statu_thread->join();
+        }
+        delete m_publish_statu_thread;
+        m_publish_statu_thread=nullptr;
+    }
+
 }
 
 Error_manager Command_manager::init(setting::System_setting system_setting)
@@ -105,8 +118,6 @@ Error_manager Command_manager::init(setting::System_setting system_setting)
             return Error_manager(ERROR,MAJOR_ERROR,"停车入口通讯节点初始化超时");
         }
 
-        StoreProcessTask* ptask=new StoreProcessTask(i);
-        m_store_command_task_map[i]=ptask;
     }
     for(int i=0;i<system_setting.export_num();++i)
     {
@@ -129,11 +140,19 @@ Error_manager Command_manager::init(setting::System_setting system_setting)
         {
             return Error_manager(ERROR,MAJOR_ERROR,"取车出口通讯节点初始化超时");
         }
-
-        PickupProcessTask* ptask=new PickupProcessTask(i);
-        m_pick_command_task_map[i]=ptask;
     }
 
+    ///创建状态发布线程
+    message::Base_info base_info;
+    base_info.set_sender(message::eMain);
+    base_info.set_receiver(message::eEmpty);
+    base_info.set_msg_type(message::eProcess_statu_map_msg);
+    m_process_statu_msg.mutable_base_info()->CopyFrom(base_info);
+    if(m_publish_statu_thread== nullptr)
+    {
+        m_publish_exit_condition.reset(false, false, false);
+        m_publish_statu_thread=new std::thread(publish_thread_func,this);
+    }
     return SUCCESS;
 }
 
@@ -151,7 +170,7 @@ Error_manager Command_manager::execute_store_command(message::Store_command_requ
        &&request.base_info().receiver()==message::eMain
        &&request.base_info().sender()==message::eTerminor)
     {
-        if(request.has_locate_information())
+        if(request.has_locate_information() &&request.has_base_info())
         {
             message::Locate_information locate_info=request.locate_information();
             if(locate_info.has_locate_correct())
@@ -208,24 +227,18 @@ Error_manager Command_manager::execute_store_command(message::Store_command_requ
                         //获取当前时间
                         auto t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
                         std::stringstream ss;
-                        ss << std::put_time(std::localtime(&t), "%Y-%m-%d:%H-%M-%S-%ms");
+                        ss << std::put_time(std::localtime(&t), "%Y-%m-%d:%H-%M-%S");
                         std::string str_time = ss.str();
                         command_info.set_time(str_time);
 
                         char place[255]={0};
-                        sprintf(place ,"027-01-%02d",request.terminal_id());
+                        sprintf(place ,"027-01-%02d:%s",request.terminal_id(),request.car_info().license().c_str());
                         command_info.set_place(place);
                         command_info.set_event(message::eStoring);
 
                         LOG(INFO)<<"收到停车指令:"<<command_info.place()+"-"+command_info.time()<<", 车牌:"<<request.car_info().license()<<
                         ",终端:"<<request.terminal_id();
-                        tq::BaseTask* ptask;
-                        if(false==m_store_command_task_map.find(request.terminal_id(),ptask))
-                        {
-                            LOG(INFO)<<"创建终端:"<<command_info.place()+"-"+command_info.time();
-                            ptask=new StoreProcessTask(request.terminal_id());
-                            m_store_command_task_map[request.terminal_id()]=ptask;
-                        }
+                        tq::BaseTask* ptask=new StoreProcessTask(request.terminal_id());
                         StoreProcessTask* pStore_task=(StoreProcessTask*)ptask;
                         //初始化流程
                         pStore_task->init_task(command_info,locate_info,request.car_info());
@@ -322,12 +335,7 @@ Error_manager Command_manager::execute_pickup_command(message::Pickup_command_re
         command_info.set_place(place);
         command_info.set_event(message::ePicking);
 
-        tq::BaseTask* ptask;
-        if(false==m_pick_command_task_map.find(request.terminal_id(),ptask))
-        {
-            ptask=new PickupProcessTask(request.terminal_id());
-            m_pick_command_task_map[request.terminal_id()]=ptask;
-        }
+        tq::BaseTask* ptask=new PickupProcessTask(request.terminal_id());
         PickupProcessTask* pPick_task=(PickupProcessTask*)ptask;
         //初始化流程
         pPick_task->init_task(command_info, request.car_info());
@@ -352,3 +360,52 @@ Error_manager Command_manager::execute_pickup_command(message::Pickup_command_re
         return Error_manager(INVALID_MESSAGE,MAJOR_ERROR,"停车请求信息错误");
     }
 }
+
+void Command_manager::erase_statu(message::Storing_process_statu statu)
+{
+    std::lock_guard<std::mutex> lock(m_process_statu_lock);
+    m_process_statu_msg.mutable_storing_process_msg_map()->erase(statu.license());
+}
+void Command_manager::erase_statu(message::Picking_process_statu statu)
+{
+    std::lock_guard<std::mutex> lock(m_process_statu_lock);
+    m_process_statu_msg.mutable_picking_process_msg_map()->erase(statu.license());
+}
+
+void Command_manager::updata_statu(message::Storing_process_statu statu)
+{
+    std::lock_guard<std::mutex> lock(m_process_statu_lock);
+    (*m_process_statu_msg.mutable_storing_process_msg_map())[statu.license()]=statu;
+}
+void Command_manager::updata_statu(message::Picking_process_statu statu)
+{
+    std::lock_guard<std::mutex> lock(m_process_statu_lock);
+    (*m_process_statu_msg.mutable_picking_process_msg_map())[statu.license()]=statu;
+}
+
+void Command_manager::publish_step_status() {
+    //未收到退出信号
+    while(false==m_publish_exit_condition.wait_for_ex(std::chrono::milliseconds(100)))
+    {
+        /*
+         * 通过communicator 发布状态
+         */
+
+        if(System_communicator::get_instance_pointer())
+        {
+            std::lock_guard<std::mutex> lock(m_process_statu_lock);
+            if(m_process_statu_msg.has_base_info()==true)
+            {
+                System_communicator::get_instance_pointer()->post_entrance_statu(m_process_statu_msg);
+            }
+
+        }
+
+    }
+}
+
+void Command_manager::publish_thread_func(Command_manager* command_manager)
+{
+    if(command_manager)
+        command_manager->publish_step_status();
+}

+ 14 - 6
system/command_manager.h

@@ -39,18 +39,26 @@ public:
      */
     Error_manager execute_pickup_command(message::Pickup_command_request_msg& request,message::Pickup_command_response_msg& response);
 
+    /*
+     * 更新进度状态
+     */
+    void erase_statu(message::Storing_process_statu statu);
+    void erase_statu(message::Picking_process_statu statu);
+    void updata_statu(message::Storing_process_statu statu);
+    void updata_statu(message::Picking_process_statu statu);
 private:
     Command_manager();
+    void publish_step_status();
+    static void publish_thread_func(Command_manager* command_manager);
 
 protected:
 
-    /*
-     * 停取车终端 map,key值为终端编号,value为终端指令执行器task,可放入线程池执行流程
-     */
-    thread_safe_map<int,tq::BaseTask*>                              m_store_command_task_map;
-    thread_safe_map<int,tq::BaseTask*>                              m_pick_command_task_map;
-
     tq::IQueue*                     m_thread_queue_process;         //指令流程线程池
+
+    std::mutex                          m_process_statu_lock;
+    message::Process_statu_map_msg      m_process_statu_msg;
+    std::thread*                    m_publish_statu_thread;             //广播状态线程
+    Thread_condition				m_publish_exit_condition;			//发送的条件变量
 };
 
 

+ 2 - 9
system/system_communicator.cpp

@@ -21,15 +21,8 @@ Error_manager System_communicator::encapsulate_send_data()
 	return Error_code::SUCCESS;
 }
 
-//发送停车流程进度
-Error_manager System_communicator::post_entrance_statu(message::Storing_process_statu_msg& msg)
-{
-    Communication_message message;
-    message.reset(msg.base_info(),msg.SerializeAsString());
-    return encapsulate_msg(&message);
-}
-//发送取车流程进度
-Error_manager System_communicator::post_entrance_statu(message::Picking_process_statu_msg& msg)
+//发送流程进度
+Error_manager System_communicator::post_entrance_statu(message::Process_statu_map_msg& msg)
 {
     Communication_message message;
     message.reset(msg.base_info(),msg.SerializeAsString());

+ 1 - 2
system/system_communicator.h

@@ -25,8 +25,7 @@ public:
     System_communicator(const System_communicator& other) = delete;
     System_communicator& operator =(const System_communicator& other) = delete;
 
-    Error_manager post_entrance_statu(message::Storing_process_statu_msg& msg);
-    Error_manager post_entrance_statu(message::Picking_process_statu_msg& msg);
+    Error_manager post_entrance_statu(message::Process_statu_map_msg& msg);
     ~System_communicator();
 
 protected:

+ 14 - 0
system/uniq_key.cpp

@@ -0,0 +1,14 @@
+//
+// Created by zx on 2020/8/10.
+//
+#include "uniq_key.h"
+#include <boost/uuid/uuid.hpp>
+#include <boost/uuid/uuid_generators.hpp>
+#include <boost/uuid/uuid_io.hpp>
+
+std::string create_key()
+{
+    boost::uuids::uuid uid = boost::uuids::random_generator()();
+    const std::string uid_str = boost::uuids::to_string(uid);
+    return uid_str;
+}

+ 12 - 0
system/uniq_key.h

@@ -0,0 +1,12 @@
+//
+// Created by zx on 2020/8/10.
+//
+
+#ifndef NNXX_TESTS_UNIQ_KEY_H
+#define NNXX_TESTS_UNIQ_KEY_H
+
+#include <string>
+
+std::string create_key();
+
+#endif //NNXX_TESTS_UNIQ_KEY_H

+ 16 - 24
test/Terminal_communication.cpp

@@ -83,35 +83,21 @@ Error_manager Terminal_communication::execute_msg(Communication_message* p_msg)
         }
     }
 
-    if(p_msg->get_message_type()==Communication_message::eStoring_process_statu_msg)
+    if(p_msg->get_message_type()==Communication_message::eProcess_statu_map_msg)
     {
-        message::Storing_process_statu_msg msg;
+        message::Process_statu_map_msg msg;
         if(msg.ParseFromString(p_msg->get_message_buf())==false)
         {
-            std::cout<<" ERROR : Storing_process_statu_msg 失败"<<std::endl;
+            std::cout<<" ERROR : process_statu_msg 失败"<<std::endl;
         }
         message::Base_info base_info=msg.base_info();
         if(base_info.sender()==message::eMain)
         {
-            m_storing_statu_map[msg.terminal_id()]=msg;
+            m_process_statu_map=msg;
 
         }
     }
 
-    if(p_msg->get_message_type()==Communication_message::ePicking_process_statu_msg)
-    {
-        message::Picking_process_statu_msg msg;
-        if(msg.ParseFromString(p_msg->get_message_buf())==false)
-        {
-            std::cout<<" ERROR : Picking_process_statu_msg 失败"<<std::endl;
-        }
-        message::Base_info base_info=msg.base_info();
-        if(base_info.sender()==message::eMain)
-        {
-            m_picking_statu_map[msg.terminal_id()]=msg;
-        }
-    }
-
     return SUCCESS;
 
     return Error_manager(FAILED,MINOR_ERROR,"terminal communication 未知消息");
@@ -163,7 +149,7 @@ Error_manager Terminal_communication::store_request(message::Store_command_reque
     Error_manager code;
     Communication_message message;
     message.reset(request.base_info(),request.SerializeAsString());
-    int timeout=1000;
+    int timeout=1000*5;
 
     code=encapsulate_msg(&message);
     if(code!=SUCCESS)
@@ -196,7 +182,7 @@ Error_manager Terminal_communication::store_request(message::Store_command_reque
         }
 
         auto end_time = std::chrono::system_clock::now();
-        auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time);
+        auto duration = std::chrono::duration_cast<std::chrono::seconds>(end_time - start_time);
         time = 1000.0 * double(duration.count()) * std::chrono::microseconds::period::num /
                std::chrono::microseconds::period::den;
         std::this_thread::yield();
@@ -272,20 +258,26 @@ Error_manager Terminal_communication::pickup_request(message::Pickup_command_req
 /*
      * 获取停车流程状态
      */
-Error_manager Terminal_communication::get_storing_statu(int terminal_id,message::Storing_process_statu_msg& msg)
+Error_manager Terminal_communication::get_storing_statu(std::string license,message::Storing_process_statu& msg)
 {
-    if(m_storing_statu_map.find(terminal_id,msg)) {
+    if(m_process_statu_map.storing_process_msg_map().find(license)!=m_process_statu_map.storing_process_msg_map().end())
+    {
+        msg=m_process_statu_map.storing_process_msg_map().at(license);
         return SUCCESS;
     }
+
     return FAILED;
 }
 
 /*
  * 获取取车流程状态
  */
-Error_manager Terminal_communication::get_picking_statu(int terminal_id,message::Picking_process_statu_msg& msg)
+Error_manager Terminal_communication::get_picking_statu(std::string license,message::Picking_process_statu& msg)
 {
-    if(m_picking_statu_map.find(terminal_id,msg))
+    if(m_process_statu_map.picking_process_msg_map().find(license)!=m_process_statu_map.picking_process_msg_map().end())
+    {
+        msg=m_process_statu_map.picking_process_msg_map().at(license);
         return SUCCESS;
+    }
     return FAILED;
 }

+ 3 - 6
test/Terminal_communication.h

@@ -42,12 +42,12 @@ public:
     /*
      * 获取停车流程状态
      */
-    Error_manager get_storing_statu(int terminal_id,message::Storing_process_statu_msg& msg);
+    Error_manager get_storing_statu(std::string license,message::Storing_process_statu& msg);
 
     /*
      * 获取取车流程状态
      */
-    Error_manager get_picking_statu(int terminal_id,message::Picking_process_statu_msg& msg);
+    Error_manager get_picking_statu(std::string license,message::Picking_process_statu& msg);
 
 protected:
     //重载函数
@@ -69,10 +69,7 @@ private:
     message::Pickup_command_response_msg            m_pickup_response_msg;
     int                                             m_terminal_id;
 
-    thread_safe_map<int ,message::Storing_process_statu_msg>        m_storing_statu_map;
-    thread_safe_map<int ,message::Picking_process_statu_msg>        m_picking_statu_map;
-
-
+    message::Process_statu_map_msg                  m_process_statu_map;
 
 };
 

+ 2 - 2
test/pickup_terminal.cpp

@@ -57,8 +57,8 @@ Error_manager pickup_terminal::pickup(message::Car_info& car_info)
 
     while(m_exit_cond.wait_for_millisecond(200)==false)
     {
-        message::Picking_process_statu_msg msg;
-        code = Terminal_communication::get_instance_pointer()->get_picking_statu(m_terminal_id, msg);
+        message::Picking_process_statu msg;
+        code = Terminal_communication::get_instance_pointer()->get_picking_statu(car_info.license(), msg);
         if (code != SUCCESS) {
             continue;
         }

+ 3 - 2
test/store_terminal.cpp

@@ -34,6 +34,7 @@ Error_manager store_terminal::init(threadsafe_queue<message::Car_info>* input,
 
 Error_manager store_terminal::storing(message::Car_info& car_info)
 {
+    usleep(1000*1000);
     message::Store_command_request_msg request;
     message::Base_info base_info;
     base_info.set_msg_type(message::eStore_command_request_msg);
@@ -65,8 +66,8 @@ Error_manager store_terminal::storing(message::Car_info& car_info)
     //等待停车完成
 
     while(m_exit_cond.wait_for_millisecond(50)==false) {
-        message::Storing_process_statu_msg msg;
-        code = Terminal_communication::get_instance_pointer()->get_storing_statu(m_terminal_id, msg);
+        message::Storing_process_statu msg;
+        code = Terminal_communication::get_instance_pointer()->get_storing_statu(car_info.license(), msg);
         if (code != SUCCESS) {
             continue;
         }

+ 7 - 8
test/terminal_client.cpp

@@ -81,13 +81,13 @@ void init_glog()
 
 int main() {
     init_glog();
-    Terminal_communication::get_instance_pointer()->communication_connect("tcp://192.168.2.183:30001");
+    Terminal_communication::get_instance_pointer()->communication_connect("tcp://192.168.2.183:30000");
     Terminal_communication::get_instance_pointer()->communication_run();
     usleep(2000*1000);
     threadsafe_queue<message::Car_info> input_queue;
     threadsafe_queue<message::Car_info> output_queue;
 
-    const int n_input=3;
+    const int n_input=6;
     const int n_output=1;
     std::vector<store_terminal*> input_terminals;
     std::vector<pickup_terminal*> output_terminals;
@@ -148,7 +148,7 @@ int main() {
 
 
 
-        int license_id = rand() % 90000 + 10000;
+        int license_id = rand() % 90000 + 20000;
         char C=rand()%10+'A';
         char license[255] = {0};
         sprintf(license, "鄂%c%d",C, license_id);
@@ -164,13 +164,12 @@ int main() {
         int in_count=input_queue.size();
         int out_count=output_queue.size();
 
-        if(n%1==0) {
-            usleep(1000*1000*1);
+        if(n%6==0) {
+            std::cin>>c;
         }
         else {
-            //暂停 5-15s 代替
-            int delay=10*1000;//in_count*200;
-            usleep(1000*delay+1);
+
+            usleep(1000+1);
             std::this_thread::yield();
         }
     }