Open() public méthode

public Open ( ) : void
Résultat void
        Stream port = null;// File.Open(@"C:\Users\hog\Desktop\gps data\asterx-m", FileMode.Open);

        public AP_GPS_COMNAV()
        {
            var sport = new SerialPort("COM13", 115200);

            sport.Open();

            port = sport.BaseStream;
        }
Exemple #2
0
        private void BUT_savesettings_Click(object sender, EventArgs e)
        {
            ICommsSerial comPort = new SerialPort();

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

                comPort.ReadTimeout = 4000;

                comPort.Open();

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

            lbl_status.Text = "Connecting";

            if (doConnect(comPort))
            {
                // cleanup
                doCommand(comPort, "AT&T");

                comPort.DiscardInBuffer();

                lbl_status.Text = "Doing Command";

                if (RTI.Text != "")
                {

                    // remote
                    string answer = doCommand(comPort, "RTI5");

                    string[] items = answer.Split('\n');

                    foreach (string item in items)
                    {
                        if (item.StartsWith("S"))
                        {
                            string[] values = item.Split(':', '=');

                            if (values.Length == 3)
                            {
                                Control[] controls = this.Controls.Find("R" + values[0].Trim(), true);

                                if (controls.Length > 0)
                                {
                                    if (controls[0].GetType() == typeof(CheckBox))
                                    {
                                        string value = ((CheckBox)controls[0]).Checked ? "1" : "0";

                                        if (value != values[2].Trim())
                                        {
                                            string cmdanswer = doCommand(comPort, "RT" + values[0].Trim() + "=" + value + "\r");

                                            if (cmdanswer.Contains("OK"))
                                            {

                                            }
                                            else
                                            {
                                                CustomMessageBox.Show("Set Command error");
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (controls[0] is TextBox)
                                        {

                                        }
                                        else
                                        {
                                            if (((ComboBox)controls[0]).SelectedValue != null)
                                            {
                                                if (((ComboBox)controls[0]).SelectedValue.ToString() != values[2].Trim())
                                                {
                                                    string cmdanswer = doCommand(comPort, "RT" + values[0].Trim() + "=" + ((ComboBox)controls[0]).SelectedValue + "\r");

                                                    if (cmdanswer.Contains("OK"))
                                                    {

                                                    }
                                                    else
                                                    {
                                                        CustomMessageBox.Show("Set Command error");
                                                    }
                                                }
                                            }
                                            else if (controls[0].Text != values[2].Trim() && controls[0].Text != "")
                                            {
                                                string cmdanswer = doCommand(comPort, "RT" + values[0].Trim() + "=" + controls[0].Text + "\r");

                                                if (cmdanswer.Contains("OK"))
                                                {

                                                }
                                                else
                                                {
                                                    CustomMessageBox.Show("Set Command error");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                // bad ?ti5 line
                            }
                        }
                    }

                    // write it
                    doCommand(comPort, "RT&W");

                    // return to normal mode
                    doCommand(comPort, "RTZ");

                    Sleep(100);
                }

                comPort.DiscardInBuffer();
                {
                    //local
                    string answer = doCommand(comPort, "ATI5");

                    string[] items = answer.Split('\n');

                    foreach (string item in items)
                    {
                        if (item.StartsWith("S"))
                        {
                            string[] values = item.Split(':', '=');

                            if (values.Length == 3)
                            {
                                Control[] controls = this.Controls.Find(values[0].Trim(), true);

                                if (controls.Length > 0)
                                {
                                    if (controls[0].GetType() == typeof(CheckBox))
                                    {
                                        string value = ((CheckBox)controls[0]).Checked ? "1" : "0";

                                        if (value != values[2].Trim())
                                        {
                                            string cmdanswer = doCommand(comPort, "AT" + values[0].Trim() + "=" + value + "\r");

                                            if (cmdanswer.Contains("OK"))
                                            {

                                            }
                                            else
                                            {
                                                CustomMessageBox.Show("Set Command error");
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (controls[0] is TextBox)
                                        {

                                        }
                                        else
                                        {
                                            if (((ComboBox)controls[0]).SelectedValue != null)
                                            {
                                                if (((ComboBox)controls[0]).SelectedValue.ToString() != values[2].Trim())
                                                {
                                                    string cmdanswer = doCommand(comPort, "AT" + values[0].Trim() + "=" + ((ComboBox)controls[0]).SelectedValue + "\r");

                                                    if (cmdanswer.Contains("OK"))
                                                    {

                                                    }
                                                    else
                                                    {
                                                        CustomMessageBox.Show("Set Command error");
                                                    }
                                                }
                                            }
                                            else if (controls[0].Text != values[2].Trim() && controls[0].Text != "")
                                            {
                                                string cmdanswer = doCommand(comPort, "AT" + values[0].Trim() + "=" + controls[0].Text + "\r");

                                                if (cmdanswer.Contains("OK"))
                                                {

                                                }
                                                else
                                                {
                                                    CustomMessageBox.Show("Set Command error");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // write it
                    doCommand(comPort, "AT&W");

                    // return to normal mode
                    doCommand(comPort, "ATZ");
                }

                lbl_status.Text = "Done";
            }
            else
            {

                // return to normal mode
                doCommand(comPort, "ATZ");

                lbl_status.Text = "Fail";
                CustomMessageBox.Show("Failed to enter command mode");
            }

            comPort.Close();
        }
Exemple #3
0
        private void BUT_resettodefault_Click(object sender, EventArgs e)
        {
            ICommsSerial comPort = new SerialPort();

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

                comPort.ReadTimeout = 4000;

                comPort.Open();

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

            lbl_status.Text = "Connecting";

            if (doConnect(comPort))
            {
                // cleanup
                doCommand(comPort, "AT&T");

                comPort.DiscardInBuffer();

                lbl_status.Text = "Doing Command ATI & AT&F";

                doCommand(comPort, "AT&F");

                doCommand(comPort, "AT&W");

                lbl_status.Text = "Reset";

                doCommand(comPort, "ATZ");

                comPort.Close();

                BUT_getcurrent_Click(sender, e);
            }
            else
            {

                // off hook
                doCommand(comPort, "ATO");

                lbl_status.Text = "Fail";
                CustomMessageBox.Show("Failed to enter command mode");
            }

            if (comPort.IsOpen)
                comPort.Close();
        }
Exemple #4
0
        private void BUT_getcurrent_Click(object sender, EventArgs e)
        {
            ICommsSerial comPort = new SerialPort();

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

                comPort.ReadTimeout = 4000;

                comPort.Open();

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

            lbl_status.Text = "Connecting";

            if (doConnect(comPort))
            {
                // cleanup
                doCommand(comPort, "AT&T");

                comPort.DiscardInBuffer();

                lbl_status.Text = "Doing Command ATI & RTI";

                ATI.Text = doCommand(comPort, "ATI");

                RTI.Text = doCommand(comPort, "RTI");

                uploader.Uploader.Frequency freq = (uploader.Uploader.Frequency)Enum.Parse(typeof(uploader.Uploader.Frequency), doCommand(comPort, "ATI3"));
                uploader.Uploader.Board board = (uploader.Uploader.Board)Enum.Parse(typeof(uploader.Uploader.Board), doCommand(comPort, "ATI2"));

                    ATI3.Text = freq.ToString();

                    ATI2.Text = board.ToString();
                    try
                    {
                        RTI2.Text = ((uploader.Uploader.Board)Enum.Parse(typeof(uploader.Uploader.Board), doCommand(comPort, "RTI2"))).ToString();
                    }
                    catch { }
                // 8 and 9
                    if (freq == uploader.Uploader.Frequency.FREQ_915)
                    {
                        S8.DataSource = Range(895000, 1000, 935000);
                        RS8.DataSource = Range(895000, 1000, 935000);

                        S9.DataSource = Range(895000, 1000, 935000);
                        RS9.DataSource = Range(895000, 1000, 935000);
                    }
                    else if (freq == uploader.Uploader.Frequency.FREQ_433)
                    {
                        S8.DataSource = Range(414000, 100, 454000);
                        RS8.DataSource = Range(414000, 100, 454000);

                        S9.DataSource = Range(414000, 100, 454000);
                        RS9.DataSource = Range(414000, 100, 454000);
                    }
                    else if (freq == uploader.Uploader.Frequency.FREQ_868)
                    {
                        S8.DataSource = Range(849000, 1000, 889000);
                        RS8.DataSource = Range(849000, 1000, 889000);

                        S9.DataSource = Range(849000, 1000, 889000);
                        RS9.DataSource = Range(849000, 1000, 889000);
                    }

                    if (board == uploader.Uploader.Board.DEVICE_ID_RFD900 || board == uploader.Uploader.Board.DEVICE_ID_RFD900A)
                    {
                        S4.DataSource = Range(1, 1, 30);
                        RS4.DataSource = Range(1, 1, 30);
                    }

                RSSI.Text = doCommand(comPort, "ATI7").Trim();

                lbl_status.Text = "Doing Command ATI5";

                string answer = doCommand(comPort, "ATI5");

                string[] items = answer.Split('\n');

                foreach (string item in items)
                {
                    if (item.StartsWith("S"))
                    {
                        string[] values = item.Split(':', '=');

                        if (values.Length == 3)
                        {
                            Control[] controls = this.Controls.Find(values[0].Trim(), true);

                            if (controls.Length > 0)
                            {
                                controls[0].Enabled = true;

                                if (controls[0] is CheckBox)
                                {
                                    ((CheckBox)controls[0]).Checked = values[2].Trim() == "1";
                                }
                                else if (controls[0] is TextBox)
                                {
                                    ((TextBox)controls[0]).Text = values[2].Trim();
                                }
                                else if (controls[0].Name.Contains("S6")) //
                                {
                                    var ans = Enum.Parse(typeof(mavlink_option), values[2].Trim());
                                    ((ComboBox)controls[0]).Text = ans.ToString();
                                }
                                else if (controls[0] is ComboBox)
                                {
                                    ((ComboBox)controls[0]).Text = values[2].Trim();
                                }
                            }
                        }
                    }
                }

                // remote
                foreach (Control ctl in groupBox2.Controls)
                {
                    if (ctl.Name.StartsWith("RS") && ctl.Name != "RSSI")
                        ctl.ResetText();
                }

                comPort.DiscardInBuffer();

                lbl_status.Text = "Doing Command RTI5";

                answer = doCommand(comPort, "RTI5");

                items = answer.Split('\n');

                foreach (string item in items)
                {
                    if (item.StartsWith("S"))
                    {
                        string[] values = item.Split(':', '=');

                        if (values.Length == 3)
                        {
                            Control[] controls = this.Controls.Find("R" + values[0].Trim(), true);

                            if (controls.Length == 0)
                                continue;

                            controls[0].Enabled = true;

                            if (controls[0] is CheckBox)
                            {
                                ((CheckBox)controls[0]).Checked = values[2].Trim() == "1";
                            }
                            else if (controls[0] is TextBox)
                            {
                                ((TextBox)controls[0]).Text = values[2].Trim();
                            }
                            else if (controls[0].Name.Contains("S6")) //
                            {
                                var ans = Enum.Parse(typeof(mavlink_option), values[2].Trim());
                                ((ComboBox)controls[0]).Text = ans.ToString();
                            }
                            else if (controls[0] is ComboBox)
                            {
                                ((ComboBox)controls[0]).Text = values[2].Trim();
                            }
                        }
                        else
                        {
                            /*
                            if (item.Contains("S15"))
                            {
                                answer = doCommand(comPort, "RTS15?");
                                int rts15 = 0;
                                if (int.TryParse(answer, out rts15))
                                {
                                    RS15.Enabled = true;
                                    RS15.Text = rts15.ToString();
                                }
                            }
                            */
                            log.Info("Odd config line :" + item);
                        }
                    }
                }

                // off hook
                doCommand(comPort, "ATO");

                lbl_status.Text = "Done";
            }
            else
            {

                // off hook
                doCommand(comPort, "ATO");

                lbl_status.Text = "Fail";
                CustomMessageBox.Show("Failed to enter command mode");
            }

            comPort.Close();

            BUT_Syncoptions.Enabled = true;

            BUT_savesettings.Enabled = true;
        }
Exemple #5
0
        /// <summary>
        /// Detects APM board version
        /// </summary>
        /// <param name="port"></param>
        /// <returns> (1280/2560/2560-2/px4/px4v2)</returns>
        public static boards DetectBoard(string port)
        {
            SerialPort serialPort = new SerialPort();
            serialPort.PortName = port;

            if (!MainV2.MONO)
            {
                ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_SerialPort"); // Win32_USBControllerDevice
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
                foreach (ManagementObject obj2 in searcher.Get())
                {
                    Console.WriteLine("PNPID: " + obj2.Properties["PNPDeviceID"].Value.ToString());

                    // check vid and pid
                    if (obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_2341&PID_0010"))
                    {
                        // check port name as well
                        if (obj2.Properties["Name"].Value.ToString().ToUpper().Contains(serialPort.PortName.ToUpper()))
                        {
                            log.Info("is a 2560-2");
                            return boards.b2560v2;
                        }
                    }

                    if (obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_26AC&PID_0010"))
                    {
                        // check port name as well
                        //if (obj2.Properties["Name"].Value.ToString().ToUpper().Contains(serialPort.PortName.ToUpper()))
                        {
                            log.Info("is a px4");
                            return boards.px4;
                        }
                    }

                    if (obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_26AC&PID_0011"))
                    {
                        log.Info("is a px4v2");
                        return boards.px4v2;
                    }

                    if (obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_26AC&PID_0001"))
                    {
                        log.Info("is a px4v2 bootloader");
                        return boards.px4v2;
                    }

                    if (obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_26AC&PID_0016"))
                    {
                        log.Info("is a px4v2 bootloader");
                        CustomMessageBox.Show("You appear to have a bootloader with a bad PID value, please update your bootloader.");
                        return boards.px4v2;
                    }

                    //|| obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_26AC&PID_0012") || obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_26AC&PID_0013") || obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_26AC&PID_0014") || obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_26AC&PID_0015") || obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_26AC&PID_0016")

                }

            }
            else
            {
                // if its mono
                if (DialogResult.Yes == CustomMessageBox.Show("Is this a APM 2+?", "APM 2+", MessageBoxButtons.YesNo))
                {
                    return boards.b2560v2;
                }
                else
                {
                    if (DialogResult.Yes == CustomMessageBox.Show("Is this a PX4/PIXHAWK?", "PX4/PIXHAWK", MessageBoxButtons.YesNo))
                    {
                        if (DialogResult.Yes == CustomMessageBox.Show("Is this a PIXHAWK?", "PIXHAWK", MessageBoxButtons.YesNo))
                        {
                            return boards.px4v2;
                        }
                        return boards.px4;
                    }
                    else
                    {
                        return boards.b2560;
                    }
                }
            }

            if (serialPort.IsOpen)
                serialPort.Close();

            serialPort.DtrEnable = true;
            serialPort.BaudRate = 57600;
            serialPort.Open();

            Thread.Sleep(100);

            int a = 0;
            while (a < 20) // 20 * 50 = 1 sec
            {
                //Console.WriteLine("write " + DateTime.Now.Millisecond);
                serialPort.DiscardInBuffer();
                serialPort.Write(new byte[] { (byte)'0', (byte)' ' }, 0, 2);
                a++;
                Thread.Sleep(50);

                //Console.WriteLine("btr {0}", serialPort.BytesToRead);
                if (serialPort.BytesToRead >= 2)
                {
                    byte b1 = (byte)serialPort.ReadByte();
                    byte b2 = (byte)serialPort.ReadByte();
                    if (b1 == 0x14 && b2 == 0x10)
                    {
                        serialPort.Close();
                        log.Info("is a 1280");
                        return boards.b1280;
                    }
                }
            }

            serialPort.Close();

            log.Warn("Not a 1280");

            Thread.Sleep(500);

            serialPort.DtrEnable = true;
            serialPort.BaudRate = 115200;
            serialPort.Open();

            Thread.Sleep(100);

            a = 0;
            while (a < 4)
            {
                byte[] temp = new byte[] { 0x6, 0, 0, 0, 0 };
                temp = BoardDetect.genstkv2packet(serialPort, temp);
                a++;
                Thread.Sleep(50);

                try
                {
                    if (temp[0] == 6 && temp[1] == 0 && temp.Length == 2)
                    {
                        serialPort.Close();
                        //HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_2341&PID_0010\640333439373519060F0\Device Parameters
                        if (!MainV2.MONO && !Thread.CurrentThread.CurrentCulture.IsChildOf(CultureInfoEx.GetCultureInfo("zh-Hans")))
                        {
                            ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_SerialPort"); // Win32_USBControllerDevice
                            ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
                            foreach (ManagementObject obj2 in searcher.Get())
                            {
                                //Console.WriteLine("Dependant : " + obj2["Dependent"]);

                                // all apm 1-1.4 use a ftdi on the imu board.

                            /*    obj2.Properties.ForEach(x =>
                                {
                                    try
                                    {
                                        log.Info(((PropertyData)x).Name.ToString() + " = " + ((PropertyData)x).Value.ToString());
                                    }
                                    catch { }
                                });
                                */
                                // check vid and pid
                                if (obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_2341&PID_0010"))
                                {
                                    // check port name as well
                                    if (obj2.Properties["Name"].Value.ToString().ToUpper().Contains(serialPort.PortName.ToUpper()))
                                    {
                                        log.Info("is a 2560-2");
                                        return boards.b2560v2;
                                    }
                                }
                            }

                            log.Info("is a 2560");
                            return boards.b2560;
                        }
                    }
                }
                catch { }
            }

            serialPort.Close();
            log.Warn("Not a 2560");

            if (DialogResult.Yes == CustomMessageBox.Show("Is this a APM 2+?", "APM 2+", MessageBoxButtons.YesNo))
            {
                return boards.b2560v2;
            }
            else
            {
                if (DialogResult.Yes == CustomMessageBox.Show("Is this a PX4/PIXHAWK?", "PX4/PIXHAWK", MessageBoxButtons.YesNo))
                {
                    if (DialogResult.Yes == CustomMessageBox.Show("Is this a PIXHAWK?", "PIXHAWK", MessageBoxButtons.YesNo))
                    {
                        return boards.px4v2;
                    }
                    return boards.px4;
                }
                else
                {
                    return boards.b2560;
                }
            }
        }
Exemple #6
0
        private void BUT_getcurrent_Click(object sender, EventArgs e)
        {
            ICommsSerial comPort = new SerialPort();

            try
            {
                if (MainV2.comPort.BaseStream.IsOpen)
                {
                    getTelemPortWithRadio(ref comPort);
                }
                else
                {
                    comPort.PortName = MainV2.comPort.BaseStream.PortName;
                    comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate;
                }

                comPort.ReadTimeout = 4000;

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

            lbl_status.Text = "Connecting";

            try
            {
                if (doConnect(comPort))
                {
                    // cleanup
                    doCommand(comPort, "AT&T");

                    comPort.DiscardInBuffer();

                    lbl_status.Text = "Doing Command ATI & RTI";

                    ATI.Text = doCommand(comPort, "ATI");

                    var freq =
                        (Uploader.Frequency)
                            Enum.Parse(typeof (Uploader.Frequency), doCommand(comPort, "ATI3"));
                    var board =
                        (Uploader.Board)
                            Enum.Parse(typeof (Uploader.Board), doCommand(comPort, "ATI2"));

                    ATI3.Text = freq.ToString();

                    ATI2.Text = board.ToString();

                    // 8 and 9
                    if (freq == Uploader.Frequency.FREQ_915)
                    {
                        MIN_FREQ.DataSource = Range(895000, 1000, 935000);
                        RMIN_FREQ.DataSource = Range(895000, 1000, 935000);

                        MAX_FREQ.DataSource = Range(895000, 1000, 935000);
                        RMAX_FREQ.DataSource = Range(895000, 1000, 935000);
                    }
                    else if (freq == Uploader.Frequency.FREQ_433)
                    {
                        MIN_FREQ.DataSource = Range(414000, 50, 460000);
                        RMIN_FREQ.DataSource = Range(414000, 50, 460000);

                        MAX_FREQ.DataSource = Range(414000, 50, 460000);
                        RMAX_FREQ.DataSource = Range(414000, 50, 460000);
                    }
                    else if (freq == Uploader.Frequency.FREQ_868)
                    {
                        MIN_FREQ.DataSource = Range(849000, 1000, 889000);
                        RMIN_FREQ.DataSource = Range(849000, 1000, 889000);

                        MAX_FREQ.DataSource = Range(849000, 1000, 889000);
                        RMAX_FREQ.DataSource = Range(849000, 1000, 889000);
                    }

                    if (board == Uploader.Board.DEVICE_ID_RFD900 ||
                        board == Uploader.Board.DEVICE_ID_RFD900A
                        || board == Uploader.Board.DEVICE_ID_RFD900P ||
                        board == Uploader.Board.DEVICE_ID_RFD900U ||
                        board == Uploader.Board.DEVICE_ID_RFD900Plus)
                    {
                        TXPOWER.DataSource = Range(1, 1, 30);
                        RTXPOWER.DataSource = Range(1, 1, 30);
                    }

                    txt_aeskey.Text = doCommand(comPort, "AT&E?").Trim();

                    RSSI.Text = doCommand(comPort, "ATI7").Trim();

                    lbl_status.Text = "Doing Command ATI5";

                    var answer = doCommand(comPort, "ATI5", true);

                    var items = answer.Split('\n');

                    foreach (var item in items)
                    {
                        if (item.StartsWith("S"))
                        {
                            var values = item.Split(':', '=');

                            if (values.Length == 3)
                            {
                                values[1] = values[1].Replace("/", "_");

                                var controls = groupBoxLocal.Controls.Find(values[1].Trim(), true);

                                if (controls.Length > 0)
                                {
                                    controls[0].Enabled = true;

                                    if (controls[0] is CheckBox)
                                    {
                                        ((CheckBox) controls[0]).Checked = values[2].Trim() == "1";
                                    }
                                    else if (controls[0] is TextBox)
                                    {
                                        ((TextBox) controls[0]).Text = values[2].Trim();
                                    }
                                    else if (controls[0].Name.Contains("MAVLINK")) //
                                    {
                                        var ans = Enum.Parse(typeof (mavlink_option), values[2].Trim());
                                        ((ComboBox) controls[0]).Text = ans.ToString();
                                    }
                                    else if (controls[0] is ComboBox)
                                    {
                                        ((ComboBox) controls[0]).Text = values[2].Trim();
                                    }
                                }
                            }
                        }
                    }

                    // remote
                    foreach (Control ctl in groupBoxRemote.Controls)
                    {
                        if (ctl.Name != "RSSI")
                            ctl.ResetText();
                    }

                    comPort.DiscardInBuffer();

                    RTI.Text = doCommand(comPort, "RTI");

                    try
                    {
                        var resp = doCommand(comPort, "RTI2");
                        if (resp.Trim() != "")
                            RTI2.Text =
                                ((Uploader.Board)Enum.Parse(typeof(Uploader.Board), resp)).ToString();
                    }
                    catch
                    {
                    }

                    txt_Raeskey.Text = doCommand(comPort, "RT&E?").Trim();

                    lbl_status.Text = "Doing Command RTI5";

                    answer = doCommand(comPort, "RTI5", true);

                    items = answer.Split('\n');

                    foreach (var item in items)
                    {
                        if (item.StartsWith("S"))
                        {
                            var values = item.Split(':', '=');

                            if (values.Length == 3)
                            {
                                values[1] = values[1].Replace("/", "_");

                                var controls = groupBoxRemote.Controls.Find("R" + values[1].Trim(), true);

                                if (controls.Length == 0)
                                    continue;

                                controls[0].Enabled = true;

                                if (controls[0] is CheckBox)
                                {
                                    ((CheckBox) controls[0]).Checked = values[2].Trim() == "1";
                                }
                                else if (controls[0] is TextBox)
                                {
                                    ((TextBox) controls[0]).Text = values[2].Trim();
                                }
                                else if (controls[0].Name.Contains("MAVLINK")) //
                                {
                                    var ans = Enum.Parse(typeof (mavlink_option), values[2].Trim());
                                    ((ComboBox) controls[0]).Text = ans.ToString();
                                }
                                else if (controls[0] is ComboBox)
                                {
                                    ((ComboBox) controls[0]).Text = values[2].Trim();
                                }
                            }
                            else
                            {
                                /*
                                if (item.Contains("S15"))
                                {
                                    answer = doCommand(comPort, "RTS15?");
                                    int rts15 = 0;
                                    if (int.TryParse(answer, out rts15))
                                    {
                                        RS15.Enabled = true;
                                        RS15.Text = rts15.ToString();
                                    }
                                }
                                */
                                log.Info("Odd config line :" + item);
                            }
                        }
                    }

                    // off hook
                    doCommand(comPort, "ATO");

                    lbl_status.Text = "Done";
                }
                else
                {
                    // off hook
                    doCommand(comPort, "ATO");

                    lbl_status.Text = "Fail";
                    CustomMessageBox.Show("Failed to enter command mode");
                }

                comPort.Close();

                BUT_Syncoptions.Enabled = true;

                BUT_savesettings.Enabled = true;
            }
            catch (Exception ex)
            {
                try
                {
                    if (comPort != null)
                        comPort.Close();
                }
                catch
                {
                }
                lbl_status.Text = "Error";
                CustomMessageBox.Show("Error during read " + ex);
            }
        }
Exemple #7
0
        private void BUT_savesettings_Click(object sender, EventArgs e)
        {
            ICommsSerial comPort = new SerialPort();

            try
            {
                if (MainV2.comPort.BaseStream.IsOpen)
                {
                    getTelemPortWithRadio(ref comPort);
                }
                else
                {
                    comPort.PortName = MainV2.comPort.BaseStream.PortName;
                    comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate;
                }

                comPort.ReadTimeout = 4000;

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

            lbl_status.Text = "Connecting";

            if (doConnect(comPort))
            {
                // cleanup
                doCommand(comPort, "AT&T");

                comPort.DiscardInBuffer();

                lbl_status.Text = "Doing Command";

                // set encryption keys at the same time, so if we are enabled we dont lose comms.
                if (RENCRYPTION_LEVEL.Checked)
                {
                    doCommand(comPort, "RT&E=" + txt_Raeskey.Text.PadRight(32, '0'), true);
                }
                if (ENCRYPTION_LEVEL.Checked)
                {
                    doCommand(comPort, "AT&E=" + txt_aeskey.Text.PadRight(32, '0'), true);
                }

                if (RTI.Text != "")
                {
                    // remote
                    var answer = doCommand(comPort, "RTI5", true);

                    var items = answer.Split(new[] {'\n'}, StringSplitOptions.RemoveEmptyEntries);

                    foreach (var item in items)
                    {
                        if (item.StartsWith("S"))
                        {
                            var values = item.Split(':', '=');

                            if (values.Length == 3)
                            {
                                values[1] = values[1].Replace("/", "_");

                                var controls = groupBoxRemote.Controls.Find("R" + values[1].Trim(), true);

                                if (controls.Length > 0)
                                {
                                    if (controls[0].GetType() == typeof (CheckBox))
                                    {
                                        var value = ((CheckBox) controls[0]).Checked ? "1" : "0";

                                        if (value != values[2].Trim())
                                        {
                                            var cmdanswer = doCommand(comPort,
                                                "RT" + values[0].Trim() + "=" + value + "\r");

                                            if (cmdanswer.Contains("OK"))
                                            {
                                            }
                                            else
                                            {
                                                CustomMessageBox.Show("Set Command error");
                                            }
                                        }
                                    }
                                    else if (controls[0] is TextBox)
                                    {
                                    }
                                    else if (controls[0].Name.Contains("MAVLINK")) //
                                    {
                                        if (((ComboBox) controls[0]).SelectedValue.ToString() != values[2].Trim())
                                        {
                                            var cmdanswer = doCommand(comPort,
                                                "RT" + values[0].Trim() + "=" + ((ComboBox) controls[0]).SelectedValue +
                                                "\r");

                                            if (cmdanswer.Contains("OK"))
                                            {
                                            }
                                            else
                                            {
                                                CustomMessageBox.Show("Set Command error");
                                            }
                                        }
                                    }
                                    else if (controls[0] is ComboBox)
                                    {
                                        if (controls[0].Text != values[2].Trim())
                                        {
                                            var cmdanswer = doCommand(comPort,
                                                "RT" + values[0].Trim() + "=" + controls[0].Text + "\r");

                                            if (cmdanswer.Contains("OK"))
                                            {
                                            }
                                            else
                                            {
                                                CustomMessageBox.Show("Set Command error");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    Sleep(100);
                }

                comPort.DiscardInBuffer();
                {
                    //local

                    var answer = doCommand(comPort, "ATI5", true);

                    var items = answer.Split(new[] {'\n'}, StringSplitOptions.RemoveEmptyEntries);

                    foreach (var item in items)
                    {
                        if (item.StartsWith("S"))
                        {
                            var values = item.Split(':', '=');

                            if (values.Length == 3)
                            {
                                values[1] = values[1].Replace("/", "_");

                                var controls = groupBoxLocal.Controls.Find(values[1].Trim(), true);

                                if (controls.Length > 0)
                                {
                                    if (controls[0].GetType() == typeof (CheckBox))
                                    {
                                        var value = ((CheckBox) controls[0]).Checked ? "1" : "0";

                                        if (value != values[2].Trim())
                                        {
                                            var cmdanswer = doCommand(comPort,
                                                "AT" + values[0].Trim() + "=" + value + "\r");

                                            if (cmdanswer.Contains("OK"))
                                            {
                                            }
                                            else
                                            {
                                                CustomMessageBox.Show("Set Command error");
                                            }
                                        }
                                    }
                                    else if (controls[0] is TextBox)
                                    {
                                    }
                                    else if (controls[0].Name.Contains("MAVLINK")) //
                                    {
                                        if (((ComboBox) controls[0]).SelectedValue.ToString() != values[2].Trim())
                                        {
                                            var cmdanswer = doCommand(comPort,
                                                "AT" + values[0].Trim() + "=" + ((ComboBox) controls[0]).SelectedValue +
                                                "\r");

                                            if (cmdanswer.Contains("OK"))
                                            {
                                            }
                                            else
                                            {
                                                CustomMessageBox.Show("Set Command error");
                                            }
                                        }
                                    }
                                    else if (controls[0] is ComboBox)
                                    {
                                        if (controls[0].Text != values[2].Trim())
                                        {
                                            var cmdanswer = doCommand(comPort,
                                                "AT" + values[0].Trim() + "=" + controls[0].Text + "\r");

                                            if (cmdanswer.Contains("OK"))
                                            {
                                            }
                                            else
                                            {
                                                CustomMessageBox.Show("Set Command error");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (RTI.Text != "")
                    {
                        // write it
                        doCommand(comPort, "RT&W");

                        // return to normal mode
                        doCommand(comPort, "RTZ");
                    }

                    // write it
                    doCommand(comPort, "AT&W");


                    // return to normal mode
                    doCommand(comPort, "ATZ");
                }

                lbl_status.Text = "Done";
            }
            else
            {
                // return to normal mode
                doCommand(comPort, "ATZ");

                lbl_status.Text = "Fail";
                CustomMessageBox.Show("Failed to enter command mode");
            }


            comPort.Close();
        }
Exemple #8
0
        private void UploadFW(bool custom = false)
        {
            ICommsSerial comPort = new SerialPort();

            var uploader = new Uploader();

            if (MainV2.comPort.BaseStream.IsOpen)
            {
                try
                {
                    getTelemPortWithRadio(ref comPort);

                    uploader.PROG_MULTI_MAX = 64;
                }
                catch (Exception ex)
                {
                    CustomMessageBox.Show("Error " + ex);
                }
            }

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

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

            // prep what we are going to upload
            var iHex = new IHex();

            iHex.LogEvent += iHex_LogEvent;

            iHex.ProgressEvent += iHex_ProgressEvent;

            var bootloadermode = false;

            // attempt bootloader mode
            try
            {
                if (upload_xmodem(comPort))
                {
                    comPort.Close();
                    return;
                }

                comPort.BaudRate = 115200;

                uploader_ProgressEvent(0);
                uploader_LogEvent("Trying Bootloader Mode");

                uploader.port = comPort;
                uploader.connect_and_sync();

                uploader.ProgressEvent += uploader_ProgressEvent;
                uploader.LogEvent += uploader_LogEvent;

                uploader_LogEvent("In Bootloader Mode");
                bootloadermode = true;
            }
            catch (Exception ex1)
            {
                log.Error(ex1);

                // cleanup bootloader mode fail, and try firmware mode
                comPort.Close();
                if (MainV2.comPort.BaseStream.IsOpen)
                {
                    // default baud... guess
                    comPort.BaudRate = 57600;
                }
                else
                {
                    comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate;
                }
                try
                {
                    comPort.Open();
                }
                catch
                {
                    CustomMessageBox.Show("Error opening port", "Error");
                    return;
                }

                uploader.ProgressEvent += uploader_ProgressEvent;
                uploader.LogEvent += 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))
            {
                // put into bootloader mode/update mode
                if (!bootloadermode)
                {
                    try
                    {
                        comPort.Write("AT&UPDATE\r\n");
                        var left = comPort.ReadExisting();
                        log.Info(left);
                        Sleep(700);
                        comPort.BaudRate = 115200;
                    }
                    catch
                    {
                    }

                    if (upload_xmodem(comPort))
                    {
                        comPort.Close();
                        return;
                    }

                    comPort.BaudRate = 115200;
                }

                try
                {
                    // force sync after changing baudrate
                    uploader.connect_and_sync();
                }
                catch
                {
                    CustomMessageBox.Show("Failed to sync with Radio");
                    goto exit;
                }

                var device = Uploader.Board.FAILED;
                var freq = 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 #9
0
        private static void Main(string[] args)
        {
            ExtractPacketAddresses("ublox 6mdata.raw", "Addrneo6m.txt", 0x1420, 0x26ddf4);

            ExtractPacketAddresses("6mdata.raw", "Addrneo6m-2.txt", 0x1420, 0x26ddf4);

            ExtractPacketAddresses("datalea6h.raw", "Addrlea6h.txt", 0x3e4c, 0x8546dc);

            ExtractPacketAddresses("datalea6h-nu602.raw", "Addrlea6hnu602.txt", 0x3e4c, 0x8546dc);

            ExtractPacketAddresses("dataneo7n.raw", "Addrneo7n.txt", 0x20001188, 0x862f0c);

            ExtractPacketAddresses("UBX_M8_301_HPG_111_REFERENCE_NEOM8P2.b45d5e63c7aa261bd58dfbcbc22bad68.bin",
                                   "Addrm8p.txt", 0, 0x6df34, true);

            ExtractPacketAddresses("UBX_M8_301_HPG_111_REFERENCE_NEOM8P2.b45d5e63c7aa261bd58dfbcbc22bad68.bin",
                                   "Addrm8p22.txt", 0, 0x6e308, true);

            ExtractPacketAddresses("EXT_G60_LEA-6H.fd1146bafac24b1347701312d42bb698.bin",
                                   "Addrlea6h-2.txt", 0, 0x546dc);

            ExtractPacketAddresses("FW101_EXT_TITLIS.42ec35ce38d201fd723f2c8b49b6a537.bin",
                                   "Addr7.txt", 0, 0x62f0c);

            ExtractPacketAddresses("UBLOX_M8_201.89cc4f1cd4312a0ac1b56c790f7c1622.bin",
                                   "Addr8_201.txt", 0, 0x739e8);

            ExtractPacketAddresses("UBX_M8_301_SPG.911f2b77b649eb90f4be14ce56717b49.bin",
                                   "Addr8_301.txt", 0, 0x7904c, true);

            ExtractPacketAddresses("UBX_M8_301_HPG_100_REFERENCE.dd38fd00c1d64d05d5b458d8a8fa4b41.bin",
                                   "Addrm8p_301_100.txt", 0, 0x6805c, true);

            ExtractPacketAddresses("UBX_M8_301_HPG_100_REFERENCE.dd38fd00c1d64d05d5b458d8a8fa4b41.bin",
                                   "Addrm8p_301_100-2.txt", 0, 0x68394, true);

            ExtractPacketAddresses("UBX_M8_301_HPG_130_REFERENCE_NEOM8P2.59a07babb501ba6a89ff87cac2f2765f.bin",
                                   "Addrm8p_301_130-2.txt", 0, 0x718a8, true);

            ExtractPacketAddresses("UBX_M8_301_HPG_130_REFERENCE_NEOM8P2.59a07babb501ba6a89ff87cac2f2765f.bin",
                                   "Addrm8p_301_130-2a.txt", 0, 0x71ca0, true);

            ExtractPacketAddresses("DO_EXT_301_HPG_140_REFERENCE.ab799cc302b64f28ba73b55dfa945a04.bin",
                                   "Addrm8p_301_140.txt", 0x73980, 0x73980, true);

            //0005bd16
            // 5bd1a   from 20 B1  ==  00 bf

            var fileBytes = File.ReadAllBytes("DO_EXT_301_HPG_140_REFERENCE.ab799cc302b64f28ba73b55dfa945a04.bin");

            var binreader = new BinaryReader(new MemoryStream(fileBytes));

            string[] desc =
            {
                "UBX8",
                "?",
                "-1",  "fwbase ","fwstart", "fwend", "-1", "-1", "0", "-1", "?", "?"
            };

            for (int a = 0; a < 12; a++)
            {
                var item = binreader.ReadInt32();
                Console.WriteLine("{1}\t0x{0:X} = {0}", item, desc[a]);
            }

            /*
             * 0.0   - Verifying image
             *
             * 0.0 Image (file size 502984) for u-blox8 accepted
             *
             * 0.0 Image Ver '3.01 (db0c89)'
             * 0.0   - CRC= 0x90A97896 0xEE9EBE1E
             * 0.0   - Trying to open port STDIO
             *
             * undefined4 __fastcall dochecksum(int *param_1,uint param_2)
             *
             * {
             * int *piVar1;
             * int iVar2;
             * int iVar3;
             * uint uVar4;
             *
             * uVar4 = param_2 >> 2;
             * iVar2 = 0;
             * iVar3 = 0;
             * piVar1 = param_1;
             * while (uVar4 != 0) {
             * iVar2 = iVar2 + *piVar1;
             * piVar1 = piVar1 + 1;
             * iVar3 = iVar3 + iVar2;
             * uVar4 = uVar4 - 1;
             * }
             * if ((iVar2 == *(int *)((int)param_1 + (param_2 & 0xfffffffc))) &&
             * (iVar3 == *(int *)((int)param_1 + (param_2 & 0xfffffffc) + 4))) {
             * return 1;
             * }
             * return 0;
             * }
             *
             */

            // should == 502972 or 502976    000000000007ACBC  000000000001EB2F

            binreader.BaseStream.Seek(4, SeekOrigin.Begin);

            var ivar2 = 0;
            var ivar3 = 0;

            while (binreader.BaseStream.Position < binreader.BaseStream.Length - 8)
            {
                var b = binreader.ReadInt32();
                ivar2 = ivar2 + b;
                ivar3 = ivar3 + ivar2;
            }

            var crc1 = binreader.ReadInt32();
            var crc2 = binreader.ReadInt32();

            if (ivar2 == crc1 && ivar3 == crc2)
            {
                Console.WriteLine("CRC passes");
            }
            else
            {
                Console.WriteLine("CRC fails should be 0x{0:X8} 0x{1:X8} currently {2:X8} {3:X8}", ivar2, ivar3, crc1,
                                  crc2);
            }

            Console.ReadLine();

            return;

            ICommsSerial port;// = /*new TcpSerial();*/ //new SerialPort("com35" ,115200);

            port = new MissionPlanner.Comms.SerialPort();

            port.PortName = "com5";
            port.BaudRate = 115200;

            // mp internal pass
            //port.PortName = "127.0.0.1";
            //port.BaudRate = 500;

            port.ReadBufferSize = 1024 * 1024;

            port.Open();

            /*
             *
             * ?????
             * 0x00800000 0x80000 flash
             * 0x20000000 0x20000 ram
             * 0x20080000 0x20000 ram
             * 0x00200000 0x8000 rom
             *
             * For ublox6 ROM7.03 use:
             *
             * to enable RXM-RAW - addr 000016c8
             * b5 62 09 01 10 00 c8 16 00 00 00 00 00 00 97 69 21 00 00 00 02 10 2b 22
             *
             *
             * to enable RXM-SFRB - addr 0000190c
             * b5 62 09 01 10 00 0c 19 00 00 00 00 00 00 83 69 21 00 00 00 02 11 5f f0
             *
             */

            var rxmraw6m = new downloadreq();

            rxmraw6m.clas      = 0x9;
            rxmraw6m.subclass  = 0x1;
            rxmraw6m.length    = 0x10;
            rxmraw6m.flags     = 0;
            rxmraw6m.startaddr = 0x16c8;
            rxmraw6m.data      = new byte[] { 0x97, 0x69, 0x21, 0x00, 0x00, 0x00, 0x02, 0x10 };

            var rxmsfrb6m = new downloadreq();

            rxmsfrb6m.clas      = 0x9;
            rxmsfrb6m.subclass  = 0x1;
            rxmsfrb6m.length    = 0x10;
            rxmsfrb6m.flags     = 0;
            rxmsfrb6m.startaddr = 0x190c;
            rxmsfrb6m.data      = new byte[] { 0x83, 0x69, 0x21, 0x00, 0x00, 0x00, 0x02, 0x11 };

            var rxmraw6h = new downloadreq();

            rxmraw6h.clas      = 0x9;
            rxmraw6h.subclass  = 0x1;
            rxmraw6h.length    = 0x10;
            rxmraw6h.flags     = 0;
            rxmraw6h.startaddr = 0x40F4;
            rxmraw6h.data      = new byte[] { 0xe7, 0xb9, 0x81, 0x00, 0x00, 0x00, 0x02, 0x10 };

            var rxmsfrb6h = new downloadreq();

            rxmsfrb6h.clas      = 0x9;
            rxmsfrb6h.subclass  = 0x1;
            rxmsfrb6h.length    = 0x10;
            rxmsfrb6h.flags     = 0;
            rxmsfrb6h.startaddr = 0x4360;
            rxmsfrb6h.data      = new byte[] { 0xd3, 0xb9, 0x81, 0x00, 0x00, 0x00, 0x02, 0x11 };

            byte[] turnonbytes = { 0, 1, 0, 0, 0, 0, 0, 0 };

            byte[] header = { 0xb5, 0x62 };

            /*
             * Load FW binary 'C:\Users\hog\Downloads\NL602-patched-fw (1).bin'
             * Binary check success, G60 image valid.
             * Version: 7.03 (45970) Mar 17 2011 16:26:24
             * FLASH Base:          0x800000
             * FW Base:             0x800000
             * FW Start:            0x800048
             * FW End:              0x860AD4
             * FW Size:             0x60ADC
             *
             * Identifying Flash
             * Flash: ManID=0x90, DevID=0x90
             *
             * firmware: 0x200000
             */

            //turnon(port, header, 2, 0x20);
            //turnon(port, header, 2, 0x12);
            //turnon(port, header, 2, 0x23);
            //turnon(port, header, 2, 0x24);
            //turnon(port, header, 2, 0x51);
            //turnon(port, header, 2, 0x52);

            // turnon(port.BaseStream, header, 3, 0xA);
            // turnon(port.BaseStream, header, 3, 0xF);

            //writepacket(port.BaseStream, header, rxmraw);
            //writepacket(port.BaseStream, header, rxmsfrb);

            //writepacket(port.BaseStream, header, rxmraw6h);
            //writepacket(port.BaseStream, header, rxmsfrb6h);

            //writepacket(port.BaseStream, header, rxmraw6m);
            //writepacket(port.BaseStream, header, rxmsfrb6m);

            //return;

            //turnon(port.BaseStream, header, 2, 0x10);
            //turnon(port.BaseStream, header, 2, 0x11);

            //testmsg.startaddr += 8;
            //testmsg.data = turnonbytes;
            //writepacket(port.BaseStream, header, testmsg);


            /*
             * System.Threading.Thread.Sleep(200);
             *
             * while (port.IsOpen)
             * {
             *
             *  while (port.BytesToRead > 0)
             *  {
             *      byte data = (byte)port.ReadByte();
             *
             *      // Console.Write("{0,2:x}",data);
             *
             *      processbyte(data);
             *  }
             *
             * }
             *
             * port.Close();
             *
             * // Console.ReadLine();
             *
             * return;
             */

            // safeboot
            var buf = new byte[] { 0xB5, 0x62, 0x09, 0x07, 0x00, 0x00, 0x10, 0x39 };

            buf = new byte[] { 0xB5, 0x62, 0x09, 0x07, 0x01, 0x00, 0x01, 0x12, 0x4D };

            //port.Write(buf, 0, buf.Length);

            //port.Close();
            //Thread.Sleep(1000);
            //port.Open();

            // dump rom/memory

            req           = new uploadreq();
            req.clas      = 0x9;
            req.subclass  = 0x2;
            req.length    = 12;
            req.startaddr = 0x800001;
            req.datasize  = 128;
            req.flags     = 0;

            var  deadline = DateTime.MinValue;
            uint lastaddr = 0;

            while (port.IsOpen)
            {
                // determine when to send a new/next request
                if (deadline < DateTime.Now || lastaddr != req.startaddr)
                {
                    var datastruct = StaticUtils.StructureToByteArray(req);

                    var checksum = ubx_checksum(datastruct, datastruct.Length);

                    port.Write(header, 0, header.Length);
                    port.Write(datastruct, 0, datastruct.Length);
                    port.Write(checksum, 0, checksum.Length);

                    deadline = DateTime.Now.AddMilliseconds(200);
                    lastaddr = req.startaddr;
                }

                Thread.Sleep(0);

                while (port.BytesToRead > 0)
                {
                    var data = (byte)port.ReadByte();

                    // Console.Write("{0,2:x}",data);

                    processbyte(data);
                }
            }
        }
        /// <summary>
        /// detects STK version 1 or 2
        /// </summary>
        /// <param name="port">comportname</param>
        /// <returns>string either (1280/2560) or "" for none</returns>
        public static string DetectVersion(string port)
        {
            SerialPort serialPort = new SerialPort();
            serialPort.PortName = port;

            if (serialPort.IsOpen)
                serialPort.Close();

            serialPort.DtrEnable = true;
            serialPort.BaudRate = 57600;
            serialPort.Open();

            serialPort.toggleDTR();

            Thread.Sleep(100);

            int a = 0;
            while (a < 20) // 20 * 50 = 1 sec
            {
                //Console.WriteLine("write " + DateTime.Now.Millisecond);
                serialPort.DiscardInBuffer();
                serialPort.Write(new byte[] { (byte)'0', (byte)' ' }, 0, 2);
                a++;
                Thread.Sleep(50);

                //Console.WriteLine("btr {0}", serialPort.BytesToRead);
                if (serialPort.BytesToRead >= 2)
                {
                    byte b1 = (byte)serialPort.ReadByte();
                    byte b2 = (byte)serialPort.ReadByte();
                    if (b1 == 0x14 && b2 == 0x10)
                    {
                        serialPort.Close();
                        log.Info("is a 1280");
                        return "1280";
                    }
                }
            }

            serialPort.Close();

            log.Warn("Not a 1280");

            Thread.Sleep(500);

            serialPort.DtrEnable = true;
            serialPort.BaudRate = 115200;
            serialPort.Open();

            serialPort.toggleDTR();

            Thread.Sleep(100);

            a = 0;
            while (a < 4)
            {
                byte[] temp = new byte[] { 0x6, 0, 0, 0, 0 };
                temp = ArduinoDetect.genstkv2packet(serialPort, temp);
                a++;
                Thread.Sleep(50);

                try
                {
                    if (temp[0] == 6 && temp[1] == 0 && temp.Length == 2)
                    {
                        serialPort.Close();
                        log.Info("is a 2560");
                        return "2560";

                    }
                }
                catch
                {
                }
            }

            serialPort.Close();
            log.Warn("Not a 2560");
            return "";
        }
Exemple #11
0
        static void doread(object o)
        {
            lock (runlock)
            {
                running++;
            }

            var portname = (string)o;

            Console.WriteLine("Scanning {0}", portname);

            try
            {
                using (SerialPort port = new SerialPort())
                {
                    port.PortName = portname;

                    foreach (var baud in bauds)
                    {
                        // try default baud
                        if (baud != 0)
                        {
                            port.BaudRate = baud;
                        }

                        port.Open();
                        port.DiscardInBuffer();

                        // let data flow in
                        Thread.Sleep(2000);

                        lock (runlock)
                        {
                            if (run == 0)
                            {
                                return;
                            }
                        }

                        int available = port.BytesToRead;
                        var buffer    = new byte[available];
                        int read      = port.Read(buffer, 0, available);

                        Console.WriteLine("{0} {1}", portname, read);

                        if (read > 0)
                        {
                            using (MemoryStream ms = new MemoryStream(buffer, 0, read))
                            {
                                MAVLink.MavlinkParse mav = new MAVLink.MavlinkParse();

                                try
                                {
again:

                                    var packet = mav.ReadPacket(ms);

                                    if (packet != null && packet.Length > 0)
                                    {
                                        port.Close();

                                        Console.WriteLine("Found Mavlink on port {0} at {1}", port.PortName,
                                                          port.BaudRate);

                                        foundport     = true;
                                        portinterface = port;

                                        if (connect)
                                        {
                                            MainV2.comPort.BaseStream = port;

                                            doconnect();
                                        }

                                        break;
                                    }
                                    Console.WriteLine(portname + " crc: " + mav.badCRC);
                                    goto again;
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(portname + " " + ex.ToString());
                                }
                            }
                        }

                        try
                        {
                            port.Close();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                        }

                        if (foundport)
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(portname + " " + ex.ToString());
            }
            finally
            {
                lock (runlock)
                {
                    running--;

                    if (running == 0)
                    {
                        run = 0;
                    }
                }
            }

            Console.WriteLine("Scan port {0} Finished!!", portname);
        }
Exemple #12
0
        private static void Main(string[] args)
        {
            ExtractPacketAddresses("ublox 6mdata.raw", "Addrneo6m.txt", 0x1420, 0x26ddf4);

            ExtractPacketAddresses("6mdata.raw", "Addrneo6m-2.txt", 0x1420, 0x26ddf4);

            ExtractPacketAddresses("datalea6h.raw", "Addrlea6h.txt", 0x3e4c, 0x8546dc);

            ExtractPacketAddresses("datalea6h-nu602.raw", "Addrlea6hnu602.txt", 0x3e4c, 0x8546dc);

            ExtractPacketAddresses("dataneo7n.raw", "Addrneo7n.txt", 0x20001188, 0x862f0c);

            ExtractPacketAddresses("UBX_M8_301_HPG_111_REFERENCE_NEOM8P2.b45d5e63c7aa261bd58dfbcbc22bad68.bin",
                                   "Addrm8p.txt", 0, 0x6df34, true);

            ExtractPacketAddresses("UBX_M8_301_HPG_111_REFERENCE_NEOM8P2.b45d5e63c7aa261bd58dfbcbc22bad68.bin",
                                   "Addrm8p22.txt", 0, 0x6e308, true);

            ExtractPacketAddresses("EXT_G60_LEA-6H.fd1146bafac24b1347701312d42bb698.bin",
                                   "Addrlea6h-2.txt", 0, 0x546dc);

            ExtractPacketAddresses("FW101_EXT_TITLIS.42ec35ce38d201fd723f2c8b49b6a537.bin",
                                   "Addr7.txt", 0, 0x62f0c);

            ExtractPacketAddresses("UBLOX_M8_201.89cc4f1cd4312a0ac1b56c790f7c1622.bin",
                                   "Addr8_201.txt", 0, 0x739e8);

            ExtractPacketAddresses("UBX_M8_301_SPG.911f2b77b649eb90f4be14ce56717b49.bin",
                                   "Addr8_301.txt", 0, 0x7904c, true);

            ExtractPacketAddresses("UBX_M8_301_HPG_100_REFERENCE.dd38fd00c1d64d05d5b458d8a8fa4b41.bin",
                                   "Addrm8p_301_100.txt", 0, 0x6805c, true);

            ExtractPacketAddresses("UBX_M8_301_HPG_100_REFERENCE.dd38fd00c1d64d05d5b458d8a8fa4b41.bin",
                                   "Addrm8p_301_100-2.txt", 0, 0x68394, true);

            ExtractPacketAddresses("UBX_M8_301_HPG_130_REFERENCE_NEOM8P2.59a07babb501ba6a89ff87cac2f2765f.bin",
                                   "Addrm8p_301_130-2.txt", 0, 0x718a8, true);

            ExtractPacketAddresses("UBX_M8_301_HPG_130_REFERENCE_NEOM8P2.59a07babb501ba6a89ff87cac2f2765f.bin",
                                   "Addrm8p_301_130-2a.txt", 0, 0x71ca0, true);

            return;

            ICommsSerial port;// = /*new TcpSerial();*/ //new SerialPort("com35" ,115200);

            port = new MissionPlanner.Comms.SerialPort();

            port.PortName = "com5";
            port.BaudRate = 115200;

            // mp internal pass
            //port.PortName = "127.0.0.1";
            //port.BaudRate = 500;

            port.ReadBufferSize = 1024 * 1024;

            port.Open();

            /*
             *
             * ?????
             * 0x00800000 0x80000 flash
             * 0x20000000 0x20000 ram
             * 0x20080000 0x20000 ram
             * 0x00200000 0x8000 rom
             *
             * For ublox6 ROM7.03 use:
             *
             * to enable RXM-RAW - addr 000016c8
             * b5 62 09 01 10 00 c8 16 00 00 00 00 00 00 97 69 21 00 00 00 02 10 2b 22
             *
             *
             * to enable RXM-SFRB - addr 0000190c
             * b5 62 09 01 10 00 0c 19 00 00 00 00 00 00 83 69 21 00 00 00 02 11 5f f0
             *
             */

            var rxmraw6m = new downloadreq();

            rxmraw6m.clas      = 0x9;
            rxmraw6m.subclass  = 0x1;
            rxmraw6m.length    = 0x10;
            rxmraw6m.flags     = 0;
            rxmraw6m.startaddr = 0x16c8;
            rxmraw6m.data      = new byte[] { 0x97, 0x69, 0x21, 0x00, 0x00, 0x00, 0x02, 0x10 };

            var rxmsfrb6m = new downloadreq();

            rxmsfrb6m.clas      = 0x9;
            rxmsfrb6m.subclass  = 0x1;
            rxmsfrb6m.length    = 0x10;
            rxmsfrb6m.flags     = 0;
            rxmsfrb6m.startaddr = 0x190c;
            rxmsfrb6m.data      = new byte[] { 0x83, 0x69, 0x21, 0x00, 0x00, 0x00, 0x02, 0x11 };

            var rxmraw6h = new downloadreq();

            rxmraw6h.clas      = 0x9;
            rxmraw6h.subclass  = 0x1;
            rxmraw6h.length    = 0x10;
            rxmraw6h.flags     = 0;
            rxmraw6h.startaddr = 0x40F4;
            rxmraw6h.data      = new byte[] { 0xe7, 0xb9, 0x81, 0x00, 0x00, 0x00, 0x02, 0x10 };

            var rxmsfrb6h = new downloadreq();

            rxmsfrb6h.clas      = 0x9;
            rxmsfrb6h.subclass  = 0x1;
            rxmsfrb6h.length    = 0x10;
            rxmsfrb6h.flags     = 0;
            rxmsfrb6h.startaddr = 0x4360;
            rxmsfrb6h.data      = new byte[] { 0xd3, 0xb9, 0x81, 0x00, 0x00, 0x00, 0x02, 0x11 };

            byte[] turnonbytes = { 0, 1, 0, 0, 0, 0, 0, 0 };

            byte[] header = { 0xb5, 0x62 };

            /*
             * Load FW binary 'C:\Users\hog\Downloads\NL602-patched-fw (1).bin'
             * Binary check success, G60 image valid.
             * Version: 7.03 (45970) Mar 17 2011 16:26:24
             * FLASH Base:          0x800000
             * FW Base:             0x800000
             * FW Start:            0x800048
             * FW End:              0x860AD4
             * FW Size:             0x60ADC
             *
             * Identifying Flash
             * Flash: ManID=0x90, DevID=0x90
             *
             * firmware: 0x200000
             */

            //turnon(port, header, 2, 0x20);
            //turnon(port, header, 2, 0x12);
            //turnon(port, header, 2, 0x23);
            //turnon(port, header, 2, 0x24);
            //turnon(port, header, 2, 0x51);
            //turnon(port, header, 2, 0x52);

            // turnon(port.BaseStream, header, 3, 0xA);
            // turnon(port.BaseStream, header, 3, 0xF);

            //writepacket(port.BaseStream, header, rxmraw);
            //writepacket(port.BaseStream, header, rxmsfrb);

            //writepacket(port.BaseStream, header, rxmraw6h);
            //writepacket(port.BaseStream, header, rxmsfrb6h);

            //writepacket(port.BaseStream, header, rxmraw6m);
            //writepacket(port.BaseStream, header, rxmsfrb6m);

            //return;

            //turnon(port.BaseStream, header, 2, 0x10);
            //turnon(port.BaseStream, header, 2, 0x11);

            //testmsg.startaddr += 8;
            //testmsg.data = turnonbytes;
            //writepacket(port.BaseStream, header, testmsg);


            /*
             * System.Threading.Thread.Sleep(200);
             *
             * while (port.IsOpen)
             * {
             *
             *  while (port.BytesToRead > 0)
             *  {
             *      byte data = (byte)port.ReadByte();
             *
             *      // Console.Write("{0,2:x}",data);
             *
             *      processbyte(data);
             *  }
             *
             * }
             *
             * port.Close();
             *
             * // Console.ReadLine();
             *
             * return;
             */

            // safeboot
            var buf = new byte[] { 0xB5, 0x62, 0x09, 0x07, 0x00, 0x00, 0x10, 0x39 };

            buf = new byte[] { 0xB5, 0x62, 0x09, 0x07, 0x01, 0x00, 0x01, 0x12, 0x4D };

            //port.Write(buf, 0, buf.Length);

            //port.Close();
            //Thread.Sleep(1000);
            //port.Open();

            // dump rom/memory

            req           = new uploadreq();
            req.clas      = 0x9;
            req.subclass  = 0x2;
            req.length    = 12;
            req.startaddr = 0x800001;
            req.datasize  = 128;
            req.flags     = 0;

            var  deadline = DateTime.MinValue;
            uint lastaddr = 0;

            while (port.IsOpen)
            {
                // determine when to send a new/next request
                if (deadline < DateTime.Now || lastaddr != req.startaddr)
                {
                    var datastruct = StaticUtils.StructureToByteArray(req);

                    var checksum = ubx_checksum(datastruct, datastruct.Length);

                    port.Write(header, 0, header.Length);
                    port.Write(datastruct, 0, datastruct.Length);
                    port.Write(checksum, 0, checksum.Length);

                    deadline = DateTime.Now.AddMilliseconds(200);
                    lastaddr = req.startaddr;
                }

                Thread.Sleep(0);

                while (port.BytesToRead > 0)
                {
                    var data = (byte)port.ReadByte();

                    // Console.Write("{0,2:x}",data);

                    processbyte(data);
                }
            }
        }