Files
PhotonVision/backend/app/handlers/SocketHandler.py

53 lines
1.5 KiB
Python
Raw Normal View History

2019-03-01 21:59:49 +02:00
import tornado.websocket
2019-03-23 23:42:24 +02:00
import json
2019-03-26 22:51:48 +02:00
from app.classes.ChameleonCamera import ChameleonCamera
2019-03-01 21:59:49 +02:00
2019-03-26 21:05:31 +02:00
2019-03-01 21:59:49 +02:00
class ChameleonWebSocket(tornado.websocket.WebSocketHandler):
2019-03-26 21:05:31 +02:00
2019-03-23 23:42:24 +02:00
def check_origin(self, origin):
return True
2019-03-26 21:05:31 +02:00
2019-03-01 21:59:49 +02:00
def open(self):
2019-03-29 18:20:40 +03:00
# TODO: read setting from default file store them
setting = json.load("file.json")
self.cam_name = setting["curr_cam"]
self.pipe_line = setting["curr_pipeline"]
# TODO: get current camera pipeline file
curr_setting = json.load(self.cam_name + "/" + self.pipe_line)
# TODO: wrtie current pipeline setting to client
self.write_message(curr_setting)
2019-03-02 00:12:41 +02:00
print("WebSocket opened")
2019-03-01 21:59:49 +02:00
def on_message(self, message):
cams = []
dic = {
'cam1': {
2019-03-29 18:20:40 +03:00
'pipelines': {
"1": {"exposure": 45, "brightness": 123123},
"2": {"exposure": 12, "brightness": 123},
"3": {"exposure": 23, "brightness": 12}
}
},
'cam2': {
2019-03-29 18:20:40 +03:00
'pipelines': {
"1": {"exposure": 15, "brightness": 1233},
"2": {"exposure": 68, "brightness": 453}
}
}
}
for cam in dic:
cams.append(ChameleonCamera(dic[cam]))
2019-03-26 21:05:01 +02:00
print(message)
2019-03-23 23:42:24 +02:00
self.write_message(message)
2019-03-02 00:12:41 +02:00
2019-03-01 21:59:49 +02:00
def on_close(self):
2019-03-02 00:12:41 +02:00
print("WebSocket closed")