-
Notifications
You must be signed in to change notification settings - Fork 0
/
uart_communication.h
62 lines (46 loc) · 1.58 KB
/
uart_communication.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* AUTHOR: Maarten Arits and Jonas Van Pelt
*/
#ifndef UART_COMMUNCATION_H_
#define UART_COMMUNCATION_H_
#include <sys/time.h>
#include <termios.h>
#include <unistd.h>
#include <stdint.h>
#define INPUT_BUFFER 255
/**
* GLOBALS
* */
enum uart_errCode {UART_ERR_READ_CHECKSUM = -4,UART_ERR_READ_LENGTH = -3,UART_ERR_READ_MESSAGE = -2,UART_ERR_READ_NO_DATA_IN_BUF = -1, UART_ERR_NONE=0,UART_ERR_SERIAL_PORT_FLUSH_INPUT,UART_ERR_SERIAL_PORT_FLUSH_OUTPUT,UART_ERR_SERIAL_PORT_OPEN,UART_ERR_SERIAL_PORT_CLOSE,UART_ERR_SERIAL_PORT_CREATE,UART_ERR_SERIAL_PORT_WRITE,UART_ERR_UNDEFINED};
typedef enum uart_errCode UART_errCode;
typedef struct{
int fd; /* serial device fd */
struct termios orig_termios; /* saved tty state structure */
struct termios cur_termios; /* tty state structure */
}serial_port;
serial_port *serial_stream;
struct Packets {
struct Serial {
uint32_t received;
uint32_t lost;
} serial;
struct UDP {
uint32_t received;
uint32_t lost;
} udp;
} packets;
union Serial_input {
char buffer[INPUT_BUFFER];
} serial_input;
//timers
struct timeval timers[10];
/********************************
* PROTOTYPES PUBLIC
* ******************************/
extern UART_errCode serial_port_create();
extern UART_errCode serial_port_setup(void); //returns the number of read bytes
extern int serial_input_check(void);
extern UART_errCode serial_port_write(uint8_t output[],long unsigned int message_length) ;
extern UART_errCode serial_port_close(void);
extern serial_port* serial_port_new(void);
#endif /*UART_COMMUNCATION_H_*/