• 大小: 7.64MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-10
  • 语言: 其他
  • 标签: Linux  CAN  

资源简介

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

评论

共有 条评论