Beispiel #1
0
        private void LoadCheckedList()
        {
            if (logEntries != null)
            {
                foreach (var item in logEntries)
                {
                    try
                    {
                        string caption = item.Name + " " + GetItemCaption(item) + "  (" + item.Length + ")";
                        AddCheckedListBoxItem(caption);
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                    }
                }

                if (logEntries.Count == 0)
                {
                    AppendSerialLog(LogStrings.NoLogsFound);
                }
                else
                {
                    AppendSerialLog(string.Format(LogStrings.SomeLogsFound, logEntries.Count));
                }
            }
            status = SerialStatus.Done;
        }
        private void FindDuplicates()
        {
            ConsoleKey keyinput = ConsoleKey.Enter;

            Console.WriteLine();
            Console.WriteLine("Beginning Reading");
            Console.WriteLine("Press any Key to Read Tag, Escape to Cancel");
            Console.WriteLine();


            do
            {
                string[] serialNumbers;

                try
                {
                    serialNumbers = _controller.TagInventory();
                }
                catch (Exception ex)
                {
                    Display.WriteError(ex.Message);
                    keyinput = ConsoleKey.Escape;
                    continue;
                }

                if (serialNumbers.Length <= 0)
                {
                    Display.WriteError("No Tag Found");
                }

                if (serialNumbers.Length > 1)
                {
                    Display.WriteError("More than 1 tag in Reader Field");
                }

                if (serialNumbers.Length == 1)
                {
                    for (int i = 0; i < serialNumbers.Length; i++)
                    {
                        SerialStatus status = SerialNumberList.Add(serialNumbers[i]);

                        switch (status)
                        {
                        case SerialStatus.Added:
                            Display.WriteInformation($"Successfully Added {serialNumbers[i]} to list");
                            break;

                        case SerialStatus.AlreadyExists:
                            Display.WriteError($"{serialNumbers[i]} ALREADY EXISTS");
                            break;

                        default:
                            break;
                        }
                    }
                }

                keyinput = Console.ReadKey().Key;
            } while (keyinput != ConsoleKey.Escape);
        }
Beispiel #3
0
        private void BUT_clearlogs_Click(object sender, EventArgs e)
        {
            if (CustomMessageBox.Show(LogStrings.Confirmation, "sure", MessageBoxButtons.YesNo) ==
                (int)System.Windows.Forms.DialogResult.Yes)
            {
                try
                {
                    SftpClient sshclient = new SftpClient(_connectionInfo);
                    sshclient.Connect();

                    foreach (var logEntry in logEntries)
                    {
                        sshclient.DeleteFile(logEntry.FullName);
                    }

                    sshclient.Disconnect();

                    AppendSerialLog(LogStrings.EraseComplete);
                    status = SerialStatus.Done;
                    CHK_logs.Items.Clear();
                }
                catch (Exception ex)
                {
                    CustomMessageBox.Show(ex.Message, Strings.ERROR);
                }
            }
        }
        private void LoadCheckedList()
        {
            if (logEntries != null)
            {
                foreach (var item in logEntries)
                {
                    try
                    {
                        string sizeMB  = ((float)item.size / 1024 / 1024).ToString("0.00");
                        string caption = item.id + " " + GetItemCaption(item) + "  (" + sizeMB + " MB)";
                        AddCheckedListBoxItem(caption);
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                    }
                }

                if (logEntries.Count == 0)
                {
                    AppendSerialLog(LogStrings.NoLogsFound);
                }
                else
                {
                    AppendSerialLog(string.Format(LogStrings.SomeLogsFound, logEntries.Count));
                    AppendSerialLog("\n=================================================");
                }
            }
            status = SerialStatus.Done;
        }
        void CreateLog(string logfile)
        {
            TextReader tr = new StreamReader(logfile);

            //
            AppendSerialLog(string.Format(LogStrings.CreatingKmlPrompt, Path.GetFileName(logfile)));

            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;
        }
Beispiel #6
0
 /// <summary>
 /// A board with Uduino is found
 /// </summary>
 public void UduinoFound()
 {
     serialStatus = SerialStatus.FOUND;
     #if UNITY_EDITOR
     if (Application.isPlaying)
     {
         EditorUtility.SetDirty(UduinoManager.Instance);
     }
     #endif
 }
        private void DownloadThread(int[] selectedLogs)
        {
            try
            {
                status = SerialStatus.Reading;

                totalBytes    = 0;
                tallyBytes    = 0;
                receivedbytes = 0;
                foreach (int a in selectedLogs)
                {
                    currentlog = a;
                    var entry = logEntries[a]; // mavlink_log_entry_t
                    totalBytes += entry.size;
                }

                UpdateProgress(0, totalBytes, 0);
                foreach (int a in selectedLogs)
                {
                    currentlog = a;

                    var    entry    = logEntries[a]; // mavlink_log_entry_t
                    string fileName = GetItemCaption(entry);

                    AppendSerialLog(string.Format(LogStrings.FetchingLog, fileName));

                    var logname = GetLog(entry.id, fileName);

                    CreateLog(logname);

                    tallyBytes   += receivedbytes;
                    receivedbytes = 0;
                    UpdateProgress(0, totalBytes, tallyBytes);
                }

                UpdateProgress(0, totalBytes, totalBytes);

                AppendSerialLog("Download complete.");
                Console.Beep();
            }
            catch (Exception ex)
            {
                AppendSerialLog("Error in log " + currentlog + ": " + ex.Message);
            }

            RunOnUIThread(() =>
            {
                BUT_DLall.Enabled   = true;
                BUT_DLthese.Enabled = true;
                status = SerialStatus.Done;
            });
        }
Beispiel #8
0
 /// <summary>
 /// Close Serial port
 /// </summary>
 public void Close()
 {
     if (serial != null && serial.IsOpen)
     {
         Log.Warning("Closing port : <color=#2196F3>[" + _port + "]</color>");
         serial.Close();
         serialStatus = SerialStatus.CLOSE;
         serial       = null;
     }
     else
     {
         Log.Warning(_port + " already closed.");
     }
 }
Beispiel #9
0
        public  int write_deal() //should     public new int write_deal() 
        {
          //  if (data_type == 0)  write_byte_count = write_message.Length;
          if(cdata.s_len>0)
            {
                cdata.copy(cdata.s_buffer, this.write_buffer, cdata.s_len, Cdata.buf_len, Cserial.buffer_len);
                this.write_byte_count = cdata.s_len;
                this.total_read_count+= (ulong)this.write_byte_count;
                this.data_type = 1;//not string
                cdata.s_len = 0;
                this.strart_write = true;
                this.write_status = SerialStatus.InWrite;
                return 0;
            }

            return -1;
        }
 private void BUT_clearlogs_Click(object sender, EventArgs e)
 {
     if (CustomMessageBox.Show(LogStrings.Confirmation, "sure", MessageBoxButtons.YesNo) ==
         System.Windows.Forms.DialogResult.Yes)
     {
         try
         {
             MainV2.comPort.EraseLog();
             AppendSerialLog(LogStrings.EraseComplete);
             status = SerialStatus.Done;
             CHK_logs.Items.Clear();
         }
         catch (Exception ex)
         {
             CustomMessageBox.Show(ex.Message, Strings.ERROR);
         }
     }
 }
Beispiel #11
0
        /// <summary>
        /// Close Serial port
        /// </summary>
        public void Close()
        {
            WriteToArduinoLoop();

            readQueue.Clear();
            writeQueue.Clear();
            messagesToRead.Clear();

            if (serial != null && serial.IsOpen)
            {
                Log.Warning("Closing port : <color=#2196F3>[" + _port + "]</color>");
                serial.Close();
                serialStatus = SerialStatus.CLOSE;
                serial       = null;
            }
            else
            {
                Log.Info(_port + " already closed.");
            }
        }
Beispiel #12
0
 /// <summary>
 /// Open a specific serial port
 /// </summary>
 public void Open()
 {
     try
     {
         #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
         _port = "\\\\.\\" + _port;
         #endif
         serial              = new SerialPort(_port, _baudrate, Parity.None, 8, StopBits.One);
         serial.ReadTimeout  = 100;
         serial.WriteTimeout = 100;
         serial.Close();
         serial.Open();
         serialStatus = SerialStatus.OPEN;
         Log.Warning("Opening stream on port <color=#2196F3>[" + _port + "]</color>");
     }
     catch (Exception e)
     {
         Log.Error("Error on port <color=#2196F3>[" + _port + "]</color> : " + e);
         serialStatus = SerialStatus.CLOSE;
     }
 }
        // AB ZhaoYJ@2017-02-23 for user-defined dir to save log
        // private void DownloadThread(int[] selectedLogs)
        private void DownloadThread(int[] selectedLogs, string save_path)
        {
            try
            {
                status = SerialStatus.Reading;

                totalBytes = 0;
                tallyBytes = 0;
                // receivedbytes = 0;

                foreach (int a in selectedLogs)
                {
                    var entry = logEntries[a]; // mavlink_log_entry_t
                    totalBytes += entry.size;
                }

                // string[] nameParts = fileName.Split(' ', '-', ':', '/');

                // string save_file = @save_path + "1.bin";

                UpdateProgress(0, totalBytes, 0);

                // AB ZhaoYJ@2017-02-23 for user-defined dir to save log
                // download log files via SFTP, remove mavlink downloader because its slow speed
                // ========= start ==========
                try
                {
                    //string host = "192.168.7.2";
                    //string user = "******";
                    //string pass = "******";

                    string host = "11.0.0.1";
                    string user = "******";
                    string pass = "******";

                    Sftp sftp = new Sftp(host, user);
                    sftp.Password = pass;
                    sftp.Connect();

                    string path = "/var/APM/logs/";

                    foreach (int a in selectedLogs)
                    {
                        var entry = logEntries[a]; // mavlink_log_entry_t

                        DateTime fileDate = GetItemCaption(entry);

                        // string[] nameParts = fileName.Split(' ', '-', ':', '/');

                        AppendSerialLog(string.Format(LogStrings.FetchingLog, fileDate.ToString()));

                        string save_file = @save_path + "\\" + "[飞行日志]" + fileDate.Year + "年" + fileDate.Month + "月" + fileDate.Day + "日" + fileDate.Hour + "时" +
                                           fileDate.Minute + "分" + fileDate.Second + "秒" + ".BIN";
                        // string save_file = @save_path + "1.bin";

                        try
                        {
                            sftp.Get(path + entry.id.ToString() + ".BIN", save_file);
                        }
                        catch (Exception ex)
                        {
                            CustomMessageBox.Show("日志文件 [" + entry.id.ToString() + " " + fileDate + "] 可能已不存在,请重新刷新日志列表", Strings.ERROR);
                        }
                        // var logname = GetLog(entry.id, fileName);
                        // CreateLog(logname);

                        tallyBytes += logEntries[a].size;
                        // receivedbytes = 0;
                        UpdateProgress(0, totalBytes, tallyBytes);
                    }
                    sftp.Close();
                    CustomMessageBox.Show("日志文件下载成功", Strings.Done);
                }
                catch (Exception ex)
                {
                    CustomMessageBox.Show(ex.Message, Strings.ERROR);
                }
                // ========= end ==========


                UpdateProgress(0, totalBytes, totalBytes);
                AppendSerialLog("=================================================");

                AppendSerialLog("\n所有日志文件下载成功.");
                Console.Beep();
            }
            catch (Exception ex)
            {
                AppendSerialLog("Error in log " + ex.Message);
            }

            RunOnUIThread(() =>
            {
                BUT_DLall.Enabled   = true;
                BUT_DLthese.Enabled = true;
                status = SerialStatus.Done;
            });
        }
Beispiel #14
0
        async Task <string> GetLog(ushort no, string fileName)
        {
            log.Info("GetLog " + no);

            MainV2.comPort.Progress += ComPort_Progress;

            status = SerialStatus.Reading;

            // get df log from mav
            var fn = await MainV2.comPort.GetLog(MainV2.comPort.MAV.sysid, MainV2.comPort.MAV.compid, no)
                     .ConfigureAwait(false);

            GC.Collect();
            status = SerialStatus.Done;

            logfile = Settings.Instance.LogDir + Path.DirectorySeparatorChar
                      + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar
                      + MainV2.comPort.MAV.sysid + Path.DirectorySeparatorChar + no + " " +
                      MakeValidFileName(fileName) + ".bin";

            // make log dir
            Directory.CreateDirectory(Path.GetDirectoryName(logfile));

            log.Info("about to move " + fn + " to: " + logfile);
            try
            {
                File.Move(fn, logfile);
            }
            catch
            {
                CustomMessageBox.Show(Strings.ErrorRenameFile + " " + logfile + "\nto " + logfile,
                                      Strings.ERROR);
            }

            // rename file if needed
            log.Info("about to GetFirstGpsTime: " + logfile);
            // get gps time of assci log
            var      dflb    = new DFLogBuffer(logfile);
            DateTime logtime = dflb.dflog.gpsstarttime;

            dflb.Clear();
            GC.Collect();

            // rename log is we have a valid gps time
            if (logtime != DateTime.MinValue)
            {
                string newlogfilename = Settings.Instance.LogDir + Path.DirectorySeparatorChar
                                        + MainV2.comPort.MAV.aptype.ToString() +
                                        Path.DirectorySeparatorChar
                                        + MainV2.comPort.MAV.sysid +
                                        Path.DirectorySeparatorChar +
                                        logtime.ToString("yyyy-MM-dd HH-mm-ss") + ".bin";
                try
                {
                    File.Move(logfile, newlogfilename);
                    logfile = newlogfilename;
                }
                catch
                {
                    CustomMessageBox.Show(Strings.ErrorRenameFile + " " + logfile + "\nto " + newlogfilename,
                                          Strings.ERROR);
                }
            }

            MainV2.comPort.Progress -= ComPort_Progress;

            return(logfile);
        }
        string GetLog(ushort no, string fileName)
        {
            log.Info("GetLog " + no);

            MainV2.comPort.Progress += comPort_Progress;

            status = SerialStatus.Reading;

            // used for log fn
            MAVLink.MAVLinkMessage 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))
            {
                if (ms != null)
                {
                    log.Info("Got Log length: " + ms.Length);
                }

                ms.Seek(0, SeekOrigin.Begin);

                status = SerialStatus.Done;

                MAVLink.mavlink_heartbeat_t hb = (MAVLink.mavlink_heartbeat_t)MainV2.comPort.DebugPacket(hbpacket);

                logfile = Settings.Instance.LogDir + Path.DirectorySeparatorChar
                          + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar
                          + hbpacket.sysid + Path.DirectorySeparatorChar + no + " " + MakeValidFileName(fileName) + ".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";

            // rename file if needed
            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 = Settings.Instance.LogDir + Path.DirectorySeparatorChar
                                        + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar
                                        + hbpacket.sysid + 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);
                }
            }

            MainV2.comPort.Progress -= comPort_Progress;

            return(logfile);
        }
Beispiel #16
0
 public void Stopping()
 {
     WriteToArduino("disconnected", instant: true);
     serialStatus = SerialStatus.STOPPING;
 }
Beispiel #17
0
        public  void Write()
        {
            if (debug) Console.WriteLine("Cserial:Write()\n");
            System.Threading.Thread.Sleep(1);//wait and for other
            this.write_status = SerialStatus.WriteStart;
            while (Cserial._continue)
            {

                write_deal();
                
                if (!strart_write)
                {
                    System.Threading.Thread.Sleep(1);//wait and free cpu
                    continue;//wait;
                }

                if(data_type ==0) 
                {
                    _serialPort.WriteLine(write_message);
                    write_message = "";
                }

                if (data_type != 0 && write_byte_count > 0)
                {
                    try
                    {
                        _serialPort.Write(write_buffer, 0, write_byte_count);
                        this.write_status = SerialStatus.WriteDone;
                        this.build_s_write_buf(write_buffer, write_byte_count);
                        this.check_and_post(this.s_write_buf);//post main thread
                        if (this.debug) Console.WriteLine(" Write()" + this.s_write_buf);
                    }
                    catch (ArgumentNullException)
                    {
                        if (this.debug) Console.WriteLine("catch(ArgumentNullException)");
                    }
                    catch (InvalidOperationException)
                    {
                        if (this.debug) Console.WriteLine("catch(InvalidOperationException)");
                        break;
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        if (this.debug) Console.WriteLine("catch(ArgumentOutOfRangeException)");
                    }
                    catch (ArgumentException)
                    {
                        if (this.debug) Console.WriteLine("catch(ArgumentException)");
                    }
                    catch (TimeoutException)
                    {
                        if (this.debug) Console.WriteLine("catch(TimeoutException)");
                    }
                    catch (Exception e)
                    {
                        if (this.debug) Console.WriteLine("catch(Exception)"+e.ToString());
                    }
                                    
                    write_byte_count = 0;
                }
                strart_write = false;//write end
            }
            this.write_status = SerialStatus.WriteEnd;
        }
        string GetLog(ushort no, string fileName)
        {
            log.Info("GetLog " + no);

            MainV2.comPort.Progress += comPort_Progress;

            status = SerialStatus.Reading;

            // used for log fn
            MAVLink.MAVLinkMessage 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))
            {
                if (ms != null)
                    log.Info("Got Log length: " + ms.Length);

                ms.Seek(0, SeekOrigin.Begin);

                status = SerialStatus.Done;

                MAVLink.mavlink_heartbeat_t hb = (MAVLink.mavlink_heartbeat_t)MainV2.comPort.DebugPacket(hbpacket);

                logfile = Settings.Instance.LogDir + Path.DirectorySeparatorChar
                          + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar
                          + hbpacket.sysid + Path.DirectorySeparatorChar + no + " " + MakeValidFileName(fileName) + ".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";

            // rename file if needed
            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 = Settings.Instance.LogDir + Path.DirectorySeparatorChar
                                        + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar
                                        + hbpacket.sysid + 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);
                }
            }

            MainV2.comPort.Progress -= comPort_Progress;

            return logfile;
        }
        string GetLog(ushort no, string fileName)
        {
            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))
            {
                if (ms != null)
                {
                    log.Info("Got Log length: " + ms.Length);
                }

                ms.Seek(0, SeekOrigin.Begin);

                status = SerialStatus.Done;

                MAVLink.mavlink_heartbeat_t hb = (MAVLink.mavlink_heartbeat_t)MainV2.comPort.DebugPacket(hbpacket);

                logfile = Settings.Instance.LogDir + Path.DirectorySeparatorChar
                          + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar
                          + hbpacket[3] + Path.DirectorySeparatorChar + no + " " + MakeValidFileName(fileName) + ".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";

            MainV2.comPort.Progress -= comPort_Progress;

            return(logfile);
        }
Beispiel #20
0
        public  void Read()
        {
            int read_count=0;
            if (debug) Console.WriteLine("Cserial:Read()\n");
            System.Threading.Thread.Sleep(1);//wait and for other
            //
            try
            {
                _serialPort.DiscardInBuffer();
            }catch(Exception e)
            {
                if (this.debug) Console.WriteLine(e.ToString());
            }

            this.read_status = SerialStatus.ReadStart;//start
            while (Cserial._continue)
            {
                try
                {
                    if (data_type == 0)
					{
                        read_message = _serialPort.ReadLine();
                        read_deal();
					}
                    else
                    {
                        try
                        {
                            read_count = this._serialPort.BytesToRead;
                            if (read_count < 1)
                            {
                                System.Threading.Thread.Sleep(this.read_sleep);//wait and for other
                                continue;
                            }
                        }
                        catch (InvalidOperationException e) { if (this.debug) Console.WriteLine(e.ToString()); break; }//InvalidOperationException

                        if (read_count > buffer_len - this.index)
                        {
                                if (this.index - this.deal_index > Cdata.min_len) read_deal();
                                if (buffer_len - this.index < buffer_len / 2) this.adjust_buffer();
                                read_count = buffer_len - this.index;
                        }

                        try//_serialPort.Read
                        {
                            read_byte_count = _serialPort.Read(this.read_buffer, this.index, read_count);
                            this.index += read_byte_count;
                            while (this.cdata.in_deal) System.Threading.Thread.Sleep(1);//wait and for other thread
                            read_deal();
                        }
                        catch (ArgumentNullException e) { if (this.debug) Console.WriteLine(e.ToString()); }
                        catch (InvalidOperationException e) { if (this.debug) Console.WriteLine(e.ToString()); break; }
                        catch (ArgumentOutOfRangeException e) { if (this.debug) Console.WriteLine(e.ToString()); }
                        catch (ArgumentException e) { if (this.debug) Console.WriteLine(e.ToString());}
                        catch (TimeoutException e) { if (this.debug) Console.WriteLine(e.ToString()); }
                        catch (Exception e) { if (this.debug) Console.WriteLine(e.ToString()); }
                    }//else

                }catch (Exception e) { if (this.debug) Console.WriteLine(e.ToString()); }
            }
            this.read_status = SerialStatus.ReadEnd;
        }
        string GetLog(ushort no, string fileName)
        {
            log.Info("GetLog " + no);

            MainV2.comPort.Progress += comPort_Progress;

            status = SerialStatus.Reading;

            // used for log fn
            MAVLink.MAVLinkMessage 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))
            {
                if (ms != null)
                    log.Info("Got Log length: " + ms.Length);

                ms.Seek(0, SeekOrigin.Begin);

                status = SerialStatus.Done;

                MAVLink.mavlink_heartbeat_t hb = (MAVLink.mavlink_heartbeat_t)MainV2.comPort.DebugPacket(hbpacket);

                logfile = Settings.Instance.LogDir + Path.DirectorySeparatorChar
                          + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar
                          + hbpacket.sysid + Path.DirectorySeparatorChar + no + " " + MakeValidFileName(fileName) + ".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";

            MainV2.comPort.Progress -= comPort_Progress;

            return logfile;
        }
        private void LoadCheckedList()
        {
            if (logEntries != null)
            {
                foreach (var item in logEntries)
                {
                    try
                    {
                        string caption = item.id + " " + GetItemCaption(item) + "  (" + item.size + ")";
                        AddCheckedListBoxItem(caption);
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                    }
                }

                if (logEntries.Count == 0)
                {
                    AppendSerialLog(LogStrings.NoLogsFound);
                }
                else
                {
                    AppendSerialLog(string.Format(LogStrings.SomeLogsFound, logEntries.Count));

                }
            }
            status = SerialStatus.Done;
        }
Beispiel #23
0
        string GetLog(string no, string fileName)
        {
            log.Info("GetLog " + no);


            status = SerialStatus.Reading;

            logfile = Settings.Instance.LogDir + Path.DirectorySeparatorChar
                      + MakeValidFileName(fileName) + ".bin";

            // make log dir
            Directory.CreateDirectory(Path.GetDirectoryName(logfile));

            log.Info("about to write: " + logfile);
            // save memorystream to file


            SftpClient client = new SftpClient(_connectionInfo);

            client.Connect();

            using (var logstream = File.Open(logfile, FileMode.Create, FileAccess.Write))
            {
                client.DownloadFile(no, logstream, downloadCallback);
            }

            client.Disconnect();

            log.Info("about to convertbin: " + logfile);

            // create ascii log
            BinaryLog.ConvertBin(logfile, logfile + ".log");

            //update the new filename
            logfile = logfile + ".log";

            // rename file if needed
            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 = Settings.Instance.LogDir + 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);
                }
            }

            MainV2.comPort.Progress -= comPort_Progress;

            return(logfile);
        }
        void CreateLog(string logfile)
        {
            TextReader tr = new StreamReader(logfile);
            //
            AppendSerialLog(string.Format(LogStrings.CreatingKmlPrompt, Path.GetFileName(logfile)));

            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;
        }
Beispiel #25
0
 /// <summary>
 /// A board with Uduino is found
 /// </summary>
 public void UduinoFound()
 {
     serialStatus = SerialStatus.FOUND;
 }
        private void DownloadThread(int[] selectedLogs)
        {
            try
            {

                status = SerialStatus.Reading;

                totalBytes = 0;
                tallyBytes = 0;
                receivedbytes = 0;
                foreach (int a in selectedLogs)
                {
                    currentlog = a;
                    var entry = logEntries[a]; // mavlink_log_entry_t
                    totalBytes += entry.size;
                }

                UpdateProgress(0, totalBytes, 0);
                foreach (int a in selectedLogs)
                {
                    currentlog = a;

                    var entry = logEntries[a]; // mavlink_log_entry_t
                    string fileName = GetItemCaption(entry);

                    AppendSerialLog(string.Format(LogStrings.FetchingLog, fileName));

                    var logname = GetLog(entry.id, fileName);

                    CreateLog(logname);

                    tallyBytes += receivedbytes;
                    receivedbytes = 0;
                    UpdateProgress(0, totalBytes, tallyBytes);
                }

                UpdateProgress(0, totalBytes, totalBytes);

                AppendSerialLog("Download complete.");
                Console.Beep();
            }
            catch (Exception ex)
            {
                AppendSerialLog("Error in log " + currentlog + ": " + ex.Message);
            }

            RunOnUIThread(() =>
                {
                    BUT_DLall.Enabled = true;
                    BUT_DLthese.Enabled = true;
                    status = SerialStatus.Done;
                });
        }
 private void BUT_clearlogs_Click(object sender, EventArgs e)
 {
     if (CustomMessageBox.Show(LogStrings.Confirmation, "sure", MessageBoxButtons.YesNo) ==
         System.Windows.Forms.DialogResult.Yes)
     {
         try
         {
             MainV2.comPort.EraseLog();
             AppendSerialLog(LogStrings.EraseComplete);
             status = SerialStatus.Done;
             CHK_logs.Items.Clear();
         }
         catch (Exception ex)
         {
             CustomMessageBox.Show(ex.Message, Strings.ERROR);
         }
     }
 }