//
// Created by Mysteo on 14.07.2023.
//

#ifndef READER_MAIN_PROG_UART_BRIDGE_HPP
#define READER_MAIN_PROG_UART_BRIDGE_HPP
#include "circular_buffer.hpp"
#include "usart.h"

#define BUF_SIZE 1024U
#define MAX_QUEUE 16

class UartBridge{

public:
    UartBridge(bool isOn, USART_TypeDef *uart1, USART_TypeDef *uart2, uint16_t baudRate1,
               uint16_t baudRate2);
    Circular_Buffer<std::string_view> *uart1Buf;
    Circular_Buffer<std::string_view> *uart2Buf;
    bool isTurnOn() const;
    void setTurnOn(bool isTurnOn);
    volatile uint8_t dataFromUart1[BUF_SIZE];
    volatile uint8_t dataFromUart2[BUF_SIZE];
    void init(void);
private:

protected:
    void uartInit(UART_HandleTypeDef* huart);
    bool turnOn;
    UART_HandleTypeDef uart1Handle, uart2Handle;
public:
    UART_HandleTypeDef* getHuart1() ;
    bool receiveStarted;
    bool receiveTimeout = true;
    UART_HandleTypeDef* getHuart2() ;

protected:
    USART_TypeDef *uart1, *uart2;

};

#endif //READER_MAIN_PROG_UART_BRIDGE_HPP
