|
Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
|
#include "mcu_periph/udp.h"#include "udp_socket.h"#include <stdlib.h>#include <stdio.h>#include <errno.h>#include <pthread.h>#include <string.h>#include <time.h>#include <sys/select.h>#include <arpa/inet.h>#include <ifaddrs.h>#include <net/if.h>#include "rt_priority.h"Go to the source code of this file.
Data Structures | |
| struct | UdpAuto |
| struct | UdpArch |
Macros | |
| #define | UDP_THREAD_PRIO 10 |
| #define | UDP_AUTO_HOST "auto" |
| #define | UDP_AUTO_MAX_GCS 8 |
| #define | UDP_AUTO_MAX_BCAST 8 |
| #define | UDP_AUTO_GCS_TIMEOUT_MS 15000 |
| #define | UDP_AUTO_BCAST_PERIOD 1000 |
| #define | UDP_AUTO_IF_REFRESH_MS 5000 |
Functions | |
| static void * | udp_thread (void *data) |
| check for new udp packets to receive or send. | |
| static uint32_t | udp_time_ms (void) |
| static void | udp_auto_refresh_bcast (struct UdpAuto *au) |
| Broadcast address of every interface that is up (not loopback). | |
| static void | udp_auto_gcs_seen (struct UdpAuto *au, struct sockaddr_in *from) |
| Remember the sender of a datagram as a GCS (called with the udp mutex). | |
| static void | udp_auto_send (struct UdpArch *ua, uint8_t *buffer, uint16_t size) |
| Send to the GCS computers found, or broadcast (see UdpAuto). | |
| int | udp_arch_auto_gcs (struct in_addr *addr, int max) |
| GCS computers found by the links with host "auto", each IP address once. | |
| void | udp_arch_init (void) |
| void | udp_arch_periph_init (struct udp_periph *p, char *host, int port_out, int port_in, bool broadcast) |
| Initialize the UDP peripheral. | |
| int | udp_char_available (struct udp_periph *p) |
| Get number of bytes available in receive buffer. | |
| uint8_t | udp_getch (struct udp_periph *p) |
| Get the last character from the receive buffer. | |
| void | udp_receive (struct udp_periph *p) |
| Read bytes from UDP. | |
| void | udp_send_message (struct udp_periph *p, long fd) |
| Send a message. | |
| void | udp_send_raw (struct udp_periph *p, long fd, uint8_t *buffer, uint16_t size) |
| Send a packet from another buffer. | |
Variables | |
| static pthread_mutex_t | udp_mutex = PTHREAD_MUTEX_INITIALIZER |
| struct UdpAuto |
Definition at line 62 of file udp_arch.c.
| Data Fields | ||
|---|---|---|
| struct sockaddr_in | bcast[UDP_AUTO_MAX_BCAST] | |
| uint32_t | bcast_refresh_ms | |
| bool | enabled | |
| struct sockaddr_in | gcs[UDP_AUTO_MAX_GCS] | |
| uint32_t | gcs_seen_ms[UDP_AUTO_MAX_GCS] | 0: free slot |
| uint32_t | last_bcast_ms | |
| int | nb_bcast | |
| uint16_t | port_out | |
| struct UdpArch |
Definition at line 74 of file udp_arch.c.
| Data Fields | ||
|---|---|---|
| struct UdpAuto | au | |
| struct UdpSocket | sock | |
| #define UDP_AUTO_BCAST_PERIOD 1000 |
Definition at line 59 of file udp_arch.c.
| #define UDP_AUTO_GCS_TIMEOUT_MS 15000 |
Definition at line 58 of file udp_arch.c.
| #define UDP_AUTO_HOST "auto" |
Definition at line 55 of file udp_arch.c.
| #define UDP_AUTO_IF_REFRESH_MS 5000 |
Definition at line 60 of file udp_arch.c.
| #define UDP_AUTO_MAX_BCAST 8 |
Definition at line 57 of file udp_arch.c.
| #define UDP_AUTO_MAX_GCS 8 |
Definition at line 56 of file udp_arch.c.
| #define UDP_THREAD_PRIO 10 |
Definition at line 42 of file udp_arch.c.
| int udp_arch_auto_gcs | ( | struct in_addr * | addr, |
| int | max ) |
GCS computers found by the links with host "auto", each IP address once.
GCS computers found by the UDP links with host "auto" (see udp_arch.c), e.g.
Definition at line 174 of file udp_arch.c.
References UdpArch::au, UdpAuto::enabled, UdpAuto::gcs, UdpAuto::gcs_seen_ms, p, UDP_AUTO_GCS_TIMEOUT_MS, UDP_AUTO_MAX_GCS, udp_mutex, and udp_time_ms().
| void udp_arch_init | ( | void | ) |
Definition at line 213 of file udp_arch.c.
References udp_mutex, and udp_thread().
| void udp_arch_periph_init | ( | struct udp_periph * | p, |
| char * | host, | ||
| int | port_out, | ||
| int | port_in, | ||
| bool | broadcast ) |
Initialize the UDP peripheral.
Allocate UdpSocket struct and create and bind the UDP socket.
Definition at line 241 of file udp_arch.c.
References UdpArch::au, UdpAuto::enabled, p, UdpAuto::port_out, UdpArch::sock, UDP_AUTO_HOST, and udp_socket_create().
|
static |
Remember the sender of a datagram as a GCS (called with the udp mutex).
Definition at line 114 of file udp_arch.c.
References UdpAuto::gcs, UdpAuto::gcs_seen_ms, UDP_AUTO_GCS_TIMEOUT_MS, UDP_AUTO_MAX_GCS, and udp_time_ms().
|
static |
Broadcast address of every interface that is up (not loopback).
Definition at line 88 of file udp_arch.c.
References UdpAuto::bcast, UdpAuto::nb_bcast, UdpAuto::port_out, and UDP_AUTO_MAX_BCAST.
Send to the GCS computers found, or broadcast (see UdpAuto).
Definition at line 142 of file udp_arch.c.
References UdpArch::au, UdpAuto::bcast, UdpAuto::bcast_refresh_ms, UdpAuto::gcs, UdpAuto::gcs_seen_ms, UdpAuto::last_bcast_ms, UdpAuto::nb_bcast, UdpArch::sock, UdpSocket::sockfd, UDP_AUTO_BCAST_PERIOD, UDP_AUTO_GCS_TIMEOUT_MS, UDP_AUTO_IF_REFRESH_MS, UDP_AUTO_MAX_GCS, udp_auto_refresh_bcast(), udp_mutex, and udp_time_ms().
| int udp_char_available | ( | struct udp_periph * | p | ) |
Get number of bytes available in receive buffer.
| p | pointer to UDP peripheral |
Definition at line 260 of file udp_arch.c.
References p, udp_mutex, and UDP_RX_BUFFER_SIZE.
| uint8_t udp_getch | ( | struct udp_periph * | p | ) |
Get the last character from the receive buffer.
| p | pointer to UDP peripheral |
Definition at line 276 of file udp_arch.c.
References p, udp_mutex, and UDP_RX_BUFFER_SIZE.
| void udp_receive | ( | struct udp_periph * | p | ) |
Read bytes from UDP.
Definition at line 288 of file udp_arch.c.
References UdpSocket::addr_in, UdpArch::au, UdpAuto::enabled, p, UdpArch::sock, UdpSocket::sockfd, udp_auto_gcs_seen(), udp_char_available(), udp_mutex, and UDP_RX_BUFFER_SIZE.
| void udp_send_message | ( | struct udp_periph * | p, |
| long | fd ) |
Send a message.
Definition at line 325 of file udp_arch.c.
References UdpSocket::addr_out, fd, p, UdpSocket::sockfd, and udp_auto_send().
| void udp_send_raw | ( | struct udp_periph * | p, |
| long | fd, | ||
| uint8_t * | buffer, | ||
| uint16_t | size ) |
Send a packet from another buffer.
Definition at line 353 of file udp_arch.c.
References UdpSocket::addr_out, fd, p, UdpSocket::sockfd, and udp_auto_send().
|
static |
check for new udp packets to receive or send.
Definition at line 370 of file udp_arch.c.
References fd, get_rt_prio(), UdpSocket::sockfd, udp_receive(), and UDP_THREAD_PRIO.
|
static |
Definition at line 79 of file udp_arch.c.
|
static |
Definition at line 46 of file udp_arch.c.