Debian Codegraph @

hinawa-tascam-fw-console-cli

raw
1 #!/usr/bin/env python3
2 # SPDX-License-Identifier: GPL-3.0-or-later
3 # Copyright (C) 2018 Takashi Sakamoto
4
5 from hinawa_utils.misc.cli_kit import CliKit
6 from hinawa_utils.tscm.tscm_console_unit import TscmConsoleUnit
7
8
9 def handle_clock_source(unit, args):
10 ops = ('set', 'get')
11 if len(args) > 0 and args[0] in ops:
12 op = args[0]
13 if op == ops[0] and len(args) == 2:
14 if unit.get_property('is-locked'):
15 print('Packet is-locked started.')
16 return False
17 source = args[1]
18 unit.set_clock_source(source)
19 else:
20 print(unit.get_clock_source())
21 return True
22 print('Arguments for clock-source command:')
23 print(' clock-source OP [SRC]')
24 print(' OP: [{0}]'.format('|'.join(ops)))
25 print(' SRC: [{0}]'.format('|'.join(unit.supported_clock_sources)))
26 return False
27
28
29 def handle_sampling_rate(unit, args):
30 ops = ('set', 'get')
31 if len(args) > 0 and args[0] in ops:
32 op = args[0]
33 if op == ops[0] and len(args) == 2:
34 rate = int(args[1])
35 unit.set_sampling_rate(rate)
36 else:
37 print(unit.get_sampling_rate())
38 return True
39 print('Arguments for sampling-rate command:')
40 print(' sampling-rate OP [RATE]')
41 print(' OP: [{0}]'.format('|'.join(ops)))
42 rates = [str(r) for r in unit.supported_sampling_rates]
43 print(' RATE: [{0}]'.format('|'.join(rates)))
44 return False
45
46
47 def handle_firmware_versions(unit, args):
48 info = unit.get_firmware_versions()
49 for name, value in info.items():
50 print('{0}: {1}'.format(name, value))
51 return True
52
53
54 def handle_routing(unit, args, cmd, labels, set_func, get_func):
55 ops = ('set', 'get')
56 if len(args) > 0 and args[0] in ops:
57 op = args[0]
58 if op == ops[0] and len(args) == 2 and args[1] in labels:
59 src = args[1]
60 set_func(src)
61 return True
62 elif op == 'get':
63 print(get_func())
64 return True
65 print('Arguments for {0} command:'.format(cmd))
66 print(' {0} OP [SRC]'.format(cmd))
67 print(' OP: [{0}]'.format('|'.join(ops)))
68 print(' SRC: [{0}]'.format('|'.join(labels)))
69 return False
70
71
72 def handle_coax_out_src(unit, args):
73 return handle_routing(unit, args, 'coaxial-out-source',
74 unit.get_coax_out_src_labels(),
75 unit.set_coax_out_src,
76 unit.get_coax_out_src)
77
78
79 def handle_opt_out_src(unit, args):
80 return handle_routing(unit, args, 'optical-out-source',
81 unit.get_opt_out_src_labels(),
82 unit.set_opt_out_src,
83 unit.get_opt_out_src)
84
85
86 def handle_stream_spdif_in_src(unit, args):
87 return handle_routing(unit, args, 'stream-spdif-in-source',
88 unit.get_stream_spdif_in_src_labels(),
89 unit.set_stream_spdif_in_src,
90 unit.get_stream_spdif_in_src)
91
92
93 def handle_input_threshold(unit, args):
94 ops = ('set', 'get')
95
96 if len(args) >= 1 and args[0] in ops:
97 op = args[0]
98 if op == 'set' and len(args) >= 2:
99 level = float(args[1])
100 unit.set_input_threshold(level)
101 return True
102 elif op == 'get':
103 level = unit.get_input_threshold()
104 print('{:.3f}'.format(level))
105 return True
106 print('Arguments for input-threshold command:')
107 print(' input-threshold OP [LEVEL]')
108 print(' OP: [{0}]'.format('|'.join(ops)))
109 print(' LEVEL: [-inf, -90..0]')
110 return True
111
112
113 def handle_master_fader(unit, args):
114 ops = ('set', 'get')
115 modes = ('False', 'True')
116 if len(args) > 0 and args[0] in ops:
117 op = args[0]
118 if op == 'set' and len(args) == 2 and args[1] in modes:
119 mode = args[1] == 'True'
120 unit.set_master_fader(mode)
121 elif op == 'get':
122 print(unit.get_master_fader())
123 return True
124 print('Arguments for master-fader command:')
125 print(' master-fader OP [MODE]')
126 print(' OP: [{0}]'.format('|'.join(ops)))
127 print(' MODE: [{0}]'.format('|'.join(modes)))
128 return False
129
130
131 def handle_bright_led(unit, args):
132 if len(args) > 1:
133 pos = int(args[0])
134 state = args[1]
135 unit.bright_led(pos, state)
136 return True
137 print('Arguments for bright-led command:')
138 print(' bright-led POS STATE')
139 print(' POS: [0-???]')
140 print(' STATE: [{0}]'.format('|'.join(unit.supported_led_status)))
141 return False
142
143
144 cmds = {
145 'clock-source': handle_clock_source,
146 'sampling-rate': handle_sampling_rate,
147 'firmware-versions': handle_firmware_versions,
148 'coaxial-out-source': handle_coax_out_src,
149 'stream-spdif-in-source': handle_stream_spdif_in_src,
150
151 'master-fader': handle_master_fader,
152 'bright-led': handle_bright_led,
153 }
154
155 fullpath = CliKit.seek_snd_unit_path()
156 if fullpath:
157 with TscmConsoleUnit(fullpath) as unit:
158 if unit.model_name == 'FW-1884':
159 cmds['optical-out-source'] = handle_opt_out_src
160 CliKit.dispatch_command(unit, cmds)