1 #Copyright (C) 2014 Intel Corporation
2 #Copyright (c) 2015 Cogent Embedded Inc.
4 #This library is free software; you can redistribute it and/or
5 #modify it under the terms of the GNU Lesser General Public
6 #License as published by the Free Software Foundation; either
7 #version 2.1 of the License, or (at your option) any later version.
9 #This library is distributed in the hope that it will be useful,
10 #but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 #Lesser General Public License for more details.
14 #You should have received a copy of the GNU Lesser General Public
15 #License along with this library; if not, write to the Free Software
16 #Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 my %messageSenders = ();
27 my %messageComments = ();
28 my %signalComments = ();
31 DbcOutput: Line(s?) eofile
33 my @electronicControlUnits = ();
34 for my $ecui (0..scalar(@ecuList)-1) {
36 $ecuField{'canId'} = $ecuList[$ecui];
38 if ( exists( $ecuMessages{$ecuList[$ecui]} ) ) {
39 my $messagesRef = $ecuMessages{$ecuList[$ecui]};
40 my @messages = @{$messagesRef};
42 $ecuField{'messages'} = \@messages;
43 for my $msgi (0..scalar(@messages)-1) {
44 my @signals = @{$messages[$msgi]{'signals'}};
46 for my $si (0..scalar(@signals)-1) {
47 my $signal = \%{$signals[$si]};
48 my $msgid = $messages[$msgi]{'canId'};
50 if ( exists( ${ecuValues{$msgid}} ) && defined ${$ecuValues{$msgid}{$signal->{'canId'}}} ) {
51 my $valueListRef=${$ecuValues{$msgid}->{$signal->{'canId'}}};
52 my @valueList = @$valueListRef;
53 $signal->{'values'} = \@valueList;
55 # Add AMBPropertyName prefix if valueName starts with number
56 foreach my $vali (@{$signal->{'values'}}) {
57 if ( $vali->{'name'} =~ m/^[0-9]/ ) {
58 $vali->{'name'} = $signal->{'AMBPropertyName'} . '_' . $vali->{'name'};
62 use Intel::IviPoc::AmbCommon;
63 $signal->{'AMBPropertyType'} = &evaluateType($signal);
67 push (@electronicControlUnits, \%ecuField);
71 $jsonroot{'pluginName'} = "pluginName";
72 $jsonroot{'electronicControlUnits'} = \@electronicControlUnits;
74 # Now return the whole internal json structure
81 Line: CommentPrefix /.*\n/
82 # Not needed to output anything yet
83 | 'VERSION' DoubleQuotedId
84 # Not needed to output anything yet
85 # Version can be empty like this ""
86 | 'NS_' ':' NSList(s?) ...'BS_'
87 # this tag holds a list of "new symbols" for the file
88 # Not needed to output anything
90 # This tag holds definition of bit timings, obsolete
91 # Not need to output anything
92 | 'BU_' ':' <skip:'[ \t]*'> Identifier(s?)
94 # This tag holds the list of ECUs in one line
95 @ecuList = @{$item[4]};
97 | 'BO_' Integer Identifier ':' Identifier Identifier Signal(s?)
100 $msg{'canId'} = $item[2];
101 $msg{'canName'} = $item[3];
102 $msg{'canDlc'} = $item[5];
103 $msg{'canEcuId'} = $item[6];
104 $msg{'signals'} = $item[7];
106 push ( @{$ecuMessages{$item[6]}}, \%msg );
108 | 'VAL_' Number Identifier ValuePair(s?) ';'
110 # This tag holds enums defined for specific messages
111 ${$ecuValues{$item[2]}->{$item[3]}} = $item[4];
113 | 'VAL_TABLE_' Identifier ValuePair(s?) ';'
115 # This tag holds predefined enumerations
116 ${$enumValues{$item[2]}} = $item[3];
118 | 'BO_TX_BU_' Number ':' Receiver(s /,/) ';'
120 # This tag defines message senders
121 @{$messageSenders{$item[2]}} = $item[4];
123 | 'CM_' DoubleQuotedId ';'
125 # This tag is a comment for the whole file
126 $fileComment = $item[2];
128 | 'CM_' 'BU_' Identifier DoubleQuotedId ';'
130 # This tag is a comment for an ECU
131 ${$ecuComments{$item[3]}} = $item[4];
133 | 'CM_' 'BO_' Identifier DoubleQuotedId ';'
135 # This tag is a comment for a message
136 ${$messageComments{$item[3]}} = $item[4];
138 | 'CM_' 'SG_' Number Identifier DoubleQuotedId ';'
140 # This tag is a comment for a signal
141 ${$signalComments{$item[3]}->{$item[4]}} = $item[5];
144 # This tag is an attribute definition
145 # Not needed to output anything yet
147 # This tag is an attribute definition
148 # Not needed to output anything yet
149 | 'BA_DEF_DEF_' /.*;/
150 # This tag is an attribute definition
151 # Not needed to output anything yet
153 # This tag is an attribute definition
154 # Not needed to output anything yet
155 | 'BA_DEF_REL_' /.*;/
156 # This tag is an attribute definition
157 # Not needed to output anything yet
158 | 'BA_DEF_DEF_REL_' /.*;/
159 # This tag is an attribute definition
160 # Not needed to output anything yet
162 # This tag is an attribute definition
163 # Not needed to output anything yet
164 | 'BA_DEF_SGTYPE_' /.*;/
165 # This tag is an attribute definition
166 # Not needed to output anything yet
167 | 'SIG_GROUP_' Number Identifier Number ':' Identifier(s) ';'
168 # This tag is a signal group definition
169 | <error: Invalid dbc format at $thisline!>
171 Signal: 'SG_' Identifier ':' DataPlacement FactorOffset Range DoubleQuotedId Receiver(s /,/)
174 $signal{'canId'} = $item[2];
176 my %placement = %{$item[4]};
177 $signal{'startBit'} = $placement{'startbit'};
178 $signal{'length'} = $placement{'length'};
179 $signal{'byteOrdering'} = $placement{'byteOrdering'};
180 $signal{'signedness'} = $placement{'signedness'};
183 $signal{'factor'} = $fo{'factor'};
184 $signal{'offset'} = $fo{'offset'};
186 my %range=%{$item[6]};
187 $signal{'minValue'} = $range{'minValue'};
188 $signal{'maxValue'} = $range{'maxValue'};
190 $signal{'unit'} = $item[7];
192 $signal{'receivers'} = $item[8];
194 my $ambPropertyName = $item[2];
195 $ambPropertyName =~ s/\_[HM]S$//;
196 $signal{'AMBPropertyName'} = $ambPropertyName;
201 NSList: ...!'BS_' Identifier
209 $rx{'name'} = $item[1];
213 ValuePair: Number DoubleQuotedId
216 $valuepair{'value'} = $item[1];
217 $valuepair{'description'} = $item[2];
220 $s =~ s!(^|\s)(\w)!$1\U$2!g;
222 $s =~ s/[^_a-zA-Z0-9]//g;
223 $s =~ s/_(?=[_]*$)//;
227 $valuepair{'name'} = $s;
232 DataPlacement: Number '|' Number '@' Number Sign
235 $placement{'startbit'} = $item[1];
236 $placement{'length'} = $item[3];
237 $placement{'byteOrdering'} = $item[5];
238 $placement{'signedness'} = $item[6];
242 FactorOffset: '(' RealNumber ',' RealNumber ')'
245 $fo{'factor'} = $item[2];
246 $fo{'offset'} = $item[4];
250 Range: '[' RealNumber '|' RealNumber ']'
253 $range{'minValue'} = $item[2];
254 $range{'maxValue'} = $item[4];
258 DoubleQuotedId: DoubleQuotation /[A-Za-z0-9°\!@#\$%\^&\*()\-_=\+\[\]\{\};:\'|,\.\/<>\?`~\ ]+/ DoubleQuotation
262 | DoubleQuotation DoubleQuotation
267 Identifier: /[A-Za-z0-9_\-]+/
272 Number: Integer | RealNumber | Sign
274 Integer: /[-+]?[0-9]*/
275 RealNumber: /[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/
278 CommentPrefix: /^\/\//
280 DoubleQuotation: "\""