Skip to content

Commit b661da2

Browse files
committed
[settings] added save for geocom
1 parent 7fefaef commit b661da2

File tree

1 file changed

+147
-4
lines changed

1 file changed

+147
-4
lines changed

src/instrumentman/settings/save.py

Lines changed: 147 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
from typing import Callable, Any
33
from enum import Enum
44

5+
from geocompy.data import Angle
56
from geocompy.communication import open_serial
67
from geocompy.geo import GeoCom
8+
from geocompy.geo.gctypes import GeoComResponse, GeoComSubsystem, GeoComCode
79
from geocompy.gsi.dna import GsiOnlineDNA
810
from geocompy.gsi.gsitypes import GsiOnlineResponse
911

@@ -15,13 +17,148 @@ def download_settings_geocom(
1517
tps: GeoCom,
1618
add_defaults: bool = False
1719
) -> SettingsDict:
18-
data: SettingsDict = {
20+
options: list[SubsystemSettingsDict] = [
21+
{
22+
"subsystem": "aut",
23+
"options": {
24+
"atr": True,
25+
"lock": False,
26+
"tolerance": [1, 1],
27+
"timeout": [15, 15],
28+
"fine_adjust_mode": "NORMAL",
29+
"search_area": [0, 0, 0.1, 0.1, True],
30+
"spiral": [0.1, 0.1],
31+
"lock_onthefly": True
32+
}
33+
},
34+
{
35+
"subsystem": "bap",
36+
"options": {
37+
"target_type": "REFLECTOR",
38+
"prism_type": "MINI",
39+
"measurement_program": "SINGLE_REF_STANDARD",
40+
"atr_setting": "NORMAL",
41+
"reduced_atr_fov": False,
42+
"precise_atr": True
43+
}
44+
},
45+
{
46+
"subsystem": "csv",
47+
"options": {
48+
"laserlot": True,
49+
"laserlot_intensity": 100,
50+
"charging": False,
51+
"preferred_powersource": "INTERNAL"
52+
}
53+
},
54+
{
55+
"subsystem": "dna",
56+
"options": {
57+
"staffmode": False,
58+
"curvature_correction": False,
59+
"staff_type": "GPCL2"
60+
}
61+
},
62+
{
63+
"subsystem": "edm",
64+
"options": {
65+
"laserpointer": False,
66+
"edm": True,
67+
"boomerang_filter": True,
68+
"tracklight_brightness": "MID",
69+
"tracklight": False,
70+
"guidelight_intensity": "OFF",
71+
"boomerang_filter_new": True
72+
}
73+
},
74+
{
75+
"subsystem": "img",
76+
"options": {
77+
"telescopic_configuration": [0, 50, 6, "INTERNAL"],
78+
"telescopic_exposure_time": 20
79+
}
80+
},
81+
{
82+
"subsystem": "kdm",
83+
"options": {
84+
"display_power": False
85+
}
86+
},
87+
{
88+
"subsystem": "sup",
89+
"options": {
90+
"poweroff_configuration": [False, "SLEEP", 600000],
91+
"low_temperature_control": False,
92+
"autorestart": True
93+
}
94+
},
95+
{
96+
"subsystem": "tmc",
97+
"options": {
98+
"compensator": True,
99+
"edm_mode_v1": "SINGLE_STANDARD",
100+
"edm_mode_v2": "SINGLE_STANDARD",
101+
"angle_correction": [True, True, True, True]
102+
}
103+
}
104+
]
105+
output_options: list[SubsystemSettingsDict] = []
106+
for group in options:
107+
settings: SubsystemSettingsDict = {
108+
"subsystem": group["subsystem"],
109+
"options": {}
110+
}
111+
112+
subsystem: GeoComSubsystem | None = getattr(
113+
tps,
114+
group["subsystem"],
115+
None
116+
)
117+
if subsystem is None:
118+
continue
119+
120+
for option, default in group["options"].items():
121+
if isinstance(default, bool):
122+
name = f"get_{option}_status"
123+
else:
124+
name = f"get_{option}"
125+
126+
method: Callable[
127+
[],
128+
GeoComResponse[Any]
129+
] | None = getattr(subsystem, name, None)
130+
if method is None:
131+
settings["options"][option] = default if add_defaults else None
132+
continue
133+
134+
response = method()
135+
value = response.params
136+
if response.error != GeoComCode.OK or value is None:
137+
settings["options"][option] = default if add_defaults else None
138+
continue
139+
140+
if isinstance(value, tuple):
141+
raw = value
142+
value = []
143+
for v in raw:
144+
if isinstance(v, Enum):
145+
value.append(v.name)
146+
elif isinstance(v, Angle):
147+
value.append(float(v))
148+
else:
149+
value.append(v)
150+
elif isinstance(value, Enum):
151+
value = value.name
152+
153+
settings["options"][option] = value
154+
155+
output_options.append(settings)
156+
157+
return {
19158
"protocol": "geocom",
20-
"settings": []
159+
"settings": output_options
21160
}
22161

23-
return data
24-
25162

26163
def download_settings_gsidna(
27164
dna: GsiOnlineDNA,
@@ -87,6 +224,12 @@ def clean_settings(
87224
k: v for k, v in subsystem["options"].items() if v is not None
88225
}
89226

227+
settings["settings"] = [
228+
s
229+
for s in settings["settings"]
230+
if len(s["options"]) > 0
231+
]
232+
90233
return settings
91234

92235

0 commit comments

Comments
 (0)