This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

am335x板子soctetcan中的标准帧修改为扩展帧

各位TI老师你们好,

问题:我要把3358这个板子的can例程中的数据帧标准帧,改为数据帧扩展帧,并且ID可以输入8位ID,我已经可以实现标准帧,但是改为扩展帧时不知道怎么改
主要是这个分析函数。输入格式为。./can_test -d can1 -w 123#0102030405060708 这是标准帧,中间加红的这一段不知道怎么才能改成扩展帧,或者你们有扩展帧的例程让小弟用一下,第一次用can,又要改,感觉好难,谢谢老师和大佬。

can.c里边的分析函数

int parse_canframe(char* strFrame, struct can_frame *frame) // 解析函数
{
int i, idx, dlen, len;
int maxdlen = CAN_MAX_DLEN;//8
int ret = CAN_MTU;//can_frame的大小
unsigned char tmp;

len = strlen(strFrame);

memset(frame, 0, sizeof(*frame)); /* init CAN FD frame, e. g. LEN = 0 */

if (len < 4)//6
return 0;
dbg_printf(" frame_id = 0x%x \n", frame->can_id);
/*
if (strFrame[3] == CANID_DELIM) //3 digits 判断第三位是否是#
{
idx = 4;
for (i=0; i<3; i++){
if ((tmp = asc2nibble(strFrame[i])) > 0x0F)
return 0;
frame->can_id |= (tmp << (2-i)*4);// 0 -- 8 1 -- 4 2 -- 0
}
} else
return 0;
*/
if((strFrame[idx] == 'R') || (strFrame[idx] == 'r')){ /* RTR frame */
frame->can_id |= CAN_RTR_FLAG;

/* check for optional DLC value for CAN 2.0B frames */
if(strFrame[++idx] && (tmp = asc2nibble(strFrame[idx])) <= CAN_MAX_DLC)
frame->can_dlc = tmp;

return ret;
}

for (i=0, dlen=0; i < maxdlen; i++){

if(strFrame[idx] == DATA_SEPERATOR) /* skip (optional) separator */
idx++;

if(idx >= len) /* end of string => end of data */
break;

if ((tmp = asc2nibble(strFrame[idx++])) > 0x0F)
return 0;
frame->data[i] = (tmp << 4);
if ((tmp = asc2nibble(strFrame[idx++])) > 0x0F)
return 0;
frame->data[i] |= tmp;
dlen++;
}
frame->can_dlc = dlen;