From b53dbffe9875c52f77f65bc65bdb4b7c898a6887 Mon Sep 17 00:00:00 2001 From: haribo Date: Fri, 22 Jul 2016 17:40:52 +0200 Subject: [PATCH] Date: 22/07/2016 By: Paul Carensac Version: 0.12.2 Cameras simulators Issues (closed): https://projects.irap.omp.eu/issues/4007 Major current version (0.11): https://projects.irap.omp.eu/versions/129 --- README.md | 6 +++--- simulators/CameraNIR.py | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ simulators/CameraVIS.py | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ simulators/Telescope.py | 12 +++++++----- simulators/socket_config.ini | 4 ++++ 5 files changed, 299 insertions(+), 8 deletions(-) create mode 100644 simulators/CameraNIR.py create mode 100644 simulators/CameraVIS.py diff --git a/README.md b/README.md index 530ecb0..0b540a9 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,9 @@ CURRENT VERSION Date: 22/07/2016 By: Paul Carensac -Version: 0.12.1 -Telescope simulator + adaptations in the code -Issues (closed): https://projects.irap.omp.eu/issues/4006 +Version: 0.12.2 +Cameras simulators +Issues (closed): https://projects.irap.omp.eu/issues/4007 Major current version (0.11): https://projects.irap.omp.eu/versions/129 ROADMAP: https://projects.irap.omp.eu/projects/pyros/roadmap diff --git a/simulators/CameraNIR.py b/simulators/CameraNIR.py new file mode 100644 index 0000000..8dc13e3 --- /dev/null +++ b/simulators/CameraNIR.py @@ -0,0 +1,142 @@ +import configparser +import socket +from enum import Enum +import time + +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(): + 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(12) + + 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, ]), + ] + + ''' I will just fill the attributes with their names and params without regarding them ''' + self.attributes = {} + + self.status = "IDLE" + self.shutter_status = "CLOSE" + + def loop(self): + # à gérer : la réception des paramètres, le temps de shutter (et son statut), le temps de start, le stop, le abort, la création d'images + pass + + cooler_timer = 0 + shutter_timer = 0 + exposure_timer = 0 + + while True: + try: + conn, addr = self.sock.accept() + except socket.error as e: + print("There was a socket error: " + repr(e)) + break + + data = conn.recv(128).decode() + + print("Received: " + data) + + answer = "" + cut_data = data.split(" ") + + if cooler_timer != 0 and time.time() > cooler_timer: + cooler_timer = 0 + status = "IDLE" + print("Stopped cooling") + if shutter_timer != 0 and time.time() > shutter_timer: + shutter_timer = 0 + print("Stopped shutter") + if exposure_timer != 0 and time.time() > exposure_timer: + exposure_timer = 0 + print("Stopped exposure") + # TODO: créer une image + + if len(cut_data) < 2: + print("Invalid message: " + data) + else: + cmd_type = cut_data[0] + cmd = cut_data[1] + args = cut_data[2:] + if cmd_type == "SET": + self.attributes[cmd] = args + elif cmd_type == "GET": + if cmd == "STATUS": + answer = self.status + elif cmd == "TEMPERATURE": + answer = "GET TEMPERATURE answer not implemented" + elif cmd == "SETUP": + answer = "GET SETUP answer not implemented" + elif cmd == "TIMER": + answer = "GET TIMER answer not implemented" + else: + answer = "Invalid cmd for GET: " + cmd + print(answer) + elif cmd_type == "DO": + if cmd == "START": + exposure_timer = time.time() + EXPOSURE_TIME + elif cmd == "STOP": + exposure_timer = 0 + elif cmd == "ABORT": + exposure_timer = 0 + elif cmd == "COOLER": + cooler_timer = time.time() + COOLER_TIME + elif cmd == "SHUTTER": + shutter_timer = time.time() + SHUTTER_TIME + else: + print("Invalid cmd for GET: " + cmd) + else: + print("Invalid message: " + data) + + if len(answer) > 0: + conn.send(bytes(answer, "UTF-8")) + print("send: " + answer) + + conn.close() + +cam = CameraVIS() +cam.loop() diff --git a/simulators/CameraVIS.py b/simulators/CameraVIS.py new file mode 100644 index 0000000..13bae87 --- /dev/null +++ b/simulators/CameraVIS.py @@ -0,0 +1,143 @@ +import configparser +import socket +from enum import Enum +import time + +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(): + 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, ]), + ] + + ''' I will just fill the attributes with their names and params without regarding them ''' + self.attributes = {} + + self.status = "IDLE" + self.shutter_status = "CLOSE" + + def loop(self): + # à gérer : la réception des paramètres, le temps de shutter (et son statut), le temps de start, le stop, le abort, la création d'images + pass + + cooler_timer = 0 + shutter_timer = 0 + exposure_timer = 0 + + while True: + try: + conn, addr = self.sock.accept() + except socket.error as e: + print("There was a socket error: " + repr(e)) + break + + data = conn.recv(128).decode() + + print("Received: " + data) + + answer = "" + cut_data = data.split(" ") + + if cooler_timer != 0 and time.time() > cooler_timer: + cooler_timer = 0 + status = "IDLE" + print("Stopped cooling") + if shutter_timer != 0 and time.time() > shutter_timer: + shutter_timer = 0 + print("Stopped shutter") + if exposure_timer != 0 and time.time() > exposure_timer: + exposure_timer = 0 + print("Stopped exposure") + # TODO: créer une image + + if len(cut_data) < 2: + print("Invalid message: " + data) + else: + cmd_type = cut_data[0] + cmd = cut_data[1] + args = cut_data[2:] + if cmd_type == "SET": + self.attributes[cmd] = args + elif cmd_type == "GET": + if cmd == "STATUS": + answer = self.status + elif cmd == "TEMPERATURE": + answer = "GET TEMPERATURE answer not implemented" + elif cmd == "SETUP": + answer = "GET SETUP answer not implemented" + elif cmd == "TIMER": + answer = "GET TIMER answer not implemented" + else: + answer = "Invalid cmd for GET: " + cmd + print(answer) + elif cmd_type == "DO": + if cmd == "START": + exposure_timer = time.time() + EXPOSURE_TIME + elif cmd == "STOP": + exposure_timer = 0 + elif cmd == "ABORT": + exposure_timer = 0 + elif cmd == "COOLER": + cooler_timer = time.time() + COOLER_TIME + elif cmd == "SHUTTER": + shutter_timer = time.time() + SHUTTER_TIME + else: + print("Invalid cmd for GET: " + cmd) + else: + print("Invalid message: " + data) + + if len(answer) > 0: + conn.send(bytes(answer, "UTF-8")) + print("send: " + answer) + + conn.close() + +cam = CameraVIS() +cam.loop() diff --git a/simulators/Telescope.py b/simulators/Telescope.py index f0dc532..ad08650 100644 --- a/simulators/Telescope.py +++ b/simulators/Telescope.py @@ -67,7 +67,7 @@ class Telescope(): ''' I will just fill the attributes with their names and params without regarding them ''' self.attributes = {} - self.doors_status = True + self.doors_status = "True" self.status = "IDLE" @@ -126,19 +126,21 @@ class Telescope(): if cmd == "START": print("Start movement") move_timer = time.time() + MOVE_TIME - if cmd == "STOP": + elif cmd == "STOP": move_timer = 0 - if cmd == "ABORT": + elif cmd == "ABORT": move_timer = 0 - if cmd == "HOMING": + elif cmd == "HOMING": print("Start movement (homing)") move_timer = time.time() + MOVE_TIME - if cmd == "DOORS": + elif cmd == "DOORS": if len(args) > 0: if args[0] != self.doors_status: print("Start door") self.doors_status = args[0] doors_timer = time.time() + DOORS_TIME + else: + print("Invalid cmd for DO: " + cmd) else: print("Invalid message: " + data) diff --git a/simulators/socket_config.ini b/simulators/socket_config.ini index baf6687..2783b83 100644 --- a/simulators/socket_config.ini +++ b/simulators/socket_config.ini @@ -1,3 +1,7 @@ [Telescope] ip=127.0.0.1 port=5000 + +[CameraVIS] +ip=127.0.0.1 +port=5001 -- libgit2 0.21.2