#ifndef sync_time_base_h #define sync_time_base_h #include "sync_time_message.h" namespace host_server{ class sync_time { private: unsigned long long m_upper_id{0}; // 上级分站id unsigned long long m_receive_time{0}; // 接收时间 unsigned long long m_send_time{0}; // 发送时间 unsigned short m_sync_level{0}; // 分站时间同步层级 long long m_delay_time{0}; // 延迟时间 bool m_rtime_over_status{false}; // 接收时间是否溢出,过周期 bool m_stime_over_status{false}; // 发送时间是否溢出,过周期 public: sync_time():m_upper_id(0), m_receive_time(0), m_send_time(0), m_sync_level(0), m_delay_time(0), m_rtime_over_status(false), m_stime_over_status(false) {} sync_time(unsigned long long upperIdCode, long long receiveTime,bool isRTimeOverflow, long long sendTime, bool isSTimeOverflow, unsigned short syncLevel):m_upper_id(upperIdCode), m_receive_time(receiveTime), m_send_time(sendTime), m_sync_level(syncLevel), m_delay_time(0), m_rtime_over_status(isRTimeOverflow), m_stime_over_status(isSTimeOverflow) {} sync_time(sync_time_message& msg, sync_time_message& upper_msg, sync_time* s = nullptr) :m_upper_id(msg.get_upper_id()), m_receive_time(msg.get_local_receive_time()), m_send_time(upper_msg.get_local_send_time()), m_sync_level(msg.get_sync_level()), m_delay_time(0) { // 根据历史记录解决时间戳溢出的问题 if(s == nullptr) { m_rtime_over_status = false; m_stime_over_status = false; } else { m_rtime_over_status = (m_receive_time < s->get_real_receive_time()) ? !s->get_rtime_status() : s->get_rtime_status(); m_stime_over_status = (m_send_time < s->get_real_send_time()) ? !s->get_stime_status() : s->get_stime_status(); // 解决同时溢出的问题 if(m_rtime_over_status && m_stime_over_status) { m_rtime_over_status = false; m_stime_over_status = false; } } } unsigned long long get_upper_id() const { return m_upper_id; } /* * 获得接收时间 * */ unsigned long long get_receive_time() const { return m_receive_time + (m_rtime_over_status ? TIME_MAX : 0); } unsigned long long get_real_receive_time() const { return m_receive_time; } void set_receive_time(unsigned long long& val) { m_receive_time = val; } bool get_rtime_status() const { return m_rtime_over_status; } void set_rtime_status(bool val) { m_rtime_over_status = val; } unsigned long long get_send_time() const { return m_send_time + (m_stime_over_status ? TIME_MAX : 0); } unsigned long long get_real_send_time() const { return m_send_time; } void set_send_time(const unsigned long long& val) { m_send_time = val; } bool get_stime_status() const { return m_stime_over_status; } void set_stime_status(bool val) { m_stime_over_status = val; } unsigned short get_sync_level() const { return m_sync_level; } void set_sync_level(unsigned short val) { m_sync_level = val; } long long get_delay_time() const { return m_delay_time; } void set_delay_time(const long long& val) { m_delay_time = val; } }; } #endif