Class: Ecu::SignalList
- Inherits:
-
Object
- Object
- Ecu::SignalList
- Includes:
- Enumerable
- Defined in:
- lib/ecu/signals/signal_list.rb,
lib/ecu/interfaces/a2l/signal_list.rb,
lib/ecu/interfaces/dbc/signal_list.rb,
lib/ecu/interfaces/lab/signal_list.rb
Constant Summary collapse
- A2LREGEXP =
%r{/begin MEASUREMENT\s+([\S]+)\s+"([^"]*)"}
- DBCREGEXP =
/ SG_ ([A-Z_0-9]+) : .*/
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#signals ⇒ Object
Returns the value of attribute signals.
-
#subheaders ⇒ Object
Returns the value of attribute subheaders.
Class Method Summary collapse
- .from_a2l(str) ⇒ Object
- .from_dbc(file_path) ⇒ Object
- .from_file(file_path) ⇒ Object
- .from_lab(str) ⇒ Object
Instance Method Summary collapse
- #each(&blk) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(signals = [], headers = [], subheaders = []) ⇒ SignalList
constructor
A new instance of SignalList.
- #map_int(&blk) ⇒ Object
- #reject(&blk) ⇒ Object
- #select(&blk) ⇒ Object
- #sort_by(&blk) ⇒ Object
- #task(task_identifier) ⇒ Object
- #tasks ⇒ Object
- #to_lab ⇒ Object
- #to_s ⇒ Object
- #uniq ⇒ Object
Constructor Details
#initialize(signals = [], headers = [], subheaders = []) ⇒ SignalList
Returns a new instance of SignalList.
21 22 23 24 25 |
# File 'lib/ecu/signals/signal_list.rb', line 21 def initialize(signals=[], headers=[], subheaders=[]) @signals = signals @headers = headers @subheaders = subheaders end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
20 21 22 |
# File 'lib/ecu/signals/signal_list.rb', line 20 def headers @headers end |
#signals ⇒ Object
Returns the value of attribute signals.
20 21 22 |
# File 'lib/ecu/signals/signal_list.rb', line 20 def signals @signals end |
#subheaders ⇒ Object
Returns the value of attribute subheaders.
20 21 22 |
# File 'lib/ecu/signals/signal_list.rb', line 20 def subheaders @subheaders end |
Class Method Details
.from_a2l(str) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/ecu/interfaces/a2l/signal_list.rb', line 7 def self.from_a2l(str) str.gsub!(%r{/\*.*?\*/}, "") signals = str.scan(A2LREGEXP).map do |name, description| Ecu::Signal.new(name: name, description: description) end new(signals) end |
.from_dbc(file_path) ⇒ Object
6 7 8 9 10 |
# File 'lib/ecu/interfaces/dbc/signal_list.rb', line 6 def self.from_dbc(file_path) new(File.open(file_path, "rb").read.scan(DBCREGEXP).map do |name| Ecu::Signal.new(name: name.first) end.reject { |signal| signal.name =~ /TA|TPCI/ }) end |
.from_file(file_path) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/ecu/signals/signal_list.rb', line 11 def self.from_file(file_path) case File.extname(file_path) when ".lab" then self.from_lab(File.read_encoded(file_path)) when ".a2l" then self.from_a2l(File.read_encoded(file_path)) when ".dbc" then self.from_dbc(File.read_encoded(file_path)) else fail "Unknown file extension: #{file_path}!" end end |
Instance Method Details
#each(&blk) ⇒ Object
27 28 29 |
# File 'lib/ecu/signals/signal_list.rb', line 27 def each(&blk) @signals.each(&blk) end |
#empty? ⇒ Boolean
35 36 37 |
# File 'lib/ecu/signals/signal_list.rb', line 35 def empty? @signals.empty? end |
#map_int(&blk) ⇒ Object
31 32 33 |
# File 'lib/ecu/signals/signal_list.rb', line 31 def map_int(&blk) self.class.new(@signals.map(&blk), @headers, @subheaders) end |
#reject(&blk) ⇒ Object
45 |
# File 'lib/ecu/signals/signal_list.rb', line 45 def reject(&blk); self.class.new(@signals.reject(&blk), @headers, @subheaders) end |
#select(&blk) ⇒ Object
44 |
# File 'lib/ecu/signals/signal_list.rb', line 44 def select(&blk); self.class.new(@signals.select(&blk), @headers, @subheaders) end |
#sort_by(&blk) ⇒ Object
46 |
# File 'lib/ecu/signals/signal_list.rb', line 46 def sort_by(&blk); self.class.new(@signals.sort_by(&blk), @headers, @subheaders) end |
#task(task_identifier) ⇒ Object
39 40 41 42 |
# File 'lib/ecu/signals/signal_list.rb', line 39 def task(task_identifier) task_identifier = tasks[task_identifier] if task_identifier.is_a? Integer select { |signal| signal.task == task_identifier } end |
#tasks ⇒ Object
48 49 50 |
# File 'lib/ecu/signals/signal_list.rb', line 48 def tasks @tasks ||= map(&:task).compact.uniq end |
#to_lab ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ecu/interfaces/lab/signal_list.rb', line 11 def to_lab out = [] out.append(*headers.map { |l| "; #{l}" }, "") unless headers.empty? out.append("[SETTINGS]") out.append("Version;V1.1") out.append("MultiRasterSeparator;&") out.append("") out.append(*subheaders.map { |l| "; #{l}" }, "") unless subheaders.empty? out.append("[RAMCELL]") out.append(*map(&:to_lab)) out.join("\n") end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/ecu/signals/signal_list.rb', line 52 def to_s "[#{map(&:to_s).join(", ")}]" end |
#uniq ⇒ Object
56 57 58 |
# File 'lib/ecu/signals/signal_list.rb', line 56 def uniq self.class.new(@signals.uniq) end |