Change in gr-gsm[master]: apps/grgsm_trx: migrate from getopt to argparse

2018-09-13 Thread Piotr Krysik
Piotr Krysik has submitted this change and it was merged. ( 
https://gerrit.osmocom.org/10832 )

Change subject: apps/grgsm_trx: migrate from getopt to argparse
..

apps/grgsm_trx: migrate from getopt to argparse

Change-Id: I24a17b4cd44db0ce95a19d7470f4f09f3c85a26d
---
M apps/grgsm_trx
1 file changed, 69 insertions(+), 106 deletions(-)

Approvals:
  Harald Welte: Looks good to me, but someone else must approve
  Piotr Krysik: Looks good to me, approved; Verified



diff --git a/apps/grgsm_trx b/apps/grgsm_trx
index 6efed07..d57c979 100755
--- a/apps/grgsm_trx
+++ b/apps/grgsm_trx
@@ -4,6 +4,7 @@
 # GR-GSM based transceiver
 #
 # (C) 2016-2018 by Vadim Yanitskiy 
+# (C) 2017-2018 by Piotr Krysik 
 #
 # All Rights Reserved
 #
@@ -22,9 +23,10 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

 import signal
-import getopt
 import sys

+from argparse import ArgumentParser
+from argparse import ArgumentTypeError
 from gnuradio import eng_notation

 from grgsm.trx import ctrl_if_bb
@@ -33,31 +35,25 @@

 COPYRIGHT = \
"Copyright (C) 2016-2018 by Vadim Yanitskiy \n" \
-   "Copyright (C) 2017 by Piotr Krysik \n" \
+   "Copyright (C) 2017-2018 by Piotr Krysik \n" \
"License GPLv2+: GNU GPL version 2 or later " \
"\n" \
"This is free software: you are free to change and redistribute it.\n" \
"There is NO WARRANTY, to the extent permitted by law.\n"

 class Application:
-   # Application variables
-   remote_addr = "127.0.0.1"
-   bind_addr = "0.0.0.0"
-   base_port = 6700
-
-   # PHY specific
-   phy_sample_rate = radio_if.SAMPLE_RATE
-   phy_freq_offset_hz = None
-   phy_tx_antenna = "TX/RX"
-   phy_rx_antenna = "RX2"
-   phy_rx_gain = 30
-   phy_tx_gain = 10
-   phy_args = ""
-   phy_ppm = 0
-
-   def __init__(self):
-   self.print_copyright()
-   self.parse_argv()
+   def __init__(self, argv):
+   self.remote_addr = argv.remote_addr
+   self.bind_addr = argv.bind_addr
+   self.base_port = argv.base_port
+   self.phy_args = argv.args
+   self.phy_sample_rate = argv.sample_rate
+   self.phy_rx_gain = argv.rx_gain
+   self.phy_tx_gain = argv.tx_gain
+   self.phy_rx_antenna = argv.rx_antenna
+   self.phy_tx_antenna = argv.tx_antenna
+   self.phy_freq_offset_hz = argv.freq_offset
+   self.phy_ppm = argv.ppm

# Set up signal handlers
signal.signal(signal.SIGINT, self.sig_handler)
@@ -95,97 +91,64 @@
print("[i] Shutting down...")
self.radio.shutdown()

-   def print_copyright(self):
-   print(COPYRIGHT)
-
-   def print_help(self):
-   s  = " Usage: " + sys.argv[0] + " [options]\n\n" \
-" Some help...\n" \
-"  -h --help this text\n\n"
-
-   # TRX specific
-   s += " TRX interface specific\n" \
-"  -i --remote-addr  Set remote address (default 
%s)\n" \
-"  -b --bind-addrSet bind address (default %s)\n" \
-"  -p --base-portSet base port number (default 
%d)\n\n"
-
-   # PHY specific
-   s += " Radio interface specific\n" \
-"  -a --device-args  Set device arguments\n" \
-"  -s --sample-rate  Set sample rate\n" \
-"  -g --rx-gain  Set RX gain (default %d)\n" \
-"  -G --tx-gain  Set TX gain (default %d)\n" \
-" --rx-antenna   Set RX antenna (default %s)\n" \
-" --tx-antenna   Set TX antenna (default %s)\n" \
-" --freq-offset  Shift baseband freq. (e.g. 
-500M)\n" \
-" --ppm  Set frequency correction (default 
%d)\n"
-
-   print(s % (
-   self.remote_addr,
-   self.bind_addr,
-   self.base_port,
-   self.phy_rx_gain,
-   self.phy_tx_gain,
-   self.phy_rx_antenna,
-   self.phy_tx_antenna,
-   self.phy_ppm))
-
-   def parse_argv(self):
-   try:
-   opts, args = getopt.getopt(sys.argv[1:],
-   "i:b:p:a:s:g:G:h",
-   ["help", "remote-addr=", "bind-addr=", 
"base-port=",
-   "device-args=", "sample-rate=", "rx-gain=", 
"tx-gain=",
-   "ppm=", "rx-antenna=", "tx-antenna=", 
"freq-offset="])
-   except getopt.GetoptError as err:
-   

Change in gr-gsm[master]: apps/grgsm_trx: migrate from getopt to argparse

2018-09-13 Thread Piotr Krysik
Piotr Krysik has posted comments on this change. ( 
https://gerrit.osmocom.org/10832 )

Change subject: apps/grgsm_trx: migrate from getopt to argparse
..


Patch Set 3: Verified+1 Code-Review+2


--
To view, visit https://gerrit.osmocom.org/10832
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: gr-gsm
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I24a17b4cd44db0ce95a19d7470f4f09f3c85a26d
Gerrit-Change-Number: 10832
Gerrit-PatchSet: 3
Gerrit-Owner: Vadim Yanitskiy 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Piotr Krysik 
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-Comment-Date: Thu, 13 Sep 2018 08:34:20 +
Gerrit-HasComments: No
Gerrit-HasLabels: Yes


Change in gr-gsm[master]: apps/grgsm_trx: migrate from getopt to argparse

2018-09-12 Thread Harald Welte
Harald Welte has posted comments on this change. ( 
https://gerrit.osmocom.org/10832 )

Change subject: apps/grgsm_trx: migrate from getopt to argparse
..


Patch Set 3: Code-Review+1


--
To view, visit https://gerrit.osmocom.org/10832
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: gr-gsm
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I24a17b4cd44db0ce95a19d7470f4f09f3c85a26d
Gerrit-Change-Number: 10832
Gerrit-PatchSet: 3
Gerrit-Owner: Vadim Yanitskiy 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Piotr Krysik 
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-Comment-Date: Wed, 12 Sep 2018 07:41:51 +
Gerrit-HasComments: No
Gerrit-HasLabels: Yes


Change in gr-gsm[master]: apps/grgsm_trx: migrate from getopt to argparse

2018-09-11 Thread Vadim Yanitskiy
Hello Piotr Krysik,

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

https://gerrit.osmocom.org/10832

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

Change subject: apps/grgsm_trx: migrate from getopt to argparse
..

apps/grgsm_trx: migrate from getopt to argparse

Change-Id: I24a17b4cd44db0ce95a19d7470f4f09f3c85a26d
---
M apps/grgsm_trx
1 file changed, 69 insertions(+), 106 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/gr-gsm refs/changes/32/10832/3
--
To view, visit https://gerrit.osmocom.org/10832
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: gr-gsm
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I24a17b4cd44db0ce95a19d7470f4f09f3c85a26d
Gerrit-Change-Number: 10832
Gerrit-PatchSet: 3
Gerrit-Owner: Vadim Yanitskiy 
Gerrit-Reviewer: Piotr Krysik 
Gerrit-Reviewer: Vadim Yanitskiy 


Change in gr-gsm[master]: apps/grgsm_trx: migrate from getopt to argparse

2018-09-11 Thread Piotr Krysik
Piotr Krysik has posted comments on this change. ( 
https://gerrit.osmocom.org/10832 )

Change subject: apps/grgsm_trx: migrate from getopt to argparse
..


Patch Set 1: -Verified -Code-Review


--
To view, visit https://gerrit.osmocom.org/10832
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: gr-gsm
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I24a17b4cd44db0ce95a19d7470f4f09f3c85a26d
Gerrit-Change-Number: 10832
Gerrit-PatchSet: 1
Gerrit-Owner: Vadim Yanitskiy 
Gerrit-Reviewer: Piotr Krysik 
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-Comment-Date: Tue, 11 Sep 2018 08:33:38 +
Gerrit-HasComments: No
Gerrit-HasLabels: Yes


Change in gr-gsm[master]: apps/grgsm_trx: migrate from getopt to argparse

2018-09-11 Thread Vadim Yanitskiy
Vadim Yanitskiy has posted comments on this change. ( 
https://gerrit.osmocom.org/10832 )

Change subject: apps/grgsm_trx: migrate from getopt to argparse
..


Patch Set 1:

> some of my changes were just thrown away without explanation

The explanation is simple: both are not related to argparse itself.
I prefer to have atomic changes, so if some day we will have to
revert this particular commit, we wouldn't lose the changes you
mentioned below.

So, let's keep this change as-is, because it does exactly what is
stated in the commit message. While renaming variables and changing
class definitions for sure can (and I think should) be done in
separate changes ;)


--
To view, visit https://gerrit.osmocom.org/10832
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: gr-gsm
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I24a17b4cd44db0ce95a19d7470f4f09f3c85a26d
Gerrit-Change-Number: 10832
Gerrit-PatchSet: 1
Gerrit-Owner: Vadim Yanitskiy 
Gerrit-Reviewer: Piotr Krysik 
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-Comment-Date: Tue, 11 Sep 2018 07:56:15 +
Gerrit-HasComments: No
Gerrit-HasLabels: No


Change in gr-gsm[master]: apps/grgsm_trx: migrate from getopt to argparse

2018-09-11 Thread Piotr Krysik
Piotr Krysik has posted comments on this change. ( 
https://gerrit.osmocom.org/10832 )

Change subject: apps/grgsm_trx: migrate from getopt to argparse
..


Patch Set 1: Verified+1 Code-Review+2

(2 comments)

This is not just rework of the previous change, some of my changes were just 
thrown away without explanation. See the comments.

https://gerrit.osmocom.org/#/c/10832/1/apps/grgsm_trx
File apps/grgsm_trx:

https://gerrit.osmocom.org/#/c/10832/1/apps/grgsm_trx@55
PS1, Line 55: argv
_hz suffix is redundant, of course frequency is in Hz


https://gerrit.osmocom.org/#/c/10832/1/apps/grgsm_trx@71
PS1, Line 71:   self.radio.freq_offset_hz = 
self.phy_freq_offset_hz
this should be passed as parameter to radio_if, there is no reason to set it to 
None in any circumstances, it can safely be 0 by default



--
To view, visit https://gerrit.osmocom.org/10832
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: gr-gsm
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I24a17b4cd44db0ce95a19d7470f4f09f3c85a26d
Gerrit-Change-Number: 10832
Gerrit-PatchSet: 1
Gerrit-Owner: Vadim Yanitskiy 
Gerrit-Reviewer: Piotr Krysik 
Gerrit-Comment-Date: Tue, 11 Sep 2018 07:41:49 +
Gerrit-HasComments: Yes
Gerrit-HasLabels: Yes


Change in gr-gsm[master]: apps/grgsm_trx: migrate from getopt to argparse

2018-09-07 Thread Vadim Yanitskiy
Vadim Yanitskiy has uploaded this change for review. ( 
https://gerrit.osmocom.org/10832


Change subject: apps/grgsm_trx: migrate from getopt to argparse
..

apps/grgsm_trx: migrate from getopt to argparse

Change-Id: I24a17b4cd44db0ce95a19d7470f4f09f3c85a26d
---
M apps/grgsm_trx
1 file changed, 69 insertions(+), 106 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/gr-gsm refs/changes/32/10832/1

diff --git a/apps/grgsm_trx b/apps/grgsm_trx
index 6efed07..d57c979 100755
--- a/apps/grgsm_trx
+++ b/apps/grgsm_trx
@@ -4,6 +4,7 @@
 # GR-GSM based transceiver
 #
 # (C) 2016-2018 by Vadim Yanitskiy 
+# (C) 2017-2018 by Piotr Krysik 
 #
 # All Rights Reserved
 #
@@ -22,9 +23,10 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

 import signal
-import getopt
 import sys

+from argparse import ArgumentParser
+from argparse import ArgumentTypeError
 from gnuradio import eng_notation

 from grgsm.trx import ctrl_if_bb
@@ -33,31 +35,25 @@

 COPYRIGHT = \
"Copyright (C) 2016-2018 by Vadim Yanitskiy \n" \
-   "Copyright (C) 2017 by Piotr Krysik \n" \
+   "Copyright (C) 2017-2018 by Piotr Krysik \n" \
"License GPLv2+: GNU GPL version 2 or later " \
"\n" \
"This is free software: you are free to change and redistribute it.\n" \
"There is NO WARRANTY, to the extent permitted by law.\n"

 class Application:
-   # Application variables
-   remote_addr = "127.0.0.1"
-   bind_addr = "0.0.0.0"
-   base_port = 6700
-
-   # PHY specific
-   phy_sample_rate = radio_if.SAMPLE_RATE
-   phy_freq_offset_hz = None
-   phy_tx_antenna = "TX/RX"
-   phy_rx_antenna = "RX2"
-   phy_rx_gain = 30
-   phy_tx_gain = 10
-   phy_args = ""
-   phy_ppm = 0
-
-   def __init__(self):
-   self.print_copyright()
-   self.parse_argv()
+   def __init__(self, argv):
+   self.remote_addr = argv.remote_addr
+   self.bind_addr = argv.bind_addr
+   self.base_port = argv.base_port
+   self.phy_args = argv.args
+   self.phy_sample_rate = argv.sample_rate
+   self.phy_rx_gain = argv.rx_gain
+   self.phy_tx_gain = argv.tx_gain
+   self.phy_rx_antenna = argv.rx_antenna
+   self.phy_tx_antenna = argv.tx_antenna
+   self.phy_freq_offset_hz = argv.freq_offset
+   self.phy_ppm = argv.ppm

# Set up signal handlers
signal.signal(signal.SIGINT, self.sig_handler)
@@ -95,97 +91,64 @@
print("[i] Shutting down...")
self.radio.shutdown()

-   def print_copyright(self):
-   print(COPYRIGHT)
-
-   def print_help(self):
-   s  = " Usage: " + sys.argv[0] + " [options]\n\n" \
-" Some help...\n" \
-"  -h --help this text\n\n"
-
-   # TRX specific
-   s += " TRX interface specific\n" \
-"  -i --remote-addr  Set remote address (default 
%s)\n" \
-"  -b --bind-addrSet bind address (default %s)\n" \
-"  -p --base-portSet base port number (default 
%d)\n\n"
-
-   # PHY specific
-   s += " Radio interface specific\n" \
-"  -a --device-args  Set device arguments\n" \
-"  -s --sample-rate  Set sample rate\n" \
-"  -g --rx-gain  Set RX gain (default %d)\n" \
-"  -G --tx-gain  Set TX gain (default %d)\n" \
-" --rx-antenna   Set RX antenna (default %s)\n" \
-" --tx-antenna   Set TX antenna (default %s)\n" \
-" --freq-offset  Shift baseband freq. (e.g. 
-500M)\n" \
-" --ppm  Set frequency correction (default 
%d)\n"
-
-   print(s % (
-   self.remote_addr,
-   self.bind_addr,
-   self.base_port,
-   self.phy_rx_gain,
-   self.phy_tx_gain,
-   self.phy_rx_antenna,
-   self.phy_tx_antenna,
-   self.phy_ppm))
-
-   def parse_argv(self):
-   try:
-   opts, args = getopt.getopt(sys.argv[1:],
-   "i:b:p:a:s:g:G:h",
-   ["help", "remote-addr=", "bind-addr=", 
"base-port=",
-   "device-args=", "sample-rate=", "rx-gain=", 
"tx-gain=",
-   "ppm=", "rx-antenna=", "tx-antenna=", 
"freq-offset="])
-   except getopt.GetoptError as err:
-   # Print(help and exit)
-