Commit 468a79dc3c0c6609ed42d1f445b329f27cc344c5
1 parent
d3faf327
Exists in
dev
added comments
Showing
1 changed file
with
18 additions
and
3 deletions
Show diff stats
src/majordome/tasks.py
... | ... | @@ -50,18 +50,23 @@ class Majordome(Task): |
50 | 50 | functions = {} |
51 | 51 | schedule = None |
52 | 52 | available_status = [] |
53 | - current_status = "RUNNING" | |
54 | 53 | alarm_list = [] |
55 | - plc_status = None | |
54 | + | |
55 | + # New variables from TP: | |
56 | 56 | config = None |
57 | + plc_status = None | |
57 | 58 | current_state = "Passive" |
59 | + current_status = "RUNNING" | |
58 | 60 | |
59 | 61 | |
60 | 62 | ''' |
61 | 63 | Function called to change and save current state of pyros. |
62 | 64 | ''' |
63 | 65 | def changeState(self, state): |
66 | + # (local variable) idem self.config.pyros_state | |
64 | 67 | self.current_state = state |
68 | + | |
69 | + # (in DB) PASSIVE, STANDBY, REMOTE, OPERATING | |
65 | 70 | self.config.pyros_state = state |
66 | 71 | self.config.save() |
67 | 72 | |
... | ... | @@ -169,6 +174,7 @@ class Majordome(Task): |
169 | 174 | #self.loop() |
170 | 175 | |
171 | 176 | |
177 | + # SETUP | |
172 | 178 | try : |
173 | 179 | self.config = get_object_or_404(Config, id=1) |
174 | 180 | except Config.ObjectDoesNotExist: |
... | ... | @@ -182,17 +188,26 @@ class Majordome(Task): |
182 | 188 | print("PLC is connected") |
183 | 189 | self.changeState("Passive") |
184 | 190 | self.config.majordome_state = "RUNNING" |
191 | + | |
192 | + # MAIN LOOP | |
185 | 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 | |
186 | 195 | self.pyros_behaviour[self.current_state](self) #each different behaviour for all pyros states |
187 | - time.sleep(2) | |
196 | + time.sleep(2) | |
197 | + | |
198 | + # EXIT | |
188 | 199 | if self.current_status == "SHUTDOWN": #shutdown options change by the main program |
189 | 200 | self.closeBehaviour(self) |
201 | + #TODO: self.kill_all_agents() | |
190 | 202 | return 0 |
191 | 203 | elif self.current_status == "RESTART": |
192 | 204 | self.config.majordome_restarted = True |
193 | 205 | self.config.save() |
206 | + #TODO: self.kill_all_agents() | |
194 | 207 | self.sendNotClosedAlarms() |
195 | 208 | self.run() |
209 | + | |
210 | + #TODO: rester dans la main loop ??? | |
196 | 211 | elif self.current_status == "RUNNING" and self.plcConnection() == False: |
197 | 212 | self.config.majordome_restarted = True |
198 | 213 | self.config.save() | ... | ... |