stepper: reduce method size
This commit is contained in:
parent
12712c241e
commit
98c51828e0
|
@ -254,18 +254,7 @@ class StepperProcess(multiprocessing.Process):
|
|||
|
||||
logger.info(f"Stepper initialisation is over")
|
||||
|
||||
def treat_command(self):
|
||||
command = ""
|
||||
if self.actuator_client.new_message_received():
|
||||
logger.info("We received a new message")
|
||||
last_message = self.actuator_client.msg["payload"]
|
||||
logger.debug(last_message)
|
||||
command = self.actuator_client.msg["topic"].split("/", 1)[1]
|
||||
logger.debug(command)
|
||||
self.actuator_client.read_message()
|
||||
|
||||
# If the command is "pump"
|
||||
if command == "pump":
|
||||
def __message_pump(self, last_message):
|
||||
logger.debug("We have received a pumping command")
|
||||
if last_message["action"] == "stop":
|
||||
logger.debug("We have received a stop pump command")
|
||||
|
@ -295,9 +284,7 @@ class StepperProcess(multiprocessing.Process):
|
|||
logger.error(
|
||||
f"The received message has the wrong argument {last_message}"
|
||||
)
|
||||
self.actuator_client.client.publish(
|
||||
"status/pump", '{"status":"Error"}'
|
||||
)
|
||||
self.actuator_client.client.publish("status/pump", '{"status":"Error"}')
|
||||
return
|
||||
# Get direction from the different received arguments
|
||||
direction = last_message["direction"]
|
||||
|
@ -310,12 +297,9 @@ class StepperProcess(multiprocessing.Process):
|
|||
logger.info("The pump is started.")
|
||||
self.pump(direction, volume, flowrate)
|
||||
else:
|
||||
logger.warning(
|
||||
f"The received message was not understood {last_message}"
|
||||
)
|
||||
logger.warning(f"The received message was not understood {last_message}")
|
||||
|
||||
# If the command is "focus"
|
||||
elif command == "focus":
|
||||
def __message_focus(self, last_message):
|
||||
logger.debug("We have received a focusing request")
|
||||
# If a new received command is "focus" but args contains "stop" we stop!
|
||||
if last_message["action"] == "stop":
|
||||
|
@ -338,10 +322,7 @@ class StepperProcess(multiprocessing.Process):
|
|||
# Set the LEDs as Yellow
|
||||
planktoscope.light.setRGB(255, 255, 0)
|
||||
|
||||
if (
|
||||
"direction" not in last_message
|
||||
or "distance" not in last_message
|
||||
):
|
||||
if "direction" not in last_message or "distance" not in last_message:
|
||||
logger.error(
|
||||
f"The received message has the wrong argument {last_message}"
|
||||
)
|
||||
|
@ -357,9 +338,25 @@ class StepperProcess(multiprocessing.Process):
|
|||
logger.info("The focus movement is started.")
|
||||
self.focus(direction, distance)
|
||||
else:
|
||||
logger.warning(
|
||||
f"The received message was not understood {last_message}"
|
||||
)
|
||||
logger.warning(f"The received message was not understood {last_message}")
|
||||
|
||||
def treat_command(self):
|
||||
command = ""
|
||||
if self.actuator_client.new_message_received():
|
||||
logger.info("We received a new message")
|
||||
last_message = self.actuator_client.msg["payload"]
|
||||
logger.debug(last_message)
|
||||
command = self.actuator_client.msg["topic"].split("/", 1)[1]
|
||||
logger.debug(command)
|
||||
self.actuator_client.read_message()
|
||||
|
||||
# If the command is "pump"
|
||||
if command == "pump":
|
||||
self.__message_pump(last_message)
|
||||
|
||||
# If the command is "focus"
|
||||
elif command == "focus":
|
||||
self.__message_focus(last_message)
|
||||
elif command != "":
|
||||
logger.warning(
|
||||
f"We did not understand the received request {command} - {last_message}"
|
||||
|
@ -518,7 +515,6 @@ class StepperProcess(multiprocessing.Process):
|
|||
"status/focus",
|
||||
'{"status":"Done"}',
|
||||
)
|
||||
time.sleep(0)
|
||||
logger.info("Shutting down the stepper process")
|
||||
self.actuator_client.client.publish("status/pump", '{"status":"Dead"}')
|
||||
self.actuator_client.client.publish("status/focus", '{"status":"Dead"}')
|
||||
|
|
Loading…
Reference in a new issue