automotive-ecu 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7f926f619d6084c07b03ea445d30312394d1204e613767e977f169a2664ca70
4
- data.tar.gz: f3a6445e04164e4e80178eb2c05f21190f45c5844a9517b1dccb13ea43022ccf
3
+ metadata.gz: 3adf406568cc23075ab176db5d171365057400613aa2ea668e217247d2734dd0
4
+ data.tar.gz: d0367f0a39c76cc2094600440a22f39a8da32118acae23419e3d95abb68910e8
5
5
  SHA512:
6
- metadata.gz: fee3b53cdb66cbd9af633ced32109e12cc4c77219df72c5818be53d7b6f4b52f7a64bae2a82c22e9d6eba67beeca75d62139f972a08092b325c0e2440f21a588
7
- data.tar.gz: b92604aef79aedecec06e6f7e42f38911e987aa6091906ccda7e4840282674e0060b77c307d680ff258226e2436dbf8ea62c18445ff2f97be73ef390936c692a
6
+ metadata.gz: f6027c77ae6110600b72ffab9611ba97e1ee6c95852f23cfbeb96c4afd09de25ddc84fd4ca220186f35b2922a8a7252d647a8d1c16f777c0b94b3b04e33cde05
7
+ data.tar.gz: 276b5f1382cc619af06908f6dfc5f090fe26f238b55c13ee07e3330f1cc233c2701f0b15a12ef1d12f7e24b0d3ef95ef4332dff7629d959060aa0f4f814c8dae
@@ -28,31 +28,31 @@ class Ecu
28
28
  str.each_line.lazy.with_index(1).each do |line, n|
29
29
  line = normalize_whitespace(line)
30
30
  case line
31
- when BLANKLINE_REGEX then next
32
- when COMMENT_REGEX
31
+ in BLANKLINE_REGEX then next
32
+ in COMMENT_REGEX
33
33
  case buffer.header
34
- when :pre then headers << line[1..].strip
35
- when :after then subheaders << line[1..].strip
36
- when :done then # Header time over, do nothing
34
+ in :pre then headers << line[1..].strip
35
+ in :after then subheaders << line[1..].strip
36
+ in :done then # Header time over, do nothing
37
37
  end
38
- when DCM_HEADER then buffer.header_seen!
39
- when Functions.dcm_header then buffer.start!(Functions, [line])
40
- when Festwert.dcm_header then buffer.start!(Festwert, [line])
41
- when Festwerteblock.dcm_header then buffer.start!(Festwerteblock, [line])
42
- when Kennlinie.dcm_header then buffer.start!(Kennlinie, [line])
43
- when Gruppenkennlinie.dcm_header then buffer.start!(Gruppenkennlinie, [line])
44
- when Festkennlinie.dcm_header then buffer.start!(Festkennlinie, [line])
45
- when Kennfeld.dcm_header then buffer.start!(Kennfeld, [line])
46
- when Gruppenkennfeld.dcm_header then buffer.start!(Gruppenkennfeld, [line])
47
- when Festkennfeld.dcm_header then buffer.start!(Festkennfeld, [line])
48
- when Stuetzstellenverteilung.dcm_header then buffer.start!(Stuetzstellenverteilung, [line])
49
- when "END" then
38
+ in DCM_HEADER then buffer.header_seen!
39
+ in ^(Functions.dcm_header) then buffer.start!(Functions, [line])
40
+ in ^(Festwert.dcm_header) then buffer.start!(Festwert, [line])
41
+ in ^(Festwerteblock.dcm_header) then buffer.start!(Festwerteblock, [line])
42
+ in ^(Kennlinie.dcm_header) then buffer.start!(Kennlinie, [line])
43
+ in ^(Gruppenkennlinie.dcm_header) then buffer.start!(Gruppenkennlinie, [line])
44
+ in ^(Festkennlinie.dcm_header) then buffer.start!(Festkennlinie, [line])
45
+ in ^(Kennfeld.dcm_header) then buffer.start!(Kennfeld, [line])
46
+ in ^(Gruppenkennfeld.dcm_header) then buffer.start!(Gruppenkennfeld, [line])
47
+ in ^(Festkennfeld.dcm_header) then buffer.start!(Festkennfeld, [line])
48
+ in ^(Stuetzstellenverteilung.dcm_header) then buffer.start!(Stuetzstellenverteilung, [line])
49
+ in "END"
50
50
  case obj = buffer.finish!(line)
51
- when Label
51
+ in Label
52
52
  fail "Duplicate label #{obj.name}" unless labels[obj.name].nil?
53
53
 
54
54
  labels[obj.name] = obj
55
- when Functions
55
+ in Functions
56
56
  fail "Duplicate functions definition" unless functions.empty?
57
57
 
58
58
  functions = obj
@@ -62,7 +62,7 @@ class Ecu
62
62
  else
63
63
  buffer.append!(line)
64
64
  end
65
- rescue RuntimeError => e
65
+ rescue StandardError => e
66
66
  raise MalformedDcmError.new(e.message, n, str), e.message
67
67
  end
68
68
 
@@ -31,21 +31,18 @@ class Ecu
31
31
  end
32
32
 
33
33
  def self.numeric_array(str)
34
- str.split.map { Float(_1) rescue Label::InvalidValue.new(_1) }
34
+ str.split.map { numeric_value(_1) }
35
35
  end
36
36
 
37
37
  def self.string_array(str)
38
38
  str.scan(/"([^"]*)"/).flatten
39
39
  end
40
40
 
41
- end
41
+ def self.numeric_value(str)
42
+ return str.to_f if str.match?(/^\d+\.$/)
42
43
 
43
- class Label
44
- InvalidValue = Struct.new(:value) do
45
- def to_s
46
- "<InvalidValue: \"#{value}\">"
47
- end
48
- def inspect; to_s; end
44
+ Float(str)
49
45
  end
46
+
50
47
  end
51
48
  end
@@ -22,6 +22,7 @@ class Ecu
22
22
  case File.extname(file_path)
23
23
  when ".lab" then self.from_lab(File.read_encoded(file_path))
24
24
  when ".a2l" then self.from_a2l(File.read_encoded(file_path))
25
+ when ".dcm" then self.from_dcm(File.read_encoded(file_path))
25
26
  else fail "Unknown file extension: #{file_path}!"
26
27
  end
27
28
  end
@@ -9,17 +9,10 @@ class Ecu
9
9
  def eql?
10
10
  return false unless @left.class == @right.class
11
11
  case @left
12
- when String then
13
- @left == @right
14
- when Numeric then
15
- @left == @right
16
- when Array then
17
- return false unless @left.size == @right.size
18
- @left.zip(@right).all? do |a, b|
19
- self.class.new(a, b).eql?
20
- end
21
- when NilClass then
22
- @left == @right
12
+ when NilClass then @left == @right
13
+ when String then @left == @right
14
+ when Numeric then @left == @right
15
+ when Array then arrays_eql?(@left, @right)
23
16
  else
24
17
  fail "Unkown value class: #{@left.class}"
25
18
  end
@@ -27,6 +20,12 @@ class Ecu
27
20
 
28
21
  private
29
22
 
23
+ def arrays_eql?(left, right)
24
+ return false unless left.size == right.size
25
+
26
+ left.zip(right).all? { self.class.new(*_1).eql? }
27
+ end
28
+
30
29
  def check_compatibility(left, right)
31
30
  if left.class != right.class
32
31
  fail ArgumentError, "Values must have the same class for comparison (#{left}: #{left.class}/#{right}: #{right.class})"
data/lib/ecu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Ecu
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: automotive-ecu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Mueller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-18 00:00:00.000000000 Z
11
+ date: 2024-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: terminal-table
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  - !ruby/object:Gem::Version
155
155
  version: '0'
156
156
  requirements: []
157
- rubygems_version: 3.4.19
157
+ rubygems_version: 3.5.11
158
158
  signing_key:
159
159
  specification_version: 4
160
160
  summary: A simple API for managing automotive ecu signals and labels