Пример #1
0
        private void ReadFirmwareFile(UpdateFile updateFile, bool setVersion)
        {
            if (updateFile.fileName != CurrentLoadedFileName)
            {
                CurrentLoadedFileName      = updateFile.fileName;
                FileBytes                  = File.ReadAllBytes(Path.Combine(FirmwareFilePath, updateFile.fileName));
                DataBytesToSendWithPadding = FileBytes;
                FileLength                 = DataBytesToSendWithPadding.Length;

                Console.WriteLine("Loading {0} with size {1}", updateFile.fileName, FileLength);

                /* prepare padding */
                int byteCountToSend = (int)((FileLength + (updateFile.fillUpto - 1)) & (0xFFFFFFFF - (updateFile.fillUpto - 1)));

                if (byteCountToSend != DataBytesToSendWithPadding.Length)
                {
                    /* create a new padded array */
                    var newBytes = InitializeArray(byteCountToSend, updateFile.paddingByte);
                    Array.Copy(DataBytesToSendWithPadding, 0, newBytes, 0, DataBytesToSendWithPadding.Length);
                    DataBytesToSendWithPadding = newBytes;
                }

                TotalBlocksToSend = (byteCountToSend - 1) / updateFile.blockSize;

                if (setVersion)
                {
                    FirmwareFileVersion = string.Format("{0}.{1}", CurrentFileVHigh, CurrentFileVLow);
                }
            }
        }
Пример #2
0
        private void PrepareCS2FileVersionInfoToSend(UpdateFile updateFile)
        {
            FileBytes = File.ReadAllBytes(Path.Combine(FirmwareFilePath, updateFile.fileName));
            var versionInfoString = GetCurrentCS2FileVersionInfo(FileBytes.Length);

            DataBytesToSendWithPadding = Encoding.ASCII.GetBytes(versionInfoString);
            FileLength = DataBytesToSendWithPadding.Length;

            Console.WriteLine("Loading data with size {0}", FileLength);

            /* prepare padding */
            int byteCountToSend = (int)((FileLength + (8 - 1)) & (0xFFFFFFFF - (8 - 1)));

            if (byteCountToSend != DataBytesToSendWithPadding.Length)
            {
                /* create a new padded array */
                var newBytes = InitializeArray(byteCountToSend, 0x00);
                Array.Copy(DataBytesToSendWithPadding, 0, newBytes, 0, DataBytesToSendWithPadding.Length);
                DataBytesToSendWithPadding = newBytes;
            }

            TotalBlocksToSend = (byteCountToSend - 1) / updateFile.blockSize;
        }