|
@@ -40,6 +40,37 @@ void net_service::on_connect(const std::shared_ptr<client>& clt)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+static bool check_message_time(const std::shared_ptr<client> &clt, const std::shared_ptr<site> &site_ptr, struct tm*p_site_tm, int site_ct, int power)
|
|
|
+{
|
|
|
+ bool result=true;
|
|
|
+
|
|
|
+ char timebuf[64]{0};
|
|
|
+ strftime(timebuf,64,"%F %T",p_site_tm);
|
|
|
+
|
|
|
+ logn_info(1,"分站数据信息:net=%s,site=%d,tm=%s,sct=%d,power=%s", clt->name().c_str(), site_ptr->m_id,timebuf,
|
|
|
+ site_ct, site_ptr->m_power_check_enable?((power&1)?"ac":"dc"):"??");
|
|
|
+
|
|
|
+ time_t site_time=mktime(p_site_tm);
|
|
|
+ double diff=difftime(site_time, site_ptr->last_site_time());
|
|
|
+ if(diff<-3) //允许2秒的时间抖动
|
|
|
+ {
|
|
|
+ logn_error(1,"分站时间回退,数据将被丢弃:net=%s,site=%d,diff=%d",clt->name().c_str(),site_ptr->m_id,(int)diff);
|
|
|
+ result=false;
|
|
|
+ }
|
|
|
+
|
|
|
+ diff=difftime(site_time, time(nullptr));
|
|
|
+ if(fabs(diff)>3)
|
|
|
+ {
|
|
|
+ logn_error(1,"分站时间与服务器时间相差太大:%s,site=%d,diff=%d",clt->name().c_str(),site_ptr->m_id,(int)diff);
|
|
|
+ result=false;
|
|
|
+ }
|
|
|
+
|
|
|
+ site_ptr->set_site_time(site_time);
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,size_t len)
|
|
|
{
|
|
|
bool message_handled=true;
|
|
@@ -68,7 +99,7 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
|
|
|
const auto &site_ptr = sit_list::instance()->get(static_cast<int32_t>(site_id));
|
|
|
if(!site_ptr)
|
|
|
{
|
|
|
- logn_error(1,"在全局分站列表中找不到分站:%s,%d", clt->name().c_str(), site_id);
|
|
|
+ logn_error(1,"未定义分站:net=%s,site=%d", clt->name().c_str(), site_id);
|
|
|
break;
|
|
|
}
|
|
|
|
|
@@ -78,21 +109,7 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- {
|
|
|
- char timebuf[64]{0};
|
|
|
- strftime(timebuf,64,"%F %T",&site_tm);
|
|
|
- logn_info(1,"分站数据信息:net=%s,sid=%d,tm=%s,sct=%d,power=%s", clt->name().c_str(), site_id,timebuf,
|
|
|
- site_ct, site_ptr->m_power_check_enable?((power&1)?"ac":"dc"):"??");
|
|
|
-
|
|
|
- time_t site_time=mktime(&site_tm);
|
|
|
- double diff=difftime(site_time, site_ptr->last_site_time());
|
|
|
- if(diff<-3) //允许2秒的时间抖动
|
|
|
- {
|
|
|
- logn_error(1,"分站时间回退,数据将被丢弃:%s,diff=%d",clt->name().c_str(),(int)diff);
|
|
|
- }
|
|
|
-
|
|
|
- site_ptr->set_site_time(site_time);
|
|
|
- }
|
|
|
+ check_message_time(clt,site_ptr,&site_tm,site_ct,power);
|
|
|
|
|
|
if(clt->type()!=2){
|
|
|
site_ptr->set_client(clt);
|
|
@@ -146,31 +163,9 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- {
|
|
|
- char timebuf[64]{0};
|
|
|
- struct tm site_tm={0};
|
|
|
- localtime_r(&site_time, &site_tm);
|
|
|
-
|
|
|
- strftime(timebuf,64,"%F %T",&site_tm);
|
|
|
- const char*power_flag="??";
|
|
|
- if(site_ptr->m_power_check_enable)
|
|
|
- {
|
|
|
- if(power==1)
|
|
|
- power_flag="dc";
|
|
|
- if(power==2)
|
|
|
- power_flag="ac";
|
|
|
- }
|
|
|
-
|
|
|
- logn_info(1,"分站数据信息:net=%s,sid=%d,tm=%s,sct=%d,power=%s", clt->name().c_str(), site_id,timebuf, site_ct, power_flag);
|
|
|
-
|
|
|
- double diff=difftime(site_time, site_ptr->last_site_time());
|
|
|
- if(diff<-3) //允许2秒的时间抖动
|
|
|
- {
|
|
|
- logn_error(1,"分站时间回退,数据将被丢弃:%s,diff=%d",clt->name().c_str(),(int)diff);
|
|
|
- }
|
|
|
-
|
|
|
- site_ptr->set_site_time(site_time);
|
|
|
- }
|
|
|
+ struct tm site_tm={0};
|
|
|
+ localtime_r(&site_time, &site_tm);
|
|
|
+ check_message_time(clt,site_ptr,&site_tm,site_ct,power);
|
|
|
|
|
|
if(clt->type()!=2){
|
|
|
site_ptr->set_client(clt);
|