-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhinawa-dice-common-cli
executable file
·130 lines (116 loc) · 5.01 KB
/
hinawa-dice-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
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
#!/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.dice.dice_unit import DiceUnit
def handle_current_status(unit, args):
print('owner address: {0:016x}'.format(unit.get_owner_addr()))
print('global enabled: {0}'.format(unit.get_enabled()))
print('clock status:')
for name, value in unit.get_clock_status().items():
print(' {0}: {1}'.format(name, value))
print('clock source detection:')
for name, value in unit.get_external_clock_states().items():
print(' {0}: {1}'.format(name, ', '.join(value)))
print('measured rate: {0}'.format(unit.get_measured_sampling_rate()))
print('dice version: {0}'.format(unit.get_dice_version()))
print('latest notification: 0x{0:08x}'.format(
unit.get_latest_notification()))
print('clock source: {0}'.format(unit.get_clock_source()))
print('sampling rate: {0}'.format(unit.get_sampling_rate()))
print('nickname: {0}'.format(unit.get_nickname()))
print('Transmitted streams:')
for i, params in enumerate(unit.get_tx_params()):
print(' Stream {0}:'.format(i))
print(' iso-channel: 0x{0:08x}'.format(params['iso-channel']))
print(' speed: {0}'.format(params['speed']))
print(' pcm: {0}'.format(params['pcm']))
print(' midi: {0}'.format(params['midi']))
if 'iec60958' in params:
print(' iec60958:')
print(' caps: {0}'.format(params['iec60958']['caps']))
print(' enable: {0}'.format(params['iec60958']['enable']))
print(' formation:')
for j, name in enumerate(params['formation']):
print(' {0}: {1}'.format(j, name))
print('Received streams:')
for i, params in enumerate(unit.get_rx_params()):
print(' Stream {0}:'.format(i))
print(' iso-channel: 0x{0:08x}'.format(params['iso-channel']))
print(' start: {0}'.format(params['start']))
print(' pcm: {0}'.format(params['pcm']))
print(' midi: {0}'.format(params['midi']))
if 'iec60958' in params:
print(' iec60958:')
print(' caps: {0}'.format(params['iec60958']['caps']))
print(' enable: {0}'.format(params['iec60958']['enable']))
print(' formation:')
for j, name in enumerate(params['formation']):
print(' {0}: {1}'.format(j, name))
sync_clock_source = unit.get_external_sync_clock_source()
if sync_clock_source != '':
sync_locked = unit.get_external_sync_locked()
sync_rate = unit.get_external_sync_rate()
sync_adat_status = unit.get_external_sync_adat_status()
print('Synchronization infomation:')
print(' clock-source: {0}'.format(sync_clock_source))
print(' locked: {0}'.format(sync_locked))
print(' sampling-rate: {0}'.format(sync_rate))
print(' adat-status: {0:x}'.format(sync_adat_status))
return True
def handle_sampling_rate(unit, args):
ops = ('set', 'get')
rates = unit.get_supported_sampling_rates()
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(' OP: [{0}]'.format('|'.join(ops)))
print(' RATE: [{0}]'.format('|'.join(map(str, rates))))
return False
def handle_clock_source(unit, args):
ops = ('set', 'get')
sources = unit.get_supported_clock_sources()
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(' OP: [{0}]'.format('|'.join(ops)))
print(' SOURCE: [{0}]'.format('|'.join(sources)))
return False
def handle_nickname(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:
name = args[1]
unit.set_nickname(name)
else:
print(unit.get_nickname())
return True
print('Arguments for nickname command:')
print(' nickname OPERATION [SOURCE]')
print(' OPERATION: {0}'.format(', '.join(ops)))
return False
cmds = {
'current-status': handle_current_status,
'sampling-rate': handle_sampling_rate,
'clock-source': handle_clock_source,
'nickname': handle_nickname,
}
fullpath = CliKit.seek_snd_unit_path()
if fullpath:
with DiceUnit(fullpath) as unit:
CliKit.dispatch_command(unit, cmds)