UDS刷写中基于CAPL完成36数据传输

一、介绍

一般来说36传输都需要发送大量数据,而基于UDS一次最多传输2048字节数据,通常需要多次36才能传输完成,在已经实现获取刷写文件(hex,bin等文件)数据并能发送诊断请求(多帧)的前提下,下面函数可以实现完成一个black所有数据的传输

其中long Send_DiagRequest_arrary(byte diag_data[],word diag_size)函数为发送诊断请求并根据响应返回不同值,正响应返回1,需要自行实现这部分功能。

二、代码实现

testfunction TC_36_Download(byte diag_data[],word diag_size)
{
    const long ExpResCode=PostitiveResponse;
    const byte SendType=0;//物理寻址
    byte resData[128];
    long resSize;
    
    long ret;
    ret=Send_DiagRequest_arrary(diag_data, diag_size);
    if(ret!=1)
    {
        testStepFail("Fail");
    }
}

testcase TC_Download_fileblock(struct FlsData F_DataInfor,byte block,dword u32MaxNumberOfBlockLength)
{
    byte temp_data[0x802];
    byte blockSequenceCounter;
    dword count;
    int i;
    
    int times;
    times=0;
    count=0;
    blockSequenceCounter=0;
    
    while(1)
    {
        times++;
        if(F_DataInfor.F_SegmentInfor[block].data_size-count>u32MaxNumberOfBlockLength-2)
        {
            
            blockSequenceCounter=blockSequenceCounter+1;

            temp_data[0]=0x36;
            temp_data[1]=blockSequenceCounter;
            for(i=0;i<u32MaxNumberOfBlockLength-2;i++)
            {
                temp_data[2+i]=F_DataInfor.FlsData_BufferArr[F_DataInfor.F_SegmentInfor[block].data_offset+i+count];
                
            }
            count=count+u32MaxNumberOfBlockLength-2;
            
            TC_36_Download(temp_data,u32MaxNumberOfBlockLength);

            if(count==F_DataInfor.F_SegmentInfor[block].data_size)
            {
                break;
                
            }
        }
        else
        {
            word diag_size;
            diag_size=F_DataInfor.F_SegmentInfor[block].data_size-count+2;
            blockSequenceCounter=blockSequenceCounter+1;
            temp_data[0]=0x36;
            temp_data[1]=blockSequenceCounter;
            for(i=0;i<diag_size-2;i++)
            {
                temp_data[2+i]=F_DataInfor.FlsData_BufferArr[F_DataInfor.F_SegmentInfor[block].data_offset+i+count];
            }
            
            TC_36_Download(temp_data,diag_size);
            break;
        }
    }
    
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值