Skip to content

Commit

Permalink
Added baud rate user input value checking per FaradayRF#30
Browse files Browse the repository at this point in the history
* Added baud rate value and type checking
* Changed argparse input type to integer
  • Loading branch information
kb1lqc committed Mar 11, 2018
1 parent 12334dc commit 9e84abf
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion faradayio_cli/faradayio_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def setupArgparse():
# Optional arguments
parser.add_argument("--addr", default="10.0.0.1",
help="Set IP Address of TUN adapter (Faraday Radio)")
parser.add_argument("-b", "--baud", default="115200",
parser.add_argument("-b", "--baud", default=115200, type=int,
help="Set serial port baud rate")
parser.add_argument("-l", "--loopback", action="store_true",
help="Use software loopback serial port")
Expand Down Expand Up @@ -78,6 +78,17 @@ def checkUserInput(args):
# Expect an IP address that is valid
ipaddress.IPv4Address(args.addr)

# Check Baud Rate
# Expect and integer
if not isinstance(args.baud, int):
raise TypeError
# Expect and integer that is a standard serial value
# Should be able to use argparse choices too
baudrate = [50, 75, 110, 134, 150, 200, 600, 1200, 1800, 2400, 4800, 9600,
19200, 38400, 57600, 115200, 230400, 460800, 500000, 57600,
921600]
if args.baud not in baudrate:
raise ValueError

def setupSerialPort(loopback, port, baud, readtimeout, writetimeout):
"""Sets up serial port by connecting to phsyical or software port.
Expand Down

0 comments on commit 9e84abf

Please sign in to comment.