public IActionResult insertar() { using (var db = new LinqContext()) { var sistemax = new software(); var sistemax2 = new software(); var sietmeax3 = new software(); sistemax.os = "Linux"; sistemax.nombre = "Atom"; sistemax.precio = 30; sistemax2.os = "Windos"; sistemax2.nombre = "Visual"; sistemax2.precio = 0; sietmeax3.os = "Os X"; sietmeax3.nombre = "Sublime text"; sietmeax3.precio = 100; var lista = new List <software>() { sistemax, sistemax2, sietmeax3 }; db.software.AddRange(lista); db.SaveChanges(); } return(View()); }
/// <summary> /// Get fw version from firmeware.diydrones.com /// </summary> /// <param name="fwurl"></param> /// <returns></returns> void getAPMVersion(object tempin) { System.Threading.Thread.CurrentThread.CurrentUICulture = Localizations.ConfigLang; try { software temp = (software)tempin; string baseurl = temp.urlpx4v2; if (baseurl == "") { return; } Localizations.ReplaceMirrorUrl(ref baseurl); Uri url = new Uri(new Uri(baseurl), "git-version.txt"); log.Info("Get url " + url.ToString()); updateProgress(-1, Strings.GettingFWVersion); WebRequest wr = WebRequest.Create(url); WebResponse wresp = wr.GetResponse(); StreamReader sr = new StreamReader(wresp.GetResponseStream()); while (!sr.EndOfStream) { string line = sr.ReadLine(); if (line.Contains("APMVERSION:")) { log.Info(line); // get index var index = softwares.IndexOf(temp); // get item to modify var item = softwares[index]; // change name item.name = line.Substring(line.IndexOf(':') + 2); // save back to list softwares[index] = item; return; } } log.Info("no answer"); } catch (Exception ex) { log.Error(ex); } finally { lock (this) { ingetapmversion--; } } }
void updateDisplayNameInvoke(software temp) { this.Invoke((MethodInvoker) delegate { updateDisplayName(temp); }); }
public async Task <ActionResult <user> > Postsoftware(software u) { _context.software.Add(u); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(Getsoftware), new { id = u.Id }, u)); }
public ActionResult DeleteConfirmed(int id) { software software = db.softwares.Find(id); db.softwares.Remove(software); db.SaveChanges(); return(RedirectToAction("Index")); }
void findfirmware(software findwhat) { DialogResult dr = CustomMessageBox.Show("Are you sure you want to upload " + findwhat.name + "?", "Continue", MessageBoxButtons.YesNo); if (dr == System.Windows.Forms.DialogResult.Yes) { update(findwhat); } }
public ActionResult Edit([Bind(Include = "SoftwareId,SoftwareName,Description,TokenRate,LearnIt,ProductFamily,Platform,LicenseType,ImagePath")] software software) { if (ModelState.IsValid) { db.Entry(software).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(software)); }
public ActionResult Edit([Bind(Include = "id,os,programs")] software software) { if (ModelState.IsValid) { db.Entry(software).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(software)); }
public ActionResult Create([Bind(Include = "id,os,programs")] software software) { if (ModelState.IsValid) { db.softwares.Add(software); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(software)); }
/// <summary> /// Get fw version from firmeware.diydrones.com /// </summary> /// <param name="fwurl"></param> /// <returns></returns> void getAPMVersion(object tempin) { lock (this) { ingetapmversion++; } try { software temp = (software)tempin; Uri url = new Uri(new Uri(temp.url2560_2), "git-version.txt"); log.Info("Get url " + url.ToString()); updateProgress(-1, "Getting FW Version"); WebRequest wr = WebRequest.Create(url); WebResponse wresp = wr.GetResponse(); StreamReader sr = new StreamReader(wresp.GetResponseStream()); while (!sr.EndOfStream) { string line = sr.ReadLine(); if (line.Contains("APMVERSION:")) { log.Info(line); // get index var index = softwares.IndexOf(temp); // get item to modify var item = softwares[index]; // change name item.name = line.Substring(line.IndexOf(':') + 2); // save back to list softwares[index] = item; return; } } log.Info("no answer"); } catch (Exception ex) { log.Error(ex); } finally { lock (this) { ingetapmversion--; } } }
public ActionResult Edit([Bind(Include = "idsoftware,nombre,version,codigo,proveedor_fk,tipo_software_fk,informacion_tecnica,configuraciones,es_activo,licencias_adquiridas,licencias_instaladas")] software software) { if (ModelState.IsValid) { db.Entry(software).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.proveedor_fk = new SelectList(db.proveedor, "idproveedor", "nombre_comercial", software.proveedor_fk); ViewBag.tipo_software_fk = new SelectList(db.tipo_de_software, "idtipo_de_software", "categoria", software.tipo_software_fk); return(View(software)); }
public async Task <IActionResult> Putsoftware(long id, software item) { if (id != item.Id) { return(BadRequest()); } _context.Entry(item).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); }
void updateDisplayName(software temp) { if (temp.url.ToLower().Contains("AR2".ToLower())) { pictureBoxRover.Text = temp.name; } if (temp.url.ToLower().Contains("firmware/AP-1".ToLower())) { pictureBoxAPM.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/APHIL-".ToLower())) { pictureBoxAPHil.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-quad-".ToLower())) { pictureBoxQuad.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-tri".ToLower())) { pictureBoxTri.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-hexa".ToLower())) { pictureBoxHexa.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-y6".ToLower())) { pictureBoxY6.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-heli-1".ToLower())) { pictureBoxHeli.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-quadhil".ToLower())) { pictureBoxACHil.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-octav-".ToLower())) { pictureBoxOctav.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-octa-".ToLower())) { pictureBoxOcta.Text = temp.name; } else { log.Info("No Home " + temp.name + " " + temp.url); } }
// GET: softwares/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } software software = db.softwares.Find(id); if (software == null) { return(HttpNotFound()); } return(View(software)); }
// GET: softwares/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } software software = db.software.Find(id); if (software == null) { return(HttpNotFound()); } ViewBag.proveedor_fk = new SelectList(db.proveedor, "idproveedor", "nombre_comercial", software.proveedor_fk); ViewBag.tipo_software_fk = new SelectList(db.tipo_de_software, "idtipo_de_software", "categoria", software.tipo_software_fk); return(View(software)); }
public bool insertSoftware(Software soft) { try { software software = new software(); software.SoftwareID = soft.codigo; software.Nombre = soft.nombre; software.Plataformas = soft.plataforma; software.RequerimientosTecnicos = soft.requerimientos; software.RadicadoNum = soft.numAutor; db.software.Add(software); db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
void updateDisplayName(software temp) { if (temp.url2560.ToLower().Contains("AR2".ToLower()) || temp.url2560.ToLower().Contains("apm1/APMRover".ToLower())) { pictureBoxRover.Text = temp.name; pictureBoxRover.Tag = temp; } else if (temp.url2560.ToLower().Contains("AP-".ToLower()) || temp.url2560.ToLower().Contains("apm1/ArduPlane".ToLower())) { pictureBoxAPM.Text = temp.name; pictureBoxAPM.Tag = temp; } else if (temp.url2560.ToLower().Contains("APHIL-".ToLower()) || temp.url2560.ToLower().Contains("apm1-hilsensors/ArduPlane".ToLower())) { pictureBoxAPHil.Text = temp.name; pictureBoxAPHil.Tag = temp; } else if (temp.url2560.ToLower().Contains("ac2-quad-".ToLower()) || temp.url2560.ToLower().Contains("1-quad/ArduCopter".ToLower())) { pictureBoxQuad.Text = temp.name; pictureBoxQuad.Tag = temp; } else if (temp.url2560.ToLower().Contains("ac2-tri".ToLower()) || temp.url2560.ToLower().Contains("-tri/ArduCopter".ToLower())) { pictureBoxTri.Text = temp.name; pictureBoxTri.Tag = temp; } else if (temp.url2560.ToLower().Contains("ac2-hexa".ToLower()) || temp.url2560.ToLower().Contains("-hexa/ArduCopter".ToLower())) { pictureBoxHexa.Text = temp.name; pictureBoxHexa.Tag = temp; } else if (temp.url2560.ToLower().Contains("ac2-y6".ToLower()) || temp.url2560.ToLower().Contains("-y6/ArduCopter".ToLower())) { pictureBoxY6.Text = temp.name; pictureBoxY6.Tag = temp; } else if (temp.url2560.ToLower().Contains("ac2-heli-".ToLower()) || temp.url2560.ToLower().Contains("-heli/ArduCopter".ToLower())) { pictureBoxHeli.Text = temp.name; pictureBoxHeli.Tag = temp; } else if (temp.url2560.ToLower().Contains("ac2-helhil".ToLower()) || temp.url2560.ToLower().Contains("-heli-hil/ArduCopter".ToLower())) { pictureBoxACHHil.Text = temp.name; pictureBoxACHHil.Tag = temp; } else if (temp.url2560.ToLower().Contains("ac2-quadhil".ToLower()) || temp.url2560.ToLower().Contains("-quad-hil/ArduCopter".ToLower())) { pictureBoxACHil.Text = temp.name; pictureBoxACHil.Tag = temp; } else if (temp.url2560.ToLower().Contains("ac2-octaquad-".ToLower()) || temp.url2560.ToLower().Contains("-octa-quad/ArduCopter".ToLower())) { pictureBoxOctaQuad.Text = temp.name; pictureBoxOctaQuad.Tag = temp; } else if (temp.url2560.ToLower().Contains("ac2-octa-".ToLower()) || temp.url2560.ToLower().Contains("-octa/ArduCopter".ToLower())) { pictureBoxOcta.Text = temp.name; pictureBoxOcta.Tag = temp; } else { log.Info("No Home " + temp.name + " " + temp.url2560); } }
void updateDisplayNameInvoke(software temp) { this.Invoke((MethodInvoker)delegate { updateDisplayName(temp); }); }
/// <summary> /// Do full update - get firmware from internet /// </summary> /// <param name="temp"></param> /// <param name="historyhash"></param> public bool update(string comport, software temp, string historyhash) { BoardDetect.boards board = BoardDetect.boards.none; try { updateProgress(-1, Strings.DetectingBoardVersion); board = BoardDetect.DetectBoard(comport); if (board == BoardDetect.boards.none) { CustomMessageBox.Show(Strings.CantDetectBoardVersion); return(false); } log.Info("Detected a " + board); updateProgress(-1, Strings.DetectedA + board); string baseurl = ""; if (board == BoardDetect.boards.b2560) { baseurl = temp.url2560.ToString(); } else if (board == BoardDetect.boards.b1280) { baseurl = temp.url.ToString(); } else if (board == BoardDetect.boards.b2560v2) { baseurl = temp.url2560_2.ToString(); } else if (board == BoardDetect.boards.px4) { baseurl = temp.urlpx4v1.ToString(); } else if (board == BoardDetect.boards.px4v2) { baseurl = temp.urlpx4v2.ToString(); } else if (board == BoardDetect.boards.px4v4) { baseurl = temp.urlpx4v4.ToString(); } else if (board == BoardDetect.boards.vrbrainv40) { baseurl = temp.urlvrbrainv40.ToString(); } else if (board == BoardDetect.boards.vrbrainv45) { baseurl = temp.urlvrbrainv45.ToString(); } else if (board == BoardDetect.boards.vrbrainv50) { baseurl = temp.urlvrbrainv50.ToString(); } else if (board == BoardDetect.boards.vrbrainv51) { baseurl = temp.urlvrbrainv51.ToString(); } else if (board == BoardDetect.boards.vrbrainv52) { baseurl = temp.urlvrbrainv52.ToString(); } else if (board == BoardDetect.boards.vrcorev10) { baseurl = temp.urlvrcorev10.ToString(); } else if (board == BoardDetect.boards.vrubrainv51) { baseurl = temp.urlvrubrainv51.ToString(); } else if (board == BoardDetect.boards.vrubrainv52) { baseurl = temp.urlvrubrainv52.ToString(); } else { CustomMessageBox.Show(Strings.InvalidBoardType); return(false); } if (board < BoardDetect.boards.px4) { if (temp.name.ToLower().Contains("arducopter")) { CustomMessageBox.Show(Strings.ThisBoardHasBeenRetired, Strings.Note); } } if (historyhash != "") { baseurl = getUrl(historyhash, baseurl); } // update to use mirror url L10N.ReplaceMirrorUrl(ref baseurl); log.Info("Using " + baseurl); // Create a request using a URL that can receive a post. WebRequest request = WebRequest.Create(baseurl); request.Timeout = 10000; // Set the Method property of the request to POST. request.Method = "GET"; // Get the request stream. Stream dataStream; //= request.GetRequestStream(); // Get the response (using statement is exception safe) using (WebResponse response = request.GetResponse()) { // Display the status. log.Info(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. using (dataStream = response.GetResponseStream()) { long bytes = response.ContentLength; long contlen = bytes; byte[] buf1 = new byte[1024]; using (FileStream fs = new FileStream( Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex", FileMode.Create)) { updateProgress(0, Strings.DownloadingFromInternet); long length = response.ContentLength; long progress = 0; dataStream.ReadTimeout = 30000; while (dataStream.CanRead) { try { updateProgress(length == 0 ? 50 : (int)((progress * 100) / length), Strings.DownloadingFromInternet); } catch { } int len = dataStream.Read(buf1, 0, 1024); if (len == 0) { break; } progress += len; bytes -= len; fs.Write(buf1, 0, len); } fs.Close(); } dataStream.Close(); } response.Close(); } updateProgress(100, Strings.DownloadedFromInternet); log.Info("Downloaded"); } catch (Exception ex) { updateProgress(50, Strings.FailedDownload); CustomMessageBox.Show("Failed to download new firmware : " + ex.ToString()); return(false); } MissionPlanner.Utilities.Tracking.AddFW(temp.name, board.ToString()); return(UploadFlash(comport, Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex", board)); }
private void update(software temp) { string board = ""; MainV2.comPort.BaseStream.DtrEnable = false; MainV2.comPort.Close(); System.Threading.Thread.Sleep(100); MainV2.comPort.giveComport = true; try { if (softwares.Count == 0) { CustomMessageBox.Show("No valid options"); return; } lbl_status.Text = "Detecting APM Version"; this.Refresh(); Application.DoEvents(); /* * ArdupilotMega.Controls.Firmware_Board fwb = new ArdupilotMega.Controls.Firmware_Board(); * fwb.ShowDialog(); * * var boardname = ArdupilotMega.Controls.Firmware_Board.fw; * * switch (boardname) * { * case ArdupilotMega.Controls.Firmware_Board.Firmware.apm1: * board = "2560"; * break; * case ArdupilotMega.Controls.Firmware_Board.Firmware.apm2: * board = "2560-2"; * break; * case ArdupilotMega.Controls.Firmware_Board.Firmware.apm2_5: * board = "2560-2"; * break; * case ArdupilotMega.Controls.Firmware_Board.Firmware.px4: * board = "px4"; * break; * } */ board = ArduinoDetect.DetectBoard(MainV2.comPortName); if (board == "") { CustomMessageBox.Show("Cant detect your APM version. Please check your cabling"); return; } int apmformat_version = -1; // fail continue if (board != "px4") { try { apmformat_version = ArduinoDetect.decodeApVar(MainV2.comPortName, board); } catch { } if (apmformat_version != -1 && apmformat_version != temp.k_format_version) { if (DialogResult.No == CustomMessageBox.Show("Epprom changed, all your setting will be lost during the update,\nDo you wish to continue?", "Epprom format changed (" + apmformat_version + " vs " + temp.k_format_version + ")", MessageBoxButtons.YesNo)) { CustomMessageBox.Show("Please connect and backup your config in the configuration tab."); return; } } } log.Info("Detected a " + board); string baseurl = ""; if (board == "2560") { baseurl = temp.url2560.ToString(); } else if (board == "1280") { baseurl = temp.url.ToString(); } else if (board == "2560-2") { baseurl = temp.url2560_2.ToString(); } else if (board == "px4") { baseurl = temp.urlpx4.ToString(); } else { CustomMessageBox.Show("Invalid Board Type"); return; } // use the git-history url if (CMB_history.Visible == true) { baseurl = getUrl(CMB_history.Text, baseurl); } log.Info("Using " + baseurl); // Create a request using a URL that can receive a post. WebRequest request = WebRequest.Create(baseurl); request.Timeout = 10000; // Set the Method property of the request to POST. request.Method = "GET"; // Get the request stream. Stream dataStream; //= request.GetRequestStream(); // Get the response. WebResponse response = request.GetResponse(); // Display the status. log.Info(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. dataStream = response.GetResponseStream(); long bytes = response.ContentLength; long contlen = bytes; byte[] buf1 = new byte[1024]; FileStream fs = new FileStream(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex", FileMode.Create); lbl_status.Text = "Downloading from Internet"; this.Refresh(); Application.DoEvents(); dataStream.ReadTimeout = 30000; while (dataStream.CanRead) { try { progress.Value = 50;// (int)(((float)(response.ContentLength - bytes) / (float)response.ContentLength) * 100); this.progress.Refresh(); } catch { } int len = dataStream.Read(buf1, 0, 1024); if (len == 0) { break; } bytes -= len; fs.Write(buf1, 0, len); } fs.Close(); dataStream.Close(); response.Close(); progress.Value = 100; this.Refresh(); Application.DoEvents(); log.Info("Downloaded"); } catch (Exception ex) { lbl_status.Text = "Failed download"; CustomMessageBox.Show("Failed to download new firmware : " + ex.ToString()); return; } System.Threading.ThreadPool.QueueUserWorkItem(apmtype, temp.name + "!" + board); UploadFlash(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex", board); }
/// <summary> /// Do full update - get firmware from internet /// </summary> /// <param name="temp"></param> /// <param name="historyhash"></param> public bool update(string comport, software temp, string historyhash) { BoardDetect.boards board = BoardDetect.boards.none; try { updateProgress(-1, Strings.DetectingBoardVersion); board = BoardDetect.DetectBoard(comport); if (board == BoardDetect.boards.none) { CustomMessageBox.Show(Strings.CantDetectBoardVersion); return false; } log.Info("Detected a " + board); updateProgress(-1, Strings.DetectedA + board); string baseurl = ""; if (board == BoardDetect.boards.b2560) { baseurl = temp.url2560.ToString(); } else if (board == BoardDetect.boards.b1280) { baseurl = temp.url.ToString(); } else if (board == BoardDetect.boards.b2560v2) { baseurl = temp.url2560_2.ToString(); } else if (board == BoardDetect.boards.px4) { baseurl = temp.urlpx4v1.ToString(); } else if (board == BoardDetect.boards.px4v2) { baseurl = temp.urlpx4v2.ToString(); } else if (board == BoardDetect.boards.px4v4) { baseurl = temp.urlpx4v4.ToString(); } else if (board == BoardDetect.boards.vrbrainv40) { baseurl = temp.urlvrbrainv40.ToString(); } else if (board == BoardDetect.boards.vrbrainv45) { baseurl = temp.urlvrbrainv45.ToString(); } else if (board == BoardDetect.boards.vrbrainv50) { baseurl = temp.urlvrbrainv50.ToString(); } else if (board == BoardDetect.boards.vrbrainv51) { baseurl = temp.urlvrbrainv51.ToString(); } else if (board == BoardDetect.boards.vrbrainv52) { baseurl = temp.urlvrbrainv52.ToString(); } else if (board == BoardDetect.boards.vrcorev10) { baseurl = temp.urlvrcorev10.ToString(); } else if (board == BoardDetect.boards.vrubrainv51) { baseurl = temp.urlvrubrainv51.ToString(); } else if (board == BoardDetect.boards.vrubrainv52) { baseurl = temp.urlvrubrainv52.ToString(); } else { CustomMessageBox.Show(Strings.InvalidBoardType); return false; } if (board < BoardDetect.boards.px4) { if (temp.name.ToLower().Contains("arducopter")) { CustomMessageBox.Show(Strings.ThisBoardHasBeenRetired, Strings.Note); } } if (historyhash != "") baseurl = getUrl(historyhash, baseurl); // update to use mirror url L10N.ReplaceMirrorUrl(ref baseurl); log.Info("Using " + baseurl); // Create a request using a URL that can receive a post. WebRequest request = WebRequest.Create(baseurl); request.Timeout = 10000; // Set the Method property of the request to POST. request.Method = "GET"; // Get the request stream. Stream dataStream; //= request.GetRequestStream(); // Get the response (using statement is exception safe) using (WebResponse response = request.GetResponse()) { // Display the status. log.Info(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. using (dataStream = response.GetResponseStream()) { long bytes = response.ContentLength; long contlen = bytes; byte[] buf1 = new byte[1024]; using (FileStream fs = new FileStream( Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex", FileMode.Create)) { updateProgress(0, Strings.DownloadingFromInternet); long length = response.ContentLength; long progress = 0; dataStream.ReadTimeout = 30000; while (dataStream.CanRead) { try { updateProgress(length == 0 ? 50 : (int)((progress * 100) / length), Strings.DownloadingFromInternet); } catch { } int len = dataStream.Read(buf1, 0, 1024); if (len == 0) break; progress += len; bytes -= len; fs.Write(buf1, 0, len); } fs.Close(); } dataStream.Close(); } response.Close(); } updateProgress(100, Strings.DownloadedFromInternet); log.Info("Downloaded"); } catch (Exception ex) { updateProgress(50, Strings.FailedDownload); CustomMessageBox.Show("Failed to download new firmware : " + ex.ToString()); return false; } MissionPlanner.Utilities.Tracking.AddFW(temp.name, board.ToString()); return UploadFlash(comport, Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex", board); }
/// <summary> /// Do full update - get firmware from internet /// </summary> /// <param name="temp"></param> /// <param name="historyhash"></param> public bool update(string comport, software temp) { string board = ""; try { updateProgress(-1, "Detecting APM Version"); board = ArduinoDetect.DetectBoard(comport); if (board == "") { CustomMessageBox.Show("Cant detect your APM version. Please check your cabling"); return(false); } int apmformat_version = -1; // fail continue if (board != "px4") { try { apmformat_version = ArduinoDetect.decodeApVar(comport, board); } catch { } if (apmformat_version != -1 && apmformat_version != temp.k_format_version) { if (DialogResult.No == CustomMessageBox.Show("Epprom changed, all your setting will be lost during the update,\nDo you wish to continue?", "Epprom format changed (" + apmformat_version + " vs " + temp.k_format_version + ")", MessageBoxButtons.YesNo)) { CustomMessageBox.Show("Please connect and backup your config in the configuration tab."); return(false); } } } log.Info("Detected a " + board); updateProgress(-1, "Detected a " + board); string baseurl = ""; if (board == "2560") { baseurl = temp.url2560.ToString(); } else if (board == "1280") { baseurl = temp.url.ToString(); } else if (board == "2560-2") { baseurl = temp.url2560_2.ToString(); } else if (board == "px4") { baseurl = temp.urlpx4.ToString(); } else { CustomMessageBox.Show("Invalid Board Type"); return(false); } log.Info("Using " + baseurl); // Create a request using a URL that can receive a post. WebRequest request = WebRequest.Create(baseurl); request.Timeout = 10000; // Set the Method property of the request to POST. request.Method = "GET"; // Get the request stream. Stream dataStream; //= request.GetRequestStream(); // Get the response. WebResponse response = request.GetResponse(); // Display the status. log.Info(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. dataStream = response.GetResponseStream(); long bytes = response.ContentLength; long contlen = bytes; byte[] buf1 = new byte[1024]; FileStream fs = new FileStream(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex", FileMode.Create); updateProgress(0, "Downloading from Internet"); dataStream.ReadTimeout = 30000; while (dataStream.CanRead) { try { updateProgress(50, "Downloading from Internet"); } catch { } int len = dataStream.Read(buf1, 0, 1024); if (len == 0) { break; } bytes -= len; fs.Write(buf1, 0, len); } fs.Close(); dataStream.Close(); response.Close(); updateProgress(100, "Downloaded from Internet"); log.Info("Downloaded"); } catch (Exception ex) { updateProgress(50, "Failed download"); CustomMessageBox.Show("Failed to download new firmware : " + ex.ToString()); return(false); } System.Threading.ThreadPool.QueueUserWorkItem(apmtype, temp.name + "!" + board); MissionPlanner.Utilities.Tracking.AddFW(temp.name, board); return(UploadFlash(comport, Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex", board)); }
internal void Firmware_Load(object sender, EventArgs e) { log.Info("FW load"); string url = ""; string url2560 = ""; string url2560_2 = ""; string name = ""; string desc = ""; int k_format_version = 0; softwares.Clear(); software temp = new software(); try { using (XmlTextReader xmlreader = new XmlTextReader("http://ardupilot-mega.googlecode.com/git/Tools/ArdupilotMegaPlanner/Firmware/firmware2.xml")) { while (xmlreader.Read()) { xmlreader.MoveToElement(); switch (xmlreader.Name) { case "url": url = xmlreader.ReadString(); break; case "url2560": url2560 = xmlreader.ReadString(); break; case "url2560-2": url2560_2 = xmlreader.ReadString(); break; case "name": name = xmlreader.ReadString(); break; case "format_version": k_format_version = int.Parse(xmlreader.ReadString()); break; case "desc": desc = xmlreader.ReadString(); break; case "Firmware": if (!url.Equals("") && !name.Equals("") && !desc.Equals("Please Update")) { temp.desc = desc; temp.name = name; temp.url = url; temp.url2560 = url2560; temp.url2560_2 = url2560_2; temp.k_format_version = k_format_version; try { updateDisplayName(temp); } catch { } // just in case softwares.Add(temp); } url = ""; url2560 = ""; name = ""; desc = ""; k_format_version = 0; temp = new software(); break; default: break; } } } } catch (Exception ex) { CustomMessageBox.Show("Failed to get Firmware List : " + ex.Message); } log.Info("FW load done"); }
private void update(software temp) { string board = ""; MainV2.comPort.BaseStream.DtrEnable = false; MainV2.comPort.Close(); System.Threading.Thread.Sleep(100); MainV2.comPort.giveComport = true; try { if (softwares.Count == 0) { CustomMessageBox.Show("No valid options"); return; } lbl_status.Text = "Detecting APM Version"; this.Refresh(); Application.DoEvents(); /* ArdupilotMega.Controls.Firmware_Board fwb = new ArdupilotMega.Controls.Firmware_Board(); fwb.ShowDialog(); var boardname = ArdupilotMega.Controls.Firmware_Board.fw; switch (boardname) { case ArdupilotMega.Controls.Firmware_Board.Firmware.apm1: board = "2560"; break; case ArdupilotMega.Controls.Firmware_Board.Firmware.apm2: board = "2560-2"; break; case ArdupilotMega.Controls.Firmware_Board.Firmware.apm2_5: board = "2560-2"; break; case ArdupilotMega.Controls.Firmware_Board.Firmware.px4: board = "px4"; break; } */ board = ArduinoDetect.DetectBoard(MainV2.comPortName); if (board == "") { CustomMessageBox.Show("Cant detect your APM version. Please check your cabling"); return; } int apmformat_version = -1; // fail continue if (board != "px4") { try { apmformat_version = ArduinoDetect.decodeApVar(MainV2.comPortName, board); } catch { } if (apmformat_version != -1 && apmformat_version != temp.k_format_version) { if (DialogResult.No == CustomMessageBox.Show("Epprom changed, all your setting will be lost during the update,\nDo you wish to continue?", "Epprom format changed (" + apmformat_version + " vs " + temp.k_format_version + ")", MessageBoxButtons.YesNo)) { CustomMessageBox.Show("Please connect and backup your config in the configuration tab."); return; } } } log.Info("Detected a " + board); string baseurl = ""; if (board == "2560") { baseurl = temp.url2560.ToString(); } else if (board == "1280") { baseurl = temp.url.ToString(); } else if (board == "2560-2") { baseurl = temp.url2560_2.ToString(); } else if (board == "px4") { baseurl = temp.urlpx4.ToString(); } else { CustomMessageBox.Show("Invalid Board Type"); return; } // use the git-history url if (CMB_history.Visible == true) { baseurl = getUrl(CMB_history.Text, baseurl); } log.Info("Using " + baseurl); // Create a request using a URL that can receive a post. WebRequest request = WebRequest.Create(baseurl); request.Timeout = 10000; // Set the Method property of the request to POST. request.Method = "GET"; // Get the request stream. Stream dataStream; //= request.GetRequestStream(); // Get the response. WebResponse response = request.GetResponse(); // Display the status. log.Info(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. dataStream = response.GetResponseStream(); long bytes = response.ContentLength; long contlen = bytes; byte[] buf1 = new byte[1024]; FileStream fs = new FileStream(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex", FileMode.Create); lbl_status.Text = "Downloading from Internet"; this.Refresh(); Application.DoEvents(); dataStream.ReadTimeout = 30000; while (dataStream.CanRead) { try { progress.Value = 50;// (int)(((float)(response.ContentLength - bytes) / (float)response.ContentLength) * 100); this.progress.Refresh(); } catch { } int len = dataStream.Read(buf1, 0, 1024); if (len == 0) break; bytes -= len; fs.Write(buf1, 0, len); } fs.Close(); dataStream.Close(); response.Close(); progress.Value = 100; this.Refresh(); Application.DoEvents(); log.Info("Downloaded"); } catch (Exception ex) { lbl_status.Text = "Failed download"; CustomMessageBox.Show("Failed to download new firmware : " + ex.ToString()); return; } System.Threading.ThreadPool.QueueUserWorkItem(apmtype, temp.name + "!" + board); UploadFlash(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex", board); }
/// <summary> /// Load xml from internet based on firmwareurl, and return softwarelist /// </summary> /// <returns></returns> public List<software> getFWList(string firmwareurl = "") { if (firmwareurl == "") firmwareurl = this.firmwareurl; log.Info("getFWList"); string url = ""; string url2560 = ""; string url2560_2 = ""; string px4 = ""; string name = ""; string desc = ""; int k_format_version = 0; softwares.Clear(); software temp = new software(); // this is for mono to a ssl server //ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy(); ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback((sender1, certificate, chain, policyErrors) => { return true; }); updateProgress(-1,"Getting FW List"); try { log.Info("url: " + firmwareurl); using (XmlTextReader xmlreader = new XmlTextReader(firmwareurl)) { while (xmlreader.Read()) { xmlreader.MoveToElement(); switch (xmlreader.Name) { case "url": url = xmlreader.ReadString(); break; case "url2560": url2560 = xmlreader.ReadString(); break; case "url2560-2": url2560_2 = xmlreader.ReadString(); break; case "urlpx4": px4 = xmlreader.ReadString(); break; case "name": name = xmlreader.ReadString(); break; case "format_version": k_format_version = int.Parse(xmlreader.ReadString()); break; case "desc": desc = xmlreader.ReadString(); break; case "Firmware": if (!url2560.Equals("") && !name.Equals("") && !desc.Equals("Please Update")) { temp.desc = desc; temp.name = name; temp.url = url; temp.url2560 = url2560; temp.url2560_2 = url2560_2; temp.urlpx4 = px4; temp.k_format_version = k_format_version; try { try { if (!url2560.Contains("github")) { name = getAPMVersion(temp.url2560); if (name != "") temp.name = name; } } catch { } } catch { } // just in case softwares.Add(temp); } url = ""; url2560 = ""; name = ""; desc = ""; k_format_version = 0; temp = new software(); break; default: break; } } } } catch (Exception ex) { log.Error(ex); //CustomMessageBox.Show("Failed to get Firmware List : " + ex.Message); throw; } log.Info("load done"); updateProgress(-1, "Received List"); return softwares; }
/// <summary> /// Do full update - get firmware from internet /// </summary> /// <param name="temp"></param> /// <param name="historyhash"></param> public bool update(string comport, software temp, string historyhash) { BoardDetect.boards board = BoardDetect.boards.none; try { updateProgress(-1, Strings.DetectingBoardVersion); board = BoardDetect.DetectBoard(comport); if (board == BoardDetect.boards.none) { CustomMessageBox.Show(Strings.CantDetectBoardVersion); return false; } int apmformat_version = -1; // fail continue if (board != BoardDetect.boards.px4 && board != BoardDetect.boards.px4v2 && board != BoardDetect.boards.vrbrainv40 && board != BoardDetect.boards.vrbrainv45 && board != BoardDetect.boards.vrbrainv50 && board != BoardDetect.boards.vrbrainv51 && board != BoardDetect.boards.vrbrainv52 && board != BoardDetect.boards.vrherov10 && board != BoardDetect.boards.vrubrainv51 && board != BoardDetect.boards.vrubrainv52 && board != BoardDetect.boards.vrgimbalv20 && board != BoardDetect.boards.vrugimbalv11) { try { apmformat_version = BoardDetect.decodeApVar(comport, board); } catch { } if (apmformat_version != -1 && apmformat_version != temp.k_format_version) { if (DialogResult.No == CustomMessageBox.Show(Strings.EppromChanged, String.Format(Strings.EppromFormatChanged, apmformat_version, temp.k_format_version), MessageBoxButtons.YesNo)) { CustomMessageBox.Show(Strings.PleaseConnectAndBackupConfig); return false; } } } log.Info("Detected a " + board); updateProgress(-1, Strings.DetectedA + board); string baseurl = ""; if (board == BoardDetect.boards.b2560) { baseurl = temp.url2560.ToString(); } else if (board == BoardDetect.boards.b1280) { baseurl = temp.url.ToString(); } else if (board == BoardDetect.boards.b2560v2) { baseurl = temp.url2560_2.ToString(); } else if (board == BoardDetect.boards.px4) { baseurl = temp.urlpx4v1.ToString(); } else if (board == BoardDetect.boards.px4v2) { baseurl = temp.urlpx4v2.ToString(); } else if (board == BoardDetect.boards.vrbrainv40) { baseurl = temp.urlvrbrainv40.ToString(); } else if (board == BoardDetect.boards.vrbrainv45) { baseurl = temp.urlvrbrainv45.ToString(); } else if (board == BoardDetect.boards.vrbrainv50) { baseurl = temp.urlvrbrainv50.ToString(); } else if (board == BoardDetect.boards.vrbrainv51) { baseurl = temp.urlvrbrainv51.ToString(); } else if (board == BoardDetect.boards.vrbrainv52) { baseurl = temp.urlvrbrainv52.ToString(); } else if (board == BoardDetect.boards.vrherov10) { baseurl = temp.urlvrherov10.ToString(); } else if (board == BoardDetect.boards.vrubrainv51) { baseurl = temp.urlvrubrainv51.ToString(); } else if (board == BoardDetect.boards.vrubrainv52) { baseurl = temp.urlvrubrainv52.ToString(); } else if (board == BoardDetect.boards.vrgimbalv20) { baseurl = temp.urlvrgimbalv20.ToString(); } else if (board == BoardDetect.boards.vrugimbalv11) { baseurl = temp.urlvrugimbalv11.ToString(); } else { CustomMessageBox.Show(Strings.InvalidBoardType); return false; } if (board < BoardDetect.boards.px4) { if (temp.name.ToLower().Contains("arducopter")) { CustomMessageBox.Show("This board has been retired, Mission Planner this will upload the last available version to your board","Note"); } } if (historyhash != "") baseurl = getUrl(historyhash, baseurl); // update to use mirror url Localizations.ReplaceMirrorUrl(ref baseurl); log.Info("Using " + baseurl); // Create a request using a URL that can receive a post. WebRequest request = WebRequest.Create(baseurl); request.Timeout = 10000; // Set the Method property of the request to POST. request.Method = "GET"; // Get the request stream. Stream dataStream; //= request.GetRequestStream(); // Get the response. WebResponse response = request.GetResponse(); // Display the status. log.Info(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. dataStream = response.GetResponseStream(); long bytes = response.ContentLength; long contlen = bytes; byte[] buf1 = new byte[1024]; FileStream fs = new FileStream(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex", FileMode.Create); updateProgress(0, Strings.DownloadingFromInternet); dataStream.ReadTimeout = 30000; while (dataStream.CanRead) { try { updateProgress(50, Strings.DownloadingFromInternet); } catch { } int len = dataStream.Read(buf1, 0, 1024); if (len == 0) break; bytes -= len; fs.Write(buf1, 0, len); } fs.Close(); dataStream.Close(); response.Close(); updateProgress(100, Strings.DownloadedFromInternet); log.Info("Downloaded"); } catch (Exception ex) { updateProgress(50, Strings.FailedDownload); CustomMessageBox.Show("Failed to download new firmware : " + ex.ToString()); return false; } MissionPlanner.Utilities.Tracking.AddFW(temp.name, board.ToString()); return UploadFlash(comport, Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex", board); }
void pdr_DoWork(object sender, Controls.ProgressWorkerEventArgs e, object passdata = null) { log.Info("FW load"); string url = ""; string url2560 = ""; string url2560_2 = ""; string px4 = ""; string name = ""; string desc = ""; int k_format_version = 0; softwares.Clear(); software temp = new software(); // this is for mono to a ssl server //ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy(); ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback((sender1, certificate, chain, policyErrors) => { return(true); }); try { log.Info("url: " + firmwareurl); using (XmlTextReader xmlreader = new XmlTextReader(firmwareurl)) { while (xmlreader.Read()) { xmlreader.MoveToElement(); switch (xmlreader.Name) { case "url": url = xmlreader.ReadString(); break; case "url2560": url2560 = xmlreader.ReadString(); break; case "url2560-2": url2560_2 = xmlreader.ReadString(); break; case "urlpx4": px4 = xmlreader.ReadString(); break; case "name": name = xmlreader.ReadString(); break; case "format_version": k_format_version = int.Parse(xmlreader.ReadString()); break; case "desc": desc = xmlreader.ReadString(); break; case "Firmware": if (!url2560.Equals("") && !name.Equals("") && !desc.Equals("Please Update")) { temp.desc = desc; temp.name = name; temp.url = url; temp.url2560 = url2560; temp.url2560_2 = url2560_2; temp.urlpx4 = px4; temp.k_format_version = k_format_version; try { try { if (!url2560.Contains("github")) { name = getAPMVersion(temp.url2560); if (name != "") { temp.name = name; } } } catch { } updateDisplayNameInvoke(temp); } catch { } // just in case softwares.Add(temp); } url = ""; url2560 = ""; name = ""; desc = ""; k_format_version = 0; temp = new software(); break; default: break; } } } } catch (Exception ex) { log.Error(ex); //CustomMessageBox.Show("Failed to get Firmware List : " + ex.Message); throw ex; } log.Info("FW load done"); ((ProgressReporterDialogue)sender).UpdateProgressAndStatus(100, "Done"); }
internal void Firmware_Load(object sender, EventArgs e) { log.Info("FW load"); string url = ""; string url2560 = ""; string url2560_2 = ""; string name = ""; string desc = ""; int k_format_version = 0; softwares.Clear(); software temp = new software(); // this is for mono to a ssl server //ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy(); ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback((sender1, certificate, chain, policyErrors) => { return(true); }); try { log.Info("url: " + firmwareurl); using (XmlTextReader xmlreader = new XmlTextReader(firmwareurl)) { while (xmlreader.Read()) { xmlreader.MoveToElement(); switch (xmlreader.Name) { case "url": url = xmlreader.ReadString(); break; case "url2560": url2560 = xmlreader.ReadString(); break; case "url2560-2": url2560_2 = xmlreader.ReadString(); break; case "name": name = xmlreader.ReadString(); break; case "format_version": k_format_version = int.Parse(xmlreader.ReadString()); break; case "desc": desc = xmlreader.ReadString(); break; case "Firmware": if (!url.Equals("") && !name.Equals("") && !desc.Equals("Please Update")) { temp.desc = desc; temp.name = name; temp.url = url; temp.url2560 = url2560; temp.url2560_2 = url2560_2; temp.k_format_version = k_format_version; try { updateDisplayName(temp); } catch { } // just in case softwares.Add(temp); } url = ""; url2560 = ""; name = ""; desc = ""; k_format_version = 0; temp = new software(); break; default: break; } } } } catch (Exception ex) { log.Error(ex); CustomMessageBox.Show("Failed to get Firmware List : " + ex.Message); } log.Info("FW load done"); }
void updateDisplayName(software temp) { if (temp.url.ToLower().Contains("firmware/AP-1".ToLower())) { pictureBoxAPM.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/APHIL-".ToLower())) { pictureBoxAPHil.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-quad-".ToLower())) { pictureBoxQuad.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-tri".ToLower())) { pictureBoxTri.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-hexa".ToLower())) { pictureBoxHexa.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-y6".ToLower())) { pictureBoxY6.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-heli-1".ToLower())) { pictureBoxHeli.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-quadhil".ToLower())) { pictureBoxACHil.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-octav-".ToLower())) { pictureBoxOctav.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-octa-".ToLower())) { pictureBoxOcta.Text = temp.name; } else { log.Info("No Home " + temp.name + " " + temp.url); } }
void pdr_DoWork(object sender, Controls.ProgressWorkerEventArgs e, object passdata = null) { log.Info("FW load"); string url = ""; string url2560 = ""; string url2560_2 = ""; string px4 = ""; string name = ""; string desc = ""; int k_format_version = 0; softwares.Clear(); software temp = new software(); // this is for mono to a ssl server //ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy(); ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback((sender1, certificate, chain, policyErrors) => { return true; }); try { log.Info("url: " + firmwareurl); using (XmlTextReader xmlreader = new XmlTextReader(firmwareurl)) { while (xmlreader.Read()) { xmlreader.MoveToElement(); switch (xmlreader.Name) { case "url": url = xmlreader.ReadString(); break; case "url2560": url2560 = xmlreader.ReadString(); break; case "url2560-2": url2560_2 = xmlreader.ReadString(); break; case "urlpx4": px4 = xmlreader.ReadString(); break; case "name": name = xmlreader.ReadString(); break; case "format_version": k_format_version = int.Parse(xmlreader.ReadString()); break; case "desc": desc = xmlreader.ReadString(); break; case "Firmware": if (!url2560.Equals("") && !name.Equals("") && !desc.Equals("Please Update")) { temp.desc = desc; temp.name = name; temp.url = url; temp.url2560 = url2560; temp.url2560_2 = url2560_2; temp.urlpx4 = px4; temp.k_format_version = k_format_version; try { try { if (!url2560.Contains("github")) { name = getAPMVersion(temp.url2560); if (name != "") temp.name = name; } } catch { } updateDisplayNameInvoke(temp); } catch { } // just in case softwares.Add(temp); } url = ""; url2560 = ""; name = ""; desc = ""; k_format_version = 0; temp = new software(); break; default: break; } } } } catch (Exception ex) { log.Error(ex); //CustomMessageBox.Show("Failed to get Firmware List : " + ex.Message); throw ex; } log.Info("FW load done"); ((ProgressReporterDialogue)sender).UpdateProgressAndStatus(100, "Done"); }
/// <summary> /// Do full update - get firmware from internet /// </summary> /// <param name="temp"></param> /// <param name="historyhash"></param> public bool update(string comport, software temp, string historyhash) { BoardDetect.boards board = BoardDetect.boards.none; try { updateProgress(-1, "Detecting Board Version"); board = BoardDetect.DetectBoard(comport); if (board == BoardDetect.boards.none) { CustomMessageBox.Show("Cant detect your Board version. Please check your cabling"); return false; } int apmformat_version = -1; // fail continue if (board != BoardDetect.boards.px4 && board != BoardDetect.boards.px4v2) { try { apmformat_version = BoardDetect.decodeApVar(comport, board); } catch { } if (apmformat_version != -1 && apmformat_version != temp.k_format_version) { if (DialogResult.No == CustomMessageBox.Show("Epprom changed, all your setting will be lost during the update,\nDo you wish to continue?", "Epprom format changed (" + apmformat_version + " vs " + temp.k_format_version + ")", MessageBoxButtons.YesNo)) { CustomMessageBox.Show("Please connect and backup your config in the configuration tab."); return false; } } } log.Info("Detected a " + board); updateProgress(-1, "Detected a " + board); string baseurl = ""; if (board == BoardDetect.boards.b2560) { baseurl = temp.url2560.ToString(); } else if (board == BoardDetect.boards.b1280) { baseurl = temp.url.ToString(); } else if (board == BoardDetect.boards.b2560v2) { baseurl = temp.url2560_2.ToString(); } else if (board == BoardDetect.boards.px4) { baseurl = temp.urlpx4v1.ToString(); } else if (board == BoardDetect.boards.px4v2) { baseurl = temp.urlpx4v2.ToString(); } else { CustomMessageBox.Show("Invalid Board Type"); return false; } if (historyhash != "") baseurl = getUrl(historyhash, baseurl); log.Info("Using " + baseurl); // Create a request using a URL that can receive a post. WebRequest request = WebRequest.Create(baseurl); request.Timeout = 10000; // Set the Method property of the request to POST. request.Method = "GET"; // Get the request stream. Stream dataStream; //= request.GetRequestStream(); // Get the response. WebResponse response = request.GetResponse(); // Display the status. log.Info(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. dataStream = response.GetResponseStream(); long bytes = response.ContentLength; long contlen = bytes; byte[] buf1 = new byte[1024]; FileStream fs = new FileStream(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex", FileMode.Create); updateProgress(0, "Downloading from Internet"); dataStream.ReadTimeout = 30000; while (dataStream.CanRead) { try { updateProgress(50, "Downloading from Internet"); } catch { } int len = dataStream.Read(buf1, 0, 1024); if (len == 0) break; bytes -= len; fs.Write(buf1, 0, len); } fs.Close(); dataStream.Close(); response.Close(); updateProgress(100, "Downloaded from Internet"); log.Info("Downloaded"); } catch (Exception ex) { updateProgress(50, "Failed download"); CustomMessageBox.Show("Failed to download new firmware : " + ex.ToString()); return false; } MissionPlanner.Utilities.Tracking.AddFW(temp.name, board.ToString()); return UploadFlash(comport, Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex", board); }
/// <summary> /// Load xml from internet based on firmwareurl, and return softwarelist /// </summary> /// <returns></returns> public List<software> getFWList(string firmwareurl = "") { if (firmwareurl == "") firmwareurl = this.firmwareurl; // mirror support L10N.ReplaceMirrorUrl(ref firmwareurl); log.Info("getFWList"); string url = ""; string url2560 = ""; string url2560_2 = ""; string px4 = ""; string px4v2 = ""; string px4v4 = ""; string vrbrainv40 = ""; string vrbrainv45 = ""; string vrbrainv50 = ""; string vrbrainv51 = ""; string vrbrainv52 = ""; string vrcorev10 = ""; string vrubrainv51 = ""; string vrubrainv52 = ""; string name = ""; string desc = ""; int k_format_version = 0; softwares.Clear(); software temp = new software(); // this is for mono to a ssl server //ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy(); ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback( (sender1, certificate, chain, policyErrors) => { return true; }); updateProgress(-1, Strings.GettingFWList); try { log.Info("url: " + firmwareurl); using (XmlTextReader xmlreader = new XmlTextReader(firmwareurl)) { while (xmlreader.Read()) { xmlreader.MoveToElement(); switch (xmlreader.Name) { case "url": url = xmlreader.ReadString(); break; case "url2560": url2560 = xmlreader.ReadString(); break; case "url2560-2": url2560_2 = xmlreader.ReadString(); break; case "urlpx4": px4 = xmlreader.ReadString(); break; case "urlpx4v2": px4v2 = xmlreader.ReadString(); break; case "urlpx4v4": px4v4 = xmlreader.ReadString(); break; case "urlvrbrainv40": vrbrainv40 = xmlreader.ReadString(); break; case "urlvrbrainv45": vrbrainv45 = xmlreader.ReadString(); break; case "urlvrbrainv50": vrbrainv50 = xmlreader.ReadString(); break; case "urlvrbrainv51": vrbrainv51 = xmlreader.ReadString(); break; case "urlvrbrainv52": vrbrainv52 = xmlreader.ReadString(); break; case "urlvrcorev10": vrcorev10 = xmlreader.ReadString(); break; case "urlvrubrainv51": vrubrainv51 = xmlreader.ReadString(); break; case "urlvrubrainv52": vrubrainv52 = xmlreader.ReadString(); break; case "name": name = xmlreader.ReadString(); break; case "format_version": k_format_version = int.Parse(xmlreader.ReadString()); break; case "desc": desc = xmlreader.ReadString(); break; case "Firmware": if (!name.Equals("") && !desc.Equals("Please Update")) { temp.desc = desc.Trim(); temp.name = name; temp.url = url; temp.url2560 = url2560; temp.url2560_2 = url2560_2; temp.urlpx4v1 = px4; temp.urlpx4v2 = px4v2; temp.urlpx4v4 = px4v4; temp.urlvrbrainv40 = vrbrainv40; temp.urlvrbrainv45 = vrbrainv45; temp.urlvrbrainv50 = vrbrainv50; temp.urlvrbrainv51 = vrbrainv51; temp.urlvrbrainv52 = vrbrainv52; temp.urlvrcorev10 = vrcorev10; temp.urlvrubrainv51 = vrubrainv51; temp.urlvrubrainv52 = vrubrainv52; temp.k_format_version = k_format_version; try { try { if (!url2560.Contains("github")) { //name = lock (this) { ingetapmversion++; } System.Threading.ThreadPool.QueueUserWorkItem(getAPMVersion, temp); //if (name != "") //temp.name = name; } } catch { } } catch { } // just in case softwares.Add(temp); } url = ""; url2560 = ""; url2560_2 = ""; px4 = ""; px4v2 = ""; px4v4 = ""; vrbrainv40 = ""; vrbrainv45 = ""; vrbrainv50 = ""; vrbrainv51 = ""; vrbrainv52 = ""; vrcorev10 = ""; vrubrainv51 = ""; vrubrainv52 = ""; name = ""; desc = ""; k_format_version = 0; temp = new software(); break; default: break; } } } } catch (Exception ex) { log.Error(ex); //CustomMessageBox.Show("Failed to get Firmware List : " + ex.Message); throw; } while (ingetapmversion > 0) System.Threading.Thread.Sleep(100); log.Info("load done"); updateProgress(-1, Strings.ReceivedList); return softwares; }
/// <summary> /// Load xml from internet based on firmwareurl, and return softwarelist /// </summary> /// <returns></returns> public List <software> getFWList(string firmwareurl = "") { if (firmwareurl == "") { firmwareurl = this.firmwareurl; } log.Info("getFWList"); string url = ""; string url2560 = ""; string url2560_2 = ""; string px4 = ""; string name = ""; string desc = ""; int k_format_version = 0; softwares.Clear(); software temp = new software(); // this is for mono to a ssl server //ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy(); ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback((sender1, certificate, chain, policyErrors) => { return(true); }); updateProgress(-1, "Getting FW List"); try { log.Info("url: " + firmwareurl); using (XmlTextReader xmlreader = new XmlTextReader(firmwareurl)) { while (xmlreader.Read()) { xmlreader.MoveToElement(); switch (xmlreader.Name) { case "url": url = xmlreader.ReadString(); break; case "url2560": url2560 = xmlreader.ReadString(); break; case "url2560-2": url2560_2 = xmlreader.ReadString(); break; case "urlpx4": px4 = xmlreader.ReadString(); break; case "name": name = xmlreader.ReadString(); break; case "format_version": k_format_version = int.Parse(xmlreader.ReadString()); break; case "desc": desc = xmlreader.ReadString(); break; case "Firmware": if (!url2560.Equals("") && !name.Equals("") && !desc.Equals("Please Update")) { temp.desc = desc; temp.name = name; temp.url = url; temp.url2560 = url2560; temp.url2560_2 = url2560_2; temp.urlpx4 = px4; temp.k_format_version = k_format_version; try { try { if (!url2560.Contains("github")) { name = getAPMVersion(temp.url2560); if (name != "") { temp.name = name; } } } catch { } } catch { } // just in case softwares.Add(temp); } url = ""; url2560 = ""; name = ""; desc = ""; k_format_version = 0; temp = new software(); break; default: break; } } } } catch (Exception ex) { log.Error(ex); //CustomMessageBox.Show("Failed to get Firmware List : " + ex.Message); throw; } log.Info("load done"); updateProgress(-1, "Received List"); return(softwares); }
public void UploadFlash(string filename, string board, software installing) { if (board == "px4") { UploadPX4(filename); return; } byte[] FLASH = new byte[1]; StreamReader sr = null; try { lbl_status.Text = "Reading Hex File"; this.Refresh(); Application.DoEvents(); sr = new StreamReader(filename); FLASH = readIntelHEXv2(sr); sr.Close(); log.InfoFormat("\n\nSize: {0}\n\n", FLASH.Length); } catch (Exception ex) { if (sr != null) { sr.Dispose(); } lbl_status.Text = "Failed read HEX"; CustomMessageBox.Show("Failed to read firmware.hex : " + ex.Message); return; } IArduinoComms port = new ArduinoSTK(); if (board == "1280") { if (FLASH.Length > 126976) { CustomMessageBox.Show("Firmware is to big for a 1280, Please upgrade your hardware!!"); return; } //port = new ArduinoSTK(); port.BaudRate = 57600; } else if (board == "2560" || board == "2560-2") { port = new ArduinoSTKv2 { BaudRate = 115200 }; } port.DataBits = 8; port.StopBits = System.IO.Ports.StopBits.One; port.Parity = System.IO.Ports.Parity.None; port.DtrEnable = true; try { port.PortName = MainV2.comPortName; port.Open(); flashing = true; if (port.connectAP()) { log.Info("starting"); lbl_status.Text = "Uploading " + FLASH.Length + " bytes to APM Board: " + board; progress.Value = 0; this.Refresh(); // this is enough to make ap_var reset //port.upload(new byte[256], 0, 2, 0); port.Progress += port_Progress; if (!port.uploadflash(FLASH, 0, FLASH.Length, 0)) { flashing = false; if (port.IsOpen) port.Close(); throw new Exception("Upload failed. Lost sync. Try Arduino!!"); } port.Progress -= new ProgressEventHandler(port_Progress); progress.Value = 100; log.Info("Uploaded"); this.Refresh(); int start = 0; short length = 0x100; byte[] flashverify = new byte[FLASH.Length + 256]; lbl_status.Text = "Verify APM"; progress.Value = 0; this.Refresh(); while (start < FLASH.Length) { progress.Value = (int)((start / (float)FLASH.Length) * 100); progress.Refresh(); port.setaddress(start); log.Info("Downloading " + length + " at " + start); port.downloadflash(length).CopyTo(flashverify, start); start += length; } progress.Value = 100; for (int s = 0; s < FLASH.Length; s++) { if (FLASH[s] != flashverify[s]) { CustomMessageBox.Show("Upload succeeded, but verify failed: exp " + FLASH[s].ToString("X") + " got " + flashverify[s].ToString("X") + " at " + s); break; } } lbl_status.Text = "Write Done... Waiting (17 sec)"; } else { lbl_status.Text = "Failed upload"; CustomMessageBox.Show("Communication Error - no connection"); } port.Close(); flashing = false; Application.DoEvents(); try { ((SerialPort)port).Open(); } catch { } DateTime startwait = DateTime.Now; if (installing.url2560_2 != null && installing.url2560_2.ToLower().Contains("copter")) CustomMessageBox.Show("Please ensure you do a live compass calibration after installing arducopter V 3.x"); try { ((SerialPort)port).Close(); } catch { } progress.Value = 100; lbl_status.Text = "Done"; } catch (Exception ex) { lbl_status.Text = "Failed upload"; CustomMessageBox.Show("Check port settings or Port in use? " + ex); try { port.Close(); } catch { } } flashing = false; MainV2.comPort.giveComport = false; }
/// <summary> /// Load xml from internet based on firmwareurl, and return softwarelist /// </summary> /// <returns></returns> public List <software> getFWList(string firmwareurl = "") { if (firmwareurl == "") { firmwareurl = this.firmwareurl; } // mirror support Localizations.ReplaceMirrorUrl(ref firmwareurl); log.Info("getFWList"); string url = ""; string url2560 = ""; string url2560_2 = ""; string px4 = ""; string px4v2 = ""; string vrbrainv40 = ""; string vrbrainv45 = ""; string vrbrainv50 = ""; string vrbrainv51 = ""; string vrbrainv52 = ""; string vrherov10 = ""; string vrubrainv51 = ""; string vrubrainv52 = ""; string vrgimbalv20 = ""; string vrugimbalv11 = ""; string name = ""; string desc = ""; int k_format_version = 0; softwares.Clear(); software temp = new software(); // this is for mono to a ssl server //ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy(); ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback((sender1, certificate, chain, policyErrors) => { return(true); }); updateProgress(-1, Strings.GettingFWList); try { log.Info("url: " + firmwareurl); using (XmlTextReader xmlreader = new XmlTextReader(firmwareurl)) { while (xmlreader.Read()) { xmlreader.MoveToElement(); switch (xmlreader.Name) { case "url": url = xmlreader.ReadString(); break; case "url2560": url2560 = xmlreader.ReadString(); break; case "url2560-2": url2560_2 = xmlreader.ReadString(); break; case "urlpx4": px4 = xmlreader.ReadString(); break; case "urlpx4v2": px4v2 = xmlreader.ReadString(); break; case "urlvrbrainv40": vrbrainv40 = xmlreader.ReadString(); break; case "urlvrbrainv45": vrbrainv45 = xmlreader.ReadString(); break; case "urlvrbrainv50": vrbrainv50 = xmlreader.ReadString(); break; case "urlvrbrainv51": vrbrainv51 = xmlreader.ReadString(); break; case "urlvrbrainv52": vrbrainv52 = xmlreader.ReadString(); break; case "urlvrherov10": vrherov10 = xmlreader.ReadString(); break; case "urlvrubrainv51": vrubrainv51 = xmlreader.ReadString(); break; case "urlvrubrainv52": vrubrainv52 = xmlreader.ReadString(); break; case "urlvrgimbalv20": vrgimbalv20 = xmlreader.ReadString(); break; case "urlvrugimbalv11": vrugimbalv11 = xmlreader.ReadString(); break; case "name": name = xmlreader.ReadString(); break; case "format_version": k_format_version = int.Parse(xmlreader.ReadString()); break; case "desc": desc = xmlreader.ReadString(); break; case "Firmware": if (!name.Equals("") && !desc.Equals("Please Update")) { temp.desc = desc.Trim(); temp.name = name; temp.url = url; temp.url2560 = url2560; temp.url2560_2 = url2560_2; temp.urlpx4v1 = px4; temp.urlpx4v2 = px4v2; temp.urlvrbrainv40 = vrbrainv40; temp.urlvrbrainv45 = vrbrainv45; temp.urlvrbrainv50 = vrbrainv50; temp.urlvrbrainv51 = vrbrainv51; temp.urlvrbrainv52 = vrbrainv52; temp.urlvrherov10 = vrherov10; temp.urlvrubrainv51 = vrubrainv51; temp.urlvrubrainv52 = vrubrainv52; temp.urlvrgimbalv20 = vrgimbalv20; temp.urlvrugimbalv11 = vrugimbalv11; temp.k_format_version = k_format_version; try { try { if (!url2560.Contains("github")) { //name = lock (this) { ingetapmversion++; } System.Threading.ThreadPool.QueueUserWorkItem(getAPMVersion, temp); //if (name != "") //temp.name = name; } } catch { } } catch { } // just in case softwares.Add(temp); } url = ""; url2560 = ""; url2560_2 = ""; px4 = ""; px4v2 = ""; vrbrainv40 = ""; vrbrainv45 = ""; vrbrainv50 = ""; vrbrainv51 = ""; vrbrainv52 = ""; vrherov10 = ""; vrubrainv51 = ""; vrubrainv52 = ""; vrgimbalv20 = ""; vrugimbalv11 = ""; name = ""; desc = ""; k_format_version = 0; temp = new software(); break; default: break; } } } } catch (Exception ex) { log.Error(ex); //CustomMessageBox.Show("Failed to get Firmware List : " + ex.Message); throw; } while (ingetapmversion > 0) { System.Threading.Thread.Sleep(100); } log.Info("load done"); updateProgress(-1, Strings.ReceivedList); return(softwares); }
internal void Firmware_Load(object sender, EventArgs e) { log.Info("FW load"); string url = ""; string url2560 = ""; string url2560_2 = ""; string name = ""; string desc = ""; int k_format_version = 0; softwares.Clear(); software temp = new software(); // this is for mono to a ssl server //ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy(); ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback((sender1, certificate, chain, policyErrors) => { return true; }); try { log.Info("url: "+firmwareurl); using (XmlTextReader xmlreader = new XmlTextReader(firmwareurl)) { while (xmlreader.Read()) { xmlreader.MoveToElement(); switch (xmlreader.Name) { case "url": url = xmlreader.ReadString(); break; case "url2560": url2560 = xmlreader.ReadString(); break; case "url2560-2": url2560_2 = xmlreader.ReadString(); break; case "name": name = xmlreader.ReadString(); break; case "format_version": k_format_version = int.Parse(xmlreader.ReadString()); break; case "desc": desc = xmlreader.ReadString(); break; case "Firmware": if (!url.Equals("") && !name.Equals("") && !desc.Equals("Please Update")) { temp.desc = desc; temp.name = name; temp.url = url; temp.url2560 = url2560; temp.url2560_2 = url2560_2; temp.k_format_version = k_format_version; try { updateDisplayName(temp); } catch { } // just in case softwares.Add(temp); } url = ""; url2560 = ""; name = ""; desc = ""; k_format_version = 0; temp = new software(); break; default: break; } } } } catch (Exception ex) { log.Error(ex); CustomMessageBox.Show("Failed to get Firmware List : " + ex.Message); } log.Info("FW load done"); }
/// <summary> /// Do full update - get firmware from internet /// </summary> /// <param name="temp"></param> /// <param name="historyhash"></param> public bool update(string comport, software temp, string historyhash) { BoardDetect.boards board = BoardDetect.boards.none; try { updateProgress(-1, Strings.DetectingBoardVersion); board = BoardDetect.DetectBoard(comport); if (board == BoardDetect.boards.none) { CustomMessageBox.Show(Strings.CantDetectBoardVersion); return(false); } int apmformat_version = -1; // fail continue if (board != BoardDetect.boards.px4 && board != BoardDetect.boards.px4v2 && board != BoardDetect.boards.vrbrainv40 && board != BoardDetect.boards.vrbrainv45 && board != BoardDetect.boards.vrbrainv50 && board != BoardDetect.boards.vrbrainv51 && board != BoardDetect.boards.vrbrainv52 && board != BoardDetect.boards.vrherov10 && board != BoardDetect.boards.vrubrainv51 && board != BoardDetect.boards.vrubrainv52 && board != BoardDetect.boards.vrgimbalv20 && board != BoardDetect.boards.vrugimbalv11) { try { apmformat_version = BoardDetect.decodeApVar(comport, board); } catch { } if (apmformat_version != -1 && apmformat_version != temp.k_format_version) { if (DialogResult.No == CustomMessageBox.Show(Strings.EppromChanged, String.Format(Strings.EppromFormatChanged, apmformat_version, temp.k_format_version), MessageBoxButtons.YesNo)) { CustomMessageBox.Show(Strings.PleaseConnectAndBackupConfig); return(false); } } } log.Info("Detected a " + board); updateProgress(-1, Strings.DetectedA + board); string baseurl = ""; if (board == BoardDetect.boards.b2560) { baseurl = temp.url2560.ToString(); } else if (board == BoardDetect.boards.b1280) { baseurl = temp.url.ToString(); } else if (board == BoardDetect.boards.b2560v2) { baseurl = temp.url2560_2.ToString(); } else if (board == BoardDetect.boards.px4) { baseurl = temp.urlpx4v1.ToString(); } else if (board == BoardDetect.boards.px4v2) { baseurl = temp.urlpx4v2.ToString(); } else if (board == BoardDetect.boards.vrbrainv40) { baseurl = temp.urlvrbrainv40.ToString(); } else if (board == BoardDetect.boards.vrbrainv45) { baseurl = temp.urlvrbrainv45.ToString(); } else if (board == BoardDetect.boards.vrbrainv50) { baseurl = temp.urlvrbrainv50.ToString(); } else if (board == BoardDetect.boards.vrbrainv51) { baseurl = temp.urlvrbrainv51.ToString(); } else if (board == BoardDetect.boards.vrbrainv52) { baseurl = temp.urlvrbrainv52.ToString(); } else if (board == BoardDetect.boards.vrherov10) { baseurl = temp.urlvrherov10.ToString(); } else if (board == BoardDetect.boards.vrubrainv51) { baseurl = temp.urlvrubrainv51.ToString(); } else if (board == BoardDetect.boards.vrubrainv52) { baseurl = temp.urlvrubrainv52.ToString(); } else if (board == BoardDetect.boards.vrgimbalv20) { baseurl = temp.urlvrgimbalv20.ToString(); } else if (board == BoardDetect.boards.vrugimbalv11) { baseurl = temp.urlvrugimbalv11.ToString(); } else { CustomMessageBox.Show(Strings.InvalidBoardType); return(false); } if (board < BoardDetect.boards.px4) { if (temp.name.ToLower().Contains("arducopter")) { CustomMessageBox.Show("This board has been retired, Mission Planner this will upload the last available version to your board", "Note"); } } if (historyhash != "") { baseurl = getUrl(historyhash, baseurl); } // update to use mirror url Localizations.ReplaceMirrorUrl(ref baseurl); log.Info("Using " + baseurl); // Create a request using a URL that can receive a post. WebRequest request = WebRequest.Create(baseurl); request.Timeout = 10000; // Set the Method property of the request to POST. request.Method = "GET"; // Get the request stream. Stream dataStream; //= request.GetRequestStream(); // Get the response. WebResponse response = request.GetResponse(); // Display the status. log.Info(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. dataStream = response.GetResponseStream(); long bytes = response.ContentLength; long contlen = bytes; byte[] buf1 = new byte[1024]; FileStream fs = new FileStream(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex", FileMode.Create); updateProgress(0, Strings.DownloadingFromInternet); dataStream.ReadTimeout = 30000; while (dataStream.CanRead) { try { updateProgress(50, Strings.DownloadingFromInternet); } catch { } int len = dataStream.Read(buf1, 0, 1024); if (len == 0) { break; } bytes -= len; fs.Write(buf1, 0, len); } fs.Close(); dataStream.Close(); response.Close(); updateProgress(100, Strings.DownloadedFromInternet); log.Info("Downloaded"); } catch (Exception ex) { updateProgress(50, Strings.FailedDownload); CustomMessageBox.Show("Failed to download new firmware : " + ex.ToString()); return(false); } MissionPlanner.Utilities.Tracking.AddFW(temp.name, board.ToString()); return(UploadFlash(comport, Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex", board)); }
void updateDisplayName(software temp) { if (temp.url.ToLower().Contains("firmware/AP-1".ToLower())) { lbl_AP.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/APHIL-".ToLower())) { lbl_APHil.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-quad-".ToLower())) { lbl_ACQuad.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-tri".ToLower())) { lbl_ACTri.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-hexa".ToLower())) { lbl_ACHexa.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-y6".ToLower())) { lbl_ACY6.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-heli-1".ToLower())) { lbl_Heli.Text = temp.name; } else if (temp.url.ToLower().Contains("firmware/ac2-quadhil".ToLower())) { lbl_ACHil.Text = temp.name; } else { Console.WriteLine("No Home "+ temp.name + " " + temp.url); } }