private void connectButton_Click(object sender, EventArgs e)
        {
            //Check to see if ip address is actually good
            if (ipAddrSelector.Text == "")
            {
                return;
            }

            //If connecting and box is not empty, use that address
            string candidateIP = "http://" + ipAddrSelector.Text + ":8181/";

            //Send request to root server as a form of "ping"
            string response = WebServerScripts.HttpGet(candidateIP, CTRProductStuff.Devices.None, 0, CTRProductStuff.Action.None, "", 2000);

            if (response.Equals("Failed"))
            {
                updateReturnTextBox();
                return;
            }
            EmptyReturn myReponse = JsonConvert.DeserializeObject <EmptyReturn>(response);

            updateReturnTextBox(0, "Connected");
            //Check the connected box if we successfully got the return message
            connectedIndicator.Checked = true;//myReponse.GeneralReturn.Error == WebServerScripts.PingReturn;
            _connectedIp = candidateIP;
            refreshButton_Click(null, null);
        }
        private void blinkButton_Click(object sender, EventArgs e)
        {
            if (deviceView.SelectedItems.Count == 1)
            {
                var descriptor = _deviceStatus.DeviceArray[deviceView.SelectedIndices[0]];
                CTRProductStuff.Devices dev = CTRProductStuff.DeviceIDMap[descriptor.ID & 0xFFFFFFC0];
                uint id = (uint)descriptor.ID & 0x3F;

                string ret = WebServerScripts.HttpGet(_connectedIp, dev, id, CTRProductStuff.Action.Blink);
                if (ret == "Failed")
                {
                    updateReturnTextBox(-999, "Failed to transmit message");
                    return;
                }
                BlinkReturn tmp = JsonConvert.DeserializeObject <BlinkReturn>(ret);

                updateReturnTextBox(tmp.GeneralReturn.Error, tmp.GeneralReturn.ErrorMessage);
            }
        }
        private void selftTestButton_Click(object sender, EventArgs e)
        {
            if (deviceView.SelectedItems.Count == 1)
            {
                var descriptor = _deviceStatus.DeviceArray[deviceView.SelectedIndices[0]];
                CTRProductStuff.Devices dev = CTRProductStuff.DeviceIDMap[descriptor.ID & 0xFFFFFFC0];
                uint id = (uint)descriptor.ID & 0x3F;

                //Self test holds a "lot" of data, so increase the timeout for it
                string ret = WebServerScripts.HttpGet(_connectedIp, dev, id, CTRProductStuff.Action.SelfTest, "", 1000);
                if (ret == "Failed")
                {
                    updateReturnTextBox();
                    return;
                }
                SelfTestReturn retClass = JsonConvert.DeserializeObject <SelfTestReturn>(ret);
                updateReturnTextBox(retClass.GeneralReturn.Error, retClass.GeneralReturn.ErrorMessage);
                selfTestBox.Text = retClass.SelfTest;
            }
        }
        private void nameChangeButton_Click(object sender, EventArgs e)
        {
            if (deviceView.SelectedItems.Count == 1)
            {
                var descriptor = _deviceStatus.DeviceArray[deviceView.SelectedIndices[0]];
                CTRProductStuff.Devices dev = CTRProductStuff.DeviceIDMap[descriptor.ID & 0xFFFFFFC0];
                uint   id = (uint)descriptor.ID & 0x3F;
                string extraParameters = "&newname=" + nameChanger.Text;

                string ret = WebServerScripts.HttpGet(_connectedIp, dev, id, CTRProductStuff.Action.SetDeviceName, extraParameters);
                if (ret == "Failed")
                {
                    updateReturnTextBox();
                    refreshButton_Click(null, null); //Update GUI
                    return;
                }
                NameReturn retJson = JsonConvert.DeserializeObject <NameReturn>(ret);
                updateReturnTextBox(retJson.GeneralReturn.Error, retJson.GeneralReturn.ErrorMessage);
                refreshButton_Click(null, null); //Update GUI
            }
        }
        private void updateFirmwareThread(string ip, CTRProductStuff.Devices device, uint id)
        {
            string ret = WebServerScripts.HttpGet(ip, device, id, CTRProductStuff.Action.UpdateFirmware, "", 60000);//Give it a minute to update

            if (ret == "Failed")
            {
                Invoke(new Action(() =>
                {
                    updateReturnTextBox(-999, "Firmware update failed");
                }));
                return;
            }

            FirmwareUpdateReturn returnClass = JsonConvert.DeserializeObject <FirmwareUpdateReturn>(ret);

            Invoke(new Action(() =>
            {
                updateReturnTextBox(returnClass.GeneralReturn.Error, returnClass.UpdateMessage);
            }));

            return;
        }
示例#6
0
        private void updateThread(string ip, CTRProductStuff.Devices device, uint deviceID, ProgressBar updateBar)
        {
            ProgressReturn returnClass = null;
            bool           starting    = true;

            do
            {
                if (closeThread)
                {
                    break;
                }

                string ret = WebServerScripts.HttpGet(ip, device, deviceID, CTRProductStuff.Action.CheckUpdateProgress);
                if (ret == "Failed")
                {
                    continue;
                }
                returnClass = JsonConvert.DeserializeObject <ProgressReturn>(ret);
                if (returnClass != null)
                {
                    if (returnClass.progress != 0)
                    {
                        starting = false;
                    }
                    Invoke(new Action(() =>
                    {
                        updateBar.Value = returnClass.progress; //Update in UI Thread
                    }));
                }
                Thread.Sleep(100);
            } while (returnClass == null || returnClass.progress != 0 || starting);

            closeThread = true;
            Invoke(new Action(() =>
            {
                Close();
            }));
        }
        private void refreshButton_Click(object sender, EventArgs e)
        {
            //On refresh poll for possible IP's and populate combobox with them
            _ipAddrItems.Clear();
            foreach (string addr in WebServerScripts.GetIPAddrs())
            {
                _ipAddrItems.Add(addr);
            }
            deviceView.Items.Clear();
            refreshConfigs();
            if (_connectedIp == "")
            {
                return;
            }
            string devices = WebServerScripts.HttpGet(_connectedIp, CTRProductStuff.Devices.None, 0, CTRProductStuff.Action.GetDeviceList, "", 1000);

            if (devices == "Failed")
            {
                updateReturnTextBox();
                return;
            }

            _deviceStatus = JsonConvert.DeserializeObject <GetDevicesReturn>(devices);
            if (_deviceStatus != null)
            {
                foreach (DeviceDescriptor d in _deviceStatus.DeviceArray)
                {
                    if ((d.ID & 0xFFFFFFC0) == 0x0204f400)
                    {
                        d.Model = "Pigeon Over Ribbon";
                    }

                    CTRProductStuff.Devices dev = CTRProductStuff.DeviceIDMap[(d.ID & 0xFFFFFFC0)];
                    string[] array = new string[7];
                    array[0] = d.Name;
                    array[1] = d.Model;
                    array[2] = (d.ID & 0x3F).ToString();
                    array[3] = d.CurrentVers;
                    array[4] = d.ManDate;
                    array[5] = d.BootloaderRev;
                    array[6] = d.SoftStatus;

                    int imageKey = 0;
                    switch (dev)
                    {
                    case CTRProductStuff.Devices.TalonSRX:
                        imageKey = 0;
                        break;

                    case CTRProductStuff.Devices.VictorSPX:
                        imageKey = 1;
                        break;

                    case CTRProductStuff.Devices.PigeonIMURibbon:
                    case CTRProductStuff.Devices.PigeonIMU:
                        imageKey = 2;
                        break;

                    case CTRProductStuff.Devices.CANifier:
                        imageKey = 3;
                        break;

                    case CTRProductStuff.Devices.PCM:
                        imageKey = 4;
                        break;

                    case CTRProductStuff.Devices.PDP:
                        imageKey = 5;
                        break;
                    }

                    deviceView.Items.Add(new ListViewItem(array, imageKey));
                }
            }
            updateReturnTextBox(_deviceStatus.GeneralReturn.Error, _deviceStatus.GeneralReturn.ErrorMessage);
            foreach (Control c in deviceSpecificControls.Controls)
            {
                c.Enabled = false;
            }
        }