Skip to content

Commit

Permalink
Merge pull request #159 from robamu-org/reduce-serial-com-port-checks
Browse files Browse the repository at this point in the history
reduce serial com port checks
  • Loading branch information
robamu authored Oct 10, 2024
2 parents 69223ba + 0093a0d commit 9800e30
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ Starting from v4.0.0, this project adheres to [Semantic Versioning](http://semve

# [unreleased]

## Fixed

- Removed serial port validity check, which does not work for something like symlinks created
with udev rules.

# [v8.0.2] 2024-08-27

## Changed
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ gui = [
"PyQt6~=6.6",
]
test = [
"pyfakefs~=4.5",
"pyfakefs~=5.7",
"pytest~=8.3"
]

[project.urls]
Expand Down
27 changes: 3 additions & 24 deletions tmtccmd/com/ser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __det_com_port_with_json_file(
json_obj = json.load(json_file)
com_port = ""
if not reconfig_com_port:
reconfig_com_port, try_hint, com_port = __try_com_port_load(json_obj=json_obj)
try_hint, com_port = __try_com_port_load(json_obj=json_obj)
if try_hint:
reconfig_com_port, com_port = __try_hint_handling(
json_cfg_path=json_cfg_path,
Expand All @@ -102,36 +102,15 @@ def __det_com_port_with_json_file(
return com_port


def __try_com_port_load(json_obj) -> Tuple[bool, bool, str]:
reconfig_com_port = False
def __try_com_port_load(json_obj) -> Tuple[bool, str]:
try_hint = False
com_port = ""
try:
com_port = json_obj[JsonKeyNames.SERIAL_PORT.value]
_LOGGER.info(f"Loaded serial port {com_port} from JSON configuration file")
if not check_port_validity(com_port):
while True:
_LOGGER.info(
"Serial port from configuration file not contained within serial"
" port list"
)
reconfigure = input(
"Reconfigure serial port or try to determine from hint? "
"[r (reconfigure) / h (hint) / c(cancel)]: "
)
if reconfigure.lower() in ["r"]:
reconfig_com_port = True
break
elif reconfigure.lower() in ["h"]:
try_hint = True
break
elif reconfigure.lower() in ["c"]:
return com_port
else:
continue
except KeyError:
try_hint = True
return reconfig_com_port, try_hint, com_port
return try_hint, com_port


def __try_hint_handling(
Expand Down

0 comments on commit 9800e30

Please sign in to comment.