Paparazzi UAS  v5.8.2_stable-0-g6260b7c
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 "mcu_periph/link_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;
50 };
51 
52 extern void udp_periph_init(struct udp_periph *p, char *host, int port_out, int port_in, bool_t broadcast);
53 extern bool_t udp_check_free_space(struct udp_periph *p, uint8_t len);
54 extern void udp_put_byte(struct udp_periph *p, 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_t broadcast);
58 extern void udp_send_message(struct udp_periph *p);
59 extern void udp_send_raw(struct udp_periph *p, uint8_t *buffer, uint16_t size);
60 extern void udp_receive(struct udp_periph *p);
61 
62 #if USE_UDP0
63 extern struct udp_periph udp0;
64 
65 #ifndef UDP0_HOST
66 #define UDP0_HOST 127.0.0.1
67 #endif
68 
69 #ifndef UDP0_PORT_OUT
70 #define UDP0_PORT_OUT 4242
71 #endif
72 
73 #ifndef UDP0_PORT_IN
74 #define UDP0_PORT_IN 4243
75 #endif
76 
77 #ifndef UDP0_BROADCAST
78 #define UDP0_BROADCAST FALSE
79 #endif
80 
81 #define UDP0Init() udp_periph_init(&udp0, STRINGIFY(UDP0_HOST), UDP0_PORT_OUT, UDP0_PORT_IN, UDP0_BROADCAST)
82 #endif // USE_UDP0
83 
84 #if USE_UDP1
85 extern struct udp_periph udp1;
86 
87 #ifndef UDP1_HOST
88 #define UDP1_HOST 127.0.0.1
89 #endif
90 
91 #ifndef UDP1_PORT_OUT
92 #define UDP1_PORT_OUT 4244
93 #endif
94 
95 #ifndef UDP1_PORT_IN
96 #define UDP1_PORT_IN 4245
97 #endif
98 
99 #ifndef UDP1_BROADCAST
100 #define UDP1_BROADCAST FALSE
101 #endif
102 
103 #define UDP1Init() udp_periph_init(&udp1, STRINGIFY(UDP1_HOST), UDP1_PORT_OUT, UDP1_PORT_IN, UDP1_BROADCAST)
104 #endif // USE_UDP1
105 
106 #if USE_UDP2
107 extern struct udp_periph udp2;
108 
109 #ifndef UDP2_HOST
110 #define UDP2_HOST 127.0.0.1
111 #endif
112 
113 #ifndef UDP2_PORT_OUT
114 #define UDP2_PORT_OUT 4246
115 #endif
116 
117 #ifndef UDP2_PORT_IN
118 #define UDP2_PORT_IN 4247
119 #endif
120 
121 #ifndef UDP2_BROADCAST
122 #define UDP2_BROADCAST FALSE
123 #endif
124 
125 #define UDP2Init() udp_periph_init(&udp2, STRINGIFY(UDP2_HOST), UDP2_PORT_OUT, UDP2_PORT_IN, UDP2_BROADCAST)
126 #endif // USE_UDP2
127 
128 #endif /* MCU_PERIPH_UDP_H */
bool_t udp_check_free_space(struct udp_periph *p, uint8_t len)
Check if there is enough free space in the transmit buffer.
Definition: udp.c:80
unsigned short uint16_t
Definition: types.h:16
uint16_t udp_char_available(struct udp_periph *p)
Get number of bytes available in receive buffer.
Definition: udp_arch.c:81
void udp_send_raw(struct udp_periph *p, uint8_t *buffer, uint16_t size)
Send a packet from another buffer.
Definition: udp_arch.c:168
uint8_t tx_buf[UDP_TX_BUFFER_SIZE]
Transmit buffer.
Definition: udp.h:44
uint16_t rx_extract_idx
Definition: udp.h:42
void udp_send_message(struct udp_periph *p)
Send a message.
Definition: udp_arch.c:142
#define UDP_RX_BUFFER_SIZE
Definition: udp.h:35
void udp_put_byte(struct udp_periph *p, uint8_t data)
Add one data byte to the tx buffer.
Definition: udp.c:90
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 * network
UDP network.
Definition: udp.h:47
Definition: udp.h:38
#define UDP_TX_BUFFER_SIZE
Definition: udp.h:36
void udp_periph_init(struct udp_periph *p, char *host, int port_out, int port_in, bool_t broadcast)
Initialize the UDP peripheral.
Definition: udp.c:58
unsigned char uint8_t
Definition: types.h:14
void udp_receive(struct udp_periph *p)
Read bytes from UDP.
Definition: udp_arch.c:109
uint16_t rx_insert_idx
Definition: udp.h:41
void udp_arch_periph_init(struct udp_periph *p, char *host, int port_out, int port_in, bool_t broadcast)
Initialize the UDP peripheral.
Definition: udp_arch.c:69
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