Commit cfc9d09cdcceaa015bf5a8d846b7f0b7409cb6bb

Authored by Jeremy
1 parent ef4dd9e1
Exists in master and in 1 other branch dev

Added dome simulator / manager

config/socket_config.ini
... ... @@ -13,3 +13,7 @@ port=5002
13 13 [PLC]
14 14 ip=127.0.0.1
15 15 port=5003
  16 +
  17 +[Dome]
  18 +ip=127.0.0.1
  19 +port=5004
... ...
pyros.py
... ... @@ -468,7 +468,7 @@ class Pyros(AManager):
468 468  
469 469 def simulator(self):
470 470 self.changeDirectory("src")
471   - self.replacePatternInFile("CELERY_TEST = True", "CELERY_TEST = False", "pyros/settings.py")
  471 + self.replacePatternInFile("CELERY_TEST = False", "CELERY_TEST = True", "pyros/settings.py")
472 472 self.execProcess("rm -f testdb.sqlite3")
473 473 self.changeDirectory("..")
474 474 self.migrate()
... ... @@ -504,6 +504,7 @@ class Pyros(AManager):
504 504 return 0
505 505 self.execProcessAsync("fuser -k 8000/tcp")
506 506 self.execProcessAsync("rm -f testdb.sqlite3")
  507 + self.execProcessAsync("ps aux | grep \" domeSimulator.py\" | awk '{ print $2 }' | xargs kill")
507 508 self.execProcessAsync("ps aux | grep \" userSimulator.py\" | awk '{ print $2 }' | xargs kill")
508 509 self.execProcessAsync("ps aux | grep \" alertSimulator.py\" | awk '{ print $2 }' | xargs kill")
509 510 self.execProcessAsync("ps aux | grep \" plcSimulator.py\" | awk '{ print $2 }' | xargs kill")
... ... @@ -524,6 +525,9 @@ class Pyros(AManager):
524 525 self.printColor(Colors.FAIL, "The simulation file " + conf + " does not exist")
525 526 return 1
526 527 self.changeDirectory("..")
  528 + self.changeDirectory("dome")
  529 + self.execProcessFromVenvAsync(self.venv_bin + " domeSimulator.py " + conf)
  530 + self.changeDirectory("..")
527 531 self.changeDirectory("user")
528 532 self.execProcessFromVenvAsync(self.venv_bin + " userSimulator.py " + conf)
529 533 self.changeDirectory("..")
... ...
simulators/dome/__init__.py 0 → 100644
simulators/dome/domeSimulator.py 0 → 100644
... ... @@ -0,0 +1,72 @@
  1 +import sys
  2 +import os
  3 +
  4 +PACKAGE_PARENT = '..'
  5 +SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
  6 +sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
  7 +
  8 +from utils.Device import Device
  9 +from utils.StatusManager import StatusManager
  10 +
  11 +class DomeSimulator(Device, StatusManager):
  12 + status = {"status": "VALID"}
  13 +
  14 + def __init__(self, argv):
  15 + super().__init__(argv)
  16 + self.setDevice("Dome")
  17 + self.setStatusManager("domeSimulator", argv)
  18 +
  19 + def domePrint(self, string: str):
  20 + print("DomeSimulator : " + string)
  21 +
  22 + def handleConnections(self):
  23 + for co in self.connections:
  24 + data = self.readBytes(128, co)
  25 +
  26 + answer = ""
  27 + cut_data = data.split(" ")
  28 +
  29 + if (len(cut_data) < 2):
  30 + self.domePrint("Received invalid message on socket : " + data)
  31 + continue
  32 + cmd_type = cut_data[0]
  33 + cmd = cut_data[1]
  34 + args = cut_data[2:]
  35 + if (cmd_type == "GET"):
  36 + if (cmd == "STATUS"):
  37 + answer = self.create_status()
  38 + else:
  39 + answer = "Invalid cmd for GET: " + cmd
  40 + self.domePrint(answer)
  41 + else:
  42 + self.domePrint("Ignored message " + data)
  43 +
  44 + if (len(answer) > 0):
  45 + self.sendMessage(answer, co)
  46 + return (0)
  47 +
  48 + def loop(self):
  49 + i = 0
  50 +
  51 + if (self.ended == 0):
  52 + self.domePrint("Not entry for telescope found in config file : " + self.config_file)
  53 + return (0)
  54 + while (True):
  55 + self.updateStatus(i)
  56 + if (self.isConnected()):
  57 + self.handleConnections()
  58 + i += 1
  59 + if (i > self.ended):
  60 + return (0)
  61 + return (1)
  62 +
  63 + def run(self):
  64 + print("Dome simulator running")
  65 + self.parse()
  66 + self.configSocket()
  67 + self.loop()
  68 + return (0)
  69 +
  70 +if __name__ == "__main__":
  71 + sim = DomeSimulator(sys.argv)
  72 + sim.run()
... ...
src/common/models.py
... ... @@ -505,6 +505,12 @@ class TaskId(models.Model):
505 505 def __str__(self):
506 506 return (str(self.task) + " - " + str(self.task_id))
507 507  
  508 +# TODO class dome define content
  509 +# class Dome(Device):
  510 +# DOME = "Dome"
  511 +
  512 +
  513 +
508 514  
509 515 class Telescope(Device):
510 516 TELESCOPE = "Telescope"
... ...
src/devices/Dome.py 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +from common.models import *
  2 +import abc
  3 +from .Device import DeviceController
  4 +
  5 +'''
  6 + Device controller for Telescope.
  7 + This class must implement set, get and do functions (DeviceController is an abstract)
  8 +'''
  9 +class DomeController(DeviceController):
  10 +
  11 + def __init__(self):
  12 + super().__init__("Telescope")
  13 +
  14 + def get(self, command: str, *args):
  15 + message = "GET " + command + " " + " ".join([str(arg) for arg in args])
  16 + self.sendMessage(message)
  17 + return (self.blockAndReadMessage())
  18 +
  19 + def set(self, command: str, *args):
  20 + message = "SET " + command + " " + " ".join([str(arg) for arg in args])
  21 + return (self.sendMessage(message))
  22 +
  23 + def do(self, command: str, *args):
  24 + message = "DO " + command + " " + " ".join([str(arg) for arg in args])
  25 + return (self.sendMessage(message))
... ...
src/majordome/tasks.py
... ... @@ -10,10 +10,12 @@ from common.models import *
10 10 from devices.Telescope import TelescopeController
11 11 from devices.CameraVIS import VISCameraController
12 12 from devices.CameraNIR import NIRCameraController
  13 +from devices.Dome import DomeController
13 14 from devices.PLC import PLCController
14 15 from django.conf import settings
15 16 from utils.JDManipulator import *
16 17 import utils.config as L
  18 +
17 19 log = L.setupLogger("MajordomeTaskLogger", "Majordome")
18 20  
19 21 '''
... ... @@ -32,6 +34,7 @@ class Majordome(Task):
32 34 status_tel = ""
33 35 status_nir = ""
34 36 status_vis = ""
  37 + status_dom = ""
35 38 timers = {}
36 39 functions = {}
37 40 schedule = None
... ... @@ -51,6 +54,7 @@ class Majordome(Task):
51 54 self.vis_camera = VISCameraController()
52 55 self.nir_camera = NIRCameraController()
53 56 self.plc = PLCController()
  57 + self.dom = DomeController()
54 58 return (0)
55 59  
56 60 '''
... ... @@ -85,15 +89,12 @@ class Majordome(Task):
85 89 Loop to wait for the device to be idle avec the starting configurations.
86 90 '''
87 91 def waitDevices(self):
88   - nir_st = ""
89   - vis_st = ""
90   - tel_st = ""
91   -
92   - while nir_st != "IDLE" or vis_st != "IDLE" and tel_st != "IDLE":
93   - nir_st = self.nir_camera.get("STATUS")
94   - vis_st = self.vis_camera.get("STATUS")
95   - tel_st = self.tel.get("STATUS")
96   -
  92 + # TODO Maybe remove comment if we need to wait the devices connection / valid status
  93 + # while self.status_vis == "" and self.status_tel == "" and self.status_nir == "" and self.status_dom == "":
  94 + self.status_vis = self.vis_camera.get("STATUS")
  95 + self.status_nir = self.nir_camera.get("STATUS")
  96 + self.status_tel = self.tel.get("STATUS")
  97 + self.status_dom = self.dom.get("STATUS")
97 98 print("Devices ready !")
98 99 return (0)
99 100  
... ... @@ -180,6 +181,7 @@ class Majordome(Task):
180 181 self.status_tel = self.tel.get("STATUS")
181 182 self.status_nir = self.nir_camera.get("STATUS")
182 183 self.status_vis = self.vis_camera.get("STATUS")
  184 + self.status_dom = self.dom.get("STATUS")
183 185 self.handleStatus()
184 186 return (0)
185 187  
... ... @@ -366,6 +368,10 @@ class Majordome(Task):
366 368 telescope = Telescope.objects.first()
367 369 camera_nir = Detector.objects.get(name="Cagire")
368 370 camera_vis = Detector.objects.get(name="Visible camera")
  371 + # TODO Dome in database
  372 + # dome = ???.objects.get(name="Dome")
  373 + # dome.status = self.status_dom
  374 + # dome.save()
369 375 # TODO adapt the status (must be short)
370 376 telescope.status = self.status_tel
371 377 camera_nir.status = self.status_nir
... ...
src/pyros/settings.py.bak
... ... @@ -119,7 +119,7 @@ LOGIN_URL = &quot;/&quot;
119 119  
120 120 # EP modif
121 121  
122   -CELERY_TEST = False
  122 +CELERY_TEST = True
123 123  
124 124 if not CELERY_TEST:
125 125 if not MYSQL:
... ...