Ejemplo n.º 1
0
 /// <summary>
 /// VOBC指令函数
 /// </summary>
 /// <param name="serverIP">产品IP</param>
 /// <param name="serverPort">产品端口</param>
 /// <param name="vobcID">VOBCID</param>
 /// <param name="commandT">VOBC指令类型</param>
 /// <param name="checkFile">VOBC文件校验信息实体</param>
 public VOBCCommand(string serverIP, int serverPort,
                    string vobcID, vobcCommandType commandT, VobcCheckFile checkFile)
 {
     vobcServerIP   = serverIP;
     vobcServerPort = serverPort;
     vobcDevID      = vobcID;
     vobcCommandT   = commandT;
     m_checkFile    = checkFile;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 打包文件校验请求信息
        /// </summary>
        /// <param name="checkFileList">待验证VOBC信息实体类集合</param>
        /// <returns>帧字节数组</returns>
        public static byte[] PackFileVerificationRequest(VobcCheckFile checkFile, VOBCProduct vobc)
        {
            byte[] pData = new byte[111];
            int    iter  = 0;

            pData[iter++] = 0x00;
            pData[iter++] = 0x6D; //帧长度
            pData[iter++] = 0x02; //帧类型码

            //填入各子子系统级校验文件类型码
            pData[iter++] = Convert.ToByte(checkFile.vobcSystemType);                                    //子子系统类型码
            pData[iter++] = Convert.ToByte(checkFile.vobcFileTypeList.Sum(tar => Convert.ToInt32(tar))); //校验文件类型码(多文件类型求和=文件类型码)
            Common.vobcSystemType systemType = checkFile.vobcSystemType;
            switch (systemType)
            {
            case Common.vobcSystemType.ATP_1:
                vobc._atpUpdateFile = Convert.ToByte(checkFile.vobcFileTypeList.Sum(tar => Convert.ToInt32(tar)));
                break;

            case Common.vobcSystemType.ATO_1:
                vobc._atoUpdateFile = Convert.ToByte(checkFile.vobcFileTypeList.Sum(tar => Convert.ToInt32(tar)));
                break;

            case Common.vobcSystemType.COM_1:
                vobc._comUpdateFile = Convert.ToByte(checkFile.vobcFileTypeList.Sum(tar => Convert.ToInt32(tar)));
                break;

            case Common.vobcSystemType.MMI:
                vobc._mmiUpdateFile = Convert.ToByte(checkFile.vobcFileTypeList.Sum(tar => Convert.ToInt32(tar)));
                break;

            case Common.vobcSystemType.CCOV:
                vobc._ccovUpdateFile = Convert.ToByte(checkFile.vobcFileTypeList.Sum(tar => Convert.ToInt32(tar)));
                break;

            default:
                break;
            }
            //MD5有效标志位 默认都重置为无效(0xAA)
            pData[21]  = 0xAA; //内核文件MD5有效标志
            pData[38]  = 0xAA; //数据文件MD5有效标志
            pData[55]  = 0xAA; //配置文件MD5有效标志
            pData[72]  = 0xAA; //引导文件MD5有效标志
            pData[89]  = 0xAA; //CCOV配置文件MD5有效标志
            pData[106] = 0xAA; //预留MD5有效标志

            //针对需要传输的文件,计算MD5值并将MD5写入数据帧
            for (int index = 0; index < checkFile.vobcFileTypeList.Count; index++)
            {
                if (checkFile.vobcFileTypeList[index] != Common.vobcFileType.INVALID)
                {
                    //计算MD5值
                    byte[] md5Value = GetMD5FromFile(checkFile.vobcFilePathList.ElementAt(index).Key);

                    //替换数组的开始索引下标
                    int replaceBeginIndex = -1;

                    //依据传输的文件类型 获取替换数组的索引下标
                    switch (checkFile.vobcFileTypeList[index])
                    {
                    case RemoteDeploy.Common.vobcFileType.CORE:
                        replaceBeginIndex = 5;
                        break;

                    case RemoteDeploy.Common.vobcFileType.DATA:
                        replaceBeginIndex = 22;
                        break;

                    case RemoteDeploy.Common.vobcFileType.NVRAM:
                        replaceBeginIndex = 39;
                        break;

                    case RemoteDeploy.Common.vobcFileType.BootLoader:
                        replaceBeginIndex = 56;
                        break;

                    case RemoteDeploy.Common.vobcFileType.CCOVConfig:
                        replaceBeginIndex = 73;
                        break;

                    default:
                        replaceBeginIndex = -1;
                        break;
                    }
                    string log = string.Empty;
                    log += "文件" + checkFile.vobcFileTypeList[index] + "MD5为:[";
                    foreach (byte item in md5Value)
                    {
                        log += Convert.ToString(item, 16) + " ";
                    }
                    log += "]";
                    LogManager.InfoLog.LogCommunicationInfo("DataPack",
                                                            "PackFileVerificationRequest", log);

                    //追加MD5值
                    ReplaceByteArray(ref pData, replaceBeginIndex, md5Value);

                    //追加MD5有效标志
                    pData[(replaceBeginIndex + md5Value.Length)] = 0x55;
                }
            }

            //跳至CRC起始位
            iter = 107;

            UInt32 crc32 = CRC.CRC32(pData, (ushort)(pData.Length - 4), 0);

            pData[iter++] = BitConverter.GetBytes(crc32)[3];
            pData[iter++] = BitConverter.GetBytes(crc32)[2];
            pData[iter++] = BitConverter.GetBytes(crc32)[1];
            pData[iter]   = BitConverter.GetBytes(crc32)[0];

            return(pData);
            //添加FFFE协议头尾
            //return FFFE.FFFEPack(pData);
        }