代码调试完毕,没有问题,结构清晰。
下面是头文件的代码,c文件代码请下载附件。
/*
* uart.h
*
* Created on:
* Author:
*/
struct T_UART_DEVICE
{
char *uart_name;
int (*ptr_fun)(unsigned char *buf,unsigned int len);
unsigned char uart_num;
unsigned char databits;
unsigned char parity;
unsigned char stopbits;
unsigned int baudrate;
};
extern struct T_UART_DEVICE uart_device;
/*
* 根据串口的名称,确定在uart_dev[]中的编号,比如/dev/ttyO0对应0,/dev/ttyO1对应1
* 返回值是串口的编号
*/
int open_uart_dev(char *uart_name);
int set_uart_opt(char *uart_name, int speed, int bits, char event, int stop);
int read_uart_data(char *uart_name, char *rcv_buf, int time_out_ms, int buf_len);
int send_uart_data(char *uart_name, char *send_buf, int buf_len);
int close_uart_dev(char *uart_name);
/*
* 创建串口线程
* uart_recvbuf_and_process是串口线程中的处理函数,参数为ptr_uart_device
* 处理函数必须是int ptr_fun (unsigned char *buf,unsigned int len);类型的函数
*/
int create_uart_pthread(struct T_UART_DEVICE *ptr_uart_device);
void *uart_recvbuf_and_process(void * ptr_uart_device);
/*
* uart_com.h
*
* Created on:
* Author:
*/
#ifndef HEADERS_DIGITALRADIO_H_
#define HEADERS_DIGITALRADIO_H_
//#define UART_RADIO 6
#define UART_RADIO "/dev/ttyO1"
#define UART_RADIO_BAUD 115200
#define UART_RADIO_DATABITS 8 //8 data bit
#define UART_RADIO_STOPBITS 1 //1 stop bit
#define UART_RADIO_PARITY 0 //no parity
#define RADIO_MAX_WAIT_TIME 6//
//底层通讯对接受到的数据解析结果变量,供通讯app层调用-------
extern unsigned char g_VerifyOK;//pc发送完数据并且mcu校验成功置1,置1后mcu开始发送数据
extern unsigned char g_CMD;// cmd
extern unsigned char g_CMD_ACMD;//acmd
extern unsigned char g_CMD_LEN;//接受data长度
extern unsigned char g_DATE[100],a_DATE;
//----------------------------------------------------------
extern int uart_com_init();
extern int read_uart_com_data(unsigned char *buf, unsigned int len);
extern int send_uart_com_data(unsigned char *buf, unsigned int len);
extern int uart_com_close();
#endif /* HEADERS_DIGITALRADIO_H_ */ |