-
Notifications
You must be signed in to change notification settings - Fork 2
/
RoomControlHandler.py
559 lines (459 loc) · 15.4 KB
/
RoomControlHandler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import http.server
import http.client
import socketserver
import base64
import re
import sqlite3
import datetime
import urllib.parse
import json
import threading
import time
import sys
import signal
import logging
import cgi
import http.server
import urllib.request
import xml.etree.ElementTree as ET
# Librairies
import Config
import CMSRecordingControl
import RelayControl
import KrammerControl
import CodecControl
relayBox1 = None
relayBox2 = None
vanGoghAutoLight = True
vangoghAutoStores = False
proxixi = True
inputValue = 0
outputValue = 1
presetValue = 4
inputNames = ["Rien","Simon","Pierre","Fabien","Sarah","AppleTV","Chrome","Spycam","TrappeMX"]
outputNames = ["","TVDroite","TVCentre","TVGauche","MX300","MX800","Inexistant","Inexistant","Spycam"]
def startThread():
server = ThreadedHTTPServer(('0.0.0.0', 1412), MyRequestHandler)
print('Starting server, use <Ctrl-C> to stop')
thread = threading.Thread(target = server.serve_forever)
thread.deamon = False
thread.start()
print("--- WEB Server started (1235) ---")
return server
class ThreadedHTTPServer(socketserver.ThreadingMixIn, http.server.HTTPServer):
"""Handle requests in a separate thread."""
class MyRequestHandler(http.server.SimpleHTTPRequestHandler):
def do_POST(self):
print("POST RECEIVED")
self.send_response(200)
self.send_header('Access-Control-Allow-Origin', '*')
self.end_headers()
content_len = int(self.headers.get("Content-Length"))
post_body = self.rfile.read(content_len).decode("utf-8")
print(post_body)
CodecEventHandler(post_body)
def log_message(self, format, *args):
sys.stdout.write("%s --> [%s] %s\n" % (self.address_string(), self.log_date_time_string(), format%args))
def CodecEventHandler(xmlData):
global vanGoghAutoLight
global vangoghAutoStores
global outputValue
global inputValue
global presetValue
global proxixi
global codecs
print("---- Handling Codec Event ----")
print("XML RECU")
print(xmlData)
if (Config.codecs["vangogh"]["mac"] in xmlData) and ((("CallSuccessful" in xmlData) and vanGoghAutoLight == True) or ("lightButton:on" in xmlData)):
print("Vangogh Call Connected")
print("Allumer la lumiere ?")
relayBox1.relay1 = True
CodecControl.SendXMLDataToCodec(Config.codecs["vangogh"],
("<Command>"
"<UserInterface>"
"<Extensions>"
"<Widget>"
"<SetValue command=\"True\">"
"<Value>on</Value>"
"<WidgetId>lightButton</WidgetId>"
"</SetValue>"
"</Widget>"
"</Extensions>"
"</UserInterface>"
"</Command>"))
if (Config.codecs["vangogh"]["mac"] in xmlData) and ((("CallDisconnect" in xmlData) and vanGoghAutoLight == True) or ("lightButton:off" in xmlData)):
print("VanGogh Call Disconnected")
print("Eteindre la lumiere ?")
relayBox1.relay1 = False
CodecControl.SendXMLDataToCodec(Config.codecs["vangogh"],
("<Command>"
"<UserInterface>"
"<Extensions>"
"<Widget>"
"<SetValue command=\"True\">"
"<Value>off</Value>"
"<WidgetId>lightButton</WidgetId>"
"</SetValue>"
"</Widget>"
"</Extensions>"
"</UserInterface>"
"</Command>"))
if (Config.codecs["vangogh"]["mac"] in xmlData) and ("autoLightButton:on" in xmlData):
print("VanGogh Auto Light Enabled")
vanGoghAutoLight = True
CodecControl.SendXMLDataToCodec(Config.codecs["vangogh"],
("<Command>"
"<UserInterface>"
"<Extensions>"
"<Widget>"
"<SetValue command=\"True\">"
"<Value>on</Value>"
"<WidgetId>autoLightButton</WidgetId>"
"</SetValue>"
"</Widget>"
"</Extensions>"
"</UserInterface>"
"</Command>"))
if (Config.codecs["vangogh"]["mac"] in xmlData) and ("autoLightButton:off" in xmlData):
print("VanGogh Auto Light Disabled")
vanGoghAutoLight = False
CodecControl.SendXMLDataToCodec(Config.codecs["vangogh"],
("<Command>"
"<UserInterface>"
"<Extensions>"
"<Widget>"
"<SetValue command=\"True\">"
"<Value>off</Value>"
"<WidgetId>autoLightButton</WidgetId>"
"</SetValue>"
"</Widget>"
"</Extensions>"
"</UserInterface>"
"</Command>"))
if (Config.codecs["vangogh"]["mac"] in xmlData) and ("storeAutoButton:on" in xmlData):
print("VanGogh Auto Store Enabled")
vangoghAutoStores = True
CodecControl.SendXMLDataToCodec(Config.codecs["vangogh"],
("<Command>"
"<UserInterface>"
"<Extensions>"
"<Widget>"
"<SetValue command=\"True\">"
"<Value>on</Value>"
"<WidgetId>storeAutoButton</WidgetId>"
"</SetValue>"
"</Widget>"
"</Extensions>"
"</UserInterface>"
"</Command>"))
if (Config.codecs["vangogh"]["mac"] in xmlData) and ("storeAutoButton:off" in xmlData):
print("VanGogh Auto Store Disabled")
vangoghAutoStores = False
CodecControl.SendXMLDataToCodec(Config.codecs["vangogh"],
("<Command>"
"<UserInterface>"
"<Extensions>"
"<Widget>"
"<SetValue command=\"True\">"
"<Value>off</Value>"
"<WidgetId>storeAutoButton</WidgetId>"
"</SetValue>"
"</Widget>"
"</Extensions>"
"</UserInterface>"
"</Command>"))
if (Config.codecs["vangogh"]["mac"] in xmlData) and ("storeUpDown:increment" in xmlData) and ("Pressed" in xmlData):
print("VG Baisse Store single ON")
relayBox2.relay1 = True
if (Config.codecs["vangogh"]["mac"] in xmlData) and ("storeUpDown:increment" in xmlData) and ("Released" in xmlData):
print("VG Baisse Store single OFF")
relayBox2.relay1 = False
if (Config.codecs["vangogh"]["mac"] in xmlData) and ("storeUpDown:decrement" in xmlData) and ("Pressed" in xmlData):
print("VG Monte Store single ON")
relayBox2.relay2 = True
if (Config.codecs["vangogh"]["mac"] in xmlData) and ("storeUpDown:decrement" in xmlData) and ("Released" in xmlData):
print("VG Monte Store single OFF")
relayBox2.relay2 = False
if (Config.codecs["vangogh"]["mac"] in xmlData) and (("storeFullUp" in xmlData) and ("Pressed" in xmlData) or (("CallDisconnect" in xmlData) and vangoghAutoStores == True)) :
print("VG Monte Store Full ON")
relayBox2.relay1 = True
time.sleep(23)
relayBox2.relay1 = False
print("VG Monte Store Full Ended")
if (Config.codecs["vangogh"]["mac"] in xmlData) and (("storeFullDown" in xmlData) and ("Pressed" in xmlData) or (("CallSuccessful" in xmlData) and vangoghAutoStores == True)) :
print("VG Monte Store Full OFF")
relayBox2.relay2 = True
time.sleep(23)
relayBox2.relay2 = False
print("VG Baisse Store Full Ended")
if ((Config.codecs["kandinsky"]["mac"] in xmlData) or (Config.codecs["kandinskySpycam"]["mac"] in xmlData)) and ("LoadValue" in xmlData):
if ("LoadValue:1" in xmlData):
krammer.callPreset(1)
if("LoadValue:2" in xmlData):
krammer.callPreset(2)
if("LoadValue:3" in xmlData):
krammer.callPreset(3)
if("LoadValue:4" in xmlData):
krammer.callPreset(4)
if ((Config.codecs["kandinsky"]["mac"] in xmlData) or (Config.codecs["kandinskySpycam"]["mac"] in xmlData)) and ("SaveValue" in xmlData):
if ("SaveValue:1" in xmlData):
presetValue = 1
if("SaveValue:2" in xmlData):
presetValue = 2
if("SaveValue:3" in xmlData):
presetValue = 3
if("SaveValue:4" in xmlData):
presetValue = 4
if ((Config.codecs["kandinsky"]["mac"] in xmlData) or (Config.codecs["kandinskySpycam"]["mac"] in xmlData)) and ("SavePreset" in xmlData):
krammer.savePreset(presetValue)
if ((Config.codecs["kandinsky"]["mac"] in xmlData) or (Config.codecs["kandinskySpycam"]["mac"] in xmlData)) and (("InputChange:increment" in xmlData) or ("InputChange:decrement" in xmlData)) and ("Released" in xmlData) :
if inputValue>0 and ("decrement" in xmlData) :
inputValue -= 1
if inputValue<8 and ("increment" in xmlData) :
inputValue += 1
name = inputNames[inputValue]
CodecControl.SendXMLDataToCodec(Config.codecs["kandinsky"],
("<Command>"
"<UserInterface>"
"<Extensions>"
"<Widget>"
"<SetValue command=\"True\">"
"<Value>"+name+"</Value>"
"<WidgetId>InputName</WidgetId>"
"</SetValue>"
"</Widget>"
"</Extensions>"
"</UserInterface>"
"</Command>"))
CodecControl.SendXMLDataToCodec(Config.codecs["kandinskySpycam"],
("<Command>"
"<UserInterface>"
"<Extensions>"
"<Widget>"
"<SetValue command=\"True\">"
"<Value>"+name+"</Value>"
"<WidgetId>InputName</WidgetId>"
"</SetValue>"
"</Widget>"
"</Extensions>"
"</UserInterface>"
"</Command>"))
if ((Config.codecs["kandinsky"]["mac"] in xmlData) or (Config.codecs["kandinskySpycam"]["mac"] in xmlData)) and (("OutputChange:increment" in xmlData) or ("OutputChange:decrement" in xmlData)) and ("Released" in xmlData) :
if outputValue>1 and ("decrement" in xmlData) :
outputValue -= 1
if outputValue<8 and ("increment" in xmlData) :
outputValue += 1
name = outputNames[outputValue]
CodecControl.SendXMLDataToCodec(Config.codecs["kandinsky"],
("<Command>"
"<UserInterface>"
"<Extensions>"
"<Widget>"
"<SetValue command=\"True\">"
"<Value>"+name+"</Value>"
"<WidgetId>OutputName</WidgetId>"
"</SetValue>"
"</Widget>"
"</Extensions>"
"</UserInterface>"
"</Command>"))
CodecControl.SendXMLDataToCodec(Config.codecs["kandinskySpycam"],
("<Command>"
"<UserInterface>"
"<Extensions>"
"<Widget>"
"<SetValue command=\"True\">"
"<Value>"+name+"</Value>"
"<WidgetId>OutputName</WidgetId>"
"</SetValue>"
"</Widget>"
"</Extensions>"
"</UserInterface>"
"</Command>"))
if ((Config.codecs["kandinsky"]["mac"] in xmlData) or (Config.codecs["kandinskySpycam"]["mac"] in xmlData)) and ("Validation" in xmlData) :
krammer.setInOut(inputValue,outputValue)
if ((Config.codecs["kandinsky"]["mac"] in xmlData) or (Config.codecs["kandinskySpycam"]["mac"] in xmlData)) and ("Proxixi:off" in xmlData) :
proxixi = False
CodecControl.SendXMLDataToCodec(Config.codecs["kandinsky"],
("<Configuration>"
"<Proximity>"
"<Mode>Off</Mode>"
"</Proximity>"
"</Configuration>"))
if ((Config.codecs["kandinsky"]["mac"] in xmlData) or (Config.codecs["kandinskySpycam"]["mac"] in xmlData)) and ("Proxixi:on" in xmlData) :
proxixi = True
CodecControl.SendXMLDataToCodec(Config.codecs["kandinsky"],
("<Configuration>"
"<Proximity>"
"<Mode>On</Mode>"
"</Proximity>"
"</Configuration>"))
if (Config.codecs["kandinsky"]["mac"] in xmlData) and (("startRecording_Button" in xmlData) and ("<Pressed item=\"1\">" in xmlData)):
print("Recording Start Button Clicked")
CMSRecordingControl.SetRecordingFromEpXMLNotif(xmlData,True)
if (Config.codecs["kandinsky"]["mac"] in xmlData) and (("endRecording_Button" in xmlData) and ("<Pressed item=\"1\">" in xmlData)):
print("Recording Stop Button Clicked")
CMSRecordingControl.SetRecordingFromEpXMLNotif(xmlData,False)
def SendCodecsFeedbackReg():
feedbackRegMonet = ("<Command>"
"<HttpFeedback>"
"<Register command=\"True\">"
"<FeedbackSlot>4</FeedbackSlot>"
"<ServerUrl>http://10.1.20.21:1412</ServerUrl>"
"<Expression item=\"1\">/Event/CallSuccessful</Expression>"
"<Expression item=\"2\">/Event/CallDisconnect</Expression>"
"<Expression item=\"3\">/Event/UserInterface/Extensions/Event</Expression>"
"</Register>"
"</HttpFeedback>"
"</Command>")
feedbackRegVangogh = ("<Command>"
"<HttpFeedback>"
"<Register command=\"True\">"
"<FeedbackSlot>4</FeedbackSlot>"
"<ServerUrl>http://10.1.20.21:1412</ServerUrl>"
"<Expression item=\"1\">/Event/CallSuccessful</Expression>"
"<Expression item=\"2\">/Event/CallDisconnect</Expression>"
"<Expression item=\"3\">/Event/UserInterface/Extensions/Event</Expression>"
"</Register>"
"</HttpFeedback>"
"</Command>")
feedbackRegKandi = ("<Command>"
"<HttpFeedback>"
"<Register command=\"True\">"
"<FeedbackSlot>4</FeedbackSlot>"
"<ServerUrl>http://10.1.20.21:1412</ServerUrl>"
"<Expression item=\"1\">/Event/CallSuccessful</Expression>"
"<Expression item=\"2\">/Event/CallDisconnect</Expression>"
"<Expression item=\"3\">/Event/UserInterface/Extensions/Event</Expression>"
"</Register>"
"</HttpFeedback>"
"</Command>")
feedbackRegSpycam = ("<Command>"
"<HttpFeedback>"
"<Register command=\"True\">"
"<FeedbackSlot>4</FeedbackSlot>"
"<ServerUrl>http://10.1.20.21:1412</ServerUrl>"
"<Expression item=\"1\">/Event/CallSuccessful</Expression>"
"<Expression item=\"2\">/Event/CallDisconnect</Expression>"
"<Expression item=\"3\">/Event/UserInterface/Extensions/Event</Expression>"
"</Register>"
"</HttpFeedback>"
"</Command>")
print("Starting Codec HTTPFeedback Registration \r\n")
#CodecControl.SendXMLDataToCodec(Config.codecs["monet"], feedbackRegMonet)
CodecControl.SendXMLDataToCodec(Config.codecs["vangogh"], feedbackRegVangogh)
CodecControl.SendXMLDataToCodec(Config.codecs["kandinsky"], feedbackRegKandi)
CodecControl.SendXMLDataToCodec(Config.codecs["kandinskySpycam"], feedbackRegSpycam)
print("Feedback Codec HTTPFeedback Completed")
def UpdateExternalStates():
# Etats Lumiere vanGogh
if relayBox1.relay1 == True:
CodecControl.SendXMLDataToCodec(Config.codecs["vangogh"],
("<Command>"
"<UserInterface>"
"<Extensions>"
"<Widget>"
"<SetValue command=\"True\">"
"<Value>on</Value>"
"<WidgetId>lightButton</WidgetId>"
"</SetValue>"
"</Widget>"
"</Extensions>"
"</UserInterface>"
"</Command>"))
else:
CodecControl.SendXMLDataToCodec(Config.codecs["vangogh"],
("<Command>"
"<UserInterface>"
"<Extensions>"
"<Widget>"
"<SetValue command=\"True\">"
"<Value>off</Value>"
"<WidgetId>lightButton</WidgetId>"
"</SetValue>"
"</Widget>"
"</Extensions>"
"</UserInterface>"
"</Command>"))
#Etat Mode lumiere auto vanGogh
if vanGoghAutoLight == True:
CodecControl.SendXMLDataToCodec(Config.codecs["vangogh"],
("<Command>"
"<UserInterface>"
"<Extensions>"
"<Widget>"
"<SetValue command=\"True\">"
"<Value>on</Value>"
"<WidgetId>autoLightButton</WidgetId>"
"</SetValue>"
"</Widget>"
"</Extensions>"
"</UserInterface>"
"</Command>"))
else:
CodecControl.SendXMLDataToCodec(Config.codecs["vangogh"],
("<Command>"
"<UserInterface>"
"<Extensions>"
"<Widget>"
"<SetValue command=\"True\">"
"<Value>off</Value>"
"<WidgetId>autoLightButton</WidgetId>"
"</SetValue>"
"</Widget>"
"</Extensions>"
"</UserInterface>"
"</Command>"))
# Etat Mode Auto Stores VanGogh
if vangoghAutoStores == True:
CodecControl.SendXMLDataToCodec(Config.codecs["vangogh"],
("<Command>"
"<UserInterface>"
"<Extensions>"
"<Widget>"
"<SetValue command=\"True\">"
"<Value>on</Value>"
"<WidgetId>storeAutoButton</WidgetId>"
"</SetValue>"
"</Widget>"
"</Extensions>"
"</UserInterface>"
"</Command>"))
else:
CodecControl.SendXMLDataToCodec(Config.codecs["vangogh"],
("<Command>"
"<UserInterface>"
"<Extensions>"
"<Widget>"
"<SetValue command=\"True\">"
"<Value>off</Value>"
"<WidgetId>storeAutoButton</WidgetId>"
"</SetValue>"
"</Widget>"
"</Extensions>"
"</UserInterface>"
"</Command>"))
def signal_term_handler(signal, frame):
print('got SIGTERM')
sys.exit(0)
try:
if __name__ == "__main__":
relayBox1 = RelayControl.RelayControl("10.1.100.99", 80, "admin", "admin") #Relais Vangogh Lumieres
relayBox2 = RelayControl.RelayControl("10.1.100.98", 80, "admin", "admin") #Relais Vangogh Stores
krammer = KrammerControl.KrammerControl()
signal.signal(signal.SIGTERM, signal_term_handler)
server = startThread()
ct = time.time()
while True:
# On update les état des dalles
UpdateExternalStates()
# On gere regulierement l'enregsitrement du feedback HTTP
SendCodecsFeedbackReg()
time.sleep(60)
except (KeyboardInterrupt, SystemExit):
server.shutdown()
print("--- WEB Server stopped ---")
sys.exit(0)