@@ -255,17 +255,19 @@ def sm_measure(sm: SpeedMeter, to: float = 0.1, freq: Optional[int] = 2*10**8) -
255
255
return sm .measure (to , freq )
256
256
257
257
258
- def main ():
258
+ def _main ():
259
259
help_dict = {
260
260
"device" : "set the target device" ,
261
261
"index" : "select index (instance) of the GLS in the Device Tree" ,
262
262
"right" : "select the RIGHT side of the GLS to use the MFB Generator or set loopback" ,
263
263
"left" : "select the LEFT side of the GLS to use the MFB Generator or set loopback" ,
264
264
"loopback" : "enable (1) or disable (0) loopback (on the '-R' or '-L' side)" ,
265
- "generate" : "start (1) or stop (0) generating (to the '-R' or '-L' side), 'c' to print its config " ,
265
+ "generate" : "start (1) or stop (0) generating (to the '-R' or '-L' side)" ,
266
266
"size" : "set frame size for the ('-R' or '-L') MFB Generator" ,
267
267
"measure" : "measure the throughput using selected Speed Meter (SM), 'a' for all, '0,1' by default" ,
268
268
"config" : "print full configuration and exit" ,
269
+ "gen-config" : "generator config - either print full configuration (no args) or set a value"
270
+ " with two extra args"
269
271
}
270
272
271
273
gls_desc = """
@@ -307,10 +309,11 @@ def main():
307
309
arg_parser .add_argument ("-R" , "--right" , action = "store_true" , help = help_dict ["right" ])
308
310
arg_parser .add_argument ("-L" , "--left" , action = "store_true" , help = help_dict ["left" ])
309
311
arg_parser .add_argument ("-l" , "--loopback" , type = int , choices = [0 , 1 ], help = help_dict ["loopback" ])
310
- arg_parser .add_argument ("-g" , "--generate" , nargs = "?" , choices = ["0" , "1" , "c" ], help = help_dict ["generate" ])
312
+ arg_parser .add_argument ("-g" , "--generate" , nargs = "?" , choices = ["0" , "1" ], help = help_dict ["generate" ])
311
313
arg_parser .add_argument ("-s" , "--size" , type = int , help = help_dict ["size" ])
312
314
arg_parser .add_argument ("-m" , "--measure" , nargs = '?' , const = "default" , choices = ["default" , "0" , "1" , "2" , "3" , "a" ], help = help_dict ["measure" ])
313
315
arg_parser .add_argument ("-c" , "--config" , action = "store_true" , help = help_dict ["config" ])
316
+ arg_parser .add_argument ("-C" , "--gen-config" , nargs = "*" , help = help_dict ["gen-config" ])
314
317
args = arg_parser .parse_args ()
315
318
316
319
try :
@@ -377,9 +380,35 @@ def main():
377
380
elif "0" in args .generate :
378
381
s .gen_stop ()
379
382
380
- if "c" in args .generate :
383
+ if args .gen_config is not None :
384
+ if len (args .gen_config ) == 0 :
381
385
print ("MFB Generator configuration:" )
382
386
print (tabulate (s .gen .get_fconfiguration ()))
387
+ elif len (args .gen_config ) == 2 :
388
+ attr , value = args .gen_config
389
+ s .gen .configure_attr (attr , value )
390
+ else :
391
+ raise ValueError ("Invalid number of arguments" )
392
+
393
+
394
+ def main ():
395
+ EXIT_ERROR = 1
396
+
397
+ try :
398
+ _main ()
399
+ except IndexError as exc :
400
+ print ("Index error:" , exc )
401
+ exit (EXIT_ERROR )
402
+ except NotImplementedError as exc :
403
+ print ("Error, feature not yet implemented:" , exc )
404
+ exit (EXIT_ERROR )
405
+ except ValueError as exc :
406
+ print ("Invalid input:" , exc )
407
+ print ("Maybe a wrong combination of arguments or unknown configuration attribute?" )
408
+ exit (EXIT_ERROR )
409
+ except Exception as exc :
410
+ print ("Unexpected error: " , exc )
411
+ exit (EXIT_ERROR )
383
412
384
413
385
414
if __name__ == "__main__" :
0 commit comments