|
@@ -57,14 +57,14 @@ static bool check_message_time(const std::shared_ptr<client> &clt, const std::sh
|
|
|
|
|
|
time_t site_time=mktime(p_site_tm);
|
|
time_t site_time=mktime(p_site_tm);
|
|
double diff=difftime(site_time, site_ptr->last_site_time());
|
|
double diff=difftime(site_time, site_ptr->last_site_time());
|
|
- if(diff<-3) //允许2秒的时间抖动
|
|
|
|
|
|
+ if(diff<-6) //允许2秒的时间抖动 3
|
|
{
|
|
{
|
|
logn_error(1,"分站时间回退,数据将被丢弃:net=%s,site=%d,diff=%d",clt->name().c_str(),site_ptr->m_id,(int)diff);
|
|
logn_error(1,"分站时间回退,数据将被丢弃:net=%s,site=%d,diff=%d",clt->name().c_str(),site_ptr->m_id,(int)diff);
|
|
result=false;
|
|
result=false;
|
|
}
|
|
}
|
|
|
|
|
|
diff=difftime(site_time, time(nullptr));
|
|
diff=difftime(site_time, time(nullptr));
|
|
- if(fabs(diff)>3)
|
|
|
|
|
|
+ if(fabs(diff)>6) //3
|
|
{
|
|
{
|
|
logn_error(1,"分站时间与服务器时间相差太大:%s,site=%d,diff=%d",clt->name().c_str(),site_ptr->m_id,(int)diff);
|
|
logn_error(1,"分站时间与服务器时间相差太大:%s,site=%d,diff=%d",clt->name().c_str(),site_ptr->m_id,(int)diff);
|
|
result=false;
|
|
result=false;
|
|
@@ -212,11 +212,9 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
|
|
if(!site_ptr){
|
|
if(!site_ptr){
|
|
logn_error(1,"在全局分站列表中找不到分站:%d", site_id);
|
|
logn_error(1,"在全局分站列表中找不到分站:%d", site_id);
|
|
break;
|
|
break;
|
|
- }else{
|
|
|
|
- //logn_info(3, "[pdoa] site_id:%d, x:%.4f, y:%.4f", site_ptr->m_id, site_ptr->x, site_ptr->y);
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- if(clt->type() != 2){
|
|
|
|
|
|
+ if(clt->type() != 2){
|
|
site_ptr->set_client(clt);
|
|
site_ptr->set_client(clt);
|
|
//site_ptr->on_power_status((power&1)==0);
|
|
//site_ptr->on_power_status((power&1)==0);
|
|
}
|
|
}
|
|
@@ -250,39 +248,18 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
- case 0x783A://tof 分站时间同步
|
|
|
|
|
|
+ case CHAR_NET_CALI_TIME://tof 分站时间同步
|
|
{
|
|
{
|
|
- // 从第一个字节开始,分别表示毫秒(2字节)、秒、分、时、天、月、年
|
|
|
|
- unsigned char buf[20]={0,13,0x78,0x3b};
|
|
|
|
-
|
|
|
|
- struct timeval tv;
|
|
|
|
- gettimeofday(&tv,0);
|
|
|
|
-
|
|
|
|
- struct tm buff={0};
|
|
|
|
- const struct tm*t=localtime_r(&tv.tv_sec,&buff);
|
|
|
|
-
|
|
|
|
- int p=4;
|
|
|
|
- buf[p++]=(tv.tv_usec/1000)&0xFF;
|
|
|
|
- buf[p++]=((tv.tv_usec/1000)>>8)&0xFF;
|
|
|
|
-
|
|
|
|
- buf[p++]=t->tm_sec;
|
|
|
|
- buf[p++]=t->tm_min;
|
|
|
|
- buf[p++]=t->tm_hour;
|
|
|
|
- buf[p++]=t->tm_mday;
|
|
|
|
- buf[p++]=t->tm_wday;
|
|
|
|
- buf[p++]=t->tm_mon+1;
|
|
|
|
- buf[p++]=t->tm_year-100;
|
|
|
|
-
|
|
|
|
- uint16_t ccrc=do_crc(buf+2,11);
|
|
|
|
-
|
|
|
|
- buf[p++]=ccrc>>8;
|
|
|
|
- buf[p++]=ccrc&0xff;
|
|
|
|
-
|
|
|
|
- std::vector<char> tmp((char*)buf,(char*)buf+15);
|
|
|
|
- clt->send(std::move(tmp));
|
|
|
|
-
|
|
|
|
- logn_info(1,"分站时间同步:ip=%s,time=%d-%02d-%02d %02d:%02d:%02d.%03d",
|
|
|
|
- clt->name().c_str(),buf[12]+2000,buf[11],buf[9],buf[8],buf[7],buf[6],buf[5]*256+buf[4]);
|
|
|
|
|
|
+ // 网络设备校时
|
|
|
|
+ net_cali_time(clt);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case CHAR_CAN_CALI_TIME:
|
|
|
|
+ {
|
|
|
|
+ // can设备校时
|
|
|
|
+ uint32_t rid=0;
|
|
|
|
+ is>>rid;
|
|
|
|
+ can_cali_time(clt, rid);
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case CHAR_LOCATEDATA_TDOA_EXTEND: // 0x863b
|
|
case CHAR_LOCATEDATA_TDOA_EXTEND: // 0x863b
|
|
@@ -328,8 +305,9 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
|
|
break;
|
|
break;
|
|
|
|
|
|
case CHAR_READER_HEART:
|
|
case CHAR_READER_HEART:
|
|
- {
|
|
|
|
- uint32_t id = 0;
|
|
|
|
|
|
+ {
|
|
|
|
+ //通信基站心跳
|
|
|
|
+ uint32_t id = 0;
|
|
uint16_t site_ct = 0;
|
|
uint16_t site_ct = 0;
|
|
uint16_t reserve = 0;
|
|
uint16_t reserve = 0;
|
|
is>>id>>site_ct>>reserve;
|
|
is>>id>>site_ct>>reserve;
|
|
@@ -339,6 +317,8 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
|
|
logn_error(1,"在全局分站列表中找不到分站:%d", id);
|
|
logn_error(1,"在全局分站列表中找不到分站:%d", id);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ site_ptr->m_device_type_id = 0x08;
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case 0x793B: //虚拟推送的心跳测试
|
|
case 0x793B: //虚拟推送的心跳测试
|
|
@@ -494,7 +474,9 @@ int32_t net_service::parse_data_anchor_opt(const std::shared_ptr<client>& clt, z
|
|
return -1;
|
|
return -1;
|
|
}*/
|
|
}*/
|
|
|
|
|
|
- //check_message_time(clt, site_ptr, &site_tm, site_ct, power);
|
|
|
|
|
|
+ if(!check_message_time(clt, site_ptr, &site_tm, site_ct, power)){
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
|
|
site_ptr->m_device_type_id = (power>>3)&0x07;
|
|
site_ptr->m_device_type_id = (power>>3)&0x07;
|
|
|
|
|
|
@@ -503,36 +485,83 @@ int32_t net_service::parse_data_anchor_opt(const std::shared_ptr<client>& clt, z
|
|
site_ptr->on_power_status((power&1)==0);
|
|
site_ptr->on_power_status((power&1)==0);
|
|
}
|
|
}
|
|
|
|
|
|
- logn_info(1,"分站数据:site_id: %d, site_ct: %d, time: %s, power: %d", site_id, site_ct, tool_time::to_str_ex(&site_tm).c_str(), power);
|
|
|
|
|
|
+ uint64_t tt = site_time_stamp;
|
|
|
|
+ tt *= 1000;
|
|
|
|
+ logn_info(1,"分站数据:site_id: %d, site_ct: %d, time_t: %llu, time: %s, power: %d", site_id, site_ct, tt, tool_time::to_str_ex(tt).c_str(), power);
|
|
|
|
|
|
return site_id;
|
|
return site_id;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void net_service::net_cali_time(const std::shared_ptr<client>& clt)
|
|
|
|
+{
|
|
|
|
+ // 从第一个字节开始,分别表示毫秒(2字节)、秒、分、时、天、月、年
|
|
|
|
+ unsigned char buf[20]={0,13,0x78,0x3b};
|
|
|
|
|
|
|
|
+ struct timeval tv;
|
|
|
|
+ gettimeofday(&tv,0);
|
|
|
|
+
|
|
|
|
+ struct tm buff={0};
|
|
|
|
+ const struct tm*t=localtime_r(&tv.tv_sec,&buff);
|
|
|
|
+
|
|
|
|
+ int p=4;
|
|
|
|
+ buf[p++]=(tv.tv_usec/1000)&0xFF;
|
|
|
|
+ buf[p++]=((tv.tv_usec/1000)>>8)&0xFF;
|
|
|
|
+
|
|
|
|
+ buf[p++]=t->tm_sec+1; // 由于硬件扫描方式会慢1秒,给补偿1秒
|
|
|
|
+ buf[p++]=t->tm_min;
|
|
|
|
+ buf[p++]=t->tm_hour;
|
|
|
|
+ buf[p++]=t->tm_mday;
|
|
|
|
+ buf[p++]=t->tm_wday;
|
|
|
|
+ buf[p++]=t->tm_mon+1;
|
|
|
|
+ buf[p++]=t->tm_year%100;
|
|
|
|
+
|
|
|
|
+ uint16_t ccrc=do_crc(buf+2,11);
|
|
|
|
+
|
|
|
|
+ buf[p++]=ccrc>>8;
|
|
|
|
+ buf[p++]=ccrc&0xff;
|
|
|
|
+
|
|
|
|
+ std::vector<char> tmp((char*)buf,(char*)buf+15);
|
|
|
|
+ clt->send(std::move(tmp));
|
|
|
|
+
|
|
|
|
+ logn_info(1,"分站时间同步:ip=%s,time=%d-%02d-%02d %02d:%02d:%02d.%03d",
|
|
|
|
+ clt->name().c_str(),buf[12]+2000,buf[11],buf[9],buf[8],buf[7],buf[6],buf[5]*256+buf[4]);
|
|
|
|
|
|
-void net_service::parse_data_card()
|
|
|
|
-{
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-/*float net_service::get_pdoa(float poa[], const double& offset)
|
|
|
|
|
|
+void net_service::can_cali_time(const std::shared_ptr<client>& clt, const int& reader_id)
|
|
{
|
|
{
|
|
- if(poa == nullptr){
|
|
|
|
- return -10.0;
|
|
|
|
- }
|
|
|
|
|
|
+ unsigned char buf[30]={0,17,0x78,0x4b};
|
|
|
|
|
|
- float poa1 = poa[0];
|
|
|
|
- float poa2 = poa[1];
|
|
|
|
|
|
+ struct timeval tv;
|
|
|
|
+ gettimeofday(&tv,0);
|
|
|
|
|
|
- float pdoa = poa2 - poa1 - offset;
|
|
|
|
- while(pdoa >= TPI){
|
|
|
|
- pdoa -= TPI;
|
|
|
|
- }
|
|
|
|
|
|
+ struct tm buff = {0};
|
|
|
|
+ const struct tm *t = localtime_r(&tv.tv_sec,&buff);
|
|
|
|
|
|
- while(pdoa < 0){
|
|
|
|
- pdoa += TPI;
|
|
|
|
- }
|
|
|
|
|
|
+ int p=4;
|
|
|
|
+ for(int i = sizeof(uint32_t) - 1; i >= 0; --i)
|
|
|
|
+ {
|
|
|
|
+ buf[p++] = ((reader_id>>(i*8))&0xFF);
|
|
|
|
+ }
|
|
|
|
+ buf[p++]=(tv.tv_usec/1000)&0xFF;
|
|
|
|
+ buf[p++]=((tv.tv_usec/1000)>>8)&0xFF;
|
|
|
|
|
|
- pdoa -= PI;
|
|
|
|
|
|
+ buf[p++]=t->tm_sec;
|
|
|
|
+ buf[p++]=t->tm_min;
|
|
|
|
+ buf[p++]=t->tm_hour;
|
|
|
|
+ buf[p++]=t->tm_mday;
|
|
|
|
+ buf[p++]=t->tm_wday;
|
|
|
|
+ buf[p++]=t->tm_mon+1;
|
|
|
|
+ buf[p++]=t->tm_year%100;
|
|
|
|
|
|
- return pdoa;
|
|
|
|
-}*/
|
|
|
|
|
|
+ uint16_t ccrc=do_crc(buf+2,15);
|
|
|
|
+
|
|
|
|
+ buf[p++]=ccrc>>8;
|
|
|
|
+ buf[p++]=ccrc&0xff;
|
|
|
|
+
|
|
|
|
+ std::vector<char> tmp((char*)buf,(char*)buf+19);
|
|
|
|
+ clt->send(std::move(tmp));
|
|
|
|
+
|
|
|
|
+ logn_info(1,"分站时间同步:site_id=%d, ip=%s, p=%d, time=%d-%02d-%02d %02d:%02d:%02d.%03d",
|
|
|
|
+ reader_id, clt->name().c_str(), p, buf[16]+2000, buf[15], buf[13], buf[12], buf[11], buf[10], buf[9]*256+buf[8]);
|
|
|
|
+}
|