#ifndef _EMBEDDED_RPC__UART_TRANSPORT_H_
#define _EMBEDDED_RPC__UART_TRANSPORT_H_

#include "erpc_framed_transport.hpp"

extern "C" {
#include <rtthread.h>
#include <rtdevice.h>
}

namespace erpc {

    class UartTransport : public FramedTransport
    {
    public:
        explicit UartTransport(const char *uartDevName);
        virtual ~UartTransport(void);

        virtual erpc_status_t init(void);

    protected:
        virtual erpc_status_t underlyingReceive(uint8_t *data, uint32_t size) override;
        virtual erpc_status_t underlyingSend(const uint8_t *data, uint32_t size) override;

    private:
        static rt_err_t uart_rx_ind(rt_device_t dev, rt_size_t size);
        void build_rx_sem_name(char *out, rt_size_t out_sz);

    private:
        const char *m_uartDevName;
        rt_device_t m_serial;
        rt_sem_t    m_rx_sem;
    };

} // namespace erpc

#endif // _EMBEDDED_RPC__UART_TRANSPORT_H_
