etho-python 1.0__py3-none-any.whl → 1.2__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/app.py +235 -242
- etho/cli.py +72 -19
- etho/res_app.py +225 -0
- etho/resumable.py +283 -0
- etho/services/DAQZeroService.py +1 -2
- etho/services/GCMZeroService.py +6 -2
- etho/services/GOVZeroService.py +31 -0
- etho/services/NICounterZeroService.py +80 -73
- etho/services/resumable.py +476 -0
- etho/utils/sound.py +62 -98
- {etho_python-1.0.dist-info → etho_python-1.2.dist-info}/METADATA +48 -21
- {etho_python-1.0.dist-info → etho_python-1.2.dist-info}/RECORD +15 -11
- etho_python-1.2.dist-info/licenses/LICENSE +21 -0
- {etho_python-1.0.dist-info → etho_python-1.2.dist-info}/WHEEL +0 -0
- {etho_python-1.0.dist-info → etho_python-1.2.dist-info}/entry_points.txt +0 -0
etho/services/GOVZeroService.py
CHANGED
|
@@ -67,6 +67,37 @@ def format_measurement_log_line(measurement: H5075Measurement) -> str:
|
|
|
67
67
|
return f"{measurement.timestamp:%Y-%m-%d %H:%M:%S},{measurement.temperature_c:.1f},{measurement.humidity:.1f}"
|
|
68
68
|
|
|
69
69
|
|
|
70
|
+
async def discover_h5075_sensors(duration: float = 10.0):
|
|
71
|
+
"""Return nearby H5075 addresses, names, and latest measurements."""
|
|
72
|
+
if bleak_import_error is not None:
|
|
73
|
+
raise bleak_import_error
|
|
74
|
+
|
|
75
|
+
duration = float(duration)
|
|
76
|
+
if duration <= 0:
|
|
77
|
+
raise ValueError("duration must be > 0")
|
|
78
|
+
|
|
79
|
+
sensors = {}
|
|
80
|
+
|
|
81
|
+
def detection_callback(device: BLEDevice, advertisement_data: AdvertisementData):
|
|
82
|
+
address = getattr(device, "address", None)
|
|
83
|
+
payload = advertisement_data.manufacturer_data.get(H5075_MANUFACTURER_ID)
|
|
84
|
+
if address is None or payload is None:
|
|
85
|
+
return
|
|
86
|
+
|
|
87
|
+
try:
|
|
88
|
+
measurement = decode_h5075_measurement(payload)
|
|
89
|
+
except ValueError:
|
|
90
|
+
return
|
|
91
|
+
|
|
92
|
+
name = getattr(advertisement_data, "local_name", None) or getattr(device, "name", None) or ""
|
|
93
|
+
sensors[normalize_address(address)] = (name, measurement)
|
|
94
|
+
|
|
95
|
+
async with BleakScanner(detection_callback=detection_callback):
|
|
96
|
+
await asyncio.sleep(duration)
|
|
97
|
+
|
|
98
|
+
return sorted((address, name, measurement) for address, (name, measurement) in sensors.items())
|
|
99
|
+
|
|
100
|
+
|
|
70
101
|
@for_all_methods(log_exceptions(logging.getLogger(__name__)))
|
|
71
102
|
@register_service
|
|
72
103
|
class GOV(BaseZeroService):
|
|
@@ -1,64 +1,73 @@
|
|
|
1
|
-
from .ZeroService import BaseZeroService
|
|
2
|
-
import time
|
|
3
|
-
import sys
|
|
4
|
-
import numpy as np
|
|
5
|
-
from . import register_service
|
|
6
|
-
from .utils.log_exceptions import for_all_methods, log_exceptions
|
|
7
|
-
from ..utils.config import undefaultify
|
|
8
|
-
import logging
|
|
9
|
-
import threading
|
|
1
|
+
from .ZeroService import BaseZeroService
|
|
2
|
+
import time
|
|
3
|
+
import sys
|
|
4
|
+
import numpy as np
|
|
5
|
+
from . import register_service
|
|
6
|
+
from .utils.log_exceptions import for_all_methods, log_exceptions
|
|
7
|
+
from ..utils.config import undefaultify
|
|
8
|
+
import logging
|
|
9
|
+
import threading
|
|
10
10
|
|
|
11
11
|
try:
|
|
12
12
|
import PyDAQmx as daq
|
|
13
|
+
|
|
13
14
|
pydaqmx_import_error = None
|
|
14
15
|
except (ImportError, NotImplementedError) as pydaqmx_import_error:
|
|
15
16
|
pass
|
|
16
17
|
|
|
17
18
|
|
|
18
|
-
@for_all_methods(log_exceptions(logging.getLogger(__name__)))
|
|
19
|
-
@register_service
|
|
20
|
-
class NIC(BaseZeroService):
|
|
21
|
-
"""
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
this["
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
params["
|
|
49
|
-
|
|
50
|
-
params,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
19
|
+
@for_all_methods(log_exceptions(logging.getLogger(__name__)))
|
|
20
|
+
@register_service
|
|
21
|
+
class NIC(BaseZeroService):
|
|
22
|
+
"""NI DAQmx Counter service for generating pulse trains via a digital output,
|
|
23
|
+
for instance as an external frame trigger for cameras.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
LOGGING_PORT = 1450 # set this to range 1420-1460
|
|
27
|
+
SERVICE_PORT = 4250 # last to digits match logging output_channels - but start with "42" instead of "14"
|
|
28
|
+
SERVICE_NAME = "NIC" # short, uppercase, 3-letter ID of the service (equals class name)
|
|
29
|
+
CLIENT_START_GROUP = "trigger"
|
|
30
|
+
|
|
31
|
+
@classmethod
|
|
32
|
+
def setup_client(cls, service_key, service_index, prot, defaults, playlistfile, save_prefix, preview, new_console):
|
|
33
|
+
this = defaults.copy()
|
|
34
|
+
this.update(prot[service_key])
|
|
35
|
+
|
|
36
|
+
if prot[service_key].get("port") is None:
|
|
37
|
+
prot[service_key]["port"] = cls.SERVICE_PORT + service_index
|
|
38
|
+
|
|
39
|
+
service = cls.make(
|
|
40
|
+
this["serializer"],
|
|
41
|
+
this["host"],
|
|
42
|
+
this["python_exe"],
|
|
43
|
+
new_console=new_console,
|
|
44
|
+
port=prot[service_key]["port"],
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
params = undefaultify(prot[service_key])
|
|
48
|
+
service.setup(
|
|
49
|
+
params["output_channel"],
|
|
50
|
+
prot["maxduration"] + 10,
|
|
51
|
+
params["frequency"],
|
|
52
|
+
params["duty_cycle"],
|
|
53
|
+
params,
|
|
54
|
+
)
|
|
55
|
+
save_suffix = f"_{service_index + 1}" if service_index > 0 else ""
|
|
56
|
+
service.init_local_logger(f"{this['savefolder']}/{save_prefix}/{save_prefix}{save_suffix}_nic.log")
|
|
57
|
+
return service
|
|
58
|
+
|
|
59
|
+
def setup(self, output_channel, duration, frequency, duty_cycle, params):
|
|
60
|
+
"""Setup the counter service (intiates the digital output channels).
|
|
58
61
|
|
|
59
62
|
Args:
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
output_channels (str): Digital output channel, e.g. "/dev1/port0/line0:1"
|
|
64
|
+
duration (float): Duration of the service.
|
|
65
|
+
frequency (float): Frequency of the pulse train in Hz.
|
|
66
|
+
duty_cycle (float): Duty cycle (pulse duration/period = duration * frequency) of the pulse train.
|
|
67
|
+
params (_type_): Unused.
|
|
68
|
+
|
|
69
|
+
Raises:
|
|
70
|
+
pydaqmx_import_error: Raised when the pydaqmx could not be imported.
|
|
62
71
|
"""
|
|
63
72
|
if pydaqmx_import_error is not None:
|
|
64
73
|
raise pydaqmx_import_error
|
|
@@ -71,22 +80,20 @@ class NIC(BaseZeroService):
|
|
|
71
80
|
self.task.CfgImplicitTiming(daq.DAQmx_Val_ContSamps, 1000)
|
|
72
81
|
|
|
73
82
|
if self.duration > 0: # if zero, will stop when nothing is to be outputted
|
|
74
|
-
self._thread_timer = threading.Timer(self.duration, self.finish, kwargs={
|
|
75
|
-
|
|
83
|
+
self._thread_timer = threading.Timer(self.duration, self.finish, kwargs={"stop_service": True})
|
|
76
84
|
|
|
77
85
|
def start(self):
|
|
78
86
|
self.task.StartTask()
|
|
79
|
-
self.log.warning(
|
|
87
|
+
self.log.warning("Started")
|
|
80
88
|
self._time_started = time.time()
|
|
81
|
-
if hasattr(self,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
if hasattr(self, "_thread_timer"):
|
|
90
|
+
self.log.warning(f"duration {self.duration} seconds")
|
|
91
|
+
self._thread_timer.start()
|
|
92
|
+
self.log.warning("finish timer started")
|
|
86
93
|
|
|
87
94
|
def stop(self):
|
|
88
95
|
self.task.StopTask()
|
|
89
|
-
self.log.warning(
|
|
96
|
+
self.log.warning("Stopped")
|
|
90
97
|
|
|
91
98
|
def finish(self, stop_service=False):
|
|
92
99
|
self.log.warning("stopping")
|
|
@@ -98,7 +105,7 @@ class NIC(BaseZeroService):
|
|
|
98
105
|
self.log.warning(" stopped ")
|
|
99
106
|
# mode log file and savefilename
|
|
100
107
|
if stop_service:
|
|
101
|
-
time.sleep(.2)
|
|
108
|
+
time.sleep(0.2)
|
|
102
109
|
self.service_stop()
|
|
103
110
|
return True
|
|
104
111
|
|
|
@@ -114,15 +121,15 @@ class NIC(BaseZeroService):
|
|
|
114
121
|
return True
|
|
115
122
|
|
|
116
123
|
|
|
117
|
-
if __name__ == "__main__":
|
|
118
|
-
if len(sys.argv) > 1:
|
|
119
|
-
ser = sys.argv[1]
|
|
120
|
-
else:
|
|
121
|
-
ser = "default"
|
|
122
|
-
if len(sys.argv) > 2:
|
|
123
|
-
port = sys.argv[2]
|
|
124
|
-
else:
|
|
125
|
-
port = NIC.SERVICE_PORT
|
|
126
|
-
s = NIC(serializer=ser)
|
|
127
|
-
s.bind("tcp://0.0.0.0:{0}".format(port)) # broadcast on all IPs
|
|
128
|
-
s.run()
|
|
124
|
+
if __name__ == "__main__":
|
|
125
|
+
if len(sys.argv) > 1:
|
|
126
|
+
ser = sys.argv[1]
|
|
127
|
+
else:
|
|
128
|
+
ser = "default"
|
|
129
|
+
if len(sys.argv) > 2:
|
|
130
|
+
port = sys.argv[2]
|
|
131
|
+
else:
|
|
132
|
+
port = NIC.SERVICE_PORT
|
|
133
|
+
s = NIC(serializer=ser)
|
|
134
|
+
s.bind("tcp://0.0.0.0:{0}".format(port)) # broadcast on all IPs
|
|
135
|
+
s.run()
|