Exemple #1
0
        public string ReadCharsetVersion()
        {
            EEPROM tempEeprom = new EEPROM();


            bool       fail = false;
            ArduinoSTK sp   = osd.OpenArduino();


            if (sp != null && sp.connectAP())
            {
                try {
                    for (int i = 0; i < 5; i++)   //try to download two times if it fail
                    {
                        byte[] data = sp.download(EEPROM_SIZE);
                        if (!sp.down_flag)
                        {
                            if (sp.keepalive())
                            {
                                Console.WriteLine("keepalive successful (iter " + i + ")");
                            }
                            else
                            {
                                Console.WriteLine("keepalive fail (iter " + i + ")");
                            }
                        }
                        else
                        {
                            eeprom.data = data;
                            break;
                        }
                    }
                } catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("Failed to talk to bootloader");
                fail = true;
            }

            sp.Close();

            if (!fail)
            {
                //lblLatestCharsetUploaded.Text = "Last charset uploaded to OSD: " + tempEeprom[CS_VERSION1_ADDR].ToString() + "." + tempEeprom[CS_VERSION1_ADDR + 1].ToString() + "." + tempEeprom[CS_VERSION1_ADDR + 2].ToString();
                return(tempEeprom.CS_version);
            }
            return("");
        }
Exemple #2
0
        internal bool readEEPROM(int length)
        {
            bool       fail = false;
            ArduinoSTK sp   = osd.OpenArduino();

            byte[] data;

            if (sp != null && sp.connectAP())
            {
                try {
                    for (int i = 0; i < 5; i++)   //try to download two times if it fail
                    {
                        data = sp.download(EEPROM_SIZE);
                        if (sp.down_flag)
                        {
                            eeprom.data = data;
                            break;
                        }
                        else
                        {
                            if (sp.keepalive())
                            {
                                Console.WriteLine("keepalive successful (iter " + i + ")");
                            }
                            else
                            {
                                Console.WriteLine("keepalive fail (iter " + i + ")");
                            }
                        }
                    }
                } catch (Exception ex) {
                    if (ex != null)
                    {
                        MessageBox.Show(ex.Message);
                        fail = true;
                    }
                }
            }
            else
            {
                MessageBox.Show("Failed to talk to bootloader");
                fail = true;
            }

            try {
                sp.Close();
            } catch {};

            return(fail);
        }
Exemple #3
0
        public int writeEEPROM(int start, int length)
        {
            ArduinoSTK sp  = osd.OpenArduino();
            int        err = 0;

            if (sp != null && sp.connectAP())
            {
                try {
                    bool spupload_flag = false;

                    for (int i = 0; i < 10; i++)   //try to upload two times if it fail
                    {
                        spupload_flag = sp.upload(eeprom.data, (short)start, (short)length, (short)start);
                        if (!spupload_flag)
                        {
                            if (sp.keepalive())
                            {
                                Console.WriteLine("keepalive successful (iter " + i + ")");
                            }
                            else
                            {
                                Console.WriteLine("keepalive fail (iter " + i + ")");
                            }
                        }
                        else
                        {
                            break;
                        }

                        if (!spupload_flag)
                        {
                            err = 1;
                        }
                    }
                } catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                    err = -1;
                }
            }
            else
            {
                MessageBox.Show("Failed to talk to bootloader");
                err = -1;
            }

            sp.Close();

            return(err);
        }
Exemple #4
0
        public OSD.ModelType GetModelType()
        {
            OSD.ModelType modelType  = OSD.ModelType.Unknown;
            EEPROM        tempEeprom = new EEPROM();

            ArduinoSTK sp = osd.OpenArduino();

            if (sp.connectAP())
            {
                try {
                    for (int i = 0; i < 5; i++)   //try to download two times if it fail
                    {
                        byte[] data = sp.download(EEPROM_SIZE);
                        if (!sp.down_flag)
                        {
                            if (sp.keepalive())
                            {
                                Console.WriteLine("keepalive successful (iter " + i + ")");
                            }
                            else
                            {
                                Console.WriteLine("keepalive fail (iter " + i + ")");
                            }
                        }
                        else
                        {
                            tempEeprom.data = data;
                            break;
                        }
                    }
                    modelType = (OSD.ModelType)tempEeprom.sets.model_type;
                } catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("Failed to talk to bootloader");
            }

            sp.Close();

            //Setup configuration panel
            return(modelType);
        }
        private void BUT_copy1280_Click(object sender, EventArgs e)
        {
            ArduinoSTK port = new ArduinoSTK();
            port.BaudRate = 57600;
            port.DataBits = 8;
            port.StopBits = StopBits.One;
            port.Parity = Parity.None;
            port.DtrEnable = true;

            try
            {
                port.PortName = ArdupilotMega.MainV2.comPortName;

                log.Info("Open Port");
                port.Open();
                log.Info("Connect AP");
                if (port.connectAP())
                {
                    log.Info("Download AP");
                    byte[] EEPROM = new byte[1024 * 4];

                    for (int a = 0; a < 4 * 1024; a += 0x100)
                    {
                        port.setaddress(a);
                        port.download(0x100).CopyTo(EEPROM, a);
                    }
                    log.Info("Verify State");
                    if (port.keepalive())
                    {
                        StreamWriter sw = new StreamWriter(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"EEPROM1280.bin");
                        BinaryWriter bw = new BinaryWriter(sw.BaseStream);
                        bw.Write(EEPROM, 0, EEPROM.Length);
                        bw.Close();

                        log.Info("Download AP");
                        byte[] FLASH = new byte[1024 * 128];

                        for (int a = 0; a < FLASH.Length; a += 0x100)
                        {
                            port.setaddress(a);
                            port.downloadflash(0x100).CopyTo(FLASH, a);
                        }

                        sw = new StreamWriter(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"FLASH1280.bin");
                        bw = new BinaryWriter(sw.BaseStream);
                        bw.Write(FLASH, 0, FLASH.Length);
                        bw.Close();

                    }
                    else
                    {
                        CustomMessageBox.Show("Communication Error - Bad data");
                    }
                }
                else
                {
                    CustomMessageBox.Show("Communication Error - no connection");
                }
                port.Close();
            }
            catch (Exception ex) { CustomMessageBox.Show("Port Error? " + ex.ToString()); if (port != null && port.IsOpen) { port.Close(); } }
        }
Exemple #6
0
        public bool WriteCharsetVersion(string version, bool showMsg = true)
        {
            //			byte[] tempEeprom = new byte[3];
            //			tempEeprom[0] = (byte)version[0];
            //			tempEeprom[1] = (byte)version[1];
            //			tempEeprom[2] = (byte)version[2];

            EEPROM tempEeprom = new EEPROM();

            ArduinoSTK sp = osd.OpenArduino();

            if (sp != null && sp.connectAP())
            {
                // Сначала считать
                try {
                    for (int i = 0; i < 5; i++)   //try to download two times if it fail
                    {
                        byte[] data = sp.download(EEPROM_SIZE);
                        if (sp.down_flag)
                        {
                            tempEeprom.data = data;
                            break;
                        }
                        else
                        {
                            if (sp.keepalive())
                            {
                                Console.WriteLine("keepalive successful (iter " + i + ")");
                            }
                            else
                            {
                                Console.WriteLine("keepalive fail (iter " + i + ")");
                            }
                        }
                    }
                } catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                    return(false);
                }

                tempEeprom.CS_version = version;

                try {
                    bool spupload_flag = false;
                    for (int i = 0; i < 10; i++)   //try to upload two times if it fail
                    //						spupload_flag = sp.upload(tempEeprom, (short)0, (short)tempEeprom.Length, (short)CS_VERSION1_ADDR);
                    {
                        spupload_flag = sp.upload(tempEeprom.data, (short)Settings_offset, (short)Settings_size, (short)Settings_offset);
                        if (!spupload_flag)
                        {
                            if (sp.keepalive())
                            {
                                Console.WriteLine("keepalive successful (iter " + i + ")");
                            }
                            else
                            {
                                Console.WriteLine("keepalive fail (iter " + i + ")");
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (spupload_flag)
                    {
                        if (showMsg)
                        {
                            MessageBox.Show("Done writing configuration data!");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Failed to upload new configuration data");
                    }
                } catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("Failed to talk to bootloader");
            }

            sp.Close();
            return(true);
        }
Exemple #7
0
        private void BUT_copy1280_Click(object sender, EventArgs e)
        {
            ArduinoSTK port = new ArduinoSTK();

            port.BaudRate  = 57600;
            port.DataBits  = 8;
            port.StopBits  = StopBits.One;
            port.Parity    = Parity.None;
            port.DtrEnable = true;

            try
            {
                port.PortName = MissionPlanner.MainV2.comPortName;

                log.Info("Open Port");
                port.Open();
                log.Info("Connect AP");
                if (port.connectAP())
                {
                    log.Info("Download AP");
                    byte[] EEPROM = new byte[1024 * 4];

                    for (int a = 0; a < 4 * 1024; a += 0x100)
                    {
                        port.setaddress(a);
                        port.download(0x100).CopyTo(EEPROM, a);
                    }
                    log.Info("Verify State");
                    if (port.keepalive())
                    {
                        StreamWriter sw = new StreamWriter(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"EEPROM1280.bin");
                        BinaryWriter bw = new BinaryWriter(sw.BaseStream);
                        bw.Write(EEPROM, 0, EEPROM.Length);
                        bw.Close();

                        log.Info("Download AP");
                        byte[] FLASH = new byte[1024 * 128];

                        for (int a = 0; a < FLASH.Length; a += 0x100)
                        {
                            port.setaddress(a);
                            port.downloadflash(0x100).CopyTo(FLASH, a);
                        }

                        sw = new StreamWriter(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"FLASH1280.bin");
                        bw = new BinaryWriter(sw.BaseStream);
                        bw.Write(FLASH, 0, FLASH.Length);
                        bw.Close();
                    }
                    else
                    {
                        CustomMessageBox.Show("Communication Error - Bad data");
                    }
                }
                else
                {
                    CustomMessageBox.Show("Communication Error - no connection");
                }
                port.Close();
            }
            catch (Exception ex) { CustomMessageBox.Show("Port Error? " + ex.ToString()); if (port != null && port.IsOpen)
                                   {
                                       port.Close();
                                   }
            }
        }