diff --git a/src/majordome/tasks.py b/src/majordome/tasks.py index 948a26f..34621a9 100644 --- a/src/majordome/tasks.py +++ b/src/majordome/tasks.py @@ -50,18 +50,23 @@ class Majordome(Task): functions = {} schedule = None available_status = [] - current_status = "RUNNING" alarm_list = [] - plc_status = None + + # New variables from TP: config = None + plc_status = None current_state = "Passive" + current_status = "RUNNING" ''' Function called to change and save current state of pyros. ''' def changeState(self, state): + # (local variable) idem self.config.pyros_state self.current_state = state + + # (in DB) PASSIVE, STANDBY, REMOTE, OPERATING self.config.pyros_state = state self.config.save() @@ -169,6 +174,7 @@ class Majordome(Task): #self.loop() + # SETUP try : self.config = get_object_or_404(Config, id=1) except Config.ObjectDoesNotExist: @@ -182,17 +188,26 @@ class Majordome(Task): print("PLC is connected") self.changeState("Passive") self.config.majordome_state = "RUNNING" + + # MAIN LOOP while self.plcConnection() != False and self.current_status == "RUNNING" : #loop until shutdown or restart + #TODO: newstate = self.pyros_behaviour[self.current_state](self) #each different behaviour for all pyros states self.pyros_behaviour[self.current_state](self) #each different behaviour for all pyros states - time.sleep(2) + time.sleep(2) + + # EXIT if self.current_status == "SHUTDOWN": #shutdown options change by the main program self.closeBehaviour(self) + #TODO: self.kill_all_agents() return 0 elif self.current_status == "RESTART": self.config.majordome_restarted = True self.config.save() + #TODO: self.kill_all_agents() self.sendNotClosedAlarms() self.run() + + #TODO: rester dans la main loop ??? elif self.current_status == "RUNNING" and self.plcConnection() == False: self.config.majordome_restarted = True self.config.save() -- libgit2 0.21.2