File: hinawa-bebob-parser

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 (67 lines) | stat: -rwxr-xr-x 2,264 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
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (C) 2018 Takashi Sakamoto

from hinawa_utils.bebob.plug_parser import PlugParser

import sys
import json

argv = sys.argv
argc = len(argv)

if argc < 3:
    print('arguments:')
    print(' 1: the number of firewire character device (/dev/fw*)')
    print(' 2: dump mode (0: id-only, 1: whole as json)')
    sys.exit()

path = '/dev/fw{0}'.format(argv[1])
mode = int(argv[2])
unit = PlugParser(path)

def dump_plug_info_to_stdio_as_json(unit):
    info = {
        'units': unit.unit_plugs,
        'subunits': unit.subunit_plugs,
        'function-blocks': unit.function_block_plugs,
        'stream-formats': unit.stream_formats,
    }
    print(json.dumps(info))

def dump_plug_info_to_stdio_as_ids_only(unit):
    for type, dir_plugs in unit.unit_plugs.items():
        for dir, plugs in dir_plugs.items():
            for num, plug in plugs.items():
                print(type, dir, num, plug['name'])

    for type, dir_plugs in unit.subunit_plugs.items():
        for id, id_plugs in dir_plugs.items():
            for dir, dir_plugs in id_plugs.items():
                for plug_id, attrs in dir_plugs.items():
                    print(type, id, dir, plug_id, attrs['name'])

    for type, type_plugs in unit.function_block_plugs.items():
        for id, id_plugs in type_plugs.items():
            for fb_type, fb_type_plugs in id_plugs.items():
                for fb_id, fb_id_plugs in fb_type_plugs.items():
                    for plug_id, attrs in fb_id_plugs['outputs'].items():
                        print(type, id, fb_type, fb_id, 'output', plug_id, \
                              attrs['name'])
                    for plug_id, attrs in fb_id_plugs['inputs'].items():
                        print(type, id, fb_type, fb_id, 'input', plug_id, \
                              attrs['name'])

    for type, dir_fmts in unit.stream_formats.items():
        for dir, fmts in dir_fmts.items():
            for i, entries in fmts.items():
                for j, entry in enumerate(entries):
                    print(type, dir, i, j, entry['type'])

if mode == 0:
    dump_plug_info_to_stdio_as_ids_only(unit)
else:
    dump_plug_info_to_stdio_as_json(unit)

sys.exit()