From 2c717948d91540016067f87bb3e0913067d42647 Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Fri, 13 Jan 2017 02:23:01 +0700 Subject: utils/conv_gen.py: improve application flexibility This change makes the conv_gen application more interactive and flexible, allowing to generate not only code definitions but also the test vectors and header files in the future. Moreover, it becomes possible to select exact code family, such as GSM, GMR etc. Change-Id: I0b476b00234c17f78b41d695cf3bfd13edb64c28 --- utils/conv_gen.py | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) (limited to 'utils') diff --git a/utils/conv_gen.py b/utils/conv_gen.py index 60580edd..e6eb50cb 100644 --- a/utils/conv_gen.py +++ b/utils/conv_gen.py @@ -23,7 +23,7 @@ mod_license = """ */ """ -import sys, os, math +import sys, os, math, argparse from functools import reduce import conv_codes_gsm @@ -254,13 +254,15 @@ def print_shared(fi, shared_polys): code = ConvolutionalCode(0, polys, name = name) code.print_state_and_output(fi) -def generate_codes(codes, path, prefix): +def generate_codes(codes, path, prefix, name): # Open a new file for writing - f = open(os.path.join(path, prefix + "_conv.c"), 'w') + f = open(os.path.join(path, name), 'w') f.write(mod_license + "\n") f.write("#include \n") f.write("#include \n\n") + sys.stderr.write("Generating convolutional codes...\n") + # Print shared tables first if hasattr(codes, "shared_polys"): print_shared(f, codes.shared_polys) @@ -279,12 +281,40 @@ def generate_codes(codes, path, prefix): code.gen_tables(prefix, f, shared_tables = shared) -if __name__ == '__main__': - path = sys.argv[1] if len(sys.argv) > 1 else os.getcwd() +def parse_argv(): + parser = argparse.ArgumentParser() - sys.stderr.write("Generating convolutional codes...\n") + # Positional arguments + parser.add_argument("action", + help = "what to generate", + choices = ["gen_codes"]) + parser.add_argument("family", + help = "convolutional code family", + choices = ["gsm"]) - # Generate GSM specific codes - generate_codes(conv_codes_gsm, path, "gsm0503") + # Optional arguments + parser.add_argument("-p", "--prefix", + help = "internal naming prefix") + parser.add_argument("-n", "--target-name", + help = "target name for generated file") + parser.add_argument("-P", "--target-path", + help = "target path for generated file") + + return parser.parse_args() + +if __name__ == '__main__': + # Parse and verify arguments + argv = parse_argv() + path = argv.target_path or os.getcwd() + + # Determine convolutional code family + if argv.family == "gsm": + codes = conv_codes_gsm + prefix = argv.prefix or "gsm0503" + + # What to generate? + if argv.action == "gen_codes": + name = argv.target_name or prefix + "_conv.c" + generate_codes(codes, path, prefix, name) sys.stderr.write("Generation complete.\n") -- cgit v1.2.3