123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- #ifndef sync_time_manager_h
- #define sync_time_manager_h
- #include <boost/serialization/singleton.hpp>
- #include <unordered_map>
- #include <map>
- #include <deque>
- #include <iostream>
- #include <mutex>
- #include "sync_time_message.h"
- #include "position.h"
- #include "common.h"
- #include "sync_time.h"
- #include "sync_helper.h"
- #include "tag_message.h"
- using namespace std;
- namespace host_server{
- class sync_manager
- {
- struct sync_time_msg_item
- {
- unsigned short sync_num;
- unordered_map<unsigned long long, sync_time_message> ump_sync_time_msg;
- };
- struct sync_time_item
- {
- unsigned short sync_num;
- unordered_map<unsigned long long, sync_time> hist_sync;
- };
- std::recursive_mutex m_mu_sync_time;
-
- bool m_log_status;
- public:
- sync_manager();
- sync_manager(bool status);
- ~sync_manager();
-
- unordered_map<unsigned long long, position> ump_anchors;
-
- unordered_map<unsigned long long, unordered_map<unsigned long long, double>> ump_distance;
-
-
- unordered_map<unsigned long long, deque<sync_time_msg_item>> ump_sync_time_msg;
-
- unordered_map<unsigned long long, deque<sync_time_item>> ump_history_sync;
- public:
-
-
-
-
-
- void init();
-
-
-
-
-
-
- void analyze_sync_msg(sync_time_message& msg);
-
-
-
-
-
-
-
-
-
-
- void update_distance(unsigned int local_id, uint8_t local_ant_num, unsigned int upper_id, uint8_t upper_ant_num, double d);
-
-
-
-
-
-
-
-
-
-
- void update_anchor(unsigned int local_id, uint8_t local_ant_num, double x, double y, double z);
-
-
-
-
-
-
-
-
- void delete_anchor(unsigned int local_id, uint8_t local_ant_num);
-
-
-
-
-
-
-
-
- unsigned long long cal_time_by_linear(tag_message& tag);
- unsigned long long cal_time_by_inter_linear(tag_message& tag);
-
-
-
-
-
-
-
- bool update_sync(unsigned long long root_id_code, int idx, unsigned short sync_num, unsigned long long local_id_code);
- int find_sync_time_msg(unsigned long long root_id_code, unsigned short sync_num);
- int find_his_sync_time(unsigned long long root_id_code, unsigned short sync_num);
- void set_log_status(bool status)
- {
- this->m_log_status = status;
- }
- bool get_log_status() const
- {
- return m_log_status;
- }
-
- long long sub(unsigned long long t1, unsigned long long t2){
- return ((t1 >= t2)? (t1 - t2):(t1 - t2 + TIME_MAX_ADD));
- }
- };
- };
- using singleton_sync_manager = boost::serialization::singleton<host_server::sync_manager>;
- #define ssync_manager singleton_sync_manager::get_mutable_instance()
- #endif
|