diff options
author | Samuel O'Brien <sam.obrien@ni.com> | 2020-06-23 15:09:55 -0500 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2020-07-13 15:21:52 -0500 |
commit | 297d5855ca3ac2e3fea329bd938cf4763fac583b (patch) | |
tree | e302783f5efcadbd451d8d24463baece7d85a47c /host/tests/common/chdr_resource/format_trace.py | |
parent | 22837edfe20feb57c24f2a55edbb65757b3fab6a (diff) | |
download | uhd-297d5855ca3ac2e3fea329bd938cf4763fac583b.tar.gz uhd-297d5855ca3ac2e3fea329bd938cf4763fac583b.tar.bz2 uhd-297d5855ca3ac2e3fea329bd938cf4763fac583b.zip |
utils: Expose CHDR Parsing API
This commit introduces a new public api in uhd::utils which allows serializing
and deserializing chdr packets.
As far as testing, this commit adds the chdr_parse_test test. It uses a
wireshark trace located in rfnoc_packets_*.cpp as well as hand coded
packets from hardcoded_packets.cpp to test the serialization and
deserialization process
Signed-off-by: Samuel O'Brien <sam.obrien@ni.com>
Diffstat (limited to 'host/tests/common/chdr_resource/format_trace.py')
-rwxr-xr-x | host/tests/common/chdr_resource/format_trace.py | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/host/tests/common/chdr_resource/format_trace.py b/host/tests/common/chdr_resource/format_trace.py new file mode 100755 index 000000000..37659668c --- /dev/null +++ b/host/tests/common/chdr_resource/format_trace.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python3 +# +# Copyright 2017 Ettus Research, a National Instruments Company +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import sys +import re + +if len(sys.argv) < 2: + print("Please supply an input filename!") + exit() + +input_arg = sys.argv[1] +filename_pat = re.compile(r"(.*)\.c") +m = filename_pat.match(input_arg) +if not m: + print("Please supply a .c file as input!") + exit() +filename = m.group(1) + +input_file = open(filename + ".c", "r") +output_file = open(filename + ".cpp", "w") + +output_header = """// +// Copyright 2020 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#include <tuple> + +""" + +# Matches a line defining a new packet, e.g +# char peer1_19[] = { /* Packet 3153 */ +# Group 1 is the array name, e.g. "peer1_19" +# Group 2 is the Commented Description, e.g. "Packet 3072" +define_pat = re.compile(r"^char (peer[0|1]_\d+)\[\] = \{ \/\* (Packet \d+) \*\/$") + +# Matches a line in the middle of a packet or at the end, e.g. +# 0x01, 0x00, 0x18, 0x00, 0x02, 0x00, 0x80, 0x00, +# 0x08, 0x00, 0x0f, 0x00 }; +# No groups, use full match +other_pat = re.compile(r"^((?:0x[0-9a-f]{2}, )*(?:0x[0-9a-f]{2}))(?: \};|, )$") + +# Used to seperate the two parties in the conversation (peer0 and peer1) +var_sort_pat = re.compile(r"^peer0_\d+$") + +output_file.write(output_header) +output_file.write("namespace {} {{\n\n".format(filename)) + +var_names_peer_0 = [] +var_names_peer_1 = [] + +while True: + line = input_file.readline() + if not line: + break + m = define_pat.match(line) + if m: + output_file.write("uint8_t {}[] = {{ // {}\n".format(m.group(1), m.group(2))) + var_sort_match = var_sort_pat.match(m.group(1)) + if var_sort_match: + var_names_peer_0.append(m.group(1)) + else: + var_names_peer_1.append(m.group(1)) + continue + m = other_pat.match(line) + if m: + output_file.write(line) + continue + print("Encountered unexpected line:\n{}".format(line)) + exit() + +for peer_name, var_names in [("peer0", var_names_peer_0), ("peer1", var_names_peer_1)]: + output_file.write("\n") + output_file.write("size_t {}_len = {};\n".format(peer_name, len(var_names))) + output_file.write("std::tuple<uint8_t*, size_t> {}[] = {{\n".format(peer_name)) + for var_name in var_names: + output_file.write("\tstd::make_tuple({0}, sizeof({0})),\n".format(var_name)) + output_file.write("};\n") + +output_file.write("\n") +output_file.write("}} // namespace {}\n".format(filename)) |