Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 private void firmwareDialogButton_Click(object sender, EventArgs e)
 {
     if (_connectedIp != "")
     {
         OpenFileDialog firmwareDialog = new OpenFileDialog();
         firmwareDialog.Filter = "CRF Firmware File|*.crf";
         firmwareDialog.Title  = "Choose a CRF File";
         if (firmwareDialog.ShowDialog() == DialogResult.OK)
         {
             fileName.Text = firmwareDialog.FileName;
             string ret = WebServerScripts.HttpPost(_connectedIp, firmwareDialog.OpenFile());
         }
     }
 }
Ejemplo n.º 3
0
        private void saveConfigButton_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;


                DeviceConfigs allConfigs = new DeviceConfigs();
                System.Collections.Generic.List <ConfigGroup> listOfConfigs = new System.Collections.Generic.List <ConfigGroup>();
                foreach (TabPage tab in groupedControls.TabPages)
                {
                    IControlGroup group    = ((GroupTabPage)tab).group.GetFromValues((GroupTabPage)tab);
                    ConfigGroup   newGroup = new ConfigGroup();
                    newGroup.Name    = tab.Text;
                    newGroup.Type    = group.GetType().Name;
                    newGroup.Ordinal = 0;
                    if (group is SlotGroup)
                    {
                        newGroup.Ordinal = (int)((SlotGroup)group).SlotNumber;
                    }
                    newGroup.Values = group;

                    listOfConfigs.Add(newGroup);
                }
                allConfigs.Configs = listOfConfigs.ToArray();
                string jsonToWrite = JsonConvert.SerializeObject(allConfigs);

                string builtIP = WebServerScripts.buildIP(_connectedIp, dev, id, CTRProductStuff.Action.SetConfig);
                using (MemoryStream outputStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(jsonToWrite)))
                {
                    string ret = WebServerScripts.HttpPost(builtIP, outputStream);
                    outputStream.Close();
                    if (ret == "Failed")
                    {
                        updateReturnTextBox();
                        return;
                    }
                    SetConfigReturn retClass = JsonConvert.DeserializeObject <SetConfigReturn>(ret);
                    if (retClass == null)
                    {
                        updateReturnTextBox();
                        return;
                    }
                    updateReturnTextBox(retClass.GeneralReturn.Error, retClass.GeneralReturn.ErrorMessage);
                }
            }
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        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;
            }
        }
Ejemplo n.º 6
0
        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
            }
        }
Ejemplo n.º 7
0
        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;
        }
Ejemplo n.º 8
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();
            }));
        }
Ejemplo n.º 9
0
        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;
            }
        }
Ejemplo n.º 10
0
        private void refreshConfigs()
        {
            groupedControls.TabPages.Clear();
            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;

                //Populate Configs with TalonSRX.json
                FileStream configParams;
                switch (dev)
                {
                case CTRProductStuff.Devices.TalonSRX:
                    configParams = File.Open("TalonSRX.json", FileMode.Open);
                    break;

                case CTRProductStuff.Devices.VictorSPX:
                    configParams = File.Open("VictorSPX.json", FileMode.Open);
                    break;

                default:
                    configParams = File.Open("NotRecognized.json", FileMode.Open);
                    break;
                }
                string builtIP = WebServerScripts.buildIP(_connectedIp, dev, id, CTRProductStuff.Action.GetConfig);
                string txt     = WebServerScripts.HttpPost(builtIP, configParams);
                configParams.Close();

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

                GetConfigsReturn configs = JsonConvert.DeserializeObject <GetConfigsReturn>(txt);

                if (configs == null)//Should never happen
                {
                    updateReturnTextBox();
                    return;
                }
                //Update return text box before doing anything else
                updateReturnTextBox(configs.GeneralReturn.Error, configs.GeneralReturn.ErrorMessage);
                if (configs.Device == null || configs.Device.Configs == null)
                {
                    return;
                }

                foreach (ConfigGroup group in configs.Device.Configs)
                {
                    Type t = Type.GetType("DiagServerAccessor." + group.Type);

                    IControlGroup newGroup = (IControlGroup)Activator.CreateInstance(t);

                    GroupTabPage newTab = new GroupTabPage(newGroup);
                    newTab.Text = group.Name;

                    newGroup.SetFromValues(group.Values, group.Ordinal);

                    newTab.Controls.Add(newGroup.CreateLayout());

                    groupedControls.TabPages.Add(newTab);
                }
            }
        }