发布
社区首页 >问答首页 >如何用CAPL程序编写8字节以上数据的2eSID接收ISOTP多帧UDS

如何用CAPL程序编写8字节以上数据的2eSID接收ISOTP多帧UDS
EN

Stack Overflow用户
提问于 2022-10-11 12:16:07
回答 1查看 161关注 0票数 -1

当CAPL程序从CANOe向ECU发送消息时,我希望接收超过8个字节的数据。我在ECU上实现了ISOTP协议,传输8字节以上的数据,运行良好。

现在我的问题是,我试图调用下面的CAPL代码,但我无法从ECU获得正确的FC帧。假设测试箱是我的CAPL程序。ECU是我读取所有字节并发送响应的地方。

代码语言:javascript
代码运行次数:0
复制
on message 0x723
{
  checkByte0 = this.byte(0) & 0x30;  
  //checkByte0 = 0x0F & 0x30; 
  write("checkbyte value %x",checkByte0 );
  if(checkByte0 == 0x30) //FC frame
  {
    write("checkbyte 30 value %x",checkByte0 );
    msg.byte(0) = 0x21;
    msg.byte(1) = 0x40;    
    msg.byte(2) = 0x50;
    msg.byte(3) = 0x60;
    msg.byte(4) = 0x70;
    output(msg);
  }
}

//send request write data by identifier 2E F190 parameters
on key 'q'
{      
  msg.byte(0) = 0x10;
  msg.byte(1) = 0x0A;
  msg.byte(2) = 0x2E;
  msg.byte(3) = 0xF1;
  msg.byte(4) = 0x90;
  msg.byte(5) = 0x10;
  msg.byte(6) = 0x20;
  msg.byte(7) = 0x30;
 } 

这里0x723是从CANOe接收到的请求消息。0x72B是我从ECU发送的响应消息。我附上了一张截图以供参考。以显示已读取的数据已正确接收。没有正确地接收到as写入的位置。输出2E读写22 SID和CAPL代码

我也是从ECU端添加代码,仅供参考。我很困惑,我是否需要定义在ECU接收端的任何功能。或者CAPL程序足够操作来接收多帧?使用上面的CAPL代码,我无法接收来自ECU的FC流控制响应。

代码语言:javascript
代码运行次数:0
复制
        /* just for underestanding Where 
        #define ISOTP_SF        0x00        /* single frame */
        #define ISOTP_FF        0x10        /* first frame */
        #define ISOTP_CF        0x20        /* consecutive frame */
        #define ISOTP_FC        0x30        /* flow control */
        /*The below line of code is where I receive data from CAN when CANOe sends a message*/
        
            CanData[8] = {0,0,0,0,0,0,0,0}
            for(dtcnt=0; dtcnt<RxCAN->DLC; dtcnt++)
            {
                CanData[dtcnt]= RxCAN->Data[dtcnt];
            }
             
            switch((uint16_t)RxCAN->StdId) 
            {
    
                case TESTER_TO_EDS: //CAN 0x723 Diagnostic
                {
                    /*Request message from CAN to Diagnostic*/
                    dgiIsoTp.IsoTpFrameTypeRcv = (0xF0 & CanData[0]);
                    /*If Isotp Single frame  == 0 then read 8 byte data */
                    if (dgiIsoTp.IsoTpFrameTypeRcv == ISOTP_SF)
                    {
                        ReadCanMsg_ISOTP(CanData, TESTER_TO_EDS);
                    }
                    else if(dgiIsoTp.IsoTpFrameTypeRcv == ISOTP_FF)
                    {
                        ReadCanMsg_ISOTP(CanData, TESTER_TO_EDS);
                    }
                    break;
                }
            }
    
/*The below lines of code where I manipulate my received message and send response based on the request message*/
void ReadCanMsg_ISOTP(uint8_t CanData[], uint16_t CanIdReq)
{
    uint8_t i; /*---- valid data bytes-----*/
    dgiIsoTp.IsoTpFrameType = 0xFF;
    dgiIsoTp.IsoTpLengthCtn = 0x00;
    dgiIsoTp.IsoTpBlockCtn = 0x00;
    dgiIsoTp.IsoTpFrameNum = 0x00;

    dgiIsoTp.TpCanID =  CanIdReq; /*response CAN ID must receive here */
    dgiIsoTp.IsoTpLen = (uint8_t) CanData[0]; /*Diagnostic Data parameters message are received here*/

    for (i = 0; i <= dgiIsoTp.IsoTpLen; i++)
    {
        /*Msgarr[25] buffer is defined if the data is > than 8 Msgarr[] must be updated */
        dgiIsoTp.Msgarr[i] = CanData[i];
    }

    /*-- Check message length and frame type-- #define CAN_SIZE = 8*/
    if (dgiIsoTp.IsoTpLen > (CAN_SIZE - 1))
    {
        dgiIsoTp.IsoTpFrameType = ISOTP_FF; /* must be == 0x10*/
        /*Here below function isoTpSend() will be called and update the multiple frames */
        isoTpSend();
    }
    else
    {
        dgiIsoTp.IsoTpFrameType = ISOTP_SF; /*must be == 0x00*/
        isoTpSend();
    }

}

我添加了上面的代码来了解我的问题。我从CANOe触发键'q‘。

代码语言:javascript
代码运行次数:0
复制
Here Length = 0x0A which is 10 bytes, SID 2E, DID F190, Data[10 20 30 40 50 60 70] 

我收到一条消息10 0A 2E F1 90 10 20 30,下一个FC帧没有从ECU发送到CANOe。其中,我无法从21 40 50 60 70 00 00 00接收CF第二帧字节。我想知道如何实现这一点?我是否需要在我的ECU应用程序端添加代码,如果有任何建议,如何实现。

这样我就可以接收超过8个字节的请求。其中的响应将是03 6E F1 90 00 00 00 00

我没有CDD文件和坎德拉执照。目前,为了测试的目的,我必须遵循手动方法,我可以实现一个CAPL代码发送请求到ECU使用SID2e请有人纠正我的逻辑。我还附上了当前输出的图片。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-17 15:18:43

我正在为我的问题加上解决办法。我在下面的代码,以供参考,如果有人是新的capl。下面的解决方案使用用于UDS诊断的WriteDatabyIdentifier SID2e接收超过8个字节的帧。我还要感谢@M.spiller,他支持我,同时让我理解,以及向量CANOe和CAPL脚本的接口。如果有人想发送超过16个字节的数据,我也会在下面添加。

代码语言:javascript
代码运行次数:0
复制
variables
{ 
  byte checkByte0;  
  message 0x723 msg = { dlc=8};
  message 0x723 msg1 = { dlc=8};
}
on message 0x723
{
  checkByte0 = this.byte(0) & 0x30;  
  //checkByte0 = 0x0F & 0x30; 
  write("checkbyte value %x",checkByte0 );
  if(checkByte0 == 0x30) //FC frame


{
    write("checkbyte 30 value %x",checkByte0 );
    msg.byte(0) = 0x21; //CF
msg.byte(1) = 0xc8;
msg.byte(2) = 0x9d;    //data
msg.byte(3) = 0x02;
msg.byte(4) = 0x8d;
msg.byte(5) = 0xfa;    
msg.byte(6) = 0x16;
msg.byte(7) = 0x8a;


msg1.byte(0) = 0x22; //CF
msg1.byte(1) = 0x85;
msg1.byte(2) = 0x93;    //data
msg1.byte(3) = 0x3a;
msg1.byte(4) = 0xef;
msg1.byte(5) = 0xdd;    
msg1.byte(6) = 0x00;
msg1.byte(7) = 0x00;
output(msg);
output(msg1);
  }
}

//send request write data by identifier 2E F190 parameters
on key 'q'
{      
  msg.byte(0) = 0x10;
  msg.byte(1) = 0x0A;
  msg.byte(2) = 0x2E;
  msg.byte(3) = 0xF1;
  msg.byte(4) = 0x90;
  msg.byte(5) = 0x10;
  msg.byte(6) = 0x20;
  msg.byte(7) = 0x30;
 } 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74028012

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档