예제 #1
0
        public void currentChecksum(Firmware fw)
        {
            if (self.bl_rev < 3)
            {
                return;
            }

            __sync();

            this.port.ReadTimeout = 1000; // 1 sec

            if (self.fw_maxsize > 0)
            {
                int expect_crc = fw.crc(self.fw_maxsize);
                __send(new byte[] { (byte)Code.GET_CRC,
                                    (byte)Code.EOC });
                int report_crc = __recv_int();
                self.__getSync();

                print("FW File 0x" + hexlify(BitConverter.GetBytes(expect_crc)) + " " + expect_crc);
                print("Current 0x" + hexlify(BitConverter.GetBytes(report_crc)) + " " + report_crc);

                if (expect_crc == report_crc)
                {
                    throw new Exception("Same Firmware. Not uploading");
                }
            }

            if (self.extf_maxsize > 0)
            {
                int expect_crc = fw.extf_crc(fw.extf_image_size);

                byte[] size_bytes = BitConverter.GetBytes(fw.extf_image_size);

                __send(new byte[] { (byte)Code.EXTF_GET_CRC,
                                    size_bytes[0], size_bytes[1], size_bytes[2], size_bytes[3],
                                    (byte)Code.EOC });

                // crc can be slow, give it 10s
                __wait_for_bytes(4, 30);

                int report_crc = __recv_int();
                self.__getSync();

                print("Ext FW File 0x" + hexlify(BitConverter.GetBytes(expect_crc)) + " " + expect_crc);
                print("Current 0x" + hexlify(BitConverter.GetBytes(report_crc)) + " " + report_crc);

                if (expect_crc == report_crc)
                {
                    throw new Exception("Same Firmware. Not uploading");
                }
            }
        }
예제 #2
0
        public void __verify_extf(Firmware fw)
        {
            int expect_crc = fw.extf_crc(fw.extf_image_size);

            byte[] size_bytes = BitConverter.GetBytes(fw.extf_image_size);

            __send(new byte[] { (byte)Code.EXTF_GET_CRC,
                                size_bytes[0], size_bytes[1], size_bytes[2], size_bytes[3],
                                (byte)Code.EOC });

            DateTime deadline = DateTime.Now.AddSeconds(10);

            while (DateTime.Now < deadline)
            {
                port.BaseStream.Flush();
                if (port.BytesToRead >= 4)
                {
                    if (ProgressEvent != null)
                    {
                        ProgressEvent(100);
                    }
                    break;
                }
                if (ProgressEvent != null)
                {
                    TimeSpan ts = new TimeSpan(deadline.Ticks - DateTime.Now.Ticks);
                    ProgressEvent(((10.0 - ts.TotalSeconds) / 10.0) * 100.0);
                }
                Thread.Yield();
            }

            __wait_for_bytes(4, 20);

            int report_crc = __recv_int();

            __getSync();

            print("extf Expected 0x" + hexlify(BitConverter.GetBytes(expect_crc)) + " " + expect_crc);
            print("extf Got      0x" + hexlify(BitConverter.GetBytes(report_crc)) + " " + report_crc);
            if (report_crc != expect_crc)
            {
                throw new Exception("Program extf CRC failed");
            }
        }