|
@@ -19,33 +19,38 @@ except ImportError:
|
19
|
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
|
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
|
32
|
class my_server_protocol_tcp(my_base_protocol_tcp):
|
28
|
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
|
35
|
self.dht_data = dht_data
|
31
|
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
|
40
|
def envdata_statistic_request(self, msg):
|
36
|
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
|
49
|
class my_client_protocol_tcp(my_base_protocol_tcp):
|
45
|
50
|
START_ROUTINE_DATA_IDS = []
|
46
|
51
|
|
47
|
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
|
54
|
self.register_callback(self.SID_READ_RESPONSE, None, self.print_read_response)
|
50
|
55
|
|
51
|
56
|
def __authentificate_process_feedback__(self, msg):
|
|
@@ -56,15 +61,11 @@ class my_client_protocol_tcp(my_base_protocol_tcp):
|
56
|
61
|
return my_base_protocol_tcp.__authentificate_process_feedback__(self, msg)
|
57
|
62
|
|
58
|
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
|
65
|
did = msg.get_data_id()
|
61
|
66
|
data = msg.get_data()
|
62
|
67
|
if did in [self.ENVDATA_STATISTIC_BMP, self.ENVDATA_STATISTIC_DHT]:
|
63
|
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
|
69
|
else:
|
68
|
70
|
print('No data received!')
|
69
|
|
- return self.STATUS_SERVICE_OR_DATA_UNKNOWN, None
|
70
|
71
|
|