CameraNIRRemoteControlDefault.py 2.66 KB
from devices.CameraRemoteControlAbstract import CameraRemoteControlAbstract
from devices import CameraNIR

'''
        Class binding method for real grammar corresponding to the generic command received in the command_matchers   
'''

class CameraNIRRemoteControlDefault(CameraRemoteControlAbstract):
    def __init__(self, command, expert_mode):
        super().__init__(command, expert_mode)
        self._camera = CameraNIR.NIRCameraController()

        self._command_matcher_set = {
            "WINDOW": self.set,
            "READMODE [MODE 1]": self.set,
            "READMODE [MODE 2]": self.set,
            "READMODE [MODE 3]": self.set,
            "FILENAME": self.set,
            "HEADER": self.set,
            "READOUT_FREQUENCY": self.set,
            "FILTER [FILTER 1]": self.set,
            "FILTER [FILTER 2]": self.set,
            "FILTER [FILTER 3]": self.set,
            "NB_IMAGES": self.set,
        }
        self._command_matcher_get = {
            "STATUS": self.get,
            "SETUP": self.get,
            "TIMER": self.get
       }
        self._command_matcher_do = {
            "COOLER ON": self.do,
            "COOLER OFF": self.do,
            "DOME SHUTTER OPEN": self.do,
            "DOME SHUTTER CLOSE": self.do,
            "DOME SHUTTER SYNCHRO": self.do,
            "START": self.do,
            "ABORT": self.do,
            "STOP": self.do
        }




    def exec_command(self):

        #os.system("echo \"status :" + str(self._command) + "\" >> /home/portos/IRAP/pyros/src/commande_recu")
        if self._command[0] == "GET":
            self._current_matcher = self._command_matcher_get
        elif self._command[0] == "SET":
            self._current_matcher = self._command_matcher_set
        elif self._command[0] == "DO":
            self._current_matcher = self._command_matcher_do
        else: return "KO: Unknown command"
        if self._command[1] in self._current_matcher:
            return self._current_matcher[self._command[1]]()
        else:
            return "KO: Unknown command"


    '''
        Locals methods for the generic grammar
    '''

    def do(self):
        definitive_command = "DO " + self._command[1] + ' ' + ' '.join(self._command[2:])
        response = self._camera.send_command(definitive_command)
        return response

    def set(self):
        definitive_command = "SET " + self._command[1] + ' ' + ' '.join(self._command[2:])
        response = self._camera.send_command(definitive_command)
        return response

    def get(self):
        definitive_command = "GET " + self._command[1] #+ ' ' + ' '.join(self._command[2:])
        response = self._camera.send_command(definitive_command)
        return response