cros_ec_python.baseclass

This file includes the base class for CrOS EC devices.

It doesn't do anything on its own, but it is used as a base for all CrosEc classes to inherit from.

See cros_ec_python.devices for a few examples of a class that inherits from this class.

 1"""
 2This file includes the base class for CrOS EC devices.
 3
 4It doesn't do anything on its own, but it is used as a base for all CrosEc classes to inherit from.
 5
 6See `cros_ec_python.devices` for a few examples of a class that inherits from this class.
 7"""
 8
 9import abc
10
11from .constants.COMMON import *
12
13
14class CrosEcClass(metaclass=abc.ABCMeta):
15    """
16    Base class for CrOS EC devices to inherit from.
17    """
18
19    @staticmethod
20    @abc.abstractmethod
21    def detect() -> bool:
22        """
23        Detect the EC type.
24        """
25        pass
26
27    @abc.abstractmethod
28    def ec_init(self) -> None:
29        """
30        Initialise the EC, this shouldn't need to be called unless the keyword arg init was set to false.
31        """
32        pass
33
34    @abc.abstractmethod
35    def ec_exit(self) -> None:
36        """
37        Close connection to the EC.
38        """
39        pass
40
41    @abc.abstractmethod
42    def command(
43        self,
44        version: Int32,
45        command: Int32,
46        outsize: Int32,
47        insize: Int32,
48        data: bytes = None,
49        warn: bool = True,
50    ) -> bytes:
51        """
52        Send a command to the EC and return the response.
53        :param version: Command version number (often 0).
54        :param command: Command to send (EC_CMD_...).
55        :param outsize: Outgoing length in bytes.
56        :param insize: Max number of bytes to accept from the EC.
57        :param data: Outgoing data to EC.
58        :param warn: Whether to warn if the response size is not as expected. Default is True.
59        :return: Response from the EC.
60        """
61        pass
62
63    @abc.abstractmethod
64    def memmap(self, offset: Int32, num_bytes: Int32) -> bytes:
65        """
66        Read memory from the EC.
67        :param offset: Offset to read from.
68        :param num_bytes: Number of bytes to read.
69        :return: Bytes read from the EC.
70        """
71        pass
class CrosEcClass:
15class CrosEcClass(metaclass=abc.ABCMeta):
16    """
17    Base class for CrOS EC devices to inherit from.
18    """
19
20    @staticmethod
21    @abc.abstractmethod
22    def detect() -> bool:
23        """
24        Detect the EC type.
25        """
26        pass
27
28    @abc.abstractmethod
29    def ec_init(self) -> None:
30        """
31        Initialise the EC, this shouldn't need to be called unless the keyword arg init was set to false.
32        """
33        pass
34
35    @abc.abstractmethod
36    def ec_exit(self) -> None:
37        """
38        Close connection to the EC.
39        """
40        pass
41
42    @abc.abstractmethod
43    def command(
44        self,
45        version: Int32,
46        command: Int32,
47        outsize: Int32,
48        insize: Int32,
49        data: bytes = None,
50        warn: bool = True,
51    ) -> bytes:
52        """
53        Send a command to the EC and return the response.
54        :param version: Command version number (often 0).
55        :param command: Command to send (EC_CMD_...).
56        :param outsize: Outgoing length in bytes.
57        :param insize: Max number of bytes to accept from the EC.
58        :param data: Outgoing data to EC.
59        :param warn: Whether to warn if the response size is not as expected. Default is True.
60        :return: Response from the EC.
61        """
62        pass
63
64    @abc.abstractmethod
65    def memmap(self, offset: Int32, num_bytes: Int32) -> bytes:
66        """
67        Read memory from the EC.
68        :param offset: Offset to read from.
69        :param num_bytes: Number of bytes to read.
70        :return: Bytes read from the EC.
71        """
72        pass

Base class for CrOS EC devices to inherit from.

@staticmethod
@abc.abstractmethod
def detect() -> bool:
20    @staticmethod
21    @abc.abstractmethod
22    def detect() -> bool:
23        """
24        Detect the EC type.
25        """
26        pass

Detect the EC type.

@abc.abstractmethod
def ec_init(self) -> None:
28    @abc.abstractmethod
29    def ec_init(self) -> None:
30        """
31        Initialise the EC, this shouldn't need to be called unless the keyword arg init was set to false.
32        """
33        pass

Initialise the EC, this shouldn't need to be called unless the keyword arg init was set to false.

@abc.abstractmethod
def ec_exit(self) -> None:
35    @abc.abstractmethod
36    def ec_exit(self) -> None:
37        """
38        Close connection to the EC.
39        """
40        pass

Close connection to the EC.

@abc.abstractmethod
def command( self, version: int, command: int, outsize: int, insize: int, data: bytes = None, warn: bool = True) -> bytes:
42    @abc.abstractmethod
43    def command(
44        self,
45        version: Int32,
46        command: Int32,
47        outsize: Int32,
48        insize: Int32,
49        data: bytes = None,
50        warn: bool = True,
51    ) -> bytes:
52        """
53        Send a command to the EC and return the response.
54        :param version: Command version number (often 0).
55        :param command: Command to send (EC_CMD_...).
56        :param outsize: Outgoing length in bytes.
57        :param insize: Max number of bytes to accept from the EC.
58        :param data: Outgoing data to EC.
59        :param warn: Whether to warn if the response size is not as expected. Default is True.
60        :return: Response from the EC.
61        """
62        pass

Send a command to the EC and return the response.

Parameters
  • version: Command version number (often 0).
  • command: Command to send (EC_CMD_...).
  • outsize: Outgoing length in bytes.
  • insize: Max number of bytes to accept from the EC.
  • data: Outgoing data to EC.
  • warn: Whether to warn if the response size is not as expected. Default is True.
Returns

Response from the EC.

@abc.abstractmethod
def memmap(self, offset: int, num_bytes: int) -> bytes:
64    @abc.abstractmethod
65    def memmap(self, offset: Int32, num_bytes: Int32) -> bytes:
66        """
67        Read memory from the EC.
68        :param offset: Offset to read from.
69        :param num_bytes: Number of bytes to read.
70        :return: Bytes read from the EC.
71        """
72        pass

Read memory from the EC.

Parameters
  • offset: Offset to read from.
  • num_bytes: Number of bytes to read.
Returns

Bytes read from the EC.