Cameras dic

Added settings folder, and creating dictionary from the cameras and pipelines
This commit is contained in:
Sagi Frimer
2019-03-31 01:27:17 +03:00
parent 3d5a326e0b
commit 557f6a109f
8 changed files with 62 additions and 36 deletions

View File

@@ -6,8 +6,5 @@ class ChameleonCamera:
def __init__(self, dic):
self.pipelines = {}
for pipeline_id in dic["pipelines"]:
self.pipelines[pipeline_id] = ChameleonPipeline(dic[pipeline_id])
def change_value(self, pipline_id, key, value):
self.pipelines[pipline_id][key] = value
for pipeline_id in dic:
self.pipelines[pipeline_id] = ChameleonPipeline(dic[pipeline_id])

View File

@@ -3,6 +3,5 @@
class ChameleonPipeline:
def __init__(self, dic):
self.id = dic["id"]
self.exposure = dic["exposure"]
self.brightness = dic["brightness"]

View File

@@ -1,52 +1,61 @@
import tornado.websocket
import json
import os
from app.classes.ChameleonCamera import ChameleonCamera
class ChameleonWebSocket(tornado.websocket.WebSocketHandler):
actions = {}
settings = {}
cams = {}
def __init__(self, application, request, **kwargs):
super().__init__(application, request, **kwargs)
self.settings_path = os.path.join(os.getcwd(), "settings")
self.cams_path = os.path.join(self.settings_path, "cams")
self.init_settings()
self.init_actions()
def init_settings(self):
with open(os.path.join(self.settings_path, 'settings.json')) as setting_file:
self.settings = json.load(setting_file)
self.init_cameras_settings()
def init_cameras_settings(self):
for curr_dir in os.listdir(self.cams_path):
pipelines = {}
for file in os.listdir(os.path.join(self.cams_path, curr_dir)):
with open(os.path.join(self.cams_path, curr_dir, file)) as pipeline:
pipelines[os.path.splitext(file)[0]] = json.load(pipeline)
self.cams[curr_dir] = pipelines
def init_actions(self):
self.actions["change_pipeline_value"] = self.change_pipeline_value
def check_origin(self, origin):
return True
def open(self):
# 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)
self.write_message(self.cams[self.settings["curr_camera"]][self.settings["curr_pipeline"]])
print("WebSocket opened")
def on_message(self, message):
cams = []
dic = {
'cam1': {
'pipelines': {
"1": {"exposure": 45, "brightness": 123123},
"2": {"exposure": 12, "brightness": 123},
"3": {"exposure": 23, "brightness": 12}
}
},
'cam2': {
'pipelines': {
"1": {"exposure": 15, "brightness": 1233},
"2": {"exposure": 68, "brightness": 453}
}
}
}
for cam in dic:
cams.append(ChameleonCamera(dic[cam]))
for key in message:
if key in self.actions:
self.actions[key](message[key])
print(message)
self.write_message(message)
def on_close(self):
print("WebSocket closed")
def change_pipeline_value(self, dic):
for key in dic:
self.cams[self.settings["curr_camera"]][self.settings["curr_pipeline"]][key] = dic[key]

View File

@@ -0,0 +1,4 @@
{
"exposure": 45,
"brightness": 123123
}

View File

@@ -0,0 +1,4 @@
{
"exposure": 23,
"brightness": 12
}

View File

@@ -0,0 +1,4 @@
{
"exposure": 2,
"brightness": 4
}

View File

@@ -0,0 +1,4 @@
{
"exposure": 2,
"brightness": 3
}

View File

@@ -0,0 +1,5 @@
{
"team_number": 1577,
"curr_camera": "cam1",
"curr_pipeline": "pipeline1"
}