2021-05-08 13:06:11 +00:00
|
|
|
#!/usr/bin/python3.8
|
2021-05-04 13:10:13 +00:00
|
|
|
import sys, logging, os, argparse
|
2021-05-08 13:06:11 +00:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description='Acquire data and store to a measurement file.'
|
|
|
|
)
|
|
|
|
parser.add_argument('filename', type=str,
|
|
|
|
help='File name to record to.'
|
|
|
|
' Extension is automatically added.')
|
|
|
|
parser.add_argument('--duration', '-d', type=float,
|
|
|
|
help='The recording duration in [s]')
|
2020-09-18 06:52:56 +00:00
|
|
|
|
2021-05-08 13:06:11 +00:00
|
|
|
device_help = 'DAQ Device to record from'
|
|
|
|
parser.add_argument('--input-daq', '-i', help=device_help, type=str,
|
|
|
|
default='Default')
|
|
|
|
parser.add_argument('--log', '-l',
|
|
|
|
help='Specify log level [info, debug, warning, ...]',
|
|
|
|
type=str, default='info')
|
2020-09-18 06:52:56 +00:00
|
|
|
|
|
|
|
|
2021-05-08 13:06:11 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
numeric_level = getattr(logging, args.log.upper(), None)
|
|
|
|
if not isinstance(numeric_level, int):
|
|
|
|
raise ValueError('Invalid log level: %s' % args.loglevel)
|
2021-05-13 19:35:51 +00:00
|
|
|
|
|
|
|
FORMAT = "[%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s"
|
2021-05-08 13:06:11 +00:00
|
|
|
logging.basicConfig(format=FORMAT, level=numeric_level)
|
2019-10-27 13:19:26 +00:00
|
|
|
|
2021-05-08 13:06:11 +00:00
|
|
|
import multiprocessing
|
|
|
|
from lasp.device import DaqConfigurations
|
|
|
|
from lasp import AvType, StreamManager, Recording# configureLogging
|
2019-10-27 13:19:26 +00:00
|
|
|
|
2021-05-08 13:06:11 +00:00
|
|
|
def main(args):
|
|
|
|
try:
|
|
|
|
streammgr = StreamManager()
|
2021-05-14 09:24:07 +00:00
|
|
|
configs = DaqConfigurations.loadAllConfigs()
|
2019-12-18 09:02:20 +00:00
|
|
|
|
2021-05-08 13:06:11 +00:00
|
|
|
config_keys = [key for key in configs.keys()]
|
|
|
|
for i, key in enumerate(config_keys):
|
|
|
|
print(f'{i:2} : {key}')
|
2019-12-18 09:02:20 +00:00
|
|
|
|
2021-05-08 13:06:11 +00:00
|
|
|
choosen_index = input('Number of configuration to use: ')
|
|
|
|
try:
|
|
|
|
daqindex = int(choosen_index)
|
|
|
|
except:
|
|
|
|
print('Invalid configuration number. Exiting.')
|
|
|
|
sys.exit(0)
|
2019-10-27 13:19:26 +00:00
|
|
|
|
2021-05-08 13:06:11 +00:00
|
|
|
choosen_key = config_keys[daqindex]
|
|
|
|
config = configs[choosen_key].input_config
|
2019-12-18 09:02:20 +00:00
|
|
|
|
2021-05-08 13:06:11 +00:00
|
|
|
print(f'Choosen configuration: {choosen_key}')
|
2018-09-13 11:56:05 +00:00
|
|
|
|
2021-05-08 13:06:11 +00:00
|
|
|
streammgr.startStream(AvType.audio_input, config, wait=True)
|
|
|
|
rec = Recording(args.filename, streammgr, args.duration)
|
2019-12-18 09:02:20 +00:00
|
|
|
|
2021-05-08 13:06:11 +00:00
|
|
|
streammgr.stopStream(AvType.audio_output)
|
2021-05-04 13:10:13 +00:00
|
|
|
finally:
|
|
|
|
try:
|
2021-05-08 13:06:11 +00:00
|
|
|
streammgr.cleanup()
|
2021-05-04 13:10:13 +00:00
|
|
|
del stream
|
|
|
|
except NameError:
|
|
|
|
pass
|
2019-12-18 09:02:20 +00:00
|
|
|
|
2021-05-08 13:06:11 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
multiprocessing.set_start_method('forkserver', force=True)
|
|
|
|
|
|
|
|
main(args)
|