221 lines
6.9 KiB
C#
221 lines
6.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace CanTool
|
|
{
|
|
|
|
enum UpdateReplyStatus
|
|
{
|
|
OK, //肯定回复
|
|
NoReply, //未回复
|
|
ContinueSend, //继续发送
|
|
}
|
|
|
|
delegate void ISeedToIOKeyArrayFunc(byte[] iSeedArray, out byte[] ioKeyArray, int level);
|
|
delegate void UpdateSendFunc();
|
|
delegate UpdateReplyStatus UpdateReplyFunc(byte[] data, UInt32 len);
|
|
|
|
struct UpdateStepItem
|
|
{
|
|
public UpdateSendFunc SendFunc;
|
|
|
|
public UpdateReplyFunc ReplyFunc;
|
|
|
|
public UpdateStepItem(UpdateSendFunc sendFunc, UpdateReplyFunc replyFunc)
|
|
{
|
|
SendFunc = sendFunc;
|
|
ReplyFunc = replyFunc;
|
|
}
|
|
}
|
|
|
|
class UpdateConfigParams
|
|
{
|
|
|
|
static public bool IsUpdate;//是否在升级中
|
|
static public int UpdateStepNum;//升级的步骤
|
|
static public bool UpdateSendCmdFlag; //升级中要发送数据
|
|
|
|
public UInt32 CANPhyDevRxId; //物理寻址ID PCAN发送 HUD接收
|
|
public UInt32 CANFuncDevRxId; //功能寻址ID PCAN发送 HUD接收
|
|
public UInt32 CANPhyDevTxId; //HUD响应ID PCAN接收 HUD发送
|
|
|
|
public byte[] FlashCheckMemoryParams = new byte[2];/*启动FLASH校验例程*/
|
|
public byte[] AppCheckMemoryParams = new byte[2];/*启动APP校验例程*/
|
|
public byte[] CheckProgramCondParams = new byte[2];/*编程预条件检查*/
|
|
public byte[] EraseMemoryParams = new byte[2];/*启动擦除内存*/
|
|
public byte[] CheckCompatibilityParams = new byte[2];/*逻辑块依赖性检查*/
|
|
|
|
|
|
public byte RequestSeedL1; //请求种子 1级
|
|
public byte SendKeyL1; //发送密钥 1级
|
|
public byte RequestSeedL2; //请求种子 2级
|
|
public byte SendKeyL2; //发送密钥 2级
|
|
public byte RequestSeedL3; //请求种子 3级
|
|
public byte SendKeyL3; //发送密钥 3级
|
|
public byte RequestSeedL4; //请求种子 4级
|
|
public byte SendKeyL4; //发送密钥 4级
|
|
|
|
public byte[] WriteFingerprintDID = new byte[2]; //写入指纹DID
|
|
|
|
//加密算法委托
|
|
public ISeedToIOKeyArrayFunc ISeedToIOKeyArray;
|
|
|
|
|
|
|
|
|
|
public UpdateStepItem[] UpdateStepItemArray;
|
|
|
|
|
|
public uint FlashDriveUpdateStartAddr; //flashdriver起始地址
|
|
public uint UIFlashDriveUpdateStartAddr; //UI的flashdriver起始地址
|
|
public uint AppUpdateStartAddr; //APP起始地址
|
|
public uint UIUpdateStartAddr; //UI起始地址
|
|
public uint RectifyStartAddr; //矫正参数的起始地址
|
|
|
|
//37 服务是否需要CRC校验
|
|
public bool IsUpdateDataCRC;
|
|
|
|
public bool CrcIsLsb;
|
|
|
|
//FlashDrive文件开头偏移 去掉头的信息
|
|
public int FlashDriveFileOffset;
|
|
//App文件开头偏移 去掉头的信息
|
|
public int AppFileOffset;
|
|
//UI文件开头偏移 去掉头的信息
|
|
public int UIFileOffset;
|
|
//矫正文件开头偏移 去掉头的信息
|
|
public int RectifyFileOffset;
|
|
|
|
//UDS最大一个包的数量 单位
|
|
public int UDSMsgLengthMax;
|
|
|
|
|
|
//构造函数
|
|
public UpdateConfigParams()
|
|
{
|
|
}
|
|
|
|
|
|
//拷贝函数
|
|
public void CopyFrom(UpdateConfigParams Params)
|
|
{
|
|
|
|
|
|
this.CANFuncDevRxId = Params.CANFuncDevRxId;
|
|
this.CANPhyDevRxId = Params.CANPhyDevRxId;
|
|
this.CANPhyDevTxId = Params.CANPhyDevTxId;
|
|
|
|
this.RequestSeedL1 = Params.RequestSeedL1;
|
|
this.SendKeyL1 = Params.SendKeyL1;
|
|
this.RequestSeedL2 = Params.RequestSeedL2;
|
|
this.SendKeyL2 = Params.SendKeyL2;
|
|
|
|
|
|
Params.FlashCheckMemoryParams.CopyTo(this.FlashCheckMemoryParams, 0);
|
|
Params.AppCheckMemoryParams.CopyTo(this.AppCheckMemoryParams, 0);
|
|
Params.CheckProgramCondParams.CopyTo(this.CheckProgramCondParams, 0);
|
|
Params.EraseMemoryParams.CopyTo(this.EraseMemoryParams, 0);
|
|
Params.CheckCompatibilityParams.CopyTo(this.CheckCompatibilityParams, 0);
|
|
|
|
|
|
this.ISeedToIOKeyArray = Params.ISeedToIOKeyArray;
|
|
|
|
this.UpdateStepItemArray = Params.UpdateStepItemArray;
|
|
|
|
|
|
this.FlashDriveUpdateStartAddr = Params.FlashDriveUpdateStartAddr;
|
|
this.UIFlashDriveUpdateStartAddr = Params.UIFlashDriveUpdateStartAddr;
|
|
this.AppUpdateStartAddr = Params.AppUpdateStartAddr;
|
|
this.UIUpdateStartAddr = Params.UIUpdateStartAddr;
|
|
this.RectifyStartAddr = Params.RectifyStartAddr;
|
|
|
|
this.IsUpdateDataCRC = Params.IsUpdateDataCRC;
|
|
|
|
this.CrcIsLsb = Params.CrcIsLsb;
|
|
|
|
this.FlashDriveFileOffset = Params.FlashDriveFileOffset;
|
|
this.AppFileOffset = Params.AppFileOffset;
|
|
this.UIFileOffset = Params.UIFileOffset;
|
|
this.RectifyFileOffset = Params.RectifyFileOffset;
|
|
|
|
this.UDSMsgLengthMax = Params.UDSMsgLengthMax;
|
|
|
|
|
|
}
|
|
|
|
public void UpdateSendLoop()
|
|
{
|
|
UpdateSendFunc sendFunc;
|
|
UpdateReplyFunc replyFunc;
|
|
|
|
if ((IsUpdate)
|
|
&& (UpdateSendCmdFlag)
|
|
)
|
|
{
|
|
|
|
sendFunc = UpdateStepItemArray[UpdateStepNum].SendFunc;
|
|
replyFunc = UpdateStepItemArray[UpdateStepNum].ReplyFunc;
|
|
|
|
if (sendFunc != null)
|
|
{
|
|
sendFunc();
|
|
}
|
|
|
|
//无需等待回复 直接到下一步
|
|
if (replyFunc == null)
|
|
{
|
|
UpdateStepNum++;
|
|
}
|
|
else
|
|
{
|
|
UpdateSendCmdFlag = false;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public void UpdateReply(byte[] data, UInt32 len)
|
|
{
|
|
UpdateReplyFunc replyFunc;
|
|
UpdateReplyStatus replyStatus;
|
|
|
|
if (IsUpdate)
|
|
{
|
|
replyFunc = UpdateStepItemArray[UpdateStepNum].ReplyFunc;
|
|
|
|
if (replyFunc != null)
|
|
{
|
|
replyStatus = replyFunc(data, len);
|
|
if (replyStatus == UpdateReplyStatus.OK)
|
|
{
|
|
++UpdateStepNum;
|
|
UpdateSendCmdFlag = true;
|
|
}
|
|
else if (replyStatus == UpdateReplyStatus.ContinueSend)
|
|
{
|
|
UpdateSendCmdFlag = true;
|
|
}
|
|
else if (replyStatus == UpdateReplyStatus.NoReply)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|