Illustrated C/C++ source sheets, symbol index, API relationship graph, compiler console and debug trace

LIVE AI / FLEXIBLE SENSING / FLIGHT CONTEXT

Sensoraia API

Live AI and sensing, connected to the flight.
See, listen, inspect and return supported results while airborne.

Loading...
Searching...
No Matches
socket.c File Reference

Loopback UDP implementation for USHER's local development transport. More...

#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/uio.h>
#include <unistd.h>
#include <string.h>
#include "socket.h"
Include dependency graph for socket.c:

Go to the source code of this file.

Macros

#define SOCKET_PORT   32000

Functions

int socket_init (int is_server)
 Create the loopback UDP endpoint and, for a server, claim USHER ownership.
void socket_deinit (void)
 Close the owned UDP endpoint; repeated calls are harmless.
int socket_get_fd (void)
 Return the active UDP descriptor for polling.
int socket_recv (char *buffer, int len)
 Receive one datagram without blocking.
void socket_send (char *buffer, int len)
 Send one loopback datagram without blocking.

Variables

static int socket_fd = -1
static struct sockaddr_in socket_server

Detailed Description

Loopback UDP implementation for USHER's local development transport.

The fixed port permits the local bridge and test tools to find each other without configuration. All I/O is non-blocking so local consumers cannot delay the flight-controller UART event loop.

Definition in file socket.c.

Macro Definition Documentation

◆ SOCKET_PORT

#define SOCKET_PORT   32000

Definition at line 39 of file socket.c.

Function Documentation

◆ socket_deinit()

void socket_deinit ( void )

Close the owned UDP endpoint; repeated calls are harmless.

Definition at line 96 of file socket.c.

◆ socket_get_fd()

int socket_get_fd ( void )

Return the active UDP descriptor for polling.

Returns
Borrowed descriptor, or a negative value before initialization/after teardown.

Definition at line 102 of file socket.c.

◆ socket_init()

int socket_init ( int is_server)

Create the loopback UDP endpoint and, for a server, claim USHER ownership.

Parameters
is_serverNonzero to bind the fixed local port; zero for an unbound sender.
Returns
0 on success, or -1 on failure; EALREADY preserves an active endpoint.

The server bind doubles as the physical-mode single-instance claim. A second USHER must fail rather than share the port because it would also compete for the same UART and camera resources.

Definition at line 44 of file socket.c.

◆ socket_recv()

int socket_recv ( char * buffer,
int len )

Receive one datagram without blocking.

Parameters
bufferDestination bytes.
lenDestination capacity.
Returns
recvfrom() result, including -1/EAGAIN when no datagram is ready.

Definition at line 107 of file socket.c.

◆ socket_send()

void socket_send ( char * buffer,
int len )

Send one loopback datagram without blocking.

Parameters
bufferPayload bytes.
lenPayload length.

Definition at line 126 of file socket.c.

Variable Documentation

◆ socket_fd

int socket_fd = -1
static

Definition at line 41 of file socket.c.

◆ socket_server

struct sockaddr_in socket_server
static

Definition at line 42 of file socket.c.