Cyclic reconnect and fast and slow request tasks implemented
This commit is contained in:
parent
fe44be82de
commit
2e01d3b503
4
kill.sh
Executable file
4
kill.sh
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
pid=`ps -aef | grep -i 'smarthome.py' | grep -v 'grep' | awk '{print $2}'`
|
||||
kill $pid
|
8
restart.sh
Executable file
8
restart.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
|
||||
BASEDIR=`dirname $0`
|
||||
#
|
||||
$BASEDIR/kill.sh
|
||||
rm -f $BASEDIR/messages.*
|
||||
$BASEDIR/start.sh
|
45
smarthome.py
45
smarthome.py
@ -24,7 +24,9 @@ class WetationFrameProt(gui.Wetation):
|
||||
PROT_ID_GARAGE = 0
|
||||
PROT_ID_IN = 1
|
||||
PROT_ID_OUT = 2
|
||||
ALL_PROT_IDS = [PROT_ID_GARAGE, PROT_ID_IN, PROT_ID_OUT]
|
||||
ALL_PROT_IDS = [PROT_ID_GARAGE, PROT_ID_IN, PROT_ID_OUT, ]
|
||||
SLOW_PROT_IDS = [PROT_ID_IN, PROT_ID_OUT, ]
|
||||
FAST_PROT_IDS = [PROT_ID_GARAGE, ]
|
||||
|
||||
REQUEST_MSGS = {
|
||||
PROT_ID_GARAGE: [
|
||||
@ -59,7 +61,9 @@ class WetationFrameProt(gui.Wetation):
|
||||
self.ShowFullScreen(config.FULL_SCREEN)
|
||||
|
||||
self.__init_communication__()
|
||||
self.__task_data_request__ = task.periodic(10, self.__initiate_data_request__)
|
||||
self.__task_1s__ = task.periodic(1, self.__task_1s_callback__)
|
||||
self.__task_10s__ = task.periodic(10, self.__task_10s_callback__)
|
||||
self.__task_60s__ = task.periodic(60, self.__task_60s_callback__)
|
||||
|
||||
def __init_protocol__(self, prot_id, ip, port, prot_class, secret):
|
||||
c_tcp = tcp_socket.tcp_client_stp(ip, port, rx_log_lvl=logging.DEBUG)
|
||||
@ -97,8 +101,25 @@ class WetationFrameProt(gui.Wetation):
|
||||
)
|
||||
self.__prot__[self.PROT_ID_OUT].register_callback(wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE, None, self.__out_data__)
|
||||
|
||||
def __initiate_data_request__(self, rt):
|
||||
def __task_1s_callback__(self, rt):
|
||||
# request data from fast prot ids
|
||||
self.__initiate_data_request__(rt, self.FAST_PROT_IDS)
|
||||
# set date and time
|
||||
wx.CallAfter(self.update_time)
|
||||
|
||||
def __task_10s_callback__(self, rt):
|
||||
# request data from slow prot ids
|
||||
self.__initiate_data_request__(rt, self.SLOW_PROT_IDS)
|
||||
|
||||
def __task_60s_callback__(self, rt):
|
||||
# reconnect prots if needed
|
||||
for prot_id in self.ALL_PROT_IDS:
|
||||
if not self.__prot__[prot_id].is_connected():
|
||||
logger.debug("Trying to reconnect prot_id %d", prot_id)
|
||||
self.__prot__[prot_id].reconnect()
|
||||
|
||||
def __initiate_data_request__(self, rt, prot_ids):
|
||||
for prot_id in prot_ids:
|
||||
if self.__prot__[prot_id].is_connected():
|
||||
for request_msg in self.REQUEST_MSGS.get(prot_id, []):
|
||||
service_id = request_msg['service_id']
|
||||
@ -109,9 +130,6 @@ class WetationFrameProt(gui.Wetation):
|
||||
logger.debug('Resetting GUI for prot_id %d', prot_id)
|
||||
wx.CallAfter(self.no_data[prot_id], None)
|
||||
|
||||
# TODO: Move the following three lines to the wx idle task
|
||||
wx.CallAfter(self.update_time)
|
||||
|
||||
def __in_data__(self, msg):
|
||||
return self.__env_data__(msg, self.PROT_ID_IN)
|
||||
|
||||
@ -193,15 +211,22 @@ class WetationFrameProt(gui.Wetation):
|
||||
self.Layout()
|
||||
|
||||
def gate_oc_evt(self, event): # wxGlade: Wetation.<event_handler>
|
||||
self.prot_garage.send(garage_protocol.my_base_protocol_tcp.SID_EXECUTE_REQUEST, garage_protocol.my_base_protocol_tcp.OPEN_CLOSE_GATE, None)
|
||||
logger.debug("Gate open/close request")
|
||||
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 run(self):
|
||||
self.__task_data_request__.run()
|
||||
self.__task_1s__.run()
|
||||
self.__task_10s__.run()
|
||||
self.__task_60s__.run()
|
||||
|
||||
def close(self):
|
||||
self.__task_data_request__.stop()
|
||||
self.__task_data_request__.join()
|
||||
self.__task_1s__.stop()
|
||||
self.__task_1s__.join()
|
||||
self.__task_10s__.stop()
|
||||
self.__task_10s__.join()
|
||||
self.__task_60s__.stop()
|
||||
self.__task_60s__.join()
|
||||
|
||||
def __del__(self):
|
||||
self.close()
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 1fa2e2fcf952f4c4a1518a0fe7fcfd06377e84e2
|
||||
Subproject commit f4a7f1e7a4156f397ee76bee01b0fdab88a727d1
|
6
start.sh
Executable file
6
start.sh
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
|
||||
BASEDIR=`dirname $0`
|
||||
rm -f $BASEDIR/messages.*
|
||||
/usr/bin/python3 $BASEDIR/smarthome.py 2> $BASEDIR/messages.err --display :0 &
|
@ -1 +1 @@
|
||||
Subproject commit 9d8dac2f943de493ebd33da62ca9329c155ea8a9
|
||||
Subproject commit 3e6e74f976a1322d97f1d50480df133455486fd6
|
Loading…
x
Reference in New Issue
Block a user