Commit 0997e1c3723ed37e56278663bc3d08f0c3ad682f
1 parent
468a79dc
Exists in
dev
moved main run() loop at the beginning of the code for clarity
Showing
1 changed file
with
76 additions
and
79 deletions
Show diff stats
src/majordome/tasks.py
... | ... | @@ -36,6 +36,7 @@ log = L.setupLogger("MajordomeTaskLogger", "Majordome") |
36 | 36 | launch schedule's sequences |
37 | 37 | ''' |
38 | 38 | class Majordome(Task): |
39 | + | |
39 | 40 | loop_speed = 1 |
40 | 41 | julian_div = 86400 |
41 | 42 | executing_sequence = None |
... | ... | @@ -57,9 +58,81 @@ class Majordome(Task): |
57 | 58 | plc_status = None |
58 | 59 | current_state = "Passive" |
59 | 60 | current_status = "RUNNING" |
61 | + pyros_behaviour = { | |
62 | + "Passive": passiveBehaviour, | |
63 | + "Standby": standbyBehaviour, | |
64 | + "Remote": remoteBehaviour, | |
65 | + "Startup": startupBehaviour, | |
66 | + "Scheduler": schedulerBehaviour, | |
67 | + "Closing": closingBehaviour, | |
68 | + } | |
60 | 69 | |
61 | 70 | |
62 | 71 | ''' |
72 | + OLD //// Function called by celery task | |
73 | + Behavior: | |
74 | + Init telescope / cameras | |
75 | + set night limits | |
76 | + check the software version | |
77 | + launch the majordome loop ///// OLD | |
78 | + | |
79 | + Main loop of Majordome | |
80 | + startup everything if needed | |
81 | + Loop over Majordome state | |
82 | + Change behaviour with the pyros states | |
83 | + Take suitable decision thanks to states in database | |
84 | + ''' | |
85 | + def run(self): | |
86 | + #self.createTask() | |
87 | + #self.updateSoftware() | |
88 | + #self.setContext() | |
89 | + #self.setTime() /// OLD Majordome | |
90 | + #self.setTasks() | |
91 | + #self.loop() | |
92 | + | |
93 | + | |
94 | + # SETUP | |
95 | + try : | |
96 | + self.config = get_object_or_404(Config, id=1) | |
97 | + except Config.ObjectDoesNotExist: | |
98 | + return (1) | |
99 | + if not self.config.majordome_restarted: | |
100 | + self.setup() #in order to start other agents ect.... | |
101 | + self.changeState("Passive No PLC") | |
102 | + print("Waiting for PLC connection") | |
103 | + while (self.plcConnection() == False): #wait until PCL is connected | |
104 | + pass | |
105 | + print("PLC is connected") | |
106 | + self.changeState("Passive") | |
107 | + self.config.majordome_state = "RUNNING" | |
108 | + | |
109 | + # MAIN LOOP | |
110 | + while self.plcConnection() != False and self.current_status == "RUNNING" : #loop until shutdown or restart | |
111 | + #TODO: newstate = self.pyros_behaviour[self.current_state](self) #each different behaviour for all pyros states | |
112 | + self.pyros_behaviour[self.current_state](self) #each different behaviour for all pyros states | |
113 | + time.sleep(2) | |
114 | + | |
115 | + # EXIT | |
116 | + if self.current_status == "SHUTDOWN": #shutdown options change by the main program | |
117 | + self.closeBehaviour(self) | |
118 | + #TODO: self.kill_all_agents() | |
119 | + return 0 | |
120 | + elif self.current_status == "RESTART": | |
121 | + self.config.majordome_restarted = True | |
122 | + self.config.save() | |
123 | + #TODO: self.kill_all_agents() | |
124 | + self.sendNotClosedAlarms() | |
125 | + self.run() | |
126 | + | |
127 | + #TODO: rester dans la main loop ??? | |
128 | + elif self.current_status == "RUNNING" and self.plcConnection() == False: | |
129 | + self.config.majordome_restarted = True | |
130 | + self.config.save() | |
131 | + self.sendNotClosedAlarms() | |
132 | + self.run() | |
133 | + | |
134 | + | |
135 | + ''' | |
63 | 136 | Function called to change and save current state of pyros. |
64 | 137 | ''' |
65 | 138 | def changeState(self, state): |
... | ... | @@ -142,97 +215,26 @@ class Majordome(Task): |
142 | 215 | # TODO: elif dome == Parked and dome_shutter == Close and telescospe == Parked |
143 | 216 | #self.changeState("Standby") |
144 | 217 | |
145 | - pyros_behaviour = { | |
146 | - "Passive": passiveBehaviour, | |
147 | - "Standby": standbyBehaviour, | |
148 | - "Remote": remoteBehaviour, | |
149 | - "Startup": startupBehaviour, | |
150 | - "Scheduler": schedulerBehaviour, | |
151 | - "Closing": closingBehaviour, | |
152 | - } | |
153 | - | |
154 | - ''' | |
155 | - OLD //// Function called by celery task | |
156 | - Behavior: | |
157 | - Init telescope / cameras | |
158 | - set night limits | |
159 | - check the software version | |
160 | - launch the majordome loop ///// OLD | |
161 | - | |
162 | - Main loop of Majordome | |
163 | - startup everything if needed | |
164 | - Loop over Majordome state | |
165 | - Change behaviour with the pyros states | |
166 | - Take suitable decision thanks to states in database | |
167 | - ''' | |
168 | - def run(self): | |
169 | - #self.createTask() | |
170 | - #self.updateSoftware() | |
171 | - #self.setContext() | |
172 | - #self.setTime() /// OLD Majordome | |
173 | - #self.setTasks() | |
174 | - #self.loop() | |
175 | - | |
176 | - | |
177 | - # SETUP | |
178 | - try : | |
179 | - self.config = get_object_or_404(Config, id=1) | |
180 | - except Config.ObjectDoesNotExist: | |
181 | - return (1) | |
182 | - if not self.config.majordome_restarted: | |
183 | - self.setup() #in order to start other agents ect.... | |
184 | - self.changeState("Passive No PLC") | |
185 | - print("Waiting for PLC connection") | |
186 | - while (self.plcConnection() == False): #wait until PCL is connected | |
187 | - pass | |
188 | - print("PLC is connected") | |
189 | - self.changeState("Passive") | |
190 | - self.config.majordome_state = "RUNNING" | |
191 | - | |
192 | - # MAIN LOOP | |
193 | - while self.plcConnection() != False and self.current_status == "RUNNING" : #loop until shutdown or restart | |
194 | - #TODO: newstate = self.pyros_behaviour[self.current_state](self) #each different behaviour for all pyros states | |
195 | - self.pyros_behaviour[self.current_state](self) #each different behaviour for all pyros states | |
196 | - time.sleep(2) | |
197 | - | |
198 | - # EXIT | |
199 | - if self.current_status == "SHUTDOWN": #shutdown options change by the main program | |
200 | - self.closeBehaviour(self) | |
201 | - #TODO: self.kill_all_agents() | |
202 | - return 0 | |
203 | - elif self.current_status == "RESTART": | |
204 | - self.config.majordome_restarted = True | |
205 | - self.config.save() | |
206 | - #TODO: self.kill_all_agents() | |
207 | - self.sendNotClosedAlarms() | |
208 | - self.run() | |
209 | 218 | |
210 | - #TODO: rester dans la main loop ??? | |
211 | - elif self.current_status == "RUNNING" and self.plcConnection() == False: | |
212 | - self.config.majordome_restarted = True | |
213 | - self.config.save() | |
214 | - self.sendNotClosedAlarms() | |
215 | - self.run() | |
219 | + | |
216 | 220 | ''' |
217 | 221 | Function called by run to startup everything before loop within majordome (Empty for the moment) |
218 | 222 | ''' |
219 | - | |
220 | 223 | def setup(self): |
221 | 224 | pass |
222 | 225 | |
226 | + | |
223 | 227 | ''' |
224 | 228 | Function called to send alarms is the site isn't closed (Empty for the moment) |
225 | 229 | ''' |
226 | - | |
227 | - | |
228 | 230 | def sendNotClosedAlarms(self): |
229 | 231 | pass |
230 | 232 | |
233 | + | |
231 | 234 | ''' |
232 | 235 | Function called by run to wait for PLC connection before and during the loop |
233 | 236 | (also gathering needed info) |
234 | 237 | ''' |
235 | - | |
236 | 238 | def plcConnection(self): |
237 | 239 | try : |
238 | 240 | self.config = Config.objects.get(pk=1) |
... | ... | @@ -248,11 +250,6 @@ class Majordome(Task): |
248 | 250 | |
249 | 251 | |
250 | 252 | |
251 | - | |
252 | - | |
253 | - | |
254 | - | |
255 | - | |
256 | 253 | ''' |
257 | 254 | Check if the instrument status is valid |
258 | 255 | ''' | ... | ... |