IR networking

Assume that none of the LNP commands are thread-safe.


The following declarations are used

typedef void (*lnp_addressing_handler_t) (const unsigned char *, unsigned char, unsigned char);


LNP logical layer commands

#include <lnp/lnp-logical.h>

void lnp_logical_range ( int i );
Sets the IR range mode. 0 = Short range (~3 ft) 1 = Long Range (>15 ft)

void lnp_logical_range_is_far ( );
returns the IR Range setting

void lnp_logical_write ( const void *buf, size_t len );
len byte block of memory starting at buf is written to the IR port. You typically will want to use lnp_addressing_write or lnp_reliable_write instead of this, as this provides no addressing functionality. A call to this function waits for the write to complete / fail.
returns 0 on success. Any other value signifies a probable collision.

void lnp_logical_fflush ( );
flushes the input buffer


LNP addressing layer commands

#include <lnp/lnp.h>

void lnp_addressing_set_handler ( unsigned char port, lnp_addressing_handler_t handler );
sets the handler for incoming data received on port port. Whenever a message is received on the specified port, a call to handler will be made, with the message as a parameter.
Parameters: port - the port to set an addressing handler for
handler - a function pointer to the function that will handle incoming data on port port

int lnp_addressing_write ( const void *data, unsigned char length, unsigned char dest, unsigned char srcport );
Transmits length bytes of a chunk of memory starting at data to dest, with an originating port of srcport. A call to this function will block until the entire message has been transmitted or until failure.
Parameters: data - a pointer to the block of memory to be sent
length - the number of bytes to send
dest - The address to broadcast to. This should be a full address, with both host address and destination port
srcport - This is used to tell the recipient which port to send replies to.
returns: 0 on success, -1 on failure

int lnp_get_hostaddr ( );
returns: the address of the current machine

void lnp_set_hostaddr ( unsigned char new_hostaddr );
changes the host address to new_hostaddr. Does not affect existing port handlers. Does not affect reliable connections, but any existing reliable conection should be re-initialized anyway.


LNP reliable layer commands

#include <lnp/lnp-reliable.h>

void lnp_reliable_init ( char dest, int port );
intializes LNP reliable communications with dest. This needs to be called by both sides of the connection before data can be sent. Both sides need to be using the same port number.

void lnp_reliable_shutdown();
Shuts down the LNP reliable communications thread. This needs to be called when the communication is no longer needed to free up the resources LNP uses.

int lnp_reliable_write ( const void * data, int real_length );
sends a real_length byte chunk of data starting from data across the network. A call to this function will block until either the message has been acknowledged or until a timeout occurs (currently 2.5 seconds)
returns: 0 on success, -1 on failure

int lnp_reliable_read ( void * data, unsigned char *src );
fills data with whatever has been received from the reliable connection. If src is non-null, then the originating address and port are stored in src. A call to this function will block until data is successfully read.
Parameters: data - The buffer to write to
src - the place to store the source address. Make this NULL if you don't want it filled in
returns: the number of bytes read

int lnp_reliable_printf ( const char * fmt, ... );
wrapper around lnp_reliable_write for more convenient writing of data across the reliable connection. uses printf style formatting
returns: number of bytes written