- 传输数据
- 请求
注意:参数值从0x01开始 01 02 03 .... 参数值为0xFF时,块序列计数器翻滚并从0x00开始发出下一条TransferData(传输数据)请求消息。
10 82 36 01(block index) xx xx xx xx
21 xx xx xx xx xx xx xx
22 xx xx xx xx xx xx xx
- 响应
02 76 01 AA AA AA AA AA
void Service36Handle(uint8_t N_TAType, uint16_t length, uint8_t *messageData)
{
bool suppressPosRspMsgIndicationBit = FALSE;
g_NRC = PR;
if(length <= MAX_SIZE && length >= 3)//min one byte data
{
uint8_t BLockIndex = *(MessageData + 1);
if(g_UpdateStep == DOWNLOAD_FLASH_DRIVER_36)
{
if(BLockIndex == g_BlockIndex) // in 0x34 has already give Init Index
{
uint16_t errorCode = 0;
errorCode = MemManger_Program( length - 2 , messageData + 2); // write Flash data, one block
if(errorCode == MEM_FINISH) // if one block finish then responde
{
ProgramLengthComplete += length - 2; // complete data
LastRequestLength = length - 2;
DiagnosticBuffTX[0] = 0x76;
DiagnosticBuffTX[1] = g_BlockIndex;
ResponseLength = 2;
g_BlockIndex++;
if(ProgramLengthComplete == ProgramLength)
{
g_UpdateStep = DOWNLOAD_FLASH_DRIVER_37; // go to next step
}
}
else
{
g_NRC = GPF;//program error
}
}
/*进行重复传输处理*/
else if((g_BlockIndex == (BLockIndex + 1)) && (ProgramLengthComplete != 0))
{
/*如果本次传输的数据大于上次传输的数据,
则将大于的部分数据写入FLASH*/
if((length - 2) > LastRequestLength)
{
uint16_t errorCode = 0;
uint16_t thisRequestLength = length - 2 - LastRequestLength; //remaining length
errorCode = MemManger_Program( thisRequestLength , MessageData + 2 + LastRequestLength);
if(errorCode == MEM_FINISH)
{
ProgramLengthComplete += thisRequestLength;
LastRequestLength += thisRequestLength;
DiagnosticBuffTX[0] = 0x76;
DiagnosticBuffTX[1] = m_BlockIndex;
ResponseLength = 2;
if(ProgramLengthComplete == ProgramLength)
{
m_UpdateStep = DOWNLOAD_FLASH_DRIVER_37;
}
}
else
{
m_NRC = GPF;//program error
}
}
else/*否则(本次传输的数据小于等于上一次传输的数据),直接给肯定响应*/
{
DiagnosticBuffTX[0] = 0x76;
DiagnosticBuffTX[1] = m_BlockIndex;
ResponseLength = 2;
}
}