1333 lines
38 KiB
C#
1333 lines
38 KiB
C#
using System;
|
||
|
||
namespace CanTool
|
||
{
|
||
partial class uds_tools
|
||
{
|
||
|
||
//当前使用的升级相关配置参数
|
||
private UpdateConfigParams UpdateConfigParamsNow = new UpdateConfigParams();
|
||
|
||
|
||
|
||
|
||
//鸿日的升级相关配置参数
|
||
private UpdateConfigParams UpdateConfigParamsHR = new UpdateConfigParams();
|
||
|
||
|
||
|
||
private void UpdateConfigParamsInit()
|
||
{
|
||
|
||
|
||
#region 鸿日升级配置
|
||
|
||
this.UpdateConfigParamsHR.CANPhyDevRxId = 0x70B;
|
||
this.UpdateConfigParamsHR.CANPhyDevTxId = 0x71B;
|
||
this.UpdateConfigParamsHR.CANFuncDevRxId = 0x7DF;
|
||
|
||
/*启动FLASH校验例程*/
|
||
this.UpdateConfigParamsHR.FlashCheckMemoryParams[0] = 0x02;
|
||
this.UpdateConfigParamsHR.FlashCheckMemoryParams[1] = 0x02;
|
||
/*启动APP校验 例程*/
|
||
this.UpdateConfigParamsHR.AppCheckMemoryParams[0] = 0x02;
|
||
this.UpdateConfigParamsHR.AppCheckMemoryParams[1] = 0x02;
|
||
/*编程预条件检查*/
|
||
this.UpdateConfigParamsHR.CheckProgramCondParams[0] = 0x02;
|
||
this.UpdateConfigParamsHR.CheckProgramCondParams[1] = 0x03;
|
||
/*启动擦除内存*/
|
||
this.UpdateConfigParamsHR.EraseMemoryParams[0] = 0xff;
|
||
this.UpdateConfigParamsHR.EraseMemoryParams[1] = 0x00;
|
||
/*逻辑块依赖性检查*/
|
||
this.UpdateConfigParamsHR.CheckCompatibilityParams[0] = 0xff;
|
||
this.UpdateConfigParamsHR.CheckCompatibilityParams[1] = 0x01;
|
||
|
||
//1级安全
|
||
this.UpdateConfigParamsHR.RequestSeedL1 = 0x01;
|
||
this.UpdateConfigParamsHR.SendKeyL1 = 0x02;
|
||
//2级安全
|
||
this.UpdateConfigParamsHR.RequestSeedL2 = 0x03;
|
||
this.UpdateConfigParamsHR.SendKeyL2 = 0x04;
|
||
//3级安全
|
||
this.UpdateConfigParamsHR.RequestSeedL3 = 0x05;
|
||
this.UpdateConfigParamsHR.SendKeyL3 = 0x06;
|
||
//4级安全
|
||
this.UpdateConfigParamsHR.RequestSeedL4 = 0x07;
|
||
this.UpdateConfigParamsHR.SendKeyL4 = 0x08;
|
||
|
||
//安全算法
|
||
this.UpdateConfigParamsHR.ISeedToIOKeyArray = SecurityAlgorithmHR.ISeedToIOKeyArray;
|
||
|
||
this.UpdateConfigParamsHR.WriteFingerprintDID[0] = 0xf1;
|
||
this.UpdateConfigParamsHR.WriteFingerprintDID[1] = 0x07;
|
||
|
||
|
||
//各个文件烧录地址
|
||
this.UpdateConfigParamsHR.FlashDriveUpdateStartAddr = 0x100800;
|
||
this.UpdateConfigParamsHR.UIFlashDriveUpdateStartAddr = 0xFEBFD800;
|
||
this.UpdateConfigParamsHR.AppUpdateStartAddr = 0x20800; //0x80000
|
||
this.UpdateConfigParamsHR.UIUpdateStartAddr = 0x1000F800; //0x10000000(old)
|
||
this.UpdateConfigParamsHR.RectifyStartAddr = 0x380000; //矫正
|
||
|
||
//37服务是否需要CRC校验
|
||
this.UpdateConfigParamsHR.IsUpdateDataCRC = false;
|
||
|
||
//CRC校验是否用小端
|
||
this.UpdateConfigParamsHR.CrcIsLsb = true;
|
||
|
||
//FlashDrive文件起始偏移 去掉头信息
|
||
this.UpdateConfigParamsHR.FlashDriveFileOffset = 0;
|
||
//App文件起始偏移 去掉头信息
|
||
this.UpdateConfigParamsHR.AppFileOffset = 0;
|
||
//UI文件起始偏移 去掉头信息
|
||
this.UpdateConfigParamsHR.UIFileOffset = 0;
|
||
//矫正参数文件起始偏移 去掉头信息
|
||
this.UpdateConfigParamsHR.RectifyFileOffset = 0;
|
||
//最大包的大小
|
||
this.UpdateConfigParamsHR.UDSMsgLengthMax = 2048;
|
||
|
||
//升级流程
|
||
this.UpdateConfigParamsHR.UpdateStepItemArray = new UpdateStepItem[]
|
||
{
|
||
/*10 01 进入默认会话*/
|
||
new UpdateStepItem(GotoDefaultSession, UpdateReply0x5001),
|
||
/*10 03 进入扩展会话*/
|
||
new UpdateStepItem(GotoExtendeSession, UpdateReply0x5003),
|
||
/*31 01 DF E0 03 从节点模式选择例行*/
|
||
//new UpdateStepItem(GotoUpdate0x3101DFE003, UpdateReply0xDFE003),
|
||
/*31 编程预条件检查*/
|
||
new UpdateStepItem(SendCheckProgramCondParamsFF02, UpdateReplyCheckProgrammingFF02),
|
||
|
||
//new UpdateStepItem(SetDTCControl0x8502, UpdateReply0xC5),
|
||
//new UpdateStepItem(SetCommunicationControl0x280103, UpdateReply0x68),
|
||
/*4 扩展会话(抑制)*/
|
||
//new UpdateStepItem(SetDTCControl0x1083, null),
|
||
/*6 通讯控制禁止(抑制)*/
|
||
new UpdateStepItem(SetDTCControl0x288101, null),
|
||
/*5 DTC设置关(抑制)*/
|
||
new UpdateStepItem(SetDTCControl0x8582, null),
|
||
/*7*/
|
||
// new UpdateStepItem(RequestSeedLevel1, UpdateReplySeedLevel1),
|
||
/**/
|
||
// new UpdateStepItem(SendKeyLevel1, UpdateReplyKeyLevel1),
|
||
/*8*/
|
||
new UpdateStepItem(GotoProgrammingSession, UpdateReply0x5002),
|
||
/*9*/
|
||
new UpdateStepItem(RequestSeedLevel3, UpdateReplySeedLevel3),
|
||
/**/
|
||
new UpdateStepItem(SendKeyLevel3, UpdateReplyKeyLevel3),
|
||
|
||
//10 下载FlashDriver
|
||
new UpdateStepItem(UDSUpdateDownloadFlashDriver, UpdateReplyRequestDownload),
|
||
/*11*/
|
||
new UpdateStepItem(UDSUpdateTransferData, UpdateReply0x76),
|
||
/*12*/
|
||
new UpdateStepItem(TransferExit, UpdateReply0x77),
|
||
/*13*/ // 检查flash driver 完整性
|
||
new UpdateStepItem(UDSUpdateFlashCheckSumCRC32, UpdateReplyFlashDriverCheckHR),
|
||
/*检查传输序列(FlashDriver)*/
|
||
//new UpdateStepItem(Diag0x1284809F, UpdateReply0x7101),
|
||
//擦除
|
||
// 14new UpdateStepItem(UDSUpdateEraseMemoryLen13, UpdateReplyEraseFlash),
|
||
new UpdateStepItem(UDSUpdateEraseMemoryLen13, UpdateReplyEraseFlash),
|
||
|
||
//15下载APP
|
||
new UpdateStepItem(UDSUpdateDownloadAppFile, UpdateReplyRequestDownload),
|
||
/*16*/
|
||
new UpdateStepItem(UDSUpdateTransferData, UpdateReply0x76),
|
||
/*17*/
|
||
new UpdateStepItem(TransferExit, UpdateReply0x77),
|
||
/*18*/ // 检测 app 完整性
|
||
new UpdateStepItem(UDSUpdateAppCheckSumHR, UpdateReplyAppCheckHR),
|
||
|
||
/*20软硬件一致性检查*/
|
||
new UpdateStepItem(SendCheckCompatibility, UpdateReplyCheckCompatibility),
|
||
|
||
//等1s
|
||
new UpdateStepItem(UpdateTimerSet1s, null),
|
||
/**/
|
||
new UpdateStepItem(UpdateTimerSet20ms, null),
|
||
|
||
/*21*/
|
||
new UpdateStepItem(UDSUpdateECUHardReset0x03, UpdateReplyECUReset),
|
||
|
||
/* 22 */
|
||
new UpdateStepItem(UpdateToolsDeinit, null),
|
||
|
||
};
|
||
|
||
#endregion
|
||
|
||
|
||
//默认升级配置
|
||
UpdateConfigParamsNow = UpdateConfigParamsHR;
|
||
|
||
}
|
||
|
||
|
||
/*10 03 进入扩展会话*/
|
||
private void GotoExtendeSession()
|
||
{
|
||
byte[] data = new byte[8];
|
||
byte len = 2;
|
||
data[0] = 0x10;
|
||
data[1] = 0x03;
|
||
|
||
UDSInfo.SendPackage(data, len, false);
|
||
|
||
rtxtLog.AppendText("请求进入扩展会话\n");
|
||
|
||
}
|
||
/*10 03 进入默认会话*/
|
||
private void GotoDefaultSession()
|
||
{
|
||
byte[] data = new byte[8];
|
||
byte len = 2;
|
||
data[0] = 0x10;
|
||
data[1] = 0x01;
|
||
|
||
UDSInfo.SendPackage(data, len, false);
|
||
|
||
rtxtLog.AppendText("请求进入默认会话\n");
|
||
|
||
}
|
||
private void GotoUpdate0x3101DFE003()
|
||
{
|
||
byte[] data = new byte[8];
|
||
byte len = 5;
|
||
data[0] = 0x31;
|
||
data[1] = 0x01;
|
||
data[2] = 0xDF;
|
||
data[3] = 0xE0;
|
||
data[4] = 0x03;
|
||
|
||
UDSInfo.SendPackage(data, len, false);
|
||
|
||
rtxtLog.AppendText("从节点模式选择例行\n");
|
||
|
||
}
|
||
|
||
/*85 02 控制DTC设置*/
|
||
private void SetDTCControl0x8502()
|
||
{
|
||
byte[] data = new byte[8];
|
||
byte len = 2;
|
||
data[0] = 0x85;
|
||
data[1] = 0x02;
|
||
|
||
UDSInfo.SendPackage(data, len, false);
|
||
//UDSInfo.SendPackage(data, len, false);
|
||
|
||
rtxtLog.AppendText("请求控制DTC设置\n");
|
||
}
|
||
/*扩展会话(抑制)*/
|
||
private void SetDTCControl0x1083()
|
||
{
|
||
byte[] data = new byte[8];
|
||
byte len = 2;
|
||
data[0] = 0x10;
|
||
data[1] = 0x83;
|
||
|
||
UDSInfo.SendPackage(data, len, false);
|
||
//UDSInfo.SendPackage(data, len, false);
|
||
|
||
rtxtLog.AppendText("扩展会话(抑制)\n");
|
||
}
|
||
/*通讯控制禁止(抑制)*/
|
||
private void SetDTCControl0x288101()
|
||
{
|
||
byte[] data = new byte[8];
|
||
byte len = 3;
|
||
data[0] = 0x28;
|
||
data[1] = 0x81;
|
||
data[2] = 0x01;
|
||
|
||
UDSInfo.SendPackage(data, len, false);
|
||
//UDSInfo.SendPackage(data, len, false);
|
||
|
||
rtxtLog.AppendText("通讯控制禁止(抑制)\n");
|
||
}
|
||
/*85 82 控制DTC设置*/
|
||
private void SetDTCControl0x8582()
|
||
{
|
||
byte[] data = new byte[8];
|
||
byte len = 2;
|
||
data[0] = 0x85;
|
||
data[1] = 0x82;
|
||
|
||
UDSInfo.SendPackage(data, len, false);
|
||
|
||
rtxtLog.AppendText("请求控制DTC设置\n");
|
||
}
|
||
|
||
private void SetCommunicationControl(byte[] did)
|
||
{
|
||
byte[] data = new byte[3];
|
||
data[0] = 0x28;
|
||
data[1] = did[0];
|
||
data[2] = did[1];
|
||
|
||
UDSInfo.SendPackage(data, data.Length, false);
|
||
|
||
rtxtLog.AppendText("请求通信控制\n");
|
||
}
|
||
|
||
/*28 03 01通信控制禁止常规报文发送*/
|
||
private void SetCommunicationControl0x280301()
|
||
{
|
||
byte[] data = new byte[2] { 0x03, 0x01 };
|
||
|
||
SetCommunicationControl(data);
|
||
}
|
||
|
||
/*28 03 03通信控制禁止常规报文发送*/
|
||
private void SetCommunicationControl0x280303()
|
||
{
|
||
byte[] data = new byte[2] { 0x03, 0x03 };
|
||
|
||
SetCommunicationControl(data);
|
||
}
|
||
|
||
/*28 83 01通信控制禁止常规报文发送*/
|
||
private void SetCommunicationControl0x288301()
|
||
{
|
||
|
||
byte[] data = new byte[2] { 0x83, 0x01 };
|
||
|
||
SetCommunicationControl(data);
|
||
}
|
||
|
||
/*28 83 03通信控制禁止常规报文发送*/
|
||
private void SetCommunicationControl0x288303()
|
||
{
|
||
byte[] data = new byte[2] { 0x83, 0x03 };
|
||
|
||
SetCommunicationControl(data);
|
||
}
|
||
|
||
/*28 81 03通信控制禁止常规报文发送*/
|
||
private void SetCommunicationControl0x280103()
|
||
{
|
||
byte[] data = new byte[2] { 0x01, 0x03 };
|
||
|
||
SetCommunicationControl(data);
|
||
}
|
||
|
||
/*10 02进入编程会话*/
|
||
private void GotoProgrammingSession()
|
||
{
|
||
byte[] data = new byte[8];
|
||
byte len = 2;
|
||
data[0] = 0x10;
|
||
data[1] = 0x02;
|
||
|
||
UDSInfo.SendPackage(data, len, false);
|
||
|
||
rtxtLog.AppendText("请求进入编程会话\n");
|
||
}
|
||
|
||
private void RequestSeed(byte level)
|
||
{
|
||
byte[] data = new byte[2];
|
||
|
||
data[0] = 0x27;
|
||
data[1] = level;
|
||
|
||
UDSInfo.SendPackage(data, 2, false);
|
||
|
||
rtxtLog.AppendText("请求安全等级种子\n");
|
||
}
|
||
|
||
private void SendKey(byte level)
|
||
{
|
||
byte[] data;
|
||
byte[] keyArray;
|
||
|
||
this.UpdateConfigParamsNow.ISeedToIOKeyArray(RecvSeed, out keyArray, level);
|
||
|
||
data = new byte[keyArray.Length + 2];
|
||
|
||
data[0] = 0x27;
|
||
data[1] = (byte)(level + 1);
|
||
|
||
Array.Copy(keyArray, 0, data, 2, keyArray.Length);
|
||
|
||
UDSInfo.SendPackage(data, data.Length, false);
|
||
|
||
|
||
rtxtLog.AppendText("发送安全等级密钥\n");
|
||
}
|
||
|
||
//请求种子 等级1
|
||
private void RequestSeedLevel1()
|
||
{
|
||
RequestSeed(UpdateConfigParamsNow.RequestSeedL1);
|
||
}
|
||
|
||
//请求种子 等级2
|
||
private void RequestSeedLevel2()
|
||
{
|
||
RequestSeed(UpdateConfigParamsNow.RequestSeedL2);
|
||
}
|
||
|
||
//请求种子 等级3
|
||
private void RequestSeedLevel3()
|
||
{
|
||
RequestSeed(UpdateConfigParamsNow.RequestSeedL3);
|
||
}
|
||
|
||
//请求种子 等级4
|
||
private void RequestSeedLevel4()
|
||
{
|
||
RequestSeed(UpdateConfigParamsNow.RequestSeedL4);
|
||
}
|
||
|
||
//发送密钥 等级1
|
||
private void SendKeyLevel1()
|
||
{
|
||
SendKey(UpdateConfigParamsNow.RequestSeedL1);
|
||
}
|
||
|
||
//发送密钥 等级2
|
||
private void SendKeyLevel2()
|
||
{
|
||
SendKey(UpdateConfigParamsNow.RequestSeedL2);
|
||
}
|
||
|
||
//发送密钥 等级3
|
||
private void SendKeyLevel3()
|
||
{
|
||
SendKey(UpdateConfigParamsNow.RequestSeedL3);
|
||
}
|
||
|
||
//发送密钥 等级4
|
||
private void SendKeyLevel4()
|
||
{
|
||
SendKey(UpdateConfigParamsNow.RequestSeedL4);
|
||
}
|
||
|
||
private void Diag0x1284809F()
|
||
{
|
||
byte[] data = new byte[] { 0x02, 0x02, 0x12, 0x84, 0x80, 0x9F };
|
||
|
||
Diag0x3101(data);
|
||
}
|
||
private void Diag0x3101(byte[] did)
|
||
{
|
||
byte[] data = new byte[did.Length + 2];
|
||
|
||
data[0] = 0x31;
|
||
data[1] = 0x01;
|
||
|
||
did.CopyTo(data, 2);
|
||
|
||
UDSInfo.SendPackage(data, data.Length, false);
|
||
}
|
||
private void SendFingerPrintLen10()
|
||
{
|
||
byte len = 10;
|
||
SendMsg_Len = len;
|
||
|
||
SendBuff[0] = 0x2e;
|
||
SendBuff[1] = 0xf1;
|
||
SendBuff[2] = 0x84;
|
||
SendBuff[3] = 0x15;
|
||
SendBuff[4] = 0x09;
|
||
SendBuff[5] = 0x0b;
|
||
SendBuff[6] = 0x31;
|
||
SendBuff[7] = 0x32;
|
||
SendBuff[8] = 0x33;
|
||
SendBuff[9] = 0x34;
|
||
|
||
UDSInfo.SendPackage(SendBuff, len, false);
|
||
|
||
|
||
rtxtLog.AppendText("写入指纹\n");
|
||
|
||
}
|
||
|
||
private void SendFingerPrintLen12()
|
||
{
|
||
byte len = 12;
|
||
SendMsg_Len = len;
|
||
|
||
SendBuff[0] = 0x2e;
|
||
SendBuff[1] = 0xf1;
|
||
SendBuff[2] = 0x84;
|
||
SendBuff[3] = 0x01;
|
||
SendBuff[4] = 0x01;
|
||
SendBuff[5] = 0x01;
|
||
SendBuff[6] = 0x32;
|
||
SendBuff[7] = 0x33;
|
||
SendBuff[8] = 0x34;
|
||
SendBuff[9] = 0x35;
|
||
SendBuff[10] = 0x36;
|
||
SendBuff[11] = 0x37;
|
||
|
||
UDSInfo.SendPackage(SendBuff, len, false);
|
||
|
||
rtxtLog.AppendText("写入指纹\n");
|
||
|
||
}
|
||
|
||
|
||
private void SendFingerPrintLen13()
|
||
{
|
||
byte len = 13;
|
||
SendMsg_Len = len;
|
||
|
||
SendBuff[0] = 0x2e;
|
||
SendBuff[1] = UpdateConfigParamsNow.WriteFingerprintDID[0];
|
||
SendBuff[2] = UpdateConfigParamsNow.WriteFingerprintDID[1];
|
||
SendBuff[3] = 0x01;
|
||
SendBuff[4] = 0x01;
|
||
SendBuff[5] = 0x01;
|
||
SendBuff[6] = 0x01;
|
||
SendBuff[7] = 0x36;
|
||
SendBuff[8] = 0x36;
|
||
SendBuff[9] = 0x36;
|
||
SendBuff[10] = 0x36;
|
||
SendBuff[11] = 0x36;
|
||
SendBuff[12] = 0x36;
|
||
|
||
|
||
UDSInfo.SendPackage(SendBuff, len, false);
|
||
|
||
rtxtLog.AppendText("写入指纹\n");
|
||
|
||
}
|
||
|
||
private void SendFingerPrintLen33()
|
||
{
|
||
|
||
byte[] data = new byte[33];
|
||
|
||
data[0] = 0x2e;
|
||
data[1] = UpdateConfigParamsNow.WriteFingerprintDID[0];
|
||
data[2] = UpdateConfigParamsNow.WriteFingerprintDID[1];
|
||
|
||
UDSInfo.SendPackage(data, data.Length, false);
|
||
|
||
rtxtLog.AppendText("写入指纹\n");
|
||
|
||
}
|
||
|
||
/*34 请求下载数据*/
|
||
private void RequestDownload(byte[] address, byte[] datasize)
|
||
{
|
||
byte len = 11;
|
||
|
||
SendMsg_Len = len;
|
||
|
||
SendBuff[0] = 0x34;
|
||
SendBuff[1] = 0x0;
|
||
SendBuff[2] = 0x44;
|
||
SendBuff[3] = address[0];
|
||
SendBuff[4] = address[1];
|
||
SendBuff[5] = address[2];
|
||
SendBuff[6] = address[3];
|
||
SendBuff[7] = datasize[0];
|
||
SendBuff[8] = datasize[1];
|
||
SendBuff[9] = datasize[2];
|
||
SendBuff[10] = datasize[3];
|
||
|
||
UDSInfo.SendPackage(SendBuff, len, false);
|
||
|
||
rtxtLog.AppendText("请求下载APP\n");
|
||
}
|
||
|
||
|
||
/*36 发送升级数据*/
|
||
private void TransferData(/*List<byte> Buffer*/ref byte[] data, byte[] size)
|
||
{
|
||
uint filesize = 0;
|
||
|
||
UInt32 step = 0;
|
||
|
||
filesize = (uint)((size[3]) | (size[2] << 8) | (size[1] << 16) | (size[0] << 24));
|
||
|
||
|
||
SendBuff[0] = 0x36;
|
||
|
||
if (filesize - FileOffset > this.UpdateConfigParamsNow.UDSMsgLengthMax)
|
||
{
|
||
SendMsg_Len = (short)(this.UpdateConfigParamsNow.UDSMsgLengthMax + 2);
|
||
SendBuff[1] = BlockIndex;
|
||
for (int i = 0; i < this.UpdateConfigParamsNow.UDSMsgLengthMax; i++)
|
||
{
|
||
|
||
SendBuff[i + 2] = data[i + FileOffset];
|
||
|
||
}
|
||
FileOffset += this.UpdateConfigParamsNow.UDSMsgLengthMax;
|
||
BlockIndex++;
|
||
|
||
UpdateFileSendBytes += this.UpdateConfigParamsNow.UDSMsgLengthMax;
|
||
}
|
||
else
|
||
{
|
||
SendMsg_Len = (short)((filesize - FileOffset) + 2);
|
||
SendBuff[1] = BlockIndex;
|
||
for (int i = 0; i < (filesize - FileOffset); i++)
|
||
{
|
||
SendBuff[i + 2] = data[i + FileOffset];
|
||
}
|
||
FileOffset = 0;
|
||
BlockIndex = 1;
|
||
UpdataFlag = 1;
|
||
|
||
CRCValue = GetCRC16(data); //新加
|
||
|
||
UpdateFileSendBytes += (SendMsg_Len - 2);
|
||
}
|
||
|
||
|
||
step = (UInt32)((UpdateFileSendBytes * 100) / (UpdateFileTotalBytes));/*更新进度条步数*/
|
||
lbUpdateProgress.Text = Convert.ToString(step) + "%";
|
||
|
||
|
||
rtxtLog.AppendText(string.Format("发送升级数据第{0}个包\n", SendBuff[1]));
|
||
UDSInfo.SendPackage(SendBuff, SendMsg_Len, false);
|
||
|
||
|
||
/*更新进度条*/
|
||
if ((2 == UpdataFileFlag))
|
||
{
|
||
if (100 >= step)
|
||
{
|
||
this.progressBar1.Value = Convert.ToInt32(step);
|
||
}
|
||
}
|
||
}
|
||
|
||
/*37 退出数据下载*/
|
||
private void TransferExit()
|
||
{
|
||
byte[] data = new byte[8];
|
||
byte len = 1;
|
||
data[0] = 0x37;
|
||
|
||
UDSInfo.SendPackage(data, len, false);
|
||
|
||
rtxtLog.AppendText("结束当前数据段下载\n");
|
||
}
|
||
|
||
private void TransferExit(uint crc32)
|
||
{
|
||
byte[] data = new byte[8];
|
||
byte len = 5;
|
||
|
||
data[0] = 0x37;
|
||
|
||
data[1] = (byte)((crc32 >> 24) & 0xff);
|
||
data[2] = (byte)((crc32 >> 16) & 0xff);
|
||
data[3] = (byte)((crc32 >> 8) & 0xff);
|
||
data[4] = (byte)((crc32 >> 0) & 0xff);
|
||
|
||
|
||
UDSInfo.SendPackage(data, len, false);
|
||
|
||
|
||
rtxtLog.AppendText("结束当前数据段下载2\n");
|
||
}
|
||
|
||
/*37 FlashDriver退出数据下载*/
|
||
private void FlashDriverTransferExitLen5()
|
||
{
|
||
|
||
TransferExit(FlashCheckSum);
|
||
}
|
||
|
||
/*37 App退出数据下载*/
|
||
private void AppTransferExitLen5()
|
||
{
|
||
//UpdateFileType
|
||
switch (UpdateFileType)
|
||
{
|
||
case UpdateFileType.App:
|
||
{
|
||
TransferExit(AppCheckSum);
|
||
break;
|
||
}
|
||
case UpdateFileType.UI:
|
||
{
|
||
TransferExit(UiCheckSum);
|
||
break;
|
||
}
|
||
case UpdateFileType.Rectify:
|
||
{
|
||
TransferExit(RectifyCheckSum);
|
||
break;
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
private void RequestCheckSum(byte[] checkParams)
|
||
{
|
||
byte[] data = new byte[4];
|
||
byte len = 4;
|
||
|
||
data[0] = 0x31;
|
||
data[1] = 0x01;
|
||
|
||
data[2] = checkParams[0];
|
||
data[3] = checkParams[1];
|
||
|
||
|
||
UDSInfo.SendPackage(data, len, false);
|
||
}
|
||
|
||
/*31 请求checksum*/
|
||
private void RequestCheckSum(byte[] checkParams, uint checksum)
|
||
{
|
||
SendMsg_Len = 8;
|
||
|
||
SendBuff[0] = 0x31;
|
||
SendBuff[1] = 0x01;
|
||
|
||
SendBuff[2] = checkParams[0];
|
||
SendBuff[3] = checkParams[1];
|
||
|
||
SendBuff[4] = (byte)((checksum) >> 24);
|
||
SendBuff[5] = (byte)((checksum) >> 16);
|
||
SendBuff[6] = (byte)((checksum) >> 8);
|
||
SendBuff[7] = (byte)(checksum);
|
||
|
||
|
||
UDSInfo.SendPackage(SendBuff, SendMsg_Len, false);
|
||
|
||
}
|
||
|
||
private void RequestCheckSumHR(byte[] checkParams, uint checksum)
|
||
{
|
||
SendMsg_Len = 8;
|
||
|
||
SendBuff[0] = 0x31;
|
||
SendBuff[1] = 0x01;
|
||
|
||
SendBuff[2] = 0xF0;
|
||
SendBuff[3] = 0x01;
|
||
|
||
SendBuff[4] = (byte)((checksum) >> 24);
|
||
SendBuff[5] = (byte)((checksum) >> 16);
|
||
SendBuff[6] = (byte)((checksum) >> 8);
|
||
SendBuff[7] = (byte)(checksum);
|
||
|
||
|
||
UDSInfo.SendPackage(SendBuff, SendMsg_Len, false);
|
||
|
||
}
|
||
|
||
/*31 请求checksum*/
|
||
private void RequestCheckSum(byte[] checkParams, byte[] startAddr, byte[] size, uint checksum)
|
||
{
|
||
SendMsg_Len = 16;
|
||
|
||
SendBuff[0] = 0x31;
|
||
SendBuff[1] = 0x01;
|
||
|
||
SendBuff[2] = checkParams[0];
|
||
SendBuff[3] = checkParams[1];
|
||
|
||
SendBuff[4] = startAddr[0];
|
||
SendBuff[5] = startAddr[1];
|
||
SendBuff[6] = startAddr[2];
|
||
SendBuff[7] = startAddr[3];
|
||
|
||
SendBuff[8] = size[0];
|
||
SendBuff[9] = size[1];
|
||
SendBuff[10] = size[2];
|
||
SendBuff[11] = size[3];
|
||
|
||
SendBuff[12] = (byte)((checksum) >> 24);
|
||
SendBuff[13] = (byte)((checksum) >> 16);
|
||
SendBuff[14] = (byte)((checksum) >> 8);
|
||
SendBuff[15] = (byte)(checksum);
|
||
|
||
|
||
UDSInfo.SendPackage(SendBuff, SendMsg_Len, false);
|
||
|
||
}
|
||
|
||
/*31 擦除eeprom*/
|
||
private void RequestEraseMemoryLen12(byte[] address, byte[] datasize)
|
||
{
|
||
byte len = 12;
|
||
|
||
SendMsg_Len = len;
|
||
|
||
SendBuff[0] = 0x31;
|
||
SendBuff[1] = 0x01;
|
||
|
||
|
||
SendBuff[2] = UpdateConfigParamsNow.EraseMemoryParams[0];
|
||
SendBuff[3] = UpdateConfigParamsNow.EraseMemoryParams[1];
|
||
|
||
|
||
SendBuff[4] = address[0];
|
||
SendBuff[5] = address[1];
|
||
SendBuff[6] = address[2];
|
||
SendBuff[7] = address[3];
|
||
SendBuff[8] = datasize[0];
|
||
SendBuff[9] = datasize[1];
|
||
SendBuff[10] = datasize[2];
|
||
SendBuff[11] = datasize[3];
|
||
|
||
UDSInfo.SendPackage(SendBuff, len, false);
|
||
|
||
rtxtLog.AppendText("擦除Flash\n");
|
||
}
|
||
|
||
/*31 擦除eeprom*/
|
||
private void RequestEraseMemoryLen13(byte[] address, byte[] datasize)
|
||
{
|
||
byte len = 13;
|
||
|
||
SendMsg_Len = len;
|
||
|
||
SendBuff[0] = 0x31;
|
||
SendBuff[1] = 0x01;
|
||
|
||
SendBuff[2] = UpdateConfigParamsNow.EraseMemoryParams[0];
|
||
SendBuff[3] = UpdateConfigParamsNow.EraseMemoryParams[1];
|
||
|
||
SendBuff[4] = 0x44;
|
||
SendBuff[5] = address[0];
|
||
SendBuff[6] = address[1];
|
||
SendBuff[7] = address[2];
|
||
SendBuff[8] = address[3];
|
||
SendBuff[9] = datasize[0];
|
||
SendBuff[10] = datasize[1];
|
||
SendBuff[11] = datasize[2];
|
||
SendBuff[12] = datasize[3];
|
||
|
||
UDSInfo.SendPackage(SendBuff, len, false);
|
||
}
|
||
|
||
/*31 逻辑块依赖性检查*/
|
||
private void SendCheckCompatibility()
|
||
{
|
||
byte[] data = new byte[8];
|
||
byte len = 4;
|
||
data[0] = 0x31;
|
||
data[1] = 0x01;
|
||
|
||
//data[2] = CheckCompatibility[0];
|
||
//data[3] = CheckCompatibility[1];
|
||
|
||
data[2] = UpdateConfigParamsNow.CheckCompatibilityParams[0];
|
||
data[3] = UpdateConfigParamsNow.CheckCompatibilityParams[1];
|
||
|
||
|
||
UDSInfo.SendPackage(data, len, false);
|
||
|
||
rtxtLog.AppendText("逻辑块依赖性检查\n");
|
||
}
|
||
|
||
/*31 编程预条件检查*/
|
||
private void SendCheckProgramCondParams()
|
||
{
|
||
byte[] data = new byte[8];
|
||
byte len = 4;
|
||
|
||
data[0] = 0x31;
|
||
data[1] = 0x01;
|
||
|
||
data[2] = UpdateConfigParamsNow.CheckProgramCondParams[0];
|
||
data[3] = UpdateConfigParamsNow.CheckProgramCondParams[1];
|
||
|
||
|
||
UDSInfo.SendPackage(data, len, false);
|
||
|
||
rtxtLog.AppendText("编程预条件检查\n");
|
||
}
|
||
/*31 编程预条件检查*/
|
||
private void SendCheckProgramCondParamsFF02()
|
||
{
|
||
byte[] data = new byte[8];
|
||
byte len = 4;
|
||
|
||
data[0] = 0x31;
|
||
data[1] = 0x01;
|
||
|
||
data[2] = 0xFF;
|
||
data[3] = 0x02;
|
||
|
||
|
||
UDSInfo.SendPackage(data, len, false);
|
||
|
||
rtxtLog.AppendText("编程预条件检查\n");
|
||
}
|
||
|
||
/*11 01 ECU复位*/
|
||
private void ECUHardReset(byte ResetParam)
|
||
{
|
||
byte[] data = new byte[8];
|
||
byte len = 2;
|
||
data[0] = 0x11;
|
||
data[1] = ResetParam;
|
||
|
||
UDSInfo.SendPackage(data, len, false);
|
||
|
||
rtxtLog.AppendText("ECU复位\n");
|
||
}
|
||
|
||
|
||
private void Send1083()
|
||
{
|
||
byte[] data = new byte[] { 0x10, 0x83 };
|
||
|
||
UDSInfo.SendPackage(data, data.Length, false);
|
||
|
||
}
|
||
|
||
private void Send288103()
|
||
{
|
||
byte[] data = new byte[] { 0x28, 0x81, 0x03 };
|
||
|
||
UDSInfo.SendPackage(data, data.Length, false);
|
||
|
||
}
|
||
|
||
|
||
private UpdateReplyStatus UpdateReply0x5003(byte[] data, UInt32 len)
|
||
{
|
||
if ((data[0] == 0x50)
|
||
&& (data[1] == 0x03)
|
||
)
|
||
{
|
||
//打印log
|
||
rtxtLog.AppendText("已进入扩展会话\n");
|
||
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReply0x5001(byte[] data, UInt32 len)
|
||
{
|
||
if ((data[0] == 0x50)
|
||
&& (data[1] == 0x01)
|
||
)
|
||
{
|
||
//打印log
|
||
rtxtLog.AppendText("已进入默认会话\n");
|
||
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
private UpdateReplyStatus UpdateReply0x5002(byte[] data, UInt32 len)
|
||
{
|
||
if ((data[0] == 0x50)
|
||
&& (data[1] == 0x02)
|
||
)
|
||
{
|
||
//打印log
|
||
rtxtLog.AppendText("已进入到编程会话\n");
|
||
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
private UpdateReplyStatus UpdateReply0x7101(byte[] data, UInt32 len)
|
||
{
|
||
if ((data[0] == 0x71)
|
||
&& (data[1] == 0x01) && (data[0] == 0x02)
|
||
&& (data[1] == 0x02)
|
||
)
|
||
{
|
||
//打印log
|
||
rtxtLog.AppendText("检查传输序列(FlashDriver)\n");
|
||
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReply0x68(byte[] data, UInt32 len)
|
||
{
|
||
if (data[0] == 0x68)
|
||
{
|
||
//打印log
|
||
rtxtLog.AppendText("已关闭通讯\n");
|
||
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReply0xC5(byte[] data, UInt32 len)
|
||
{
|
||
if (data[0] == 0xC5)
|
||
{
|
||
//打印log
|
||
rtxtLog.AppendText("已关闭DTC记录\n");
|
||
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
|
||
|
||
|
||
private UpdateReplyStatus UpdateReplySeed(byte[] data, UInt32 len, byte level)
|
||
{
|
||
if ((data[0] == 0x67)
|
||
&& (data[1] == level)
|
||
)
|
||
{
|
||
//打印log
|
||
rtxtLog.AppendText("获取种子成功\n");
|
||
|
||
Array.Copy(data, 2, RecvSeed, 0, len - 2);
|
||
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReplySeedLevel1(byte[] data, UInt32 len)
|
||
{
|
||
return UpdateReplySeed(data, len, UpdateConfigParamsNow.RequestSeedL1);
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReplySeedLevel2(byte[] data, UInt32 len)
|
||
{
|
||
return UpdateReplySeed(data, len, UpdateConfigParamsNow.RequestSeedL2);
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReplySeedLevel3(byte[] data, UInt32 len)
|
||
{
|
||
return UpdateReplySeed(data, len, UpdateConfigParamsNow.RequestSeedL3);
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReplySeedLevel4(byte[] data, UInt32 len)
|
||
{
|
||
return UpdateReplySeed(data, len, UpdateConfigParamsNow.RequestSeedL4);
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReplyKey(byte[] data, UInt32 len, byte level)
|
||
{
|
||
if ((data[0] == 0x67)
|
||
&& (data[1] == level)
|
||
)
|
||
{
|
||
//打印log
|
||
rtxtLog.AppendText("安全访问通过\n");
|
||
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReplyKeyLevel1(byte[] data, UInt32 len)
|
||
{
|
||
return UpdateReplyKey(data, len, UpdateConfigParamsNow.SendKeyL1);
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReplyKeyLevel2(byte[] data, UInt32 len)
|
||
{
|
||
return UpdateReplyKey(data, len, UpdateConfigParamsNow.SendKeyL2);
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReplyKeyLevel3(byte[] data, UInt32 len)
|
||
{
|
||
return UpdateReplyKey(data, len, UpdateConfigParamsNow.SendKeyL3);
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReplyKeyLevel4(byte[] data, UInt32 len)
|
||
{
|
||
return UpdateReplyKey(data, len, UpdateConfigParamsNow.SendKeyL4);
|
||
}
|
||
|
||
|
||
private UpdateReplyStatus UpdateReplyWriteFingerprint(byte[] data, UInt32 len)
|
||
{
|
||
|
||
if ((data[0] == 0x6E)
|
||
&&(data[1] == UpdateConfigParamsNow.WriteFingerprintDID[0])
|
||
&& (data[2] == UpdateConfigParamsNow.WriteFingerprintDID[1])
|
||
//|| (data[1] == 0xf1) && (data[2] == 0x07)
|
||
)
|
||
{
|
||
//打印log
|
||
rtxtLog.AppendText("写入指纹成功\n");
|
||
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
|
||
}
|
||
|
||
private bool UpdateReply0x3101(byte[] data, UInt32 len, byte[] did)
|
||
{
|
||
if((data[0] == 0x71)
|
||
&& (data[1] == 0x01)
|
||
&& (data[2] == did[0])
|
||
&& (data[3] == did[1])
|
||
)
|
||
{
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
private bool UpdateReply0x3101F001(byte[] data, UInt32 len, byte[] did)
|
||
{
|
||
if ((data[0] == 0x71)
|
||
&& (data[1] == 0x01)
|
||
&& (data[2] == 0xF0)
|
||
&& (data[3] == 0x01)
|
||
)
|
||
{
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
private bool UpdateReply0x3101FF02(byte[] data, UInt32 len, byte[] did)
|
||
{
|
||
if ((data[0] == 0x71)
|
||
&& (data[1] == 0x01)
|
||
&& (data[2] == 0xFF)
|
||
&& (data[3] == 0x02)
|
||
)
|
||
{
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReply0xDFE003(byte[] data, UInt32 len)
|
||
{
|
||
if (UpdateReply0x3101(data, len, new byte[2]{0xdf, 0xe0})
|
||
)
|
||
{
|
||
rtxtLog.AppendText("0xDFE0通过\n");
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReplyCheckProgramming(byte[] data, UInt32 len)
|
||
{
|
||
if (UpdateReply0x3101(data, len, UpdateConfigParamsNow.CheckProgramCondParams)
|
||
)
|
||
{
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
private UpdateReplyStatus UpdateReplyCheckProgrammingFF02(byte[] data, UInt32 len)
|
||
{
|
||
if (UpdateReply0x3101FF02(data, len, UpdateConfigParamsNow.CheckProgramCondParams)
|
||
)
|
||
{
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
private UpdateReplyStatus UpdateReplyEraseFlash(byte[] data, UInt32 len)
|
||
{
|
||
if (UpdateReply0x3101(data, len, UpdateConfigParamsNow.EraseMemoryParams)
|
||
)
|
||
{
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReplyFlashDriverCheck(byte[] data, UInt32 len)
|
||
{
|
||
if(UpdateReply0x3101(data, len, UpdateConfigParamsNow.FlashCheckMemoryParams)
|
||
&& (data[5] == 0)
|
||
)
|
||
{
|
||
rtxtLog.AppendText("FlashDriver校验和通过\n");
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReplyFlashDriverCheckHR(byte[] data, UInt32 len)
|
||
{
|
||
if (UpdateReply0x3101F001(data, len, UpdateConfigParamsNow.FlashCheckMemoryParams)
|
||
&& (data[5] == 0)
|
||
)
|
||
{
|
||
rtxtLog.AppendText("FlashDriver校验和通过\n");
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReplyAppCheck(byte[] data, UInt32 len)
|
||
{
|
||
if (UpdateReply0x3101(data, len, UpdateConfigParamsNow.AppCheckMemoryParams)
|
||
&& (data[4] == 0)
|
||
)
|
||
{
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReplyAppCheckHR(byte[] data, UInt32 len)
|
||
{
|
||
if (UpdateReply0x3101F001(data, len, UpdateConfigParamsNow.AppCheckMemoryParams)
|
||
&& (data[4] == 0)
|
||
)
|
||
{
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReplyCheckCompatibility(byte[] data, UInt32 len)
|
||
{
|
||
if (UpdateReply0x3101(data, len, UpdateConfigParamsNow.CheckCompatibilityParams)
|
||
&& (data[4] == 0)
|
||
)
|
||
{
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReplyRequestDownload(byte[] data, UInt32 len)
|
||
{
|
||
if (data[0] == 0x74)
|
||
{
|
||
|
||
UpdateConfigParamsNow.UDSMsgLengthMax = (int)((data[2] << 8) | data[3]);
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReply0x76(byte[] data, UInt32 len)
|
||
{
|
||
if (data[0] != 0x76)
|
||
{
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
|
||
|
||
if (0 == UpdataFlag)
|
||
{
|
||
return UpdateReplyStatus.ContinueSend;
|
||
}
|
||
else
|
||
{
|
||
|
||
UpdataFlag = 0;
|
||
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
}
|
||
private UpdateReplyStatus UpdateReply0x71(byte[] data, UInt32 len)
|
||
{
|
||
if (data[0] != 0x71)
|
||
{
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
|
||
|
||
if (0 == UpdataFlag)
|
||
{
|
||
return UpdateReplyStatus.ContinueSend;
|
||
}
|
||
else
|
||
{
|
||
|
||
UpdataFlag = 0;
|
||
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
}
|
||
|
||
private UpdateReplyStatus UpdateReply0x77(byte[] data, UInt32 len)
|
||
{
|
||
if (data[0] != 0x77)
|
||
{
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
|
||
if (1 == UpdataFileFlag)
|
||
{
|
||
if (((((uint)data[1] << 8) | (uint)data[2]) == (CRCValue & 0xffff))
|
||
|| (false == UpdateConfigParamsNow.IsUpdateDataCRC))
|
||
{
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
else
|
||
{
|
||
//打印log
|
||
rtxtLog.AppendText("CRC校验错误\n");
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
}
|
||
else if (2 == UpdataFileFlag)
|
||
{
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
|
||
|
||
private UpdateReplyStatus UpdateReplyECUReset(byte[] data, UInt32 len)
|
||
{
|
||
if (data[0] == 0x51)
|
||
{
|
||
//打印log
|
||
rtxtLog.AppendText("复位成功\n");
|
||
|
||
|
||
timerFlashMain.Enabled = false;
|
||
|
||
EntrySecurityFlag = EntrySecurityStatus.Idle;
|
||
|
||
UpdateConfigParams.IsUpdate = false;
|
||
UpdateConfigParams.UpdateStepNum = 0;
|
||
UpdateConfigParams.UpdateSendCmdFlag = false;
|
||
|
||
return UpdateReplyStatus.OK;
|
||
}
|
||
|
||
return UpdateReplyStatus.NoReply;
|
||
}
|
||
|
||
|
||
}
|
||
}
|