Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
udp_arch.c File Reference
#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"
Include dependency graph for udp_arch.c:

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

Data Structure Documentation

◆ UdpAuto

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

◆ UdpArch

struct UdpArch

Definition at line 74 of file udp_arch.c.

Collaboration diagram for UdpArch:
Data Fields
struct UdpAuto au
struct UdpSocket sock

Macro Definition Documentation

◆ UDP_AUTO_BCAST_PERIOD

#define UDP_AUTO_BCAST_PERIOD   1000

Definition at line 59 of file udp_arch.c.

◆ UDP_AUTO_GCS_TIMEOUT_MS

#define UDP_AUTO_GCS_TIMEOUT_MS   15000

Definition at line 58 of file udp_arch.c.

◆ UDP_AUTO_HOST

#define UDP_AUTO_HOST   "auto"

Definition at line 55 of file udp_arch.c.

◆ UDP_AUTO_IF_REFRESH_MS

#define UDP_AUTO_IF_REFRESH_MS   5000

Definition at line 60 of file udp_arch.c.

◆ UDP_AUTO_MAX_BCAST

#define UDP_AUTO_MAX_BCAST   8

Definition at line 57 of file udp_arch.c.

◆ UDP_AUTO_MAX_GCS

#define UDP_AUTO_MAX_GCS   8

Definition at line 56 of file udp_arch.c.

◆ UDP_THREAD_PRIO

#define UDP_THREAD_PRIO   10

Definition at line 42 of file udp_arch.c.

Function Documentation

◆ udp_arch_auto_gcs()

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().

Here is the call graph for this function:

◆ udp_arch_init()

void udp_arch_init ( void )

Definition at line 213 of file udp_arch.c.

References udp_mutex, and udp_thread().

Here is the call graph for this function:

◆ udp_arch_periph_init()

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().

Here is the call graph for this function:

◆ udp_auto_gcs_seen()

void udp_auto_gcs_seen ( struct UdpAuto * au,
struct sockaddr_in * from )
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().

Here is the call graph for this function:

◆ udp_auto_refresh_bcast()

void udp_auto_refresh_bcast ( struct UdpAuto * au)
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.

◆ udp_auto_send()

void udp_auto_send ( struct UdpArch * ua,
uint8_t * buffer,
uint16_t size )
static

◆ udp_char_available()

int udp_char_available ( struct udp_periph * p)

Get number of bytes available in receive buffer.

Parameters
ppointer to UDP peripheral
Returns
number of bytes available in receive buffer

Definition at line 260 of file udp_arch.c.

References p, udp_mutex, and UDP_RX_BUFFER_SIZE.

◆ udp_getch()

uint8_t udp_getch ( struct udp_periph * p)

Get the last character from the receive buffer.

Parameters
ppointer to UDP peripheral
Returns
last byte

Definition at line 276 of file udp_arch.c.

References p, udp_mutex, and UDP_RX_BUFFER_SIZE.

◆ udp_receive()

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.

Here is the call graph for this function:

◆ udp_send_message()

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().

Here is the call graph for this function:

◆ udp_send_raw()

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().

Here is the call graph for this function:

◆ udp_thread()

void * udp_thread ( void * data)
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.

Here is the call graph for this function:

◆ udp_time_ms()

uint32_t udp_time_ms ( void )
static

Definition at line 79 of file udp_arch.c.

Variable Documentation

◆ udp_mutex

pthread_mutex_t udp_mutex = PTHREAD_MUTEX_INITIALIZER
static

Definition at line 46 of file udp_arch.c.