from common.models import TelescopeCommand from devices import Telescope #from time import sleep import time import os import sys ''' THIS IS A PROTOTYPE ! Its does not use the RemoteControlClass which convert the command to specific grammar, it need to be implemented Agent which turn in an infinite loop and watch the database looking for requests to execute, it will be also used for retrieving the status of the device ''' class TelescopeMonitoring(): _telescope_controller = Telescope.TelescopeController() def __init__(self): self.loop() ''' Method looking for commands to execute in the database, if there are some, return them ''' def get_requests(self): try: requests = TelescopeCommand.objects.filter(answer=None) except TelescopeCommand.DoesNotExist: requests = None return requests ''' Method that executes the requests found in db by get_requests, then place the corresponding answer in the db for the request Pour utiliser la traduction de grammaires, instancier ici un TelescopeRemoteControlXXXX et executer sa méthode exec_command ''' def execute_request(self, request): #remplacer cette ligne par l'utilisation de TelescopeRemoteControl answer = self._telescope_controller.send_command(request.request) request.answer = answer request.save() ''' Main loop, added sleep to save the use of the CPU ''' def loop(self): while True: requests = self.get_requests() if requests: for request in requests: self.execute_request(request) #TODO: rajouter ici la gestion des status et le stockage en db time.sleep(0.03)