diff --git a/Tools/autotest/apmrover2.py b/Tools/autotest/apmrover2.py index b2844756bf..cdc8208f71 100644 --- a/Tools/autotest/apmrover2.py +++ b/Tools/autotest/apmrover2.py @@ -89,17 +89,8 @@ class AutoTestRover(AutoTest): self.progress("Started simulator") - # get a mavlink connection going - connection_string = '127.0.0.1:19550' - try: - self.mav = mavutil.mavlink_connection(connection_string, - robust_parsing=True) - except Exception as msg: - self.progress("Failed to start mavlink connection on %s" % - connection_string) - raise - self.mav.message_hooks.append(self.message_hook) - self.mav.idle_hooks.append(self.idle_hook) + self.get_mavlink_connection_going() + self.hasInit = True self.apply_defaultfile_parameters() diff --git a/Tools/autotest/arducopter.py b/Tools/autotest/arducopter.py index ba8e70c37d..9f6df57fc9 100644 --- a/Tools/autotest/arducopter.py +++ b/Tools/autotest/arducopter.py @@ -114,17 +114,8 @@ class AutoTestCopter(AutoTest): self.progress("Started simulator") - # get a mavlink connection going - connection_string = '127.0.0.1:19550' - try: - self.mav = mavutil.mavlink_connection(connection_string, - robust_parsing=True) - except Exception as msg: - self.progress("Failed to start mavlink connection on %s: %s" % - (connection_string, msg,)) - raise - self.mav.message_hooks.append(self.message_hook) - self.mav.idle_hooks.append(self.idle_hook) + self.get_mavlink_connection_going() + self.hasInit = True self.progress("Ready to start testing!") diff --git a/Tools/autotest/arduplane.py b/Tools/autotest/arduplane.py index 2992a4b951..ff65839621 100644 --- a/Tools/autotest/arduplane.py +++ b/Tools/autotest/arduplane.py @@ -83,17 +83,8 @@ class AutoTestPlane(AutoTest): self.progress("Started simulator") - # get a mavlink connection going - connection_string = '127.0.0.1:19550' - try: - self.mav = mavutil.mavlink_connection(connection_string, - robust_parsing=True) - except Exception as msg: - self.progress("Failed to start mavlink connection on %s: %s" - % (connection_string, msg)) - raise - self.mav.message_hooks.append(self.message_hook) - self.mav.idle_hooks.append(self.idle_hook) + self.get_mavlink_connection_going() + self.hasInit = True self.progress("Ready to start testing!") diff --git a/Tools/autotest/ardusub.py b/Tools/autotest/ardusub.py index d29b4023da..3a9b6d8588 100644 --- a/Tools/autotest/ardusub.py +++ b/Tools/autotest/ardusub.py @@ -78,17 +78,8 @@ class AutoTestSub(AutoTest): self.progress("Started simulator") - # get a mavlink connection going - connection_string = '127.0.0.1:19550' - try: - self.mav = mavutil.mavlink_connection(connection_string, - robust_parsing=True) - except Exception as msg: - self.progress("Failed to start mavlink connection on %s: %s" % - (connection_string, msg,)) - raise - self.mav.message_hooks.append(self.message_hook) - self.mav.idle_hooks.append(self.idle_hook) + self.get_mavlink_connection_going() + self.hasInit = True self.apply_defaultfile_parameters() diff --git a/Tools/autotest/common.py b/Tools/autotest/common.py index be280034f1..cc58663ec4 100644 --- a/Tools/autotest/common.py +++ b/Tools/autotest/common.py @@ -861,6 +861,19 @@ class AutoTest(ABC): self.progress("Failed to get EKF.flags=%u" % required_value) raise AutoTestTimeoutException() + def get_mavlink_connection_going(self): + # get a mavlink connection going + connection_string = '127.0.0.1:19550' + try: + self.mav = mavutil.mavlink_connection(connection_string, + robust_parsing=True) + except Exception as msg: + self.progress("Failed to start mavlink connection on %s: %s" % + (connection_string, msg,)) + raise + self.mav.message_hooks.append(self.message_hook) + self.mav.idle_hooks.append(self.idle_hook) + def run_test(self, desc, function, interact=False): self.progress("#") self.progress("########## %s ##########" % (desc)) diff --git a/Tools/autotest/quadplane.py b/Tools/autotest/quadplane.py index 43d48ee622..d7ca0f1376 100644 --- a/Tools/autotest/quadplane.py +++ b/Tools/autotest/quadplane.py @@ -82,17 +82,8 @@ class AutoTestQuadPlane(AutoTest): self.progress("Started simulator") - # get a mavlink connection going - connection_string = '127.0.0.1:19550' - try: - self.mav = mavutil.mavlink_connection(connection_string, - robust_parsing=True) - except Exception as msg: - self.progress("Failed to start mavlink connection on %s: %s" % - (connection_string, msg)) - raise - self.mav.message_hooks.append(self.message_hook) - self.mav.idle_hooks.append(self.idle_hook) + self.get_mavlink_connection_going() + self.hasInit = True self.progress("Ready to start testing!")