// the region contains a class constructor #region Constructor // constructor public UcCanTrace(CanMessageSendTool can) { InitializeComponent(); // parent CanTool = can; // grid createGrid(); // menu createMenu(); grid.ContextMenuStrip = menu; // send tool sendWrkr = new canTraceUtils.sendWorker(CanTool, this); mode = traceMode.pause; //ts = new canTraceUtils.timestamp(); ts = new canTraceUtils.timestamp_offset(); conv = new canTraceUtils.mConverter(); conv.TS = ts; tbPlayFrom.KeyPress += Tools.textBoxIntOnlyEvent; tbPlayTo.KeyPress += Tools.textBoxIntOnlyEvent; updateMsgCounter(); cbTraceMode.Items.Add("All"); cbTraceMode.Items.Add("Selected"); cbTraceMode.SelectedIndex = 0; // icons btnTrace.Image = Properties.Resources.icon_record; btnSendStep.Image = Properties.Resources.icon_step; btnPlay.Image = Properties.Resources.icon_play; btnClear.Image = Properties.Resources.icon_clear; btnSendStep.Enabled = false; btnPlay.Enabled = false; btnSendRange.Enabled = false; btnClear.Enabled = false; tbPlayFrom.Enabled = btnPlay.Enabled; tbPlayTo.Enabled = btnPlay.Enabled; lblSendFrom.Enabled = btnPlay.Enabled; lblSendTo.Enabled = btnPlay.Enabled; lblSendFrom.Font = new Font("Consolas", 9, FontStyle.Italic); lblSendTo.Font = lblSendFrom.Font; cbTraceMode.Font = new Font("Consolas", 8f); lblTotalMsgs.Font = new Font("Calibri", 9.0f); foreach (DataGridViewColumn col in grid.Columns) { col.HeaderCell.Style.Font = new Font("Calibri", 9.0f, FontStyle.Bold); } grid.DefaultCellStyle.Font = new Font("Consolas", 8.5f);//, FontStyle.Italic); // System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip(); // ToolTip1.SetToolTip(this.btnTrace, "Start/Stop Recording"); }
// region: decompressor #region decompressor // do decompression private string doDecompress(string source, string dest) { if (string.IsNullOrEmpty(source) || string.IsNullOrEmpty(dest)) { return("Decompression failed. Invalid arguments"); } long msg_cnt = 0; List <canMessage2> ls = doDecompressToList(source, out msg_cnt); // free GC.Collect(); string sres = "Decompression failed. No CAN messages."; if (ls != null && ls.Count > 0) { canTraceUtils.timestamp_offset ts = new canTraceUtils.timestamp_offset(); ui_set_state_string("Converting..."); // a workaround to reduce MAX RAM consumtion // do write, 100k entries at once int page_size = 100 * 1000; int page_cnt = (ls.Count / page_size) + 1; int written = 0; ui_progress_set(page_cnt, 0); for (int page = 0; page < page_cnt && !m_thread_stop_req; page++) { bool header = page == 0; int offset = page * page_size; int len = ls.Count - page * page_size; if (len > page_size) { len = page_size; } // execute if (header == true) { // write + header File.WriteAllText(dest, canTraceUtils.mConverter.msg_list_to_string( ls.GetRange(page * page_size, len), ts, true)); } else { // append, no header File.AppendAllText(dest, canTraceUtils.mConverter.msg_list_to_string( ls.GetRange(page * page_size, len), ts, false)); } //Thread.Sleep(200); written += len; // progress ui_progress_step(); } string str_time_sec = "NULL"; // timer if (m_sw != null) { long msec = m_sw.ElapsedMilliseconds; str_time_sec = string.Format("{0:0.0} sec", (double)msec / 1000.0d); } if (written > 0 && !m_thread_stop_req) { sres = string.Format("Decompression completed successfully.{0}" + "Number of CAN messages: {1} (out of {2}).{3}" + "Elapsed time: {4}", Environment.NewLine, written, msg_cnt, Environment.NewLine, str_time_sec); } else { sres = "Decompression failed. Unknown error."; } } return(sres); }