net-service.cpp 1.8 KB

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