Source code for hermespy.modem.frame_generator.frame_generator

# -*- coding: utf-8 -*-
from __future__ import annotations

from abc import ABC, abstractmethod
from typing_extensions import override

import numpy as np

from hermespy.core import DeserializationProcess, Serializable, SerializationProcess
from ..bits_source import BitsSource

__author__ = "Egor Achkasov"
__copyright__ = "Copyright 2024, Barkhausen Institut gGmbH"
__credits__ = ["Egor Achkasov", "Jan Adler"]
__license__ = "AGPLv3"
__version__ = "1.5.0"
__maintainer__ = "Jan Adler"
__email__ = "jan.adler@barkhauseninstitut.org"
__status__ = "Prototype"


[docs] class FrameGenerator(ABC, Serializable): """Base class for frame generators."""
[docs] @abstractmethod def pack_frame(self, source: BitsSource, num_bits: int) -> np.ndarray: """Generate a frame of num_bits bits from the given bitsource. Args: source: Payload source. num_bits: Number of bits in the whole resulting frame. Returns: Array of ints with each element beeing an individual bit. """ ... # pragma: no cover
[docs] @abstractmethod def unpack_frame(self, frame: np.ndarray) -> np.ndarray: """Extract the original payload from the frame generated with pack_frame. Args: frame: Array of bits of a frame, generated with pack_frame. Returns: Array of payload bits.""" ... # pragma: no cover
[docs] class FrameGeneratorStub(FrameGenerator): """A dummy placeholder frame generator, packing and unpacking payload without any overhead."""
[docs] def pack_frame(self, source: BitsSource, num_bits: int) -> np.ndarray: return source.generate_bits(num_bits)
[docs] def unpack_frame(self, frame: np.ndarray) -> np.ndarray: return frame
[docs] @override def serialize(self, process: SerializationProcess) -> None: return
[docs] @classmethod @override def Deserialize(cls, process: DeserializationProcess) -> FrameGeneratorStub: return cls()