Class: Msp430Bsl::Command
- Inherits:
-
Object
- Object
- Msp430Bsl::Command
- Defined in:
- lib/msp430_bsl/command.rb
Instance Attribute Summary collapse
-
#addr ⇒ Object
Returns the value of attribute addr.
-
#code ⇒ Object
Returns the value of attribute code.
-
#configs ⇒ Object
Returns the value of attribute configs.
-
#data ⇒ Object
Returns the value of attribute data.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(cmd_name, addr: nil, data: nil) ⇒ Command
constructor
A new instance of Command.
- #length ⇒ Object
- #packet ⇒ Object
-
#splitted_addr ⇒ Object
Split address to [low, middle, high] bytes.
Constructor Details
#initialize(cmd_name, addr: nil, data: nil) ⇒ Command
Returns a new instance of Command.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/msp430_bsl/command.rb', line 18 def initialize(cmd_name, addr: nil, data: nil) raise Exceptions::Command::NameNotSupported, cmd_name unless self.class.supports?(cmd_name) @name = cmd_name @configs = self.class[@name] @code = configs[:code] @addr = addr @data = data validate end |
Instance Attribute Details
#addr ⇒ Object
Returns the value of attribute addr.
6 7 8 |
# File 'lib/msp430_bsl/command.rb', line 6 def addr @addr end |
#code ⇒ Object
Returns the value of attribute code.
6 7 8 |
# File 'lib/msp430_bsl/command.rb', line 6 def code @code end |
#configs ⇒ Object
Returns the value of attribute configs.
6 7 8 |
# File 'lib/msp430_bsl/command.rb', line 6 def configs @configs end |
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/msp430_bsl/command.rb', line 6 def data @data end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/msp430_bsl/command.rb', line 6 def name @name end |
Class Method Details
.[](cmd_name) ⇒ Object
12 13 14 15 16 |
# File 'lib/msp430_bsl/command.rb', line 12 def self.[](cmd_name) raise Exceptions::Command::NameNotSupported, cmd_name unless supports?(cmd_name) Configs::CMDS[cmd_name.to_sym] end |
.supports?(cmd_name) ⇒ Boolean
8 9 10 |
# File 'lib/msp430_bsl/command.rb', line 8 def self.supports?(cmd_name) Configs::CMDS.keys.include? cmd_name.to_sym end |
Instance Method Details
#length ⇒ Object
36 37 38 |
# File 'lib/msp430_bsl/command.rb', line 36 def length code.to_bytes_ary.length end |
#packet ⇒ Object
30 31 32 33 34 |
# File 'lib/msp430_bsl/command.rb', line 30 def packet return @packet if @packet @packet = [code, splitted_addr, data].flatten.compact end |
#splitted_addr ⇒ Object
Split address to [low, middle, high] bytes
41 42 43 44 45 |
# File 'lib/msp430_bsl/command.rb', line 41 def splitted_addr if addr [ (addr & 0xFF), ((addr >> 8) & 0xFF), ((addr >> 16) & 0xFF) ] end end |