-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhinawa-motu-common-cli
executable file
·101 lines (84 loc) · 3.18 KB
/
hinawa-motu-common-cli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (C) 2018 Takashi Sakamoto
import signal
from hinawa_utils.misc.cli_kit import CliKit
from hinawa_utils.motu.motu_unit import MotuUnit
from gi.repository import GLib
def handle_opt_iface_mode(uniit, args):
ops = ('set', 'get')
if len(args) > 2 and args[0] in ops:
op = args[0]
direction = args[1]
index = args[2]
if op == ops[0] and len(args) == 4:
mode = args[3]
unit.set_opt_iface_mode(direction, index, mode)
else:
print(unit.get_opt_iface_mode(direction, index))
return True
print('Arguments for optical input interface mode:')
print(' opt-iface-mode OPERATION DIRECTION INDEX [MODE]')
print(' OPERATION: [{0}]'.format('|'.join(ops)))
directions = [str(d) for d in unit.get_supported_opt_iface_directions()]
print(' DIRECTION: [{0}]'.format('|'.join(directions)))
indexes = [str(i) for i in unit.get_opt_iface_indexes()]
print(' INDEX: [{0}]'.format('|'.join(indexes)))
modes = [str(m) for m in unit.get_opt_iface_modes()]
print(' MODE: [{0}]'.format('|'.join(modes)))
return False
def handle_sampling_rate(unit, args):
ops = ('set', 'get')
if len(args) > 0 and args[0] in ops:
op = args[0]
if op == ops[0] and len(args) == 2:
rate = int(args[1])
unit.set_sampling_rate(rate)
else:
print(unit.get_sampling_rate())
return True
print('Arguments for sampling-rate command:')
print(' sampling-rate OPERATION [RATE]')
print(' OPERATION: [{0}]'.format('|'.join(ops)))
rates = [str(r) for r in unit.get_sampling_rates()]
print(' RATE: [{0}]'.format('|'.join(rates)))
return False
def handle_clock_source(unit, args):
ops = ('set', 'get')
if len(args) > 0 and args[0] in ops:
op = args[0]
if op == ops[0] and len(args) == 2:
source = args[1]
unit.set_clock_source(source)
else:
print(unit.get_clock_source())
return True
print('Arguments for clock-source command:')
print(' clock-source OPERATION [SOURCE]')
print(' OPERATION: [{0}]'.format('|'.join(ops)))
sources = unit.get_supported_clock_sources()
print(' SOURCE: [{0}]'.format('|'.join(sources)))
return False
def handle_listen_message(unit, args):
loop = GLib.MainLoop()
def handle_unix_signal():
loop.quit()
def handle_notified(unit, notification):
print('{0:08x}'.format(notification))
def handle_disconnect(unit, loop):
loop.quit()
unit.connect('notified', handle_notified)
GLib.unix_signal_add(GLib.PRIORITY_HIGH, signal.SIGINT, handle_unix_signal)
unit.connect('notify::is-disconnected', handle_disconnect, loop)
loop.run()
return True
cmds = {
'opt-iface-mode': handle_opt_iface_mode,
'sampling-rate': handle_sampling_rate,
'clock-source': handle_clock_source,
'listen-message': handle_listen_message,
}
fullpath = CliKit.seek_snd_unit_path()
if fullpath:
with MotuUnit(fullpath) as unit:
CliKit.dispatch_command(unit, cmds)