Browse Source

protocol adaption to module update

master
Dirk Alders 4 years ago
parent
commit
07357d33ad
1 changed files with 17 additions and 16 deletions
  1. 17
    16
      __init__.py

+ 17
- 16
__init__.py View File

19
 logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
19
 logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
20
 
20
 
21
 
21
 
22
+ENVDATA_STATISTIC_DHT = 0
23
+ENVDATA_STATISTIC_BMP = 1
24
+
22
 class my_base_protocol_tcp(socket_protocol.pure_json_protocol):
25
 class my_base_protocol_tcp(socket_protocol.pure_json_protocol):
23
-    ENVDATA_STATISTIC_DHT = 0
24
-    ENVDATA_STATISTIC_BMP = 1
26
+    def __init__(self, *args, **kwargs):
27
+        socket_protocol.pure_json_protocol.__init__(self, *args, **kwargs)
28
+        self.add_data((socket_protocol.SID_READ_REQUEST, socket_protocol.SID_READ_RESPONSE), ENVDATA_STATISTIC_DHT, 'dht_data')
29
+        self.add_data((socket_protocol.SID_READ_REQUEST, socket_protocol.SID_READ_RESPONSE), ENVDATA_STATISTIC_BMP, 'bmp_data')
25
 
30
 
26
 
31
 
27
 class my_server_protocol_tcp(my_base_protocol_tcp):
32
 class my_server_protocol_tcp(my_base_protocol_tcp):
28
     def __init__(self, comm_instance, dht_data, bmp_data, secret=None):
33
     def __init__(self, comm_instance, dht_data, bmp_data, secret=None):
29
-        socket_protocol.pure_json_protocol.__init__(self, comm_instance, secret)
34
+        my_base_protocol_tcp.__init__(self, comm_instance, secret=secret)
30
         self.dht_data = dht_data
35
         self.dht_data = dht_data
31
         self.bmp_data = bmp_data
36
         self.bmp_data = bmp_data
32
-        self.register_callback(self.SID_READ_REQUEST, self.ENVDATA_STATISTIC_BMP, self.envdata_statistic_request)
33
-        self.register_callback(self.SID_READ_REQUEST, self.ENVDATA_STATISTIC_DHT, self.envdata_statistic_request)
37
+        self.register_callback(socket_protocol.SID_READ_REQUEST, ENVDATA_STATISTIC_BMP, self.envdata_statistic_request)
38
+        self.register_callback(socket_protocol.SID_READ_REQUEST, ENVDATA_STATISTIC_DHT, self.envdata_statistic_request)
34
 
39
 
35
     def envdata_statistic_request(self, msg):
40
     def envdata_statistic_request(self, msg):
36
         did = msg.get_data_id()
41
         did = msg.get_data_id()
37
-        if did == self.ENVDATA_STATISTIC_BMP:
38
-            return self.STATUS_OKAY, dict(self.bmp_data.pop())
39
-        elif did == self.ENVDATA_STATISTIC_DHT:
40
-            return self.STATUS_OKAY, dict(self.dht_data.pop())
41
-        return self.STATUS_SERVICE_OR_DATA_UNKNOWN, None
42
+        if did == ENVDATA_STATISTIC_BMP:
43
+            return socket_protocol.STATUS_OKAY, dict(self.bmp_data.pop())
44
+        elif did == ENVDATA_STATISTIC_DHT:
45
+            return socket_protocol.STATUS_OKAY, dict(self.dht_data.pop())
46
+        return socket_protocol.STATUS_SERVICE_OR_DATA_UNKNOWN, None
42
 
47
 
43
 
48
 
44
 class my_client_protocol_tcp(my_base_protocol_tcp):
49
 class my_client_protocol_tcp(my_base_protocol_tcp):
45
     START_ROUTINE_DATA_IDS = []
50
     START_ROUTINE_DATA_IDS = []
46
 
51
 
47
     def __init__(self, comm_instance, secret=None):
52
     def __init__(self, comm_instance, secret=None):
48
-        socket_protocol.pure_json_protocol.__init__(self, comm_instance, secret)
53
+        my_base_protocol_tcp.__init__(self, comm_instance, secret=secret)
49
         self.register_callback(self.SID_READ_RESPONSE, None, self.print_read_response)
54
         self.register_callback(self.SID_READ_RESPONSE, None, self.print_read_response)
50
 
55
 
51
     def __authentificate_process_feedback__(self, msg):
56
     def __authentificate_process_feedback__(self, msg):
56
         return my_base_protocol_tcp.__authentificate_process_feedback__(self, msg)
61
         return my_base_protocol_tcp.__authentificate_process_feedback__(self, msg)
57
 
62
 
58
     def print_read_response(self, msg):
63
     def print_read_response(self, msg):
59
-        if msg.get_status() == self.STATUS_OKAY:
64
+        if msg.get_status() == socket_protocol.STATUS_OKAY:
60
             did = msg.get_data_id()
65
             did = msg.get_data_id()
61
             data = msg.get_data()
66
             data = msg.get_data()
62
             if did in [self.ENVDATA_STATISTIC_BMP, self.ENVDATA_STATISTIC_DHT]:
67
             if did in [self.ENVDATA_STATISTIC_BMP, self.ENVDATA_STATISTIC_DHT]:
63
                 print(helpers.continues_statistic_multivalue(**data))
68
                 print(helpers.continues_statistic_multivalue(**data))
64
-            else:
65
-                return self.STATUS_SERVICE_OR_DATA_UNKNOWN, None
66
-            return self.STATUS_OKAY, None
67
         else:
69
         else:
68
             print('No data received!')
70
             print('No data received!')
69
-            return self.STATUS_SERVICE_OR_DATA_UNKNOWN, None
70
 
71
 

Loading…
Cancel
Save