// convert a message to a row (obsolete) /* * static public object[] msg2row (canAnalyzer.canMessage2 msg, timestamp ts, int idx) * { * int dataIdx = 0; * * string[] data = msg.GetDataStringList().ToArray(); * * int tsVal = ts.update(msg.TimeStamp.TimeStamp); * * // timestamp string * string sTs = msecTs2String(tsVal); * * // ts, id, dlc, data * object[] values = { * idx, * sTs, * msg.Id.GetIdAsString(), * msg.Id.GetDlcAsString(), * ( data.Length >= ++dataIdx ? data[dataIdx-1] : string.Empty ), * ( data.Length >= ++dataIdx ? data[dataIdx-1] : string.Empty ), * ( data.Length >= ++dataIdx ? data[dataIdx-1] : string.Empty ), * ( data.Length >= ++dataIdx ? data[dataIdx-1] : string.Empty ), * ( data.Length >= ++dataIdx ? data[dataIdx-1] : string.Empty ), * ( data.Length >= ++dataIdx ? data[dataIdx-1] : string.Empty ), * ( data.Length >= ++dataIdx ? data[dataIdx-1] : string.Empty ), * ( data.Length >= ++dataIdx ? data[dataIdx-1] : string.Empty ), * }; * * return values; * } */ // convert a message to the row (new) static public object[] msg2row(canAnalyzer.canMessage2 msg, timestamp_offset ts, int idx) { int dataIdx = 0; string[] data = msg.GetDataStringList().ToArray(); //int tsVal = ts.update(msg.TimeStamp.TimeStamp); int tsVal = ts.update(msg.timestamp_absolute); // timestamp string string sTs = msecTs2String(tsVal); // ts, id, dlc, data object[] values = { idx, sTs, msg.Id.GetIdAsString(), msg.Id.GetDlcAsString(), (data.Length >= ++dataIdx ? data[dataIdx - 1] : string.Empty), (data.Length >= ++dataIdx ? data[dataIdx - 1] : string.Empty), (data.Length >= ++dataIdx ? data[dataIdx - 1] : string.Empty), (data.Length >= ++dataIdx ? data[dataIdx - 1] : string.Empty), (data.Length >= ++dataIdx ? data[dataIdx - 1] : string.Empty), (data.Length >= ++dataIdx ? data[dataIdx - 1] : string.Empty), (data.Length >= ++dataIdx ? data[dataIdx - 1] : string.Empty), (data.Length >= ++dataIdx ? data[dataIdx - 1] : string.Empty), }; return(values); }
// convert message list to string public static string msg_list_to_string(List <canAnalyzer.canMessage2> ls, timestamp_offset usr_ts = null, bool add_header = true) { // converter mConverter conv = new canTraceUtils.mConverter(); // timestamp timestamp_offset ts = usr_ts == null ? new canTraceUtils.timestamp_offset() : usr_ts; conv.TS = ts; // builder StringBuilder sb = new StringBuilder(); // append the header string if (add_header) { sb.Append(conv.getHeaderString()); sb.Append(Environment.NewLine); } // append the messages (fast edition) for (int i = 0; i < ls.Count; i++) { var msg = ls[i]; // update timestamp int new_ts = ts.update(msg.timestamp_absolute); // pad positins int sb_start_pos = sb.Length; int pad_cnt; // 1) time if (new_ts < 10000) { sb.Append(' '); } sb.AppendFormat("{0} s.", ((double)new_ts / 1000).ToString("F3")); pad_cnt = sb.Length - sb_start_pos; sb.Append(' ', tsLenMin - pad_cnt); // 2) CAN id sb_start_pos = sb.Length; sb.Append("0x"); sb.Append(msg.Id.GetIdAsString()); pad_cnt = sb.Length - sb_start_pos; sb.Append(' ', idLenMin - pad_cnt); // 3) CAN dlc sb_start_pos = sb.Length; sb.Append(msg.Id.GetDlcAsString()); pad_cnt = sb.Length - sb_start_pos; sb.Append(' ', dlcMinLen - pad_cnt); // 4) data, works faster then 'getdatastring' if (msg.Data != null && msg.Data.Length > 0) { for (int d = 0; d < msg.Data.Length - 1; d++) { sb.Append("0x"); sb.Append(msg.Data[d].ToString("X2")); sb.Append(", "); } // the last one sb.Append("0x"); sb.Append(msg.Data[msg.Data.Length - 1].ToString("X2")); } sb.Append(Environment.NewLine); } // to string return(sb.ToString()); }