1
- # Wirepas Oy
1
+ # Copyright Wirepas Ltd 2019
2
2
3
3
import wirepas_messaging
4
4
@@ -14,16 +14,20 @@ def convert_proto_role_to_wirepas(base, flags):
14
14
Returns:
15
15
Wirepas role as an int
16
16
"""
17
- base_proto_to_wirepas = dict ([
18
- (wirepas_messaging .gateway .NodeRole .SINK , 1 ),
19
- (wirepas_messaging .gateway .NodeRole .ROUTER , 2 ),
20
- (wirepas_messaging .gateway .NodeRole .NON_ROUTER , 3 )
21
- ])
22
-
23
- flag_proto_to_wirepas = dict ([
24
- (wirepas_messaging .gateway .NodeRole .LOW_LATENCY , 0x10 ),
25
- (wirepas_messaging .gateway .NodeRole .AUTOROLE , 0x80 )
26
- ])
17
+ base_proto_to_wirepas = dict (
18
+ [
19
+ (wirepas_messaging .gateway .NodeRole .SINK , 1 ),
20
+ (wirepas_messaging .gateway .NodeRole .ROUTER , 2 ),
21
+ (wirepas_messaging .gateway .NodeRole .NON_ROUTER , 3 ),
22
+ ]
23
+ )
24
+
25
+ flag_proto_to_wirepas = dict (
26
+ [
27
+ (wirepas_messaging .gateway .NodeRole .LOW_LATENCY , 0x10 ),
28
+ (wirepas_messaging .gateway .NodeRole .AUTOROLE , 0x80 ),
29
+ ]
30
+ )
27
31
28
32
wirepas_role = base_proto_to_wirepas [base ]
29
33
@@ -43,23 +47,27 @@ def convert_wirepas_role_to_proto(wirepas_role):
43
47
Returns:
44
48
Tupple with protocol buffer base and flags
45
49
"""
46
- wirepas_base = wirepas_role & 0xf
47
-
48
- wirepas_base_to_proto = dict ([
49
- (1 , wirepas_messaging .gateway .NodeRole .SINK ),
50
- (2 , wirepas_messaging .gateway .NodeRole .ROUTER ),
51
- (3 , wirepas_messaging .gateway .NodeRole .NON_ROUTER )
52
- ])
53
-
54
- flag_proto_to_wirepas = dict ([
55
- (0x10 , wirepas_messaging .gateway .NodeRole .LOW_LATENCY ),
56
- (0x80 , wirepas_messaging .gateway .NodeRole .AUTOROLE )
57
- ])
50
+ wirepas_base = wirepas_role & 0xF
51
+
52
+ wirepas_base_to_proto = dict (
53
+ [
54
+ (1 , wirepas_messaging .gateway .NodeRole .SINK ),
55
+ (2 , wirepas_messaging .gateway .NodeRole .ROUTER ),
56
+ (3 , wirepas_messaging .gateway .NodeRole .NON_ROUTER ),
57
+ ]
58
+ )
59
+
60
+ flag_proto_to_wirepas = dict (
61
+ [
62
+ (0x10 , wirepas_messaging .gateway .NodeRole .LOW_LATENCY ),
63
+ (0x80 , wirepas_messaging .gateway .NodeRole .AUTOROLE ),
64
+ ]
65
+ )
58
66
59
67
base = wirepas_base_to_proto [wirepas_base ]
60
68
61
69
flags = []
62
- flags_val = wirepas_role & 0xf0
70
+ flags_val = wirepas_role & 0xF0
63
71
for flag in flag_proto_to_wirepas :
64
72
if flag & flags_val != 0 :
65
73
flags .append (flag_proto_to_wirepas [flag ])
@@ -116,26 +124,23 @@ def parse_config_rw(message_obj, dic):
116
124
117
125
if message_obj .HasField ("node_role" ):
118
126
dic ["node_role" ] = convert_proto_role_to_wirepas (
119
- message_obj .node_role .role , message_obj .node_role .flags )
127
+ message_obj .node_role .role , message_obj .node_role .flags
128
+ )
120
129
130
+ parse_optional_field (message_obj , "node_address" , dic , "node_address" )
131
+ parse_optional_field (message_obj , "network_address" , dic , "network_address" )
132
+ parse_optional_field (message_obj , "network_channel" , dic , "network_channel" )
121
133
parse_optional_field (
122
- message_obj , "node_address" , dic , "node_address" )
123
- parse_optional_field (
124
- message_obj , "network_address" , dic , "network_address" )
125
- parse_optional_field (
126
- message_obj , "network_channel" , dic , "network_channel" )
134
+ message_obj .app_config , "diag_interval_s" , dic , "app_config_diag"
135
+ )
136
+ parse_optional_field (message_obj .app_config , "seq" , dic , "app_config_seq" )
127
137
parse_optional_field (
128
- message_obj .app_config , "diag_interval_s" , dic , "app_config_diag" )
129
- parse_optional_field (
130
- message_obj .app_config , "seq" , dic , "app_config_seq" )
131
- parse_optional_field (
132
- message_obj .app_config , "app_config_data" , dic , "app_config_data" )
133
- parse_optional_field (
134
- message_obj , "channel_map" , dic , "channel_map" )
138
+ message_obj .app_config , "app_config_data" , dic , "app_config_data"
139
+ )
140
+ parse_optional_field (message_obj , "channel_map" , dic , "channel_map" )
135
141
136
142
if message_obj .HasField ("sink_state" ):
137
- dic ["started" ] = (message_obj .sink_state ==
138
- wirepas_messaging .gateway .ON )
143
+ dic ["started" ] = message_obj .sink_state == wirepas_messaging .gateway .ON
139
144
140
145
141
146
def set_config_rw (message_obj , dic ):
@@ -155,27 +160,22 @@ def set_config_rw(message_obj, dic):
155
160
# Field is unknown, just skip it
156
161
pass
157
162
158
- set_optional_field (
159
- message_obj , "node_address" , dic , "node_address" )
160
- set_optional_field (
161
- message_obj , "network_address" , dic , "network_address" )
162
- set_optional_field (
163
- message_obj , "network_channel" , dic , "network_channel" )
163
+ set_optional_field (message_obj , "node_address" , dic , "node_address" )
164
+ set_optional_field (message_obj , "network_address" , dic , "network_address" )
165
+ set_optional_field (message_obj , "network_channel" , dic , "network_channel" )
164
166
165
167
set_optional_field (
166
- message_obj .app_config , "diag_interval_s" , dic , "app_config_diag" )
167
- set_optional_field (
168
- message_obj .app_config , "seq" , dic , "app_config_seq" )
168
+ message_obj .app_config , "diag_interval_s" , dic , "app_config_diag"
169
+ )
170
+ set_optional_field ( message_obj .app_config , "seq" , dic , "app_config_seq" )
169
171
170
172
try :
171
- message_obj .app_config .app_config_data = bytes (
172
- dic ["app_config_data" ])
173
+ message_obj .app_config .app_config_data = bytes (dic ["app_config_data" ])
173
174
except KeyError :
174
175
# Field is unknown, just skip it
175
176
pass
176
177
177
- set_optional_field (
178
- message_obj , "channel_map" , dic , "channel_map" )
178
+ set_optional_field (message_obj , "channel_map" , dic , "channel_map" )
179
179
180
180
try :
181
181
if dic ["started" ]:
@@ -198,10 +198,8 @@ def parse_config_keys(message_obj, dic):
198
198
dic (dict): the dictionary where to copy the keys into
199
199
"""
200
200
201
- parse_optional_field (
202
- message_obj .keys , "cipher" , dic , "cipher_key" )
203
- parse_optional_field (
204
- message_obj .keys , "authentication" , dic , "authentication_key" )
201
+ parse_optional_field (message_obj .keys , "cipher" , dic , "cipher_key" )
202
+ parse_optional_field (message_obj .keys , "authentication" , dic , "authentication_key" )
205
203
206
204
207
205
def set_config_keys (message_obj , dic ):
@@ -214,10 +212,8 @@ def set_config_keys(message_obj, dic):
214
212
message_obj (proto): protocol buffer object
215
213
dic (dict): the dictionary where to copy the keys from
216
214
"""
217
- set_optional_field (
218
- message_obj , "cipher" , dic , "cipher_key" )
219
- set_optional_field (
220
- message_obj , "authentication" , dic , "authentication_key" )
215
+ set_optional_field (message_obj , "cipher" , dic , "cipher_key" )
216
+ set_optional_field (message_obj , "authentication" , dic , "authentication_key" )
221
217
222
218
223
219
def parse_config_ro (message_obj , dic ):
@@ -230,36 +226,31 @@ def parse_config_ro(message_obj, dic):
230
226
231
227
"""
232
228
parse_optional_field (
233
- message_obj .current_ac_range , "min_ms" , dic , "current_ac_range_min" )
229
+ message_obj .current_ac_range , "min_ms" , dic , "current_ac_range_min"
230
+ )
234
231
parse_optional_field (
235
- message_obj .current_ac_range , "max_ms" , dic , "current_ac_range_max" )
232
+ message_obj .current_ac_range , "max_ms" , dic , "current_ac_range_max"
233
+ )
236
234
237
- parse_optional_field (
238
- message_obj .ac_limits , "min_ms" , dic , "min_ac" )
239
- parse_optional_field (
240
- message_obj .ac_limits , "max_ms" , dic , "max_ac" )
235
+ parse_optional_field (message_obj .ac_limits , "min_ms" , dic , "min_ac" )
236
+ parse_optional_field (message_obj .ac_limits , "max_ms" , dic , "max_ac" )
241
237
242
- parse_optional_field (
243
- message_obj , "max_mtu" , dic , "max_mtu" )
238
+ parse_optional_field (message_obj , "max_mtu" , dic , "max_mtu" )
244
239
245
- parse_optional_field (
246
- message_obj .channel_limits , "min_channel" , dic , "min_ch" )
247
- parse_optional_field (
248
- message_obj .channel_limits , "max_channel" , dic , "max_ch" )
249
- parse_optional_field (
250
- message_obj , "hw_magic" , dic , "hw_magic" )
251
- parse_optional_field (
252
- message_obj , "stack_profile" , dic , "stack_profile" )
253
- parse_optional_field (
254
- message_obj , "app_config_max_size" , dic , "app_config_max_size" )
255
- parse_optional_field (
256
- message_obj , "are_keys_set" , dic , "are_keys_set" )
240
+ parse_optional_field (message_obj .channel_limits , "min_channel" , dic , "min_ch" )
241
+ parse_optional_field (message_obj .channel_limits , "max_channel" , dic , "max_ch" )
242
+ parse_optional_field (message_obj , "hw_magic" , dic , "hw_magic" )
243
+ parse_optional_field (message_obj , "stack_profile" , dic , "stack_profile" )
244
+ parse_optional_field (message_obj , "app_config_max_size" , dic , "app_config_max_size" )
245
+ parse_optional_field (message_obj , "are_keys_set" , dic , "are_keys_set" )
257
246
258
247
if message_obj .HasField ("firmware_version" ):
259
- dic ["firmware_version" ] = [message_obj .firmware_version .major ,
260
- message_obj .firmware_version .minor ,
261
- message_obj .firmware_version .maint ,
262
- message_obj .firmware_version .dev ]
248
+ dic ["firmware_version" ] = [
249
+ message_obj .firmware_version .major ,
250
+ message_obj .firmware_version .minor ,
251
+ message_obj .firmware_version .maint ,
252
+ message_obj .firmware_version .dev ,
253
+ ]
263
254
264
255
265
256
def set_config_ro (message_obj , dic ):
@@ -271,32 +262,21 @@ def set_config_ro(message_obj, dic):
271
262
dic (dict): the dictionary where to copy the ro fields from
272
263
273
264
"""
274
- set_optional_field (
275
- message_obj .current_ac_range , "min_ms" , dic , "min_ac_cur" )
276
- set_optional_field (
277
- message_obj .current_ac_range , "max_ms" , dic , "max_ac_cur" )
265
+ set_optional_field (message_obj .current_ac_range , "min_ms" , dic , "min_ac_cur" )
266
+ set_optional_field (message_obj .current_ac_range , "max_ms" , dic , "max_ac_cur" )
278
267
279
- set_optional_field (
280
- message_obj .ac_limits , "min_ms" , dic , "min_ac" )
281
- set_optional_field (
282
- message_obj .ac_limits , "max_ms" , dic , "max_ac" )
268
+ set_optional_field (message_obj .ac_limits , "min_ms" , dic , "min_ac" )
269
+ set_optional_field (message_obj .ac_limits , "max_ms" , dic , "max_ac" )
283
270
284
- set_optional_field (
285
- message_obj , "max_mtu" , dic , "max_mtu" )
271
+ set_optional_field (message_obj , "max_mtu" , dic , "max_mtu" )
286
272
287
- set_optional_field (
288
- message_obj .channel_limits , "min_channel" , dic , "min_ch" )
289
- set_optional_field (
290
- message_obj .channel_limits , "max_channel" , dic , "max_ch" )
273
+ set_optional_field (message_obj .channel_limits , "min_channel" , dic , "min_ch" )
274
+ set_optional_field (message_obj .channel_limits , "max_channel" , dic , "max_ch" )
291
275
292
- set_optional_field (
293
- message_obj , "hw_magic" , dic , "hw_magic" )
294
- set_optional_field (
295
- message_obj , "stack_profile" , dic , "stack_profile" )
296
- set_optional_field (
297
- message_obj , "app_config_max_size" , dic , "app_config_max_size" )
298
- set_optional_field (
299
- message_obj , "are_keys_set" , dic , "are_keys_set" )
276
+ set_optional_field (message_obj , "hw_magic" , dic , "hw_magic" )
277
+ set_optional_field (message_obj , "stack_profile" , dic , "stack_profile" )
278
+ set_optional_field (message_obj , "app_config_max_size" , dic , "app_config_max_size" )
279
+ set_optional_field (message_obj , "are_keys_set" , dic , "are_keys_set" )
300
280
301
281
try :
302
282
message_obj .firmware_version .major = dic ["firmware_version" ][0 ]
0 commit comments