Commit b53dbffe9875c52f77f65bc65bdb4b7c898a6887
1 parent
ac26ad2b
Exists in
master
and in
1 other branch
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
Showing
5 changed files
with
299 additions
and
8 deletions
Show diff stats
README.md
... | ... | @@ -62,9 +62,9 @@ CURRENT VERSION |
62 | 62 | |
63 | 63 | Date: 22/07/2016 |
64 | 64 | By: Paul Carensac |
65 | -Version: 0.12.1 | |
66 | -Telescope simulator + adaptations in the code | |
67 | -Issues (closed): https://projects.irap.omp.eu/issues/4006 | |
65 | +Version: 0.12.2 | |
66 | +Cameras simulators | |
67 | +Issues (closed): https://projects.irap.omp.eu/issues/4007 | |
68 | 68 | Major current version (0.11): https://projects.irap.omp.eu/versions/129 |
69 | 69 | |
70 | 70 | ROADMAP: https://projects.irap.omp.eu/projects/pyros/roadmap | ... | ... |
... | ... | @@ -0,0 +1,142 @@ |
1 | +import configparser | |
2 | +import socket | |
3 | +from enum import Enum | |
4 | +import time | |
5 | + | |
6 | +CONFIG_FILE = "socket_config.ini" | |
7 | + | |
8 | +EXPOSURE_TIME = 5 | |
9 | +SHUTTER_TIME = 3 | |
10 | +COOLER_TIME = 10 | |
11 | + | |
12 | +class ReadmodeEnum(Enum): | |
13 | + ramp = "Ramp" | |
14 | + # TODO: définir les modes de lecture | |
15 | + | |
16 | +class ShutterEnum(Enum): | |
17 | + synchro = "Synchro" | |
18 | + closed = "Closed" | |
19 | + opened = "Opened" | |
20 | + | |
21 | + | |
22 | +class CameraVIS(): | |
23 | + def __init__(self): | |
24 | + config = configparser.ConfigParser() | |
25 | + config.read(CONFIG_FILE) | |
26 | + | |
27 | + ip = config.get("CameraNIR", "ip") | |
28 | + port = int(config.get("CameraNIR", "port")) | |
29 | + | |
30 | + self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
31 | + self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
32 | + self.sock.bind((ip, port)) | |
33 | + self.sock.listen(12) | |
34 | + | |
35 | + self.set_msgs = [ | |
36 | + ("WINDOW", [4, ], int), | |
37 | + ("READMODE", [1, ], ReadmodeEnum), | |
38 | + ("FILENAME", [1, ], str), | |
39 | + ("HEADER", [1, ], dict), | |
40 | + ("READOUT_FREQUENCY", [1, ], float), | |
41 | + ("NB_IMAGES", [1, ], int), | |
42 | + ] | |
43 | + | |
44 | + self.get_msgs = [ | |
45 | + "STATUS", | |
46 | + "SETUP", | |
47 | + "TEMPERATURE", | |
48 | + "TIMER", | |
49 | + ] | |
50 | + | |
51 | + self.do_msgs = [ | |
52 | + ("COOLER", [2, ], float), | |
53 | + ("SHUTTER", [1, ], ShutterEnum), | |
54 | + ("START", [0, ]), | |
55 | + ("ABORT", [0, ]), | |
56 | + ("STOP", [0, ]), | |
57 | + ] | |
58 | + | |
59 | + ''' I will just fill the attributes with their names and params without regarding them ''' | |
60 | + self.attributes = {} | |
61 | + | |
62 | + self.status = "IDLE" | |
63 | + self.shutter_status = "CLOSE" | |
64 | + | |
65 | + def loop(self): | |
66 | + # à 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 | |
67 | + pass | |
68 | + | |
69 | + cooler_timer = 0 | |
70 | + shutter_timer = 0 | |
71 | + exposure_timer = 0 | |
72 | + | |
73 | + while True: | |
74 | + try: | |
75 | + conn, addr = self.sock.accept() | |
76 | + except socket.error as e: | |
77 | + print("There was a socket error: " + repr(e)) | |
78 | + break | |
79 | + | |
80 | + data = conn.recv(128).decode() | |
81 | + | |
82 | + print("Received: " + data) | |
83 | + | |
84 | + answer = "" | |
85 | + cut_data = data.split(" ") | |
86 | + | |
87 | + if cooler_timer != 0 and time.time() > cooler_timer: | |
88 | + cooler_timer = 0 | |
89 | + status = "IDLE" | |
90 | + print("Stopped cooling") | |
91 | + if shutter_timer != 0 and time.time() > shutter_timer: | |
92 | + shutter_timer = 0 | |
93 | + print("Stopped shutter") | |
94 | + if exposure_timer != 0 and time.time() > exposure_timer: | |
95 | + exposure_timer = 0 | |
96 | + print("Stopped exposure") | |
97 | + # TODO: créer une image | |
98 | + | |
99 | + if len(cut_data) < 2: | |
100 | + print("Invalid message: " + data) | |
101 | + else: | |
102 | + cmd_type = cut_data[0] | |
103 | + cmd = cut_data[1] | |
104 | + args = cut_data[2:] | |
105 | + if cmd_type == "SET": | |
106 | + self.attributes[cmd] = args | |
107 | + elif cmd_type == "GET": | |
108 | + if cmd == "STATUS": | |
109 | + answer = self.status | |
110 | + elif cmd == "TEMPERATURE": | |
111 | + answer = "GET TEMPERATURE answer not implemented" | |
112 | + elif cmd == "SETUP": | |
113 | + answer = "GET SETUP answer not implemented" | |
114 | + elif cmd == "TIMER": | |
115 | + answer = "GET TIMER answer not implemented" | |
116 | + else: | |
117 | + answer = "Invalid cmd for GET: " + cmd | |
118 | + print(answer) | |
119 | + elif cmd_type == "DO": | |
120 | + if cmd == "START": | |
121 | + exposure_timer = time.time() + EXPOSURE_TIME | |
122 | + elif cmd == "STOP": | |
123 | + exposure_timer = 0 | |
124 | + elif cmd == "ABORT": | |
125 | + exposure_timer = 0 | |
126 | + elif cmd == "COOLER": | |
127 | + cooler_timer = time.time() + COOLER_TIME | |
128 | + elif cmd == "SHUTTER": | |
129 | + shutter_timer = time.time() + SHUTTER_TIME | |
130 | + else: | |
131 | + print("Invalid cmd for GET: " + cmd) | |
132 | + else: | |
133 | + print("Invalid message: " + data) | |
134 | + | |
135 | + if len(answer) > 0: | |
136 | + conn.send(bytes(answer, "UTF-8")) | |
137 | + print("send: " + answer) | |
138 | + | |
139 | + conn.close() | |
140 | + | |
141 | +cam = CameraVIS() | |
142 | +cam.loop() | ... | ... |
... | ... | @@ -0,0 +1,143 @@ |
1 | +import configparser | |
2 | +import socket | |
3 | +from enum import Enum | |
4 | +import time | |
5 | + | |
6 | +CONFIG_FILE = "socket_config.ini" | |
7 | + | |
8 | +EXPOSURE_TIME = 5 | |
9 | +SHUTTER_TIME = 3 | |
10 | +COOLER_TIME = 10 | |
11 | + | |
12 | +class ReadmodeEnum(Enum): | |
13 | + ramp = "Ramp" | |
14 | + # TODO: définir les modes de lecture | |
15 | + | |
16 | +class ShutterEnum(Enum): | |
17 | + synchro = "Synchro" | |
18 | + closed = "Closed" | |
19 | + opened = "Opened" | |
20 | + | |
21 | + | |
22 | +class CameraVIS(): | |
23 | + def __init__(self): | |
24 | + config = configparser.ConfigParser() | |
25 | + config.read(CONFIG_FILE) | |
26 | + | |
27 | + ip = config.get("CameraVIS", "ip") | |
28 | + port = int(config.get("CameraVIS", "port")) | |
29 | + | |
30 | + self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
31 | + self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
32 | + self.sock.bind((ip, port)) | |
33 | + self.sock.listen(12) | |
34 | + | |
35 | + self.set_msgs = [ | |
36 | + ("WINDOW", [4, ], int), | |
37 | + ("READMODE", [1, ], ReadmodeEnum), | |
38 | + ("FILENAME", [1, ], str), | |
39 | + ("HEADER", [1, ], dict), | |
40 | + ("READOUT_FREQUENCY", [1, ], float), | |
41 | + ("EXPOSURE", [1, ], int), | |
42 | + ("BINNING", [2, ], int), | |
43 | + ] | |
44 | + | |
45 | + self.get_msgs = [ | |
46 | + "STATUS", | |
47 | + "SETUP", | |
48 | + "TEMPERATURE", | |
49 | + "TIMER", | |
50 | + ] | |
51 | + | |
52 | + self.do_msgs = [ | |
53 | + ("COOLER", [2, ], float), | |
54 | + ("SHUTTER", [1, ], ShutterEnum), | |
55 | + ("START", [0, ]), | |
56 | + ("ABORT", [0, ]), | |
57 | + ("STOP", [0, ]), | |
58 | + ] | |
59 | + | |
60 | + ''' I will just fill the attributes with their names and params without regarding them ''' | |
61 | + self.attributes = {} | |
62 | + | |
63 | + self.status = "IDLE" | |
64 | + self.shutter_status = "CLOSE" | |
65 | + | |
66 | + def loop(self): | |
67 | + # à 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 | |
68 | + pass | |
69 | + | |
70 | + cooler_timer = 0 | |
71 | + shutter_timer = 0 | |
72 | + exposure_timer = 0 | |
73 | + | |
74 | + while True: | |
75 | + try: | |
76 | + conn, addr = self.sock.accept() | |
77 | + except socket.error as e: | |
78 | + print("There was a socket error: " + repr(e)) | |
79 | + break | |
80 | + | |
81 | + data = conn.recv(128).decode() | |
82 | + | |
83 | + print("Received: " + data) | |
84 | + | |
85 | + answer = "" | |
86 | + cut_data = data.split(" ") | |
87 | + | |
88 | + if cooler_timer != 0 and time.time() > cooler_timer: | |
89 | + cooler_timer = 0 | |
90 | + status = "IDLE" | |
91 | + print("Stopped cooling") | |
92 | + if shutter_timer != 0 and time.time() > shutter_timer: | |
93 | + shutter_timer = 0 | |
94 | + print("Stopped shutter") | |
95 | + if exposure_timer != 0 and time.time() > exposure_timer: | |
96 | + exposure_timer = 0 | |
97 | + print("Stopped exposure") | |
98 | + # TODO: créer une image | |
99 | + | |
100 | + if len(cut_data) < 2: | |
101 | + print("Invalid message: " + data) | |
102 | + else: | |
103 | + cmd_type = cut_data[0] | |
104 | + cmd = cut_data[1] | |
105 | + args = cut_data[2:] | |
106 | + if cmd_type == "SET": | |
107 | + self.attributes[cmd] = args | |
108 | + elif cmd_type == "GET": | |
109 | + if cmd == "STATUS": | |
110 | + answer = self.status | |
111 | + elif cmd == "TEMPERATURE": | |
112 | + answer = "GET TEMPERATURE answer not implemented" | |
113 | + elif cmd == "SETUP": | |
114 | + answer = "GET SETUP answer not implemented" | |
115 | + elif cmd == "TIMER": | |
116 | + answer = "GET TIMER answer not implemented" | |
117 | + else: | |
118 | + answer = "Invalid cmd for GET: " + cmd | |
119 | + print(answer) | |
120 | + elif cmd_type == "DO": | |
121 | + if cmd == "START": | |
122 | + exposure_timer = time.time() + EXPOSURE_TIME | |
123 | + elif cmd == "STOP": | |
124 | + exposure_timer = 0 | |
125 | + elif cmd == "ABORT": | |
126 | + exposure_timer = 0 | |
127 | + elif cmd == "COOLER": | |
128 | + cooler_timer = time.time() + COOLER_TIME | |
129 | + elif cmd == "SHUTTER": | |
130 | + shutter_timer = time.time() + SHUTTER_TIME | |
131 | + else: | |
132 | + print("Invalid cmd for GET: " + cmd) | |
133 | + else: | |
134 | + print("Invalid message: " + data) | |
135 | + | |
136 | + if len(answer) > 0: | |
137 | + conn.send(bytes(answer, "UTF-8")) | |
138 | + print("send: " + answer) | |
139 | + | |
140 | + conn.close() | |
141 | + | |
142 | +cam = CameraVIS() | |
143 | +cam.loop() | ... | ... |
simulators/Telescope.py
... | ... | @@ -67,7 +67,7 @@ class Telescope(): |
67 | 67 | ''' I will just fill the attributes with their names and params without regarding them ''' |
68 | 68 | self.attributes = {} |
69 | 69 | |
70 | - self.doors_status = True | |
70 | + self.doors_status = "True" | |
71 | 71 | self.status = "IDLE" |
72 | 72 | |
73 | 73 | |
... | ... | @@ -126,19 +126,21 @@ class Telescope(): |
126 | 126 | if cmd == "START": |
127 | 127 | print("Start movement") |
128 | 128 | move_timer = time.time() + MOVE_TIME |
129 | - if cmd == "STOP": | |
129 | + elif cmd == "STOP": | |
130 | 130 | move_timer = 0 |
131 | - if cmd == "ABORT": | |
131 | + elif cmd == "ABORT": | |
132 | 132 | move_timer = 0 |
133 | - if cmd == "HOMING": | |
133 | + elif cmd == "HOMING": | |
134 | 134 | print("Start movement (homing)") |
135 | 135 | move_timer = time.time() + MOVE_TIME |
136 | - if cmd == "DOORS": | |
136 | + elif cmd == "DOORS": | |
137 | 137 | if len(args) > 0: |
138 | 138 | if args[0] != self.doors_status: |
139 | 139 | print("Start door") |
140 | 140 | self.doors_status = args[0] |
141 | 141 | doors_timer = time.time() + DOORS_TIME |
142 | + else: | |
143 | + print("Invalid cmd for DO: " + cmd) | |
142 | 144 | else: |
143 | 145 | print("Invalid message: " + data) |
144 | 146 | ... | ... |