automotive-ecu 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ecu/interfaces/dcm/dcm_lexer.rb +16 -14
- data/lib/ecu/interfaces/dcm/dcm_parser.rb +84 -76
- data/lib/ecu/interfaces/dcm/festwert.rb +5 -4
- data/lib/ecu/interfaces/dcm/label_list.rb +8 -6
- data/lib/ecu/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4ad47ed36e2d54205a5c804187b85e2f2a7b91d73f2fc1bc548f691a87804c88
|
|
4
|
+
data.tar.gz: 2ab14530309248995b479e9dc4010bf61a83f767efd62ddf9b739686791aaae5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: de3516033d423a95b0c813f3e22eed22a0195fbbf5c4d7b2dc6f3604d897d59bd4b7bc46f0b527651fa5f3c1ffecec4cc3642e3f1482033b0104154088abdb44
|
|
7
|
+
data.tar.gz: ebaf253e55c358547cb63ad4024a8bf0e90c6bb7a529b5ab30a9117593436aacd15d546bd226a5cf7a02156edfe2193c94e67f51e59fc9545c6b9688cd35b45b
|
|
@@ -48,25 +48,27 @@ class Ecu
|
|
|
48
48
|
|
|
49
49
|
return if @scan.eos?
|
|
50
50
|
|
|
51
|
-
case
|
|
52
|
-
when @scan.skip(NEWLINE)
|
|
53
|
-
when
|
|
54
|
-
when @scan.skip(
|
|
55
|
-
when @scan.skip(
|
|
56
|
-
when
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
51
|
+
case @doc.getbyte(@scan.pos)
|
|
52
|
+
when 10, 13 then @scan.skip(NEWLINE) && :NEWLINE # \n \r
|
|
53
|
+
when 34 then @scan.skip(QUOTED_TEXT) && :QUOTED_TEXT # "
|
|
54
|
+
when 42 then @scan.skip(COMMENT) && :COMMENT # *
|
|
55
|
+
when 64 then @scan.skip(DIMENSIONS_SEP) && :DIMENSIONS_SEP # @
|
|
56
|
+
when 43, 45, 46, 48..57 # + - . 0-9
|
|
57
|
+
if @scan.skip(FLOAT) then :FLOAT
|
|
58
|
+
elsif @scan.skip(INT) then :INT
|
|
59
|
+
else @scan.getch; :UNKNOWN_CHAR
|
|
60
|
+
end
|
|
62
61
|
else
|
|
63
|
-
@scan.
|
|
64
|
-
:
|
|
62
|
+
if s = @scan.scan(KW_RE) then KW_TABLE[s]
|
|
63
|
+
elsif @scan.skip(HEADER) then :HEADER
|
|
64
|
+
elsif @scan.skip(IDENTIFIER) then :IDENTIFIER
|
|
65
|
+
else @scan.getch; :UNKNOWN_CHAR
|
|
66
|
+
end
|
|
65
67
|
end
|
|
66
68
|
end
|
|
67
69
|
|
|
68
70
|
def token_value
|
|
69
|
-
@
|
|
71
|
+
@scan.matched
|
|
70
72
|
end
|
|
71
73
|
|
|
72
74
|
def lineno
|
|
@@ -35,83 +35,92 @@ class Ecu
|
|
|
35
35
|
while tok = lexer.next_token
|
|
36
36
|
begin
|
|
37
37
|
case @state
|
|
38
|
-
|
|
38
|
+
when :PRE_HEADER
|
|
39
39
|
case tok
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
when :HEADER then next_state(:POST_HEADER)
|
|
41
|
+
when :COMMENT then add_header(lexer.token_value)
|
|
42
|
+
when :NEWLINE then # noop
|
|
43
|
+
else raise DcmParserError.new("Unexpected token #{debug_token(tok)} (state: #{@state})", lexer)
|
|
43
44
|
end
|
|
44
|
-
|
|
45
|
+
when :POST_HEADER
|
|
45
46
|
case tok
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
when :FUNKTIONEN then next_state(:FUNCTIONS_CONTENT)
|
|
48
|
+
when :FESTWERT then start_label(Festwert)
|
|
49
|
+
when :FESTWERTEBLOCK then start_label(Festwerteblock)
|
|
50
|
+
when :KENNLINIE then start_label(Kennlinie)
|
|
51
|
+
when :GRUPPENKENNLINIE then start_label(Gruppenkennlinie)
|
|
52
|
+
when :FESTKENNLINIE then start_label(Festkennlinie)
|
|
53
|
+
when :KENNFELD then start_label(Kennfeld)
|
|
54
|
+
when :GRUPPENKENNFELD then start_label(Gruppenkennfeld)
|
|
55
|
+
when :FESTKENNFELD then start_label(Festkennfeld)
|
|
56
|
+
when :STUETZSTELLENVERTEILUNG then start_label(Stuetzstellenverteilung)
|
|
57
|
+
when :COMMENT then add_subheader(lexer.token_value)
|
|
58
|
+
when :NEWLINE then # noop
|
|
59
|
+
else raise DcmParserError.new("Unexpected token #{debug_token(tok)} (state: #{@state})", lexer)
|
|
58
60
|
end
|
|
59
|
-
|
|
61
|
+
when :FUNCTIONS_CONTENT
|
|
60
62
|
case tok
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
when :FKT then next_state(:FUNCTION_CONTENT)
|
|
64
|
+
when :NEWLINE then # noop
|
|
65
|
+
when :END then next_state(:POST_HEADER)
|
|
66
|
+
else raise DcmParserError.new("Unexpected token #{debug_token(tok)} (state: #{@state})", lexer)
|
|
64
67
|
end
|
|
65
|
-
|
|
68
|
+
when :FUNCTION_CONTENT
|
|
66
69
|
case tok
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
when :IDENTIFIER then # append that shit?
|
|
71
|
+
when :QUOTED_TEXT then # append that shit as well?
|
|
72
|
+
when :NEWLINE then next_state(:FUNCTIONS_CONTENT)
|
|
73
|
+
else raise DcmParserError.new("Unexpected token #{debug_token(tok)} (state: #{@state})", lexer)
|
|
70
74
|
end
|
|
71
|
-
|
|
75
|
+
when :LABEL_HEADLINE
|
|
72
76
|
case tok
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
when :IDENTIFIER then add_name(lexer.token_value)
|
|
78
|
+
when :DIMENSIONS_SEP then # noop, order handled by #add_dimension
|
|
79
|
+
when :INT then add_dimension(lexer.token_value.to_i)
|
|
80
|
+
when :NEWLINE then next_state(:LABEL_CONTENT)
|
|
81
|
+
else raise DcmParserError.new("Unexpected token #{debug_token(tok)} (state: #{@state})", lexer)
|
|
77
82
|
end
|
|
78
|
-
|
|
83
|
+
when :LABEL_CONTENT
|
|
79
84
|
case tok
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
85
|
+
when :WERT then start_property(:WERT, :NUMERIC_PROPERTY)
|
|
86
|
+
when :TEXT then start_property(:TEXT, :TEXT_PROPERTY)
|
|
87
|
+
when :EINHEIT_X then start_property(:EINHEIT_X, :TEXT_PROPERTY)
|
|
88
|
+
when :EINHEIT_Y then start_property(:EINHEIT_Y, :TEXT_PROPERTY)
|
|
89
|
+
when :EINHEIT_W then start_property(:EINHEIT_W, :TEXT_PROPERTY)
|
|
90
|
+
when :LANGNAME then start_property(:LANGNAME, :TEXT_PROPERTY)
|
|
91
|
+
when :FUNKTION then start_property(:FUNKTION, :ID_PROPERTY)
|
|
92
|
+
when :DISPLAYNAME then start_property(:DISPLAYNAME, :ID_PROPERTY)
|
|
93
|
+
when :END then labels << finish_label
|
|
94
|
+
when :"ST/X" then start_property(:"ST/X", :NUMERIC_PROPERTY)
|
|
95
|
+
when :"ST/Y" then start_property(:"ST/Y", :NUMERIC_PROPERTY)
|
|
96
|
+
when :"ST_TX/X" then start_property(:"ST_TX/X", :TEXT_PROPERTY)
|
|
97
|
+
when :"ST_TX/Y" then start_property(:"ST_TX/Y", :TEXT_PROPERTY)
|
|
98
|
+
when :NEWLINE then # noop, DCM badly formatted
|
|
99
|
+
when :COMMENT then # noop, some programs add SST in comments
|
|
100
|
+
else raise DcmParserError.new("Unexpected token #{debug_token(tok)} (state: #{@state})", lexer)
|
|
95
101
|
end
|
|
96
|
-
|
|
102
|
+
when :NUMERIC_PROPERTY
|
|
97
103
|
case tok
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
104
|
+
when :FLOAT then append_property(lexer.token_value.to_f)
|
|
105
|
+
when :INT then append_property(lexer.token_value.to_i)
|
|
106
|
+
when :NEWLINE then finish_property
|
|
107
|
+
else raise DcmParserError.new("Unexpected token #{debug_token(tok)} (state: #{@state})", lexer)
|
|
101
108
|
end
|
|
102
|
-
|
|
109
|
+
when :TEXT_PROPERTY
|
|
103
110
|
case tok
|
|
104
|
-
|
|
105
|
-
|
|
111
|
+
when :QUOTED_TEXT then append_property(lexer.token_value[1..-2])
|
|
112
|
+
when :NEWLINE then finish_property
|
|
113
|
+
else raise DcmParserError.new("Unexpected token #{debug_token(tok)} (state: #{@state})", lexer)
|
|
106
114
|
end
|
|
107
|
-
|
|
115
|
+
when :ID_PROPERTY
|
|
108
116
|
case tok
|
|
109
|
-
|
|
110
|
-
|
|
117
|
+
when :IDENTIFIER then append_property(lexer.token_value)
|
|
118
|
+
when :NEWLINE then finish_property
|
|
119
|
+
else raise DcmParserError.new("Unexpected token #{debug_token(tok)} (state: #{@state})", lexer)
|
|
111
120
|
end
|
|
112
121
|
end
|
|
113
|
-
rescue
|
|
114
|
-
raise
|
|
122
|
+
rescue DcmParserError
|
|
123
|
+
raise
|
|
115
124
|
rescue StandardError => e
|
|
116
125
|
raise DcmParserError.new("#{e.message} on #{e.backtrace.first} (state: #{@state})", lexer)
|
|
117
126
|
end
|
|
@@ -149,10 +158,8 @@ class Ecu
|
|
|
149
158
|
|
|
150
159
|
def finish_label
|
|
151
160
|
next_state(:POST_HEADER) do
|
|
152
|
-
@properties
|
|
153
|
-
|
|
154
|
-
.then { @constructor.new(**_1) }
|
|
155
|
-
.tap { reset_label! }
|
|
161
|
+
@properties.delete(:displayname)
|
|
162
|
+
@constructor.new(**@properties).tap { reset_label! }
|
|
156
163
|
end
|
|
157
164
|
end
|
|
158
165
|
|
|
@@ -175,14 +182,19 @@ class Ecu
|
|
|
175
182
|
|
|
176
183
|
def start_property(key, newstate)
|
|
177
184
|
next_state(newstate) do
|
|
178
|
-
@key
|
|
179
|
-
@
|
|
185
|
+
@key = KEY_MAPPING[key]
|
|
186
|
+
@is_ary = ARY_PROPERTIES.include?(@key)
|
|
187
|
+
if @is_ary
|
|
188
|
+
@properties[@key] ||= []
|
|
189
|
+
@value = @properties[@key] # alias: append_property writes directly to target
|
|
190
|
+
else
|
|
191
|
+
@value = nil
|
|
192
|
+
end
|
|
180
193
|
end
|
|
181
194
|
end
|
|
182
195
|
|
|
183
196
|
def append_property(value)
|
|
184
|
-
|
|
185
|
-
if ARY_PROPERTIES.include?(@key)
|
|
197
|
+
if @is_ary
|
|
186
198
|
@value << value
|
|
187
199
|
else
|
|
188
200
|
fail "Multiple definitions for #{@key}" if @value
|
|
@@ -193,22 +205,18 @@ class Ecu
|
|
|
193
205
|
|
|
194
206
|
def finish_property
|
|
195
207
|
next_state(:LABEL_CONTENT) do
|
|
196
|
-
if @properties
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
fail "Multiple property lines not allowed for #{key}"
|
|
201
|
-
end
|
|
202
|
-
else
|
|
203
|
-
@properties[@key] = @value
|
|
204
|
-
end
|
|
208
|
+
next if @is_ary # values already in @properties[@key] via @value alias
|
|
209
|
+
|
|
210
|
+
fail "Multiple property lines not allowed for #{@key}" if @properties.key?(@key)
|
|
211
|
+
@properties[@key] = @value
|
|
205
212
|
end
|
|
206
213
|
end
|
|
207
214
|
|
|
208
215
|
def reset_label!
|
|
209
216
|
@constructor = nil
|
|
210
|
-
@properties =
|
|
217
|
+
@properties = {}
|
|
211
218
|
@key = nil
|
|
219
|
+
@is_ary = false
|
|
212
220
|
@value = nil
|
|
213
221
|
end
|
|
214
222
|
|
|
@@ -7,10 +7,11 @@ class Ecu
|
|
|
7
7
|
str << " LANGNAME #{description.enquote}\n" if description
|
|
8
8
|
str << " FUNKTION #{function}\n" if function
|
|
9
9
|
str << " EINHEIT_W #{unit.enquote}\n" if unit
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
if value.is_a?(Numeric)
|
|
11
|
+
str << " WERT " << value.to_s << "\n"
|
|
12
|
+
else
|
|
13
|
+
str << " TEXT " << value.enquote << "\n"
|
|
14
|
+
end
|
|
14
15
|
str << "END\n"
|
|
15
16
|
end
|
|
16
17
|
end
|
|
@@ -29,21 +29,23 @@ class Ecu
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def to_dcm(indented=false)
|
|
32
|
-
|
|
32
|
+
buf = String.new
|
|
33
33
|
|
|
34
34
|
unless headers.empty?
|
|
35
|
-
|
|
35
|
+
headers.each { buf << "* " << _1 << "\n" }
|
|
36
|
+
buf << "\n"
|
|
36
37
|
end
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
buf << DCM_HEADER << "\n"
|
|
39
40
|
|
|
40
41
|
unless subheaders.empty?
|
|
41
|
-
|
|
42
|
+
buf << "\n"
|
|
43
|
+
subheaders.each { buf << "* " << _1 << "\n" }
|
|
42
44
|
end
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
each { buf << "\n" << _1.to_dcm(indented) }
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
buf
|
|
47
49
|
end
|
|
48
50
|
end
|
|
49
51
|
end
|
data/lib/ecu/version.rb
CHANGED