LASP 1.0
Library for Acoustic Signal Processing
Loading...
Searching...
No Matches
lasp_daqconfigs.py
Go to the documentation of this file.
1# -*- coding: utf-8 -*-
2from .lasp_cpp import DaqConfiguration, LASP_VERSION_MAJOR
3
4"""!
5Author: J.A. de Jong - ASCEE
6
7Description:
8
9Data Acquistiion (DAQ) device descriptors, and the DAQ devices themselves
10
11"""
12__all__ = ["DaqConfigurations"]
13import json
14
15from .lasp_common import Qty, SIQtys, lasp_shelve
16from .lasp_cpp import DaqChannel, DaqConfiguration
17
18
20 """
21 DaqConfigurations stores a set containing an input configuration and an
22 output configuration.
23 """
24
26 self,
27 duplex_mode: bool,
28 input_config: DaqConfiguration,
29 output_config: DaqConfiguration,
30 ):
31 """
32 Initialize set of DaqConfigurations.
33
34 Args:
35 duplex_mode: If true, the input configuration is used for output as
36 well. This makes only sense when the device is capable of having
37 simultaneous input / output.
38 input_config: The configuration settings for the input
39 output_config: The configuration settoutgs for the output
40 """
41
42 self.input_config = input_config
43 self.output_config = output_config
44 self.duplex_mode = duplex_mode
45
46 @staticmethod
47 def getNames():
48 """
49 Get a list of all names of DaqConfigurations sets.
50
51 Returns:
52 list of names
53
54 """
55 with lasp_shelve() as sh:
56 configs_ser = sh.load(f"daqconfigs_v{LASP_VERSION_MAJOR}", {})
57 return list(configs_ser.keys())
58
59 @staticmethod
60 def loadAll():
61 """
62 Returns a dictionary of all configurations presets. The dictionary keys
63 are the names of the configurations
64
65 Returns:
66 all configurations, as a dictionary
67
68 """
69 with lasp_shelve() as sh:
70 configs_ser = sh.load(f"daqconfigs_v{LASP_VERSION_MAJOR}", {})
71 configs = {}
72 for name, val in configs_ser.items():
73 configs[name] = DaqConfigurations.load(name)
74 return configs
75
76 @staticmethod
77 def load(name: str):
78 """
79 Load a single configuration preset, containing input config and output config
80
81 Args:
82 name: The name of the configuration to load.
83
84 """
85
86 with lasp_shelve() as sh:
87 configs_str = sh.load(f"daqconfigs_v{LASP_VERSION_MAJOR}", {})
88 config_str = configs_str[name]
89
90 duplex_mode = config_str[0]
91 input_config = DaqConfiguration.fromTOML(config_str[1])
92 output_config = DaqConfiguration.fromTOML(config_str[2])
93 return DaqConfigurations(duplex_mode, input_config, output_config)
94
95 @staticmethod
96 def loadRaw():
97 """
98 Returns configurations presets in the raw form they are stored.
99
100 Returns:
101 all configurations, raw
102 """
103 with lasp_shelve() as sh:
104 configs_raw = sh.load(f"daqconfigs_v{LASP_VERSION_MAJOR}", {})
105 return configs_raw
106
107 def save(self, name: str):
108 """
109 Save the current set of configurations to the shelve store.
110
111 Args:
112 name: The name of the configuration set.
113 """
114 with lasp_shelve() as sh:
115
116 # Convert to TOML
117 input_str = self.input_config.toTOML()
118 output_str = self.output_config.toTOML()
119
120 configs_str = sh.load(f"daqconfigs_v{LASP_VERSION_MAJOR}", {})
121 configs_str[name] = [self.duplex_mode, input_str, output_str]
122 sh.store(f"daqconfigs_v{LASP_VERSION_MAJOR}", configs_str)
123
124 @staticmethod
125 def saveRaw(configs_raw):
126 """
127 Save configurations presets, using already formatted data
128
129 Arg:
130 all configurations, raw data format in form they are stored
131 """
132 with lasp_shelve() as sh:
133 sh.store(f"daqconfigs_v{LASP_VERSION_MAJOR}", configs_raw)
134
135 @staticmethod
136 def delete(name: str):
137 """
138 Delete a DaqConfigurations set from the store.
139
140 """
141 with lasp_shelve() as sh:
142 configs_str = sh.load(f"daqconfigs_v{LASP_VERSION_MAJOR}", {})
143 del configs_str[name]
144 sh.store(f"daqconfigs_v{LASP_VERSION_MAJOR}", configs_str)
static DaqConfiguration fromTOML(const std::string &toml)
Load in a DAQConfiguration from TOML.
DaqConfigurations stores a set containing an input configuration and an output configuration.
__init__(self, bool duplex_mode, DaqConfiguration input_config, DaqConfiguration output_config)
Initialize set of DaqConfigurations.
loadAll()
Returns a dictionary of all configurations presets.
save(self, str name)
Save the current set of configurations to the shelve store.
load(str name)
Load a single configuration preset, containing input config and output config.
saveRaw(configs_raw)
Save configurations presets, using already formatted data.
loadRaw()
Returns configurations presets in the raw form they are stored.
delete(str name)
Delete a DaqConfigurations set from the store.
getNames()
Get a list of all names of DaqConfigurations sets.