[PATCH] libosmocore[master]: utils/conv_gen.py: improve application flexibility

Vadim Yanitskiy gerrit-no-reply at lists.osmocom.org
Fri Feb 3 09:16:41 UTC 2017


Hello Harald Welte, Jenkins Builder, Holger Freyther,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/1584

to look at the new patch set (#5).

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
---
M src/gsm/Makefile.am
M utils/conv_gen.py
2 files changed, 38 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/84/1584/5

diff --git a/src/gsm/Makefile.am b/src/gsm/Makefile.am
index 4ec441f..653bdb9 100644
--- a/src/gsm/Makefile.am
+++ b/src/gsm/Makefile.am
@@ -35,6 +35,6 @@
 
 # Convolutional codes generation
 gsm0503_conv.c:
-	$(AM_V_GEN)python2 $(top_srcdir)/utils/conv_gen.py
+	$(AM_V_GEN)python2 $(top_srcdir)/utils/conv_gen.py gen_codes gsm
 
 CLEANFILES = gsm0503_conv.c
diff --git a/utils/conv_gen.py b/utils/conv_gen.py
index 60580ed..e6eb50c 100644
--- a/utils/conv_gen.py
+++ b/utils/conv_gen.py
@@ -23,7 +23,7 @@
  */
 """
 
-import sys, os, math
+import sys, os, math, argparse
 from functools import reduce
 import conv_codes_gsm
 
@@ -254,12 +254,14 @@
 		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"):
@@ -279,12 +281,40 @@
 
 		code.gen_tables(prefix, f, shared_tables = shared)
 
+def parse_argv():
+	parser = argparse.ArgumentParser()
+
+	# Positional arguments
+	parser.add_argument("action",
+		help = "what to generate",
+		choices = ["gen_codes"])
+	parser.add_argument("family",
+		help = "convolutional code family",
+		choices = ["gsm"])
+
+	# 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__':
-	path = sys.argv[1] if len(sys.argv) > 1 else os.getcwd()
+	# Parse and verify arguments
+	argv = parse_argv()
+	path = argv.target_path or os.getcwd()
 
-	sys.stderr.write("Generating convolutional codes...\n")
+	# Determine convolutional code family
+	if argv.family == "gsm":
+		codes = conv_codes_gsm
+		prefix = argv.prefix or "gsm0503"
 
-	# Generate GSM specific codes
-	generate_codes(conv_codes_gsm, path, "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")

-- 
To view, visit https://gerrit.osmocom.org/1584
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I0b476b00234c17f78b41d695cf3bfd13edb64c28
Gerrit-PatchSet: 5
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Vadim Yanitskiy <axilirator at gmail.com>
Gerrit-Reviewer: tnt <tnt at 246tNt.com>


More information about the gerrit-log mailing list