1142 return res |
1163 return res |
1143 |
1164 |
1144 print(get_device_data()) |
1165 print(get_device_data()) |
1145 del get_device_data |
1166 del get_device_data |
1146 """ |
1167 """ |
1147 out, err = self.executeCommands(command, mode=self._submitMode) |
1168 ] |
1148 if err: |
1169 res = {} |
1149 raise OSError(self._shortError(err)) |
1170 for command in commands: |
1150 return ast.literal_eval(out.decode("utf-8")) |
1171 out, err = self.executeCommands(command, mode=self._submitMode) |
|
1172 if err: |
|
1173 raise OSError(self._shortError(err)) |
|
1174 res.update(ast.literal_eval(out.decode("utf-8"))) |
|
1175 return res |
1151 |
1176 |
1152 def getBoardInformation(self): |
1177 def getBoardInformation(self): |
1153 """ |
1178 """ |
1154 Public method to get some information data of the connected board. |
1179 Public method to get some information data of the connected board. |
1155 |
1180 |
1156 @return dictionary containing the determined data |
1181 @return dictionary containing the determined data |
1157 @rtype dict |
1182 @rtype dict |
1158 @exception OSError raised to indicate an issue with the device |
1183 @exception OSError raised to indicate an issue with the device |
1159 """ |
1184 """ |
1160 commands = [ # needs to be splitted for boards with low memory |
1185 commands = [ # needs to be splitted for boards with low memory |
1161 """def get_board_info(): |
|
1162 res = {} |
|
1163 |
|
1164 import gc |
|
1165 gc.enable() |
|
1166 gc.collect() |
|
1167 mem_alloc = gc.mem_alloc() |
|
1168 mem_free = gc.mem_free() |
|
1169 mem_total = mem_alloc + mem_free |
|
1170 res['mem_total_kb'] = mem_total / 1024.0 |
|
1171 res['mem_used_kb'] = mem_alloc / 1024.0 |
|
1172 res['mem_used_pc'] = mem_alloc / mem_total * 100.0 |
|
1173 res['mem_free_kb'] = mem_free / 1024.0 |
|
1174 res['mem_free_pc'] = mem_free / mem_total * 100.0 |
|
1175 del gc, mem_alloc, mem_free, mem_total |
|
1176 |
|
1177 return res |
|
1178 |
|
1179 print(get_board_info()) |
|
1180 del get_board_info |
|
1181 """, |
|
1182 """def get_board_info(): |
1186 """def get_board_info(): |
1183 res = {} |
1187 res = {} |
1184 |
1188 |
1185 try: |
1189 try: |
1186 import os |
1190 import os |
1240 """, |
1244 """, |
1241 """def get_board_info(): |
1245 """def get_board_info(): |
1242 res = {} |
1246 res = {} |
1243 |
1247 |
1244 try: |
1248 try: |
|
1249 import ulab |
|
1250 res['ulab'] = ulab.__version__ |
|
1251 except ImportError: |
|
1252 res['ulab'] = None |
|
1253 |
|
1254 return res |
|
1255 |
|
1256 print(get_board_info()) |
|
1257 del get_board_info |
|
1258 """, |
|
1259 ] |
|
1260 |
|
1261 gc_command = """def get_board_info(): |
|
1262 res = {} |
|
1263 |
|
1264 import gc |
|
1265 gc.enable() |
|
1266 gc.collect() |
|
1267 mem_alloc = gc.mem_alloc() |
|
1268 mem_free = gc.mem_free() |
|
1269 mem_total = mem_alloc + mem_free |
|
1270 res['mem_total'] = mem_total |
|
1271 res['mem_used'] = mem_alloc |
|
1272 res['mem_free'] = mem_free |
|
1273 del gc, mem_alloc, mem_free, mem_total |
|
1274 |
|
1275 return res |
|
1276 |
|
1277 print(get_board_info()) |
|
1278 del get_board_info |
|
1279 """ |
|
1280 |
|
1281 flash_command = """def get_board_info(): |
|
1282 res = {} |
|
1283 |
|
1284 try: |
1245 import os |
1285 import os |
1246 stat_ = os.statvfs('/flash') |
1286 stat_ = os.statvfs('/flash') |
1247 res['flash_info_available'] = True |
1287 res['flash_info_available'] = True |
1248 res['flash_total_kb'] = stat_[2] * stat_[0] / 1024.0 |
1288 res['flash_total'] = stat_[2] * stat_[0] |
1249 res['flash_free_kb'] = stat_[3] * stat_[0] / 1024.0 |
1289 res['flash_free'] = stat_[3] * stat_[0] |
1250 res['flash_used_kb'] = res['flash_total_kb'] - res['flash_free_kb'] |
|
1251 res['flash_free_pc'] = res['flash_free_kb'] / res['flash_total_kb'] * 100.0 |
|
1252 res['flash_used_pc'] = res['flash_used_kb'] / res['flash_total_kb'] * 100.0 |
|
1253 except (AttributeError, OSError): |
1290 except (AttributeError, OSError): |
1254 res['flash_info_available'] = False |
1291 res['flash_info_available'] = False |
1255 |
1292 |
1256 return res |
1293 return res |
1257 |
1294 |
1258 print(get_board_info()) |
1295 print(get_board_info()) |
1259 del get_board_info |
1296 del get_board_info |
1260 """, |
1297 """ |
1261 """def get_board_info(): |
1298 |
|
1299 machine_command = """def get_board_info(): |
1262 res = {} |
1300 res = {} |
1263 |
1301 |
1264 try: |
1302 try: |
1265 import machine as mc |
1303 import machine as mc |
1266 try: |
1304 try: |
1267 if isinstance(mc.freq(), tuple): |
1305 if isinstance(mc.freq(), tuple): |
1268 res['mc_frequency_mhz'] = mc.freq()[0] / 1000000.0 |
1306 res['mc_frequency'] = mc.freq()[0] |
1269 else: |
1307 else: |
1270 res['mc_frequency_mhz'] = mc.freq() / 1000000.0 |
1308 res['mc_frequency'] = mc.freq() |
1271 except NotImplementedError: |
1309 except NotImplementedError: |
1272 res['mc_frequency_mhz'] = None |
1310 res['mc_frequency'] = None |
1273 try: |
1311 try: |
1274 res['mc_temp_c'] = mc.Temp().read() |
1312 res['mc_temp_c'] = mc.Temp().read() |
1275 except AttributeError: |
1313 except AttributeError: |
1276 pass |
1314 res['mc_temp_c'] = None |
1277 res['mc_id'] = mc.unique_id() |
1315 res['mc_id'] = mc.unique_id() |
1278 except ImportError: |
1316 except ImportError: |
1279 try: |
1317 try: |
1280 import microcontroller as mc |
1318 import microcontroller as mc |
1281 res['mc_frequency_mhz'] = mc.cpu.frequency / 1000000.0 |
1319 res['mc_frequency'] = mc.cpu.frequency |
1282 res['mc_temp_c'] = mc.cpu.temperature |
1320 res['mc_temp_c'] = mc.cpu.temperature |
1283 res['mc_id'] = mc.cpu.uid |
1321 res['mc_id'] = mc.cpu.uid |
1284 except ImportError: |
1322 except ImportError: |
1285 res['mc_frequency_mhz'] = None |
1323 res['mc_frequency'] = None |
1286 res['mc_temp_c'] = None |
1324 res['mc_temp_c'] = None |
1287 if 'mc_id' in res: |
1325 if 'mc_id' in res: |
1288 res['mc_id'] = ':'.join('{0:02X}'.format(x) for x in res['mc_id']) |
1326 res['mc_id'] = ':'.join('{0:02X}'.format(x) for x in res['mc_id']) |
|
1327 else: |
|
1328 res['mc_id'] = None |
1289 |
1329 |
1290 return res |
1330 return res |
1291 |
1331 |
1292 print(get_board_info()) |
1332 print(get_board_info()) |
1293 del get_board_info |
1333 del get_board_info |
1294 """, |
1334 """ |
1295 """def get_board_info(): |
|
1296 res = {} |
|
1297 |
|
1298 try: |
|
1299 import ulab |
|
1300 res['ulab'] = ulab.__version__ |
|
1301 except ImportError: |
|
1302 res['ulab'] = None |
|
1303 |
|
1304 return res |
|
1305 |
|
1306 print(get_board_info()) |
|
1307 del get_board_info |
|
1308 """, |
|
1309 ] |
|
1310 res = {} |
1335 res = {} |
1311 for command in commands: |
1336 for command in commands: |
1312 out, err = self.executeCommands(command, mode=self._submitMode) |
1337 out, err = self.executeCommands(command, mode=self._submitMode) |
1313 if err: |
1338 if err: |
1314 raise OSError(self._shortError(err)) |
1339 raise OSError(self._shortError(err)) |
1315 res.update(ast.literal_eval(out.decode("utf-8"))) |
1340 res.update(ast.literal_eval(out.decode("utf-8"))) |
|
1341 |
|
1342 # Execute the commands needing some special postprocessing due to some |
|
1343 # boards supporting integer only. |
|
1344 out, err = self.executeCommands(gc_command, mode=self._submitMode) |
|
1345 if err: |
|
1346 raise OSError(self._shortError(err)) |
|
1347 gc_res = ast.literal_eval(out.decode("utf-8")) |
|
1348 res['mem_total_kb'] = gc_res["mem_total"] / 1024.0 |
|
1349 res['mem_used_kb'] = gc_res["mem_used"] / 1024.0 |
|
1350 res['mem_used_pc'] = gc_res["mem_used"] / gc_res["mem_total"] * 100.0 |
|
1351 res['mem_free_kb'] = gc_res["mem_free"] / 1024.0 |
|
1352 res['mem_free_pc'] = gc_res["mem_free"] / gc_res["mem_total"] * 100.0 |
|
1353 |
|
1354 out, err = self.executeCommands(flash_command, mode=self._submitMode) |
|
1355 if err: |
|
1356 raise OSError(self._shortError(err)) |
|
1357 flash_res = ast.literal_eval(out.decode("utf-8")) |
|
1358 res['flash_info_available'] = flash_res["flash_info_available"] |
|
1359 if flash_res["flash_info_available"]: |
|
1360 res['flash_total_kb'] = flash_res["flash_total"] / 1024.0 |
|
1361 res['flash_free_kb'] = flash_res["flash_free"] / 1024.0 |
|
1362 res['flash_used_kb'] = res['flash_total_kb'] - res['flash_free_kb'] |
|
1363 res['flash_free_pc'] = res['flash_free_kb'] / res['flash_total_kb'] * 100.0 |
|
1364 res['flash_used_pc'] = res['flash_used_kb'] / res['flash_total_kb'] * 100.0 |
|
1365 |
|
1366 out, err = self.executeCommands(machine_command, mode=self._submitMode) |
|
1367 if err: |
|
1368 raise OSError(self._shortError(err)) |
|
1369 machine_res = ast.literal_eval(out.decode("utf-8")) |
|
1370 res['mc_frequency_mhz'] = ( |
|
1371 machine_res["mc_frequency"] / 1000000.0 |
|
1372 if machine_res["mc_frequency"] is not None |
|
1373 else None |
|
1374 ) |
|
1375 res["mc_temp_c"] = machine_res["mc_temp_c"] |
|
1376 res["mc_id"] = machine_res["mc_id"] |
|
1377 |
1316 return res |
1378 return res |
1317 |
1379 |
1318 def getModules(self): |
1380 def getModules(self): |
1319 """ |
1381 """ |
1320 Public method to show a list of modules built into the firmware. |
1382 Public method to show a list of modules built into the firmware. |