MCPcopy Create free account
hub / github.com/bitcraze/crazyflie-lib-python / _internal_flash

Method _internal_flash

cflib/bootloader/__init__.py:256–382  ·  view source on GitHub ↗
(self, target, current_file_number=1, total_files=1)

Source from the content-addressed store, hash-verified

254 self._cload.close()
255
256 def _internal_flash(self, target, current_file_number=1, total_files=1):
257
258 image = target['data']
259 t_data = target['target']
260
261 start_page = target['start_page']
262
263 # If used from a UI we need some extra things for reporting progress
264 factor = (100.0 * t_data.page_size) / len(image)
265 progress = 0
266
267 if self.progress_cb:
268 self.progress_cb(
269 '({}/{}) Starting...'.format(current_file_number, total_files),
270 int(progress))
271 else:
272 sys.stdout.write(
273 'Flashing {} of {} to {} ({}): '.format(
274 current_file_number, total_files,
275 TargetTypes.to_string(t_data.id), target['type']))
276 sys.stdout.flush()
277
278 if len(image) > ((t_data.flash_pages - start_page) *
279 t_data.page_size):
280 if self.progress_cb:
281 self.progress_cb(
282 'Error: Not enough space to flash the image file.',
283 int(progress))
284 else:
285 print('Error: Not enough space to flash the image file.')
286 raise Exception()
287
288 if not self.progress_cb:
289 logger.info(('%d bytes (%d pages) ' % (
290 (len(image) - 1), int(len(image) / t_data.page_size) + 1)))
291 sys.stdout.write(('%d bytes (%d pages) ' % (
292 (len(image) - 1), int(len(image) / t_data.page_size) + 1)))
293 sys.stdout.flush()
294
295 # For each page
296 ctr = 0 # Buffer counter
297 for i in range(0, int((len(image) - 1) / t_data.page_size) + 1):
298 if self.terminate_flashing_cb and self.terminate_flashing_cb():
299 raise Exception('Flashing terminated')
300
301 # Load the buffer
302 if ((i + 1) * t_data.page_size) > len(image):
303 self._cload.upload_buffer(
304 t_data.addr, ctr, 0, image[i * t_data.page_size:])
305 else:
306 self._cload.upload_buffer(
307 t_data.addr, ctr, 0,
308 image[i * t_data.page_size: (i + 1) * t_data.page_size])
309
310 ctr += 1
311
312 if self.progress_cb:
313 progress += factor

Callers 2

write_cf1_configMethod · 0.95
flashMethod · 0.95

Calls 4

writeMethod · 0.80
to_stringMethod · 0.80
upload_bufferMethod · 0.80
write_flashMethod · 0.80

Tested by

no test coverage detected