Skip to content

Commit 2c12c6e

Browse files
committed
[stn] added logging to upload
1 parent 1d9c62e commit 2c12c6e

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/instrumentman/station/upload.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from logging import getLogger
2+
13
from geocompy.data import Angle, Coordinate
24
from geocompy.communication import open_serial
35
from geocompy.geo import GeoCom
@@ -17,31 +19,44 @@ def main(
1719
orientation: str | None = None,
1820
azimuth: str | None = None
1921
) -> None:
22+
logger = getLogger("iman.station.upload")
23+
logger.info(f"Opening connection on {port}")
24+
logger.debug(
25+
f"Connection parameters: baud={baud:d}, timeout={timeout:d}, "
26+
f"tries={retry:d}, sync-after-timeout={str(sync_after_timeout)}"
27+
)
2028
with open_serial(
2129
port=port,
2230
speed=baud,
2331
timeout=timeout,
2432
retry=retry,
2533
sync_after_timeout=sync_after_timeout
2634
) as com:
27-
tps = GeoCom(com)
35+
tps = GeoCom(com, logger.getChild("instrument"))
2836
if coordinates is not None and instrumentheight is not None:
2937
resp_stn = tps.tmc.set_station(
3038
Coordinate(*coordinates),
3139
instrumentheight
3240
)
3341
if resp_stn.error != GeoComCode.OK:
3442
echo_red("Cannot set station")
43+
logger.critical(f"Cannot set station ({resp_stn})")
3544
exit(1)
3645
else:
3746
echo_green("Station set")
47+
logger.info(f"Station set to {coordinates}")
3848

3949
if azimuth is not None:
4050
hz = Angle.from_dms(azimuth)
51+
logger.info(f"Setting azimuth to {azimuth}")
4152
elif orientation is not None:
53+
logger.info(f"Setting orientation to {orientation}")
4254
resp_angle = tps.tmc.get_angle()
4355
if resp_angle.error != GeoComCode.OK or resp_angle.params is None:
44-
echo_red("Could not set orientation")
56+
echo_red("Could not get current orientation")
57+
logger.critical(
58+
f"Could not get current orientation ({resp_angle})"
59+
)
4560
exit(1)
4661

4762
hz = (
@@ -54,6 +69,10 @@ def main(
5469
resp_ori = tps.tmc.set_azimuth(hz)
5570
if resp_ori.error != GeoComCode.OK:
5671
echo_red("Could not set orientation/azimuth")
72+
logger.critical(f"Could not set orientation/azimuth ({resp_ori})")
5773
exit(1)
5874

5975
echo_green("Orientation/azimuth set")
76+
logger.info("Orientation/azimuth set")
77+
78+
logger.info(f"Closed connection on {port}")

0 commit comments

Comments
 (0)