1. 简述
开发BootLoader,实现OTA升级和CAN刷写功能,CAN刷写使用CANoe实现。CANoe可以打开二进制文件和文本文档。
官方参考API:
file:///D:/VectorCANoe15/Help01/CANoeCANalyzerHTML5/CANoeCANalyzer.htm#Topics/CAPLFunctions/Other/CAPLfunctionsGeneralOverview.htm
官方参考代码:
file:///D:/VectorCANoe15/Help01/CANoeCANalyzerHTML5/CANoeCANalyzer.htm#Topics/CAPLFunctions/Other/Functions/CAPLfunctionsExapmleFileFunctions.htm
2. 使用
这里以部分函数为例,具体参考官方API文档。
/* openFileRead-打开文件进行读访问 */
dword openFileRead (char filename[], dword mode); // form 1
dword openFileRead (char filename[], dword mode, dword fileEncoding); // form 2
参数:
filename: 文件名
mode: 0-以文本方式打开; 1-以二进制方式打开
返回值:
文件句柄: 0-发生错误
/* fileClose -关闭文件 */
long fileClose (dword fileHandle);
/* fileGetString-从指定文件读取字符串 */
long fileGetString (char buff[], long buffsize, dword fileHandle);
参数:
buff: 用于读出的字符串缓冲区
buffsize: 字符串长度
fileHandle: 文件句柄
3. 代码
/*@!Encoding:936*/
includes
{
}
variables
{
}
on preStart
{
write("ECU1");
}
on start
{
dword fileHandle;
char buffer[64];
fileHandle = openFileRead("capl.txt", 0);
if (fileHandle != 0)
{
while (fileGetString(buffer,9,fileHandle) !=0) //读取8个字符串
{
write("%s", buffer);
}
}
fileClose (fileHandle);
}
读取8个字符串为什么参数为9?
Characters are read until the end of line is reached or the number of read characters is equal to buffsize -1.
The end of line is marked either.
读取字符,直到到达行尾,或者读取的字符数等于buffsize -1。