123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227 |
- //
- // Created by huli on 2021/8/3.
- //
- #include "dispatch_plc.h"
- #include "../system/system_communication.h"
- #include "dispatch_manager.h"
- Dispatch_plc::Dispatch_plc()
- {
- m_dispatch_plc_status = Dispatch_plc::Dispatch_plc_status::DISPATCH_PLC_UNKNOW;
- m_plc_id = 0;
- mp_execute_thread = NULL;
- mp_data_storage_thread = NULL;
- }
- Dispatch_plc::~Dispatch_plc()
- {
- dispatch_plc_uninit();
- }
- //调度plc 初始化
- Error_manager Dispatch_plc::dispatch_plc_init(int plc_id)
- {
- m_plc_id = plc_id;
- m_status_updata_time = std::chrono::system_clock::now();
- m_last_heartbeat = 0;
- // 线程默认开启
- m_execute_condition.reset(false, true, false);
- mp_execute_thread = new std::thread(&Dispatch_plc::execute_thread_fun, this);
- // m_data_storage_condition.reset(false, true, false);
- // mp_data_storage_thread = new std::thread(&Dispatch_plc::data_storage_thread_fun, this);
- m_dispatch_plc_status = Dispatch_plc::Dispatch_plc_status::DISPATCH_PLC_READY;
- return Error_code::SUCCESS;
- }
- //调度plc 反初始化
- Error_manager Dispatch_plc::dispatch_plc_uninit()
- {
- if (mp_execute_thread)
- {
- m_execute_condition.kill_all();
- }
- if (mp_data_storage_thread)
- {
- m_data_storage_condition.kill_all();
- }
- if (mp_execute_thread)
- {
- mp_execute_thread->join();
- delete mp_execute_thread;
- mp_execute_thread = NULL;
- }
- if (mp_data_storage_thread)
- {
- mp_data_storage_thread->join();
- delete mp_data_storage_thread;
- mp_data_storage_thread = NULL;
- }
- m_dispatch_plc_status = Dispatch_plc::Dispatch_plc_status::DISPATCH_PLC_UNKNOW;
- return Error_code::SUCCESS;
- }
- //调度plc 执行请求
- //Error_manager Dispatch_plc::execute_for_dispatch_request_msg(message::Dispatch_request_msg& dispatch_request_msg)
- //{
- //
- // if ( m_dispatch_plc_status == Dispatch_plc::Dispatch_plc_status::DISPATCH_PLC_READY )
- // {
- // std::unique_lock<std::mutex> t_lock(m_lock);
- //
- // //设定超时时间, 默认比任务指令里面的时间少10秒,
- // if ( dispatch_request_msg.base_info().has_timeout_ms() )
- // {
- // m_timeout_ms = dispatch_request_msg.base_info().timeout_ms() - DISPATCH_PROCESS_ATTENUATION_TIMEOUT_MS;
- // }
- // else
- // {
- // m_timeout_ms = DISPATCH_PROCESS_TIMEOUT_MS - DISPATCH_PROCESS_ATTENUATION_TIMEOUT_MS;
- // }
- // m_command_key = dispatch_request_msg.command_key();
- // m_start_time = std::chrono::system_clock::now();
- //
- //
- //// m_dispatch_request_msg = dispatch_request_msg;
- //// if ( dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_STORE_CAR )
- //// {
- //// m_dispatch_process_type = Common_data::Dispatch_process_type::DISPATCH_PROCESS_STORE;
- //// }
- //// else if ( dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_PICKUP_CAR )
- //// {
- //// m_dispatch_process_type = Common_data::Dispatch_process_type::DISPATCH_PROCESS_PICKUP;
- //// }
- //// else
- //// {
- //// return Error_manager(Error_code::DISPATCH_PLC_REQUEST_ERROR, Error_level::MINOR_ERROR,
- //// " dispatch_request_msg.dispatch_motion_direction() PARAMRTER ERROR ");
- //// }
- //
- // m_dispatch_process_type = Common_data::Dispatch_process_type::DISPATCH_PROCESS_TYPE_UNKNOW;
- // m_dispatch_plc_status = Dispatch_plc::Dispatch_plc_status::DISPATCH_PLC_REQUEST;
- // }
- // else
- // {
- // return Error_manager(Error_code::DISPATCH_PLC_STATUS_ERROR, Error_level::MINOR_ERROR,
- // " m_dispatch_plc_status error ");
- // }
- //
- // return Error_code::SUCCESS;
- //}
- //新版调度plc 执行请求 存车
- Error_manager Dispatch_plc::execute_for_dispatch_request_msg(park_table &park_table_msg, Common_data::Dispatch_process_type dispatch_process_type, Common_data::Car_type car_type)
- {
- if ( m_dispatch_plc_status == Dispatch_plc::Dispatch_plc_status::DISPATCH_PLC_READY )
- {
- std::unique_lock<std::mutex> t_lock(m_lock);
- //超时默认一小时.
- m_timeout_ms = DISPATCH_PROCESS_TIMEOUT_MS - DISPATCH_PROCESS_ATTENUATION_TIMEOUT_MS;
- //合成唯一码.
- // char t_buf[256] = {0};
- // sprintf(t_buf, "%d+%s+%s", park_table_msg.queue_id(), park_table_msg.car_number().c_str(), park_table_msg.primary_key().c_str());
- // m_command_key = park_table_msg.primary_key()+"_park";
- m_start_time = std::chrono::system_clock::now();
- m_park_table_msg = park_table_msg;
- m_dispatch_process_type = dispatch_process_type;
- m_car_type = car_type;
- if ( m_dispatch_process_type == Common_data::DISPATCH_PROCESS_STORE )
- {
- m_command_key = park_table_msg.primary_key()+"_store";
- }
- if ( m_dispatch_process_type == Common_data::DISPATCH_PROCESS_REALLOCATE )
- {
- m_command_key = park_table_msg.primary_key()+"_reallocate";
- }
- m_dispatch_plc_status = Dispatch_plc::Dispatch_plc_status::DISPATCH_PLC_REQUEST;
- }
- else
- {
- return Error_manager(Error_code::DISPATCH_PLC_STATUS_ERROR, Error_level::MINOR_ERROR,
- " m_dispatch_plc_status error ");
- }
- return Error_code::SUCCESS;
- }
- //新版调度plc 执行请求 取车
- Error_manager Dispatch_plc::execute_for_dispatch_request_msg(pick_table &pick_table_msg, Common_data::Dispatch_process_type dispatch_process_type, Common_data::Car_type car_type)
- {
- if ( m_dispatch_plc_status == Dispatch_plc::Dispatch_plc_status::DISPATCH_PLC_READY )
- {
- std::unique_lock<std::mutex> t_lock(m_lock);
- //超时默认一小时.
- m_timeout_ms = DISPATCH_PROCESS_TIMEOUT_MS - DISPATCH_PROCESS_ATTENUATION_TIMEOUT_MS;
- //合成唯一码.
- // char t_buf[256] = {0};
- // sprintf(t_buf, "%d+%s+%s", pick_table_msg.queue_id(), pick_table_msg.car_number().c_str(), pick_table_msg.primary_key().c_str());
- // m_command_key = pick_table_msg.primary_key()+"_pick";
- m_start_time = std::chrono::system_clock::now();
- m_pick_table_msg = pick_table_msg;
- m_dispatch_process_type = dispatch_process_type;
- m_car_type = car_type;
- if ( m_dispatch_process_type == Common_data::DISPATCH_PROCESS_PICKUP )
- {
- m_command_key = pick_table_msg.primary_key()+"_pickup";
- }
- if ( m_dispatch_process_type == Common_data::DISPATCH_PROCESS_REVOCATION )
- {
- m_command_key = pick_table_msg.primary_key()+"_revocation";
- }
- m_dispatch_plc_status = Dispatch_plc::Dispatch_plc_status::DISPATCH_PLC_REQUEST;
- }
- else
- {
- return Error_manager(Error_code::DISPATCH_PLC_STATUS_ERROR, Error_level::MINOR_ERROR,
- " m_dispatch_plc_status error ");
- }
- return Error_code::SUCCESS;
- }
- Dispatch_plc::Dispatch_plc_status Dispatch_plc::get_dispatch_plc_status()
- {
- return m_dispatch_plc_status;
- }
- //message::Dispatch_request_msg Dispatch_plc::get_dispatch_request_msg()
- //{
- // std::unique_lock<std::mutex> t_lock(m_lock);
- // return m_dispatch_request_msg;
- //}
- Error_manager Dispatch_plc::get_result()
- {
- return m_result;
- }
- float Dispatch_plc::get_response_working_total_time()
- {
- std::unique_lock<std::mutex> t_lock(m_lock);
- return m_response_working_total_time;
- }
- float Dispatch_plc::get_response_working_remaining_time()
- {
- std::unique_lock<std::mutex> t_lock(m_lock);
- return m_response_working_remaining_time;
- }
- void Dispatch_plc::clear_request_msg()
- {
- m_request_key.clear(); //请求唯一码, 用作识别
- m_request_status = 0; //请求确认标志
- // 调度指令的起点,终点,方向
- m_request_dispatch_motion_direction = Common_data::Dispatch_process_type::DISPATCH_PROCESS_TYPE_UNKNOW; //调度方向 0=未知,1=存车,2=取车
- m_request_passageway_id = 0; //出入口id 6个入口和6个出口
- m_request_passageway_direction = Common_data::Passageway_direction::PASSAGEWAY_DIRECTION_UNKNOWN; //出入口方向 0=未知,1=入口,2=出口
- m_request_parkingspace_index_id = 0; //楼上车位索引id 1~180(3*6*13)
- m_request_parkingspace_unit_id = 0; //楼上车位单元号 1~3
- m_request_parkingspace_label_id = 0; //楼上车位标签号 1~78
- m_request_parkingspace_floor_id = 0; //楼上车位楼层号 2~11
- m_request_parkingspace_room_id = 0; //楼上车位房间号 1~6
- m_request_parkingspace_direction = Common_data::Parkingspace_direction::PARKINGSPACE_DIRECTION_UNKNOWN; //楼上车位方向 0=未知,1=朝南,2=朝北
- //汽车的定位信息(地面雷达)
- m_request_car_center_x = 0; //整车的中心点x值, 四轮的中心, 单位:米 m
- m_request_car_center_y = 0; //整车的中心点y值, 四轮的中心, 单位:米 m
- m_request_car_angle = 0; //整车的车身旋转角, 单位:度 (-90~90)
- m_request_car_front_theta = 0; //整车的前轮的旋转角, 单位:度 (-90~90)
- m_request_car_length = 0; //整车的长度, 用于规避碰撞, 单位:米 m
- m_request_car_width = 0; //整车的宽度, 用于规避碰撞, 单位:米 m
- m_request_car_height = 0; //整车的高度, 用于规避碰撞, 单位:米 m
- m_request_car_wheel_base = 0; //整车的轮距, 前后轮的距离, 用于机器人或agv的抓车, 单位:米 m
- m_request_car_wheel_width = 0; //整车的轮距, 左右轮的距离, 用于机器人或agv的抓车, 单位:米 m
- m_request_car_license.clear(); //车牌号(汽车唯一标示) 例如: 鄂A12345
- m_request_car_type = Common_data::Car_type::UNKNOW_CAR_TYPE; //车的大小
- m_request_uniformed_car_x = 0; //转角复位后,车辆中心点x
- m_request_uniformed_car_y = 0; //转角复位后,车辆中心点y
- //防撞雷达
- m_request_anticollision_lidar_flag = Common_data::Anticollision_lidar_flag::ANTICOLLISION_LIDAR_UNKNOWN; //汽车是否停到正确的位置, 防撞雷达 预留, 楚天暂时不用,0=未知,1=位置正常,2=位置异常
- //轮距雷达
- m_request_car_wheel_base_exact_value = 0; //汽车前后轮距,轮距雷达的精确值 预留, 楚天暂时不用,单位:米 m
- }
- //jiancha qingqiu xiaoxi
- //Error_manager Dispatch_plc::check_dispatch_request_msg(message::Dispatch_request_msg & dispatch_request_msg)
- //{
- // return Error_code::SUCCESS;
- // /*
- // Error_manager t_error;
- //
- // if(dispatch_request_msg.has_locate_information() &&
- // dispatch_request_msg.has_dispatch_motion_direction() &&
- // dispatch_request_msg.has_car_type() &&
- // dispatch_request_msg.has_id_struct() &&
- // dispatch_request_msg.has_command_key())
- // {
- // if ( m_dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_STORE_CAR )
- // {
- // if ( dispatch_request_msg.id_struct().has_unit_id() )
- // {
- //
- // }
- // }
- // else if( m_dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_PICKUP_CAR )
- //
- // return Error_code::SUCCESS;
- // }
- // else
- // {
- // return Error_manager(Error_code::DISPATCH_PLC_REQUEST_ERROR, Error_level::MINOR_ERROR,
- // " m_dispatch_plc_status error ");
- // }
- // */
- // return Error_code::SUCCESS;
- //}
- //执行外界任务的执行函数
- void Dispatch_plc::execute_thread_fun()
- {
- LOG(INFO) << " Dispatch_plc::execute_thread_fun() start " << this;
- Error_manager t_error;
- while (m_execute_condition.is_alive())
- {
- m_execute_condition.wait();
- if (m_execute_condition.is_alive())
- {
- std::this_thread::sleep_for(std::chrono::microseconds(1));
- std::this_thread::sleep_for(std::chrono::milliseconds(1));
- // std::this_thread::sleep_for(std::chrono::seconds(1));
- std::this_thread::yield();
- // std::unique_lock<std::mutex> t_lock(m_lock);
- static int t_count = 0;
- if (t_count % 1000 == 0 )
- {
- std::cout << " huli test :::: " << " m_plc_id = " << m_plc_id << std::endl;
- std::cout << " huli test :::: " << " m_dispatch_plc_status = " << m_dispatch_plc_status << std::endl;
- }
- t_count++;
- switch ((Dispatch_plc_status) m_dispatch_plc_status)
- {
- case DISPATCH_PLC_READY:
- {
- if ( m_dispatch_process_type == Common_data::Dispatch_process_type::DISPATCH_PROCESS_TYPE_UNKNOW )
- {
- update_dispatch_plc_communication();
- }
- else
- {
- // m_result = check_dispatch_request_msg(m_dispatch_request_msg);
- //收到新指令, 进入工作阶段,强制清空错误码.
- m_result.error_manager_clear_all();
- if(m_result == Error_code::SUCCESS)
- {
- m_dispatch_plc_status = DISPATCH_PLC_REQUEST;
- }
- else
- {
- m_dispatch_plc_status = DISPATCH_PLC_RESPONSE;
- }
- }
- break;
- }
- case DISPATCH_PLC_REQUEST://给plc发送请求
- {
- //收到新指令, 进入工作阶段,强制清空错误码.
- m_result.error_manager_clear_all();
- #ifdef PLC_OVER_TIME_TO_ERROR
- if ( std::chrono::system_clock::now() - m_start_time > std::chrono::milliseconds(m_timeout_ms) )
- {
- //超时直接报错
- m_result = Error_manager(Error_code::DISPATCH_PLC_TIME_OUT, Error_level::MINOR_ERROR,
- " DISPATCH_PLC_TIME_OUT fun error ");
- m_dispatch_plc_status = DISPATCH_PLC_RESPONSE;
- }
- else
- #endif
- {
- //封装 给plc的调度请求
- // m_result = encapsulate_dispatch_request_to_plc();
- m_result = encapsulate_dispatch_request_to_plc_new();
- test_start_time = std::chrono::system_clock::now();
- m_result = Error_code::SUCCESS;
- if ( m_result == Error_code::SUCCESS )
- {
- m_dispatch_plc_status = DISPATCH_PLC_WORKING;
- }
- else
- {
- m_dispatch_plc_status = DISPATCH_PLC_RESPONSE;
- }
- }
- break;
- }
- case DISPATCH_PLC_WORKING:
- {
- #ifdef PLC_OVER_TIME_TO_ERROR
- if ( std::chrono::system_clock::now() - m_start_time > std::chrono::milliseconds(m_timeout_ms) )
- {
- //超时直接报错
- m_result = Error_manager(Error_code::DISPATCH_PLC_TIME_OUT, Error_level::MINOR_ERROR,
- " DISPATCH_PLC_TIME_OUT fun error ");
- m_dispatch_plc_status = DISPATCH_PLC_RESPONSE;
- }
- else
- #endif
- {
- update_dispatch_plc_communication();
- //检查plc答复反馈
- // m_result = check_response_from_plc();
- m_result = check_response_from_plc_new();
- if ( m_result == Error_code::SUCCESS )
- {
- m_dispatch_plc_status = DISPATCH_PLC_RESPONSE;
- }
- else if ( m_result != Error_code::NODATA )
- {
- // m_dispatch_plc_status = DISPATCH_PLC_FAULT;
- m_dispatch_plc_status = DISPATCH_PLC_RESPONSE;
- }
- //else NODATA 原地等待
- }
- break;
- }
- case DISPATCH_PLC_RESPONSE:
- {
- test_end_time = std::chrono::system_clock::now();
- auto time_dur = test_end_time - test_start_time;
- if ( time_dur < std::chrono::seconds(2) )
- {
- LOG(INFO) << " 调度完成, 时间太短, 按任意键继续 = "<< time_dur.count() << " --- " << this;
- getchar();
- }
- //20211213. huli m_request_status = 0 after over process
- m_request_status = 0;
- clear_request_msg();
- //发送调度答复信息给主控
- // send_dispatch_response_to_main_control();
- // send_dispatch_response_to_main_control_new();
- //无论前面的流程是否正确,都要给主控答复, 反馈里面填充错误码即可.
- //最新版本不用答复消息, Dispatch_plc 切回 DISPATCH_PLC_READY 后, 由 Dispatch_manager 答复数据库
- if ( m_result == Error_code::SUCCESS )
- {
- /*
- //response add to _map
- if ( m_dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_STORE_CAR )
- {
- std::unique_lock<std::mutex> t_lock(Dispatch_manager::get_instance_references().m_lock);
- std::chrono::system_clock::time_point t_time = std::chrono::system_clock::now();
- Dispatch_manager::get_instance_references().m_dispatch_response_store_map[t_time] = m_dispatch_response_msg;
- Dispatch_manager::get_instance_references().m_store_updata_time = std::chrono::system_clock::now();
- }
- else if( m_dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_PICKUP_CAR )
- {
- std::unique_lock<std::mutex> t_lock(Dispatch_manager::get_instance_references().m_lock);
- int t_terminal_id = m_dispatch_request_msg.id_struct().terminal_id();
- Dispatch_manager::get_instance_references().m_dispatch_response_pickup_map[t_terminal_id] = m_dispatch_response_msg;
- Dispatch_manager::get_instance_references().m_pickup_updata_time = std::chrono::system_clock::now();
- }
- */
- //流程正常结束, 恢复到待机状态.
- m_dispatch_plc_status = DISPATCH_PLC_READY;
- m_dispatch_process_type = Common_data::Dispatch_process_type::DISPATCH_PROCESS_TYPE_UNKNOW;
- // m_result.error_manager_clear_all();
- }
- else
- {
- //流程异常结束, 进入到故障状态.
- m_dispatch_plc_status = DISPATCH_PLC_FAULT;
- }
- break;
- }
- case DISPATCH_PLC_FAULT:
- case DISPATCH_PLC_DISCONNECT:
- {
- //20211213. huli m_request_status = 0 after over process
- m_request_status = 0;
- clear_request_msg();
- //不在接受新的任务,但是保持基本的通信正常
- update_dispatch_plc_communication();
- /*
- //response add to _map
- if ( m_dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_STORE_CAR )
- {
- std::unique_lock<std::mutex> t_lock(Dispatch_manager::get_instance_references().m_lock);
- std::chrono::system_clock::time_point t_time = std::chrono::system_clock::now();
- Dispatch_manager::get_instance_references().m_dispatch_response_store_map[t_time] = m_dispatch_response_msg;
- Dispatch_manager::get_instance_references().m_store_updata_time = std::chrono::system_clock::now();
- }
- else if( m_dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_PICKUP_CAR )
- {
- std::unique_lock<std::mutex> t_lock(Dispatch_manager::get_instance_references().m_lock);
- int t_terminal_id = m_dispatch_request_msg.id_struct().terminal_id();
- Dispatch_manager::get_instance_references().m_dispatch_response_pickup_map[t_terminal_id] = m_dispatch_response_msg;
- Dispatch_manager::get_instance_references().m_pickup_updata_time = std::chrono::system_clock::now();
- }
- */
- //20211209 huli //流程异常结束, 进入到 ready.
- m_dispatch_plc_status = DISPATCH_PLC_READY;
- m_dispatch_process_type = Common_data::Dispatch_process_type::DISPATCH_PROCESS_TYPE_UNKNOW;
- // m_result.error_manager_clear_all();
- LOG(ERROR) << " Dispatch_plc::execute_thread_fun() dispatch_plc is fault, now recover to normal " << this;
- break;
- }
- }
- }
- }
- }
- //数据储存线程函数
- void Dispatch_plc::data_storage_thread_fun()
- {
- LOG(INFO) << " Dispatch_plc::data_storage_thread_fun() start " << this;
- Error_manager t_error;
- while (m_data_storage_condition.is_alive())
- {
- m_data_storage_condition.wait();
- if (m_data_storage_condition.is_alive())
- {
- std::this_thread::sleep_for(std::chrono::microseconds(1));
- std::this_thread::sleep_for(std::chrono::milliseconds(1));
- std::this_thread::sleep_for(std::chrono::seconds(1));
- std::this_thread::yield();
- // std::unique_lock<std::mutex> t_lock(m_lock);
- char buf[16] = {0}; //数据转字符串然后存数据库
- std::string t_plc_data_string;
- float t_heartbeat = Dispatch_communication::get_instance_references().m_data_storage_from_plc_to_manager.m_heartbeat;
- {
- std::unique_lock<std::mutex> t_lock1(Dispatch_communication::get_instance_references().m_data_lock);
- char * tp = buf;
- for (int i = 0; i < DATA_STORAGE_PLC_DATA_LENGTH; ++i)
- {
- sprintf(buf, "%g\t", Dispatch_communication::get_instance_references().m_data_storage_from_plc_to_manager.m_plc_data[i]);
- t_plc_data_string += buf;
- }
- // std::cout << " huli test :::: " << " t_plc_data_string = " << t_plc_data_string << std::endl;
- }
- Dispatch_manager::get_instance_references().m_dispatch_command.insert_plc_data(t_plc_data_string, t_heartbeat);
- }
- }
- }
- //封装 给plc的调度请求
- Error_manager Dispatch_plc::encapsulate_dispatch_request_to_plc()
- {
- // //把m_dispatch_request_msg的信息传给本地的数据缓存.
- // std::unique_lock<std::mutex> t_lock(m_lock);
- // m_request_key = m_dispatch_request_msg.command_key();
- // m_request_status = 1;
- // if ( m_dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_STORE_CAR )
- // {
- // m_request_dispatch_motion_direction = Common_data::Dispatch_motion_direction::DISPATCH_MOTION_DIRECTION_STORE;
- // m_request_passageway_direction = Common_data::Passageway_direction::PASSAGEWAY_DIRECTION_INLET;
- // m_request_passageway_id = m_dispatch_request_msg.mutable_id_struct()->terminal_id()+1;//0~5入口终端号改为1~6
- // }
- // else if( m_dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_PICKUP_CAR )
- // {
- // m_request_dispatch_motion_direction = Common_data::Dispatch_motion_direction::DISPATCH_MOTION_DIRECTION_PICKUP;
- // m_request_passageway_direction = Common_data::Passageway_direction::PASSAGEWAY_DIRECTION_OUTLET;
- // m_request_passageway_id = m_dispatch_request_msg.mutable_id_struct()->terminal_id()+1;//0~5入口终端号改为1~6
- //
- // }
- // else
- // {
- // m_request_dispatch_motion_direction = Common_data::Dispatch_motion_direction::DISPATCH_MOTION_DIRECTION_UNKNOWN;
- // m_request_passageway_direction = Common_data::Passageway_direction::PASSAGEWAY_DIRECTION_UNKNOWN;
- // m_request_passageway_id = -1;
- // }
- //
- // if ( m_dispatch_request_msg.locate_information().locate_correct() )
- // {
- // m_request_car_center_x = m_dispatch_request_msg.locate_information().locate_x();
- // m_request_car_center_y = m_dispatch_request_msg.locate_information().locate_y();
- //#ifdef MEASURE_TO_PLC_CORRECTION
- // m_request_car_angle = m_dispatch_request_msg.locate_information().locate_angle()-90+0.3;//80~100改为-10~+10
- //#endif
- //#ifndef MEASURE_TO_PLC_CORRECTION
- // m_request_car_angle = m_dispatch_request_msg.locate_information().locate_angle();
- //#endif
- // m_request_car_front_theta = m_dispatch_request_msg.locate_information().locate_front_theta();
- // m_request_car_length = m_dispatch_request_msg.locate_information().locate_length();
- // m_request_car_width = m_dispatch_request_msg.locate_information().locate_width();
- // m_request_car_height = m_dispatch_request_msg.locate_information().locate_height();
- // m_request_car_wheel_base = m_dispatch_request_msg.locate_information().locate_wheel_base();
- // m_request_car_wheel_width = m_dispatch_request_msg.locate_information().locate_wheel_width();
- // m_request_uniformed_car_x = m_dispatch_request_msg.locate_information().uniformed_car_x();
- // m_request_uniformed_car_y = m_dispatch_request_msg.locate_information().uniformed_car_y();
- // }
- // else
- // {
- // m_request_car_center_x = m_dispatch_request_msg.locate_information().locate_x();
- // m_request_car_center_y = m_dispatch_request_msg.locate_information().locate_y();
- //#ifdef MEASURE_TO_PLC_CORRECTION
- // m_request_car_angle = m_dispatch_request_msg.locate_information().locate_angle()-90+0.3;//80~100改为-10~+10
- //#endif
- //#ifndef MEASURE_TO_PLC_CORRECTION
- // m_request_car_angle = m_dispatch_request_msg.locate_information().locate_angle();
- //#endif
- // m_request_car_front_theta = m_dispatch_request_msg.locate_information().locate_front_theta();
- // m_request_car_length = m_dispatch_request_msg.locate_information().locate_length();
- // m_request_car_width = m_dispatch_request_msg.locate_information().locate_width();
- // m_request_car_height = m_dispatch_request_msg.locate_information().locate_height();
- // m_request_car_wheel_base = m_dispatch_request_msg.locate_information().locate_wheel_base();
- // m_request_car_wheel_width = m_dispatch_request_msg.locate_information().locate_wheel_width();
- // m_request_uniformed_car_x = m_dispatch_request_msg.locate_information().uniformed_car_x();
- // m_request_uniformed_car_y = m_dispatch_request_msg.locate_information().uniformed_car_y();
- // }
- //
- // if ( m_dispatch_request_msg.parkspace_info_ex_size() ==1 )
- // {
- // m_request_parkingspace_index_id = m_dispatch_request_msg.parkspace_info_ex(0).parkingspace_index_id();
- // m_request_parkingspace_unit_id = m_dispatch_request_msg.parkspace_info_ex(0).parkingspace_unit_id()+1;//0~2单元号改为1~3
- // m_request_parkingspace_label_id = m_dispatch_request_msg.parkspace_info_ex(0).parkingspace_label_id();
- // m_request_parkingspace_floor_id = m_dispatch_request_msg.parkspace_info_ex(0).parkingspace_floor_id();
- // m_request_parkingspace_room_id = m_dispatch_request_msg.parkspace_info_ex(0).parkingspace_room_id();
- // //车位朝向, 小号朝前朝南, 大号朝后朝北
- // m_request_parkingspace_direction = (Common_data::Parkingspace_direction)m_dispatch_request_msg.parkspace_info_ex(0).parkingspace_direction();
- //
- //
- // //20211220, utf-8 -> GBK
- // m_request_car_license = String_convert::utf8_to_gbk( m_dispatch_request_msg.parkspace_info_ex(0).car_info().car_numberplate() );
- //
- // m_request_car_type = (Common_data::Car_type)m_dispatch_request_msg.parkspace_info_ex(0).car_type();
- //
- // //20211207, huli add wheel_base for pickup_car
- // if( m_dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_PICKUP_CAR )
- // {
- // m_request_car_wheel_base = m_dispatch_request_msg.parkspace_info_ex(0).car_info().car_wheel_base();
- // m_request_car_wheel_width = m_dispatch_request_msg.parkspace_info_ex(0).car_info().car_wheel_width();
- // }
- // }
- // else
- // {
- // return Error_manager(Error_code::DISPATCH_PLC_REQUEST_ERROR, Error_level::MINOR_ERROR,
- // " m_dispatch_request_msg.parkspace_info_ex_size() !=1 error ");
- // }
- return Error_code::SUCCESS;
- }
- //封装 给plc的调度请求
- Error_manager Dispatch_plc::encapsulate_dispatch_request_to_plc_new()
- {
- //把m_dispatch_request_msg的信息传给本地的数据缓存.
- std::unique_lock<std::mutex> t_lock(m_lock);
- m_request_key = m_command_key;
- m_request_status = 1;
- if ( m_dispatch_process_type == Common_data::Dispatch_process_type::DISPATCH_PROCESS_STORE ||
- m_dispatch_process_type == Common_data::Dispatch_process_type::DISPATCH_PROCESS_REALLOCATE)
- {
- //基本信息
- m_request_dispatch_motion_direction = m_dispatch_process_type;
- m_request_passageway_direction = Common_data::Passageway_direction::PASSAGEWAY_DIRECTION_INLET;
- m_request_passageway_id = m_park_table_msg.terminal_id();
- // m_request_passageway_id = m_terminal_id;
- //感测雷达信息, 存车专有
- // if ( m_park_table_msg.entrance_measure_info().border_statu() )
- if ( true )
- {
- m_request_car_center_x = m_park_table_msg.entrance_measure_info().cx();
- m_request_car_center_y = m_park_table_msg.entrance_measure_info().cy();
- m_request_car_angle = m_park_table_msg.entrance_measure_info().theta();
- m_request_car_front_theta = m_park_table_msg.entrance_measure_info().front_theta();
- m_request_car_length = m_park_table_msg.entrance_measure_info().length();
- m_request_car_width = m_park_table_msg.entrance_measure_info().width();
- m_request_car_height = m_park_table_msg.entrance_measure_info().height();
- m_request_car_wheel_base = m_park_table_msg.entrance_measure_info().wheelbase();
- m_request_car_wheel_width = m_park_table_msg.entrance_measure_info().width();
- m_request_uniformed_car_x = m_park_table_msg.entrance_measure_info().cx();
- m_request_uniformed_car_y = m_park_table_msg.entrance_measure_info().cy();
- }
- //车位信息
- m_request_parkingspace_index_id = m_park_table_msg.allocated_space_info().id();
- m_request_parkingspace_unit_id = m_park_table_msg.allocated_space_info().unit_id();
- int t_parkingspace_label_id = (m_park_table_msg.allocated_space_info().id() - 1 )%78;
- m_request_parkingspace_label_id = t_parkingspace_label_id+1;
- m_request_parkingspace_floor_id = m_park_table_msg.allocated_space_info().floor();
- m_request_parkingspace_room_id = m_park_table_msg.allocated_space_info().room_id();
- //车位朝向, 奇数朝南, 偶数朝北
- if ( m_request_parkingspace_index_id %2 == 1 )
- {
- m_request_parkingspace_direction = Common_data::Parkingspace_direction::PARKINGSPACE_DIRECTION_SOUTH;
- }
- else
- {
- m_request_parkingspace_direction = Common_data::Parkingspace_direction::PARKINGSPACE_DIRECTION_NORTH;
- }
- //20211220, utf-8 -> GBK
- m_request_car_license = String_convert::utf8_to_gbk( m_park_table_msg.car_number() );
- m_request_car_type = Common_data::judge_car_type_with_car_height(m_request_car_height);
- }
- else if( m_dispatch_process_type == Common_data::Dispatch_process_type::DISPATCH_PROCESS_PICKUP ||
- m_dispatch_process_type == Common_data::Dispatch_process_type::DISPATCH_PROCESS_REVOCATION)
- {
- m_request_dispatch_motion_direction = m_dispatch_process_type;
- m_request_passageway_direction = Common_data::Passageway_direction::PASSAGEWAY_DIRECTION_OUTLET;
- m_request_passageway_id = m_pick_table_msg.terminal_id();
- // m_request_passageway_id = m_terminal_id;
- //20211207, 取车专有, 数据库保存的汽车信息, 轮距
- m_request_car_center_x = m_pick_table_msg.actually_measure_info().cx();
- m_request_car_center_y = m_pick_table_msg.actually_measure_info().cy();
- m_request_car_angle = m_pick_table_msg.actually_measure_info().theta();
- m_request_car_front_theta = m_pick_table_msg.actually_measure_info().front_theta();
- m_request_car_length = m_pick_table_msg.actually_measure_info().length();
- m_request_car_width = m_pick_table_msg.actually_measure_info().width();
- m_request_car_height = m_pick_table_msg.actually_measure_info().height();
- m_request_car_wheel_base = m_pick_table_msg.actually_measure_info().wheelbase();
- m_request_car_wheel_width = m_pick_table_msg.actually_measure_info().width();
- m_request_uniformed_car_x = m_pick_table_msg.actually_measure_info().cx();
- m_request_uniformed_car_y = m_pick_table_msg.actually_measure_info().cy();
- //车位信息
- m_request_parkingspace_index_id = m_pick_table_msg.actually_space_info().id();
- m_request_parkingspace_unit_id = m_pick_table_msg.actually_space_info().unit_id();
- int t_parkingspace_label_id = (m_pick_table_msg.actually_space_info().id() -1 )%78;
- m_request_parkingspace_label_id = t_parkingspace_label_id +1 ;
- m_request_parkingspace_floor_id = m_pick_table_msg.actually_space_info().floor();
- m_request_parkingspace_room_id = m_pick_table_msg.actually_space_info().room_id();
- //车位朝向, 奇数朝南, 偶数朝北
- if ( m_request_parkingspace_index_id %2 == 1 )
- {
- m_request_parkingspace_direction = Common_data::Parkingspace_direction::PARKINGSPACE_DIRECTION_SOUTH;
- }
- else
- {
- m_request_parkingspace_direction = Common_data::Parkingspace_direction::PARKINGSPACE_DIRECTION_NORTH;
- }
- //20211220, utf-8 -> GBK
- m_request_car_license = String_convert::utf8_to_gbk( m_pick_table_msg.car_number() );
- m_request_car_type = Common_data::judge_car_type_with_car_height(m_request_car_height);
- }
- else
- {
- m_request_dispatch_motion_direction = Common_data::Dispatch_process_type::DISPATCH_PROCESS_TYPE_UNKNOW;
- m_request_passageway_direction = Common_data::Passageway_direction::PASSAGEWAY_DIRECTION_UNKNOWN;
- m_request_passageway_id = -1;
- }
- return Error_code::SUCCESS;
- }
- //更新plc通信
- Error_manager Dispatch_plc::update_dispatch_plc_communication()
- {
- std::unique_lock<std::mutex> t_lock(m_lock);
- std::unique_lock<std::mutex> t_lock1(Dispatch_communication::get_instance_references().m_data_lock);
- /*
- //请求消息, 调度->plc
- Dispatch_communication::Dispatch_request_from_manager_to_plc_for_data * tp_dispatch_request_from_manager_to_plc_for_data =
- & Dispatch_communication::get_instance_references().m_dispatch_request_from_manager_to_plc_for_data;
- Dispatch_communication::Dispatch_request_from_manager_to_plc_for_key * m_dispatch_request_from_manager_to_plc_for_key =
- & Dispatch_communication::get_instance_references().m_dispatch_request_from_manager_to_plc_for_key;
- memset(m_dispatch_request_from_manager_to_plc_for_key->m_request_key, 0, 50);
- int t_size1 = m_request_key.size()<=50 ? m_request_key.size() : 50 ;
- m_request_key = "123456789";
- memcpy(m_dispatch_request_from_manager_to_plc_for_key->m_request_key, m_request_key.c_str(), t_size1);
- static unsigned char index = 0;
- index++;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_dispatch_motion_direction = index;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_passageway_id = 02;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_passageway_direction = 03;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_parkingspace_index_id = 04;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_parkingspace_unit_id = 05;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_parkingspace_floor_id = 6;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_parkingspace_room_id = 7;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_parkingspace_direction = 8;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_center_x = 11;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_center_y = 12;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_angle = 13;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_front_theta = 14;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_length = 15;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_width = 16;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_height = 17;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_wheel_base = 18;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_wheel_width = 19;
- memset(tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_license, 0, 20);
- int t_size2 = m_request_key.size()<=20 ? m_request_key.size() : 20 ;
- m_request_car_license = "ABCDEF";
- memcpy(tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_license, m_request_car_license.c_str(), t_size2);
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_type = 33;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_anticollision_lidar_flag = 44;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_wheel_base_exact_value = 55;
- */
- //请求消息, 调度->plc
- Dispatch_communication::Dispatch_request_from_manager_to_plc_for_data * tp_dispatch_request_from_manager_to_plc_for_data =
- & Dispatch_communication::get_instance_references().m_dispatch_request_from_manager_to_plc_for_data;
- Dispatch_communication::Dispatch_request_from_manager_to_plc_for_key * m_dispatch_request_from_manager_to_plc_for_key =
- & Dispatch_communication::get_instance_references().m_dispatch_request_from_manager_to_plc_for_key;
- memset(m_dispatch_request_from_manager_to_plc_for_key->m_request_key, 0, 50);
- int t_size1 = m_request_key.size()<=50 ? m_request_key.size() : 50 ;
- memcpy(m_dispatch_request_from_manager_to_plc_for_key->m_request_key, m_request_key.c_str(), t_size1);
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_status = m_request_status;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_dispatch_motion_direction = m_request_dispatch_motion_direction;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_passageway_id = m_request_passageway_id;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_passageway_direction = m_request_passageway_direction;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_parkingspace_index_id = m_request_parkingspace_index_id;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_parkingspace_unit_id = m_request_parkingspace_unit_id;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_parkingspace_label_id = m_request_parkingspace_label_id;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_parkingspace_floor_id = m_request_parkingspace_floor_id;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_parkingspace_room_id = m_request_parkingspace_room_id;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_parkingspace_direction = m_request_parkingspace_direction;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_center_x = m_request_car_center_x;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_center_y = m_request_car_center_y;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_angle = m_request_car_angle;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_front_theta = m_request_car_front_theta;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_length = m_request_car_length;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_width = m_request_car_width;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_height = m_request_car_height;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_wheel_base = m_request_car_wheel_base;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_wheel_width = m_request_car_wheel_width;
- memset(tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_license, 0, 20);
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_license[0] = 18;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_license[1] = m_request_car_license.length();
- unsigned char * p_ch = tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_license;
- memcpy(p_ch+2, m_request_car_license.c_str(), m_request_car_license.length());
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_type = m_request_car_type;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_uniformed_car_x = m_request_uniformed_car_x;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_uniformed_car_y = m_request_uniformed_car_y;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_anticollision_lidar_flag = m_request_anticollision_lidar_flag;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_car_wheel_base_exact_value = m_request_car_wheel_base_exact_value;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_clamp_lidar_deviation_1 = m_request_clamp_lidar_deviation_1;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_clamp_lidar_deviation_2 = m_request_clamp_lidar_deviation_2;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_clamp_lidar_deviation_3 = m_request_clamp_lidar_deviation_3;
- tp_dispatch_request_from_manager_to_plc_for_data->m_request_clamp_lidar_deviation_4 = m_request_clamp_lidar_deviation_4;
- //答复消息, plc->调度
- Dispatch_communication::Dispatch_response_from_plc_to_manager * tp_dispatch_response_from_plc_to_manager =
- & Dispatch_communication::get_instance_references().m_dispatch_response_from_plc_to_manager;
- m_response_key = (char*) tp_dispatch_response_from_plc_to_manager->m_response_key;
- m_response_status = (Dispatch_plc::Response_status)tp_dispatch_response_from_plc_to_manager->m_response_status;
- m_response_working_total_time = tp_dispatch_response_from_plc_to_manager->m_response_working_total_time;
- m_response_working_remaining_time = tp_dispatch_response_from_plc_to_manager->m_response_working_remaining_time;
- m_response_dispatch_motion_direction = (Common_data::Dispatch_process_type)tp_dispatch_response_from_plc_to_manager->m_response_dispatch_motion_direction;
- m_response_passageway_id = tp_dispatch_response_from_plc_to_manager->m_response_passageway_id;
- m_response_passageway_direction = (Common_data::Passageway_direction)tp_dispatch_response_from_plc_to_manager->m_response_passageway_direction;
- m_response_parkingspace_index_id = tp_dispatch_response_from_plc_to_manager->m_response_parkingspace_index_id;
- m_response_parkingspace_unit_id = tp_dispatch_response_from_plc_to_manager->m_response_parkingspace_unit_id;
- m_response_parkingspace_label_id = tp_dispatch_response_from_plc_to_manager->m_response_parkingspace_label_id;
- m_response_parkingspace_floor_id = tp_dispatch_response_from_plc_to_manager->m_response_parkingspace_floor_id;
- m_response_parkingspace_room_id = tp_dispatch_response_from_plc_to_manager->m_response_parkingspace_room_id;
- m_response_parkingspace_direction = (Common_data::Parkingspace_direction)tp_dispatch_response_from_plc_to_manager->m_response_parkingspace_direction;
- m_response_car_center_x = tp_dispatch_response_from_plc_to_manager->m_response_car_center_x;
- m_response_car_center_y = tp_dispatch_response_from_plc_to_manager->m_response_car_center_y;
- m_response_car_angle = tp_dispatch_response_from_plc_to_manager->m_response_car_angle;
- m_response_car_front_theta = tp_dispatch_response_from_plc_to_manager->m_response_car_front_theta;
- m_response_car_length = tp_dispatch_response_from_plc_to_manager->m_response_car_length;
- m_response_car_width = tp_dispatch_response_from_plc_to_manager->m_response_car_width;
- m_response_car_height = tp_dispatch_response_from_plc_to_manager->m_response_car_height;
- m_response_car_wheel_base = tp_dispatch_response_from_plc_to_manager->m_response_car_wheel_base;
- m_response_car_wheel_width = tp_dispatch_response_from_plc_to_manager->m_response_car_wheel_width;
- m_response_car_license = (char*) (tp_dispatch_response_from_plc_to_manager->m_response_car_license+2);
- m_response_car_type = (Common_data::Car_type) tp_dispatch_response_from_plc_to_manager->m_response_car_type;
- m_response_uniformed_car_x = tp_dispatch_response_from_plc_to_manager->m_response_uniformed_car_x;
- m_response_uniformed_car_y = tp_dispatch_response_from_plc_to_manager->m_response_uniformed_car_y;
- m_response_anticollision_lidar_flag = (Common_data::Anticollision_lidar_flag)tp_dispatch_response_from_plc_to_manager->m_response_anticollision_lidar_flag;
- m_response_car_wheel_base_exact_value = tp_dispatch_response_from_plc_to_manager->m_response_car_wheel_base_exact_value;
- m_response_clamp_lidar_deviation_1 = tp_dispatch_response_from_plc_to_manager->m_response_clamp_lidar_deviation_1;
- m_response_clamp_lidar_deviation_2 = tp_dispatch_response_from_plc_to_manager->m_response_clamp_lidar_deviation_2;
- m_response_clamp_lidar_deviation_3 = tp_dispatch_response_from_plc_to_manager->m_response_clamp_lidar_deviation_3;
- m_response_clamp_lidar_deviation_4 = tp_dispatch_response_from_plc_to_manager->m_response_clamp_lidar_deviation_4;
- /*
- std::cout << " huli test :::: " << " ------------------------------------------------------ = " << std::endl;
- std::cout << " huli test :::: " << " m_response_key = " << m_response_key << std::endl;
- std::cout << " huli test :::: " << " m_response_status = " << (int)m_response_status << std::endl;
- std::cout << " huli test :::: " << " m_response_dispatch_motion_direction = " << (int)m_response_dispatch_motion_direction << std::endl;
- std::cout << " huli test :::: " << " m_response_passageway_id = " << m_response_passageway_id << std::endl;
- std::cout << " huli test :::: " << " m_response_passageway_direction = " << (int)m_response_passageway_direction << std::endl;
- std::cout << " huli test :::: " << " m_response_parkingspace_index_id = " << m_response_parkingspace_index_id << std::endl;
- std::cout << " huli test :::: " << " m_response_parkingspace_unit_id = " << m_response_parkingspace_unit_id << std::endl;
- std::cout << " huli test :::: " << " m_response_parkingspace_floor_id = " << m_response_parkingspace_floor_id << std::endl;
- std::cout << " huli test :::: " << " m_response_parkingspace_room_id = " << m_response_parkingspace_room_id << std::endl;
- std::cout << " huli test :::: " << " m_response_parkingspace_direction = " << (int)m_response_parkingspace_direction << std::endl;
- std::cout << " huli test :::: " << " m_response_car_center_x = " << m_response_car_center_x << std::endl;
- std::cout << " huli test :::: " << " m_response_car_center_y = " << m_response_car_center_y << std::endl;
- std::cout << " huli test :::: " << " m_response_car_license = " << m_response_car_license << std::endl;
- */
- //状态消息, 调度->plc
- Dispatch_communication::Dispatch_plc_status_from_manager_to_plc * tp_dispatch_plc_status_from_manager_to_plc =
- & Dispatch_communication::get_instance_references().m_dispatch_plc_status_from_manager_to_plc;
- m_dispatch_heartbeat++;
- tp_dispatch_plc_status_from_manager_to_plc->m_dispatch_heartbeat = m_dispatch_heartbeat;
- //状态消息, plc->调度
- Dispatch_communication::Dispatch_plc_status_from_plc_to_manager * tp_dispatch_plc_status_from_plc_to_manager =
- & Dispatch_communication::get_instance_references().m_dispatch_plc_status_from_plc_to_manager;
- m_plc_heartbeat = tp_dispatch_plc_status_from_plc_to_manager->m_plc_heartbeat;
- m_plc_status_info = tp_dispatch_plc_status_from_plc_to_manager->m_plc_status_info;
- m_turnplate_angle_min1 = tp_dispatch_plc_status_from_plc_to_manager->m_turnplate_angle_min1;
- m_turnplate_angle_max1 = tp_dispatch_plc_status_from_plc_to_manager->m_turnplate_angle_max1;
- m_turnplate_angle_min2 = tp_dispatch_plc_status_from_plc_to_manager->m_turnplate_angle_min2;
- m_turnplate_angle_max2 = tp_dispatch_plc_status_from_plc_to_manager->m_turnplate_angle_max2;
- //need
- //通过心跳帧来判断通信是否正常
- // if ( m_last_heartbeat != tp_dispatch_plc_status_from_plc_to_manager->m_plc_heartbeat )
- // {
- // m_last_heartbeat = tp_dispatch_plc_status_from_plc_to_manager->m_plc_heartbeat;
- // m_status_updata_time = std::chrono::system_clock::now();
- //
- // if ( m_dispatch_plc_status == Dispatch_plc::Dispatch_plc_status::DISPATCH_PLC_DISCONNECT )
- // {
- // m_dispatch_plc_status = Dispatch_plc::Dispatch_plc_status::DISPATCH_PLC_READY;
- // }
- // }
- // else if(std::chrono::system_clock::now() - m_status_updata_time > std::chrono::milliseconds(COMMUNICATION_OVER_TIME_MS))
- // {
- // m_dispatch_plc_status = Dispatch_plc::Dispatch_plc_status::DISPATCH_PLC_DISCONNECT;
- // }
- //else 继续等待,直到消息刷新或者超时.
- return Error_code::SUCCESS;
- }
- //检查plc答复反馈
- Error_manager Dispatch_plc::check_response_from_plc()
- {
- // std::unique_lock<std::mutex> t_lock(m_lock);
- //
- //
- //#ifndef WAIT_PLC_RESPONSE
- // //need, 调试代码, 延时10s, 直接返回成功
- // if ( std::chrono::system_clock::now() - m_start_time > std::chrono::seconds(20) )
- // {
- // return Error_code::SUCCESS;
- // }
- // //返回没有收到数据
- // else
- // {
- // return Error_code::NODATA;
- // }
- //#endif
- //
- //
- //#ifdef WAIT_PLC_RESPONSE
- //
- // static bool s_update_flag = false;
- // //检查唯一码
- // if ( m_response_key == m_request_key )
- // {
- // //第一次同步时,刷新时间
- // if ( s_update_flag == false )
- // {
- // s_update_flag = true;
- // if ( m_dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_STORE_CAR )
- // {
- // std::unique_lock<std::mutex> t_lock(Dispatch_manager::get_instance_references().m_lock);
- // Dispatch_manager::get_instance_references().m_store_updata_time = std::chrono::system_clock::now();
- // }
- // else if( m_dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_PICKUP_CAR )
- // {
- // std::unique_lock<std::mutex> t_lock(Dispatch_manager::get_instance_references().m_lock);
- // Dispatch_manager::get_instance_references().m_pickup_updata_time = std::chrono::system_clock::now();
- // }
- // }
- //
- //
- // if(m_response_status == RESPONS_WORKING)
- // {
- // return Error_code::NODATA;//返回没有收到数据
- // }
- // else
- // {
- // std::cout<< "m_response_status = " << m_response_status << std::endl;
- // //如果故障,则添加错误码
- // if ( m_response_status != RESPONS_OVER )
- // {
- // //添加错误码
- // Error_manager t_error(DISPATCH_PLC_RESPONS_ERROR, MINOR_ERROR, " Dispatch_plc::check_response_from_plc() m_respons_status is error");
- // return t_error;
- // }
- //
- // return Error_code::SUCCESS;
- // }
- //
- // }
- // else
- // {
- // s_update_flag = false;
- // return Error_code::NODATA;//返回没有收到数据
- // }
- //#endif
- return Error_code::SUCCESS;
- }
- //检查plc答复反馈
- Error_manager Dispatch_plc::check_response_from_plc_new()
- {
- std::unique_lock<std::mutex> t_lock(m_lock);
- #ifndef WAIT_PLC_RESPONSE
- //need, 调试代码, 延时10s, 直接返回成功
- if ( std::chrono::system_clock::now() - m_start_time > std::chrono::seconds(10) )
- {
- return Error_code::SUCCESS;
- }
- //返回没有收到数据
- else
- {
- return Error_code::NODATA;
- }
- #endif
- #ifdef WAIT_PLC_RESPONSE
- static bool s_update_flag = false;
- //检查唯一码
- if ( m_response_key == m_request_key )
- {
- //20230213 huli add plc car_wheel_base
- m_plc_car_wheel_base = m_response_car_wheel_base_exact_value;
- m_plc_clamp_lidar_deviation_1 = m_response_clamp_lidar_deviation_1;
- m_plc_clamp_lidar_deviation_2 = m_response_clamp_lidar_deviation_2;
- m_plc_clamp_lidar_deviation_3 = m_response_clamp_lidar_deviation_3;
- m_plc_clamp_lidar_deviation_4 = m_response_clamp_lidar_deviation_4;
- //第一次同步时,刷新时间
- if ( s_update_flag == false )
- {
- s_update_flag = true;
- // if ( m_dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_STORE_CAR )
- // {
- // std::unique_lock<std::mutex> t_lock(Dispatch_manager::get_instance_references().m_lock);
- // Dispatch_manager::get_instance_references().m_store_updata_time = std::chrono::system_clock::now();
- // }
- // else if( m_dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_PICKUP_CAR )
- // {
- // std::unique_lock<std::mutex> t_lock(Dispatch_manager::get_instance_references().m_lock);
- // Dispatch_manager::get_instance_references().m_pickup_updata_time = std::chrono::system_clock::now();
- // }
- }
- if(m_response_status == RESPONS_WORKING)
- {
- return Error_code::NODATA;//返回没有收到数据
- }
- else
- {
- std::cout<< "m_response_status = " << m_response_status << std::endl;
- //如果故障,则添加错误码
- if ( m_response_status == RESPONS_OVER )
- {
- return Error_code::SUCCESS;
- }
- else if(m_response_status == RESPONS_REALLOCATE_MIN_CAR)
- {
- //重新分配小车
- return DISPATCH_PLC_REALLOCATE_MIN_CAR;
- }
- else if(m_response_status == RESPONS_REALLOCATE_MID_CAR)
- {
- //重新分配中车
- return DISPATCH_PLC_REALLOCATE_MID_CAR;
- }
- else if(m_response_status == RESPONS_REALLOCATE_BIG_CAR)
- {
- //重新分配大车
- return DISPATCH_PLC_REALLOCATE_BIG_CAR;
- }
- else if(m_response_status == RESPONS_REALLOCATE_HUGE_CAR)
- {
- //重新分配fault
- return DISPATCH_PLC_REALLOCATE_HUGE_CAR;
- }
- else if(m_response_status == RESPONS_REALLOCATE_FAULT_CAR)
- {
- //重新分配fault
- return DISPATCH_PLC_REALLOCATE_FAULT_CAR;
- }
- else //如果故障,则添加错误码
- {
- //添加错误码
- Error_manager t_error(DISPATCH_PLC_RESPONS_ERROR, MINOR_ERROR, " Dispatch_plc::check_response_from_plc() m_respons_status is error");
- return t_error;
- }
- }
- }
- else
- {
- s_update_flag = false;
- return Error_code::NODATA;//返回没有收到数据
- }
- #endif
- return Error_code::SUCCESS;
- }
- //发送调度答复信息给主控
- Error_manager Dispatch_plc::send_dispatch_response_to_main_control()
- {
- // std::unique_lock<std::mutex> t_lock(m_lock);
- // m_dispatch_response_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_response_msg);
- // m_dispatch_response_msg.mutable_base_info()->set_timeout_ms(m_dispatch_request_msg.base_info().timeout_ms());
- // m_dispatch_response_msg.mutable_base_info()->set_sender(message::Communicator::eDispatch_manager);
- // m_dispatch_response_msg.mutable_base_info()->set_receiver(message::Communicator::eMain);
- //
- // m_dispatch_response_msg.set_command_key(m_dispatch_request_msg.command_key());
- // m_dispatch_response_msg.set_dispatch_motion_direction(m_dispatch_request_msg.dispatch_motion_direction());
- // m_dispatch_response_msg.mutable_id_struct()->set_terminal_id(m_dispatch_request_msg.mutable_id_struct()->terminal_id());
- // m_dispatch_response_msg.mutable_id_struct()->set_unit_id(m_dispatch_request_msg.mutable_id_struct()->unit_id());
- // m_dispatch_response_msg.mutable_locate_information()->CopyFrom(m_dispatch_request_msg.locate_information());
- // m_dispatch_response_msg.mutable_parkspace_info_ex()->CopyFrom(m_dispatch_request_msg.parkspace_info_ex());
- // m_dispatch_response_msg.set_car_type(m_dispatch_request_msg.car_type());
- //
- // if ( m_dispatch_response_msg.dispatch_motion_direction() == message::E_STORE_CAR )
- // {
- // for (int i = 0; i < m_dispatch_response_msg.parkspace_info_ex_size(); ++i)
- // {
- // if ( m_result == Error_code::SUCCESS )
- // {
- // m_dispatch_response_msg.mutable_parkspace_info_ex(i)->set_parkspace_status_target(message::Parkspace_status::eParkspace_occupied);
- // }
- // else
- // {
- // m_dispatch_response_msg.mutable_parkspace_info_ex(i)->set_parkspace_status_target(message::Parkspace_status::eParkspace_empty);
- // }
- // }
- // }
- // else if( m_dispatch_response_msg.dispatch_motion_direction() == message::E_PICKUP_CAR )
- // {
- // for (int i = 0; i < m_dispatch_response_msg.parkspace_info_ex_size(); ++i)
- // {
- // if ( m_result == Error_code::SUCCESS )
- // {
- // m_dispatch_response_msg.mutable_parkspace_info_ex(i)->set_parkspace_status_target(message::Parkspace_status::eParkspace_empty);
- // }
- // else
- // {
- // m_dispatch_response_msg.mutable_parkspace_info_ex(i)->set_parkspace_status_target(message::Parkspace_status::eParkspace_occupied);
- // }
- // }
- // }
- //
- //
- // m_dispatch_response_msg.mutable_error_manager()->set_error_code(m_result.get_error_code());
- // m_dispatch_response_msg.mutable_error_manager()->set_error_level((message::Error_level)m_result.get_error_level());
- // m_dispatch_response_msg.mutable_error_manager()->set_error_description(m_result.get_error_description());
- //
- //
- // std::cout << " huli test :::: " << " m_dispatch_response_msg = " << m_dispatch_response_msg.DebugString()<< std::endl;
- //
- // std::string t_msg = m_dispatch_response_msg.SerializeAsString();
- // System_communication::get_instance_references().encapsulate_task_msg(t_msg);
- return Error_code::SUCCESS;
- }
- //发送调度答复信息给主控
- Error_manager Dispatch_plc::send_dispatch_response_to_main_control_new()
- {
- // std::unique_lock<std::mutex> t_lock(m_lock);
- //
- // std::string t_msg;
- // if ( m_dispatch_process_type == Common_data::Dispatch_process_type::DISPATCH_PROCESS_STORE )
- // {
- // measure_info t_measure_info = m_park_table_msg.entrance_measure_info();
- // m_park_table_msg.mutable_actually_measure_info()->CopyFrom(t_measure_info);
- // parkspace_info t_parkspace_info = m_park_table_msg.allocated_space_info();
- // m_park_table_msg.mutable_actually_space_info()->CopyFrom(t_parkspace_info);
- // //存车真实轴距
- // m_park_table_msg.mutable_actually_measure_info()->set_wheelbase(m_response_car_wheel_base_exact_value);
- //
- // if ( m_result != Error_code::SUCCESS )
- // {
- // std::string t_error_string = m_result.to_string();
- // m_park_table_msg.mutable_statu()->set_execute_statu(eError);
- // m_park_table_msg.mutable_statu()->set_statu_description(t_error_string);
- // }
- // t_msg = m_park_table_msg.DebugString();
- // }
- // else if ( m_dispatch_process_type == Common_data::Dispatch_process_type::DISPATCH_PROCESS_PICKUP )
- // {
- // m_pick_table_msg.set_export_id(1);
- // if ( m_result != Error_code::SUCCESS )
- // {
- // std::string t_error_string = m_result.to_string();
- // m_pick_table_msg.mutable_statu()->set_execute_statu(eError);
- // m_pick_table_msg.mutable_statu()->set_statu_description(t_error_string);
- // }
- // t_msg = m_pick_table_msg.DebugString();
- // }
- //
- // System_communication::get_instance_references().encapsulate_task_msg(t_msg, 1);
- // std::cout << " huli test :::: " << " m_command_completed_msg = " << t_msg << std::endl;
- // Dispatch_manager::get_instance_references().ack_rabbitmq_message_new();
- return Error_code::SUCCESS;
- }
|