Class: SDN::Message::SetMotorIP
- Inherits:
-
Message
- Object
- Message
- SDN::Message::SetMotorIP
- Defined in:
- lib/sdn/message/set.rb
Overview
Command that stores, deletes, or distributes intermediate positions.
Constant Summary collapse
- MSG =
Protocol message number
0x15- PARAMS_LENGTH =
Number of protocol parameter bytes expected
4- TYPE =
for distribute, value is how many IPs to distribute over Mapping from symbolic write modes to SDN parameter values.
{ delete: 0x00, current_position: 0x01, position_pulses: 0x02, position_percent: 0x03, distribute: 0x04 }.freeze
Instance Attribute Summary collapse
-
#ip ⇒ Integer?
Requested intermediate-position slot in the range 1..16.
-
#type ⇒ :delete, ...
Requested intermediate-position write mode.
- #value ⇒ Integer?
Instance Method Summary collapse
-
#initialize(dest = nil, type = :delete, ip = nil, value = nil, **kwargs) ⇒ SetMotorIP
constructor
Creates an intermediate position write command.
-
#params ⇒ <Integer>
Returns the protocol-specific payload bytes for this message.
-
#parse(params) ⇒ void
Parses protocol-specific parameter bytes into this message instance.
Constructor Details
#initialize(dest = nil, type = :delete, ip = nil, value = nil, **kwargs) ⇒ SetMotorIP
Creates an intermediate position write command.
198 199 200 201 202 203 204 |
# File 'lib/sdn/message/set.rb', line 198 def initialize(dest = nil, type = :delete, ip = nil, value = nil, **kwargs) kwargs[:dest] ||= dest super(**kwargs) self.type = type self.ip = ip self.value = value end |
Instance Attribute Details
#ip ⇒ Integer?
Requested intermediate-position slot in the range 1..16.
184 185 186 |
# File 'lib/sdn/message/set.rb', line 184 def ip @ip end |
#type ⇒ :delete, ...
Requested intermediate-position write mode.
177 178 179 |
# File 'lib/sdn/message/set.rb', line 177 def type @type end |
#value ⇒ Integer?
189 190 191 |
# File 'lib/sdn/message/set.rb', line 189 def value @value end |
Instance Method Details
#params ⇒ <Integer>
Returns the protocol-specific payload bytes for this message.
236 237 238 |
# File 'lib/sdn/message/set.rb', line 236 def params transform_param(TYPE[type]) + transform_param(ip || 0) + from_number(value || 0, 2) end |
#parse(params) ⇒ void
This method returns an undefined value.
Parses protocol-specific parameter bytes into this message instance.
207 208 209 210 211 212 213 214 |
# File 'lib/sdn/message/set.rb', line 207 def parse(params) super self.type = TYPE.invert[to_number(params[0])] ip = to_number(params[1]) ip = nil if ip.zero? self.ip = ip self.value = to_number(params[2..3]) end |