Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Simple-udp

The default Contiki UDP API is difficult to use.

The simple-udp module provides a significantly simpler API.

Data Structures

struct  simple_udp_connection
 

Macros

#define UIP_IP_BUF   ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])
 

Typedefs

typedef void(* simple_udp_callback )(struct simple_udp_connection *c, const uip_ipaddr_t *source_addr, uint16_t source_port, const uip_ipaddr_t *dest_addr, uint16_t dest_port, const uint8_t *data, uint16_t datalen)
 

Functions

static void init_simple_udp (void)
 
 PROCESS (simple_udp_process,"Simple UDP process")
 
 PROCESS_THREAD (simple_udp_process, ev, data)
 
void simple_udp_init (void)
 
int simple_udp_register (struct simple_udp_connection *c, uint16_t local_port, uip_ipaddr_t *remote_addr, uint16_t remote_port, simple_udp_callback receive_callback)
 Register a UDP connection. More...
 
int simple_udp_send (struct simple_udp_connection *c, const void *data, uint16_t datalen)
 Send a UDP packet. More...
 
int simple_udp_sendto (struct simple_udp_connection *c, const void *data, uint16_t datalen, const uip_ipaddr_t *to)
 Send a UDP packet to a specified IP address. More...
 
int simple_udp_sendto_port (struct simple_udp_connection *c, const void *data, uint16_t datalen, const uip_ipaddr_t *to, uint16_t port)
 Send a UDP packet to a specified IP address and UDP port. More...
 

Variables

static uint8_t databuffer [UIP_BUFSIZE]
 
static uint8_t started = 0
 

#define UIP_IP_BUF   ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])

Referenced by PROCESS_THREAD().

typedef void(* simple_udp_callback)(struct simple_udp_connection *c, const uip_ipaddr_t *source_addr, uint16_t source_port, const uip_ipaddr_t *dest_addr, uint16_t dest_port, const uint8_t *data, uint16_t datalen)

static void init_simple_udp ( void  )
static

References NULL, process_start(), and started.

Referenced by simple_udp_register().

PROCESS ( simple_udp_process  ,
"Simple UDP process  
)
void simple_udp_init ( void  )
int simple_udp_register ( struct simple_udp_connection c,
uint16_t  local_port,
uip_ipaddr_t remote_addr,
uint16_t  remote_port,
simple_udp_callback  receive_callback 
)

Register a UDP connection.

Parameters
cA pointer to a struct simple_udp_connection
local_portThe local UDP port in host byte order
remote_addrThe remote IP address
remote_portThe remote UDP port in host byte order
receive_callbackA pointer to a function to be called for incoming packets
Return values
0If no UDP connection could be allocated
1If the connection was successfully allocated
        This function registers a UDP connection and attaches a
        callback function to it. The callback function will be
        called for incoming packets. The local UDP port can be
        set to 0 to indicate that an ephemeral UDP port should
        be allocated. The remote IP address can be NULL, to
        indicate that packets from any IP address should be
        accepted.

References init_simple_udp(), simple_udp_connection::local_port, NULL, PROCESS_CONTEXT_BEGIN, PROCESS_CONTEXT_END, simple_udp_connection::receive_callback, simple_udp_connection::remote_addr, simple_udp_connection::remote_port, udp_bind, simple_udp_connection::udp_conn, udp_new(), UIP_HTONS, and uip_ipaddr_copy.

Referenced by PROCESS_THREAD().

int simple_udp_send ( struct simple_udp_connection c,
const void *  data,
uint16_t  datalen 
)

Send a UDP packet.

Parameters
cA pointer to a struct simple_udp_connection
dataA pointer to the data to be sent
datalenThe length of the data
        This function sends a UDP packet. The packet will be
        sent to the IP address and with the UDP ports that were
        specified when the connection wa registered with
        simple_udp_register().
See Also
simple_udp_sendto()

References NULL, simple_udp_connection::remote_addr, simple_udp_connection::remote_port, simple_udp_connection::udp_conn, UIP_HTONS, and uip_udp_packet_sendto().

int simple_udp_sendto ( struct simple_udp_connection c,
const void *  data,
uint16_t  datalen,
const uip_ipaddr_t to 
)

Send a UDP packet to a specified IP address.

Parameters
cA pointer to a struct simple_udp_connection
dataA pointer to the data to be sent
datalenThe length of the data
toThe IP address of the receiver
        This function sends a UDP packet to a specified IP
        address. The packet will be sent with the UDP ports
        that were specified when the connection wa registered
        with simple_udp_register().
See Also
simple_udp_send()

References NULL, simple_udp_connection::remote_port, simple_udp_connection::udp_conn, UIP_HTONS, and uip_udp_packet_sendto().

Referenced by PROCESS_THREAD(), and send_msg().

int simple_udp_sendto_port ( struct simple_udp_connection c,
const void *  data,
uint16_t  datalen,
const uip_ipaddr_t to,
uint16_t  port 
)

Send a UDP packet to a specified IP address and UDP port.

Parameters
cA pointer to a struct simple_udp_connection
dataA pointer to the data to be sent
datalenThe length of the data
toThe IP address of the receiver
portThe UDP port of the receiver, in host byte order
        This function sends a UDP packet to a specified IP
        address and UDP port. The packet will be sent with the
        UDP ports that were specified when the connection wa
        registered with simple_udp_register().
See Also
simple_udp_sendto()

References NULL, simple_udp_connection::udp_conn, UIP_HTONS, and uip_udp_packet_sendto().

uint8_t databuffer[UIP_BUFSIZE]
static

Referenced by PROCESS_THREAD().

uint8_t started = 0
static

Referenced by init_simple_udp().