classdef.h 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765
  1. #ifndef YASERVER_CLASSDEF_H_
  2. #define YASERVER_CLASSDEF_H_
  3. #define MAX_DIST_CACHE 4 //5
  4. #define DIST_COUNT 4
  5. #define ANCHOR_COUNT 4
  6. #define MINE_EVENT_COUNT 3
  7. #define SECTION_EVENT_COUNT 6
  8. #define AREA_EVENT_COUNT 5
  9. #define CARD_EVENT_COUNT 30
  10. #define READER_EVENT_COUNT 12
  11. #define KALMAN_OFFSET_COOR 0.01
  12. #define KALMAN_OFFSET_MOVE 1
  13. #define KALMAN_OFFSET_RANGING 0.01
  14. #define KALMAN_INTERVAL 0.3
  15. #define KALMAN_OFFSET_COOR_TRI 0.01
  16. #define KALMAN_OFFSET_MOVE_TRI 1
  17. #define KALMAN_OFFSET_RANGING_TRI 0.09
  18. #define KALMAN_INTERVAL_TRI 1
  19. #define ANTENNA_COUNT 2
  20. #define ADHOC_COUNT 10
  21. #define READER_TIMEOUT 20
  22. #define CARD_LOST_TIME_OUT 30 // (30 * 60)
  23. #define CARD_LOST_TIME_OUT_SPECIAL_AREA 1800
  24. #define READER_SEND_STATE_TIMEOUT 30 // (2* 60 * 60)
  25. #define OVER_TIME (480 * 60)
  26. //#define CARD_TYPE_ADHOC 3
  27. #define MAX_SEMACOUNT 64
  28. //#define INVALID_COORDINATE -1
  29. //算法类型
  30. //#define ALGORITHM_TYPE_TOF
  31. #define ALGORITHM_TYPE_TDOA
  32. //#define ALGORITHM_TYPE_INS //使用惯导判断
  33. #define ENABLE_MY_LOG
  34. #include <string>
  35. #include <ctime>
  36. #include <map>
  37. #include <iostream>
  38. #include <string>
  39. #include <vector>
  40. #include <unordered_map>
  41. #include <deque>
  42. #include <mutex>
  43. #include <thread>
  44. //#include "winsock2.h"
  45. #include <kalman\locate.h>
  46. #include "Filter\KalmanFilter.h"
  47. #include "algorithm\FittingPosition.h"
  48. #include "algorithm/cell/cell_struct.h"
  49. #include "LocateRecord.h"
  50. #define MIN(x,y) (x < y ? x : y)
  51. #define MAX(x,y) (x > y ? x : y)
  52. using namespace std;
  53. //算法中使用的常量定义
  54. const int MAX_CALC_POINTS = 30;
  55. const double INS_WEIGHT = 9.0; //惯导权重
  56. const double UWB_WEIGHT = 1.0; //UWB权重
  57. const double MAX_VECHILE_SPEED = 30.0; //25
  58. const double NEAR_READER = 4.0;
  59. const double MIN_DIFFER_DISTANCE = 10.0;
  60. const double VECHILE_ACCELERATE_THRESHOLD = 10;
  61. const double PERSON_ACCELERATE_THRESHOLD = 10;
  62. const int ACCELERATE_INIT_STATE = -10;
  63. const double INVALID_COORDINATE = -1000.0;
  64. const double CHAMBER_WIDTH = 10.0; //特指前端展现巷道的宽度,单位为像素
  65. const double VEHICLE_WIDTH = 10.0;
  66. const int MAX_READER_TDOA_PATH_NUMS = 10; //主要是因为拐弯处可能存在多解的原因
  67. const int LIGHT_CTRL_DELAY = 1000;
  68. const int MAX_REBOUND_COUNTS = 5;
  69. enum ALARM_FLAG{
  70. //AF_CARD_OVER_COUNT = 1,
  71. //AF_CARD_AREA_OVER_COUNT,
  72. AF_CARD_OVER_TIME,
  73. AF_CARD_OVER_SPEED,
  74. AF_CARD_AREA_OVER_SPEED,
  75. AF_CARD_AREA_OVER_TIME,
  76. AF_CARD_LOW_POWER,
  77. AF_CARD_LOW_POWER_SERIOUS,
  78. AF_CARD_AREA_FORBIDDEN,
  79. AF_AREA_OVER_COUNT,
  80. AF_AREA_OVER_TIME,
  81. AF_AREA_FORBIDDEN,
  82. AF_CARD_OVER_COUNT
  83. };
  84. enum AREA_TYPE
  85. {
  86. AREA_TYPE_FORBIDDEN = 3, // 限制区域
  87. AREA_TYPE_NO_COVER = 1000, // 非覆盖区域,车辆信号消失后,定位到附近非覆盖区域内
  88. AREA_TYPE_SPECIAL = 1001, // 特殊区域,只给你前端用来标识是否显示图标,胶轮车硐室
  89. };
  90. enum EDIT_TYPE_ID{
  91. ET_INSERT = 0, // 新增
  92. ET_UPDATE, // 修改
  93. ET_DELETE // 删除
  94. };
  95. enum ALARM_TYPE_ID
  96. {
  97. ATID_OVER_COUNT_PERSON = 1,
  98. ATID_POWER,
  99. ATID_OVER_COUNT_VEHICLE,
  100. };
  101. enum STATUS_DEVICE{
  102. STATUS_DEVICE_NORMAL = 0,
  103. STATUS_DEVICE_ERROR,
  104. };
  105. enum STATUS_MOVING
  106. {
  107. STATUS_MOVING_MOTIONLESS = 0,
  108. STATUS_MOVING_MOTION,
  109. STATUS_MOVING_IDLING
  110. };
  111. enum STATUS_CARD
  112. {
  113. STATUS_NORMAL = 0, //正常
  114. STATUS_ERROR = 1,
  115. STATUS_ERROR_SERIOUS = 2,
  116. STATUS_POWER_LOWER = 1, //电量低
  117. STATUS_POWER_LOWER_SERIOUS = 2, //电量极低
  118. STATUS_OVER_TIME = 4, //超时
  119. //STATUS_OVER_COUNT = 1,
  120. STATUS_OVER_SPEED = 8, //超速
  121. STATUS_AREA_OVER_TIME = 16, //区域超时
  122. //STATUS_AREA_OVER_COUNT = 1,
  123. STATUS_AREA_OVER_SPEED = 32, //区域超速
  124. STATUS_AREA_FORBIDDEN = 64, //进入限制区域
  125. STATUS_HELP = 128, //呼救
  126. STATUS_HELP_DEALED = 256, //
  127. STATUS_CALL = 512, //呼叫
  128. STATUS_LOST = 1024 //进入盲区
  129. //STATUS_ERROR_DEALED,
  130. };
  131. enum STORE_CARD_DATA_FLAG{
  132. HIS_LOCATION = 0,
  133. HIS_RAW_DATA,
  134. HIS_AREA_LOCATION_ENTER,
  135. HIS_AREA_LOCATION_LEAVE,
  136. RPT_ATTEND_DOWN,
  137. RPT_ATTEND_UP
  138. };
  139. enum STORE_MINE_DATA_FLAG{
  140. ALARM_MINE_OVER_COUNT_PERSON_START = 0,
  141. ALARM_MINE_OVER_COUNT_PERSON_END,
  142. ALARM_MINE_OVER_COUNT_VEHICLE_START,
  143. ALARM_MINE_OVER_COUNT_VEHICLE_END
  144. };
  145. enum STORE_LIGHT_DATA_FLAG{
  146. ALARM_LIGHT_FAULT_START= 0, //故障开始
  147. ALARM_LIGHT_FAULT_END, //故障结束
  148. ALARM_LIGHT_NETWORK_START, //网络故障开始
  149. ALARM_LIGHT_NETWORK_END, //网络故障结束
  150. ALARM_LIGHT_CONTROL_FAILE //控制失败
  151. };
  152. enum STORE_SECTION_DATA_FLAG{
  153. ALARM_SECTION_START = 0, // 区段告警开始
  154. ALARM_SECTION_END // 区段告警结束
  155. };
  156. enum LIGHT_STATE{
  157. LIGHT_NORMAL = 0, // 正常
  158. LIGHT_FAULT, // 异常
  159. LIGHT_NETWORK_ERROR, // 网络故障
  160. LIGHT_CONTROL_ERROR // 控制失败
  161. };
  162. enum LOCATE_TYPE
  163. {
  164. LT_COORDINATE = 0, // 使用坐标定位
  165. LT_READER, // 使用分站定位
  166. };
  167. enum FILTER_TYPE{
  168. NO_FILTER = 0, // 不使用滤波
  169. FILTER_KALMAN = 1, // 使用kalman滤波
  170. };
  171. enum SECTION_STATE{
  172. SECTION_STATE_NORMAL = 0, //正常
  173. SECTION_STATE_BUSY = 1, //繁忙
  174. SECTION_STATE_CONGESTION = 2, //拥堵
  175. };
  176. enum LIGHT_SHAPE{
  177. RED_CIRCLE_SOLID = 1, //红色实心圆
  178. RED_CIRCLE = 2, //红色空心圆
  179. RED_CROSS = 3, //红色叉形
  180. GREEN_UP = 4, //绿色上箭头
  181. GREEN_DOWN = 5, //绿色下箭头
  182. GREEN_LEFT = 6, //绿色左箭头
  183. GREEN_RIGHT = 7, //绿色右箭头
  184. RED_SPARK = 8, //红色闪烁
  185. GREEN_SPARK = 9 //绿色闪烁
  186. };
  187. enum LIGHT_STREAM{
  188. UP_STREAM = 1, //上行
  189. DOWN_STREAM = 2, //下行
  190. };
  191. enum LIGHT_COLOR{
  192. COLOR_RED = 1, // 红色
  193. COLOR_GREEN = 2, // 绿色
  194. };
  195. enum LIGHT_CTRL_STATE{
  196. CTRL_STATE_AUTO = 1, // 自动控制
  197. CTRL_STATE_MANUAL = 2, // 手动控制
  198. };
  199. enum LIGHTS_SELECT_TYPE
  200. {
  201. LST_ALL_LIGHTS = 0, // 所有灯
  202. LST_ALL_UP_LIGHTS = 1, // 所有上行
  203. LST_ALL_DWON_LIGHTS = 2,// 所有下行
  204. LST_SOME_LIGHTS = 3 // 指定灯
  205. };
  206. enum AREA_PROPERTY{
  207. MAIN_TUNNEL = 0, // 主巷道
  208. BRANCH_TUNNEL = 1, // 分支巷道
  209. };
  210. enum OUTPUT_POS{
  211. CENTRAL_POS = 0, // 居中
  212. LEFT_POS, // 靠左
  213. RIGHT_POS // 靠右
  214. };
  215. enum PATROL_STATE
  216. {
  217. PS_NORMAL = 0, // 正常
  218. PS_EARLY, // 早到
  219. PS_LATE, // 迟到
  220. PS_NON_ARRIVAL // 未到
  221. };
  222. enum PATROL_STAY_STATE
  223. {
  224. PSS_NORMAL = 0, // 正常
  225. PSS_TOO_LONG, // 停留过长
  226. PSS_TOO_SHORT // 停留太短
  227. };
  228. enum ALGO_LOC_TYPE{
  229. ALGO_LOC_SUCCESSED = 0, //算法定位成功
  230. ALGO_FAILED_CONDITION_1, //同步序号相差大于5
  231. ALGO_FAILED_CONDITION_2, //相同卡序列号,时间同步序号却相差大于5
  232. ALGO_FAILED_CONDITION_3, //时间同步戳值存在异常
  233. ALGO_FAILED_CONDITION_4, //卡的上次时间戳大于卡的本次时间戳
  234. ALGO_FAILED_CONDITION_5, //人卡加速度超限
  235. ALGO_FAILED_CONDITION_6, //车卡加速度超限
  236. ALGO_FAILED_CONDITION_7, //车卡速度超限
  237. ALGO_FAILED_CONDITION_8, //卡尔曼连续2s定位失败等
  238. ALGO_FAILED_CONDITION_9, //分站时间戳的距离差值大于分站之间的距离
  239. ALGO_FAILED_CONDITION_10, //分站之间无地图集
  240. ALGO_FAILED_CONDITION_11, //定位无解or解的个数为0
  241. ALGO_FAILED_CONDITION_12, //分站附近(小于4m),分站不是特殊分站
  242. ALGO_FAILED_CONDITION_13, //解与无地图集两分站之间的距离差(大于10m)
  243. ALGO_FAILED_CONDITION_14, //定位结果距离定位分站之间的距离差大于4
  244. ALGO_FAILED_CONDITION_15, //参与定位的数据条数小于2
  245. ALGO_LOC_TOTAL
  246. };
  247. enum ALGO_RETURN_VALUE{
  248. DIST_COUNT_LESS_THAN_TWO = 10001,
  249. DIST_COUNT_LESS_FOR_TIMESTAMP_ERROR,
  250. DIST_COUNT_LESS_FOR_SYNC_NUM_DIFFER_FIVE,
  251. ALGO_CALC_SOLUTION = 30001,
  252. ALGO_CALC_NO_SOLUTION_WITH_TWO_DATA,
  253. ALGO_CALC_ONE_DATA,
  254. SOLUTION_NO_SOLUTION = 40001,
  255. SOLUTION_NEAR_READER,
  256. SOLUTION_TWO_SOLUTION,
  257. SOLUTION_ERROR_STREAM,
  258. POSITION_INVALID,
  259. CHECK_PERSON_ACCE_OVER_SPEED = 50001,
  260. CHECK_VEHICLE_ACCE_OVER_SPEED,
  261. CHECK_VEHICLE_OVER_SPEED,
  262. KALMAN_FILTER_LONG_INTERVAL = 60001,
  263. ALGO_USE_KALMAN_FILTER = 70001,
  264. };
  265. extern unsigned int g_nAlgoFailedCounts[ALGO_LOC_TOTAL]; //全局的统计所有次数
  266. extern unsigned int g_nAlgoFailedCycleCounts[ALGO_LOC_TOTAL]; //指定周期内的所有统计次数
  267. extern ULONGLONG g_ullCurTime;
  268. #define ALGORITHM_FAILED(nType) { \
  269. g_nAlgoFailedCounts[nType]++; \
  270. }
  271. struct AlgoFailedMsg{
  272. std::string strCardId;
  273. int nCardStamp;
  274. int nType;
  275. SYSTEMTIME st;
  276. bool bStatus;
  277. AlgoFailedMsg(){
  278. strCardId = "";
  279. nCardStamp = 0;
  280. nType = 0;
  281. bStatus = false;
  282. }
  283. };
  284. enum DEVICE_TYPE{
  285. DT_CARD_READER = 0, //读卡分站
  286. DT_CTRL_READER = 1, // 控制分站
  287. DT_LIGHT = 3, // 红绿灯
  288. DT_SPEAKER = 4, // 告警器
  289. DT_TURNOUT = 5, // 道岔
  290. DT_LED = 6 // 显示屏
  291. };
  292. enum CALL_STATE{
  293. CALL_NONE = 0, //无呼叫信息
  294. CALL_SUCCESSED = 1, //呼叫成功
  295. CALL_ING = 2, //呼叫中
  296. CALL_FAILED = 3, //呼叫失败
  297. };
  298. struct SQLTHREAD_DATA//写数据库线程传递的参数
  299. {
  300. char* pText;//数据库语句地址指针
  301. int nRepeatTimes;//已经重试几次
  302. };
  303. // 定位坐标
  304. struct _coordinate{
  305. _coordinate(){
  306. t = 0;
  307. reader_id = 0;
  308. tt = 0;
  309. d = 0.0;
  310. sync_num = 0;
  311. x = 0.0;
  312. y = 0.0;
  313. z = 0.0;
  314. a = 0.0;
  315. v = 0.0;
  316. antenna_id = 0;
  317. d_offset = 0.0;
  318. special = 0;
  319. acceleration = 0;
  320. acce_state = 0;
  321. acce_state_last = 0;
  322. ins_direction = 0;
  323. }
  324. int t; // 定位时间戳
  325. int reader_id;
  326. unsigned long long syncRootId;
  327. unsigned long long tt;
  328. double d; // 距离
  329. double x; // x坐标
  330. double y; // y坐标
  331. double z; // z坐标
  332. double a; // 平面角度
  333. double v; // 速度
  334. int antenna_id;
  335. double d_offset; // 与显示距离的偏移,用来修正单基站的情况
  336. int sync_num; //同步序号
  337. double acceleration; //加速度
  338. int acce_state; //加速度状态
  339. int acce_state_last; //加速度计上一次状态
  340. int ins_direction; //惯导方向
  341. int special; //分站是否属于特殊分站,0属于特殊分站,1普通分站
  342. int reason;
  343. _coordinate& operator=(_coordinate &tmp){
  344. t = tmp.t;
  345. reader_id = tmp.reader_id;
  346. tt = tmp.tt;
  347. d = tmp.d;
  348. sync_num = tmp.sync_num;
  349. x = tmp.x;
  350. y = tmp.y;
  351. z = tmp.z;
  352. a = tmp.a;
  353. v = tmp.v;
  354. antenna_id = tmp.antenna_id;
  355. d_offset = tmp.d_offset;
  356. special = tmp.special;
  357. acceleration = tmp.acceleration;
  358. acce_state = tmp.acce_state;
  359. acce_state_last = tmp.acce_state_last;
  360. ins_direction = tmp.ins_direction;
  361. reason = ALGO_LOC_SUCCESSED;
  362. return *this;
  363. }
  364. };
  365. struct _point{ // 坐标
  366. double x;
  367. double y;
  368. double z;
  369. _point(){
  370. x = y = z = 0;
  371. }
  372. _point(double a,double b,double c){
  373. x = a;
  374. y = b;
  375. z = c;
  376. }
  377. };
  378. struct sync_data{
  379. double x;
  380. double y;
  381. double vx;
  382. double vy;
  383. int sync_num; //本次同步号
  384. bool update;
  385. std::shared_ptr<nspLocate::LocateRecord> locate;
  386. sync_data(){
  387. x = 0.0;
  388. y = 0.0;
  389. vx = 0.0;
  390. vy = 0.0;
  391. sync_num = 0;
  392. update = false;
  393. locate = nullptr;
  394. }
  395. sync_data& operator=(sync_data&tmp){
  396. x = tmp.x;
  397. y = tmp.y;
  398. vx = tmp.vx;
  399. vy = tmp.vy;
  400. sync_num = tmp.sync_num;
  401. update = tmp.update;
  402. locate = tmp.locate;
  403. return *this;
  404. }
  405. };
  406. struct _call_info_card
  407. {
  408. int card_id;
  409. int card_type;
  410. int call_type;
  411. string str_card_id;
  412. time_t start_time;
  413. int time_out;
  414. //bool is_success;
  415. int call_state;
  416. };
  417. //typedef map<std::string, _call_info_card*> CallInfoCardMap;
  418. typedef map<std::string, std::shared_ptr<_call_info_card>> CallInfoCardMap;
  419. struct _call_info_reader
  420. {
  421. bool is_call_all;
  422. bool is_start_call; //true,开始呼叫;false,取消呼叫
  423. BYTE call_type;
  424. int cards_count;
  425. CallInfoCardMap mpCard;
  426. };
  427. typedef map<int, std::shared_ptr<_call_info_reader>> CallInfoReaderMap;
  428. struct _call_info_user
  429. {
  430. std::string user_name;
  431. CallInfoReaderMap mpReader;
  432. };
  433. typedef map<string, std::shared_ptr<_call_info_user>> CallInfoUserMap;
  434. // 分站接收时间定义
  435. struct ReceiveData{
  436. unsigned int reader_id; // 分站号
  437. unsigned short antenna_id; // 天线号
  438. long long rec_time_stamp; // 分站接收时间,一个5字节的无符号数
  439. int special;
  440. double x; //分站的x坐标
  441. double y; //分站的y坐标
  442. double z; //分站的z坐标
  443. ReceiveData(){
  444. reader_id = -1;
  445. antenna_id = -1;
  446. rec_time_stamp = 0;
  447. x = y = z = 0.0;
  448. special = -1;
  449. };
  450. };
  451. struct INFO_PRE{
  452. int t;
  453. long long detaT;
  454. double dist;
  455. int ant;
  456. int sta_num;
  457. };
  458. struct POS{
  459. double posx;
  460. double posy;
  461. double posz;
  462. double pos_radius;
  463. double cx;
  464. double cy;
  465. double cz;
  466. //三个方向的速度
  467. double cvx;
  468. double cvy;
  469. double cvz;
  470. //加速度
  471. double av;
  472. //保存定位结果的两个分站信息
  473. int nFirstReader;
  474. int nSecondReader;
  475. //精度参考
  476. double dDiff[MAX_READER_TDOA_PATH_NUMS];
  477. double dis_diff;
  478. int reason;
  479. int status;
  480. int card_count; //卡的ct号
  481. bool update;
  482. bool is_back;
  483. bool is_fit;
  484. //当前分站同步序号与参考数据的分站同步序号时间差值
  485. double diff_reader_sync_num;
  486. //参考数据的定位坐标
  487. double ref_x;
  488. double ref_y;
  489. double ref_z;
  490. double origin_speed; //原始定位结果算的速度
  491. double sumVariance; // 保存各定位解之间差值的和
  492. POS(){
  493. nFirstReader = 0;
  494. nSecondReader = 0;
  495. pos_radius = 0;
  496. posx = posy = posz = INVALID_COORDINATE;
  497. cx = cy = cz = cvx = cvy = cvz = 0.0;
  498. av = 0.0;
  499. status = 0;
  500. for (int i=0;i<MAX_READER_TDOA_PATH_NUMS;i++)
  501. {
  502. dDiff[i] = 0;
  503. }
  504. dis_diff = 999999.9;
  505. update = false;
  506. is_fit = false;
  507. is_back = false;
  508. origin_speed = 0;
  509. sumVariance = 0;
  510. diff_reader_sync_num = 0;
  511. ref_x = ref_y = ref_z = 0;
  512. reason = -1;
  513. reason = ALGO_LOC_SUCCESSED;
  514. }
  515. POS& operator=(POS& tmp){
  516. nFirstReader = tmp.nFirstReader;
  517. nSecondReader = tmp.nSecondReader;
  518. posx = tmp.posx;
  519. posy = tmp.posy;
  520. posz = tmp.posz;
  521. cx = tmp.cx;
  522. cy = tmp.cy;
  523. cz = tmp.cz;
  524. cvx = tmp.cvx;
  525. cvy = tmp.cvy;
  526. cvz = tmp.cvz;
  527. av = tmp.av;
  528. update = tmp.update;
  529. origin_speed = tmp.origin_speed;
  530. status = tmp.status;
  531. is_back = tmp.is_back;
  532. diff_reader_sync_num = tmp.diff_reader_sync_num;
  533. dis_diff = tmp.dis_diff;
  534. ref_x = tmp.ref_x;
  535. ref_y = tmp.ref_y;
  536. ref_z = tmp.ref_z;
  537. sumVariance = tmp.sumVariance;
  538. for (int i=0;i<MAX_READER_TDOA_PATH_NUMS;i++)
  539. {
  540. dDiff[i] = tmp.dDiff[i];
  541. }
  542. pos_radius = tmp.pos_radius;
  543. reason = ALGO_LOC_SUCCESSED;
  544. return *this;
  545. }
  546. };
  547. //解的结构体
  548. struct SOLUTION{
  549. double x[3];
  550. double y[3];
  551. double z[3];
  552. int nCount;
  553. SOLUTION(){
  554. for (int i =0;i<3;i++)
  555. {
  556. x[i] = y[i] = z[i] = INVALID_COORDINATE;
  557. nCount = 0;
  558. }
  559. }
  560. };
  561. class Mine;
  562. class Area;
  563. class SpecialAreaEntry;
  564. class DrivingfaceRender;
  565. class DrivingfaceWarningPoint;
  566. class Reader;
  567. class Card;
  568. class MapInfo;
  569. class Dept;
  570. class BanShift;
  571. class OccLevel;
  572. class ReaderPath;
  573. class PatrolPoint;
  574. class PatrolTask;
  575. class Section;
  576. class Chamber;
  577. class Light;
  578. class LightsGroup;
  579. class LightCallInfo;
  580. class StorePostion;
  581. class LandmarkInfo;
  582. class MapDirectionInfo;
  583. typedef map<string, std::shared_ptr<Card>> CardMap;
  584. typedef map<int, std::shared_ptr<Area>> AreaMap;
  585. typedef map<int, std::shared_ptr<DrivingfaceWarningPoint>>DrivingfaceWarningPointMap;
  586. typedef map<int, std::shared_ptr<SpecialAreaEntry>> SpecilaAreaEntryMap;
  587. typedef map<int, std::shared_ptr<DrivingfaceRender>> DrivingfaceRenderMap;
  588. typedef map<int, std::shared_ptr<Reader>> ReaderMap;
  589. typedef map<int, std::shared_ptr<MapInfo>> MapInfoMap;
  590. typedef map<int, std::shared_ptr<MapDirectionInfo>>MapDirectionInfoMap;
  591. typedef map<int, std::shared_ptr<LandmarkInfo>>LandmarkInfoMap;
  592. typedef map<int, std::shared_ptr<Dept>> DeptMap;
  593. typedef map<int, std::shared_ptr<BanShift>> BanShiftMap;
  594. typedef map<int, std::shared_ptr<OccLevel>> OccLevelMap;
  595. typedef map<int, string> AlarmTypeMap;
  596. typedef map<int,std::shared_ptr<ReaderPath>> ReaderPathMap;
  597. typedef unordered_map<int,std::shared_ptr<ReaderPathMap>> TDOAReaderPathMap;
  598. typedef unordered_map<std::string, std::shared_ptr<_coordinate>> DistMap;
  599. typedef map<unsigned long long ,std::shared_ptr<ReceiveData>> ReceiveDataMap;
  600. typedef map<int,std::shared_ptr<Section>> SectionMap; //路段信息
  601. typedef map<int,std::shared_ptr<Chamber>> ChamberMap; //硐室信息
  602. typedef map<int,std::shared_ptr<Light>> LightMap; //红绿灯信息
  603. typedef map<int,std::shared_ptr<LightsGroup>> LightGroupMap; //红绿灯组信息
  604. typedef map<unsigned int, std::shared_ptr<PatrolPoint>> PatrolPointMap;
  605. typedef map<unsigned int, std::shared_ptr<PatrolTask>> PatrolTaskMap;
  606. typedef map<std::string, std::shared_ptr<PatrolTask>> PatrolTaskCheckMap;
  607. typedef map<unsigned int, std::shared_ptr<PatrolPoint>> PatrolPointMap;
  608. typedef map<unsigned int, std::shared_ptr<PatrolTask>> PatrolTaskMap;
  609. typedef map<std::string, std::shared_ptr<PatrolTask>> PatrolTaskCheckMap;
  610. typedef deque<std::shared_ptr<StorePostion>> QueStrorePos;
  611. typedef std::map<std::string,std::list<std::shared_ptr<Cell>>> CellPathMap;
  612. typedef struct key_value_pair
  613. {
  614. int key;
  615. int value;
  616. struct key_value_pair* next;
  617. }KeyValuePair;
  618. typedef struct statistic_data_str
  619. {
  620. int index;
  621. KeyValuePair* data_info;
  622. struct statistic_data_str* next;
  623. }StatisticDataStr;
  624. struct DistQueMapItem
  625. {
  626. WORD cardstamp;
  627. DistMap distmap;
  628. };
  629. typedef deque<DistQueMapItem> DistQueMap;
  630. // 地图
  631. class MapInfo{
  632. public:
  633. MapInfo(void);
  634. ~MapInfo(void);
  635. public:
  636. int map_id;
  637. string map_path;
  638. string map_name;
  639. double map_width;
  640. double map_height;
  641. double map_scale;
  642. int map_type;
  643. AreaMap map_area_list;
  644. ReaderMap map_reader_list;
  645. ReaderMap map_ctrl_reader_list;
  646. CardMap map_card_list_person;
  647. CardMap map_card_list_vehicle;
  648. ChamberMap map_chamber_list;
  649. SectionMap map_section_list;
  650. LightMap map_light_list;
  651. LightGroupMap map_light_group_list;
  652. };
  653. class LandmarkInfo
  654. {
  655. public:
  656. int landmark_id;
  657. string landmark_name;
  658. int map_id;
  659. double x;
  660. double y;
  661. double z;
  662. };
  663. class MapDirectionInfo
  664. {
  665. public:
  666. int map_direction_id;
  667. int map_id;
  668. int north_angle;
  669. };
  670. // 区域
  671. class Area // 矩形
  672. {
  673. private:
  674. std::vector<std::string> split(std::string str,std::string pattern);
  675. double get_vertex(std::string src); // 顶点
  676. public:
  677. Area(void);
  678. ~Area(void);
  679. void init_border(string sz_path);
  680. bool is_in_polygon(_point p);
  681. int is_special(); // 是否为特殊区域
  682. public:
  683. int map_id;
  684. int area_id;
  685. string area_name;
  686. string area_type_name;
  687. string path; // 多边形
  688. int area_type_id;
  689. // 人员
  690. int over_count_person;
  691. int over_time_person;
  692. int under_count_person;
  693. int under_time_person;
  694. // 车辆
  695. int over_count_vehicle;
  696. int over_time_vehicle;
  697. int under_count_vehicle;
  698. int under_time_vehicle;
  699. double over_speed_vehicle; //区域车辆速度阈值
  700. int polygon_count;
  701. _point* polygon;
  702. double rect_left;
  703. double rect_right;
  704. double rect_top;
  705. double rect_bottom;
  706. // 区域人数
  707. int count_person;
  708. int count_vehicle;
  709. int count_card;
  710. // 是否写考勤
  711. int is_att; // 0 停车场外,1 停车场内
  712. bool is_area_over_time_person; // 车辆超时
  713. bool is_area_over_time_vehicle; // 人员超时
  714. int count_area_over_time_person; // 超时人数
  715. int count_area_over_time_vehicle; // 超时车数
  716. time_t time_over_time_person; // 开始超时时间
  717. time_t time_over_time_vehicle; // 开始超时时间
  718. bool is_area_over_count_person; // 人员超员
  719. bool is_area_over_count_vehicle; // 车辆超员
  720. int count_area_over_count_person;
  721. int count_area_over_count_vehicle;
  722. time_t time_over_count_person; // 开始时间
  723. time_t time_over_count_vehicle; // 开始时间
  724. bool is_area_forbidden_person;
  725. bool is_area_forbidden_vehicle;
  726. int count_area_forbidden_person;
  727. int count_area_forbidden_vehicle;
  728. time_t time_forbidden_person; // 开始时间
  729. time_t time_forbidden_vehicle; // 开始时间
  730. std::shared_ptr<CardMap> area_card_list_person;
  731. std::shared_ptr<CardMap> area_card_list_vehicle;
  732. std::shared_ptr<CardMap> area_card_list_over_speed;
  733. INT64 m_event_list[AREA_EVENT_COUNT]; // 保存事件Id
  734. };
  735. class DrivingfaceWarningPoint
  736. {
  737. public:
  738. int warning_point_id;
  739. string warning_point_name;
  740. int driving_face_id;
  741. float point_x;
  742. float point_y;
  743. float point_z;
  744. float warning_threshold;
  745. int is_valid;
  746. };
  747. class SpecialAreaEntry
  748. {
  749. public:
  750. SpecialAreaEntry(){}
  751. public:
  752. double start_point_x;
  753. double start_point_y;
  754. double start_point_z;
  755. double end_point_x;
  756. double end_point_y;
  757. double end_point_z;
  758. int special_area_id;
  759. };
  760. class DrivingfaceRender
  761. {
  762. public:
  763. DrivingfaceRender(){}
  764. public:
  765. INT drivingface_id;
  766. INT reader_id;
  767. double vertical_distance;
  768. double x;
  769. double y;
  770. double z;
  771. };
  772. // 自组网预置坐标
  773. class Adhoc
  774. {
  775. public:
  776. Adhoc();
  777. ~Adhoc();
  778. public:
  779. int adhoc_id;
  780. double x;
  781. double y;
  782. double z;
  783. int idx;
  784. };
  785. // 天线
  786. class Antenna
  787. {
  788. public:
  789. Antenna(void);
  790. ~Antenna(void);
  791. public:
  792. int antenna_id;
  793. double antenna_x;
  794. double antenna_y;
  795. double antenna_z;
  796. double antenna_angle;
  797. };
  798. // 分站
  799. class Reader
  800. {
  801. public:
  802. Reader(void);
  803. ~Reader(void);
  804. public:
  805. int reader_id; // 分站号
  806. string reader_name; // 分站名称
  807. int device_type_id;
  808. int pos_state; // 位置状态 1井上,2井下
  809. string ip;
  810. double reader_x;
  811. double reader_y;
  812. double reader_z;
  813. double reader_angle;
  814. double reader_interval_time;
  815. int map_id; // 所在地图
  816. int area_id; // 所属区域
  817. double map_scale; // 比例尺
  818. time_t rec_time;
  819. time_t reader_time; // 分站时间
  820. time_t lost_time;
  821. time_t last_send_time; // 最后向前端发送时间
  822. int temperature; // 温度
  823. int tick_count; // 计数器
  824. int reader_state; // 状态 0 正常, 1 故障
  825. int reader_state_old;
  826. int sync_level;
  827. unsigned long long sync_rootId;
  828. std::shared_ptr<Antenna> ant[ANTENNA_COUNT];
  829. std::shared_ptr<Adhoc> adhoc[ADHOC_COUNT];
  830. map<int,_point> readerCoveragePath;
  831. bool bIsInitCoverage;
  832. int m_nIsSpecial;
  833. bool init_ctrl_reader_state; //当为控制分站时,第一次需要获得此控制分站下的红绿灯状态
  834. INT64 m_event_list[READER_EVENT_COUNT]; // 保存事件Id
  835. public:
  836. string get_state_text();
  837. };
  838. class StorePostion
  839. {
  840. public:
  841. StorePostion(){
  842. x = y = z = 0;
  843. GetLocalTime(&save_time);
  844. };
  845. ~StorePostion();
  846. double x, y, z;
  847. SYSTEMTIME save_time;
  848. };
  849. // 卡
  850. class Card
  851. {
  852. public:
  853. Card(void);
  854. ~Card(void);
  855. Card(string cardid, int cardtype,double z_offset, double offset_x = 12.0, double offset_y =12.0);
  856. public:
  857. CRITICAL_SECTION m_csCard;
  858. public:
  859. int card_type; // 卡类型 0x01人, 0x02车
  860. //int64_t card_id; // 卡唯一标识, 高位为卡号,低位为卡类型, ((card_id << 8) | card_type)
  861. string card_id;
  862. // 人员
  863. string level; // 级别
  864. string occupation; // 职务
  865. // 人员、车辆
  866. string id; // 编号,人员或车辆
  867. string name; // 姓名、车辆名称
  868. string number; // 身份证号码,车牌号码
  869. //string photo; // 照片
  870. //string company; // 单位
  871. string department; // 部门
  872. string group; // 班组
  873. string worktype; // 工种、车辆类型
  874. int dept_id;
  875. int occlevel_id; // 职务id
  876. int group_id;
  877. string driver_id; //如果是车辆,则有司机id
  878. int light_id;
  879. //time_t deal_time; // 最后处理卡逻辑时间
  880. SYSTEMTIME deal_time;
  881. SYSTEMTIME enter_area_time;
  882. //driving face write database time
  883. ULONGLONG drive_face_location_write_time;
  884. ULONGLONG drive_face_location_end_time;
  885. //SYSTEMTIME down_time;
  886. time_t rec_time; // 最后接收时间
  887. time_t down_time; // 入井时间
  888. time_t up_time; // 升井时间
  889. time_t enter_reader_time; // 进入分站时间
  890. time_t low_power_time; // 电量低开始时间
  891. double coor_offset_x;
  892. double coor_offset_y;
  893. double x;
  894. double y;
  895. double z;
  896. //double driving_face_x; //cur shift start point
  897. //double driving_face_y;
  898. //double driving_face_z;
  899. int driving_face_id;
  900. double driving_face_cur_shift_start_x; //cur shift start position
  901. double driving_face_cur_shift_start_y;
  902. double driving_face_cur_shift_start_z;
  903. double driving_face_cur_shift_x; //cur shift real point
  904. double driving_face_cur_shift_y;
  905. double driving_face_cur_shift_z;
  906. double drving_face_cur_shift_max_speed;
  907. double a; // 上次定位时的角度
  908. int t; // 上次定位时的时间戳
  909. double z_offset;
  910. bool init_postion;
  911. bool is_first_location;
  912. int is_driving_face_start;
  913. double v; //速度
  914. double mileage;
  915. double xx;
  916. double yy;
  917. double zz;
  918. double x1, x2, x3, x4;
  919. double y1, y2, y3, y4;
  920. double z1, z2, z3, z4;
  921. double right_x,right_y,right_z; //分别指卡位置右边偏移的x,y,z坐标
  922. double left_x,left_y,left_z; //分别指卡位置左边偏移的x,y,z坐标
  923. double last_x;
  924. double last_y;
  925. double last_z;
  926. double stored_x;
  927. double stored_y;
  928. double stored_z;
  929. double output_x;
  930. double output_y;
  931. double last_vx;
  932. double last_vy;
  933. int state; // 0 正常, 共32bit,每个bit代表一个状态,从右起:
  934. // 第一位 0x01 井下超时, 第二位 0x02 区域超时, 第三位 0x04 超速, 第四位 0x08, 进入限制区域
  935. // 状态,故障、电量低等
  936. int state_moving; // 运动状态, 0 静止,1 启动
  937. // 电量低、 呼叫、呼救
  938. int status_over_time; // 0 未超时,1 超时
  939. int status_over_speed; // 0 未超速,1 超速
  940. int status_area_over_time; // 0 未区域超时, 1 区域超时
  941. int status_area_over_speed; // 0 未区域超速, 1 区域超速
  942. int status_area_forbidden; // 0 未进入限制区域, 1 进入限制区域
  943. int status_help; // 0 未呼救, 1 呼救, 2 已处理呼救
  944. int status_call; // 0 未呼叫 1 呼叫
  945. int status_power; // 0 电量正常,1 电量低
  946. int status_lost; // 0 未进入盲区,1 盲区状态
  947. int map_id; // 当前地图
  948. double map_scale; // 地图比例尺
  949. int map_id_old; // 上次测距所在地图
  950. int area_id; // 当前区域
  951. int landmark_id;
  952. double landmark_dis;
  953. int landmark_direction;
  954. int reader_id; // 当前分站
  955. Reader* p_reader;
  956. std::shared_ptr<ReaderPathMap> pReaderPathMap;
  957. std::shared_ptr<TDOAReaderPathMap> pTdoaReaderPathMap;
  958. _coordinate** p_dists_locate;
  959. map<unsigned long long,std::shared_ptr<_coordinate>> mp_dists_locate;
  960. _coordinate last_locate;
  961. _coordinate origin_locate;
  962. _coordinate kalman_locate;
  963. double m_dFirstDiff;
  964. double m_dSecondDiff;
  965. QueStrorePos _storepostions;
  966. DistQueMap _dists;
  967. int time_stamp_max; // 最大时间戳,即需要计算定位的时间戳
  968. int time_stamp_cal;
  969. int m_nFilterType;
  970. int m_nLastLocateT;
  971. int m_nCalcSyncNum; //卡在算法中的同步号,此同步号和卡的实时同步号并不一定一致
  972. int m_nSyncNumInList; //从队列中取出的大于5的同步号
  973. int m_nStream; //上行、下行
  974. int m_nLightGroupId;
  975. int m_nMoveDirection; //1为正向运动,-1为负向运动
  976. int m_nIsRailroad; //是否为有轨车,0为无轨车,1为有轨车
  977. int m_nOutputPosState; //0为正常输出中间坐标,1为输出靠左偏移坐标,2为输出靠右偏移坐标
  978. bool issent; // true 已发送至客户端,false 新数据,需要发送至客户端
  979. bool issaved; //true 已保存到数据库,false 生成新的考勤记录,需要保存到数据库
  980. bool isdealed; // 已经处理
  981. bool isreceive; // 接收到
  982. bool is_pos_changed;
  983. bool is_deal_by_algo;
  984. bool is_hist;
  985. bool is_need_cal;
  986. bool m_bUseFilter;
  987. bool isoutput; //是否输出到json
  988. bool is_red_light;
  989. bool is_mine_over_time; // 是否井下超时
  990. bool is_mine_over_speed;
  991. bool is_area_over_time; // 是否区域超时, 区域超时分车辆超时、人员超时
  992. bool is_area_over_speed; // 是否区域超速
  993. time_t time_area_over_time; // 区域超时开始时间
  994. time_t time_over_time; // 井下超时开始时间
  995. time_t time_area_forbidden; // 进入限制区域时间
  996. time_t time_over_speed; // 超速开始时间
  997. time_t time_area_over_speed;
  998. time_t time_low_power;
  999. time_t time_red_light; //闯红灯时间
  1000. time_t last_locate_time; // 最后定位时间
  1001. void reset();
  1002. void set_reader(std::shared_ptr<Reader> preader);
  1003. //void set_reader(std::weak_ptr<Reader> preader);
  1004. void add_dist(_coordinate* dist);
  1005. void add_dist(std::shared_ptr<_coordinate> dist);
  1006. void remove_dist_head();
  1007. string concat(int reader_id, int ant_id);
  1008. time_t get_working_time();
  1009. string get_state_text();
  1010. string get_acc_text();
  1011. double get_speed();
  1012. void set_speed(double v);
  1013. int get_effictive_dist_count(int offset = 0);
  1014. void set_reader_path_tof(std::shared_ptr<ReaderPathMap> rpm);
  1015. void set_reader_path_tdoa(std::shared_ptr<TDOAReaderPathMap> trpm);
  1016. void inspect_coordinate(int acce_state);
  1017. bool checkStream(double x1,double y1,double x2,double y2,int nStream);
  1018. int const PosState();
  1019. void PosState(int val);
  1020. void PosStateOld(int val);
  1021. bool is_pos_state_changed(); // 入\升井状态变化
  1022. int const StateBiz();
  1023. INT64 m_event_list[CARD_EVENT_COUNT]; // 保存事件Id
  1024. public:
  1025. std::shared_ptr<nspLocate::LocateRecord> locate;
  1026. void algo_tof(int cnt);
  1027. void algo_tdoa(int cnt);
  1028. int algo_tdoa_1d(int cnt); //一维定位
  1029. int algo_tdoa_2d(int cnt); //二维定位
  1030. int algo_tdoa_3d(int cnt); //三维定位
  1031. void algo_calc_offset(); //计算偏移坐标
  1032. bool algo_is_same_direction(double x,double y,double z); //检查此次方向
  1033. int CheckDistData(int cnt);
  1034. int AssembleDistData(std::shared_ptr<ReceiveDataMap> pRdm);
  1035. int SaveCardAlgoData(std::shared_ptr<POS>& pos);
  1036. int SaveCardAlgoData(std::shared_ptr<Cell>& cell);
  1037. int SaveOriginDataBeforeFilter(std::shared_ptr<POS> pos);
  1038. int ChooseOneSolution(std::shared_ptr<ReceiveDataMap> pRdm, std::vector<std::shared_ptr<POS>> udm_pos, std::shared_ptr<POS>& pos);// 输出唯一解
  1039. int CheckSolution(std::shared_ptr<POS>& p); // 验证唯一解合法性,如速度、加速度
  1040. int CheckSulutionByStream(std::shared_ptr<POS> p); //参数使用非引用,即不可修改其值
  1041. bool IsExistPath(int left,int right);
  1042. int CopySolution(std::shared_ptr<POS> source,std::shared_ptr<POS>& dest);
  1043. int CalcPositionBySpeed(std::shared_ptr<POS>& pos,double v);
  1044. //std::shared_ptr<nspLocate::LocateRecord> locate;
  1045. int GetDeltaT(map<unsigned long long,std::shared_ptr<_coordinate>> dl);
  1046. int CheckCardStatus();
  1047. public:
  1048. // 滤波算法相关
  1049. std::unique_ptr<CKalmanFilter> m_pKalmanFilter;
  1050. list<sync_data> m_syncNumList;
  1051. std::list<std::shared_ptr<POS>> his_idle_pos;
  1052. int last_s_locate_reader[2]; //上一次定位成功的分站信息
  1053. double ins_weight; //加速度计状态权重
  1054. double uwb_weight; //uwb状态权重
  1055. int diff_direction_counts;
  1056. int acce_cur_state; //在算法中保存当前加速度状态,保存这两个值的原因是在多线程情况下accelerate_state和accelerate_state_last状态可能变化
  1057. int acce_last_state; //在算法中保存上一次加速度状态
  1058. std::list<double> vt_his_speed;
  1059. void get_coordinate();
  1060. void get_coordinate(int cnt);
  1061. void get_coordinate_3d(int cnt);
  1062. void set_anchors(int cnt);
  1063. void EnableFilter(int nType);
  1064. int FindDistMap(int cardstamp);
  1065. int KalmanFilterProcess(std::shared_ptr<POS>& pos);
  1066. int InitAlgoParam();
  1067. bool CheckCrossCycle();
  1068. bool isRebound(std::shared_ptr<POS> pos); //判断是否回跳
  1069. public:
  1070. bool b_save_pos;
  1071. //在长时间无法定位的情况下使用拟合算法输出点
  1072. std::list<std::shared_ptr<POS>> his_pos; //保存之前5个点的信息
  1073. bool is_ref_pos; //判断是否作为参考点
  1074. bool is_fit_pos;
  1075. bool have_fit_pos;
  1076. bool have_long_fit_pos;
  1077. bool is_over_interval; //用于保存modify_card_speed中当前时间和卡的最后接收时间的是否超过指定时间的状态
  1078. int count_idle; //统计坐标连续有多少次没变化了,用于判断车辆是否怠速,统计5次
  1079. int cur_fit_nums; //当前拟合次数,当有新数据放入his_pos即重置它
  1080. int cur_ref_totals;
  1081. int count_change_direction; // 统计方向改变后的的连续定位次数,大于3次,改变行驶方向。
  1082. double fitting_v[REF_POSITION_NUM];
  1083. double fitting_ct[REF_POSITION_NUM];
  1084. double fitting_x[REF_POSITION_NUM];
  1085. double fitting_y[REF_POSITION_NUM];
  1086. double fit_new_x[FIT_POSITION_NUM];
  1087. double fit_new_y[FIT_POSITION_NUM];
  1088. //第二种拟合
  1089. std::list<std::shared_ptr<POS>> long_his_pos; //保存之前20个点的信息,此信息必须是UWB定位信息
  1090. double long_fitting_ct[REF_POSITION_NUM];
  1091. double long_fitting_x[REF_POSITION_NUM];
  1092. double long_fitting_y[REF_POSITION_NUM];
  1093. double long_fit_new_x[FIT_POSITION_NUM*4];
  1094. double long_fit_new_y[FIT_POSITION_NUM*4];
  1095. int UpdateFittingData(std::shared_ptr<POS> pos); //更新拟合基础数据
  1096. int CalcFittingData(); //计算拟合数据
  1097. int CalcLongFittingData();
  1098. int CalcFittingData(int ret,std::shared_ptr<POS>& pos);
  1099. int CalcLongFittingData(int ret,std::shared_ptr<POS>& pos);
  1100. int GetPosFromFittingData(std::shared_ptr<POS>& pos);
  1101. std::shared_ptr<POS> GetPosFromFittingData(); //从拟合数据获取定位坐标
  1102. int CheckSolutionByFit(int ret,std::shared_ptr<POS>& pos);
  1103. int CheckSolutionBySpeed(std::shared_ptr<POS>& pos);
  1104. private:
  1105. bool b_long_interval; //上一次定位的间隔时间差大于10s
  1106. int state_biz; //业务状态,呼叫/超时/进入禁区等
  1107. int pos_state; // 位置状态,0初始化,1井下,2井上,3车场分站
  1108. int pos_state_old;
  1109. int pos_state_count; // 当前位置状态确认次数
  1110. int pos_state_confirm_times; // 井下、井上状态确认次数,默认为1
  1111. public:
  1112. AlgoFailedMsg m_afmData;
  1113. public:
  1114. bool b_pos_change; //位置发生了改变
  1115. bool b_enter_intersection; //车辆是否进入过路口区域
  1116. public: // 采集到的底层数据
  1117. int reader_tickcount;
  1118. int time_stamp; // 定位时间戳
  1119. int ranging_type; // 报文类型 tof,tdoa
  1120. int accelerate_state; // 加速度
  1121. int antenna_id; // 天线号
  1122. double antenna_angle; // 天线角度
  1123. double distance; // 距离
  1124. int64_t flying_time; // 飞行时间
  1125. int power_state; // 电量
  1126. int sync_num;
  1127. int time_stamp_last; // 定位时间戳
  1128. int context_type_last; // 报文类型 tof,tdoa
  1129. int accelerate_state_last; // 上一次加速度状态
  1130. int antenna_id_last; // 天线号
  1131. double antenna_angle_last; // 天线角度
  1132. double distance_last; // 距离
  1133. int64_t flying_time_last; // 飞行时间
  1134. int power_state_last; // 电量
  1135. int ins_direction; //上一次的惯导合成方向
  1136. int direction; //上下行概念
  1137. int reader_id_last; //上一次定位时间戳的分站id
  1138. string str_his_time;
  1139. string str_rec_time;
  1140. public:
  1141. //格子算法的代码
  1142. bool bInitalCellPath;
  1143. bool isNeedWrited;
  1144. std::shared_ptr<CellPathMap> mpCellPath;
  1145. std::string curCellReaderName; //当前格子所属分站名
  1146. std::string originCellReaderName; //原始定位格子所属分站名
  1147. ULONGLONG calc_cell_time; //保存当前定位的计时器(通过数据和通过500ms补充)
  1148. ULONGLONG data_cell_time; //用于区分两次通过数据进行定位的
  1149. SYSTEMTIME cellDealTime; //格子处理时间
  1150. int curCellId; //当前格子id
  1151. int originCellId; //原始定位格子id
  1152. int nIncrease; //格子是否增长,0为未识别,如果增长为1,如果下降为-1
  1153. int nStartLocateCounts; //启动定位计数统计,根据前5次定位计算是否怠速:如果怠速,则继续不运动;如果运动,则开始加速
  1154. int change_cell_dir; //改变格子方向
  1155. int locateCounts; //统计定位次数,用于取模计算
  1156. int isInsertToDb; //插入数据库
  1157. bool isIdling; //怠速状态
  1158. std::thread* pThread;
  1159. std::shared_ptr<Cell> last_cell;
  1160. std::list<std::shared_ptr<Cell>> his_cell;
  1161. std::list<std::shared_ptr<Cell>> locate_cells;
  1162. int DiscreteLocate(int cnt);
  1163. int PersonLocation(int cnt);
  1164. bool CheckIdleStatus();
  1165. bool CheckStartRule();
  1166. bool isOverThreshold();
  1167. bool isRebound(std::shared_ptr<Cell> cell);
  1168. std::shared_ptr<Cell> Position2Cell(std::shared_ptr<POS> pos); //点转化为格子信息
  1169. std::shared_ptr<POS> Cell2Position(std::shared_ptr<Cell>& cell); //格子信息转化坐标输出
  1170. std::shared_ptr<Cell> GetNextCell(std::shared_ptr<Cell> lastCell,int increase,int nIndex);
  1171. std::shared_ptr<Cell> GetNextCell(std::shared_ptr<Cell> lastCell,int increase,int nIndex,std::shared_ptr<Cell> newCell);
  1172. int SetCellPathMap(std::shared_ptr<CellPathMap> pCellPath);
  1173. int ChangeSystemTime(SYSTEMTIME& st,const int condition);
  1174. int ChangeSystemTime(SYSTEMTIME& st); //在st基础上加500ms
  1175. //void handle_data_thread(LPVOID pContext);
  1176. //HANDLE hEvent;
  1177. HWND pMainWnd;
  1178. int SetMainHwnd(HWND hWnd){
  1179. pMainWnd = hWnd;
  1180. return 0;
  1181. }
  1182. public:
  1183. //测试函数
  1184. int OutputCmdLog(int n);
  1185. //呼叫信息
  1186. int call_type;
  1187. std::vector<int> vt_deal_call_reader_id;
  1188. time_t recv_call_time; //卡接收到呼叫的时间戳
  1189. };
  1190. class BanShift
  1191. {
  1192. public:
  1193. BanShift();
  1194. ~BanShift();
  1195. BanShift(int id, std::string s, std::string e);
  1196. int shift_id;
  1197. std::string start_time;
  1198. std::string end_time;
  1199. };
  1200. class Dept
  1201. {
  1202. public:
  1203. Dept();
  1204. ~Dept();
  1205. Dept(int id, string name);
  1206. private:
  1207. public:
  1208. int dept_id;
  1209. string dept_name;
  1210. CardMap dept_card_list_person;
  1211. CardMap dept_card_list_vehicle;
  1212. };
  1213. class OccLevel
  1214. {
  1215. public:
  1216. OccLevel();
  1217. ~OccLevel();
  1218. OccLevel(int id);
  1219. private:
  1220. public:
  1221. int occlevel_id;
  1222. CardMap level_card_list_person;
  1223. CardMap level_card_list_vehicle;
  1224. };
  1225. /*
  1226. * 地图集路径描述
  1227. */
  1228. class ReaderPath{
  1229. public:
  1230. ReaderPath(){
  1231. bIsInit = false;
  1232. nRealCalcPoints = 0;
  1233. x[0] = x[1] = y[0] = y[1] = 0;
  1234. for(int i=0;i<MAX_CALC_POINTS;i++){
  1235. px[i] = py[i] = pz[i] = 0;
  1236. }
  1237. }
  1238. public:
  1239. //对于TOF而言,x,y表示1,2天线对应的坐标
  1240. //对于TDOA而言,x,y表示焦点F1,F2(等同于分站i,i+1)的坐标
  1241. int nRealCalcPoints;
  1242. double x[2];
  1243. double y[2];
  1244. double z[2];
  1245. double px[MAX_CALC_POINTS];
  1246. double py[MAX_CALC_POINTS];
  1247. double pz[MAX_CALC_POINTS];
  1248. bool bIsInit;
  1249. };
  1250. //红绿灯
  1251. class Light{
  1252. public:
  1253. int m_nID; //红绿灯id
  1254. int m_nMapID; //地图id
  1255. int m_nReaderID; //传输分站id
  1256. int m_nAreaID; //区域id
  1257. int m_nSectionID; //路段id
  1258. int m_nLightsGroupID; //红绿灯组id
  1259. int m_nPort; //与分站之间通信的路数
  1260. int m_nState; //红绿灯是否可用状态,0可用,1不可用
  1261. int m_nOldState;
  1262. int device_type_id; //设备类型
  1263. double x; //x坐标
  1264. double y; //y坐标
  1265. double z; //z坐标
  1266. std::string m_strIP; //红绿灯ip
  1267. std::string m_strName; //红绿灯名字
  1268. std::string m_strLabel;
  1269. time_t rec_time;
  1270. time_t last_send_time;
  1271. public:
  1272. Light();
  1273. ~Light(){}
  1274. public:
  1275. int get_light_state();
  1276. public:
  1277. int m_nStream; //0为上行,1为下行
  1278. int m_nColor; //0x01 红色, 0x02 绿色
  1279. int m_nShape; // 形状 0x01 实心圆形,0x02 空心圆形,0x03 叉形,0x04 - 0x07 上下左右箭头,0xFF 警告闪烁
  1280. int m_nStateBiz; //0为正常,1为网络故障,2为控制失败,3为灯故障
  1281. int m_nIsCtrl; // 设备控制状态 0x01 自动控制,0x02手动控制
  1282. time_t alarm_start_time;
  1283. };
  1284. class LightsGroup{
  1285. public:
  1286. int m_nID;
  1287. int m_nState;
  1288. bool m_bIsUsed;
  1289. std::string m_strName;
  1290. std::string m_strLabel;
  1291. public:
  1292. int m_nSectionId; //灯组所在的路口区域
  1293. std::string m_strVechileId; //控制此灯组的车辆id
  1294. map<int,std::shared_ptr<Light>> mp_lights_list;
  1295. public:
  1296. LightsGroup();
  1297. ~LightsGroup(){};
  1298. public:
  1299. bool isExist(std::shared_ptr<Light> pLight);
  1300. bool isAllLightColor(int nColor);
  1301. };
  1302. class BaseArea{
  1303. public:
  1304. BaseArea(){
  1305. m_nPolygonCount = 0;
  1306. m_pPolygon = NULL;
  1307. }
  1308. ~BaseArea(){
  1309. if (m_pPolygon)
  1310. {
  1311. delete[] m_pPolygon;
  1312. m_pPolygon = NULL;
  1313. }
  1314. }
  1315. public:
  1316. int init_border(string path);
  1317. bool IsInPolygon(_point p);
  1318. private:
  1319. double GetVertex(std::string src); // 顶点
  1320. std::vector<std::string> Split(std::string str,std::string pattern);
  1321. public:
  1322. int m_nProperty;
  1323. int m_nPolygonCount;
  1324. _point* m_pPolygon;
  1325. };
  1326. //硐室
  1327. class Chamber:public BaseArea{
  1328. public:
  1329. int m_nID; //硐室编号
  1330. int m_nState; //使用状态,特指此硐室是否处于可用
  1331. int m_nIsUsed; //硐室内是否有车
  1332. int m_nSectionID; //硐室所属路段ID
  1333. int m_nMapID; //硐室所属地图ID
  1334. std::string m_strPath; //硐室区域
  1335. std::string m_strName; //硐室名称
  1336. std::string m_strLabel; //硐室描述
  1337. public:
  1338. Chamber();
  1339. ~Chamber();
  1340. };
  1341. //路段
  1342. class Section:public BaseArea{
  1343. public:
  1344. int m_nID;
  1345. int m_nMapId;
  1346. std::string m_strPath;
  1347. std::string m_strName;
  1348. std::string m_strLabel;
  1349. public:
  1350. int m_nState; //0---正常,1---繁忙,2---拥堵
  1351. time_t alarm_start_time;
  1352. ChamberMap mp_champer_list;
  1353. LightMap mp_light_list;
  1354. CardMap mp_vehicle_list;
  1355. CardMap mp_staffer_list;
  1356. INT64 m_event_list[SECTION_EVENT_COUNT];
  1357. public:
  1358. Section();
  1359. ~Section(){}
  1360. public:
  1361. bool is_has_chamber(); //是否有未使用的躲避硐室
  1362. int get_section_state(); //路段状态
  1363. int get_section_vehicle_counts(); //路段内车辆总数
  1364. int get_section_staffer_counts(); //路段内人员总数
  1365. };
  1366. class PatrolTask
  1367. {
  1368. public:
  1369. PatrolTask();
  1370. ~PatrolTask();
  1371. private:
  1372. public:
  1373. int patrol_task_id;
  1374. int patrol_path_id;
  1375. string card_id;
  1376. string starffer_id;
  1377. time_t start_time;
  1378. time_t end_time;
  1379. PatrolPointMap mpPoint;
  1380. bool is_in_cur_point;
  1381. int cur_point_idx;
  1382. int state; // 巡检状态
  1383. int stay_state; // 停留时长状态
  1384. int duration_stay; //停留时长
  1385. time_t enter_time; // 进入该节点时间
  1386. time_t leave_time; // 离开当前节点时间
  1387. };
  1388. class PatrolPoint
  1389. {
  1390. public:
  1391. PatrolPoint();
  1392. ~PatrolPoint();
  1393. private:
  1394. public:
  1395. int idx; // 在路径中的索引
  1396. int patrol_point_id;
  1397. int map_id;
  1398. double x; // 区域范围圆心
  1399. double y;
  1400. double z;
  1401. double ranging; // 距离范围
  1402. int duration_last; // 距离上个节点时长
  1403. int duration_stay_min; // 本节点最小时长
  1404. int duration_stay_max; // 本节点最大时长
  1405. int duration_ranging; // 距离上个节点时长最大偏差,含正负
  1406. };
  1407. enum EVENT_TYPE{ // 事件类型
  1408. ET_UNKNOWN = 0,
  1409. ET_OVER_COUNT_PERSON = 1, // 井下人员超员
  1410. ET_OVER_COUNT_VEHICLE = 2, // 井下车辆超员
  1411. ET_AREA_OVER_COUNT_PERSON = 3, // 区域人员超员
  1412. ET_AREA_OVER_COUNT_VEHICLE = 4, // 区域车辆超员
  1413. ET_SECTION_OVER_COUNT = 5, // 路段拥堵
  1414. ET_READER_ERROR = 6, // 分站通信异常
  1415. ET_ctrl_reader_ERROR = 7, // 控制分站异常
  1416. ET_LIGHT_ERROR = 8, // 交通灯异常
  1417. ET_READER_CALL = 9, // 分站呼叫标识卡
  1418. ET_READER_CALL_CANCEL = 10, // 取消呼叫分站
  1419. ET_CARD_LOW_POWER = 11, // 电量低
  1420. ET_CARD_LOW_POWER_SERIOUS = 12, // 电量极低
  1421. ET_CARD_OVER_TIME_PERSON = 13, // 人员井下超时
  1422. ET_CARD_OVER_TIME_VEHICLE = 14, // 车辆井下超时
  1423. ET_CARD_AREA_OVER_TIME_PERSON = 15, // 人员区域超时
  1424. ET_CARD_AREA_OVER_TIME_VEHICLE = 16, // 车辆区域超时
  1425. ET_CARD_AREA_LIMIT_PERSON = 17, // 人员进入限制区域
  1426. ET_CARD_AREA_LIMIT_VEHICLE = 18, // 车辆进入限制区域
  1427. ET_CARD_AREA_FORBIDDEN_PERSON = 19, // 人员进入禁止区域
  1428. ET_CARD_AREA_FORBIDDEN_VEHICLE = 20, // 车辆进入禁止区域
  1429. ET_CARD_OVER_SPEED = 21, // 车辆超速
  1430. ET_CARD_AREA_OVER_SPEED = 22, // 车辆区域超速
  1431. ET_CARD_RUN_THE_RED_LIGHT = 23, // 车辆闯红灯
  1432. ET_CARD_HELP = 24, // 人员呼救
  1433. ET_CARD_CALLED = 25, // 人员已被呼叫
  1434. ET_CARD_PATROL_ERROR = 26, // 人员巡检异常
  1435. ET_CARD_LOST = 27, // 标识卡信号丢失
  1436. ET_CARD_DRIVINGFACE_WARNING_AREA = 28, //掘进面靠近预警区域告警
  1437. CARD_EVENT_COUNT_MAX,
  1438. };
  1439. enum OBJECT_TYPE // 对象类型
  1440. {
  1441. OT_MINE = 1, // 矿井
  1442. OT_AREA = 2, // 区域
  1443. OT_SECTION = 3, // 路段
  1444. OT_DEVICE_READER = 4, // 分站
  1445. OT_DEVICE_LIGHT = 5, // 交通灯
  1446. OT_DEVICE_ctrl_reader = 6, // 控制分站
  1447. OT_DEVICE_LED = 7, // led屏
  1448. OT_DEVICE_SPEAKER = 8, // 防爆音箱
  1449. OT_CARD = 9 // 标识卡,包括人员、车辆、自组网等
  1450. };
  1451. enum EVENT_STATUS{ // 事件状态
  1452. ES_START = 0, // 事件开始
  1453. ES_END = 100 // 事件结束
  1454. };
  1455. enum REQUEST_COUNTS_TYPE{
  1456. REQUEST_ALL = 0,
  1457. REQUEST_ALL_OVER_TIME_PERSON,
  1458. REQUEST_AREA_OVER_TIME_PERSON,
  1459. REQUEST_SPECIAL_ERROR_PERSON,
  1460. REQUEST_ALL_OVER_TIME_VEHICLE,
  1461. REQUEST_AREA_OVER_TIME_VEHICLE,
  1462. REQUEST_ALL_OVER_PERSON,
  1463. REQUEST_AREA_OVER_PERSON,
  1464. REQUEST_ALL_OVER_VEHICLE,
  1465. REQUEST_AREA_OVER_VEHICLE
  1466. };
  1467. class YaEvent
  1468. {
  1469. private:
  1470. INT64 ev_id;
  1471. public:
  1472. YaEvent(){};
  1473. YaEvent(INT64 e_id){
  1474. ev_id = e_id;
  1475. obj_id = "";
  1476. cur_time = time(NULL);
  1477. map_id = 0;
  1478. area_id = 0;
  1479. x = 0;
  1480. y = 0;
  1481. limit_value = 0;
  1482. cur_value = 0;
  1483. desc = "";
  1484. landmarkid = 0;
  1485. landmarkdirect = 0;
  1486. landmarkdist = 0;
  1487. is_count = false;
  1488. };
  1489. ~YaEvent(){};
  1490. public:
  1491. EVENT_STATUS status;
  1492. EVENT_TYPE ev_type;
  1493. OBJECT_TYPE obj_type;
  1494. std::string obj_id;
  1495. time_t cur_time;
  1496. int map_id;
  1497. int area_id;
  1498. double x;
  1499. double y;
  1500. double limit_value;
  1501. double cur_value;
  1502. std::string desc;
  1503. int landmarkid;
  1504. int landmarkdirect;
  1505. int landmarkdist;
  1506. bool is_sent; // 已发送
  1507. bool is_count;
  1508. INT64 get_id(){return ev_id;};
  1509. };
  1510. class LightCallInfo{
  1511. public:
  1512. LightCallInfo(){
  1513. light_id = 0;
  1514. ctrl_type = 0;
  1515. ctrl_color = 0;
  1516. light_state = 0;
  1517. task_id = "";
  1518. }
  1519. public:
  1520. int light_id;
  1521. int ctrl_type;
  1522. int ctrl_color;
  1523. int light_state;
  1524. std::string task_id;
  1525. };
  1526. enum DIRECTION_TYPE{
  1527. NODIRECTORY = 0,
  1528. EAST = 1,
  1529. SOURTH = 2,
  1530. WEST = 3,
  1531. NORTH = 4
  1532. };
  1533. #endif //YASERVER_CLASSDEF_H_