| 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.dice.dice_unit import DiceUnit |
| 7 |
|
| 8 |
|
| 9 |
def handle_current_status(unit, args): |
| 10 |
print('owner address: {0:016x}'.format(unit.get_owner_addr())) |
| 11 |
print('global enabled: {0}'.format(unit.get_enabled())) |
| 12 |
print('clock status:') |
| 13 |
for name, value in unit.get_clock_status().items(): |
| 14 |
print(' {0}: {1}'.format(name, value)) |
| 15 |
print('clock source detection:') |
| 16 |
for name, value in unit.get_external_clock_states().items(): |
| 17 |
print(' {0}: {1}'.format(name, ', '.join(value))) |
| 18 |
print('measured rate: {0}'.format(unit.get_measured_sampling_rate())) |
| 19 |
print('dice version: {0}'.format(unit.get_dice_version())) |
| 20 |
print('latest notification: 0x{0:08x}'.format( |
| 21 |
unit.get_latest_notification())) |
| 22 |
print('clock source: {0}'.format(unit.get_clock_source())) |
| 23 |
print('sampling rate: {0}'.format(unit.get_sampling_rate())) |
| 24 |
print('nickname: {0}'.format(unit.get_nickname())) |
| 25 |
print('Transmitted streams:') |
| 26 |
for i, params in enumerate(unit.get_tx_params()): |
| 27 |
print(' Stream {0}:'.format(i)) |
| 28 |
print(' iso-channel: 0x{0:08x}'.format(params['iso-channel'])) |
| 29 |
print(' speed: {0}'.format(params['speed'])) |
| 30 |
print(' pcm: {0}'.format(params['pcm'])) |
| 31 |
print(' midi: {0}'.format(params['midi'])) |
| 32 |
if 'iec60958' in params: |
| 33 |
print(' iec60958:') |
| 34 |
print(' caps: {0}'.format(params['iec60958']['caps'])) |
| 35 |
print(' enable: {0}'.format(params['iec60958']['enable'])) |
| 36 |
print(' formation:') |
| 37 |
for j, name in enumerate(params['formation']): |
| 38 |
print(' {0}: {1}'.format(j, name)) |
| 39 |
print('Received streams:') |
| 40 |
for i, params in enumerate(unit.get_rx_params()): |
| 41 |
print(' Stream {0}:'.format(i)) |
| 42 |
print(' iso-channel: 0x{0:08x}'.format(params['iso-channel'])) |
| 43 |
print(' start: {0}'.format(params['start'])) |
| 44 |
print(' pcm: {0}'.format(params['pcm'])) |
| 45 |
print(' midi: {0}'.format(params['midi'])) |
| 46 |
if 'iec60958' in params: |
| 47 |
print(' iec60958:') |
| 48 |
print(' caps: {0}'.format(params['iec60958']['caps'])) |
| 49 |
print(' enable: {0}'.format(params['iec60958']['enable'])) |
| 50 |
print(' formation:') |
| 51 |
for j, name in enumerate(params['formation']): |
| 52 |
print(' {0}: {1}'.format(j, name)) |
| 53 |
sync_clock_source = unit.get_external_sync_clock_source() |
| 54 |
if sync_clock_source != '': |
| 55 |
sync_locked = unit.get_external_sync_locked() |
| 56 |
sync_rate = unit.get_external_sync_rate() |
| 57 |
sync_adat_status = unit.get_external_sync_adat_status() |
| 58 |
|
| 59 |
print('Synchronization infomation:') |
| 60 |
print(' clock-source: {0}'.format(sync_clock_source)) |
| 61 |
print(' locked: {0}'.format(sync_locked)) |
| 62 |
print(' sampling-rate: {0}'.format(sync_rate)) |
| 63 |
print(' adat-status: {0:x}'.format(sync_adat_status)) |
| 64 |
|
| 65 |
return True |
| 66 |
|
| 67 |
|
| 68 |
def handle_sampling_rate(unit, args): |
| 69 |
ops = ('set', 'get') |
| 70 |
rates = unit.get_supported_sampling_rates() |
| 71 |
if len(args) > 0 and args[0] in ops: |
| 72 |
op = args[0] |
| 73 |
if op == ops[0] and len(args) == 2: |
| 74 |
rate = int(args[1]) |
| 75 |
unit.set_sampling_rate(rate) |
| 76 |
else: |
| 77 |
print(unit.get_sampling_rate()) |
| 78 |
return True |
| 79 |
print('Arguments for sampling-rate command:') |
| 80 |
print(' sampling-rate OPERATION [RATE]') |
| 81 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 82 |
print(' RATE: [{0}]'.format('|'.join(map(str, rates)))) |
| 83 |
return False |
| 84 |
|
| 85 |
|
| 86 |
def handle_clock_source(unit, args): |
| 87 |
ops = ('set', 'get') |
| 88 |
sources = unit.get_supported_clock_sources() |
| 89 |
if len(args) > 0 and args[0] in ops: |
| 90 |
op = args[0] |
| 91 |
if op == ops[0] and len(args) == 2: |
| 92 |
source = args[1] |
| 93 |
unit.set_clock_source(source) |
| 94 |
else: |
| 95 |
print(unit.get_clock_source()) |
| 96 |
return True |
| 97 |
print('Arguments for clock-source command:') |
| 98 |
print(' clock-source OPERATION [SOURCE]') |
| 99 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 100 |
print(' SOURCE: [{0}]'.format('|'.join(sources))) |
| 101 |
return False |
| 102 |
|
| 103 |
|
| 104 |
def handle_nickname(unit, args): |
| 105 |
ops = ('set', 'get') |
| 106 |
if len(args) > 0 and args[0] in ops: |
| 107 |
op = args[0] |
| 108 |
if op == ops[0] and len(args) == 2: |
| 109 |
name = args[1] |
| 110 |
unit.set_nickname(name) |
| 111 |
else: |
| 112 |
print(unit.get_nickname()) |
| 113 |
return True |
| 114 |
print('Arguments for nickname command:') |
| 115 |
print(' nickname OPERATION [SOURCE]') |
| 116 |
print(' OPERATION: {0}'.format(', '.join(ops))) |
| 117 |
return False |
| 118 |
|
| 119 |
|
| 120 |
cmds = { |
| 121 |
'current-status': handle_current_status, |
| 122 |
'sampling-rate': handle_sampling_rate, |
| 123 |
'clock-source': handle_clock_source, |
| 124 |
'nickname': handle_nickname, |
| 125 |
} |
| 126 |
|
| 127 |
fullpath = CliKit.seek_snd_unit_path() |
| 128 |
if fullpath: |
| 129 |
with DiceUnit(fullpath) as unit: |
| 130 |
CliKit.dispatch_command(unit, cmds) |