| 1 |
#!/usr/bin/env python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# |
| 4 |
# Copyright 2023 NXP |
| 5 |
# |
| 6 |
# SPDX-License-Identifier: BSD-3-Clause |
| 7 |
|
| 8 |
"""Generic commands implementation.""" |
| 9 |
|
| 10 |
from abc import ABC, abstractmethod |
| 11 |
|
| 12 |
|
| 13 |
class CmdResponseBase(ABC): |
| 14 |
"""Response base format class.""" |
| 15 |
|
| 16 |
@abstractmethod |
| 17 |
def __str__(self) -> str: |
| 18 |
"""Get object info.""" |
| 19 |
|
| 20 |
@property |
| 21 |
@abstractmethod |
| 22 |
def value(self) -> int: |
| 23 |
"""Return a integer representation of the response.""" |
| 24 |
|
| 25 |
|
| 26 |
class CmdPacketBase(ABC): |
| 27 |
"""COmmand protocol base.""" |
| 28 |
|
| 29 |
@abstractmethod |
| 30 |
def to_bytes(self, padding: bool = True) -> bytes: |
| 31 |
"""Serialize CmdPacket into bytes. |
| 32 |
|
| 33 |
:param padding: If True, add padding to specific size |
| 34 |
:return: Serialized object into bytes |
| 35 |
""" |