Commit 5f7e49553cb243b9f93dd487f3656f52fc1e43f2
1 parent
d51386bf
Exists in
dev
Add some commands to the device simulators
Showing
7 changed files
with
201 additions
and
54 deletions
Show diff stats
simulators/camera/cameraNIRSimulator.py
... | ... | @@ -12,10 +12,17 @@ from utils.StatusManager import StatusManager |
12 | 12 | |
13 | 13 | #(EP) class CameraNIRSimulator(Device, StatusManager): |
14 | 14 | class CameraNIRSimulator(DeviceSim, StatusManager): |
15 | - status = {"status" : "VALID"} | |
16 | 15 | exposure_time = 5 |
17 | 16 | shutter_time = 3 |
18 | 17 | cooler_timer = 5 |
18 | + _window_x1 = 0 | |
19 | + _window_x2 = 0 | |
20 | + _window_y1 = 0 | |
21 | + _window_y2 = 0 | |
22 | + _cooler = "OFF" | |
23 | + status = {"status": "VALID", "exposure_time" : exposure_time, "shutter_time": shutter_time, | |
24 | + "cooler_timer" : cooler_timer, "cooler" : _cooler, "win x1" : _window_x1, "win x2" : _window_x2, "win y1" : _window_y1, "win_y2" : _window_y2} | |
25 | + | |
19 | 26 | |
20 | 27 | def __init__(self, argv): |
21 | 28 | super().__init__(argv) |
... | ... | @@ -26,6 +33,50 @@ class CameraNIRSimulator(DeviceSim, StatusManager): |
26 | 33 | if DEBUG_FILE: |
27 | 34 | print("cameraNIRSimulator : " + string) |
28 | 35 | |
36 | + def deal_command(self, cmd_type, cmd, args): | |
37 | + answer = "" | |
38 | + | |
39 | + if cmd_type == "GET": | |
40 | + if cmd == "STATUS": | |
41 | + answer = str({"status": "VALID", "exposure_time" : self.exposure_time, "shutter_time": self.shutter_time, | |
42 | + "cooler_timer" : self.cooler_timer, "cooler" : self._cooler, | |
43 | + "win x1" : self._window_x1, "win x2" : self._window_x2, | |
44 | + "win y1" : self._window_y1, "win_y2" : self._window_y2}) | |
45 | + elif cmd == "TIMER": | |
46 | + answer = "cooler timer : " + str(self.cooler_timer) | |
47 | + else: | |
48 | + answer = "NOT IMPLEMENTED YET" | |
49 | + | |
50 | + elif cmd_type == "SET": | |
51 | + if cmd == "WINDOW": | |
52 | + os.system("echo " + str(args) + " >> /home/portos/IRAP/PYROS/argss") | |
53 | + self._window_x1 = int(args[0]) | |
54 | + self._window_x2 = int(args[1]) | |
55 | + self._window_y1 = int(args[2]) | |
56 | + self._window_y2 = int(args[3]) | |
57 | + answer = "Window coordinates are set to " + str(args) | |
58 | + | |
59 | + else: | |
60 | + answer = "NOT IMPLEMENTED YET" | |
61 | + | |
62 | + elif cmd_type == "DO": | |
63 | + if cmd == "COOLER": | |
64 | + if args[0] == "ON": | |
65 | + self._cooler = "ON tmp: " + str(args[1]) | |
66 | + answer = "COOLER TURNED ON tmp: " + str(args[1]) | |
67 | + | |
68 | + elif args[0] == "OFF": | |
69 | + self._cooler = "OFF" | |
70 | + answer = "COOLER TURNED OFF" | |
71 | + | |
72 | + else: | |
73 | + answer = "NOT IMPLEMENTED YET" | |
74 | + | |
75 | + else: | |
76 | + answer = "Invalid or not implemented cmd" | |
77 | + | |
78 | + return answer | |
79 | + | |
29 | 80 | def handleConnection(self): |
30 | 81 | for co in self.connections: |
31 | 82 | data = self.readBytes(128, co) |
... | ... | @@ -39,6 +90,11 @@ class CameraNIRSimulator(DeviceSim, StatusManager): |
39 | 90 | cmd_type = cut_data[0] |
40 | 91 | cmd = cut_data[1] |
41 | 92 | args = cut_data[2:] |
93 | + | |
94 | + answer = self.deal_command(cmd_type, cmd, args) | |
95 | + | |
96 | + | |
97 | + ''' | |
42 | 98 | if (cmd_type == "GET"): |
43 | 99 | if (cmd == "STATUS"): |
44 | 100 | answer = self.create_status() |
... | ... | @@ -61,6 +117,9 @@ class CameraNIRSimulator(DeviceSim, StatusManager): |
61 | 117 | answer = "CAPTURING" |
62 | 118 | else: |
63 | 119 | self.cameraNIRPrint("Ignored message " + data) |
120 | + ''' | |
121 | + | |
122 | + | |
64 | 123 | |
65 | 124 | if (len(answer) > 0): |
66 | 125 | self.sendMessage(answer, co) | ... | ... |
simulators/camera/cameraVISSimulator.py
... | ... | @@ -13,10 +13,18 @@ from utils.StatusManager import StatusManager |
13 | 13 | |
14 | 14 | #(EP) class CameraVISSimulator(Device, StatusManager): |
15 | 15 | class CameraVISSimulator(DeviceSim, StatusManager): |
16 | - status = {"status" : "VALID"} | |
17 | 16 | exposure_time = 5 |
18 | 17 | shutter_time = 3 |
19 | 18 | cooler_timer = 5 |
19 | + _window_x1 = 0 | |
20 | + _window_x2 = 0 | |
21 | + _window_y1 = 0 | |
22 | + _window_y2 = 0 | |
23 | + _cooler = "OFF" | |
24 | + status = {"status": "VALID", "exposure_time": exposure_time, "shutter_time": shutter_time, | |
25 | + "cooler_timer": cooler_timer, "cooler": _cooler, "win x1": _window_x1, "win x2": _window_x2, | |
26 | + "win y1": _window_y1, "win_y2": _window_y2} | |
27 | + | |
20 | 28 | |
21 | 29 | def __init__(self, argv): |
22 | 30 | super().__init__(argv) |
... | ... | @@ -27,12 +35,58 @@ class CameraVISSimulator(DeviceSim, StatusManager): |
27 | 35 | if DEBUG_FILE: |
28 | 36 | print("cameraVISSimulator : " + string) |
29 | 37 | |
38 | + | |
39 | + | |
40 | + def deal_command(self, cmd_type, cmd, args): | |
41 | + answer = "" | |
42 | + | |
43 | + if cmd_type == "GET": | |
44 | + if cmd == "STATUS": | |
45 | + answer = str({"status": "VALID", "exposure_time" : self.exposure_time, "shutter_time": self.shutter_time, | |
46 | + "cooler_timer" : self.cooler_timer, "cooler" : self._cooler, | |
47 | + "win x1" : self._window_x1, "win x2" : self._window_x2, | |
48 | + "win y1" : self._window_y1, "win_y2" : self._window_y2}) | |
49 | + elif cmd == "TIMER": | |
50 | + answer = "cooler timer : " + str(self.cooler_timer) | |
51 | + else: | |
52 | + answer = "NOT IMPLEMENTED YET" | |
53 | + | |
54 | + elif cmd_type == "SET": | |
55 | + if cmd == "WINDOW": | |
56 | + os.system("echo " + str(args) + " >> /home/portos/IRAP/PYROS/argss") | |
57 | + self._window_x1 = int(args[0]) | |
58 | + self._window_x2 = int(args[1]) | |
59 | + self._window_y1 = int(args[2]) | |
60 | + self._window_y2 = int(args[3]) | |
61 | + answer = "Window coordinates are set to " + str(args) | |
62 | + | |
63 | + else: | |
64 | + answer = "NOT IMPLEMENTED YET" | |
65 | + | |
66 | + elif cmd_type == "DO": | |
67 | + if cmd == "COOLER": | |
68 | + if args[0] == "ON": | |
69 | + self._cooler = "ON tmp: " + str(args[1]) | |
70 | + answer = "COOLER TURNED ON tmp: " + str(args[1]) | |
71 | + | |
72 | + elif args[0] == "OFF": | |
73 | + self._cooler = "OFF" | |
74 | + answer = "COOLER TURNED OFF" | |
75 | + | |
76 | + else: | |
77 | + answer = "NOT IMPLEMENTED YET" | |
78 | + | |
79 | + else: | |
80 | + answer = "Invalid or not implemented cmd" | |
81 | + | |
82 | + return answer | |
83 | + | |
30 | 84 | def handleConnection(self): |
31 | 85 | for co in self.connections: |
32 | 86 | data = self.readBytes(128, co) |
33 | 87 | |
34 | 88 | answer = "" |
35 | - cut_data = data.split(" ") | |
89 | + cut_data = data.split() | |
36 | 90 | |
37 | 91 | if (len(cut_data) < 2): |
38 | 92 | self.cameraVISPrint("Received invalid message on socket : " + data) |
... | ... | @@ -40,28 +94,7 @@ class CameraVISSimulator(DeviceSim, StatusManager): |
40 | 94 | cmd_type = cut_data[0] |
41 | 95 | cmd = cut_data[1] |
42 | 96 | args = cut_data[2:] |
43 | - if (cmd_type == "GET"): | |
44 | - if (cmd == "STATUS"): | |
45 | - answer = self.create_status() | |
46 | - else: | |
47 | - answer = "Invalid cmd for GET: " + cmd | |
48 | - self.cameraVISPrint(answer) | |
49 | - elif (cmd_type == "DO"): | |
50 | - if (cmd == "CAPTURE"): | |
51 | - folder_name = args[0] | |
52 | - nb_images = int(args[1]) | |
53 | - duration = args[2] | |
54 | - i = 0 | |
55 | - while i < nb_images: | |
56 | - try: | |
57 | - with open(folder_name + os.sep + "vis_image_" + str(i), "w") as f: | |
58 | - f.write(folder_name + " " + str(nb_images) + " " + str(duration)) | |
59 | - except Exception as e: | |
60 | - self.cameraVISPrint(str(e)) | |
61 | - i += 1 | |
62 | - answer = "CAPTURING" | |
63 | - else: | |
64 | - self.cameraVISPrint("Ignored message " + data) | |
97 | + answer = self.deal_command(cmd_type, cmd, args) | |
65 | 98 | |
66 | 99 | if (len(answer) > 0): |
67 | 100 | self.sendMessage(answer, co) | ... | ... |
simulators/telescope/telescopeSimulator.py
1 | 1 | import os |
2 | 2 | import sys |
3 | +import time | |
3 | 4 | |
4 | 5 | DEBUG_FILE = False |
5 | 6 | PACKAGE_PARENT = '..' |
... | ... | @@ -11,10 +12,13 @@ from utils.StatusManager import StatusManager |
11 | 12 | |
12 | 13 | |
13 | 14 | class TelescopeSimulator(DeviceSim, StatusManager): |
14 | - status = {"status": "VALID"} | |
15 | + _coords = "0, 0, 0" | |
16 | + _real_coords = "0, 0 ,0" | |
15 | 17 | doors_timer = 5 |
16 | 18 | move_time = 5 |
17 | - _loop_mode = False | |
19 | + _loop_mode = False | |
20 | + status = {"status": "VALID", "coords": _coords, "real_coords" : _real_coords, "doors_timer": doors_timer, "move_time" : move_time, "loop_mode": _loop_mode} | |
21 | + | |
18 | 22 | |
19 | 23 | def __init__(self, argv): |
20 | 24 | super().__init__(argv) |
... | ... | @@ -28,12 +32,54 @@ class TelescopeSimulator(DeviceSim, StatusManager): |
28 | 32 | if DEBUG_FILE: |
29 | 33 | print("telescopeSimulator : " + string) |
30 | 34 | |
35 | + | |
36 | + def deal_command(self, cmd_type, cmd, args): | |
37 | + answer = "" | |
38 | + if cmd_type == "GET": | |
39 | + if cmd == "INFORMATIONS": | |
40 | + status = {"status": "VALID", "coords": self._coords, "real_coords": self._real_coords, "doors_timer": self.doors_timer, | |
41 | + "move_time": self.move_time, "loop_mode": self._loop_mode} | |
42 | + answer = str(status) | |
43 | + elif cmd.startswith("COORD"): | |
44 | + answer = cmd +" " + str(self._coords) | |
45 | + else: | |
46 | + answer = "NOT IMPLEMENTED YET" | |
47 | + | |
48 | + elif cmd_type == "SET": | |
49 | + if cmd.startswith("COORD"): | |
50 | + self._coords = str(args) | |
51 | + answer = "COORDS set to " + self._coords | |
52 | + else: | |
53 | + answer = "NOT IMPLEMENTED YET" | |
54 | + | |
55 | + | |
56 | + elif cmd_type == "DO": | |
57 | + if cmd == "GOTO": | |
58 | + self._real_coords = self._coords | |
59 | + answer = "Starting slew of the mount" | |
60 | + | |
61 | + elif cmd == "HOMING": | |
62 | + self._coords = "0, 0, 0" | |
63 | + self._real_coords = "0, 0, 0" | |
64 | + answer = "Start the Homong of the mount" | |
65 | + | |
66 | + else: | |
67 | + answer = "NOT IMPLEMENTED YET" | |
68 | + | |
69 | + | |
70 | + | |
71 | + | |
72 | + else: | |
73 | + answer ="Invalid or not implemented cmd" | |
74 | + return answer | |
75 | + | |
76 | + | |
31 | 77 | def handleConnection(self): |
32 | 78 | for co in self.connections: |
33 | 79 | data = self.readBytes(128, co) |
34 | 80 | |
35 | - answer = "" | |
36 | - cut_data = data.split(" ") | |
81 | + #answer = "" | |
82 | + cut_data = data.split() | |
37 | 83 | |
38 | 84 | if (len(cut_data) < 2): |
39 | 85 | self.telescopePrint("Received invalid message on socket : " + data) |
... | ... | @@ -41,25 +87,18 @@ class TelescopeSimulator(DeviceSim, StatusManager): |
41 | 87 | cmd_type = cut_data[0] |
42 | 88 | cmd = cut_data[1] |
43 | 89 | args = cut_data[2:] |
44 | - if cmd_type == "GET": | |
45 | - if cmd == "STATUS": | |
46 | - answer = self.create_status() | |
47 | - else: | |
48 | - answer = "Invalid or not implemented cmd for GET: " + cmd | |
49 | - self.telescopePrint(answer) | |
50 | - elif cmd_type == "DO": | |
51 | - if cmd == "GOTO": | |
52 | - answer = "NEW POSITION SET TO " + ' '.join(args) | |
53 | - else: | |
54 | - answer = "Invalid or not implemented cmd for DO: " + cmd | |
55 | - elif cmd_type == "SET": | |
56 | - answer = "Invalid or not implemented cmd for SET: " + cmd | |
57 | - else: | |
58 | - answer = "Unknown command received : " + data | |
59 | - self.telescopePrint("Ignored message " + data) | |
90 | + | |
91 | + answer = self.deal_command(cmd_type, cmd, args) | |
92 | + | |
93 | + ''' | |
94 | + sleep pour simuler temps de latence de mouvement : probleme sans multi-thread le simulateur est inactif pendant ce temps | |
95 | + ''' | |
60 | 96 | |
61 | 97 | if (len(answer) > 0): |
62 | 98 | self.sendMessage(answer, co) |
99 | + | |
100 | + | |
101 | + | |
63 | 102 | return (0) |
64 | 103 | |
65 | 104 | def loop(self): | ... | ... |
src/dashboard/views.py
... | ... | @@ -334,12 +334,16 @@ def submit_command_to_cameraVIS_1(request): |
334 | 334 | input_0 = request.POST.get("input_number_0") |
335 | 335 | input_1 = request.POST.get("input_number_1") |
336 | 336 | input_2 = request.POST.get("input_number_2") |
337 | + input_3 = request.POST.get("input_number_3") | |
338 | + | |
337 | 339 | if input_0: |
338 | 340 | commands.append(input_0) |
339 | 341 | if input_1: |
340 | 342 | commands.append(input_1) |
341 | 343 | if input_2: |
342 | 344 | commands.append(input_2) |
345 | + if input_3: | |
346 | + commands.append(input_3) | |
343 | 347 | except Exception: |
344 | 348 | pass |
345 | 349 | response = CameraVISRemoteControlDefault(commands, expert_mode=False, chosen_camera="ddrago_r").exec_command() |
... | ... | @@ -381,12 +385,16 @@ def submit_command_to_cameraNIR(request): |
381 | 385 | input_0 = request.POST.get("input_number_0") |
382 | 386 | input_1 = request.POST.get("input_number_1") |
383 | 387 | input_2 = request.POST.get("input_number_2") |
388 | + input_3 = request.POST.get("input_number_3") | |
389 | + | |
384 | 390 | if input_0: |
385 | 391 | commands.append(input_0) |
386 | 392 | if input_1: |
387 | 393 | commands.append(input_1) |
388 | 394 | if input_2: |
389 | 395 | commands.append(input_2) |
396 | + if input_3: | |
397 | + commands.append(input_3) | |
390 | 398 | except Exception: |
391 | 399 | pass |
392 | 400 | response = CameraNIRRemoteControlDefault(commands, expert_mode=False).exec_command() |
... | ... | @@ -431,12 +439,16 @@ def submit_command_to_cameraVIS_2(request): |
431 | 439 | input_0 = request.POST.get("input_number_0") |
432 | 440 | input_1 = request.POST.get("input_number_1") |
433 | 441 | input_2 = request.POST.get("input_number_2") |
442 | + input_3 = request.POST.get("input_number_3") | |
443 | + | |
434 | 444 | if input_0: |
435 | 445 | commands.append(input_0) |
436 | 446 | if input_1: |
437 | 447 | commands.append(input_1) |
438 | 448 | if input_2: |
439 | 449 | commands.append(input_2) |
450 | + if input_3: | |
451 | + commands.append(input_3) | |
440 | 452 | except Exception: |
441 | 453 | pass |
442 | 454 | response = CameraVISRemoteControlDefault(commands, expert_mode=False, chosen_camera="ddrago_b").exec_command() |
... | ... | @@ -473,16 +485,20 @@ def send_command_to_telescope(request): |
473 | 485 | def submit_command_to_telescope(request): |
474 | 486 | if request.method == 'POST': |
475 | 487 | commands = [request.POST.get("first_command"), request.POST.get("first_param")] |
476 | - try: #TODO faire un truc plus joli pour gรฉrer les params queqlue soit leur nombre | |
488 | + try: #TODO faire un truc plus joli pour gรฉrer les params quelque soit leur nombre la c'est du rapide super moche et max 4 input | |
477 | 489 | input_0 = request.POST.get("input_number_0") |
478 | 490 | input_1 = request.POST.get("input_number_1") |
479 | 491 | input_2 = request.POST.get("input_number_2") |
492 | + input_3 = request.POST.get("input_number_3") | |
493 | + | |
480 | 494 | if input_0: |
481 | 495 | commands.append(input_0) |
482 | 496 | if input_1: |
483 | 497 | commands.append(input_1) |
484 | 498 | if input_2: |
485 | 499 | commands.append(input_2) |
500 | + if input_3: | |
501 | + commands.append(input_3) | |
486 | 502 | except Exception: |
487 | 503 | pass |
488 | 504 | response = TelescopeRemoteControlDefault(commands, False).exec_command() | ... | ... |
src/devices/Device.py
... | ... | @@ -102,9 +102,9 @@ class DeviceController(): |
102 | 102 | return ("NOT_SET2") |
103 | 103 | try: |
104 | 104 | readable, writable, exceptional = select.select([self.sock], [], [self.sock], 0) |
105 | - if not (readable or exceptional): | |
105 | + #if not (readable or exceptional): | |
106 | 106 | #ret = self.sock.recv(size).decode() |
107 | - raise (Exception("KO: socket error or not implemented command")) | |
107 | + #raise (Exception("KO: socket error or not implemented command")) | |
108 | 108 | |
109 | 109 | ret = self.sock.recv(size).decode() |
110 | 110 | if (not ret): | ... | ... |
src/misc/templates/base.html
... | ... | @@ -148,7 +148,7 @@ a { |
148 | 148 | <ul class="nav navbar-nav navbar-right navbar-user navbar-expand-lg"> |
149 | 149 | <li><a id="plc_state"></a></li> |
150 | 150 | <li><a class="nav-brand" id="hour">Sun elevation :</a></li> |
151 | - <li><a class="nav-brand" id="day_night" href="{% url "weather" %}"><img id="day_night_img"></a></li> | |
151 | + <li><a class="nav-brand" id="day_night" ><img id="day_night_img"></a></li> | |
152 | 152 | <li><a class="nav-brand" id="wind" href="{% url "weather" %}"><img id="wind_img"></a></li> |
153 | 153 | <li><a class="nav-brand" id="weather" href="{% url "weather" %}"><img id="weather_img"></a></li> |
154 | 154 | <li><a class="nav-brand" id="globalmode" style="color: black;"> <p id="text_globalmode" >{% global_mode request %} </p></a> |
... | ... | @@ -232,8 +232,8 @@ a { |
232 | 232 | _img_day_night.src ="{% static 'media/rising_sun.png' %}"; |
233 | 233 | else |
234 | 234 | _img_day_night.src ="{% static 'media/moon.png' %}"; |
235 | - _img_day_night.width = 18; | |
236 | - _img_day_night.height = 18; | |
235 | + _img_day_night.width = 22; | |
236 | + _img_day_night.height = 22; | |
237 | 237 | _img_day_night.id ="day_night_img"; |
238 | 238 | _img_day_night.alt="html5"; |
239 | 239 | $("#day_night_img").replaceWith(_img_day_night); | ... | ... |
src/misc/templates/base_unlogged.html
... | ... | @@ -107,7 +107,7 @@ a { |
107 | 107 | </ul> |
108 | 108 | <ul class="nav navbar-nav navbar-right navbar-user"> |
109 | 109 | <li><a class="nav-brand" id="hour"></a></li> |
110 | - <li><a class="nav-brand" id="day_night" href="{% url "weather" %}"><img id="day_night_img"></a></li> | |
110 | + <li><a class="nav-brand" id="day_night" ><img id="day_night_img"></a></li> | |
111 | 111 | <li><a class="nav-brand" id="wind" href="{% url "weather" %}"><img id="wind_img"></a></li> |
112 | 112 | <li><a class="nav-brand" id="weather" href="{% url "weather" %}"><img id="weather_img"></a></li> |
113 | 113 | <li> |
... | ... | @@ -149,8 +149,8 @@ a { |
149 | 149 | _img_day_night.src ="{% static 'media/rising_sun.png' %}"; |
150 | 150 | else |
151 | 151 | _img_day_night.src ="{% static 'media/moon.png' %}"; |
152 | - _img_day_night.width = 18; | |
153 | - _img_day_night.height = 18; | |
152 | + _img_day_night.width = 22; | |
153 | + _img_day_night.height = 22; | |
154 | 154 | _img_day_night.id ="day_night_img"; |
155 | 155 | _img_day_night.alt="html5"; |
156 | 156 | $("#day_night_img").replaceWith(_img_day_night); | ... | ... |