Skip to content

Commit 3a27f95

Browse files
committed
Starting basic parsing
1 parent 3769f67 commit 3a27f95

File tree

3 files changed

+177
-0
lines changed

3 files changed

+177
-0
lines changed

ArrowPoint-CANbus-Test/ArrowPointCANBusTest.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@
6767
<Content Include="Test-Data\Configuration\CanConfig.xml">
6868
<SubType>Designer</SubType>
6969
</Content>
70+
<Content Include="Test-Data\Configuration\dbc standard.txt" />
7071
</ItemGroup>
7172
<ItemGroup>
7273
<None Include="packages.config" />
74+
<None Include="Test-Data\Configuration\WaveSculter.dbc" />
7375
</ItemGroup>
7476
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
7577
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Scope
2+
This document doesn't claim to specifiy the complete [Vector DBC standard](http://vector.com/vi_candb_en.html)
3+
4+
# Format description
5+
`<...>`: Required field
6+
`[...]`: Optional field
7+
` | `: Or (eg. <A|B>)
8+
9+
# Supported Keywords
10+
## VERSION
11+
Version identifier of the DBC file.
12+
Format: `VERSION "<VersionIdentifier>"`
13+
14+
## BS_
15+
Bus configuration.
16+
Format:: `BS_: <Speed>`
17+
Speed in kBit/s
18+
19+
## BU_
20+
List of all CAN-Nodes, seperated by whitespaces.
21+
22+
## BO_
23+
Message definition.
24+
Format: `BO_ <CAN-ID> <MessageName>: <MessageLength> <SendingNode>`
25+
MessageLength in bytes.
26+
27+
## SG_
28+
Signal definition.
29+
Format: `SG_ <SignalName> [M|m<MultiplexerIdentifier>] : <StartBit>|<Length>@<Endianness><Signed> (<Factor>,<Offset>) [<Min>|<Max>] "[Unit]" [ReceivingNodes]`
30+
Length in bits.
31+
Signed: + = unsigned; - = signed
32+
Endianness: 1 = little-endian, Intel; 0 = big-endian, Motorola
33+
M: If M than this signals contains a multiplexer identifier.
34+
MultiplexerIdentifier: Signal definition is only used if the value of the multiplexer signal equals to this value.
35+
36+
## CM_
37+
Description field.
38+
Format: `CM_ [<BU_|BO_|SG_> [CAN-ID] [SignalName]] "<DescriptionText>";`
39+
40+
## BA_DEF_
41+
Attribute definition.
42+
Format: `BA_DEF_ [BU_|BO_|SG_] "<AttributeName>" <DataType> [Config];`
43+
44+
DataType | Description | Config format
45+
---------|---------------------|----------------
46+
INT | integer | `<min> <max>`
47+
FLOAT | floating point | `<min> <max>`
48+
STRING | string |
49+
ENUM | enumeration | `"<Value0>","<Value1>"...`
50+
51+
## BA_DEF_DEF_
52+
Attribute default value
53+
Format: `BA_DEF_DEF_ "<AttributeName>" ["]<DefaultValue>["];`
54+
55+
## BA_
56+
Attribute
57+
Format: `BA_ "<AttributeName>" [BU_|BO_|SG_] [Node|CAN-ID] [SignalName] <AttributeValue>;`
58+
59+
## VAL_
60+
Value definitions for signals.
61+
Format: `VAL_ <CAN-ID> <SignalsName> <ValTableName|ValTableDefinition>;`
62+
63+
## VAL_TABLE_
64+
Value table definition for signals.
65+
Format: `VAL_TABLE_ <ValueTableName> <ValueTableDefinition>;`
66+
ValueTableDefinition: List of `IntValue "StringValue"` Pairs, seperated by whitespaces
67+
68+
# Attributes
69+
In this sections are standard attributes used by [CANpy](https://github.com/stefanhoelzl/CANpy) defined. The attributes can be overwritten within a DBC file.
70+
## Message Attributes
71+
72+
### GenMsgSendType
73+
Defines the send type of a message.
74+
Supported types:
75+
* cyclic
76+
* triggered
77+
* cyclicIfActive
78+
* cyclicAndTriggered
79+
* cyclicIfActiveAndTriggered
80+
* none
81+
Definition: `BA_DEF BO_ "GenMsgSendType" ENUM "cyclic","triggered","cyclicIfActive","cyclicAndTriggered","cyclicIfActiveAndTriggered","none"`
82+
Default: none
83+
Definition: `BA_DEF_DEF "GenMsgSendType" "none"`
84+
85+
### GenMsgCycleTime
86+
Defines the cycle time of a message in ms.
87+
Definition: `BA_DEF BO_ "GenMsgCycleTime" INT 0 0`
88+
Default: 0
89+
Definition: `BA_DEF_DEF "GenMsgCycleTime" 0`
90+
91+
### GenMsgStartDelayTime
92+
Defines the allowed delay after startup this message must occure the first time in ms.
93+
Definition: `BA_DEF BO_ "GenMsgStartDelayTime" INT 0 0`
94+
Default: 0 (=GenMsgCycleTime)
95+
Definition: `BA_DEF_DEF "GenMsgStartDelayTime" 0`
96+
97+
### GenMsgDelayTime
98+
Defines the allowed delay for a message in ms.
99+
Definition: `BA_DEF BO_ "GenMsgDelayTime" INT 0 0`
100+
Default: 0
101+
Definition: `BA_DEF_DEF "GenMsgDelayTime" 0`
102+
103+
## Signal Attributes
104+
### GenSigStartValue
105+
Defines the value as long as no value is set/received for this signal.
106+
Definition: `BA_DEF SG_ "GenSigStartValue" INT 0 0`
107+
Default: 0
108+
Definition: `BA_DEF_DEF "GenSigStartValue" 0`
109+
110+
# Sources
111+
http://pisnoop.s3.amazonaws.com/snoop_help_dbc.htm
112+
http://www.racelogic.co.uk/_downloads/vbox/Application_Notes/CAN%20Format%20for%20VBOXII%20and%20PRO%20v4.pdf
113+
https://hackage.haskell.org/package/ecu-0.0.8/src/src/j1939_utf8.dbc
114+
http://www.ingenieurbuerobecker.de/downloads/CANtool_Manual.pdf

ArrowPoint-CANbus-Tools/Services/ConfigService.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,67 @@ public void SaveConfig(string filename)
5858
}
5959

6060

61+
public void LoadDBCFile(string filename)
62+
{
63+
string[] lines = System.IO.File.ReadAllLines(filename);
64+
65+
const int VERSION = 0;
66+
const int BS = 1;
67+
const int BU = 2;
68+
const int BO = 3;
69+
const int SG = 4;
70+
const int CM = 5;
71+
const int BA_DEF = 6;
72+
const int BA_DEF_DEF = 7;
73+
const int BA = 8;
74+
const int VAL = 9;
75+
const int VAL_TABLE = 10;
76+
77+
int parseState = -1;
78+
79+
Configuration = new NetworkDefinition();
80+
81+
foreach (string line in lines)
82+
{
83+
84+
int marker = line.IndexOf(' ');
85+
if (marker < 3) marker = 3;
86+
string checktag = line.Trim().Substring(0, marker);
87+
88+
switch (checktag)
89+
{
90+
case "VERSION": parseState = VERSION; break;
91+
case "BS_": parseState = BS; break;
92+
case "BU_": parseState = BU; break;
93+
case "BO_": parseState = BO; break;
94+
case "SG_": parseState = SG; break;
95+
case "CM_": parseState = CM; break;
96+
case "BA_DEF_": parseState = BA_DEF; break;
97+
case "BA_DEF_DEF_": parseState = BA_DEF_DEF; break;
98+
case "BA_": parseState = BA; break;
99+
case "VAL_": parseState = VAL; break;
100+
case "VAL_TABLE_": parseState = VAL_TABLE; break;
101+
}
102+
103+
switch (parseState)
104+
{
105+
case VERSION: Configuration.Document.version = line.Substring(9); break;
106+
case BS: Configuration.Bus[0].baudrate = line.Substring(4); break;
107+
case BU: break;
108+
case BO: break;
109+
case SG: break;
110+
case CM: break;
111+
case BA_DEF: break;
112+
case BA_DEF_DEF: break;
113+
case BA: break;
114+
case VAL: break;
115+
case VAL_TABLE: break;
116+
}
117+
}
118+
}
119+
120+
121+
61122
public List<CanPacket> UnknownCanIds(Bus bus)
62123
{
63124
List<CanPacket> unknownPackets = null;

0 commit comments

Comments
 (0)