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