require_relative "../interfaces/lab/signal" class Ecu class Signal DEFAULT_SIGNAL_SIZE = 32 DEFAULT_PERIOD = 10e-3 attr_accessor :name, :description, :task def initialize(name:, task: "Undefined", description: nil) @name = name.chomp.strip @task = task @description = description end def <=>(other) return nil unless other.is_a?(self.class) name.downcase <=> other.name.downcase end def ==(other) name == other.name end alias :eql? :== def hash [name].hash end def grep(regexp) name.match(regexp) || (!description.nil? && description.match(regexp)) end def bandwidth DEFAULT_SIGNAL_SIZE / period end def period return DEFAULT_PERIOD if task.nil? case task when /100us/ then 100e-6 when /10ms/ then 10e-3 when /segment/ then 12e-3 when /100ms/ then 100e-3 when /1s/ then 1 else DEFAULT_PERIOD end end def basename name.sub(/_\[\d+\]$/, "") end def to_h instance_variables. map { |v| [v.to_s[1..-1].to_sym, instance_variable_get(v)] }. to_h end def to_s str = "Signal: #{name}" str << " [#{task}]" unless task.nil? str end def with(hsh={}) return self if hsh.empty? self.class.new(**to_h.merge(hsh)) end end end