Skip to content
This repository was archived by the owner on Jan 31, 2019. It is now read-only.

Commit 50359f9

Browse files
committed
Merge branch 'april-1-patch'
- Tweaks to uploading code for better reporting of failures when over VEXnet - Fix project upgrading. Works as intended now
2 parents 2a991c5 + 6dd0c65 commit 50359f9

File tree

8 files changed

+50
-29
lines changed

8 files changed

+50
-29
lines changed

proscli/flasher.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import os.path
44
import ntpath
5+
import serial
56
import sys
67
import prosflasher.ports
78
import prosflasher.upload
@@ -93,11 +94,10 @@ def flash(ctx, save_file_system, y, port, binary, no_poll, retry):
9394
click.echo('Flashing ' + binary + ' to ' + ', '.join(port))
9495
for p in port:
9596
tries = 1
96-
while tries <= retry:
97-
code = prosflasher.upload.upload(p, y, binary, no_poll, ctx)
98-
if code or code == -1000:
99-
break
97+
code = prosflasher.upload.upload(p, y, binary, no_poll, ctx)
98+
while tries <= retry and (not code or code == -1000):
10099
click.echo('Retrying...')
100+
code = prosflasher.upload.upload(p, y, binary, no_poll, ctx)
101101
tries += 1
102102

103103

@@ -167,7 +167,7 @@ def get_sys_info(cfg, yes, port):
167167
port = [port]
168168

169169
for p in port:
170-
sys_info = prosflasher.upload.ask_sys_info(prosflasher.ports.create_serial(p), cfg)
170+
sys_info = prosflasher.upload.ask_sys_info(prosflasher.ports.create_serial(p, serial.PARITY_EVEN), cfg)
171171
click.echo(repr(sys_info))
172172

173173
pass

proscli/upgrade.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def get_upgrade_command():
1616
if getattr(sys, 'frozen', False):
1717
cmd = os.path.abspath(os.path.join(sys.executable, '..', '..', 'updater.exe'))
1818
if os.path.exists(cmd):
19-
return [cmd, '/silentall', '-nofreqcheck']
19+
return [cmd, '-reducedgui']
2020
else:
2121
return False
2222
else:

prosconductor/providers/githubreleases.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def get_cert_attr():
2626

2727
class GithubReleasesDepotProvider(DepotProvider):
2828
registrar = 'github-releases'
29-
location_desc = 'eyo smwd'
29+
location_desc = 'username/repository'
3030
config = {
3131
'include_prereleases': {
3232
'method': 'bool',
@@ -80,7 +80,7 @@ def list_online(self, template_types=None):
8080
# filter out pre-releases according to registar_options (include_prerelease implies prerelease) and
8181
# by if the release has a kernel-template.zip or library-template.zip file
8282
for release in [rel for rel in json if
83-
(not rel['prerelease'] or config.registrar_options.get('include_prerelease', False)) and
83+
(not rel['prerelease'] or config.registrar_options.get('include_prereleases', False)) and
8484
(not rel['draft'] or config.registrar_options.get('include_draft', False))]:
8585
for asset in [a for a in release['assets'] if
8686
re.fullmatch(string=a['name'].lower(), pattern='.*-template.zip')]:

prosconductor/providers/local.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ def create_project(identifier, dest, pros_cli=None):
117117
copytree(config.directory, dest)
118118
for root, dirs, files in os.walk(dest):
119119
for d in dirs:
120-
d = os.path.relpath(os.path.join(root, d), config.directory)
120+
d = os.path.relpath(os.path.join(root, d), dest)
121121
if any([fnmatch.fnmatch(d, p) for p in config.template_ignore]):
122122
verbose('Removing {}'.format(d))
123123
os.rmdir(os.path.join(root, d))
124124
for f in files:
125-
f = os.path.relpath(os.path.join(root, f), config.directory)
125+
f = os.path.relpath(os.path.join(root, f), dest)
126126
if any([fnmatch.fnmatch(f, p) for p in config.template_ignore]):
127127
verbose('Removing {}'.format(f))
128128
os.remove(os.path.join(root, f))

prosflasher/bootloader.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def send_bootloader_command(port, command, response_size=1):
2121
port.write([command, 0xff - command])
2222
time.sleep(0.01)
2323
response = port.read(response_size)
24+
debug_response(command, response)
2425
return response
2526

2627

@@ -52,7 +53,7 @@ def prepare_bootloader(port):
5253
time.sleep(0.01)
5354
port.rts = 0
5455
time.sleep(0.01)
55-
for _ in range(0,3):
56+
for _ in range(0, 3):
5657
port.write([0x7f])
5758
response = port.read(1)
5859
debug_response(0x7f, response)
@@ -120,7 +121,7 @@ def erase_flash(port):
120121
return True
121122

122123

123-
def write_flash(port, start_address, data, retry=2):
124+
def write_flash(port, start_address, data, retry=2, is_wireless=False):
124125
data = bytearray(data)
125126
if len(data) > 256:
126127
click.echo('Tried writing too much data at once! ({} bytes)'.format(len(data)))
@@ -130,33 +131,39 @@ def write_flash(port, start_address, data, retry=2):
130131
debug('Writing {} bytes to {}'.format(len(data), adr_to_str(c_addr)))
131132
response = send_bootloader_command(port, 0x31)
132133
if response is None or len(response) < 1 or response[0] != ACK:
133-
click.echo('failed (write command not accepted)')
134-
return False
134+
if retry > 0:
135+
debug('RETRYING PACKET AT COMMAND')
136+
return write_flash(port, start_address, data, retry=retry - 1)
137+
else:
138+
click.echo('failed (write command not accepted)')
139+
return False
135140
port.write(c_addr)
136141
port.flush()
142+
time.sleep(0.005 if is_wireless else 0.002)
137143
response = port.read(1)
138144
debug_response(adr_to_str(c_addr), response)
139145
if response is None or len(response) < 1 or response[0] != ACK:
140146
if retry > 0:
141-
debug('RETRYING PACKET')
142-
write_flash(port, start_address, data, retry=retry - 1)
147+
debug('RETRYING PACKET AT ADDRESS')
148+
return write_flash(port, start_address, data, retry=retry - 1)
143149
else:
144150
click.echo('failed (address not accepted)')
145151
return False
146152
checksum = len(data) - 1
147153
for x in data:
148154
checksum ^= x
149-
send_data = data
155+
send_data = data[:]
150156
send_data.insert(0, len(send_data) - 1)
151157
send_data.append(checksum)
152158
port.write(send_data)
153-
time.sleep(0.005)
159+
port.flush()
160+
time.sleep(0.007 if is_wireless else 0.002)
154161
response = port.read(1)
155162
debug('STM BL RESPONSE TO WRITE: {}'.format(response))
156163
if response is None or len(response) < 1 or response[0] != ACK:
157164
if retry > 0:
158-
debug('RETRYING PACKET')
159-
write_flash(port, start_address, data, retry=retry - 1)
165+
debug('RETRYING PACKET AT WRITE')
166+
return write_flash(port, start_address, data, retry=retry - 1)
160167
else:
161168
click.echo('failed (could not complete upload)')
162169
return False
@@ -171,14 +178,14 @@ def chunks(l, n):
171178
yield l[i:i + n]
172179

173180

174-
def upload_binary(port, file):
181+
def upload_binary(port, file, is_wireless=False):
175182
address = 0x08000000
176183
with open(file, 'rb') as f:
177184
data = bytes(f.read())
178-
data_segments = [data[x:x+MAX_WRITE_SIZE] for x in range(0, len(data), MAX_WRITE_SIZE)]
185+
data_segments = [data[x:x + MAX_WRITE_SIZE] for x in range(0, len(data), MAX_WRITE_SIZE)]
179186
with click.progressbar(data_segments, label='Uploading binary to Cortex...') as segments:
180187
for segment in segments:
181-
if not write_flash(port, address, segment):
188+
if not write_flash(port, address, segment, is_wireless=is_wireless):
182189
return False
183190
address += 0x100
184191
return True

prosflasher/ports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def create_serial(port, parity):
4141
# port.port = port_str if port_str != '' else None
4242
port.timeout = 0.5
4343
# port.write_timeout = 5.0
44-
port.inter_byte_timeout = 0.1 # todo make sure this is seconds
44+
port.inter_byte_timeout = 0.2
4545
return port
4646

4747

prosflasher/upload.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ def __repr__(self):
6060
self.joystick_firmware, self.joystick_battery,
6161
self.cortex_firmware, self.cortex_battery, self.backup_battery)
6262

63+
@property
64+
def is_wireless(self):
65+
return self.connection_type == ConnectionType.serial_vexnet2 or \
66+
self.connection_type == ConnectionType.serial_vexnet2_dl or \
67+
self.connection_type == ConnectionType.serial_vexnet1 or \
68+
self.connection_type == ConnectionType.serial_vexnet1_turbo
69+
6370

6471
# THIS MANAGES THE UPLOAD PROCESS FOR A GIVEN PORT/BINARY PAIR
6572
def upload(port, y, binary, no_poll=False, ctx=proscli.utils.State()):
@@ -79,19 +86,23 @@ def upload(port, y, binary, no_poll=False, ctx=proscli.utils.State()):
7986
time.sleep(1.5)
8087
sys_info = ask_sys_info(port)
8188
if sys_info is None:
82-
click.echo('Failed to get system info... Try again', err=True)
83-
return False
89+
sys_info = SystemInfo()
90+
sys_info.connection_type = ConnectionType.unknown
91+
click.echo('Failed to get system info... Prompting to continue...', err=True)
8492
click.echo(repr(sys_info))
8593
else:
8694
sys_info = SystemInfo()
8795
sys_info.connection_type = ConnectionType.serial_usb # assume this
8896
if sys_info.connection_type == ConnectionType.unknown and not y:
8997
click.confirm('Unable to determine system type. It may be necessary to press the '
90-
'programming button on the programming kit. Continue?', abort=True, default=True)
98+
'programming button on the programming kit. Continuing is usually safe.'
99+
' Continue?', abort=True, default=True)
91100
if sys_info.connection_type == ConnectionType.serial_vexnet2:
92101
# need to send to download channel
93102
if not send_to_download_channel(port):
94103
return False
104+
if sys_info.is_wireless: # increase read timeout for wireless connections
105+
port.timeout = 1.0
95106
if not expose_bootloader(port):
96107
return False
97108
port.read_all()
@@ -101,7 +112,11 @@ def upload(port, y, binary, no_poll=False, ctx=proscli.utils.State()):
101112
return False
102113
if not prosflasher.bootloader.erase_flash(port):
103114
return False
104-
if not prosflasher.bootloader.upload_binary(port, binary):
115+
if not prosflasher.bootloader.upload_binary(port, binary, is_wireless=sys_info.is_wireless):
116+
if sys_info.is_wireless:
117+
click.echo('Binary failed to upload. You may now need to upload via a USB connection because too many '
118+
'packets were dropped. Move the joystick closer to the microcontroller for a more reliable '
119+
'connection.')
105120
return False
106121
if not prosflasher.bootloader.send_go_command(port, 0x08000000):
107122
return False
@@ -273,4 +288,3 @@ def dump_cortex(port, file, verbose=False):
273288
port.close()
274289
click.echo("Download complete!")
275290
pass
276-

version

-1 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)