File: hinawa-oxfw-generic-cui

package info (click to toggle)
hinawa-utils 0.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 936 kB
  • sloc: python: 11,005; makefile: 3
file content (75 lines) | stat: -rwxr-xr-x 2,939 bytes parent folder | download
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
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (C) 2018 Takashi Sakamoto

from hinawa_utils.misc.cui_kit import CuiKit
from hinawa_utils.oxfw.oxfw_unit import OxfwUnit

# Helper functions
def handle_current_status(unit, args):
    print('Current status:')
    print('  Packet Streaming:')
    print('    running:          {0}'.format(unit.get_property('streaming')))
    fmts = unit.get_current_stream_formats()
    print('    sampling-rate:    {0}'.format(fmts['playback']['sampling-rate']))
    print('  Stream formats:')
    print('    playback: {0} PCM'.format(len(fmts['playback']['formation'])))
    if fmts['capture']:
        print('    capture:  {0} PCM'.format(len(fmts['capture']['formation'])))
    print('ASIC information:')
    print('  type:             {0}'.format(unit.hw_info['asic-type']))
    print('  ID:               {0}'.format(unit.hw_info['asic-id']))
    print('  firmware version: {0}'.format(unit.hw_info['firmware-version']))
    return True

def dump_stream_format(fmt):
    print('        sampling-rate: {0}'.format(fmt['sampling-rate']))
    print('        rate-control:  {0}'.format(fmt['rate-control']))
    print('        formation:')
    for num, data_channel in enumerate(fmt['formation']):
        print('          {0}: {1}'.format(num, data_channel))

def handle_stream_format(unit, args):
    ops = ('set', 'get')
    if len(args) > 0 and args[0] in ops:
        op = args[0]
        if op == ops[0]and len(args) > 1:
            fmts = unit.supported_stream_formats
            p_entry = int(args[1])
            p_fmt = fmts['playback'][p_entry]
            if 'capture' in fmts:
                c_entry = int(args[2])
                c_fmt = fmts['capture'][c_entry]
            else:
                c_fmt = None
            unit.set_stream_formats(p_fmt, c_fmt)
        else:
            for dir, fmt in unit.get_current_stream_formats().items():
                if fmt:
                    print('{0}:'.format(dir))
                    dump_stream_format(fmt)
        return True
    print('Arguments for stream-format command:')
    print('  stream-format OPERATION [PLAYBACK-FORMAT-ENTRY [CAPTURE-FORMAT-ENTRY]]')
    print('    OPERATION: {0}'.format(', '.join(ops)))
    fmts = unit.supported_stream_formats
    print('    PLAYBACK-FORMAT-ENTRY:')
    for num, fmt in enumerate(fmts['playback']):
        print('      Entry {0}:'.format(num))
        dump_stream_format(fmt)
    if 'capture' in fmts and len(fmts['capture']) > 0:
        print('    CAPTURE-FORMAT-ENTRY:')
        for num, fmt in enumerate(fmts['capture']):
            print('      Entry {0}:'.format(num))
            dump_stream_format(fmt)
    return False

cmds = {
    'current-status':   handle_current_status,
    'stream-format':    handle_stream_format,
}

fullpath = CuiKit.seek_snd_unit_path()
if fullpath:
    unit = OxfwUnit(fullpath)
    CuiKit.dispatch_command(unit, cmds)