-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhinawa-tascam-fw-console-cli
executable file
·160 lines (134 loc) · 5.14 KB
/
hinawa-tascam-fw-console-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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (C) 2018 Takashi Sakamoto
from hinawa_utils.misc.cli_kit import CliKit
from hinawa_utils.tscm.tscm_console_unit import TscmConsoleUnit
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:
if unit.get_property('is-locked'):
print('Packet is-locked started.')
return False
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 OP [SRC]')
print(' OP: [{0}]'.format('|'.join(ops)))
print(' SRC: [{0}]'.format('|'.join(unit.supported_clock_sources)))
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 OP [RATE]')
print(' OP: [{0}]'.format('|'.join(ops)))
rates = [str(r) for r in unit.supported_sampling_rates]
print(' RATE: [{0}]'.format('|'.join(rates)))
return False
def handle_firmware_versions(unit, args):
info = unit.get_firmware_versions()
for name, value in info.items():
print('{0}: {1}'.format(name, value))
return True
def handle_routing(unit, args, cmd, labels, set_func, get_func):
ops = ('set', 'get')
if len(args) > 0 and args[0] in ops:
op = args[0]
if op == ops[0] and len(args) == 2 and args[1] in labels:
src = args[1]
set_func(src)
return True
elif op == 'get':
print(get_func())
return True
print('Arguments for {0} command:'.format(cmd))
print(' {0} OP [SRC]'.format(cmd))
print(' OP: [{0}]'.format('|'.join(ops)))
print(' SRC: [{0}]'.format('|'.join(labels)))
return False
def handle_coax_out_src(unit, args):
return handle_routing(unit, args, 'coaxial-out-source',
unit.get_coax_out_src_labels(),
unit.set_coax_out_src,
unit.get_coax_out_src)
def handle_opt_out_src(unit, args):
return handle_routing(unit, args, 'optical-out-source',
unit.get_opt_out_src_labels(),
unit.set_opt_out_src,
unit.get_opt_out_src)
def handle_stream_spdif_in_src(unit, args):
return handle_routing(unit, args, 'stream-spdif-in-source',
unit.get_stream_spdif_in_src_labels(),
unit.set_stream_spdif_in_src,
unit.get_stream_spdif_in_src)
def handle_input_threshold(unit, args):
ops = ('set', 'get')
if len(args) >= 1 and args[0] in ops:
op = args[0]
if op == 'set' and len(args) >= 2:
level = float(args[1])
unit.set_input_threshold(level)
return True
elif op == 'get':
level = unit.get_input_threshold()
print('{:.3f}'.format(level))
return True
print('Arguments for input-threshold command:')
print(' input-threshold OP [LEVEL]')
print(' OP: [{0}]'.format('|'.join(ops)))
print(' LEVEL: [-inf, -90..0]')
return True
def handle_master_fader(unit, args):
ops = ('set', 'get')
modes = ('False', 'True')
if len(args) > 0 and args[0] in ops:
op = args[0]
if op == 'set' and len(args) == 2 and args[1] in modes:
mode = args[1] == 'True'
unit.set_master_fader(mode)
elif op == 'get':
print(unit.get_master_fader())
return True
print('Arguments for master-fader command:')
print(' master-fader OP [MODE]')
print(' OP: [{0}]'.format('|'.join(ops)))
print(' MODE: [{0}]'.format('|'.join(modes)))
return False
def handle_bright_led(unit, args):
if len(args) > 1:
pos = int(args[0])
state = args[1]
unit.bright_led(pos, state)
return True
print('Arguments for bright-led command:')
print(' bright-led POS STATE')
print(' POS: [0-???]')
print(' STATE: [{0}]'.format('|'.join(unit.supported_led_status)))
return False
cmds = {
'clock-source': handle_clock_source,
'sampling-rate': handle_sampling_rate,
'firmware-versions': handle_firmware_versions,
'coaxial-out-source': handle_coax_out_src,
'stream-spdif-in-source': handle_stream_spdif_in_src,
'master-fader': handle_master_fader,
'bright-led': handle_bright_led,
}
fullpath = CliKit.seek_snd_unit_path()
if fullpath:
with TscmConsoleUnit(fullpath) as unit:
if unit.model_name == 'FW-1884':
cmds['optical-out-source'] = handle_opt_out_src
CliKit.dispatch_command(unit, cmds)