2023-01-28 16:01:54 -08:00
|
|
|
from abc import ABC, abstractmethod
|
2023-03-06 21:52:08 -08:00
|
|
|
from typing import List
|
|
|
|
|
|
|
|
|
|
from .constants import McuType
|
2023-01-28 16:01:54 -08:00
|
|
|
|
2023-03-07 14:44:10 -08:00
|
|
|
TIMEOUT = int(15 * 1e3) # default timeout, in milliseconds
|
2023-01-28 16:01:54 -08:00
|
|
|
|
|
|
|
|
class BaseHandle(ABC):
|
2023-03-06 09:24:00 -08:00
|
|
|
"""
|
|
|
|
|
A handle to talk to a panda.
|
|
|
|
|
Borrows heavily from the libusb1 handle API.
|
|
|
|
|
"""
|
2023-03-07 14:44:10 -08:00
|
|
|
|
2023-01-28 16:01:54 -08:00
|
|
|
@abstractmethod
|
|
|
|
|
def close(self) -> None:
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-03-07 14:44:10 -08:00
|
|
|
def controlWrite(self, request_type: int, request: int, value: int, index: int, data, timeout: int = TIMEOUT) -> int:
|
2023-01-28 16:01:54 -08:00
|
|
|
...
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-03-07 14:44:10 -08:00
|
|
|
def controlRead(self, request_type: int, request: int, value: int, index: int, length: int, timeout: int = TIMEOUT) -> bytes:
|
2023-01-28 16:01:54 -08:00
|
|
|
...
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-03-07 14:44:10 -08:00
|
|
|
def bulkWrite(self, endpoint: int, data: List[int], timeout: int = TIMEOUT) -> int:
|
2023-01-28 16:01:54 -08:00
|
|
|
...
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-03-07 14:44:10 -08:00
|
|
|
def bulkRead(self, endpoint: int, length: int, timeout: int = TIMEOUT) -> bytes:
|
2023-01-28 16:01:54 -08:00
|
|
|
...
|
2023-03-06 09:24:00 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class BaseSTBootloaderHandle(ABC):
|
|
|
|
|
"""
|
|
|
|
|
A handle to talk to a panda while it's in the STM32 bootloader.
|
|
|
|
|
"""
|
|
|
|
|
|
2023-03-06 21:52:08 -08:00
|
|
|
@abstractmethod
|
|
|
|
|
def get_mcu_type(self) -> McuType:
|
|
|
|
|
...
|
|
|
|
|
|
2023-03-06 09:24:00 -08:00
|
|
|
@abstractmethod
|
|
|
|
|
def close(self) -> None:
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
def clear_status(self) -> None:
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-03-06 21:52:08 -08:00
|
|
|
def program(self, address: int, dat: bytes) -> None:
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
def erase_app(self) -> None:
|
2023-03-06 09:24:00 -08:00
|
|
|
...
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-03-06 21:52:08 -08:00
|
|
|
def erase_bootstub(self) -> None:
|
2023-03-06 09:24:00 -08:00
|
|
|
...
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
def jump(self, address: int) -> None:
|
|
|
|
|
...
|
|
|
|
|
|