Skip to content

Commit bcb4b85

Browse files
committed
Added GSI Online DNA tests
1 parent ba74cc5 commit bcb4b85

File tree

4 files changed

+88
-29
lines changed

4 files changed

+88
-29
lines changed

src/instrumentman/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from . import terminal
1010
from . import setup
1111
from . import setmeasurement
12-
from . import geocomtest
12+
from . import protocoltest
1313
from . import inclination
1414

1515

@@ -57,7 +57,8 @@ def cli_test() -> None:
5757
cli_measure.add_command(inclination.cli_measure)
5858
cli_calc.add_command(setmeasurement.cli_calc)
5959
cli_calc.add_command(inclination.cli_calc)
60-
cli_test.add_command(geocomtest.cli)
60+
cli_test.add_command(protocoltest.cli_geocom)
61+
cli_test.add_command(protocoltest.cli_gsidna)
6162
cli_merge.add_command(setmeasurement.cli_merge)
6263
cli_merge.add_command(inclination.cli_merge)
6364
cli_validate.add_command(setmeasurement.cli_validate)

src/instrumentman/geocomtest/__init__.py

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from typing import Any
2+
3+
from click_extra import extra_command
4+
5+
from ..utils import (
6+
com_option_group,
7+
com_port_argument
8+
)
9+
10+
11+
@extra_command(
12+
"geocom",
13+
params=None,
14+
context_settings={"auto_envvar_prefix": None}
15+
) # type: ignore[misc]
16+
@com_port_argument()
17+
@com_option_group()
18+
def cli_geocom(**kwargs: Any) -> None:
19+
"""Test the availability of various GeoCom protocol functions on an
20+
instrument."""
21+
from .app import main
22+
23+
kwargs["protocol"] = "geocom"
24+
main(**kwargs)
25+
26+
27+
@extra_command(
28+
"gsidna",
29+
params=None,
30+
context_settings={"auto_envvar_prefix": None}
31+
) # type: ignore[misc]
32+
@com_port_argument()
33+
@com_option_group()
34+
def cli_gsidna(**kwargs: Any) -> None:
35+
"""Test the availability of various GSI Online DNA functions on an
36+
instrument."""
37+
from .app import main
38+
39+
kwargs["protocol"] = "gsidna"
40+
main(**kwargs)

src/instrumentman/geocomtest/app.py renamed to src/instrumentman/protocoltest/app.py

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from geocompy.data import Angle
77
from geocompy.geo import GeoCom
88
from geocompy.geo.gctypes import GeoComCode
9+
from geocompy.gsi.dna import GsiOnlineDNA
910
from geocompy.communication import open_serial
1011

1112
from ..utils import (
@@ -15,7 +16,7 @@
1516
)
1617

1718

18-
def tests(tps: GeoCom) -> None:
19+
def tests_geocom(tps: GeoCom) -> None:
1920
echo("GeoCom connection successful")
2021
echo(
2122
"Various GeoCom functions will be tested. Certain settings will be "
@@ -55,8 +56,44 @@ def tests(tps: GeoCom) -> None:
5556
echo_yellow(f"Mororization unavailable ({resp_changeface.response})")
5657

5758

59+
def tests_gsidna(dna: GsiOnlineDNA) -> None:
60+
echo("GSI Online connection successful")
61+
echo(
62+
"Various GSI Online DNA functions will be tested. Certain settings "
63+
"might be changed on the instrument (staff mode, point number, etc.)."
64+
)
65+
pause("Press any key when ready to proceed...")
66+
67+
echo("Testing settings...")
68+
staff_get = dna.settings.get_staff_mode()
69+
if staff_get.value is None:
70+
echo_red("Settings queries unavailable")
71+
else:
72+
echo_green("Settings queries available")
73+
74+
staff_set = dna.settings.set_staff_mode(False)
75+
if not staff_set.value:
76+
echo_red("Settings commands unavailable")
77+
else:
78+
echo_green("Settings commands available")
79+
80+
echo("Testing measurements...")
81+
point_get = dna.measurements.get_point_id()
82+
if point_get is None:
83+
echo_red("Measurement/database queries unavailable")
84+
else:
85+
echo_green("Measurement/database queries available")
86+
87+
point_set = dna.measurements.set_point_id("TEST")
88+
if not point_set.value:
89+
echo_red("Measurement/database commands unavailable")
90+
else:
91+
echo_green("Measurement/database commands available")
92+
93+
5894
def main(
5995
port: str,
96+
protocol: str,
6097
baud: int = 9600,
6198
timeout: int = 15,
6299
retry: int = 1,
@@ -70,7 +107,11 @@ def main(
70107
retry=retry,
71108
sync_after_timeout=sync_after_timeout
72109
) as com:
73-
tps = GeoCom(com)
74-
tests(tps)
110+
if protocol == "geocom":
111+
tps = GeoCom(com)
112+
tests_geocom(tps)
113+
elif protocol == "gsidna":
114+
dna = GsiOnlineDNA(com)
115+
tests_gsidna(dna)
75116
except (SerialException, ConnectionError) as e:
76-
echo_red(f"GeoCom connection was not successful ({e})")
117+
echo_red(f"Connection was not successful ({e})")

0 commit comments

Comments
 (0)