Blame view

simulators/dome/domeSimulator.py 2.12 KB
cfc9d09c   Jeremy   Added dome simula...
1
import os
ce470283   Jeremy   Plc simulator fin...
2
import sys
cfc9d09c   Jeremy   Added dome simula...
3

3224f14a   Jeremy   Fixed some simula...
4
DEBUG_FILE = False
cfc9d09c   Jeremy   Added dome simula...
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
from utils.DeviceSim import DeviceSim
cfc9d09c   Jeremy   Added dome simula...
10
11
from utils.StatusManager import StatusManager

1957226d   Etienne Pallier   Renamed (simulato...
12
class DomeSimulator(DeviceSim, StatusManager):
cfc9d09c   Jeremy   Added dome simula...
13
14
15
16
17
18
19
20
    status = {"status": "VALID"}

    def __init__(self, argv):
        super().__init__(argv)
        self.setDevice("Dome")
        self.setStatusManager("domeSimulator", argv)

    def domePrint(self, string: str):
3224f14a   Jeremy   Fixed some simula...
21
22
        if DEBUG_FILE:
            print("DomeSimulator : " + string)
cfc9d09c   Jeremy   Added dome simula...
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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

    def handleConnections(self):
        for co in self.connections:
            data = self.readBytes(128, co)

            answer = ""
            cut_data = data.split(" ")

            if (len(cut_data) < 2):
                self.domePrint("Received invalid message on socket : " + data)
                continue
            cmd_type = cut_data[0]
            cmd = cut_data[1]
            args = cut_data[2:]
            if (cmd_type == "GET"):
                if (cmd == "STATUS"):
                    answer = self.create_status()
                else:
                    answer = "Invalid cmd for GET: " + cmd
                    self.domePrint(answer)
            else:
                self.domePrint("Ignored message " + data)

            if (len(answer) > 0):
                self.sendMessage(answer, co)
        return (0)

    def loop(self):
        i = 0

        if (self.ended == 0):
            self.domePrint("Not entry for telescope found in config file : " + self.config_file)
            return (0)
        while (True):
            self.updateStatus(i)
            if (self.isConnected()):
                self.handleConnections()
            i += 1
            if (i > self.ended):
                return (0)
        return (1)

    def run(self):
3224f14a   Jeremy   Fixed some simula...
66
67
        if DEBUG_FILE:
            print("Dome simulator running")
cfc9d09c   Jeremy   Added dome simula...
68
69
70
71
72
73
74
75
        self.parse()
        self.configSocket()
        self.loop()
        return (0)

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