/*
 * uart_dev.h
 *
 *  Created on: 2024年6月22日
 *      Author: psx
 */

#ifndef APP_INC_UART_DEV_H_
#define APP_INC_UART_DEV_H_

#include "debug.h"
#include "ring_queue.h"
#include "rs485.h"


#define  ASCII_CHAR_BACKSPACE                           0x08    /* '\b' */
#define  ASCII_CHAR_CHARACTER_TABULATION                0x09    /* '\t' */
#define  ASCII_CHAR_LINE_FEED                           0x0A    /* '\n' */
#define  ASCII_CHAR_LINE_TABULATION                     0x0B    /* '\v' */
#define  ASCII_CHAR_FORM_FEED                           0x0C    /* '\f' */
#define  ASCII_CHAR_CARRIAGE_RETURN                     0x0D    /* '\r' */

typedef uint32_t device_handle;
extern device_handle g_bat485_uart3_handle;
extern device_handle g_gw485_uart4_handle;
//extern uint8_t rs485_out_buff[100];


typedef enum{
//   RAIN_RS485_UART_INDEX  = 0,
   BAT485_UART_INDEX      = 3,
   GW485_UART_INDEX       = 4,
}uartIndex_e;

/* UART 驱动数据结构,对应一个uart设备 */
typedef struct _uart_device_info{
  uint8_t       init;
  uartIndex_e   uart_index;
  uint32_t      uart_baudrate;
  RingQueue     uart_ring_queue;
}uart_device_info;

void bat485_tx_enabla(void);
void bat485_tx_disenabla(void);
void gw485_tx_enabla(void);
void gw485_tx_disenabla(void);

//device_handle uart_dev_init(uartIndex_e uart_index, uint8_t *buff, int buff_size);
device_handle uart_dev_init(void);
void uart_sendstr(device_handle device,char *str);
void uart_dev_write(device_handle device, void *data, int len);
int uart_dev_char_present(device_handle device);
char uart_dev_in_char(device_handle device);
int ring_queue_dev_char_present(RingQueue *ring_queue);
char ring_queue_dev_in_char(RingQueue *ring_queue);
int ring_queue_length(device_handle device);


#endif /* APP_INC_UART_DEV_H_ */