class Ecu::Stuetzstellenverteilung
def self.dcm_header
def self.dcm_header %r{STUETZSTELLENVERTEILUNG\s+(?<name>[A-Za-z0-9\._]+)\s+(?<xdim>\d+)} end
def bytesize
def bytesize xdim * BYTESIZE[:number] end
def equality_properties
def equality_properties [:name, :xvalue] end
def initialize(name:,
def initialize(name:, xdim:, xvalue:, xunit: nil, function: nil, description: nil) @name = name @xdim = xdim @xvalue = xvalue @xunit = xunit @function = function @description = description init_error "Dimensions for xvalue don't match xdim" if xvalue.size != xdim end
def properties
def properties [:name, :xdim, :xvalue, :xunit, :function, :description] end
def round_to(n)
def round_to(n) return self unless xvalue.all? { |x| x.is_a?(Numeric) } self.with \ xvalue: xvalue.map { |x| x.round(n) } end
def to_dcm
def to_dcm "#{type.upcase} #{name} #{xdim}\n".tap do |str| str << " LANGNAME #{description.enquote}\n" if description str << " FUNKTION #{function}\n" if function str << " EINHEIT_X #{xunit.enquote}\n" if xunit str << case xvalue.first when Numeric then " ST/X #{xvalue.join(" ")}\n" when String then " ST_TX/X #{xvalue.map(&:enquote).join(" ")}\n" end str << "END\n" end end
def to_mfile
def to_mfile "#{name} = [#{xvalue.join(" ")}];\n" end
def to_s(detail: false)
def to_s(detail: false) if detail == :value "#{name}:\n#{to_s(detail: :justvalue)}" elsif detail == :justvalue ValuePrinter.call(self) elsif detail == :onelinefull "#{name} #{to_s(detail: :oneline)}" elsif detail == :oneline "(#{xdim}x1) X: #{valuestats(xvalue)}" else "#{name}: #{@xdim}x1 #{type}".tap do |str| if detail str << "\n" str << " Unit: \"#{xunit}\"\n" str << " Value:\n" str << ValuePrinter.call(self).indent(4) str << "\n" end end end end