Skip to content

Commit be76f56

Browse files
committed
[stn] added more parameters to upload
1 parent ce62fba commit be76f56

File tree

2 files changed

+59
-21
lines changed

2 files changed

+59
-21
lines changed

src/instrumentman/station/__init__.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
option,
77
file_path
88
)
9+
from cloup.constraints import (
10+
constraint,
11+
mutually_exclusive,
12+
all_or_none
13+
)
914

1015
from ..utils import (
1116
com_port_argument,
@@ -60,23 +65,43 @@ def cli_calc(**kwargs: Any) -> None:
6065
@com_port_argument()
6166
@com_option_group()
6267
@option(
68+
"-c",
6369
"--coordinates",
6470
help="station coordinates",
6571
type=(float, float, float),
66-
default=(0, 0, 0)
72+
is_flag=False,
73+
flag_value=(0, 0, 0)
6774
)
6875
@option(
76+
"-i",
6977
"--instrumentheight",
7078
"--iheight",
7179
help="instrument height",
7280
type=float,
73-
default=0
81+
is_flag=False,
82+
flag_value=0
7483
)
7584
@option(
85+
"-o",
7686
"--orientation",
7787
help="instrument orientation correction",
88+
type=Angle()
89+
)
90+
@option(
91+
"-a",
92+
"--azimuth",
93+
help="current azimuth",
7894
type=Angle(),
79-
default="0-00-00"
95+
is_flag=False,
96+
flag_value="0-00-00"
97+
)
98+
@constraint(
99+
mutually_exclusive,
100+
["orientation", "azimuth"]
101+
)
102+
@constraint(
103+
all_or_none,
104+
["coordinates", "instrumentheight"]
80105
)
81106
def cli_upload(**kwargs: Any) -> None:
82107
"""Upload station setup to instrument."""

src/instrumentman/station/upload.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ def main(
1212
timeout: int = 15,
1313
retry: int = 1,
1414
sync_after_timeout: bool = False,
15-
coordinates: tuple[float, float, float] = (0, 0, 0),
16-
instrumentheight: float = 0,
17-
orientation: str = "0-00-00"
15+
coordinates: tuple[float, float, float] | None = None,
16+
instrumentheight: float | None = None,
17+
orientation: str | None = None,
18+
azimuth: str | None = None
1819
) -> None:
19-
station = Coordinate(*coordinates)
20-
ori = Angle.from_dms(orientation)
2120
with open_serial(
2221
port=port,
2322
speed=baud,
@@ -26,21 +25,35 @@ def main(
2625
sync_after_timeout=sync_after_timeout
2726
) as com:
2827
tps = GeoCom(com)
29-
resp_stn = tps.tmc.set_station(station, instrumentheight)
30-
if resp_stn.error != GeoComCode.OK:
31-
echo_red("Cannot set station")
32-
exit(1)
28+
if coordinates is not None and instrumentheight is not None:
29+
resp_stn = tps.tmc.set_station(
30+
Coordinate(*coordinates),
31+
instrumentheight
32+
)
33+
if resp_stn.error != GeoComCode.OK:
34+
echo_red("Cannot set station")
35+
exit(1)
36+
else:
37+
echo_green("Station set")
3338

34-
resp_angle = tps.tmc.get_angle()
35-
if resp_angle.error != GeoComCode.OK or resp_angle.params is None:
36-
echo_red("Cannot set orientation")
37-
exit(1)
39+
if azimuth is not None:
40+
hz = Angle.from_dms(azimuth)
41+
elif orientation is not None:
42+
resp_angle = tps.tmc.get_angle()
43+
if resp_angle.error != GeoComCode.OK or resp_angle.params is None:
44+
echo_red("Could not set orientation")
45+
exit(1)
46+
47+
hz = (
48+
resp_angle.params[0]
49+
+ Angle.from_dms(orientation)
50+
).normalized()
51+
else:
52+
exit()
3853

39-
resp_ori = tps.tmc.set_azimuth(
40-
(resp_angle.params[0] + ori).normalized()
41-
)
54+
resp_ori = tps.tmc.set_azimuth(hz)
4255
if resp_ori.error != GeoComCode.OK:
43-
echo_red("Cannot set orientation")
56+
echo_red("Could not set orientation/azimuth")
4457
exit(1)
4558

46-
echo_green("Station and orientation set")
59+
echo_green("Orientation/azimuth set")

0 commit comments

Comments
 (0)