main_test.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #pragma once
  2. #include "db_api/CDBSingletonDefine.h"
  3. #include"module_service/module_mgr.h"
  4. void test_find_path(const point&p1,const point&p2)
  5. {
  6. printf("\nfind-path: from=(%.3lf,%.3lf),to=(%.3lf,%.3lf)\n",p1.x,p1.y,p2.x,p2.y);
  7. std::vector<point> rc=card_path::inst().find_path(p1,p2);
  8. for(uint32_t i=0;i<rc.size();i++)
  9. printf("x=%.3lf,y=%.3lf\n",rc[i].x,rc[i].y);
  10. }
  11. struct test_Sa{
  12. static void test_savedata2db(void * p)
  13. {
  14. while(true)
  15. {
  16. std::string sql = "CALL add_att_staff(0010000002323, 2323, '2018-12-14 14:00:14', '2018-12-14 14:00:14', 0, 0, 0.000);";
  17. sDBConnPool.PushAsync(sql.c_str());
  18. //boost::this_thread::sleep( boost::posix_time::microseconds( 10000 ) );
  19. usleep(1000*1000);
  20. }
  21. }
  22. static void test_query(void *p)
  23. {
  24. std::string sql = "SELECT ve.vehicle_id, ve.card_id, c.card_type_id, \
  25. ve.dept_id, ve.group_id, v.vehicle_type_id, vt.vehicle_level_id, \
  26. vt.is_railroad AS vt_is_railroad,ve.need_display ,ve.power_alarm,\
  27. vt.vehicle_category_id,v.bigger_car_flag,vc.over_speed \
  28. FROM dat_vehicle_extend ve \
  29. LEFT JOIN dat_vehicle v ON ve.vehicle_id = v.vehicle_id \
  30. LEFT JOIN dat_card c ON ve.card_id = c.card_id \
  31. LEFT JOIN dat_dept d ON ve.dept_id = d.dept_id \
  32. LEFT JOIN dat_group g ON ve.group_id = g.group_id \
  33. LEFT JOIN dat_vehicle_type vt ON v.vehicle_type_id = vt.vehicle_type_id \
  34. LEFT JOIN dat_vehicle_category vc ON vc.vehicle_category_id = vt.vehicle_category_id \
  35. WHERE c.state_id = 0";
  36. std::string Error;
  37. YADB::CDBResultSet DBRes;
  38. while(true)
  39. {
  40. if (!sDBConnPool.Query(sql.c_str(),DBRes,Error))
  41. {
  42. printf(" Error = %s \n",Error.c_str());
  43. }
  44. usleep(10);
  45. }
  46. }
  47. static void Test_JsonDataSend(void * p)
  48. {
  49. std::string text = "";
  50. FILE * pfile = fopen("message_error.json","r");
  51. if ( NULL != pfile)
  52. {
  53. char p[10240] = {0};
  54. while(!feof(pfile))
  55. {
  56. memset(p,0,sizeof(p));
  57. fread(p,1,sizeof(p) - 1,pfile);
  58. text += std::string(p);
  59. }
  60. fclose(pfile);
  61. }
  62. int count = 0;
  63. while(true)
  64. {
  65. swsClientMgr.send(JSON_CMD_VALUE_PUSH,text);
  66. usleep(1000*1000*2);
  67. printf("WSClient Send DataLen=%d count=%d \n",(int)text.length(),count++);
  68. }
  69. }
  70. static void test_geofault(void * p)
  71. {
  72. sleep(5);
  73. std::shared_ptr<card_location_base> c = card_list::instance()->get_card_by_cid(1116);
  74. if (c != nullptr)
  75. {
  76. double x = 2542.0;
  77. double y = -180;
  78. double a = 2;
  79. point p(2542.0,y,0); //2542.0,-227.2,
  80. c->set(p);
  81. c->get_area_tool()->m_site = sit_list::instance()->get(245);
  82. while (true)
  83. {
  84. y = y - a;
  85. if (y < -222)
  86. {
  87. a = -2;
  88. }
  89. else if (y > -180)
  90. {
  91. a = 2;
  92. }
  93. c->set(x,y,0);
  94. p.set(x,y,0);
  95. c->get_area_tool()->on_point(c,p);
  96. sleep(1);
  97. }
  98. }
  99. }
  100. };
  101. void test_createthread()
  102. {
  103. for (int i = 0 ; i < 1 ; i++)
  104. {
  105. new std::thread( std::bind( &test_Sa::test_geofault, &i ) );
  106. }
  107. }