Air SDK library

<airsdk/airsdk.hpp>

class ControlInterface

ControlInterface class used to communicate with the local drone ‘control’ daemon

Public Functions

ControlInterface()

ControlInterface default constructor. This constructor creates an internal thread and its associated event loop.

ControlInterface(pomp::Loop &loop)

ControlInterface constructor that takes a pomp::Loop reference. The caller is responsible of running the event loop (calling loop.waitAndProcess()). This constructor does not use an internal thread.

Parameters:

loop – pre-existing pomp loop object reference

ControlInterface(pomp::Loop &&loop)

ControlInterface constructor that takes a pomp::Loop by r-value reference. This constructor does not use an internal thread.

Parameters:

loop – pre-existing pomp loop r-value reference

~ControlInterface()

ControlInterface destructor. Stops internal loop and join the internal thread if necessary.

int connect(const Listener<ControlInterface> &listener = Listener<ControlInterface>())

Connect the control interface to the local ‘control’ process.

Parameters:

listener – control interface listener object

Returns:

a non-zero value in case of error

bool is_connected() const

Returns true if this control interface is connected to the local ‘control’ process.

Returns:

true if connected, false otherwise.

inline bool send(const struct arsdk_cmd *cmd, SentCallback<ControlInterface> sent_cb = nullptr, void *userdata = nullptr)

Sends a message to the local ‘control’ process.

Parameters:
  • cmd – the arsdk command buffer to send

  • sent_cb – callback function that will be called once when the message is sent (for non-ack commands), acknowledged (for acknowledged commands) or if the operation has failed.

  • userdata – void* userdata pointer that will be passed to the sent_cb callback.

Returns:

true if the message has been encoded and pushed to the send pending queue, false otherwise.

using airsdk::control::ConnectedCallback = std::function<void(bool, void*)>

Connection callback function type.

Param success:

A boolean set to true if the connection succeeded, false otherwise

Param userdata:

A void* userdata pointer

using airsdk::control::DisconnectedCallback = std::function<void(bool, void*)>

Disconnection callback function type.

Param success:

A boolean set to true if the disconnection succeeded, false otherwise;

Param userdata:

A void* userdata pointer

template<typename T>
using airsdk::control::SentCallback = std::function<void(T*, const struct arsdk_cmd*, bool, void*)>

Sent command callback function type.

Param control_itf:

The control_itf object that initiated this send operation.

Param cmd:

The sent arsdk command

Param success:

A boolean set to true if the sending operation succeeded, false otherwise.

Param userdata:

A void* userdata pointer

template<typename T>
using airsdk::control::ReceivedCallback = std::function<void(T*, const struct arsdk_cmd *cmd, void *userdata)>

Sent command callback function type.

Param control_itf:

The control_itf object that initiated this send operation.

Param cmd:

The received arsdk command

Param userdata:

A void* userdata pointer

template<typename T>
struct Listener

A ControlInterface listener structure.

Public Members

ConnectedCallback connected_cb
DisconnectedCallback disconnected_cb
SentCallback<T> sent_cb
ReceivedCallback<T> received_cb
void *userdata

<airsdk/airsdk.h>

int airsdk_control_itf_new(struct airsdk_control_itf **ret)

Creates a new control interface structure. This function also creates an internal thread and its associated event loop.

Parameters:

ret – the newly created control interface structure

Returns:

a non-zero value in case of error

int airsdk_control_itf_new_with_loop(struct pomp_loop *loop, struct airsdk_control_itf **ret)

Creates a new control interface structure with a pre-existing pomp loop. The caller is responsible of running the event loop (calling pomp_loop_wait_and_process()).

Parameters:
  • loop – pre-existing pomp loop handle

  • ret – the newly created control interface structure

Returns:

a non-zero value in case of error

int airsdk_control_itf_connect(struct airsdk_control_itf *control_itf, struct airsdk_control_itf_listener *listener)

Connect the control interface to the local ‘control’ process.

Parameters:
  • control_itf – the control interface structure

  • listener – control interface listener structure

Returns:

a non-zero value in case of error

bool airsdk_control_itf_is_connected(struct airsdk_control_itf *control_itf)

Returns true if the control interface is connected to the local ‘control’ process.

Parameters:

control_itf – the control interface structure

Returns:

true if connected, false otherwise.

bool airsdk_control_itf_send(struct airsdk_control_itf *control_itf, struct arsdk_cmd *cmd, airsdk_control_sent_cb_t command_sent_cb, void *userdata)

Sends a message to the local ‘control’ process.

Parameters:
  • control_itf – the control interface structure

  • cmd – the arsdk command buffer to send

  • command_sent_cb – callback function that will be called when the status of the sent command message changes and/or when the message is acknowledged.

  • userdata – void* userdata pointer that will be passed to the ‘command_sent_cb’ callback.

Returns:

true if the message has been encoded and pushed to the send pending queue, false otherwise.

typedef void (*airsdk_control_connected_cb_t)(bool, void*)
typedef void (*airsdk_control_disconnected_cb_t)(bool, void*)
typedef void (*airsdk_control_sent_cb_t)(struct airsdk_control_itf*, const struct arsdk_cmd*, bool, void*)
typedef void (*airsdk_control_received_cb_t)(struct airsdk_control_itf*, const struct arsdk_cmd*, void*)
struct airsdk_control_itf_listener

Public Members

airsdk_control_connected_cb_t connected_cb
airsdk_control_disconnected_cb_t disconnected_cb
airsdk_control_sent_cb_t sent_cb
airsdk_control_received_cb_t received_cb
void *userdata