|
@@ -8,122 +8,131 @@ except ImportError:
|
8
|
8
|
piface_function = None
|
9
|
9
|
|
10
|
10
|
|
11
|
|
-class my_base_protocol(socket_protocol.pure_json_protocol):
|
12
|
|
- DID_MODE = 0
|
13
|
|
- DID_STATE = 1
|
14
|
|
- #
|
15
|
|
- DID_BAKERY = 2
|
16
|
|
- DID_BAKE_HOUSE = 3
|
17
|
|
- DID_MILL = 4
|
18
|
|
- DID_REESE_HOUSE = 5
|
19
|
|
- DID_PLOENLEIN = 6
|
|
11
|
+DID_MODE = 0
|
|
12
|
+DID_STATE = 1
|
|
13
|
+#
|
|
14
|
+DID_BAKERY = 2
|
|
15
|
+DID_BAKE_HOUSE = 3
|
|
16
|
+DID_MILL = 4
|
|
17
|
+DID_REESE_HOUSE = 5
|
|
18
|
+DID_PLOENLEIN = 6
|
20
|
19
|
|
|
20
|
+class my_base_protocol(socket_protocol.pure_json_protocol):
|
|
21
|
+ def __init__(self, *args, **kwargs):
|
|
22
|
+ socket_protocol.pure_json_protocol.__init__(self, *args, **kwargs)
|
|
23
|
+ self.add_data((socket_protocol.SID_READ_REQUEST, socket_protocol.SID_READ_RESPONSE), DID_MODE, 'mode')
|
|
24
|
+ self.add_data((socket_protocol.SID_READ_REQUEST, socket_protocol.SID_READ_RESPONSE), DID_STATE, 'state')
|
|
25
|
+ self.add_data((socket_protocol.SID_EXECUTE_REQUEST, socket_protocol.SID_EXECUTE_RESPONSE), DID_BAKERY, 'on_off_bakery')
|
|
26
|
+ self.add_data((socket_protocol.SID_EXECUTE_REQUEST, socket_protocol.SID_EXECUTE_RESPONSE), DID_BAKE_HOUSE, 'on_off_bake_house')
|
|
27
|
+ self.add_data((socket_protocol.SID_EXECUTE_REQUEST, socket_protocol.SID_EXECUTE_RESPONSE), DID_MILL, 'on_off_mill')
|
|
28
|
+ self.add_data((socket_protocol.SID_EXECUTE_REQUEST, socket_protocol.SID_EXECUTE_RESPONSE), DID_REESE_HOUSE, 'on_off_reese_house')
|
|
29
|
+ self.add_data((socket_protocol.SID_EXECUTE_REQUEST, socket_protocol.SID_EXECUTE_RESPONSE), DID_PLOENLEIN, 'on_off_ploenlein')
|
21
|
30
|
|
22
|
31
|
class my_server_protocol(my_base_protocol):
|
23
|
32
|
def __init__(self, comm_instance, secret=None):
|
24
|
|
- socket_protocol.pure_json_protocol.__init__(self, comm_instance, secret)
|
|
33
|
+ my_base_protocol.__init__(self, comm_instance, secret=secret)
|
25
|
34
|
self.leyk = piface_function.leyk()
|
26
|
|
- self.register_callback(self.SID_EXECUTE_REQUEST, self.DID_MODE, self.set_mode)
|
27
|
|
- self.register_callback(self.SID_EXECUTE_REQUEST, self.DID_BAKERY, self.set_bakery)
|
28
|
|
- self.register_callback(self.SID_EXECUTE_REQUEST, self.DID_BAKE_HOUSE, self.set_bake_house)
|
29
|
|
- self.register_callback(self.SID_EXECUTE_REQUEST, self.DID_MILL, self.set_mill)
|
30
|
|
- self.register_callback(self.SID_EXECUTE_REQUEST, self.DID_REESE_HOUSE, self.set_reese_house)
|
31
|
|
- self.register_callback(self.SID_EXECUTE_REQUEST, self.DID_PLOENLEIN, self.set_ploenlein)
|
32
|
|
- self.register_callback(self.SID_READ_REQUEST, self.DID_MODE, self.get_mode)
|
33
|
|
- self.register_callback(self.SID_READ_REQUEST, self.DID_STATE, self.get_state)
|
34
|
|
- self.register_callback(self.SID_READ_REQUEST, self.DID_BAKERY, self.get_bakery)
|
35
|
|
- self.register_callback(self.SID_READ_REQUEST, self.DID_BAKE_HOUSE, self.get_bake_house)
|
36
|
|
- self.register_callback(self.SID_READ_REQUEST, self.DID_MILL, self.get_mill)
|
37
|
|
- self.register_callback(self.SID_READ_REQUEST, self.DID_REESE_HOUSE, self.get_reese_house)
|
38
|
|
- self.register_callback(self.SID_READ_REQUEST, self.DID_PLOENLEIN, self.get_ploenlein)
|
|
35
|
+ self.register_callback(socket_protocol.SID_EXECUTE_REQUEST, DID_MODE, self.set_mode)
|
|
36
|
+ self.register_callback(socket_protocol.SID_EXECUTE_REQUEST, DID_BAKERY, self.set_bakery)
|
|
37
|
+ self.register_callback(socket_protocol.SID_EXECUTE_REQUEST, DID_BAKE_HOUSE, self.set_bake_house)
|
|
38
|
+ self.register_callback(socket_protocol.SID_EXECUTE_REQUEST, DID_MILL, self.set_mill)
|
|
39
|
+ self.register_callback(socket_protocol.SID_EXECUTE_REQUEST, DID_REESE_HOUSE, self.set_reese_house)
|
|
40
|
+ self.register_callback(socket_protocol.SID_EXECUTE_REQUEST, DID_PLOENLEIN, self.set_ploenlein)
|
|
41
|
+ self.register_callback(socket_protocol.SID_READ_REQUEST, DID_MODE, self.get_mode)
|
|
42
|
+ self.register_callback(socket_protocol.SID_READ_REQUEST, DID_STATE, self.get_state)
|
|
43
|
+ self.register_callback(socket_protocol.SID_READ_REQUEST, DID_BAKERY, self.get_bakery)
|
|
44
|
+ self.register_callback(socket_protocol.SID_READ_REQUEST, DID_BAKE_HOUSE, self.get_bake_house)
|
|
45
|
+ self.register_callback(socket_protocol.SID_READ_REQUEST, DID_MILL, self.get_mill)
|
|
46
|
+ self.register_callback(socket_protocol.SID_READ_REQUEST, DID_REESE_HOUSE, self.get_reese_house)
|
|
47
|
+ self.register_callback(socket_protocol.SID_READ_REQUEST, DID_PLOENLEIN, self.get_ploenlein)
|
39
|
48
|
|
40
|
49
|
def set_mode(self, msg):
|
41
|
50
|
if self.leyk.set_mode(msg.get_data()):
|
42
|
|
- return self.STATUS_OKAY, None
|
|
51
|
+ return socket_protocol.STATUS_OKAY, None
|
43
|
52
|
else:
|
44
|
|
- return self.STATUS_OPERATION_NOT_PERMITTED, None
|
|
53
|
+ return socket_protocol.STATUS_OPERATION_NOT_PERMITTED, None
|
45
|
54
|
|
46
|
55
|
def get_mode(self, msg):
|
47
|
|
- return self.STATUS_OKAY, self.leyk.get_mode()
|
|
56
|
+ return socket_protocol.STATUS_OKAY, self.leyk.get_mode()
|
48
|
57
|
|
49
|
58
|
def get_state(self, msg):
|
50
|
|
- return self.STATUS_OKAY, self.leyk.get_state()
|
|
59
|
+ return socket_protocol.STATUS_OKAY, self.leyk.get_state()
|
51
|
60
|
|
52
|
61
|
def set_bakery(self, msg):
|
53
|
62
|
if msg.get_data() is True or msg.get_data() is False:
|
54
|
63
|
if self.leyk.set_bakery(msg.get_data()) is not True:
|
55
|
|
- return self.STATUS_OPERATION_NOT_PERMITTED, None
|
|
64
|
+ return socket_protocol.STATUS_OPERATION_NOT_PERMITTED, None
|
56
|
65
|
else:
|
57
|
|
- return self.STATUS_OKAY, None
|
|
66
|
+ return socket_protocol.STATUS_OKAY, None
|
58
|
67
|
else:
|
59
|
|
- return self.STATUS_SERVICE_OR_DATA_UNKNOWN, None
|
|
68
|
+ return socket_protocol.STATUS_SERVICE_OR_DATA_UNKNOWN, None
|
60
|
69
|
|
61
|
70
|
def get_bakery(self, msg):
|
62
|
|
- return self.STATUS_OKAY, self.leyk.get_bakery()
|
|
71
|
+ return socket_protocol.STATUS_OKAY, self.leyk.get_bakery()
|
63
|
72
|
|
64
|
73
|
def set_bake_house(self, msg):
|
65
|
74
|
if msg.get_data() is True or msg.get_data() is False:
|
66
|
75
|
if self.leyk.set_bake_house(msg.get_data()) is not True:
|
67
|
|
- return self.STATUS_OPERATION_NOT_PERMITTED, None
|
|
76
|
+ return socket_protocol.STATUS_OPERATION_NOT_PERMITTED, None
|
68
|
77
|
else:
|
69
|
|
- return self.STATUS_OKAY, None
|
|
78
|
+ return socket_protocol.STATUS_OKAY, None
|
70
|
79
|
else:
|
71
|
|
- return self.STATUS_SERVICE_OR_DATA_UNKNOWN, None
|
|
80
|
+ return socket_protocol.STATUS_SERVICE_OR_DATA_UNKNOWN, None
|
72
|
81
|
|
73
|
82
|
def get_bake_house(self, msg):
|
74
|
|
- return self.STATUS_OKAY, self.leyk.get_bake_house()
|
|
83
|
+ return socket_protocol.STATUS_OKAY, self.leyk.get_bake_house()
|
75
|
84
|
|
76
|
85
|
def set_mill(self, msg):
|
77
|
86
|
if msg.get_data() is True or msg.get_data() is False:
|
78
|
87
|
if self.leyk.set_mill(msg.get_data()) is not True:
|
79
|
|
- return self.STATUS_OPERATION_NOT_PERMITTED, None
|
|
88
|
+ return socket_protocol.STATUS_OPERATION_NOT_PERMITTED, None
|
80
|
89
|
else:
|
81
|
|
- return self.STATUS_OKAY, None
|
|
90
|
+ return socket_protocol.STATUS_OKAY, None
|
82
|
91
|
else:
|
83
|
|
- return self.STATUS_SERVICE_OR_DATA_UNKNOWN, None
|
|
92
|
+ return socket_protocol.STATUS_SERVICE_OR_DATA_UNKNOWN, None
|
84
|
93
|
|
85
|
94
|
def get_mill(self, msg):
|
86
|
|
- return self.STATUS_OKAY, self.leyk.get_mill()
|
|
95
|
+ return socket_protocol.STATUS_OKAY, self.leyk.get_mill()
|
87
|
96
|
|
88
|
97
|
def set_reese_house(self, msg):
|
89
|
98
|
if msg.get_data() is True or msg.get_data() is False:
|
90
|
99
|
if self.leyk.set_reese_house(msg.get_data()) is not True:
|
91
|
|
- return self.STATUS_OPERATION_NOT_PERMITTED, None
|
|
100
|
+ return socket_protocol.STATUS_OPERATION_NOT_PERMITTED, None
|
92
|
101
|
else:
|
93
|
|
- return self.STATUS_OKAY, None
|
|
102
|
+ return socket_protocol.STATUS_OKAY, None
|
94
|
103
|
else:
|
95
|
|
- return self.STATUS_SERVICE_OR_DATA_UNKNOWN, None
|
|
104
|
+ return socket_protocol.STATUS_SERVICE_OR_DATA_UNKNOWN, None
|
96
|
105
|
|
97
|
106
|
def get_reese_house(self, msg):
|
98
|
|
- return self.STATUS_OKAY, self.leyk.get_reese_house()
|
|
107
|
+ return socket_protocol.STATUS_OKAY, self.leyk.get_reese_house()
|
99
|
108
|
|
100
|
109
|
def set_ploenlein(self, msg):
|
101
|
110
|
if msg.get_data() is True or msg.get_data() is False:
|
102
|
111
|
if self.leyk.set_ploenlein(msg.get_data()) is not True:
|
103
|
|
- return self.STATUS_OPERATION_NOT_PERMITTED, None
|
|
112
|
+ return socket_protocol.STATUS_OPERATION_NOT_PERMITTED, None
|
104
|
113
|
else:
|
105
|
|
- return self.STATUS_OKAY, None
|
|
114
|
+ return socket_protocol.STATUS_OKAY, None
|
106
|
115
|
else:
|
107
|
|
- return self.STATUS_SERVICE_OR_DATA_UNKNOWN, None
|
|
116
|
+ return socket_protocol.STATUS_SERVICE_OR_DATA_UNKNOWN, None
|
108
|
117
|
|
109
|
118
|
def get_ploenlein(self, msg):
|
110
|
|
- return self.STATUS_OKAY, self.leyk.get_ploenlein()
|
|
119
|
+ return socket_protocol.STATUS_OKAY, self.leyk.get_ploenlein()
|
111
|
120
|
|
112
|
121
|
|
113
|
122
|
class my_client_protocol(my_base_protocol):
|
114
|
123
|
START_ROUTINE_DATA_IDS = [
|
115
|
|
- my_base_protocol.DID_MODE,
|
116
|
|
- my_base_protocol.DID_BAKERY,
|
117
|
|
- my_base_protocol.DID_BAKE_HOUSE,
|
118
|
|
- my_base_protocol.DID_MILL,
|
119
|
|
- my_base_protocol.DID_REESE_HOUSE,
|
120
|
|
- my_base_protocol.DID_PLOENLEIN,
|
|
124
|
+ DID_MODE,
|
|
125
|
+ DID_BAKERY,
|
|
126
|
+ DID_BAKE_HOUSE,
|
|
127
|
+ DID_MILL,
|
|
128
|
+ DID_REESE_HOUSE,
|
|
129
|
+ DID_PLOENLEIN,
|
121
|
130
|
]
|
122
|
131
|
|
123
|
132
|
def __init__(self, *args, **kwargs):
|
124
|
|
- socket_protocol.pure_json_protocol.__init__(self, *args, **kwargs)
|
125
|
|
- self.register_callback(self.SID_EXECUTE_RESPONSE, None, self.start_routine_response)
|
126
|
|
- self.register_callback(self.SID_READ_RESPONSE, None, self.read_data_main_state)
|
|
133
|
+ my_base_protocol.__init__(self, *args, **kwargs)
|
|
134
|
+ self.register_callback(socket_protocol.SID_EXECUTE_RESPONSE, None, self.start_routine_response)
|
|
135
|
+ self.register_callback(socket_protocol.SID_READ_RESPONSE, None, self.read_data_main_state)
|
127
|
136
|
|
128
|
137
|
def __authentificate_process_feedback__(self, msg):
|
129
|
138
|
if msg.get_data() is True:
|
|
@@ -133,34 +142,28 @@ class my_client_protocol(my_base_protocol):
|
133
|
142
|
return my_base_protocol.__authentificate_process_feedback__(self, msg)
|
134
|
143
|
|
135
|
144
|
def start_routine_response(self, msg):
|
136
|
|
- if msg.get_status() == self.STATUS_OKAY and msg.get_data_id() in self.START_ROUTINE_DATA_IDS:
|
|
145
|
+ if msg.get_status() == socket_protocol.STATUS_OKAY and msg.get_data_id() in self.START_ROUTINE_DATA_IDS:
|
137
|
146
|
print("OKAY")
|
138
|
|
- return self.STATUS_OKAY, None
|
139
|
147
|
else:
|
140
|
148
|
print("FAILED")
|
141
|
|
- return self.STATUS_SERVICE_OR_DATA_UNKNOWN, None
|
142
|
149
|
|
143
|
150
|
def read_data_main_state(self, msg):
|
144
|
|
- if msg.get_status() == self.STATUS_OKAY:
|
145
|
|
- if msg.get_data_id() == self.DID_MODE:
|
|
151
|
+ if msg.get_status() == socket_protocol.STATUS_OKAY:
|
|
152
|
+ if msg.get_data_id() == DID_MODE:
|
146
|
153
|
print("Mode: %s" % repr(msg.get_data()))
|
147
|
|
- return self.STATUS_OKAY, None
|
148
|
|
- elif msg.get_data_id() == self.DID_STATE:
|
|
154
|
+ elif msg.get_data_id() == DID_STATE:
|
149
|
155
|
print("State: %s" % repr(msg.get_data()))
|
150
|
|
- return self.STATUS_OKAY, None
|
151
|
|
- elif msg.get_data_id() in [self.DID_BAKE_HOUSE, self.DID_BAKERY, self.DID_MILL, self.DID_PLOENLEIN, self.DID_REESE_HOUSE]:
|
|
156
|
+ elif msg.get_data_id() in [DID_BAKE_HOUSE, DID_BAKERY, DID_MILL, DID_PLOENLEIN, DID_REESE_HOUSE]:
|
152
|
157
|
state = {
|
153
|
158
|
0: 'Off',
|
154
|
159
|
1: 'On',
|
155
|
160
|
}.get(msg.get_data())
|
156
|
161
|
target = {
|
157
|
|
- self.DID_BAKE_HOUSE: 'Bakehouse',
|
158
|
|
- self.DID_BAKERY: 'Bakery',
|
159
|
|
- self.DID_MILL: 'Mill',
|
160
|
|
- self.DID_REESE_HOUSE: 'Reesehouse',
|
161
|
|
- self.DID_PLOENLEIN: 'Ploenlein',
|
|
162
|
+ DID_BAKE_HOUSE: 'Bakehouse',
|
|
163
|
+ DID_BAKERY: 'Bakery',
|
|
164
|
+ DID_MILL: 'Mill',
|
|
165
|
+ DID_REESE_HOUSE: 'Reesehouse',
|
|
166
|
+ DID_PLOENLEIN: 'Ploenlein',
|
162
|
167
|
}.get(msg.get_data_id())
|
163
|
168
|
print('The light in {target} is {state}'.format(state=state, target=target))
|
164
|
|
- return self.STATUS_OKAY, None
|
165
|
169
|
print('Error receiving data!')
|
166
|
|
- return self.STATUS_SERVICE_OR_DATA_UNKNOWN, None
|