1
0

net-service.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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=nullptr;
  18. m_sync_worker=nullptr;
  19. m_loc_worker=worker::instance();
  20. m_sync_worker=tdoa_sync::instance();
  21. }
  22. net_service::~net_service()
  23. {
  24. if(m_loc_worker)
  25. m_loc_worker->stop();
  26. }
  27. void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t len)
  28. {
  29. //clt->send(std::move(v));
  30. logn_bin(1,"",data,len);//输出二进制日志
  31. zistream is(data,len-2);
  32. uint16_t cmd;
  33. is>>skip(2)>>cmd;
  34. switch(cmd)
  35. {
  36. case 0x843b://tof
  37. {
  38. uint32_t site_id;
  39. is>>site_id>>skip(12);
  40. struct timeval tv;
  41. gettimeofday(&tv,NULL);
  42. uint64_t t = tv.tv_sec*1000 + tv.tv_usec/1000;
  43. int index=0;
  44. while(!is.eof())
  45. {
  46. uint64_t tstamp = t -1000 + 50 + index* 45;
  47. index++;
  48. task*t=task::alloc<message_locinfo>();
  49. message_locinfo&m=t->body<message_locinfo>();
  50. m.load(is,cmd==0x863b);
  51. m.m_time_stamp=tstamp;
  52. m.m_site_id=site_id;
  53. t->m_cmd_code=cmd;
  54. t->m_hash_id=m.m_card_id;
  55. m_loc_worker->request(t);
  56. }
  57. }
  58. break;
  59. case 0x863b://tdoa
  60. {
  61. uint32_t site_id;
  62. is>>site_id>>skip(12);
  63. while(!is.eof())
  64. {
  65. task*t=task::alloc<message_locinfo>();
  66. message_locinfo&m=t->body<message_locinfo>();
  67. m.load(is,cmd==0x863b);
  68. m.m_site_id=site_id;
  69. t->m_cmd_code=cmd;
  70. t->m_hash_id=m.m_card_id;
  71. m_sync_worker->translate(m);
  72. m_loc_worker->request(t);
  73. }
  74. }
  75. break;
  76. case 0xa78d://time sync
  77. {
  78. message_tdoasync m;
  79. m.load(is);
  80. m_sync_worker->on_message(m);
  81. }
  82. //site_message::on_sync(this,t.m_param1);
  83. break;
  84. case 0x853b://tof his
  85. case 0x873b://tdoa his
  86. break;
  87. case 0x804c://ctrl site message
  88. break;
  89. }
  90. }