Class: SerialCanBus::Request::BtrSetup

Inherits:
BitStruct
  • Object
show all
Defined in:
lib/serial_can_bus/request.rb

Overview

Setup arbitrary CAN bus speeds.

Constant Summary collapse

BITRATE =

The following formula shows how the SJA1000 clock speed, Baud Rate Prescaler and Time Segment registers are used to calculate the bitrate.

bitrate = 16000000 / (2 * (BRP.x + 1) * (3 + TSEG1.x + TSEG2.x))

The BITRATE hash includes valid BTR0/BTR1 values, for the SJA1000 of the CANUSB adapter, corresponding to each bitrate.

{ 1000000 => 0x4014,
                 800000 => 0x4016,
                 500000 => 0x401c,
                 250000 => 0x411c,
                 125000 => 0x431c,
                 100000 => 0x441c,
50000 => 0x491c,
20000 => 0x581c,
10000 => 0x711c }

Instance Method Summary collapse

Instance Method Details

#bitrate=(bitrate) ⇒ Object


118
119
120
121
122
123
124
# File 'lib/serial_can_bus/request.rb', line 118

def bitrate=(bitrate)
  unless BITRATE[bitrate]
    raise 'unsupported bitrate'
  end

  self.value = BITRATE[bitrate].to_s(16).rjust(4, '0').upcase
end

#valueObject

:attr_accessor: value bitrate (String, 4 bytes), see BITRATE constant and bitrate=() for automatic conversion from Fixnum


116
# File 'lib/serial_can_bus/request.rb', line 116

string :value, 4*8, 'command', :default => BITRATE[125000]