tr_tool.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. #ifndef TR_TOOL_H
  2. #define TR_TOOL_H
  3. #include <map>
  4. #include <boost/circular_buffer.hpp>
  5. enum THREE_RATES_CARD_TYPE
  6. {
  7. CT_NONE = 0,
  8. CT_PERSON = 1,
  9. CT_COALMINING_MACHINE = 4, //采煤机
  10. CT_TUNNELBORING_MACHINE = 5 //掘进机
  11. };
  12. enum THREE_RATES_VEHICLE_TYPE
  13. {
  14. E_VEHICLE_COALMINING = 25, //采煤机
  15. E_VEHICLE_DRIVING = 26 //掘进机
  16. };
  17. enum E_THREE_VEHICLE_TYPE
  18. {
  19. E_COALMINING_DRIVER = 16, //采煤机司机
  20. E_DRIVING_DRIVER = 40 //掘进机司机
  21. };
  22. struct coaldrivingface_card
  23. {
  24. std::string m_scard_id; // card id
  25. int m_nvehicle_id; // vehicle id
  26. bool m_bopen; // vehicle open/close status
  27. time_t m_tstartup_time; // start time
  28. int m_ncard_type; // card type
  29. int m_ndept_id; // department id
  30. int m_vehicle_type; // 车类型
  31. int m_work_face_id; // 工作面ID
  32. uint32_t id;
  33. uint64_t rec_time;
  34. double x;
  35. double y;
  36. double z;
  37. double final_v;
  38. int m_nshake_threshold; // shake threshold
  39. boost::circular_buffer<int> m_cb_state; // vibrate state value
  40. coaldrivingface_card()
  41. {
  42. m_cb_state.set_capacity(10); // 设置10个开关机标志位,10个中有7个为1则为开机,有7个为0则为关机
  43. for (int index = 0; index < 10; index++)// 循环队列初始化
  44. {
  45. m_cb_state.push_back(0);
  46. }
  47. m_tstartup_time = 0;
  48. m_bopen = false;
  49. m_nvehicle_id = 0;
  50. m_scard_id = "";
  51. m_ncard_type = CT_NONE;
  52. m_ndept_id = -1;
  53. m_nshake_threshold = 10;
  54. id = 0;
  55. rec_time = 0;
  56. x = y = z = final_v =0;
  57. m_vehicle_type = 0;
  58. }
  59. };
  60. struct ChangedDBDate
  61. {
  62. ChangedDBDate()
  63. :webname("")
  64. , param("")
  65. , edit_type_id(0)
  66. {
  67. }
  68. void copy(const ChangedDBDate & Db)
  69. {
  70. *this = Db;
  71. }
  72. //数据类型
  73. std::string webname;
  74. //参数
  75. std::string param;
  76. //更改类型,0 新增,1 修改,2 删除
  77. int edit_type_id;
  78. };
  79. //综采面信息
  80. class CoalMiningArea
  81. {
  82. public:
  83. //区域编号
  84. int coalface_id;
  85. //综采面端点1
  86. double x1;
  87. double y1;
  88. //综采面端点2
  89. double x2;
  90. double y2;
  91. //认为到达端点的距离范围
  92. double distance;
  93. //采煤机的坐标偏移量,单位是像素
  94. double m_x_offset;
  95. double m_y_offset;
  96. double m_max_distance;
  97. CoalMiningArea()
  98. {
  99. coalface_id = 0;
  100. x1 = x2 = y1 = y2 = 0.0;
  101. m_max_distance=0.0;
  102. }
  103. };
  104. //挖煤机正规循环率的中间参数
  105. class CoalMiningRegularCycle
  106. {
  107. public:
  108. //卡Id
  109. int vehicle_id;
  110. //区域编号
  111. int coalface_id;
  112. //是否开始计算
  113. bool IsWorking;
  114. //半刀计数标记
  115. bool bHalfKnife;
  116. //目标点序号
  117. int bDirection;
  118. //上次发送位置时间
  119. time_t last_time;
  120. //开始时间;
  121. time_t start_time;
  122. //记录最小距离的时间
  123. time_t mindis_time;
  124. //离目标点的最小距离
  125. double mindistance;
  126. //计划刀数
  127. double schedule_times;
  128. //开始位置
  129. double start_x;
  130. double start_y;
  131. //结束位置
  132. double end_x;
  133. double end_y;
  134. //时间和位置记录
  135. //std::string pos_record;
  136. double avg_distance;
  137. int dis_num;
  138. CoalMiningRegularCycle()
  139. {
  140. vehicle_id = coalface_id = bDirection= 0;
  141. IsWorking = false;
  142. last_time = start_time = mindis_time = 0;
  143. schedule_times = start_x =start_y = end_x = end_y=avg_distance=0;
  144. dis_num=0;
  145. }
  146. };
  147. //挖煤机每刀详细参数
  148. class CoalminingRegularCycleDetail
  149. {
  150. public:
  151. int vehicle_id;// 卡号;
  152. //区域编号 (工作面--work_face_id(dat_work_face)
  153. int coalface_id;
  154. time_t start_time;//开始时间;
  155. time_t end_time;//结束时间;
  156. int dept_id;//对应队组ID;
  157. double start_x;//开始x坐标;
  158. double start_y;//开始y坐标;
  159. double end_x;//结束x坐标;
  160. double end_y;//结束y坐标;
  161. int move_direction;
  162. CoalminingRegularCycleDetail()
  163. {
  164. vehicle_id = dept_id = coalface_id = 0;
  165. start_time = end_time = 0;
  166. start_x = start_y = end_x = end_y = 0.0;
  167. }
  168. };
  169. class tr_helper
  170. {
  171. public:
  172. /*
  173. * Functon: String switch to time_t
  174. * Parameters: str, string
  175. * Returns: time_t
  176. * Throws: void
  177. */
  178. static time_t string_switch_time_t(const std::string& str)
  179. {
  180. struct tm tm_time;
  181. time_t t_time;
  182. sscanf(str.c_str(), "%d-%d-%d %d:%d:%d" ,
  183. &(tm_time.tm_year),
  184. &(tm_time.tm_mon),
  185. &(tm_time.tm_mday),
  186. &(tm_time.tm_hour),
  187. &(tm_time.tm_min),
  188. &(tm_time.tm_sec));
  189. tm_time.tm_year -= 1900;
  190. tm_time.tm_mon--;
  191. tm_time.tm_isdst = -1;
  192. t_time = mktime(&tm_time);
  193. return t_time;
  194. }
  195. /*
  196. * Functon: time_t switch to string
  197. * Parameters: time, time_t
  198. * Returns: string
  199. * Throws: void
  200. */
  201. static std::string time_t_switch_string(const time_t& time)
  202. {
  203. std::string str;
  204. char tmp[64];
  205. strftime(tmp, sizeof(tmp), "%Y-%m-%d %X", localtime(&time));
  206. str = tmp;
  207. return str;
  208. }
  209. /*
  210. * Functon: time_t switch to string
  211. * Parameters: type, int32_t; id, uint32_t
  212. * Returns: string
  213. * Throws: void
  214. */
  215. static std::string merge_typy_id_to_card(int32_t type, uint32_t id)
  216. {
  217. char tmp[15] = {'\0'};
  218. sprintf(tmp, "%03d%010d", type, id);
  219. return std::string(tmp);
  220. }
  221. /*
  222. * Functon: time_t switch to data
  223. * Parameters: t, time_t
  224. * Returns: string
  225. * Throws: void
  226. */
  227. static std::string time_t2string_date(const time_t& t)
  228. {
  229. struct tm *p = NULL;
  230. char buf[30] = {0};
  231. if (t == 0 || t == -1)
  232. {
  233. return "0";
  234. }
  235. p = localtime(&t);
  236. snprintf(buf,
  237. sizeof(buf),
  238. "%04d-%02d-%02d",
  239. p->tm_year + 1900,p->tm_mon + 1,p->tm_mday);
  240. std::string str = "";
  241. str = buf;
  242. return str;
  243. }
  244. static bool is_coalminingface(int _type)
  245. {
  246. if (_type == THREE_RATES_CARD_TYPE::CT_COALMINING_MACHINE
  247. || _type == THREE_RATES_VEHICLE_TYPE::E_VEHICLE_COALMINING)
  248. {
  249. return true;
  250. }
  251. return false;
  252. }
  253. static bool is_coalminingface(const std::shared_ptr<coaldrivingface_card> &_card)
  254. {
  255. if (_card->m_ncard_type == THREE_RATES_CARD_TYPE::CT_COALMINING_MACHINE
  256. || _card->m_vehicle_type == THREE_RATES_VEHICLE_TYPE::E_VEHICLE_COALMINING)
  257. {
  258. return true;
  259. }
  260. return false;
  261. }
  262. static bool is_drivingface(int _type)
  263. {
  264. if (_type == THREE_RATES_VEHICLE_TYPE::E_VEHICLE_DRIVING
  265. || _type == THREE_RATES_CARD_TYPE::CT_TUNNELBORING_MACHINE)
  266. {
  267. return true;
  268. }
  269. return false;
  270. }
  271. static bool is_drivingface(const std::shared_ptr<coaldrivingface_card> &_card)
  272. {
  273. if (_card->m_ncard_type == THREE_RATES_CARD_TYPE::CT_TUNNELBORING_MACHINE
  274. || _card->m_vehicle_type == THREE_RATES_VEHICLE_TYPE::E_VEHICLE_DRIVING)
  275. {
  276. return true;
  277. }
  278. return false;
  279. }
  280. public:
  281. static const int SQL_LENGTH = 2000;
  282. };
  283. typedef std::map<int,std::shared_ptr<coaldrivingface_card>> coaldrivingface_map;
  284. typedef std::map<int,std::shared_ptr<CoalMiningArea> > CoalMiningAreaMap; //综采面区域信息
  285. typedef std::map<int,std::shared_ptr<CoalMiningRegularCycle>> CoalMiningRegularCycleMap;//采煤机正规循环率计算参数,编号和参数
  286. typedef std::map<int, int> CoalWorkfaceVehicleMap; // 采煤机工作面与车卡绑定表
  287. #endif