예제 #1
0
 /// <summary>
 /// 防滑分析设置界面用户输入完成之后点击“设置完成”按钮产生的事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Confirm_Button_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         canHelper = new CanHelper();
         //set_bit(Byte_0x91[0], 1, true);
         Byte_0x91[0] = 0x01;
         SaveValue();
         for (int i = 0; i < 10; i++)
         {
             canHelper.Send_0x91(Byte_0x91);
             canHelper.Send_0x92(Byte_0x92);
             canHelper.Send_0x93(Byte_0x93);
             canHelper.Send_0x94(Byte_0x94);
         }
         bSend = true;
     }
     catch (Exception)
     {
         MessageBox.Show("数据发送失败!");
         bSend = false;
     }
     if (bSend == true)
     {
         MessageBox.Show("数据发送成功!");
     }
 }
 /// <summary>
 /// 发送逻辑
 /// </summary>
 private void Send()
 {
     canHelper = new CanHelper();
     for (int i = 0; i < transData.Count; i++)
     {
         canHelper.Send(transData[i]);
     }
 }
예제 #3
0
파일: Program.cs 프로젝트: ww4u/MRQUpdate
        // 主函数需要指定文件路径、MRH地址、设备的RecieveID
        //! filePath ip_desc receiveId
        static void Main(string[] args)
        {
            // 参数为空
            if (args == null || args.Length != 3)
            {
                Console.WriteLine("error:you need input three params!");
                return;
            }
            FilePath  = args[0];
            Ip        = args[1];
            RecieveId = Convert.ToUInt32(args[2]);
            //FilePath = C:\\Users\\DINGJIANWEI\\Desktop\\Sinanju Update\\MRQMV(Software)Update(Normal)_00.00.02.00.03.upd;
            //Ip = TCPIP0::169.254.1.2::inst0::INSTR;
            //RecieveId = 384;
            // 搜索-T
            Comm = new Communication("MRH-T");
            if (Comm.OpenCan(Ip) == 0)
            {
                Console.WriteLine("Notify:Open MRH-T Success");
            }
            else
            {
                Console.WriteLine("Notify:Open MRH-T Failed");
                return;
            }
            // 切换模式
            string cmd = $"SYSTEM:MODE:SWITCH 0\n";

            CanHelper.VCI_Write(Comm.currentDeviceType, Comm.selectedDeviceIndex, Encoding.Default.GetBytes(cmd),
                                (uint)cmd.Length);
            // 搜索设备
            if (!SearchDevices())
            {
                return;
            }
            // 检查设备类型
            if (!CheckDevices())
            {
                return;
            }
            // 开始升级
            StartUpdate();
        }
예제 #4
0
 private void CanForm_Load(object sender, EventArgs e)
 {
     canHelper = new CanHelper();
     canHelper.ReceviedData += CanHelper_ReceviedData;
 }
예제 #5
0
파일: Program.cs 프로젝트: ww4u/MRQUpdate
        private static bool UpdateFpga1()
        {
            if (fileHeader.Fpga1Len == 0)
            {
                Console.WriteLine("Notify:No FPGA1 !");
                return(true);
            }
            Console.WriteLine("Notify:Prepare to update FPGA1 !");
            if (!restart)
            {
                // 发送升级命令
                SendData(RecieveId, (byte)DriveControllerMainCommand.Update, (byte)UpdateSubCommand.START,
                         null, (byte)UpdateType.APP);
                Thread.Sleep(100);
                // 先重启
                Console.WriteLine("Notify:Prepare to reload !");
                int tryTimes = 0;
                while (tryTimes <= 50)
                {
                    SendData(RecieveId, (byte)DriveControllerMainCommand.Link,
                             (byte)LinkSubCommand.INTFCQuery);
                    Thread.Sleep(100);
                    var result = Comm.ReceiveData((byte)DriveControllerMainCommand.Link,
                                                  (byte)LinkSubCommand.INTFCQuery);
                    if (result.Count != DeviceList.Count)
                    {
                        Thread.Sleep(100);
                    }
                    else
                    {
                        Console.WriteLine("Notify:Reload successfully!");
                        break;
                    }
                    tryTimes++;
                }
                if (tryTimes >= 50)
                {
                    Console.WriteLine("Error:Reload failed!");
                    return(false);
                }
                restart = true;
            }
            int sendCount = 0;
            int preValue  = 0;

            for (int i = 0; i < fileHeader.Fpga1BlockCount; i++)
            {
                BlockHeader header = new BlockHeader();
                header.HeaderLen = BReader.ReadUInt32();
                header.Index     = BReader.ReadUInt32();
                header.Len       = BReader.ReadUInt32();
                byte[] blockHash = new byte[16];
                for (int j = 0; j < blockHash.Length; j++)
                {
                    blockHash[j] = BReader.ReadByte();
                }
                header.BlockHash = blockHash;
                if (header.Len > 0)
                {
                    var buffer    = BReader.ReadBytes((int)header.Len);
                    MD5 md5       = new MD5CryptoServiceProvider();
                    var hashBytes = md5.ComputeHash(buffer.ToArray());
                    if (hashBytes.Where((t, k) => t != header.BlockHash[k]).Any())
                    {
                        Console.WriteLine("Error:FPGA1 file has validation error, file may be corrupted,Stop updating!");
                        return(false);
                    }
                    if (i == 0)
                    {
                        var addr = fileHeader.Fpga1Addr;
                        SendData(RecieveId, (byte)DriveControllerMainCommand.Update,
                                 (byte)UpdateSubCommand.FPGAADDR,
                                 BitConverter.GetBytes(addr));
                        Thread.Sleep(10);
                        // 发送升级命令
                        SendData(RecieveId, (byte)DriveControllerMainCommand.Update, (byte)UpdateSubCommand.START,
                                 null, (byte)UpdateType.FPGA);
                        Thread.Sleep(100);
                        CanHelper.VCI_ClearBuffer(Comm.currentDeviceType, Comm.selectedDeviceIndex, 0);
                        Console.WriteLine("Notify:Prepare to erase the FLASH !");
                        byte[] len = BitConverter.GetBytes(768 * 1024);
                        // 擦除fpga命令
                        SendData(RecieveId, (byte)DriveControllerMainCommand.Update, (byte)UpdateSubCommand.ERASE,
                                 len, (byte)UpdateType.FPGA);
                        if (!CheckState(DeviceList, (byte)DriveControllerMainCommand.Update, (byte)UpdateSubCommand.ERASE))
                        {
                            Console.WriteLine("Error:Erase the FLASH failed!");
                            return(false);
                        }
                        // 下发数据
                        Console.WriteLine("Notify:Send FPGA1 data,please wait for a moment...");
                    }
                    for (int j = 0; j < 4; j++)
                    {
                        byte[] param = new byte[4];
                        Array.Copy(header.BlockHash, 4 * j, param, 0, 4);
                        byte index = (byte)(((j + 1) << 4) + 4);
                        // 发送哈希校验
                        SendData(RecieveId, (byte)DriveControllerMainCommand.Update, (byte)UpdateSubCommand.MD5, param, index);
                    }
                    int sendBytes;
                    for (int j = 0; j < (int)header.Len; j += sendBytes)
                    {
                        if (j + MaxLen > header.Len)
                        {
                            sendBytes = (int)header.Len - j;
                        }
                        else
                        {
                            sendBytes = MaxLen;
                        }
                        byte[] sendData = new byte[sendBytes];
                        Array.Copy(buffer, j, sendData, 0, sendBytes);
                        //SendData(RecieveId, (byte)DriveControllerMainCommand.Update, (byte)UpdateSubCommand.DATA,
                        //    sendData);
                        SendData(RecieveId, (byte)DriveControllerMainCommand.Data, sendData);
                        sendCount += sendBytes;
                        var value = (int)(sendCount * 1.0 / fileHeader.Fpga1Len * 100);
                        if (preValue != value)
                        {
                            Console.WriteLine($"Progress:{value}%");
                        }
                        preValue = value;
                    }
                    // 发送完成
                    SendData(RecieveId, (byte)DriveControllerMainCommand.Update, (byte)UpdateSubCommand.END);
                    if (!CheckState(DeviceList, (byte)DriveControllerMainCommand.Update, (byte)UpdateSubCommand.END))
                    {
                        Console.WriteLine("Error:Does not respond");
                        return(false);
                    }
                }
            }
            Console.WriteLine("FPGA1 data download completed !");
            return(true);
        }
예제 #6
0
파일: Program.cs 프로젝트: ww4u/MRQUpdate
        private static bool UpdateBoot(List <DeviceInfo> list)
        {
            BlockHeader blockHeader = new BlockHeader
            {
                HeaderLen = BReader.ReadUInt32(),
                Index     = BReader.ReadUInt32(),
                Len       = BReader.ReadUInt32()
            };
            var tempHash = new byte[16];

            for (int i = 0; i < tempHash.Length; i++)
            {
                tempHash[i] = BReader.ReadByte();
            }
            blockHeader.BlockHash = tempHash;
            if (blockHeader.Len > 0)
            {
                var buff      = BReader.ReadBytes((int)blockHeader.Len);
                MD5 md5       = new MD5CryptoServiceProvider();
                var hashBytes = md5.ComputeHash(buff.ToArray());
                if (hashBytes.Where((t, i) => t != fileHeader.BootBlockHash[i]).Any())
                {
                    Console.WriteLine("Error:ARM file has validation error, file may be corrupted,Stop updating!");
                    return(false);
                }
                ;
                // 发送升级命令
                SendData(RecieveId, (byte)DriveControllerMainCommand.Update, (byte)UpdateSubCommand.START,
                         null, (byte)UpdateType.BOOT);
                if (!CheckState(list, (byte)DriveControllerMainCommand.Update, (byte)UpdateSubCommand.START))
                {
                    return(false);
                }
                byte[] len = BitConverter.GetBytes(32 * 1024);
                // 擦除BOOT命令
                SendData(RecieveId, (byte)DriveControllerMainCommand.Update, (byte)UpdateSubCommand.ERASE,
                         len, (byte)UpdateType.BOOT);
                if (!CheckState(list, (byte)DriveControllerMainCommand.Update, (byte)UpdateSubCommand.ERASE))
                {
                    return(false);
                }
                // 下发数据
                Console.WriteLine("Notify:Send BOOT data,please wait for a moment...");
                for (int j = 0; j < 4; j++)
                {
                    byte[] param = new byte[4];
                    Array.Copy(blockHeader.BlockHash, 4 * j, param, 0, 4);
                    byte index = (byte)(((j + 1) << 4) + 4);
                    // 发送哈希校验
                    SendData(RecieveId, (byte)DriveControllerMainCommand.Update, (byte)UpdateSubCommand.MD5,
                             param, index);
                }
                Thread.Sleep(10);
                int sendBytes;
                int sendCount = 0;
                int preValue  = 0;
                int tempCount = 0;
                for (int i = 0; i < (int)blockHeader.Len; i += sendBytes)
                {
                    if (i + bootMaxLen > blockHeader.Len)
                    {
                        sendBytes = (int)blockHeader.Len - i;
                    }
                    else
                    {
                        sendBytes = bootMaxLen;
                    }
                    byte[] sendData = new byte[sendBytes];
                    Array.Copy(buff, i, sendData, 0, sendBytes);
                    SendData(RecieveId, (byte)DriveControllerMainCommand.Update, (byte)UpdateSubCommand.DATA,
                             sendData);
                    sendCount += sendBytes;
                    tempCount += sendBytes;
                    var value = (int)(sendCount * 1.0 / fileHeader.BootLen * 100);
                    if (preValue != value)
                    {
                        Console.WriteLine($"Progress:{value}%");
                    }
                    preValue = value;
                    if (tempCount >= 2048)
                    {
                        Thread.Sleep(100);
                        tempCount -= 2048;
                    }
                }
                Thread.Sleep(100);
                CanHelper.VCI_ClearBuffer(Comm.currentDeviceType, Comm.selectedDeviceIndex, 0);
                Thread.Sleep(100);
                SendData(RecieveId, (byte)DriveControllerMainCommand.Update, (byte)UpdateSubCommand.END);
                if (!CheckState(list, (byte)DriveControllerMainCommand.Update, (byte)UpdateSubCommand.END))
                {
                    Console.WriteLine("Error:BOOT data download failed !");
                    return(false);
                }
                // 等待返回
                Console.WriteLine("Notify:BOOT data download complete !");
            }
            else
            {
                Console.WriteLine("Notify:No boot !");
            }
            return(true);
        }
예제 #7
0
파일: Program.cs 프로젝트: ww4u/MRQUpdate
        private static bool CheckVer()
        {
            bool armFlg, fpgaFlg;

            //读取boot版本号
            CanHelper.VCI_ClearBuffer(Comm.currentDeviceType, Comm.selectedDeviceIndex, 0);
            Thread.Sleep(100);
            SendData(RecieveId, (byte)DriveControllerMainCommand.System, (byte)SystemSubCommand.BOOTVERQuery);
            var result = Comm.ReceiveData((byte)DriveControllerMainCommand.System, (byte)SystemSubCommand.BOOTVERQuery);

            if (result.Count == 0 || result.Count != DeviceList.Count)
            {
                Console.WriteLine("Error:Cannot get the BOOT version!");
                return(false);
            }
            int mainVer, subVer, branchVer, childVer1, childVer2, childVer3;

            bootIndex = 3;
            for (int j = 0; j < result.Count; j++)
            {
                mainVer = result[j].Result[2];
                subVer  = result[j].Result[3];
                if (mainVer <= 2)
                {
                    bootIndex = 4;
                    break;
                }
                if (mainVer < fileHeader.BootVersion[0])
                {
                    bootIndex = 3;
                    break;
                }
                if (mainVer > fileHeader.BootVersion[0])
                {
                    bootIndex = 0;
                    break;
                }
                if (subVer > fileHeader.BootVersion[1])
                {
                    bootIndex = 2;
                    break;
                }
                bootIndex = subVer < fileHeader.BootVersion[1] ? 3 : 1;
            }
            //读取Arm版本号
            SendData(RecieveId, (byte)DriveControllerMainCommand.Factory, 2);
            result   = Comm.ReceiveData((byte)DriveControllerMainCommand.Factory, 2);
            armIndex = 3;
            if (result.Count == 0 || result.Count != DeviceList.Count)
            {
                armFlg = false;
            }
            else
            {
                armFlg = true;
                for (int j = 0; j < result.Count; j++)
                {
                    mainVer   = result[j].Result[2];
                    subVer    = result[j].Result[3];
                    branchVer = result[j].Result[4];
                    childVer1 = result[j].Result[5];
                    if (result[j].Result.Length <= 6)
                    {
                        childVer2 = 0;
                    }
                    else
                    {
                        childVer2 = result[j].Result[6];
                    }
                    if (branchVer < fileHeader.ArmVersion[2])
                    {
                        armIndex = 3;
                        break;
                    }
                    if (branchVer > fileHeader.ArmVersion[2])
                    {
                        armIndex = 2;
                        break;
                    }
                    if (childVer1 < fileHeader.ArmVersion[3])
                    {
                        armIndex = 3;
                        break;
                    }
                    if (childVer1 > fileHeader.ArmVersion[3])
                    {
                        armIndex = 2;
                        break;
                    }
                    if (childVer2 < fileHeader.ArmVersion[4])
                    {
                        armIndex = 3;
                        break;
                    }
                    if (childVer2 > fileHeader.ArmVersion[4])
                    {
                        armIndex = 2;
                        break;
                    }
                    if (mainVer != fileHeader.ArmVersion[0])
                    {
                        armIndex = 3;
                        break;
                    }
                    armIndex = 1;
                }
            }
            //读取fpga版本号
            SendData(RecieveId, (byte)DriveControllerMainCommand.System, (byte)SystemSubCommand.FPGAVERQuery);
            result     = Comm.ReceiveData((byte)DriveControllerMainCommand.System, (byte)SystemSubCommand.FPGAVERQuery);
            fpga1Index = 3;
            fpga2Index = 3;
            if (result.Count == 0 || result.Count != DeviceList.Count)
            {
                fpgaFlg = false;
            }
            else
            {
                fpgaFlg = true;
                for (int j = 0; j < result.Count; j++)
                {
                    mainVer   = result[j].Result[2];
                    subVer    = result[j].Result[3];
                    branchVer = result[j].Result[4];
                    childVer1 = result[j].Result[5];
                    childVer2 = result[j].Result[6];
                    childVer3 = result[j].Result[7];
                    if (j % 2 == 0)
                    {
                        if (mainVer != fileHeader.Fpga1Version[0] || subVer != fileHeader.Fpga1Version[1] ||
                            branchVer != fileHeader.Fpga1Version[2] ||
                            childVer1 != fileHeader.Fpga1Version[3] || childVer2 != fileHeader.Fpga1Version[4] ||
                            childVer3 != fileHeader.Fpga1Version[5])
                        {
                            fpga1Index = 0;
                            break;
                        }
                        fpga1Index = 1;
                    }
                    else
                    {
                        if (mainVer != fileHeader.Fpga2Version[0] || subVer != fileHeader.Fpga2Version[1] ||
                            branchVer != fileHeader.Fpga2Version[2] ||
                            childVer1 != fileHeader.Fpga2Version[3] || childVer2 != fileHeader.Fpga2Version[4] ||
                            childVer3 != fileHeader.Fpga2Version[5])
                        {
                            fpga2Index = 0;
                            break;
                        }
                        fpga2Index = 1;
                    }
                }
            }

            if (!armFlg && !fpgaFlg)
            {
                updateType = 1;
            }
            else
            {
                updateType = 0;
            }
            return(true);
        }