Skip to content

Commit e251cf2

Browse files
authored
Merge pull request #187 from Luos-io/rc_2.2.12
Pyluos Release 2.2.12
2 parents e8530c6 + 0b287f8 commit e251cf2

File tree

4 files changed

+51
-41
lines changed

4 files changed

+51
-41
lines changed

pyluos/io/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def dumps(self, msg):
5252
def io_from_host(host, *args, **kwargs):
5353
for cls in IOs:
5454
if cls.is_host_compatible(host):
55-
return cls(host=host)
55+
return cls(host=host, **kwargs)
5656

5757
raise ValueError('No corresponding IO found (among {}).'.format(discover_hosts))
5858

pyluos/io/ws.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ def available_hosts(cls):
4444
if os.system('ping -c 1 -W1 -t1 {} > /dev/null 2>&1'.format(ip)) == 0
4545
]
4646

47-
def __init__(self, host, port=9342):
47+
def __init__(self, host, port=9342, baudrate=None):
4848
host = resolve_hostname(host, port)
4949

5050
self._ws = websocket.WebSocket()
5151
self._ws.connect("ws://" + str(host) + ":" + str(port)+"/ws")
5252

53-
self._msg = queue.Queue(500)
53+
self._msg = queue.Queue(4096)
5454
self._running = True
5555

5656
self._poll_loop = Thread(target=self._poll)

pyluos/tools/bootloader.py

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ def find_network(device):
6969
while ('routing_table' not in state):
7070
if ('route_table' in state):
7171
print('version of luos not supported')
72-
return
72+
return None
7373
state = device._poll_once()
7474
if (time.time()-startTime > 1):
7575
retry = retry +1
7676
if retry > 5:
7777
# detection is not working
78-
sys.exit("Detection failed.")
78+
print('Detection failed.')
79+
return None
7980
device._send({'detection': {}})
8081
startTime = time.time()
8182

@@ -243,7 +244,7 @@ def erase_flash(device, topic, nodes_to_program):
243244
return_value = False
244245
break
245246
# check if it is a response message
246-
if 'bootloader' in state:
247+
if 'bootloader' in state:
247248
for response in state['bootloader']:
248249
if (response['response'] == BOOTLOADER_ERASE_RESP):
249250
# this node responded, delete it from the failed nodes list
@@ -265,7 +266,7 @@ def erase_flash(device, topic, nodes_to_program):
265266
break
266267

267268
# check if it is a response message
268-
if 'bootloader' in state:
269+
if 'bootloader' in state:
269270
for response in state['bootloader']:
270271
if (response['response'] == BOOTLOADER_ERASE_RESP):
271272
# this node responded, delete it from the failed nodes list
@@ -540,7 +541,7 @@ def check_crc(device, topic, nodes_to_program):
540541

541542
# send crc command
542543
send_topic_command(device, topic, BOOTLOADER_CRC_TEST)
543-
544+
544545
state = device._poll_once()
545546
# wait bin_end response
546547
init_time = time.time()
@@ -556,7 +557,7 @@ def check_crc(device, topic, nodes_to_program):
556557
source_crc = int.from_bytes(compute_crc(), byteorder='big')
557558
node_crc = response['crc_value']
558559
node_id = response['node']
559-
# crc properly received
560+
# crc properly received
560561
if (source_crc == node_crc):
561562
print(u" ╰> CRC test for node", node_id, " : OK.")
562563
if node_id in failed_nodes:
@@ -588,7 +589,7 @@ def check_crc(device, topic, nodes_to_program):
588589
source_crc = int.from_bytes(compute_crc(), byteorder='big')
589590
node_crc = response['crc_value']
590591
node_id = response['node']
591-
# crc properly received
592+
# crc properly received
592593
if (source_crc == node_crc):
593594
print(u" ╰> CRC test for node", node_id, " : OK.")
594595
if node_id in failed_nodes:
@@ -613,30 +614,32 @@ def check_crc(device, topic, nodes_to_program):
613614
# *******************************************************************************
614615
def reboot_network(device, topic, nodes_to_reboot):
615616
for node in nodes_to_reboot:
616-
send_node_command(device, node, topic, BOOTLOADER_STOP)
617-
# delay to let gate send commands
618-
time.sleep(0.01)
617+
send_node_command(device, node, topic, BOOTLOADER_STOP)
618+
# delay to let gate send commands
619+
time.sleep(0.01)
619620
# *******************************************************************************
620621
# @brief command used to flash luos nodes
621622
# @param flash function arguments : -g, -t, -b
622623
# @return None
623624
# *******************************************************************************
624625
def luos_flash(args):
625-
print('Luos flash subcommand with parameters :')
626-
print('\t--baudrate : ', args.baudrate)
627-
print('\t--gate : ', args.gate)
628-
print('\t--target : ', args.target)
629-
print('\t--binary : ', args.binary)
630-
print('\t--port : ', args.port)
631-
632626
topic = 1
633627

634628
if not (args.port):
635629
try:
636630
args.port= serial_discover(os.getenv('LUOS_BAUDRATE', args.baudrate))[0]
637631
except:
638-
sys.exit()
639-
return
632+
print('Please specify a port to access the network.')
633+
return BOOTLOADER_FLASH_PORT_ERROR
634+
635+
baudrate = os.getenv('LUOS_BAUDRATE', args.baudrate)
636+
637+
print('Luos flash subcommand with parameters :')
638+
print('\t--baudrate : ', baudrate)
639+
print('\t--gate : ', args.gate)
640+
print('\t--target : ', args.target)
641+
print('\t--binary : ', args.binary)
642+
print('\t--port : ', args.port)
640643

641644
# state used to check each step
642645
machine_state = True
@@ -648,23 +651,26 @@ def luos_flash(args):
648651
try:
649652
f = open(FILEPATH, mode="rb")
650653
except IOError:
651-
sys.exit("Cannot open :", FILEPATH)
654+
print("Cannot open :", FILEPATH)
652655
return BOOTLOADER_FLASH_BINARY_ERROR
653656
else:
654657
f.close()
655658

656659
# init device
657-
device = Device(args.port, baudrate=os.getenv('LUOS_BAUDRATE', args.baudrate), background_task=False)
660+
device = Device(args.port, baudrate=baudrate, background_task=False)
658661

659662
# find routing table
660663
state = find_network(device)
664+
if state is None:
665+
return BOOTLOADER_DETECT_ERROR
661666

662667
# searching nodes to program in network
663668
(nodes_to_reboot, nodes_to_program) = create_target_list(args, state)
664669

665670
# check if we have available node to program
666671
if not nodes_to_program:
667-
sys.exit("No target found :\n" + str(device.nodes))
672+
print("No target found :\n" + str(device.nodes))
673+
return BOOTLOADER_DETECT_ERROR
668674

669675
# reboot all nodes in bootloader mode
670676
print("** Reboot all nodes in bootloader mode **")
@@ -679,12 +685,14 @@ def luos_flash(args):
679685
# find routing table in boot mode
680686
# its necessary to give ids to bootloader services
681687
state = find_network(device)
688+
if state is None:
689+
return BOOTLOADER_DETECT_ERROR
682690

683691
# wait before next step
684692
time.sleep(0.4)
685693

686694
print("\n** Programming nodes **")
687-
695+
688696
# go to header state if node is ready
689697
for node in nodes_to_program:
690698
print("--> Check if node", node, " is ready.")
@@ -715,7 +723,7 @@ def luos_flash(args):
715723
total_fails.extend(failed_nodes)
716724
machine_state = True
717725
print("Flash of node: ", failed_nodes, "failed!")
718-
726+
719727
# inform the node of the end of the loading
720728
print("--> Programmation finished, waiting for acknowledge.")
721729
machine_state, failed_nodes = send_binary_end(device, topic, nodes_to_program)
@@ -759,18 +767,20 @@ def luos_flash(args):
759767
# @return None
760768
# *******************************************************************************
761769
def luos_detect(args):
762-
print('Luos detect subcommand on port : ', args.port)
763-
print('\tLuos detect subcommand at baudrate : ', args.baudrate)
764-
765770
if not (args.port):
766771
try:
767772
args.port= serial_discover(os.getenv('LUOS_BAUDRATE', args.baudrate))[0]
768773
except:
769-
sys.exit()
770-
return
774+
print('Please specify a port to access the network.')
775+
return BOOTLOADER_DETECT_ERROR
776+
777+
baudrate = os.getenv('LUOS_BAUDRATE', args.baudrate)
778+
779+
print('Luos detect subcommand on port : ', args.port)
780+
print('\tLuos detect subcommand at baudrate : ', baudrate)
771781

772782
# detect network
773-
device = Device(args.port, baudrate=os.getenv('LUOS_BAUDRATE', args.baudrate))
783+
device = Device(args.port, baudrate=baudrate)
774784
# print network to user
775785
print(device.nodes)
776786
device.close()
@@ -783,20 +793,20 @@ def luos_detect(args):
783793
# @return None
784794
# *******************************************************************************
785795
def luos_reset(args):
786-
print('Luos discover subcommand on port : ', args.port)
787-
print('\tLuos discover subcommand at baudrate : ', args.baudrate)
788-
789796
if not (args.port):
790797
try:
791798
args.port= serial_discover(os.getenv('LUOS_BAUDRATE', args.baudrate))[0]
792799
except:
793-
sys.exit()
794-
return
800+
return BOOTLOADER_DETECT_ERROR
795801

802+
baudrate = os.getenv('LUOS_BAUDRATE', args.baudrate)
803+
804+
print('Luos discover subcommand on port : ', args.port)
805+
print('\tLuos discover subcommand at baudrate : ', args.baudrate)
796806

797807
# send rescue command
798808
print('Send reset command.')
799-
port = serial.Serial(args.port, os.getenv('LUOS_BAUDRATE', args.baudrate), timeout=0.05)
809+
port = serial.Serial(args.port, baudrate, timeout=0.05)
800810
rst_cmd = {
801811
'bootloader': {
802812
'command': {
@@ -811,7 +821,7 @@ def luos_reset(args):
811821
port.close()
812822

813823
# detect network
814-
device = Device(args.port, baudrate=os.getenv('LUOS_BAUDRATE', args.baudrate), background_task=False)
824+
device = Device(args.port, baudrate=baudrate, background_task=False)
815825

816826
print(device.nodes)
817827
device.close()

pyluos/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = '2.2.11'
1+
version = '2.2.12'

0 commit comments

Comments
 (0)