diff --git a/simulators/CameraNIR.py b/simulators/CameraNIR.py index 0e8a944..538331b 100644 --- a/simulators/CameraNIR.py +++ b/simulators/CameraNIR.py @@ -1,63 +1,21 @@ -import configparser import socket from enum import Enum import time import os from random import randint +from Device import Device IMAGES_FOLDER = '../src/images' -CONFIG_FILE = "socket_config.ini" EXPOSURE_TIME = 5 SHUTTER_TIME = 3 COOLER_TIME = 10 -class ReadmodeEnum(Enum): - ramp = "Ramp" - # TODO: définir les modes de lecture -class ShutterEnum(Enum): - synchro = "Synchro" - closed = "Closed" - opened = "Opened" +class CameraNIR(Device): - -class CameraNIR(): def __init__(self): - config = configparser.ConfigParser() - config.read(CONFIG_FILE) - - ip = config.get("CameraNIR", "ip") - port = int(config.get("CameraNIR", "port")) - - self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - self.sock.bind((ip, port)) - self.sock.listen(122) - - self.set_msgs = [ - ("WINDOW", [4, ], int), - ("READMODE", [1, ], ReadmodeEnum), - ("FILENAME", [1, ], str), - ("HEADER", [1, ], dict), - ("READOUT_FREQUENCY", [1, ], float), - ("NB_IMAGES", [1, ], int), - ] - - self.get_msgs = [ - "STATUS", - "SETUP", - "TEMPERATURE", - "TIMER", - ] - - self.do_msgs = [ - ("COOLER", [2, ], float), - ("SHUTTER", [1, ], ShutterEnum), - ("START", [0, ]), - ("ABORT", [0, ]), - ("STOP", [0, ]), - ] + super().__init__("CameraNIR") ''' I will just fill the attributes with their names and params without regarding them ''' self.attributes = {} diff --git a/simulators/CameraVIS.py b/simulators/CameraVIS.py index 458061e..89737f9 100644 --- a/simulators/CameraVIS.py +++ b/simulators/CameraVIS.py @@ -1,64 +1,20 @@ -import configparser import socket from enum import Enum import time import os from random import randint +from Device import Device IMAGES_FOLDER = '../src/images' -CONFIG_FILE = "socket_config.ini" EXPOSURE_TIME = 5 SHUTTER_TIME = 3 COOLER_TIME = 10 -class ReadmodeEnum(Enum): - ramp = "Ramp" - # TODO: définir les modes de lecture -class ShutterEnum(Enum): - synchro = "Synchro" - closed = "Closed" - opened = "Opened" - - -class CameraVIS(): +class CameraVIS(Device): def __init__(self): - config = configparser.ConfigParser() - config.read(CONFIG_FILE) - - ip = config.get("CameraVIS", "ip") - port = int(config.get("CameraVIS", "port")) - - self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - self.sock.bind((ip, port)) - self.sock.listen(12) - - self.set_msgs = [ - ("WINDOW", [4, ], int), - ("READMODE", [1, ], ReadmodeEnum), - ("FILENAME", [1, ], str), - ("HEADER", [1, ], dict), - ("READOUT_FREQUENCY", [1, ], float), - ("EXPOSURE", [1, ], int), - ("BINNING", [2, ], int), - ] - - self.get_msgs = [ - "STATUS", - "SETUP", - "TEMPERATURE", - "TIMER", - ] - - self.do_msgs = [ - ("COOLER", [2, ], float), - ("SHUTTER", [1, ], ShutterEnum), - ("START", [0, ]), - ("ABORT", [0, ]), - ("STOP", [0, ]), - ] + super().__init__("CameraVIS") ''' I will just fill the attributes with their names and params without regarding them ''' self.attributes = {} diff --git a/simulators/Device.py b/simulators/Device.py new file mode 100644 index 0000000..b5efc1a --- /dev/null +++ b/simulators/Device.py @@ -0,0 +1,61 @@ +import configparser +import socket +import json + + +# from enum import Enum +# import time +# import os +# from random import randint + +IMAGES_FOLDER = '../src/images' +CONFIG_FILE = "socket_config.ini" +GRAMMAR_FILE = "grammar.json" + +class Device(): + + def __init__(self, simul_name): + + config = configparser.ConfigParser() + config.read(CONFIG_FILE) + + ip = config.get(simul_name, "ip") + port = int(config.get(simul_name, "port")) + + self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + self.sock.bind((ip, port)) + self.sock.listen(122) + + self.set_msgs = [] + self.get_msgs = [] + self.do_msgs = [] + + self.enums = {} + + with open("grammar.json") as grammar_file: + grammar = json.load(grammar_file) + + enums = grammar["Enums"] + + for enum in enums : + self.enums[enum] = enums[enum] + + if simul_name[:6] == "Camera": + device = grammar["Camera"] + + for item in device["set"]: + self.set_msgs.append((item["name"], item["nb_param"], item["param_type"])) # TODO : transformer les param_type qui ne sont pas des enum + for item in device["get"]: + self.get_msgs.append(item) + for item in device["do"]: + self.do_msgs.append((item["name"], item["nb_param"], item["param_type"])) # TODO : transformer les param_type qui ne sont pas des enum + + device = grammar[simul_name] + + for item in device["set"]: + self.set_msgs.append((item["name"], item["nb_param"], item["param_type"])) # TODO : transformer les param_type qui ne sont pas des enum + for item in device["get"]: + self.get_msgs.append(item) + for item in device["do"]: + self.do_msgs.append((item["name"], item["nb_param"], item["param_type"])) # TODO : transformer les param_type qui ne sont pas des enum diff --git a/simulators/PLC.py b/simulators/PLC.py index e49cb8b..884c7f3 100644 --- a/simulators/PLC.py +++ b/simulators/PLC.py @@ -1,31 +1,11 @@ -import configparser import socket from enum import Enum +from Device import Device -CONFIG_FILE = "socket_config.ini" - -class PLC(): +class PLC(Device): def __init__(self): - config = configparser.ConfigParser() - config.read(CONFIG_FILE) - - ip = config.get("PLC", "ip") - port = int(config.get("PLC", "port")) - - self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - self.sock.bind((ip, port)) - self.sock.listen(12) - - self.set_msgs = [] - - get_msgs = [ - "STATUS", - ] - - do_msgs = [] - + super().__init__("PLC") def loop(self): while True: diff --git a/simulators/Telescope.py b/simulators/Telescope.py index ad08650..fca0506 100644 --- a/simulators/Telescope.py +++ b/simulators/Telescope.py @@ -1,68 +1,15 @@ -import configparser import socket from enum import Enum import time - -CONFIG_FILE = "socket_config.ini" - -class RotatorEnum(Enum): - none = "None" - synchro = "Synchro" - tracking = "Tracking" - -class MoveModeEnum(Enum): - goto = "Goto" - track = "Track" - goto_track = "GotoTrack" - -class CoordsFrameEnum(Enum): - hadec = "Hadec" - radec = "Radec" - altaz = "Altaz" +from Device import Device DOORS_TIME = 5 MOVE_TIME = 5 -class Telescope(): +class Telescope(Device): def __init__(self): - config = configparser.ConfigParser() - config.read(CONFIG_FILE) - - ip = config.get("Telescope", "ip") - port = int(config.get("Telescope", "port")) - - self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - self.sock.bind((ip, port)) - self.sock.listen(12) - - - self.set_msgs = [ - ("SPEED", [2, 3], float), - ("COORDS", [2, 3], float), - ("TRACKING_SPEED", [2, 3], float), - ("ACCEL", [2, 3], float), - - ("ROTATOR", [1, ], RotatorEnum), - ("FOCUS", [1, ], float), - ("MOVE_MODE", [1, ], MoveModeEnum), - ("COORDS_FRAME", [1, ], CoordsFrameEnum), - ] - - get_msgs = [ - "POSITION", - "STATUS", - "SETUP", - ] - - do_msgs = [ - ("DOORS", [1, ], bool), - ("START", [0, ],), - ("ABORT", [0, ],), - ("STOP", [0, ],), - ("HOMING", [0, ],), - ] + super().__init__("Telescope") ''' I will just fill the attributes with their names and params without regarding them ''' self.attributes = {} diff --git a/simulators/grammar.json b/simulators/grammar.json new file mode 100644 index 0000000..82b02c7 --- /dev/null +++ b/simulators/grammar.json @@ -0,0 +1,229 @@ +{ + "Telescope" : { + "set": [ + { + "name": "SPEED", + "nb_param": [2, 3], + "param_type": "float" + }, + { + "name": "COORDS", + "nb_param": [2, 3], + "param_type": "float" + }, + { + "name": "TRACKING_SPEED", + "nb_param": [2, 3], + "param_type": "float" + }, + { + "name": "ACCEL", + "nb_param": [2, 3], + "param_type": "float" + }, + { + "name": "ROTATOR", + "nb_param": [1], + "param_type": "EnumRotator" + }, + { + "name": "FOCUS", + "nb_param": [1], + "param_type": "float" + }, + { + "name": "MOVE_MODE", + "nb_param": [1], + "param_type": "EnumMoveMode" + }, + { + "name": "COORDS_FRAME", + "nb_param": [1], + "param_type": "EnumCoordsFrame" + } + + ], + "get": [ + "POSITION", + "STATUS", + "SETUP" + ], + + "do": [ + { + "name": "DOORS", + "nb_param": [1], + "param_type": "bool" + }, + { + "name": "START", + "nb_param": [0], + "param_type": "" + }, + { + "name": "ABORT", + "nb_param": [0], + "param_type": "" + }, + { + "name": "STOP", + "nb_param": [0], + "param_type": "" + }, + { + "name": "HOMING", + "nb_param": [0], + "param_type": "" + } + + ] + }, + + "Camera" : { + "set" : [ + { + "name": "WINDOW", + "nb_param": [4], + "param_type": "int" + }, + { + "name": "READMODE", + "nb_param": [1], + "param_type": "EnumReadMode" + }, + { + "name": "FILENAME", + "nb_param": [1], + "param_type": "str" + }, + { + "name": "HEADER", + "nb_param": [1], + "param_type": "dict" + }, + { + "name": "READOUT_FREQUENCY", + "nb_param": [1], + "param_type": "float" + }, + { + "name": "FILTER", + "nb_param": [1], + "param_type": "EnumFilter" + } + ], + "get" : [ + "STATUS", + "TEMPERATURE", + "SETUP", + "TIMER" + ], + + "do" : [ + { + "name": "COOLER", + "nb_param": [2], + "param_type": "float" + }, + { + "name": "SHUTTER", + "nb_param": [1], + "param_type": "EnumShutter" + }, + { + "name": "START", + "nb_param": [0], + "param_type": "" + }, + { + "name": "STOP", + "nb_param": [0], + "param_type": "" + }, + { + "name": "ABORT", + "nb_param": [0], + "param_type": "" + } + ] + }, + + "CameraVIS" : { + "set" : [ + { + "name": "EXPOSURE", + "nb_param": [1], + "param_type": "int" + }, + { + "name": "BINNING", + "nb_param": [2], + "param_type": "int" + } + ], + "get" : [], + "do" : [] + }, + + "CameraNIR" : { + "set" : [ + { + "name": "NB_IMAGES", + "nb_param": [1], + "param_type": "int" + } + ], + "get" : [], + "do" : [] + }, + + "CameraNIR" : { + "set" : [ + { + "name": "NB_IMAGES", + "nb_param": [1], + "param_type": "int" + } + ], + "get" : [], + "do" : [] + }, + + "PLC" : { + "set" : [], + "get" : [ + "STATUS" + ], + "do" : [] + }, + + "Enums" : { + "EnumReadMode" : [ + "Ramp" + ], + "EnumShutter" : [ + "Synchro", + "Closed", + "Opened" + ], + "EnumFilter" : [ + "T", + "H" + ], + "EnumRotator" : [ + "None", + "Synchro", + "Tracking" + ], + "EnumMoveMode" : [ + "Goto", + "Track", + "GotoTrack" + ], + "EnumCoordsFrame" : [ + "Hadec", + "Radec", + "Altaz" + ] + } +} diff --git a/src/common/RequestBuilder.py b/src/common/RequestBuilder.py index c456287..404ff91 100644 --- a/src/common/RequestBuilder.py +++ b/src/common/RequestBuilder.py @@ -171,6 +171,7 @@ class RequestBuilder(): if settings.CELERY_TEST == False: pass + # TODO: mettre une condition de temps pour lancer le scheduling (il faut être nuit -2 min au minimum) # scheduler.tasks.scheduling.delay(first_schedule=True, alert=self.request.is_alert) # TODO : changer le first_schedule ... return self.request diff --git a/src/majordome/tasks.py b/src/majordome/tasks.py index 467c449..bc3aea7 100644 --- a/src/majordome/tasks.py +++ b/src/majordome/tasks.py @@ -47,16 +47,16 @@ class execute_sequence(Task): scheduler.tasks.scheduling.delay(first_schedule=True, alert=False) # TODO : changer le first_schedule à False return - tel = Tel.TelescopeObj() + tel = Tel.TelescopeController() tel.set("SPEED", 10.0, 10.0, 10.0) tel.set("COORDS", 104.0, 12.0, 88.0) - tel.set("COORDS_FRAME", Tel.CoordsFrameEnum.radec) + tel.set("COORDS_FRAME", "Radec") tel.set("TRACKING_SPEED", 0.3, 0.3, 0.3) tel.set("ACCEL", 1.0, 1.0, 1.0) - tel.set("ROTATOR", Tel.RotatorEnum.tracking) + tel.set("ROTATOR", "Tracking") tel.set("FOCUS", 23562.0) - tel.set("MOVE_MODE", Tel.MoveModeEnum.goto_track) + tel.set("MOVE_MODE", "GotoTrack") tel.do("START") diff --git a/src/observation_manager/tasks.py b/src/observation_manager/tasks.py index 97c65ac..7bbc332 100644 --- a/src/observation_manager/tasks.py +++ b/src/observation_manager/tasks.py @@ -53,11 +53,11 @@ class execute_plan_vis(Task): # TODO: mettre les vraies configurations en fct du plan cam.set("WINDOW", 0, 100, 10, 100) - cam.set("READMODE", VIS.ReadmodeEnum.ramp) + cam.set("READMODE", "Ramp") cam.set("FILENAME", plan.name) cam.set("HEADER", {}) cam.set("READOUT_FREQUENCY", 20.0) - cam.set("FILTER", VIS.FilterEnum.h) + cam.set("FILTER", "H") cam.set("EXPOSURE", 180) cam.set("BINNING", 300, 300) @@ -134,11 +134,11 @@ class execute_plan_nir(Task): def set_camera(self, cam, plan): cam.set("WINDOW", 0, 100, 10, 100) - cam.set("READMODE", NIR.ReadmodeEnum.ramp) + cam.set("READMODE", "Ramp") cam.set("FILENAME", plan.name) cam.set("HEADER", {}) cam.set("READOUT_FREQUENCY", 20.0) - cam.set("FILTER", NIR.FilterEnum.h) + cam.set("FILTER", "H") cam.set("NB_IMAGES", 28) diff --git a/src/pyros/settings.py b/src/pyros/settings.py index ae50995..5f0d36c 100644 --- a/src/pyros/settings.py +++ b/src/pyros/settings.py @@ -29,7 +29,7 @@ MODULES_VERSIONS = { # Set MYSQL to False if you want to use SQLITE # This line MUST NOT be changed at all except from changing True/False # (or install_requirements script will become invalid) -MYSQL = True +MYSQL = False import os diff --git a/src/routine_manager/views.py b/src/routine_manager/views.py index 21ca650..6ef50d2 100644 --- a/src/routine_manager/views.py +++ b/src/routine_manager/views.py @@ -27,7 +27,9 @@ def requests_list(request, status=0, message=""): # TODO: uncomment for alert filter # requests_objs = Request.objects.filter(pyros_user=request.user.pyros_user).filter(is_alert=False).order_by("-updated") - requests_objs = Request.objects.filter(pyros_user=request.user.pyros_user).order_by("-updated") +# requests_objs = Request.objects.filter(pyros_user=request.user.pyros_user).order_by("-updated") + + requests_objs = Request.objects.all().order_by("-updated") requests = [] diff --git a/src/user_manager/forms.py b/src/user_manager/forms.py index 27d1853..fbcf979 100644 --- a/src/user_manager/forms.py +++ b/src/user_manager/forms.py @@ -61,6 +61,7 @@ class PyrosUserCreationForm(forms.ModelForm): user.last_name = self.cleaned_data['last_name'] user.save() + # Default values for country and user level pyros_user = PyrosUser.objects.create(user=user, country=Country.objects.all()[0], user_level=UserLevel.objects.all()[0], tel=self.cleaned_data['tel'], laboratory=self.cleaned_data['laboratory'], -- libgit2 0.21.2