net-service.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include <thread>
  2. #include <mutex>
  3. #include <atomic>
  4. #include <iostream>
  5. #include <memory>
  6. #include <string.h>
  7. #include <math.h>
  8. #include <log.h>
  9. #include <znet.h>
  10. #include <zstream.h>
  11. #include <sys/time.h>
  12. #include "worker.h"
  13. #include "tdoa_sync.h"
  14. #include "net-service.h"
  15. net_service::net_service()
  16. {
  17. m_loc_worker=worker::instance();
  18. m_sync_worker=tdoa_sync::instance();
  19. }
  20. net_service::~net_service()
  21. {
  22. m_loc_worker->stop();
  23. }
  24. void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t len)
  25. {
  26. //clt->send(std::move(v));
  27. logn_bin(1,"",data,len);//输出二进制日志
  28. zistream is(data,len-2);
  29. uint16_t cmd;
  30. is>>skip(2)>>cmd;
  31. switch(cmd)
  32. {
  33. case 0x843b://tof
  34. {
  35. uint32_t site_id;
  36. is>>site_id>>skip(12);
  37. struct timeval tv;
  38. gettimeofday(&tv,NULL);
  39. uint64_t t = tv.tv_sec*1000 + tv.tv_usec/1000;
  40. int index=0;
  41. while(!is.eof())
  42. {
  43. uint64_t tstamp = t -1000 + 50 + index* 45;
  44. index++;
  45. task*t=task::alloc<message_locinfo>();
  46. message_locinfo&m=t->body<message_locinfo>();
  47. m.load(is,cmd==0x863b);
  48. m.m_time_stamp=tstamp;
  49. m.m_site_id=site_id;
  50. if(m.m_card_id != 1222)
  51. {
  52. log_error("----error cardid");
  53. continue;
  54. }
  55. std_info("....%llu",m.m_time_stamp);
  56. t->m_cmd_code=cmd;
  57. t->m_hash_id=m.m_card_id;
  58. m_loc_worker->request(t);
  59. }
  60. }
  61. break;
  62. case 0x863b://tdoa
  63. {
  64. uint32_t site_id;
  65. is>>site_id>>skip(12);
  66. while(!is.eof())
  67. {
  68. task*t=task::alloc<message_locinfo>();
  69. message_locinfo&m=t->body<message_locinfo>();
  70. m.load(is,cmd==0x863b);
  71. m.m_site_id=site_id;
  72. t->m_cmd_code=cmd;
  73. t->m_hash_id=m.m_card_id;
  74. m_sync_worker->translate(m);
  75. m_loc_worker->request(t);
  76. }
  77. }
  78. break;
  79. case 0xa78d://time sync
  80. {
  81. message_tdoasync m;
  82. m.load(is);
  83. m_sync_worker->on_message(m);
  84. }
  85. //site_message::on_sync(this,t.m_param1);
  86. break;
  87. case 0x853b://tof his
  88. case 0x873b://tdoa his
  89. break;
  90. case 0x804c://ctrl site message
  91. break;
  92. }
  93. }