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

Method flash

cflib/bootloader/__init__.py:139–209  ·  view source on GitHub ↗
(self, filename, targets)

Source from the content-addressed store, hash-verified

137 self._internal_flash(target=to_flash)
138
139 def flash(self, filename, targets):
140 for target in targets:
141 if TargetTypes.from_string(target) not in self._cload.targets:
142 print('Target {} not found by bootloader'.format(target))
143 return False
144
145 files_to_flash = ()
146 if zipfile.is_zipfile(filename):
147 # Read the manifest (don't forget to check so there is one!)
148 try:
149 zf = zipfile.ZipFile(filename)
150 js = zf.read('manifest.json').decode('UTF-8')
151 j = json.loads(js)
152 files = j['files']
153 platform_id = self._get_platform_id()
154 files_for_platform = self._filter_platform(files, platform_id)
155 if len(targets) == 0:
156 targets = self._extract_targets_from_manifest_files(
157 files_for_platform)
158
159 zip_targets = self._extract_zip_targets(files_for_platform)
160 except KeyError as e:
161 print(e)
162 print('No manifest.json in {}'.format(filename))
163 return
164
165 try:
166 # Match and create targets
167 for target in targets:
168 t = targets[target]
169 for type in t:
170 file_to_flash = {}
171 current_target = '{}-{}'.format(target, type)
172 file_to_flash['type'] = type
173 # Read the data, if this fails we bail
174 file_to_flash['target'] = self._cload.targets[
175 TargetTypes.from_string(target)]
176 file_to_flash['data'] = zf.read(
177 zip_targets[target][type]['filename'])
178 file_to_flash['start_page'] = file_to_flash[
179 'target'].start_page
180 files_to_flash += (file_to_flash,)
181 except KeyError:
182 print('Could not find a file for {} in {}'.format(
183 current_target, filename))
184 return False
185
186 else:
187 if len(targets) != 1:
188 print('Not an archive, must supply one target to flash')
189 else:
190 file_to_flash = {}
191 file_to_flash['type'] = 'binary'
192 f = open(filename, 'rb')
193 for t in targets:
194 file_to_flash['target'] = self._cload.targets[
195 TargetTypes.from_string(t)]
196 file_to_flash['type'] = targets[t][0]

Callers

nothing calls this directly

Calls 8

_get_platform_idMethod · 0.95
_filter_platformMethod · 0.95
_extract_zip_targetsMethod · 0.95
_internal_flashMethod · 0.95
from_stringMethod · 0.80
readMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected