somfy_sdn 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/sdn_mqtt_bridge +5 -0
- data/lib/sdn/message.rb +179 -0
- data/lib/sdn/messages/control.rb +154 -0
- data/lib/sdn/messages/get.rb +99 -0
- data/lib/sdn/messages/helpers.rb +51 -0
- data/lib/sdn/messages/post.rb +162 -0
- data/lib/sdn/messages/set.rb +230 -0
- data/lib/sdn/mqtt_bridge.rb +494 -0
- data/lib/sdn/version.rb +3 -0
- data/lib/somfy_sdn.rb +2 -0
- metadata +109 -0
@@ -0,0 +1,230 @@
|
|
1
|
+
module SDN
|
2
|
+
class Message
|
3
|
+
class SetMotorLimits < Message
|
4
|
+
MSG = 0x11
|
5
|
+
PARAMS_LENGTH = 4
|
6
|
+
TYPE = { delete: 0x00, current_position: 0x01, specified_position: 0x02, jog_ms: 0x04, jog_pulses: 0x05 }
|
7
|
+
TARGET = { down: 0x00, up: 0x01 }
|
8
|
+
|
9
|
+
attr_reader :type, :target, :value
|
10
|
+
|
11
|
+
def initialize(dest = nil, type = :delete, target = :up, value = nil, **kwargs)
|
12
|
+
kwargs[:dest] = dest
|
13
|
+
super(**kwargs)
|
14
|
+
self.type = type
|
15
|
+
self.target = target
|
16
|
+
self.value = value
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse(params)
|
20
|
+
super
|
21
|
+
self.type = TYPE.invert[to_number(params[0])]
|
22
|
+
self.target = TARGET.invert[to_number(params[1])]
|
23
|
+
self.value = to_number(params[2..3])
|
24
|
+
end
|
25
|
+
|
26
|
+
def type=(value)
|
27
|
+
raise ArgumentError, "type must be one of :delete, :current_position, :specified_position, :jog_ms, :jog_pulses" unless TYPE.keys.include?(value)
|
28
|
+
@type = value
|
29
|
+
end
|
30
|
+
|
31
|
+
def target=(value)
|
32
|
+
raise ArgumentError, "target must be one of :up, :down" unless TARGET.keys.include?(value)
|
33
|
+
@target = value
|
34
|
+
end
|
35
|
+
|
36
|
+
def value=(value)
|
37
|
+
@value = value&. & 0xffff
|
38
|
+
end
|
39
|
+
|
40
|
+
def params
|
41
|
+
param = value || 0
|
42
|
+
param /= 10 if target == :jog_ms
|
43
|
+
transform_param(TYPE[type]) + transform_param(TARGET[target]) + from_number(param, 2)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class SetMotorDirection < Message
|
48
|
+
MSG = 0x12
|
49
|
+
PARAMS_LENGTH = 1
|
50
|
+
DIRECTION = { standard: 0x00, reversed: 0x01 }.freeze
|
51
|
+
|
52
|
+
attr_reader :direction
|
53
|
+
|
54
|
+
def initialize(dest = nil, direction = :standard, **kwargs)
|
55
|
+
kwargs[:dest] ||= dest
|
56
|
+
super(**kwargs)
|
57
|
+
self.direction = direction
|
58
|
+
end
|
59
|
+
|
60
|
+
def parse(params)
|
61
|
+
super
|
62
|
+
self.direction = DIRECTION.invert[to_number(params[0])]
|
63
|
+
end
|
64
|
+
|
65
|
+
def direction=(value)
|
66
|
+
raise ArgumentError, "direction must be one of :standard, :reversed" unless DIRECTION.keys.include?(value)
|
67
|
+
@direction = value
|
68
|
+
end
|
69
|
+
|
70
|
+
def params
|
71
|
+
transform_param(DIRECTION[direction])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class SetMotorRollingSpeed < Message
|
76
|
+
MSG = 0x13
|
77
|
+
PARAMS_LENGTH = 3
|
78
|
+
|
79
|
+
attr_accessor :up_speed, :down_speed, :slow_speed
|
80
|
+
def initialize(dest = nil, up_speed: nil, down_speed: nil, slow_speed: nil, **kwargs)
|
81
|
+
kwargs[:dest] ||= dest
|
82
|
+
super(**kwargs)
|
83
|
+
self.up_speed = up_speed
|
84
|
+
self.down_speed = down_speed
|
85
|
+
self.slow_speed = slow_speed
|
86
|
+
end
|
87
|
+
|
88
|
+
def parse(params)
|
89
|
+
super
|
90
|
+
self.up_speed = to_number(params[0])
|
91
|
+
self.down_speed = to_number(params[1])
|
92
|
+
self.slow_speed = to_number(params[2])
|
93
|
+
end
|
94
|
+
|
95
|
+
def params
|
96
|
+
transform_param(up_speed || 0xff) + transform_param(down_speed || 0xff) + transform_param(slow_speed || 0xff)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
class SetMotorIP < Message
|
101
|
+
MSG = 0x15
|
102
|
+
PARAMS_LENGTH = 4
|
103
|
+
# for distribute, value is how many IPs to distribute over
|
104
|
+
TYPE = { delete: 0x00, current_position: 0x01, position_pulses: 0x02, position_percent: 0x03, distribute: 0x04 }.freeze
|
105
|
+
|
106
|
+
attr_reader :type, :ip, :value
|
107
|
+
|
108
|
+
def initialize(dest = nil, type = :delete, ip = nil, value = nil, **kwargs)
|
109
|
+
kwargs[:dest] ||= dest
|
110
|
+
super(**kwargs)
|
111
|
+
self.type = type
|
112
|
+
self.ip = ip
|
113
|
+
self.value = value
|
114
|
+
end
|
115
|
+
|
116
|
+
def parse(params)
|
117
|
+
super
|
118
|
+
self.type = TYPE.invert[to_number(params[0])]
|
119
|
+
ip = to_number(params[1])
|
120
|
+
ip = nil if ip == 0
|
121
|
+
self.ip = ip
|
122
|
+
self.value = to_number(params[2..3])
|
123
|
+
end
|
124
|
+
|
125
|
+
def type=(value)
|
126
|
+
raise ArgumentError, "type must be one of :delete, :current_position, :position_pulses, :position_percent, :distribute" unless TYPE.keys.include?(value)
|
127
|
+
@type = value
|
128
|
+
end
|
129
|
+
|
130
|
+
def ip=(value)
|
131
|
+
raise ArgumentError, "ip must be in range 1..16 or nil" unless ip.nil? || (1..16).include?(ip)
|
132
|
+
@ip = value
|
133
|
+
end
|
134
|
+
|
135
|
+
def value=(value)
|
136
|
+
@value = value &. & 0xffff
|
137
|
+
end
|
138
|
+
|
139
|
+
def params
|
140
|
+
transform_param(TYPE[type]) + transform_param(ip || 0) + from_number(value || 0, 2)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
class SetFactoryDefault < Message
|
145
|
+
MSG = 0x1f
|
146
|
+
PARAMS_LENGTH = 1
|
147
|
+
RESET = { all_settings: 0x00, group_addresses: 0x01, limits: 0x11, rotation: 0x12, rolling_speed: 0x13, ips: 0x15, locks: 0x17 }
|
148
|
+
|
149
|
+
attr_reader :reset
|
150
|
+
|
151
|
+
def initialize(dest = nil, reset = :all_settings, **kwargs)
|
152
|
+
kwargs[:dest] ||= dest
|
153
|
+
super(**kwargs)
|
154
|
+
self.reset = reset
|
155
|
+
end
|
156
|
+
|
157
|
+
def parse(params)
|
158
|
+
super
|
159
|
+
self.reset = RESET.invert[to_number(params)]
|
160
|
+
end
|
161
|
+
|
162
|
+
def reset=(value)
|
163
|
+
raise ArgumentError, "reset must be one of :all_settings, :group_addresses, :limits, :rotation, :rolling_speed, :ips, :locks" unless RESET.keys.include?(value)
|
164
|
+
@reset = value
|
165
|
+
end
|
166
|
+
|
167
|
+
def params
|
168
|
+
transform_param(RESET[reset])
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
class SetGroupAddr < Message
|
173
|
+
MSG = 0x51
|
174
|
+
PARAMS_LENGTH = 4
|
175
|
+
|
176
|
+
attr_reader :group_index, :group_address
|
177
|
+
|
178
|
+
def initialize(dest = nil, group_index = 0, group_address = nil, **kwargs)
|
179
|
+
kwargs[:dest] ||= dest
|
180
|
+
super(**kwargs)
|
181
|
+
self.group_index = group_index
|
182
|
+
self.group_address = group_address
|
183
|
+
end
|
184
|
+
|
185
|
+
def parse(params)
|
186
|
+
super
|
187
|
+
self.group_index = to_number(params[0])
|
188
|
+
self.group_address = transform_param(params[1..3])
|
189
|
+
end
|
190
|
+
|
191
|
+
def group_index=(value)
|
192
|
+
raise ArgumentError, "group_index is out of range" unless (0...16).include?(value)
|
193
|
+
@group_index = value
|
194
|
+
end
|
195
|
+
|
196
|
+
def group_address=(value)
|
197
|
+
@group_address = value
|
198
|
+
end
|
199
|
+
|
200
|
+
def params
|
201
|
+
transform_param(group_index) + transform_param(group_address || [0, 0, 0])
|
202
|
+
end
|
203
|
+
|
204
|
+
def class_inspect
|
205
|
+
", group_index=#{group_index.inspect}, group_address=#{group_address ? print_address(group_address) : 'nil'}"
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
class SetNodeLabel < Message
|
210
|
+
MSG = 0x55
|
211
|
+
PARAMS_LENGTH = 16
|
212
|
+
|
213
|
+
attr_accessor :label
|
214
|
+
|
215
|
+
def initialize(dest = nil, label = '', **kwargs)
|
216
|
+
kwargs[:dest] ||= dest
|
217
|
+
super(**kwargs)
|
218
|
+
self.label = label
|
219
|
+
end
|
220
|
+
|
221
|
+
def parse(params)
|
222
|
+
self.label = to_string(params)
|
223
|
+
end
|
224
|
+
|
225
|
+
def params
|
226
|
+
from_string(label, 16)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|