Exemplo n.º 1
0
        private void iniFileCovertToHeader(HeaderStruct fileHeader)
        {
            string hts;

            hts = ht["FwVender"].ToString();
            for (int i = 0; i < hts.Length; i++)
            {
                var temp = Encoding.Default.GetBytes(hts);
                fileHeader.FwVender[i] = temp[i];
            }

            hts = ht["Platform"].ToString();
            for (int i = 0; i < hts.Length; i++)
            {
                var temp = Encoding.Default.GetBytes(hts);
                fileHeader.Platform[i] = temp[i];
            }

            hts = ht["DevType"].ToString();
            fileHeader.DevType = (byte)Int16.Parse(hts.Substring(2, 2), NumberStyles.HexNumber);

            hts = ht["MCS_Ver"].ToString();
            for (int i = 0; i < hts.Length; i++)
            {
                var temp = Encoding.Default.GetBytes(hts);
                fileHeader.MCSVer[i] = temp[i];
            }

            hts = ht["BlVer"].ToString();
            for (int i = 0; i < hts.Length; i++)
            {
                var temp = Encoding.Default.GetBytes(hts);
                fileHeader.BootLaoderfwVer[i] = temp[i];
            }

            hts = ht["AppfwVer"].ToString();
            for (int i = 0; i < hts.Length; i++)
            {
                var temp = Encoding.Default.GetBytes(hts);
                fileHeader.AppfwVer[i] = temp[i];
            }

            hts = ht["Start"].ToString();
            for (int i = 0; i < 4; i++)
            {
                fileHeader.InterFlashStart[i] = (byte)Int16.Parse(hts.Substring(2 * (i + 1), 2), NumberStyles.HexNumber);
            }

            hts = ht["End"].ToString();
            for (int i = 0; i < 4; i++)
            {
                fileHeader.InterFlashEnd[i] = (byte)Int16.Parse(hts.Substring(2 * (i + 1), 2), NumberStyles.HexNumber);
            }
        }
Exemplo n.º 2
0
        public int FileHeader_Maker(byte [] buff, HeaderStruct fileHeader)
        {
            int length = 0;

            //FwVender
            for (int i = 0; i < fileHeader.FwVender.Length; i++)
            {
                buff[length++] = fileHeader.FwVender[i];
            }

            //platform
            for (int i = 0; i < fileHeader.Platform.Length; i++)
            {
                buff[length++] = fileHeader.Platform[i];
            }

            //Application firmware version
            for (int i = 0; i < fileHeader.AppfwVer.Length; i++)
            {
                buff[length++] = fileHeader.AppfwVer[i];
            }

            //Bootloader firmware version
            for (int i = 0; i < fileHeader.BootLaoderfwVer.Length; i++)
            {
                buff[length++] = fileHeader.BootLaoderfwVer[i];
            }

            //mcs  version
            for (int i = 0; i < fileHeader.MCSVer.Length; i++)
            {
                buff[length++] = fileHeader.MCSVer[i];
            }

            //Inter flash Filesize
            for (int i = 0; i < fileHeader.InterFileSize.Length; i++)
            {
                buff[length++] = fileHeader.InterFileSize[i];
            }

            //Inter Flash Start
            for (int i = 0; i < fileHeader.InterFlashStart.Length; i++)
            {
                buff[length++] = fileHeader.InterFlashStart[i];
            }

            //Inter Flash End
            for (int i = 0; i < fileHeader.InterFlashEnd.Length; i++)
            {
                buff[length++] = fileHeader.InterFlashEnd[i];
            }

            //Ext Flash filesize
            for (int i = 0; i < fileHeader.ExtentFileSize.Length; i++)
            {
                buff[length++] = fileHeader.ExtentFileSize[i];
            }

            //Ext Flash Start
            for (int i = 0; i < fileHeader.ExtentFlashStart.Length; i++)
            {
                buff[length++] = fileHeader.ExtentFlashStart[i];
            }

            //Ext Flash End
            for (int i = 0; i < fileHeader.ExtentFlashEnd.Length; i++)
            {
                buff[length++] = fileHeader.ExtentFlashEnd[i];
            }

            //Device type
            buff[length++] = fileHeader.DevType;

            //Reserve
            for (int i = 0; i < fileHeader.Reserve.Length; i++)
            {
                buff[length++] = fileHeader.Reserve[i];
            }

            //CRC16
            UInt16 crc = st_crc.CRC16(buff, length);

            fileHeader.CRC16[0] = (byte)(crc >> 8);
            fileHeader.CRC16[1] = (byte)(crc);
            for (int i = 0; i < fileHeader.CRC16.Length; i++)
            {
                buff[length++] = fileHeader.CRC16[i];
            }

            return(length);
        }