fake_trx/burst_gen.py: add burst capture support

Now all generated bursts can be also written to a capture file,
using a new option called '--output-file'. If a file already
exists, bursts would be appended to the end. Otherwise a new
capture file is created.

Change-Id: I074ff7dbc4d6beecdecce20de9dade5939e707f2
This commit is contained in:
Vadim Yanitskiy 2018-02-20 18:19:48 +07:00
parent 3dfd6cbae5
commit 711e2f256e
1 changed files with 15 additions and 1 deletions

View File

@ -27,6 +27,7 @@ import getopt
import sys import sys
from rand_burst_gen import RandBurstGen from rand_burst_gen import RandBurstGen
from data_dump import DATADumpFile
from data_if import DATAInterface from data_if import DATAInterface
from gsm_shared import * from gsm_shared import *
from data_msg import * from data_msg import *
@ -43,6 +44,7 @@ class Application:
remote_addr = "127.0.0.1" remote_addr = "127.0.0.1"
base_port = 5700 base_port = 5700
conn_mode = "TRX" conn_mode = "TRX"
output_file = None
burst_type = None burst_type = None
burst_count = 1 burst_count = 1
@ -64,6 +66,10 @@ class Application:
# Set up signal handlers # Set up signal handlers
signal.signal(signal.SIGINT, self.sig_handler) signal.signal(signal.SIGINT, self.sig_handler)
# Open requested capture file
if self.output_file is not None:
self.ddf = DATADumpFile(self.output_file)
def run(self): def run(self):
# Init DATA interface with TRX or L1 # Init DATA interface with TRX or L1
if self.conn_mode == "TRX": if self.conn_mode == "TRX":
@ -133,6 +139,10 @@ class Application:
# Send message # Send message
self.data_if.send_msg(msg) self.data_if.send_msg(msg)
# Append a new message to the capture
if self.output_file is not None:
self.ddf.append_msg(msg)
self.shutdown() self.shutdown()
def print_copyright(self): def print_copyright(self):
@ -144,6 +154,7 @@ class Application:
" -h --help this text\n\n" " -h --help this text\n\n"
s += " TRX interface specific\n" \ s += " TRX interface specific\n" \
" -o --output-file Write bursts to a capture file\n" \
" -m --conn-mode Send bursts to: TRX (default) / L1\n" \ " -m --conn-mode Send bursts to: TRX (default) / L1\n" \
" -r --remote-addr Set remote address (default %s)\n" \ " -r --remote-addr Set remote address (default %s)\n" \
" -p --base-port Set base port number (default %d)\n\n" " -p --base-port Set base port number (default %d)\n\n"
@ -165,9 +176,10 @@ class Application:
def parse_argv(self): def parse_argv(self):
try: try:
opts, args = getopt.getopt(sys.argv[1:], opts, args = getopt.getopt(sys.argv[1:],
"m:r:p:b:c:f:t:h", "o:m:r:p:b:c:f:t:h",
[ [
"help", "help",
"output-file="
"conn-mode=", "conn-mode=",
"remote-addr=", "remote-addr=",
"base-port=", "base-port=",
@ -188,6 +200,8 @@ class Application:
self.print_help() self.print_help()
sys.exit(2) sys.exit(2)
elif o in ("-o", "--output-file"):
self.output_file = v
elif o in ("-m", "--conn-mode"): elif o in ("-m", "--conn-mode"):
self.conn_mode = v self.conn_mode = v
elif o in ("-r", "--remote-addr"): elif o in ("-r", "--remote-addr"):