pypicoboot 1.1.5__tar.gz → 1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pypicoboot-1.1.5 → pypicoboot-1.2}/PKG-INFO +1 -1
- {pypicoboot-1.1.5 → pypicoboot-1.2}/picoboot/_version.py +1 -1
- pypicoboot-1.2/picoboot/core/log.py +58 -0
- {pypicoboot-1.1.5 → pypicoboot-1.2}/picoboot/picoboot.py +7 -25
- {pypicoboot-1.1.5 → pypicoboot-1.2}/pypicoboot.egg-info/PKG-INFO +1 -1
- {pypicoboot-1.1.5 → pypicoboot-1.2}/pypicoboot.egg-info/SOURCES.txt +1 -0
- {pypicoboot-1.1.5 → pypicoboot-1.2}/LICENSE +0 -0
- {pypicoboot-1.1.5 → pypicoboot-1.2}/README.md +0 -0
- {pypicoboot-1.1.5 → pypicoboot-1.2}/picoboot/__init__.py +0 -0
- {pypicoboot-1.1.5 → pypicoboot-1.2}/picoboot/core/__init__.py +0 -0
- {pypicoboot-1.1.5 → pypicoboot-1.2}/picoboot/core/enums.py +0 -0
- {pypicoboot-1.1.5 → pypicoboot-1.2}/picoboot/picobootmonitor.py +0 -0
- {pypicoboot-1.1.5 → pypicoboot-1.2}/picoboot/tools/picotool.py +0 -0
- {pypicoboot-1.1.5 → pypicoboot-1.2}/picoboot/utils.py +0 -0
- {pypicoboot-1.1.5 → pypicoboot-1.2}/pypicoboot.egg-info/dependency_links.txt +0 -0
- {pypicoboot-1.1.5 → pypicoboot-1.2}/pypicoboot.egg-info/requires.txt +0 -0
- {pypicoboot-1.1.5 → pypicoboot-1.2}/pypicoboot.egg-info/top_level.txt +0 -0
- {pypicoboot-1.1.5 → pypicoboot-1.2}/pyproject.toml +0 -0
- {pypicoboot-1.1.5 → pypicoboot-1.2}/setup.cfg +0 -0
- {pypicoboot-1.1.5 → pypicoboot-1.2}/setup.py +0 -0
- {pypicoboot-1.1.5 → pypicoboot-1.2}/tests/test_000_init.py +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""
|
|
2
|
+
/*
|
|
3
|
+
* This file is part of the pypicoboot distribution (https://github.com/polhenarejos/pypicoboot).
|
|
4
|
+
* Copyright (c) 2025 Pol Henarejos.
|
|
5
|
+
*
|
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
8
|
+
* the Free Software Foundation, version 3.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful, but
|
|
11
|
+
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13
|
+
* Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import os
|
|
21
|
+
import logging
|
|
22
|
+
|
|
23
|
+
TRACE_LEVEL = 5
|
|
24
|
+
logging.addLevelName(TRACE_LEVEL, "TRACE")
|
|
25
|
+
|
|
26
|
+
def trace(self, message, *args, **kwargs):
|
|
27
|
+
if self.isEnabledFor(TRACE_LEVEL):
|
|
28
|
+
self._log(TRACE_LEVEL, message, args, **kwargs)
|
|
29
|
+
|
|
30
|
+
# Afegeix logger.trace()
|
|
31
|
+
logging.Logger.trace = trace
|
|
32
|
+
|
|
33
|
+
def get_logger(name: str):
|
|
34
|
+
env_level = os.getenv("PICOBOOT_LOG", "CRITICAL").upper()
|
|
35
|
+
|
|
36
|
+
valid_levels = {
|
|
37
|
+
"TRACE": TRACE_LEVEL,
|
|
38
|
+
"DEBUG": logging.DEBUG,
|
|
39
|
+
"INFO": logging.INFO,
|
|
40
|
+
"WARNING": logging.WARNING,
|
|
41
|
+
"ERROR": logging.ERROR,
|
|
42
|
+
"CRITICAL": logging.CRITICAL,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
level = valid_levels.get(env_level, logging.CRITICAL)
|
|
46
|
+
|
|
47
|
+
logger = logging.getLogger(name)
|
|
48
|
+
logger.setLevel(level)
|
|
49
|
+
|
|
50
|
+
if not logger.handlers:
|
|
51
|
+
handler = logging.StreamHandler()
|
|
52
|
+
handler.setFormatter(logging.Formatter(
|
|
53
|
+
fmt="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
|
54
|
+
datefmt="%Y-%m-%d %H:%M:%S"
|
|
55
|
+
))
|
|
56
|
+
logger.addHandler(handler)
|
|
57
|
+
|
|
58
|
+
return logger
|
|
@@ -16,31 +16,6 @@
|
|
|
16
16
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
"""
|
|
19
|
-
import os
|
|
20
|
-
import logging
|
|
21
|
-
|
|
22
|
-
def get_logger(name: str):
|
|
23
|
-
env_level = os.getenv("PICOBOOT_LOG", "CRITICAL").upper()
|
|
24
|
-
|
|
25
|
-
valid_levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
|
|
26
|
-
if env_level not in valid_levels:
|
|
27
|
-
print(f"[logger] Warning: nivell '{env_level}' invàlid. Usant INFO.")
|
|
28
|
-
env_level = "INFO"
|
|
29
|
-
|
|
30
|
-
logger = logging.getLogger(name)
|
|
31
|
-
logger.setLevel(env_level)
|
|
32
|
-
|
|
33
|
-
if not logger.handlers:
|
|
34
|
-
handler = logging.StreamHandler()
|
|
35
|
-
handler.setFormatter(logging.Formatter(
|
|
36
|
-
fmt="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
|
37
|
-
datefmt="%Y-%m-%d %H:%M:%S"
|
|
38
|
-
))
|
|
39
|
-
logger.addHandler(handler)
|
|
40
|
-
|
|
41
|
-
return logger
|
|
42
|
-
|
|
43
|
-
logger = get_logger("picoboot")
|
|
44
19
|
|
|
45
20
|
from binascii import hexlify
|
|
46
21
|
from typing import Optional
|
|
@@ -51,6 +26,9 @@ import itertools
|
|
|
51
26
|
from .utils import uint_to_int
|
|
52
27
|
from .core.enums import NamedIntEnum
|
|
53
28
|
from .picobootmonitor import PicoBootMonitor, PicoBootMonitorObserver
|
|
29
|
+
from .core.log import get_logger
|
|
30
|
+
|
|
31
|
+
logger = get_logger("PicoBoot")
|
|
54
32
|
|
|
55
33
|
# Valors per defecte segons el datasheet (es poden canviar via OTP) :contentReference[oaicite:4]{index=4}
|
|
56
34
|
DEFAULT_VID = 0x2E8A
|
|
@@ -369,6 +347,7 @@ class PicoBoot:
|
|
|
369
347
|
raise
|
|
370
348
|
logger.debug(f"Sending command {cmd_id} (0x{cmd_id:02X}) with token {token} (0x{token:08X}) and transfer_length {transfer_length}")
|
|
371
349
|
|
|
350
|
+
logger.trace(f"Command header: {hexlify(header).decode()}")
|
|
372
351
|
self.ep_out.write(header, timeout=timeout)
|
|
373
352
|
logger.debug(f"Command header sent: {hexlify(header).decode()}")
|
|
374
353
|
|
|
@@ -386,6 +365,7 @@ class PicoBoot:
|
|
|
386
365
|
chunks.append(chunk)
|
|
387
366
|
remaining -= len(chunk)
|
|
388
367
|
data_in = b"".join(chunks)
|
|
368
|
+
logger.trace(f"Received data_in: {hexlify(data_in).decode()}")
|
|
389
369
|
if len(data_in) != transfer_length:
|
|
390
370
|
logger.error(f"Expected {transfer_length} bytes, got {len(data_in)}")
|
|
391
371
|
raise PicoBootError(f"Expected {transfer_length} bytes, got {len(data_in)}")
|
|
@@ -393,6 +373,7 @@ class PicoBoot:
|
|
|
393
373
|
if data_out is None or len(data_out) < transfer_length:
|
|
394
374
|
logger.error("data_out missing or too short for OUT command")
|
|
395
375
|
raise ValueError("data_out missing or too short for OUT command")
|
|
376
|
+
logger.trace(f"Sending data_out: {hexlify(data_out[:transfer_length]).decode()}")
|
|
396
377
|
self.ep_out.write(data_out[:transfer_length], timeout=timeout)
|
|
397
378
|
|
|
398
379
|
try:
|
|
@@ -404,6 +385,7 @@ class PicoBoot:
|
|
|
404
385
|
except usb.core.USBError:
|
|
405
386
|
logger.error("No ACK received after command")
|
|
406
387
|
raise PicoBootError("No ACK received after command")
|
|
388
|
+
logger.debug("ACK received.")
|
|
407
389
|
|
|
408
390
|
return data_in
|
|
409
391
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|