automotive-ecu 0.1.2 → 0.1.4

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: 24338ba9633d36789c4ba4f5c7ae67659c2dca146a878ae426555afcc18419cc
4
- data.tar.gz: 70103adf18b506ab21d62bd5d8c9a95266d19dac8a7d2688c55ed85748fa6d10
3
+ metadata.gz: ad8f4f30b32824a37a57939951230876c96e1e6de5d89939fe831eb68b6fd92f
4
+ data.tar.gz: 397829925fb22b56f76ddd60820c52b8a89739b2e0dccbfc94ad8fb174acec94
5
5
  SHA512:
6
- metadata.gz: 1c4624a8d94693d35d9db642d677816b26bb461e7676837147ae4c81fb013f2097d884e90b00dcb92f0781ee335c939360ec20ab40712c5ff223921c030da169
7
- data.tar.gz: 5f92059a106311e053750e57f36b5341850b4dfab169ec1edcb7a263d1078191c339a9b4b221b668539a2ded36dc356f2b8a5fc55968cd1743a74aad86bb8003
6
+ metadata.gz: d51985201cc46cfe5f4cdab85903f71b3018983fd2053752487cc0295587f9788760e97249da7f0fca07c277fd2fd0982c7d7825d414d21c19654c0afe6da4b6
7
+ data.tar.gz: 611e2e6b00449f3303f4edf383af46151cce36d340bf6ca67cd932a95739e86865a146f76b5e1b436088c175620db376bef8995fe74c8d61d63d3e6b4dce8623
@@ -4,8 +4,10 @@ class Ecu
4
4
  %r{FESTWERT\s+(?<name>[A-Za-z0-9\._]+)}
5
5
  end
6
6
 
7
- def to_dcm
8
- "#{type.upcase} #{name}\n".tap do |str|
7
+ def to_dcm(indented=false)
8
+ fmtstr = indented ? "%-26s%s\n" : "%s %s\n"
9
+
10
+ sprintf(fmtstr, type.upcase, name).tap do |str|
9
11
  str << " LANGNAME #{description.enquote}\n" if description
10
12
  str << " FUNKTION #{function}\n" if function
11
13
  str << " EINHEIT_W #{unit.enquote}\n" if unit
@@ -3,11 +3,13 @@ require_relative "../../../core_ext"
3
3
  class Ecu
4
4
  class Festwerteblock < Label
5
5
  def self.dcm_header
6
- %r{FESTWERTEBLOCK\s+(?<name>[A-Za-z0-9\._]+)\s+(?<xdim>\d+)(?:\s+@\s+(?<ydim>\d+))?}
6
+ %r{^FESTWERTEBLOCK\s+(?<name>[A-Za-z0-9\._]+)\s+(?<xdim>\d+)(?:\s+@\s+(?<ydim>\d+))?}
7
7
  end
8
8
 
9
- def to_dcm
10
- "FESTWERTEBLOCK #{name} #{xdim}".tap do |str|
9
+ def to_dcm(indented=false)
10
+ fmtstr = indented ? "%-26s%s %s" : "%s %s %d"
11
+
12
+ sprintf(fmtstr, type.upcase, name, xdim).tap do |str|
11
13
  str << " @ #{ydim}" if ydim != 1
12
14
  str << "\n"
13
15
  str << " LANGNAME #{description.enquote}\n" if description
@@ -4,8 +4,10 @@ class Ecu
4
4
  %r{^KENNFELD\s+(?<name>[A-Za-z0-9\._]+)\s+(?<xdim>\d+)\s+(?<ydim>\d+)}
5
5
  end
6
6
 
7
- def to_dcm
8
- "#{type.upcase} #{name} #{xdim} #{ydim}\n".tap do |str|
7
+ def to_dcm(indented=false)
8
+ fmtstr = indented ? "%-26s%s %s %s\n" : "%s %s %d %d\n"
9
+
10
+ sprintf(fmtstr, type.upcase, name, xdim, ydim).tap do |str|
9
11
  str << " LANGNAME #{description.enquote}\n" if description
10
12
  str << " FUNKTION #{function}\n" if function
11
13
  str << " EINHEIT_X #{xunit.enquote}\n" if xunit
@@ -4,8 +4,10 @@ class Ecu
4
4
  %r{^KENNLINIE\s+(?<name>[A-Za-z0-9\._]+)\s+(?<xdim>\d+)}
5
5
  end
6
6
 
7
- def to_dcm
8
- "#{type.upcase} #{name} #{xdim}\n".tap do |str|
7
+ def to_dcm(indented=false)
8
+ fmtstr = indented ? "%-26s%s %s\n" : "%s %s %d\n"
9
+
10
+ sprintf(fmtstr, type.upcase, name, xdim).tap do |str|
9
11
  str << " LANGNAME #{description.enquote}\n" if description
10
12
  str << " FUNKTION #{function}\n" if function
11
13
  str << " EINHEIT_X #{xunit.enquote}\n" if xunit
@@ -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
@@ -73,7 +73,7 @@ class Ecu
73
73
  line.chomp.gsub(/[[:space:]]/, " ").rstrip
74
74
  end
75
75
 
76
- def to_dcm
76
+ def to_dcm(indented=false)
77
77
  out = []
78
78
 
79
79
  unless headers.empty?
@@ -86,7 +86,7 @@ class Ecu
86
86
  out += subheaders.map { "* " + _1 }.push("")
87
87
  end
88
88
 
89
- out += map(&:to_dcm)
89
+ out += map { _1.to_dcm(indented) }
90
90
 
91
91
  out.join("\n")
92
92
  end
@@ -31,12 +31,18 @@ class Ecu
31
31
  end
32
32
 
33
33
  def self.numeric_array(str)
34
- str.split.map { Float(_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
+ def self.numeric_value(str)
42
+ return str.to_f if str.match?(/^\d+\.$/)
43
+
44
+ Float(str)
45
+ end
46
+
41
47
  end
42
48
  end
@@ -4,8 +4,10 @@ class Ecu
4
4
  %r{STUETZSTELLENVERTEILUNG\s+(?<name>[A-Za-z0-9\._]+)\s+(?<xdim>\d+)}
5
5
  end
6
6
 
7
- def to_dcm
8
- "#{type.upcase} #{name} #{xdim}\n".tap do |str|
7
+ def to_dcm(indented=false)
8
+ fmtstr = indented ? "%-26s%s %s\n" : "%s %s %d\n"
9
+
10
+ sprintf(fmtstr, type.upcase, name, xdim).tap do |str|
9
11
  str << " LANGNAME #{description.enquote}\n" if description
10
12
  str << " FUNKTION #{function}\n" if function
11
13
  str << " EINHEIT_X #{xunit.enquote}\n" if xunit
data/lib/ecu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Ecu
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.4"
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.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Mueller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-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