最近,我正在研究car-to-X通信,并使用两个车载单元(OBU)。使用gpsd和gpsd客户端可以读取和监控两个模块上的GPS数据,我还可以使用iPerf测量网络性能。为此,一台设备充当服务器,另一台充当客户端。现在,我想用两台不同的笔记本电脑连接这两台设备,测量网络性能,并在OBUs外部读取GPS数据。我还需要同步之间的全球定位系统数据和iPerf输出,以便我可以检测TPV (时间,位置,速度)明智的吞吐量,延迟等。现在我需要同步全球定位系统和iPerf数据在一起,以便我可以存储为日志文件和以后处理的数据。有没有人可以帮助我如何做到这一点。我已经尝试了一个解决方案,那就是-时间戳GPS和iperf数据,并存储到日志中。我有第二个解决方案,这是发送全球定位系统数据作为iperf有效载荷,使用-f选项。我想试试第二个,但不太确定该怎么做。任何人的帮助都是非常感谢的。
发布于 2017-05-08 07:08:23
您没有提到您熟悉哪种脚本语言或编程语言。有许多方法可以做到这一点,从简单的python或bash脚本,到更复杂的C++程序。
我不想为你写一个完整的演示软件,不知道你具体要找什么,但我能够拿出这个sample c++ gpsd client的一部分,并修改它,使它也运行iperf和输出为csv (然后你可以管道到记录器或任何你想做的)。
#include <iostream>
#include <iomanip>
#include <ctime>
#include <sstream>
#include <memory>
#include <libgpsmm.h>
std::string exec(const char *cmd) {
std::array<char, 128> buffer;
std::string result;
std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
if (!pipe) throw std::runtime_error("popen() failed!");
while (!feof(pipe.get())) {
if (fgets(buffer.data(), 128, pipe.get()) != NULL) result += buffer.data();
}
return result;
}
int main(int argc, char **argv)
{
if (argc < 2) {
std::cout << "Please execute command with a remote iperf server. Exiting." <<
"\n";
return 1;
}
gpsmm gps_rec("localhost", DEFAULT_GPSD_PORT);
if (gps_rec.stream(WATCH_ENABLE | WATCH_JSON) == NULL) {
std::cerr << "No GPSD running.\n";
return 1;
}
for (;;) {
// run iperf and get output in a string (note: needs error checking!)
// the cut portion is there to remove the first column from the csv output
// which is time, as we'll take the gps time instead.
std::stringstream iperfCmd;
iperfCmd << "iperf -c " << argv[1] << " -ey C | cut -d , -f 2-9";
const std::string& tmp = iperfCmd.str();
const char *iperfCmdArr = tmp.c_str();
std::string iperfOutput = exec(iperfCmdArr);
struct gps_data_t *newdata;
if (!gps_rec.waiting(50000000)) continue;
if ((newdata = gps_rec.read()) == NULL) {
std::cerr << "Read error.\n";
return 1;
} else {
while (((newdata = gps_rec.read()) == NULL) ||
(newdata->fix.mode < 1)) {
// Do nothing; don't want to output wrong initial time
}
timestamp_t ts = newdata->fix.time;
double latitude = newdata->fix.latitude;
double longitude = newdata->fix.longitude;
// convert GPSD's timestamp_t into time_t
time_t seconds;
seconds = (time_t)ts;
auto tm = *std::localtime(&seconds);
std::ostringstream oss;
oss << std::put_time(&tm, "%d-%m-%Y %H:%M:%S");
auto time_str = oss.str();
// set decimal precision
std::cout.precision(6);
std::cout.setf(std::ios::fixed, std::ios::floatfield);
std::cout << time_str << "," <<
latitude << "," <<
longitude << "," << iperfOutput;
// uncomment below to break out of for loop (will only output 1 iteration)
// return 0;
}
}
return 0;
}可以修改iperfCmd变量以更改iperf命令。例如,如果您想运行双向测试,可以将其更改为"-rey C“。查看iperf --help以获取您需要的内容,但是您必须为-y输出保留“CSV C”标志。如果您有gpsd (有时还有必要的libgps-dev库),您可以这样编译代码:
g++ -Wall -std=c++14 -pedantic $(pkg-config --cflags --libs libgps) gpsd-iperf-example.cpp -o gpsd-iperf-example然后运行(按CTRL-C停止):
gpsd-iperf-example servername假设gpsd工作正常,并且您使用的是iperf v2,则输出应如下所示:
07-05-2017 19:05:10,45.3XXXXX,-75.8XXXXX,192.168.2.36,40466,192.168.2.28,5001,4,0.0-10.0,286785536,228615722
07-05-2017 19:05:11,45.3XXXXX,-75.8XXXXX,192.168.2.36,40468,192.168.2.28,5001,4,0.0-10.0,328859648,261792317
07-05-2017 19:05:12,45.3XXXXX,-75.8XXXXX,192.168.2.36,40470,192.168.2.28,5001,4,0.0-10.0,293601280,234307789您可以进一步解析或简单地调整c++程序。我不确定这是否是你想要的,但同样,有很多方法可以做到这一点,只需查看代码片段并根据需要进行调整即可。
https://stackoverflow.com/questions/42097901
复制相似问题