| 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.oxfw.oxfw_unit import OxfwUnit |
| 7 |
|
| 8 |
# Helper functions |
| 9 |
|
| 10 |
|
| 11 |
def handle_current_status(unit, args): |
| 12 |
print('Current status:') |
| 13 |
print(' Packet Streaming:') |
| 14 |
print(' running: {0}'.format(unit.get_property('is-locked'))) |
| 15 |
fmts = unit.get_current_stream_formats() |
| 16 |
print( |
| 17 |
' sampling-rate: {0}'.format(fmts['playback']['sampling-rate'])) |
| 18 |
print(' Stream formats:') |
| 19 |
print(' playback: {0} PCM'.format(len(fmts['playback']['formation']))) |
| 20 |
if fmts['capture']: |
| 21 |
print(' capture: {0} PCM'.format( |
| 22 |
len(fmts['capture']['formation']))) |
| 23 |
print('ASIC information:') |
| 24 |
print(' type: {0}'.format(unit.hw_info['asic-type'])) |
| 25 |
print(' ID: {0}'.format(unit.hw_info['asic-id'])) |
| 26 |
print(' firmware version: {0}'.format(unit.hw_info['firmware-version'])) |
| 27 |
return True |
| 28 |
|
| 29 |
|
| 30 |
def dump_stream_format(fmt): |
| 31 |
print(' sampling-rate: {0}'.format(fmt['sampling-rate'])) |
| 32 |
print(' rate-control: {0}'.format(fmt['rate-control'])) |
| 33 |
print(' formation:') |
| 34 |
for num, data_channel in enumerate(fmt['formation']): |
| 35 |
print(' {0}: {1}'.format(num, data_channel)) |
| 36 |
|
| 37 |
|
| 38 |
def handle_stream_format(unit, args): |
| 39 |
ops = ('set', 'get') |
| 40 |
if len(args) > 0 and args[0] in ops: |
| 41 |
op = args[0] |
| 42 |
if op == ops[0]and len(args) > 1: |
| 43 |
fmts = unit.supported_stream_formats |
| 44 |
p_entry = int(args[1]) |
| 45 |
p_fmt = fmts['playback'][p_entry] |
| 46 |
if 'capture' in fmts: |
| 47 |
c_entry = int(args[2]) |
| 48 |
c_fmt = fmts['capture'][c_entry] |
| 49 |
else: |
| 50 |
c_fmt = None |
| 51 |
unit.set_stream_formats(p_fmt, c_fmt) |
| 52 |
else: |
| 53 |
for dir, fmt in unit.get_current_stream_formats().items(): |
| 54 |
if fmt: |
| 55 |
print('{0}:'.format(dir)) |
| 56 |
dump_stream_format(fmt) |
| 57 |
return True |
| 58 |
print('Arguments for stream-format command:') |
| 59 |
print( |
| 60 |
' stream-format OPERATION [PLAYBACK-FORMAT-ENTRY [CAPTURE-FORMAT-ENTRY]]') |
| 61 |
print(' OPERATION: {0}'.format(', '.join(ops))) |
| 62 |
fmts = unit.supported_stream_formats |
| 63 |
print(' PLAYBACK-FORMAT-ENTRY:') |
| 64 |
for num, fmt in enumerate(fmts['playback']): |
| 65 |
print(' Entry {0}:'.format(num)) |
| 66 |
dump_stream_format(fmt) |
| 67 |
if 'capture' in fmts and len(fmts['capture']) > 0: |
| 68 |
print(' CAPTURE-FORMAT-ENTRY:') |
| 69 |
for num, fmt in enumerate(fmts['capture']): |
| 70 |
print(' Entry {0}:'.format(num)) |
| 71 |
dump_stream_format(fmt) |
| 72 |
return False |
| 73 |
|
| 74 |
|
| 75 |
cmds = { |
| 76 |
'current-status': handle_current_status, |
| 77 |
'stream-format': handle_stream_format, |
| 78 |
} |
| 79 |
|
| 80 |
fullpath = CliKit.seek_snd_unit_path() |
| 81 |
if fullpath: |
| 82 |
with OxfwUnit(fullpath) as unit: |
| 83 |
CliKit.dispatch_command(unit, cmds) |