From 12e4796cd3a7830759c8961bc7ebb1fd0d3673cc Mon Sep 17 00:00:00 2001
From: Achilleas Anastasopoulos <anastas@umich.edu>
Date: Thu, 2 Jun 2011 18:26:33 -0400
Subject: Updated some of the examples in gr-trellis to use the options parser

---
 gr-trellis/src/examples/test_tcm.py | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

(limited to 'gr-trellis/src/examples/test_tcm.py')

diff --git a/gr-trellis/src/examples/test_tcm.py b/gr-trellis/src/examples/test_tcm.py
index bd7fa0b3e5..d2e3c62716 100755
--- a/gr-trellis/src/examples/test_tcm.py
+++ b/gr-trellis/src/examples/test_tcm.py
@@ -7,6 +7,8 @@ import math
 import sys
 import random
 import fsm_utils
+from gnuradio.eng_option import eng_option
+from optparse import OptionParser
 
 def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
     tb = gr.top_block ()
@@ -70,18 +72,25 @@ def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
 
 
 
-def main(args):
-    nargs = len (args)
-    if nargs == 3:
-        fname=args[0]
-        esn0_db=float(args[1]) # Es/No in dB
-        rep=int(args[2]) # number of times the experiment is run to collect enough errors
-    else:
-        sys.stderr.write ('usage: test_tcm.py fsm_fname Es/No_db  repetitions\n')
-        sys.exit (1)
+def main():
+    parser = OptionParser(option_class=eng_option)
+    parser.add_option("-f", "--fsm_file", type="string", default="fsm_files/awgn1o2_4.fsm", help="Filename containing the fsm specification, e.g. -f fsm_files/awgn1o2_4.fsm (default=fsm_files/awgn1o2_4.fsm)")
+    parser.add_option("-e", "--esn0", type="eng_float", default=10.0, help="Symbol energy to noise PSD level ratio in dB, e.g., -e 10.0 (default=10.0)")
+    parser.add_option("-r", "--repetitions", type="int", default=100, help="Number of packets to be generated for the simulation, e.g., -r 100 (default=100)")
+
+    (options, args) = parser.parse_args ()
+    if len(args) != 0:
+        parser.print_help()
+        raise SystemExit, 1
+
+    fname=options.fsm_file
+    esn0_db=float(options.esn0)
+    rep=int(options.repetitions)
 
     # system parameters
     f=trellis.fsm(fname) # get the FSM specification from a file
+    # alternatively you can specify the fsm from its generator matrix
+    #f=trellis.fsm(1,2,[5,7]) 
     Kb=1024*16  # packet size in bits (make it multiple of 16 so it can be packed in a short)
     bitspersymbol = int(round(math.log(f.I())/math.log(2))) # bits per FSM input symbol
     K=Kb/bitspersymbol # packet size in trellis steps
@@ -114,4 +123,4 @@ def main(args):
 
 
 if __name__ == '__main__':
-    main (sys.argv[1:])
+    main()
-- 
cgit v1.2.3