Exemple #1
0
        private void BUT_copyto1280_Click(object sender, EventArgs e)
        {
            IArduinoComms port = new ArduinoSTK();

            port.BaudRate = 57600;

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

            StreamReader sr = new StreamReader(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"EEPROM1280.bin");
            BinaryReader br = new BinaryReader(sr.BaseStream);

            byte[] EEPROM = br.ReadBytes(1024 * 4);
            br.Close();
            sr.Close();

            sr = new StreamReader(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"FLASH1280.bin");
            br = new BinaryReader(sr.BaseStream);
            byte[] FLASH = br.ReadBytes(1024 * 128);
            br.Close();
            sr.Close();

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

                port.Open();



                if (port.connectAP())
                {
                    log.Info("starting");


                    port.uploadflash(FLASH, 0, FLASH.Length, 0);

                    port.upload(EEPROM, 0, (short)EEPROM.Length, 0);


                    log.Info("Uploaded");
                }
                else
                {
                    CustomMessageBox.Show("Communication Error - no connection");
                }
                port.Close();
            }
            catch (Exception ex) { CustomMessageBox.Show("Check port settings or Port in use? " + ex.ToString()); port.Close(); }
        }
Exemple #2
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 #3
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 #4
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 #5
0
        private void resetBoardSettingsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ArduinoSTK sp;

            try
            {
                if (comPort.IsOpen)
                {
                    comPort.Close();
                }

                sp           = new ArduinoSTK();
                sp.PortName  = CMB_ComPort.Text;
                sp.BaudRate  = 57600;
                sp.DtrEnable = true;

                sp.Open();
            }
            catch { MessageBox.Show("Error opening com port", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }

            eeprom = new byte[eeprom.Length];

            if (sp.connectAP())
            {
                try
                {
                    if (sp.upload(eeprom, 0, 1024, 0))
                    {
                        MessageBox.Show("Done!");
                    }
                    else
                    {
                        MessageBox.Show("Failed to upload new settings");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("Failed to talk to bootloader");
            }

            sp.Close();
        }
Exemple #6
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_copyto1280_Click(object sender, EventArgs e)
        {
            ArduinoComms port = new ArduinoSTK();

            port.BaudRate = 57600;

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

            StreamReader sr = new StreamReader(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"EEPROM1280.bin");
            BinaryReader br = new BinaryReader(sr.BaseStream);
            byte[] EEPROM = br.ReadBytes(1024 * 4);
            br.Close();
            sr.Close();

            sr = new StreamReader(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"FLASH1280.bin");
            br = new BinaryReader(sr.BaseStream);
            byte[] FLASH = br.ReadBytes(1024 * 128);
            br.Close();
            sr.Close();

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

                port.Open();

                if (port.connectAP())
                {
                    log.Info("starting");

                    port.uploadflash(FLASH, 0, FLASH.Length, 0);

                    port.upload(EEPROM, 0, (short)EEPROM.Length, 0);

                    log.Info("Uploaded");

                }
                else
                {

                    CustomMessageBox.Show("Communication Error - no connection");
                }
                port.Close();

            }
            catch (Exception ex) { CustomMessageBox.Show("Check port settings or Port in use? " + ex.ToString()); port.Close(); }
        }
        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 #9
0
        private void BUT_upload_Click(object sender, EventArgs e)
        {
            ArduinoSTK comPort = new ArduinoSTK();

            uploader.Uploader uploader = new uploader.Uploader();

            try
            {
                comPort.PortName = MainV2.comPort.BaseStream.PortName;
                comPort.BaudRate = 115200;

                comPort.Open();

            }
            catch { CustomMessageBox.Show("Invalid ComPort or in use"); return; }

            bool bootloadermode = false;

            try
            {
                uploader_ProgressEvent(0);
                uploader_LogEvent("Trying Bootloader Mode");
                uploader.port = comPort;
                uploader.connect_and_sync();

                uploader.ProgressEvent += new ProgressEventHandler(uploader_ProgressEvent);
                uploader.LogEvent += new LogEventHandler(uploader_LogEvent);

                uploader_LogEvent("In Bootloader Mode");
                bootloadermode = true;
            }
            catch
            {
                comPort.Close();
                comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate;
                comPort.Open();

                uploader.ProgressEvent += new ProgressEventHandler(uploader_ProgressEvent);
                uploader.LogEvent += new LogEventHandler(uploader_LogEvent);

                uploader_LogEvent("Trying Firmware Mode");
                bootloadermode = false;
            }

            if (bootloadermode || doConnect(comPort))
            {
                if (getFirmware())
                {
                    uploader.IHex iHex = new uploader.IHex();

                    iHex.LogEvent += new LogEventHandler(iHex_LogEvent);

                    iHex.ProgressEvent += new ProgressEventHandler(iHex_ProgressEvent);

                    try
                    {
                        iHex.load(firmwarefile);
                    }
                    catch { CustomMessageBox.Show("Bad Firmware File"); goto exit; }

                    if (!bootloadermode)
                    {
                        try
                        {
                            comPort.Write("AT&UPDATE\r\n");
                            string left = comPort.ReadExisting();
                            Console.WriteLine(left);
                            Sleep(700);
                            comPort.BaudRate = 115200;
                        }
                        catch { }
                    }

                    try
                    {
                        uploader.upload(comPort, iHex);
                    }
                    catch (Exception ex) { CustomMessageBox.Show("Upload Failed " + ex.Message); }
                }
                else
                {
                    CustomMessageBox.Show("Failed to download new firmware");
                }
            }
            else
            {
                CustomMessageBox.Show("Failed to identify Radio");
            }

            exit:
            if (comPort.IsOpen)
                comPort.Close();
        }
Exemple #10
0
        private void BUT_upload_Click(object sender, EventArgs e)
        {
            ArduinoSTK comPort = new ArduinoSTK();

            uploader.Uploader uploader = new uploader.Uploader();

            try
            {
                comPort.PortName = MainV2.comPort.BaseStream.PortName;
                comPort.BaudRate = 115200;

                comPort.Open();

            }
            catch { CustomMessageBox.Show("Invalid ComPort or in use"); return; }

            bool bootloadermode = false;

            // attempt bootloader mode
            try
            {
                uploader_ProgressEvent(0);
                uploader_LogEvent("Trying Bootloader Mode");
                uploader.port = comPort;
                uploader.connect_and_sync();

                uploader.ProgressEvent += new ProgressEventHandler(uploader_ProgressEvent);
                uploader.LogEvent += new LogEventHandler(uploader_LogEvent);

                uploader_LogEvent("In Bootloader Mode");
                bootloadermode = true;
            }
            catch
            {
                // cleanup bootloader mode fail, and try firmware mode
                comPort.Close();
                comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate;
                comPort.Open();

                uploader.ProgressEvent += new ProgressEventHandler(uploader_ProgressEvent);
                uploader.LogEvent += new LogEventHandler(uploader_LogEvent);

                uploader_LogEvent("Trying Firmware Mode");
                bootloadermode = false;
            }

            // check for either already bootloadermode, or if we can do a ATI to ID the firmware
            if (bootloadermode || doConnect(comPort))
            {

                uploader.IHex iHex = new uploader.IHex();

                iHex.LogEvent += new LogEventHandler(iHex_LogEvent);

                iHex.ProgressEvent += new ProgressEventHandler(iHex_ProgressEvent);

                // put into bootloader mode/udpate mode
                if (!bootloadermode)
                {
                    try
                    {
                        comPort.Write("AT&UPDATE\r\n");
                        string left = comPort.ReadExisting();
                        log.Info(left);
                        Sleep(700);
                        comPort.BaudRate = 115200;
                    }
                    catch { }
                }

                global::uploader.Uploader.Code device = global::uploader.Uploader.Code.FAILED;
                global::uploader.Uploader.Code freq = global::uploader.Uploader.Code.FAILED;

                // get the device type and frequency in the bootloader
                uploader.getDevice(ref device, ref freq);

                // get firmware for this device
                if (getFirmware(device))
                {
                    // load the hex
                    try
                    {
                        iHex.load(firmwarefile);
                    }
                    catch { CustomMessageBox.Show("Bad Firmware File"); goto exit; }

                    // upload the hex and verify
                    try
                    {
                        uploader.upload(comPort, iHex);
                    }
                    catch (Exception ex) { CustomMessageBox.Show("Upload Failed " + ex.Message); }

                }
                else
                {
                    CustomMessageBox.Show("Failed to download new firmware");
                }

            }
            else
            {
                CustomMessageBox.Show("Failed to identify Radio");
            }

            exit:
            if (comPort.IsOpen)
                comPort.Close();
        }
Exemple #11
0
        private void UploadFW(bool custom = false)
        {
            ArduinoSTK comPort = new ArduinoSTK();

            uploader.Uploader uploader = new uploader.Uploader();

            try
            {
                comPort.PortName = MainV2.comPort.BaseStream.PortName;
                comPort.BaudRate = 115200;

                comPort.Open();
            }
            catch { CustomMessageBox.Show("Invalid ComPort or in use"); return; }

            bool bootloadermode = false;

            // attempt bootloader mode
            try
            {
                uploader_ProgressEvent(0);
                uploader_LogEvent("Trying Bootloader Mode");
                uploader.port = comPort;
                uploader.connect_and_sync();

                uploader.ProgressEvent += new ProgressEventHandler(uploader_ProgressEvent);
                uploader.LogEvent      += new LogEventHandler(uploader_LogEvent);

                uploader_LogEvent("In Bootloader Mode");
                bootloadermode = true;
            }
            catch
            {
                // cleanup bootloader mode fail, and try firmware mode
                comPort.Close();
                comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate;
                try
                {
                    comPort.Open();
                }
                catch { CustomMessageBox.Show("Error opening port", "error"); return; }

                uploader.ProgressEvent += new ProgressEventHandler(uploader_ProgressEvent);
                uploader.LogEvent      += new LogEventHandler(uploader_LogEvent);

                uploader_LogEvent("Trying Firmware Mode");
                bootloadermode = false;
            }

            // check for either already bootloadermode, or if we can do a ATI to ID the firmware
            if (bootloadermode || doConnect(comPort))
            {
                uploader.IHex iHex = new uploader.IHex();

                iHex.LogEvent += new LogEventHandler(iHex_LogEvent);

                iHex.ProgressEvent += new ProgressEventHandler(iHex_ProgressEvent);

                // put into bootloader mode/udpate mode
                if (!bootloadermode)
                {
                    try
                    {
                        comPort.Write("AT&UPDATE\r\n");
                        string left = comPort.ReadExisting();
                        log.Info(left);
                        Sleep(700);
                        comPort.BaudRate = 115200;
                    }
                    catch { }
                }

                global::uploader.Uploader.Board     device = global::uploader.Uploader.Board.FAILED;
                global::uploader.Uploader.Frequency freq   = global::uploader.Uploader.Frequency.FAILED;

                // get the device type and frequency in the bootloader
                uploader.getDevice(ref device, ref freq);

                // get firmware for this device
                if (getFirmware(device, custom))
                {
                    // load the hex
                    try
                    {
                        iHex.load(firmwarefile);
                    }
                    catch { CustomMessageBox.Show("Bad Firmware File"); goto exit; }

                    // upload the hex and verify
                    try
                    {
                        uploader.upload(comPort, iHex);
                    }
                    catch (Exception ex) { CustomMessageBox.Show("Upload Failed " + ex.Message); }
                }
                else
                {
                    CustomMessageBox.Show("Failed to download new firmware");
                }
            }
            else
            {
                CustomMessageBox.Show("Failed to identify Radio");
            }

exit:
            if (comPort.IsOpen)
            {
                comPort.Close();
            }
        }
Exemple #12
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 #13
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();
                                   }
            }
        }
Exemple #14
0
        private void BUT_ReadIOB_Click(object sender, EventArgs e)
        {
            toolStripProgressBar1.Style     = ProgressBarStyle.Continuous;
            this.toolStripStatusLabel1.Text = "";

            bool       fail = false;
            ArduinoSTK sp;

            try
            {
                if (comPort.IsOpen)
                {
                    comPort.Close();
                }

                sp           = new ArduinoSTK();
                sp.PortName  = CMB_ComPort.Text;
                sp.BaudRate  = 57600;
                sp.DtrEnable = true;

                sp.Open();
            }
            catch { MessageBox.Show("Error opening com port", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }

            if (sp.connectAP())
            {
                try
                {
                    eeprom = sp.download(1024);
                }
                catch (Exception ex)
                {
                    fail = true;
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("Failed to talk to bootloader");
                fail = true;
            }

            sp.Close();

            int startmbind = 64;

            if (!fail)
            {
                for (int pos = 0; pos < 16; pos++)
                {
                    patterns[pos] = (ushort)((ushort)(eeprom[pos * 2] << 8) + eeprom[pos * 2 + 1]);

                    Control[] ctls = this.Controls.Find("pattern" + (pos + 1), true);
                    if (ctls.Length > 0)
                    {
                        ((Pattern)ctls[0]).Value      = patterns[pos];
                        ((Pattern)ctls[0]).FlightMode = (ushort)(eeprom[startmbind + pos * 2]);
                    }
                }
            }

            printeeprom();

            if (!fail)
            {
                MessageBox.Show("Done!");
            }
        }
Exemple #15
0
        private void updateFirmwareToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStripProgressBar1.Style     = ProgressBarStyle.Continuous;
            this.toolStripStatusLabel1.Text = "";

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "*.hex|*.hex";

            ofd.ShowDialog();

            if (ofd.FileName != "")
            {
                byte[] FLASH;
                try
                {
                    toolStripStatusLabel1.Text = "Reading Hex File";

                    statusStrip1.Refresh();

                    FLASH = readIntelHEXv2(new StreamReader(ofd.FileName));
                }
                catch { MessageBox.Show("Bad Hex File"); return; }

                bool       fail = false;
                ArduinoSTK sp;

                try
                {
                    if (comPort.IsOpen)
                    {
                        comPort.Close();
                    }

                    sp           = new ArduinoSTK();
                    sp.PortName  = CMB_ComPort.Text;
                    sp.BaudRate  = 57600;
                    sp.DtrEnable = true;

                    sp.Open();
                }
                catch { MessageBox.Show("Error opening com port", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }

                toolStripStatusLabel1.Text = "Connecting to Board";

                if (sp.connectAP())
                {
                    sp.Progress += new ArduinoSTK.ProgressEventHandler(sp_Progress);
                    try
                    {
                        if (!sp.uploadflash(FLASH, 0, FLASH.Length, 0))
                        {
                            if (sp.IsOpen)
                            {
                                sp.Close();
                            }

                            MessageBox.Show("Upload failed. Lost sync. Try using Arduino to upload instead",
                                            "Error",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Warning);
                        }
                    }
                    catch (Exception ex)
                    {
                        fail = true;
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Failed to talk to bootloader");
                }

                sp.Close();

                if (!fail)
                {
                    toolStripStatusLabel1.Text = "Done";

                    MessageBox.Show("Done!");
                }
                else
                {
                    toolStripStatusLabel1.Text = "Failed";
                }
            }
        }
Exemple #16
0
        private void BUT_WriteIOB_Click(object sender, EventArgs e)
        {
            toolStripProgressBar1.Style     = ProgressBarStyle.Continuous;
            this.toolStripStatusLabel1.Text = "";

            foreach (Control ctl in tabPage2.Controls)
            {
                if (ctl.GetType() == typeof(Pattern))
                {
                    Pattern pat = ctl as Pattern;

                    int no = 0;

                    if (int.TryParse(pat.Name.Substring(pat.Name.Length - 2), out no))
                    {
                        eeprom[(no - 1) * 2]     = (byte)(pat.Value >> 8);
                        eeprom[(no - 1) * 2 + 1] = (byte)(pat.Value & 0xff);

                        eeprom[64 + (no - 1) * 2]     = (byte)pat.FlightMode;
                        eeprom[64 + (no - 1) * 2 + 1] = (byte)pat.FlightMode;
                    }
                    else if (int.TryParse(pat.Name.Substring(pat.Name.Length - 1), out no))
                    {
                        eeprom[(no - 1) * 2]     = (byte)(pat.Value >> 8);
                        eeprom[(no - 1) * 2 + 1] = (byte)(pat.Value & 0xff);

                        eeprom[64 + (no - 1) * 2]     = (byte)pat.FlightMode;
                        eeprom[64 + (no - 1) * 2 + 1] = (byte)pat.FlightMode;
                    }
                }
            }

            printeeprom();

            ArduinoSTK sp;

            try
            {
                if (comPort.IsOpen)
                {
                    comPort.Close();
                }

                sp           = new ArduinoSTK();
                sp.PortName  = CMB_ComPort.Text;
                sp.BaudRate  = 57600;
                sp.DtrEnable = true;

                sp.Open();
            }
            catch { MessageBox.Show("Error opening com port", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }

            if (sp.connectAP())
            {
                try
                {
                    if (sp.upload(eeprom, 0, 126, 0))
                    {
                        MessageBox.Show("Done!");
                    }
                    else
                    {
                        MessageBox.Show("Failed to upload new settings");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("Failed to talk to bootloader");
            }

            sp.Close();
        }