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()); } } }
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); } } }
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); } } }