|
@@ -0,0 +1,66 @@
|
|
1
|
+#!/usr/bin/env python
|
|
2
|
+# -*- coding: UTF-8 -*-
|
|
3
|
+
|
|
4
|
+import config
|
|
5
|
+import os
|
|
6
|
+import protocol
|
|
7
|
+import report
|
|
8
|
+import sys
|
|
9
|
+import tcp_socket
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+def help_msg():
|
|
13
|
+ print(""""Possible commands are:
|
|
14
|
+ * q[uit]
|
|
15
|
+ * auto[matic]
|
|
16
|
+ * man[ual]
|
|
17
|
+ * mode
|
|
18
|
+ * state
|
|
19
|
+ * get [all,bakehose,bakery,mill,reesehouse,ploenlein]
|
|
20
|
+ * set [all,bakehose,bakery,mill,reesehouse,ploenlein] [on,off]""")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+if __name__ == '__main__':
|
|
25
|
+ report.appLoggingConfigure(os.path.dirname(__file__), 'logfile', config.loggers)
|
|
26
|
+ c = tcp_socket.tcp_client_stp(config.server_ip, config.server_port)
|
|
27
|
+ prot = protocol.my_client_protocol(c, secret=config.secret)
|
|
28
|
+ target_dict = {
|
|
29
|
+ 'bakehouse': [prot.DID_BAKE_HOUSE, ],
|
|
30
|
+ 'bakery': [prot.DID_BAKERY, ],
|
|
31
|
+ 'mill': [prot.DID_MILL, ],
|
|
32
|
+ 'ploenlein': [prot.DID_PLOENLEIN, ],
|
|
33
|
+ 'reesehouse': [prot.DID_REESE_HOUSE, ],
|
|
34
|
+ 'all': [prot.DID_BAKE_HOUSE, prot.DID_BAKERY, prot.DID_MILL, prot.DID_PLOENLEIN, prot.DID_REESE_HOUSE]
|
|
35
|
+ }
|
|
36
|
+ if prot.authentificate():
|
|
37
|
+ help_msg()
|
|
38
|
+ cmd = None
|
|
39
|
+ while cmd not in ["q", "quit"]:
|
|
40
|
+ cmd = sys.stdin.readline()
|
|
41
|
+ cmd = cmd.lower().strip('\n')
|
|
42
|
+ if cmd == 'help':
|
|
43
|
+ help_msg()
|
|
44
|
+ elif cmd in ["auto", "automatic"]:
|
|
45
|
+ prot.send(prot.SID_EXECUTE_REQUEST, prot.DID_MODE, 'automatic')
|
|
46
|
+ elif cmd in ["man", "manual"]:
|
|
47
|
+ prot.send(prot.SID_EXECUTE_REQUEST, prot.DID_MODE, 'manual')
|
|
48
|
+ elif cmd == "mode":
|
|
49
|
+ prot.send(prot.SID_READ_REQUEST, prot.DID_MODE, None)
|
|
50
|
+ elif cmd == "state":
|
|
51
|
+ prot.send(prot.SID_READ_REQUEST, prot.DID_STATE, None)
|
|
52
|
+ elif cmd.startswith('get '):
|
|
53
|
+ target = target_dict.get(cmd.split(' ')[1])
|
|
54
|
+ if target is not None:
|
|
55
|
+ for t in target:
|
|
56
|
+ prot.send(prot.SID_READ_REQUEST, t, None)
|
|
57
|
+ elif cmd.startswith('set '):
|
|
58
|
+ target = target_dict.get(cmd.split(' ')[1])
|
|
59
|
+ try:
|
|
60
|
+ state = {'on': True, 'off': False}.get(cmd.split(' ')[2])
|
|
61
|
+ except IndexError:
|
|
62
|
+ state = None
|
|
63
|
+ if target is not None and state is not None:
|
|
64
|
+ for t in target:
|
|
65
|
+ prot.send(prot.SID_EXECUTE_REQUEST, t, state)
|
|
66
|
+ c.close()
|