// // Created by zx on 2020/1/3. // #include "System_Manager.h" #include #include #include #include #include using google::protobuf::io::FileInputStream; using google::protobuf::io::FileOutputStream; using google::protobuf::io::ZeroCopyInputStream; using google::protobuf::io::CodedInputStream; using google::protobuf::io::ZeroCopyOutputStream; using google::protobuf::io::CodedOutputStream; using google::protobuf::Message; System_Manager::System_Manager() { m_laser_vector.clear(); m_terminal_vector.clear(); mp_plc=NULL; mp_locater=NULL; mp_verify_result_tool=NULL; mp_wj_controller=NULL; } System_Manager::~System_Manager() { //第一步, 清除流程,保证不会再调用plc,然后最先析构plc,防止回调崩溃 for(int i=0;iforce_stop_command(); } } //析构plc if(mp_plc!=NULL) { delete mp_plc; mp_plc=NULL; } //第二步析构terminor for(int i=0;iconnect_laser()!=SUCCESS) { char description[255]={0}; sprintf(description,"Laser %d connect failed...",i); return Error_manager(LASER_CONNECT_FAILED,NORMAL,description); } } } //查询是否有livox雷达,初始化库 for (int i = 0; i < laser_parameters.laser_parameters_size(); ++i) { std::string type = laser_parameters.laser_parameters(i).type(); if (type.find("Livox") != type.npos) { if (Start() == false) { Uninit(); return Error_manager(LASER_LIVOX_SKD_INIT_FAILED,NORMAL,"Livox laser init failed..."); } break; } } //创建limit模块 mp_verify_result_tool=new Verify_result(hardware_parameter); LOG(WARNING)<<"0 verify addr : "<initialize(wj_parameter); if(code!=SUCCESS) { return code; }*/ //创建测量模块 mp_locater=new Locater(); code=mp_locater->init(locater_parameter); if(code!=SUCCESS) { return code; } //创建terminor int terminor_count=terminor_parameter_all.terminor_parameters_size(); if(terminor_count<=0) { return Error_manager(SYSTEM_PARAMETER_ERROR,NORMAL,"parameter error terminor num is 0"); } m_terminal_vector.resize(terminor_count); for(int i=0;iset_save_root_path(terminor_parameter_all.save_root_path()); } //最后创建plc,连接,设置回调 /*mp_plc=new Plc_Communicator(plc_parameter); code=mp_plc->get_error(); if(code!=SUCCESS) { code.set_error_description("plc create error"); return code; } code=mp_plc->set_plc_callback(plc_command_callback,this);*/ plc_command_callback(1,this); return code; } //plc指令回调函数,当plc收到测量指令后,调用此回调函数 //terminal_id:收到指令的终端编号 //owner:this指针 Error_manager System_Manager::plc_command_callback(int terminal_id_plc,void* owner) { int terminal_id=terminal_id_plc-1; Error_manager code; LOG(INFO)<<"RECEIVE terminal command , ID : "<=system_manager->m_terminal_vector.size()) { char description[255]={0}; sprintf(description,"terminal command id(%d) out of range, terminal size:%d", terminal_id,system_manager->m_terminal_vector.size()); return Error_manager(PARAMETER_ERROR,NEGLIGIBLE_ERROR,description); } //第二步,根据terminal_id,启动对应terminaor执行指令流程, if(system_manager->m_laser_vector.size()==0) { return Error_manager(SYSTEM_INPUT_TERMINOR_NO_LASERS,NORMAL,"laser parameter has no laser"); } if(system_manager->mp_wj_controller==NULL) { Error_manager(PARAMETER_ERROR,NEGLIGIBLE_ERROR,"wj lidar is null"); } code=system_manager->m_terminal_vector[terminal_id]->execute_command(system_manager->m_laser_vector, system_manager->mp_wj_controller, system_manager->mp_plc,system_manager->mp_locater,system_manager->mp_verify_result_tool,10); switch(code.get_error_code()) { case SUCCESS:break; case TERMINOR_CREATE_WORKING_THREAD_FAILED: { LOG(ERROR)<