CAPL 发送接受诊断命令

发布时间 2023-06-12 11:25:34作者: 可乐芬达

发送诊断命令

on key 'a'{
  long Request_Size=0,Req_iter = 0;
  byte Req_Buffer[4095];
  byte DiagReqBuffer[2] = {0x10,0x01};
  diagRequest Door.DefaultSessionControl Req_obj;
  Request_Size = elCount(DiagReqBuffer);
  write("Request size is %d \n", Request_Size);
  writeEx(1,1,"Diag request byte is: ");
  diagResize(Req_obj,Request_Size);
  for (Req_iter=0;Req_iter<Request_Size;Req_iter++)
  {
    diagSetPrimitiveByte(Req_obj,Req_iter,DiagReqBuffer[Req_iter]);
    writeEx(1,1,"%02x ",DiagReqBuffer[Req_iter]);
  }
  write("\n");
  diagSendRequest(Req_obj);
}

接受诊断命令

on diagResponse *{
  byte rsBuf[4095];
  int iter=0;
  long Response_length=0;
  Response_length= DiagGetPrimitiveSize(this);
  write("Diag response length is: %d \n", Response_length);
  writeEx(1,1,"Diag response byte is: ");
  for(iter=0; iter<Response_length; iter++){
    rsBuf[iter]=diagGetPrimitiveByte(this,iter);
    writeEx(1,1,"%02x ",rsBuf[iter]);
  }
  write("\n");
}

用到的函数

不换行输出 writeEx(long sink, dword severity, char format[], ...)

sink 指显示在哪个窗口
Values:
-3	Trace Window
-2	Output to the logging file (only in ASC format and if the CAPL node is inserted in the Measurement Setup in front of the Logging Block)
-1	Reserved
0	Output to the System page of the Write Window
1	Output to the CAPL page of the Write Window
4	Output to the Test page of the Write Window

severity Log level 等级
Values:
0	Success
1	Information
2	Warning
3	Error
The parameter severity has no meaning for output to the Trace Window.


diagRequest Door.DefaultSessionControl Req_obj
DefaultSessionControl 是 ECU Door 的默认会话控制对象,此处相当于实例化了一个对象
DiagGetPrimitiveSize 获取诊断请求或者响应部分 Pyload 部分的长度
diagGetPrimitiveByte 按字节获取诊断请求或者响应部分 Pyload 的数据