Class: CresIP::Action
- Inherits:
-
Object
- Object
- CresIP::Action
- Defined in:
- lib/cresip/action.rb
Overview
Digital Feedback: 05 0006 000003 00 1300 Analog Set: 05 0008 000005 14 004204d2 Date & Time:(dev) 05 000b 000008 08 0e230710092216
(controller) 05 000b 000008 08 0e230709092216
Unknown: (dev) 05 0009 000006 20 0103009201
(dev) 05 000a 000007 20 01041500f203
(controller) 05 0014 000011 20 110e1c050000444d204f757470757473
Update Incomming: 05 0005 000002 03 00 (device & server)
05 0006 000003 03 2107 (device)
05 0005 000002 03 16 (server)
Serial Set: (dev) 05 0013 000010 12 03444d2d54582d344b2d3330322d43
Constant Summary collapse
- Feedback =
[:analog_feedback, :digital_feedback, :serial_feedback]
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#join ⇒ Object
readonly
Returns the value of attribute join.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #feedback? ⇒ Boolean
-
#initialize(header = PacketHeader.new, action = ActionHeader.new) ⇒ Action
constructor
A new instance of Action.
- #payload ⇒ Object
- #set_join(number) ⇒ Object
- #set_value(data, type: :set, join: @join) ⇒ Object
- #to_binary_s ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(header = PacketHeader.new, action = ActionHeader.new) ⇒ Action
Returns a new instance of Action.
43 44 45 46 47 48 49 50 51 |
# File 'lib/cresip/action.rb', line 43 def initialize(header = PacketHeader.new, action = ActionHeader.new) @header = header @action = action @header.packet_type = PacketTypes[:action_info] if action.type && self.respond_to?(action.type, true) @join, @value = self.send(action.type, action.payload) end end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
53 54 55 |
# File 'lib/cresip/action.rb', line 53 def action @action end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
53 54 55 |
# File 'lib/cresip/action.rb', line 53 def header @header end |
#join ⇒ Object (readonly)
Returns the value of attribute join.
53 54 55 |
# File 'lib/cresip/action.rb', line 53 def join @join end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
53 54 55 |
# File 'lib/cresip/action.rb', line 53 def value @value end |
Instance Method Details
#feedback? ⇒ Boolean
64 65 66 |
# File 'lib/cresip/action.rb', line 64 def feedback? Feedback.include? @action.type end |
#payload ⇒ Object
59 60 61 |
# File 'lib/cresip/action.rb', line 59 def payload @action.payload end |
#set_join(number) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/cresip/action.rb', line 93 def set_join(number) @join = number # this keeps the binary representation up to date set_value(@value) number end |
#set_value(data, type: :set, join: @join) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/cresip/action.rb', line 74 def set_value(data, type: :set, join: @join) case data when String @action.payload_type = type == :set ? PayloadType[:serial_set] : PayloadType[:serial_feedback] @action.payload = encode_serial_set(join, data) when Integer @action.payload_type = type == :set ? PayloadType[:analog_set] : PayloadType[:analog_feedback] @action.payload = encode_analog_set(join, data) when true, false @action.payload_type = type == :set ? PayloadType[:digital_set] : PayloadType[:digital_feedback] @action.payload = encode_digital_set(join, data) else raise 'invalid data type' end @join = join @value = data end |
#to_binary_s ⇒ Object
68 69 70 71 72 |
# File 'lib/cresip/action.rb', line 68 def to_binary_s action_resp = @action.to_binary_s @header.packet_size = action_resp.length "#{@header.to_binary_s}#{action_resp}" end |
#type ⇒ Object
55 56 57 |
# File 'lib/cresip/action.rb', line 55 def type @action.type end |