Jelajahi Sumber

流程状态取消map,每个流程单独发送

zx 4 tahun lalu
induk
melakukan
2b8f4084f2

+ 2 - 2
communication/communication_message.h

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

+ 16 - 14
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*\231\006\n\014Message_type\022\r"
+      "\t\022\022\n\nleave_time\030\013 \001(\t*\276\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,21 +402,22 @@ 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\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"
+      "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"
   };
   ::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
-      descriptor, 2218);
+      descriptor, 2255);
   ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
     "message_base.proto", &protobuf_RegisterTypes);
 }
@@ -463,6 +464,7 @@ bool Message_type_IsValid(int value) {
     case 67:
     case 68:
     case 144:
+    case 145:
       return true;
     default:
       return false;

+ 3 - 2
message/message_base.pb.h

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

+ 3 - 1
message/message_base.proto

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

File diff ditekan karena terlalu besar
+ 482 - 1065
message/process_message.pb.cc


File diff ditekan karena terlalu besar
+ 417 - 599
message/process_message.pb.h


+ 16 - 22
message/process_message.proto

@@ -76,32 +76,26 @@ message Waitfor_leave_step_statu
 }
 
 //停车流程进度消息
-message Storing_process_statu
+message Storing_process_statu_msg
 {
-    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;
-    required Confirm_space_step_statu   confirm_space_step=6;
-    optional Release_space_step_statu   failed_release_space_step=7;
+    required Base_info                  base_info=1;
+    required int32                      terminal_id=2;              //终端id
+    required string                     license=3;
+    required Alloc_space_step_statu     alloc_space_step=4;
+    required Measure_step_statu         measure_step=5;
+    required Dispatch_store_step_statu  dispatch_step=6;
+    required Confirm_space_step_statu   confirm_space_step=7;
+    optional Release_space_step_statu   failed_release_space_step=8;
 }
 
 //取车流程进度消息
-message Picking_process_statu
-{
-    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
+message Picking_process_statu_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;
+    required int32                      terminal_id=2;              //终端id
+    required string                     license=3;
+    required Check_space_step_statu     check_space_step=4;
+    required Dispatch_pick_step_statu   dispatch_step=5;
+    required Release_space_step_statu   release_space_step=6;
+    required Waitfor_leave_step_statu   waitfor_leave=7;
 }
-

+ 0 - 1
parkspace/Parkspace_communicator.cpp

@@ -397,7 +397,6 @@ Error_manager Parkspace_communicator::encapsulate_msg(Communication_message* mes
             message::Parkspace_confirm_alloc_request_msg request;
             request.ParseFromString(message->get_message_buf());
             //记录数据
-            LOG(INFO)<<" Add  request :  "<<request.command_info().DebugString();
             m_confirm_table[request.command_info().time()]=message::Parkspace_confirm_alloc_response_msg();
             //发送请求
             code= Communication_socket_base::encapsulate_msg(message);

+ 89 - 49
system/PickupProcessTask.cpp

@@ -14,26 +14,50 @@ PickupProcessTask::PickupProcessTask(unsigned int terminal_id)
 {
     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(is_ready()) {
-        reset_process_statu();
-    }
-    else
+    ///创建状态发布线程
+    if(m_publish_statu_thread== nullptr)
     {
-        return Error_manager(ERROR,MINOR_ERROR,"终端未准备!!!");
+        m_publish_exit_condition.reset(false, false, false);
+        m_publish_statu_thread=new std::thread(publish_thread_func,this);
     }
 
+   return SUCCESS;
+
 }
 
 /*
@@ -54,30 +78,16 @@ 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.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());
+    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_msg.set_license(m_car_info.license());
 
 
 
 }
 
-/*
-     * 检查当前任务是否处于空闲准备状态
-     */
-bool PickupProcessTask::is_ready()
-{
-    std::lock_guard<std::mutex> lock(m_picking_statu_lock);
-    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;
-}
 
 /*
  * 查询车位
@@ -87,7 +97,7 @@ Error_manager PickupProcessTask::search_space()
     //更新状态
     {
         std::lock_guard<std::mutex> lock(m_picking_statu_lock);
-        m_picking_process_statu.mutable_check_space_step()->set_step_statu(message::eWorking);
+        m_picking_process_statu_msg.mutable_check_space_step()->set_step_statu(message::eWorking);
     }
 
     /*
@@ -97,8 +107,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.mutable_check_space_step()->set_step_statu(message::eError);
-        m_picking_process_statu.mutable_check_space_step()->set_description("查询车位请求汽车信息错误");
+        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("查询车位请求汽车信息错误");
         return Error_manager(INVALID_MESSAGE,CRITICAL_ERROR,"查询车位请求汽车信息错误");
     }
 
@@ -109,8 +119,8 @@ Error_manager PickupProcessTask::search_space()
     std::lock_guard<std::mutex> lock(m_picking_statu_lock);
     if(code!=SUCCESS)
     {
-        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);
+        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);
         return code;
     }
 
@@ -130,12 +140,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.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);
+        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);
     }
     else {
-        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());
+        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());
     }
     return code;
 }
@@ -152,8 +162,8 @@ void PickupProcessTask::Main()
             //更新状态
             {
                 std::lock_guard<std::mutex> lock(m_picking_statu_lock);
-                m_picking_process_statu.mutable_dispatch_step()->set_step_statu(message::eWorking);
-                m_picking_process_statu.mutable_dispatch_step()->mutable_space_info()->CopyFrom(
+                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_parcspace_search_response_msg.car_position());
             }
             //开始工作
@@ -167,11 +177,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.mutable_dispatch_step()->set_step_statu(message::eError);
-                m_picking_process_statu.mutable_dispatch_step()->set_description(code.get_error_description());
+                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());
                 break;
             }
-            m_picking_process_statu.mutable_dispatch_step()->set_step_statu(message::eComplete);
+            m_picking_process_statu_msg.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()
@@ -185,20 +195,20 @@ void PickupProcessTask::Main()
             //更新状态
             {
                 std::lock_guard<std::mutex> lock(m_picking_statu_lock);
-                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_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_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.mutable_release_space_step()->set_step_statu(message::eError);
-                m_picking_process_statu.mutable_release_space_step()->set_description(code.get_error_description());
+                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());
                 LOG(ERROR)<<"取车释放车位失败:"<<code.get_error_description();
                 break;
             }
-            m_picking_process_statu.mutable_release_space_step()->set_step_statu(message::eComplete);
+            m_picking_process_statu_msg.mutable_release_space_step()->set_step_statu(message::eComplete);
         }
         //第三步,等待车辆离开
         case 2:
@@ -206,19 +216,19 @@ void PickupProcessTask::Main()
             //更新状态
             {
                 std::lock_guard<std::mutex> lock(m_picking_statu_lock);
-                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);
+                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);
             }
             //等待离开
             code=wait_for_leave_step();
             std::lock_guard<std::mutex> lock(m_picking_statu_lock);
             if(code!=SUCCESS)
             {
-                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());
+                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());
                 break;
             }
-            m_picking_process_statu.mutable_waitfor_leave()->set_step_statu(message::eComplete);
+            m_picking_process_statu_msg.mutable_waitfor_leave()->set_step_statu(message::eComplete);
         }
     }
 
@@ -325,3 +335,33 @@ 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);
+            }
+
+        }
+
+    }
+}

+ 8 - 1
system/PickupProcessTask.h

@@ -48,12 +48,19 @@ 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;
@@ -62,7 +69,7 @@ private:
 
     //取车车位的进度状态
     std::mutex                                              m_picking_statu_lock;
-    message::Picking_process_statu                    m_picking_process_statu;
+    message::Picking_process_statu_msg                      m_picking_process_statu_msg;
 
 };
 

+ 97 - 63
system/StoreProcessTask.cpp

@@ -12,15 +12,32 @@
 #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()
 {
-    Command_manager::get_instance_pointer()->erase_statu(m_storing_process_statu);
+    //退出线程
+    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,
@@ -32,6 +49,12 @@ 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);
+    }
 
     reset_process_statu();
     return SUCCESS;
@@ -139,17 +162,15 @@ 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.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());
-    m_storing_process_statu.set_terminal_id(m_terminor_id);
+    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_msg.set_license(m_car_info.license());
+    m_storing_process_statu_msg.set_terminal_id(m_terminor_id);
 
 
-    Command_manager::get_instance_pointer()->updata_statu(m_storing_process_statu);
-
 }
 
 /*
@@ -160,9 +181,8 @@ Error_manager StoreProcessTask::alloc_space()
     //更新车位分配步骤状态
     {
         std::lock_guard<std::mutex> lock(m_storing_statu_lock);
-        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);
-        Command_manager::get_instance_pointer()->updata_statu(m_storing_process_statu);
+        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);
     }
 
     /*
@@ -171,9 +191,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.mutable_alloc_space_step()->set_step_statu(message::eError);
-        m_storing_process_statu.mutable_alloc_space_step()->set_description("停车请求缺少车辆高度和宽度信息");
-        Command_manager::get_instance_pointer()->updata_statu(m_storing_process_statu);
+        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("停车请求缺少车辆高度和宽度信息");
         return Error_manager(FAILED,MINOR_ERROR,"停车请求缺少车辆高度和宽度信息");
     }
     /*
@@ -183,9 +202,8 @@ Error_manager StoreProcessTask::alloc_space()
     if(code!=SUCCESS)
     {
         std::lock_guard<std::mutex> lock(m_storing_statu_lock);
-        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());
-        Command_manager::get_instance_pointer()->updata_statu(m_storing_process_statu);
+        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());
         return code;
     }
 
@@ -195,7 +213,7 @@ Error_manager StoreProcessTask::alloc_space()
     base_info.set_msg_type(message::eParkspace_allocation_request_msg);
     base_info.set_sender(message::eMain);
     base_info.set_receiver(message::eParkspace);
-    base_info.set_timeout_ms(1000); //测量超时1s
+    base_info.set_timeout_ms(1000); //超时1s
     request.mutable_base_info()->CopyFrom(base_info);
 
     request.mutable_car_info()->CopyFrom(m_car_info);
@@ -209,9 +227,8 @@ Error_manager StoreProcessTask::alloc_space()
     std::lock_guard<std::mutex> lock(m_storing_statu_lock);
     if(code!=SUCCESS)
     {
-        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());
-        Command_manager::get_instance_pointer()->updata_statu(m_storing_process_statu);
+        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());
         return code;
     }
 
@@ -220,21 +237,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.mutable_alloc_space_step()->set_step_statu(message::eError);
-            m_storing_process_statu.mutable_alloc_space_step()->set_description("分配车位反馈的车辆信息不匹配");
-            Command_manager::get_instance_pointer()->updata_statu(m_storing_process_statu);
+            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("分配车位反馈的车辆信息不匹配");
             return Error_manager(ERROR,MINOR_ERROR,"分配车位反馈的车辆信息不匹配");
         }
 
-        m_storing_process_statu.mutable_alloc_space_step()->set_step_statu(message::eComplete);
-        Command_manager::get_instance_pointer()->updata_statu(m_storing_process_statu);
+        m_storing_process_statu_msg.mutable_alloc_space_step()->set_step_statu(message::eComplete);
         return SUCCESS;
     }
     else
     {
-        m_storing_process_statu.mutable_alloc_space_step()->set_step_statu(message::eError);
-        m_storing_process_statu.mutable_alloc_space_step()->set_description("分配车位反馈结果错误");
-        Command_manager::get_instance_pointer()->updata_statu(m_storing_process_statu);
+        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("分配车位反馈结果错误");
         return Error_manager(FAILED,MINOR_ERROR,"分配车位反馈结果错误");
     }
 }
@@ -355,8 +369,7 @@ void StoreProcessTask::Main()
             //更新状态信息
             {
                 std::lock_guard<std::mutex> lock(m_storing_statu_lock);
-                m_storing_process_statu.mutable_measure_step()->set_step_statu(message::eWorking);
-                Command_manager::get_instance_pointer()->updata_statu(m_storing_process_statu);
+                m_storing_process_statu_msg.mutable_measure_step()->set_step_statu(message::eWorking);
             }
             //开始定位
             code=locate_step();
@@ -366,16 +379,14 @@ void StoreProcessTask::Main()
             if(code!=SUCCESS)
             {
                 //更新进度状态
-                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());
-                Command_manager::get_instance_pointer()->updata_statu(m_storing_process_statu);
+                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());
                 LOG(ERROR)<<"测量失败:"<<code.get_error_description();
                 break;
             }
             //更新状态信息
-            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);
-            Command_manager::get_instance_pointer()->updata_statu(m_storing_process_statu);
+            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);
         }
         //第二步,调度
         case 1:
@@ -383,12 +394,11 @@ void StoreProcessTask::Main()
             //更新状态信息
             {
                 std::lock_guard<std::mutex> lock(m_storing_statu_lock);
-                m_storing_process_statu.mutable_dispatch_step()->set_step_statu(message::eWorking);
-                m_storing_process_statu.mutable_dispatch_step()->mutable_locate_info()->CopyFrom(
+                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_measure_response_msg.locate_information());
-                m_storing_process_statu.mutable_dispatch_step()->mutable_space_info()->CopyFrom(
+                m_storing_process_statu_msg.mutable_dispatch_step()->mutable_space_info()->CopyFrom(
                         m_parcspace_alloc_response_msg.allocated_space_info());
-                Command_manager::get_instance_pointer()->updata_statu(m_storing_process_statu);
             }
             //开始调度
             code=dispatch_step();
@@ -397,15 +407,13 @@ void StoreProcessTask::Main()
             std::lock_guard<std::mutex> lock(m_storing_statu_lock);
             if(code!=SUCCESS)
             {
-                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());
-                Command_manager::get_instance_pointer()->updata_statu(m_storing_process_statu);
+                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());
                 LOG(ERROR)<<"调度失败:"<<code.get_error_description();
                 break;
             }
             //更新状态信息
-            m_storing_process_statu.mutable_dispatch_step()->set_step_statu(message::eComplete);
-            Command_manager::get_instance_pointer()->updata_statu(m_storing_process_statu);
+            m_storing_process_statu_msg.mutable_dispatch_step()->set_step_statu(message::eComplete);
         }
         //第三步,占据车位
         case 2:
@@ -413,27 +421,24 @@ void StoreProcessTask::Main()
             //更新状态信息
             {
                 std::lock_guard<std::mutex> lock(m_storing_statu_lock);
-                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_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_parcspace_alloc_response_msg.allocated_space_info());
-                Command_manager::get_instance_pointer()->updata_statu(m_storing_process_statu);
             }
             //开始工作
             code=confirm_space_step();
             std::lock_guard<std::mutex> lock(m_storing_statu_lock);
             if(code!=SUCCESS)
             {
-                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());
-                Command_manager::get_instance_pointer()->updata_statu(m_storing_process_statu);
+                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());
                 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.mutable_confirm_space_step()->set_step_statu(message::eComplete);
-            Command_manager::get_instance_pointer()->updata_statu(m_storing_process_statu);
+            m_storing_process_statu_msg.mutable_confirm_space_step()->set_step_statu(message::eComplete);
         }
         //第四步,打印...  日志 .... 记录.....
         case 3:
@@ -457,24 +462,21 @@ void StoreProcessTask::Main()
     //失败,清理车位
     {
         std::lock_guard<std::mutex> lock(m_storing_statu_lock);
-        m_storing_process_statu.mutable_failed_release_space_step()->set_step_statu(message::eWorking);
-        Command_manager::get_instance_pointer()->updata_statu(m_storing_process_statu);
+        m_storing_process_statu_msg.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.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());
-        Command_manager::get_instance_pointer()->updata_statu(m_storing_process_statu);
+        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());
         LOG(ERROR)<<"致命故障,停车失败,清理车位故障:"<<code.get_error_description();
 
     }
     else
     {
-        m_storing_process_statu.mutable_failed_release_space_step()->set_step_statu(message::eComplete);
-        Command_manager::get_instance_pointer()->updata_statu(m_storing_process_statu);
+        m_storing_process_statu_msg.mutable_failed_release_space_step()->set_step_statu(message::eComplete);
     }
     usleep(1000*1000*10);
     /*
@@ -482,6 +484,38 @@ void StoreProcessTask::Main()
     */
 }
 
+/*
+ * 发布状态线程
+ */
+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);
+            }
+
+        }
+
+    }
+}
+
+
 /*
      * 初始化 接收到的消息
      */

+ 11 - 1
system/StoreProcessTask.h

@@ -57,6 +57,12 @@ 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;
@@ -72,7 +78,11 @@ protected:
     message::Dispatch_response_msg                  m_dispatch_response_msg;        //调度模块的反馈数据
 
     std::mutex                                      m_storing_statu_lock;
-    message::Storing_process_statu                  m_storing_process_statu;    //停车流程进度信息
+    message::Storing_process_statu_msg              m_storing_process_statu_msg;    //停车流程进度信息
+
+private:
+    std::thread*                    m_publish_statu_thread;             //广播状态线程
+    Thread_condition				m_publish_exit_condition;			//发送的条件变量
 
 };
 

+ 47 - 125
system/command_manager.cpp

@@ -11,8 +11,7 @@
 #include "system_communicator.h"
 
 Command_manager::Command_manager()
-    :m_thread_queue_process(nullptr),
-    m_publish_statu_thread(nullptr)
+    :m_thread_queue_process(nullptr)
 {
 
 }
@@ -25,39 +24,23 @@ 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)
-{
+Error_manager Command_manager::init(setting::System_setting system_setting) {
     /*
      * 检查参数
      */
-    if(system_setting.has_bind_ip()==false || system_setting.has_entrance_num()== false
-        ||system_setting.has_export_num()==false )
-    {
-        return Error_manager(ERROR,MAJOR_ERROR,"系统配置错误");
+    if (system_setting.has_bind_ip() == false || system_setting.has_entrance_num() == false
+        || system_setting.has_export_num() == false) {
+        return Error_manager(ERROR, MAJOR_ERROR, "系统配置错误");
     }
-    if(system_setting.entrance_num()<0 || system_setting.export_num()<0)
-    {
-        return Error_manager(ERROR,MAJOR_ERROR,"系统配置出入口数量错误");
+    if (system_setting.entrance_num() < 0 || system_setting.export_num() < 0) {
+        return Error_manager(ERROR, MAJOR_ERROR, "系统配置出入口数量错误");
     }
 
     //创建线程池
-    if(m_thread_queue_process== nullptr)
-    {
-        m_thread_queue_process=tq::TQFactory::CreateDefaultQueue();
+    if (m_thread_queue_process == nullptr) {
+        m_thread_queue_process = tq::TQFactory::CreateDefaultQueue();
         m_thread_queue_process->Start(12);
     }
 
@@ -65,7 +48,7 @@ Error_manager Command_manager::init(setting::System_setting system_setting)
     /*
      * 此处添加等待各个通讯模块正常代码
      */
-    std::chrono::system_clock::time_point t_start=std::chrono::system_clock::now();
+    /*std::chrono::system_clock::time_point t_start=std::chrono::system_clock::now();
     std::chrono::system_clock::time_point t_end=std::chrono::system_clock::now();
 
     Error_manager parkspace_code=ERROR;
@@ -91,9 +74,9 @@ Error_manager Command_manager::init(setting::System_setting system_setting)
     //检查节点并创建停取车流程
     for(int i=0;i<system_setting.entrance_num();++i)
     {
-        /*
-         * 检查入口 i 的各个节点状态
-         */
+//
+//        检查入口 i 的各个节点状态
+//
         LOG(INFO)<<"初始化停车入口:"<<i<<"  测量及调度模块...";
         Error_manager locate_code=ERROR,dispatch_code=ERROR;
         do {
@@ -142,44 +125,33 @@ Error_manager Command_manager::init(setting::System_setting system_setting)
         }
     }
 
-    ///创建状态发布线程
-    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;
 }
 
 /*
  * 执行停车请求
  */
+}
+
 Error_manager Command_manager::execute_store_command(message::Store_command_request_msg& request,message::Store_command_response_msg& response)
 {
-
-    if(m_thread_queue_process==nullptr)
-    {
-        return Error_manager(ERROR,CRITICAL_ERROR,"线程池未初始化,bug");
+    if (m_thread_queue_process == nullptr) {
+        return Error_manager(ERROR, CRITICAL_ERROR, "线程池未初始化,bug");
     }
-    if(request.base_info().msg_type()==message::eStore_command_request_msg
-       &&request.base_info().receiver()==message::eMain
-       &&request.base_info().sender()==message::eTerminor)
+    if (request.base_info().msg_type() == message::eStore_command_request_msg
+        && request.base_info().receiver() == message::eMain
+        && request.base_info().sender() == message::eTerminor)
     {
-        if(request.has_locate_information() &&request.has_base_info())
+        if (request.has_locate_information() && request.has_base_info())
         {
-            message::Locate_information locate_info=request.locate_information();
-            if(locate_info.has_locate_correct())
+            message::Locate_information locate_info = request.locate_information();
+            if (locate_info.has_locate_correct())
             {
-                if(locate_info.locate_correct()==true)
+                if (locate_info.locate_correct() == true)
                 {
-                    if(locate_info.has_locate_width()&&locate_info.has_locate_height()
-                       &&locate_info.has_locate_x()&&locate_info.has_locate_y()
-                       &&locate_info.has_locate_angle()&&locate_info.has_locate_wheel_base())
+                    if (locate_info.has_locate_width() && locate_info.has_locate_height()
+                        && locate_info.has_locate_x() && locate_info.has_locate_y()
+                        && locate_info.has_locate_angle() && locate_info.has_locate_wheel_base())
                     {
                         /*
                          * 检查消息完毕,开始处理
@@ -197,7 +169,7 @@ Error_manager Command_manager::execute_store_command(message::Store_command_requ
                         /*
                         * 检查各个节点是否正常
                         */
-                        Error_manager parkspace_code= Parkspace_communicator::get_instance_pointer()->check_statu();
+                        /*Error_manager parkspace_code= Parkspace_communicator::get_instance_pointer()->check_statu();
                         if(parkspace_code!=SUCCESS)
                         {
                             error_msg.set_error_code(parkspace_code.get_error_code());
@@ -220,7 +192,7 @@ Error_manager Command_manager::execute_store_command(message::Store_command_requ
                             error_msg.set_error_description(dispatch_code.get_error_description());
                             response.mutable_code()->CopyFrom(error_msg);
                             return dispatch_code;
-                        }
+                        }*/
 
                         //一切正常,接受指令
                         message::Command_info command_info;
@@ -231,34 +203,34 @@ Error_manager Command_manager::execute_store_command(message::Store_command_requ
                         std::string str_time = ss.str();
                         command_info.set_time(str_time);
 
-                        char place[255]={0};
-                        sprintf(place ,"027-01-%02d:%s",request.terminal_id(),request.car_info().license().c_str());
+                        char place[255] = {0};
+                        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=new StoreProcessTask(request.terminal_id());
-                        StoreProcessTask* pStore_task=(StoreProcessTask*)ptask;
+                        LOG(INFO) << "收到停车指令:" << command_info.place() + "-" + command_info.time() << ", 车牌:"
+                                  << request.car_info().license() <<
+                                  ",终端:" << request.terminal_id();
+                        tq::BaseTask *ptask = new StoreProcessTask(request.terminal_id());
+                        StoreProcessTask *pStore_task = (StoreProcessTask *) ptask;
                         //初始化流程
-                        pStore_task->init_task(command_info,locate_info,request.car_info());
+                        pStore_task->init_task(command_info, locate_info, request.car_info());
 
                         //获取车位
-                        Error_manager code=pStore_task->alloc_space();
-                        if(code==SUCCESS)
-                        {
+                        Error_manager code = pStore_task->alloc_space();
+                        if (code == SUCCESS) {
                             m_thread_queue_process->AddTask(pStore_task);
                             response.mutable_code()->CopyFrom(error_msg);
                             return SUCCESS;
 
                         }
-                        usleep(1000*5000);
-                        delete pStore_task;
+                        usleep(1000 * 5000);
+                        //delete pStore_task;
                         error_msg.set_error_code(code.get_error_code());
                         error_msg.set_error_description(code.to_string());
                         response.mutable_code()->CopyFrom(error_msg);
-                        LOG(ERROR)<<"创建停车流程失败(车位分配失败),终端:"<<request.terminal_id()<<
-                                  "车牌:"<<request.car_info().license()<<"  "<<code.to_string();
+                        LOG(ERROR) << "创建停车流程失败(车位分配失败),终端:" << request.terminal_id() <<
+                                   "车牌:" << request.car_info().license() << "  " << code.to_string();
                         return code;
 
                     }
@@ -267,14 +239,13 @@ Error_manager Command_manager::execute_store_command(message::Store_command_requ
 
         }
 
-        return Error_manager(FAILED,MINOR_ERROR,"创建停车流程失败......");
-    }
-    else
-    {
-        return Error_manager(INVALID_MESSAGE,MAJOR_ERROR,"停车请求基本信息错误");
+        return Error_manager(FAILED, MINOR_ERROR, "创建停车流程失败......");
+    } else {
+        return Error_manager(INVALID_MESSAGE, MAJOR_ERROR, "停车请求基本信息错误");
     }
 }
 
+
 /*
  * 执行取车请求
  */
@@ -362,52 +333,3 @@ 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();
-}

+ 6 - 14
system/command_manager.h

@@ -39,26 +39,18 @@ 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:
 
-    tq::IQueue*                     m_thread_queue_process;         //指令流程线程池
+    /*
+     * 停取车终端 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;
 
-    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;			//发送的条件变量
+    tq::IQueue*                     m_thread_queue_process;         //指令流程线程池
 };
 
 

+ 9 - 2
system/system_communicator.cpp

@@ -21,8 +21,15 @@ Error_manager System_communicator::encapsulate_send_data()
 	return Error_code::SUCCESS;
 }
 
-//发送流程进度
-Error_manager System_communicator::post_entrance_statu(message::Process_statu_map_msg& msg)
+//发送停车流程进度
+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)
 {
     Communication_message message;
     message.reset(msg.base_info(),msg.SerializeAsString());

+ 2 - 1
system/system_communicator.h

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

+ 23 - 15
test/Terminal_communication.cpp

@@ -83,21 +83,35 @@ Error_manager Terminal_communication::execute_msg(Communication_message* p_msg)
         }
     }
 
-    if(p_msg->get_message_type()==Communication_message::eProcess_statu_map_msg)
+    if(p_msg->get_message_type()==Communication_message::eStoring_process_statu_msg)
     {
-        message::Process_statu_map_msg msg;
+        message::Storing_process_statu_msg msg;
         if(msg.ParseFromString(p_msg->get_message_buf())==false)
         {
-            std::cout<<" ERROR : process_statu_msg 失败"<<std::endl;
+            std::cout<<" ERROR : Storing_process_statu_msg 失败"<<std::endl;
         }
         message::Base_info base_info=msg.base_info();
         if(base_info.sender()==message::eMain)
         {
-            m_process_statu_map=msg;
+            m_storing_statu_map[msg.terminal_id()]=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 未知消息");
@@ -182,7 +196,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::seconds>(end_time - start_time);
+        auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time);
         time = 1000.0 * double(duration.count()) * std::chrono::microseconds::period::num /
                std::chrono::microseconds::period::den;
         std::this_thread::yield();
@@ -258,26 +272,20 @@ Error_manager Terminal_communication::pickup_request(message::Pickup_command_req
 /*
      * 获取停车流程状态
      */
-Error_manager Terminal_communication::get_storing_statu(std::string license,message::Storing_process_statu& msg)
+Error_manager Terminal_communication::get_storing_statu(int terminal_id,message::Storing_process_statu_msg& 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);
+    if(m_storing_statu_map.find(terminal_id,msg)) {
         return SUCCESS;
     }
-
     return FAILED;
 }
 
 /*
  * 获取取车流程状态
  */
-Error_manager Terminal_communication::get_picking_statu(std::string license,message::Picking_process_statu& msg)
+Error_manager Terminal_communication::get_picking_statu(int terminal_id,message::Picking_process_statu_msg& 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);
+    if(m_picking_statu_map.find(terminal_id,msg))
         return SUCCESS;
-    }
     return FAILED;
 }

+ 6 - 3
test/Terminal_communication.h

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

+ 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;
-        code = Terminal_communication::get_instance_pointer()->get_picking_statu(car_info.license(), msg);
+        message::Picking_process_statu_msg msg;
+        code = Terminal_communication::get_instance_pointer()->get_picking_statu(m_terminal_id, msg);
         if (code != SUCCESS) {
             continue;
         }

+ 2 - 2
test/store_terminal.cpp

@@ -66,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;
-        code = Terminal_communication::get_instance_pointer()->get_storing_statu(car_info.license(), msg);
+        message::Storing_process_statu_msg msg;
+        code = Terminal_communication::get_instance_pointer()->get_storing_statu(m_terminal_id, msg);
         if (code != SUCCESS) {
             continue;
         }

+ 4 - 3
test/terminal_client.cpp

@@ -81,7 +81,7 @@ void init_glog()
 
 int main() {
     init_glog();
-    Terminal_communication::get_instance_pointer()->communication_connect("tcp://192.168.2.183:30000");
+    Terminal_communication::get_instance_pointer()->communication_connect("tcp://192.168.245.112:30000");
     Terminal_communication::get_instance_pointer()->communication_run();
     usleep(2000*1000);
     threadsafe_queue<message::Car_info> input_queue;
@@ -113,7 +113,7 @@ int main() {
     while (c!='q') {
 
 
-        int license_id = rand() % 90000 + 0000;
+        int license_id = rand() % 50000 + 10000;
         char C=rand()%10+'A';
         char license[255] = {0};
         sprintf(license, "鄂%c%d",C, license_id);
@@ -130,7 +130,8 @@ int main() {
         int out_count=output_queue.size();
 
         if(n%6==0) {
-            std::cin>>c;
+            printf("  input  q to quite    n=%d\n",n);
+            c=getchar();
         }
         else {