Browse Source

Restructuring including GUI reset in case of disconnects

mod_update
Dirk Alders 4 years ago
parent
commit
bb4a9b5bc0
6 changed files with 180 additions and 88 deletions
  1. 1
    1
      config_example/config.py
  2. 10
    14
      gui.py
  3. 10
    14
      gui.wxg
  4. 157
    57
      smarthome.py
  5. 1
    1
      socket_protocol
  6. 1
    1
      tcp_socket

+ 1
- 1
config_example/config.py View File

@@ -6,7 +6,7 @@ import stringtools
6 6
 import task
7 7
 import tcp_socket
8 8
 
9
-FULL_SCRREN = False
9
+FULL_SCREEN = False
10 10
 
11 11
 
12 12
 # TCP-Server

+ 10
- 14
gui.py View File

@@ -1,7 +1,7 @@
1 1
 #!/usr/bin/env python
2 2
 # -*- coding: UTF-8 -*-
3 3
 #
4
-# generated by wxGlade 0.9.3 on Mon Sep  7 11:55:26 2020
4
+# generated by wxGlade 0.9.3 on Wed Sep  9 07:31:16 2020
5 5
 #
6 6
 
7 7
 import wx
@@ -18,18 +18,18 @@ class Wetation(wx.Frame):
18 18
         # begin wxGlade: Wetation.__init__
19 19
         kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
20 20
         wx.Frame.__init__(self, *args, **kwds)
21
-        self.SetSize((800, 628))
21
+        self.SetSize((800, 655))
22 22
         self.date = wx.StaticText(self, wx.ID_ANY, "xx.xx.xxxx", style=wx.ALIGN_LEFT)
23 23
         self.time = wx.StaticText(self, wx.ID_ANY, "xx:xx", style=wx.ALIGN_RIGHT)
24
-        self.heading_out_envdata = wx.StaticText(self, wx.ID_ANY, u"Außentemperatur")
24
+        self.heading_out_envdata = wx.StaticText(self, wx.ID_ANY, u"Außen")
25 25
         self.out_humidity = wx.StaticText(self, wx.ID_ANY, "- %", style=wx.ALIGN_RIGHT)
26
-        self.out_pressure = wx.StaticText(self, wx.ID_ANY, "- mbar", style=wx.ALIGN_RIGHT)
26
+        self.out_pressure = wx.StaticText(self, wx.ID_ANY, "- hPa", style=wx.ALIGN_RIGHT)
27 27
         self.out_temperature_min = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
28 28
         self.out_temperature_max = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
29 29
         self.out_temperature = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
30
-        self.heading_in_envdata = wx.StaticText(self, wx.ID_ANY, "Innentemperatur")
30
+        self.heading_in_envdata = wx.StaticText(self, wx.ID_ANY, "Innen")
31 31
         self.in_humidity = wx.StaticText(self, wx.ID_ANY, "- %", style=wx.ALIGN_RIGHT)
32
-        self.in_pressure = wx.StaticText(self, wx.ID_ANY, "- mbar", style=wx.ALIGN_RIGHT)
32
+        self.in_pressure = wx.StaticText(self, wx.ID_ANY, "- hPa", style=wx.ALIGN_RIGHT)
33 33
         self.in_temperature_min = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
34 34
         self.in_temperature_max = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
35 35
         self.in_temperature = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
@@ -58,7 +58,7 @@ class Wetation(wx.Frame):
58 58
         self.time.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
59 59
         self.heading_out_envdata.SetBackgroundColour(wx.Colour(35, 35, 142))
60 60
         self.heading_out_envdata.SetForegroundColour(wx.Colour(250, 249, 255))
61
-        self.heading_out_envdata.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
61
+        self.heading_out_envdata.SetFont(wx.Font(16, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
62 62
         self.out_humidity.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
63 63
         self.out_pressure.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
64 64
         self.out_temperature_min.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
@@ -66,7 +66,7 @@ class Wetation(wx.Frame):
66 66
         self.out_temperature.SetFont(wx.Font(48, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
67 67
         self.heading_in_envdata.SetBackgroundColour(wx.Colour(35, 35, 142))
68 68
         self.heading_in_envdata.SetForegroundColour(wx.Colour(250, 249, 255))
69
-        self.heading_in_envdata.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
69
+        self.heading_in_envdata.SetFont(wx.Font(16, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
70 70
         self.in_humidity.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
71 71
         self.in_pressure.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
72 72
         self.in_temperature_min.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
@@ -74,13 +74,9 @@ class Wetation(wx.Frame):
74 74
         self.in_temperature.SetFont(wx.Font(48, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
75 75
         self.heading_garage.SetBackgroundColour(wx.Colour(35, 35, 142))
76 76
         self.heading_garage.SetForegroundColour(wx.Colour(250, 249, 255))
77
-        self.heading_garage.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
78
-        self.heading_garage.Hide()
79
-        self.gate_oc.Hide()
80
-        self.gate_close.Hide()
77
+        self.heading_garage.SetFont(wx.Font(16, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
78
+        self.gate_oc.SetMinSize((100, 50))
81 79
         self.gate_position.Enable(False)
82
-        self.gate_position.Hide()
83
-        self.gate_open.Hide()
84 80
         # end wxGlade
85 81
 
86 82
     def __do_layout(self):

+ 10
- 14
gui.wxg View File

@@ -1,9 +1,9 @@
1 1
 <?xml version="1.0"?>
2
-<!-- generated by wxGlade 0.9.3 on Mon Sep  7 11:55:31 2020 -->
2
+<!-- generated by wxGlade 0.9.3 on Wed Sep  9 07:31:12 2020 -->
3 3
 
4 4
 <application class="MyApp" encoding="UTF-8" for_version="3.0" header_extension=".h" indent_amount="4" indent_symbol="space" is_template="0" language="python" mark_blocks="1" name="app" option="0" overwrite="1" path="./gui.py" source_extension=".cpp" top_window="wetation" use_gettext="0" use_new_namespace="1">
5 5
     <object class="Wetation" name="wetation" base="EditFrame">
6
-        <size>800, 628</size>
6
+        <size>800, 655</size>
7 7
         <background>#faf9ff</background>
8 8
         <foreground>#23238e</foreground>
9 9
         <title>frame</title>
@@ -106,14 +106,14 @@
106 106
                     <background>#23238e</background>
107 107
                     <foreground>#faf9ff</foreground>
108 108
                     <font>
109
-                        <size>12</size>
109
+                        <size>16</size>
110 110
                         <family>default</family>
111 111
                         <style>normal</style>
112 112
                         <weight>normal</weight>
113 113
                         <underlined>0</underlined>
114 114
                         <face />
115 115
                     </font>
116
-                    <label>Außentemperatur</label>
116
+                    <label>Außen</label>
117 117
                     <attribute>1</attribute>
118 118
                 </object>
119 119
             </object>
@@ -161,7 +161,7 @@
161 161
                                         <face />
162 162
                                     </font>
163 163
                                     <style>wxALIGN_RIGHT</style>
164
-                                    <label>- mbar</label>
164
+                                    <label>- hPa</label>
165 165
                                     <attribute>1</attribute>
166 166
                                 </object>
167 167
                             </object>
@@ -255,14 +255,14 @@
255 255
                     <background>#23238e</background>
256 256
                     <foreground>#faf9ff</foreground>
257 257
                     <font>
258
-                        <size>12</size>
258
+                        <size>16</size>
259 259
                         <family>default</family>
260 260
                         <style>normal</style>
261 261
                         <weight>normal</weight>
262 262
                         <underlined>0</underlined>
263 263
                         <face />
264 264
                     </font>
265
-                    <label>Innentemperatur</label>
265
+                    <label>Innen</label>
266 266
                     <attribute>1</attribute>
267 267
                 </object>
268 268
             </object>
@@ -310,7 +310,7 @@
310 310
                                         <face />
311 311
                                     </font>
312 312
                                     <style>wxALIGN_RIGHT</style>
313
-                                    <label>- mbar</label>
313
+                                    <label>- hPa</label>
314 314
                                     <attribute>1</attribute>
315 315
                                 </object>
316 316
                             </object>
@@ -404,14 +404,13 @@
404 404
                     <background>#23238e</background>
405 405
                     <foreground>#faf9ff</foreground>
406 406
                     <font>
407
-                        <size>12</size>
407
+                        <size>16</size>
408 408
                         <family>default</family>
409 409
                         <style>normal</style>
410 410
                         <weight>normal</weight>
411 411
                         <underlined>0</underlined>
412 412
                         <face />
413 413
                     </font>
414
-                    <hidden>1</hidden>
415 414
                     <label>Garage</label>
416 415
                     <attribute>1</attribute>
417 416
                 </object>
@@ -429,7 +428,7 @@
429 428
                             <events>
430 429
                                 <handler event="EVT_BUTTON">gate_oc_evt</handler>
431 430
                             </events>
432
-                            <hidden>1</hidden>
431
+                            <size>100, 50</size>
433 432
                             <label>Garage</label>
434 433
                         </object>
435 434
                     </object>
@@ -438,7 +437,6 @@
438 437
                         <border>0</border>
439 438
                         <flag>wxALIGN_CENTER</flag>
440 439
                         <object class="wxStaticText" name="gate_close" base="EditStaticText">
441
-                            <hidden>1</hidden>
442 440
                             <label>Close</label>
443 441
                             <attribute>1</attribute>
444 442
                         </object>
@@ -449,7 +447,6 @@
449 447
                         <flag>wxEXPAND</flag>
450 448
                         <object class="wxSlider" name="gate_position" base="EditSlider">
451 449
                             <disabled>1</disabled>
452
-                            <hidden>1</hidden>
453 450
                             <style>wxSL_HORIZONTAL</style>
454 451
                             <range>0, 100</range>
455 452
                             <value>50</value>
@@ -460,7 +457,6 @@
460 457
                         <border>0</border>
461 458
                         <flag>wxALIGN_CENTER</flag>
462 459
                         <object class="wxStaticText" name="gate_open" base="EditStaticText">
463
-                            <hidden>1</hidden>
464 460
                             <label>Open</label>
465 461
                             <attribute>1</attribute>
466 462
                         </object>

+ 157
- 57
smarthome.py View File

@@ -2,6 +2,8 @@
2 2
 # -*- coding: UTF-8 -*-
3 3
 #
4 4
 
5
+#TODO: Zyklischer reconnect versuch (ggf. inkl. herstellen der Schnittstelle für ein reconnect beim tcp_client)
6
+
5 7
 import config
6 8
 import rpi_envsens as envsens
7 9
 import garage_protocol
@@ -19,83 +21,181 @@ logger = logging.getLogger('APP')
19 21
 
20 22
 
21 23
 class WetationFrameProt(gui.Wetation):
24
+    PROT_ID_GARAGE = 0
25
+    PROT_ID_IN = 1
26
+    PROT_ID_OUT = 2
27
+    ALL_PROT_IDS = [PROT_ID_GARAGE, PROT_ID_IN, PROT_ID_OUT]
28
+    
29
+    REQUEST_MSGS = {
30
+        PROT_ID_GARAGE: [
31
+            {
32
+                'service_id': garage_protocol.my_base_protocol_tcp.SID_READ_REQUEST,
33
+                'data_id': garage_protocol.my_base_protocol_tcp.GATE_POSITION,
34
+            },
35
+        ],
36
+        PROT_ID_IN: [
37
+            {
38
+                'service_id': wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST,
39
+                'data_id': wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA,
40
+            },
41
+        ],
42
+        PROT_ID_OUT: [
43
+            {
44
+                'service_id': wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST,
45
+                'data_id': wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA,
46
+            },
47
+        ],
48
+    }
49
+
50
+
22 51
     def __init__(self, *args, **kwds):
52
+        self.__prot__ = {}
53
+        self.no_data = {
54
+            self.PROT_ID_GARAGE: self.update_gate_position,
55
+            self.PROT_ID_IN: self.update_current_env_data_in,
56
+            self.PROT_ID_OUT: self.update_current_env_data_out,
57
+        }
23 58
         gui.Wetation.__init__(self, *args, **kwds)
59
+        self.ShowFullScreen(config.FULL_SCREEN)
60
+
61
+        self.__init_communication__()
24 62
         self.__task_data_request__ = task.periodic(10, self.__initiate_data_request__)
25
-        self.__init__communication__()
26 63
 
27
-    def __init__communication__(self):
64
+    def __init_protocol__(self, prot_id, ip, port, prot_class, secret):
65
+        c_tcp = tcp_socket.tcp_client_stp(ip, port, rx_log_lvl=logging.DEBUG)
66
+        self.__prot__[prot_id] = prot_class(c_tcp, secret)
67
+        if config.server_garage_secret is not None:
68
+            self.__prot__[prot_id].authentificate()
69
+
70
+    def __init_communication__(self):
28 71
         #
29 72
         # Start TCP-Clients
30
-        c_tcp = tcp_socket.tcp_client_stp(config.server_out_ip, config.server_out_port, rx_log_lvl=logging.DEBUG)
31
-        self.prot_out = wetation_protocol.my_base_protocol_tcp(c_tcp, config.server_out_secret)
32
-        self.prot_out.register_callback(wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE, wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA, self.update_current_env_data_out)
33
-        if config.server_out_secret is not None:
34
-            self.prot_out.authentificate()
35
-
36
-        c_tcp = tcp_socket.tcp_client_stp(config.server_in_ip, config.server_in_port, rx_log_lvl=logging.DEBUG)
37
-        self.prot_in = wetation_protocol.my_base_protocol_tcp(c_tcp, config.server_in_secret)
38
-        self.prot_in.register_callback(wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE, wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA, self.update_current_env_data_in)
39
-        if config.server_in_secret is not None:
40
-            self.prot_in.authentificate()
41
-
42
-        c_tcp = tcp_socket.tcp_client_stp(config.server_garage_ip, config.server_garage_port, rx_log_lvl=logging.DEBUG)
43
-        self.prot_garage = garage_protocol.my_base_protocol_tcp(c_tcp, config.server_garage_secret)
44
-        self.prot_garage.register_callback(garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE, garage_protocol.my_base_protocol_tcp.GATE_POSITION, self.update_gate_position)
45
-        if config.server_garage_secret is not None:
46
-            self.prot_garage.authentificate()
73
+        self.__init_protocol__(
74
+            self.PROT_ID_GARAGE,
75
+            config.server_garage_ip,
76
+            config.server_garage_port,
77
+            garage_protocol.my_base_protocol_tcp,
78
+            config.server_garage_secret
79
+        )
80
+        self.__prot__[self.PROT_ID_GARAGE].register_callback(garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE, None, self.__garage_data__)
81
+
82
+        self.__init_protocol__(
83
+            self.PROT_ID_IN,
84
+            config.server_in_ip,
85
+            config.server_in_port,
86
+            wetation_protocol.my_base_protocol_tcp,
87
+            config.server_in_secret
88
+        )
89
+        self.__prot__[self.PROT_ID_IN].register_callback(wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE, None, self.__in_data__)
90
+
91
+        self.__init_protocol__(
92
+            self.PROT_ID_OUT,
93
+            config.server_out_ip,
94
+            config.server_out_port,
95
+            wetation_protocol.my_base_protocol_tcp,
96
+            config.server_out_secret
97
+        )
98
+        self.__prot__[self.PROT_ID_OUT].register_callback(wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE, None, self.__out_data__)
47 99
 
48
-    def __update_current_envdata__(self, msg, temperature, humidity, pressure):
100
+    def __initiate_data_request__(self, rt):
101
+        for prot_id in self.ALL_PROT_IDS:
102
+            if self.__prot__[prot_id].is_connected():
103
+                for request_msg in self.REQUEST_MSGS.get(prot_id, []):
104
+                    service_id = request_msg['service_id']
105
+                    data_id = request_msg['data_id']
106
+                    logger.debug('Sending data request for prot_id %d, service_id %d and data_id %d', prot_id, service_id, data_id)
107
+                    self.__prot__[prot_id].send(service_id, data_id, None)
108
+            else:
109
+                logger.debug('Resetting GUI for prot_id %d', prot_id)
110
+                wx.CallAfter(self.no_data[prot_id], None)
111
+
112
+        # TODO: Move the following three lines to the wx idle task
113
+        wx.CallAfter(self.update_time)
114
+
115
+    def __in_data__(self, msg):
116
+        return self.__env_data__(msg, self.PROT_ID_IN)
117
+
118
+    def __out_data__(self, msg):
119
+        return self.__env_data__(msg, self.PROT_ID_OUT)
120
+
121
+    def __env_data__(self, msg, prot_id):
122
+        logger.debug('Received data for prot_id %d, service_id %d, data_id %d', prot_id, msg.get_service_id(), msg.get_data_id())
49 123
         if msg.get_status() == wetation_protocol.my_base_protocol_tcp.STATUS_OKAY:
50
-            env_data = msg.get_data()
51
-            wx.CallAfter(temperature.SetLabel, "%.1f °C" % env_data[envsens.KEY_TEMPERATURE])
52
-            wx.CallAfter(humidity.SetLabel, "%.1f %%" % env_data[envsens.KEY_HUMIDITY])
53
-            wx.CallAfter(pressure.SetLabel, "%.0f mbar" % env_data[envsens.KEY_PRESSURE])
54
-            wx.CallAfter(self.Layout)
124
+            if msg.get_data_id() == wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA:
125
+                if prot_id == self.PROT_ID_IN:
126
+                    wx.CallAfter(self.update_current_env_data_in, msg)
127
+                else:
128
+                    wx.CallAfter(self.update_current_env_data_out, msg)
129
+                return wetation_protocol.my_base_protocol_tcp.STATUS_OKAY, None
130
+            else:
131
+                logger.warning('Received unknown data for prot_id %d, service_id %d, data_id %d', self.PROT_ID_GARAGE, msg.get_service_id(), msg.get_data_id())
55 132
             return wetation_protocol.my_base_protocol_tcp.STATUS_OKAY, None
56 133
         else:
57
-            logger.error('No environmental data received! MSG_STATUS was %s', wetation_protocol.my_base_protocol_tcp.STATUS_NAMES.get(msg.get_status(), repr(msg.get_status())))
134
+            logger.error('Error, receiving environmental data! MSG_STATUS was %s with PROT_ID %d', garage_protocol.my_base_protocol_tcp.STATUS_NAMES.get(msg.get_status(), repr(msg.get_status())), prot_id)
58 135
             return wetation_protocol.my_base_protocol_tcp.STATUS_SERVICE_OR_DATA_UNKNOWN, None
59 136
 
60
-    def update_current_env_data_out(self, msg):
61
-        return self.__update_current_envdata__(msg, self.out_temperature, self.out_humidity, self.out_pressure)
137
+    def __garage_data__(self, msg):
138
+        logger.debug('Received data for prot_id %d, service_id %d, data_id %d', self.PROT_ID_GARAGE, msg.get_service_id(), msg.get_data_id())
139
+        if msg.get_status() == garage_protocol.my_base_protocol_tcp.STATUS_OKAY:
140
+            if msg.get_data_id() == garage_protocol.my_base_protocol_tcp.GATE_POSITION:
141
+                wx.CallAfter(self.update_gate_position, msg)
142
+                return garage_protocol.my_base_protocol_tcp.STATUS_OKAY, None
143
+            else:
144
+                logger.warning('Received unknown data for prot_id %d, service_id %d, data_id %d', self.PROT_ID_GARAGE, msg.get_service_id(), msg.get_data_id())
145
+        else:
146
+            logger.error('Error, receiving garage data! MSG_STATUS was %s', garage_protocol.my_base_protocol_tcp.STATUS_NAMES.get(msg.get_status(), repr(msg.get_status())))
147
+            return garage_protocol.my_base_protocol_tcp.STATUS_SERVICE_OR_DATA_UNKNOWN, None
148
+
62 149
 
63 150
     def update_current_env_data_in(self, msg):
64
-        return self.__update_current_envdata__(msg, self.in_temperature, self.in_humidity, self.in_pressure)
151
+        if msg is None:
152
+            temperature = '-.-'
153
+            humidity = '-.-'
154
+            pressure = '-'
155
+        else:
156
+            env_data = msg.get_data()
157
+            temperature = '%.1f' % env_data[envsens.KEY_TEMPERATURE]
158
+            humidity = '%.1f' % env_data[envsens.KEY_HUMIDITY]
159
+            pressure = '%.0f' % env_data[envsens.KEY_PRESSURE]
160
+        self.in_temperature.SetLabel("%s °C" % temperature)
161
+        self.in_humidity.SetLabel("%s %%" % humidity)
162
+        self.in_pressure.SetLabel("%s hPa" % pressure)
163
+        self.Layout()
65 164
 
66
-    def update_gate_position(self, msg):
67
-        if msg.get_status() == garage_protocol.my_base_protocol_tcp.STATUS_OKAY:
68
-            #
69
-            # show gate section in GUI
70
-            #
71
-            self.heading_garage.Show(True)
72
-            self.gate_oc.Show(True)
73
-            self.gate_open.Show(True)
74
-            self.gate_position.Show(True)
75
-            self.gate_close.Show(True)
76
-            #
77
-            # update gate position
78
-            #
79
-            wx.CallAfter(self.gate_position.SetValue, msg.get_data() * 100)
80
-            wx.CallAfter(self.Layout)
81
-            return garage_protocol.my_base_protocol_tcp.STATUS_OKAY, None
165
+    def update_current_env_data_out(self, msg):
166
+        if msg is None:
167
+            temperature = '-.-'
168
+            humidity = '-.-'
169
+            pressure = '-'
82 170
         else:
83
-            logger.error('No gate position received! MSG_STATUS was %s', garage_protocol.my_base_protocol_tcp.STATUS_NAMES.get(msg.get_status(), repr(msg.get_status())))
84
-            return garage_protocol.my_base_protocol_tcp.STATUS_SERVICE_OR_DATA_UNKNOWN, None
171
+            env_data = msg.get_data()
172
+            temperature = "%.1f" % env_data[envsens.KEY_TEMPERATURE]
173
+            humidity = "%.1f" % env_data[envsens.KEY_HUMIDITY]
174
+            pressure = "%.0f" % env_data[envsens.KEY_PRESSURE]
175
+        self.out_temperature.SetLabel("%s °C" % temperature)
176
+        self.out_humidity.SetLabel("%s %%" % humidity)
177
+        self.out_pressure.SetLabel("%s hPa" % pressure)
178
+        self.Layout()
85 179
 
86
-    def garage_oc_evt(self, event):  # wxGlade: Wetation.<event_handler>
180
+    def update_gate_position(self, msg):
181
+        self.heading_garage.Show(msg is not None)
182
+        self.gate_oc.Show(msg is not None)
183
+        self.gate_open.Show(msg is not None)
184
+        self.gate_position.Show(msg is not None)
185
+        self.gate_close.Show(msg is not None)
186
+        if msg is not None:
187
+            self.gate_position.SetValue(msg.get_data() * 100)
188
+        self.Layout()
189
+
190
+    def update_time(self):
191
+        self.time.SetLabel(time.strftime("%H:%M"))
192
+        self.date.SetLabel(time.strftime("%d.%m.%Y"))
193
+        self.Layout()
194
+
195
+    def gate_oc_evt(self, event):  # wxGlade: Wetation.<event_handler>
87 196
         self.prot_garage.send(garage_protocol.my_base_protocol_tcp.SID_EXECUTE_REQUEST, garage_protocol.my_base_protocol_tcp.OPEN_CLOSE_GATE, None)
88 197
         event.Skip()
89 198
 
90
-    def __initiate_data_request__(self, rt):
91
-        self.prot_out.send(wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST, wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA, None)
92
-        self.prot_in.send(wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST, wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA, None)
93
-        self.prot_garage.send(garage_protocol.my_base_protocol_tcp.SID_READ_REQUEST, garage_protocol.my_base_protocol_tcp.GATE_POSITION, None)
94
-        # TODO: Move the following three lines to the wx idle task
95
-        wx.CallAfter(self.time.SetLabel, time.strftime("%H:%M"))
96
-        wx.CallAfter(self.date.SetLabel, time.strftime("%d.%m.%Y"))
97
-        wx.CallAfter(self.Layout)
98
-
99 199
     def run(self):
100 200
         self.__task_data_request__.run()
101 201
 

+ 1
- 1
socket_protocol

@@ -1 +1 @@
1
-Subproject commit b0857e4569c34b9b644f5640731be0c413ce54d4
1
+Subproject commit bfcdef7ad7ce8d8cb1fb1245ad7ce56ead34b39c

+ 1
- 1
tcp_socket

@@ -1 +1 @@
1
-Subproject commit 62f13e2d878b09b81d094c2f77dbd830d72be2c7
1
+Subproject commit 10aa319d2edffda001750bf26bd468753d9c2dc4

Loading…
Cancel
Save