Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
udp.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Freek van tienen <freek.v.tienen@gmail.com>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
28 #ifndef MCU_PERIPH_UDP_H
29 #define MCU_PERIPH_UDP_H
30 
31 #include "std.h"
32 #include "mcu_periph/udp_arch.h"
33 #include "pprzlink/pprzlink_device.h"
34 
35 #define UDP_RX_BUFFER_SIZE 256
36 #define UDP_TX_BUFFER_SIZE 256
37 
38 struct udp_periph {
47  void *network;
49  struct link_device device;
50 };
51 
52 extern void udp_periph_init(struct udp_periph *p, char *host, int port_out, int port_in, bool broadcast);
53 extern bool udp_check_free_space(struct udp_periph *p, long *fd, uint16_t len);
54 extern void udp_put_byte(struct udp_periph *p, long fd, uint8_t data);
55 extern uint16_t udp_char_available(struct udp_periph *p);
56 extern uint8_t udp_getch(struct udp_periph *p);
57 extern void udp_arch_periph_init(struct udp_periph *p, char *host, int port_out, int port_in, bool broadcast);
58 extern void udp_send_message(struct udp_periph *p, long fd);
59 extern void udp_send_raw(struct udp_periph *p, long fd, uint8_t *buffer, uint16_t size);
60 extern void udp_receive(struct udp_periph *p);
61 extern void udp_put_buffer(struct udp_periph *p, long fd, const uint8_t *data, uint16_t len);
62 
63 #if USE_UDP0
64 extern struct udp_periph udp0;
65 
66 #ifndef UDP0_HOST
67 #define UDP0_HOST 127.0.0.1
68 #endif
69 
70 #ifndef UDP0_PORT_OUT
71 #define UDP0_PORT_OUT 4242
72 #endif
73 
74 #ifndef UDP0_PORT_IN
75 #define UDP0_PORT_IN 4243
76 #endif
77 
78 #ifndef UDP0_BROADCAST
79 #define UDP0_BROADCAST FALSE
80 #endif
81 
82 #define UDP0Init() udp_periph_init(&udp0, STRINGIFY(UDP0_HOST), UDP0_PORT_OUT, UDP0_PORT_IN, UDP0_BROADCAST)
83 #endif // USE_UDP0
84 
85 #if USE_UDP1
86 extern struct udp_periph udp1;
87 
88 #ifndef UDP1_HOST
89 #define UDP1_HOST 127.0.0.1
90 #endif
91 
92 #ifndef UDP1_PORT_OUT
93 #define UDP1_PORT_OUT 4244
94 #endif
95 
96 #ifndef UDP1_PORT_IN
97 #define UDP1_PORT_IN 4245
98 #endif
99 
100 #ifndef UDP1_BROADCAST
101 #define UDP1_BROADCAST FALSE
102 #endif
103 
104 #define UDP1Init() udp_periph_init(&udp1, STRINGIFY(UDP1_HOST), UDP1_PORT_OUT, UDP1_PORT_IN, UDP1_BROADCAST)
105 #endif // USE_UDP1
106 
107 #if USE_UDP2
108 extern struct udp_periph udp2;
109 
110 #ifndef UDP2_HOST
111 #define UDP2_HOST 127.0.0.1
112 #endif
113 
114 #ifndef UDP2_PORT_OUT
115 #define UDP2_PORT_OUT 4246
116 #endif
117 
118 #ifndef UDP2_PORT_IN
119 #define UDP2_PORT_IN 4247
120 #endif
121 
122 #ifndef UDP2_BROADCAST
123 #define UDP2_BROADCAST FALSE
124 #endif
125 
126 #define UDP2Init() udp_periph_init(&udp2, STRINGIFY(UDP2_HOST), UDP2_PORT_OUT, UDP2_PORT_IN, UDP2_BROADCAST)
127 #endif // USE_UDP2
128 
129 #endif /* MCU_PERIPH_UDP_H */
unsigned short uint16_t
Definition: types.h:16
void udp_periph_init(struct udp_periph *p, char *host, int port_out, int port_in, bool broadcast)
Initialize the UDP peripheral.
Definition: udp.c:60
void udp_arch_periph_init(struct udp_periph *p, char *host, int port_out, int port_in, bool broadcast)
Initialize the UDP peripheral.
Definition: udp_arch.c:69
uint16_t udp_char_available(struct udp_periph *p)
Get number of bytes available in receive buffer.
Definition: udp_arch.c:81
uint8_t tx_buf[UDP_TX_BUFFER_SIZE]
Transmit buffer.
Definition: udp.h:44
uint16_t rx_extract_idx
Definition: udp.h:42
#define UDP_RX_BUFFER_SIZE
Definition: udp.h:35
bool udp_check_free_space(struct udp_periph *p, long *fd, uint16_t len)
Check if there is enough free space in the transmit buffer.
Definition: udp.c:83
void udp_send_raw(struct udp_periph *p, long fd, uint8_t *buffer, uint16_t size)
Send a packet from another buffer.
Definition: udp_arch.c:168
uint16_t tx_insert_idx
Definition: udp.h:45
uint8_t udp_getch(struct udp_periph *p)
Get the last character from the receive buffer.
Definition: udp_arch.c:97
void udp_send_message(struct udp_periph *p, long fd)
Send a message.
Definition: udp_arch.c:142
void udp_put_buffer(struct udp_periph *p, long fd, const uint8_t *data, uint16_t len)
Definition: udp.c:103
void * network
UDP network.
Definition: udp.h:47
void udp_put_byte(struct udp_periph *p, long fd, uint8_t data)
Add one data byte to the tx buffer.
Definition: udp.c:93
Definition: udp.h:38
#define UDP_TX_BUFFER_SIZE
Definition: udp.h:36
unsigned char uint8_t
Definition: types.h:14
void udp_receive(struct udp_periph *p)
Read bytes from UDP.
Definition: udp_arch.c:109
int fd
Definition: serial.c:26
uint16_t rx_insert_idx
Definition: udp.h:41
static float p[2][2]
uint8_t rx_buf[UDP_RX_BUFFER_SIZE]
Receive buffer.
Definition: udp.h:40
struct link_device device
Generic device interface.
Definition: udp.h:49