|
@@ -12,6 +12,7 @@ import logging
|
12
|
12
|
import numbers
|
13
|
13
|
import os
|
14
|
14
|
import report
|
|
15
|
+import socket_protocol
|
15
|
16
|
import task
|
16
|
17
|
import tcp_socket
|
17
|
18
|
import time
|
|
@@ -63,22 +64,22 @@ class WetationFrameProt(gui.Wetation):
|
63
|
64
|
REQUEST_MSGS_SLOW = {
|
64
|
65
|
PROT_ID_IN: [
|
65
|
66
|
{
|
66
|
|
- 'service_id': wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST,
|
67
|
|
- 'data_id': wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_DHT,
|
|
67
|
+ 'service_id': socket_protocol.SID_READ_REQUEST,
|
|
68
|
+ 'data_id': wetation_protocol.ENVDATA_STATISTIC_DHT,
|
68
|
69
|
},
|
69
|
70
|
{
|
70
|
|
- 'service_id': wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST,
|
71
|
|
- 'data_id': wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP,
|
|
71
|
+ 'service_id': socket_protocol.SID_READ_REQUEST,
|
|
72
|
+ 'data_id': wetation_protocol.ENVDATA_STATISTIC_BMP,
|
72
|
73
|
},
|
73
|
74
|
],
|
74
|
75
|
PROT_ID_OUT: [
|
75
|
76
|
{
|
76
|
|
- 'service_id': wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST,
|
77
|
|
- 'data_id': wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_DHT,
|
|
77
|
+ 'service_id': socket_protocol.SID_READ_REQUEST,
|
|
78
|
+ 'data_id': wetation_protocol.ENVDATA_STATISTIC_DHT,
|
78
|
79
|
},
|
79
|
80
|
{
|
80
|
|
- 'service_id': wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST,
|
81
|
|
- 'data_id': wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP,
|
|
81
|
+ 'service_id': socket_protocol.SID_READ_REQUEST,
|
|
82
|
+ 'data_id': wetation_protocol.ENVDATA_STATISTIC_BMP,
|
82
|
83
|
},
|
83
|
84
|
],
|
84
|
85
|
}
|
|
@@ -86,8 +87,8 @@ class WetationFrameProt(gui.Wetation):
|
86
|
87
|
REQUEST_MSGS_FAST = {
|
87
|
88
|
PROT_ID_GARAGE: [
|
88
|
89
|
{
|
89
|
|
- 'service_id': garage_protocol.my_base_protocol_tcp.SID_READ_REQUEST,
|
90
|
|
- 'data_id': garage_protocol.my_base_protocol_tcp.GATE_POSITION,
|
|
90
|
+ 'service_id': socket_protocol.SID_READ_REQUEST,
|
|
91
|
+ 'data_id': garage_protocol.GATE_POSITION,
|
91
|
92
|
},
|
92
|
93
|
],
|
93
|
94
|
}
|
|
@@ -162,13 +163,13 @@ class WetationFrameProt(gui.Wetation):
|
162
|
163
|
cn = self.PROT_NAMES[prot_id]
|
163
|
164
|
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
|
164
|
165
|
if prot_id == self.PROT_ID_GARAGE:
|
165
|
|
- if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION:
|
|
166
|
+ if service_id == socket_protocol.SID_READ_RESPONSE and data_id == garage_protocol.GATE_POSITION:
|
166
|
167
|
rv = isinstance(data, numbers.Number)
|
167
|
|
- elif service_id == garage_protocol.my_base_protocol_tcp.SID_EXECUTE_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.OPEN_CLOSE_GATE:
|
|
168
|
+ elif service_id == socket_protocol.SID_EXECUTE_RESPONSE and data_id == garage_protocol.OPEN_CLOSE_GATE:
|
168
|
169
|
if data is True:
|
169
|
170
|
rv = True
|
170
|
171
|
elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]:
|
171
|
|
- if service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP:
|
|
172
|
+ if service_id == socket_protocol.SID_READ_RESPONSE and data_id == wetation_protocol.ENVDATA_STATISTIC_BMP:
|
172
|
173
|
rv = True
|
173
|
174
|
for main_key in [bmp_180.KEY_PRESSURE, bmp_180.KEY_TEMPERATURE, bmp_180.KEY_TIME]:
|
174
|
175
|
if main_key not in data:
|
|
@@ -179,7 +180,7 @@ class WetationFrameProt(gui.Wetation):
|
179
|
180
|
if not isinstance(data[main_key].get(sub_key), numbers.Number):
|
180
|
181
|
rv = False
|
181
|
182
|
break
|
182
|
|
- elif service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_DHT:
|
|
183
|
+ elif service_id == socket_protocol.SID_READ_RESPONSE and data_id == wetation_protocol.ENVDATA_STATISTIC_DHT:
|
183
|
184
|
rv = True
|
184
|
185
|
for main_key in [dht_22.KEY_HUMIDITY, dht_22.KEY_TEMPERATURE, dht_22.KEY_TIME]:
|
185
|
186
|
if main_key not in data:
|
|
@@ -200,16 +201,16 @@ class WetationFrameProt(gui.Wetation):
|
200
|
201
|
data = msg.get_data()
|
201
|
202
|
if self.__validate_response_data__(prot_id, service_id, data_id, data):
|
202
|
203
|
wx.CallAfter(self.__data__, prot_id, service_id, data_id, data)
|
203
|
|
- return wetation_protocol.my_base_protocol_tcp.STATUS_OKAY, None
|
|
204
|
+ return socket_protocol.STATUS_OKAY, None
|
204
|
205
|
else:
|
205
|
206
|
wx.CallAfter(self.__no_data__, prot_id, service_id, data_id)
|
206
|
|
- return wetation_protocol.my_base_protocol_tcp.STATUS_SERVICE_OR_DATA_UNKNOWN, None
|
|
207
|
+ return socket_protocol.STATUS_SERVICE_OR_DATA_UNKNOWN, None
|
207
|
208
|
|
208
|
209
|
def __no_data__(self, prot_id, service_id, data_id):
|
209
|
210
|
cn = self.PROT_NAMES[prot_id]
|
210
|
211
|
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
|
211
|
212
|
if prot_id == self.PROT_ID_GARAGE:
|
212
|
|
- if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION:
|
|
213
|
+ if service_id == socket_protocol.SID_READ_RESPONSE and data_id == garage_protocol.GATE_POSITION:
|
213
|
214
|
logger.warning('Resetting GUI elements for %s', cn)
|
214
|
215
|
self.heading_garage.Show(False)
|
215
|
216
|
self.gate_oc.Show(False)
|
|
@@ -218,10 +219,10 @@ class WetationFrameProt(gui.Wetation):
|
218
|
219
|
self.gate_close.Show(False)
|
219
|
220
|
self.Layout()
|
220
|
221
|
return
|
221
|
|
- elif service_id == garage_protocol.my_base_protocol_tcp.SID_EXECUTE_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.OPEN_CLOSE_GATE:
|
|
222
|
+ elif service_id == socket_protocol.SID_EXECUTE_RESPONSE and data_id == garage_protocol.OPEN_CLOSE_GATE:
|
222
|
223
|
return
|
223
|
224
|
elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]:
|
224
|
|
- if service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP:
|
|
225
|
+ if service_id == socket_protocol.SID_READ_RESPONSE and data_id == wetation_protocol.ENVDATA_STATISTIC_BMP:
|
225
|
226
|
logger.warning('Resetting GUI elements for %s', cn)
|
226
|
227
|
txt_pressure = '- hPa'
|
227
|
228
|
if prot_id == self.PROT_ID_IN:
|
|
@@ -230,7 +231,7 @@ class WetationFrameProt(gui.Wetation):
|
230
|
231
|
self.out_pressure.SetLabel(txt_pressure)
|
231
|
232
|
self.Layout()
|
232
|
233
|
return
|
233
|
|
- elif service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_DHT:
|
|
234
|
+ elif service_id == socket_protocol.SID_READ_RESPONSE and data_id == wetation_protocol.ENVDATA_STATISTIC_DHT:
|
234
|
235
|
logger.warning('Resetting GUI elements for %s', cn)
|
235
|
236
|
txt_temperature = '-.- °C'
|
236
|
237
|
txt_humidity = '-.- %'
|
|
@@ -248,7 +249,7 @@ class WetationFrameProt(gui.Wetation):
|
248
|
249
|
cn = self.PROT_NAMES[prot_id]
|
249
|
250
|
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
|
250
|
251
|
if prot_id == self.PROT_ID_GARAGE:
|
251
|
|
- if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION:
|
|
252
|
+ if service_id == socket_protocol.SID_READ_RESPONSE and data_id == garage_protocol.GATE_POSITION:
|
252
|
253
|
logger.debug('Setting %s position to %3d', cn, int(data * 100))
|
253
|
254
|
self.heading_garage.Show(True)
|
254
|
255
|
self.gate_oc.Show(True)
|
|
@@ -258,10 +259,10 @@ class WetationFrameProt(gui.Wetation):
|
258
|
259
|
self.gate_position.SetValue(int(data * 100))
|
259
|
260
|
self.Layout()
|
260
|
261
|
return
|
261
|
|
- elif service_id == garage_protocol.my_base_protocol_tcp.SID_EXECUTE_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.OPEN_CLOSE_GATE:
|
|
262
|
+ elif service_id == socket_protocol.SID_EXECUTE_RESPONSE and data_id == garage_protocol.OPEN_CLOSE_GATE:
|
262
|
263
|
return
|
263
|
264
|
elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]:
|
264
|
|
- if service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP:
|
|
265
|
+ if service_id == socket_protocol.SID_READ_RESPONSE and data_id == wetation_protocol.ENVDATA_STATISTIC_BMP:
|
265
|
266
|
data = helpers.continues_statistic_multivalue(**data)
|
266
|
267
|
logger.debug('Setting %s pressure to %4d hPa', cn, data[bmp_180.KEY_PRESSURE].mean)
|
267
|
268
|
#
|
|
@@ -271,7 +272,7 @@ class WetationFrameProt(gui.Wetation):
|
271
|
272
|
else:
|
272
|
273
|
wx.CallAfter(self.update_current_bmp_env_data, data, self.out_pressure)
|
273
|
274
|
return
|
274
|
|
- elif service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_DHT:
|
|
275
|
+ elif service_id == socket_protocol.SID_READ_RESPONSE and data_id == wetation_protocol.ENVDATA_STATISTIC_DHT:
|
275
|
276
|
data = helpers.continues_statistic_multivalue(**data)
|
276
|
277
|
#
|
277
|
278
|
# Current environmental data
|
|
@@ -321,7 +322,7 @@ class WetationFrameProt(gui.Wetation):
|
321
|
322
|
).ShowModal()
|
322
|
323
|
if r == wx.ID_YES:
|
323
|
324
|
logger.debug("Gate open/close request")
|
324
|
|
- self.__prot__[self.PROT_ID_GARAGE].send(garage_protocol.my_base_protocol_tcp.SID_EXECUTE_REQUEST, garage_protocol.my_base_protocol_tcp.OPEN_CLOSE_GATE, None)
|
|
325
|
+ self.__prot__[self.PROT_ID_GARAGE].send(socket_protocol.SID_EXECUTE_REQUEST, garage_protocol.OPEN_CLOSE_GATE, None)
|
325
|
326
|
event.Skip()
|
326
|
327
|
|
327
|
328
|
def reset_in_temp_minmax_evt(self, event):
|