Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/shell bootloader baudrate #159

Merged
merged 2 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions pyluos/tools/bootloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,14 +435,15 @@ def reboot_network(device, nodes_to_reboot):
# *******************************************************************************
def luos_flash(args):
print('Luos flash subcommand with parameters :')
print('\t--baudrate : ', args.baudrate)
print('\t--gate : ', args.gate)
print('\t--target : ', args.target)
print('\t--binary : ', args.binary)
print('\t--port : ', args.port)

if not (args.port):
try:
args.port= serial_discover()[0]
args.port= serial_discover(os.getenv('LUOS_BAUDRATE', args.baudrate))[0]
except:
sys.exit("Can't find any Gate interface")
return
Expand All @@ -462,7 +463,7 @@ def luos_flash(args):
f.close()

# init device
device = Device(args.port, background_task=False, baudrate=os.getenv('LUOS_BAUDRATE', 1000000))
device = Device(args.port, baudrate=os.getenv('LUOS_BAUDRATE', args.baudrate), background_task=False)

# find routing table
state = find_network(device)
Expand Down Expand Up @@ -546,16 +547,17 @@ def luos_flash(args):
# *******************************************************************************
def luos_detect(args):
print('Luos detect subcommand on port : ', args.port)
print('\tLuos detect subcommand at baudrate : ', args.baudrate)

if not (args.port):
try:
args.port= serial_discover()[0]
args.port= serial_discover(os.getenv('LUOS_BAUDRATE', args.baudrate))[0]
except:
sys.exit("Can't find any Gate interface")
return

# detect network
device = Device(args.port, baudrate=os.getenv('LUOS_BAUDRATE', 1000000))
device = Device(args.port, baudrate=os.getenv('LUOS_BAUDRATE', args.baudrate))
# print network to user
print(device.nodes)
device.close()
Expand All @@ -569,18 +571,19 @@ def luos_detect(args):
# *******************************************************************************
def luos_reset(args):
print('Luos discover subcommand on port : ', args.port)
print('\tLuos discover subcommand at baudrate : ', args.baudrate)

if not (args.port):
try:
args.port= serial_discover()[0]
args.port= serial_discover(os.getenv('LUOS_BAUDRATE', args.baudrate))[0]
except:
sys.exit("Can't find any Gate interface")
return


# send rescue command
print('Send reset command.')
port = serial.Serial(args.port, os.getenv('LUOS_BAUDRATE', 1000000), timeout=0.05)
port = serial.Serial(args.port, os.getenv('LUOS_BAUDRATE', args.baudrate), timeout=0.05)
rst_cmd = {
'bootloader': {
'command': {
Expand All @@ -595,7 +598,8 @@ def luos_reset(args):
port.close()

# detect network
device = Device(args.port, background_task=False)
device = Device(args.port, baudrate=os.getenv('LUOS_BAUDRATE', args.baudrate), background_task=False)

print(device.nodes)
device.close()

Expand Down Expand Up @@ -627,20 +631,29 @@ def luos_options():
help='target node to flash',
default=['2'],
nargs='*')
flash_parser.add_argument('--baudrate',
help='Choose pyluos serial baudrate default value = 1000000',
default=1000000)
flash_parser.set_defaults(func=luos_flash)

# declare "detect" subcommand
detect_parser = subparsers.add_parser('detect',
help='tool to detect luos network')
detect_parser.add_argument('port', help='port used to detect network',
nargs='?')
detect_parser.add_argument('--baudrate',
help='Choose pyluos serial baudrate default value = 1000000',
default=1000000)
detect_parser.set_defaults(func=luos_detect)

# declare "rescue" subcommand
rescue_parser = subparsers.add_parser('reset',
help='tool to reset one or multiple blocked nodes in rescue mode')
rescue_parser.add_argument('port', help='port used to access to the network',
nargs='?')
rescue_parser.add_argument('--baudrate',
help='Choose pyluos serial baudrate default value = 1000000',
default=1000000)
rescue_parser.set_defaults(func=luos_reset)

return parser
Expand Down
13 changes: 10 additions & 3 deletions pyluos/tools/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
from ..io.serial_io import Serial
import serial
import struct
import argparse

def serial_ports():
return Serial.available_hosts()

def serial_discover():
def serial_discover(baudrate=1000000):
serial_hosts = serial_ports()
available_serial = []
print("Searching for a gate available")
for serial_host in serial_hosts:
print("Testing " + str(serial_host))
try:
port = serial.Serial(serial_host, os.getenv('LUOS_BAUDRATE', 1000000), timeout=0.05)
port = serial.Serial(serial_host, baudrate, timeout=0.05)
JeromeGalan marked this conversation as resolved.
Show resolved Hide resolved
except:
continue

Expand All @@ -35,7 +36,13 @@ def serial_discover():
return available_serial

def main():
gate_list = serial_discover()
parser.add_argument("--baudrate", action="store",
help="Choose pyluos serial baudrate default value = 1000000",
default=1000000)

args = parser.parse_args()

gate_list = serial_discover(os.getenv('LUOS_BAUDRATE', args.baudrate))

if gate_list:
print("Available Luos gate on port : " + str(gate_list))
Expand Down
10 changes: 7 additions & 3 deletions pyluos/tools/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def main():
parser.add_argument("--version", action="store_true",
help="print version information and exit")

parser.add_argument("--baudrate", action="store",
help="Choose pyluos serial baudrate default value = 1000000",
default=1000000)

args = parser.parse_args()

def print_version():
Expand All @@ -51,12 +55,12 @@ def print_version():

if args.port is not None:
# Ready to rocks
device = Device(args.port)
device = Device(args.port, baudrate=os.getenv('LUOS_BAUDRATE', args.baudrate))
embed(banner1 = "\n Hit Ctrl-D to exit this interpreter.\n\nYour luos device has been successfully mounted into a \"device\" object:\n" + str(device.nodes) + "\n")
else:
Gates = serial_discover()
Gates = serial_discover(os.getenv('LUOS_BAUDRATE', args.baudrate))
if Gates:
device = Device(Gates[0])
device = Device(Gates[0], baudrate=os.getenv('LUOS_BAUDRATE', args.baudrate))
embed(banner1 = "\n Hit Ctrl-D to exit this interpreter.\n\nYour luos device has been successfully mounted into a \"device\" object:\n" + str(device.nodes) + "\n")

except OperationAbortedException:
Expand Down