Skip to content

Commit 0545496

Browse files
committed
fix(flight controller): fix issue #407
Closes #407
1 parent 83803ad commit 0545496

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

ardupilot_methodic_configurator/backend_flightcontroller.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,36 @@ def __create_connection_with_retry(
288288
if log_errors:
289289
logging_warning(_("Connection failed: %s"), e)
290290
logging_error(_("Failed to connect after %d attempts."), retries)
291-
return str(e)
291+
error_message = str(e)
292+
guidance = self.__get_connection_error_guidance(e, self.comport.device if self.comport else "")
293+
if guidance:
294+
error_message = f"{error_message}\n\n{guidance}"
295+
return error_message
296+
297+
def __get_connection_error_guidance(self, error: Exception, device: str) -> str:
298+
"""
299+
Provides guidance based on the type of connection error.
300+
301+
Args:
302+
error (Exception): The exception that occurred during connection.
303+
device (str): The device path or connection string.
304+
305+
Returns:
306+
str: Guidance message specific to the error type, or empty string if no specific guidance.
307+
308+
"""
309+
# Check for permission denied errors on Linux
310+
if isinstance(error, PermissionError) and os_name == "posix" and "/dev/" in device:
311+
return _(
312+
"Permission denied accessing the serial port. This is common on Linux systems.\n"
313+
"To fix this issue, add your user to the 'dialout' group with the following command:\n"
314+
" sudo adduser $USER dialout\n"
315+
"Then log out and log back in for the changes to take effect."
316+
)
317+
318+
# Add more specific guidance for other error types as needed
319+
320+
return ""
292321

293322
def __process_autopilot_version(self, m: MAVLink_autopilot_version_message, banner_msgs: list[str]) -> str:
294323
if m is None:

0 commit comments

Comments
 (0)