From a2df42ad09b27685d51d974ab86a306276f43a72 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 29 Dec 2017 09:04:49 +0100 Subject: DPDCE: Add status option --- dpd/main.py | 83 ++++++++++++++++++++++++++++++-------------------------- dpd/src/Adapt.py | 13 +++++++++ 2 files changed, 57 insertions(+), 39 deletions(-) (limited to 'dpd') diff --git a/dpd/main.py b/dpd/main.py index 3ca0d35..1a2d696 100755 --- a/dpd/main.py +++ b/dpd/main.py @@ -65,6 +65,8 @@ parser.add_argument('--name', default="", type=str, help='Name of the logging directory') parser.add_argument('-r', '--reset', action="store_true", help='Reset the DPD settings to the defaults.') +parser.add_argument('-s', '--status', action="store_true", + help='Display the currently running DPD settings.') cli_args = parser.parse_args() @@ -84,25 +86,34 @@ plot = cli_args.plot # Logging import logging -dt = datetime.datetime.now().isoformat() -logging_path = '/tmp/dpd_{}'.format(dt).replace('.', '_').replace(':', '-') -if name: - logging_path += '_' + name -os.makedirs(logging_path) -logging.basicConfig(format='%(asctime)s - %(module)s - %(levelname)s - %(message)s', - datefmt='%Y-%m-%d %H:%M:%S', - filename='{}/dpd.log'.format(logging_path), - filemode='w', - level=logging.DEBUG) -# also log up to INFO to console -console = logging.StreamHandler() -console.setLevel(logging.INFO) -# set a format which is simpler for console use -formatter = logging.Formatter('%(asctime)s - %(module)s - %(levelname)s - %(message)s') -# tell the handler to use this format -console.setFormatter(formatter) -# add the handler to the root logger -logging.getLogger('').addHandler(console) +# Simple usage scenarios don't need to clutter /tmp +if not (cli_args.status or cli_args.reset): + dt = datetime.datetime.now().isoformat() + logging_path = '/tmp/dpd_{}'.format(dt).replace('.', '_').replace(':', '-') + if name: + logging_path += '_' + name + print("Logs and plots written to {}".format(logging_path)) + os.makedirs(logging_path) + logging.basicConfig(format='%(asctime)s - %(module)s - %(levelname)s - %(message)s', + datefmt='%Y-%m-%d %H:%M:%S', + filename='{}/dpd.log'.format(logging_path), + filemode='w', + level=logging.DEBUG) + # also log up to INFO to console + console = logging.StreamHandler() + console.setLevel(logging.INFO) + # set a format which is simpler for console use + formatter = logging.Formatter('%(asctime)s - %(module)s - %(levelname)s - %(message)s') + # tell the handler to use this format + console.setFormatter(formatter) + # add the handler to the root logger + logging.getLogger('').addHandler(console) +else: + dt = datetime.datetime.now().isoformat() + logging.basicConfig(format='%(asctime)s - %(module)s - %(levelname)s - %(message)s', + datefmt='%Y-%m-%d %H:%M:%S', + level=logging.DEBUG) + logging_path = None logging.info("DPDCE starting up with options: {}".format(cli_args)) @@ -128,6 +139,17 @@ meas = Measure(c, samplerate, port, num_req) extStat = ExtractStatistic(c) adapt = Adapt(c, port_rc, coef_path) +if cli_args.status: + status = { + "txgain": adapt.get_txgain(), + "rxgain": adapt.get_rxgain(), + "digital_gain": adapt.get_digital_gain(), + "predistorter": adapt.get_predistorter() + } + + logging.info("ODR-DabMod currently running with {}".format(status)) + sys.exit(0) + if cli_args.lut: model = Lut(c) else: @@ -154,26 +176,9 @@ rx_gain = adapt.get_rxgain() digital_gain = adapt.get_digital_gain() dpddata = adapt.get_predistorter() -if dpddata[0] == "poly": - coefs_am = dpddata[1] - coefs_pm = dpddata[2] - logging.info( - "TX gain {}, RX gain {}, dpd_coefs_am {}," - " dpd_coefs_pm {}, digital_gain {}".format( - tx_gain, rx_gain, coefs_am, coefs_pm, digital_gain - ) - ) -elif dpddata[0] == "lut": - scalefactor = dpddata[1] - lut = dpddata[2] - logging.info( - "TX gain {}, RX gain {}, LUT scalefactor {}," - " LUT {}, digital_gain {}".format( - tx_gain, rx_gain, scalefactor, lut, digital_gain - ) - ) -else: - logging.error("Unknown dpd data format {}".format(dpddata[0])) + +logging.info("TX gain {}, RX gain {}, digital_gain {}, {!s}".format( + tx_gain, rx_gain, digital_gain, Adapt.dpddata_to_str(dpddata))) if cli_args.reset: logging.info("DPD Settings were reset to default values.") diff --git a/dpd/src/Adapt.py b/dpd/src/Adapt.py index 153442b..53ef037 100644 --- a/dpd/src/Adapt.py +++ b/dpd/src/Adapt.py @@ -42,6 +42,19 @@ def _write_lut_file(scalefactor, lut, path): f.write("{}\n{}\n".format(coef.real, coef.imag)) f.close() +def dpddata_to_str(dpddata): + if dpddata[0] == "poly": + coefs_am = dpddata[1] + coefs_pm = dpddata[2] + return "dpd_coefs_am {}, dpd_coefs_pm {}".format( + self.coefs_am, self.coefs_pm) + elif dpddata[0] == "lut": + scalefactor = dpddata[1] + lut = dpddata[2] + return "LUT scalefactor {}, LUT {}".format( + scalefactor, lut) + else: + raise ValueError("Unknown dpddata type {}".format(dpddata[0])) class Adapt: """Uses the ZMQ remote control to change parameters of the DabMod -- cgit v1.2.3