etho-python 0.23.0__py3-none-any.whl → 1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
etho/client.py CHANGED
@@ -1,10 +1,8 @@
1
- import time
2
- import numpy as np
3
- import logging
4
- from itertools import cycle
5
- from rich.progress import Progress
6
- import rich
7
- import threading
1
+ import time
2
+ import logging
3
+ from rich.progress import Progress
4
+ import rich
5
+ import threading
8
6
  import _thread as thread
9
7
  import queue
10
8
  from typing import Optional, Union, Dict, Any
@@ -13,13 +11,8 @@ import psutil
13
11
  from .utils.tui import rich_information
14
12
 
15
13
  from . import config
16
- from .utils.config import defaultify, readconfig, undefaultify
17
- from .utils.sound import parse_table, load_sounds, build_playlist
18
-
19
- from .services.GOVZeroService import GOV
20
- from .services.DAQZeroService import DAQ
21
- from .services.GCMZeroService import GCM
22
- from .services.NICounterZeroService import NIC
14
+ from . import services as service_module
15
+ from .utils.config import defaultify, readconfig
23
16
 
24
17
 
25
18
  def timed(fn, s, *args, **kwargs):
@@ -59,6 +52,71 @@ def _reject_remote_host_blocks(prot: Dict[str, Any]) -> None:
59
52
  raise ValueError(f"Remote service hosts are no longer supported. Remove the 'host' block from: {services}.")
60
53
 
61
54
 
55
+ def _setup_services(prot, defaults, playlistfile, save_prefix, preview, new_console):
56
+ services = {}
57
+ service_classes = {}
58
+ service_counts = {}
59
+
60
+ for service_name in prot["use_services"]:
61
+ service_class = service_module.service_class_for(service_name)
62
+ service_type = service_class.SERVICE_NAME
63
+ service_index = service_counts.get(service_type, 0)
64
+ service_counts[service_type] = service_index + 1
65
+
66
+ service = service_class.setup_client(
67
+ service_name,
68
+ service_index,
69
+ prot,
70
+ defaults,
71
+ playlistfile,
72
+ save_prefix,
73
+ preview,
74
+ new_console,
75
+ )
76
+ if service is None:
77
+ continue
78
+
79
+ services[service_name] = service
80
+ service_classes[service_name] = service_class
81
+
82
+ return services, service_classes
83
+
84
+
85
+ def _start_services(services, service_classes):
86
+ logging.info("Starting services")
87
+
88
+ start_groups = {service_name: getattr(service_classes[service_name], "CLIENT_START_GROUP", "pre") for service_name in services}
89
+ started_groups = set()
90
+ time_last_prereq_started = time.time()
91
+
92
+ def start_group(group):
93
+ nonlocal time_last_prereq_started
94
+ started_groups.add(group)
95
+ for service_name, service in services.items():
96
+ if start_groups[service_name] != group:
97
+ continue
98
+ logging.info(f" {service_name}.")
99
+ service.start()
100
+ if group in {"pre", "trigger"}:
101
+ time_last_prereq_started = time.time()
102
+
103
+ start_group("pre")
104
+ time.sleep(0.5)
105
+ start_group("trigger")
106
+
107
+ if "daq" in start_groups.values():
108
+ wait_remaining = 5 - (time.time() - time_last_prereq_started)
109
+ if wait_remaining > 0:
110
+ time.sleep(wait_remaining)
111
+ start_group("daq")
112
+
113
+ for group in start_groups.values():
114
+ if group not in started_groups:
115
+ start_group(group)
116
+
117
+ logging.info("All services started.")
118
+
119
+
62
120
  def client(
63
121
  protocolfile: Optional[str],
64
122
  playlistfile: Optional[str] = None,
@@ -112,201 +170,13 @@ def client(
112
170
 
113
171
  new_console = debug
114
172
 
115
- services = {}
116
- if "GOV" in prot["use_services"] and not preview:
117
- this = defaults.copy()
118
-
119
- if prot["GOV"].get("port") is None:
120
- prot["GOV"]["port"] = GOV.SERVICE_PORT
121
-
122
- interval = prot["GOV"].get("interval")
123
- if interval is None:
124
- interval = 60
125
-
126
- gov = GOV.make(
127
- this["serializer"],
128
- this["host"],
129
- this["python_exe"],
130
- port=prot["GOV"]["port"],
131
- )
132
- gov.setup(prot["GOV"]["address"], interval, prot["maxduration"] + 10)
133
- gov.init_local_logger(f"{this['savefolder']}/{save_prefix}/{save_prefix}_gov.log")
134
- services["GOV"] = gov
135
-
136
- gcm_keys = [key for key in prot["use_services"] if "GCM" in key]
137
- for gcm_cnt, gcm_key in enumerate(gcm_keys):
138
- # if gcm_key in prot["use_services"] and gcm_key in prot:
139
- this = defaults.copy()
140
- this.update(prot[gcm_key])
141
-
142
- if "port" not in prot[gcm_key]:
143
- prot[gcm_key]["port"] = GCM.SERVICE_PORT + gcm_cnt
144
- gcm = GCM.make(
145
- this["serializer"],
146
- this["host"],
147
- this["python_exe"],
148
- new_console=new_console,
149
- port=prot[gcm_key]["port"],
150
- )
151
-
152
- cam_params = undefaultify(prot[gcm_key])
153
- if not preview:
154
- maxduration = prot["maxduration"] + 10
155
- else:
156
- maxduration = 1_000_000
157
-
158
- if preview:
159
- cam_params["callbacks"] = {"disp_fast": None}
160
-
161
- save_suffix = f"_{gcm_cnt + 1}" if gcm_cnt > 0 else ""
162
- gcm.setup(
163
- f"{this['savefolder']}/{save_prefix}/{save_prefix}{save_suffix}",
164
- maxduration,
165
- cam_params,
166
- )
167
-
168
- if not preview:
169
- gcm.init_local_logger(f"{this['savefolder']}/{save_prefix}/{save_prefix}{save_suffix}_gcm.log")
170
- services[gcm_key] = gcm
171
-
172
- daq_keys = [key for key in prot["use_services"] if "DAQ" in key]
173
- daq_keys = [] if preview else daq_keys
174
- for daq_cnt, daq_key in enumerate(daq_keys):
175
- this = defaults.copy()
176
- this.update(prot[daq_key])
177
-
178
- if "device" not in prot[daq_key]:
179
- prot[daq_key]["device"] = "Dev1"
180
-
181
- if "port" not in prot[daq_key]:
182
- prot[daq_key]["port"] = DAQ.SERVICE_PORT + daq_cnt
183
-
184
- if this["host"] in config["ATTENUATION"]: # use node specific attenuation data
185
- attenuation = config["ATTENUATION"][this["host"]]
186
- logging.info(f"Using attenuation data specific to {this['host']}.")
187
- else:
188
- attenuation = config["ATTENUATION"]
189
-
190
- # Load/generate all stimuli specified in playlist
191
- fs = prot[daq_key]["samplingrate"]
192
- playlist = parse_table(playlistfile)
193
- sounds = load_sounds(
194
- playlist,
195
- fs,
196
- attenuation=attenuation,
197
- LEDamp=prot[daq_key]["ledamp"],
198
- stimfolder=config["stimfolder"],
199
- )
200
- sounds = [sound.astype(np.float64) for sound in sounds]
201
-
202
- # Generate stimulus sequence (shuffle, loop playlist)
203
- playlist_items, totallen = build_playlist(sounds, prot["maxduration"], fs, shuffle=prot[daq_key]["shuffle"])
204
- if prot["maxduration"] == -1:
205
- logging.info(f"Setting maxduration from playlist to {totallen}.")
206
- prot["maxduration"] = totallen
207
- playlist_items = cycle(playlist_items) # iter(playlist_items)
208
- else:
209
- playlist_items = cycle(playlist_items)
210
-
211
- # split analog and digital outputs
212
- # TODO: catch errors if channel numbers are inconsistent - sounds[ii].shape[-1] should be nb_analog+nb_digital
213
- if prot[daq_key]["digital_chans_out"] is not None:
214
- nb_digital_chans_out = len(prot[daq_key]["digital_chans_out"])
215
- digital_data = [snd[:, -nb_digital_chans_out:].astype(np.uint8) for snd in sounds]
216
- analog_data = [snd[:, :-nb_digital_chans_out] for snd in sounds] # remove digital traces from stimset
217
- else:
218
- digital_data = None
219
- analog_data = sounds
220
-
221
- daq = DAQ.make(
222
- this["serializer"],
223
- this["host"],
224
- this["python_exe"],
225
- new_console=new_console,
226
- port=prot[daq_key]["port"],
227
- )
228
- save_suffix = f"_{daq_cnt + 1}" if daq_cnt > 0 else ""
229
- daq.setup(
230
- f"{this['savefolder']}/{save_prefix}/{save_prefix}{save_suffix}",
231
- playlist_items,
232
- playlist,
233
- prot["maxduration"],
234
- fs,
235
- dev_name=prot[daq_key]["device"],
236
- clock_source=prot[daq_key]["clock_source"],
237
- nb_inputsamples_per_cycle=prot[daq_key]["nb_inputsamples_per_cycle"],
238
- analog_chans_in=prot[daq_key]["analog_chans_in"],
239
- # analog_chans_in_limits=None,
240
- # analog_chans_in_terminals=None,
241
- analog_chans_out=prot[daq_key]["analog_chans_out"],
242
- # analog_chans_out_limits=None,
243
- analog_data_out=analog_data,
244
- digital_chans_out=prot[daq_key]["digital_chans_out"],
245
- digital_data_out=digital_data,
246
- metadata={
247
- "analog_chans_in_info": prot[daq_key]["analog_chans_in_info"],
248
- "analog_chans_out_info": prot[daq_key]["analog_chans_out_info"],
249
- "digitial_chans_out_info": prot[daq_key]["digitial_chans_out_info"],
250
- },
251
- params=undefaultify(prot[daq_key]),
252
- )
253
- daq.init_local_logger(f"{this['savefolder']}/{save_prefix}/{save_prefix}{save_suffix}_daq.log")
254
- services[daq_key] = daq
255
-
256
- if "NIC" in prot["use_services"]:
257
- this = defaults.copy()
258
- this.update(prot["NIC"])
259
-
260
- nic = NIC.make(
261
- this["serializer"],
262
- this["host"],
263
- this["python_exe"],
264
- new_console=new_console,
265
- port=prot["NIC"]["port"],
266
- )
267
-
268
- nic_params = undefaultify(prot["NIC"])
269
- nic.setup(
270
- nic_params["output_channel"],
271
- prot["maxduration"] + 10,
272
- nic_params["frequency"],
273
- nic_params["duty_cycle"],
274
- nic_params,
275
- )
276
- nic.init_local_logger(f"{this['savefolder']}/{save_prefix}/{save_prefix}{save_suffix}_daq.log")
173
+ services, service_classes = _setup_services(prot, defaults, playlistfile, save_prefix, preview, new_console)
277
174
 
278
175
  # display config info
279
176
  for key, s in services.items():
280
177
  rich_information(s.information(), prefix=key)
281
178
 
282
- logging.info("Starting services")
283
- # First, start video services - this will start acquisition or, if external triggering is enabled, arm the cameras to wait for the triggers
284
- time_last_cam_started = time.time() + 5 # in case no cam was initialized
285
- for service_name, service in services.items():
286
- if "GCM" in service_name or "GOV" in service_name:
287
- logging.info(f" {service_name}.")
288
- service.start()
289
- time_last_cam_started = time.time()
290
- time.sleep(0.5)
291
-
292
- # start the counter task for triggering frames
293
- if "NIC" in prot["use_services"]:
294
- logging.info(" NI Counter service.")
295
- nic.start()
296
- time_last_cam_started = time.time()
297
-
298
- # Wait 5 seconds for cams to run
299
- if daq_keys:
300
- while time.time() - time_last_cam_started < 5:
301
- time.sleep(0.1)
302
-
303
- # Start DAQ services
304
- for service_name, service in services.items():
305
- if "DAQ" in service_name:
306
- logging.info(f" {service_name}.")
307
- service.start()
308
-
309
- logging.info("All services started.")
179
+ _start_services(services, service_classes)
310
180
 
311
181
  if monitor or show_progress:
312
182
  total = 0
@@ -1,12 +1,14 @@
1
- from .ZeroService import BaseZeroService # import super class
2
- import time
3
- import threading
4
- import logging
5
- import defopt
6
- from typing import Optional
7
-
8
- from .utils.log_exceptions import for_all_methods, log_exceptions
9
- from .utils.concurrent_task import Pipe
1
+ from .ZeroService import BaseZeroService # import super class
2
+ import time
3
+ import threading
4
+ import logging
5
+ import defopt
6
+ from typing import Optional
7
+
8
+ from . import register_service
9
+ from .utils.log_exceptions import for_all_methods, log_exceptions
10
+ from .utils.concurrent_task import Pipe
11
+ from ..utils.config import undefaultify
10
12
 
11
13
  try:
12
14
  from pybmt.callback.threshold_callback import ThresholdCallback
@@ -17,16 +19,40 @@ try:
17
19
  except ImportError as pybmt_error:
18
20
  pass
19
21
 
20
- # decorate all methods in the class so that exceptions are properly logged
21
- @for_all_methods(log_exceptions(logging.getLogger(__name__)))
22
- class BLT(BaseZeroService):
23
-
24
- LOGGING_PORT = 1452 # set this to range 1420-1460
25
- SERVICE_PORT = 4252 # last two digits match logging port - but start with "42" instead of "14"
26
- SERVICE_NAME = "BLT" # short, uppercase, 3-letter ID of the service (must equal class name)
27
-
28
- def setup(self, savefilename, duration, params):
29
- if pybmt_error is not None:
22
+ # decorate all methods in the class so that exceptions are properly logged
23
+ @for_all_methods(log_exceptions(logging.getLogger(__name__)))
24
+ @register_service
25
+ class BLT(BaseZeroService):
26
+
27
+ LOGGING_PORT = 1452 # set this to range 1420-1460
28
+ SERVICE_PORT = 4252 # last two digits match logging port - but start with "42" instead of "14"
29
+ SERVICE_NAME = "BLT" # short, uppercase, 3-letter ID of the service (must equal class name)
30
+ CLIENT_START_GROUP = "pre"
31
+
32
+ @classmethod
33
+ def setup_client(cls, service_key, service_index, prot, defaults, playlistfile, save_prefix, preview, new_console):
34
+ this = defaults.copy()
35
+ this.update(prot[service_key])
36
+
37
+ if prot[service_key].get("port") is None:
38
+ prot[service_key]["port"] = cls.SERVICE_PORT + service_index
39
+
40
+ service = cls.make(
41
+ this["serializer"],
42
+ this["host"],
43
+ this["python_exe"],
44
+ new_console=new_console,
45
+ port=prot[service_key]["port"],
46
+ )
47
+
48
+ params = undefaultify(prot[service_key])
49
+ save_suffix = f"_{service_index + 1}" if service_index > 0 else ""
50
+ service.setup(f"{this['savefolder']}/{save_prefix}/{save_prefix}{save_suffix}", prot["maxduration"], params)
51
+ service.init_local_logger(f"{this['savefolder']}/{save_prefix}/{save_prefix}{save_suffix}_{service_key.lower()}.log")
52
+ return service
53
+
54
+ def setup(self, savefilename, duration, params):
55
+ if pybmt_error is not None:
30
56
  raise pybmt_error
31
57
  self.log.info("setup")
32
58
  self._time_started = None
@@ -1,13 +1,18 @@
1
- from .ZeroService import BaseZeroService
2
- import time
3
- import threading
4
- import sys
5
- import copy
6
- from typing import Iterable, Sequence, Optional, Dict, Any
7
- from .utils.log_exceptions import for_all_methods, log_exceptions
8
- from .callbacks import callbacks
9
- import logging
10
- import numpy as np
1
+ from .ZeroService import BaseZeroService
2
+ import time
3
+ import threading
4
+ import sys
5
+ import copy
6
+ from itertools import cycle
7
+ from typing import Iterable, Sequence, Optional, Dict, Any
8
+ from . import register_service
9
+ from .. import config as global_config
10
+ from ..utils.config import undefaultify
11
+ from ..utils.sound import parse_table, load_sounds, build_playlist
12
+ from .utils.log_exceptions import for_all_methods, log_exceptions
13
+ from .callbacks import callbacks
14
+ import logging
15
+ import numpy as np
11
16
 
12
17
  daqmx_import_error = None
13
18
  try:
@@ -18,16 +23,95 @@ except (ImportError, NameError, NotImplementedError) as daqmx_import_error:
18
23
  pass
19
24
 
20
25
 
21
- @for_all_methods(log_exceptions(logging.getLogger(__name__)))
22
- class DAQ(BaseZeroService):
23
- """Bundles and synchronizes analog/digital input and output tasks."""
24
-
25
- LOGGING_PORT = 1449 # set this to range 1420-1460
26
- SERVICE_PORT = 4249 # last to digits match logging port - but start with "42" instead of "14"
27
- SERVICE_NAME = "DAQ" # short, uppercase, 3-letter ID of the service (equals class name)
28
-
29
- def setup(
30
- self,
26
+ @for_all_methods(log_exceptions(logging.getLogger(__name__)))
27
+ @register_service
28
+ class DAQ(BaseZeroService):
29
+ """Bundles and synchronizes analog/digital input and output tasks."""
30
+
31
+ LOGGING_PORT = 1449 # set this to range 1420-1460
32
+ SERVICE_PORT = 4249 # last to digits match logging port - but start with "42" instead of "14"
33
+ SERVICE_NAME = "DAQ" # short, uppercase, 3-letter ID of the service (equals class name)
34
+ CLIENT_START_GROUP = "daq"
35
+
36
+ @classmethod
37
+ def setup_client(cls, service_key, service_index, prot, defaults, playlistfile, save_prefix, preview, new_console):
38
+ if preview:
39
+ return None
40
+
41
+ this = defaults.copy()
42
+ this.update(prot[service_key])
43
+
44
+ if prot[service_key].get("device") is None:
45
+ prot[service_key]["device"] = "Dev1"
46
+
47
+ if prot[service_key].get("port") is None:
48
+ prot[service_key]["port"] = cls.SERVICE_PORT + service_index
49
+
50
+ if this["host"] in global_config["ATTENUATION"]:
51
+ attenuation = global_config["ATTENUATION"][this["host"]]
52
+ logging.info(f"Using attenuation data specific to {this['host']}.")
53
+ else:
54
+ attenuation = global_config["ATTENUATION"]
55
+
56
+ fs = prot[service_key]["samplingrate"]
57
+ playlist = parse_table(playlistfile)
58
+ sounds = load_sounds(
59
+ playlist,
60
+ fs,
61
+ attenuation=attenuation,
62
+ LEDamp=prot[service_key]["ledamp"],
63
+ stimfolder=global_config["stimfolder"],
64
+ )
65
+ sounds = [sound.astype(np.float64) for sound in sounds]
66
+
67
+ playlist_items, totallen = build_playlist(sounds, prot["maxduration"], fs, shuffle=prot[service_key]["shuffle"])
68
+ if prot["maxduration"] == -1:
69
+ logging.info(f"Setting maxduration from playlist to {totallen}.")
70
+ prot["maxduration"] = totallen
71
+ playlist_items = cycle(playlist_items)
72
+
73
+ if prot[service_key]["digital_chans_out"] is not None:
74
+ nb_digital_chans_out = len(prot[service_key]["digital_chans_out"])
75
+ digital_data = [snd[:, -nb_digital_chans_out:].astype(np.uint8) for snd in sounds]
76
+ analog_data = [snd[:, :-nb_digital_chans_out] for snd in sounds]
77
+ else:
78
+ digital_data = None
79
+ analog_data = sounds
80
+
81
+ service = cls.make(
82
+ this["serializer"],
83
+ this["host"],
84
+ this["python_exe"],
85
+ new_console=new_console,
86
+ port=prot[service_key]["port"],
87
+ )
88
+ save_suffix = f"_{service_index + 1}" if service_index > 0 else ""
89
+ service.setup(
90
+ f"{this['savefolder']}/{save_prefix}/{save_prefix}{save_suffix}",
91
+ playlist_items,
92
+ playlist,
93
+ prot["maxduration"],
94
+ fs,
95
+ dev_name=prot[service_key]["device"],
96
+ clock_source=prot[service_key]["clock_source"],
97
+ nb_inputsamples_per_cycle=prot[service_key]["nb_inputsamples_per_cycle"],
98
+ analog_chans_in=prot[service_key]["analog_chans_in"],
99
+ analog_chans_out=prot[service_key]["analog_chans_out"],
100
+ analog_data_out=analog_data,
101
+ digital_chans_out=prot[service_key]["digital_chans_out"],
102
+ digital_data_out=digital_data,
103
+ metadata={
104
+ "analog_chans_in_info": prot[service_key]["analog_chans_in_info"],
105
+ "analog_chans_out_info": prot[service_key]["analog_chans_out_info"],
106
+ "digitial_chans_out_info": prot[service_key]["digitial_chans_out_info"],
107
+ },
108
+ params=undefaultify(prot[service_key]),
109
+ )
110
+ service.init_local_logger(f"{this['savefolder']}/{save_prefix}/{save_prefix}{save_suffix}_daq.log")
111
+ return service
112
+
113
+ def setup(
114
+ self,
31
115
  savefilename: str = None,
32
116
  play_order: Iterable = None,
33
117
  playlist_info=None,
@@ -1,12 +1,14 @@
1
- #!/usr/bin/env python
2
- from .ZeroService import BaseZeroService # import super class
3
- import time # for timer
4
- import threading
5
- from .utils.log_exceptions import for_all_methods, log_exceptions
6
- from .dlp import dlp_runners
7
- import logging
8
- import defopt
9
- from typing import Optional
1
+ #!/usr/bin/env python
2
+ from .ZeroService import BaseZeroService # import super class
3
+ import time # for timer
4
+ import threading
5
+ from . import register_service
6
+ from .utils.log_exceptions import for_all_methods, log_exceptions
7
+ from .dlp import dlp_runners
8
+ from ..utils.config import undefaultify
9
+ import logging
10
+ import defopt
11
+ from typing import Optional
10
12
 
11
13
  try:
12
14
  import pycrafter4500
@@ -20,16 +22,41 @@ except ImportError as dlp_import_error:
20
22
  pass
21
23
 
22
24
 
23
- # decorate all methods in the class so that exceptions are properly logged
24
- @for_all_methods(log_exceptions(logging.getLogger(__name__)))
25
- class DLP(BaseZeroService):
26
-
27
- LOGGING_PORT = 1453 # set this to range 1420-1460
28
- SERVICE_PORT = 4253 # last two digits match logging port - but start with "42" instead of "14"
29
- SERVICE_NAME = "DLP" # short, uppercase, 3-letter ID of the service (must equal class name)
30
-
31
- def setup(self, duration, logfilename, params=None):
32
- if dlp_import_error is not None:
25
+ # decorate all methods in the class so that exceptions are properly logged
26
+ @for_all_methods(log_exceptions(logging.getLogger(__name__)))
27
+ @register_service
28
+ class DLP(BaseZeroService):
29
+
30
+ LOGGING_PORT = 1453 # set this to range 1420-1460
31
+ SERVICE_PORT = 4253 # last two digits match logging port - but start with "42" instead of "14"
32
+ SERVICE_NAME = "DLP" # short, uppercase, 3-letter ID of the service (must equal class name)
33
+ CLIENT_START_GROUP = "pre"
34
+
35
+ @classmethod
36
+ def setup_client(cls, service_key, service_index, prot, defaults, playlistfile, save_prefix, preview, new_console):
37
+ this = defaults.copy()
38
+ this.update(prot[service_key])
39
+
40
+ if prot[service_key].get("port") is None:
41
+ prot[service_key]["port"] = cls.SERVICE_PORT + service_index
42
+
43
+ service = cls.make(
44
+ this["serializer"],
45
+ this["host"],
46
+ this["python_exe"],
47
+ new_console=new_console,
48
+ port=prot[service_key]["port"],
49
+ )
50
+
51
+ params = undefaultify(prot[service_key])
52
+ save_suffix = f"_{service_index + 1}" if service_index > 0 else ""
53
+ savefilename = f"{this['savefolder']}/{save_prefix}/{save_prefix}{save_suffix}"
54
+ service.setup(prot["maxduration"], savefilename, params)
55
+ service.init_local_logger(f"{this['savefolder']}/{save_prefix}/{save_prefix}{save_suffix}_{service_key.lower()}.log")
56
+ return service
57
+
58
+ def setup(self, duration, logfilename, params=None):
59
+ if dlp_import_error is not None:
33
60
  raise dlp_import_error
34
61
 
35
62
  self._time_started = None
@@ -1,24 +1,61 @@
1
- from .ZeroService import BaseZeroService
2
- import time
3
- import threading
4
- import sys
5
- from .utils.log_exceptions import for_all_methods, log_exceptions
6
- import logging
7
- from ..services import camera
8
- from .callbacks import callbacks
1
+ from .ZeroService import BaseZeroService
2
+ import time
3
+ import threading
4
+ import sys
5
+ from . import register_service
6
+ from .utils.log_exceptions import for_all_methods, log_exceptions
7
+ import logging
8
+ from ..services import camera
9
+ from ..utils.config import undefaultify
10
+ from .callbacks import callbacks
9
11
 
10
12
 
11
13
  logger = logging.getLogger(__name__)
12
14
 
13
15
 
14
- @for_all_methods(log_exceptions(logger))
15
- class GCM(BaseZeroService):
16
- LOGGING_PORT = 1446 # set this to range 1420-1460
17
- SERVICE_PORT = 4246 # last to digits match logging port - but start with "42" instead of "14"
18
- SERVICE_NAME = "GCM" # short, uppercase, 3-letter ID of the service (equals class name)
19
-
20
- def setup(self, savefilename, duration, params):
21
- self._time_started = None
16
+ @for_all_methods(log_exceptions(logger))
17
+ @register_service
18
+ class GCM(BaseZeroService):
19
+ LOGGING_PORT = 1446 # set this to range 1420-1460
20
+ SERVICE_PORT = 4246 # last to digits match logging port - but start with "42" instead of "14"
21
+ SERVICE_NAME = "GCM" # short, uppercase, 3-letter ID of the service (equals class name)
22
+ CLIENT_START_GROUP = "pre"
23
+
24
+ @classmethod
25
+ def setup_client(cls, service_key, service_index, prot, defaults, playlistfile, save_prefix, preview, new_console):
26
+ this = defaults.copy()
27
+ this.update(prot[service_key])
28
+
29
+ if prot[service_key].get("port") is None:
30
+ prot[service_key]["port"] = cls.SERVICE_PORT + service_index
31
+
32
+ service = cls.make(
33
+ this["serializer"],
34
+ this["host"],
35
+ this["python_exe"],
36
+ new_console=new_console,
37
+ port=prot[service_key]["port"],
38
+ )
39
+
40
+ params = undefaultify(prot[service_key])
41
+ duration = 1_000_000 if preview else prot["maxduration"] + 10
42
+
43
+ if preview:
44
+ params["callbacks"] = {"disp_fast": None}
45
+
46
+ save_suffix = f"_{service_index + 1}" if service_index > 0 else ""
47
+ service.setup(
48
+ f"{this['savefolder']}/{save_prefix}/{save_prefix}{save_suffix}",
49
+ duration,
50
+ params,
51
+ )
52
+
53
+ if not preview:
54
+ service.init_local_logger(f"{this['savefolder']}/{save_prefix}/{save_prefix}{save_suffix}_gcm.log")
55
+ return service
56
+
57
+ def setup(self, savefilename, duration, params):
58
+ self._time_started = None
22
59
  self.duration = duration
23
60
  self.savefilename = savefilename
24
61
  self.c = None