资源简介
Linux平台USB转CAN设备数据解析代码,可用于车机数据解析。欢迎大家下载!

代码片段和文件信息
#include “CanFile.h“
#include
CanFile::CanFile() {
}
CanFile::~CanFile()
{
}
bool CanFile::load(string radar_path string car_path)
{
cout << “loading radar can file!“ << endl;
LoadCanFile(radar_path radar_can_pack_);
cout << “loading vehicle can file!“ << endl;
LoadCanFile(car_path car_can_pack_);
return true;
}
string CanFile::string_to_hex(const string& str) //transfer string to hex-string
{
string result = “0x“;
result += str;
return result;
}
VCI_CAN_OBJ CanFile::string_to_canfrmae(std::vector str) {
VCI_CAN_OBJ frame;
frame.TimeStamp = trans_to_uint_time(stod(str[0]));
frame.ID = UINT(stof(str[3]) + 0.5);
frame.DataLen = UINT(stoi(str[4]));
for (int i = 0; i < frame.DataLen; i++)
{
string aa = string_to_hex(str[5 + i]);
int b = int(stof(aa) + 0.5);
frame.Data[i] = BYTE(b);
}
return frame;
}
int CanFile::LoadCanFile(string path std::vector & can_pack) {
std::ifstream can_file(path);
if (!can_file) {
cout << “Unable to open can file“;
exit(0); // terminate with error
}
std::string feature; //存储读取的每行数据
string feat_onePoint; //存储每行按空格分开的每一个float数据
std::vector lines; //存储每行数据
can_pack.clear();
int cnt = 0;
while (!can_file.eof())
{
getline(can_file feature); //一次读取一行数据
if (feature.length() <= 0) {
break;
}
stringstream stringin(feature); //使用串流实现对string的输入输出操作
lines.clear();
while (stringin >> feat_onePoint) { //按空格一次读取一个数据存入feat_onePoint
lines.push_back(feat_onePoint); //存储每行按空格分开的数据
}
VCI_CAN_OBJ frame = string_to_canfrmae(lines);
can_pack.push_back(frame); //存储所有数据
//cout << cnt++ << endl;
}
can_file.close();
return 1;
}
double CanFile::updata_radar_obs(double timestamp) {
int a = sizeof(UINT);
UINT obs_time = trans_to_uint_time(timestamp);
double rd_time = 0;
while (last_radar_idx_ < radar_can_pack_.size() &&
radar_can_pack_[last_radar_idx_].TimeStamp < obs_time)
{
can_frame frame = { 0 };
frame.can_id = radar_can_pack_[last_radar_idx_].ID;
frame.can_dlc = radar_can_pack_[last_radar_idx_].DataLen;
memcpy(&frame.data &radar_can_pack_[last_radar_idx_].Data sizeof(frame.data));
frame2Value_ContiRadar(&frame);
radar_msg_.update(frame.can_id g_data_ContiRadar);
rd_time = trans_to_float_time(radar_can_pack_[last_radar_idx_].TimeStamp);
last_radar_idx_++;
}
return rd_time;
}
int CanFile::updata_vehicle_obs(double timestamp) {
UINT obs_time = trans_to_uint_time(timestamp);
while (last_car_idx_ < car_can_pack_.size() &&
car_can_pack_[last_car_idx_].TimeStamp < obs_time)
{
can_frame frame = { 0 };
frame.can_id = car_can_pack_[last_car_idx_].ID;
frame.can_dlc = car_can_pack_[last_car_idx_].DataLen;
memcpy(&frame.data &car_can_pack_[last_car_idx_].Data sizeof(frame.data));
frame2Value_Vehicle(&frame);
car_msg_ = g_data_vehicle;
last_car_idx_++;
}
return 1
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-06-10 04:54 canparse\
文件 554 2018-12-04 07:23 canparse\ContiRadarMsg.h
文件 887 2018-12-04 07:23 canparse\ContiRadarMsg.cpp
文件 1628 2018-12-04 07:23 canparse\CanMatrix_ContiRadar.h
文件 3465 2018-12-04 07:23 canparse\CanMatrix_ContiRadar.cpp
文件 1518 2018-12-04 07:23 canparse\CanMatrix_Car.h
文件 3475 2018-12-04 07:23 canparse\CanMatrix_Car.cpp
文件 2382 2018-12-04 07:23 canparse\CanMatrix.h
文件 4305 2018-12-04 07:23 canparse\CanMatrix.cpp
文件 1256 2018-12-04 07:23 canparse\CanFile.h
文件 3462 2018-12-04 07:23 canparse\CanFile.cpp
目录 0 2019-06-10 04:54 canparse\.vscode\
目录 0 2019-06-10 04:54 canparse\.vscode\ipch\
目录 0 2019-06-10 04:54 canparse\.vscode\ipch\bd7e9afe7fb66268\
文件 1167360 2019-06-10 04:50 canparse\.vscode\ipch\bd7e9afe7fb66268\CanMatrix_Car.ipch
文件 8 2019-06-10 04:50 canparse\.vscode\ipch\bd7e9afe7fb66268\mmap_address.bin
目录 0 2019-06-10 04:54 canparse\.vscode\ipch\a2055dfac254ad02\
文件 60125184 2019-06-10 04:49 canparse\.vscode\ipch\a2055dfac254ad02\CanFile.ipch
文件 8 2019-06-10 04:49 canparse\.vscode\ipch\a2055dfac254ad02\mmap_address.bin
相关资源
- stm32f407上的两个can发送和接收例程
- CANopen使用手册_埃斯顿
- CanuMobiSim
- uboot到linux logo显示不间断 补丁
- UNIX/LINUX编程实践教程的源码
- Linux任务管理器
- linux应用层的华容道游戏源代码
- 28335CAN调试程序
- ubuntu9.10 可加载内核模块和字符设备驱
- MP3文件ID3v2ID3v2APEv2标签读取
- UART转CAN或LIN的工具(Uart2any)和文档
- 28335写的用spi读取传感器数据并用CA
- 操作系统实验——虚存管理实验
- wwwscan-很强大的后台扫描工具
- linux下的发包工具sendip
- 尚观培训linux许巍关于c 的笔记和讲义
- 尚观培训linux董亮老师关于数据结构的
- linux 线程池源码 c 版
- linux C 电梯程序练习
- linux下用多进程同步方法解决生产者
- Linux 操作系统实验(全)
- Linux From Scratch 中文手册
- linux 网络实验 ftp程序
- Linux命令大全离线版&在线版
- 操作系统共享内存实验
- dos 下运行Linux 命令--gnu_utils
- linux 0.12内核源代码
- linux简易shell C实现
- linux实验报告及心得体会
- 基于GTK的Linux环境下的简易任务管理器
评论
共有 条评论