一、介绍
一般来说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;
}
}
}