// conver a row to the message public canAnalyzer.canMessage2 row2message(DataGridViewRow row) { int cellIdx = 1 + 1; string sId = row.Cells[cellIdx++].Value.ToString(); int id = Convert.ToInt32(sId, 16); // format bool is29b = sId.Length > 5; // 0x7FF // dlc int dlc = Convert.ToInt32(row.Cells[cellIdx++].Value.ToString(), 10); // data byte[] data = new byte[dlc]; for (int i = 0; i < dlc; i++) { data[i] = Convert.ToByte(row.Cells[cellIdx + i].Value.ToString(), 16); } // timestamp string sTs = row.Cells[0].Value.ToString(); sTs = sTs.Replace(" ", string.Empty); sTs = sTs.Substring(0, sTs.IndexOf("s.")); int ts = (int)(Convert.ToDouble(sTs) * 1000.0d); // convert canAnalyzer.canMessageId canId = new canAnalyzer.canMessageId(id, dlc, is29b); canAnalyzer.canMessage2 canMsg = new canAnalyzer.canMessage2(canId, data, ts); return(canMsg); }
// constructor public cmdReadParams(int id, string[] dataMask, bool is29b = false, int tmo = 1000, int dlcMin = -1, bool asVar = false, int varIdx = -1) { // params Id = new canAnalyzer.canMessageId(id, dataMask.Length, is29b); Timeout = tmo; UseAsVar = asVar; VarIdx = varIdx; DlcMin = dlcMin; IsStrictIdValue = true; IdFormat = string.Empty; AnyID = false; // mask DataMask = new string[Id.Dlc]; for (int i = 0; i < Id.Dlc; i++) { DataMask[i] = dataMask[i]; } // mask foreach (var s in DataMask) { DataMaskString += s + ","; } DataMaskString = DataMaskString.Remove(DataMaskString.Length - 1, 1); }
// conver a row to a message public canAnalyzer.canMessage2 row2msg(DataGridViewRow row) { int cellIdx = 1; string sTs = row.Cells[cellIdx++].Value.ToString(); sTs = sTs.Replace(" s.", ""); int ts = (int)(Convert.ToDouble(sTs) * 1000); canAnalyzer.canMessageId id = new canAnalyzer.canMessageId( row.Cells[cellIdx++].Value.ToString(), Convert.ToInt32(row.Cells[cellIdx++].Value.ToString()) ); List <byte> data = new List <byte>(); for (int i = cellIdx; i < row.Cells.Count; i++) { object cell_val = row.Cells[i].Value; if (cell_val == null) { break; } string sdata = cell_val.ToString(); if (string.IsNullOrEmpty(sdata)) { break; } byte b = Convert.ToByte(row.Cells[i].Value.ToString(), 16); data.Add(b); } return(new canAnalyzer.canMessage2(id, data.ToArray(), ts)); }
// do check the id public bool Check(canAnalyzer.canMessageId id) { // just compare 2 values if (IsStrictIdValue) { if (DlcMin == -1) { return(id.Equals(Id)); } else { return(id.Id == Id.Id && id.Id >= DlcMin); } } else { if (id.Is29bit == Id.Is29bit) { if (AnyID) { return(true); } } } return(false); }