#ifndef TR_TOOL_H #define TR_TOOL_H #include #include enum THREE_RATES_CARD_TYPE { CT_NONE = 0, CT_PERSON = 1, CT_COALMINING_MACHINE = 4, //采煤机 CT_TUNNELBORING_MACHINE = 5 //掘进机 }; enum THREE_RATES_VEHICLE_TYPE { E_VEHICLE_COALMINING = 25, //采煤机 E_VEHICLE_DRIVING = 26 //掘进机 }; enum E_THREE_VEHICLE_TYPE { E_COALMINING_DRIVER = 16, //采煤机司机 E_DRIVING_DRIVER = 40 //掘进机司机 }; struct coaldrivingface_card { std::string m_scard_id; // card id int m_nvehicle_id; // vehicle id bool m_bopen; // vehicle open/close status time_t m_tstartup_time; // start time int m_ncard_type; // card type int m_ndept_id; // department id int m_vehicle_type; // 车类型 int m_work_face_id; // 工作面ID uint32_t id; uint64_t rec_time; double x; double y; double z; double final_v; int m_nshake_threshold; // shake threshold boost::circular_buffer m_cb_state; // vibrate state value coaldrivingface_card() { m_cb_state.set_capacity(10); // 设置10个开关机标志位,10个中有7个为1则为开机,有7个为0则为关机 for (int index = 0; index < 10; index++)// 循环队列初始化 { m_cb_state.push_back(0); } m_tstartup_time = 0; m_bopen = false; m_nvehicle_id = 0; m_scard_id = ""; m_ncard_type = CT_NONE; m_ndept_id = -1; m_nshake_threshold = 10; id = 0; rec_time = 0; x = y = z = final_v =0; m_vehicle_type = 0; } }; struct ChangedDBDate { ChangedDBDate() :webname("") , param("") , edit_type_id(0) { } void copy(const ChangedDBDate & Db) { *this = Db; } //数据类型 std::string webname; //参数 std::string param; //更改类型,0 新增,1 修改,2 删除 int edit_type_id; }; //综采面信息 class CoalMiningArea { public: //区域编号 int coalface_id; //综采面端点1 double x1; double y1; //综采面端点2 double x2; double y2; //认为到达端点的距离范围 double distance; //采煤机的坐标偏移量,单位是像素 double m_x_offset; double m_y_offset; double m_max_distance; CoalMiningArea() { coalface_id = 0; x1 = x2 = y1 = y2 = 0.0; m_max_distance=0.0; } }; //挖煤机正规循环率的中间参数 class CoalMiningRegularCycle { public: //卡Id int vehicle_id; //区域编号 int coalface_id; //是否开始计算 bool IsWorking; //半刀计数标记 bool bHalfKnife; //目标点序号 int bDirection; //上次发送位置时间 time_t last_time; //开始时间; time_t start_time; //记录最小距离的时间 time_t mindis_time; //离目标点的最小距离 double mindistance; //计划刀数 double schedule_times; //开始位置 double start_x; double start_y; //结束位置 double end_x; double end_y; //时间和位置记录 //std::string pos_record; double avg_distance; int dis_num; CoalMiningRegularCycle() { vehicle_id = coalface_id = bDirection= 0; IsWorking = false; last_time = start_time = mindis_time = 0; schedule_times = start_x =start_y = end_x = end_y=avg_distance=0; dis_num=0; } }; //挖煤机每刀详细参数 class CoalminingRegularCycleDetail { public: int vehicle_id;// 卡号; //区域编号 (工作面--work_face_id(dat_work_face) int coalface_id; time_t start_time;//开始时间; time_t end_time;//结束时间; int dept_id;//对应队组ID; double start_x;//开始x坐标; double start_y;//开始y坐标; double end_x;//结束x坐标; double end_y;//结束y坐标; int move_direction; CoalminingRegularCycleDetail() { vehicle_id = dept_id = coalface_id = 0; start_time = end_time = 0; start_x = start_y = end_x = end_y = 0.0; } }; class tr_helper { public: /* * Functon: String switch to time_t * Parameters: str, string * Returns: time_t * Throws: void */ static time_t string_switch_time_t(const std::string& str) { struct tm tm_time; time_t t_time; sscanf(str.c_str(), "%d-%d-%d %d:%d:%d" , &(tm_time.tm_year), &(tm_time.tm_mon), &(tm_time.tm_mday), &(tm_time.tm_hour), &(tm_time.tm_min), &(tm_time.tm_sec)); tm_time.tm_year -= 1900; tm_time.tm_mon--; tm_time.tm_isdst = -1; t_time = mktime(&tm_time); return t_time; } /* * Functon: time_t switch to string * Parameters: time, time_t * Returns: string * Throws: void */ static std::string time_t_switch_string(const time_t& time) { std::string str; char tmp[64]; strftime(tmp, sizeof(tmp), "%Y-%m-%d %X", localtime(&time)); str = tmp; return str; } /* * Functon: time_t switch to string * Parameters: type, int32_t; id, uint32_t * Returns: string * Throws: void */ static std::string merge_typy_id_to_card(int32_t type, uint32_t id) { char tmp[15] = {'\0'}; sprintf(tmp, "%03d%010d", type, id); return std::string(tmp); } /* * Functon: time_t switch to data * Parameters: t, time_t * Returns: string * Throws: void */ static std::string time_t2string_date(const time_t& t) { struct tm *p = NULL; char buf[30] = {0}; if (t == 0 || t == -1) { return "0"; } p = localtime(&t); snprintf(buf, sizeof(buf), "%04d-%02d-%02d", p->tm_year + 1900,p->tm_mon + 1,p->tm_mday); std::string str = ""; str = buf; return str; } static bool is_coalminingface(int _type) { if (_type == THREE_RATES_CARD_TYPE::CT_COALMINING_MACHINE || _type == THREE_RATES_VEHICLE_TYPE::E_VEHICLE_COALMINING) { return true; } return false; } static bool is_coalminingface(const std::shared_ptr &_card) { if (_card->m_ncard_type == THREE_RATES_CARD_TYPE::CT_COALMINING_MACHINE || _card->m_vehicle_type == THREE_RATES_VEHICLE_TYPE::E_VEHICLE_COALMINING) { return true; } return false; } static bool is_drivingface(int _type) { if (_type == THREE_RATES_VEHICLE_TYPE::E_VEHICLE_DRIVING || _type == THREE_RATES_CARD_TYPE::CT_TUNNELBORING_MACHINE) { return true; } return false; } static bool is_drivingface(const std::shared_ptr &_card) { if (_card->m_ncard_type == THREE_RATES_CARD_TYPE::CT_TUNNELBORING_MACHINE || _card->m_vehicle_type == THREE_RATES_VEHICLE_TYPE::E_VEHICLE_DRIVING) { return true; } return false; } public: static const int SQL_LENGTH = 2000; }; typedef std::map> coaldrivingface_map; typedef std::map > CoalMiningAreaMap; //综采面区域信息 typedef std::map> CoalMiningRegularCycleMap;//采煤机正规循环率计算参数,编号和参数 typedef std::map CoalWorkfaceVehicleMap; // 采煤机工作面与车卡绑定表 #endif