hyperion.ng
Enumerations | Functions
IP Connection

Enumerations

enum  { IPCON_CALLBACK_ENUMERATE = 253, IPCON_CALLBACK_CONNECTED = 0, IPCON_CALLBACK_DISCONNECTED = 1 }
 Possible IDs for ipcon_register_callback.
 
enum  { IPCON_ENUMERATION_TYPE_AVAILABLE = 0, IPCON_ENUMERATION_TYPE_CONNECTED = 1, IPCON_ENUMERATION_TYPE_DISCONNECTED = 2 }
 Possible values for enumeration_type parameter of EnumerateCallback.
 
enum  { IPCON_CONNECT_REASON_REQUEST = 0, IPCON_CONNECT_REASON_AUTO_RECONNECT = 1 }
 Possible values for connect_reason parameter of ConnectedCallback.
 
enum  { IPCON_DISCONNECT_REASON_REQUEST = 0, IPCON_DISCONNECT_REASON_ERROR = 1, IPCON_DISCONNECT_REASON_SHUTDOWN = 2 }
 Possible values for disconnect_reason parameter of DisconnectedCallback.
 
enum  { IPCON_CONNECTION_STATE_DISCONNECTED = 0, IPCON_CONNECTION_STATE_CONNECTED = 1, IPCON_CONNECTION_STATE_PENDING = 2 }
 Possible return values of ipcon_get_connection_state.
 

Functions

void ipcon_create (IPConnection *ipcon)
 Creates an IP Connection object that can be used to enumerate the available devices. More...
 
void ipcon_destroy (IPConnection *ipcon)
 Destroys the IP Connection object. More...
 
int ipcon_connect (IPConnection *ipcon, const char *host, uint16_t port)
 Creates a TCP/IP connection to the given host and c\ port. More...
 
int ipcon_disconnect (IPConnection *ipcon)
 Disconnects the TCP/IP connection from the Brick Daemon or the WIFI/Ethernet Extension.
 
int ipcon_get_connection_state (IPConnection *ipcon)
 Can return the following states: More...
 
void ipcon_set_auto_reconnect (IPConnection *ipcon, bool auto_reconnect)
 Enables or disables auto-reconnect. More...
 
bool ipcon_get_auto_reconnect (IPConnection *ipcon)
 Returns true if auto-reconnect is enabled, false otherwise.
 
void ipcon_set_timeout (IPConnection *ipcon, uint32_t timeout)
 Sets the timeout in milliseconds for getters and for setters for which the response expected flag is activated. More...
 
uint32_t ipcon_get_timeout (IPConnection *ipcon)
 Returns the timeout as set by ipcon_set_timeout.
 
int ipcon_enumerate (IPConnection *ipcon)
 Broadcasts an enumerate request. More...
 
void ipcon_wait (IPConnection *ipcon)
 Stops the current thread until ipcon_unwait is called. More...
 
void ipcon_unwait (IPConnection *ipcon)
 Unwaits the thread previously stopped by ipcon_wait. More...
 
void ipcon_register_callback (IPConnection *ipcon, uint8_t id, void *callback, void *user_data)
 Registers a callback for a given ID.
 

Detailed Description

Function Documentation

§ ipcon_connect()

int ipcon_connect ( IPConnection ipcon,
const char *  host,
uint16_t  port 
)

Creates a TCP/IP connection to the given host and c\ port.

The host and port can point to a Brick Daemon or to a WIFI/Ethernet Extension.

Devices can only be controlled when the connection was established successfully.

Blocks until the connection is established and returns an error code if there is no Brick Daemon or WIFI/Ethernet Extension listening at the given host and port.

§ ipcon_create()

void ipcon_create ( IPConnection ipcon)

Creates an IP Connection object that can be used to enumerate the available devices.

It is also required for the constructor of Bricks and Bricklets.

§ ipcon_destroy()

void ipcon_destroy ( IPConnection ipcon)

Destroys the IP Connection object.

Calls ipcon_disconnect internally. The connection to the Brick Daemon gets closed and the threads of the IP Connection are terminated.

§ ipcon_enumerate()

int ipcon_enumerate ( IPConnection ipcon)

Broadcasts an enumerate request.

All devices will respond with an enumerate callback.

§ ipcon_get_connection_state()

int ipcon_get_connection_state ( IPConnection ipcon)

Can return the following states:

  • IPCON_CONNECTION_STATE_DISCONNECTED: No connection is established.
  • IPCON_CONNECTION_STATE_CONNECTED: A connection to the Brick Daemon or the WIFI/Ethernet Extension is established.
  • IPCON_CONNECTION_STATE_PENDING: IP Connection is currently trying to connect.

§ ipcon_set_auto_reconnect()

void ipcon_set_auto_reconnect ( IPConnection ipcon,
bool  auto_reconnect 
)

Enables or disables auto-reconnect.

If auto-reconnect is enabled, the IP Connection will try to reconnect to the previously given host and port, if the connection is lost.

Default value is true.

§ ipcon_set_timeout()

void ipcon_set_timeout ( IPConnection ipcon,
uint32_t  timeout 
)

Sets the timeout in milliseconds for getters and for setters for which the response expected flag is activated.

Default timeout is 2500.

§ ipcon_unwait()

void ipcon_unwait ( IPConnection ipcon)

Unwaits the thread previously stopped by ipcon_wait.

ipcon_wait and ipcon_unwait act in the same way as "acquire" and "release" of a semaphore.

§ ipcon_wait()

void ipcon_wait ( IPConnection ipcon)

Stops the current thread until ipcon_unwait is called.

This is useful if you rely solely on callbacks for events, if you want to wait for a specific callback or if the IP Connection was created in a thread.

ipcon_wait and ipcon_unwait act in the same way as "acquire" and "release" of a semaphore.