private void downloadsinglethread() { try { for (int i = 0; i < CHK_logs.CheckedItems.Count; ++i) { int a = (int)CHK_logs.CheckedItems[i]; { currentlog = a; System.Threading.Thread.Sleep(1100); comPort.Write("dump "); System.Threading.Thread.Sleep(100); comPort.Write(a.ToString() + "\r"); comPort.DiscardInBuffer(); status = serialstatus.Createfile; while (status != serialstatus.Done) { System.Threading.Thread.Sleep(100); } } } } catch (Exception ex) { CustomMessageBox.Show(ex.Message, "Error"); } }
private void downloadsinglethread() { try { for (int i = 0; i < CHK_logs.CheckedItems.Count; ++i) { int a = (int)CHK_logs.CheckedItems[i]; currentlog = a; var logname = GetLog((ushort)a); CreateLog(logname); if (chk_droneshare.Checked) { try { Utilities.DroneApi.droneshare.doUpload(logname); } catch (Exception ex) { CustomMessageBox.Show("Droneshare upload failed " + ex.ToString()); } } } status = serialstatus.Done; updateDisplay(); Console.Beep(); } catch (Exception ex) { CustomMessageBox.Show(ex.Message, "Error in log " + currentlog); } }
private void downloadsinglethread() { try { for (int i = 0; i < CHK_logs.CheckedItems.Count; ++i) { int a = (int)CHK_logs.CheckedItems[i]; currentlog = a; var logname = GetLog((ushort)a); CreateLog(logname); } status = serialstatus.Done; updateDisplay(); Console.Beep(); } catch (Exception ex) { CustomMessageBox.Show(ex.Message, "Error in log " + currentlog); } }
private void downloadthread(int startlognum, int endlognum) { try { for (int a = startlognum; a <= endlognum; a++) { currentlog = a; var logname = GetLog((ushort)a); CreateLog(logname); if (chk_droneshare.Checked) { try { Utilities.DroneApi.droneshare.doUpload(logname); } catch (Exception ex) { CustomMessageBox.Show("Droneshare upload failed " + ex.ToString()); } } } status = serialstatus.Done; updateDisplay(); Console.Beep(); } catch (Exception ex) { CustomMessageBox.Show(ex.Message, "Error in log " + currentlog); } }
private void Log_Load(object sender, EventArgs e) { if (!MainV2.comPort.BaseStream.IsOpen) { this.Close(); CustomMessageBox.Show("Please Connect"); return; } try { var list = MainV2.comPort.GetLogList(); foreach (var item in list) { genchkcombo(item.id); TXT_seriallog.AppendText(item.id + "\t" + new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(item.time_utc).ToLocalTime() + "\test size:\t" + item.size +"\r\n"); } if (list.Count == 0) { TXT_seriallog.AppendText("No logs to download"); } } catch { CustomMessageBox.Show(Strings.ErrorLogList, Strings.ERROR); this.Close(); } status = serialstatus.Done; }
private void downloadthread(int startlognum, int endlognum) { try { for (int a = startlognum; a <= endlognum; a++) { currentlog = a; System.Threading.Thread.Sleep(1100); comPort.Write("dump "); System.Threading.Thread.Sleep(100); comPort.Write(a.ToString() + "\r"); comPort.DiscardInBuffer(); status = serialstatus.Createfile; while (status != serialstatus.Done) { System.Threading.Thread.Sleep(100); } } Console.Beep(); } catch (Exception ex) { CustomMessageBox.Show(ex.Message, Strings.ERROR); } }
private void Log_Load(object sender, EventArgs e) { if (!MainV2.comPort.BaseStream.IsOpen) { this.Close(); CustomMessageBox.Show("Please Connect"); return; } try { var list = MainV2.comPort.GetLogList(); foreach (var item in list) { genchkcombo(item.id); TXT_seriallog.AppendText(item.id + "\t" + new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(item.time_utc).ToLocalTime() + "\test size:\t" + item.size + "\r\n"); } if (list.Count == 0) { TXT_seriallog.AppendText("No logs to download"); } } catch { CustomMessageBox.Show("Cannot get log list.", "Error"); this.Close(); } status = serialstatus.Done; }
void CreateLog(string logfile) { TextReader tr = new StreamReader(logfile); // this.Invoke((System.Windows.Forms.MethodInvoker) delegate() { TXT_seriallog.AppendText("Creating KML for " + logfile + "\n"); }); LogOutput lo = new LogOutput(); while (tr.Peek() != -1) { lo.processLine(tr.ReadLine()); } tr.Close(); try { lo.writeKML(logfile + ".kml"); } catch { } // usualy invalid lat long error status = serialstatus.Done; updateDisplay(); }
private void Log_Load(object sender, EventArgs e) { status = serialstatus.Connecting; comPort = MainV2.comPort.BaseStream; //comPort.ReceivedBytesThreshold = 50; //comPort.ReadBufferSize = 1024 * 1024; try { comPort.toggleDTR(); //comPort.Open(); } catch (Exception) { MessageBox.Show("Error opening comport"); } System.Threading.Thread t11 = new System.Threading.Thread(delegate() { DateTime start = DateTime.Now; threadrun = true; System.Threading.Thread.Sleep(2000); try { comPort.Write("\n\n\n\n"); } catch { } while (threadrun) { try { updateDisplay(); System.Threading.Thread.Sleep(10); if (!comPort.IsOpen) { break; } while (comPort.BytesToRead >= 4) { comPort_DataReceived((object)null, (SerialDataReceivedEventArgs)null); } } catch (Exception ex) { Console.WriteLine("crash in comport reader " + ex.ToString()); } // cant exit unless told to } Console.WriteLine("Comport thread close"); }); t11.Name = "comport reader"; t11.Start(); MainV2.threads.Add(t11); // doesnt seem to work on mac //comPort.DataReceived += new SerialDataReceivedEventHandler(comPort_DataReceived); }
string GetLog(ushort no) { MainV2.comPort.Progress += comPort_Progress; status = serialstatus.Reading; // get df log from mav var ms = MainV2.comPort.GetLog(no); status = serialstatus.Done; MainV2.comPort.Progress -= comPort_Progress; // set log fn byte[] hbpacket = MainV2.comPort.getHeartBeat(); MAVLink.mavlink_heartbeat_t hb = (MAVLink.mavlink_heartbeat_t)MainV2.comPort.DebugPacket(hbpacket); logfile = MainV2.LogDir + Path.DirectorySeparatorChar + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar + hbpacket[3] + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd HH-mm") + " " + no + ".bin"; // make log dir Directory.CreateDirectory(Path.GetDirectoryName(logfile)); // save memorystream to file using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(logfile))) { bw.Write(ms.ToArray()); } // read binary log to assci log var temp1 = Log.BinaryLog.ReadLog(logfile); // delete binary log file //File.Delete(logfile); logfile = logfile + ".log"; // write assci log File.WriteAllLines(logfile, temp1); // get gps time of assci log DateTime logtime = DFLog.GetFirstGpsTime(logfile); // rename log is we have a valid gps time if (logtime != DateTime.MinValue) { string newlogfilename = MainV2.LogDir + Path.DirectorySeparatorChar + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar + hbpacket[3] + Path.DirectorySeparatorChar + logtime.ToString("yyyy-MM-dd HH-mm") + ".log"; File.Move(logfile, newlogfilename); // rename bin as well File.Move(logfile.Replace(".log", ""), newlogfilename.Replace(".log", ".bin")); logfile = newlogfilename; } return(logfile); }
string GetLog(ushort no) { MainV2.comPort.Progress += comPort_Progress; status = serialstatus.Reading; // get df log from mav var ms = MainV2.comPort.GetLog(no); status = serialstatus.Done; updateDisplay(); MainV2.comPort.Progress -= comPort_Progress; // set log fn byte[] hbpacket = MainV2.comPort.getHeartBeat(); MAVLink.mavlink_heartbeat_t hb = (MAVLink.mavlink_heartbeat_t)MainV2.comPort.DebugPacket(hbpacket); logfile = MainV2.LogDir + Path.DirectorySeparatorChar + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar + hbpacket[3] + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + " " + no + ".bin"; // make log dir Directory.CreateDirectory(Path.GetDirectoryName(logfile)); // save memorystream to file using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(logfile))) { bw.Write(ms.ToArray()); } // create ascii log BinaryLog.ConvertBin(logfile, logfile + ".log"); //update the new filename logfile = logfile + ".log"; // get gps time of assci log DateTime logtime = DFLog.GetFirstGpsTime(logfile); // rename log is we have a valid gps time if (logtime != DateTime.MinValue) { string newlogfilename = MainV2.LogDir + Path.DirectorySeparatorChar + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar + hbpacket[3] + Path.DirectorySeparatorChar + logtime.ToString("yyyy-MM-dd HH-mm-ss") + ".log"; try { File.Move(logfile, newlogfilename); // rename bin as well File.Move(logfile.Replace(".log", ""), newlogfilename.Replace(".log", ".bin")); logfile = newlogfilename; } catch { CustomMessageBox.Show("Failed to rename file " + logfile + "\nto " + newlogfilename, "Error"); } } return(logfile); }
private void BUT_clearlogs_Click(object sender, EventArgs e) { System.Threading.Thread.Sleep(500); comPort.Write("erase\r"); System.Threading.Thread.Sleep(100); TXT_seriallog.AppendText("!!Allow 30 seconds for erase\n"); status = serialstatus.Done; }
private void bListLogs_Click(object sender, EventArgs e) { if (status == serialstatus.Connected) { serialPort1.Write("logs\r"); status = serialstatus.GetLogs; } }
private void bEraseLogs_Click(object sender, EventArgs e) { if (status == serialstatus.Connected) { cross = 0; serialPort1.Write("erase\r"); status = serialstatus.Erasing; } }
private void BUT_clearlogs_Click(object sender, EventArgs e) { try { MainV2.comPort.EraseLog(); TXT_seriallog.AppendText("!!Allow 30-90 seconds for erase\n"); status = serialstatus.Done; CHK_logs.Items.Clear(); } catch (Exception ex) { CustomMessageBox.Show(ex.Message, "Error"); } }
private void Log_Load(object sender, EventArgs e) { if (!MainV2.comPort.BaseStream.IsOpen) { this.Close(); CustomMessageBox.Show("Please Connect"); return; } try { var list = MainV2.comPort.GetLogList(); foreach (var item in list) { genchkcombo(item.id); TXT_seriallog.AppendText(item.id + "\t" + new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(item.time_utc).ToLocalTime() + "\test size:\t" + item.size + "\r\n"); //TXT_seriallog.AppendText(item.id + "\t" + new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(item.time_utc).ToLocalTime() + "\test size:\t" + item.size +"\r\n"); //if(item.size > 5000) //i it's at least 5 kB //{mi // genchkcombo(item.id); //add to list of downloads //} //else //{ } } if (list.Count == 0) { TXT_seriallog.AppendText("No logs to download"); } //for (int i = 0; i < CHK_logs.Items.Count; i ++) //check all the logs in the list //{ // CHK_logs.SetItemChecked(i, true); //} // status = serialstatus.Done; //BUT_DLthese.PerformClick(); //download the checked items // BUT_DLall.PerformClick(); } catch { CustomMessageBox.Show(Strings.ErrorLogList, Strings.ERROR); this.Close(); } status = serialstatus.Done; }
private void BUT_clearlogs_Click(object sender, EventArgs e) { try { System.Threading.Thread.Sleep(500); comPort.Write("erase\r"); System.Threading.Thread.Sleep(100); TXT_seriallog.AppendText("!!Allow 30-90 seconds for erase\n"); status = serialstatus.Done; CHK_logs.Items.Clear(); } catch (Exception ex) { CustomMessageBox.Show(ex.Message, "Error"); } }
private void BUT_clearlogs_Click(object sender, EventArgs e) { if (CustomMessageBox.Show("Are you sure?", "sure", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { try { MainV2.comPort.EraseLog(); TXT_seriallog.AppendText("!!Allow 30-90 seconds for erase\n"); status = serialstatus.Done; updateDisplay(); CHK_logs.Items.Clear(); } catch (Exception ex) { CustomMessageBox.Show(ex.Message, "Error"); } } }
private void downloadthread(int startlognum, int endlognum) { for (int a = startlognum; a <= endlognum; a++) { currentlog = a; System.Threading.Thread.Sleep(500); comPort.Write("dump "); System.Threading.Thread.Sleep(100); comPort.Write(a.ToString() + "\r"); status = serialstatus.Createfile; while (status != serialstatus.Done) { System.Threading.Thread.Sleep(100); } } }
private void bConnect_Click(object sender, EventArgs e) { if (!isConnected) { if (sSerialPortName == "") { return; } //if no port selected then do nothin' at connect //Assume that the selection in the combobox for port is still valid serialPort1.PortName = sSerialPortName; serialPort1.BaudRate = iSerialPortBaudrate; try { serialPort1.Open(); } catch { //WRONG, it seems that the combobox selection pointed to a port which is no longer available MessageBoxEx.Show(this, "Please check that your USB cable is still connected.\r\n", "Error opening COM port", MessageBoxButtons.OK, MessageBoxIcon.Error); return; //Exit without connecting; } //Set button text and status isConnected = true; System.Threading.Thread.Sleep(3000); status = serialstatus.Connecting; serialPort1.Write("+++"); //Try to enter command line mode bConnect.Text = "Disconnect"; UpdateDisplay(); } else { serialPort1.Write("exit\r"); bConnect.Text = "Connect"; //System.Threading.Thread.Sleep(500); serialPort1.Close(); isConnected = false; UpdateDisplay(); } }
private void downloadsinglethread() { for (int i = 0; i < CHK_logs.CheckedItems.Count; ++i) { int a = (int)CHK_logs.CheckedItems[i]; { currentlog = a; System.Threading.Thread.Sleep(500); comPort.Write("dump "); System.Threading.Thread.Sleep(100); comPort.Write(a.ToString() + "\r"); status = serialstatus.Createfile; while (status != serialstatus.Done) { System.Threading.Thread.Sleep(100); } } } }
private void downloadthread(int startlognum, int endlognum) { try { for (int a = startlognum; a <= endlognum; a++) { currentlog = a; var logname = GetLog((ushort)a); CreateLog(logname); } status = serialstatus.Done; updateDisplay(); Console.Beep(); } catch (Exception ex) { CustomMessageBox.Show(ex.Message, "Error in log " + currentlog); } }
private void downloadsinglethread() { for (int i = 0; i < chkList.CheckedItems.Count; i++) { int a = (int)chkList.CheckedItems[i]; { currentlog = a; //open file logfilename = sLogDirectory + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd HH-mm") + " " + currentlog + ".log"; file = new StreamWriter(logfilename); System.Threading.Thread.Sleep(500); serialPort1.Write("dump " + a.ToString() + "\r"); status = serialstatus.Downloading; System.Threading.Thread.Sleep(100); while (status != serialstatus.Connected) { System.Threading.Thread.Sleep(100); } file.Close(); file.Dispose(); } } }
private void Log_Load(object sender, EventArgs e) { //if (!MainV2.comPort.BaseStream.IsOpen) //{ // this.Close(); // CustomMessageBox.Show("Please Connect"); // return; //} if (!GCSMainForm.comPort.BaseStream.IsOpen) { this.Close(); CustomMessageBox.Show("请先连接"); return; } try { //var list = MainV2.comPort.GetLogList(); var list = GCSMainForm.comPort.GetLogList(); foreach (var item in list) { genchkcombo(item.id); TXT_seriallog.AppendText(item.id + "\t" + new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(item.time_utc).ToLocalTime() + "\test size:\t" + item.size + "\r\n"); } if (list.Count == 0) { TXT_seriallog.AppendText("æ— æ—¥å¿—"); } } catch { CustomMessageBox.Show(Strings.ErrorLogList, Strings.ERROR); this.Close(); } status = serialstatus.Done; }
private void downloadsinglethread() { try { for (int i = 0; i < CHK_logs.CheckedItems.Count; ++i) { int a = (int)CHK_logs.CheckedItems[i]; currentlog = a; var logname = GetLog((ushort)a); CreateLog(logname); if (chk_droneshare.Checked) { try { Utilities.DroneApi.droneshare.doUpload(logname); } catch (Exception ex) { CustomMessageBox.Show("Droneshare upload failed " + ex.ToString()); } } } status = serialstatus.Done; updateDisplay(); Console.Beep(); } catch (Exception ex) { CustomMessageBox.Show(ex.Message, "Error in log " + currentlog); } }
private void Log_Load(object sender, EventArgs e) { status = serialstatus.Connecting; comPort = MainV2.comPort.BaseStream; //comPort.ReceivedBytesThreshold = 50; //comPort.ReadBufferSize = 1024 * 1024; try { comPort.DtrEnable = false; System.Threading.Thread.Sleep(100); comPort.DtrEnable = true; //comPort.Open(); } catch (Exception) { MessageBox.Show("Error opening comport"); } System.Threading.Thread t11 = new System.Threading.Thread(delegate() { DateTime start = DateTime.Now; threadrun = true; System.Threading.Thread.Sleep(2000); try { comPort.Write("\n\n\n\n"); } catch { } while (threadrun) { try { updateDisplay(); System.Threading.Thread.Sleep(10); if (!comPort.IsOpen) break; while (comPort.BytesToRead >= 4) { comPort_DataReceived((object)null, (SerialDataReceivedEventArgs)null); } } catch (Exception ex) { Console.WriteLine("crash in comport reader " + ex.ToString()); } // cant exit unless told to } Console.WriteLine("Comport thread close"); }); t11.Name = "comport reader"; t11.Start(); MainV2.threads.Add(t11); // doesnt seem to work on mac //comPort.DataReceived += new SerialDataReceivedEventHandler(comPort_DataReceived); }
private void bConnect_Click(object sender, EventArgs e) { if (!isConnected) { if (sSerialPortName == "") { return; } //if no port selected then do nothin' at connect //Assume that the selection in the combobox for port is still valid serialPort1.PortName = sSerialPortName; serialPort1.BaudRate = iSerialPortBaudrate; try { serialPort1.Open(); } catch { //WRONG, it seems that the combobox selection pointed to a port which is no longer available MessageBoxEx.Show(this, "Please check that your USB cable is still connected.\r\n", "Error opening COM port", MessageBoxButtons.OK, MessageBoxIcon.Error); return; //Exit without connecting; } //Set button text and status isConnected = true; System.Threading.Thread.Sleep(3000); status = serialstatus.Connecting; serialPort1.Write("+++"); //Try to enter command line mode bConnect.Text = "Disconnect"; UpdateDisplay(); } else { serialPort1.Write("exit\r"); bConnect.Text = "Connect"; //System.Threading.Thread.Sleep(500); serialPort1.Close(); isConnected = false; UpdateDisplay(); } }
void CreateLog(string logfile) { TextReader tr = new StreamReader(logfile); // this.Invoke((System.Windows.Forms.MethodInvoker)delegate() { TXT_seriallog.AppendText("Creating KML for " + logfile + "\n"); }); LogOutput lo = new LogOutput(); while (tr.Peek() != -1) { lo.processLine(tr.ReadLine()); } tr.Close(); try { lo.writeKML(logfile + ".kml"); } catch { } // usualy invalid lat long error status = serialstatus.Done; updateDisplay(); }
string GetLog(ushort no) { log.Info("GetLog " + no); MainV2.comPort.Progress += comPort_Progress; status = serialstatus.Reading; // used for log fn byte[] hbpacket = MainV2.comPort.getHeartBeat(); if (hbpacket != null) log.Info("Got hbpacket length: " + hbpacket.Length); // get df log from mav using (var ms = MainV2.comPort.GetLog(no)) { ms.Seek(0, SeekOrigin.Begin); if (ms != null) log.Info("Got Log length: " + ms.Length); status = serialstatus.Done; updateDisplay(); MainV2.comPort.Progress -= comPort_Progress; MAVLink.mavlink_heartbeat_t hb = (MAVLink.mavlink_heartbeat_t) MainV2.comPort.DebugPacket(hbpacket); logfile = MainV2.LogDir + Path.DirectorySeparatorChar + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar + hbpacket[3] + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + " " + no + ".bin"; // make log dir Directory.CreateDirectory(Path.GetDirectoryName(logfile)); log.Info("about to write: " + logfile); // save memorystream to file using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(logfile))) { byte[] buffer = new byte[256*1024]; while (ms.Position < ms.Length) { int read = ms.Read(buffer, 0, buffer.Length); bw.Write(buffer, 0, read); } } } log.Info("about to convertbin: " + logfile); // create ascii log BinaryLog.ConvertBin(logfile, logfile + ".log"); //update the new filename logfile = logfile + ".log"; log.Info("about to GetFirstGpsTime: " + logfile); // get gps time of assci log DateTime logtime = new DFLog().GetFirstGpsTime(logfile); // rename log is we have a valid gps time if (logtime != DateTime.MinValue) { string newlogfilename = MainV2.LogDir + Path.DirectorySeparatorChar + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar + hbpacket[3] + Path.DirectorySeparatorChar + logtime.ToString("yyyy-MM-dd HH-mm-ss") + ".log"; try { File.Move(logfile, newlogfilename); // rename bin as well File.Move(logfile.Replace(".log", ""), newlogfilename.Replace(".log", ".bin")); logfile = newlogfilename; } catch { CustomMessageBox.Show(Strings.ErrorRenameFile + " " + logfile + "\nto " + newlogfilename, Strings.ERROR); } } return logfile; }
private void Log_Load(object sender, EventArgs e) { status = serialstatus.Connecting; comPort = MainV2.comPort.BaseStream; try { comPort.toggleDTR(); comPort.DiscardInBuffer(); // 10 sec waitandsleep(10000); } catch (Exception ex) { log.Error("Error opening comport", ex); CustomMessageBox.Show("Error opening comport"); } var t11 = new System.Threading.Thread(delegate() { var start = DateTime.Now; threadrun = true; readandsleep(100); try { comPort.Write("\n\n\n\n"); // more in "connecting" } catch { } while (threadrun) { try { updateDisplay(); System.Threading.Thread.Sleep(10); if (!comPort.IsOpen) { break; } while (comPort.BytesToRead >= 4) { comPort_DataReceived((object)null, (SerialDataReceivedEventArgs)null); } } catch (Exception ex) { log.Error("crash in comport reader " + ex); } // cant exit unless told to } log.Info("Comport thread close"); }) { Name = "comport reader" }; t11.Start(); // doesnt seem to work on mac //comPort.DataReceived += new SerialDataReceivedEventHandler(comPort_DataReceived); }
private void downloadthread(dltype type) { try { downloading = true; List<int> items = new List<int>(); switch(type) { case dltype.All: for (int i = 0; i < CHK_logs.Items.Count; ++i) items.Add((int)CHK_logs.Items[i]); break; case dltype.Selected: for (int i = 0; i < CHK_logs.CheckedItems.Count; ++i) items.Add((int)CHK_logs.CheckedItems[i]); break; case dltype.MinusOne: items.Add(-1); break; } for (int i = 0; i < items.Count; ++i) { currentlog = items[i]; comPort.Write("dump "); comPort.Write(items[i].ToString() + "\r"); log.Info("state ->Createfile\r"); status = serialstatus.Createfile; if (i==items.Count-1) downloading = false; while (status != serialstatus.Done && status != serialstatus.Error) { System.Threading.Thread.Sleep(10); } if (exitpending || status == serialstatus.Error) { downloading = false; return; } } Console.Beep(); } catch (Exception ex) { CustomMessageBox.Show(ex.Message, "Error in log " + currentlog); } }
private void downloadsinglethread() { try { for (int i = 0; i < CHK_logs.CheckedItems.Count; ++i) { int a = (int) CHK_logs.CheckedItems[i]; { currentlog = a; System.Threading.Thread.Sleep(1100); comPort.Write("dump "); System.Threading.Thread.Sleep(100); comPort.Write(a.ToString() + "\r"); comPort.DiscardInBuffer(); status = serialstatus.Createfile; while (status != serialstatus.Done) { System.Threading.Thread.Sleep(100); } } } Console.Beep(); } catch (Exception ex) { CustomMessageBox.Show(ex.Message, Strings.ERROR); } }
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e) { serialPort1.ReadTimeout = 500; while (serialPort1.BytesToRead > 0 && isConnected) { //updatedisplay line = ""; try { line = serialPort1.ReadLine(); //readline(comPort); if (!line.Contains("\n")) { line = line + "\n"; } } catch { line = serialPort1.ReadExisting(); //byte[] data = readline(comPort); //line = Encoding.ASCII.GetString(data, 0, data.Length); } receivedbytes += line.Length; if (line.Contains(">>>")) { // if (status == serialstatus.GetLogs) // { // if (logcount >= 1) genchkcombo(-1); // } status = serialstatus.Connected; } switch (status) { case serialstatus.Connecting: if (line.Contains(">>>")) { status = serialstatus.Connected; } break; case serialstatus.Erasing: cross++; break; case serialstatus.GetLogs: if (line.Contains("start") && line.Contains("end")) { Regex regex2 = new Regex(@"^Log ([0-9]+),", RegexOptions.IgnoreCase); if (regex2.IsMatch(line)) { MatchCollection matchs = regex2.Matches(line); logcount = int.Parse(matchs[0].Groups[1].Value); genchkcombo(logcount); //status = serialstatus.Done; } } break; case serialstatus.Downloading: file.Write(line); break; } this.Invoke(new EventHandler(DisplayText)); } }
private void Log_Load(object sender, EventArgs e) { log.Info("state ->Connecting\r"); status = serialstatus.Connecting; connect_substate = 0; comPort = GCSViews.Terminal.comPort; t11 = new System.Threading.Thread(delegate() { var start = DateTime.Now; bool threaderror = false; threadrun = true; try { comPort.Write("exit\rlogs\r"); // more in "connecting" } catch (Exception ex) { log.Info("state ->Error\r"); status = serialstatus.Error; log.Error("Error in comport thread " + ex); threaderror = true; } while (threadrun) { try { updateDisplay(); System.Threading.Thread.Sleep(1); while (comPort.BytesToRead > 0) { comPort_DataReceived((object)null, (SerialDataReceivedEventArgs)null); } } catch (Exception ex) { if (!threaderror) { log.Info("state ->Error\r"); status = serialstatus.Error; log.Error("Error in comport thread " + ex); threaderror = true; } } // cant exit unless told to } log.Info("Comport thread close"); }); t11.IsBackground = true; t11.Name = "Log serial thread"; t11.Start(); // doesnt seem to work on mac //comPort.DataReceived += new SerialDataReceivedEventHandler(comPort_DataReceived); }
private void downloadthread(int startlognum, int endlognum) { for (int a = startlognum; a <= endlognum; a++) { currentlog = a; System.Threading.Thread.Sleep(500); comPort.Write("dump "); System.Threading.Thread.Sleep(100); comPort.Write(a.ToString() + "\r"); status = serialstatus.Createfile; while (status != serialstatus.Done) { System.Threading.Thread.Sleep(100); } } }
void comPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { try { while (comPort.BytesToRead > 0 && threadrun) { updateDisplay(); string line = ""; comPort.ReadTimeout = 500; try { line = comPort.ReadLine(); //readline(comPort); if (!line.Contains("\n")) line = line + "\n"; } catch { line = comPort.ReadExisting(); //byte[] data = readline(comPort); //line = Encoding.ASCII.GetString(data, 0, data.Length); } receivedbytes += line.Length; //string line = Encoding.ASCII.GetString(data, 0, data.Length); switch (status) { case serialstatus.Connecting: if (line.Contains("ENTER") || line.Contains("GROUND START") || line.Contains("reset to FLY") || line.Contains("interactive setup") || line.Contains("CLI") || line.Contains("Ardu")) { try { comPort.Write("\n\n\n\n"); } catch { } comPort.Write("logs\r"); status = serialstatus.Done; } break; case serialstatus.Closefile: sw.Close(); TextReader tr = new StreamReader(logfile); this.Invoke((System.Windows.Forms.MethodInvoker)delegate() { TXT_seriallog.AppendText("Createing KML for " + logfile); }); while (tr.Peek() != -1) { processLine(tr.ReadLine()); } tr.Close(); try { writeKML(logfile + ".kml"); } catch { } // usualy invalid lat long error status = serialstatus.Done; break; case serialstatus.Createfile: receivedbytes = 0; Directory.CreateDirectory(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"logs"); logfile = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"logs" + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd HH-mm") + " " + currentlog + ".log"; sw = new StreamWriter(logfile); status = serialstatus.Waiting; lock (thisLock) { this.Invoke((System.Windows.Forms.MethodInvoker)delegate() { TXT_seriallog.Clear(); }); } //if (line.Contains("Dumping Log")) { status = serialstatus.Reading; } break; case serialstatus.Done: // if (line.Contains("start") && line.Contains("end")) { Regex regex2 = new Regex(@"^Log ([0-9]+),", RegexOptions.IgnoreCase); if (regex2.IsMatch(line)) { MatchCollection matchs = regex2.Matches(line); logcount = int.Parse(matchs[0].Groups[1].Value); genchkcombo(logcount); //status = serialstatus.Done; } } if (line.Contains("No logs")) { status = serialstatus.Done; } break; case serialstatus.Reading: if (line.Contains("packets read") || line.Contains("Done") || line.Contains("logs enabled")) { status = serialstatus.Closefile; break; } sw.Write(line); continue; case serialstatus.Waiting: if (line.Contains("Dumping Log") || line.Contains("GPS:") || line.Contains("NTUN:") || line.Contains("CTUN:") || line.Contains("PM:")) { status = serialstatus.Reading; } break; } lock (thisLock) { this.BeginInvoke((MethodInvoker)delegate() { Console.Write(line); TXT_seriallog.AppendText(line.Replace((char)0x0,' ')); // auto scroll if (TXT_seriallog.TextLength >= 10000) { TXT_seriallog.Text = TXT_seriallog.Text.Substring(TXT_seriallog.TextLength / 2); } TXT_seriallog.SelectionStart = TXT_seriallog.Text.Length; TXT_seriallog.ScrollToCaret(); TXT_seriallog.Refresh(); }); } } log.Info("exit while"); } catch (Exception ex) { CustomMessageBox.Show("Error reading data" + ex.ToString()); } }
private void downloadthread(dltype type) { try { List<int> items = new List<int>(); switch(type) { case dltype.All: for (int i = 0; i < CHK_logs.Items.Count; ++i) items.Add((int)CHK_logs.Items[i]); break; case dltype.Selected: for (int i = 0; i < CHK_logs.CheckedItems.Count; ++i) items.Add((int)CHK_logs.CheckedItems[i]); break; } for (int i = 0; i < items.Count; ++i) { currentlog = items[i]; var logname = GetLog((ushort)currentlog); CreateLog(logname); } status = serialstatus.Done; Console.Beep(); } catch (Exception ex) { CustomMessageBox.Show(ex.Message, "Error in log " + currentlog); } }
private void Log_Load(object sender, EventArgs e) { status = serialstatus.Connecting; comPort = GCSViews.Terminal.comPort; try { Console.WriteLine("Log_load " + comPort.IsOpen); if (!comPort.IsOpen) comPort.Open(); //Console.WriteLine("Log dtr"); //comPort.toggleDTR(); Console.WriteLine("Log discard"); comPort.DiscardInBuffer(); Console.WriteLine("Log w&sleep"); try { // try provoke a response comPort.Write("\n\n?\r\n\n"); } catch { } // 10 sec waitandsleep(10000); } catch (Exception ex) { log.Error("Error opening comport", ex); CustomMessageBox.Show("Error opening comport"); return; } var t11 = new System.Threading.Thread(delegate() { var start = DateTime.Now; threadrun = true; if (comPort.IsOpen) readandsleep(100); try { if (comPort.IsOpen) comPort.Write("\n\n\n\nexit\r\nlogs\r\n"); // more in "connecting" } catch { } while (threadrun) { try { updateDisplay(); System.Threading.Thread.Sleep(1); if (!comPort.IsOpen) break; while (comPort.BytesToRead >= 4) { comPort_DataReceived((object) null, (SerialDataReceivedEventArgs) null); } } catch (Exception ex) { log.Error("crash in comport reader " + ex); } // cant exit unless told to } log.Info("Comport thread close"); }) {Name = "comport reader", IsBackground = true}; t11.Start(); // doesnt seem to work on mac //comPort.DataReceived += new SerialDataReceivedEventHandler(comPort_DataReceived); }
void comPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { try { while (comPort.BytesToRead > 0 && threadrun) { updateDisplay(); string line = ""; comPort.ReadTimeout = 500; try { line = comPort.ReadLine(); if (!line.Contains("\n")) line = line + "\n"; } catch { line = comPort.ReadExisting(); } receivedbytes += line.Length; //string line = Encoding.ASCII.GetString(data, 0, data.Length); switch (status) { case serialstatus.Connecting: if (connect_substate==0 && line.Contains("] logs")) { connect_substate++; break; } if (connect_substate == 1 && line.Contains("Log]")) { connect_substate++; } if (connect_substate == 2) { // clear history this.BeginInvoke((System.Windows.Forms.MethodInvoker)delegate() { TXT_seriallog.Clear(); }); log.Info("state ->ReceiveListing\r"); status = serialstatus.ReceiveListing; } break; case serialstatus.Done: break; case serialstatus.Closefile: sw.Close(); DateTime logtime = DFLog.GetFirstGpsTime(logfile); if (logtime != DateTime.MinValue) { string newlogfilename = MainV2.LogDir + Path.DirectorySeparatorChar + logtime.ToString("yyyy-MM-dd HH-mm-ss") + ".log"; try { File.Move(logfile, newlogfilename); logfile = newlogfilename; } catch (Exception ex) { CustomMessageBox.Show("Failed to rename file " + logfile + "\nto " + newlogfilename,"Error"); } } CreateLog(logfile); log.Info("state ->ReceiveListing\r"); status = serialstatus.ReceiveListing; break; case serialstatus.Createfile: receivedbytes = 0; Directory.CreateDirectory(MainV2.LogDir); logfile = MainV2.LogDir + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + " " + currentlog + ".log"; sw = new StreamWriter(logfile); log.Info("state ->Reading\r"); status = serialstatus.Reading; break; case serialstatus.ReceiveListing: { Regex regex2 = new Regex(@"^Log ([0-9]+)[,\s]", RegexOptions.IgnoreCase); if (regex2.IsMatch(line)) { MatchCollection matchs = regex2.Matches(line); int lognr = int.Parse(matchs[0].Groups[1].Value); genchkcombo(lognr); } } if (line.Contains("Log]")) { log.Info("state ->Done\r"); status = serialstatus.Done; } break; case serialstatus.Reading: if (line.Contains("packets read") || line.Contains("Done") || line.Contains("logs enabled")) { log.Info("state ->Closefile\r"); status = serialstatus.Closefile; break; } sw.Write(line); continue; case serialstatus.Erasing: if (line.Contains("Log]")) { log.Info("state ->ReceiveListing\r"); status = serialstatus.ReceiveListing; } break; } setButtonState(status == serialstatus.Done && !downloading); lock (thisLock) { this.BeginInvoke((MethodInvoker)delegate() { Console.Write(line); TXT_seriallog.AppendText(line.Replace((char)0x0,' ')); // auto scroll if (TXT_seriallog.TextLength >= 50000) { TXT_seriallog.Text = TXT_seriallog.Text.Substring(TXT_seriallog.TextLength / 2); } TXT_seriallog.SelectionStart = TXT_seriallog.Text.Length; TXT_seriallog.ScrollToCaret(); TXT_seriallog.Refresh(); }); } } } catch (Exception ex) { //CustomMessageBox.Show("Error reading data" + ex.ToString()); } }
private void downloadthread(int startlognum, int endlognum) { try { for (int a = startlognum; a <= endlognum; a++) { currentlog = a; System.Threading.Thread.Sleep(1100); comPort.Write("dump "); System.Threading.Thread.Sleep(100); comPort.Write(a.ToString() + "\r"); comPort.DiscardInBuffer(); status = serialstatus.Createfile; while (status != serialstatus.Done) { System.Threading.Thread.Sleep(100); } } Console.Beep(); } catch (Exception ex) { CustomMessageBox.Show(ex.Message, Strings.ERROR); } }
private void Log_Load(object sender, EventArgs e) { if (MainV2.config["log_isarducopter"] != null) { CHK_arducopter.Checked = bool.Parse(MainV2.config["log_isarducopter"].ToString()); CHK_arduplane.Checked = bool.Parse(MainV2.config["log_isarduplane"].ToString()); CHK_ardurover.Checked = bool.Parse(MainV2.config["log_isardurover"].ToString()); } status = serialstatus.Connecting; MainV2.comPort.giveComport = true; comPort = MainV2.comPort.BaseStream; comPort.DtrEnable = false; comPort.RtsEnable = false; try { Console.WriteLine("Log_load " + comPort.IsOpen); if (!comPort.IsOpen) comPort.Open(); Console.WriteLine("Log dtr"); comPort.toggleDTR(); Console.WriteLine("Log discard"); comPort.DiscardInBuffer(); Console.WriteLine("Log w&sleep"); try { // try provoke a responce comPort.Write("\n\n?\r\n\n"); } catch { } // 10 sec waitandsleep(10000); } catch (Exception ex) { log.Error("Error opening comport", ex); CustomMessageBox.Show("Error opening comport"); } var t11 = new System.Threading.Thread(delegate() { var start = DateTime.Now; threadrun = true; readandsleep(100); try { comPort.Write("\n\n\n\nexit\r\nlogs\r\n"); // more in "connecting" } catch { } while (threadrun) { try { updateDisplay(); System.Threading.Thread.Sleep(10); if (!comPort.IsOpen) break; while (comPort.BytesToRead >= 4) { comPort_DataReceived((object)null, (SerialDataReceivedEventArgs)null); } } catch (Exception ex) { log.Error("crash in comport reader " + ex); } // cant exit unless told to } log.Info("Comport thread close"); }) {Name = "comport reader"}; t11.Start(); // doesnt seem to work on mac //comPort.DataReceived += new SerialDataReceivedEventHandler(comPort_DataReceived); }
private void BUT_clearlogs_Click(object sender, EventArgs e) { try { System.Threading.Thread.Sleep(500); comPort.Write("erase\r"); System.Threading.Thread.Sleep(100); TXT_seriallog.AppendText("!!Allow 30-90 seconds for erase\n"); status = serialstatus.Done; CHK_logs.Items.Clear(); } catch (Exception ex) { CustomMessageBox.Show(ex.Message, Strings.ERROR); } }
private void downloadthread(int startlognum, int endlognum) { try { for (int a = startlognum; a <= endlognum; a++) { currentlog = a; var logname = GetLog((ushort)a); CreateLog(logname); } status = serialstatus.Done; updateDisplay(); Console.Beep(); } catch (Exception ex) { CustomMessageBox.Show(ex.Message, "Error in log " + currentlog); } }
string GetLog(ushort no) { MainV2.comPort.Progress += comPort_Progress; status = serialstatus.Reading; // get df log from mav var ms = MainV2.comPort.GetLog(no); status = serialstatus.Done; updateDisplay(); MainV2.comPort.Progress -= comPort_Progress; // set log fn byte[] hbpacket = MainV2.comPort.getHeartBeat(); MAVLink.mavlink_heartbeat_t hb = (MAVLink.mavlink_heartbeat_t)MainV2.comPort.DebugPacket(hbpacket); logfile = MainV2.LogDir + Path.DirectorySeparatorChar + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar + hbpacket[3] + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + " " + no + ".bin"; // make log dir Directory.CreateDirectory(Path.GetDirectoryName(logfile)); // save memorystream to file using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(logfile))) { bw.Write(ms.ToArray()); } // read binary log to assci log var temp1 = Log.BinaryLog.ReadLog(logfile); // delete binary log file //File.Delete(logfile); logfile = logfile + ".log"; // write assci log using (StreamWriter sw = new StreamWriter(logfile)) { foreach (string line in temp1) { sw.Write(line); } sw.Close(); } // get gps time of assci log DateTime logtime = DFLog.GetFirstGpsTime(logfile); // rename log is we have a valid gps time if (logtime != DateTime.MinValue) { string newlogfilename = MainV2.LogDir + Path.DirectorySeparatorChar + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar + hbpacket[3] + Path.DirectorySeparatorChar + logtime.ToString("yyyy-MM-dd HH-mm-ss") + ".log"; try { File.Move(logfile, newlogfilename); // rename bin as well File.Move(logfile.Replace(".log", ""), newlogfilename.Replace(".log", ".bin")); logfile = newlogfilename; } catch (Exception ex) { CustomMessageBox.Show("Failed to rename file " + logfile + "\nto " + newlogfilename, "Error"); } } return logfile; }
private void downloadsinglethread() { try { for (int i = 0; i < CHK_logs.CheckedItems.Count; ++i) { int a = (int)CHK_logs.CheckedItems[i]; { currentlog = a; var logname = GetLog((ushort)a); CreateLog(logname); } } status = serialstatus.Done; updateDisplay(); Console.Beep(); } catch (Exception ex) { CustomMessageBox.Show(ex.Message, "Error in log " + currentlog); } }
string GetLog(ushort no) { log.Info("GetLog " + no); MainV2.comPort.Progress += comPort_Progress; status = serialstatus.Reading; // used for log fn byte[] hbpacket = MainV2.comPort.getHeartBeat(); if (hbpacket != null) { log.Info("Got hbpacket length: " + hbpacket.Length); } // get df log from mav using (var ms = MainV2.comPort.GetLog(no)) { ms.BaseStream.Seek(0, SeekOrigin.Begin); if (ms != null) { log.Info("Got Log length: " + ms.BaseStream.Length); } status = serialstatus.Done; updateDisplay(); MainV2.comPort.Progress -= comPort_Progress; MAVLink.mavlink_heartbeat_t hb = (MAVLink.mavlink_heartbeat_t)MainV2.comPort.DebugPacket(hbpacket); logfile = MainV2.LogDir + Path.DirectorySeparatorChar + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar + hbpacket[3] + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + " " + no + ".bin"; // make log dir Directory.CreateDirectory(Path.GetDirectoryName(logfile)); log.Info("about to write: " + logfile); // save memorystream to file using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(logfile))) { byte[] buffer = new byte[256 * 1024]; while (ms.BaseStream.Position < ms.BaseStream.Length) { int read = ms.BaseStream.Read(buffer, 0, buffer.Length); bw.Write(buffer, 0, read); } } } log.Info("about to convertbin: " + logfile); // create ascii log BinaryLog.ConvertBin(logfile, logfile + ".log"); //update the new filename logfile = logfile + ".log"; log.Info("about to GetFirstGpsTime: " + logfile); // get gps time of assci log DateTime logtime = new DFLog().GetFirstGpsTime(logfile); // rename log is we have a valid gps time if (logtime != DateTime.MinValue) { string newlogfilename = MainV2.LogDir + Path.DirectorySeparatorChar + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar + hbpacket[3] + Path.DirectorySeparatorChar + logtime.ToString("yyyy-MM-dd HH-mm-ss") + ".log"; try { File.Move(logfile, newlogfilename); // rename bin as well File.Move(logfile.Replace(".log", ""), newlogfilename.Replace(".log", ".bin")); logfile = newlogfilename; } catch { CustomMessageBox.Show(Strings.ErrorRenameFile + " " + logfile + "\nto " + newlogfilename, Strings.ERROR); } } return(logfile); }
private void Log_Load(object sender, EventArgs e) { if (MainV2.config["log_isarducopter"] != null) { CHK_arducopter.Checked = bool.Parse(MainV2.config["log_isarducopter"].ToString()); CHK_arduplane.Checked = bool.Parse(MainV2.config["log_isarduplane"].ToString()); CHK_ardurover.Checked = bool.Parse(MainV2.config["log_isardurover"].ToString()); } status = serialstatus.Connecting; MainV2.comPort.giveComport = true; comPort = MainV2.comPort.BaseStream; comPort.DtrEnable = false; comPort.RtsEnable = false; if (comPort.IsOpen) { comPort.Close(); } try { Console.WriteLine("Log_load " + comPort.IsOpen); // 4mb comPort.ReadBufferSize = 1024 * 1024 * 4; if (!comPort.IsOpen) { comPort.Open(); } Console.WriteLine("Log dtr"); comPort.toggleDTR(); Console.WriteLine("Log discard"); comPort.DiscardInBuffer(); Console.WriteLine("Log w&sleep"); try { // try provoke a responce comPort.Write("\n\n?\r\n\n"); } catch { } // 10 sec waitandsleep(10000); } catch (Exception ex) { log.Error("Error opening comport", ex); CustomMessageBox.Show("Error opening comport"); } var t11 = new System.Threading.Thread(delegate() { var start = DateTime.Now; threadrun = true; readandsleep(100); try { comPort.Write("\n\n\n\nexit\r\nlogs\r\n"); // more in "connecting" } catch { } while (threadrun) { try { updateDisplay(); System.Threading.Thread.Sleep(1); if (!comPort.IsOpen) { break; } while (comPort.BytesToRead >= 4) { comPort_DataReceived((object)null, (SerialDataReceivedEventArgs)null); } } catch (Exception ex) { log.Error("crash in comport reader " + ex); } // cant exit unless told to } log.Info("Comport thread close"); }) { Name = "comport reader", IsBackground = true }; t11.Start(); // doesnt seem to work on mac //comPort.DataReceived += new SerialDataReceivedEventHandler(comPort_DataReceived); }
string GetLog(ushort no) { MainV2.comPort.Progress += comPort_Progress; status = serialstatus.Reading; // get df log from mav var ms = MainV2.comPort.GetLog(no); status = serialstatus.Done; updateDisplay(); MainV2.comPort.Progress -= comPort_Progress; // set log fn byte[] hbpacket = MainV2.comPort.getHeartBeat(); MAVLink.mavlink_heartbeat_t hb = (MAVLink.mavlink_heartbeat_t)MainV2.comPort.DebugPacket(hbpacket); logfile = MainV2.LogDir + Path.DirectorySeparatorChar + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar + hbpacket[3] + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + " " + no + ".bin"; // make log dir Directory.CreateDirectory(Path.GetDirectoryName(logfile)); // save memorystream to file using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(logfile))) { bw.Write(ms.ToArray()); } // create ascii log BinaryLog.ConvertBin(logfile, logfile + ".log"); //update the new filename logfile = logfile + ".log"; // get gps time of assci log DateTime logtime = new DFLog().GetFirstGpsTime(logfile); // rename log is we have a valid gps time if (logtime != DateTime.MinValue) { string newlogfilename = MainV2.LogDir + Path.DirectorySeparatorChar + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar + hbpacket[3] + Path.DirectorySeparatorChar + logtime.ToString("yyyy-MM-dd HH-mm-ss") + ".log"; try { File.Move(logfile, newlogfilename); // rename bin as well File.Move(logfile.Replace(".log", ""), newlogfilename.Replace(".log", ".bin")); logfile = newlogfilename; } catch { CustomMessageBox.Show(Strings.ErrorRenameFile+ " " + logfile + "\nto " + newlogfilename, Strings.ERROR); } } return logfile; }
void comPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { try { while (comPort.BytesToRead > 0 && threadrun) { updateDisplay(); string line = ""; comPort.ReadTimeout = 500; try { line = comPort.ReadLine(); //readline(comPort); if (!line.Contains("\n")) { line = line + "\n"; } } catch { line = comPort.ReadExisting(); //byte[] data = readline(comPort); //line = Encoding.ASCII.GetString(data, 0, data.Length); } receivedbytes += line.Length; //string line = Encoding.ASCII.GetString(data, 0, data.Length); switch (status) { case serialstatus.Connecting: if (line.Contains("ENTER") || line.Contains("GROUND START") || line.Contains("reset to FLY") || line.Contains("interactive setup") || line.Contains("CLI") || line.Contains("Ardu")) { try { System.Threading.Thread.Sleep(200); comPort.Write("\n\n\n\n"); } catch { } System.Threading.Thread.Sleep(500); comPort.Write("logs\r"); status = serialstatus.Done; } break; case serialstatus.Closefile: sw.Close(); TextReader tr = new StreamReader(logfile); this.Invoke((System.Windows.Forms.MethodInvoker) delegate() { TXT_seriallog.AppendText("Creating KML for " + logfile); }); while (tr.Peek() != -1) { processLine(tr.ReadLine()); } tr.Close(); try { writeKML(logfile + ".kml"); } catch { } // usualy invalid lat long error status = serialstatus.Done; comPort.DiscardInBuffer(); break; case serialstatus.Createfile: receivedbytes = 0; Directory.CreateDirectory(MainV2.LogDir); logfile = MainV2.LogDir + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd HH-mm") + " " + currentlog + ".log"; sw = new StreamWriter(logfile); status = serialstatus.Waiting; lock (thisLock) { this.Invoke((System.Windows.Forms.MethodInvoker) delegate() { TXT_seriallog.Clear(); }); } //if (line.Contains("Dumping Log")) { status = serialstatus.Reading; } break; case serialstatus.Done: // // if (line.Contains("start") && line.Contains("end")) { Regex regex2 = new Regex(@"^Log ([0-9]+)[,\s]", RegexOptions.IgnoreCase); if (regex2.IsMatch(line)) { MatchCollection matchs = regex2.Matches(line); logcount = int.Parse(matchs[0].Groups[1].Value); genchkcombo(logcount); //status = serialstatus.Done; } } if (line.Contains("No logs")) { status = serialstatus.Done; } break; case serialstatus.Reading: if (line.Contains("packets read") || line.Contains("Done") || line.Contains("logs enabled")) { status = serialstatus.Closefile; Console.Write("CloseFile: " + line); break; } sw.Write(line); continue; case serialstatus.Waiting: if (line.Contains("Dumping Log") || line.Contains("GPS:") || line.Contains("NTUN:") || line.Contains("CTUN:") || line.Contains("PM:")) { status = serialstatus.Reading; Console.Write("Reading: " + line); } break; } lock (thisLock) { this.BeginInvoke((MethodInvoker) delegate() { Console.Write(line); TXT_seriallog.AppendText(line.Replace((char)0x0, ' ')); // auto scroll if (TXT_seriallog.TextLength >= 10000) { TXT_seriallog.Text = TXT_seriallog.Text.Substring(TXT_seriallog.TextLength / 2); } TXT_seriallog.SelectionStart = TXT_seriallog.Text.Length; TXT_seriallog.ScrollToCaret(); TXT_seriallog.Refresh(); }); } } //log.Info("exit while"); } catch (Exception ex) { CustomMessageBox.Show("Error reading data" + ex.ToString()); } }
private void downloadthread(int startlognum, int endlognum) { try { for (int a = startlognum; a <= endlognum; a++) { currentlog = a; var logname = GetLog((ushort)a); CreateLog(logname); if (chk_droneshare.Checked) { try { Utilities.DroneApi.droneshare.doUpload(logname); } catch (Exception ex) { CustomMessageBox.Show("Droneshare upload failed " + ex.ToString()); } } } status = serialstatus.Done; updateDisplay(); Console.Beep(); } catch (Exception ex) { CustomMessageBox.Show(ex.Message, "Error in log " + currentlog); } }
private void Log_Load(object sender, EventArgs e) { if (!MainV2.comPort.BaseStream.IsOpen) { this.Close(); CustomMessageBox.Show("Please Connect"); return; } try { var list = MainV2.comPort.GetLogList(); foreach (var item in list) { genchkcombo(item.id); TXT_seriallog.AppendText(item.id + " " + new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(item.time_utc).ToLocalTime() + " est size: " + item.size +"\n"); } } catch { CustomMessageBox.Show("Cannot get log list.","Error"); this.Close(); } status = serialstatus.Done; }
private void BUT_clearlogs_Click(object sender, EventArgs e) { if (CustomMessageBox.Show("Are you sure?", "sure", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { try { MainV2.comPort.EraseLog(); TXT_seriallog.AppendText("!!Allow 30-90 seconds for erase\n"); status = serialstatus.Done; updateDisplay(); CHK_logs.Items.Clear(); } catch (Exception ex) { CustomMessageBox.Show(ex.Message, Strings.ERROR); } } }
private void BUT_clearlogs_Click(object sender, EventArgs e) { try { MainV2.comPort.EraseLog(); TXT_seriallog.AppendText("!!Allow 30-90 seconds for erase\n"); status = serialstatus.Done; CHK_logs.Items.Clear(); } catch (Exception ex) { CustomMessageBox.Show(ex.Message, "Error"); } }
private void BUT_clearlogs_Click(object sender, EventArgs e) { System.Threading.Thread.Sleep(500); comPort.Write("erase\r"); System.Threading.Thread.Sleep(100); TXT_seriallog.AppendText("!!Allow 30-90 seconds for erase\n"); status = serialstatus.Done; CHK_logs.Items.Clear(); }
string GetLog(ushort no) { MainV2.comPort.Progress += comPort_Progress; status = serialstatus.Reading; // get df log from mav var ms = MainV2.comPort.GetLog(no); status = serialstatus.Done; MainV2.comPort.Progress -= comPort_Progress; // set log fn byte[] hbpacket = MainV2.comPort.getHeartBeat(); MAVLink.mavlink_heartbeat_t hb = (MAVLink.mavlink_heartbeat_t)MainV2.comPort.DebugPacket(hbpacket); logfile = MainV2.LogDir + Path.DirectorySeparatorChar + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar + hbpacket[3] + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd HH-mm") + " " + currentlog + ".bin"; // make log dir Directory.CreateDirectory(Path.GetDirectoryName(logfile)); // save memorystream to file using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(logfile))) { bw.Write(ms.ToArray()); } // read binary log to assci log var temp1 = Log.BinaryLog.ReadLog(logfile); // delete binary log file //File.Delete(logfile); logfile = logfile + ".log"; // write assci log File.WriteAllLines(logfile, temp1); // get gps time of assci log DateTime logtime = DFLog.GetFirstGpsTime(logfile); // rename log is we have a valid gps time if (logtime != DateTime.MinValue) { string newlogfilename = MainV2.LogDir + Path.DirectorySeparatorChar + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar + hbpacket[3] + Path.DirectorySeparatorChar + logtime.ToString("yyyy-MM-dd HH-mm") + ".log"; File.Move(logfile, newlogfilename); // rename bin as well File.Move(logfile.Replace(".log", ""), newlogfilename.Replace(".log", ".bin")); logfile = newlogfilename; } return logfile; }
private void downloadsinglethread() { for (int i = 0; i < CHK_logs.CheckedItems.Count; ++i) { int a = (int)CHK_logs.CheckedItems[i]; { currentlog = a; System.Threading.Thread.Sleep(500); comPort.Write("dump "); System.Threading.Thread.Sleep(100); comPort.Write(a.ToString() + "\r"); status = serialstatus.Createfile; while (status != serialstatus.Done) { System.Threading.Thread.Sleep(100); } } } }
private void Log_Load(object sender, EventArgs e) { if (!MainV2.comPort.BaseStream.IsOpen) { this.Close(); CustomMessageBox.Show("Please Connect"); return; } var list = MainV2.comPort.GetLogList(); foreach (var item in list) { genchkcombo(item.id); } status = serialstatus.Done; }
private void Log_Load(object sender, EventArgs e) { status = serialstatus.Connecting; comPort = MainV2.comPort.BaseStream; //comPort.ReceivedBytesThreshold = 50; //comPort.ReadBufferSize = 1024 * 1024; try { comPort.toggleDTR(); //comPort.Open(); } catch (Exception ex) { log.Error("Error opening comport", ex); CustomMessageBox.Show("Error opening comport"); } var t11 = new System.Threading.Thread(delegate() { var start = DateTime.Now; threadrun = true; System.Threading.Thread.Sleep(2000); try { comPort.Write("\n\n\n\n"); // more in "connecting" } catch { } while (threadrun) { try { updateDisplay(); System.Threading.Thread.Sleep(10); if (!comPort.IsOpen) break; while (comPort.BytesToRead >= 4) { comPort_DataReceived((object)null, (SerialDataReceivedEventArgs)null); } } catch (Exception ex) { log.Error("crash in comport reader " + ex); } // cant exit unless told to } log.Info("Comport thread close"); }) {Name = "comport reader"}; t11.Start(); // doesnt seem to work on mac //comPort.DataReceived += new SerialDataReceivedEventHandler(comPort_DataReceived); }
private void Log_Load(object sender, EventArgs e) { status = serialstatus.Connecting; comPort = GCSViews.Terminal.comPort; try { Console.WriteLine("Log_load " + comPort.IsOpen); if (!comPort.IsOpen) { comPort.Open(); } //Console.WriteLine("Log dtr"); //comPort.toggleDTR(); Console.WriteLine("Log discard"); comPort.DiscardInBuffer(); Console.WriteLine("Log w&sleep"); try { // try provoke a response comPort.Write("\n\n?\r\n\n"); } catch { } // 10 sec waitandsleep(10000); } catch (Exception ex) { log.Error("Error opening comport", ex); CustomMessageBox.Show("Error opening comport"); return; } var t11 = new System.Threading.Thread(delegate() { var start = DateTime.Now; threadrun = true; if (comPort.IsOpen) { readandsleep(100); } try { if (comPort.IsOpen) { comPort.Write("\n\n\n\nexit\r\nlogs\r\n"); // more in "connecting" } } catch { } while (threadrun) { try { updateDisplay(); System.Threading.Thread.Sleep(1); if (!comPort.IsOpen) { break; } while (comPort.BytesToRead >= 4) { comPort_DataReceived((object)null, (SerialDataReceivedEventArgs)null); } } catch (Exception ex) { log.Error("crash in comport reader " + ex); } // cant exit unless told to } log.Info("Comport thread close"); }) { Name = "comport reader", IsBackground = true }; t11.Start(); // doesnt seem to work on mac //comPort.DataReceived += new SerialDataReceivedEventHandler(comPort_DataReceived); }