#include #include #include #include #include "db_api/CDBSingletonDefine.h" #include "websocket/wsClientMgr.h" #include "websocket/wsTimerThread.h" #include "card.h" #include "ant.h" #include "area.h" #include "card_path.h" #include "landmark.h" #include "special_area.h" #include "mine.h" #include "event.h" #include "module_service/module_mgr.h" #include #include "three_rates.h" #include "mine_business.h" #include "sys_setting.h" #include "websocket/web_connect.h" #include "forbid_staff_down_mine.h" #include "bulletin_broad_show.h" #include "sync_time/sync_manager.h" #include "module_service/module_traffic_light_manager.h" config_file config; void handlereader(uint32_t readerid,bool duration,uint32_t t) {} //三率模块中告警回调 void Handle_ThreeRates_Event_Callback(const int evType, const int evId, uint64_t id , double limitVal, double curVal, bool bFalg) { if (evId >= EVENT_TYPE::CARD_EVENT_COUNT_MAX || evType > OBJECT_TYPE::OT_CARD) { return ; } event_tool::instance()->handle_event((OBJECT_TYPE)evType,(EVENT_TYPE)evId,id,limitVal,curVal,bFalg); } struct Init_Setting { // 初始化系统参数 void init() { three_rates_flag = config.get("service.three_rates_flag", 0); traffic_light_flag = config.get("service.traffic_light_flag", 0); anti_coll_flag = config.get("service.anti_collision_flag", 0); use_original_algo = config.get("algo.use_original_algo", 0); YADB::_DB_POOL_SETTING_ DBSetting; DBSetting.Host = config.get("db.host","127.0.0.1"); DBSetting.User = config.get("db.user","root"); DBSetting.PWD = config.get("db.passwd","123456"); DBSetting.DBName = config.get("db.dbname","yaxt"); DBSetting.CharSet = config.get("db.charset","utf8"); DBSetting.TimeOut = config.get("db.conn_timeout",5); DBSetting.PoolSize = config.get("db.pool_size",30); DBSetting.Port = config.get("db.port",3306); if(!_mysql_init(DBSetting)) { std_info("连接DB[%s:%s] 失败,采集服务器无法启动!",DBSetting.Host.c_str(),DBSetting.User.c_str()); log_warn("连接DB[%s:%s] 失败,采集服务器无法启动!",DBSetting.Host.c_str(),DBSetting.User.c_str()); exit(0); } log_info("数据库线程池创建成功"); std::string url = config.get("service.websocket_url","ws://127.0.0.1:8086"); std::string url_2 = config.get("service.websocket_url_bak",""); int32_t send_interval = config.get("service.interval_send_json_postion",1); std_info("json_interval:%d,[%s]",send_interval,url.c_str()); std::vector url_list; url_list.push_back(url); if(!url_2.empty()) url_list.push_back(url_2); if(!wsClientMgr_init(url_list, send_interval)) { std_info("连接webServer[%s] 失败,采集服务器无法启动!",url.c_str()); log_warn("连接webServer[%s] 失败!",url.c_str()); } CYaSetting::Init_sys_setting(); CYaSetting::m_sys_setting.m_enable_anti_coll = anti_coll_flag; //公告牌功能 //bulletin_broad_show::inst()->OnInit(&config); sit_list::instance()->load_from_db(); card_list::instance()->init_card_from_db(); area_list::instance()->init_from_db(); area_list::instance()->init_area_persons_dynamic_thre_from_db(); //forbid_staff_down_mine::instance()->init_forbid_staff(); //Landmark_list::instance()->init_from_db(); //special_area_list::instance()->init_from_db(); mine_business::inst()->load(); card_list::instance()->load_his_card_postion_from_db(); event_list::instance()->load_his_data_from_db(true); if(three_rates_flag){ db_para dp; dp.Host = DBSetting.Host; dp.User = DBSetting.User; dp.PWD = DBSetting.PWD ; dp.DBName = DBSetting.DBName; dp.CharSet = DBSetting.CharSet ; dp.TimeOut = DBSetting.TimeOut; dp.PoolSize = DBSetting.PoolSize; init_three_rates(dp); } if(traffic_light_flag){ init_traffic_light(); } // tdoa基站天线间时间同步数据 //init_ant_sync(); log_info("Init_Setting::init Success. \n" ); } void init_three_rates(const db_para& dbs) { log_info("init three_rates ..................."); init_para ip; ip.send_pt = handlereader; ip.driving_face_alarm = Handle_ThreeRates_Event_Callback; three_rates::get_instance()->init(ip,dbs); three_rates::get_instance()->start(); std_info("加载三率模块成功"); } void init_traffic_light() { log_info("init traffic_light ..................."); traffic_light_manager::instance()->init(CYaSetting::m_sys_setting.light_group_count); traffic_light_manager::instance()->start(); std_info("成功加载信号灯模块"); } bool _mysql_init(YADB::_DB_POOL_SETTING_ &dps) { std::string szError = ""; bool flag = true; //创建连接池 if ( !sDBConnPool.Create( dps, szError ) ) { log_error("数据库线程池创建失败,Err=%s", szError.c_str()); std_error("数据库线程池创建失败,Err=%s", szError.c_str()); flag = false; } return flag; } bool wsClientMgr_init(const std::vector&uri_list,int32_t st) { std::map MsgFuncList; module_mgr::init(config, MsgFuncList); web_connect::init(uri_list, st, MsgFuncList); return web_connect::connect(); } // 初始化时间同步内的天线间距离信息 void init_ant_sync() { for(auto site : sit_list::instance()->m_map){ ssync_manager.update_anchor(site.second->m_id, 1, site.second->m_ant[0].x, site.second->m_ant[0].y, site.second->m_ant[0].z); } double d = 0.0; for(auto it = ssync_manager.ump_anchors.begin(); it != ssync_manager.ump_anchors.end(); ++it){ for(auto it2 = std::next(it,1);it2 != ssync_manager.ump_anchors.end(); ++it2){ d = sqrt(pow((it->second.x - it2->second.x),2) + pow((it->second.y - it2->second.y),2) + pow((it->second.z - it2->second.z),2)) * 10000 / (2.99702547 * 15.65); ssync_manager.update_distance(it->first>>8, it->first&0xFF, it2->first>>8, it2->first&0xFF, d); } } } }; /* * @brief 停止业务模块和websocket server的连接 * @param 无 * @return 无 * @note * @warning * @bug * */ void cleanup() { module_mgr::stop(); web_connect::close(); } void usage(char ** argv) { std::string cmd(argv[1]); if(cmd=="--help" || cmd == "-H") { printf("用法:yals [选项]文件...\n"); printf("选项:\n"); printf("--help 显示此帮助说明\n"); printf("-v|--version 显示采集程序版本信息\n"); } else if(cmd == "--version" || cmd == "-v") { printf("zhuhai xinxingxin data collector server (采集程序) 1.3.0 build 11\n"); } else { printf("Unknown option:%s\n",cmd.c_str()); printf( "usage:yals [--version][--help][-v][-H]\n"); } } /* * @brief 主程序入口 * @param [in] int argc * @param [in] char* argv[] * @return 0表示正常运行,非零值表示错误 * @note * @warning * @bug * */ int main(int argc ,char * argv[]) { if(argc >1) { usage(argv); return 0; } // 加载共享内存 log_init("../etc/log.ini"); if(config.open("../etc/config.ini")) return -1; // 系统初始化 Init_Setting is; is.init(); // 业务模块服务启动 module_mgr::start(); //web_connect::start_beatheart_monitor(); //atexit(&cleanup); // 提供数据给第三方服务 int interface_port = config.get("service.interface_port",7001); log_info("service-position.run(%d)",interface_port); std_info("service-position.run(%d)",interface_port); ios_service::start_service_position(interface_port); // 启动网络模块服务 net_service mh; int port = config.get("service.port",4000); log_info("service_handle::instance(&mh)->run(%d)",port); std_info("service_handle::instance(&mh)->run(%d)",port); service_handle::instance(&mh)->run(port); // 关闭数据库连接池 sDBConnPool.Close(); sleep(1); printf("Collector Server Exit ...\n"); return 0; }