1 Star 2 Fork 2

mtooooo / DbcParser

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

DbcParser

Continuous Integration GitHub

Probably the first .NET DBC file parser. Includes packing and unpacking functionality for sending and receiving CAN signals.

Below is a quick preview of the extracted data using a Tesla dbc file taken from commaai/opendbc project:

Preview

Quickstart

Install the library via Nuget Packages and add at the top of your file:

using DbcParserLib;
using DbcParserLib.Model;

Parsing

Then to parse a dbc file use the static class Parser, using one oth the parsing flavours:

Dbc dbc = Parser.ParseFromPath("C:\\your_dbc_file.dbc");
Dbc dbc = Parser.ParseFromStream(File.OpenRead("C:\\your_dbc_file.dbc")); // Or a stream from network
Dbc dbc = Parser.Parse("a dbc as string");

Handling Dbc object

The Dbc object contains two collections, Messages and Nodes, both are IEnumerable<T> so can be accessed, iterated and queried using standard LINQ.

As an example, take all messages with id > 100 and more than 2 signals:

var filteredSelection = dbc
			.Messages
			.Where(m => m.ID > 100 && m.Signals.Count > 2)
			.ToArray();

Packing/Unpacking signals

Simple scenario

To pack and unpack signals you can use static class Packer Example for packing/unpacking a signal: 14 bits, Min: -61.92, Max: 101.91

Signal sig = new Signal
{
  sig.Length = 14,
  sig.StartBit = 2,
  sig.IsSigned = 1,
  sig.ByteOrder = 1, // 0 = Big Endian (Motorola), 1 = Little Endian (Intel)
  sig.Factor = 0.01,
  sig.Offset = 20
};

// This packs the signal for sending
ulong TxMsg = Packer.TxSignalPack(-34.3, sig);

// This unpacks a received signal and calculates the corresponding engineering value
double val = Packer.RxSignalUnpack(TxMsg, sig);

Multiple signals can be packed before CAN transmission using:

ulong TxMsg = 0;
TxMsg |= Packer.TxSignalPack(value1, sig1);
TxMsg |= Packer.TxSignalPack(value2, sig2);
TxMsg |= Packer.TxSignalPack(value3, sig3);
// ...
// Send TxMsg on CAN

The user needs to make sure that the signals do not overlap with each other by properly specifying the Length and StartBit.

Multiplexing

A message can contain multiplexed data, i.e. layout can change depending on a multiplexor value. The Packer class is unaware of multiplexing, so it's up to the user to check that the given message actually contains the signal. As an example, consider the following dbc lines:

BO_ 568 UI_driverAssistRoadSign: 8 GTW
 SG_ UI_roadSign M : 0|8@1+ (1,0) [0|0] ""  DAS
 SG_ UI_dummyData m0 : 8|1@1+ (1,0) [0|0] "" Vector__XXX
 SG_ UI_stopSignStopLineDist m1 : 8|10@1+ (0.25,-8) [-8|247.5] "m" Vector__XXX

Signal UI_dummyData will only be available when UI_roadSign value is 0 while UI_stopSignStopLineDist will only be available when UI_roadSign value is 1. You can access multiplexing information calling

var multiplexingInfo = signal.MultiplexingInfo();
if(multiplexingInfo.Role == MultiplexingRole.Multiplexor)
{
	// This is a multiplexor!
}
else if(multiplexingInfo.Role == MultiplexingRole.Multiplexed)
{
	Console.WriteLine($"This signal is multiplexed and will be available when multiplexor value is {multiplexingInfo.Group}");
}

You can also check is a message does contain multiplexed signals by calling the extension method

if(message.IsMultiplexed())
{
	// ...
}

Contributions

Contributions are appreciated! Feel free to create pull requests to improve this library.

MIT License Copyright (c) 2021 EFeru Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

CAN数据库 DBC file解析。 Probably the first .NET DBC file parser. Includes packing and unpacking functionality for sending and receiving CAN signals. 展开 收起
C#
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C#
1
https://gitee.com/mtoooo/DbcParser.git
git@gitee.com:mtoooo/DbcParser.git
mtoooo
DbcParser
DbcParser
main

搜索帮助