1、读取文件
(1)引用头文件:
#include <iostream>
#include <fstream>
#include <string>
(2)获取要刷写的文件
ifstream file("./test.hex", ios::binary);
if (!file.is_open()) {
cout<<"Error opening file"<<endl;
}
2、存放文件
一般读取出来的数据是String类型,用来进行传输的都是用0xAB这种格式,要进行转化之后,定义一个data去接收转化后正常的数据。之后按照uds要求从data中获取数据,进行传输文件。
for(int j=0;j<s.length();j+=2)
{
highByte = toupper(s[j]);
lowByte = toupper(s[j + 1]);
if (highByte > 0x39)
highByte -= 0x37;
else
highByte -= 0x30;
if (lowByte > 0x39)
lowByte -= 0x37;
else
lowByte -= 0x30;
d = (highByte << 4) | lowByte;
data.push_back(d);
}