|
@@ -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);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
/*
|
|
|
* 初始化 接收到的消息
|
|
|
*/
|