11import os
22from datetime import datetime
3- from logging import getLogger
3+ from logging import Logger , getLogger
44from typing import Iterator , Literal
55from itertools import chain
66import pathlib
1111from geocompy .geo .gctypes import GeoComCode
1212from geocompy .geo .gcdata import Face
1313
14- from ..utils import make_logger
1514from ..targets import (
1615 TargetPoint ,
1716 TargetList ,
@@ -57,38 +56,41 @@ def iter_targets(
5756
5857def measure_set (
5958 tps : GeoCom ,
59+ logger : Logger ,
6060 filepath : str ,
6161 order_spec : Literal ['AaBb' , 'AabB' , 'ABab' , 'ABba' , 'ABCD' ],
6262 count : int = 1 ,
6363 pointnames : str = ""
6464) -> Session :
65- applog = getLogger ( "APP " )
65+ logger . info ( "Starting set measurements " )
6666 points = load_targets_from_json (filepath )
6767 if pointnames != "" :
6868 use_points = set (pointnames .split ("," ))
6969 loaded_points = set (points .get_target_names ())
7070 excluded_points = loaded_points - use_points
71- applog .debug (f"Excluding points: { excluded_points } " )
71+ logger .debug (f"Excluding points: { excluded_points } " )
7272 for pt in excluded_points :
7373 points .pop_target (pt )
7474
75+ logger .info ("Measuring inclination, temperature and battery level" )
7576 tps .aut .turn_to (0 , Angle (180 , 'deg' ))
7677 incline = tps .tmc .get_angle_inclination ('MEASURE' ).params
7778 temp = tps .csv .get_internal_temperature ().params
7879 battery = tps .csv .check_power ().params
80+ logger .info ("Retrieving station setup" )
7981 resp_station = tps .tmc .get_station ().params
8082 if resp_station is None :
8183 station = Coordinate (0 , 0 , 0 )
8284 iheight = 0.0
83- applog . warning (
84- "Could not retrieve station and instrument height, using default "
85+ logger . error (
86+ "Could not retrieve station and instrument height, defaulting to 0 "
8587 )
8688 else :
8789 station , iheight = resp_station
8890
8991 session = Session (station , iheight )
9092 for i in range (count ):
91- applog .info (f"Starting set cycle { i + 1 } " )
93+ logger .info (f"Starting set cycle { i + 1 } " )
9294 output = Cycle (
9395 datetime .now (),
9496 battery [0 ] if battery is not None else None ,
@@ -97,7 +99,7 @@ def measure_set(
9799 )
98100
99101 for f , t in iter_targets (points , order_spec ):
100- applog .info (f"Measuring { t .name } ({ f .name } )" )
102+ logger .info (f"Measuring { t .name } ({ f .name } )" )
101103 rel_coords = (
102104 (t .coords + Coordinate (0 , 0 , t .height ))
103105 - (station + Coordinate (0 , 0 , iheight ))
@@ -110,7 +112,7 @@ def measure_set(
110112 tps .aut .turn_to (hz , v )
111113 resp_atr = tps .aut .fine_adjust (0.5 , 0.5 )
112114 if resp_atr .error != GeoComCode .OK :
113- applog .error (
115+ logger .error (
114116 f"ATR fine adjustment failed ({ resp_atr .error .name } ), "
115117 "skipping point"
116118 )
@@ -120,7 +122,7 @@ def measure_set(
120122 tps .tmc .do_measurement ()
121123 resp_angle = tps .tmc .get_simple_measurement (10 )
122124 if resp_angle .params is None :
123- applog .error (
125+ logger .error (
124126 f"Error during measurement ({ resp_angle .error .name } ), "
125127 "skipping point"
126128 )
@@ -132,11 +134,12 @@ def measure_set(
132134 t .height ,
133135 resp_angle .params
134136 )
135- applog .info ("Done" )
137+ logger .info ("Done" )
136138
137139 session .cycles .append (output )
138140
139141 tps .aut .turn_to (0 , Angle (180 , 'deg' ))
142+ logger .info ("Finished set measurements" )
140143
141144 return session
142145
@@ -153,41 +156,41 @@ def main(
153156 cycles : int = 1 ,
154157 order : Literal ['AaBb' , 'AabB' , 'ABab' , 'ABba' , 'ABCD' ] = "ABba" ,
155158 sync_time : bool = True ,
156- points : str = "" ,
157- debug : bool = False ,
158- info : bool = False ,
159- warning : bool = False ,
160- error : bool = False ,
159+ points : str = ""
161160) -> None :
162- log = make_logger ("TPS" , debug , info , warning , error )
163- applog = make_logger ("APP" , debug , info , warning , error )
164- applog .info ("Starting measurement session" )
165-
161+ logger = getLogger ("iman.sets.measure" )
162+ logger .info (f"Opening connection on { port } " )
163+ logger .debug (
164+ f"Connection parameters: baud={ baud :d} , timeout={ timeout :d} , "
165+ f"tries={ retry :d} , sync-after-timeout={ str (sync_after_timeout )} "
166+ )
166167 with open_serial (
167168 port ,
168169 retry = retry ,
169170 sync_after_timeout = sync_after_timeout ,
170171 speed = baud ,
171172 timeout = timeout
172173 ) as com :
173- tps = GeoCom (com , log )
174+ tps = GeoCom (com , logger . getChild ( "instrument" ) )
174175 if sync_time :
175176 tps .csv .set_datetime (datetime .now ())
177+ logger .info ("Synced instrument date-time to computer" )
176178
177179 session = measure_set (
178180 tps ,
181+ logger ,
179182 str (targets ),
180183 order ,
181184 cycles ,
182185 points
183186 )
184187
185- applog .info ("Finished measurement session " )
188+ logger .info (f"Closed connection on { port } " )
186189
187190 timestamp = session .cycles [0 ].time .strftime ("%Y%m%d_%H%M%S" )
188191 filename = os .path .join (
189192 directory ,
190193 format .format (time = timestamp , order = order , cycle = cycles )
191194 )
192195 session .export_to_json (filename )
193- applog .info (f"Saved measurement results at '{ filename } '" )
196+ logger .info (f"Saved measurement results to '{ filename } '" )
0 commit comments