tdoa_sync.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #include "tdoa_sync.h"
  2. #include "sync_time/sync_time_message.h"
  3. #include "sync_manager.h"
  4. #include <log.h>
  5. #include <config_file.h>
  6. extern config_file config;
  7. struct tdoa_sync_impl:tdoa_sync
  8. {
  9. virtual void on_message(message_tdoasync&msg)
  10. {
  11. host_server::sync_time_message _sync_msg;
  12. _sync_msg.set_local_id((unsigned long long)(msg.m_local_site_id));
  13. _sync_msg.set_local_id((unsigned long long)((_sync_msg.get_local_id() << 8) + msg.m_local_ant_id));
  14. _sync_msg.set_upper_id((unsigned long long)(msg.m_parent_site_id));
  15. _sync_msg.set_upper_id((unsigned long long)((_sync_msg.get_upper_id() << 8) + msg.m_parent_ant_id));
  16. _sync_msg.set_root_id((unsigned long long)(msg.m_root_site_id));
  17. _sync_msg.set_root_id((unsigned long long)((_sync_msg.get_root_id() << 8) + msg.m_root_ant_id));
  18. _sync_msg.set_sync_num(msg.m_sync_num);
  19. _sync_msg.set_sync_level(msg.m_local_level);
  20. _sync_msg.set_local_send_time(msg.m_send_time);
  21. _sync_msg.set_local_receive_time(msg.m_recv_time);
  22. auto _sync_msg_tmp = _sync_msg;
  23. for (auto iter = ssync_manager.map_id_manager.begin();
  24. iter != ssync_manager.map_id_manager.end();
  25. iter++)
  26. iter->second.analyze_sync_msg(_sync_msg);
  27. //ssync_manager.analyze_sync_msg(_sync_msg);
  28. }
  29. virtual void translate(message_tdoa_locinfo& tdoa_msg)
  30. {
  31. host_server::tag_message _tag_msg;
  32. _tag_msg.m_receive_time = tdoa_msg.m_card_msg.m_loc_stamp;
  33. _tag_msg.m_local_id = host_server::sync_helper::parse_id((unsigned long long)tdoa_msg.m_site_msg.m_site_id, (unsigned long long)(tdoa_msg.m_card_msg.m_ant_id + 1));
  34. _tag_msg.m_sync_num = tdoa_msg.m_card_msg.m_sync_num;
  35. _tag_msg.m_sync_root_id = ssync_manager.sRootIdCode;
  36. unsigned long long rootIdCode = ssync_manager.sRootIdCode;
  37. if (ssync_manager.map_id_manager.count(tdoa_msg.m_card_msg.m_id) == 0)
  38. {
  39. ssync_manager.map_id_manager[tdoa_msg.m_card_msg.m_id].sRootIdCode = ssync_manager.sRootIdCode;
  40. //ssync_manager.map_id_manager[loc.m_card_msg.m_id].m_mu_sync_time = m_mu_sync_time;
  41. ssync_manager.map_id_manager[tdoa_msg.m_card_msg.m_id].m_log_status = ssync_manager.m_log_status;
  42. ssync_manager.map_id_manager[tdoa_msg.m_card_msg.m_id].ump_anchors = ssync_manager.ump_anchors;
  43. ssync_manager.map_id_manager[tdoa_msg.m_card_msg.m_id].ump_distance = ssync_manager.ump_distance;
  44. ssync_manager.map_id_manager[tdoa_msg.m_card_msg.m_id].ump_sync_time_msg = ssync_manager.ump_sync_time_msg;
  45. ssync_manager.map_id_manager[tdoa_msg.m_card_msg.m_id].ump_history_sync = ssync_manager.ump_history_sync;
  46. }
  47. int idx = ssync_manager.map_id_manager[tdoa_msg.m_card_msg.m_id].find_sync_time_msg(rootIdCode, _tag_msg.m_sync_num);
  48. if (idx >= 0)
  49. {
  50. ssync_manager.map_id_manager[tdoa_msg.m_card_msg.m_id].ump_sync_time_msg[rootIdCode][idx].ump_sync_time_msg_item[_tag_msg.m_local_id].tag = _tag_msg;
  51. tdoa_msg.m_interpolation = ssync_manager.map_id_manager[tdoa_msg.m_card_msg.m_id].ump_sync_time_msg[rootIdCode][idx].ump_sync_time_msg_item[_tag_msg.m_local_id].map_tdoa_msg[tdoa_msg.m_card_msg.m_id].m_interpolation;
  52. ssync_manager.map_id_manager[tdoa_msg.m_card_msg.m_id].ump_sync_time_msg[rootIdCode][idx].ump_sync_time_msg_item[_tag_msg.m_local_id].map_tdoa_msg[tdoa_msg.m_card_msg.m_id] = tdoa_msg;
  53. ssync_manager.map_id_manager[tdoa_msg.m_card_msg.m_id].ump_sync_time_msg[rootIdCode][idx].nDataCount++;
  54. /*if (ssync_manager.ump_sync_time_msg[rootIdCode][idx].nCardCount<
  55. ssync_manager.ump_sync_time_msg[rootIdCode][idx].ump_sync_time_msg[_tag_msg.m_local_id].map_tdoa_msg.size())
  56. {
  57. ssync_manager.ump_sync_time_msg[rootIdCode][idx].nCardCount = ssync_manager.ump_sync_time_msg[rootIdCode][idx].ump_sync_time_msg[_tag_msg.m_local_id].map_tdoa_msg.size();
  58. }*/
  59. int nDataCount = ssync_manager.map_id_manager[tdoa_msg.m_card_msg.m_id].ump_sync_time_msg[rootIdCode][idx].nDataCount;
  60. int nSize = ssync_manager.map_id_manager[tdoa_msg.m_card_msg.m_id].ump_sync_time_msg[rootIdCode][idx].ump_sync_time_msg_item.size();
  61. //if (nDataCount >= 3 && nDataCount >= nSize * ssync_manager.ump_sync_time_msg[rootIdCode][idx].nCardCount)
  62. if (nDataCount >= 8)
  63. {
  64. for (auto it = ssync_manager.map_id_manager[tdoa_msg.m_card_msg.m_id].ump_sync_time_msg[rootIdCode][idx].ump_sync_time_msg_item.begin();
  65. it != ssync_manager.map_id_manager[tdoa_msg.m_card_msg.m_id].ump_sync_time_msg[rootIdCode][idx].ump_sync_time_msg_item.end();
  66. it++)
  67. {
  68. // 线性插值后的值
  69. uint64_t ip_value = 0;
  70. // 线性插值类型
  71. int ip_type = config.get("service.interpolation", 0);
  72. switch (ip_type) {
  73. case 0:
  74. ip_value = ssync_manager.map_id_manager[tdoa_msg.m_card_msg.m_id].cal_time_by_linear(it->second.tag);
  75. break;
  76. case 1:
  77. ip_value = ssync_manager.map_id_manager[tdoa_msg.m_card_msg.m_id].cal_time_by_inter_linear(it->second.tag);
  78. break;
  79. default:
  80. break;
  81. }
  82. if (0 == ip_value) {
  83. ip_value = LONGLONG_MAX;
  84. }
  85. for (auto iter_tmp = it->second.map_tdoa_msg.begin(); iter_tmp != it->second.map_tdoa_msg.end(); iter_tmp++)
  86. iter_tmp->second.m_interpolation = ip_value;
  87. }
  88. }
  89. }
  90. }
  91. };
  92. tdoa_sync*tdoa_sync::instance()
  93. {
  94. static tdoa_sync_impl _impl;
  95. return &_impl;
  96. }