|
|
|
@ -12,7 +12,6 @@ import logging
|
|
|
|
|
import numbers
|
|
|
|
|
import os
|
|
|
|
|
import report
|
|
|
|
|
import socket_protocol
|
|
|
|
|
import task
|
|
|
|
|
import tcp_socket
|
|
|
|
|
import time
|
|
|
|
@ -64,22 +63,22 @@ class WetationFrameProt(gui.Wetation):
|
|
|
|
|
REQUEST_MSGS_SLOW = {
|
|
|
|
|
PROT_ID_IN: [
|
|
|
|
|
{
|
|
|
|
|
'service_id': socket_protocol.SID_READ_REQUEST,
|
|
|
|
|
'data_id': wetation_protocol.ENVDATA_STATISTIC_DHT,
|
|
|
|
|
'service_id': wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST,
|
|
|
|
|
'data_id': wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_DHT,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
'service_id': socket_protocol.SID_READ_REQUEST,
|
|
|
|
|
'data_id': wetation_protocol.ENVDATA_STATISTIC_BMP,
|
|
|
|
|
'service_id': wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST,
|
|
|
|
|
'data_id': wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
PROT_ID_OUT: [
|
|
|
|
|
{
|
|
|
|
|
'service_id': socket_protocol.SID_READ_REQUEST,
|
|
|
|
|
'data_id': wetation_protocol.ENVDATA_STATISTIC_DHT,
|
|
|
|
|
'service_id': wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST,
|
|
|
|
|
'data_id': wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_DHT,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
'service_id': socket_protocol.SID_READ_REQUEST,
|
|
|
|
|
'data_id': wetation_protocol.ENVDATA_STATISTIC_BMP,
|
|
|
|
|
'service_id': wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST,
|
|
|
|
|
'data_id': wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
@ -87,8 +86,8 @@ class WetationFrameProt(gui.Wetation):
|
|
|
|
|
REQUEST_MSGS_FAST = {
|
|
|
|
|
PROT_ID_GARAGE: [
|
|
|
|
|
{
|
|
|
|
|
'service_id': socket_protocol.SID_READ_REQUEST,
|
|
|
|
|
'data_id': garage_protocol.GATE_POSITION,
|
|
|
|
|
'service_id': garage_protocol.my_base_protocol_tcp.SID_READ_REQUEST,
|
|
|
|
|
'data_id': garage_protocol.my_base_protocol_tcp.GATE_POSITION,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
@ -121,7 +120,7 @@ class WetationFrameProt(gui.Wetation):
|
|
|
|
|
cn = self.PROT_NAMES[prot_id]
|
|
|
|
|
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
|
|
|
|
|
logger.info('Initiating communication channel')
|
|
|
|
|
c_tcp = tcp_socket.tcp_client_stp(self.PROT_IPS[prot_id], self.PROT_PORTS[prot_id])
|
|
|
|
|
c_tcp = tcp_socket.tcp_client_stp(self.PROT_IPS[prot_id], self.PROT_PORTS[prot_id], rx_log_lvl=logging.DEBUG)
|
|
|
|
|
self.__prot__[prot_id] = self.PROT_CLASSES[prot_id](c_tcp, secret=self.PROT_SECRETS[prot_id], auto_auth=True, channel_name=cn)
|
|
|
|
|
#
|
|
|
|
|
self.__prot__[prot_id].register_callback(None, None, self.__prot_resp_callbacks__, prot_id)
|
|
|
|
@ -163,13 +162,13 @@ class WetationFrameProt(gui.Wetation):
|
|
|
|
|
cn = self.PROT_NAMES[prot_id]
|
|
|
|
|
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
|
|
|
|
|
if prot_id == self.PROT_ID_GARAGE:
|
|
|
|
|
if service_id == socket_protocol.SID_READ_RESPONSE and data_id == garage_protocol.GATE_POSITION:
|
|
|
|
|
if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION:
|
|
|
|
|
rv = isinstance(data, numbers.Number)
|
|
|
|
|
elif service_id == socket_protocol.SID_EXECUTE_RESPONSE and data_id == garage_protocol.OPEN_CLOSE_GATE:
|
|
|
|
|
elif service_id == garage_protocol.my_base_protocol_tcp.SID_EXECUTE_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.OPEN_CLOSE_GATE:
|
|
|
|
|
if data is True:
|
|
|
|
|
rv = True
|
|
|
|
|
elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]:
|
|
|
|
|
if service_id == socket_protocol.SID_READ_RESPONSE and data_id == wetation_protocol.ENVDATA_STATISTIC_BMP:
|
|
|
|
|
if service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP:
|
|
|
|
|
rv = True
|
|
|
|
|
for main_key in [bmp_180.KEY_PRESSURE, bmp_180.KEY_TEMPERATURE, bmp_180.KEY_TIME]:
|
|
|
|
|
if main_key not in data:
|
|
|
|
@ -180,7 +179,7 @@ class WetationFrameProt(gui.Wetation):
|
|
|
|
|
if not isinstance(data[main_key].get(sub_key), numbers.Number):
|
|
|
|
|
rv = False
|
|
|
|
|
break
|
|
|
|
|
elif service_id == socket_protocol.SID_READ_RESPONSE and data_id == wetation_protocol.ENVDATA_STATISTIC_DHT:
|
|
|
|
|
elif service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_DHT:
|
|
|
|
|
rv = True
|
|
|
|
|
for main_key in [dht_22.KEY_HUMIDITY, dht_22.KEY_TEMPERATURE, dht_22.KEY_TIME]:
|
|
|
|
|
if main_key not in data:
|
|
|
|
@ -201,16 +200,16 @@ class WetationFrameProt(gui.Wetation):
|
|
|
|
|
data = msg.get_data()
|
|
|
|
|
if self.__validate_response_data__(prot_id, service_id, data_id, data):
|
|
|
|
|
wx.CallAfter(self.__data__, prot_id, service_id, data_id, data)
|
|
|
|
|
return socket_protocol.STATUS_OKAY, None
|
|
|
|
|
return wetation_protocol.my_base_protocol_tcp.STATUS_OKAY, None
|
|
|
|
|
else:
|
|
|
|
|
wx.CallAfter(self.__no_data__, prot_id, service_id, data_id)
|
|
|
|
|
return socket_protocol.STATUS_SERVICE_OR_DATA_UNKNOWN, None
|
|
|
|
|
return wetation_protocol.my_base_protocol_tcp.STATUS_SERVICE_OR_DATA_UNKNOWN, None
|
|
|
|
|
|
|
|
|
|
def __no_data__(self, prot_id, service_id, data_id):
|
|
|
|
|
cn = self.PROT_NAMES[prot_id]
|
|
|
|
|
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
|
|
|
|
|
if prot_id == self.PROT_ID_GARAGE:
|
|
|
|
|
if service_id == socket_protocol.SID_READ_RESPONSE and data_id == garage_protocol.GATE_POSITION:
|
|
|
|
|
if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION:
|
|
|
|
|
logger.warning('Resetting GUI elements for %s', cn)
|
|
|
|
|
self.heading_garage.Show(False)
|
|
|
|
|
self.gate_oc.Show(False)
|
|
|
|
@ -219,10 +218,10 @@ class WetationFrameProt(gui.Wetation):
|
|
|
|
|
self.gate_close.Show(False)
|
|
|
|
|
self.Layout()
|
|
|
|
|
return
|
|
|
|
|
elif service_id == socket_protocol.SID_EXECUTE_RESPONSE and data_id == garage_protocol.OPEN_CLOSE_GATE:
|
|
|
|
|
elif service_id == garage_protocol.my_base_protocol_tcp.SID_EXECUTE_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.OPEN_CLOSE_GATE:
|
|
|
|
|
return
|
|
|
|
|
elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]:
|
|
|
|
|
if service_id == socket_protocol.SID_READ_RESPONSE and data_id == wetation_protocol.ENVDATA_STATISTIC_BMP:
|
|
|
|
|
if service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP:
|
|
|
|
|
logger.warning('Resetting GUI elements for %s', cn)
|
|
|
|
|
txt_pressure = '- hPa'
|
|
|
|
|
if prot_id == self.PROT_ID_IN:
|
|
|
|
@ -231,7 +230,7 @@ class WetationFrameProt(gui.Wetation):
|
|
|
|
|
self.out_pressure.SetLabel(txt_pressure)
|
|
|
|
|
self.Layout()
|
|
|
|
|
return
|
|
|
|
|
elif service_id == socket_protocol.SID_READ_RESPONSE and data_id == wetation_protocol.ENVDATA_STATISTIC_DHT:
|
|
|
|
|
elif service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_DHT:
|
|
|
|
|
logger.warning('Resetting GUI elements for %s', cn)
|
|
|
|
|
txt_temperature = '-.- °C'
|
|
|
|
|
txt_humidity = '-.- %'
|
|
|
|
@ -249,7 +248,7 @@ class WetationFrameProt(gui.Wetation):
|
|
|
|
|
cn = self.PROT_NAMES[prot_id]
|
|
|
|
|
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
|
|
|
|
|
if prot_id == self.PROT_ID_GARAGE:
|
|
|
|
|
if service_id == socket_protocol.SID_READ_RESPONSE and data_id == garage_protocol.GATE_POSITION:
|
|
|
|
|
if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION:
|
|
|
|
|
logger.debug('Setting %s position to %3d', cn, int(data * 100))
|
|
|
|
|
self.heading_garage.Show(True)
|
|
|
|
|
self.gate_oc.Show(True)
|
|
|
|
@ -259,10 +258,10 @@ class WetationFrameProt(gui.Wetation):
|
|
|
|
|
self.gate_position.SetValue(int(data * 100))
|
|
|
|
|
self.Layout()
|
|
|
|
|
return
|
|
|
|
|
elif service_id == socket_protocol.SID_EXECUTE_RESPONSE and data_id == garage_protocol.OPEN_CLOSE_GATE:
|
|
|
|
|
elif service_id == garage_protocol.my_base_protocol_tcp.SID_EXECUTE_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.OPEN_CLOSE_GATE:
|
|
|
|
|
return
|
|
|
|
|
elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]:
|
|
|
|
|
if service_id == socket_protocol.SID_READ_RESPONSE and data_id == wetation_protocol.ENVDATA_STATISTIC_BMP:
|
|
|
|
|
if service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP:
|
|
|
|
|
data = helpers.continues_statistic_multivalue(**data)
|
|
|
|
|
logger.debug('Setting %s pressure to %4d hPa', cn, data[bmp_180.KEY_PRESSURE].mean)
|
|
|
|
|
#
|
|
|
|
@ -272,7 +271,7 @@ class WetationFrameProt(gui.Wetation):
|
|
|
|
|
else:
|
|
|
|
|
wx.CallAfter(self.update_current_bmp_env_data, data, self.out_pressure)
|
|
|
|
|
return
|
|
|
|
|
elif service_id == socket_protocol.SID_READ_RESPONSE and data_id == wetation_protocol.ENVDATA_STATISTIC_DHT:
|
|
|
|
|
elif service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_DHT:
|
|
|
|
|
data = helpers.continues_statistic_multivalue(**data)
|
|
|
|
|
#
|
|
|
|
|
# Current environmental data
|
|
|
|
@ -322,7 +321,7 @@ class WetationFrameProt(gui.Wetation):
|
|
|
|
|
).ShowModal()
|
|
|
|
|
if r == wx.ID_YES:
|
|
|
|
|
logger.debug("Gate open/close request")
|
|
|
|
|
self.__prot__[self.PROT_ID_GARAGE].send(socket_protocol.SID_EXECUTE_REQUEST, garage_protocol.OPEN_CLOSE_GATE, None)
|
|
|
|
|
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)
|
|
|
|
|
event.Skip()
|
|
|
|
|
|
|
|
|
|
def reset_in_temp_minmax_evt(self, event):
|
|
|
|
@ -369,7 +368,7 @@ class MyApp(wx.App):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
report.appLoggingConfigure(os.path.dirname(__file__), config.LOGTARGET, ((config.APP_NAME, config.LOGLVL), ), fmt=config.formatter, host=config.LOGHOST, port=config.LOGPORT)
|
|
|
|
|
report.appLoggingConfigure(os.path.dirname(__file__), config.LOGTARGET, ((config.APP_NAME, 'DEBUG'), ), fmt=config.formatter, host=config.LOGHOST, port=config.LOGPORT)
|
|
|
|
|
#
|
|
|
|
|
app = MyApp(0)
|
|
|
|
|
app.frame.run()
|
|
|
|
|