In embedded firmware systems, communication peripherals such as UART and SPI are often accessed through a common abstract interface. This allows higher-level modules to interact with different hardware drivers without changing application logic.
In this problem, you will implement an abstract communication driver using Embedded C++ concepts.
You are given a base class CommDriver. Your task is to declare two pure virtual member functions in this class:
send(const string& data)receive() → returns stringTwo derived classes, UartDriver and SpiDriver, already implement these functions.
The program will:
"UART" or "SPI")receive()This exercise focuses on abstract base classes, pure virtual functions, and runtime polymorphism, which are commonly used in embedded HAL (Hardware Abstraction Layer) design.
Input / Output Specification:
Input
type → "UART" or "SPI"message → non-empty, single-word string (no spaces)Output
<TYPE> SEND: <message><TYPE> RECV: <message>Example:
Input:
UART Hello
Output:
UART SEND: Hello
UART RECV: HelloConstraints & Assumptions:
Input
UART Hello
Expected Output
UART SEND: Hello UART RECV: Hello