1. pcap解析工具

Libpcap是Packet Capture Libray的英文缩写,即数据包捕获函数库。提供的接口函数实现和封装了与数据包截获有关的过程。

        安装方法:sudo apt install libpcap-dev

2. pcap header中的时间戳解析

Libpcap中的packet的header结构如下:

struct timeval
{__time_t tv_sec;       /* Seconds.  */__suseconds_t tv_usec;   /* Microseconds.  */
};struct pcap_pkthdr {struct timeval ts;    /* time stamp */bpf_u_int32 caplen; /* length of portion present */bpf_u_int32 len; /* length this packet (off wire) */
};

其中 ,ts即为接收时间戳。利用Libpcap库中的pcap_next_ex()函数可从packet中解析其header数据

int InputPCAP::getPacket(velodyne_msgs::VelodynePacket *pkt, const double time_offset){struct pcap_pkthdr *header;const u_char *pkt_data;while (true){int res;if ((res = pcap_next_ex(pcap_, &header, &pkt_data)) >= 0){// Skip packets not for the correct port and from the// selected IP address.if (0 == pcap_offline_filter(&pcap_packet_filter_,header, pkt_data))continue;// Keep the reader from blowing through the file.if (read_fast_ == false)packet_rate_.sleep();memcpy(&pkt->data[0], pkt_data+42, packet_size);if (!gps_time_) {if (!pcap_time_) {pkt->stamp = ros::Time::now(); // time_offset not considered here, as no synchronization required} else {pkt->stamp = ros::Time(header->ts.tv_sec, header->ts.tv_usec * 1000); // }} else {// time for each packet is a 4 byte uint located starting at offset 1200 in// the data packetpkt->stamp = rosTimeFromGpsTimestamp(&(pkt->data[1200]), header);}empty_ = false;return 0;                   // success}if (empty_)                 // no data in file?{ROS_WARN("Error %d reading Velodyne packet: %s", res, pcap_geterr(pcap_));return -1;}if (read_once_){ROS_INFO("end of file reached -- done reading.");return -1;}if (repeat_delay_ > 0.0){ROS_INFO("end of file reached -- delaying %.3f seconds.",repeat_delay_);usleep(rint(repeat_delay_ * 1000000.0));}ROS_DEBUG("replaying Velodyne dump file");// I can't figure out how to rewind the file, because it// starts with some kind of header.  So, close the file// and reopen it with pcap.pcap_close(pcap_);pcap_ = pcap_open_offline(filename_.c_str(), errbuf_);empty_ = true;              // maybe the file disappeared?} // loop back and try again}

3. pcap data中gps时间格式

velodyne的数据包格式中gps timestamp数据存放于[1200~1203],共4个字节。表示一小时内的毫秒数。

4. gps时间戳合成

第一步 从packet的status data中获取gps timestamp;

第二步 提取header中的时间戳,并将精度保留到小时;

第三步 将第二步结果与gps timestamp结合,得到时间戳;

第四步 对齐时间戳。

ros::Time resolveHourAmbiguity(const ros::Time &stamp, const ros::Time &nominal_stamp) {const int HALFHOUR_TO_SEC = 1800;ros::Time retval = stamp;if (nominal_stamp.sec > stamp.sec) {if (nominal_stamp.sec - stamp.sec > HALFHOUR_TO_SEC) {retval.sec = retval.sec + 2*HALFHOUR_TO_SEC;}} else if (stamp.sec - nominal_stamp.sec > HALFHOUR_TO_SEC) {retval.sec = retval.sec - 2*HALFHOUR_TO_SEC;}return retval;
}ros::Time rosTimeFromGpsTimestamp(const uint8_t * const data, const struct pcap_pkthdr *header = NULL) {const int HOUR_TO_SEC = 3600;// time for each packet is a 4 byte uint// It is the number of microseconds from the top of the houruint32_t usecs = (uint32_t) ( ((uint32_t) data[3]) << 24 |((uint32_t) data[2] ) << 16 |((uint32_t) data[1] ) << 8 |((uint32_t) data[0] ));ROS_INFO("gpstime: %d", usecs);ros::Time time_nom = ros::Time();// if header is NULL, assume real time operationif (!header) {time_nom = ros::Time::now(); // use this to recover the hour} else {ROS_INFO("header sec: %ld, usec: %ld", header->ts.tv_sec, header->ts.tv_usec);time_nom = ros::Time(header->ts.tv_sec, header->ts.tv_usec * 1000);}uint32_t cur_hour = time_nom.sec / HOUR_TO_SEC;ros::Time stamp = ros::Time((cur_hour * HOUR_TO_SEC) + (usecs / 1000000),(usecs % 1000000) * 1000);ROS_INFO("before stamp sec: %d, nsec: %d", stamp.sec, stamp.nsec);stamp = resolveHourAmbiguity(stamp, time_nom);ROS_INFO("after stamp sec: %d, nsec: %d", stamp.sec, stamp.nsec);return stamp;
}

Velodyne 32E pcap包GPS时间戳解析相关推荐

  1. C++实现pcap包解析,并提取指定特征帧

    目录 前言 1.流量结构 2.类C结构 3.指令类型 二.代码示例 1.引入头文件 2.设置全局变量 3.函数 1.高低字节交换 2. 十六字节拼接 3.将木马检测结果写入csv文件 4.获取文件夹下 ...

  2. python解析pcap包,python-用scapy读取PCAP文件

    我有大约10GB的pcap数据和IPv6流量,用于分析存储在IPv6头和其他扩展头中的信息.为此,我决定使用Scapy框架.我尝试了rdpcap函数,但是对于如此大的文件,不建议这样做.它试图将所有文 ...

  3. SLAM精度评估常见问题——GPS时间戳与bag包时间戳如何对齐

    在使用evo进行精度评估时,由于evo是通过时间戳来进行配准和比较的,为了使结果更准确,需要将GPS与bag包的时间戳进行转换对齐 在这里更方便的方法是转换GPS时间戳到bag包 首先查看GPS文件 ...

  4. python解析pcap包已text格式输出_python分析pcap包

    前两天需要分析一个pcap包,写了一段python脚本,将每个包的基本信息(源/目的MAC.源/目的IP.源/目的端口)提取出来. 在实现过程中为了省事用了dpkt开发包,不过只用了几个简单的函数,具 ...

  5. pcap文件格式及文件解析

    pcap文件格式及文件解析 第一部分:PCAP包文件格式 一 基本格式: 文件头 数据包头数据报数据包头数据报...... 二.文件头: 文件头结构体  sturct pcap_file_header ...

  6. linux 发包命令,LINUX tcpreplay命令-将PCAP包重新发送,用于性能或者功能测试

    将PCAP包重新发送,用于性能或者功能测试 补充说明 简单的说, tcpreplay 是一种pcap包的重放工具,它可以将用ethreal.wireshark工具抓下来的包原样或经过任意修改后重放回去 ...

  7. google Guava包的ListenableFuture解析

    原文地址  译者:罗立树  校对:方腾飞 并发编程是一个难题,但是一个强大而简单的抽象可以显著的简化并发的编写.出于这样的考虑,Guava 定义了 ListenableFuture接口并继承了JDK ...

  8. 学习笔记之rpm程序包管理功能解析

    Rpm包管理功能全解 软件包管理的功能:将编译好的程序的各组成文件打包成一个或几个程序包文件,为了方便的实现程序包的安装.升级.卸载.查询.校验.数据库维护. 下面我们来看看RPM包管理的解析 Rpm ...

  9. android gps磁偏角,GPS数据格式解析

    GPS数据格式解析 简介 GPS发送数据以行为单位,数据格式如下: $信息类型,x,x,x,x,x,x,x,x,x,x,x,x,x 每行以字符"$"开头,以为结尾,CR-Carri ...

最新文章

  1. Linux服务器下的HTTP抓包分析
  2. OpenAI及DeepMind两团队令未来的AI机器更安全
  3. php html url编码,html中url编码是什么?有什么用?
  4. Django之中间件-CSRF
  5. mysql 基础配置经验
  6. DPDK EAL parameters(DPDK环境抽象层参数)-原始版本(F-Stack配置文件的配置参数)
  7. Windows7下无法安装Oracle11.1.0问题
  8. WinPE启动盘制作
  9. Windows2012安装AppFabric失败返回1603错误的解决方案
  10. git push 报错 remote: error: hook declined to update
  11. 桌面计算机图标无法附到任务栏,win7系统电脑快捷方式无法添加到任务栏的解决方法...
  12. 我的TLS1.3之旅
  13. 对于无线网络经常掉线的问题
  14. 秋招经验总结(私企,外企,国企)
  15. Windows10切换用户显示User Profile Service或ProfSvc服务登录失败
  16. 苹果apple通过双重认证帐户恢复获取AppID访问权限
  17. python|安装skimage库报错:required to install pyproject.toml-based projects
  18. js --- 转数值类型
  19. 谷歌布莱克·勒莫因:为什么我觉得AI已觉醒了?
  20. K 近邻算法 API

热门文章

  1. w10投影全屏设置_win10如何让投影仪铺满全屏
  2. 海贼王经典语录(转)
  3. EasyPR--开发详解(5)颜色定位与偏斜扭转
  4. linux下sv高亮设置的详细教程
  5. c语言while根据近似公式求,c语言用π=1-1/3+1/5-1/7+.公式求π的近似值,直到最后一项的绝对值小于10^-6为止...
  6. 学术会议 Rebuttal 模板资料留存
  7. linux查询主机信息命令,用来获取Linux主机信息的5个常用命令
  8. windows远程桌面工具之间如何进行控制?
  9. Java字符串使用Split以竖线作为分隔符
  10. 基于单片机火灾监测报警系统设计-毕设资料