コード例 #1
0
        public void UpdateFirmware(string FileName, InFieldUpdate.Types Tipe)
        {
            FileInfo info = new FileInfo(CurrentPath + FileName);

            if (!info.Exists)
            {
                PrintLine("File not found, type it correctly.");
                return;
            }
            PrintLine("update in progress, please wait a moment..");
            CallPrintEvent(Screen);
            switch (Tipe)
            {
            case InFieldUpdate.Types.Application:
                InFieldUpdate.Initialize(InFieldUpdate.Types.Application);
                LoadFile(info.FullName, InFieldUpdate.Types.Application);
                break;

            case InFieldUpdate.Types.Configuration:
                InFieldUpdate.Initialize(InFieldUpdate.Types.Configuration);
                LoadFile(info.FullName, InFieldUpdate.Types.Configuration);
                break;

            case InFieldUpdate.Types.Firmware:
                InFieldUpdate.Initialize(InFieldUpdate.Types.Firmware);
                LoadFile(info.FullName, InFieldUpdate.Types.Firmware);
                break;
            }
            InFieldUpdate.FlashAndReset();
        }
コード例 #2
0
        public static void LoadFile(string filename, InFieldUpdate.Types type)
        {
            using (var stream = new FileStream(filename, FileMode.Open))
            {
                var data = new byte[BLOCK_SIZE];

                for (int i = 0; i < stream.Length / BLOCK_SIZE; i++)
                {
                    stream.Read(data, 0, BLOCK_SIZE);
                    InFieldUpdate.Load(type, data, BLOCK_SIZE);
                }

                stream.Read(data, 0, (int)stream.Length % BLOCK_SIZE);
                InFieldUpdate.Load(type, data, (int)stream.Length % BLOCK_SIZE);
            }
        }
コード例 #3
0
        public static void FlashFirmware()
        {
            // Reserve the memory needed to buffer the update.
            // A lot of RAM is needed so it is recommended to do this at the program start.
            InFieldUpdate.Initialize(InFieldUpdate.Types.Application);

            // Start loading the new firmware on the RAM reserved in last step.
            // Nothing is written to FLASH In this stage. Power loss and failures are okay
            // Simply abort this stage any way you like!
            // Files can come from Storage, from network, from serial bus and any Other way.
            LoadFile("\\SD\\IFU\\aplikasi1.hex", InFieldUpdate.Types.Application);

            //LoadFile("\\SD\\Config.hex", InFieldUpdate.Types.Configuration);
            //LoadFile("\\SD\\Firmware.hex", InFieldUpdate.Types.Firmware);
            //LoadFile("\\SD\\Firmware2.hex", InFieldUpdate.Types.Firmware); //Only if your device has two firmware files.

            // This method will copy The new firmware from RAM to FLASH.
            // This function will not return But will reset the system when done.
            // Power loss during Before this function resets the system quill result in a corrupted firmware.
            // A manual update will be needed if this method failed, due to power loss for example.
            InFieldUpdate.FlashAndReset();
        }