From 236bc056bb339f65906d3364892f8862b25e02a5 Mon Sep 17 00:00:00 2001 From: tanupoo Date: Fri, 28 Aug 2020 19:14:19 +0900 Subject: [PATCH] moved parse_args() from library to toa.py. --- README.md | 2 +- lorawan_toa_cal.py | 50 --------------------------------------------- toa.py | 51 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index 99cdce3..30c7d46 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ LoRa Time on Air calculator. positional arguments: SF Spreading Factor. It should be from 7 to 12. SIZE PHY payload size in byte. Remember that PHY payload - (i.e. MAC frame) is consist of MHDR(1) + MAC payload + + (i.e. MAC frame) consists of MHDR(1) + MAC payload + MIC(4), or MHDR(1) + FHDR(7) + FPort(1) + APP + MIC(4). For example, SIZE for Join Request is going to be 23. If the size of an application message (APP) is 12, SIZE diff --git a/lorawan_toa_cal.py b/lorawan_toa_cal.py index 0c741d4..48b6784 100644 --- a/lorawan_toa_cal.py +++ b/lorawan_toa_cal.py @@ -94,53 +94,3 @@ def get_toa(n_size, n_sf, n_bw=125, enable_auto_ldro=True, enable_ldro=False, return ret -import argparse - -def parse_args(): - p = argparse.ArgumentParser( - description="LoRa Time on Air calculator.") - p.add_argument("n_sf", metavar="SF", type=int, - help="Spreading Factor. It should be from 7 to 12.") - p.add_argument("n_size", metavar="SIZE", type=int, - help="""PHY payload size in byte. - Remember that PHY payload (i.e. MAC frame) is consist of - MHDR(1) + MAC payload + MIC(4), or - MHDR(1) + FHDR(7) + FPort(1) + APP + MIC(4). - For example, SIZE for Join Request is going to be 23. - If the size of an application message (APP) is - 12, SIZE is going to be 25. """) - p.add_argument("--band-width", action="store", dest="n_bw", type=int, - default=125, metavar="NUMBER", - help="bandwidth in kHz. default is 125 kHz.") - p.add_argument("--disable-auto-ldro", action="store_false", - dest="enable_auto_ldro", - help="disable the auto LDRO and disable LDRO.") - p.add_argument("--enable-ldro", action="store_true", dest="enable_ldro", - help="This option is available when the auto LDRO is disabled.") - p.add_argument("--disable-eh", action="store_false", dest="enable_eh", - help="disable the explicit header.") - p.add_argument("--downlink", action="store_false", dest="enable_crc", - help="disable the CRC field, which is for the LoRaWAN downlink stream.") - p.add_argument("--disable-crc", action="store_false", dest="enable_crc", - help="same effect as the --downlink option.") - p.add_argument("--cr", action="store", dest="n_cr", - type=int, default=1, metavar="NUMBER", - help="specify the CR value. default is 1 as LoRaWAN does.") - p.add_argument("--preamble", action="store", dest="n_preamble", - type=int, default=8, metavar="NUMBER", - help="specify the preamble. default is 8 for AS923.") - p.add_argument("--duty-cycle", action="store", dest="n_duty_cycle", - type=int, default=1, metavar="NUMBER", - help="specify the duty cycle in percentage. default is 1 %%.") - p.add_argument("-v", action="store_true", dest="f_verbose", - default=False, - help="enable verbose mode.") - p.add_argument("-d", action="append_const", dest="_f_debug", default=[], - const=1, help="increase debug mode.") - - args = p.parse_args() - - args.v_de = False - args.debug_level = len(args._f_debug) - return args - diff --git a/toa.py b/toa.py index 3ece2ab..e466a2e 100755 --- a/toa.py +++ b/toa.py @@ -1,6 +1,55 @@ #!/usr/bin/env python -from lorawan_toa_cal import get_toa, parse_args +from lorawan_toa_cal import get_toa +import argparse + +def parse_args(): + p = argparse.ArgumentParser( + description="LoRa Time on Air calculator.") + p.add_argument("n_sf", metavar="SF", type=int, + help="Spreading Factor. It should be from 7 to 12.") + p.add_argument("n_size", metavar="SIZE", type=int, + help="""PHY payload size in byte. + Remember that PHY payload (i.e. MAC frame) consists of + MHDR(1) + MAC payload + MIC(4), or + MHDR(1) + FHDR(7) + FPort(1) + APP + MIC(4). + For example, SIZE for Join Request is going to be 23. + If the size of an application message (APP) is + 12, SIZE is going to be 25. """) + p.add_argument("--band-width", action="store", dest="n_bw", type=int, + default=125, metavar="NUMBER", + help="bandwidth in kHz. default is 125 kHz.") + p.add_argument("--disable-auto-ldro", action="store_false", + dest="enable_auto_ldro", + help="disable the auto LDRO and disable LDRO.") + p.add_argument("--enable-ldro", action="store_true", dest="enable_ldro", + help="This option is available when the auto LDRO is disabled.") + p.add_argument("--disable-eh", action="store_false", dest="enable_eh", + help="disable the explicit header.") + p.add_argument("--downlink", action="store_false", dest="enable_crc", + help="disable the CRC field, which is for the LoRaWAN downlink stream.") + p.add_argument("--disable-crc", action="store_false", dest="enable_crc", + help="same effect as the --downlink option.") + p.add_argument("--cr", action="store", dest="n_cr", + type=int, default=1, metavar="NUMBER", + help="specify the CR value. default is 1 as LoRaWAN does.") + p.add_argument("--preamble", action="store", dest="n_preamble", + type=int, default=8, metavar="NUMBER", + help="specify the preamble. default is 8 for AS923.") + p.add_argument("--duty-cycle", action="store", dest="n_duty_cycle", + type=int, default=1, metavar="NUMBER", + help="specify the duty cycle in percentage. default is 1 %%.") + p.add_argument("-v", action="store_true", dest="f_verbose", + default=False, + help="enable verbose mode.") + p.add_argument("-d", action="append_const", dest="_f_debug", default=[], + const=1, help="increase debug mode.") + + args = p.parse_args() + + args.v_de = False + args.debug_level = len(args._f_debug) + return args if __name__ == "__main__" : opt = parse_args()