Blame view

simulators/camera/cameraVISSimulator.py 4.18 KB
605b65e5   Jeremy   Update simulators
1
2
3
import os
import sys

3224f14a   Jeremy   Fixed some simula...
4
DEBUG_FILE = False
605b65e5   Jeremy   Update simulators
5
6
7
8
PACKAGE_PARENT = '..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))

1957226d   Etienne Pallier   Renamed (simulato...
9
10
#(EP renamed) from utils.Device import Device
from utils.DeviceSim import DeviceSim
605b65e5   Jeremy   Update simulators
11
12
from utils.StatusManager import StatusManager

76dfa189   Unknown   Adding devices lo...
13

1957226d   Etienne Pallier   Renamed (simulato...
14
15
#(EP) class CameraVISSimulator(Device, StatusManager):
class CameraVISSimulator(DeviceSim, StatusManager):
605b65e5   Jeremy   Update simulators
16
17
18
    exposure_time = 5
    shutter_time = 3
    cooler_timer = 5
5f7e4955   Quentin Durand   Add some commands...
19
20
21
22
23
24
25
26
27
    _window_x1 = 0
    _window_x2 = 0
    _window_y1 = 0
    _window_y2 = 0
    _cooler = "OFF"
    status = {"status": "VALID", "exposure_time": exposure_time, "shutter_time": shutter_time,
              "cooler_timer": cooler_timer, "cooler": _cooler, "win x1": _window_x1, "win x2": _window_x2,
              "win y1": _window_y1, "win_y2": _window_y2}

605b65e5   Jeremy   Update simulators
28
29
30
31
32

    def __init__(self, argv):
        super().__init__(argv)
        self.setDevice("CameraVIS")
        self.setStatusManager("cameraVISSimulator", argv)
76dfa189   Unknown   Adding devices lo...
33
        self.cameraVISPrint("COUCOU CECI EST UN TEST")
605b65e5   Jeremy   Update simulators
34
    def cameraVISPrint(self, string: str):
3224f14a   Jeremy   Fixed some simula...
35
36
        if DEBUG_FILE:
            print("cameraVISSimulator : " + string)
605b65e5   Jeremy   Update simulators
37

5f7e4955   Quentin Durand   Add some commands...
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83


    def deal_command(self, cmd_type, cmd, args):
        answer = ""

        if cmd_type == "GET":
            if cmd == "STATUS":
                answer = str({"status": "VALID", "exposure_time" : self.exposure_time, "shutter_time": self.shutter_time,
              "cooler_timer" : self.cooler_timer, "cooler" : self._cooler,
              "win x1" : self._window_x1, "win x2" : self._window_x2,
              "win y1" : self._window_y1, "win_y2" : self._window_y2})
            elif cmd == "TIMER":
                answer = "cooler timer : " + str(self.cooler_timer)
            else:
                answer = "NOT IMPLEMENTED YET"

        elif cmd_type == "SET":
            if cmd == "WINDOW":
                os.system("echo " + str(args) + " >> /home/portos/IRAP/PYROS/argss")
                self._window_x1 = int(args[0])
                self._window_x2 = int(args[1])
                self._window_y1 = int(args[2])
                self._window_y2 = int(args[3])
                answer = "Window coordinates are set to " + str(args)

            else:
                answer = "NOT IMPLEMENTED YET"

        elif cmd_type == "DO":
            if cmd == "COOLER":
                if args[0] == "ON":
                    self._cooler = "ON tmp: " + str(args[1])
                    answer = "COOLER TURNED ON tmp: " + str(args[1])

                elif args[0] == "OFF":
                    self._cooler = "OFF"
                    answer = "COOLER TURNED OFF"

            else:
                answer = "NOT IMPLEMENTED YET"

        else:
            answer = "Invalid or not implemented cmd"

        return answer

605b65e5   Jeremy   Update simulators
84
    def handleConnection(self):
f7dd3df1   Jeremy   Update simulators...
85
86
        for co in self.connections:
            data = self.readBytes(128, co)
605b65e5   Jeremy   Update simulators
87

f7dd3df1   Jeremy   Update simulators...
88
            answer = ""
5f7e4955   Quentin Durand   Add some commands...
89
            cut_data = data.split()
605b65e5   Jeremy   Update simulators
90

f7dd3df1   Jeremy   Update simulators...
91
92
93
94
95
96
            if (len(cut_data) < 2):
                self.cameraVISPrint("Received invalid message on socket : " + data)
                continue
            cmd_type = cut_data[0]
            cmd = cut_data[1]
            args = cut_data[2:]
5f7e4955   Quentin Durand   Add some commands...
97
            answer = self.deal_command(cmd_type, cmd, args)
605b65e5   Jeremy   Update simulators
98

f7dd3df1   Jeremy   Update simulators...
99
100
            if (len(answer) > 0):
                self.sendMessage(answer, co)
605b65e5   Jeremy   Update simulators
101
102
103
104
105
106
        return (0)

    def loop(self):
        i = 0

        if (self.ended == 0):
3224f14a   Jeremy   Fixed some simula...
107
            self.cameraVISPrint("No entry for cameraVIS found in config file : " + self.config_file)
605b65e5   Jeremy   Update simulators
108
109
110
111
112
            return (0)
        while (True):
            self.updateStatus(i)
            if (self.isConnected()):
                self.handleConnection()
605b65e5   Jeremy   Update simulators
113
114
115
116
117
118
            i += 1
            if (i > self.ended):
                return (0)
        return (1)

    def run(self):
3224f14a   Jeremy   Fixed some simula...
119
120
        if DEBUG_FILE:
            print("cameraVIS simulator running")
605b65e5   Jeremy   Update simulators
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
        self.parse()
        self.configSocket()
        self.loop()
        return (0)

if (__name__ == "__main__"):
    sim = CameraVISSimulator(sys.argv)
    sim.run()


# from Camera import Camera
# 
# class CameraVIS(Camera):
#     def __init__(self):
#         super().__init__("CameraVIS")
# 
# cam = CameraVIS()
# cam.loop()