summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2017-01-13 02:23:01 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2017-02-09 06:39:58 +0000
commit2c717948d91540016067f87bb3e0913067d42647 (patch)
treef2df2b6ac055a7bd1f5d5ef54be2566bfb6d3d6f /utils
parent4ffb43f654d12663af0c072eb6191716d377f4b5 (diff)
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
Diffstat (limited to 'utils')
-rw-r--r--utils/conv_gen.py46
1 files changed, 38 insertions, 8 deletions
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 <stdint.h>\n")
f.write("#include <osmocom/core/conv.h>\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")