/*
* libiio - Library for interfacing industrial I/O (IIO) devices
*
* Copyright (C) 2014 Analog Devices, Inc.
* Author: Paul Cercueil <paul.cercueil@analog.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* */
/** @file iio.h
* @brief Public interface */
#ifndef __IIO_H__
#define __IIO_H__
#ifdef __cplusplus
extern "C" {
#endif
//#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/types.h>
#include <stddef.h>
#ifdef _MSC_BUILD
/* Come on Microsoft, time to get some C99... */
typedef long ssize_t;
#endif
/* Breaks with MATLAB on Linux
* #ifdef __GNUC__
* #define __cnst __attribute__((const))
* #define __pure __attribute__((pure))
* #define __notused __attribute__((unused))
* #else */
#define __cnst
#define __pure
#define __notused
/* #endif */
#ifdef _WIN32
# ifdef LIBIIO_EXPORTS
# define __api __declspec(dllexport)
# else
# define __api __declspec(dllimport)
# endif
/* Breaks with MATLAB on Linux
* #elif __GNUC__ >= 4
* # define __api __attribute__((visibility ("default"))) */
#else
# define __api
#endif
struct iio_context;
struct iio_device;
struct iio_channel;
struct iio_buffer;
/* ---------------------------------------------------------------------------*/
/* ------------------------- Top-level functions -----------------------------*/
/** @defgroup TopLevel Top-level functions
* @{ */
/** @brief Get the version of the libiio library
* @param major A pointer to an unsigned integer (NULL accepted)
* @param minor A pointer to an unsigned integer (NULL accepted)
* @param git_tag A pointer to a 8-characters buffer (NULL accepted) */
__api void iio_library_get_version(unsigned int *major,
unsigned int *minor, char git_tag[8]);
/** @} *//* ------------------------------------------------------------------*/
/* ------------------------- Context functions -------------------------------*/
/** @defgroup Context Context
* @{
* @struct iio_context
* @brief Contains the representation of an IIO context */
/** @brief Create a context from local or remote IIO devices
* @return On success, A pointer to an iio_context structure
* @return On failure, NULL is returned and errno is set appropriately
*
* <b>NOTE:</b> This function will create a network context if the IIOD_REMOTE
* environment variable is set to the hostname where the IIOD server runs. If
* set to an empty string, the server will be discovered using ZeroConf.
* If the environment variable is not set, a local context will be created
* instead. */
__api struct iio_context * iio_create_default_context(void);
/** @brief Create a context from local IIO devices (Linux only)
* @return On success, A pointer to an iio_context structure
* @return On failure, NULL is returned and errno is set appropriately */
__api struct iio_context * iio_create_local_context(void);
/** @brief Create a context from a XML file
* @param xml_file Path to the XML file to open
* @return On success, A pointer to an iio_context structure
* @return On failure, NULL is returned and errno is set appropriately
*
* <b>NOTE:</b> The format of the XML must comply to the one returned by
* iio_context_get_xml. */
__api struct iio_context * iio_create_xml_context(const char *xml_file);
/** @brief Create a context from XML data in memory
* @param xml Pointer to the XML data in memory
* @param len Length of the XML string in memory (excluding the final \0)
* @return On success, A pointer to an iio_context structure
* @return On failure, NULL is returned and errno is set appropriately
*
* <b>NOTE:</b> The format of the XML must comply to the one returned by
* iio_context_get_xml */
__api struct iio_context * iio_create_xml_context_mem(
const char *xml, size_t len);
/** @brief Create a context from the network
* @param host Hostname, IPv4 or IPv6 address where the IIO Daemon is running
* @return On success, a pointer to an iio_context structure
* @return On failure, NULL is returned and errno is set appropriately */
__api struct iio_context * iio_create_network_context(const char *host);
/** @brief Duplicate a pre-existing IIO context
* @param ctx A pointer to an iio_context structure
* @return On success, A pointer to an iio_context structure
* @return On failure, NULL is returned and errno is set appropriately */
__api struct iio_context * iio_context_clone(const struct iio_context *ctx);
/** @brief Destroy the given context
* @param ctx A pointer to an iio_context structure
*
* <b>NOTE:</b> After that function, the iio_context pointer shall be invalid. */
__api void iio_context_destroy(struct iio_context *ctx);
/** @brief Get the version of the backend in use
* @param ctx A pointer to an iio_context structure
* @param major A pointer to an unsigned integer (NULL accepted)
* @param minor A pointer to an unsigned integer (NULL accepted)
* @param git_tag A pointer to a 8-characters buffer (NULL accepted)
* @return On success, 0 is returned
* @return On error, a negative errno code is returned */
__api int iio_context_get_version(const struct iio_context *ctx,
unsigned int *major, unsigned int *minor, char git_tag[8]);
/** @brief Obtain a XML representation of the given context
* @param ctx A pointer to an iio_context structure
* @return A pointer to a static NULL-terminated string */
__api __pure const char * iio_context_get_xml(const struct iio_context *ctx);
/** @brief Get the name of the given context
* @param ctx A pointer to an iio_context structure
* @return A pointer to a static NULL-terminated string
*
* <b>NOTE:</b>The returned string will be <b><i>local</i></b>,
* <b><i>xml</i></b> or <b><i>network</i></b> when the context has been
* created with the local, xml and network backends respectively.*/
__api __pure const char * iio_context_get_name(const struct iio_context *ctx);
/** @brief Get a description of the given context
* @param ctx A pointer to an iio_context structure
* @return A pointer to a static NULL-terminated string
*
* <b>NOTE:</b>The returned string will contain human-readable information about
* the current context. */
__api __pure const char * iio_context_get_description(
const struct iio_context *ctx);
/** @brief Enumerate the devices found in the given context
* @param ctx A pointer to an iio_context structure
* @return The number of devices found */
__api __pure unsigned int iio_context_get_devices_count(
const struct iio_context *ctx);
/** @brief Get the device present at the given index
* @param ctx A pointer to an iio_context structure
* @param index The index corresponding to the device
* @return On success, a pointer to an iio_device structure
* @return If the index is invalid, NULL is returned */
__api __pure struct iio_device * iio_context_get_device(
const struct iio_context *ctx, unsigned int index);
/** @brief Try to find a device structure by its name of ID
* @param ctx A pointer to an iio_context structure
* @param name A NULL-terminated string corresponding to the name or the ID of
* the device to search for
* @return On success, a pointer to an iio_device structure
* @return If the name or ID does not correspond to any known device, NULL is
* returned */
__api __pure struct iio_device * iio_context_find_device(
const struct iio_context *ctx, const char *name);
/** @brief Set a timeout for I/O operations
* @param ctx A pointer to an iio_context structure
* @param timeout_ms A positive integer representing the time in milliseconds
* after which a timeout occurs
评论0