public string PrintSignalType(SignalBitsDesc sig) { sb.Clear(); sb.Append(($" public {__typeprint[(int)sig.SigType]} {sig.FieldName};").PadRight(35, ' ')); string comment = $" // "; comment += (sig.Signed) ? " [-]" : " "; comment += $" Bits={sig.LengthBit:D2}. "; comment += $" [ "; comment += sig.MinValue.ToViewable().PadRight(6, ' '); comment += ", "; comment += sig.MaxValue.ToViewable().PadRight(6, ' '); comment += " ] "; if (sig.FieldUnit != null) { comment += ($" Unit:'{sig.FieldUnit}'").PadRight(13, ' '); } if (sig.Offset != 0) { comment += ($" Offset= {sig.Offset}").PadRight(18, ' '); } if (sig.Factor != 1) { comment += ($" Factor= {sig.Factor}").PadRight(15, ' '); } return(sb.ToString() + comment); }
public string PrintSignalType(SignalBitsDesc sig, Int32 pad_sig_name, bool bitfield) { sb.Clear(); sb.AppendLine(); if (sig.CommentText != null) { sb.AppendLine(" // " + sig.CommentText); } if (sig.ValueText != null) { sb.AppendLine(sig.ValueText); } var dtype = ""; dtype += $" {__typeprint[(int)sig.SigType]} {sig.FieldName}"; if (bitfield && (sig.LengthBit < 8)) { dtype += $" : {sig.LengthBit}"; } dtype += ";"; dtype = dtype.PadRight(pad_sig_name + 16); sb.Append(dtype); string comment = $" // "; comment += (sig.Signed) ? " [-]" : " "; comment += $" Bits={sig.LengthBit:D2}. "; comment += $" [ "; comment += sig.MinValue.ToViewable().PadRight(6, ' '); comment += ", "; comment += sig.MaxValue.ToViewable().PadRight(6, ' '); comment += " ] "; if (sig.FieldUnit != null) { comment += ($" Unit:'{sig.FieldUnit}'").PadRight(13, ' '); } if (sig.Offset != 0) { comment += ($" Offset= {sig.Offset}").PadRight(18, ' '); } if (sig.Factor != 1) { comment += ($" Factor= {sig.Factor}").PadRight(15, ' '); } return(sb.ToString() + comment); }
public string PrintSignalPackExpression(SignalBitsDesc sig) { sb.Clear(); if (sig.Offset == 0 && sig.Factor == 1) { return(null); } sb.Append($"// signal: @{sig.FieldName}" + Environment.NewLine); sb.AppendLine($"public const double {sig.FieldName}_CovFactor = {sig.Factor};"); sb.Append($"public static {__typeprint[(int)sig.SigType]} {sig.FieldName}_CovS(double x) => "); //sb.Append($"{sig.FieldName}_CovS(x) "); var str = String.Empty; if (sig.Factor != 1) { str += $"(x / {sig.Factor})"; } else { str += "x"; } if (sig.Offset != 0) { if (sig.Offset < 0) { str += " + " + Math.Abs(sig.RawOffset); } else { str += " - " + Math.Abs(sig.RawOffset); } } else { } sb.Append($"({__typeprint[(int)sig.SigType]})({str});"); return(sb.ToString()); }
public string PrintUnpackFunctionBody(SignalBitsDesc sig) { sb.Clear(); UInt16 startb = (UInt16)((sig.Order == BitLayout.Intel) ? (sig.StartBit + (sig.LengthBit - 1)) : (sig.StartBit)); if (startb > 63) { startb = 63; } Int32 bn = startb / 8; Int32 bbc = (startb % 8) + 1; Int32 l = sig.LengthBit; sb.Clear(); if (bbc > l) { sb.Append($"((_d[{bn}] >> {bbc - l}) & ({__lm[l]}))"); sig.SigToByte[bn] = $"((_m.{sig.FieldName} & ({__lm[l]})) << {bbc - l})"; } else if (bbc == l) { // no rolling bits sb.Append($"(_d[{bn}] & ({__lm[l]}))"); sig.SigToByte[bn] = $"(_m.{sig.FieldName} & ({__lm[l]}))"; } else { var type64_cov = String.Empty; l -= bbc; if (l > 31) { type64_cov = ""; } sb.Append($"({type64_cov}(_d[{bn}] & ({__lm[bbc]})) << {l})"); sig.SigToByte[bn] = $"((_m.{sig.FieldName} >> {l}) & ({__lm[bbc]}))"; while ((l - 8) >= 0) { type64_cov = String.Empty; l -= 8; bn = ShiftByte(sig, bn); sb.Append(" | "); if (l == 0) { // last byte is aligned sb.Append($"(_d[{bn}] & ({__lm[8]}))"); sig.SigToByte[bn] = $"(_m.{sig.FieldName} & ({__lm[8]}))"; } else { if (l > 31) { type64_cov = "(UInt64)"; } sb.Append($"({type64_cov}(_d[{bn}] & ({__lm[8]})) << {l})"); sig.SigToByte[bn] = $"((_m.{sig.FieldName} >> {l}) & ({__lm[8]}))"; } } if (l > 0) { bn = ShiftByte(sig, bn); sb.Append($" | ((_d[{ bn}] >> {8 - l}) & ({ __lm[l]}))"); sig.SigToByte[bn] = $"((_m.{sig.FieldName} & ({ __lm[l]})) << {8 - l})"; } } return(sb.ToString()); }
private int ShiftByte(SignalBitsDesc sg, int bn) { return((sg.Order == BitLayout.Intel) ? (bn - 1) : (bn + 1)); }
public string PrintPackFunctionBody(SignalBitsDesc sig) { sb.Clear(); return(sb.ToString()); }
public void TrimDbcRawStream(StringReader reader) { var line = String.Empty; MessageDescriptor msgDesc = null; while ((line = reader.ReadLine()) != null) { if (line.StartsWith("BO_ ")) { if (msgDesc != null) { // this means that new message was met and previous message needs to be added to list msgDesc.AddSignals(msgDesc.Signals.OrderBy(o => o.StartBit).ToList()); Messages.Add(msgDesc); } msgDesc = new MessageDescriptor(); if (!msgDesc.ParseVectorDbcLine(line)) { // bad unparsing. clear message reference msgDesc = null; } } if (regSigStart.IsMatch(line) && (msgDesc != null)) { var sig = new SignalBitsDesc(); sig.ParseFromVectorDbcString(line); msgDesc.Signals.Add(sig); } else if (line.StartsWith("BA_ ")) { // try parse this section for getting cycle time var bastr = new AttrDescriptor(); if (bastr.ParseBA_(line) == true) { if (ba_.Where(b => b.MsgId == bastr.MsgId).FirstOrDefault() == null) { // there is no this message in collection yet ba_.Add(bastr); } } } if (line.StartsWith("CM_ ") || commenter.IsCollectingData) { if (commenter.PassString(line) == true) { if (commenter.Info.Type == CommentType.MessageComment) { var msg = Messages.Where(m => m.MessageId == commenter.Info.MsgId).FirstOrDefault(); if (msg != null) { // appropriate message was found msg.CommentText = commenter.Info.Text; } } else if (commenter.Info.Type == CommentType.SignalComment) { var msg = Messages.Where(m => m.MessageId == commenter.Info.MsgId).FirstOrDefault(); if (msg != null) { // appropriate message was found var sig = msg.Signals.Where(s => s.FieldName == commenter.Info.SigName).FirstOrDefault(); if (sig != null) { sig.CommentText = commenter.Info.Text; if (IsRollingCounterCodeAvailalbe && sig.CommentText.Contains(RollingCounterMatch)) { if (msg.RollSig == null) { msg.RollSig = sig; } } else if (IsChecksumMatchCodeAvailable && sig.CommentText.Contains(ChecksumMatch)) { if (msg.CsmSig == null) { msg.CsmType = "kCRCUndefined"; if (sig.CommentText.Contains("CRC8_SAEJ1850")) { msg.CsmType = "kSAEJ1850"; } else if (sig.CommentText.Contains("XOR8_Generic")) { msg.CsmType = "kXOR8"; } else if (sig.CommentText.Contains("XOR4_generic") || sig.CommentText.Contains("XOR4_SAS")) { msg.CsmType = "kXOR4"; } else if (sig.CommentText.Contains("XOR")) { // common case for XOR-base algorythms msg.CsmType = "kXOR8"; } msg.CsmSig = sig; } } } } } } } else if (line.StartsWith("VAL_ ")) { valuator.PassString(line); var msg = Messages.Where(m => m.MessageId == valuator.MsgId).FirstOrDefault(); if (msg != null) { // appropriate message was found var sig = msg.Signals.Where(s => s.FieldName == valuator.SigName).FirstOrDefault(); if (sig != null) { sig.ValueText = valuator.Text; } } } Messages = Messages.OrderBy(m => m.MessageId).ToList(); } if (msgDesc != null) { msgDesc.Signals = msgDesc.Signals.OrderBy(o => o.StartBit).ToList(); Messages.Add(msgDesc); } foreach (var ba in ba_) { // update all the messages with parsed succesfully cycle time var msg = Messages.Where(d => d.MessageId == ba.MsgId).FirstOrDefault(); if (msg != null) { msg.CycTime = ba.CycTime; } } }
public string PrintSignalPackExpression(SignalBitsDesc sig, string nameprefix) { var newline = Environment.NewLine; var signame = nameprefix + "_" + sig.FieldName; sb.Clear(); if (sig.Offset == 0 && sig.Factor == 1) { return(null); } sb.Append($"// signal: @{sig.FieldName}" + newline); sb.Append($"#define {signame}_CovFactor ({sig.Factor})" + newline); sb.AppendLine("// conversion value to CAN signal"); sb.Append($"#define {signame}_toS(x) "); // Generate macro for conversion value to CAN signal var str = String.Empty; if (sig.Factor != 1) { str += $"(x) / {sig.Factor}"; } else { str += "(x)"; } if (sig.Offset != 0) { if (sig.Offset < 0) { str += " + " + Math.Abs(sig.RawOffset); } else { str += " - " + Math.Abs(sig.RawOffset); } } else { } sb.AppendLine($"(({__typeprint[(int)sig.SigType]})({str}))"); // Generate macro for conversion CAN signal to valuetoSig sb.AppendLine("// conversion value from CAN signal"); sb.Append($"#define {signame}_fromS(x) "); str = String.Empty; if (sig.Factor != 1) { str += $"(x) * {sig.Factor}"; } else { str += "(x)"; } sb.AppendLine($"({str})"); return(sb.ToString()); }