summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore20
-rw-r--r--.travis.yml124
-rw-r--r--Android.bp60
-rwxr-xr-xCI/travis/after_deploy7
-rwxr-xr-xCI/travis/before_deploy183
-rwxr-xr-xCI/travis/before_install_darwin5
-rwxr-xr-xCI/travis/before_install_linux34
-rwxr-xr-xCI/travis/deploy10
-rw-r--r--CI/travis/deploy.rsa.encbin1680 -> 0 bytes
-rw-r--r--CI/travis/generateDocumentationAndDeploy.sh.in97
-rwxr-xr-xCI/travis/inside_docker.sh26
-rw-r--r--CI/travis/jobs_running_cnt.py42
-rw-r--r--CI/travis/lib.sh304
-rwxr-xr-xCI/travis/make_darwin13
-rwxr-xr-xCI/travis/make_linux42
-rwxr-xr-xCI/travis/make_linux_qemu13
-rwxr-xr-xCI/travis/setup_qemu_for_arm.sh87
-rw-r--r--CI/travis/zip.txt62
-rw-r--r--CMakeLists.txt478
-rw-r--r--COPYING.txt456
-rw-r--r--Distribution.xml.cmakein20
-rw-r--r--Doxyfile.in1853
-rw-r--r--METADATA17
-rw-r--r--MODULE_LICENSE_LGPL0
-rw-r--r--OWNERS2
-rw-r--r--README.md52
-rw-r--r--appveyor.yml151
-rw-r--r--backend.c84
-rw-r--r--bindings/CMakeLists.txt3
-rw-r--r--bindings/csharp/.gitignore3
-rw-r--r--bindings/csharp/AssemblyInfo.cs.in5
-rw-r--r--bindings/csharp/Attr.cs102
-rw-r--r--bindings/csharp/CMakeLists.txt70
-rw-r--r--bindings/csharp/Channel.cs236
-rw-r--r--bindings/csharp/Context.cs231
-rw-r--r--bindings/csharp/Device.cs262
-rw-r--r--bindings/csharp/IOBuffer.cs143
-rw-r--r--bindings/csharp/Trigger.cs67
-rw-r--r--bindings/csharp/examples/ExampleProgram.cs82
-rw-r--r--bindings/csharp/key.snkbin596 -> 0 bytes
-rw-r--r--bindings/csharp/libiio-sharp.dll.config.cmakein3
-rw-r--r--bindings/csharp/libiio-sharp.pc.cmakein10
-rw-r--r--bindings/matlab/CMakeLists.txt26
-rw-r--r--bindings/matlab/iio-wrapper.h46
-rw-r--r--bindings/matlab/iio_installer_script.m17
-rw-r--r--bindings/matlab/iio_sys_obj.m474
-rw-r--r--bindings/matlab/iio_sys_obj_matlab.m350
-rw-r--r--bindings/matlab/libiio_if.m701
-rw-r--r--bindings/matlab/libiio_if_daq2.m701
-rw-r--r--bindings/python/.gitignore3
-rw-r--r--bindings/python/CMakeLists.txt21
-rwxr-xr-xbindings/python/examples/iio_info.py89
-rw-r--r--bindings/python/iio.py864
-rw-r--r--bindings/python/setup.py.cmakein24
-rw-r--r--buffer.c324
-rw-r--r--channel.c844
-rw-r--r--cmake/CheckCaseSensitiveFileSystem.cmake38
-rw-r--r--cmake/DarwinPackaging.cmake12
-rw-r--r--cmake/LinuxPackaging.cmake140
-rw-r--r--context.c437
-rw-r--r--debug.h96
-rw-r--r--device.c1151
-rw-r--r--doc/codemodel.svg319
-rw-r--r--examples/.gitignore3
-rw-r--r--examples/Makefile46
-rw-r--r--examples/ad9361-iiostream.c294
-rw-r--r--examples/ad9371-iiostream.c306
-rw-r--r--examples/dummy-iiostream.c374
-rw-r--r--examples/iio-monitor.c359
-rw-r--r--iio-config.h31
-rw-r--r--iio-config.h.cmakein31
-rw-r--r--iio-lock.h30
-rw-r--r--iio-private.h292
-rw-r--r--iio.h1777
-rw-r--r--iiod-client.c674
-rw-r--r--iiod-client.h71
-rw-r--r--iiod/.gitignore4
-rw-r--r--iiod/CMakeLists.txt81
-rw-r--r--iiod/iiod.c471
-rw-r--r--iiod/init/iiod.conf.cmakein13
-rw-r--r--iiod/init/iiod.init.cmakein60
-rw-r--r--iiod/init/iiod.service.cmakein17
-rw-r--r--iiod/lexer.l170
-rw-r--r--iiod/ops.c1421
-rw-r--r--iiod/ops.h129
-rw-r--r--iiod/parser.y463
-rw-r--r--iiod/queue.h574
-rw-r--r--iiod/thread-pool.c189
-rw-r--r--iiod/thread-pool.h35
-rw-r--r--iiod/usbd.c408
l---------include/iio.h1
-rw-r--r--libiio.iss.cmakein69
-rw-r--r--libiio.pc.cmakein12
-rw-r--r--libiio.rules.cmakein1
-rw-r--r--local.c2076
-rw-r--r--lock.c90
-rw-r--r--mainpage.dox256
-rw-r--r--network.c1627
-rw-r--r--properties.rc.cmakein24
-rw-r--r--scan.c214
-rw-r--r--serial.c535
-rw-r--r--sort.c93
-rw-r--r--sort.h28
-rw-r--r--tests/.gitignore5
-rw-r--r--tests/CMakeLists.txt60
-rw-r--r--tests/iio_adi_xflow_check.c348
-rw-r--r--tests/iio_attr.c754
-rw-r--r--tests/iio_genxml.c145
-rw-r--r--tests/iio_info.c452
-rw-r--r--tests/iio_readdev.c425
-rw-r--r--tests/iio_reg.c111
-rw-r--r--tests/iio_writedev.c453
-rw-r--r--usb.c1192
-rw-r--r--utilities.c214
-rw-r--r--xml.c458
-rw-r--r--xml/ad5541a.xml19
-rw-r--r--xml/ad5628-1.xml71
-rw-r--r--xml/ad7091r.xml16
-rw-r--r--xml/adis16488.xml86
119 files changed, 2 insertions, 30292 deletions
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index e0efbc7..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,20 +0,0 @@
-*.so.*
-*.so
-*.o
-*.plist
-obj-*
-*.deb
-
-libiio.iss
-libiio.pc
-
-CMakeCache.txt
-CMakeFiles
-cmake_install.cmake
-install_manifest.txt
-Makefile
-build/
-
-html/
-Doxyfile
-doxygen_sqlite3.db
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 94cd09e..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,124 +0,0 @@
-language: c
-
-env:
- global:
- # SSHHOST
- - secure: "NEXUEA+ccm/I21ujCPuKYIHFb8Gogunr3nYysCRpTBNT40PsU9VFIy5vbmMxPAkCaMwk8XZ0rMHE3uaNGbBAGfoDL9v0Ban5wG/jA1JkmOAWUpFrUsbQeejXNRA04QcZ/4VeL6TgFegV2T6V0tLB4M6/X316dIPhS9Tat1ZUC8s="
- # SSHUSER
- - secure: "bYHqhcYYuSbciQa5mBqMxs3CbJkrxxD7/G4zDW2war1IcMh8AC/KPeoYIuhd/L2Mg9+tP++xCznKUJzX85Hu+8EyrMGkC/6zWpGYgyO27DH7wl+9AJjR191WJKkg+S6OqZmb/5v0rdJMDnGOZHrRVB3Vec9dBT+jDTQbyxrckxE="
- # DEPLOY_TO directory
- - secure: "PMp93w9HAYd0pR4aw2LT1sMIVmA06f01Xq2jaGW2iy74n3GrqBYe7H9aMR0WD1S6KH9sFydqFI11bCpwUQXPopl+8MPA34AS7V2gaxDUdE+UZnKKXpKV6KRPRp/txlryuEGspjFJM0bo5g1H5lPBSBFj8PB1Bf6BiloGl8TTuiY="
- - BRANCH_PULL=$TRAVIS_PULL_REQUEST_BRANCH
- - PULL=$TRAVIS_PULL_REQUEST
- - BRANCH=$TRAVIS_BRANCH
-
-matrix:
- include:
- - compiler: "gcc"
- os: linux
- env:
- - PLATFORM=linux BITS=64 HOST=x86_64
- # TODO do `check` or `check_hw` here too, not just `check_sw` (as part of `coverage`)
- - CHECK_RULE=coverage GCOV=1
- - PKG_RULE=gzip
- - COVERITY_SCAN_PROJECT_NAME="$TRAVIS_REPO_SLUG"
- - COVERITY_SCAN_BRANCH_PATTERN="master"
- - COVERITY_SCAN_NOTIFICATION_EMAIL="robin.getz@analog.com"
- - COVERITY_SCAN_BUILD_COMMAND_PREPEND="mkdir build && cd build && cmake .."
- - COVERITY_SCAN_BUILD_COMMAND="make"
- # The COVERITY_SCAN_TOKEN
- - secure: "QQt2l9IVo0xXWLx7Xqgz/4Iezj7YroY3MKfmG+OhtzkMRx4prhx32/07JMNAcYx6mQrccyZkBNzpYuXlfIZjFL3xDxDj5+iKv5XXpJbRFQGhc5xZtAlzOIqHNMcFc0Aj8J2mZwKfSaDnBdf+nMgKcmn46pYbpJOmPe9iEfeLvvg="
- - compiler: "clang"
- os: linux
- dist: trusty
- env: LDIST=DO_NOT_DEPLOY
- - compiler: "gcc"
- os: linux
- dist: precise
- env: LDIST=-precise
- - compiler: "gcc"
- os: linux
- dist: trusty
- env: LDIST=-trusty
- - compiler: "gcc"
- os: osx
- osx_image: xcode6.4
- env: LDIST=-osx_10.10
- - compiler: "gcc"
- os: osx
- osx_image: xcode7.3
- env: LDIST=-osx_10.11
- - compiler: "gcc"
- os: osx
- osx_image: xcode8.1
- env:
- - LDIST=-osx_10.12
- - EXTRA_SSH=-oHostKeyAlgorithms=+ssh-dss
-
-addons:
- artifacts: true
- ssh_known_hosts:
- secure: "q0dQ9MrhnOCo031McxSdQIqw4N6tEyAZLq7mdbWkAJcXOh/CX58NjFvcdSfamleDUYRmg7KpCZPPgnbx2JtqVvWJv8aNnr67CE1GIjRP1Fxh2WaKS+VK+I6rro7GwCO2C9d+uffCt63LfZKqddF1T7vMI2IgHcu9irc5LCuw6Wo="
-
-before_install:
- - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./CI/travis/before_install_darwin ; fi
- - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./CI/travis/before_install_linux ; fi
- - if [[ -n "$COVERITY_SCAN_PROJECT_NAME" ]] ; then echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca- ; fi
- - if [ -n "$COVERITY_SCAN_PROJECT_NAME" -a "$TRAVIS_EVENT_TYPE" == "cron" ] ; then curl -s 'https://scan.coverity.com/scripts/travisci_build_coverity_scan.sh' | bash || true ; fi
-
- - mkdir -p $TRAVIS_BUILD_DIR/build
- - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then mkdir -p $TRAVIS_BUILD_DIR/build_tar ; fi
-
-script:
- - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ${TRAVIS_BUILD_DIR}/CI/travis/make_linux; fi
- - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ${TRAVIS_BUILD_DIR}/CI/travis/make_darwin; fi
-
-notifications:
- email:
- on_success: change
- on_failure: always
-
-before_deploy:
- - . ${TRAVIS_BUILD_DIR}/CI/travis/before_deploy
- - openssl aes-256-cbc -K $encrypted_48a720578612_key -iv $encrypted_48a720578612_iv -in ${TRAVIS_BUILD_DIR}/CI/travis/deploy.rsa.enc -out /tmp/deploy.rsa -d
- - eval "$(ssh-agent -s)"
- - chmod 600 /tmp/deploy.rsa
- - ssh-add /tmp/deploy.rsa
-deploy:
- - provider: releases
- api_key:
- secure: Bl7sfWp796+D7cF99+YdmbQjr5stXh4H/4hN2L5FNL0FEHL4XnIscSqySgy2NNmcqWF4Mz5WNXMZ9M8rYSNAiOndcaBYB+xvesAUbIdncwswgTNn2cj6yQbv0yR9qVUdoyczvZMK1vIc6GtKWWkh0AmgR04cAFffU3fr+78JHIw=
- file:
- - "${RELEASE_PKG_FILE_DEB}"
- - "${RELEASE_PKG_FILE_RPM}"
- - "${RELEASE_PKG_FILE_TGZ}"
- skip_cleanup: true
- on:
- repo: analogdevicesinc/libiio
- tags: true
- condition: "($CC = gcc) && ($TRAVIS_OS_NAME = linux)"
- - provider: releases
- api_key:
- secure: Bl7sfWp796+D7cF99+YdmbQjr5stXh4H/4hN2L5FNL0FEHL4XnIscSqySgy2NNmcqWF4Mz5WNXMZ9M8rYSNAiOndcaBYB+xvesAUbIdncwswgTNn2cj6yQbv0yR9qVUdoyczvZMK1vIc6GtKWWkh0AmgR04cAFffU3fr+78JHIw=
- file:
- - "${RELEASE_PKG_FILE_PKG}"
- - "${RELEASE_PKG_FILE_TGZ}"
- skip_cleanup: true
- on:
- repo: analogdevicesinc/libiio
- tags: true
- condition: "$TRAVIS_OS_NAME = osx"
- - provider: script
- skip_cleanup: true
- script:
- - ${TRAVIS_BUILD_DIR}/CI/travis/deploy
- on:
- condition: "($CC = gcc) && ($TRAVIS_OS_NAME = linux)"
- all_branches: true
- - provider: script
- skip_cleanup: true
- script:
- - ${TRAVIS_BUILD_DIR}/CI/travis/deploy
- on:
- condition: "$TRAVIS_OS_NAME = osx"
- all_branches: true
diff --git a/Android.bp b/Android.bp
deleted file mode 100644
index b712610..0000000
--- a/Android.bp
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright 2019 The Android Open Source Project
-
-package {
- default_applicable_licenses: ["external_libiio_license"],
-}
-
-// Added automatically by a large-scale-change that took the approach of
-// 'apply every license found to every target'. While this makes sure we respect
-// every license restriction, it may not be entirely correct.
-//
-// e.g. GPL in an MIT project might only apply to the contrib/ directory.
-//
-// Please consider splitting the single license below into multiple licenses,
-// taking care not to lose any license_kind information, and overriding the
-// default license using the 'licenses: [...]' property on targets as needed.
-//
-// For unused files, consider creating a 'fileGroup' with "//visibility:private"
-// to attach the license to, and including a comment whether the files may be
-// used in the current project.
-// See: http://go/android-license-faq
-license {
- name: "external_libiio_license",
- visibility: [":__subpackages__"],
- license_kinds: [
- "SPDX-license-identifier-BSD",
- "SPDX-license-identifier-LGPL",
- "SPDX-license-identifier-LGPL-2.1",
- "SPDX-license-identifier-LGPL-3.0",
- ],
- license_text: [
- "COPYING.txt",
- ],
-}
-
-cc_library_headers {
- name: "libiio_headers",
- export_include_dirs: ["include"],
-}
-
-cc_library_shared {
- name: "libiio",
- srcs: [
- "backend.c",
- "buffer.c",
- "channel.c",
- "context.c",
- "device.c",
- "local.c",
- "scan.c",
- "sort.c",
- "utilities.c",
- ],
-
- cflags: [
- "-Wall",
- "-Werror",
- "-Wno-sign-compare",
- "-Wno-unused-parameter",
- ],
-}
diff --git a/CI/travis/after_deploy b/CI/travis/after_deploy
deleted file mode 100755
index 66705aa..0000000
--- a/CI/travis/after_deploy
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/sh -e
-
-. CI/travis/lib.sh
-
-should_trigger_next_builds "$TRAVIS_BRANCH" || exit 0
-
-trigger_adi_build "libad9361-iio" "$TRAVIS_BRANCH"
diff --git a/CI/travis/before_deploy b/CI/travis/before_deploy
deleted file mode 100755
index 9d3fd05..0000000
--- a/CI/travis/before_deploy
+++ /dev/null
@@ -1,183 +0,0 @@
-#!/bin/sh -e
-
-. CI/travis/lib.sh
-
-# Don't prepare a deploy on a Coverity build
-if [ "x${COVERITY_SCAN_PROJECT_NAME}" != "x" ] ; then exit 0; fi
-
-deploy=0
-if [ -z "$TRAVIS_BUILD_DIR" ] ; then
- t=$(find ./ -name CMakeCache.txt|head -1)
- if [ -n "${t}" ] ; then
- cd $(dirname $(dirname ${t}))
- TRAVIS_BUILD_DIR=$(pwd)
- else
- echo "I am confused - can't find CMakeCache.txt"
- exit
- fi
-else
- cd $TRAVIS_BUILD_DIR
-fi
-pwd
-
-if [ -z "${LDIST}" -a -f "build/.LDIST" ] ; then
- export LDIST="-$(cat build/.LDIST)"
-fi
-if [ -z "${LDIST}" ] ; then
- export LDIST="-$(get_ldist)"
-fi
-
-check_file()
-{
-temp=""
-for i in $(find ./ -name CMakeCache.txt)
-do
-hit=$(find $(dirname ${i}) -maxdepth 1 -name "libiio*.$1" -a ! -name "*${LDIST}*")
-if [ "$(echo ${hit} | wc -w)" -gt "1" ] ; then
- echo "I am confused - more than 2 $1 files!"
- echo $hit
- exit 1
-else
- if [ "$(echo ${hit} | wc -w)" -eq "1" ] ; then
- if [ -z "${temp}" ] ; then
- temp=$hit
- else
- echo "I am confused - more than 2 $1 files"
- echo $temp
- echo $hit
- exit 1
- fi
- fi
-fi
-done
-}
-
-check_file deb
-if [ -n "${temp}" ] ; then
- deploy=$(expr ${deploy} + 1)
- if [ -z "${TARGET_DEB}" ] ; then
- export TARGET_DEB=$(echo ${temp} | \
- sed -e 's:^./.*/::' -e 's:-Linux::' -e 's:.deb$::')${LDIST}.deb
- fi
- echo "deploying ${temp} to nightly $TARGET_DEB"
- if [ -z "${RELEASE_PKG_FILE_DEB}" ] ; then
- export RELEASE_PKG_FILE_DEB=$(dirname ${temp})/${TARGET_DEB}
- cp ${temp} ${RELEASE_PKG_FILE_DEB}
- fi
- echo ${TARGET_DEB}
- ls -lh ${temp}
- echo ${RELEASE_PKG_FILE_DEB}
- ls -lh ${RELEASE_PKG_FILE_DEB}
-else
- echo "Skipping deployment of debian package"
-fi
-
-check_file rpm
-if [ -n "${temp}" ] ; then
- deploy=$(expr ${deploy} + 1)
- if [ -z "${TARGET_RPM}" ] ; then
- export TARGET_RPM=$(echo ${temp} | \
- sed -e 's:^./.*/::' -e 's:-Linux::' -e 's:.rpm$::')${LDIST}.rpm
- fi
- echo "deploying ${temp} to nightly $TARGET_RPM"
- if [ -z "${RELEASE_PKG_FILE_RPM}" ] ; then
- export RELEASE_PKG_FILE_RPM=$(dirname ${temp})/${TARGET_RPM}
- cp ${temp} ${RELEASE_PKG_FILE_RPM}
- fi
- echo ${TARGET_RPM}
- ls -lh ${temp}
- echo ${RELEASE_PKG_FILE_RPM}
- ls -lh ${RELEASE_PKG_FILE_RPM}
-else
- echo "Skipping deployment of rpm package"
-fi
-
-check_file tar.gz
-if [ -n "${temp}" ] ; then
- deploy=$(expr ${deploy} + 1)
- if [ -z "${TARGET_TGZ}" ] ; then
- echo Add the MATLAB bindings into the tar file
- (
- cd $(dirname ${temp})
- if [ -d tarball_fixup ] ; then
- rm -rf tarball_fixup
- fi
- mkdir tarball_fixup && cd tarball_fixup
-
- if [ "$TRAVIS_OS_NAME" = "osx" ] ; then
- tar --strip-components=1 -xzf ${TRAVIS_BUILD_DIR}/${temp}
- else
- tar -xzf ${TRAVIS_BUILD_DIR}/${temp}
- fi
-
- mkdir -p usr/include usr/lib/matlab/iio
- cp ${TRAVIS_BUILD_DIR}/bindings/matlab/iio-wrapper.h usr/include/
- cp ${TRAVIS_BUILD_DIR}/bindings/matlab/*.m usr/lib/matlab/iio/
-
- if [ "$TRAVIS_OS_NAME" = "osx" ] ; then
- cd usr/lib
- ln -fs ../../Library/Frameworks/iio.framework/iio libiio.dylib
- install_name_tool -change /usr/local/opt/libusb/lib/libusb-1.0.0.dylib @rpath/libusb-1.0.dylib libiio.dylib
- install_name_tool -add_rpath @loader_path/../../../../../usr/lib libiio.dylib
- install_name_tool -add_rpath /usr/local/opt/libusb/lib libiio.dylib
-
- cd ../include
- ln -s ../../Library/Frameworks/iio.framework/Headers/iio.h iio.h
-
- # Update references for tools
- cd ../..
- TOOLS=Library/Frameworks/iio.framework/Tools/*
- for tool in $TOOLS
- do
- install_name_tool -add_rpath @loader_path/../../ $tool
- done
- cp /usr/local/lib/libusb-1.0.dylib usr/lib/
- chmod +w usr/lib/libusb-1.0.dylib
- install_name_tool -id @rpath/libusb-1.0.dylib usr/lib/libusb-1.0.dylib
-
- tar -czf ${TRAVIS_BUILD_DIR}/${temp} usr Library
- else
- tar -czf ${TRAVIS_BUILD_DIR}/${temp} usr lib
- fi
- )
-
- export TARGET_TGZ=$(echo ${temp} | \
- sed -e 's:^./.*/::' -e 's:-Linux::' -e 's:-Darwin::' -e 's:.tar.gz$::')${LDIST}.tar.gz;
- fi
- echo "deploying ${temp} to $TARGET_TGZ"
- if [ -z "${RELEASE_PKG_FILE_TGZ}" ] ; then
- export RELEASE_PKG_FILE_TGZ=$(dirname ${temp})/${TARGET_TGZ}
- cp ${temp} ${RELEASE_PKG_FILE_TGZ}
- fi
- echo ${TARGET_TGZ}
- ls -lh ${temp}
- echo ${RELEASE_PKG_FILE_TGZ}
- ls -lh ${RELEASE_PKG_FILE_TGZ}
-else
- echo "Skipping deployment of tarball"
-fi
-
-check_file pkg
-if [ -n "${temp}" ] ; then
- deploy=$(expr ${deploy} + 1)
- if [ -z "${TARGET_PKG}" ] ; then
- export TARGET_PKG=$(echo ${temp} | \
- sed -e 's:^./.*/::' -e 's:.pkg$::')${LDIST}.pkg
- fi
- echo "deploying ${temp} to nightly $TARGET_PKG"
- if [ -z "${RELEASE_PKG_FILE_PKG}" ] ; then
- export RELEASE_PKG_FILE_PKG=$(dirname ${temp})/${TARGET_PKG}
- cp ${temp} ${RELEASE_PKG_FILE_PKG}
- fi
- echo ${TARGET_PKG}
- ls -lh ${temp}
- echo ${RELEASE_PKG_FILE_PKG}
- ls -lh ${RELEASE_PKG_FILE_PKG}
-else
- echo "Skipping deployment of OS X package"
-fi
-
-if [ "${deploy}" -eq "0" ] ; then
- echo did not deploy any files
- exit 1
-fi
diff --git a/CI/travis/before_install_darwin b/CI/travis/before_install_darwin
deleted file mode 100755
index f8645b3..0000000
--- a/CI/travis/before_install_darwin
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh -e
-
-. CI/travis/lib.sh
-
-brew_install_or_upgrade cmake doxygen libusb libxml2
diff --git a/CI/travis/before_install_linux b/CI/travis/before_install_linux
deleted file mode 100755
index b25a781..0000000
--- a/CI/travis/before_install_linux
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/sh -e
-
-. CI/travis/lib.sh
-
-handle_centos() {
- # FIXME: see about adding `libserialport-dev` from EPEL ; maybe libusb-1.0.0-devel...
- yum -y groupinstall 'Development Tools'
- yum -y install cmake libxml2-devel libusb1-devel doxygen libaio-devel \
- avahi-devel bzip2 gzip rpm rpm-build
-}
-
-handle_centos_docker() {
- prepare_docker_image "centos:centos${OS_VERSION}"
-}
-
-handle_ubuntu_docker() {
- prepare_docker_image "ubuntu:${OS_VERSION}"
-}
-
-handle_default() {
- sudo apt-get -qq update
- sudo apt-get install -y cmake graphviz libaio-dev libavahi-client-dev libavahi-common-dev libusb-1.0-0-dev libxml2-dev rpm tar bzip2 gzip flex bison git
- if [ -n "${GH_DOC_TOKEN}" ] ; then
- sudo apt-get install -y doxygen
- fi
- if [ `sudo apt-cache search libserialport-dev | wc -l` -gt 0 ] ; then
- sudo apt-get install -y libserialport-dev
- fi
-}
-
-OS_TYPE=${1:-default}
-OS_VERSION=${2}
-
-handle_${OS_TYPE}
diff --git a/CI/travis/deploy b/CI/travis/deploy
deleted file mode 100755
index 63a3f60..0000000
--- a/CI/travis/deploy
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh -e
-
-. CI/travis/lib.sh
-
-# libname from to suffix
-upload_file_to_swdownloads libiio ${RELEASE_PKG_FILE_DEB} ${TARGET_DEB} .deb
-upload_file_to_swdownloads libiio ${RELEASE_PKG_FILE_RPM} ${TARGET_RPM} .rpm
-upload_file_to_swdownloads libiio ${RELEASE_PKG_FILE_TGZ} ${TARGET_TGZ} .tar.gz
-upload_file_to_swdownloads libiio ${RELEASE_PKG_FILE_PKG} ${TARGET_PKG} .pkg
-
diff --git a/CI/travis/deploy.rsa.enc b/CI/travis/deploy.rsa.enc
deleted file mode 100644
index 78fe1ff..0000000
--- a/CI/travis/deploy.rsa.enc
+++ /dev/null
Binary files differ
diff --git a/CI/travis/generateDocumentationAndDeploy.sh.in b/CI/travis/generateDocumentationAndDeploy.sh.in
deleted file mode 100644
index 079913a..0000000
--- a/CI/travis/generateDocumentationAndDeploy.sh.in
+++ /dev/null
@@ -1,97 +0,0 @@
-#!/bin/sh
-set -x
-################################################################################
-# Title : generateDocumentationAndDeploy.sh
-# Date created : 16Nov2018
-# Original Author: "Jeroen de Bruijn"
-# based on https://gist.github.com/vidavidorra/548ffbcdae99d752da02
-#
-# Preconditions:
-# - Packages doxygen graphviz must be installed.
-# - An gh-pages branch should already exist. See below for mor info on how to
-# create a gh-pages branch.
-#
-# Required global variables:
-# - GH_DOC_TOKEN : Secure token to the github repository.
-#
-# This script will generate Doxygen documentation and push the documentation to
-# the gh-pages branch of a repository specified by $TRAVIS_REPO_SLUG
-# Before this script is used there should already be a gh-pages branch in the
-# repository.
-#
-# This file is processed by CMAKE to get the version in the commit message
-#
-################################################################################
-
-##### Setup this script and get the current gh-pages branch.
-echo 'Setting up the script...'
-GH_REPO_NAME=$(echo $TRAVIS_REPO_SLUG | awk -F/ '{print $2}')
-
-# Exit with nonzero exit code if anything fails
-set -e
-
-# by the time this script is run, we should have already made the docs
-cd $TRAVIS_BUILD_DIR/build
-#docs should be in the $TRAVIS_BUILD_DIR/build/html directory
-if [ ! -d "html" ] || [ ! -f "./html/index.html" ]; then
- echo '' >&2
- echo 'Warning: No documentation (html) files have been found!' >&2
- echo 'Warning: Not going to push the documentation to GitHub!' >&2
- exit 0
-fi
-
-if [ -z "${TRAVIS_TAG}" ] ; then
- echo 'Warning: Not a tag' >&2
- echo 'Warning: Not going to push the documentation to GitHub!' >&2
- exit 0
-fi
-
-# Get the current gh-pages branch
-git clone -b gh-pages https://git@github.com/$TRAVIS_REPO_SLUG
-cd $GH_REPO_NAME
-
-# Remove everything currently in the gh-pages branch.
-# GitHub is smart enough to know which files have changed and which files have
-# stayed the same and will only update the changed files. So the gh-pages branch
-# can be safely cleaned, and it is sure that everything pushed later is the new
-# documentation.
-rm -rf *
-
-#copy the files over
-cp -a ../html/* ./
-
-##### Configure git.
-# Set the push default to simple i.e. push only the current branch.
-git config --global push.default simple
-# Pretend to be an user called Travis CI.
-git config user.name "Autogenerated by Travis CI"
-git config user.email "robin.getz@analog.com"
-
-# Need to create a .nojekyll file to allow filenames starting with an underscore
-# to be seen on the gh-pages site. Therefore creating an empty .nojekyll file.
-# Presumably this is only needed when the SHORT_NAMES option in Doxygen is set
-# to NO, which it is by default. So creating the file just in case.
-if [ ! -f ".nojekyll" ] ; then
- touch .nojekyll
-fi
-
-################################################################################
-##### Upload the documentation to the gh-pages branch of the repository. #####
-
-echo 'Uploading documentation to the gh-pages branch...'
-# Add everything in this directory (the Doxygen code documentation) to the
-# gh-pages branch.
-#
-# GitHub is smart enough to know which files have changed and which files have
-# stayed the same and will only update the changed files.
-git add --all
-
-# Commit the added files with a title and description containing the Travis CI
-# build number and the GitHub commit reference that issued this build.
-git commit -m "Deploy autogenerated docs for ${GH_REPO_NAME} v@LIBIIO_VERSION_MAJOR@.@LIBIIO_VERSION_MINOR@-g@LIBIIO_VERSION_GIT@" --sign
-
-# Force push to the remote gh-pages branch.
-# The ouput is redirected to /dev/null to hide any sensitive credential data
-# that might otherwise be exposed.
-git push --force "https://${GH_DOC_TOKEN}@github.com/${TRAVIS_REPO_SLUG}" > /dev/null 2>&1
-
diff --git a/CI/travis/inside_docker.sh b/CI/travis/inside_docker.sh
deleted file mode 100755
index 7aa9522..0000000
--- a/CI/travis/inside_docker.sh
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/bin/sh -e
-
-LIBNAME="$1"
-OS_TYPE="$2"
-
-export INSIDE_DOCKER="1"
-export TRAVIS_BUILD_DIR="/$LIBNAME"
-
-cd /$LIBNAME
-
-if [ -d "/$LIBNAME/CI" ] ; then
- CI="/$LIBNAME/CI"
-elif [ -d "/$LIBNAME/ci" ] ; then
- CI="/$LIBNAME/ci"
-else
- echo "No CI/ci directory present"
- exit 1
-fi
-
-$CI/travis/before_install_linux "$OS_TYPE"
-
-$CI/travis/make_linux "$OS_TYPE"
-
-# need to find this out inside the container
-. $CI/travis/lib.sh
-echo "$(get_ldist)" > /${LIBNAME}/build/.LDIST
diff --git a/CI/travis/jobs_running_cnt.py b/CI/travis/jobs_running_cnt.py
deleted file mode 100644
index e5f4121..0000000
--- a/CI/travis/jobs_running_cnt.py
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/usr/bin/python
-
-import os
-import sys
-import urllib2
-import json
-
-# This is pretty constant, but allow it to be overriden via env-var
-url = os.getenv('TRAVIS_API_URL', 'https://api.travis-ci.org')
-
-if (not url.lower().startswith("https://")):
- print (0)
- sys.exit(0)
-
-ci_token = os.getenv('TRAVIS_API_TOKEN')
-build_id = os.getenv('TRAVIS_BUILD_ID')
-
-headers = {
- 'Content-Type': 'application/json',
- 'Accept': 'application/json',
- 'Travis-API-Version': "3",
- 'Authorization': "token {0}".format(ci_token)
-}
-
-# Codacy's bandit linter may complain that we haven't validated
-# this URL for permitted schemes; we have validated this a few lines above
-req = urllib2.Request("{0}/build/{1}/jobs".format(url, build_id),
- headers=headers)
-
-response = urllib2.urlopen(req).read()
-json_r = json.loads(response.decode('utf-8'))
-
-jobs_running = 0
-for job in json_r['jobs']:
- # bump number of jobs higher, so nothing triggers
- if (job['state'] in [ 'canceled', 'failed' ]):
- jobs_running += 99
- break
- if (job['state'] in [ 'started', 'created', 'queued', 'received' ]):
- jobs_running += 1
-
-print (jobs_running)
diff --git a/CI/travis/lib.sh b/CI/travis/lib.sh
deleted file mode 100644
index a071cfc..0000000
--- a/CI/travis/lib.sh
+++ /dev/null
@@ -1,304 +0,0 @@
-#!/bin/sh -e
-
-export TRAVIS_API_URL="https://api.travis-ci.org"
-LOCAL_BUILD_DIR=${LOCAL_BUILD_DIR:-build}
-
-COMMON_SCRIPTS="jobs_running_cnt.py inside_docker.sh"
-
-echo_red() { printf "\033[1;31m$*\033[m\n"; }
-echo_green() { printf "\033[1;32m$*\033[m\n"; }
-echo_blue() { printf "\033[1;34m$*\033[m\n"; }
-
-get_script_path() {
- local script="$1"
-
- [ -n "$script" ] || return 1
-
- if [ -f "CI/travis/$script" ] ; then
- echo "CI/travis/$script"
- elif [ -f "ci/travis/$script" ] ; then
- echo "ci/travis/$script"
- elif [ -f "${LOCAL_BUILD_DIR}/$script" ] ; then
- echo "${LOCAL_BUILD_DIR}/$script"
- else
- return 1
- fi
-}
-
-pipeline_branch() {
- local branch=$1
-
- [ -n "$branch" ] || return 1
-
- # master is a always a pipeline branch
- [ "$branch" = "master" ] && return 0
-
- set +x
- # Check if branch name is 20XX_RY where:
- # XX - 14 to 99 /* wooh, that's a lot of years */
- # Y - 1 to 9 /* wooh, that's a lot of releases per year */
- for year in $(seq 2014 2099) ; do
- for rel_num in $(seq 1 9) ; do
- [ "$branch" = "${year}_R${rel_num}" ] && \
- return 0
- done
- done
-
- return 1
-}
-
-should_trigger_next_builds() {
- local branch="$1"
-
- [ -z "${COVERITY_SCAN_PROJECT_NAME}" ] || return 1
-
- # These Travis-CI vars have to be non-empty
- [ -n "$TRAVIS_PULL_REQUEST" ] || return 1
- [ -n "$branch" ] || return 1
- set +x
- [ -n "$TRAVIS_API_TOKEN" ] || return 1
-
- # Has to be a non-pull-request
- [ "$TRAVIS_PULL_REQUEST" = "false" ] || return 1
-
- pipeline_branch "$branch" || return 1
-
- local python_script="$(get_script_path jobs_running_cnt.py)"
- if [ -z "$python_script" ] ; then
- echo "Could not find 'jobs_running_cnt.py'"
- return 1
- fi
-
- local jobs_cnt=$(python $python_script)
-
- # Trigger next job if we are the last job running
- [ "$jobs_cnt" = "1" ]
-}
-
-trigger_build() {
- local repo_slug="$1"
- local branch="$2"
-
- [ -n "$repo_slug" ] || return 1
- [ -n "$branch" ] || return 1
-
- local body="{
- \"request\": {
- \"branch\":\"$branch\"
- }
- }"
-
- # Turn off tracing here (shortly)
- set +x
- curl -s -X POST \
- -H "Content-Type: application/json" \
- -H "Accept: application/json" \
- -H "Travis-API-Version: 3" \
- -H "Authorization: token $TRAVIS_API_TOKEN" \
- -d "$body" \
- https://api.travis-ci.org/repo/$repo_slug/requests
-}
-
-trigger_adi_build() {
- local adi_repo="$1"
- local branch="$2"
-
- [ -n "$adi_repo" ] || return 1
- trigger_build "analogdevicesinc%2F$adi_repo" "$branch"
-}
-
-command_exists() {
- local cmd=$1
- [ -n "$cmd" ] || return 1
- type "$cmd" >/dev/null 2>&1
-}
-
-get_ldist() {
- case "$(uname)" in
- Linux*)
- if [ ! -f /etc/os-release ] ; then
- if [ -f /etc/centos-release ] ; then
- echo "centos-$(sed -e 's/CentOS release //' -e 's/(.*)$//' \
- -e 's/ //g' /etc/centos-release)-$(uname -m)"
- return 0
- fi
- ls /etc/*elease
- [ -z "${OSTYPE}" ] || {
- echo "${OSTYPE}-unknown"
- return 0
- }
- echo "linux-unknown"
- return 0
- fi
- . /etc/os-release
- if ! command_exists dpkg ; then
- echo $ID-$VERSION_ID-$(uname -m)
- else
- echo $ID-$VERSION_ID-$(dpkg --print-architecture)
- fi
- ;;
- Darwin*)
- echo "darwin-$(sw_vers -productVersion)"
- ;;
- *)
- echo "$(uname)-unknown"
- ;;
- esac
- return 0
-}
-
-__brew_install_or_upgrade() {
- brew install $1 || \
- brew upgrade $1 || \
- brew ls --version $1
-}
-
-brew_install_or_upgrade() {
- while [ -n "$1" ] ; do
- __brew_install_or_upgrade "$1" || return 1
- shift
- done
-}
-
-sftp_cmd_pipe() {
- sftp ${EXTRA_SSH} ${SSHUSER}@${SSHHOST}
-}
-
-sftp_rm_artifact() {
- local artifact="$1"
- sftp_cmd_pipe <<-EOF
- cd ${DEPLOY_TO}
- rm ${artifact}
- EOF
-}
-
-sftp_upload() {
- local FROM="$1"
- local TO="$2"
- local LATE="$3"
-
- sftp_cmd_pipe <<-EOF
- cd ${DEPLOY_TO}
-
- put ${FROM} ${TO}
- ls -l ${TO}
-
- symlink ${TO} ${LATE}
- ls -l ${LATE}
- bye
- EOF
-}
-
-upload_file_to_swdownloads() {
-
- if [ "$#" -ne 4 ] ; then
- echo "skipping deployment of something"
- echo "send called with $@"
- return 0
- fi
-
- local LIBNAME=$1
- local FROM=$2
- local FNAME=$3
- local EXT=$4
-
- if [ -z "$FROM" ] ; then
- echo no file to send
- return 1
- fi
-
- if [ ! -r "$FROM" ] ; then
- echo "file $FROM is not readable"
- return 1
- fi
-
- if [ -n "$TRAVIS_PULL_REQUEST_BRANCH" ] ; then
- local branch="$TRAVIS_PULL_REQUEST_BRANCH"
- else
- local branch="$TRAVIS_BRANCH"
- fi
-
- local TO=${branch}_${FNAME}
- local LATE=${branch}_latest_${LIBNAME}${LDIST}${EXT}
- local GLOB=${DEPLOY_TO}/${branch}_${LIBNAME}-*
-
- echo attemting to deploy $FROM to $TO
- echo and ${branch}_${LIBNAME}${LDIST}${EXT}
- ssh -V
-
- for rmf in ${TO} ${LATE} ; do
- sftp_rm_artifact ${rmf} || \
- echo_blue "Could not delete ${rmf}"
- done
-
- sftp_upload "${FROM}" "${TO}" "${LATE}" || {
- echo_red "Failed to upload artifact from '${FROM}', to '${TO}', symlink '${LATE}'"
- return 1
- }
-
- # limit things to a few files, so things don't grow forever
- if [ "${EXT}" = ".deb" ] ; then
- for files in $(ssh ${EXTRA_SSH} ${SSHUSER}@${SSHHOST} \
- "ls -lt ${GLOB}" | tail -n +100 | awk '{print $NF}')
- do
- ssh ${EXTRA_SSH} ${SSHUSER}@${SSHHOST} \
- "rm ${DEPLOY_TO}/${files}" || \
- return 1
- done
- fi
-
- return 0
-}
-
-prepare_docker_image() {
- local DOCKER_IMAGE="$1"
- sudo apt-get -qq update
- echo 'DOCKER_OPTS="-H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock -s devicemapper"' | sudo tee /etc/default/docker > /dev/null
- sudo service docker restart
- sudo docker pull "$DOCKER_IMAGE"
-}
-
-run_docker_script() {
- local DOCKER_SCRIPT="$(get_script_path $1)"
- local DOCKER_IMAGE="$2"
- local OS_TYPE="$3"
- local MOUNTPOINT="${4:-docker_build_dir}"
- sudo docker run --rm=true \
- -v "$(pwd):/${MOUNTPOINT}:rw" \
- $DOCKER_IMAGE \
- /bin/bash -e "/${MOUNTPOINT}/${DOCKER_SCRIPT}" "${MOUNTPOINT}" "${OS_TYPE}"
-}
-
-ensure_command_exists() {
- local cmd="$1"
- local package="$2"
- [ -n "$cmd" ] || return 1
- [ -n "$package" ] || package="$cmd"
- ! command_exists "$cmd" || return 0
- # go through known package managers
- for pacman in apt-get brew yum ; do
- command_exists $pacman || continue
- $pacman install -y $package || {
- # Try an update if install doesn't work the first time
- $pacman -y update && \
- $pacman install -y $package
- }
- return $?
- done
- return 1
-}
-
-ensure_command_exists sudo
-
-# Other scripts will download lib.sh [this script] and lib.sh will
-# in turn download the other scripts it needs.
-# This gives way more flexibility when changing things, as they propagate
-for script in $COMMON_SCRIPTS ; do
- [ ! -f "CI/travis/$script" ] || continue
- [ ! -f "ci/travis/$script" ] || continue
- [ ! -f "${LOCAL_BUILD_DIR}/$script" ] || continue
- mkdir -p ${LOCAL_BUILD_DIR}
- ensure_command_exists wget
- wget https://raw.githubusercontent.com/analogdevicesinc/libiio/master/CI/travis/$script \
- -O $LOCAL_BUILD_DIR/$script
-done
diff --git a/CI/travis/make_darwin b/CI/travis/make_darwin
deleted file mode 100755
index aff1af9..0000000
--- a/CI/travis/make_darwin
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/sh -e
-
-if [ "x${COVERITY_SCAN_PROJECT_NAME}" != "x" ] ; then exit 0; fi
-
-cd $TRAVIS_BUILD_DIR/build
-cmake -DOSX_PACKAGE=ON ..
-make
-ls
-
-cd $TRAVIS_BUILD_DIR/build_tar
-cmake -DOSX_PACKAGE=OFF -DENABLE_PACKAGING=ON ..
-make && make package
-ls
diff --git a/CI/travis/make_linux b/CI/travis/make_linux
deleted file mode 100755
index 0e1e5c9..0000000
--- a/CI/travis/make_linux
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/bin/sh -e
-
-if [ "x${COVERITY_SCAN_PROJECT_NAME}" != "x" ] ; then exit 0; fi
-
-. CI/travis/lib.sh
-
-handle_default() {
- mkdir -p build
- cd build
- cmake -DENABLE_PACKAGING=ON -DDEB_DETECT_DEPENDENCIES=ON ..
- make && make package
- if [ -n "${GH_DOC_TOKEN}" ] && \
- [ -f "./generateDocumentationAndDeploy.sh" ] ; then
- sh generateDocumentationAndDeploy.sh
- fi
- cd ..
-}
-
-handle_centos() {
- mkdir -p build
- cd build
- cmake -DENABLE_PACKAGING=ON ..
- make && make package
- cd ..
-}
-
-handle_centos_docker() {
- run_docker_script inside_docker.sh \
- "centos:centos${OS_VERSION}" "centos"
-}
-
-handle_ubuntu_docker() {
- run_docker_script inside_docker.sh \
- "ubuntu:${OS_VERSION}"
-}
-
-LIBNAME="$1"
-OS_TYPE=${2:-default}
-OS_VERSION="$3"
-
-handle_${OS_TYPE}
-
diff --git a/CI/travis/make_linux_qemu b/CI/travis/make_linux_qemu
deleted file mode 100755
index b1d101d..0000000
--- a/CI/travis/make_linux_qemu
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/bash
-set -ex
-
-CHROOT_DIR=/tmp/arm-chroot
-
-sudo chroot ${CHROOT_DIR} bash -c "cd ${TRAVIS_BUILD_DIR} && ./CI/travis/make_linux libiio"
-sudo chroot ${CHROOT_DIR} bash -c ". ${TRAVIS_BUILD_DIR}/CI/travis/lib.sh && get_ldist > ${TRAVIS_BUILD_DIR}/build/.LDIST"
-
-#move the artifacts back to the non-qemu place
-sudo rsync -av ${CHROOT_DIR}/${TRAVIS_BUILD_DIR}/ ${TRAVIS_BUILD_DIR}/
-#make sure the normal travis user can read them
-sudo chown -R ${USER} ${TRAVIS_BUILD_DIR}
-
diff --git a/CI/travis/setup_qemu_for_arm.sh b/CI/travis/setup_qemu_for_arm.sh
deleted file mode 100755
index 2904e94..0000000
--- a/CI/travis/setup_qemu_for_arm.sh
+++ /dev/null
@@ -1,87 +0,0 @@
-#!/bin/bash
-# Based on a test script from avsm/ocaml repo https://github.com/avsm/ocaml
-set -ex
-
-if [ $# -ne 1 ] ; then
- echo Must include debian distribution ie wheezy, jessie, stretch, or buster
- exit -1
-fi
-if [[ ! $1 =~ ^wheezy|jessie|stretch|buster$ ]] ; then
- echo Must include debian distribution ie wheezy, jessie, stretch, or buster
- exit -1
-fi
-
-CHROOT_DIR=/tmp/arm-chroot
-MIRROR=http://archive.raspbian.org/raspbian
-# wheezy = 7 (2013-05-04); jessie = 8 (2015-04-26); stretch = 9 (2017-06-17); buster = 10 (2019-03-12)
-VERSION=$1
-echo building for ${VERSION}
-CHROOT_ARCH=armhf
-
-# Host dependencies
-sudo apt-get update
-sudo apt-get install -qq -y qemu-user-static binfmt-support sbuild wget debian-archive-keyring ubuntu-keyring gnupg libudev1 libudev-dev liblzma-dev libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev
-# need a newer version of qemu :(
-QEMU_DIR=/tmp/qemu
-sudo mkdir -p ${QEMU_DIR}
-sudo chown ${USER} /tmp/qemu
-cd ${QEMU_DIR}
-wget https://download.qemu.org/qemu-3.1.0.tar.xz
-tar xf qemu-3.1.0.tar.xz
-cd qemu-3.1.0
-mkdir build
-mkdir install
-cd build
-../configure --prefix=${QEMU_DIR}/install --disable-bsd-user --disable-guest-agent --disable-strip --disable-werror --disable-gcrypt --disable-debug-info --disable-debug-tcg --disable-docs --disable-tcg-interpreter --enable-attr --disable-brlapi --disable-linux-aio --disable-bzip2 --disable-bluez --disable-cap-ng --disable-curl --disable-fdt --disable-glusterfs --disable-gnutls --disable-nettle --disable-gtk --disable-rdma --disable-libiscsi --disable-vnc-jpeg --disable-kvm --disable-lzo --disable-curses --disable-libnfs --disable-numa --disable-opengl --disable-vnc-png --disable-rbd --disable-vnc-sasl --disable-sdl --disable-seccomp --disable-smartcard --disable-snappy --disable-spice --disable-libssh2 --disable-libusb --disable-usb-redir --disable-vde --disable-vhost-net --disable-virglrenderer --disable-virtfs --disable-vnc --disable-vte --disable-xen --disable-xen-pci-passthrough --disable-xfsctl --enable-linux-user --disable-system --disable-blobs --disable-tools --target-list=arm-linux-user --static --disable-pie
-make -j $(nproc)
-make install
-ls -lR ${QEMU_DIR}/install
-cd /tmp
-
-# per https://wiki.ubuntu.com/DebootstrapChroot
-if [[ "$VERSION" =~ ^wheezy|jessie$ ]] ; then
- sudo apt-get install -qq -y debootstrap
-
-elif [[ "$VERSION" =~ ^stretch$ ]] ; then
- sudo add-apt-repository -r "deb http://archive.ubuntu.com/ubuntu $(lsb_release -cs)-updates main restricted universe multiverse "
- sudo apt-get install -qq -y -t $(lsb_release -cs)-updates debootstrap
-elif [[ "$VERSION" =~ ^buster$ ]] ; then
- wget http://http.us.debian.org/debian/pool/main/d/debootstrap/debootstrap_1.0.111_all.deb -O /tmp/debootstrap_1.0.111_all.deb
- sudo dpkg --install /tmp/debootstrap_1.0.111_all.deb
-fi
-
-# Create chrooted environment
-sudo mkdir ${CHROOT_DIR}
-sudo debootstrap --foreign --no-check-gpg --include=fakeroot,build-essential --arch=${CHROOT_ARCH} ${VERSION} ${CHROOT_DIR} ${MIRROR}
-sudo cp ${QEMU_DIR}/install/bin/qemu-arm ${CHROOT_DIR}/usr/bin/qemu-arm-static
-${CHROOT_DIR}/usr/bin/qemu-arm-static -version
-sudo chroot ${CHROOT_DIR} ./debootstrap/debootstrap --second-stage
-sudo sbuild-createchroot --arch=${CHROOT_ARCH} --foreign --setup-only ${VERSION} ${CHROOT_DIR} ${MIRROR}
-
-# Create file with environment variables which will be used inside chrooted
-# environment
-echo "export ARCH=${ARCH}" > envvars.sh
-echo "export TRAVIS_BUILD_DIR=${TRAVIS_BUILD_DIR}" >> envvars.sh
-chmod a+x envvars.sh
-
-# Install dependencies inside chroot
-sudo chroot ${CHROOT_DIR} dpkg --add-architecture ${CHROOT_ARCH}
-sudo chroot ${CHROOT_DIR} dpkg --remove-architecture amd64
-sudo chroot ${CHROOT_DIR} apt-get update
-sudo chroot ${CHROOT_DIR} apt-get --allow-unauthenticated install -qq -y locales
-sudo chroot ${CHROOT_DIR} locale
-sudo chroot ${CHROOT_DIR} bash -c "echo en_US.UTF-8 UTF-8 > /etc/locale.gen"
-sudo chroot ${CHROOT_DIR} locale-gen
-#sudo chroot ${CHROOT_DIR} bash -c "echo -e 'LANG=\"en_US.UTF-8\"\\nLANGUAGE=\"en_US:en\"\\n' > /etc/default/locale"
-sudo chroot ${CHROOT_DIR} apt-get --allow-unauthenticated install -qq -y build-essential git m4 sudo python cmake
-
-# Create build dir and copy travis build files to our chroot environment
-sudo mkdir -p ${CHROOT_DIR}/${TRAVIS_BUILD_DIR}
-sudo rsync -av ${TRAVIS_BUILD_DIR}/ ${CHROOT_DIR}/${TRAVIS_BUILD_DIR}/
-
-# Indicate chroot environment has been set up
-sudo touch ${CHROOT_DIR}/.chroot_is_done
-
-# Call standard before_install_linux in chroot environment
-sudo chroot ${CHROOT_DIR} bash -c "cd ${TRAVIS_BUILD_DIR} && pwd && ./CI/travis/before_install_linux"
-
diff --git a/CI/travis/zip.txt b/CI/travis/zip.txt
deleted file mode 100644
index 0427357..0000000
--- a/CI/travis/zip.txt
+++ /dev/null
@@ -1,62 +0,0 @@
- libiio Windows binary snapshot - README
-
- *********************************************************************
- * The latest version of this snapshot can always be downloaded at: *
- * https://github.com/analogdevicesinc/libiio *
- *********************************************************************
-
-In this archive, you should find the following directories:
-o ./include : Common include files
-o ./MinGW32 : 32-bit binaries compiled by the MinGW toolchain
-o ./MinGW64 : 64-bit binaries compiled by the MinGW toolchain
-o ./MS32 : 32-bit binaries compiled by the MicroSoft toolchain
-o ./MS64 : 364bit binaries compiled by the MicroSoft toolchain
-
-o Visual Studio:
- - Open existing or create a new project for your application
- - Copy iio.h, from the include\ directory, into your project and make sure that
- the location where the file reside appears in the 'Additional Include
- Directories' section (Configuration Properties -> C/C++ -> General).
- - Copy the relevant .lib file from MS32\ or MS64\ and add 'libiio.lib' to
- your 'Additional Dependencies' (Configuration Properties -> Linker -> Input)
- Also make sure that the directory where libiio.lib resides is added to
- 'Additional Library Directories' (Configuration Properties -> Linker
- -> General)
- - If you use the static version of the libiio library, make sure that
- 'Runtime Library' is set to 'Multi-threaded DLL (/MD)' (Configuration
- Properties -> C/C++ -> Code Generation).
- - Compile and run your application. If you use the DLL version of libiio,
- remember that you need to have a copy of the DLL either in the runtime
- directory or in system32
-
-o WDK/DDK:
- - The following is an example of a sources files that you can use to compile
- a libiio 1.0 based console application. In this sample ..\libiio\ is the
- directory where you would have copied libiio.h as well as the relevant
- libiio.lib
-
- TARGETNAME=your_app
- TARGETTYPE=PROGRAM
- USE_MSVCRT=1
- UMTYPE=console
- INCLUDES=..\libiio;$(DDK_INC_PATH)
- TARGETLIBS=..\libiio\libiio.lib
- SOURCES=your_app.c
-
-o MinGW/cygwin
- - Copy libiio.h, from include/ to your default include directory,
- and copy the MinGW32/ or MinGW64/ .a files to your default library directory.
- Or, if you don't want to use the default locations, make sure that you feed
- the relevant -I and -L options to the compiler.
- - Add the '-liio' linker option when compiling.
-
-o Additional information:
- - The libiio API documentation can be accessed at:
- http://analogdevicesinc.github.io/libiio/
- - For some libiio samples (including source), please have a look in examples/
- and tests/ directories
- - The MinGW and MS generated DLLs are fully interchangeable, provided that you
- use the import libs provided or generate one from the .def also provided.
- - If you find any issue, please visit
- http://analogdevicesinc.github.io/libiio/
- and check the Issues section
diff --git a/CMakeLists.txt b/CMakeLists.txt
deleted file mode 100644
index d9b7ea1..0000000
--- a/CMakeLists.txt
+++ /dev/null
@@ -1,478 +0,0 @@
-cmake_minimum_required(VERSION 2.8.7)
-project(libiio C)
-
-set(LIBIIO_VERSION_MAJOR 0)
-set(LIBIIO_VERSION_MINOR 18)
-set(VERSION "${LIBIIO_VERSION_MAJOR}.${LIBIIO_VERSION_MINOR}")
-if (WIN32)
- string(TIMESTAMP BUILD_YEAR "%Y")
-endif()
-
-# Set the default install path to /usr
-if (NOT WIN32 AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
- set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "default install path" FORCE)
-endif()
-
-set(CMAKE_INSTALL_DOCDIR "" CACHE PATH "documentation root (DATAROOTDIR/doc/${PROJECT_NAME}${LIBIIO_VERSION_MAJOR}-doc)")
-include(GNUInstallDirs)
-if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
- set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
- set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
-endif()
-set(CMAKE_INSTALL_DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME}${LIBIIO_VERSION_MAJOR}-doc")
-
-set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
- CACHE PATH "Installation directory for pkgconfig (.pc) files")
-mark_as_advanced(INSTALL_PKGCONFIG_DIR)
-
-if (NOT CMAKE_BUILD_TYPE)
- set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
- "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel."
- FORCE)
- set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS None Debug Release RelWithDebInfo MinSizeRel)
-endif()
-
-set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")
-
-if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
- option(OSX_PACKAGE "Create a OSX package" ON)
- set(CMAKE_MACOSX_RPATH ON)
- set(SKIP_INSTALL_ALL ${OSX_PACKAGE})
-endif()
-
-option(WITH_NETWORK_BACKEND "Enable the network backend" ON)
-option(WITH_TESTS "Build the test programs" ON)
-
-if (WITH_TESTS)
- set(NEED_THREADS 1)
-endif()
-
-if (MSVC)
- # Avoid annoying warnings from Visual Studio
- add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)
-
- set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "")
- set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll.a" ".a" ".lib")
-endif()
-
-if (NOT LOG_LEVEL)
- set(LOG_LEVEL Info CACHE STRING "Log level" FORCE)
- set_property(CACHE LOG_LEVEL PROPERTY STRINGS NoLog Error Warning Info Debug)
-endif()
-
-if (CMAKE_COMPILER_IS_GNUCC)
- if (NOT WIN32)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
- endif()
-
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare")
-
- include(CheckCCompilerFlag)
- check_c_compiler_flag(-Wpedantic HAS_WPEDANTIC)
- if (HAS_WPEDANTIC)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpedantic")
- endif()
-endif()
-
-include(CheckSymbolExists)
-check_symbol_exists(strdup "string.h" HAS_STRDUP)
-check_symbol_exists(strerror_r "string.h" HAS_STRERROR_R)
-check_symbol_exists(newlocale "locale.h" HAS_NEWLOCALE)
-
-IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
- option(WITH_IIOD "Build the IIO Daemon" ON)
- option(WITH_LOCAL_BACKEND "Enable the local backend" ON)
-
- if (WITH_IIOD AND NOT WITH_LOCAL_BACKEND)
- message(SEND_ERROR "IIOD can only be enabled if the local backend is enabled")
- endif()
- if (WITH_IIOD)
- set(NEED_THREADS 1)
- endif()
-
- set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE=1")
- add_definitions(-D_GNU_SOURCE=1)
-endif()
-
-option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON)
-if (ENABLE_IPV6)
- check_symbol_exists(in6addr_any "netinet/in.h" HAVE_IPV6)
-
- if (NOT HAVE_IPV6)
- message(WARNING "IPv6 is not available in your system.")
- endif()
-endif()
-
-set(LIBIIO_CFILES backend.c channel.c device.c context.c buffer.c utilities.c scan.c sort.c)
-set(LIBIIO_HEADERS iio.h)
-
-add_definitions(-D_POSIX_C_SOURCE=200809L -D__XSI_VISIBLE=500 -DLIBIIO_EXPORTS=1)
-
-# Get the GIT hash of the latest commit
-include(FindGit OPTIONAL)
-if (GIT_FOUND)
- execute_process(
- COMMAND ${GIT_EXECUTABLE} rev-parse --show-toplevel
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
- OUTPUT_VARIABLE LIBIIO_GIT_REPO
- OUTPUT_STRIP_TRAILING_WHITESPACE
- ERROR_QUIET
- )
-
- if ("${LIBIIO_GIT_REPO}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
- execute_process(
- COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
- OUTPUT_VARIABLE LIBIIO_VERSION_GIT
- OUTPUT_STRIP_TRAILING_WHITESPACE
- )
- endif()
-endif()
-
-set(LIBIIO_VERSION ${VERSION}.g${LIBIIO_VERSION_GIT})
-file(WRITE ${CMAKE_BINARY_DIR}/.version ${LIBIIO_VERSION})
-
-if (NOT LIBIIO_VERSION_GIT)
- set(LIBIIO_VERSION_GIT v${VERSION})
-endif()
-
-if(WITH_LOCAL_BACKEND)
- add_definitions(-DLOCAL_BACKEND=1)
- set(LIBIIO_CFILES ${LIBIIO_CFILES} local.c)
-
- # Link with librt if present
- find_library(LIBRT_LIBRARIES rt)
- if (LIBRT_LIBRARIES)
- set(LIBS_TO_LINK ${LIBS_TO_LINK} ${LIBRT_LIBRARIES})
- endif()
-
- option(WITH_LOCAL_CONFIG "Read local context attributes from /etc/libiio.ini" OFF)
- if (WITH_LOCAL_CONFIG)
- find_library(LIBINI_LIBRARIES ini)
- find_path(LIBINI_INCLUDE_DIR ini.h)
- if (NOT LIBINI_LIBRARIES OR NOT LIBINI_INCLUDE_DIR)
- message(SEND_ERROR "WITH_LOCAL_CONFIG option requires libini to be installed")
- else()
- include_directories(${LIBINI_INCLUDE_DIR})
- set(LIBS_TO_LINK ${LIBS_TO_LINK} ${LIBINI_LIBRARIES})
- endif()
- endif()
-endif()
-
-find_library(LIBUSB_LIBRARIES usb-1.0)
-find_path(LIBUSB_INCLUDE_DIR libusb-1.0/libusb.h)
-if (LIBUSB_LIBRARIES AND LIBUSB_INCLUDE_DIR)
- message(STATUS "Looking for libusb-1.0 : Found")
- option(WITH_USB_BACKEND "Enable the libusb backend" ON)
-
- if(WITH_USB_BACKEND)
- add_definitions(-DUSB_BACKEND=1)
- set(LIBIIO_CFILES ${LIBIIO_CFILES} usb.c)
- set(LIBS_TO_LINK ${LIBS_TO_LINK} ${LIBUSB_LIBRARIES})
- set(IIOD_CLIENT 1)
- set(NEED_LIBXML2 1)
- set(NEED_THREADS 1)
-
- include_directories(${LIBUSB_INCLUDE_DIR})
-
- set(TEMP ${CMAKE_REQUIRED_LIBRARIES})
- set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}
- ${LIBUSB_LIBRARIES})
- check_symbol_exists(libusb_get_version "libusb-1.0/libusb.h"
- HAS_LIBUSB_GETVERSION)
- set(CMAKE_REQUIRED_LIBRARIES ${TEMP})
- endif()
-else()
- message(STATUS "Looking for libusb-1.0 : Failed; building without usb")
-endif()
-
-find_library(LIBSERIALPORT_LIBRARIES serialport)
-find_path(LIBSERIALPORT_INCLUDE_DIR libserialport.h)
-if (LIBSERIALPORT_LIBRARIES AND LIBSERIALPORT_INCLUDE_DIR)
- option(WITH_SERIAL_BACKEND "Enable the serial backend" ON)
-
- if (WITH_SERIAL_BACKEND)
- file(STRINGS ${LIBSERIALPORT_INCLUDE_DIR}/libserialport.h LIBSERIALPORT_VERSION_STR REGEX "SP_PACKAGE_VERSION_STRING")
- string(REGEX REPLACE "#define SP_PACKAGE_VERSION_STRING \"(.*)\"" "\\1" LIBSERIALPORT_VERSION ${LIBSERIALPORT_VERSION_STR})
- if ("${LIBSERIALPORT_VERSION}" VERSION_LESS 0.1.1)
- message(WARNING "The installed version of libserialport is too old. The minimum version supported is 0.1.1. Disabling Serial support.")
- SET(WITH_SERIAL_BACKEND OFF)
- else()
- add_definitions(-DSERIAL_BACKEND=1)
- set(LIBIIO_CFILES ${LIBIIO_CFILES} serial.c)
- set(LIBS_TO_LINK ${LIBS_TO_LINK} ${LIBSERIALPORT_LIBRARIES})
-
- set(NEED_THREADS 1)
- set(IIOD_CLIENT 1)
- set(NEED_LIBXML2 1)
-
- include_directories(${LIBSERIALPORT_INCLUDE_DIR})
- endif()
- endif()
-endif()
-
-include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
-
-if(WITH_NETWORK_BACKEND)
- if (WIN32)
- set(LIBS_TO_LINK ${LIBS_TO_LINK} wsock32 ws2_32)
- endif()
-
- if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
- include(CheckCSourceCompiles)
- check_c_source_compiles("#include <fcntl.h>\nint main(void) { return O_TMPFILE; }" HAS_O_TMPFILE)
-
- if (HAS_O_TMPFILE)
- option(WITH_NETWORK_GET_BUFFER "Enable experimental zero-copy transfers" OFF)
- endif(HAS_O_TMPFILE)
-
- check_c_source_compiles("#include <sys/eventfd.h>\nint main(void) { return eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); }" WITH_NETWORK_EVENTFD)
- endif()
-
- if(NOT WIN32)
- include(CheckCSourceCompiles)
- check_c_source_compiles("#include <unistd.h>\n#include <fcntl.h>\nint main(void) { int fd[2]; return pipe2(fd, O_CLOEXEC | O_NONBLOCK); }" HAS_PIPE2)
- endif()
-
- add_definitions(-DNETWORK_BACKEND=1)
- set(LIBIIO_CFILES ${LIBIIO_CFILES} network.c)
-
- find_library(AVAHI_CLIENT_LIBRARIES avahi-client)
- find_library(AVAHI_COMMON_LIBRARIES avahi-common)
- if(AVAHI_CLIENT_LIBRARIES AND AVAHI_COMMON_LIBRARIES)
- set(HAVE_AVAHI ON)
- set(AVAHI_LIBRARIES ${AVAHI_CLIENT_LIBRARIES} ${AVAHI_COMMON_LIBRARIES})
- set(LIBS_TO_LINK ${LIBS_TO_LINK} ${AVAHI_LIBRARIES})
- endif()
-
- set(NEED_THREADS 1)
- set(IIOD_CLIENT 1)
- set(NEED_LIBXML2 1)
-endif()
-
-# Since libxml2-2.9.2, libxml2 provides its own LibXml2-config.cmake, with all
-# variables correctly set.
-# So, try first to find the CMake module provided by libxml2 package, then fallback
-# on the CMake's FindLibXml2.cmake module (which can lack some definition, especially
-# in static build case).
-find_package(LibXml2 QUIET NO_MODULE)
-if(DEFINED LIBXML2_VERSION_STRING)
- set(LIBXML2_FOUND ON)
- set(LIBXML2_INCLUDE_DIR ${LIBXML2_INCLUDE_DIRS})
-else()
- include(FindLibXml2)
-endif()
-
-if (LIBXML2_FOUND)
- option(WITH_XML_BACKEND "Enable the XML backend" ON)
-
- if (WITH_XML_BACKEND)
- set(LIBIIO_CFILES ${LIBIIO_CFILES} xml.c)
- add_definitions(${LIBXML2_DEFINITIONS} -DXML_BACKEND=1)
- include_directories(${LIBXML2_INCLUDE_DIR})
- set(LIBS_TO_LINK ${LIBS_TO_LINK} ${LIBXML2_LIBRARIES})
- endif()
-endif()
-
-if (NEED_LIBXML2 AND NOT (LIBXML2_FOUND AND WITH_XML_BACKEND))
- message(SEND_ERROR "The selected backends require libxml2 and the XML backend to be enabled")
-endif()
-
-if (NEED_THREADS)
- if (NOT WIN32)
- find_library(PTHREAD_LIBRARIES pthread)
-
- if (PTHREAD_LIBRARIES)
- set(LIBS_TO_LINK ${LIBS_TO_LINK} ${PTHREAD_LIBRARIES})
- else()
- message(WARNING "pthread library not found; support for threads will be disabled")
- set(NO_THREADS ON)
- endif()
- else()
- endif()
-
- set(LIBIIO_CFILES ${LIBIIO_CFILES} lock.c)
-endif()
-
-if (IIOD_CLIENT)
- set(LIBIIO_CFILES ${LIBIIO_CFILES} iiod-client.c)
-endif()
-
-configure_file(libiio.iss.cmakein ${CMAKE_CURRENT_BINARY_DIR}/libiio.iss @ONLY)
-
-set(LIBIIO_PC ${CMAKE_CURRENT_BINARY_DIR}/libiio.pc)
-configure_file(libiio.pc.cmakein ${LIBIIO_PC} @ONLY)
-
-if(NOT SKIP_INSTALL_ALL)
- install(FILES ${LIBIIO_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}")
-endif()
-
-#set(SETUP_PY ${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/setup.py)
-#configure_file(python/setup.py.in ${SETUP_PY} @ONLY)
-
-add_subdirectory(bindings)
-
-if (WITH_MATLAB_BINDINGS_API)
- set(LIBIIO_EXTRA_HEADERS ${LIBIIO_EXTRA_HEADERS} bindings/matlab/iio-wrapper.h)
- add_definitions(-DMATLAB_BINDINGS_API=1)
-endif()
-
-if(WITH_TESTS)
- add_subdirectory(tests)
-endif()
-
-if (WIN32)
- set(LIBIIO_ORIGINAL_FILENAME libiio.dll)
- set(LIBIIO_RC ${CMAKE_CURRENT_BINARY_DIR}/properties.rc)
- configure_file(properties.rc.cmakein ${LIBIIO_RC} @ONLY)
-endif()
-
-add_library(iio ${LIBIIO_CFILES} ${LIBIIO_HEADERS} ${LIBIIO_EXTRA_HEADERS} ${LIBIIO_RC})
-set_target_properties(iio PROPERTIES
- VERSION ${VERSION}
- SOVERSION ${LIBIIO_VERSION_MAJOR}
- FRAMEWORK TRUE
- PUBLIC_HEADER ${LIBIIO_HEADERS}
- C_STANDARD 99
- C_STANDARD_REQUIRED ON
- C_EXTENSIONS OFF
-)
-target_link_libraries(iio LINK_PRIVATE ${LIBS_TO_LINK})
-
-if (MSVC)
- set_target_properties(iio PROPERTIES OUTPUT_NAME libiio)
-endif()
-
-if(NOT SKIP_INSTALL_ALL)
- install(TARGETS iio
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
- FRAMEWORK DESTINATION /Library/Frameworks
- PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
-endif()
-
-find_package(Doxygen)
-if(DOXYGEN_FOUND)
- option(WITH_DOC "Generate documentation with Doxygen" ON)
-
- # It is not an error when 'dot' is not found, just switching off the Doxygen's HAVE_DOT option
- find_package_handle_standard_args (Dot REQUIRED_VARS DOXYGEN_DOT_EXECUTABLE)
-
- include(cmake/CheckCaseSensitiveFileSystem.cmake)
- if (HAVE_CASE_SENSITIVE_FILESYSTEM)
- set(CMAKE_CASE_SENSITIVE_FILESYSTEM "YES")
- else()
- set(CMAKE_CASE_SENSITIVE_FILESYSTEM "NO")
- endif()
-
- if (WITH_DOC)
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CI/travis/generateDocumentationAndDeploy.sh.in
- ${CMAKE_CURRENT_BINARY_DIR}/generateDocumentationAndDeploy.sh @ONLY)
- set(HTML_DEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/html)
- file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/doc DESTINATION ${HTML_DEST_DIR})
-
- add_custom_command(TARGET iio POST_BUILD
- COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
- COMMENT "Generating API documentation with Doxygen" VERBATIM
- )
-
- if(NOT SKIP_INSTALL_ALL)
- install(DIRECTORY ${HTML_DEST_DIR} DESTINATION ${CMAKE_INSTALL_DOCDIR})
- endif()
- endif()
-else()
- message(STATUS "Doxygen not found, API documentation won't be generated")
-endif()
-
-# Create an installer if compiling for OSX
-if(OSX_PACKAGE)
- set(LIBIIO_PKG ${CMAKE_CURRENT_BINARY_DIR}/libiio-${VERSION}.g${LIBIIO_VERSION_GIT}.pkg)
- set(LIBIIO_TEMP_PKG ${CMAKE_CURRENT_BINARY_DIR}/libiio-${VERSION}-temp.pkg)
- set(LIBIIO_DISTRIBUTION_XML ${CMAKE_CURRENT_BINARY_DIR}/Distribution.xml)
- set(LIBIIO_FRAMEWORK_DIR ${CMAKE_CURRENT_BINARY_DIR}/iio.framework)
- configure_file(Distribution.xml.cmakein ${LIBIIO_DISTRIBUTION_XML} @ONLY)
-
- find_program(PKGBUILD_EXECUTABLE
- NAMES pkgbuild
- DOC "OSX Package builder (pkgbuild)")
- mark_as_advanced(PKGBUILD_EXECUTABLE)
-
- find_program(PRODUCTBUILD_EXECUTABLE
- NAMES productbuild
- DOC "OSX Package builder (productbuild)")
- mark_as_advanced(PRODUCTBUILD_EXECUTABLE)
-
- foreach(_tool ${IIO_TESTS_TARGETS})
- list(APPEND IIO_TESTS $<TARGET_FILE:${_tool}>)
- endforeach()
-
- add_custom_command(OUTPUT ${LIBIIO_PKG}
- COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBIIO_FRAMEWORK_DIR}/Tools
- COMMAND ${CMAKE_COMMAND} -E copy ${IIO_TESTS} ${LIBIIO_FRAMEWORK_DIR}/Tools
- COMMAND ${PKGBUILD_EXECUTABLE}
- --component ${LIBIIO_FRAMEWORK_DIR}
- --identifier com.adi.iio --version ${VERSION}
- --install-location /Library/Frameworks ${LIBIIO_TEMP_PKG}
- COMMAND ${PRODUCTBUILD_EXECUTABLE}
- --distribution ${LIBIIO_DISTRIBUTION_XML} ${LIBIIO_PKG}
- COMMAND ${CMAKE_COMMAND} -E remove ${LIBIIO_TEMP_PKG}
- DEPENDS iio ${IIO_TESTS_TARGETS} ${LIBIIO_DISTRIBUTION_XML}
- )
-
- if (PKGBUILD_EXECUTABLE AND PRODUCTBUILD_EXECUTABLE)
- add_custom_target(libiio-pkg ALL DEPENDS ${LIBIIO_PKG})
-
- install(CODE "execute_process(COMMAND /usr/sbin/installer -pkg ${LIBIIO_PKG} -target /)")
- else()
- message(WARNING "Missing pkgbuild or productbuild: OSX installer won't be created.")
- endif()
-endif()
-
-if(WITH_IIOD)
- option(WITH_SYSTEMD "Enable installation of systemd service file for iiod" OFF)
- set(SYSTEMD_UNIT_INSTALL_DIR /lib/systemd/system CACHE PATH "default install path for systemd unit files")
-
- option(WITH_SYSVINIT "Enable installation of SysVinit script for iiod" OFF)
- set(SYSVINIT_INSTALL_DIR /etc/init.d CACHE PATH "default install path for SysVinit scripts")
-
- option(WITH_UPSTART "Enable installation of upstart config file for iiod" OFF)
- set(UPSTART_CONF_INSTALL_DIR /etc/init CACHE PATH "default install path for upstart conf files")
-
- if (NOT PTHREAD_LIBRARIES)
- message(WARNING "IIOD requires threads support; disabling")
- set(WITH_IIOD OFF CACHE BOOL "" FORCE)
- else()
- add_subdirectory(iiod)
- endif()
-endif()
-
-if (NOT OSX_PACKAGE)
- # Support creating some basic binpkgs via `make package`.
- # Disabled if OSX_PACKAGE is enabled, as tarballs would end up empty otherwise.
- option(ENABLE_PACKAGING "Create .deb/.rpm or .tar.gz packages via 'make package'" OFF)
-
- if(ENABLE_PACKAGING)
- if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
- include(cmake/DarwinPackaging.cmake)
- endif()
- if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
- include(cmake/LinuxPackaging.cmake)
- endif()
- endif()
-endif()
-
-if (WITH_USB_BACKEND AND CMAKE_SYSTEM_NAME MATCHES "^Linux")
- option(INSTALL_UDEV_RULE "Install a udev rule for detection of USB devices" ON)
-
- if (INSTALL_UDEV_RULE)
- set(UDEV_RULES_INSTALL_DIR /lib/udev/rules.d CACHE PATH "default install path for udev rules")
-
- configure_file(libiio.rules.cmakein ${CMAKE_CURRENT_BINARY_DIR}/90-libiio.rules @ONLY)
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/90-libiio.rules DESTINATION ${UDEV_RULES_INSTALL_DIR})
- endif()
-endif()
-
-configure_file(iio-config.h.cmakein ${CMAKE_CURRENT_BINARY_DIR}/iio-config.h @ONLY)
diff --git a/COPYING.txt b/COPYING.txt
deleted file mode 100644
index ca4f73b..0000000
--- a/COPYING.txt
+++ /dev/null
@@ -1,456 +0,0 @@
- GNU LESSER GENERAL PUBLIC LICENSE
- Version 2.1, February 1999
-
- Copyright (C) 1991, 1999 Free Software Foundation, Inc.
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-[This is the first released version of the Lesser GPL. It also counts
- as the successor of the GNU Library Public License, version 2, hence
- the version number 2.1.]
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-Licenses are intended to guarantee your freedom to share and change
-free software--to make sure the software is free for all its users.
-
- This license, the Lesser General Public License, applies to some
-specially designated software packages--typically libraries--of the
-Free Software Foundation and other authors who decide to use it. You
-can use it too, but we suggest you first think carefully about whether
-this license or the ordinary General Public License is the better
-strategy to use in any particular case, based on the explanations below.
-
- When we speak of free software, we are referring to freedom of use,
-not price. Our General Public Licenses are designed to make sure that
-you have the freedom to distribute copies of free software (and charge
-for this service if you wish); that you receive source code or can get
-it if you want it; that you can change the software and use pieces of
-it in new free programs; and that you are informed that you can do
-these things.
-
- To protect your rights, we need to make restrictions that forbid
-distributors to deny you these rights or to ask you to surrender these
-rights. These restrictions translate to certain responsibilities for
-you if you distribute copies of the library or if you modify it.
-
- For example, if you distribute copies of the library, whether gratis
-or for a fee, you must give the recipients all the rights that we gave
-you. You must make sure that they, too, receive or can get the source
-code. If you link other code with the library, you must provide
-complete object files to the recipients, so that they can relink them
-with the library after making changes to the library and recompiling
-it. And you must show them these terms so they know their rights.
-
- We protect your rights with a two-step method: (1) we copyright the
-library, and (2) we offer you this license, which gives you legal
-permission to copy, distribute and/or modify the library.
-
- To protect each distributor, we want to make it very clear that
-there is no warranty for the free library. Also, if the library is
-modified by someone else and passed on, the recipients should know
-that what they have is not the original version, so that the original
-author's reputation will not be affected by problems that might be
-introduced by others.
-
- Finally, software patents pose a constant threat to the existence of
-any free program. We wish to make sure that a company cannot
-effectively restrict the users of a free program by obtaining a
-restrictive license from a patent holder. Therefore, we insist that
-any patent license obtained for a version of the library must be
-consistent with the full freedom of use specified in this license.
-
- Most GNU software, including some libraries, is covered by the
-ordinary GNU General Public License. This license, the GNU Lesser
-General Public License, applies to certain designated libraries, and
-is quite different from the ordinary General Public License. We use
-this license for certain libraries in order to permit linking those
-libraries into non-free programs.
-
- When a program is linked with a library, whether statically or using
-a shared library, the combination of the two is legally speaking a
-combined work, a derivative of the original library. The ordinary
-General Public License therefore permits such linking only if the
-entire combination fits its criteria of freedom. The Lesser General
-Public License permits more lax criteria for linking other code with
-the library.
-
- We call this license the "Lesser" General Public License because it
-does Less to protect the user's freedom than the ordinary General
-Public License. It also provides other free software developers Less
-of an advantage over competing non-free programs. These disadvantages
-are the reason we use the ordinary General Public License for many
-libraries. However, the Lesser license provides advantages in certain
-special circumstances.
-
- For example, on rare occasions, there may be a special need to
-encourage the widest possible use of a certain library, so that it becomes
-a de-facto standard. To achieve this, non-free programs must be
-allowed to use the library. A more frequent case is that a free
-library does the same job as widely used non-free libraries. In this
-case, there is little to gain by limiting the free library to free
-software only, so we use the Lesser General Public License.
-
- In other cases, permission to use a particular library in non-free
-programs enables a greater number of people to use a large body of
-free software. For example, permission to use the GNU C Library in
-non-free programs enables many more people to use the whole GNU
-operating system, as well as its variant, the GNU/Linux operating
-system.
-
- Although the Lesser General Public License is Less protective of the
-users' freedom, it does ensure that the user of a program that is
-linked with the Library has the freedom and the wherewithal to run
-that program using a modified version of the Library.
-
- The precise terms and conditions for copying, distribution and
-modification follow. Pay close attention to the difference between a
-"work based on the library" and a "work that uses the library". The
-former contains code derived from the library, whereas the latter must
-be combined with the library in order to run.
-
- GNU LESSER GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License Agreement applies to any software library or other
-program which contains a notice placed by the copyright holder or
-other authorized party saying it may be distributed under the terms of
-this Lesser General Public License (also called "this License").
-Each licensee is addressed as "you".
-
- A "library" means a collection of software functions and/or data
-prepared so as to be conveniently linked with application programs
-(which use some of those functions and data) to form executables.
-
- The "Library", below, refers to any such software library or work
-which has been distributed under these terms. A "work based on the
-Library" means either the Library or any derivative work under
-copyright law: that is to say, a work containing the Library or a
-portion of it, either verbatim or with modifications and/or translated
-straightforwardly into another language. (Hereinafter, translation is
-included without limitation in the term "modification".)
-
- "Source code" for a work means the preferred form of the work for
-making modifications to it. For a library, complete source code means
-all the source code for all modules it contains, plus any associated
-interface definition files, plus the scripts used to control compilation
-and installation of the library.
-
- Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running a program using the Library is not restricted, and output from
-such a program is covered only if its contents constitute a work based
-on the Library (independent of the use of the Library in a tool for
-writing it). Whether that is true depends on what the Library does
-and what the program that uses the Library does.
-
- 1. You may copy and distribute verbatim copies of the Library's
-complete source code as you receive it, in any medium, provided that
-you conspicuously and appropriately publish on each copy an
-appropriate copyright notice and disclaimer of warranty; keep intact
-all the notices that refer to this License and to the absence of any
-warranty; and distribute a copy of this License along with the
-Library.
-
- You may charge a fee for the physical act of transferring a copy,
-and you may at your option offer warranty protection in exchange for a
-fee.
-
- 2. You may modify your copy or copies of the Library or any portion
-of it, thus forming a work based on the Library, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) The modified work must itself be a software library.
-
- b) You must cause the files modified to carry prominent notices
- stating that you changed the files and the date of any change.
-
- c) You must cause the whole of the work to be licensed at no
- charge to all third parties under the terms of this License.
-
- d) If a facility in the modified Library refers to a function or a
- table of data to be supplied by an application program that uses
- the facility, other than as an argument passed when the facility
- is invoked, then you must make a good faith effort to ensure that,
- in the event an application does not supply such function or
- table, the facility still operates, and performs whatever part of
- its purpose remains meaningful.
-
- (For example, a function in a library to compute square roots has
- a purpose that is entirely well-defined independent of the
- application. Therefore, Subsection 2d requires that any
- application-supplied function or table used by this function must
- be optional: if the application does not supply it, the square
- root function must still compute square roots.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Library,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Library, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote
-it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Library.
-
-In addition, mere aggregation of another work not based on the Library
-with the Library (or with a work based on the Library) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may opt to apply the terms of the ordinary GNU General Public
-License instead of this License to a given copy of the Library. To do
-this, you must alter all the notices that refer to this License, so
-that they refer to the ordinary GNU General Public License, version 2,
-instead of to this License. (If a newer version than version 2 of the
-ordinary GNU General Public License has appeared, then you can specify
-that version instead if you wish.) Do not make any other change in
-these notices.
-
- Once this change is made in a given copy, it is irreversible for
-that copy, so the ordinary GNU General Public License applies to all
-subsequent copies and derivative works made from that copy.
-
- This option is useful when you wish to copy part of the code of
-the Library into a program that is not a library.
-
- 4. You may copy and distribute the Library (or a portion or
-derivative of it, under Section 2) in object code or executable form
-under the terms of Sections 1 and 2 above provided that you accompany
-it with the complete corresponding machine-readable source code, which
-must be distributed under the terms of Sections 1 and 2 above on a
-medium customarily used for software interchange.
-
- If distribution of object code is made by offering access to copy
-from a designated place, then offering equivalent access to copy the
-source code from the same place satisfies the requirement to
-distribute the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 5. A program that contains no derivative of any portion of the
-Library, but is designed to work with the Library by being compiled or
-linked with it, is called a "work that uses the Library". Such a
-work, in isolation, is not a derivative work of the Library, and
-therefore falls outside the scope of this License.
-
- However, linking a "work that uses the Library" with the Library
-creates an executable that is a derivative of the Library (because it
-contains portions of the Library), rather than a "work that uses the
-library". The executable is therefore covered by this License.
-Section 6 states terms for distribution of such executables.
-
- When a "work that uses the Library" uses material from a header file
-that is part of the Library, the object code for the work may be a
-derivative work of the Library even though the source code is not.
-Whether this is true is especially significant if the work can be
-linked without the Library, or if the work is itself a library. The
-threshold for this to be true is not precisely defined by law.
-
- If such an object file uses only numerical parameters, data
-structure layouts and accessors, and small macros and small inline
-functions (ten lines or less in length), then the use of the object
-file is unrestricted, regardless of whether it is legally a derivative
-work. (Executables containing this object code plus portions of the
-Library will still fall under Section 6.)
-
- Otherwise, if the work is a derivative of the Library, you may
-distribute the object code for the work under the terms of Section 6.
-Any executables containing that work also fall under Section 6,
-whether or not they are linked directly with the Library itself.
-
- 6. As an exception to the Sections above, you may also combine or
-link a "work that uses the Library" with the Library to produce a
-work containing portions of the Library, and distribute that work
-under terms of your choice, provided that the terms permit
-modification of the work for the customer's own use and reverse
-engineering for debugging such modifications.
-
- You must give prominent notice with each copy of the work that the
-Library is used in it and that the Library and its use are covered by
-this License. You must supply a copy of this License. If the work
-during execution displays copyright notices, you must include the
-copyright notice for the Library among them, as well as a reference
-directing the user to the copy of this License. Also, you must do one
-of these things:
-
- a) Accompany the work with the complete corresponding
- machine-readable source code for the Library including whatever
- changes were used in the work (which must be distributed under
- Sections 1 and 2 above); and, if the work is an executable linked
- with the Library, with the complete machine-readable "work that
- uses the Library", as object code and/or source code, so that the
- user can modify the Library and then relink to produce a modified
- executable containing the modified Library. (It is understood
- that the user who changes the contents of definitions files in the
- Library will not necessarily be able to recompile the application
- to use the modified definitions.)
-
- b) Use a suitable shared library mechanism for linking with the
- Library. A suitable mechanism is one that (1) uses at run time a
- copy of the library already present on the user's computer system,
- rather than copying library functions into the executable, and (2)
- will operate properly with a modified version of the library, if
- the user installs one, as long as the modified version is
- interface-compatible with the version that the work was made with.
-
- c) Accompany the work with a written offer, valid for at
- least three years, to give the same user the materials
- specified in Subsection 6a, above, for a charge no more
- than the cost of performing this distribution.
-
- d) If distribution of the work is made by offering access to copy
- from a designated place, offer equivalent access to copy the above
- specified materials from the same place.
-
- e) Verify that the user has already received a copy of these
- materials or that you have already sent this user a copy.
-
- For an executable, the required form of the "work that uses the
-Library" must include any data and utility programs needed for
-reproducing the executable from it. However, as a special exception,
-the materials to be distributed need not include anything that is
-normally distributed (in either source or binary form) with the major
-components (compiler, kernel, and so on) of the operating system on
-which the executable runs, unless that component itself accompanies
-the executable.
-
- It may happen that this requirement contradicts the license
-restrictions of other proprietary libraries that do not normally
-accompany the operating system. Such a contradiction means you cannot
-use both them and the Library together in an executable that you
-distribute.
-
- 7. You may place library facilities that are a work based on the
-Library side-by-side in a single library together with other library
-facilities not covered by this License, and distribute such a combined
-library, provided that the separate distribution of the work based on
-the Library and of the other library facilities is otherwise
-permitted, and provided that you do these two things:
-
- a) Accompany the combined library with a copy of the same work
- based on the Library, uncombined with any other library
- facilities. This must be distributed under the terms of the
- Sections above.
-
- b) Give prominent notice with the combined library of the fact
- that part of it is a work based on the Library, and explaining
- where to find the accompanying uncombined form of the same work.
-
- 8. You may not copy, modify, sublicense, link with, or distribute
-the Library except as expressly provided under this License. Any
-attempt otherwise to copy, modify, sublicense, link with, or
-distribute the Library is void, and will automatically terminate your
-rights under this License. However, parties who have received copies,
-or rights, from you under this License will not have their licenses
-terminated so long as such parties remain in full compliance.
-
- 9. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Library or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Library (or any work based on the
-Library), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Library or works based on it.
-
- 10. Each time you redistribute the Library (or any work based on the
-Library), the recipient automatically receives a license from the
-original licensor to copy, distribute, link with or modify the Library
-subject to these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties with
-this License.
-
- 11. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Library at all. For example, if a patent
-license would not permit royalty-free redistribution of the Library by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Library.
-
-If any portion of this section is held invalid or unenforceable under any
-particular circumstance, the balance of the section is intended to apply,
-and the section as a whole is intended to apply in other circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 12. If the distribution and/or use of the Library is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Library under this License may add
-an explicit geographical distribution limitation excluding those countries,
-so that distribution is permitted only in or among countries not thus
-excluded. In such case, this License incorporates the limitation as if
-written in the body of this License.
-
- 13. The Free Software Foundation may publish revised and/or new
-versions of the Lesser General Public License from time to time.
-Such new versions will be similar in spirit to the present version,
-but may differ in detail to address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Library
-specifies a version number of this License which applies to it and
-"any later version", you have the option of following the terms and
-conditions either of that version or of any later version published by
-the Free Software Foundation. If the Library does not specify a
-license version number, you may choose any version ever published by
-the Free Software Foundation.
-
- 14. If you wish to incorporate parts of the Library into other free
-programs whose distribution conditions are incompatible with these,
-write to the author to ask for permission. For software which is
-copyrighted by the Free Software Foundation, write to the Free
-Software Foundation; we sometimes make exceptions for this. Our
-decision will be guided by the two goals of preserving the free status
-of all derivatives of our free software and of promoting the sharing
-and reuse of software generally.
-
- NO WARRANTY
-
- 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
-WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
-EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
-OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
-KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
-LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
-THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
- 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
-WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
-AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
-FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
-CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
-LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
-RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
-FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
-SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
-DAMAGES.
diff --git a/Distribution.xml.cmakein b/Distribution.xml.cmakein
deleted file mode 100644
index 2bec89b..0000000
--- a/Distribution.xml.cmakein
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
-<installer-gui-script minSpecVersion="2" >
- <title>Libiio</title>
- <options customize="never" rootVolumeOnly="true" />
- <allowed-os-versions>
- <os-version min="10.6.6" />
- </allowed-os-versions>
- <license file="@CMAKE_CURRENT_SOURCE_DIR@/COPYING.txt" mime-type="text/plain" />
- <product id="libiio" version="@VERSION@" />
- <choices-outline>
- <line choice="default" >
- <line choice="libiio" />
- </line>
- </choices-outline>
- <choice id="default" />
- <choice id="libiio" visible="false" >
- <pkg-ref id="libiio" />
- </choice>
- <pkg-ref id="libiio" version="@VERSION@" onConclusion="none" >@LIBIIO_TEMP_PKG@</pkg-ref>
-</installer-gui-script>
diff --git a/Doxyfile.in b/Doxyfile.in
deleted file mode 100644
index 2dc2d92..0000000
--- a/Doxyfile.in
+++ /dev/null
@@ -1,1853 +0,0 @@
-DOXYFILE_ENCODING = UTF-8
-PROJECT_NAME = "libiio"
-PROJECT_NUMBER = @LIBIIO_VERSION_MAJOR@.@LIBIIO_VERSION_MINOR@
-
-# Using the PROJECT_BRIEF tag one can provide an optional one line description
-# for a project that appears at the top of each page and should give viewer a
-# quick idea about the purpose of the project. Keep the description short.
-
-PROJECT_BRIEF = "Library for interfacing with IIO devices"
-
-# With the PROJECT_LOGO tag one can specify an logo or icon that is included in
-# the documentation. The maximum height of the logo should not exceed 55 pixels
-# and the maximum width should not exceed 200 pixels. Doxygen will copy the logo
-# to the output directory.
-
-PROJECT_LOGO =
-
-# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
-# into which the generated documentation will be written. If a relative path is
-# entered, it will be relative to the location where doxygen was started. If
-# left blank the current directory will be used.
-
-OUTPUT_DIRECTORY = .
-CREATE_SUBDIRS = NO
-OUTPUT_LANGUAGE = English
-
-# If the BRIEF_MEMBER_DESC tag is set to YES doxygen will include brief member
-# descriptions after the members that are listed in the file and class
-# documentation (similar to Javadoc). Set to NO to disable this.
-# The default value is: YES.
-
-BRIEF_MEMBER_DESC = YES
-
-# If the REPEAT_BRIEF tag is set to YES doxygen will prepend the brief
-# description of a member or function before the detailed description
-#
-# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
-# brief descriptions will be completely suppressed.
-# The default value is: YES.
-
-REPEAT_BRIEF = YES
-
-# This tag implements a quasi-intelligent brief description abbreviator that is
-# used to form the text in various listings. Each string in this list, if found
-# as the leading text of the brief description, will be stripped from the text
-# and the result, after processing the whole list, is used as the annotated
-# text. Otherwise, the brief description is used as-is. If left blank, the
-# following values are used ($name is automatically replaced with the name of
-# the entity):The $name class, The $name widget, The $name file, is, provides,
-# specifies, contains, represents, a, an and the.
-
-ABBREVIATE_BRIEF =
-
-# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
-# doxygen will generate a detailed section even if there is only a brief
-# description.
-# The default value is: NO.
-
-ALWAYS_DETAILED_SEC = NO
-
-# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
-# inherited members of a class in the documentation of that class as if those
-# members were ordinary class members. Constructors, destructors and assignment
-# operators of the base classes will not be shown.
-# The default value is: NO.
-
-INLINE_INHERITED_MEMB = NO
-
-# If the FULL_PATH_NAMES tag is set to YES doxygen will prepend the full path
-# before files name in the file list and in the header files. If set to NO the
-# shortest path that makes the file name unique will be used
-# The default value is: YES.
-
-FULL_PATH_NAMES = YES
-
-# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path.
-# Stripping is only done if one of the specified strings matches the left-hand
-# part of the path. The tag can be used to show relative paths in the file list.
-# If left blank the directory from which doxygen is run is used as the path to
-# strip.
-#
-# Note that you can specify absolute paths here, but also relative paths, which
-# will be relative from the directory where doxygen is started.
-# This tag requires that the tag FULL_PATH_NAMES is set to YES.
-
-STRIP_FROM_PATH =
-
-# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the
-# path mentioned in the documentation of a class, which tells the reader which
-# header file to include in order to use a class. If left blank only the name of
-# the header file containing the class definition is used. Otherwise one should
-# specify the list of include paths that are normally passed to the compiler
-# using the -I flag.
-
-STRIP_FROM_INC_PATH =
-
-# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but
-# less readable) file names. This can be useful is your file systems doesn't
-# support long names like on DOS, Mac, or CD-ROM.
-# The default value is: NO.
-
-SHORT_NAMES = NO
-
-# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the
-# first line (until the first dot) of a Javadoc-style comment as the brief
-# description. If set to NO, the Javadoc-style will behave just like regular Qt-
-# style comments (thus requiring an explicit @brief command for a brief
-# description.)
-# The default value is: NO.
-
-JAVADOC_AUTOBRIEF = NO
-
-# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first
-# line (until the first dot) of a Qt-style comment as the brief description. If
-# set to NO, the Qt-style will behave just like regular Qt-style comments (thus
-# requiring an explicit \brief command for a brief description.)
-# The default value is: NO.
-
-QT_AUTOBRIEF = NO
-
-# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a
-# multi-line C++ special comment block (i.e. a block of //! or /// comments) as
-# a brief description. This used to be the default behavior. The new default is
-# to treat a multi-line C++ comment block as a detailed description. Set this
-# tag to YES if you prefer the old behavior instead.
-#
-# Note that setting this tag to YES also means that rational rose comments are
-# not recognized any more.
-# The default value is: NO.
-
-MULTILINE_CPP_IS_BRIEF = NO
-
-# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the
-# documentation from any documented member that it re-implements.
-# The default value is: YES.
-
-INHERIT_DOCS = YES
-
-# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce a
-# new page for each member. If set to NO, the documentation of a member will be
-# part of the file/class/namespace that contains it.
-# The default value is: NO.
-
-SEPARATE_MEMBER_PAGES = NO
-
-# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen
-# uses this value to replace tabs by spaces in code fragments.
-# Minimum value: 1, maximum value: 16, default value: 4.
-
-TAB_SIZE = 4
-
-# This tag can be used to specify a number of aliases that act as commands in
-# the documentation. An alias has the form:
-# name=value
-# For example adding
-# "sideeffect=@par Side Effects:\n"
-# will allow you to put the command \sideeffect (or @sideeffect) in the
-# documentation, which will result in a user-defined paragraph with heading
-# "Side Effects:". You can put \n's in the value part of an alias to insert
-# newlines.
-
-ALIASES =
-
-# This tag can be used to specify a number of word-keyword mappings (TCL only).
-# A mapping has the form "name=value". For example adding "class=itcl::class"
-# will allow you to use the command class in the itcl::class meaning.
-
-TCL_SUBST =
-
-# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources
-# only. Doxygen will then generate output that is more tailored for C. For
-# instance, some of the names that are used will be different. The list of all
-# members will be omitted, etc.
-# The default value is: NO.
-
-OPTIMIZE_OUTPUT_FOR_C = YES
-
-# Doxygen selects the parser to use depending on the extension of the files it
-# parses. With this tag you can assign which parser to use for a given
-# extension. Doxygen has a built-in mapping, but you can override or extend it
-# using this tag. The format is ext=language, where ext is a file extension, and
-# language is one of the parsers supported by doxygen: IDL, Java, Javascript,
-# C#, C, C++, D, PHP, Objective-C, Python, Fortran, VHDL. For instance to make
-# doxygen treat .inc files as Fortran files (default is PHP), and .f files as C
-# (default is Fortran), use: inc=Fortran f=C.
-#
-# Note For files without extension you can use no_extension as a placeholder.
-#
-# Note that for custom extensions you also need to set FILE_PATTERNS otherwise
-# the files are not read by doxygen.
-
-EXTENSION_MAPPING =
-
-# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments
-# according to the Markdown format, which allows for more readable
-# documentation. See http://daringfireball.net/projects/markdown/ for details.
-# The output of markdown processing is further processed by doxygen, so you can
-# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in
-# case of backward compatibilities issues.
-# The default value is: YES.
-
-MARKDOWN_SUPPORT = YES
-
-# When enabled doxygen tries to link words that correspond to documented
-# classes, or namespaces to their corresponding documentation. Such a link can
-# be prevented in individual cases by by putting a % sign in front of the word
-# or globally by setting AUTOLINK_SUPPORT to NO.
-# The default value is: YES.
-
-AUTOLINK_SUPPORT = YES
-
-# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
-# tag is set to YES, then doxygen will reuse the documentation of the first
-# member in the group (if any) for the other members of the group. By default
-# all members of a group must be documented explicitly.
-# The default value is: NO.
-
-DISTRIBUTE_GROUP_DOC = NO
-
-# Set the SUBGROUPING tag to YES to allow class member groups of the same type
-# (for instance a group of public functions) to be put as a subgroup of that
-# type (e.g. under the Public Functions section). Set it to NO to prevent
-# subgrouping. Alternatively, this can be done per class using the
-# \nosubgrouping command.
-# The default value is: YES.
-
-SUBGROUPING = YES
-
-# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions
-# are shown inside the group in which they are included (e.g. using \ingroup)
-# instead of on a separate page (for HTML and Man pages) or section (for LaTeX
-# and RTF).
-#
-# Note that this feature does not work in combination with
-# SEPARATE_MEMBER_PAGES.
-# The default value is: NO.
-
-INLINE_GROUPED_CLASSES = NO
-
-# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions
-# with only public data fields or simple typedef fields will be shown inline in
-# the documentation of the scope in which they are defined (i.e. file,
-# namespace, or group documentation), provided this scope is documented. If set
-# to NO, structs, classes, and unions are shown on a separate page (for HTML and
-# Man pages) or section (for LaTeX and RTF).
-# The default value is: NO.
-
-INLINE_SIMPLE_STRUCTS = NO
-
-# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or
-# enum is documented as struct, union, or enum with the name of the typedef. So
-# typedef struct TypeS {} TypeT, will appear in the documentation as a struct
-# with name TypeT. When disabled the typedef will appear as a member of a file,
-# namespace, or class. And the struct will be named TypeS. This can typically be
-# useful for C code in case the coding convention dictates that all compound
-# types are typedef'ed and only the typedef is referenced, never the tag name.
-# The default value is: NO.
-
-TYPEDEF_HIDES_STRUCT = NO
-
-# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This
-# cache is used to resolve symbols given their name and scope. Since this can be
-# an expensive process and often the same symbol appears multiple times in the
-# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small
-# doxygen will become slower. If the cache is too large, memory is wasted. The
-# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range
-# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536
-# symbols. At the end of a run doxygen will report the cache usage and suggest
-# the optimal cache size from a speed point of view.
-# Minimum value: 0, maximum value: 9, default value: 0.
-
-LOOKUP_CACHE_SIZE = 0
-
-#---------------------------------------------------------------------------
-# Build related configuration options
-#---------------------------------------------------------------------------
-
-# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
-# documentation are documented, even if no documentation was available. Private
-# class members and static file members will be hidden unless the
-# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES.
-# Note: This will also disable the warnings about undocumented members that are
-# normally produced when WARNINGS is set to YES.
-# The default value is: NO.
-
-EXTRACT_ALL = NO
-
-# If the EXTRACT_PRIVATE tag is set to YES all private members of a class will
-# be included in the documentation.
-# The default value is: NO.
-
-EXTRACT_PRIVATE = NO
-
-# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal
-# scope will be included in the documentation.
-# The default value is: NO.
-
-EXTRACT_PACKAGE = NO
-
-# If the EXTRACT_STATIC tag is set to YES all static members of a file will be
-# included in the documentation.
-# The default value is: NO.
-
-EXTRACT_STATIC = NO
-
-# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) defined
-# locally in source files will be included in the documentation. If set to NO
-# only classes defined in header files are included. Does not have any effect
-# for Java sources.
-# The default value is: YES.
-
-EXTRACT_LOCAL_CLASSES = NO
-
-# This flag is only useful for Objective-C code. When set to YES local methods,
-# which are defined in the implementation section but not in the interface are
-# included in the documentation. If set to NO only methods in the interface are
-# included.
-# The default value is: NO.
-
-EXTRACT_LOCAL_METHODS = NO
-
-# If this flag is set to YES, the members of anonymous namespaces will be
-# extracted and appear in the documentation as a namespace called
-# 'anonymous_namespace{file}', where file will be replaced with the base name of
-# the file that contains the anonymous namespace. By default anonymous namespace
-# are hidden.
-# The default value is: NO.
-
-EXTRACT_ANON_NSPACES = NO
-
-# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all
-# undocumented members inside documented classes or files. If set to NO these
-# members will be included in the various overviews, but no documentation
-# section is generated. This option has no effect if EXTRACT_ALL is enabled.
-# The default value is: NO.
-
-HIDE_UNDOC_MEMBERS = NO
-
-# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all
-# undocumented classes that are normally visible in the class hierarchy. If set
-# to NO these classes will be included in the various overviews. This option has
-# no effect if EXTRACT_ALL is enabled.
-# The default value is: NO.
-
-HIDE_UNDOC_CLASSES = YES
-
-# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend
-# (class|struct|union) declarations. If set to NO these declarations will be
-# included in the documentation.
-# The default value is: NO.
-
-HIDE_FRIEND_COMPOUNDS = NO
-
-# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any
-# documentation blocks found inside the body of a function. If set to NO these
-# blocks will be appended to the function's detailed documentation block.
-# The default value is: NO.
-
-HIDE_IN_BODY_DOCS = NO
-
-# The INTERNAL_DOCS tag determines if documentation that is typed after a
-# \internal command is included. If the tag is set to NO then the documentation
-# will be excluded. Set it to YES to include the internal documentation.
-# The default value is: NO.
-
-INTERNAL_DOCS = NO
-
-# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file
-# names in lower-case letters. If set to YES upper-case letters are also
-# allowed. This is useful if you have classes or files whose names only differ
-# in case and if your file system supports case sensitive file names. Windows
-# and Mac users are advised to set this option to NO.
-# The default value is: system dependent.
-
-CASE_SENSE_NAMES = @CMAKE_CASE_SENSITIVE_FILESYSTEM@
-
-# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with
-# their full class and namespace scopes in the documentation. If set to YES the
-# scope will be hidden.
-# The default value is: NO.
-
-HIDE_SCOPE_NAMES = NO
-
-# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of
-# the files that are included by a file in the documentation of that file.
-# The default value is: YES.
-
-SHOW_INCLUDE_FILES = YES
-
-# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each
-# grouped member an include statement to the documentation, telling the reader
-# which file to include in order to use the member.
-# The default value is: NO.
-
-SHOW_GROUPED_MEMB_INC = NO
-
-# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include
-# files with double quotes in the documentation rather than with sharp brackets.
-# The default value is: NO.
-
-FORCE_LOCAL_INCLUDES = NO
-
-# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the
-# documentation for inline members.
-# The default value is: YES.
-
-INLINE_INFO = YES
-
-# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the
-# (detailed) documentation of file and class members alphabetically by member
-# name. If set to NO the members will appear in declaration order.
-# The default value is: YES.
-
-SORT_MEMBER_DOCS = YES
-
-# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief
-# descriptions of file, namespace and class members alphabetically by member
-# name. If set to NO the members will appear in declaration order. Note that
-# this will also influence the order of the classes in the class list.
-# The default value is: NO.
-
-SORT_BRIEF_DOCS = NO
-
-# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the
-# (brief and detailed) documentation of class members so that constructors and
-# destructors are listed first. If set to NO the constructors will appear in the
-# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS.
-# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief
-# member documentation.
-# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting
-# detailed member documentation.
-# The default value is: NO.
-
-SORT_MEMBERS_CTORS_1ST = NO
-
-# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy
-# of group names into alphabetical order. If set to NO the group names will
-# appear in their defined order.
-# The default value is: NO.
-
-SORT_GROUP_NAMES = NO
-
-# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by
-# fully-qualified names, including namespaces. If set to NO, the class list will
-# be sorted only by class name, not including the namespace part.
-# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
-# Note: This option applies only to the class list, not to the alphabetical
-# list.
-# The default value is: NO.
-
-SORT_BY_SCOPE_NAME = NO
-
-# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper
-# type resolution of all parameters of a function it will reject a match between
-# the prototype and the implementation of a member function even if there is
-# only one candidate or it is obvious which candidate to choose by doing a
-# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still
-# accept a match between prototype and implementation in such cases.
-# The default value is: NO.
-
-STRICT_PROTO_MATCHING = NO
-
-# The GENERATE_TODOLIST tag can be used to enable ( YES) or disable ( NO) the
-# todo list. This list is created by putting \todo commands in the
-# documentation.
-# The default value is: YES.
-
-GENERATE_TODOLIST = YES
-
-# The GENERATE_TESTLIST tag can be used to enable ( YES) or disable ( NO) the
-# test list. This list is created by putting \test commands in the
-# documentation.
-# The default value is: YES.
-
-GENERATE_TESTLIST = YES
-
-# The GENERATE_BUGLIST tag can be used to enable ( YES) or disable ( NO) the bug
-# list. This list is created by putting \bug commands in the documentation.
-# The default value is: YES.
-
-GENERATE_BUGLIST = YES
-
-# The GENERATE_DEPRECATEDLIST tag can be used to enable ( YES) or disable ( NO)
-# the deprecated list. This list is created by putting \deprecated commands in
-# the documentation.
-# The default value is: YES.
-
-GENERATE_DEPRECATEDLIST= YES
-
-# The ENABLED_SECTIONS tag can be used to enable conditional documentation
-# sections, marked by \if <section_label> ... \endif and \cond <section_label>
-# ... \endcond blocks.
-
-ENABLED_SECTIONS =
-
-# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the
-# initial value of a variable or macro / define can have for it to appear in the
-# documentation. If the initializer consists of more lines than specified here
-# it will be hidden. Use a value of 0 to hide initializers completely. The
-# appearance of the value of individual variables and macros / defines can be
-# controlled using \showinitializer or \hideinitializer command in the
-# documentation regardless of this setting.
-# Minimum value: 0, maximum value: 10000, default value: 30.
-
-MAX_INITIALIZER_LINES = 30
-
-# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at
-# the bottom of the documentation of classes and structs. If set to YES the list
-# will mention the files that were used to generate the documentation.
-# The default value is: YES.
-
-SHOW_USED_FILES = YES
-
-# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This
-# will remove the Files entry from the Quick Index and from the Folder Tree View
-# (if specified).
-# The default value is: YES.
-
-SHOW_FILES = YES
-
-# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces
-# page. This will remove the Namespaces entry from the Quick Index and from the
-# Folder Tree View (if specified).
-# The default value is: YES.
-
-SHOW_NAMESPACES = YES
-
-# The FILE_VERSION_FILTER tag can be used to specify a program or script that
-# doxygen should invoke to get the current version for each file (typically from
-# the version control system). Doxygen will invoke the program by executing (via
-# popen()) the command command input-file, where command is the value of the
-# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided
-# by doxygen. Whatever the program writes to standard output is used as the file
-# version. For an example see the documentation.
-
-FILE_VERSION_FILTER =
-
-# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed
-# by doxygen. The layout file controls the global structure of the generated
-# output files in an output format independent way. To create the layout file
-# that represents doxygen's defaults, run doxygen with the -l option. You can
-# optionally specify a file name after the option, if omitted DoxygenLayout.xml
-# will be used as the name of the layout file.
-#
-# Note that if you run doxygen from a directory containing a file called
-# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE
-# tag is left empty.
-
-LAYOUT_FILE =
-
-# The CITE_BIB_FILES tag can be used to specify one or more bib files containing
-# the reference definitions. This must be a list of .bib files. The .bib
-# extension is automatically appended if omitted. This requires the bibtex tool
-# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info.
-# For LaTeX the style of the bibliography can be controlled using
-# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the
-# search path. Do not use file names with spaces, bibtex cannot handle them. See
-# also \cite for info how to create references.
-
-CITE_BIB_FILES =
-
-#---------------------------------------------------------------------------
-# Configuration options related to warning and progress messages
-#---------------------------------------------------------------------------
-
-# The QUIET tag can be used to turn on/off the messages that are generated to
-# standard output by doxygen. If QUIET is set to YES this implies that the
-# messages are off.
-# The default value is: NO.
-
-QUIET = YES
-
-# The WARNINGS tag can be used to turn on/off the warning messages that are
-# generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES
-# this implies that the warnings are on.
-#
-# Tip: Turn warnings on while writing the documentation.
-# The default value is: YES.
-
-WARNINGS = YES
-
-# If the WARN_IF_UNDOCUMENTED tag is set to YES, then doxygen will generate
-# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag
-# will automatically be disabled.
-# The default value is: YES.
-
-WARN_IF_UNDOCUMENTED = YES
-
-# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for
-# potential errors in the documentation, such as not documenting some parameters
-# in a documented function, or documenting parameters that don't exist or using
-# markup commands wrongly.
-# The default value is: YES.
-
-WARN_IF_DOC_ERROR = YES
-
-# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that
-# are documented, but have no documentation for their parameters or return
-# value. If set to NO doxygen will only warn about wrong or incomplete parameter
-# documentation, but not about the absence of documentation.
-# The default value is: NO.
-
-WARN_NO_PARAMDOC = NO
-
-# The WARN_FORMAT tag determines the format of the warning messages that doxygen
-# can produce. The string should contain the $file, $line, and $text tags, which
-# will be replaced by the file and line number from which the warning originated
-# and the warning text. Optionally the format may contain $version, which will
-# be replaced by the version of the file (if it could be obtained via
-# FILE_VERSION_FILTER)
-# The default value is: $file:$line: $text.
-
-WARN_FORMAT = "$file:$line: $text"
-
-# The WARN_LOGFILE tag can be used to specify a file to which warning and error
-# messages should be written. If left blank the output is written to standard
-# error (stderr).
-
-WARN_LOGFILE =
-
-#---------------------------------------------------------------------------
-# Configuration options related to the input files
-#---------------------------------------------------------------------------
-
-# The INPUT tag is used to specify the files and/or directories that contain
-# documented source files. You may enter file names like myfile.cpp or
-# directories like /usr/src/myproject. Separate the files or directories with
-# spaces.
-# Note: If this tag is empty the current directory is searched.
-
-INPUT = @CMAKE_SOURCE_DIR@
-
-# This tag can be used to specify the character encoding of the source files
-# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
-# libiconv (or the iconv built into libc) for the transcoding. See the libiconv
-# documentation (see: http://www.gnu.org/software/libiconv) for the list of
-# possible encodings.
-# The default value is: UTF-8.
-
-INPUT_ENCODING = UTF-8
-
-# If the value of the INPUT tag contains directories, you can use the
-# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and
-# *.h) to filter out the source-files in the directories. If left blank the
-# following patterns are tested:*.c, *.cc, *.cxx, *.cpp, *.c++, *.java, *.ii,
-# *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp,
-# *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown,
-# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf,
-# *.qsf, *.as and *.js.
-
-FILE_PATTERNS = *.c *.h *.dox
-
-# The RECURSIVE tag can be used to specify whether or not subdirectories should
-# be searched for input files as well.
-# The default value is: NO.
-
-RECURSIVE = NO
-
-# The EXCLUDE tag can be used to specify files and/or directories that should be
-# excluded from the INPUT source files. This way you can easily exclude a
-# subdirectory from a directory tree whose root is specified with the INPUT tag.
-#
-# Note that relative paths are relative to the directory from which doxygen is
-# run.
-
-EXCLUDE = @CMAKE_SOURCE_DIR@/iio-private.h @CMAKE_SOURCE_DIR@/debug.h
-
-# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
-# directories that are symbolic links (a Unix file system feature) are excluded
-# from the input.
-# The default value is: NO.
-
-EXCLUDE_SYMLINKS = NO
-
-# If the value of the INPUT tag contains directories, you can use the
-# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
-# certain files from those directories.
-#
-# Note that the wildcards are matched against the file with absolute path, so to
-# exclude all test directories for example use the pattern */test/*
-
-EXCLUDE_PATTERNS =
-
-# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
-# (namespaces, classes, functions, etc.) that should be excluded from the
-# output. The symbol name can be a fully qualified name, a word, or if the
-# wildcard * is used, a substring. Examples: ANamespace, AClass,
-# AClass::ANamespace, ANamespace::*Test
-#
-# Note that the wildcards are matched against the file with absolute path, so to
-# exclude all test directories use the pattern */test/*
-
-EXCLUDE_SYMBOLS =
-
-# The EXAMPLE_PATH tag can be used to specify one or more files or directories
-# that contain example code fragments that are included (see the \include
-# command).
-
-EXAMPLE_PATH =
-
-# If the value of the EXAMPLE_PATH tag contains directories, you can use the
-# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and
-# *.h) to filter out the source-files in the directories. If left blank all
-# files are included.
-
-EXAMPLE_PATTERNS =
-
-# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
-# searched for input files to be used with the \include or \dontinclude commands
-# irrespective of the value of the RECURSIVE tag.
-# The default value is: NO.
-
-EXAMPLE_RECURSIVE = NO
-
-# The IMAGE_PATH tag can be used to specify one or more files or directories
-# that contain images that are to be included in the documentation (see the
-# \image command).
-
-IMAGE_PATH = @CMAKE_SOURCE_DIR@/doc
-
-# The INPUT_FILTER tag can be used to specify a program that doxygen should
-# invoke to filter for each input file. Doxygen will invoke the filter program
-# by executing (via popen()) the command:
-#
-# <filter> <input-file>
-#
-# where <filter> is the value of the INPUT_FILTER tag, and <input-file> is the
-# name of an input file. Doxygen will then use the output that the filter
-# program writes to standard output. If FILTER_PATTERNS is specified, this tag
-# will be ignored.
-#
-# Note that the filter must not add or remove lines; it is applied before the
-# code is scanned, but not when the output code is generated. If lines are added
-# or removed, the anchors will not be placed correctly.
-
-INPUT_FILTER =
-
-# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
-# basis. Doxygen will compare the file name with each pattern and apply the
-# filter if there is a match. The filters are a list of the form: pattern=filter
-# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how
-# filters are used. If the FILTER_PATTERNS tag is empty or if none of the
-# patterns match the file name, INPUT_FILTER is applied.
-
-FILTER_PATTERNS =
-
-# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
-# INPUT_FILTER ) will also be used to filter the input files that are used for
-# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES).
-# The default value is: NO.
-
-FILTER_SOURCE_FILES = NO
-
-# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file
-# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and
-# it is also possible to disable source filtering for a specific pattern using
-# *.ext= (so without naming a filter).
-# This tag requires that the tag FILTER_SOURCE_FILES is set to YES.
-
-FILTER_SOURCE_PATTERNS =
-
-# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that
-# is part of the input, its contents will be placed on the main page
-# (index.html). This can be useful if you have a project on for instance GitHub
-# and want to reuse the introduction page also for the doxygen output.
-
-USE_MDFILE_AS_MAINPAGE =
-
-#---------------------------------------------------------------------------
-# Configuration options related to source browsing
-#---------------------------------------------------------------------------
-
-# If the SOURCE_BROWSER tag is set to YES then a list of source files will be
-# generated. Documented entities will be cross-referenced with these sources.
-#
-# Note: To get rid of all source code in the generated output, make sure that
-# also VERBATIM_HEADERS is set to NO.
-# The default value is: NO.
-
-SOURCE_BROWSER = NO
-
-# Setting the INLINE_SOURCES tag to YES will include the body of functions,
-# classes and enums directly into the documentation.
-# The default value is: NO.
-
-INLINE_SOURCES = NO
-
-# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any
-# special comment blocks from generated source code fragments. Normal C, C++ and
-# Fortran comments will always remain visible.
-# The default value is: YES.
-
-STRIP_CODE_COMMENTS = YES
-
-# If the REFERENCED_BY_RELATION tag is set to YES then for each documented
-# function all documented functions referencing it will be listed.
-# The default value is: NO.
-
-REFERENCED_BY_RELATION = NO
-
-# If the REFERENCES_RELATION tag is set to YES then for each documented function
-# all documented entities called/used by that function will be listed.
-# The default value is: NO.
-
-REFERENCES_RELATION = NO
-
-# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set
-# to YES, then the hyperlinks from functions in REFERENCES_RELATION and
-# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will
-# link to the documentation.
-# The default value is: YES.
-
-REFERENCES_LINK_SOURCE = YES
-
-# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the
-# source code will show a tooltip with additional information such as prototype,
-# brief description and links to the definition and documentation. Since this
-# will make the HTML file larger and loading of large files a bit slower, you
-# can opt to disable this feature.
-# The default value is: YES.
-# This tag requires that the tag SOURCE_BROWSER is set to YES.
-
-SOURCE_TOOLTIPS = YES
-
-# If the USE_HTAGS tag is set to YES then the references to source code will
-# point to the HTML generated by the htags(1) tool instead of doxygen built-in
-# source browser. The htags tool is part of GNU's global source tagging system
-# (see http://www.gnu.org/software/global/global.html). You will need version
-# 4.8.6 or higher.
-#
-# To use it do the following:
-# - Install the latest version of global
-# - Enable SOURCE_BROWSER and USE_HTAGS in the config file
-# - Make sure the INPUT points to the root of the source tree
-# - Run doxygen as normal
-#
-# Doxygen will invoke htags (and that will in turn invoke gtags), so these
-# tools must be available from the command line (i.e. in the search path).
-#
-# The result: instead of the source browser generated by doxygen, the links to
-# source code will now point to the output of htags.
-# The default value is: NO.
-# This tag requires that the tag SOURCE_BROWSER is set to YES.
-
-USE_HTAGS = NO
-
-# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a
-# verbatim copy of the header file for each class for which an include is
-# specified. Set to NO to disable this.
-# See also: Section \class.
-# The default value is: YES.
-
-VERBATIM_HEADERS = YES
-
-#---------------------------------------------------------------------------
-# Configuration options related to the alphabetical class index
-#---------------------------------------------------------------------------
-
-# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all
-# compounds will be generated. Enable this if the project contains a lot of
-# classes, structs, unions or interfaces.
-# The default value is: YES.
-
-ALPHABETICAL_INDEX = YES
-
-# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in
-# which the alphabetical index list will be split.
-# Minimum value: 1, maximum value: 20, default value: 5.
-# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.
-
-COLS_IN_ALPHA_INDEX = 5
-
-# In case all classes in a project start with a common prefix, all classes will
-# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag
-# can be used to specify a prefix (or a list of prefixes) that should be ignored
-# while generating the index headers.
-# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.
-
-IGNORE_PREFIX =
-
-#---------------------------------------------------------------------------
-# Configuration options related to the HTML output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_HTML tag is set to YES doxygen will generate HTML output
-# The default value is: YES.
-
-GENERATE_HTML = YES
-
-# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a
-# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
-# it.
-# The default directory is: html.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_OUTPUT = html
-
-# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each
-# generated HTML page (for example: .htm, .php, .asp).
-# The default value is: .html.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_FILE_EXTENSION = .html
-
-# The HTML_HEADER tag can be used to specify a user-defined HTML header file for
-# each generated HTML page. If the tag is left blank doxygen will generate a
-# standard header.
-#
-# To get valid HTML the header file that includes any scripts and style sheets
-# that doxygen needs, which is dependent on the configuration options used (e.g.
-# the setting GENERATE_TREEVIEW). It is highly recommended to start with a
-# default header using
-# doxygen -w html new_header.html new_footer.html new_stylesheet.css
-# YourConfigFile
-# and then modify the file new_header.html. See also section "Doxygen usage"
-# for information on how to generate the default header that doxygen normally
-# uses.
-# Note: The header is subject to change so you typically have to regenerate the
-# default header when upgrading to a newer version of doxygen. For a description
-# of the possible markers and block names see the documentation.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_HEADER =
-
-# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each
-# generated HTML page. If the tag is left blank doxygen will generate a standard
-# footer. See HTML_HEADER for more information on how to generate a default
-# footer and what special commands can be used inside the footer. See also
-# section "Doxygen usage" for information on how to generate the default footer
-# that doxygen normally uses.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_FOOTER =
-
-# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style
-# sheet that is used by each HTML page. It can be used to fine-tune the look of
-# the HTML output. If left blank doxygen will generate a default style sheet.
-# See also section "Doxygen usage" for information on how to generate the style
-# sheet that doxygen normally uses.
-# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as
-# it is more robust and this tag (HTML_STYLESHEET) will in the future become
-# obsolete.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_STYLESHEET =
-
-# The HTML_EXTRA_STYLESHEET tag can be used to specify an additional user-
-# defined cascading style sheet that is included after the standard style sheets
-# created by doxygen. Using this option one can overrule certain style aspects.
-# This is preferred over using HTML_STYLESHEET since it does not replace the
-# standard style sheet and is therefor more robust against future updates.
-# Doxygen will copy the style sheet file to the output directory. For an example
-# see the documentation.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_EXTRA_STYLESHEET =
-
-# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
-# other source files which should be copied to the HTML output directory. Note
-# that these files will be copied to the base HTML output directory. Use the
-# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these
-# files. In the HTML_STYLESHEET file, use the file name only. Also note that the
-# files will be copied as-is; there are no commands or markers available.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_EXTRA_FILES =
-
-# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen
-# will adjust the colors in the stylesheet and background images according to
-# this color. Hue is specified as an angle on a colorwheel, see
-# http://en.wikipedia.org/wiki/Hue for more information. For instance the value
-# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300
-# purple, and 360 is red again.
-# Minimum value: 0, maximum value: 359, default value: 220.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_COLORSTYLE_HUE = 220
-
-# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors
-# in the HTML output. For a value of 0 the output will use grayscales only. A
-# value of 255 will produce the most vivid colors.
-# Minimum value: 0, maximum value: 255, default value: 100.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_COLORSTYLE_SAT = 100
-
-# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the
-# luminance component of the colors in the HTML output. Values below 100
-# gradually make the output lighter, whereas values above 100 make the output
-# darker. The value divided by 100 is the actual gamma applied, so 80 represents
-# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not
-# change the gamma.
-# Minimum value: 40, maximum value: 240, default value: 80.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_COLORSTYLE_GAMMA = 80
-
-# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
-# page will contain the date and time when the page was generated. Setting this
-# to NO can help when comparing the output of multiple runs.
-# The default value is: YES.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_TIMESTAMP = YES
-
-# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
-# documentation will contain sections that can be hidden and shown after the
-# page has loaded.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_DYNAMIC_SECTIONS = NO
-
-# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries
-# shown in the various tree structured indices initially; the user can expand
-# and collapse entries dynamically later on. Doxygen will expand the tree to
-# such a level that at most the specified number of entries are visible (unless
-# a fully collapsed tree already exceeds this amount). So setting the number of
-# entries 1 will produce a full collapsed tree by default. 0 is a special value
-# representing an infinite number of entries and will result in a full expanded
-# tree by default.
-# Minimum value: 0, maximum value: 9999, default value: 100.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_INDEX_NUM_ENTRIES = 100
-
-# If the GENERATE_DOCSET tag is set to YES, additional index files will be
-# generated that can be used as input for Apple's Xcode 3 integrated development
-# environment (see: http://developer.apple.com/tools/xcode/), introduced with
-# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a
-# Makefile in the HTML output directory. Running make will produce the docset in
-# that directory and running make install will install the docset in
-# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at
-# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html
-# for more information.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-GENERATE_DOCSET = NO
-
-# This tag determines the name of the docset feed. A documentation feed provides
-# an umbrella under which multiple documentation sets from a single provider
-# (such as a company or product suite) can be grouped.
-# The default value is: Doxygen generated docs.
-# This tag requires that the tag GENERATE_DOCSET is set to YES.
-
-DOCSET_FEEDNAME = "Doxygen generated docs"
-
-# This tag specifies a string that should uniquely identify the documentation
-# set bundle. This should be a reverse domain-name style string, e.g.
-# com.mycompany.MyDocSet. Doxygen will append .docset to the name.
-# The default value is: org.doxygen.Project.
-# This tag requires that the tag GENERATE_DOCSET is set to YES.
-
-DOCSET_BUNDLE_ID = org.doxygen.Project
-
-# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify
-# the documentation publisher. This should be a reverse domain-name style
-# string, e.g. com.mycompany.MyDocSet.documentation.
-# The default value is: org.doxygen.Publisher.
-# This tag requires that the tag GENERATE_DOCSET is set to YES.
-
-DOCSET_PUBLISHER_ID = org.doxygen.Publisher
-
-# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher.
-# The default value is: Publisher.
-# This tag requires that the tag GENERATE_DOCSET is set to YES.
-
-DOCSET_PUBLISHER_NAME = Publisher
-
-# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three
-# additional HTML index files: index.hhp, index.hhc, and index.hhk. The
-# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop
-# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on
-# Windows.
-#
-# The HTML Help Workshop contains a compiler that can convert all HTML output
-# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML
-# files are now used as the Windows 98 help format, and will replace the old
-# Windows help format (.hlp) on all Windows platforms in the future. Compressed
-# HTML files also contain an index, a table of contents, and you can search for
-# words in the documentation. The HTML workshop also contains a viewer for
-# compressed HTML files.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-GENERATE_HTMLHELP = NO
-
-# The CHM_FILE tag can be used to specify the file name of the resulting .chm
-# file. You can add a path in front of the file if the result should not be
-# written to the html output directory.
-# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
-
-CHM_FILE =
-
-# The HHC_LOCATION tag can be used to specify the location (absolute path
-# including file name) of the HTML help compiler ( hhc.exe). If non-empty
-# doxygen will try to run the HTML help compiler on the generated index.hhp.
-# The file has to be specified with full path.
-# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
-
-HHC_LOCATION =
-
-# The GENERATE_CHI flag controls if a separate .chi index file is generated (
-# YES) or that it should be included in the master .chm file ( NO).
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
-
-GENERATE_CHI = NO
-
-# The CHM_INDEX_ENCODING is used to encode HtmlHelp index ( hhk), content ( hhc)
-# and project file content.
-# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
-
-CHM_INDEX_ENCODING =
-
-# The BINARY_TOC flag controls whether a binary table of contents is generated (
-# YES) or a normal table of contents ( NO) in the .chm file.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
-
-BINARY_TOC = NO
-
-# The TOC_EXPAND flag can be set to YES to add extra items for group members to
-# the table of contents of the HTML help documentation and to the tree view.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
-
-TOC_EXPAND = NO
-
-# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and
-# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that
-# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help
-# (.qch) of the generated HTML documentation.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-GENERATE_QHP = NO
-
-# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify
-# the file name of the resulting .qch file. The path specified is relative to
-# the HTML output folder.
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QCH_FILE =
-
-# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help
-# Project output. For more information please see Qt Help Project / Namespace
-# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace).
-# The default value is: org.doxygen.Project.
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QHP_NAMESPACE = org.doxygen.Project
-
-# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt
-# Help Project output. For more information please see Qt Help Project / Virtual
-# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual-
-# folders).
-# The default value is: doc.
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QHP_VIRTUAL_FOLDER = doc
-
-# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom
-# filter to add. For more information please see Qt Help Project / Custom
-# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-
-# filters).
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QHP_CUST_FILTER_NAME =
-
-# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the
-# custom filter to add. For more information please see Qt Help Project / Custom
-# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-
-# filters).
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QHP_CUST_FILTER_ATTRS =
-
-# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this
-# project's filter section matches. Qt Help Project / Filter Attributes (see:
-# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes).
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QHP_SECT_FILTER_ATTRS =
-
-# The QHG_LOCATION tag can be used to specify the location of Qt's
-# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the
-# generated .qhp file.
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QHG_LOCATION =
-
-# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be
-# generated, together with the HTML files, they form an Eclipse help plugin. To
-# install this plugin and make it available under the help contents menu in
-# Eclipse, the contents of the directory containing the HTML and XML files needs
-# to be copied into the plugins directory of eclipse. The name of the directory
-# within the plugins directory should be the same as the ECLIPSE_DOC_ID value.
-# After copying Eclipse needs to be restarted before the help appears.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-GENERATE_ECLIPSEHELP = NO
-
-# A unique identifier for the Eclipse help plugin. When installing the plugin
-# the directory name containing the HTML and XML files should also have this
-# name. Each documentation set should have its own identifier.
-# The default value is: org.doxygen.Project.
-# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES.
-
-ECLIPSE_DOC_ID = org.doxygen.Project
-
-# If you want full control over the layout of the generated HTML pages it might
-# be necessary to disable the index and replace it with your own. The
-# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top
-# of each HTML page. A value of NO enables the index and the value YES disables
-# it. Since the tabs in the index contain the same information as the navigation
-# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-DISABLE_INDEX = NO
-
-# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index
-# structure should be generated to display hierarchical information. If the tag
-# value is set to YES, a side panel will be generated containing a tree-like
-# index structure (just like the one that is generated for HTML Help). For this
-# to work a browser that supports JavaScript, DHTML, CSS and frames is required
-# (i.e. any modern browser). Windows users are probably better off using the
-# HTML help feature. Via custom stylesheets (see HTML_EXTRA_STYLESHEET) one can
-# further fine-tune the look of the index. As an example, the default style
-# sheet generated by doxygen has an example that shows how to put an image at
-# the root of the tree instead of the PROJECT_NAME. Since the tree basically has
-# the same information as the tab index, you could consider setting
-# DISABLE_INDEX to YES when enabling this option.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-GENERATE_TREEVIEW = NO
-
-# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that
-# doxygen will group on one line in the generated HTML documentation.
-#
-# Note that a value of 0 will completely suppress the enum values from appearing
-# in the overview section.
-# Minimum value: 0, maximum value: 20, default value: 4.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-ENUM_VALUES_PER_LINE = 4
-
-# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used
-# to set the initial width (in pixels) of the frame in which the tree is shown.
-# Minimum value: 0, maximum value: 1500, default value: 250.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-TREEVIEW_WIDTH = 250
-
-# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open links to
-# external symbols imported via tag files in a separate window.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-EXT_LINKS_IN_WINDOW = NO
-
-# Use this tag to change the font size of LaTeX formulas included as images in
-# the HTML documentation. When you change the font size after a successful
-# doxygen run you need to manually remove any form_*.png images from the HTML
-# output directory to force them to be regenerated.
-# Minimum value: 8, maximum value: 50, default value: 10.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-FORMULA_FONTSIZE = 10
-
-# Use the FORMULA_TRANPARENT tag to determine whether or not the images
-# generated for formulas are transparent PNGs. Transparent PNGs are not
-# supported properly for IE 6.0, but are supported on all modern browsers.
-#
-# Note that when changing this option you need to delete any form_*.png files in
-# the HTML output directory before the changes have effect.
-# The default value is: YES.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-FORMULA_TRANSPARENT = YES
-
-# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see
-# http://www.mathjax.org) which uses client side Javascript for the rendering
-# instead of using prerendered bitmaps. Use this if you do not have LaTeX
-# installed or if you want to formulas look prettier in the HTML output. When
-# enabled you may also need to install MathJax separately and configure the path
-# to it using the MATHJAX_RELPATH option.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-USE_MATHJAX = NO
-
-# When MathJax is enabled you can set the default output format to be used for
-# the MathJax output. See the MathJax site (see:
-# http://docs.mathjax.org/en/latest/output.html) for more details.
-# Possible values are: HTML-CSS (which is slower, but has the best
-# compatibility), NativeMML (i.e. MathML) and SVG.
-# The default value is: HTML-CSS.
-# This tag requires that the tag USE_MATHJAX is set to YES.
-
-MATHJAX_FORMAT = HTML-CSS
-
-# When MathJax is enabled you need to specify the location relative to the HTML
-# output directory using the MATHJAX_RELPATH option. The destination directory
-# should contain the MathJax.js script. For instance, if the mathjax directory
-# is located at the same level as the HTML output directory, then
-# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax
-# Content Delivery Network so you can quickly see the result without installing
-# MathJax. However, it is strongly recommended to install a local copy of
-# MathJax from http://www.mathjax.org before deployment.
-# The default value is: http://cdn.mathjax.org/mathjax/latest.
-# This tag requires that the tag USE_MATHJAX is set to YES.
-
-MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
-
-# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax
-# extension names that should be enabled during MathJax rendering. For example
-# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols
-# This tag requires that the tag USE_MATHJAX is set to YES.
-
-MATHJAX_EXTENSIONS =
-
-# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces
-# of code that will be used on startup of the MathJax code. See the MathJax site
-# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an
-# example see the documentation.
-# This tag requires that the tag USE_MATHJAX is set to YES.
-
-MATHJAX_CODEFILE =
-
-# When the SEARCHENGINE tag is enabled doxygen will generate a search box for
-# the HTML output. The underlying search engine uses javascript and DHTML and
-# should work on any modern browser. Note that when using HTML help
-# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET)
-# there is already a search function so this one should typically be disabled.
-# For large projects the javascript based search engine can be slow, then
-# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to
-# search using the keyboard; to jump to the search box use <access key> + S
-# (what the <access key> is depends on the OS and browser, but it is typically
-# <CTRL>, <ALT>/<option>, or both). Inside the search box use the <cursor down
-# key> to jump into the search results window, the results can be navigated
-# using the <cursor keys>. Press <Enter> to select an item or <escape> to cancel
-# the search. The filter options can be selected when the cursor is inside the
-# search box by pressing <Shift>+<cursor down>. Also here use the <cursor keys>
-# to select a filter and <Enter> or <escape> to activate or cancel the filter
-# option.
-# The default value is: YES.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-SEARCHENGINE = YES
-
-# When the SERVER_BASED_SEARCH tag is enabled the search engine will be
-# implemented using a web server instead of a web client using Javascript. There
-# are two flavours of web server based searching depending on the
-# EXTERNAL_SEARCH setting. When disabled, doxygen will generate a PHP script for
-# searching and an index file used by the script. When EXTERNAL_SEARCH is
-# enabled the indexing and searching needs to be provided by external tools. See
-# the section "External Indexing and Searching" for details.
-# The default value is: NO.
-# This tag requires that the tag SEARCHENGINE is set to YES.
-
-SERVER_BASED_SEARCH = NO
-
-# When EXTERNAL_SEARCH tag is enabled doxygen will no longer generate the PHP
-# script for searching. Instead the search results are written to an XML file
-# which needs to be processed by an external indexer. Doxygen will invoke an
-# external search engine pointed to by the SEARCHENGINE_URL option to obtain the
-# search results.
-#
-# Doxygen ships with an example indexer ( doxyindexer) and search engine
-# (doxysearch.cgi) which are based on the open source search engine library
-# Xapian (see: http://xapian.org/).
-#
-# See the section "External Indexing and Searching" for details.
-# The default value is: NO.
-# This tag requires that the tag SEARCHENGINE is set to YES.
-
-EXTERNAL_SEARCH = NO
-
-# The SEARCHENGINE_URL should point to a search engine hosted by a web server
-# which will return the search results when EXTERNAL_SEARCH is enabled.
-#
-# Doxygen ships with an example indexer ( doxyindexer) and search engine
-# (doxysearch.cgi) which are based on the open source search engine library
-# Xapian (see: http://xapian.org/). See the section "External Indexing and
-# Searching" for details.
-# This tag requires that the tag SEARCHENGINE is set to YES.
-
-SEARCHENGINE_URL =
-
-# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed
-# search data is written to a file for indexing by an external tool. With the
-# SEARCHDATA_FILE tag the name of this file can be specified.
-# The default file is: searchdata.xml.
-# This tag requires that the tag SEARCHENGINE is set to YES.
-
-SEARCHDATA_FILE = searchdata.xml
-
-# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the
-# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is
-# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple
-# projects and redirect the results back to the right project.
-# This tag requires that the tag SEARCHENGINE is set to YES.
-
-EXTERNAL_SEARCH_ID =
-
-# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen
-# projects other than the one defined by this configuration file, but that are
-# all added to the same external search index. Each project needs to have a
-# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id of
-# to a relative location where the documentation can be found. The format is:
-# EXTRA_SEARCH_MAPPINGS = tagname1=loc1 tagname2=loc2 ...
-# This tag requires that the tag SEARCHENGINE is set to YES.
-
-EXTRA_SEARCH_MAPPINGS =
-
-#---------------------------------------------------------------------------
-# Configuration options related to the LaTeX output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_LATEX tag is set to YES doxygen will generate LaTeX output.
-# The default value is: YES.
-
-GENERATE_LATEX = NO
-GENERATE_MAN = NO
-
-#---------------------------------------------------------------------------
-# Configuration options related to the preprocessor
-#---------------------------------------------------------------------------
-
-# If the ENABLE_PREPROCESSING tag is set to YES doxygen will evaluate all
-# C-preprocessor directives found in the sources and include files.
-# The default value is: YES.
-
-ENABLE_PREPROCESSING = YES
-
-# If the MACRO_EXPANSION tag is set to YES doxygen will expand all macro names
-# in the source code. If set to NO only conditional compilation will be
-# performed. Macro expansion can be done in a controlled way by setting
-# EXPAND_ONLY_PREDEF to YES.
-# The default value is: NO.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-MACRO_EXPANSION = NO
-
-# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then
-# the macro expansion is limited to the macros specified with the PREDEFINED and
-# EXPAND_AS_DEFINED tags.
-# The default value is: NO.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-EXPAND_ONLY_PREDEF = NO
-
-# If the SEARCH_INCLUDES tag is set to YES the includes files in the
-# INCLUDE_PATH will be searched if a #include is found.
-# The default value is: YES.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-SEARCH_INCLUDES = YES
-
-# The INCLUDE_PATH tag can be used to specify one or more directories that
-# contain include files that are not input files but should be processed by the
-# preprocessor.
-# This tag requires that the tag SEARCH_INCLUDES is set to YES.
-
-INCLUDE_PATH =
-
-# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
-# patterns (like *.h and *.hpp) to filter out the header-files in the
-# directories. If left blank, the patterns specified with FILE_PATTERNS will be
-# used.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-INCLUDE_FILE_PATTERNS =
-
-# The PREDEFINED tag can be used to specify one or more macro names that are
-# defined before the preprocessor is started (similar to the -D option of e.g.
-# gcc). The argument of the tag is a list of macros of the form: name or
-# name=definition (no spaces). If the definition and the "=" are omitted, "=1"
-# is assumed. To prevent a macro definition from being undefined via #undef or
-# recursively expanded use the := operator instead of the = operator.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-PREDEFINED =
-
-# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
-# tag can be used to specify a list of macro names that should be expanded. The
-# macro definition that is found in the sources will be used. Use the PREDEFINED
-# tag if you want to use a different macro definition that overrules the
-# definition found in the source code.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-EXPAND_AS_DEFINED =
-
-# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will
-# remove all refrences to function-like macros that are alone on a line, have an
-# all uppercase name, and do not end with a semicolon. Such function macros are
-# typically used for boiler-plate code, and will confuse the parser if not
-# removed.
-# The default value is: YES.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-SKIP_FUNCTION_MACROS = YES
-
-#---------------------------------------------------------------------------
-# Configuration options related to external references
-#---------------------------------------------------------------------------
-
-# The TAGFILES tag can be used to specify one or more tag files. For each tag
-# file the location of the external documentation should be added. The format of
-# a tag file without this location is as follows:
-# TAGFILES = file1 file2 ...
-# Adding location for the tag files is done as follows:
-# TAGFILES = file1=loc1 "file2 = loc2" ...
-# where loc1 and loc2 can be relative or absolute paths or URLs. See the
-# section "Linking to external documentation" for more information about the use
-# of tag files.
-# Note: Each tag file must have an unique name (where the name does NOT include
-# the path). If a tag file is not located in the directory in which doxygen is
-# run, you must also specify the path to the tagfile here.
-
-TAGFILES =
-
-# When a file name is specified after GENERATE_TAGFILE, doxygen will create a
-# tag file that is based on the input files it reads. See section "Linking to
-# external documentation" for more information about the usage of tag files.
-
-GENERATE_TAGFILE =
-
-# If the ALLEXTERNALS tag is set to YES all external class will be listed in the
-# class index. If set to NO only the inherited external classes will be listed.
-# The default value is: NO.
-
-ALLEXTERNALS = NO
-
-# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed in
-# the modules index. If set to NO, only the current project's groups will be
-# listed.
-# The default value is: YES.
-
-EXTERNAL_GROUPS = YES
-
-# If the EXTERNAL_PAGES tag is set to YES all external pages will be listed in
-# the related pages index. If set to NO, only the current project's pages will
-# be listed.
-# The default value is: YES.
-
-EXTERNAL_PAGES = YES
-
-# The PERL_PATH should be the absolute path and name of the perl script
-# interpreter (i.e. the result of 'which perl').
-# The default file (with absolute path) is: /usr/bin/perl.
-
-PERL_PATH = /usr/bin/perl
-
-#---------------------------------------------------------------------------
-# Configuration options related to the dot tool
-#---------------------------------------------------------------------------
-
-# If the CLASS_DIAGRAMS tag is set to YES doxygen will generate a class diagram
-# (in HTML and LaTeX) for classes with base or super classes. Setting the tag to
-# NO turns the diagrams off. Note that this option also works with HAVE_DOT
-# disabled, but it is recommended to install and use dot, since it yields more
-# powerful graphs.
-# The default value is: YES.
-
-CLASS_DIAGRAMS = YES
-
-# You can define message sequence charts within doxygen comments using the \msc
-# command. Doxygen will then run the mscgen tool (see:
-# http://www.mcternan.me.uk/mscgen/)) to produce the chart and insert it in the
-# documentation. The MSCGEN_PATH tag allows you to specify the directory where
-# the mscgen tool resides. If left empty the tool is assumed to be found in the
-# default search path.
-
-MSCGEN_PATH =
-
-# You can include diagrams made with dia in doxygen documentation. Doxygen will
-# then run dia to produce the diagram and insert it in the documentation. The
-# DIA_PATH tag allows you to specify the directory where the dia binary resides.
-# If left empty dia is assumed to be found in the default search path.
-
-DIA_PATH =
-
-# If set to YES, the inheritance and collaboration graphs will hide inheritance
-# and usage relations if the target is undocumented or is not a class.
-# The default value is: YES.
-
-HIDE_UNDOC_RELATIONS = YES
-
-# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
-# available from the path. This tool is part of Graphviz (see:
-# http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent
-# Bell Labs. The other options in this section have no effect if this option is
-# set to NO
-# The default value is: NO.
-
-HAVE_DOT = @DOXYGEN_DOT_FOUND@
-
-# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed
-# to run in parallel. When set to 0 doxygen will base this on the number of
-# processors available in the system. You can set it explicitly to a value
-# larger than 0 to get control over the balance between CPU load and processing
-# speed.
-# Minimum value: 0, maximum value: 32, default value: 0.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_NUM_THREADS = 0
-
-# When you want a differently looking font n the dot files that doxygen
-# generates you can specify the font name using DOT_FONTNAME. You need to make
-# sure dot is able to find the font, which can be done by putting it in a
-# standard location or by setting the DOTFONTPATH environment variable or by
-# setting DOT_FONTPATH to the directory containing the font.
-# The default value is: Helvetica.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_FONTNAME = Helvetica
-
-# The DOT_FONTSIZE tag can be used to set the size (in points) of the font of
-# dot graphs.
-# Minimum value: 4, maximum value: 24, default value: 10.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_FONTSIZE = 10
-
-# By default doxygen will tell dot to use the default font as specified with
-# DOT_FONTNAME. If you specify a different font using DOT_FONTNAME you can set
-# the path where dot can find it using this tag.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_FONTPATH =
-
-# If the CLASS_GRAPH tag is set to YES then doxygen will generate a graph for
-# each documented class showing the direct and indirect inheritance relations.
-# Setting this tag to YES will force the CLASS_DIAGRAMS tag to NO.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-CLASS_GRAPH = YES
-
-# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a
-# graph for each documented class showing the direct and indirect implementation
-# dependencies (inheritance, containment, and class references variables) of the
-# class with other documented classes.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-COLLABORATION_GRAPH = YES
-
-# If the GROUP_GRAPHS tag is set to YES then doxygen will generate a graph for
-# groups, showing the direct groups dependencies.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-GROUP_GRAPHS = YES
-
-# If the UML_LOOK tag is set to YES doxygen will generate inheritance and
-# collaboration diagrams in a style similar to the OMG's Unified Modeling
-# Language.
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-UML_LOOK = NO
-
-# If the UML_LOOK tag is enabled, the fields and methods are shown inside the
-# class node. If there are many fields or methods and many nodes the graph may
-# become too big to be useful. The UML_LIMIT_NUM_FIELDS threshold limits the
-# number of items for each type to make the size more manageable. Set this to 0
-# for no limit. Note that the threshold may be exceeded by 50% before the limit
-# is enforced. So when you set the threshold to 10, up to 15 fields may appear,
-# but if the number exceeds 15, the total amount of fields shown is limited to
-# 10.
-# Minimum value: 0, maximum value: 100, default value: 10.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-UML_LIMIT_NUM_FIELDS = 10
-
-# If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and
-# collaboration graphs will show the relations between templates and their
-# instances.
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-TEMPLATE_RELATIONS = NO
-
-# If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to
-# YES then doxygen will generate a graph for each documented file showing the
-# direct and indirect include dependencies of the file with other documented
-# files.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-INCLUDE_GRAPH = YES
-
-# If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are
-# set to YES then doxygen will generate a graph for each documented file showing
-# the direct and indirect include dependencies of the file with other documented
-# files.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-INCLUDED_BY_GRAPH = YES
-
-# If the CALL_GRAPH tag is set to YES then doxygen will generate a call
-# dependency graph for every global function or class method.
-#
-# Note that enabling this option will significantly increase the time of a run.
-# So in most cases it will be better to enable call graphs for selected
-# functions only using the \callgraph command.
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-CALL_GRAPH = YES
-
-# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller
-# dependency graph for every global function or class method.
-#
-# Note that enabling this option will significantly increase the time of a run.
-# So in most cases it will be better to enable caller graphs for selected
-# functions only using the \callergraph command.
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-CALLER_GRAPH = YES
-
-# If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical
-# hierarchy of all classes instead of a textual one.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-GRAPHICAL_HIERARCHY = YES
-
-# If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the
-# dependencies a directory has on other directories in a graphical way. The
-# dependency relations are determined by the #include relations between the
-# files in the directories.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DIRECTORY_GRAPH = YES
-
-# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
-# generated by dot.
-# Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order
-# to make the SVG files visible in IE 9+ (other browsers do not have this
-# requirement).
-# Possible values are: png, jpg, gif and svg.
-# The default value is: png.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_IMAGE_FORMAT = png
-
-# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to
-# enable generation of interactive SVG images that allow zooming and panning.
-#
-# Note that this requires a modern browser other than Internet Explorer. Tested
-# and working are Firefox, Chrome, Safari, and Opera.
-# Note: For IE 9+ you need to set HTML_FILE_EXTENSION to xhtml in order to make
-# the SVG files visible. Older versions of IE do not have SVG support.
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-INTERACTIVE_SVG = NO
-
-# The DOT_PATH tag can be used to specify the path where the dot tool can be
-# found. If left blank, it is assumed the dot tool can be found in the path.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_PATH = "@DOXYGEN_DOT_PATH@"
-
-# The DOTFILE_DIRS tag can be used to specify one or more directories that
-# contain dot files that are included in the documentation (see the \dotfile
-# command).
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOTFILE_DIRS =
-
-# The MSCFILE_DIRS tag can be used to specify one or more directories that
-# contain msc files that are included in the documentation (see the \mscfile
-# command).
-
-MSCFILE_DIRS =
-
-# The DIAFILE_DIRS tag can be used to specify one or more directories that
-# contain dia files that are included in the documentation (see the \diafile
-# command).
-
-DIAFILE_DIRS =
-
-# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes
-# that will be shown in the graph. If the number of nodes in a graph becomes
-# larger than this value, doxygen will truncate the graph, which is visualized
-# by representing a node as a red box. Note that doxygen if the number of direct
-# children of the root node in a graph is already larger than
-# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note that
-# the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.
-# Minimum value: 0, maximum value: 10000, default value: 50.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_GRAPH_MAX_NODES = 25
-
-# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs
-# generated by dot. A depth value of 3 means that only nodes reachable from the
-# root by following a path via at most 3 edges will be shown. Nodes that lay
-# further from the root node will be omitted. Note that setting this option to 1
-# or 2 may greatly reduce the computation time needed for large code bases. Also
-# note that the size of a graph can be further restricted by
-# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.
-# Minimum value: 0, maximum value: 1000, default value: 0.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-MAX_DOT_GRAPH_DEPTH = 10
-
-# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
-# background. This is disabled by default, because dot on Windows does not seem
-# to support this out of the box.
-#
-# Warning: Depending on the platform used, enabling this option may lead to
-# badly anti-aliased labels on the edges of a graph (i.e. they become hard to
-# read).
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_TRANSPARENT = YES
-
-# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output
-# files in one run (i.e. multiple -o and -T options on the command line). This
-# makes dot run faster, but since only newer versions of dot (>1.8.10) support
-# this, this feature is disabled by default.
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_MULTI_TARGETS = NO
-
-# If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page
-# explaining the meaning of the various boxes and arrows in the dot generated
-# graphs.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-GENERATE_LEGEND = YES
-
-# If the DOT_CLEANUP tag is set to YES doxygen will remove the intermediate dot
-# files that are used to generate the various graphs.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_CLEANUP = YES
diff --git a/METADATA b/METADATA
deleted file mode 100644
index ac0441a..0000000
--- a/METADATA
+++ /dev/null
@@ -1,17 +0,0 @@
-name: "libiio"
-description:
- "Library for interfacing with Linux IIO devices"
-
-third_party {
- url {
- type: HOMEPAGE
- value: "https://github.com/analogdevicesinc/libiio"
- }
- url {
- type: ARCHIVE
- value: "https://github.com/analogdevicesinc/libiio/archive/4e22517c60f3c5e691320871956edede15459ae3.zip"
- }
- version: "4e22517c60f3c5e691320871956edede15459ae3"
- last_upgrade_date { year: 2020 month: 2 day: 3 }
- license_type: RESTRICTED
-}
diff --git a/MODULE_LICENSE_LGPL b/MODULE_LICENSE_LGPL
deleted file mode 100644
index e69de29..0000000
--- a/MODULE_LICENSE_LGPL
+++ /dev/null
diff --git a/OWNERS b/OWNERS
index 7529cb9..5e339a8 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1 +1,3 @@
+# Please go through go/android-3p process if you need this project in the future.
+
include platform/system/core:/janitors/OWNERS
diff --git a/README.md b/README.md
deleted file mode 100644
index 4ea237a..0000000
--- a/README.md
+++ /dev/null
@@ -1,52 +0,0 @@
-# libiio
-
-Library for interfacing with Linux IIO devices
-
-libiio is used to interface to the Linux Industrial Input/Output (IIO) Subsystem. The Linux IIO subsystem is intended to provide support for devices that in some sense are analog to digital or digital to analog converters (ADCs, DACs). This includes, but is not limited to ADCs, Accelerometers, Gyros, IMUs, Capacitance to Digital Converters (CDCs), Pressure Sensors, Color, Light and Proximity Sensors, Temperature Sensors, Magnetometers, DACs, DDS (Direct Digital Synthesis), PLLs (Phase Locked Loops), Variable/Programmable Gain Amplifiers (VGA, PGA), and RF transceivers. You can use libiio natively on an embedded Linux target (local mode), or use libiio to communicate remotely to that same target from a host Linux, Windows or MAC over USB or Ethernet or Serial.
-
-Although libiio was primarily developed by Analog Devices Inc., it is an active open source library, which many people have contributed to. It released under the GNU Lesser General Public License, version 2.1 or later, this open-source license allows anyone to use the library, on any vendors processor/FPGA/SoC, which may be controlling any vendors peripheral device (ADC, DAC, etc) either locally or remotely. This includes closed or open-source, commercial or non-commercial applications (subject to the LGPL license freedoms, obligations and restrictions).
-
-License : [![License](https://img.shields.io/badge/license-LGPL2-blue.svg)](https://github.com/analogdevicesinc/libiio/blob/master/COPYING.txt)
-Latest Release : [![GitHub release](https://img.shields.io/github/release/analogdevicesinc/libiio.svg)](https://github.com/analogdevicesinc/libiio/releases/latest)
-Downloads : [![Github All Releases](https://img.shields.io/github/downloads/analogdevicesinc/libiio/total.svg)](https://github.com/analogdevicesinc/libiio/releases/latest)
-
-Scans : [![Coverity Scan Build Status](https://img.shields.io/coverity/scan/4796.svg)](https://scan.coverity.com/projects/analogdevicesinc-libiio)
-Release docs: [![Documentation](https://codedocs.xyz/analogdevicesinc/libiio.svg)](http://analogdevicesinc.github.io/libiio/)
-Issues : [![open bugs](https://img.shields.io/github/issues/analogdevicesinc/libiio.svg)](https://github.com/analogdevicesinc/libiio/issues)
-[![closed bugs](https://img.shields.io/github/issues-closed/analogdevicesinc/libiio.svg)](https://github.com/analogdevicesinc/libiio/issues?q=is%3Aissue+is%3Aclosed)
-
-Support:<br>
-If you have a question about libiio and an Analog Devices IIO kernel driver please ask on : [![EngineerZone](https://img.shields.io/badge/chat-on%20EngineerZone-blue.svg)](https://ez.analog.com/linux-device-drivers/linux-software-drivers). If you have a question about a non-ADI devices, please ask it on [github](https://github.com/analogdevicesinc/libiio/issues).
-
-As with many open source packages, we use [GitHub](https://github.com/analogdevicesinc/libiio) to do develop and maintain the source, and [Travis CI](https://travis-ci.com/) and [Appveyor](https://www.appveyor.com/) for continuous integration.
- - If you want to just use libiio, we suggest using the [latest release](https://github.com/analogdevicesinc/libiio/releases/latest).
- - If you think you have found a bug in the release, or need a feature which isn't in the release, try the latest **untested** binaries from the master branch and check out the [documentation](https://codedocs.xyz/analogdevicesinc/libiio/) based on the master branch. We provide builds for a few operating systems. If you need something else, we can most likely add that -- just ask.
-
-| Operating System | GitHub master status | Version | Primary Installer Package | Alternative Package, tarball or zip |
-|:-----------------------:|:---------------------:|:-------:|:-------------------:|:--------------:|
-| Windows | [![Windows Status](https://ci.appveyor.com/api/projects/status/github/analogdevicesinc/libiio?svg=true)](https://ci.appveyor.com/project/analogdevicesinc/libiio/branch/master) | Windows 10<br />Windows 8.1<br />Windows 8<br />Windows 7 | [![Latest Windows installer](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/win_box.png)](https://ci.appveyor.com/api/projects/analogdevicesinc/libiio/artifacts/libiio-setup.exe?branch=master) | [![Latest Windows zip](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/win_box.png)](https://ci.appveyor.com/api/projects/analogdevicesinc/libiio/artifacts/libiio.zip?branch=master) |
-| OS X | [![OSX Status](https://api.travis-ci.org/analogdevicesinc/libiio.svg?branch=master&label=osx&passingTex=foo)](https://travis-ci.org/analogdevicesinc/libiio) | OS X High Sierra <br />(v 10.13) | [![OS-X package 10.13](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/osx_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-darwin-10.13.6.pkg) | [![OS-X tarball 10.10](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/osx_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-darwin-10.13.6.tar.gz) |
-| | | macOS Sierra<br />(v 10.12) | [![OS-X package 10.12](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/osx_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-darwin-10.12.6.pkg) | [![OS-X tarball 10.12](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/osx_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-darwin-10.12.6.tar.gz) |
-| | | OS X El Capitan<br />(v 10.11) | [![OS-X package 10.11](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/osx_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-darwin-10.11.6.pkg) | [![OS-X tarball 10.11](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/osx_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-darwin-10.11.6.tar.gz) |
-| Linux | [![Linux Status](https://api.travis-ci.org/analogdevicesinc/libiio.svg?branch=master&label=linux)](https://travis-ci.org/analogdevicesinc/libiio) | Ubuntu Bionic Beaver<br />(v 18.04)<sup>1</sup> | [![Debian](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/deb.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-ubuntu-18.04-amd64.deb) | [![RPM File](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/rpm.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-ubuntu-18.04-amd64.rpm) [![tar.gz](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/linux_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-ubuntu-18.04-amd64.tar.gz) |
-| | | Ubuntu Xenial Xerus<br />(v 16.04)<sup>1</sup> | [![Debian](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/deb.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-ubuntu-16.04-amd64.deb) | [![RPM File](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/rpm.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-ubuntu-16.04-amd64.rpm) [![tar.gz file](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/linux_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-ubuntu-16.04-amd64.tar.gz) |
-| | | Ubuntu Trusty Tahr<br />(v 14.04)<sup>1</sup> | [![Debian](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/deb.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-ubuntu-14.04-amd64.deb) | [![RPM File](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/rpm.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-ubuntu-14.04-amd64.rpm) [![tar.gz file](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/linux_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-ubuntu-14.04-amd64.tar.gz) |
-| | | CentOS 7 | [![RPM File](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/rpm.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-centos-7-x86_64.rpm) | [![Debian](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/deb.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-centos-7-x86_64.deb) [![tar.gz](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/linux_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-centos-7-x86_64.tar.gz) |
-| | | CentOS 6 | [![RPM File](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/rpm.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-centos-6.10-x86_64.rpm) | [![Debian](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/deb.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-centos-6.10-x86_64.deb) [![tar.gz](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/linux_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-centos-6.10-x86_64.tar.gz) |
-
-If you use it, and like it - please let us know. If you use it, and hate it - please let us know that too. The goal of the project is to try to make Linux IIO devices easier to use on a variety of platforms. If we aren't doing that - we will try to make it better.
-
-Feedback is appreciated (in order of preference):
-
- * [Github trackers](https://github.com/analogdevicesinc/libiio/issues) for bugs, improvements, or feature requests
- * [Analog Devices web forums](https://ez.analog.com/community/linux-device-drivers/linux-software-drivers) for general help on libiio and/or ADI Linux IIO drivers
- * [The IIO mailing list](http://vger.kernel.org/vger-lists.html#linux-iio) for questions about other Linux IIO drivers, or kernel-specific IIO questions
-
-Weblinks:
- * About IIO: https://wiki.analog.com/software/linux/docs/iio/iio
- * API Documentation: http://analogdevicesinc.github.io/libiio/
- * Libiio : http://wiki.analog.com/resources/tools-software/linux-software/libiio
- * Libiio internals : http://wiki.analog.com/resources/tools-software/linux-software/libiio_internals
-
-1. The Ubuntu packages are known to work on their Debian counterpart releases.
-
diff --git a/appveyor.yml b/appveyor.yml
deleted file mode 100644
index 47216c4..0000000
--- a/appveyor.yml
+++ /dev/null
@@ -1,151 +0,0 @@
-version: '{branch}.{build}'
-clone_depth: 1
-
-skip_commits:
- message: /(iiod|IIOD):.*/
-
-environment:
- # Tell msys2 to add mingw64 to the path
- MSYSTEM: MINGW64
- # Tell msys2 to inherit the current directory when starting the shell
- CHERE_INVOKING: 1
-
-configuration:
- - Release
-
-install:
- - echo "Checking out sub-modules..."
- - git submodule update --init
- - echo "Downloading deps..."
- - cd C:\
- - appveyor DownloadFile http://swdownloads.analog.com/cse/build/libiio-win-deps.zip
- - 7z x -y "C:\libiio-win-deps.zip"
- #Install Inno Setup
- - choco install InnoSetup
- - set PATH=%PATH%;"C:\Program Files (x86)\Inno Setup 5"
-
-build_script:
- - set OLD_PATH=%PATH%
- - set OPT_PATH=C:\msys64\mingw32\bin;C:\msys64\mingw64\bin;
- - set PATH=%OPT_PATH%%PATH%
- - set GENERATOR=Unix Makefiles
- - cd C:\projects\libiio
- - set folder-path=C:\projects\libiio\build-mingw-win32\%configuration%
- # MinGW 32 bit
- - echo "Running cmake for MinGW 32 bit... "
- - mkdir C:\projects\libiio\build-mingw-win32
- - cd C:\projects\libiio\build-mingw-win32
- - C:\msys64\usr\bin\bash -lc "pwd"
- - mkdir C:\projects\libiio\build-mingw-win32\"%configuration%"& cd C:\projects\libiio\build-mingw-win32\"%configuration%"
- - C:\msys64\usr\bin\bash -lc "pwd"
- - C:\msys64\usr\bin\bash -lc "pacman -Rs --noconfirm mingw-w64-i686-gcc-ada mingw-w64-i686-gcc-fortran mingw-w64-i686-gcc-libgfortran mingw-w64-i686-gcc-objc"
- - C:\msys64\usr\bin\bash -lc "rm /mingw32/etc/gdbinit"
- - C:\msys64\usr\bin\bash -lc "pacman --noconfirm -Sy mingw-w64-i686-gcc mingw-w64-i686-libusb mingw-w64-i686-curl mingw-w64-i686-cmake mingw-w64-i686-libxml2 mingw-w64-i686-pkg-config mingw-w64-i686-libzip"
- - C:\msys64\usr\bin\bash -lc "pacman --noconfirm -Syu"
- # Newer llvm breaks doxygen, use old version for now
- - C:\msys64\usr\bin\bash -lc "pacman -U --noconfirm http://repo.msys2.org/mingw/i686/mingw-w64-i686-llvm-5.0.0-3-any.pkg.tar.xz http://repo.msys2.org/mingw/i686/mingw-w64-i686-clang-5.0.0-3-any.pkg.tar.xz"
- # set the specific version of doxygen (06-Jun-2018), need to look at this later.
- - C:\msys64\usr\bin\bash -lc "pacman -U --noconfirm http://repo.msys2.org/mingw/i686/mingw-w64-i686-doxygen-1.8.14-2-any.pkg.tar.xz"
- - C:\msys64\usr\bin\bash -lc "pacman -U --noconfirm http://repo.msys2.org/mingw/i686/mingw-w64-i686-graphviz-2.40.1-4-any.pkg.tar.xz"
- # Download a 32-bit version of windres.exe
- - appveyor DownloadFile http://swdownloads.analog.com/cse/build/windres.exe.gz -FileName C:\windres.exe.gz
- - C:\msys64\usr\bin\bash -lc "cd /c ; gunzip windres.exe.gz"
- - C:\msys64\usr\bin\bash -lc "cmake -G '%GENERATOR%' -DCMAKE_RC_COMPILER=/c/windres.exe -DGIT_EXECUTABLE=C:/Program\ Files/Git/cmd/git.exe -DCMAKE_BUILD_TYPE=%configuration% -DCMAKE_INSTALL_PREFIX=/mingw32 -DCMAKE_C_COMPILER:FILEPATH=/mingw32/bin/i686-w64-mingw32-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=/mingw32/bin/i686-w64-mingw32-g++.exe -DCSHARP_BINDINGS:BOOL=OFF -DPKG_CONFIG_EXECUTABLE:FILEPATH=/mingw32/bin/pkg-config.exe -DENABLE_IPV6:BOOL=OFF -DPYTHON_BINDINGS:BOOL=OFF -DLIBSERIALPORT_LIBRARIES=/c/libs/32/libserialport.dll.a -DLIBSERIALPORT_INCLUDE_DIR=/c/include -DLIBLZMA_LIBRARY=c:/msys64/mingw32/lib/liblzma.dll.a /c/projects/libiio && make -j3"
-
- # MinGW 64 bit
- - cd c:\projects\libiio
- - echo "Running cmake for MinGW 64 bit... "
- - mkdir c:\projects\libiio\build-mingw-win64
- - cd c:\projects\libiio\build-mingw-win64
- - mkdir c:\projects\libiio\build-mingw-win64\"%configuration%"& cd c:\projects\libiio\build-mingw-win64\"%configuration%"
- - C:\msys64\usr\bin\bash -lc "pwd"
- - C:\msys64\usr\bin\bash -lc "pacman -Rs --noconfirm mingw-w64-x86_64-gcc-ada mingw-w64-x86_64-gcc-fortran mingw-w64-x86_64-gcc-libgfortran mingw-w64-x86_64-gcc-objc"
- - C:\msys64\usr\bin\bash -lc "rm /mingw64/etc/gdbinit"
- - C:\msys64\usr\bin\bash -lc "pacman --noconfirm -Sy mingw-w64-x86_64-gcc mingw-w64-x86_64-libusb mingw-w64-x86_64-curl mingw-w64-x86_64-cmake mingw-w64-x86_64-libxml2 mingw-w64-x86_64-pkg-config mingw-w64-x86_64-libzip"
- - C:\msys64\usr\bin\bash -lc "pacman --noconfirm -Syu"
- # Newer llvm breaks doxygen, use old version for now
- - C:\msys64\usr\bin\bash -lc "pacman -U --noconfirm http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-llvm-5.0.0-3-any.pkg.tar.xz http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-clang-5.0.0-3-any.pkg.tar.xz"
- # set the specific version of doxygen, need to look at this later.
- - C:\msys64\usr\bin\bash -lc "pacman -U --noconfirm http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-doxygen-1.8.14-2-any.pkg.tar.xz"
- - C:\msys64\usr\bin\bash -lc "pacman -U --noconfirm http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-graphviz-2.40.1-4-any.pkg.tar.xz"
- - C:\msys64\usr\bin\bash -lc "cmake -G '%GENERATOR%' -DCMAKE_BUILD_TYPE=%configuration% -DCMAKE_INSTALL_PREFIX=/mingw64 -DCMAKE_C_COMPILER:FILEPATH=/mingw64/bin/x86_64-w64-mingw32-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=/mingw64/bin/x86_64-w64-mingw32-g++.exe -DCSHARP_BINDINGS:BOOL=OFF -DPKG_CONFIG_EXECUTABLE:FILEPATH=/mingw64/bin/pkg-config.exe -DENABLE_IPV6:BOOL=OFF -DPYTHON_BINDINGS:BOOL=OFF -DLIBSERIALPORT_LIBRARIES=/c/libs/64/libserialport.dll.a -DLIBSERIALPORT_INCLUDE_DIR=/c/include /c/projects/libiio && make -j3"
-
- # Move the tests folder
- - cd c:\projects\libiio
- - mkdir build-mingw-win32\tests\ build-mingw-win32\tests\"%configuration%"& copy build-mingw-win32\Release\tests\*.exe build-mingw-win32\tests\"%configuration%"\
- - mkdir build-mingw-win64\tests\ build-mingw-win64\tests\"%configuration%"& copy build-mingw-win64\Release\tests\*.exe build-mingw-win64\tests\"%configuration%"\
-
- - set PATH=%OLD_PATH%
- - set GENERATOR=Visual Studio 12
- - cd c:\projects\libiio
- - set folder-path=c:\projects\libiio\build-win32
- #MSVC 32 bit
- - echo "Running cmake for Visual Studio 32 bit... "
- - mkdir build-win32
- - cd build-win32
- - set MCS_EXECUTABLE_PATH="C:\Windows\Microsoft.NET\Framework\v4.0.30319"
- - cmake -G "%GENERATOR%" -DCMAKE_BUILD_TYPE:STRING="%configuration%" -DENABLE_IPV6:BOOL=OFF -DCMAKE_SYSTEM_PREFIX_PATH="C:" -DPYTHON_BINDINGS:BOOL=OFF -DLIBXML2_LIBRARIES="C:\\libs\\32\\libxml2.lib" -DLIBUSB_LIBRARIES="C:\\libs\\32\\libusb-1.0.lib" -DLIBSERIALPORT_LIBRARIES="C:\\libs\\32\\libserialport.dll.a" ..
- - cmake --build . --config %configuration%
-
- #MSVC 64 bit
- - cd c:\projects\libiio
- - echo "Running cmake for Visual Studio 64 bit... "
- - mkdir build-win64
- - cd build-win64
- - cmake -G "%GENERATOR% Win64" -DCMAKE_BUILD_TYPE:STRING="%configuration%" -DENABLE_IPV6:BOOL=OFF -DCMAKE_SYSTEM_PREFIX_PATH="C:" -DPYTHON_BINDINGS:BOOL=OFF -DLIBXML2_LIBRARIES="C:\\libs\\64\\libxml2.lib" -DLIBUSB_LIBRARIES="C:\\libs\\64\\libusb-1.0.lib" -DLIBSERIALPORT_LIBRARIES="C:\\libs\\64\\libserialport.dll.a" ..
- - cmake --build . --config %configuration%
-
- #Create the installer
- - ISCC %folder-path%\libiio.iss
- - appveyor PushArtifact C:\libiio-setup.exe
-
- # Create ZIP package
- # set LIBIIO_VERSION to current project version determined by cmake
- - ps: >-
- Set-AppveyorBuildVariable -Name LIBIIO_VERSION -Value (get-content .version)
- - set ARCHIVE_NAME=libiio-%LIBIIO_VERSION%
- - cd c:\projects\libiio
- - mkdir c:\%ARCHIVE_NAME% c:\%ARCHIVE_NAME%\include c:\%ARCHIVE_NAME%\MS32 c:\%ARCHIVE_NAME%\MS64 c:\%ARCHIVE_NAME%\MinGW32 c:\%ARCHIVE_NAME%\MinGW64
- - copy iio.h c:\%ARCHIVE_NAME%\include
- - copy build-win32\Release\libiio.* c:\%ARCHIVE_NAME%\MS32
- - copy build-win64\Release\libiio.* c:\%ARCHIVE_NAME%\MS64
- - copy build-mingw-win32\Release\libiio.* c:\%ARCHIVE_NAME%\MinGW32
- - copy build-mingw-win64\Release\libiio.* c:\%ARCHIVE_NAME%\MinGW64
- - del c:\%ARCHIVE_NAME%\MinGW32\libiio.iss
- - del c:\%ARCHIVE_NAME%\MinGW64\libiio.iss
- - del c:\%ARCHIVE_NAME%\MinGW32\libiio.pc
- - del c:\%ARCHIVE_NAME%\MinGW64\libiio.pc
-
- - copy build-win32\tests\Release\*.exe c:\%ARCHIVE_NAME%\MS32
- - copy build-win64\tests\Release\*.exe c:\%ARCHIVE_NAME%\MS64
- - copy build-mingw-win32\tests\Release\*.exe c:\%ARCHIVE_NAME%\MinGW32
- - copy build-mingw-win64\tests\Release\*.exe c:\%ARCHIVE_NAME%\MinGW64
-
- #Copy dependencies for MSVC
- - copy c:\libs\32\libxml2.dll c:\%ARCHIVE_NAME%\MS32
- - copy c:\libs\64\libxml2.dll c:\%ARCHIVE_NAME%\MS64
- - copy c:\libs\32\libusb-1.0.dll c:\%ARCHIVE_NAME%\MS32
- - copy c:\libs\64\libusb-1.0.dll c:\%ARCHIVE_NAME%\MS64
- - copy c:\libs\32\libserialport-0.dll c:\%ARCHIVE_NAME%\MS32
- - copy c:\libs\64\libserialport-0.dll c:\%ARCHIVE_NAME%\MS64
-
- #Copy dependencies for MinGW
- - C:\msys64\usr\bin\bash -lc "cd c:/msys64/mingw32/bin ; cp -r libwinpthread-*.dll libgcc_*.dll libstdc++-*.dll libiconv-*.dll zlib*.dll libxml2-*.dll liblzma-*.dll libzip*.dll libusb-*.dll /c/%ARCHIVE_NAME%/MinGW32"
- - C:\msys64\usr\bin\bash -lc "cd c:/msys64/mingw64/bin ; cp -r libwinpthread-*.dll libgcc_*.dll libstdc++-*.dll libiconv-*.dll zlib*.dll libxml2-*.dll liblzma-*.dll libzip*.dll libusb-*.dll /c/%ARCHIVE_NAME%/MinGW64"
- - C:\msys64\usr\bin\bash -lc "cd c:/libs/32 ; cp libserialport-*.dll /c/%ARCHIVE_NAME%/MinGW32"
- - C:\msys64\usr\bin\bash -lc "cd c:/libs/64 ; cp libserialport-*.dll /c/%ARCHIVE_NAME%/MinGW64"
-
- - copy "c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\redist\x86\Microsoft.VC120.CRT\msvcr120.dll" c:\%ARCHIVE_NAME%\MS32
- - copy "c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\redist\x64\Microsoft.VC120.CRT\msvcr120.dll" c:\%ARCHIVE_NAME%\MS64
- - xcopy /S bindings\matlab c:\%ARCHIVE_NAME%\MS32\matlab\
- - xcopy /S bindings\matlab c:\%ARCHIVE_NAME%\MS64\matlab\
- - xcopy /S bindings\matlab c:\%ARCHIVE_NAME%\MinGW32\matlab\
- - xcopy /S bindings\matlab c:\%ARCHIVE_NAME%\MinGW64\matlab\
- - del c:\%ARCHIVE_NAME%\MS32\matlab\CMakeLists.txt
- - del c:\%ARCHIVE_NAME%\MS64\matlab\CMakeLists.txt
- - del c:\%ARCHIVE_NAME%\MinGW32\matlab\CMakeLists.txt
- - del c:\%ARCHIVE_NAME%\MinGW64\matlab\CMakeLists.txt
-
- - copy c:\projects\libiio\CI\travis\zip.txt c:\%ARCHIVE_NAME%\README.txt
- - 7z a "c:\libiio.zip" c:\%ARCHIVE_NAME%
- - appveyor PushArtifact c:\libiio.zip
diff --git a/backend.c b/backend.c
deleted file mode 100644
index 091267a..0000000
--- a/backend.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2017 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.
- */
-
-#include "iio-config.h"
-#include "iio-private.h"
-
-#include <string.h>
-
-unsigned int iio_get_backends_count(void)
-{
- unsigned int count = 0;
-
-#ifdef WITH_LOCAL_BACKEND
- count++;
-#endif
-#ifdef WITH_XML_BACKEND
- count++;
-#endif
-#ifdef WITH_NETWORK_BACKEND
- count++;
-#endif
-#ifdef WITH_USB_BACKEND
- count++;
-#endif
-#ifdef WITH_SERIAL_BACKEND
- count++;
-#endif
-
- return count;
-}
-
-const char * iio_get_backend(unsigned int index)
-{
-#ifdef WITH_LOCAL_BACKEND
- if (index == 0)
- return "local";
- index--;
-#endif
-#ifdef WITH_XML_BACKEND
- if (index == 0)
- return "xml";
- index--;
-#endif
-#ifdef WITH_NETWORK_BACKEND
- if (index == 0)
- return "ip";
- index--;
-#endif
-#ifdef WITH_USB_BACKEND
- if (index == 0)
- return "usb";
- index--;
-#endif
-#ifdef WITH_SERIAL_BACKEND
- if (index == 0)
- return "serial";
-#endif
- return NULL;
-}
-
-bool iio_has_backend(const char *backend)
-{
- unsigned int i;
-
- for (i = 0; i < iio_get_backends_count(); i++)
- if (strcmp(backend, iio_get_backend(i)) == 0)
- return true;
-
- return false;
-}
diff --git a/bindings/CMakeLists.txt b/bindings/CMakeLists.txt
deleted file mode 100644
index e2afcf0..0000000
--- a/bindings/CMakeLists.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-add_subdirectory(csharp)
-add_subdirectory(matlab)
-add_subdirectory(python)
diff --git a/bindings/csharp/.gitignore b/bindings/csharp/.gitignore
deleted file mode 100644
index 475b306..0000000
--- a/bindings/csharp/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-AssemblyInfo.cs
-libiio-sharp-0.5.pc
-libiio-sharp.dll.config
diff --git a/bindings/csharp/AssemblyInfo.cs.in b/bindings/csharp/AssemblyInfo.cs.in
deleted file mode 100644
index 5d1de04..0000000
--- a/bindings/csharp/AssemblyInfo.cs.in
+++ /dev/null
@@ -1,5 +0,0 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-
-[assembly:AssemblyVersion("@LIBIIO_CS_VERSION@")]
-[assembly:AssemblyDelaySign(false)]
diff --git a/bindings/csharp/Attr.cs b/bindings/csharp/Attr.cs
deleted file mode 100644
index 2ddcc3e..0000000
--- a/bindings/csharp/Attr.cs
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2015 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.
- *
- * */
-
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace iio
-{
- /// <summary><see cref="iio.Attr"/> class:
- /// Contains the representation of a channel or device attribute.</summary>
- public abstract class Attr
- {
- /// <summary>The name of this attribute.</summary>
- public readonly string name;
-
- /// <summary>The filename in sysfs to which this attribute is bound.</summary>
- public readonly string filename;
-
- internal Attr(string name, string filename = null)
- {
- this.filename = filename == null ? name : filename;
- this.name = name;
- }
-
- /// <summary>Read the value of this attribute as a <c>string</c>.</summary>
- /// <exception cref="System.Exception">The attribute could not be read.</exception>
- public abstract string read();
-
- /// <summary>Set this attribute to the value contained in the <c>string</c> argument.</summary>
- /// <param name="val">The <c>string</c> value to set the parameter to.</param>
- /// <exception cref="System.Exception">The attribute could not be written.</exception>
- public abstract void write(string val);
-
- /// <summary>Read the value of this attribute as a <c>bool</c>.</summary>
- /// <exception cref="System.Exception">The attribute could not be read.</exception>
- public bool read_bool()
- {
- string val = read();
- return (val.CompareTo("1") == 0) || (val.CompareTo("Y") == 0);
- }
-
- /// <summary>Read the value of this attribute as a <c>double</c>.</summary>
- /// <exception cref="System.Exception">The attribute could not be read.</exception>
- public double read_double()
- {
- return double.Parse(read(), CultureInfo.InvariantCulture);
- }
-
- /// <summary>Read the value of this attribute as a <c>long</c>.</summary>
- /// <exception cref="System.Exception">The attribute could not be read.</exception>
- public long read_long()
- {
- return long.Parse(read(), CultureInfo.InvariantCulture);
- }
-
- /// <summary>Set this attribute to the value contained in the <c>bool</c> argument.</summary>
- /// <param name="val">The <c>bool</c> value to set the parameter to.</param>
- /// <exception cref="System.Exception">The attribute could not be written.</exception>
- public void write(bool val)
- {
- if (val)
- write("1");
- else
- write("0");
- }
-
- /// <summary>Set this attribute to the value contained in the <c>long</c> argument.</summary>
- /// <param name="val">The <c>long</c> value to set the parameter to.</param>
- /// <exception cref="System.Exception">The attribute could not be written.</exception>
- public void write(long val)
- {
- write(val.ToString(CultureInfo.InvariantCulture));
- }
-
- /// <summary>Set this attribute to the value contained in the <c>double</c> argument.</summary>
- /// <param name="val">The <c>double</c> value to set the parameter to.</param>
- /// <exception cref="System.Exception">The attribute could not be written.</exception>
- public void write(double val)
- {
- write(val.ToString(CultureInfo.InvariantCulture));
- }
- }
-}
diff --git a/bindings/csharp/CMakeLists.txt b/bindings/csharp/CMakeLists.txt
deleted file mode 100644
index 7e9d19b..0000000
--- a/bindings/csharp/CMakeLists.txt
+++ /dev/null
@@ -1,70 +0,0 @@
-cmake_minimum_required(VERSION 2.8.7)
-project(libiio-sharp NONE)
-
-if (WIN32)
- set(MCS_EXECUTABLE_NAME csc)
-else()
- set(MCS_EXECUTABLE_NAME mcs)
-endif()
-
-find_program(MCS_EXECUTABLE
- NAMES ${MCS_EXECUTABLE_NAME}
- HINTS "C:/Windows/Microsoft.NET/Framework/v4.0.30319"
- PATHS ENV MCS_EXECUTABLE_PATH
- DOC "C# compiler")
-mark_as_advanced(MCS_EXECUTABLE)
-
-if (MCS_EXECUTABLE)
- option(CSHARP_BINDINGS "Install C# bindings" ON)
-
- if (CSHARP_BINDINGS)
- set(LIBIIO_CS_PC_IN "${CMAKE_CURRENT_SOURCE_DIR}/libiio-sharp.pc.cmakein")
- set(LIBIIO_CS_PC "${CMAKE_CURRENT_BINARY_DIR}/libiio-sharp-${VERSION}.pc")
- configure_file(${LIBIIO_CS_PC_IN} ${LIBIIO_CS_PC} @ONLY)
- if(NOT SKIP_INSTALL_ALL)
- install(FILES ${LIBIIO_CS_PC} DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
- endif()
-
- set(LIBIIO_CS_DLL_CONFIG_IN "${CMAKE_CURRENT_SOURCE_DIR}/libiio-sharp.dll.config.cmakein")
- set(LIBIIO_CS_DLL_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/libiio-sharp.dll.config")
- configure_file(${LIBIIO_CS_DLL_CONFIG_IN} ${LIBIIO_CS_DLL_CONFIG} @ONLY)
- if(NOT SKIP_INSTALL_ALL)
- install(FILES ${LIBIIO_CS_DLL_CONFIG} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cli/libiio-sharp-${VERSION})
- endif()
-
- set(LIBIIO_CS_VERSION ${VERSION}.0.0)
- set(LIBIIO_CS_INFO_IN ${CMAKE_CURRENT_SOURCE_DIR}/AssemblyInfo.cs.in)
- set(LIBIIO_CS_INFO ${CMAKE_CURRENT_BINARY_DIR}/AssemblyInfo.cs)
- configure_file(${LIBIIO_CS_INFO_IN} ${LIBIIO_CS_INFO} @ONLY)
-
- set(LIBIIO_CS_DLL "${CMAKE_CURRENT_BINARY_DIR}/libiio-sharp.dll")
- set(LIBIIO_CS_SOURCES
- ${CMAKE_CURRENT_SOURCE_DIR}/Attr.cs
- ${CMAKE_CURRENT_SOURCE_DIR}/Channel.cs
- ${CMAKE_CURRENT_SOURCE_DIR}/Context.cs
- ${CMAKE_CURRENT_SOURCE_DIR}/Device.cs
- ${CMAKE_CURRENT_SOURCE_DIR}/IOBuffer.cs
- ${CMAKE_CURRENT_SOURCE_DIR}/Trigger.cs
- ${LIBIIO_CS_INFO}
- )
-
- foreach(SRC ${LIBIIO_CS_SOURCES})
- file(TO_NATIVE_PATH ${SRC} TMP)
- set(LIBIIO_CS_SOURCES_REALPATH ${LIBIIO_CS_SOURCES_REALPATH} ${TMP})
- endforeach(SRC)
-
- file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/key.snk SIGN_KEY)
- file(TO_NATIVE_PATH ${LIBIIO_CS_DLL} LIBIIO_CS_DLL_OUT)
-
- add_custom_command(OUTPUT ${LIBIIO_CS_DLL}
- COMMAND ${MCS_EXECUTABLE} /target:library /out:${LIBIIO_CS_DLL_OUT} /debug /keyfile:${SIGN_KEY} ${LIBIIO_CS_SOURCES_REALPATH}
- DEPENDS ${LIBIIO_CS_SOURCES}
- )
-
- add_custom_target(libiio-sharp ALL DEPENDS ${LIBIIO_CS_DLL})
-
- if(NOT SKIP_INSTALL_ALL)
- install(FILES ${LIBIIO_CS_DLL} ${LIBIIO_CS_DLL}.mdb DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cli/libiio-sharp-${VERSION})
- endif()
- endif()
-endif()
diff --git a/bindings/csharp/Channel.cs b/bindings/csharp/Channel.cs
deleted file mode 100644
index 491a4ad..0000000
--- a/bindings/csharp/Channel.cs
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2015 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.
- *
- * */
-
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Runtime.InteropServices;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace iio
-{
- /// <summary><see cref="iio.Channel"/> class:
- /// Contains the representation of an input or output channel.</summary>
- public class Channel
- {
- private class ChannelAttr : Attr
- {
- private IntPtr chn;
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern int iio_channel_attr_read(IntPtr chn, [In()] string name, [Out()] StringBuilder val, uint len);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern int iio_channel_attr_write(IntPtr chn, [In()] string name, string val);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_channel_attr_get_filename(IntPtr chn, [In()] string attr);
-
- public ChannelAttr(IntPtr chn, string name) : base(name, Marshal.PtrToStringAnsi(iio_channel_attr_get_filename(chn, name)))
- {
- this.chn = chn;
- }
-
- public override string read()
- {
- StringBuilder builder = new StringBuilder(1024);
- int err = iio_channel_attr_read(chn, name, builder, (uint) builder.Capacity);
- if (err < 0)
- throw new Exception("Unable to read channel attribute " + err);
- return builder.ToString();
- }
-
- public override void write(string str)
- {
- int err = iio_channel_attr_write(chn, name, str);
- if (err < 0)
- throw new Exception("Unable to write channel attribute " + err);
- }
- }
-
-
- private IntPtr chn;
- private uint sample_size;
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_channel_get_id(IntPtr chn);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_channel_get_name(IntPtr chn);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern uint iio_channel_get_attrs_count(IntPtr chn);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_channel_get_attr(IntPtr chn, uint index);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- [return: MarshalAs(UnmanagedType.I1)]
- private static extern bool iio_channel_is_output(IntPtr chn);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- [return: MarshalAs(UnmanagedType.I1)]
- private static extern bool iio_channel_is_scan_element(IntPtr chn);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern void iio_channel_enable(IntPtr chn);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern void iio_channel_disable(IntPtr chn);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- [return: MarshalAs(UnmanagedType.I1)]
- private static extern bool iio_channel_is_enabled(IntPtr chn);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern uint iio_channel_read_raw(IntPtr chn, IntPtr buf, IntPtr dst, uint len);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern uint iio_channel_write_raw(IntPtr chn, IntPtr buf, IntPtr src, uint len);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern uint iio_channel_read(IntPtr chn, IntPtr buf, IntPtr dst, uint len);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern uint iio_channel_write(IntPtr chn, IntPtr buf, IntPtr src, uint len);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_channel_get_data_format(IntPtr chn);
-
- /// <summary>The name of this channel.</summary>
- public readonly string name;
-
- /// <summary>An identifier of this channel.</summary>
- /// <remarks>It is possible that two channels have the same ID,
- /// if one is an input channel and the other is an output channel.</remarks>
- public readonly string id;
-
- /// <summary>Contains <c>true</c> if the channel is an output channel,
- /// <c>false</c> otherwise.</summary>
- public readonly bool output;
-
- /// <summary>Contains <c>true</c> if the channel is a scan element,
- /// <c>false</c> otherwise.</summary>
- /// <remarks>If a channel is a scan element, then it is possible to enable it
- /// and use it for I/O operations.</remarks>
- public readonly bool scan_element;
-
- /// <summary>A <c>list</c> of all the attributes that this channel has.</summary>
- public readonly List<Attr> attrs;
-
- internal Channel(IntPtr chn)
- {
- this.chn = chn;
- attrs = new List<Attr>();
- sample_size = (uint)Marshal.ReadInt32(iio_channel_get_data_format(this.chn)) / 8;
- uint nb_attrs = iio_channel_get_attrs_count(chn);
-
- for (uint i = 0; i < nb_attrs; i++)
- attrs.Add(new ChannelAttr(this.chn, Marshal.PtrToStringAnsi(iio_channel_get_attr(chn, i))));
-
- IntPtr name_ptr = iio_channel_get_name(this.chn);
- if (name_ptr == IntPtr.Zero)
- name = "";
- else
- name = Marshal.PtrToStringAnsi(name_ptr);
-
- id = Marshal.PtrToStringAnsi(iio_channel_get_id(this.chn));
- output = iio_channel_is_output(this.chn);
- scan_element = iio_channel_is_scan_element(this.chn);
- }
-
- /// <summary>Enable the current channel, so that it can be used for I/O operations.</summary>
- public void enable()
- {
- iio_channel_enable(this.chn);
- }
-
- /// <summary>Disable the current channel.</summary>
- public void disable()
- {
- iio_channel_disable(this.chn);
- }
-
- /// <summary>Returns whether or not the channel has been enabled.</summary>
- public bool is_enabled()
- {
- return iio_channel_is_enabled(this.chn);
- }
-
- /// <summary>Extract the samples corresponding to this channel from the
- /// given <see cref="iio.IOBuffer"/> object.</summary>
- /// <param name="buffer">A valid instance of the <see cref="iio.IOBuffer"/> class.</param>
- /// <param name="raw">If set to <c>true</c>, the samples are not converted from their
- /// hardware format to their host format.</param>
- /// <returns>A <c>byte</c> array containing the extracted samples.</returns>
- /// <exception cref="System.Exception">The samples could not be read.</exception>
- public byte[] read(IOBuffer buffer, bool raw = false)
- {
- if (!is_enabled())
- throw new Exception("Channel must be enabled before the IOBuffer is instantiated");
- if (this.output)
- throw new Exception("Unable to read from output channel");
-
- byte[] array = new byte[(int) (buffer.samples_count * sample_size)];
- MemoryStream stream = new MemoryStream(array, true);
- GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned);
- IntPtr addr = handle.AddrOfPinnedObject();
- uint count;
-
- if (raw)
- count = iio_channel_read_raw(this.chn, buffer.buf, addr, buffer.samples_count * sample_size);
- else
- count = iio_channel_read(this.chn, buffer.buf, addr, buffer.samples_count * sample_size);
- handle.Free();
- stream.SetLength((long) count);
- return stream.ToArray();
-
- }
-
- /// <summary>
- /// Write the specified array of samples corresponding to this channel into the
- /// given <see cref="iio.IOBuffer"/> object.</summary>
- /// <param name="buffer">A valid instance of the <see cref="iio.IOBuffer"/> class.</param>
- /// <param name="array">A <c>byte</c> array containing the samples to write.</param>
- /// <param name="raw">If set to <c>true</c>, the samples are not converted from their
- /// host format to their native format.</param>
- /// <returns>The number of bytes written.</returns>
- /// <exception cref="System.Exception">The samples could not be written.</exception>
- public uint write(IOBuffer buffer, byte[] array, bool raw = false)
- {
- if (!is_enabled())
- throw new Exception("Channel must be enabled before the IOBuffer is instantiated");
- if (!this.output)
- throw new Exception("Unable to write to an input channel");
-
- GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned);
- IntPtr addr = handle.AddrOfPinnedObject();
- uint count;
-
- if (raw)
- count = iio_channel_write_raw(this.chn, buffer.buf, addr, (uint) array.Length);
- else
- count = iio_channel_write(this.chn, buffer.buf, addr, (uint) array.Length);
- handle.Free();
-
- return count;
- }
- }
-}
diff --git a/bindings/csharp/Context.cs b/bindings/csharp/Context.cs
deleted file mode 100644
index e5c478f..0000000
--- a/bindings/csharp/Context.cs
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2015 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.
- *
- * */
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.InteropServices;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace iio
-{
- public class Version
- {
- public readonly uint major;
- public readonly uint minor;
- public readonly string git_tag;
-
- internal Version(uint major, uint minor, string git_tag)
- {
- this.major = major;
- this.minor = minor;
- this.git_tag = git_tag;
- }
- }
-
- /// <summary><see cref="iio.Context"/> class:
- /// Contains the representation of an IIO context.</summary>
- public class Context : IDisposable
- {
- private IntPtr ctx;
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_create_network_context(
- [In()][MarshalAs(UnmanagedType.LPStr)] string hostname
- );
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_create_context_from_uri(
- [In()][MarshalAs(UnmanagedType.LPStr)] string uri
- );
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_create_default_context();
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern void iio_context_destroy(IntPtr ctx);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_context_get_name(IntPtr ctx);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_context_get_description(IntPtr ctx);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_context_get_xml(IntPtr ctx);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern void iio_library_get_version(ref uint major, ref uint minor, [Out()] StringBuilder git_tag);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern int iio_context_get_version(IntPtr ctx, ref uint major, ref uint minor, [Out()] StringBuilder git_tag);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern uint iio_context_get_devices_count(IntPtr ctx);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_context_get_device(IntPtr ctx, uint index);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- [return: MarshalAs(UnmanagedType.I1)]
- private static extern bool iio_device_is_trigger(IntPtr dev);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern int iio_context_set_timeout(IntPtr ctx, uint timeout_ms);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_context_clone(IntPtr ctx);
-
- /// <summary>A XML representation of the current context.</summary>
- public readonly string xml;
-
- /// <summary>The name of the current context.</summary>
- public readonly string name;
-
- /// <summary>Retrieve a human-readable information string about the current context.</summary>
- public readonly string description;
- public readonly Version library_version, backend_version;
-
- /// <summary>A <c>List</c> of all the IIO devices present on the current context.</summary>
- public readonly List<Device> devices;
-
- /// <summary>Initializes a new instance of the <see cref="iio.Context"/> class,
- /// using the provided URI. For compatibility with existing code, providing
- /// an IP address or a hostname here will automatically create a network
- /// context.</summary>
- /// <param name="uri">URI to use for the IIO context creation</param>
- /// <returns>an instance of the <see cref="iio.Context"/> class</returns>
- /// <exception cref="System.Exception">The IIO context could not be created.</exception>
- public Context(string uri) : this(getContextFromString(uri)) {}
-
- /// <summary>Initializes a new instance of the <see cref="iio.Context"/> class,
- /// using the local or the network backend of the IIO library.</summary>
- /// <remarks>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.</remarks>
- /// <exception cref="System.Exception">The IIO context could not be created.</exception>
- public Context() : this(iio_create_default_context()) {}
-
- private static IntPtr getContextFromString(string str)
- {
- IntPtr ptr = iio_create_context_from_uri(str);
- if (ptr == IntPtr.Zero)
- ptr = iio_create_network_context(str);
- return ptr;
- }
-
- private Context(IntPtr ctx)
- {
- this.ctx = ctx;
-
- if (ctx == IntPtr.Zero)
- throw new Exception("Unable to create IIO context");
-
- uint nb_devices = iio_context_get_devices_count(ctx);
-
- devices = new List<Device>();
- for (uint i = 0; i < nb_devices; i++)
- {
- IntPtr ptr = iio_context_get_device(ctx, i);
- if (iio_device_is_trigger(ptr))
- devices.Add(new Trigger(this, ptr));
- else
- devices.Add(new Device(this, ptr));
- }
-
- xml = Marshal.PtrToStringAnsi(iio_context_get_xml(ctx));
- name = Marshal.PtrToStringAnsi(iio_context_get_name(ctx));
- description = Marshal.PtrToStringAnsi(iio_context_get_description(ctx));
-
- uint major = 0;
- uint minor = 0;
- StringBuilder builder = new StringBuilder(8);
- iio_library_get_version(ref major, ref minor, builder);
- library_version = new Version(major, minor, builder.ToString());
-
- major = 0;
- minor = 0;
- builder.Clear();
- int err = iio_context_get_version(ctx, ref major, ref minor, builder);
- if (err < 0)
- throw new Exception("Unable to read backend version");
- backend_version = new Version(major, minor, builder.ToString());
- }
-
- ~Context()
- {
- if (ctx != IntPtr.Zero)
- Dispose(false);
- }
-
- /// <summary>Clone this instance.</summary>
- public Context clone()
- {
- return new Context(iio_context_clone(this.ctx));
- }
-
- /// <summary>Get the <see cref="iio.Device"/> object of the specified name.</summary>
- /// <param name="name">Name or ID of the device to look for</param>
- /// <exception cref="System.Exception">The IIO device with the specified
- /// name or ID could not be found in the current context.</exception>
- public Device get_device(string name)
- {
- foreach (Device each in devices) {
- if (each.name.CompareTo(name) == 0 ||
- each.id.CompareTo(name) == 0)
- return each;
- }
-
- throw new Exception("Device " + name + " not found");
- }
-
- /// <summary>Set a timeout for I/O operations.</summary>
- /// <param name="timeout">The timeout value, in milliseconds</param>
- /// <exception cref="System.Exception">The timeout could not be applied.</exception>
- public void set_timeout(uint timeout)
- {
- int ret = iio_context_set_timeout(ctx, timeout);
- if (ret < 0)
- throw new Exception("Unable to set timeout");
- }
-
- /// <summary>Releases all resource used by the <see cref="iio.Context"/> object.</summary>
- /// <remarks>Call <see cref="Dispose"/> when you are finished using the <see cref="iio.Context"/>. The
- /// <see cref="Dispose"/> method leaves the <see cref="iio.Context"/> in an unusable state. After calling
- /// <see cref="Dispose"/>, you must release all references to the <see cref="iio.Context"/> so the garbage
- /// collector can reclaim the memory that the <see cref="iio.Context"/> was occupying.</remarks>
- public void Dispose()
- {
- Dispose(true);
- }
-
- private void Dispose(bool clean)
- {
- if (ctx != IntPtr.Zero)
- {
- if (clean)
- GC.SuppressFinalize(this);
- iio_context_destroy(ctx);
- ctx = IntPtr.Zero;
- }
- }
- }
-}
diff --git a/bindings/csharp/Device.cs b/bindings/csharp/Device.cs
deleted file mode 100644
index 8d7fa82..0000000
--- a/bindings/csharp/Device.cs
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2015 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.
- *
- * */
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.InteropServices;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace iio
-{
- /// <summary><see cref="iio.Device"/> class:
- /// Contains the representation of an IIO device.</summary>
- public class Device
- {
- private class DeviceAttr : Attr
- {
- private IntPtr dev;
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern int iio_device_attr_read(IntPtr dev, [In()] string name, [Out()] StringBuilder val, uint len);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern int iio_device_attr_write(IntPtr dev, [In()] string name, [In()] string val);
-
- public DeviceAttr(IntPtr dev, string name) : base(name)
- {
- this.dev = dev;
- }
-
- public override string read()
- {
- StringBuilder builder = new StringBuilder(1024);
- int err = iio_device_attr_read(dev, name, builder, 1024);
- if (err < 0)
- throw new Exception("Unable to read device attribute " + err);
- return builder.ToString();
- }
-
- public override void write(string str)
- {
- int err = iio_device_attr_write(dev, name, str);
- if (err < 0)
- throw new Exception("Unable to write device attribute " + err);
- }
- }
-
- private class DeviceDebugAttr : Attr
- {
- private IntPtr dev;
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern int iio_device_debug_attr_read(IntPtr dev, [In()] string name, [Out()] StringBuilder val, uint len);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern int iio_device_debug_attr_write(IntPtr dev, [In()] string name, [In()] string val);
-
- public DeviceDebugAttr(IntPtr dev, string name) : base(name)
- {
- this.dev = dev;
- }
-
- public override string read()
- {
- StringBuilder builder = new StringBuilder(1024);
- int err = iio_device_debug_attr_read(dev, name, builder, 1024);
- if (err < 0)
- throw new Exception("Unable to read debug attribute " + err);
- return builder.ToString();
- }
-
- public override void write(string str)
- {
- int err = iio_device_debug_attr_write(dev, name, str);
- if (err < 0)
- throw new Exception("Unable to write debug attribute " + err);
- }
- }
-
- private Context ctx;
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_device_get_id(IntPtr dev);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_device_get_name(IntPtr dev);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern uint iio_device_get_channels_count(IntPtr dev);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_device_get_channel(IntPtr dev, uint index);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern uint iio_device_get_attrs_count(IntPtr dev);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern uint iio_device_get_debug_attrs_count(IntPtr dev);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_device_get_attr(IntPtr dev, uint index);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_device_get_debug_attr(IntPtr dev, uint index);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern int iio_device_get_trigger(IntPtr dev, IntPtr triggerptr);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern int iio_device_set_trigger(IntPtr dev, IntPtr trigger);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern int iio_device_get_sample_size(IntPtr dev);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern int iio_device_reg_write(IntPtr dev, uint addr, uint value);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern int iio_device_reg_read(IntPtr dev, uint addr, ref uint value);
-
- internal IntPtr dev;
-
- /// <summary>An identifier of this device.</summary>
- /// <remarks>The identifier is only valid in this IIO context</remarks>
- public readonly string id;
-
- /// <summary>The name of this device.</summary>
- public readonly string name;
-
- /// <summary>A <c>list</c> of all the attributes that this device has.</summary>
- public readonly List<Attr> attrs;
-
- /// <summary>A <c>list</c> of all the debug attributes that this device has.</summary>
- public readonly List<Attr> debug_attrs;
-
- /// <summary>A <c>list</c> of all the <see cref="iio.Channel"/> objects that this device possesses.</summary>
- public readonly List<Channel> channels;
-
- internal Device(Context ctx, IntPtr dev)
- {
- this.ctx = ctx;
- this.dev = dev;
- channels = new List<Channel>();
- attrs = new List<Attr>();
- debug_attrs = new List<Attr>();
-
- uint nb_channels = iio_device_get_channels_count(dev),
- nb_attrs = iio_device_get_attrs_count(dev),
- nb_debug_attrs = iio_device_get_debug_attrs_count(dev);
-
- for (uint i = 0; i < nb_channels; i++)
- channels.Add(new Channel(iio_device_get_channel(dev, i)));
-
- for (uint i = 0; i < nb_attrs; i++)
- attrs.Add(new DeviceAttr(dev, Marshal.PtrToStringAnsi(iio_device_get_attr(dev, i))));
- for (uint i = 0; i < nb_debug_attrs; i++)
- debug_attrs.Add(new DeviceDebugAttr(dev, Marshal.PtrToStringAnsi(iio_device_get_debug_attr(dev, i))));
-
- id = Marshal.PtrToStringAnsi(iio_device_get_id(dev));
-
- IntPtr name_ptr = iio_device_get_name(dev);
- if (name_ptr == IntPtr.Zero)
- name = "";
- else
- name = Marshal.PtrToStringAnsi(name_ptr);
- }
-
- /// <summary>Get the <see cref="iio.Channel"/> object of the specified name.</summary>
- /// <param name="name">Name or ID of the channel to look for</param>
- /// <exception cref="System.Exception">The IIO device with the specified
- /// name or ID could not be found in the current context.</exception>
- public Channel get_channel(string name)
- {
- foreach (Channel each in channels) {
- if (each.name.CompareTo(name) == 0 ||
- each.id.CompareTo(name) == 0)
- return each;
- }
-
- throw new Exception("Channel " + name + " not found");
- }
-
- /// <summary>Affect a trigger to this device.</summary>
- /// <param name="trig">A valid instance of the <see cref="iio.Trigger"/> class.</param>
- /// <exception cref="System.Exception">The trigger could not be set.</exception>
- public void set_trigger(Trigger trig)
- {
- int err = iio_device_set_trigger(this.dev, trig == null ? IntPtr.Zero : trig.dev);
- if (err < 0)
- throw new Exception("Unable to set trigger: err=" + err);
- }
-
- /// <summary>Get the current trigger affected to this device.</summary>
- /// <returns>An instance of the <see cref="iio.Trigger"/> class.</returns>
- /// <exception cref="System.Exception">The instance could not be retrieved.</exception>
- public Trigger get_trigger()
- {
- IntPtr ptr = (IntPtr)0;
- int err = iio_device_get_trigger(this.dev, ptr);
- if (err < 0)
- throw new Exception("Unable to get trigger: err=" + err);
-
- ptr = Marshal.ReadIntPtr(ptr);
-
- foreach (Trigger trig in ctx.devices) {
- if (trig.dev == ptr)
- return trig;
- }
-
- return null;
- }
-
- /// <summary>Get the current sample size of the device.</summary>
- /// <remarks>The sample size varies each time channels get enabled or disabled.</remarks>
- /// <exception cref="System.Exception">Internal error. Please report any bug.</exception>
- public uint get_sample_size()
- {
- int ret = iio_device_get_sample_size(dev);
- if (ret < 0)
- throw new Exception("Internal error. Please report any bug.");
- return (uint) ret;
- }
- /// <summary>Set a value to one register of this device.</summary>
- /// <param name="addr">The address of the register concerned.</param>
- /// <param name="value">The value that will be used for this register.</param>
- /// <exception cref="System.Exception">The register could not be written.</exception>
- public void reg_write(uint addr, uint value)
- {
- int err = iio_device_reg_write(dev, addr, value);
- if (err < 0)
- throw new Exception("Unable to write register");
- }
-
- /// <summary>Read the content of a register of this device.</summary>
- /// <param name="addr">The address of the register concerned.</param>
- /// <exception cref="System.Exception">The register could not be read.</exception>
- public uint reg_read(uint addr)
- {
- uint value = 0;
- int err = iio_device_reg_read(dev, addr, ref value);
- if (err < 0)
- throw new Exception("Unable to read register");
- return value;
- }
- }
-}
diff --git a/bindings/csharp/IOBuffer.cs b/bindings/csharp/IOBuffer.cs
deleted file mode 100644
index 1697f6e..0000000
--- a/bindings/csharp/IOBuffer.cs
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2015 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.
- *
- * */
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.InteropServices;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace iio
-{
- /// <summary><see cref="iio.IOBuffer"/> class:
- /// The class used for all I/O operations.</summary>
- public class IOBuffer : IDisposable
- {
- private bool circular_buffer_pushed;
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_device_create_buffer(IntPtr dev, uint samples_count,
- [MarshalAs(UnmanagedType.I1)] bool circular);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern void iio_buffer_destroy(IntPtr buf);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern int iio_buffer_refill(IntPtr buf);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern int iio_buffer_push_partial(IntPtr buf, uint samples_count);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_buffer_start(IntPtr buf);
-
- [DllImport("libiio.dll", CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr iio_buffer_end(IntPtr buf);
-
- internal IntPtr buf;
-
- /// <summary>The size of this buffer, in samples.</summary>
- public readonly uint samples_count;
-
- /// <summary>If <c>true</c>, the buffer is circular.</summary>
- public readonly bool circular;
-
- /// <summary>Initializes a new instance of the <see cref="iio.IOBuffer"/> class.</summary>
- /// <param name="dev">The <see cref="iio.Device"/> object that represents the device
- /// where the I/O operations will be performed.</param>
- /// <param name="samples_count">The size of the buffer, in samples.</param>
- /// <param name="circular">If set to <c>true</c>, the buffer is circular.</param>
- /// <exception cref="System.Exception">The buffer could not be created.</exception>
- public IOBuffer(Device dev, uint samples_count, bool circular = false)
- {
- this.samples_count = samples_count;
- this.circular = circular;
- this.circular_buffer_pushed = false;
-
- buf = iio_device_create_buffer(dev.dev, samples_count, circular);
- if (buf == IntPtr.Zero)
- throw new Exception("Unable to create buffer");
- }
-
- ~IOBuffer()
- {
- if (buf != IntPtr.Zero)
- Dispose(false);
- }
-
- /// <summary>Fetch a new set of samples from the hardware.</summary>
- /// <exception cref="System.Exception">The buffer could not be refilled.</exception>
- public void refill()
- {
- int err = iio_buffer_refill(this.buf);
- if (err < 0)
- throw new Exception("Unable to refill buffer: err=" + err);
- }
-
- /// <summary>Submit the samples contained in this buffer to the hardware.</summary>
- /// <exception cref="System.Exception">The buffer could not be pushed.</exception>
- public void push(uint samples_count)
- {
- if (circular && circular_buffer_pushed)
- throw new Exception("Circular buffer already pushed\n");
-
- int err = iio_buffer_push_partial(this.buf, samples_count);
- if (err < 0)
- throw new Exception("Unable to push buffer: err=" + err);
- circular_buffer_pushed = true;
- }
-
- public void push()
- {
- push(this.samples_count);
- }
-
- /// <summary>Releases all resource used by the <see cref="iio.IOBuffer"/> object.</summary>
- /// <remarks>Call <see cref="Dispose"/> when you are finished using the <see cref="iio.IOBuffer"/>. The
- /// <see cref="Dispose"/> method leaves the <see cref="iio.IOBuffer"/> in an unusable state. After calling
- /// <see cref="Dispose"/>, you must release all references to the <see cref="iio.IOBuffer"/> so the garbage
- /// collector can reclaim the memory that the <see cref="iio.IOBuffer"/> was occupying.</remarks>
- public void Dispose()
- {
- Dispose(true);
- }
-
- private void Dispose(bool clean)
- {
- if (buf != IntPtr.Zero)
- {
- if (clean)
- GC.SuppressFinalize(this);
- iio_buffer_destroy(buf);
- buf = IntPtr.Zero;
- }
- }
-
- /// <summary>Copy the given array of samples inside the <see cref="iio.IOBuffer"/> object.</summary>
- /// <param name="array">A <c>byte</c> array containing the samples that should be written.</param>
- /// <remarks>The number of samples written will not exceed the size of the buffer.</remarks>
- public void fill(byte[] array)
- {
- int length = (int) iio_buffer_end(buf) - (int) iio_buffer_start(buf);
- if (length > array.Length)
- length = array.Length;
- Marshal.Copy(array, 0, iio_buffer_start(buf), length);
- }
- }
-}
diff --git a/bindings/csharp/Trigger.cs b/bindings/csharp/Trigger.cs
deleted file mode 100644
index 4614143..0000000
--- a/bindings/csharp/Trigger.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2015 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.
- *
- * */
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.InteropServices;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace iio
-{
- /// <summary><see cref="iio.Trigger"/> class:
- /// Contains the representation of an IIO device that can act as a trigger.</summary>
- public class Trigger : Device
- {
- internal Trigger(Context ctx, IntPtr ptr) : base(ctx, ptr) { }
-
- /// <summary>Configure a new frequency for this trigger.</summary>
- /// <exception cref="System.Exception">The new frequency could not be set.</exception>
- public void set_rate(ulong rate)
- {
- foreach (Attr each in attrs)
- if (each.name.Equals("frequency"))
- {
- each.write((long) rate);
- return;
- }
- throw new Exception("Trigger has no frequency?");
- }
-
- /// <summary>Get the currently configured frequency of this trigger.</summary>
- /// <exception cref="System.Exception">The configured frequency could not be obtained.</exception>
- public ulong get_rate()
- {
- foreach (Attr each in attrs)
- if (each.name.Equals("frequency"))
- return (ulong) each.read_long();
- throw new Exception("Trigger has no frequency?");
- }
-
- public new void set_trigger(Trigger trig)
- {
- throw new InvalidComObjectException("Device is already a trigger");
- }
-
- public new Trigger get_trigger()
- {
- throw new InvalidComObjectException("Device is already a trigger");
- }
- }
-}
diff --git a/bindings/csharp/examples/ExampleProgram.cs b/bindings/csharp/examples/ExampleProgram.cs
deleted file mode 100644
index f33e381..0000000
--- a/bindings/csharp/examples/ExampleProgram.cs
+++ /dev/null
@@ -1,82 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using iio;
-
-namespace IIOCSharp
-{
- class ExampleProgram
- {
- static void Main(string[] args)
- {
- Context ctx = new Context("10.44.2.241");
- if (ctx == null)
- {
- Console.WriteLine("Unable to create IIO context");
- return;
- }
-
- Console.WriteLine("IIO context created: " + ctx.name);
- Console.WriteLine("IIO context description: " + ctx.description);
-
- Console.WriteLine("IIO context has " + ctx.devices.Count + " devices:");
- foreach (Device dev in ctx.devices) {
- Console.WriteLine("\t" + dev.id + ": " + dev.name);
-
- if (dev is Trigger)
- {
- Console.WriteLine("Found trigger! Rate=" + ((Trigger) dev).get_rate());
- }
-
- Console.WriteLine("\t\t" + dev.channels.Count + " channels found:");
-
- foreach (Channel chn in dev.channels)
- {
- string type = "input";
- if (chn.output)
- type = "output";
- Console.WriteLine("\t\t\t" + chn.id + ": " + chn.name + " (" + type + ")");
-
- if (chn.attrs.Count == 0)
- continue;
-
- Console.WriteLine("\t\t\t" + chn.attrs.Count + " channel-specific attributes found:");
- foreach (Attr attr in chn.attrs)
- {
- Console.WriteLine("\t\t\t\t" + attr.name);
- if (attr.name.CompareTo("frequency") == 0)
- {
- Console.WriteLine("Attribute content: " + attr.read());
- }
- }
-
- }
-
- /* If we find cf-ad9361-lpc, try to read a few bytes from the first channel */
- if (dev.name.CompareTo("cf-ad9361-lpc") == 0)
- {
- Channel chn = dev.channels[0];
- chn.enable();
- IOBuffer buf = new IOBuffer(dev, 0x8000);
- buf.refill();
-
- Console.WriteLine("Read " + chn.read(buf).Length + " bytes from hardware");
- buf.Dispose();
- }
-
- if (dev.attrs.Count == 0)
- continue;
-
- Console.WriteLine("\t\t" + dev.attrs.Count + " device-specific attributes found:");
- foreach (Attr attr in dev.attrs)
- Console.WriteLine("\t\t\t" + attr.name);
-
- }
-
- /* Wait for user input */
- Console.ReadLine();
- }
- }
-}
diff --git a/bindings/csharp/key.snk b/bindings/csharp/key.snk
deleted file mode 100644
index fc21149..0000000
--- a/bindings/csharp/key.snk
+++ /dev/null
Binary files differ
diff --git a/bindings/csharp/libiio-sharp.dll.config.cmakein b/bindings/csharp/libiio-sharp.dll.config.cmakein
deleted file mode 100644
index c9ef9bb..0000000
--- a/bindings/csharp/libiio-sharp.dll.config.cmakein
+++ /dev/null
@@ -1,3 +0,0 @@
-<configuration>
- <dllmap dll="libiio.dll" target="libiio.so.@LIBIIO_VERSION_MAJOR@"/>
-</configuration>
diff --git a/bindings/csharp/libiio-sharp.pc.cmakein b/bindings/csharp/libiio-sharp.pc.cmakein
deleted file mode 100644
index 5e6fd22..0000000
--- a/bindings/csharp/libiio-sharp.pc.cmakein
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@CMAKE_INSTALL_PREFIX@
-exec_prefix=@CMAKE_INSTALL_PREFIX@
-libdir=@CMAKE_INSTALL_PREFIX@/lib
-
-Name: libiio-cs
-Description: CLI bindings for libiio
-Version: @VERSION@
-
-Requires:
-Libs: -r:${libdir}/cli/libiio-sharp-@VERSION@/libiio-sharp.dll
diff --git a/bindings/matlab/CMakeLists.txt b/bindings/matlab/CMakeLists.txt
deleted file mode 100644
index 4eea7d5..0000000
--- a/bindings/matlab/CMakeLists.txt
+++ /dev/null
@@ -1,26 +0,0 @@
-find_program(
- MATLAB_EXECUTABLE
- NAMES matlab
- DOC "Matlab main program"
-)
-mark_as_advanced(MATLAB_EXECUTABLE)
-
-option(WITH_MATLAB_BINDINGS_API "Enable MATLAB bindings API" ON)
-
-if (MATLAB_EXECUTABLE AND NOT SKIP_INSTALL_ALL)
- option(MATLAB_BINDINGS "Install MATLAB bindings" ON)
-
- if (MATLAB_BINDINGS)
- install(
- DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
- DESTINATION "${CMAKE_INSTALL_PREFIX}/share/libiio"
- PATTERN "CMakeLists.txt" EXCLUDE
- )
- install(
- CODE "execute_process(
- COMMAND ${MATLAB_EXECUTABLE} -nodesktop
- -nodisplay -r \"cd('${CMAKE_INSTALL_PREFIX}/share/libiio/matlab');iio_installer_script;exit;\"
- OUTPUT_QUIET)")
- set(WITH_MATLAB_BINDINGS_API ON CACHE BOOL "" FORCE)
- endif()
-endif()
diff --git a/bindings/matlab/iio-wrapper.h b/bindings/matlab/iio-wrapper.h
deleted file mode 100644
index ce2b046..0000000
--- a/bindings/matlab/iio-wrapper.h
+++ /dev/null
@@ -1,46 +0,0 @@
-#ifndef MATLAB_LOADLIBRARY
-#define MATLAB_LOADLIBRARY
-#include <iio.h>
-
-#ifndef __api
-#define __api
-#endif
-
-struct iio_scan_block;
-
-/** @brief Create a scan block
-* @param backend A NULL-terminated string containing the backend to use for
-* scanning. If NULL, all the available backends are used.
-* @param flags Unused for now. Set to 0.
-* @return on success, a pointer to a iio_scan_block structure
-* @return On failure, NULL is returned and errno is set appropriately */
-__api struct iio_scan_block * iio_create_scan_block(
- const char *backend, unsigned int flags);
-
-
-/** @brief Destroy the given scan block
-* @param ctx A pointer to an iio_scan_block structure
-*
-* <b>NOTE:</b> After that function, the iio_scan_block pointer shall be invalid. */
-__api void iio_scan_block_destroy(struct iio_scan_block *blk);
-
-
-/** @brief Enumerate available contexts via scan block
-* @param blk A pointer to a iio_scan_block structure.
-* @returns On success, the number of contexts found.
-* @returns On failure, a negative error number.
-*/
-__api ssize_t iio_scan_block_scan(struct iio_scan_block *blk);
-
-
-/** @brief Get the iio_context_info for a particular context
-* @param blk A pointer to an iio_scan_block structure
-* @param index The index corresponding to the context.
-* @return A pointer to the iio_context_info for the context
-* @returns On success, a pointer to the specified iio_context_info
-* @returns On failure, NULL is returned and errno is set appropriately
-*/
-__api struct iio_context_info *iio_scan_block_get_info(
- struct iio_scan_block *blk, unsigned int index);
-
-#endif
diff --git a/bindings/matlab/iio_installer_script.m b/bindings/matlab/iio_installer_script.m
deleted file mode 100644
index 1276729..0000000
--- a/bindings/matlab/iio_installer_script.m
+++ /dev/null
@@ -1,17 +0,0 @@
-function installer_script(varargin)
- if nargin > 0
- install = varargin{1}; % use the command line arguement
- else
- install = true; % assume install
- end
- thisDir = fileparts(mfilename('fullpath')); % path to this script
-
- if install
- pathfunc = @addpath; % add paths for installation
- else
- pathfunc = @rmpath; % remove paths for uninstall
- end
-
- pathfunc(thisDir);
- savepath;
-end
diff --git a/bindings/matlab/iio_sys_obj.m b/bindings/matlab/iio_sys_obj.m
deleted file mode 100644
index 1f8380f..0000000
--- a/bindings/matlab/iio_sys_obj.m
+++ /dev/null
@@ -1,474 +0,0 @@
-% Copyright 2014-15(c) Analog Devices, Inc.
-%
-% All rights reserved.
-%
-% Redistribution and use in source and binary forms, with or without modification,
-% are permitted provided that the following conditions are met:
-% - Redistributions of source code must retain the above copyright
-% notice, this list of conditions and the following disclaimer.
-% - Redistributions in binary form must reproduce the above copyright
-% notice, this list of conditions and the following disclaimer in
-% the documentation and/or other materials provided with the
-% distribution.
-% - Neither the name of Analog Devices, Inc. nor the names of its
-% contributors may be used to endorse or promote products derived
-% from this software without specific prior written permission.
-% - The use of this software may or may not infringe the patent rights
-% of one or more patent holders. This license does not release you
-% from the requirement that you obtain separate licenses from these
-% patent holders to use this software.
-% - Use of the software either in source or binary form or filter designs
-% resulting from the use of this software, must be connected to, run
-% on or loaded to an Analog Devices Inc. component.
-%
-% THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
-% INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A
-% PARTICULAR PURPOSE ARE DISCLAIMED.
-%
-% IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-% EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY
-% RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-% BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-% STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
-% THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-classdef iio_sys_obj < matlab.System & matlab.system.mixin.Propagates ...
- & matlab.system.mixin.CustomIcon
- % iio_sys_obj System Object block for IIO devices
-
- properties (Nontunable)
- % Public, non-tunable properties.
-
- %ip_address IP address
- ip_address = '';
-
- %dev_name Device name
- dev_name = '';
-
- %in_ch_no Number of input data channels
- in_ch_no = 0;
-
- %in_ch_size Input data channel size [samples]
- in_ch_size = 8192;
-
- %out_ch_no Number of output data channels
- out_ch_no = 0;
-
- %out_ch_size Output data channel size [samples]
- out_ch_size = 8192;
- end
-
- properties (Access = protected)
- % Protected class properties.
-
- %iio_dev_cfg Device configuration structure
- iio_dev_cfg = [];
- end
-
- properties (Access = private)
- % Private class properties.
-
- %libiio_data_in_dev libiio IIO interface object for the input data device
- libiio_data_in_dev = {};
-
- %libiio_data_out_dev libiio IIO interface object for the output data device
- libiio_data_out_dev = {};
-
- %libiio_ctrl_dev libiio IIO interface object for the control device
- libiio_ctrl_dev = {};
-
- %sys_obj_initialized Holds the initialization status of the system object
- sys_obj_initialized = 0;
- end
-
- properties (DiscreteState)
- % Discrete state properties.
-
- %num_cfg_in Numeric type input control channels data
- num_cfg_in;
-
- %str_cfg_in String type input control channels data
- str_cfg_in;
- end
-
- methods
- %% Constructor
- function obj = iio_sys_obj(varargin)
- % Construct the libiio interface objects
- obj.libiio_data_in_dev = libiio_if();
- obj.libiio_data_out_dev = libiio_if();
- obj.libiio_ctrl_dev = libiio_if();
-
- % Support name-value pair arguments when constructing the object.
- setProperties(obj,nargin,varargin{:});
- end
- end
-
- methods (Access = protected)
- %% Utility functions
-
- function config = getObjConfig(obj)
- % Read the selected device configuration
-
- % Open the configuration file
- fname = sprintf('%s.cfg', obj.dev_name);
- fp_cfg = fopen(fname);
- if(fp_cfg < 0)
- config = {};
- return;
- end
-
- % Build the object configuration structure
- config = struct('data_in_device', '',... % Pointer to the data input device
- 'data_out_device', '',... % Pointer to the data output device
- 'ctrl_device', '',... % Pointer to the control device
- 'cfg_ch', [],... % Configuration channels list
- 'mon_ch', []); % Monitoring channels list
-
- % Build the configuration/monitoring channels structure
- ch_cfg = struct('port_name', '',... % Name of the port to be displayed on the object block
- 'port_attr', '',... % Associated device attribute name
- 'ctrl_dev_name', '',... % Control device name
- 'ctrl_dev', 0); % Pointer to the control device object
-
- % Read the object's configuration
- while(~feof(fp_cfg))
- line = fgets(fp_cfg);
- if(strfind(line,'#'))
- continue;
- end
- if(~isempty(strfind(line, 'channel')))
- % Get the associated configuration/monitoring channels
- idx = strfind(line, '=');
- line = line(idx+1:end);
- line = strsplit(line, ',');
- ch_cfg.port_name = strtrim(line{1});
- ch_cfg.port_attr = strtrim(line{3});
- if(length(line) > 4)
- ch_cfg.ctrl_dev_name = strtrim(line{4});
- else
- ch_cfg.ctrl_dev_name = 'ctrl_device';
- end
- if(strcmp(strtrim(line{2}), 'IN'))
- config.cfg_ch = [config.cfg_ch ch_cfg];
- elseif(strcmp(strtrim(line{2}), 'OUT'))
- config.mon_ch = [config.mon_ch ch_cfg];
- end
- elseif(~isempty(strfind(line, 'data_in_device')))
- % Get the associated data input device
- idx = strfind(line, '=');
- tmp = line(idx+1:end);
- tmp = strtrim(tmp);
- config.data_in_device = tmp;
- elseif(~isempty(strfind(line, 'data_out_device')))
- % Get the associated data output device
- idx = strfind(line, '=');
- tmp = line(idx+1:end);
- tmp = strtrim(tmp);
- config.data_out_device = tmp;
- elseif(~isempty(strfind(line, 'ctrl_device')))
- % Get the associated control device
- idx = strfind(line, '=');
- tmp = line(idx+1:end);
- tmp = strtrim(tmp);
- config.ctrl_device = tmp;
- end
- end
- fclose(fp_cfg);
- end
-
- end
-
- methods (Access = protected)
- %% Common functions
- function setupImpl(obj)
- % Implement tasks that need to be performed only once.
-
- % Set the initialization status to fail
- obj.sys_obj_initialized = 0;
-
- % Read the object's configuration from the associated configuration file
- obj.iio_dev_cfg = getObjConfig(obj);
- if(isempty(obj.iio_dev_cfg))
- msgbox('Could not read device configuration!', 'Error','error');
- return;
- end
-
- % Initialize discrete-state properties.
- obj.num_cfg_in = zeros(1, length(obj.iio_dev_cfg.cfg_ch));
- obj.str_cfg_in = zeros(length(obj.iio_dev_cfg.cfg_ch), 64);
-
- % Initialize the libiio data input device
- if(obj.in_ch_no ~= 0)
- [ret, err_msg, msg_log] = init(obj.libiio_data_in_dev, obj.ip_address, ...
- obj.iio_dev_cfg.data_in_device, 'OUT', ...
- obj.in_ch_no, obj.in_ch_size);
- fprintf('%s', msg_log);
- if(ret < 0)
- msgbox(err_msg, 'Error','error');
- return;
- end
- end
-
- % Initialize the libiio data output device
- if(obj.out_ch_no ~= 0)
- [ret, err_msg, msg_log] = init(obj.libiio_data_out_dev, obj.ip_address, ...
- obj.iio_dev_cfg.data_out_device, 'IN', ...
- obj.out_ch_no, obj.out_ch_size);
- fprintf('%s', msg_log);
- if(ret < 0)
- msgbox(err_msg, 'Error','error');
- return;
- end
- end
-
- % Initialize the libiio control device
- if(~isempty(obj.iio_dev_cfg.ctrl_device))
- [ret, err_msg, msg_log] = init(obj.libiio_ctrl_dev, obj.ip_address, ...
- obj.iio_dev_cfg.ctrl_device, '', ...
- 0, 0);
- fprintf('%s', msg_log);
- if(ret < 0)
- msgbox(err_msg, 'Error','error');
- return;
- end
- end
-
- % Assign the control device for each monitoring channel
- for i = 1 : length(obj.iio_dev_cfg.mon_ch)
- if(strcmp(obj.iio_dev_cfg.mon_ch(i).ctrl_dev_name, 'data_in_device'))
- obj.iio_dev_cfg.mon_ch(i).ctrl_dev = obj.libiio_data_in_dev;
- elseif(strcmp(obj.iio_dev_cfg.mon_ch(i).ctrl_dev_name, 'data_out_device'))
- obj.iio_dev_cfg.mon_ch(i).ctrl_dev = obj.libiio_data_out_dev;
- else
- obj.iio_dev_cfg.mon_ch(i).ctrl_dev = obj.libiio_ctrl_dev;
- end
- end
-
- % Assign the control device for each configuration channel
- for i = 1 : length(obj.iio_dev_cfg.cfg_ch)
- if(strcmp(obj.iio_dev_cfg.cfg_ch(i).ctrl_dev_name, 'data_in_device'))
- obj.iio_dev_cfg.cfg_ch(i).ctrl_dev = obj.libiio_data_in_dev;
- elseif(strcmp(obj.iio_dev_cfg.cfg_ch(i).ctrl_dev_name, 'data_out_device'))
- obj.iio_dev_cfg.cfg_ch(i).ctrl_dev = obj.libiio_data_out_dev;
- else
- obj.iio_dev_cfg.cfg_ch(i).ctrl_dev = obj.libiio_ctrl_dev;
- end
- end
-
- % Set the initialization status to success
- obj.sys_obj_initialized = 1;
- end
-
- function releaseImpl(obj)
- % Release any resources used by the system object.
- obj.iio_dev_cfg = {};
- delete(obj.libiio_data_in_dev);
- delete(obj.libiio_data_out_dev);
- delete(obj.libiio_ctrl_dev);
- end
-
- function varargout = stepImpl(obj, varargin)
- % Implement the system object's processing flow.
- varargout = cell(1, obj.out_ch_no + length(obj.iio_dev_cfg.mon_ch));
- if(obj.sys_obj_initialized == 0)
- return;
- end
-
- % Implement the device configuration flow
- for i = 1 : length(obj.iio_dev_cfg.cfg_ch)
- if(~isempty(varargin{i + obj.in_ch_no}))
- if(length(varargin{i + obj.in_ch_no}) == 1)
- new_data = (varargin{i + obj.in_ch_no} ~= obj.num_cfg_in(i));
- else
- new_data = ~strncmp(char(varargin{i + obj.in_ch_no}'), char(obj.str_cfg_in(i,:)), length(varargin{i + obj.in_ch_no}));
- end
- if(new_data == 1)
- if(length(varargin{i + obj.in_ch_no}) == 1)
- obj.num_cfg_in(i) = varargin{i + obj.in_ch_no};
- str = num2str(obj.num_cfg_in(i));
- else
- for j = 1:length(varargin{i + obj.in_ch_no})
- obj.str_cfg_in(i,j) = varargin{i + obj.in_ch_no}(j);
- end
- obj.str_cfg_in(i,j+1) = 0;
- str = char(obj.str_cfg_in(i,:));
- end
- writeAttributeString(obj.iio_dev_cfg.cfg_ch(i).ctrl_dev, obj.iio_dev_cfg.cfg_ch(i).port_attr, str);
- end
- end
- end
-
- % Implement the data transmit flow
- writeData(obj.libiio_data_in_dev, varargin);
-
- % Implement the data capture flow
- [~, data] = readData(obj.libiio_data_out_dev);
- for i = 1 : obj.out_ch_no
- varargout{i} = data{i};
- end
-
- % Implement the parameters monitoring flow
- for i = 1 : length(obj.iio_dev_cfg.mon_ch)
- [~, val] = readAttributeDouble(obj.iio_dev_cfg.mon_ch(i).ctrl_dev, obj.iio_dev_cfg.mon_ch(i).port_attr);
- varargout{obj.out_ch_no + i} = val;
- end
-
-
- end
-
- function resetImpl(obj)
- % Initialize discrete-state properties.
- obj.num_cfg_in = zeros(1, length(obj.iio_dev_cfg.cfg_ch));
- obj.str_cfg_in = zeros(length(obj.iio_dev_cfg.cfg_ch), 64);
- end
-
- function num = getNumInputsImpl(obj)
- % Get number of inputs.
- num = obj.in_ch_no;
-
- config = getObjConfig(obj);
- if(~isempty(config))
- num = num + length(config.cfg_ch);
- end
- end
-
- function varargout = getInputNamesImpl(obj)
- % Get input names
-
- % Get the number of input data channels
- data_ch_no = obj.in_ch_no;
-
- % Get number of control channels
- cfg_ch_no = 0;
- config = getObjConfig(obj);
- if(~isempty(config))
- cgf_ch_no = length(config.cfg_ch);
- end
-
- if(data_ch_no + cgf_ch_no ~= 0)
- varargout = cell(1, data_ch_no + cgf_ch_no);
- for i = 1 : data_ch_no
- varargout{i} = sprintf('DATA_IN%d', i);
- end
- for i = data_ch_no + 1 : data_ch_no + cgf_ch_no
- varargout{i} = config.cfg_ch(i - data_ch_no).port_name;
- end
- else
- varargout = {};
- end
- end
-
- function num = getNumOutputsImpl(obj)
- % Get number of outputs.
- num = obj.out_ch_no;
-
- config = getObjConfig(obj);
- if(~isempty(config))
- num = num + length(config.mon_ch);
- end
- end
-
- function varargout = getOutputNamesImpl(obj)
- % Get output names
-
- % Get the number of output data channels
- data_ch_no = obj.out_ch_no;
-
- % Get number of monitoring channels
- mon_ch_no = 0;
- config = getObjConfig(obj);
- if(~isempty(config))
- mon_ch_no = length(config.mon_ch);
- end
-
- if(data_ch_no + mon_ch_no ~= 0)
- varargout = cell(1, data_ch_no + mon_ch_no);
- for i = 1 : data_ch_no
- varargout{i} = sprintf('DATA_OUT%d', i);
- end
- for i = data_ch_no + 1 : data_ch_no + mon_ch_no
- varargout{i} = config.mon_ch(i - data_ch_no).port_name;
- end
- else
- varargout = {};
- end
- end
-
- function varargout = isOutputFixedSizeImpl(obj)
- % Get outputs fixed size.
- varargout = cell(1, getNumOutputs(obj));
- for i = 1 : getNumOutputs(obj)
- varargout{i} = true;
- end
- end
-
- function varargout = getOutputDataTypeImpl(obj)
- % Get outputs data types.
- varargout = cell(1, getNumOutputs(obj));
- for i = 1 : getNumOutputs(obj)
- varargout{i} = 'double';
- end
- end
-
- function varargout = isOutputComplexImpl(obj)
- % Get outputs data types.
- varargout = cell(1, getNumOutputs(obj));
- for i = 1 : getNumOutputs(obj)
- varargout{i} = false;
- end
- end
-
- function varargout = getOutputSizeImpl(obj)
- % Implement if input size does not match with output size.
- varargout = cell(1, getNumOutputs(obj));
- for i = 1:obj.out_ch_no
- varargout{i} = [obj.out_ch_size 1];
- end
- for i = obj.out_ch_no + 1 : length(varargout)
- varargout{i} = [1 1];
- end
- end
-
- function icon = getIconImpl(obj)
- % Define a string as the icon for the System block in Simulink.
- if(~isempty(obj.dev_name))
- icon = obj.dev_name;
- else
- icon = mfilename('class');
- end
- end
-
- %% Backup/restore functions
- function s = saveObjectImpl(obj)
- % Save private, protected, or state properties in a
- % structure s. This is necessary to support Simulink
- % features, such as SimState.
- end
-
- function loadObjectImpl(obj, s, wasLocked)
- % Read private, protected, or state properties from
- % the structure s and assign it to the object obj.
- end
-
- %% Simulink functions
- function z = getDiscreteStateImpl(obj)
- % Return structure of states with field names as
- % DiscreteState properties.
- z = struct([]);
- end
- end
-
- methods(Static, Access = protected)
- %% Simulink customization functions
- function header = getHeaderImpl(obj)
- % Define header for the System block dialog box.
- header = matlab.system.display.Header(mfilename('class'));
- end
-
- function group = getPropertyGroupsImpl(obj)
- % Define section for properties in System block dialog box.
- group = matlab.system.display.Section(mfilename('class'));
- end
- end
-end
diff --git a/bindings/matlab/iio_sys_obj_matlab.m b/bindings/matlab/iio_sys_obj_matlab.m
deleted file mode 100644
index 572ec03..0000000
--- a/bindings/matlab/iio_sys_obj_matlab.m
+++ /dev/null
@@ -1,350 +0,0 @@
-% Copyright 2014(c) Analog Devices, Inc.
-%
-% All rights reserved.
-%
-% Redistribution and use in source and binary forms, with or without modification,
-% are permitted provided that the following conditions are met:
-% - Redistributions of source code must retain the above copyright
-% notice, this list of conditions and the following disclaimer.
-% - Redistributions in binary form must reproduce the above copyright
-% notice, this list of conditions and the following disclaimer in
-% the documentation and/or other materials provided with the
-% distribution.
-% - Neither the name of Analog Devices, Inc. nor the names of its
-% contributors may be used to endorse or promote products derived
-% from this software without specific prior written permission.
-% - The use of this software may or may not infringe the patent rights
-% of one or more patent holders. This license does not release you
-% from the requirement that you obtain separate licenses from these
-% patent holders to use this software.
-% - Use of the software either in source or binary form or filter designs
-% resulting from the use of this software, must be connected to, run
-% on or loaded to an Analog Devices Inc. component.
-%
-% THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
-% INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A
-% PARTICULAR PURPOSE ARE DISCLAIMED.
-%
-% IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-% EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY
-% RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-% BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-% STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
-% THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-classdef iio_sys_obj_matlab
- % iio_sys_obj System Object block for IIO devices
-
- properties (Access = public)
- % Public, non-tunable properties.
-
- %ip_address IP address
- ip_address = '';
-
- %dev_name Device name
- dev_name = '';
-
- %in_ch_no Number of input data channels
- in_ch_no = 0;
-
- %in_ch_size Input data channel size [samples]
- in_ch_size = 8192;
-
- %out_ch_no Number of output data channels
- out_ch_no = 0;
-
- %out_ch_size Output data channel size [samples]
- out_ch_size = 8192;
- end
-
- properties (Access = public)
- % Protected class properties.
-
- %iio_dev_cfg Device configuration structure
- iio_dev_cfg = [];
- end
-
- properties (Access = private)
- % Private class properties.
-
- %libiio_data_in_dev libiio IIO interface object for the input data device
- libiio_data_in_dev = {};
-
- %libiio_data_out_dev libiio IIO interface object for the output data device
- libiio_data_out_dev = {};
-
- %libiio_ctrl_dev libiio IIO interface object for the control device
- libiio_ctrl_dev = {};
-
- %sys_obj_initialized Holds the initialization status of the system object
- sys_obj_initialized = 0;
- end
-
- properties (Access = private)
- % Discrete state properties.
-
- %num_cfg_in Numeric type input control channels data
- num_cfg_in;
-
- %str_cfg_in String type input control channels data
- str_cfg_in;
- end
-
- methods
- %% Constructor
- function obj = iio_sys_obj_matlab(varargin)
- % Construct the libiio interface objects
- obj.libiio_data_in_dev = libiio_if();
- obj.libiio_data_out_dev = libiio_if();
- obj.libiio_ctrl_dev = libiio_if();
- end
- end
-
- methods (Access = protected)
- %% Utility functions
-
- function config = getObjConfig(obj)
- % Read the selected device configuration
-
- % Open the configuration file
- fname = sprintf('%s.cfg', obj.dev_name);
- fp_cfg = fopen(fname);
- if(fp_cfg < 0)
- config = {};
- return;
- end
-
- % Build the object configuration structure
- config = struct('data_in_device', '',... % Pointer to the data input device
- 'data_out_device', '',... % Pointer to the data output device
- 'ctrl_device', '',... % Pointer to the control device
- 'cfg_ch', [],... % Configuration channels list
- 'mon_ch', [],... % Monitoring channels list
- 'in_ch_names', [],... % Configuration channels names
- 'out_ch_names', []); % Monitoring channels names
- config.in_ch_names = {};
- config.out_ch_names = {};
-
- % Build the configuration/monitoring channels structure
- ch_cfg = struct('port_name', '',... % Name of the port to be displayed on the object block
- 'port_attr', '',... % Associated device attribute name
- 'ctrl_dev_name', '',... % Control device name
- 'ctrl_dev', 0); % Pointer to the control device object
-
- % Read the object's configuration
- while(~feof(fp_cfg))
- line = fgets(fp_cfg);
- if(strfind(line,'#'))
- continue;
- end
- if(~isempty(strfind(line, 'channel')))
- % Get the associated configuration/monitoring channels
- idx = strfind(line, '=');
- line = line(idx+1:end);
- line = strsplit(line, ',');
- ch_cfg.port_name = strtrim(line{1});
- ch_cfg.port_attr = strtrim(line{3});
- if(length(line) > 4)
- ch_cfg.ctrl_dev_name = strtrim(line{4});
- else
- ch_cfg.ctrl_dev_name = 'ctrl_device';
- end
- if(strcmp(strtrim(line{2}), 'IN'))
- config.cfg_ch = [config.cfg_ch ch_cfg];
- config.in_ch_names = [config.in_ch_names ch_cfg.port_name];
- elseif(strcmp(strtrim(line{2}), 'OUT'))
- config.mon_ch = [config.mon_ch ch_cfg];
- config.out_ch_names = [config.out_ch_names ch_cfg.port_name];
- end
- elseif(~isempty(strfind(line, 'data_in_device')))
- % Get the associated data input device
- idx = strfind(line, '=');
- tmp = line(idx+1:end);
- tmp = strtrim(tmp);
- config.data_in_device = tmp;
- elseif(~isempty(strfind(line, 'data_out_device')))
- % Get the associated data output device
- idx = strfind(line, '=');
- tmp = line(idx+1:end);
- tmp = strtrim(tmp);
- config.data_out_device = tmp;
- elseif(~isempty(strfind(line, 'ctrl_device')))
- % Get the associated control device
- idx = strfind(line, '=');
- tmp = line(idx+1:end);
- tmp = strtrim(tmp);
- config.ctrl_device = tmp;
- end
- end
- fclose(fp_cfg);
- end
-
- end
-
- methods (Access = public)
- %% Helper functions
- function ret = getInChannel(obj, channelName)
- % Returns the index of a named input channel
- ret = obj.in_ch_no + find(strcmp(obj.iio_dev_cfg.in_ch_names, channelName));
- end
-
- function ret = getOutChannel(obj, channelName)
- % Returns the index of a named output channel
- ret = obj.out_ch_no + find(strcmp(obj.iio_dev_cfg.out_ch_names, channelName));
- end
-
- %% Common functions
- function ret = setupImpl(obj)
- % Implement tasks that need to be performed only once.
-
- % Set the initialization status to fail
- obj.sys_obj_initialized = 0;
-
- % Read the object's configuration from the associated configuration file
- obj.iio_dev_cfg = getObjConfig(obj);
- if(isempty(obj.iio_dev_cfg))
- msgbox('Could not read device configuration!', 'Error','error');
- return;
- end
-
- % Initialize discrete-state properties.
- obj.num_cfg_in = zeros(1, length(obj.iio_dev_cfg.cfg_ch));
- obj.str_cfg_in = zeros(length(obj.iio_dev_cfg.cfg_ch), 64);
-
- % Initialize the libiio data input device
- if(obj.in_ch_no ~= 0)
- [ret, err_msg, msg_log] = init(obj.libiio_data_in_dev, obj.ip_address, ...
- obj.iio_dev_cfg.data_in_device, 'OUT', ...
- obj.in_ch_no, obj.in_ch_size);
- fprintf('%s', msg_log);
- if(ret < 0)
- msgbox(err_msg, 'Error','error');
- return;
- end
- end
-
- % Initialize the libiio data output device
- if(obj.out_ch_no ~= 0)
- [ret, err_msg, msg_log] = init(obj.libiio_data_out_dev, obj.ip_address, ...
- obj.iio_dev_cfg.data_out_device, 'IN', ...
- obj.out_ch_no, obj.out_ch_size);
- fprintf('%s', msg_log);
- if(ret < 0)
- msgbox(err_msg, 'Error','error');
- return;
- end
- end
-
- % Initialize the libiio control device
- if(~isempty(obj.iio_dev_cfg.ctrl_device))
- [ret, err_msg, msg_log] = init(obj.libiio_ctrl_dev, obj.ip_address, ...
- obj.iio_dev_cfg.ctrl_device, '', ...
- 0, 0);
- fprintf('%s', msg_log);
- if(ret < 0)
- msgbox(err_msg, 'Error','error');
- return;
- end
- end
-
- % Assign the control device for each monitoring channel
- for i = 1 : length(obj.iio_dev_cfg.mon_ch)
- if(strcmp(obj.iio_dev_cfg.mon_ch(i).ctrl_dev_name, 'data_in_device'))
- obj.iio_dev_cfg.mon_ch(i).ctrl_dev = obj.libiio_data_in_dev;
- elseif(strcmp(obj.iio_dev_cfg.mon_ch(i).ctrl_dev_name, 'data_out_device'))
- obj.iio_dev_cfg.mon_ch(i).ctrl_dev = obj.libiio_data_out_dev;
- else
- obj.iio_dev_cfg.mon_ch(i).ctrl_dev = obj.libiio_ctrl_dev;
- end
- end
-
- % Assign the control device for each configuration channel
- for i = 1 : length(obj.iio_dev_cfg.cfg_ch)
- if(strcmp(obj.iio_dev_cfg.cfg_ch(i).ctrl_dev_name, 'data_in_device'))
- obj.iio_dev_cfg.cfg_ch(i).ctrl_dev = obj.libiio_data_in_dev;
- elseif(strcmp(obj.iio_dev_cfg.cfg_ch(i).ctrl_dev_name, 'data_out_device'))
- obj.iio_dev_cfg.cfg_ch(i).ctrl_dev = obj.libiio_data_out_dev;
- else
- obj.iio_dev_cfg.cfg_ch(i).ctrl_dev = obj.libiio_ctrl_dev;
- end
- end
-
- % Set the initialization status to success
- obj.sys_obj_initialized = 1;
- ret = obj;
- end
-
- function releaseImpl(obj)
- % Release any resources used by the system object.
- obj.iio_dev_cfg = {};
- delete(obj.libiio_data_in_dev);
- delete(obj.libiio_data_out_dev);
- delete(obj.libiio_ctrl_dev);
- end
-
- function ret = stepImpl(obj, varargin)
- % Implement the system object's processing flow.
- varargout = cell(1, obj.out_ch_no + length(obj.iio_dev_cfg.mon_ch));
- if(obj.sys_obj_initialized == 0)
- return;
- end
-
- % Implement the device configuration flow
- for i = 1 : length(obj.iio_dev_cfg.cfg_ch)
- if(~isempty(varargin{1}{i + obj.in_ch_no}))
- if(length(varargin{1}{i + obj.in_ch_no}) == 1)
- new_data = (varargin{1}{i + obj.in_ch_no} ~= obj.num_cfg_in(i));
- else
- new_data = ~strncmp(char(varargin{1}{i + obj.in_ch_no}'), char(obj.str_cfg_in(i,:)), length(varargin{1}{i + obj.in_ch_no}));
- end
- if(new_data == 1)
- if(length(varargin{1}{i + obj.in_ch_no}) == 1)
- obj.num_cfg_in(i) = varargin{1}{i + obj.in_ch_no};
- str = num2str(obj.num_cfg_in(i));
- else
- for j = 1:length(varargin{1}{i + obj.in_ch_no})
- obj.str_cfg_in(i,j) = varargin{1}{i + obj.in_ch_no}(j);
- end
- obj.str_cfg_in(i,j+1) = 0;
- str = char(obj.str_cfg_in(i,:));
- end
- writeAttributeString(obj.iio_dev_cfg.cfg_ch(i).ctrl_dev, obj.iio_dev_cfg.cfg_ch(i).port_attr, str);
- end
- end
- end
-
- % Implement the data transmit flow
- writeData(obj.libiio_data_in_dev, varargin{1});
-
- % Implement the data capture flow
- [~, data] = readData(obj.libiio_data_out_dev);
- for i = 1 : obj.out_ch_no
- varargout{i} = data{i};
- end
-
- % Implement the parameters monitoring flow
- for i = 1 : length(obj.iio_dev_cfg.mon_ch)
- [~, val] = readAttributeDouble(obj.iio_dev_cfg.mon_ch(i).ctrl_dev, obj.iio_dev_cfg.mon_ch(i).port_attr);
- varargout{obj.out_ch_no + i} = val;
- end
-
- ret=varargout;
- end
-
- function ret = writeFirData(obj, fir_data_file)
- fir_data_str = fileread(fir_data_file);
- ret = writeAttributeString(obj.libiio_ctrl_dev, 'in_out_voltage_filter_fir_en', '0');
- if ret<0
- return;
- end
- ret = writeAttributeString(obj.libiio_ctrl_dev, 'filter_fir_config', fir_data_str);
- if ret<0
- return;
- end
- ret = writeAttributeString(obj.libiio_ctrl_dev, 'in_out_voltage_filter_fir_en', '1');
- if ret<0
- return;
- end
- end
- end
-end
diff --git a/bindings/matlab/libiio_if.m b/bindings/matlab/libiio_if.m
deleted file mode 100644
index 9fde04d..0000000
--- a/bindings/matlab/libiio_if.m
+++ /dev/null
@@ -1,701 +0,0 @@
-% Copyright 2014(c) Analog Devices, Inc.
-%
-% All rights reserved.
-%
-% Redistribution and use in source and binary forms, with or without modification,
-% are permitted provided that the following conditions are met:
-% - Redistributions of source code must retain the above copyright
-% notice, this list of conditions and the following disclaimer.
-% - Redistributions in binary form must reproduce the above copyright
-% notice, this list of conditions and the following disclaimer in
-% the documentation and/or other materials provided with the
-% distribution.
-% - Neither the name of Analog Devices, Inc. nor the names of its
-% contributors may be used to endorse or promote products derived
-% from this software without specific prior written permission.
-% - The use of this software may or may not infringe the patent rights
-% of one or more patent holders. This license does not release you
-% from the requirement that you obtain separate licenses from these
-% patent holders to use this software.
-% - Use of the software either in source or binary form or filter designs
-% resulting from the use of this software, must be connected to, run
-% on or loaded to an Analog Devices Inc. component.
-%
-% THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
-% INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A
-% PARTICULAR PURPOSE ARE DISCLAIMED.
-%
-% IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-% EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY
-% RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-% BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-% STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
-% THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-classdef libiio_if < handle
- % libiio_if Interface object for for IIO devices
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Protected properties
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- properties (Access = protected)
- libname = 'libiio';
- hname = 'iio-wrapper.h';
- dev_name = '';
- data_ch_no = 0;
- data_ch_size = 0;
- dev_type = '';
- iio_ctx = {};
- iio_dev = {};
- iio_buffer = {};
- iio_channel = {};
- iio_buf_size = 8192;
- iio_scan_elm_no = 0;
- if_initialized = 0;
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Static private methods
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- methods (Static, Access = private)
- function out = modInstanceCnt(val)
- % Manages the number of object instances to handle proper DLL unloading
- persistent instance_cnt;
- if isempty(instance_cnt)
- instance_cnt = 0;
- end
- instance_cnt = instance_cnt + val;
- out = instance_cnt;
- end
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Protected methods
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- methods (Access = protected)
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Creates the network context
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ret, err_msg, msg_log] = createNetworkContext(obj, ip_address)
- % Initialize the return values
- ret = -1;
- err_msg = '';
- msg_log = [];
-
- % Create the network context
- obj.iio_ctx = calllib(obj.libname, 'iio_create_network_context', ip_address);
-
- % Check if the network context is valid
- if (isNull(obj.iio_ctx))
- obj.iio_ctx = {};
- err_msg = 'Could not connect to the IIO server!';
- return;
- end
-
- % Increase the object's instance count
- libiio_if.modInstanceCnt(1);
- msg_log = [msg_log sprintf('%s: Connected to IP %s\n', class(obj), ip_address)];
-
- % Set the return code to success
- ret = 0;
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Releases the network context and unload the libiio library
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function releaseContext(obj)
- calllib(obj.libname, 'iio_context_destroy', obj.iio_ctx);
- obj.iio_ctx = {};
- instCnt = libiio_if.modInstanceCnt(-1);
- if(instCnt == 0)
- unloadlibrary(obj.libname);
- end
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Checks the compatibility of the different software modules.
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ret, err_msg, msg_log] = checkVersions(obj)
- % Initialize the return values
- ret = -1;
- err_msg = '';
- msg_log = [];
-
- % Create a set of pointers to read the iiod and dll versions
- data = zeros(1, 10);
- remote_pMajor = libpointer('uint32Ptr', data(1));
- remote_pMinor = libpointer('uint32Ptr', data(2));
- remote_pGitTag = libpointer('int8Ptr', [int8(data(3:end)) 0]);
- local_pMajor = libpointer('uint32Ptr', data(1));
- local_pMinor = libpointer('uint32Ptr', data(2));
- local_pGitTag = libpointer('int8Ptr', [int8(data(3:end)) 0]);
-
- % get remote libiio version
- calllib(obj.libname, 'iio_context_get_version', obj.iio_ctx, remote_pMajor, remote_pMinor, remote_pGitTag);
- % extract git hash without trailing null char
- remote_githash = remote_pGitTag.Value(1:7);
- remote_version_str = sprintf('Remote libiio version: %d.%d, (git-%s)', remote_pMajor.Value, remote_pMinor.Value, remote_githash);
- msg_log = [msg_log sprintf('%s: %s\n', class(obj), remote_version_str)];
-
- % get local libiio version
- calllib(obj.libname, 'iio_library_get_version', local_pMajor, local_pMinor, local_pGitTag);
- local_githash = local_pGitTag.Value(1:7);
- local_version_str = sprintf('Local libiio version: %d.%d, (git-%s)', local_pMajor.Value, local_pMinor.Value, local_githash);
- msg_log = [msg_log sprintf('%s: %s\n', class(obj), local_version_str)];
-
- if(remote_pMajor.Value < local_pMajor.Value)
- err_msg = ['The libiio version running on the device is outdated! ' ...
- 'Run the adi_update_tools.sh script to get libiio up to date.'];
- return;
- elseif(remote_pMajor.Value > local_pMajor.Value)
- err_msg = ['The libiio version on the local host is outdated! ' ...
- 'On Windows, reinstall the dll using the latest installer ' ...
- 'from the Analog Devices wiki.'];
- return;
- end
-
- % Set the return code to success
- ret = 0;
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Detect if the specified device is present in the system
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ret, err_msg, msg_log] = initDevice(obj, dev_name)
- % Initialize the return values
- ret = -1;
- err_msg = '';
- msg_log = [];
-
- % Store the device name
- obj.dev_name = dev_name;
-
- % Get the number of devices
- nb_devices = calllib(obj.libname, 'iio_context_get_devices_count', obj.iio_ctx);
-
- % If no devices are present return with error
- if(nb_devices == 0)
- err_msg = 'No devices were detected in the system!';
- return;
- end
- msg_log = [msg_log sprintf('%s: Found %d devices in the system\n', class(obj), nb_devices)];
-
- % Detect if the targeted device is installed
- dev_found = 0;
- for i = 0 : nb_devices - 1
- dev = calllib(obj.libname, 'iio_context_get_device', obj.iio_ctx, i);
- name = calllib(obj.libname, 'iio_device_get_name', dev);
- if(strcmp(name, dev_name))
- obj.iio_dev = dev;
- dev_found = 1;
- break;
- end
- clear dev;
- end
-
- % Check if the target device was detected
- if(dev_found == 0)
- err_msg = 'Could not find target configuration device!';
- return;
- end
-
- msg_log = [msg_log sprintf('%s: %s was found in the system\n', class(obj), obj.dev_name)];
-
- % Set the return code to success
- ret = 0;
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Initializes the output data channels
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ret, err_msg, msg_log] = initOutputDataChannels(obj, ch_no, ch_size)
- % Initialize the return values
- ret = -1;
- err_msg = '';
- msg_log = [];
-
- % Save the number of channels and size
- obj.data_ch_no = ch_no;
- obj.data_ch_size = ch_size;
-
- % Get the number of channels that the device has
- nb_channels = calllib(obj.libname, 'iio_device_get_channels_count', obj.iio_dev);
- if(nb_channels == 0)
- err_msg = 'The selected device does not have any channels!';
- return;
- end
-
- % Enable the data channels
- if(ch_no ~= 0)
- % Check if the device has output channels. The
- % logic here assumes that a device can have
- % only input or only output channels
- obj.iio_channel{1} = calllib(obj.libname, 'iio_device_get_channel', obj.iio_dev, 0);
- is_output = calllib(obj.libname, 'iio_channel_is_output', obj.iio_channel{1});
- if(is_output == 0)
- err_msg = 'The selected device does not have output channels!';
- return;
- end
- % Enable all the channels
- for j = 0 : nb_channels - 1
- obj.iio_channel{j+1} = calllib(obj.libname, 'iio_device_get_channel', obj.iio_dev, j);
- calllib(obj.libname, 'iio_channel_enable', obj.iio_channel{j+1});
- is_scan_element = calllib(obj.libname, 'iio_channel_is_scan_element', obj.iio_channel{j+1});
- if(is_scan_element == 1)
- obj.iio_scan_elm_no = obj.iio_scan_elm_no + 1;
- end
- end
- msg_log = [msg_log sprintf('%s: Found %d output channels for the device %s\n', class(obj), obj.iio_scan_elm_no, obj.dev_name)];
-
- % Check if the number of channels in the device
- % is greater or equal to the system object
- % input channels
- if(obj.iio_scan_elm_no < ch_no)
- obj.iio_channel = {};
- err_msg = 'The selected device does not have enough output channels!';
- return;
- end
-
- % Enable the DAC buffer output
- obj.if_initialized = 1;
- ret = writeAttributeString(obj, 'altvoltage0*raw', '0');
- obj.if_initialized = 0;
- if(ret < 0)
- obj.iio_channel = {};
- err_msg = 'Could not enable the DAC buffer output!';
- return;
- end
-
- % Create the IIO buffer used to write data
- obj.iio_buf_size = obj.data_ch_size * obj.iio_scan_elm_no;
- obj.iio_buffer = calllib(obj.libname, 'iio_device_create_buffer', obj.iio_dev,...
- obj.data_ch_size, 1);
- end
-
- msg_log = [msg_log sprintf('%s: %s output data channels successfully initialized\n', class(obj), obj.dev_name)];
-
- % Set the return code to success
- ret = 0;
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Initializes the input data channels
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ret, err_msg, msg_log] = initInputDataChannels(obj, ch_no, ch_size)
- % Initialize the return values
- ret = -1;
- err_msg = '';
- msg_log = [];
-
- % Save the number of channels and size
- obj.data_ch_no = ch_no;
- obj.data_ch_size = ch_size;
-
- % Get the number of channels that the device has
- nb_channels = calllib(obj.libname, 'iio_device_get_channels_count', obj.iio_dev);
- if(nb_channels == 0)
- err_msg = 'The selected device does not have any channels!';
- return;
- end
-
- % Enable the system object output channels
- if(ch_no ~= 0)
- % Check if the device has input channels. The
- % logic here assumes that a device can have
- % only input or only output channels
- obj.iio_channel{1} = calllib(obj.libname, 'iio_device_get_channel', obj.iio_dev, 0);
- is_output = calllib(obj.libname, 'iio_channel_is_output', obj.iio_channel{1});
- if(is_output == 1)
- err_msg = 'The selected device does not have input channels!';
- return;
- end
- msg_log = [msg_log sprintf('%s: Found %d input channels for the device %s\n', class(obj), nb_channels, obj.dev_name)];
-
- % Check if the number of channels in the device
- % is greater or equal to the system object
- % output channels
- if(nb_channels < ch_no)
- obj.iio_channel = {};
- err_msg = 'The selected device does not have enough input channels!';
- return;
- end
-
- % Enable the channels
- for j = 0 : ch_no - 1
- obj.iio_channel{j+1} = calllib(obj.libname, 'iio_device_get_channel', obj.iio_dev, j);
- calllib(obj.libname, 'iio_channel_enable', obj.iio_channel{j+1});
- end
- for j = ch_no : nb_channels - 1
- obj.iio_channel{j+1} = calllib(obj.libname, 'iio_device_get_channel', obj.iio_dev, j);
- calllib(obj.libname, 'iio_channel_disable', obj.iio_channel{j+1});
- end
- % Create the IIO buffer used to read data
- obj.iio_buf_size = obj.data_ch_size * obj.data_ch_no;
- obj.iio_buffer = calllib(obj.libname, 'iio_device_create_buffer', obj.iio_dev, obj.iio_buf_size, 0);
- end
-
- msg_log = [msg_log sprintf('%s: %s input data channels successfully initialized\n', class(obj), obj.dev_name)];
-
- % Set the return code to success
- ret = 0;
- end
-
- end
-
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Public methods
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- methods
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Constructor
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function obj = libiio_if()
- % Constructor
- obj.if_initialized = 0;
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Destructor
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function delete(obj)
- % Release any resources used by the system object.
- if((obj.if_initialized == 1) && libisloaded(obj.libname))
- if(~isempty(obj.iio_buffer))
- calllib(obj.libname, 'iio_buffer_destroy', obj.iio_buffer);
- end
- if(~isempty(obj.iio_ctx))
- calllib(obj.libname, 'iio_context_destroy', obj.iio_ctx);
- end
- obj.iio_buffer = {};
- obj.iio_channel = {};
- obj.iio_dev = {};
- obj.iio_ctx = {};
- instCnt = libiio_if.modInstanceCnt(-1);
- if(instCnt == 0)
- unloadlibrary(obj.libname);
- end
- end
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Initializes the libiio interface
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ret, err_msg, msg_log] = init(obj, ip_address, ...
- dev_name, dev_type, ...
- data_ch_no, data_ch_size)
- % Initialize the return values
- ret = -1;
- err_msg = '';
- msg_log = [];
-
- % Save the device type
- obj.dev_type = dev_type;
-
- % Set the initialization status to fail
- obj.if_initialized = 0;
-
- % Load the libiio library
- if(~libisloaded(obj.libname))
- try
- % ignore unknown type warnings due to header parsing limitations
- warnState = warning('off', 'MATLAB:loadlibrary:TypeNotFound');
- cleanupObj = onCleanup(@()warning(warnState));
- [notfound, warnings] = loadlibrary(obj.libname, obj.hname, 'addheader', 'iio.h');
- cleanupObj = []; % restore the warning state
- catch exception
- err_msg = exception.message;
- return;
- end
- end
-
- if(~libisloaded(obj.libname))
- err_msg = 'Could not load the libiio library!';
- return;
- end
-
- % Create the network context
- [ret, err_msg, msg_log] = createNetworkContext(obj, ip_address);
- if(ret < 0)
- return;
- end
-
- % Check the software versions
- [ret, err_msg, msg_log_new] = checkVersions(obj);
- msg_log = [msg_log msg_log_new];
- if(ret < 0)
- releaseContext(obj);
- return;
- end
-
- % Initialize the device
- [ret, err_msg, msg_log_new] = initDevice(obj, dev_name);
- msg_log = [msg_log msg_log_new];
- if(ret < 0)
- releaseContext(obj);
- return;
- end
-
- % Initialize the output data channels
- if(strcmp(dev_type, 'OUT'))
- [ret, err_msg, msg_log_new] = initOutputDataChannels(obj, data_ch_no, data_ch_size);
- msg_log = [msg_log msg_log_new];
- if(ret < 0)
- releaseContext(obj);
- return;
- end
- end
-
- % Initialize the input data channels
- if(strcmp(dev_type, 'IN'))
- [ret, err_msg, msg_log_new] = initInputDataChannels(obj, data_ch_no, data_ch_size);
- msg_log = [msg_log msg_log_new];
- if(ret < 0)
- releaseContext(obj);
- return;
- end
- end
-
- % Set the initialization status to success
- obj.if_initialized = 1;
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Implement the data capture flow
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ret, data] = readData(obj)
- % Initialize the return values
- ret = -1;
- data = cell(1, obj.data_ch_no);
- for i = 1 : obj.data_ch_no
- data{i} = zeros(obj.data_ch_size, 1);
- end
-
- % Check if the interface is initialized
- if(obj.if_initialized == 0)
- return;
- end
-
- % Check if the device type is output
- if(~strcmp(obj.dev_type, 'IN'))
- return;
- end
-
- % Read the data
- calllib(obj.libname, 'iio_buffer_refill', obj.iio_buffer);
- buffer = calllib(obj.libname, 'iio_buffer_first', obj.iio_buffer, obj.iio_channel{1});
- setdatatype(buffer, 'int16Ptr', obj.iio_buf_size);
- for i = 1 : obj.data_ch_no
- data{i} = double(buffer.Value(i:obj.data_ch_no:end));
- end
-
- % Set the return code to success
- ret = 0;
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Implement the data transmit flow
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function ret = writeData(obj, data)
- % Initialize the return values
- ret = -1;
-
- % Check if the interface is initialized
- if(obj.if_initialized == 0)
- return;
- end
-
- % Check if the device type is input
- if(~strcmp(obj.dev_type, 'OUT'))
- return;
- end
-
- % Destroy the buffer
- calllib(obj.libname, 'iio_buffer_destroy', obj.iio_buffer);
- obj.iio_buffer = {};
-
- % Enable the DAC buffer output
- ret = writeAttributeString(obj, 'altvoltage0*raw', '0');
- if(ret < 0)
- obj.iio_channel = {};
- err_msg = 'Could not enable the DAC buffer output!';
- return;
- end
-
- % Create the IIO buffer used to write data
- obj.iio_buf_size = obj.data_ch_size * obj.iio_scan_elm_no;
- obj.iio_buffer = calllib(obj.libname, 'iio_device_create_buffer', obj.iio_dev,...
- obj.data_ch_size, 1);
-
- % Transmit the data
- buffer = calllib(obj.libname, 'iio_buffer_start', obj.iio_buffer);
- setdatatype(buffer, 'int16Ptr', obj.iio_buf_size);
- for i = 1 : obj.data_ch_no
- buffer.Value(i : obj.iio_scan_elm_no : obj.iio_buf_size) = int16(data{i});
- end
- for i = obj.data_ch_no + 1 : obj.iio_scan_elm_no
- buffer.Value(i : obj.iio_scan_elm_no : obj.iio_buf_size) = 0;
- end
- calllib(obj.libname, 'iio_buffer_push', obj.iio_buffer);
-
- % Set the return code to success
- ret = 0;
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Find an attribute based on the name. The name can contain wildcard '*' characters
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ret, ch, attr] = findAttribute(obj, attr_name)
- % Initialize the return values
- ret = -1;
- ch = 0;
- attr = '';
-
- % Check if the interface is initialized
- if(obj.if_initialized == 0)
- return;
- end
-
- % Check if this is a device attribute
- name = calllib(obj.libname, 'iio_device_find_attr', obj.iio_dev, attr_name);
- if(~isempty(name))
- ret = 0;
- return;
- end
-
- % This is a channel attribute, search for the corresponding channel
- chn_no = calllib(obj.libname, 'iio_device_get_channels_count', obj.iio_dev);
- for k = 0 : chn_no - 1
- ch = calllib(obj.libname, 'iio_device_get_channel', obj.iio_dev, k);
- attr_no = calllib(obj.libname, 'iio_channel_get_attrs_count', ch);
- attr_found = 0;
- for l = 0 : attr_no - 1
- attr = calllib(obj.libname, 'iio_channel_get_attr', ch, l);
- name = calllib(obj.libname, 'iio_channel_attr_get_filename', ch, attr);
- % The attribute to find can contain wildcard '*' characters,
- % search for all the substrings in the attribute name
- str_find = strsplit(attr_name, '*');
- str_find = str_find(find(~strcmp(str_find, '')));
- has_wildcard = ~isempty(strfind(attr_name, '*'));
- attr_found = 1;
- for i = 1 : length(str_find)
- if(has_wildcard == 0)
- ret = strcmp(name, str_find{i});
- if(ret == 0)
- ret = [];
- end
- else
- ret = strfind(name, str_find{i});
- end
- if(isempty(ret))
- attr_found = 0;
- break;
- end
- end
- if(attr_found == 1)
- break;
- end
- clear attr;
- end
- % Check if the attribute was found
- if(attr_found == 0)
- clear ch;
- else
- ret = 1;
- break;
- end
- end
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Read an attribute as a double value
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ret, val] = readAttributeDouble(obj, attr_name)
- % Find the attribute
- [ret, ch, attr] = findAttribute(obj, attr_name);
- if(ret < 0)
- val = 0;
- return;
- end
-
- % Create a double pointer to be used for data read
- data = zeros(1, 10);
- pData = libpointer('doublePtr', data(1));
-
- % Read the attribute value
- if(ret > 0)
- calllib(obj.libname, 'iio_channel_attr_read_double', ch, attr, pData);
- clear ch;
- clear attr;
- else
- calllib(obj.libname, 'iio_device_attr_read_double', obj.iio_dev, attr_name, pData);
- end
- val = pData.Value;
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Read an attribute as a string value
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ret, val] = readAttributeString(obj, attr_name)
- % Find the attribute
- [ret, ch, attr] = findAttribute(obj, attr_name);
- if(ret < 0)
- val = '';
- return;
- end
-
- % Create a pointer to be used for data read
- data = char(ones(1, 512));
- pData = libpointer('stringPtr', data);
-
- % Read the attribute value
- if(ret > 0)
- [~, ~, ~, val] = calllib(obj.libname, 'iio_channel_attr_read', ch, attr, pData, 512);
- clear ch;
- clear attr;
- else
- [~, ~, ~, val] = calllib(obj.libname, 'iio_device_attr_read', obj.iio_dev, attr_name, pData, 512);
- end
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Write a string double value
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function ret = writeAttributeDouble(obj, attr_name, val)
- % Find the attribute
- [ret, ch, attr] = findAttribute(obj, attr_name);
- if(ret < 0)
- return;
- end
-
- % Write the attribute
- if(ret > 0)
- calllib(obj.libname, 'iio_channel_attr_write_double', ch, attr, val);
- clear ch;
- clear attr;
- else
- calllib(obj.libname, 'iio_device_attr_write_double', obj.iio_dev, attr_name, val);
- end
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Write a string attribute value
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function ret = writeAttributeString(obj, attr_name, str)
- % Find the attribute
- [ret, ch, attr] = findAttribute(obj, attr_name);
- if(ret < 0)
- return;
- end
-
- % Write the attribute
- if(ret > 0)
- calllib(obj.libname, 'iio_channel_attr_write', ch, attr, str);
- clear ch;
- clear attr;
- else
- calllib(obj.libname, 'iio_device_attr_write', obj.iio_dev, attr_name, str);
- end
- end
- end
-end
diff --git a/bindings/matlab/libiio_if_daq2.m b/bindings/matlab/libiio_if_daq2.m
deleted file mode 100644
index 0ac5708..0000000
--- a/bindings/matlab/libiio_if_daq2.m
+++ /dev/null
@@ -1,701 +0,0 @@
-% Copyright 2014(c) Analog Devices, Inc.
-%
-% All rights reserved.
-%
-% Redistribution and use in source and binary forms, with or without modification,
-% are permitted provided that the following conditions are met:
-% - Redistributions of source code must retain the above copyright
-% notice, this list of conditions and the following disclaimer.
-% - Redistributions in binary form must reproduce the above copyright
-% notice, this list of conditions and the following disclaimer in
-% the documentation and/or other materials provided with the
-% distribution.
-% - Neither the name of Analog Devices, Inc. nor the names of its
-% contributors may be used to endorse or promote products derived
-% from this software without specific prior written permission.
-% - The use of this software may or may not infringe the patent rights
-% of one or more patent holders. This license does not release you
-% from the requirement that you obtain separate licenses from these
-% patent holders to use this software.
-% - Use of the software either in source or binary form or filter designs
-% resulting from the use of this software, must be connected to, run
-% on or loaded to an Analog Devices Inc. component.
-%
-% THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
-% INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A
-% PARTICULAR PURPOSE ARE DISCLAIMED.
-%
-% IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-% EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY
-% RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-% BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-% STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
-% THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-classdef libiio_if < handle
- % libiio_if Interface object for for IIO devices
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Protected properties
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- properties (Access = protected)
- libname = 'libiio';
- hname = 'iio.h';
- dev_name = '';
- data_ch_no = 0;
- data_ch_size = 0;
- dev_type = '';
- iio_ctx = {};
- iio_dev = {};
- iio_buffer = {};
- iio_channel = {};
- iio_buf_size = 8192;
- iio_scan_elm_no = 0;
- if_initialized = 0;
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Static private methods
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- methods (Static, Access = private)
- function out = modInstanceCnt(val)
- % Manages the number of object instances to handle proper DLL unloading
- persistent instance_cnt;
- if isempty(instance_cnt)
- instance_cnt = 0;
- end
- instance_cnt = instance_cnt + val;
- out = instance_cnt;
- end
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Protected methods
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- methods (Access = protected)
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Creates the network context
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ret, err_msg, msg_log] = createNetworkContext(obj, ip_address)
- % Initialize the return values
- ret = -1;
- err_msg = '';
- msg_log = [];
-
- % Create the network context
- obj.iio_ctx = calllib(obj.libname, 'iio_create_network_context', ip_address);
-
- % Check if the network context is valid
- if (isNull(obj.iio_ctx))
- obj.iio_ctx = {};
- err_msg = 'Could not connect to the IIO server!';
- return;
- end
-
- % Increase the object's instance count
- libiio_if.modInstanceCnt(1);
- msg_log = [msg_log sprintf('%s: Connected to IP %s\n', class(obj), ip_address)];
-
- % Set the return code to success
- ret = 0;
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Releases the network context and unload the libiio library
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function releaseContext(obj)
- calllib(obj.libname, 'iio_context_destroy', obj.iio_ctx);
- obj.iio_ctx = {};
- instCnt = libiio_if.modInstanceCnt(-1);
- if(instCnt == 0)
- unloadlibrary(obj.libname);
- end
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Checks the compatibility of the different software modules.
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ret, err_msg, msg_log] = checkVersions(obj)
- % Initialize the return values
- ret = -1;
- err_msg = '';
- msg_log = [];
-
- % Create a set of pointers to read the iiod and dll versions
- data = zeros(1, 10);
- remote_pMajor = libpointer('uint32Ptr', data(1));
- remote_pMinor = libpointer('uint32Ptr', data(2));
- remote_pGitTag = libpointer('int8Ptr', [int8(data(3:end)) 0]);
- local_pMajor = libpointer('uint32Ptr', data(1));
- local_pMinor = libpointer('uint32Ptr', data(2));
- local_pGitTag = libpointer('int8Ptr', [int8(data(3:end)) 0]);
-
- % get remote libiio version
- calllib(obj.libname, 'iio_context_get_version', obj.iio_ctx, remote_pMajor, remote_pMinor, remote_pGitTag);
- % extract git hash without trailing null char
- remote_githash = remote_pGitTag.Value(1:7);
- remote_version_str = sprintf('Remote libiio version: %d.%d, (git-%s)', remote_pMajor.Value, remote_pMinor.Value, remote_githash);
- msg_log = [msg_log sprintf('%s: %s\n', class(obj), remote_version_str)];
-
- % get local libiio version
- calllib(obj.libname, 'iio_library_get_version', local_pMajor, local_pMinor, local_pGitTag);
- local_githash = local_pGitTag.Value(1:7);
- local_version_str = sprintf('Local libiio version: %d.%d, (git-%s)', local_pMajor.Value, local_pMinor.Value, local_githash);
- msg_log = [msg_log sprintf('%s: %s\n', class(obj), local_version_str)];
-
- if(remote_pMajor.Value < local_pMajor.Value)
- err_msg = ['The libiio version running on the device is outdated! ' ...
- 'Run the adi_update_tools.sh script to get libiio up to date.'];
- return;
- elseif(remote_pMajor.Value > local_pMajor.Value)
- err_msg = ['The libiio version on the local host is outdated! ' ...
- 'On Windows, reinstall the dll using the latest installer ' ...
- 'from the Analog Devices wiki.'];
- return;
- end
-
- % Set the return code to success
- ret = 0;
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Detect if the specified device is present in the system
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ret, err_msg, msg_log] = initDevice(obj, dev_name)
- % Initialize the return values
- ret = -1;
- err_msg = '';
- msg_log = [];
-
- % Store the device name
- obj.dev_name = dev_name;
-
- % Get the number of devices
- nb_devices = calllib(obj.libname, 'iio_context_get_devices_count', obj.iio_ctx);
-
- % If no devices are present return with error
- if(nb_devices == 0)
- err_msg = 'No devices were detected in the system!';
- return;
- end
- msg_log = [msg_log sprintf('%s: Found %d devices in the system\n', class(obj), nb_devices)];
-
- % Detect if the targeted device is installed
- dev_found = 0;
- for i = 0 : nb_devices - 1
- dev = calllib(obj.libname, 'iio_context_get_device', obj.iio_ctx, i);
- name = calllib(obj.libname, 'iio_device_get_name', dev);
- if(strcmp(name, dev_name))
- obj.iio_dev = dev;
- dev_found = 1;
- break;
- end
- clear dev;
- end
-
- % Check if the target device was detected
- if(dev_found == 0)
- err_msg = 'Could not find target configuration device!';
- return;
- end
-
- msg_log = [msg_log sprintf('%s: %s was found in the system\n', class(obj), obj.dev_name)];
-
- % Set the return code to success
- ret = 0;
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Initializes the output data channels
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ret, err_msg, msg_log] = initOutputDataChannels(obj, ch_no, ch_size)
- % Initialize the return values
- ret = -1;
- err_msg = '';
- msg_log = [];
-
- % Save the number of channels and size
- obj.data_ch_no = ch_no;
- obj.data_ch_size = ch_size;
-
- % Get the number of channels that the device has
- nb_channels = calllib(obj.libname, 'iio_device_get_channels_count', obj.iio_dev);
- if(nb_channels == 0)
- err_msg = 'The selected device does not have any channels!';
- return;
- end
-
- % Enable the data channels
- if(ch_no ~= 0)
- % Check if the device has output channels. The
- % logic here assumes that a device can have
- % only input or only output channels
- obj.iio_channel{1} = calllib(obj.libname, 'iio_device_get_channel', obj.iio_dev, 0);
- is_output = calllib(obj.libname, 'iio_channel_is_output', obj.iio_channel{1});
- if(is_output == 0)
- err_msg = 'The selected device does not have output channels!';
- return;
- end
- % Enable all the channels
- for j = 0 : nb_channels - 1
- obj.iio_channel{j+1} = calllib(obj.libname, 'iio_device_get_channel', obj.iio_dev, j);
- if(j < ch_no)
- calllib(obj.libname, 'iio_channel_enable', obj.iio_channel{j+1});
- is_scan_element = calllib(obj.libname, 'iio_channel_is_scan_element', obj.iio_channel{j+1});
- if(is_scan_element == 1)
- obj.iio_scan_elm_no = obj.iio_scan_elm_no + 1;
- end
- else
- calllib(obj.libname, 'iio_channel_disable', obj.iio_channel{j+1});
- end
- end
- msg_log = [msg_log sprintf('%s: Found %d output channels for the device %s\n', class(obj), obj.iio_scan_elm_no, obj.dev_name)];
-
- % Check if the number of channels in the device
- % is greater or equal to the system object
- % input channels
- if(obj.iio_scan_elm_no < ch_no)
- obj.iio_channel = {};
- err_msg = 'The selected device does not have enough output channels!';
- return;
- end
-
- % Enable the DAC buffer output
- obj.if_initialized = 1;
- ret = writeAttributeString(obj, 'altvoltage0*raw', '0');
- obj.if_initialized = 0;
- if(ret < 0)
- obj.iio_channel = {};
- err_msg = 'Could not enable the DAC buffer output!';
- return;
- end
-
- % Create the IIO buffer used to write data
- obj.iio_buf_size = obj.data_ch_size * obj.iio_scan_elm_no;
- obj.iio_buffer = calllib(obj.libname, 'iio_device_create_buffer', obj.iio_dev,...
- obj.data_ch_size, 1);
- end
-
- msg_log = [msg_log sprintf('%s: %s output data channels successfully initialized\n', class(obj), obj.dev_name)];
-
- % Set the return code to success
- ret = 0;
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Initializes the input data channels
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ret, err_msg, msg_log] = initInputDataChannels(obj, ch_no, ch_size)
- % Initialize the return values
- ret = -1;
- err_msg = '';
- msg_log = [];
-
- % Save the number of channels and size
- obj.data_ch_no = ch_no;
- obj.data_ch_size = ch_size;
-
- % Get the number of channels that the device has
- nb_channels = calllib(obj.libname, 'iio_device_get_channels_count', obj.iio_dev);
- if(nb_channels == 0)
- err_msg = 'The selected device does not have any channels!';
- return;
- end
-
- % Enable the system object output channels
- if(ch_no ~= 0)
- % Check if the device has input channels. The
- % logic here assumes that a device can have
- % only input or only output channels
- obj.iio_channel{1} = calllib(obj.libname, 'iio_device_get_channel', obj.iio_dev, 0);
- is_output = calllib(obj.libname, 'iio_channel_is_output', obj.iio_channel{1});
- if(is_output == 1)
- err_msg = 'The selected device does not have input channels!';
- return;
- end
- msg_log = [msg_log sprintf('%s: Found %d input channels for the device %s\n', class(obj), nb_channels, obj.dev_name)];
-
- % Check if the number of channels in the device
- % is greater or equal to the system object
- % output channels
- if(nb_channels < ch_no)
- obj.iio_channel = {};
- err_msg = 'The selected device does not have enough input channels!';
- return;
- end
-
- % Enable the channels
- for j = 0 : ch_no - 1
- obj.iio_channel{j+1} = calllib(obj.libname, 'iio_device_get_channel', obj.iio_dev, j);
- calllib(obj.libname, 'iio_channel_enable', obj.iio_channel{j+1});
- end
- for j = ch_no : nb_channels - 1
- obj.iio_channel{j+1} = calllib(obj.libname, 'iio_device_get_channel', obj.iio_dev, j);
- calllib(obj.libname, 'iio_channel_disable', obj.iio_channel{j+1});
- end
- % Create the IIO buffer used to read data
- obj.iio_buf_size = obj.data_ch_size * obj.data_ch_no;
- obj.iio_buffer = calllib(obj.libname, 'iio_device_create_buffer', obj.iio_dev, obj.iio_buf_size, 0);
- end
-
- msg_log = [msg_log sprintf('%s: %s input data channels successfully initialized\n', class(obj), obj.dev_name)];
-
- % Set the return code to success
- ret = 0;
- end
-
- end
-
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Public methods
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- methods
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Constructor
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function obj = libiio_if()
- % Constructor
- obj.if_initialized = 0;
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Destructor
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function delete(obj)
- % Release any resources used by the system object.
- if((obj.if_initialized == 1) && libisloaded(obj.libname))
- if(~isempty(obj.iio_buffer))
- calllib(obj.libname, 'iio_buffer_destroy', obj.iio_buffer);
- end
- if(~isempty(obj.iio_ctx))
- calllib(obj.libname, 'iio_context_destroy', obj.iio_ctx);
- end
- obj.iio_buffer = {};
- obj.iio_channel = {};
- obj.iio_dev = {};
- obj.iio_ctx = {};
- instCnt = libiio_if.modInstanceCnt(-1);
- if(instCnt == 0)
- unloadlibrary(obj.libname);
- end
- end
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Initializes the libiio interface
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ret, err_msg, msg_log] = init(obj, ip_address, ...
- dev_name, dev_type, ...
- data_ch_no, data_ch_size)
- % Initialize the return values
- ret = -1;
- err_msg = '';
- msg_log = [];
-
- % Save the device type
- obj.dev_type = dev_type;
-
- % Set the initialization status to fail
- obj.if_initialized = 0;
-
- % Load the libiio library
- if(~libisloaded(obj.libname))
- try
- [notfound, warnings] = loadlibrary(obj.libname, obj.hname);
- catch exception
- err_msg = exception.message;
- return;
- end
- end
-
- if(~libisloaded(obj.libname))
- err_msg = 'Could not load the libiio library!';
- return;
- end
-
- % Create the network context
- [ret, err_msg, msg_log] = createNetworkContext(obj, ip_address);
- if(ret < 0)
- return;
- end
-
- % Check the software versions
- [ret, err_msg, msg_log_new] = checkVersions(obj);
- msg_log = [msg_log msg_log_new];
- if(ret < 0)
- releaseContext(obj);
- return;
- end
-
- % Initialize the device
- [ret, err_msg, msg_log_new] = initDevice(obj, dev_name);
- msg_log = [msg_log msg_log_new];
- if(ret < 0)
- releaseContext(obj);
- return;
- end
-
- % Initialize the output data channels
- if(strcmp(dev_type, 'OUT'))
- [ret, err_msg, msg_log_new] = initOutputDataChannels(obj, data_ch_no, data_ch_size);
- msg_log = [msg_log msg_log_new];
- if(ret < 0)
- releaseContext(obj);
- return;
- end
- end
-
- % Initialize the input data channels
- if(strcmp(dev_type, 'IN'))
- [ret, err_msg, msg_log_new] = initInputDataChannels(obj, data_ch_no, data_ch_size);
- msg_log = [msg_log msg_log_new];
- if(ret < 0)
- releaseContext(obj);
- return;
- end
- end
-
- % Set the initialization status to success
- obj.if_initialized = 1;
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Implement the data capture flow
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ret, data] = readData(obj)
- % Initialize the return values
- ret = -1;
- data = cell(1, obj.data_ch_no);
- for i = 1 : obj.data_ch_no
- data{i} = zeros(obj.data_ch_size, 1);
- end
-
- % Check if the interface is initialized
- if(obj.if_initialized == 0)
- return;
- end
-
- % Check if the device type is output
- if(~strcmp(obj.dev_type, 'IN'))
- return;
- end
-
- % Read the data
- calllib(obj.libname, 'iio_buffer_refill', obj.iio_buffer);
- buffer = calllib(obj.libname, 'iio_buffer_first', obj.iio_buffer, obj.iio_channel{1});
- setdatatype(buffer, 'int16Ptr', obj.iio_buf_size);
- for i = 1 : obj.data_ch_no
- data{i} = double(buffer.Value(i:obj.data_ch_no:end));
- end
-
- % Set the return code to success
- ret = 0;
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Implement the data transmit flow
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function ret = writeData(obj, data)
- % Initialize the return values
- ret = -1;
-
- % Check if the interface is initialized
- if(obj.if_initialized == 0)
- return;
- end
-
- % Check if the device type is input
- if(~strcmp(obj.dev_type, 'OUT'))
- return;
- end
-
- % Destroy the buffer
- calllib(obj.libname, 'iio_buffer_destroy', obj.iio_buffer);
- obj.iio_buffer = {};
-
- % Enable the DAC buffer output
- ret = writeAttributeString(obj, 'altvoltage0*raw', '0');
- if(ret < 0)
- obj.iio_channel = {};
- err_msg = 'Could not enable the DAC buffer output!';
- return;
- end
-
- % Create the IIO buffer used to write data
- obj.iio_buf_size = obj.data_ch_size * obj.iio_scan_elm_no;
- obj.iio_buffer = calllib(obj.libname, 'iio_device_create_buffer', obj.iio_dev,...
- obj.data_ch_size, 1);
-
- % Transmit the data
- buffer = calllib(obj.libname, 'iio_buffer_start', obj.iio_buffer);
- setdatatype(buffer, 'int16Ptr', obj.iio_buf_size);
- for i = 1 : obj.data_ch_no
- buffer.Value(i : obj.iio_scan_elm_no : obj.iio_buf_size) = int16(data{i});
- end
- for i = obj.data_ch_no + 1 : obj.iio_scan_elm_no
- buffer.Value(i : obj.iio_scan_elm_no : obj.iio_buf_size) = 0;
- end
- calllib(obj.libname, 'iio_buffer_push', obj.iio_buffer);
-
- % Set the return code to success
- ret = 0;
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Find an attribute based on the name. The name can contain wildcard '*' characters
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ret, ch, attr] = findAttribute(obj, attr_name)
- % Initialize the return values
- ret = -1;
- ch = 0;
- attr = '';
-
- % Check if the interface is initialized
- if(obj.if_initialized == 0)
- return;
- end
-
- % Check if this is a device attribute
- name = calllib(obj.libname, 'iio_device_find_attr', obj.iio_dev, attr_name);
- if(~isempty(name))
- ret = 0;
- return;
- end
-
- % This is a channel attribute, search for the corresponding channel
- chn_no = calllib(obj.libname, 'iio_device_get_channels_count', obj.iio_dev);
- for k = 0 : chn_no - 1
- ch = calllib(obj.libname, 'iio_device_get_channel', obj.iio_dev, k);
- attr_no = calllib(obj.libname, 'iio_channel_get_attrs_count', ch);
- attr_found = 0;
- for l = 0 : attr_no - 1
- attr = calllib(obj.libname, 'iio_channel_get_attr', ch, l);
- name = calllib(obj.libname, 'iio_channel_attr_get_filename', ch, attr);
- % The attribute to find can contain wildcard '*' characters,
- % search for all the substrings in the attribute name
- str_find = strsplit(attr_name, '*');
- str_find = str_find(find(~strcmp(str_find, '')));
- has_wildcard = ~isempty(strfind(attr_name, '*'));
- attr_found = 1;
- for i = 1 : length(str_find)
- if(has_wildcard == 0)
- ret = strcmp(name, str_find{i});
- if(ret == 0)
- ret = [];
- end
- else
- ret = strfind(name, str_find{i});
- end
- if(isempty(ret))
- attr_found = 0;
- break;
- end
- end
- if(attr_found == 1)
- break;
- end
- clear attr;
- end
- % Check if the attribute was found
- if(attr_found == 0)
- clear ch;
- else
- ret = 1;
- break;
- end
- end
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Read an attribute as a double value
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ret, val] = readAttributeDouble(obj, attr_name)
- % Find the attribute
- [ret, ch, attr] = findAttribute(obj, attr_name);
- if(ret < 0)
- val = 0;
- return;
- end
-
- % Create a double pointer to be used for data read
- data = zeros(1, 10);
- pData = libpointer('doublePtr', data(1));
-
- % Read the attribute value
- if(ret > 0)
- calllib(obj.libname, 'iio_channel_attr_read_double', ch, attr, pData);
- clear ch;
- clear attr;
- else
- calllib(obj.libname, 'iio_device_attr_read_double', obj.iio_dev, attr_name, pData);
- end
- val = pData.Value;
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Read an attribute as a string value
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ret, val] = readAttributeString(obj, attr_name)
- % Find the attribute
- [ret, ch, attr] = findAttribute(obj, attr_name);
- if(ret < 0)
- val = '';
- return;
- end
-
- % Create a pointer to be used for data read
- data = char(ones(1, 512));
- pData = libpointer('stringPtr', data);
-
- % Read the attribute value
- if(ret > 0)
- [~, ~, ~, val] = calllib(obj.libname, 'iio_channel_attr_read', ch, attr, pData, 512);
- clear ch;
- clear attr;
- else
- [~, ~, ~, val] = calllib(obj.libname, 'iio_device_attr_read', obj.iio_dev, attr_name, pData, 512);
- end
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Write a string double value
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function ret = writeAttributeDouble(obj, attr_name, val)
- % Find the attribute
- [ret, ch, attr] = findAttribute(obj, attr_name);
- if(ret < 0)
- return;
- end
-
- % Write the attribute
- if(ret > 0)
- calllib(obj.libname, 'iio_channel_attr_write_double', ch, attr, val);
- clear ch;
- clear attr;
- else
- calllib(obj.libname, 'iio_device_attr_write_double', obj.iio_dev, attr_name, val);
- end
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Write a string attribute value
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function ret = writeAttributeString(obj, attr_name, str)
- % Find the attribute
- [ret, ch, attr] = findAttribute(obj, attr_name);
- if(ret < 0)
- return;
- end
-
- % Write the attribute
- if(ret > 0)
- calllib(obj.libname, 'iio_channel_attr_write', ch, attr, str);
- clear ch;
- clear attr;
- else
- calllib(obj.libname, 'iio_device_attr_write', obj.iio_dev, attr_name, str);
- end
- end
- end
-end
diff --git a/bindings/python/.gitignore b/bindings/python/.gitignore
deleted file mode 100644
index cbf6e08..0000000
--- a/bindings/python/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-setup.py
-*.pyc
-__pycache__/
diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt
deleted file mode 100644
index 4ba6aca..0000000
--- a/bindings/python/CMakeLists.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-cmake_minimum_required(VERSION 2.8.7)
-project(libiio-py NONE)
-
-include(FindPythonInterp)
-
-if (PYTHONINTERP_FOUND)
- option(PYTHON_BINDINGS "Install Python bindings" ON)
-
- if (PYTHON_BINDINGS)
- set(SETUP_PY_IN ${CMAKE_CURRENT_SOURCE_DIR}/setup.py.cmakein)
- set(SETUP_PY ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
-
- configure_file(${SETUP_PY_IN} ${SETUP_PY})
-
- add_custom_target(libiio-py ALL DEPENDS ${SETUP_PY} COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} --quiet build)
-
- if(NOT SKIP_INSTALL_ALL)
- install(CODE "execute_process(WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} install --root=\$ENV{DESTDIR}/ --prefix=${CMAKE_INSTALL_PREFIX})")
- endif()
- endif()
-endif()
diff --git a/bindings/python/examples/iio_info.py b/bindings/python/examples/iio_info.py
deleted file mode 100755
index e29b297..0000000
--- a/bindings/python/examples/iio_info.py
+++ /dev/null
@@ -1,89 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright (C) 2015 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.
-
-import iio
-from sys import argv
-
-def main():
- print('Library version: %u.%u (git tag: %s)' % iio.version)
-
- if len(argv) == 3 and argv[1] == '--uri':
- uri = argv[2]
- else:
- contexts = iio.scan_contexts()
- if len(contexts) > 1:
- print('Multiple contexts found. Please select one using --uri:')
- for index, each in enumerate(contexts):
- print('\t%d: %s [%s]' % (index, contexts[each], each))
- return
-
- uri = next(iter(contexts), None)
-
- ctx = iio.Context(uri)
-
- if uri is not None:
- print('Using auto-detected IIO context at URI \"%s\"' % uri)
-
- print('IIO context created: ' + ctx.name)
- print('Backend version: %u.%u (git tag: %s)' % ctx.version)
- print('Backend description string: ' + ctx.description)
-
- if len(ctx.attrs) > 0:
- print('IIO context has %u attributes:' % len(ctx.attrs))
- for attr, value in ctx.attrs.items():
- print('\t' + attr + ': ' + value)
-
- print('IIO context has %u devices:' % len(ctx.devices))
-
- for dev in ctx.devices:
- print('\t' + dev.id + ': ' + dev.name)
-
- if dev is iio.Trigger:
- print('Found trigger! Rate: %u Hz' % dev.frequency)
-
- print('\t\t%u channels found:' % len(dev.channels))
-
- for chn in dev.channels:
- print('\t\t\t%s: %s (%s)' % (chn.id, chn.name or "", 'output' if chn.output else 'input'))
-
- if len(chn.attrs) != 0:
- print('\t\t\t%u channel-specific attributes found:' % len(chn.attrs))
-
- for attr in chn.attrs:
- try:
- print('\t\t\t\t' + attr + ', value: ' + chn.attrs[attr].value)
- except OSError as e:
- print('Unable to read ' + attr + ': ' + e.strerror)
-
- if len(dev.attrs) != 0:
- print('\t\t%u device-specific attributes found:' % len(dev.attrs))
-
- for attr in dev.attrs:
- try:
- print('\t\t\t' + attr + ', value: ' + dev.attrs[attr].value)
- except OSError as e:
- print('Unable to read ' + attr + ': ' + e.strerror)
-
- if len(dev.debug_attrs) != 0:
- print('\t\t%u debug attributes found:' % len(dev.debug_attrs))
-
- for attr in dev.debug_attrs:
- try:
- print('\t\t\t' + attr + ', value: ' + dev.debug_attrs[attr].value)
- except OSError as e:
- print('Unable to read ' + attr + ': ' + e.strerror)
-
-if __name__ == '__main__':
- main()
diff --git a/bindings/python/iio.py b/bindings/python/iio.py
deleted file mode 100644
index 3ffe2a2..0000000
--- a/bindings/python/iio.py
+++ /dev/null
@@ -1,864 +0,0 @@
-#!/usr/bin/env python
-#
-# 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.
-
-from ctypes import Structure, c_char_p, c_uint, c_int, c_size_t, \
- c_ssize_t, c_char, c_void_p, c_bool, create_string_buffer, \
- POINTER as _POINTER, CDLL as _cdll, memmove as _memmove, byref as _byref
-from os import strerror as _strerror
-from platform import system as _system
-import weakref
-
-if 'Windows' in _system():
- from ctypes import get_last_error
-else:
- from ctypes import get_errno
-
-def _checkNull(result, func, arguments):
- if result:
- return result
- else:
- err = get_last_error() if 'Windows' in _system() else get_errno()
- raise OSError(err, _strerror(err))
-
-def _checkNegative(result, func, arguments):
- if result >= 0:
- return result
- else:
- raise OSError(-result, _strerror(-result))
-
-class _ScanContext(Structure):
- pass
-class _ContextInfo(Structure):
- pass
-class _Context(Structure):
- pass
-class _Device(Structure):
- pass
-class _Channel(Structure):
- pass
-class _Buffer(Structure):
- pass
-
-_ScanContextPtr = _POINTER(_ScanContext)
-_ContextInfoPtr = _POINTER(_ContextInfo)
-_ContextPtr = _POINTER(_Context)
-_DevicePtr = _POINTER(_Device)
-_ChannelPtr = _POINTER(_Channel)
-_BufferPtr = _POINTER(_Buffer)
-
-_lib = _cdll('libiio.dll' if 'Windows' in _system() else 'libiio.so.0',
- use_errno = True, use_last_error = True)
-
-_get_backends_count = _lib.iio_get_backends_count
-_get_backends_count.restype = c_uint
-
-_get_backend = _lib.iio_get_backend
-_get_backend.argtypes = (c_uint, )
-_get_backend.restype = c_char_p
-_get_backend.errcheck = _checkNull
-
-_create_scan_context = _lib.iio_create_scan_context
-_create_scan_context.argtypes = (c_char_p, c_uint)
-_create_scan_context.restype = _ScanContextPtr
-_create_scan_context.errcheck = _checkNull
-
-_destroy_scan_context = _lib.iio_scan_context_destroy
-_destroy_scan_context.argtypes = (_ScanContextPtr, )
-
-_get_context_info_list = _lib.iio_scan_context_get_info_list
-_get_context_info_list.argtypes = (_ScanContextPtr, _POINTER(_POINTER(_ContextInfoPtr)))
-_get_context_info_list.restype = c_ssize_t
-_get_context_info_list.errcheck = _checkNegative
-
-_context_info_list_free = _lib.iio_context_info_list_free
-_context_info_list_free.argtypes = (_POINTER(_ContextInfoPtr), )
-
-_context_info_get_description = _lib.iio_context_info_get_description
-_context_info_get_description.argtypes = (_ContextInfoPtr, )
-_context_info_get_description.restype = c_char_p
-
-_context_info_get_uri = _lib.iio_context_info_get_uri
-_context_info_get_uri.argtypes = (_ContextInfoPtr, )
-_context_info_get_uri.restype = c_char_p
-
-_new_local = _lib.iio_create_local_context
-_new_local.restype = _ContextPtr
-_new_local.errcheck = _checkNull
-
-_new_xml = _lib.iio_create_xml_context
-_new_xml.restype = _ContextPtr
-_new_xml.argtypes = (c_char_p, )
-_new_xml.errcheck = _checkNull
-
-_new_network = _lib.iio_create_network_context
-_new_network.restype = _ContextPtr
-_new_network.argtypes = (c_char_p, )
-_new_network.errcheck = _checkNull
-
-_new_default = _lib.iio_create_default_context
-_new_default.restype = _ContextPtr
-_new_default.errcheck = _checkNull
-
-_new_uri = _lib.iio_create_context_from_uri
-_new_uri.restype = _ContextPtr
-_new_uri.errcheck = _checkNull
-
-_destroy = _lib.iio_context_destroy
-_destroy.argtypes = (_ContextPtr, )
-
-_get_name = _lib.iio_context_get_name
-_get_name.restype = c_char_p
-_get_name.argtypes = (_ContextPtr, )
-_get_name.errcheck = _checkNull
-
-_get_description = _lib.iio_context_get_description
-_get_description.restype = c_char_p
-_get_description.argtypes = (_ContextPtr, )
-
-_get_xml = _lib.iio_context_get_xml
-_get_xml.restype = c_char_p
-_get_xml.argtypes = (_ContextPtr, )
-
-_get_library_version = _lib.iio_library_get_version
-_get_library_version.argtypes = (_POINTER(c_uint), _POINTER(c_uint), c_char_p, )
-
-_get_version = _lib.iio_context_get_version
-_get_version.restype = c_int
-_get_version.argtypes = (_ContextPtr, _POINTER(c_uint), _POINTER(c_uint), c_char_p, )
-_get_version.errcheck = _checkNegative
-
-_get_attrs_count = _lib.iio_context_get_attrs_count
-_get_attrs_count.restype = c_uint
-_get_attrs_count.argtypes = (_ContextPtr, )
-
-_get_attr = _lib.iio_context_get_attr
-_get_attr.restype = c_int
-_get_attr.argtypes = (_ContextPtr, c_uint, _POINTER(c_char_p), _POINTER(c_char_p))
-_get_attr.errcheck = _checkNegative
-
-_devices_count = _lib.iio_context_get_devices_count
-_devices_count.restype = c_uint
-_devices_count.argtypes = (_ContextPtr, )
-
-_get_device = _lib.iio_context_get_device
-_get_device.restype = _DevicePtr
-_get_device.argtypes = (_ContextPtr, c_uint)
-_get_device.errcheck = _checkNull
-
-_set_timeout = _lib.iio_context_set_timeout
-_set_timeout.restype = c_int
-_set_timeout.argtypes = (_ContextPtr, c_uint, )
-_set_timeout.errcheck = _checkNegative
-
-_clone = _lib.iio_context_clone
-_clone.restype = _ContextPtr
-_clone.argtypes = (_ContextPtr, )
-_clone.errcheck = _checkNull
-
-_d_get_id = _lib.iio_device_get_id
-_d_get_id.restype = c_char_p
-_d_get_id.argtypes = (_DevicePtr, )
-_d_get_id.errcheck = _checkNull
-
-_d_get_name = _lib.iio_device_get_name
-_d_get_name.restype = c_char_p
-_d_get_name.argtypes = (_DevicePtr, )
-
-_d_attr_count = _lib.iio_device_get_attrs_count
-_d_attr_count.restype = c_uint
-_d_attr_count.argtypes = (_DevicePtr, )
-
-_d_get_attr = _lib.iio_device_get_attr
-_d_get_attr.restype = c_char_p
-_d_get_attr.argtypes = (_DevicePtr, )
-_d_get_attr.errcheck = _checkNull
-
-_d_read_attr = _lib.iio_device_attr_read
-_d_read_attr.restype = c_ssize_t
-_d_read_attr.argtypes = (_DevicePtr, c_char_p, c_char_p, c_size_t)
-_d_read_attr.errcheck = _checkNegative
-
-_d_write_attr = _lib.iio_device_attr_write
-_d_write_attr.restype = c_ssize_t
-_d_write_attr.argtypes = (_DevicePtr, c_char_p, c_char_p)
-_d_write_attr.errcheck = _checkNegative
-
-_d_debug_attr_count = _lib.iio_device_get_debug_attrs_count
-_d_debug_attr_count.restype = c_uint
-_d_debug_attr_count.argtypes = (_DevicePtr, )
-
-_d_get_debug_attr = _lib.iio_device_get_debug_attr
-_d_get_debug_attr.restype = c_char_p
-_d_get_debug_attr.argtypes = (_DevicePtr, )
-_d_get_debug_attr.errcheck = _checkNull
-
-_d_read_debug_attr = _lib.iio_device_debug_attr_read
-_d_read_debug_attr.restype = c_ssize_t
-_d_read_debug_attr.argtypes = (_DevicePtr, c_char_p, c_char_p, c_size_t)
-_d_read_debug_attr.errcheck = _checkNegative
-
-_d_write_debug_attr = _lib.iio_device_debug_attr_write
-_d_write_debug_attr.restype = c_ssize_t
-_d_write_debug_attr.argtypes = (_DevicePtr, c_char_p, c_char_p)
-_d_write_debug_attr.errcheck = _checkNegative
-
-_d_reg_write = _lib.iio_device_reg_write
-_d_reg_write.restype = c_int
-_d_reg_write.argtypes = (_DevicePtr, c_uint, c_uint)
-_d_reg_write.errcheck = _checkNegative
-
-_d_reg_read = _lib.iio_device_reg_read
-_d_reg_read.restype = c_int
-_d_reg_read.argtypes = (_DevicePtr, c_uint, _POINTER(c_uint))
-_d_reg_read.errcheck = _checkNegative
-
-_channels_count = _lib.iio_device_get_channels_count
-_channels_count.restype = c_uint
-_channels_count.argtypes = (_DevicePtr, )
-
-_get_channel = _lib.iio_device_get_channel
-_get_channel.restype = _ChannelPtr
-_get_channel.argtypes = (_DevicePtr, c_uint)
-_get_channel.errcheck = _checkNull
-
-_get_sample_size = _lib.iio_device_get_sample_size
-_get_sample_size.restype = c_int
-_get_sample_size.argtypes = (_DevicePtr, )
-_get_sample_size.errcheck = _checkNegative
-
-_d_is_trigger = _lib.iio_device_is_trigger
-_d_is_trigger.restype = c_bool
-_d_is_trigger.argtypes = (_DevicePtr, )
-
-_d_get_trigger = _lib.iio_device_get_trigger
-_d_get_trigger.restype = c_int
-_d_get_trigger.argtypes = (_DevicePtr, _DevicePtr, )
-_d_get_trigger.errcheck = _checkNegative
-
-_d_set_trigger = _lib.iio_device_set_trigger
-_d_set_trigger.restype = c_int
-_d_set_trigger.argtypes = (_DevicePtr, _DevicePtr, )
-_d_set_trigger.errcheck = _checkNegative
-
-_d_set_buffers_count = _lib.iio_device_set_kernel_buffers_count
-_d_set_buffers_count.restype = c_int
-_d_set_buffers_count.argtypes = (_DevicePtr, c_uint)
-_d_set_buffers_count.errcheck = _checkNegative
-
-_c_get_id = _lib.iio_channel_get_id
-_c_get_id.restype = c_char_p
-_c_get_id.argtypes = (_ChannelPtr, )
-_c_get_id.errcheck = _checkNull
-
-_c_get_name = _lib.iio_channel_get_name
-_c_get_name.restype = c_char_p
-_c_get_name.argtypes = (_ChannelPtr, )
-
-_c_is_output = _lib.iio_channel_is_output
-_c_is_output.restype = c_bool
-_c_is_output.argtypes = (_ChannelPtr, )
-
-_c_is_scan_element = _lib.iio_channel_is_scan_element
-_c_is_scan_element.restype = c_bool
-_c_is_scan_element.argtypes = (_ChannelPtr, )
-
-_c_attr_count = _lib.iio_channel_get_attrs_count
-_c_attr_count.restype = c_uint
-_c_attr_count.argtypes = (_ChannelPtr, )
-
-_c_get_attr = _lib.iio_channel_get_attr
-_c_get_attr.restype = c_char_p
-_c_get_attr.argtypes = (_ChannelPtr, )
-_c_get_attr.errcheck = _checkNull
-
-_c_get_filename = _lib.iio_channel_attr_get_filename
-_c_get_filename.restype = c_char_p
-_c_get_filename.argtypes = (_ChannelPtr, c_char_p, )
-_c_get_filename.errcheck = _checkNull
-
-_c_read_attr = _lib.iio_channel_attr_read
-_c_read_attr.restype = c_ssize_t
-_c_read_attr.argtypes = (_ChannelPtr, c_char_p, c_char_p, c_size_t)
-_c_read_attr.errcheck = _checkNegative
-
-_c_write_attr = _lib.iio_channel_attr_write
-_c_write_attr.restype = c_ssize_t
-_c_write_attr.argtypes = (_ChannelPtr, c_char_p, c_char_p)
-_c_write_attr.errcheck = _checkNegative
-
-_c_enable = _lib.iio_channel_enable
-_c_enable.argtypes = (_ChannelPtr, )
-
-_c_disable = _lib.iio_channel_disable
-_c_disable.argtypes = (_ChannelPtr, )
-
-_c_is_enabled = _lib.iio_channel_is_enabled
-_c_is_enabled.restype = c_bool
-_c_is_enabled.argtypes = (_ChannelPtr, )
-
-_c_read = _lib.iio_channel_read
-_c_read.restype = c_ssize_t
-_c_read.argtypes = (_ChannelPtr, _BufferPtr, c_void_p, c_size_t, )
-
-_c_read_raw = _lib.iio_channel_read_raw
-_c_read_raw.restype = c_ssize_t
-_c_read_raw.argtypes = (_ChannelPtr, _BufferPtr, c_void_p, c_size_t, )
-
-_c_write = _lib.iio_channel_write
-_c_write.restype = c_ssize_t
-_c_write.argtypes = (_ChannelPtr, _BufferPtr, c_void_p, c_size_t, )
-
-_c_write_raw = _lib.iio_channel_write_raw
-_c_write_raw.restype = c_ssize_t
-_c_write_raw.argtypes = (_ChannelPtr, _BufferPtr, c_void_p, c_size_t, )
-
-_create_buffer = _lib.iio_device_create_buffer
-_create_buffer.restype = _BufferPtr
-_create_buffer.argtypes = (_DevicePtr, c_size_t, c_bool, )
-_create_buffer.errcheck = _checkNull
-
-_buffer_destroy = _lib.iio_buffer_destroy
-_buffer_destroy.argtypes = (_BufferPtr, )
-
-_buffer_refill = _lib.iio_buffer_refill
-_buffer_refill.restype = c_ssize_t
-_buffer_refill.argtypes = (_BufferPtr, )
-_buffer_refill.errcheck = _checkNegative
-
-_buffer_push_partial = _lib.iio_buffer_push_partial
-_buffer_push_partial.restype = c_ssize_t
-_buffer_push_partial.argtypes = (_BufferPtr, c_uint, )
-_buffer_push_partial.errcheck = _checkNegative
-
-_buffer_start = _lib.iio_buffer_start
-_buffer_start.restype = c_void_p
-_buffer_start.argtypes = (_BufferPtr, )
-
-_buffer_end = _lib.iio_buffer_end
-_buffer_end.restype = c_void_p
-_buffer_end.argtypes = (_BufferPtr, )
-
-def _get_lib_version():
- major = c_uint()
- minor = c_uint()
- buf = create_string_buffer(8)
- _get_library_version(_byref(major), _byref(minor), buf)
- return (major.value, minor.value, buf.value.decode('ascii') )
-
-version = _get_lib_version()
-backends = [ _get_backend(x).decode('ascii') for x in range(0, _get_backends_count()) ]
-
-class _Attr(object):
- def __init__(self, name, filename = None):
- self._name = name
- self._name_ascii = name.encode('ascii')
- self._filename = name if filename is None else filename
-
- def __str__(self):
- return self._name
-
- name = property(lambda self: self._name, None, None,
- "The name of this attribute.\n\ttype=str")
- filename = property(lambda self: self._filename, None, None,
- "The filename in sysfs to which this attribute is bound.\n\ttype=str")
- value = property(lambda self: self.__read(), lambda self, x: self.__write(x),
- None, "Current value of this attribute.\n\ttype=str")
-
-class ChannelAttr(_Attr):
- """Represents an attribute of a channel."""
-
- def __init__(self, channel, name):
- super(ChannelAttr, self).__init__(name, _c_get_filename(channel, name.encode('ascii')).decode('ascii'))
- self._channel = channel
-
- def _Attr__read(self):
- buf = create_string_buffer(1024)
- _c_read_attr(self._channel, self._name_ascii, buf, len(buf))
- return buf.value.decode('ascii')
-
- def _Attr__write(self, value):
- _c_write_attr(self._channel, self._name_ascii, value.encode('ascii'))
-
-class DeviceAttr(_Attr):
- """Represents an attribute of an IIO device."""
-
- def __init__(self, device, name):
- super(DeviceAttr, self).__init__(name)
- self._device = device
-
- def _Attr__read(self):
- buf = create_string_buffer(1024)
- _d_read_attr(self._device, self._name_ascii, buf, len(buf))
- return buf.value.decode('ascii')
-
- def _Attr__write(self, value):
- _d_write_attr(self._device, self._name_ascii, value.encode('ascii'))
-
-class DeviceDebugAttr(DeviceAttr):
- """Represents a debug attribute of an IIO device."""
-
- def __init__(self, device, name):
- super(DeviceDebugAttr, self).__init__(device, name)
-
- def _Attr__read(self):
- buf = create_string_buffer(1024)
- _d_read_debug_attr(self._device, self._name_ascii, buf, len(buf))
- return buf.value.decode('ascii')
-
- def _Attr__write(self, value):
- _d_write_debug_attr(self._device, self._name_ascii, value.encode('ascii'))
-
-class Channel(object):
- def __init__(self, _channel):
- self._channel = _channel
- self._attrs = { name : ChannelAttr(_channel, name) for name in \
- [_c_get_attr(_channel, x).decode('ascii') for x in range(0, _c_attr_count(_channel))] }
- self._id = _c_get_id(self._channel).decode('ascii')
-
- name_raw = _c_get_name(self._channel)
- self._name = name_raw.decode('ascii') if name_raw is not None else None
- self._output = _c_is_output(self._channel)
- self._scan_element = _c_is_scan_element(self._channel)
-
- def read(self, buf, raw = False):
- """
- Extract the samples corresponding to this channel from the given iio.Buffer object.
-
- parameters:
- buf: type=iio.Buffer
- A valid instance of the iio.Buffer class
- raw: type=bool
- If set to True, the samples are not converted from their
- native format to their host format
-
- returns: type=bytearray
- An array containing the samples for this channel
- """
- array = bytearray(buf._length)
- mytype = c_char * len(array)
- c_array = mytype.from_buffer(array)
- if raw:
- length = _c_read_raw(self._channel, buf._buffer, c_array, len(array))
- else:
- length = _c_read(self._channel, buf._buffer, c_array, len(array))
- return array[:length]
-
- def write(self, buf, array, raw = False):
- """
- Write the specified array of samples corresponding to this channel into the given iio.Buffer object.
-
- parameters:
- buf: type=iio.Buffer
- A valid instance of the iio.Buffer class
- array: type=bytearray
- The array containing the samples to copy
- raw: type=bool
- If set to True, the samples are not converted from their
- host format to their native format
-
- returns: type=int
- The number of bytes written
- """
- mytype = c_char * len(array)
- c_array = mytype.from_buffer(array)
- if raw:
- return _c_write_raw(self._channel, buf._buffer, c_array, len(array))
- else:
- return _c_write(self._channel, buf._buffer, c_array, len(array))
-
- id = property(lambda self: self._id, None, None,
- "An identifier of this channel.\n\tNote that it is possible that two channels have the same ID, if one is an input channel and the other is an output channel.\n\ttype=str")
- name = property(lambda self: self._name, None, None,
- "The name of this channel.\n\ttype=str")
- attrs = property(lambda self: self._attrs, None, None,
- "List of attributes for this channel.\n\ttype=dict of iio.ChannelAttr")
- output = property(lambda self: self._output, None, None,
- "Contains True if the channel is an output channel, False otherwise.\n\ttype=bool")
- scan_element = property(lambda self: self._scan_element, None, None,
- "Contains True if the channel is a scan element, False otherwise.\n\tIf a channel is a scan element, then it is possible to enable it and use it for I/O operations.\n\ttype=bool")
- enabled = property(lambda self: _c_is_enabled(self._channel), \
- lambda self, x: _c_enable(self._channel) if x else _c_disable(self._channel),
- None, "Configured state of the channel\n\ttype=bool")
-
-class Buffer(object):
- """The class used for all I/O operations."""
-
- def __init__(self, device, samples_count, cyclic = False):
- """
- Initializes a new instance of the Buffer class.
-
- parameters:
- device: type=iio.Device
- The iio.Device object that represents the device where the I/O
- operations will be performed
- samples_count: type=int
- The size of the buffer, in samples
- circular: type=bool
- If set to True, the buffer is circular
-
- returns: type=iio.Buffer
- An new instance of this class
- """
- try:
- self._buffer = _create_buffer(device._device, samples_count, cyclic)
- except:
- self._buffer = None
- raise
- self._length = samples_count * device.sample_size
- self._samples_count = samples_count
-
- self._ctx = device.ctx()
- # Holds a reference to the corresponding IIO Context. This ensures that
- # every iio.Buffer object is destroyed before its corresponding IIO Context.
-
- def __del__(self):
- if self._buffer is not None:
- _buffer_destroy(self._buffer)
-
- def __len__(self):
- """The size of this buffer, in bytes."""
- return self._length
-
- def refill(self):
- """Fetch a new set of samples from the hardware."""
- _buffer_refill(self._buffer)
-
- def push(self, samples_count = None):
- """
- Submit the samples contained in this buffer to the hardware.
-
- parameters:
- samples_count: type=int
- The number of samples to submit, default = full buffer
- """
- _buffer_push_partial(self._buffer, samples_count or self._samples_count)
-
- def read(self):
- """
- Retrieve the samples contained inside the Buffer object.
-
- returns: type=bytearray
- An array containing the samples
- """
-
- start = _buffer_start(self._buffer)
- end = _buffer_end(self._buffer)
- array = bytearray(end - start)
- mytype = c_char * len(array)
- c_array = mytype.from_buffer(array)
- _memmove(c_array, start, len(array))
- return array
-
- def write(self, array):
- """
- Copy the given array of samples inside the Buffer object.
-
- parameters:
- array: type=bytearray
- The array containing the samples to copy
-
- returns: type=int
- The number of bytes written into the buffer
- """
- start = _buffer_start(self._buffer)
- end = _buffer_end(self._buffer)
- length = end - start
- if length > len(array):
- length = len(array)
- mytype = c_char * len(array)
- c_array = mytype.from_buffer(array)
- _memmove(start, c_array, length)
- return length
-
-class _DeviceOrTrigger(object):
- def __init__(self, _device):
- self._device = _device
- self._attrs = { name : DeviceAttr(_device, name) for name in \
- [_d_get_attr(_device, x).decode('ascii') for x in range(0, _d_attr_count(_device))] }
- self._debug_attrs = { name: DeviceDebugAttr(_device, name) for name in \
- [_d_get_debug_attr(_device, x).decode('ascii') for x in range(0, _d_debug_attr_count(_device))] }
-
- # TODO(pcercuei): Use a dictionary for the channels.
- chans = [ Channel(_get_channel(self._device, x))
- for x in range(0, _channels_count(self._device)) ]
- self._channels = sorted(chans, key=lambda c: c.id)
- self._id = _d_get_id(self._device).decode('ascii')
-
- name_raw = _d_get_name(self._device)
- self._name = name_raw.decode('ascii') if name_raw is not None else None
-
- def reg_write(self, reg, value):
- """
- Set a value to one register of this device.
-
- parameters:
- reg: type=int
- The register address
- value: type=int
- The value that will be used for this register
- """
- _d_reg_write(self._device, reg, value)
-
- def reg_read(self, reg):
- """
- Read the content of a register of this device.
-
- parameters:
- reg: type=int
- The register address
-
- returns: type=int
- The value of the register
- """
- value = c_uint()
- _d_reg_read(self._device, reg, _byref(value))
- return value.value
-
- def find_channel(self, name_or_id, is_output = False):
- """
-
- Find a IIO channel by its name or ID.
-
- parameters:
- name_or_id: type=str
- The name or ID of the channel to find
- is_output: type=bool
- Set to True to search for an output channel
-
- returns: type=iio.Device or type=iio.Trigger
- The IIO Device
- """
- return next((x for x in self.channels \
- if name_or_id == x.name or name_or_id == x.id and \
- x.output == is_output), None)
-
- def set_kernel_buffers_count(self, count):
- """
-
- Set the number of kernel buffers to use with the specified device.
-
- parameters:
- count: type=int
- The number of kernel buffers
-
- """
- return _d_set_buffers_count(self._device, count)
-
- @property
- def sample_size(self):
- """
- Current sample size of this device.
- type: int
-
- The sample size varies each time channels get enabled or disabled."""
- return _get_sample_size(self._device)
-
- id = property(lambda self: self._id, None, None,
- "An identifier of this device, only valid in this IIO context.\n\ttype=str")
- name = property(lambda self: self._name, None, None,
- "The name of this device.\n\ttype=str")
- attrs = property(lambda self: self._attrs, None, None,
- "List of attributes for this IIO device.\n\ttype=dict of iio.DeviceAttr")
- debug_attrs = property(lambda self: self._debug_attrs, None, None,
- "List of debug attributes for this IIO device.\n\ttype=dict of iio.DeviceDebugAttr")
- channels = property(lambda self: self._channels, None, None,
- "List of channels available with this IIO device.\n\ttype=list of iio.Channel objects")
-
-class Trigger(_DeviceOrTrigger):
- """Contains the representation of an IIO device that can act as a trigger."""
-
- def __init__(self, _device):
- super(Trigger, self).__init__(_device)
-
- def _get_rate(self):
- return int(self._attrs['frequency'].value)
-
- def _set_rate(self, value):
- self._attrs['frequency'].value = str(value)
-
- frequency = property(_get_rate, _set_rate, None,
- "Configured frequency (in Hz) of this trigger\n\ttype=int")
-
-class Device(_DeviceOrTrigger):
- """Contains the representation of an IIO device."""
-
- def __init__(self, ctx, _device):
- super(Device, self).__init__(_device)
- self.ctx = weakref.ref(ctx)
-
- def _set_trigger(self, trigger):
- _d_set_trigger(self._device, trigger._device if trigger else None)
-
- def _get_trigger(self):
- value = _Device()
- _d_get_trigger(self._device, _byref(value))
-
- for dev in self.ctx()._devices:
- if value == dev._device:
- return dev
- return None
-
- trigger = property(_get_trigger, _set_trigger, None, \
- "Contains the configured trigger for this IIO device.\n\ttype=iio.Trigger")
-
-class Context(object):
- """Contains the representation of an IIO context."""
-
- def __init__(self, _context=None):
- """
- Initializes a new instance of the Context class, using the local or the network backend of the IIO library.
-
- returns: type=iio.Context
- An new instance of this class
-
- 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.
- """
- self._context = None
-
- if(_context is None):
- self._context = _new_default()
- elif type(_context) is str or type(_context) is unicode:
- self._context = _new_uri(_context.encode('ascii'))
- else:
- self._context = _context
-
- self._attrs = {}
- for x in range(0, _get_attrs_count(self._context)):
- str1 = c_char_p()
- str2 = c_char_p()
- _get_attr(self._context, x, _byref(str1), _byref(str2))
- self._attrs[str1.value.decode('ascii')] = str2.value.decode('ascii')
-
- # TODO(pcercuei): Use a dictionary for the devices.
- self._devices = [ Trigger(dev) if _d_is_trigger(dev) else Device(self, dev) for dev in \
- [ _get_device(self._context, x) for x in range(0, _devices_count(self._context)) ]]
- self._name = _get_name(self._context).decode('ascii')
- self._description = _get_description(self._context).decode('ascii')
- self._xml = _get_xml(self._context).decode('ascii')
-
- major = c_uint()
- minor = c_uint()
- buf = create_string_buffer(8)
- _get_version(self._context, _byref(major), _byref(minor), buf)
- self._version = (major.value, minor.value, buf.value.decode('ascii') )
-
- def __del__(self):
- if(self._context is not None):
- _destroy(self._context)
-
- def set_timeout(self, timeout):
- """
- Set a timeout for I/O operations.
-
- parameters:
- timeout: type=int
- The timeout value, in milliseconds
- """
- _set_timeout(self._context, timeout)
-
- def clone(self):
- """
- Clone this instance.
-
- returns: type=iio.LocalContext
- An new instance of this class
- """
- return Context(_clone(self._context))
-
- def find_device(self, name_or_id):
- """
-
- Find a IIO device by its name or ID.
-
- parameters:
- name_or_id: type=str
- The name or ID of the device to find
-
- returns: type=iio.Device or type=iio.Trigger
- The IIO Device
- """
- return next((x for x in self.devices \
- if name_or_id == x.name or name_or_id == x.id), None)
-
- name = property(lambda self: self._name, None, None, \
- "Name of this IIO context.\n\ttype=str")
- description = property(lambda self: self._description, None, None, \
- "Description of this IIO context.\n\ttype=str")
- xml = property(lambda self: self._xml, None, None, \
- "XML representation of the current context.\n\ttype=str")
- version = property(lambda self: self._version, None, None, \
- "Version of the backend.\n\ttype=(int, int, str)")
- attrs = property(lambda self: self._attrs, None, None, \
- "List of context-specific attributes\n\ttype=dict of str objects")
- devices = property(lambda self: self._devices, None, None, \
- "List of devices contained in this context.\n\ttype=list of iio.Device and iio.Trigger objects")
-
-class LocalContext(Context):
- def __init__(self):
- """
- Initializes a new instance of the Context class, using the local backend of the IIO library.
-
- returns: type=iio.LocalContext
- An new instance of this class
- """
- ctx = _new_local()
- super(LocalContext, self).__init__(ctx)
-
-class XMLContext(Context):
- def __init__(self, xmlfile):
- """
- Initializes a new instance of the Context class, using the XML backend of the IIO library.
-
- parameters:
- xmlfile: type=str
- Filename of the XML file to build the context from
-
- returns: type=iio.XMLContext
- An new instance of this class
- """
- ctx = _new_xml(xmlfile.encode('ascii'))
- super(XMLContext, self).__init__(ctx)
-
-class NetworkContext(Context):
- def __init__(self, hostname = None):
- """
- Initializes a new instance of the Context class, using the network backend of the IIO library.
-
- parameters:
- hostname: type=str
- Hostname, IPv4 or IPv6 address where the IIO Daemon is running
-
- returns: type=iio.NetworkContext
- An new instance of this class
- """
- ctx = _new_network(hostname.encode('ascii') if hostname is not None else None)
- super(NetworkContext, self).__init__(ctx)
-
-def scan_contexts():
- d = dict()
- ptr = _POINTER(_ContextInfoPtr)()
-
- ctx = _create_scan_context(None, 0)
- nb = _get_context_info_list(ctx, _byref(ptr));
-
- for i in range(0, nb):
- d[_context_info_get_uri(ptr[i]).decode('ascii')] = _context_info_get_description(ptr[i]).decode('ascii')
-
- _context_info_list_free(ptr)
- _destroy_scan_context(ctx)
- return d
diff --git a/bindings/python/setup.py.cmakein b/bindings/python/setup.py.cmakein
deleted file mode 100644
index 4cf1b50..0000000
--- a/bindings/python/setup.py.cmakein
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright (C) 2015 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.
-
-from distutils.core import setup
-
-setup(name='libiio',
- version='${VERSION}',
- package_dir={'': '${CMAKE_CURRENT_SOURCE_DIR}'},
- description='Library to use the Industrial IO devices',
- url='https://github.com/analogdevicesinc/libiio',
- py_modules=['iio'],
- )
diff --git a/buffer.c b/buffer.c
deleted file mode 100644
index 91aeff6..0000000
--- a/buffer.c
+++ /dev/null
@@ -1,324 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2014-2015 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.
- *
- * */
-
-#include "iio-config.h"
-#include "iio-private.h"
-
-#include <errno.h>
-#include <string.h>
-
-struct callback_wrapper_data {
- ssize_t (*callback)(const struct iio_channel *, void *, size_t, void *);
- void *data;
- uint32_t *mask;
-};
-
-static bool device_is_high_speed(const struct iio_device *dev)
-{
- /* Little trick: We call the backend's get_buffer() function, which is
- * for now only implemented in the Local backend, with a NULL pointer.
- * It will return -ENOSYS if the device is not high speed, and either
- * -EBADF or -EINVAL otherwise. */
- const struct iio_backend_ops *ops = dev->ctx->ops;
- return !!ops->get_buffer &&
- (ops->get_buffer(dev, NULL, 0, NULL, 0) != -ENOSYS);
-}
-
-struct iio_buffer * iio_device_create_buffer(const struct iio_device *dev,
- size_t samples_count, bool cyclic)
-{
- int ret = -EINVAL;
- struct iio_buffer *buf;
- unsigned int sample_size = iio_device_get_sample_size(dev);
-
- if (!sample_size || !samples_count)
- goto err_set_errno;
-
- buf = malloc(sizeof(*buf));
- if (!buf) {
- ret = -ENOMEM;
- goto err_set_errno;
- }
-
- buf->dev_sample_size = sample_size;
- buf->length = sample_size * samples_count;
- buf->dev = dev;
- buf->mask = calloc(dev->words, sizeof(*buf->mask));
- if (!buf->mask) {
- ret = -ENOMEM;
- goto err_free_buf;
- }
-
- /* Set the default channel mask to the one used by the device.
- * While input buffers will erase this as soon as the refill function
- * is used, it is useful for output buffers, as it permits
- * iio_buffer_foreach_sample to be used. */
- memcpy(buf->mask, dev->mask, dev->words * sizeof(*buf->mask));
-
- ret = iio_device_open(dev, samples_count, cyclic);
- if (ret < 0)
- goto err_free_mask;
-
- buf->dev_is_high_speed = device_is_high_speed(dev);
- if (buf->dev_is_high_speed) {
- /* Dequeue the first buffer, so that buf->buffer is correctly
- * initialized */
- buf->buffer = NULL;
- if (iio_device_is_tx(dev)) {
- ret = dev->ctx->ops->get_buffer(dev, &buf->buffer,
- buf->length, buf->mask, dev->words);
- if (ret < 0)
- goto err_close_device;
- }
- } else {
- buf->buffer = malloc(buf->length);
- if (!buf->buffer) {
- ret = -ENOMEM;
- goto err_close_device;
- }
- }
-
- buf->sample_size = iio_device_get_sample_size_mask(dev,
- buf->mask, dev->words);
- buf->data_length = buf->length;
- return buf;
-
-err_close_device:
- iio_device_close(dev);
-err_free_mask:
- free(buf->mask);
-err_free_buf:
- free(buf);
-err_set_errno:
- errno = -ret;
- return NULL;
-}
-
-void iio_buffer_destroy(struct iio_buffer *buffer)
-{
- iio_device_close(buffer->dev);
- if (!buffer->dev_is_high_speed)
- free(buffer->buffer);
- free(buffer->mask);
- free(buffer);
-}
-
-int iio_buffer_get_poll_fd(struct iio_buffer *buffer)
-{
- return iio_device_get_poll_fd(buffer->dev);
-}
-
-int iio_buffer_set_blocking_mode(struct iio_buffer *buffer, bool blocking)
-{
- return iio_device_set_blocking_mode(buffer->dev, blocking);
-}
-
-ssize_t iio_buffer_refill(struct iio_buffer *buffer)
-{
- ssize_t read;
- const struct iio_device *dev = buffer->dev;
-
- if (buffer->dev_is_high_speed) {
- read = dev->ctx->ops->get_buffer(dev, &buffer->buffer,
- buffer->length, buffer->mask, dev->words);
- } else {
- read = iio_device_read_raw(dev, buffer->buffer, buffer->length,
- buffer->mask, dev->words);
- }
-
- if (read >= 0) {
- buffer->data_length = read;
- buffer->sample_size = iio_device_get_sample_size_mask(dev,
- buffer->mask, dev->words);
- }
- return read;
-}
-
-ssize_t iio_buffer_push(struct iio_buffer *buffer)
-{
- const struct iio_device *dev = buffer->dev;
- ssize_t ret;
-
- if (buffer->dev_is_high_speed) {
- void *buf;
- ret = dev->ctx->ops->get_buffer(dev, &buf,
- buffer->data_length, buffer->mask, dev->words);
- if (ret >= 0) {
- buffer->buffer = buf;
- ret = (ssize_t) buffer->data_length;
- }
- } else {
- void *ptr = buffer->buffer;
- size_t tmp_len;
-
- /* iio_device_write_raw doesn't guarantee that all bytes are
- * written */
- for (tmp_len = buffer->data_length; tmp_len; ) {
- ret = iio_device_write_raw(dev, ptr, tmp_len);
- if (ret < 0)
- goto out_reset_data_length;
-
- tmp_len -= ret;
- ptr = (void *) ((uintptr_t) ptr + ret);
- }
-
- ret = (ssize_t) buffer->data_length;
- }
-
-out_reset_data_length:
- buffer->data_length = buffer->length;
- return ret;
-}
-
-ssize_t iio_buffer_push_partial(struct iio_buffer *buffer, size_t samples_count)
-{
- size_t new_len = samples_count * buffer->dev_sample_size;
-
- if (new_len == 0 || new_len > buffer->length)
- return -EINVAL;
-
- buffer->data_length = new_len;
- return iio_buffer_push(buffer);
-}
-
-ssize_t iio_buffer_foreach_sample(struct iio_buffer *buffer,
- ssize_t (*callback)(const struct iio_channel *,
- void *, size_t, void *), void *d)
-{
- uintptr_t ptr = (uintptr_t) buffer->buffer,
- start = ptr,
- end = ptr + buffer->data_length;
- const struct iio_device *dev = buffer->dev;
- ssize_t processed = 0;
-
- if (buffer->sample_size == 0)
- return -EINVAL;
-
- if (buffer->data_length < buffer->dev_sample_size)
- return 0;
-
- while (end - ptr >= (size_t) buffer->sample_size) {
- unsigned int i;
-
- for (i = 0; i < dev->nb_channels; i++) {
- const struct iio_channel *chn = dev->channels[i];
- unsigned int length = chn->format.length / 8;
-
- if (chn->index < 0)
- break;
-
- /* Test if the buffer has samples for this channel */
- if (!TEST_BIT(buffer->mask, chn->number))
- continue;
-
- if ((ptr - start) % length)
- ptr += length - ((ptr - start) % length);
-
- /* Test if the client wants samples from this channel */
- if (TEST_BIT(dev->mask, chn->number)) {
- ssize_t ret = callback(chn,
- (void *) ptr, length, d);
- if (ret < 0)
- return ret;
- else
- processed += ret;
- }
-
- if (i == dev->nb_channels - 1 || dev->channels[
- i + 1]->index != chn->index)
- ptr += length * chn->format.repeat;
- }
- }
- return processed;
-}
-
-void * iio_buffer_start(const struct iio_buffer *buffer)
-{
- return buffer->buffer;
-}
-
-void * iio_buffer_first(const struct iio_buffer *buffer,
- const struct iio_channel *chn)
-{
- size_t len;
- unsigned int i;
- uintptr_t ptr = (uintptr_t) buffer->buffer,
- start = ptr;
-
- if (!iio_channel_is_enabled(chn))
- return iio_buffer_end(buffer);
-
- for (i = 0; i < buffer->dev->nb_channels; i++) {
- struct iio_channel *cur = buffer->dev->channels[i];
- len = cur->format.length / 8 * cur->format.repeat;
-
- /* NOTE: dev->channels are ordered by index */
- if (cur->index < 0 || cur->index == chn->index)
- break;
-
- /* Test if the buffer has samples for this channel */
- if (!TEST_BIT(buffer->mask, cur->number))
- continue;
-
- /* Two channels with the same index use the same samples */
- if (i > 0 && cur->index == buffer->dev->channels[i - 1]->index)
- continue;
-
- if ((ptr - start) % len)
- ptr += len - ((ptr - start) % len);
- ptr += len;
- }
-
- len = chn->format.length / 8;
- if ((ptr - start) % len)
- ptr += len - ((ptr - start) % len);
- return (void *) ptr;
-}
-
-ptrdiff_t iio_buffer_step(const struct iio_buffer *buffer)
-{
- return (ptrdiff_t) buffer->sample_size;
-}
-
-void * iio_buffer_end(const struct iio_buffer *buffer)
-{
- return (void *) ((uintptr_t) buffer->buffer + buffer->data_length);
-}
-
-void iio_buffer_set_data(struct iio_buffer *buf, void *data)
-{
- buf->userdata = data;
-}
-
-void * iio_buffer_get_data(const struct iio_buffer *buf)
-{
- return buf->userdata;
-}
-
-const struct iio_device * iio_buffer_get_device(const struct iio_buffer *buf)
-{
- return buf->dev;
-}
-
-void iio_buffer_cancel(struct iio_buffer *buf)
-{
- const struct iio_backend_ops *ops = buf->dev->ctx->ops;
-
- if (ops->cancel)
- ops->cancel(buf->dev);
-}
diff --git a/channel.c b/channel.c
deleted file mode 100644
index e360a63..0000000
--- a/channel.c
+++ /dev/null
@@ -1,844 +0,0 @@
-/*
- * 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.
- *
- * */
-
-#include "debug.h"
-#include "iio-private.h"
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-static const char * const iio_chan_type_name_spec[] = {
- [IIO_VOLTAGE] = "voltage",
- [IIO_CURRENT] = "current",
- [IIO_POWER] = "power",
- [IIO_ACCEL] = "accel",
- [IIO_ANGL_VEL] = "anglvel",
- [IIO_MAGN] = "magn",
- [IIO_LIGHT] = "illuminance",
- [IIO_INTENSITY] = "intensity",
- [IIO_PROXIMITY] = "proximity",
- [IIO_TEMP] = "temp",
- [IIO_INCLI] = "incli",
- [IIO_ROT] = "rot",
- [IIO_ANGL] = "angl",
- [IIO_TIMESTAMP] = "timestamp",
- [IIO_CAPACITANCE] = "capacitance",
- [IIO_ALTVOLTAGE] = "altvoltage",
- [IIO_CCT] = "cct",
- [IIO_PRESSURE] = "pressure",
- [IIO_HUMIDITYRELATIVE] = "humidityrelative",
- [IIO_ACTIVITY] = "activity",
- [IIO_STEPS] = "steps",
- [IIO_ENERGY] = "energy",
- [IIO_DISTANCE] = "distance",
- [IIO_VELOCITY] = "velocity",
- [IIO_CONCENTRATION] = "concentration",
- [IIO_RESISTANCE] = "resistance",
- [IIO_PH] = "ph",
- [IIO_UVINDEX] = "uvindex",
- [IIO_ELECTRICALCONDUCTIVITY] = "electricalconductivity",
- [IIO_COUNT] = "count",
- [IIO_INDEX] = "index",
- [IIO_GRAVITY] = "gravity",
-};
-
-static const char * const modifier_names[] = {
- [IIO_MOD_X] = "x",
- [IIO_MOD_Y] = "y",
- [IIO_MOD_Z] = "z",
- [IIO_MOD_X_AND_Y] = "x&y",
- [IIO_MOD_X_AND_Z] = "x&z",
- [IIO_MOD_Y_AND_Z] = "y&z",
- [IIO_MOD_X_AND_Y_AND_Z] = "x&y&z",
- [IIO_MOD_X_OR_Y] = "x|y",
- [IIO_MOD_X_OR_Z] = "x|z",
- [IIO_MOD_Y_OR_Z] = "y|z",
- [IIO_MOD_X_OR_Y_OR_Z] = "x|y|z",
- [IIO_MOD_ROOT_SUM_SQUARED_X_Y] = "sqrt(x^2+y^2)",
- [IIO_MOD_SUM_SQUARED_X_Y_Z] = "x^2+y^2+z^2",
- [IIO_MOD_LIGHT_BOTH] = "both",
- [IIO_MOD_LIGHT_IR] = "ir",
- [IIO_MOD_LIGHT_CLEAR] = "clear",
- [IIO_MOD_LIGHT_RED] = "red",
- [IIO_MOD_LIGHT_GREEN] = "green",
- [IIO_MOD_LIGHT_BLUE] = "blue",
- [IIO_MOD_LIGHT_UV] = "uv",
- [IIO_MOD_QUATERNION] = "quaternion",
- [IIO_MOD_TEMP_AMBIENT] = "ambient",
- [IIO_MOD_TEMP_OBJECT] = "object",
- [IIO_MOD_NORTH_MAGN] = "from_north_magnetic",
- [IIO_MOD_NORTH_TRUE] = "from_north_true",
- [IIO_MOD_NORTH_MAGN_TILT_COMP] = "from_north_magnetic_tilt_comp",
- [IIO_MOD_NORTH_TRUE_TILT_COMP] = "from_north_true_tilt_comp",
- [IIO_MOD_RUNNING] = "running",
- [IIO_MOD_JOGGING] = "jogging",
- [IIO_MOD_WALKING] = "walking",
- [IIO_MOD_STILL] = "still",
- [IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z] = "sqrt(x^2+y^2+z^2)",
- [IIO_MOD_I] = "i",
- [IIO_MOD_Q] = "q",
- [IIO_MOD_CO2] = "co2",
- [IIO_MOD_VOC] = "voc",
-};
-
-/*
- * Looks for a IIO channel modifier at the beginning of the string s. If a
- * modifier was found the symbolic constant (IIO_MOD_*) is returned, otherwise
- * IIO_NO_MOD is returned. If a modifier was found len_p will be updated with
- * the length of the modifier.
- */
-unsigned int find_channel_modifier(const char *s, size_t *len_p)
-{
- unsigned int i;
- size_t len;
-
- for (i = 0; i < ARRAY_SIZE(modifier_names); i++) {
- if (!modifier_names[i])
- continue;
- len = strlen(modifier_names[i]);
- if (strncmp(s, modifier_names[i], len) == 0 &&
- (s[len] == '\0' || s[len] == '_')) {
- if (len_p)
- *len_p = len;
- return i;
- }
- }
-
- return IIO_NO_MOD;
-}
-
-/*
- * Initializes all auto-detected fields of the channel struct. Must be called
- * after the channel has been otherwise fully initialized.
- */
-void iio_channel_init_finalize(struct iio_channel *chn)
-{
- unsigned int i;
- size_t len;
- char *mod;
-
- chn->type = IIO_CHAN_TYPE_UNKNOWN;
- chn->modifier = IIO_NO_MOD;
-
- for (i = 0; i < ARRAY_SIZE(iio_chan_type_name_spec); i++) {
- len = strlen(iio_chan_type_name_spec[i]);
- if (strncmp(iio_chan_type_name_spec[i], chn->id, len) != 0)
- continue;
- /* Type must be followed by either a '_' or a digit */
- if (chn->id[len] != '_' && (chn->id[len] < '0' || chn->id[len] > '9'))
- continue;
-
- chn->type = (enum iio_chan_type) i;
- }
-
- mod = strchr(chn->id, '_');
- if (!mod)
- return;
-
- mod++;
-
- for (i = 0; i < ARRAY_SIZE(modifier_names); i++) {
- if (!modifier_names[i])
- continue;
- len = strlen(modifier_names[i]);
- if (strncmp(modifier_names[i], mod, len) != 0)
- continue;
-
- chn->modifier = (enum iio_modifier) i;
- break;
- }
-}
-
-static char *get_attr_xml(struct iio_channel_attr *attr, size_t *length)
-{
- char *str;
- size_t len = strlen(attr->name) + sizeof("<attribute name=\"\" />");
- if (attr->filename)
- len += strlen(attr->filename) + sizeof("filename=\"\"");
-
- str = malloc(len);
- if (!str)
- return NULL;
-
- *length = len - 1; /* Skip the \0 */
- if (attr->filename)
- iio_snprintf(str, len, "<attribute name=\"%s\" filename=\"%s\" />",
- attr->name, attr->filename);
- else
- iio_snprintf(str, len, "<attribute name=\"%s\" />", attr->name);
- return str;
-}
-
-static char * get_scan_element(const struct iio_channel *chn, size_t *length)
-{
- char buf[1024], repeat[12] = "", *str;
- char processed = (chn->format.is_fully_defined ? 'A' - 'a' : 0);
-
- if (chn->format.repeat > 1)
- iio_snprintf(repeat, sizeof(repeat), "X%u", chn->format.repeat);
-
- iio_snprintf(buf, sizeof(buf), "<scan-element index=\"%li\" "
- "format=\"%ce:%c%u/%u%s&gt;&gt;%u\" />",
- chn->index, chn->format.is_be ? 'b' : 'l',
- chn->format.is_signed ? 's' + processed : 'u' + processed,
- chn->format.bits, chn->format.length, repeat,
- chn->format.shift);
-
- if (chn->format.with_scale) {
- char *ptr = strrchr(buf, '\0');
- iio_snprintf(ptr - 2, buf + sizeof(buf) - ptr + 2,
- "scale=\"%f\" />", chn->format.scale);
- }
-
- str = iio_strdup(buf);
- if (str)
- *length = strlen(str);
- return str;
-}
-
-/* Returns a string containing the XML representation of this channel */
-char * iio_channel_get_xml(const struct iio_channel *chn, size_t *length)
-{
- size_t len = sizeof("<channel id=\"\" name=\"\" "
- "type=\"output\" ></channel>")
- + strlen(chn->id) + (chn->name ? strlen(chn->name) : 0);
- char *ptr, *str, **attrs, *scan_element = NULL;
- size_t *attrs_len, scan_element_len = 0;
- unsigned int i;
-
- if (chn->is_scan_element) {
- scan_element = get_scan_element(chn, &scan_element_len);
- if (!scan_element)
- return NULL;
- else
- len += scan_element_len;
- }
-
- attrs_len = malloc(chn->nb_attrs * sizeof(*attrs_len));
- if (!attrs_len)
- goto err_free_scan_element;
-
- attrs = malloc(chn->nb_attrs * sizeof(*attrs));
- if (!attrs)
- goto err_free_attrs_len;
-
- for (i = 0; i < chn->nb_attrs; i++) {
- char *xml = get_attr_xml(&chn->attrs[i], &attrs_len[i]);
- if (!xml)
- goto err_free_attrs;
- attrs[i] = xml;
- len += attrs_len[i];
- }
-
- str = malloc(len);
- if (!str)
- goto err_free_attrs;
-
- iio_snprintf(str, len, "<channel id=\"%s\"", chn->id);
- ptr = strrchr(str, '\0');
-
- if (chn->name) {
- sprintf(ptr, " name=\"%s\"", chn->name);
- ptr = strrchr(ptr, '\0');
- }
-
- sprintf(ptr, " type=\"%s\" >", chn->is_output ? "output" : "input");
- ptr = strrchr(ptr, '\0');
-
- if (chn->is_scan_element) {
- strcpy(ptr, scan_element);
- ptr += scan_element_len;
- }
-
- for (i = 0; i < chn->nb_attrs; i++) {
- strcpy(ptr, attrs[i]);
- ptr += attrs_len[i];
- free(attrs[i]);
- }
-
- free(scan_element);
- free(attrs);
- free(attrs_len);
-
- strcpy(ptr, "</channel>");
- *length = ptr - str + sizeof("</channel>") - 1;
- return str;
-
-err_free_attrs:
- while (i--)
- free(attrs[i]);
- free(attrs);
-err_free_attrs_len:
- free(attrs_len);
-err_free_scan_element:
- if (chn->is_scan_element)
- free(scan_element);
- return NULL;
-}
-
-const char * iio_channel_get_id(const struct iio_channel *chn)
-{
- return chn->id;
-}
-
-const char * iio_channel_get_name(const struct iio_channel *chn)
-{
- return chn->name;
-}
-
-bool iio_channel_is_output(const struct iio_channel *chn)
-{
- return chn->is_output;
-}
-
-bool iio_channel_is_scan_element(const struct iio_channel *chn)
-{
- return chn->is_scan_element;
-}
-
-enum iio_modifier iio_channel_get_modifier(const struct iio_channel *chn)
-{
- return chn->modifier;
-}
-
-enum iio_chan_type iio_channel_get_type(const struct iio_channel *chn)
-{
- return chn->type;
-}
-
-unsigned int iio_channel_get_attrs_count(const struct iio_channel *chn)
-{
- return chn->nb_attrs;
-}
-
-const char * iio_channel_get_attr(const struct iio_channel *chn,
- unsigned int index)
-{
- if (index >= chn->nb_attrs)
- return NULL;
- else
- return chn->attrs[index].name;
-}
-
-const char * iio_channel_find_attr(const struct iio_channel *chn,
- const char *name)
-{
- unsigned int i;
- for (i = 0; i < chn->nb_attrs; i++) {
- const char *attr = chn->attrs[i].name;
- if (!strcmp(attr, name))
- return attr;
- }
- return NULL;
-}
-
-ssize_t iio_channel_attr_read(const struct iio_channel *chn,
- const char *attr, char *dst, size_t len)
-{
- if (chn->dev->ctx->ops->read_channel_attr)
- return chn->dev->ctx->ops->read_channel_attr(chn,
- attr, dst, len);
- else
- return -ENOSYS;
-}
-
-ssize_t iio_channel_attr_write_raw(const struct iio_channel *chn,
- const char *attr, const void *src, size_t len)
-{
- if (chn->dev->ctx->ops->write_channel_attr)
- return chn->dev->ctx->ops->write_channel_attr(chn,
- attr, src, len);
- else
- return -ENOSYS;
-}
-
-ssize_t iio_channel_attr_write(const struct iio_channel *chn,
- const char *attr, const char *src)
-{
- return iio_channel_attr_write_raw(chn, attr, src, strlen(src) + 1);
-}
-
-void iio_channel_set_data(struct iio_channel *chn, void *data)
-{
- chn->userdata = data;
-}
-
-void * iio_channel_get_data(const struct iio_channel *chn)
-{
- return chn->userdata;
-}
-
-long iio_channel_get_index(const struct iio_channel *chn)
-{
- return chn->index;
-}
-
-const struct iio_data_format * iio_channel_get_data_format(
- const struct iio_channel *chn)
-{
- return &chn->format;
-}
-
-bool iio_channel_is_enabled(const struct iio_channel *chn)
-{
- return chn->index >= 0 && chn->dev->mask &&
- TEST_BIT(chn->dev->mask, chn->number);
-}
-
-void iio_channel_enable(struct iio_channel *chn)
-{
- if (chn->is_scan_element && chn->index >= 0 && chn->dev->mask)
- SET_BIT(chn->dev->mask, chn->number);
-}
-
-void iio_channel_disable(struct iio_channel *chn)
-{
- if (chn->index >= 0 && chn->dev->mask)
- CLEAR_BIT(chn->dev->mask, chn->number);
-}
-
-void free_channel(struct iio_channel *chn)
-{
- size_t i;
- for (i = 0; i < chn->nb_attrs; i++) {
- free(chn->attrs[i].name);
- free(chn->attrs[i].filename);
- }
- if (chn->nb_attrs)
- free(chn->attrs);
- if (chn->name)
- free(chn->name);
- if (chn->id)
- free(chn->id);
- free(chn);
-}
-
-static void byte_swap(uint8_t *dst, const uint8_t *src, size_t len)
-{
- size_t i;
- for (i = 0; i < len; i++)
- dst[i] = src[len - i - 1];
-}
-
-static void shift_bits(uint8_t *dst, size_t shift, size_t len, bool left)
-{
- size_t i, shift_bytes = shift / 8;
- shift %= 8;
-
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
- if (!left)
-#else
- if (left)
-#endif
- {
- if (shift_bytes) {
- memmove(dst, dst + shift_bytes, len - shift_bytes);
- memset(dst + len - shift_bytes, 0, shift_bytes);
- }
- if (shift) {
- for (i = 0; i < len; i++) {
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
- dst[i] >>= shift;
- if (i < len - 1)
- dst[i] |= dst[i + 1] << (8 - shift);
-#else
- dst[i] <<= shift;
- if (i < len - 1)
- dst[i] |= dst[i + 1] >> (8 - shift);
-#endif
- }
- }
- } else {
- if (shift_bytes) {
- memmove(dst + shift_bytes, dst, len - shift_bytes);
- memset(dst, 0, shift_bytes);
- }
- if (shift) {
- for (i = len; i > 0; i--) {
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
- dst[i - 1] <<= shift;
- if (i > 1)
- dst[i - 1] |= dst[i - 2] >> (8 - shift);
-#else
- dst[i - 1] >>= shift;
- if (i > 1)
- dst[i - 1] |= dst[i - 2] << (8 - shift);
-#endif
- }
- }
- }
-}
-
-static void sign_extend(uint8_t *dst, size_t bits, size_t len)
-{
- size_t upper_bytes = ((len * 8 - bits) / 8);
- uint8_t msb, msb_bit = 1 << ((bits - 1) % 8);
-
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
- msb = dst[len - 1 - upper_bytes] & msb_bit;
- if (upper_bytes)
- memset(dst + len - upper_bytes, msb ? 0xff : 0x00, upper_bytes);
- if (msb)
- dst[len - 1 - upper_bytes] |= ~(msb_bit - 1);
- else
- dst[len - 1 - upper_bytes] &= (msb_bit - 1);
-#else
- /* XXX: untested */
- msb = dst[upper_bytes] & msb_bit;
- if (upper_bytes)
- memset(dst, msb ? 0xff : 0x00, upper_bytes);
- if (msb)
- dst[upper_bytes] |= ~(msb_bit - 1);
-#endif
-}
-
-static void mask_upper_bits(uint8_t *dst, size_t bits, size_t len)
-{
- size_t i;
-
- /* Clear upper bits */
- if (bits % 8)
- dst[bits / 8] &= (1 << (bits % 8)) - 1;
-
- /* Clear upper bytes */
- for (i = (bits + 7) / 8; i < len; i++)
- dst[i] = 0;
-}
-
-
-void iio_channel_convert(const struct iio_channel *chn,
- void *dst, const void *src)
-{
- uintptr_t src_ptr = (uintptr_t) src, dst_ptr = (uintptr_t) dst;
- unsigned int len = chn->format.length / 8;
- ptrdiff_t end = len * chn->format.repeat;
- uintptr_t end_ptr = src_ptr + end;
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
- bool swap = chn->format.is_be;
-#else
- bool swap = !chn->format.is_be;
-#endif
-
- for (src_ptr = (uintptr_t) src; src_ptr < end_ptr;
- src_ptr += len, dst_ptr += len) {
- if (len == 1 || !swap)
- memcpy((void *) dst_ptr, (const void *) src_ptr, len);
- else
- byte_swap((void *) dst_ptr, (const void *) src_ptr,
- len);
-
- if (chn->format.shift)
- shift_bits((void *) dst_ptr, chn->format.shift, len,
- false);
-
- if (!chn->format.is_fully_defined) {
- if (chn->format.is_signed)
- sign_extend((void *) dst_ptr,
- chn->format.bits, len);
- else
- mask_upper_bits((void *) dst_ptr,
- chn->format.bits, len);
- }
- }
-}
-
-void iio_channel_convert_inverse(const struct iio_channel *chn,
- void *dst, const void *src)
-{
- uintptr_t src_ptr = (uintptr_t) src, dst_ptr = (uintptr_t) dst;
- unsigned int len = chn->format.length / 8;
- ptrdiff_t end = len * chn->format.repeat;
- uintptr_t end_ptr = dst_ptr + end;
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
- bool swap = chn->format.is_be;
-#else
- bool swap = !chn->format.is_be;
-#endif
- uint8_t buf[1024];
-
- /* Somehow I doubt we will have samples of 8192 bits each. */
- if (len > sizeof(buf))
- return;
-
- for (dst_ptr = (uintptr_t) dst; dst_ptr < end_ptr;
- src_ptr += len, dst_ptr += len) {
- memcpy(buf, (const void *) src_ptr, len);
- mask_upper_bits(buf, chn->format.bits, len);
-
- if (chn->format.shift)
- shift_bits(buf, chn->format.shift, len, true);
-
- if (len == 1 || !swap)
- memcpy((void *) dst_ptr, buf, len);
- else
- byte_swap((void *) dst_ptr, buf, len);
- }
-}
-
-size_t iio_channel_read_raw(const struct iio_channel *chn,
- struct iio_buffer *buf, void *dst, size_t len)
-{
- uintptr_t src_ptr, dst_ptr = (uintptr_t) dst, end = dst_ptr + len;
- unsigned int length = chn->format.length / 8 * chn->format.repeat;
- uintptr_t buf_end = (uintptr_t) iio_buffer_end(buf);
- ptrdiff_t buf_step = iio_buffer_step(buf);
-
- for (src_ptr = (uintptr_t) iio_buffer_first(buf, chn);
- src_ptr < buf_end && dst_ptr + length <= end;
- src_ptr += buf_step, dst_ptr += length)
- memcpy((void *) dst_ptr, (const void *) src_ptr, length);
- return dst_ptr - (uintptr_t) dst;
-}
-
-size_t iio_channel_read(const struct iio_channel *chn,
- struct iio_buffer *buf, void *dst, size_t len)
-{
- uintptr_t src_ptr, dst_ptr = (uintptr_t) dst, end = dst_ptr + len;
- unsigned int length = chn->format.length / 8 * chn->format.repeat;
- uintptr_t buf_end = (uintptr_t) iio_buffer_end(buf);
- ptrdiff_t buf_step = iio_buffer_step(buf);
-
- for (src_ptr = (uintptr_t) iio_buffer_first(buf, chn);
- src_ptr < buf_end && dst_ptr + length <= end;
- src_ptr += buf_step, dst_ptr += length)
- iio_channel_convert(chn,
- (void *) dst_ptr, (const void *) src_ptr);
- return dst_ptr - (uintptr_t) dst;
-}
-
-size_t iio_channel_write_raw(const struct iio_channel *chn,
- struct iio_buffer *buf, const void *src, size_t len)
-{
- uintptr_t dst_ptr, src_ptr = (uintptr_t) src, end = src_ptr + len;
- unsigned int length = chn->format.length / 8 * chn->format.repeat;
- uintptr_t buf_end = (uintptr_t) iio_buffer_end(buf);
- ptrdiff_t buf_step = iio_buffer_step(buf);
-
- for (dst_ptr = (uintptr_t) iio_buffer_first(buf, chn);
- dst_ptr < buf_end && src_ptr + length <= end;
- dst_ptr += buf_step, src_ptr += length)
- memcpy((void *) dst_ptr, (const void *) src_ptr, length);
- return src_ptr - (uintptr_t) src;
-}
-
-size_t iio_channel_write(const struct iio_channel *chn,
- struct iio_buffer *buf, const void *src, size_t len)
-{
- uintptr_t dst_ptr, src_ptr = (uintptr_t) src, end = src_ptr + len;
- unsigned int length = chn->format.length / 8 * chn->format.repeat;
- uintptr_t buf_end = (uintptr_t) iio_buffer_end(buf);
- ptrdiff_t buf_step = iio_buffer_step(buf);
-
- for (dst_ptr = (uintptr_t) iio_buffer_first(buf, chn);
- dst_ptr < buf_end && src_ptr + length <= end;
- dst_ptr += buf_step, src_ptr += length)
- iio_channel_convert_inverse(chn,
- (void *) dst_ptr, (const void *) src_ptr);
- return src_ptr - (uintptr_t) src;
-}
-
-int iio_channel_attr_read_longlong(const struct iio_channel *chn,
- const char *attr, long long *val)
-{
- char *end, buf[1024];
- long long value;
- ssize_t ret = iio_channel_attr_read(chn, attr, buf, sizeof(buf));
- if (ret < 0)
- return (int) ret;
-
- value = strtoll(buf, &end, 0);
- if (end == buf)
- return -EINVAL;
- *val = value;
- return 0;
-}
-
-int iio_channel_attr_read_bool(const struct iio_channel *chn,
- const char *attr, bool *val)
-{
- long long value;
- int ret = iio_channel_attr_read_longlong(chn, attr, &value);
- if (ret < 0)
- return ret;
-
- *val = !!value;
- return 0;
-}
-
-int iio_channel_attr_read_double(const struct iio_channel *chn,
- const char *attr, double *val)
-{
- char buf[1024];
- ssize_t ret = iio_channel_attr_read(chn, attr, buf, sizeof(buf));
- if (ret < 0)
- return (int) ret;
- else
- return read_double(buf, val);
-}
-
-int iio_channel_attr_write_longlong(const struct iio_channel *chn,
- const char *attr, long long val)
-{
- ssize_t ret;
- char buf[1024];
- iio_snprintf(buf, sizeof(buf), "%lld", val);
- ret = iio_channel_attr_write(chn, attr, buf);
- return ret < 0 ? ret : 0;
-}
-
-int iio_channel_attr_write_double(const struct iio_channel *chn,
- const char *attr, double val)
-{
- ssize_t ret;
- char buf[1024];
-
- ret = (ssize_t) write_double(buf, sizeof(buf), val);
- if (!ret)
- ret = iio_channel_attr_write(chn, attr, buf);
- return ret < 0 ? ret : 0;
-}
-
-int iio_channel_attr_write_bool(const struct iio_channel *chn,
- const char *attr, bool val)
-{
- ssize_t ret;
- if (val)
- ret = iio_channel_attr_write_raw(chn, attr, "1", 2);
- else
- ret = iio_channel_attr_write_raw(chn, attr, "0", 2);
- return ret < 0 ? ret : 0;
-}
-
-const char * iio_channel_attr_get_filename(
- const struct iio_channel *chn, const char *attr)
-{
- unsigned int i;
- for (i = 0; i < chn->nb_attrs; i++) {
- if (!strcmp(chn->attrs[i].name, attr))
- return chn->attrs[i].filename;
- }
- return NULL;
-}
-
-int iio_channel_attr_read_all(struct iio_channel *chn,
- int (*cb)(struct iio_channel *chn,
- const char *attr, const char *val, size_t len, void *d),
- void *data)
-{
- int ret, buf_size;
- char *buf, *ptr;
- unsigned int i;
-
- /* We need a big buffer here; 1 MiB should be enough */
- buf = malloc(0x100000);
- if (!buf)
- return -ENOMEM;
-
- ret = (int) iio_channel_attr_read(chn, NULL, buf, 0x100000);
- if (ret < 0)
- goto err_free_buf;
-
- ptr = buf;
- buf_size = ret;
-
- for (i = 0; i < iio_channel_get_attrs_count(chn); i++) {
- const char *attr = iio_channel_get_attr(chn, i);
- int32_t len;
-
- if (buf_size < 4) {
- ret = -EPROTO;
- break;
- }
-
- len = (int32_t) iio_be32toh(*(uint32_t *) ptr);
- ptr += 4;
- buf_size -= 4;
-
- if (len > 0 && buf_size < len) {
- ret = -EPROTO;
- break;
- }
-
- if (len > 0) {
- ret = cb(chn, attr, ptr, (size_t) len, data);
- if (ret < 0)
- goto err_free_buf;
-
- if (len & 0x3)
- len = ((len >> 2) + 1) << 2;
- ptr += len;
- if (len >= buf_size)
- buf_size = 0;
- else
- buf_size -= len;
- }
- }
-
-err_free_buf:
- free(buf);
- return ret < 0 ? ret : 0;
-}
-
-int iio_channel_attr_write_all(struct iio_channel *chn,
- ssize_t (*cb)(struct iio_channel *chn,
- const char *attr, void *buf, size_t len, void *d),
- void *data)
-{
- char *buf, *ptr;
- unsigned int i;
- size_t len = 0x100000;
- int ret;
-
- /* We need a big buffer here; 1 MiB should be enough */
- buf = malloc(len);
- if (!buf)
- return -ENOMEM;
-
- ptr = buf;
-
- for (i = 0; i < iio_channel_get_attrs_count(chn); i++) {
- const char *attr = iio_channel_get_attr(chn, i);
-
- ret = (int) cb(chn, attr, ptr + 4, len - 4, data);
- if (ret < 0)
- goto err_free_buf;
-
- *(int32_t *) ptr = (int32_t) iio_htobe32((uint32_t) ret);
- ptr += 4;
- len -= 4;
-
- if (ret > 0) {
- if (ret & 0x3)
- ret = ((ret >> 2) + 1) << 2;
- ptr += ret;
- len -= ret;
- }
- }
-
- ret = (int) iio_channel_attr_write_raw(chn, NULL, buf, ptr - buf);
-
-err_free_buf:
- free(buf);
- return ret < 0 ? ret : 0;
-}
-
-const struct iio_device * iio_channel_get_device(const struct iio_channel *chn)
-{
- return chn->dev;
-}
diff --git a/cmake/CheckCaseSensitiveFileSystem.cmake b/cmake/CheckCaseSensitiveFileSystem.cmake
deleted file mode 100644
index 8bbf81c..0000000
--- a/cmake/CheckCaseSensitiveFileSystem.cmake
+++ /dev/null
@@ -1,38 +0,0 @@
-#
-# Check if the file system is case sensitive or not
-# Inspired by Andreas Lauser's cmake at:
-# https://github.com/OPM/opm-parser/blob/master/cmake/Modules/CheckCaseSensitiveFileSystem.cmake
-# Included in libiio (LGPL2) with permission.
-#
-# Sets the following variable:
-# HAVE_CASE_SENSITIVE_FILESYSTEM True if the file system honors the case of files
-#
-# I dislike that we have to emit a file from CMake, but I can't think of a better way.
-
-message(STATUS "Check for case-sensitive file systems")
-string(RANDOM LENGTH 6 ALPHABET abcdefghijklmnopqrstuvwxyz TMP_FILE_L)
-set(TMP_FILE_L "${TMP_FILE_L}.tmp")
-string(TOUPPER ${TMP_FILE_L} TMP_FILE_U)
-string(TIMESTAMP TMP_TIME)
-set(TMP_FILE_CONTENTS "${TMP_FILE_L} ${TMP_TIME}")
-# create a uppercase file
-file(WRITE "${CMAKE_BINARY_DIR}/${TMP_FILE_U}" "${TMP_FILE_CONTENTS}")
-
-# test if lowercase file can be opened
-set(FileContents "")
-if (EXISTS "${CMAKE_BINARY_DIR}/${TMP_FILE_L}")
- file(READ "${CMAKE_BINARY_DIR}/${TMP_FILE_L}" FileContents)
-endif()
-
-# remove the file
-file(REMOVE "${CMAKE_BINARY_DIR}/${TMP_FILE_U}")
-
-# check the contents
-# If it is empty, the file system is case sensitive.
-if ("${FileContents}" STREQUAL "${TMP_FILE_CONTENTS}")
- message(STATUS "File system is not case-sensitive")
- set(HAVE_CASE_SENSITIVE_FILESYSTEM 0)
-else()
- message(STATUS "File system is case-sensitive")
- set(HAVE_CASE_SENSITIVE_FILESYSTEM 1)
-endif()
diff --git a/cmake/DarwinPackaging.cmake b/cmake/DarwinPackaging.cmake
deleted file mode 100644
index 23490e4..0000000
--- a/cmake/DarwinPackaging.cmake
+++ /dev/null
@@ -1,12 +0,0 @@
-# support creating some basic binpkgs via `make package`
-
-set(CPACK_SET_DESTDIR ON)
-set(CPACK_GENERATOR TGZ)
-
-set(CPACK_PACKAGE_VERSION_MAJOR ${LIBIIO_VERSION_MAJOR})
-set(CPACK_PACKAGE_VERSION_MINOR ${LIBIIO_VERSION_MINOR})
-set(CPACK_PACKAGE_VERSION_PATCH g${LIBIIO_VERSION_GIT})
-set(CPACK_BUNDLE_NAME libiio)
-set(CPACK_PACKAGE_VERSION ${LIBIIO_VERSION})
-
-include(CPack)
diff --git a/cmake/LinuxPackaging.cmake b/cmake/LinuxPackaging.cmake
deleted file mode 100644
index 72f1c18..0000000
--- a/cmake/LinuxPackaging.cmake
+++ /dev/null
@@ -1,140 +0,0 @@
-# support creating some basic binpkgs via `make package`
-set(CPACK_SET_DESTDIR ON)
-set(CPACK_GENERATOR TGZ;DEB)
-
-FIND_PROGRAM(RPMBUILD_CMD rpmbuild)
-if (RPMBUILD_CMD)
- set(CPACK_PACKAGE_RELOCATABLE OFF)
- set(CPACK_GENERATOR ${CPACK_GENERATOR};RPM)
- set(CPACK_RPM_PACKAGE_REQUIRES "libaio >= 0.3.107, avahi >= 0.6.25, libusb1 >= 1.0.9, libxml2 >= 2.7.6")
-endif()
-
-# Add these for CentOS 7
-set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
- /lib
- /lib/udev
- /lib/udev/rules.d
- /usr/sbin
- /usr/lib/python2.7
- /usr/lib/python2.7/site-packages
- /usr/lib/pkgconfig
- /usr/lib64/pkgconfig
-)
-
-set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
-set(CPACK_PACKAGE_VERSION_MAJOR ${LIBIIO_VERSION_MAJOR})
-set(CPACK_PACKAGE_VERSION_MINOR ${LIBIIO_VERSION_MINOR})
-set(CPACK_PACKAGE_VERSION_PATCH g${LIBIIO_VERSION_GIT})
-set(CPACK_BUNDLE_NAME libiio)
-set(CPACK_PACKAGE_VERSION ${LIBIIO_VERSION})
-# debian specific package settings
-set(CPACK_PACKAGE_CONTACT "Engineerzone <https://ez.analog.com/community/linux-device-drivers>")
-
-option(DEB_DETECT_DEPENDENCIES "Detect dependencies for .deb packages" OFF)
-
-# if we are going to be looking for things, make sure we have the utilities
-if(DEB_DETECT_DEPENDENCIES)
- FIND_PROGRAM(DPKG_CMD dpkg)
- FIND_PROGRAM(DPKGQ_CMD dpkg-query)
-endif()
-
-# if we want to, and have the capabilities find what is needed,
-# based on what backends are turned on and what libraries are installed
-if(DEB_DETECT_DEPENDENCIES AND DPKG_CMD AND DPKGQ_CMD)
- message(STATUS "querying installed packages on system for dependancies")
- execute_process(COMMAND "${DPKG_CMD}" --print-architecture
- OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
- OUTPUT_STRIP_TRAILING_WHITESPACE)
- # don't add a package dependancy if it is not installed locally
- # these should be the debian package names
- set(PACKAGES "libc6")
- if (WITH_LOCAL_BACKEND)
- set(PACKAGES "${PACKAGES} libaio")
- endif()
- if(HAVE_AVAHI)
- set(PACKAGES "${PACKAGES} libavahi-client libavahi-common")
- endif()
- if(WITH_USB_BACKEND)
- set(PACKAGES "${PACKAGES} libusb-1")
- endif()
- if(WITH_XML_BACKEND)
- set(PACKAGES "${PACKAGES} libxml2")
- endif()
- if(WITH_SERIAL_BACKEND)
- set(PACKAGES "${PACKAGES} libserialport0")
- endif()
- # find the version of the installed package, which is hard to do in
- # cmake first, turn the list into an list (seperated by semicolons)
- string(REGEX REPLACE " " ";" PACKAGES ${PACKAGES})
- # then iterate over each
- foreach(package ${PACKAGES})
- # List packages matching given pattern ${package},
- # key is the glob (*) at the end of the ${package} name,
- # so we don't need to be so specific
- execute_process(COMMAND "${DPKG_CMD}" -l ${package}*
- OUTPUT_VARIABLE DPKG_PACKAGES)
- # returns a string, in a format:
- # ii libxml2:amd64 2.9.4+dfsg1- amd64 GNOME XML library
- # 'ii' means installed - which is what we are looking for
- STRING(REGEX MATCHALL "ii ${package}[a-z0-9A-Z.-]*"
- DPKG_INSTALLED_PACKAGES ${DPKG_PACKAGES})
- # get rid of the 'ii', and split things up, so we can look
- # at the name
- STRING(REGEX REPLACE "ii " ";" NAME_INSTALLED_PACKAGES
- ${DPKG_INSTALLED_PACKAGES})
- foreach(match ${NAME_INSTALLED_PACKAGES})
- # ignore packages marked as dev, debug,
- # documentations, or utils
- STRING(REGEX MATCHALL "dev|dbg|doc|utils" TEMP_TEST
- ${match})
- if("${TEMP_TEST}" STREQUAL "")
- # find the actual version, executes:
- # dpkg-query --showformat='\${Version}'
- # --show libusb-1.0-0
- execute_process(COMMAND "${DPKGQ_CMD}"
- --showformat='\${Version}'
- --show "${match}"
- OUTPUT_VARIABLE DPKGQ_VER)
- # debian standard is package_ver-debian_ver,
- # "'2.9.4+dfsg1-2.1'"
- # ignore patches and debian suffix version, and
- # remove single quote
- string(REGEX REPLACE "[+-][a-z0-9A-Z.]*" ""
- DPKGQ_VER ${DPKGQ_VER})
- string(REGEX REPLACE "'" "" DPKGQ_VER
- ${DPKGQ_VER})
- # build the string for the Debian dependancy
- set(CPACK_DEBIAN_PACKAGE_DEPENDS
- "${CPACK_DEBIAN_PACKAGE_DEPENDS}"
- "${match} (>= ${DPKGQ_VER}), ")
- endif()
- endforeach(match)
- endforeach(package)
- # remove the dangling end comma
- string(REGEX REPLACE ", $" "" CPACK_DEBIAN_PACKAGE_DEPENDS
- ${CPACK_DEBIAN_PACKAGE_DEPENDS})
-else()
- # assume everything is turned on, and running on a modern OS
- set(CPACK_DEBIAN_PACKAGE_DEPENDS "libaio (>= 0.3.109), libavahi-client (>= 0.6.31), libavahi-common (>= 0.6.31), libc6 (>= 2.19), libusb-1.0-0 (>= 2:1.0.17), libxml2 (>= 2.9.1), libserialport0 (>=0.1.1)")
- message(STATUS "Using default dependencies for packaging")
-endif()
-
-message(STATUS "Package dependencies (.deb): " ${CPACK_DEBIAN_PACKAGE_DEPENDS})
-if (CPACK_RPM_PACKAGE_REQUIRES)
- message(STATUS "Package dependencies (.rpm): " ${CPACK_RPM_PACKAGE_REQUIRES})
-endif()
-
-if(${CMAKE_MAJOR_VERSION} LESS 3)
- # old versions of cmake dont include this, but the same vintage of dpkg requires it
- IF(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
- FIND_PROGRAM(DPKG_CMD dpkg)
- IF(NOT DPKG_CMD)
- MESSAGE(STATUS "Can not find dpkg in your path, default to i386.")
- SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
- ENDIF(NOT DPKG_CMD)
- EXECUTE_PROCESS(COMMAND "${DPKG_CMD}" --print-architecture
- OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
- OUTPUT_STRIP_TRAILING_WHITESPACE)
- ENDIF(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
-endif()
-include(CPack)
diff --git a/context.c b/context.c
deleted file mode 100644
index 2b54730..0000000
--- a/context.c
+++ /dev/null
@@ -1,437 +0,0 @@
-/*
- * 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.
- *
- * */
-
-#include "debug.h"
-#include "iio-config.h"
-#include "iio-private.h"
-#include "sort.h"
-
-#include <errno.h>
-#include <string.h>
-
-#ifdef _WIN32
-#define LOCAL_BACKEND 0
-#define NETWORK_BACKEND 1
-#endif
-
-static const char xml_header[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
-"<!DOCTYPE context ["
-"<!ELEMENT context (device | context-attribute)*>"
-"<!ELEMENT context-attribute EMPTY>"
-"<!ELEMENT device (channel | attribute | debug-attribute | buffer-attribute)*>"
-"<!ELEMENT channel (scan-element?, attribute*)>"
-"<!ELEMENT attribute EMPTY>"
-"<!ELEMENT scan-element EMPTY>"
-"<!ELEMENT debug-attribute EMPTY>"
-"<!ELEMENT buffer-attribute EMPTY>"
-"<!ATTLIST context name CDATA #REQUIRED description CDATA #IMPLIED>"
-"<!ATTLIST context-attribute name CDATA #REQUIRED value CDATA #REQUIRED>"
-"<!ATTLIST device id CDATA #REQUIRED name CDATA #IMPLIED>"
-"<!ATTLIST channel id CDATA #REQUIRED type (input|output) #REQUIRED name CDATA #IMPLIED>"
-"<!ATTLIST scan-element index CDATA #REQUIRED format CDATA #REQUIRED scale CDATA #IMPLIED>"
-"<!ATTLIST attribute name CDATA #REQUIRED filename CDATA #IMPLIED>"
-"<!ATTLIST debug-attribute name CDATA #REQUIRED>"
-"<!ATTLIST buffer-attribute name CDATA #REQUIRED>"
-"]>";
-
-/* Returns a string containing the XML representation of this context */
-char * iio_context_create_xml(const struct iio_context *ctx)
-{
- size_t len, *devices_len = NULL;
- char *str, *ptr, **devices = NULL;
- unsigned int i;
-
- len = strlen(ctx->name) + sizeof(xml_header) - 1 +
- sizeof("<context name=\"\" ></context>");
- if (ctx->description)
- len += strlen(ctx->description) +
- sizeof(" description=\"\"") - 1;
-
- for (i = 0; i < ctx->nb_attrs; i++)
- len += strlen(ctx->attrs[i]) +
- strlen(ctx->values[i]) +
- sizeof("<context-attribute name=\"\" value=\"\" />");
-
- if (ctx->nb_devices) {
- devices_len = malloc(ctx->nb_devices * sizeof(*devices_len));
- if (!devices_len) {
- errno = ENOMEM;
- return NULL;
- }
-
- devices = calloc(ctx->nb_devices, sizeof(*devices));
- if (!devices)
- goto err_free_devices_len;
-
- for (i = 0; i < ctx->nb_devices; i++) {
- char *xml = iio_device_get_xml(ctx->devices[i],
- &devices_len[i]);
- if (!xml)
- goto err_free_devices;
- devices[i] = xml;
- len += devices_len[i];
- }
- }
-
- str = malloc(len);
- if (!str) {
- errno = ENOMEM;
- goto err_free_devices;
- }
-
- if (ctx->description) {
- iio_snprintf(str, len, "%s<context name=\"%s\" "
- "description=\"%s\" >",
- xml_header, ctx->name, ctx->description);
- } else {
- iio_snprintf(str, len, "%s<context name=\"%s\" >",
- xml_header, ctx->name);
- }
-
- ptr = strrchr(str, '\0');
-
- for (i = 0; i < ctx->nb_attrs; i++)
- ptr += sprintf(ptr, "<context-attribute name=\"%s\" value=\"%s\" />",
- ctx->attrs[i], ctx->values[i]);
-
-
- for (i = 0; i < ctx->nb_devices; i++) {
- strcpy(ptr, devices[i]);
- ptr += devices_len[i];
- free(devices[i]);
- }
-
- free(devices);
- free(devices_len);
- strcpy(ptr, "</context>");
- return str;
-
-err_free_devices:
- for (i = 0; i < ctx->nb_devices; i++)
- free(devices[i]);
- free(devices);
-err_free_devices_len:
- free(devices_len);
- return NULL;
-}
-
-const char * iio_context_get_xml(const struct iio_context *ctx)
-{
- return ctx->xml;
-}
-
-const char * iio_context_get_name(const struct iio_context *ctx)
-{
- return ctx->name;
-}
-
-const char * iio_context_get_description(const struct iio_context *ctx)
-{
- if (ctx->description)
- return ctx->description;
- else
- return "";
-}
-
-void iio_context_destroy(struct iio_context *ctx)
-{
- unsigned int i;
- if (ctx->ops->shutdown)
- ctx->ops->shutdown(ctx);
-
- for (i = 0; i < ctx->nb_attrs; i++) {
- free(ctx->attrs[i]);
- free(ctx->values[i]);
- }
- if (ctx->nb_attrs) {
- free(ctx->attrs);
- free(ctx->values);
- }
- for (i = 0; i < ctx->nb_devices; i++)
- free_device(ctx->devices[i]);
- if (ctx->nb_devices)
- free(ctx->devices);
- if (ctx->xml)
- free(ctx->xml);
- if (ctx->description)
- free(ctx->description);
- free(ctx);
-}
-
-unsigned int iio_context_get_devices_count(const struct iio_context *ctx)
-{
- return ctx->nb_devices;
-}
-
-struct iio_device * iio_context_get_device(const struct iio_context *ctx,
- unsigned int index)
-{
- if (index >= ctx->nb_devices)
- return NULL;
- else
- return ctx->devices[index];
-}
-
-struct iio_device * iio_context_find_device(const struct iio_context *ctx,
- const char *name)
-{
- unsigned int i;
- for (i = 0; i < ctx->nb_devices; i++) {
- struct iio_device *dev = ctx->devices[i];
- if (!strcmp(dev->id, name) ||
- (dev->name && !strcmp(dev->name, name)))
- return dev;
- }
- return NULL;
-}
-
-static void reorder_channels(struct iio_device *dev)
-{
- bool found;
- unsigned int i;
-
- /* Reorder channels by index */
- do {
- found = false;
- for (i = 1; i < dev->nb_channels; i++) {
- struct iio_channel **channels = dev->channels;
- long ch1 = channels[i - 1]->index;
- long ch2 = channels[i]->index;
-
- if (ch1 == ch2 && ch1 >= 0) {
- ch1 = channels[i - 1]->format.shift;
- ch2 = channels[i]->format.shift;
- }
-
- if (ch2 >= 0 && ((ch1 > ch2) || ch1 < 0)) {
- struct iio_channel *bak = channels[i];
- channels[i] = channels[i - 1];
- channels[i - 1] = bak;
- found = true;
- }
- }
- } while (found);
-
- for (i = 0; i < dev->nb_channels; i++)
- dev->channels[i]->number = i;
-}
-
-int iio_context_init(struct iio_context *ctx)
-{
- unsigned int i;
-
- for (i = 0; i < ctx->nb_devices; i++)
- reorder_channels(ctx->devices[i]);
-
- if (!ctx->xml) {
- ctx->xml = iio_context_create_xml(ctx);
- if (!ctx->xml)
- return -ENOMEM;
- }
-
- return 0;
-}
-
-int iio_context_get_version(const struct iio_context *ctx,
- unsigned int *major, unsigned int *minor, char git_tag[8])
-{
- if (ctx->ops->get_version)
- return ctx->ops->get_version(ctx, major, minor, git_tag);
-
- iio_library_get_version(major, minor, git_tag);
- return 0;
-}
-
-int iio_context_set_timeout(struct iio_context *ctx, unsigned int timeout)
-{
- if (ctx->ops->set_timeout)
- return ctx->ops->set_timeout(ctx, timeout);
- else
- return -ENOSYS;
-}
-
-struct iio_context * iio_context_clone(const struct iio_context *ctx)
-{
- if (ctx->ops->clone) {
- return ctx->ops->clone(ctx);
- } else {
- errno = ENOSYS;
- return NULL;
- }
-}
-
-struct iio_context * iio_create_context_from_uri(const char *uri)
-{
-#ifdef WITH_LOCAL_BACKEND
- if (strcmp(uri, "local:") == 0) /* No address part */
- return iio_create_local_context();
-#endif
-
-#ifdef WITH_XML_BACKEND
- if (strncmp(uri, "xml:", sizeof("xml:") - 1) == 0)
- return iio_create_xml_context(uri + sizeof("xml:") - 1);
-#endif
-
-#ifdef WITH_NETWORK_BACKEND
- if (strncmp(uri, "ip:", sizeof("ip:") - 1) == 0)
- return iio_create_network_context(uri+3);
-#endif
-
-#ifdef WITH_USB_BACKEND
- if (strncmp(uri, "usb:", sizeof("usb:") - 1) == 0)
- return usb_create_context_from_uri(uri);
-#endif
-
-#ifdef WITH_SERIAL_BACKEND
- if (strncmp(uri, "serial:", sizeof("serial:") - 1) == 0)
- return serial_create_context_from_uri(uri);
-#endif
-
- errno = ENOSYS;
- return NULL;
-}
-
-struct iio_context * iio_create_default_context(void)
-{
- char *hostname = getenv("IIOD_REMOTE");
-
- if (hostname) {
- struct iio_context *ctx;
-
- ctx = iio_create_context_from_uri(hostname);
- if (ctx)
- return ctx;
-
-#ifdef WITH_NETWORK_BACKEND
- /* If the environment variable is an empty string, we will
- * discover the server using ZeroConf */
- if (strlen(hostname) == 0)
- hostname = NULL;
-
- return iio_create_network_context(hostname);
-#endif
- }
-
- return iio_create_local_context();
-}
-
-struct iio_context * iio_create_local_context(void)
-{
-#ifdef WITH_LOCAL_BACKEND
- return local_create_context();
-#else
- errno = ENOSYS;
- return NULL;
-#endif
-}
-
-struct iio_context * iio_create_network_context(const char *hostname)
-{
-#ifdef WITH_NETWORK_BACKEND
- return network_create_context(hostname);
-#else
- errno = ENOSYS;
- return NULL;
-#endif
-}
-
-struct iio_context * iio_create_xml_context_mem(const char *xml, size_t len)
-{
-#ifdef WITH_XML_BACKEND
- return xml_create_context_mem(xml, len);
-#else
- errno = ENOSYS;
- return NULL;
-#endif
-}
-
-struct iio_context * iio_create_xml_context(const char *xml_file)
-{
-#ifdef WITH_XML_BACKEND
- return xml_create_context(xml_file);
-#else
- errno = ENOSYS;
- return NULL;
-#endif
-}
-
-unsigned int iio_context_get_attrs_count(const struct iio_context *ctx)
-{
- return ctx->nb_attrs;
-}
-
-int iio_context_get_attr(const struct iio_context *ctx, unsigned int index,
- const char **name, const char **value)
-{
- if (index >= ctx->nb_attrs)
- return -EINVAL;
-
- if (name)
- *name = ctx->attrs[index];
- if (value)
- *value = ctx->values[index];
- return 0;
-}
-
-const char * iio_context_get_attr_value(
- const struct iio_context *ctx, const char *name)
-{
- unsigned int i;
-
- for (i = 0; i < ctx->nb_attrs; i++) {
- if (!strcmp(name, ctx->attrs[i]))
- return ctx->values[i];
- }
-
- return NULL;
-}
-
-int iio_context_add_attr(struct iio_context *ctx,
- const char *key, const char *value)
-{
- char **attrs, **values, *new_key, *new_val;
-
- attrs = realloc(ctx->attrs,
- (ctx->nb_attrs + 1) * sizeof(*ctx->attrs));
- if (!attrs)
- return -ENOMEM;
-
- ctx->attrs = attrs;
-
- values = realloc(ctx->values,
- (ctx->nb_attrs + 1) * sizeof(*ctx->values));
- if (!values)
- return -ENOMEM;
-
- ctx->values = values;
-
- new_key = iio_strdup(key);
- if (!new_key)
- return -ENOMEM;
-
- new_val = iio_strdup(value);
- if (!new_val) {
- free(new_key);
- return -ENOMEM;
- }
-
- ctx->attrs[ctx->nb_attrs] = new_key;
- ctx->values[ctx->nb_attrs] = new_val;
- ctx->nb_attrs++;
- return 0;
-}
diff --git a/debug.h b/debug.h
deleted file mode 100644
index cb84ad6..0000000
--- a/debug.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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.
- *
- * */
-
-#ifndef DEBUG_H
-#define DEBUG_H
-
-#include "iio-config.h"
-
-#include <stdio.h>
-
-#define NoLog_L 0
-#define Error_L 1
-#define Warning_L 2
-#define Info_L 3
-#define Debug_L 4
-
-/* -------------------- */
-
-#ifdef WITH_COLOR_DEBUG
-#ifndef COLOR_DEBUG
-#define COLOR_DEBUG "\e[0;32m"
-#endif
-#ifndef COLOR_WARNING
-#define COLOR_WARNING "\e[01;35m"
-#endif
-#ifndef COLOR_ERROR
-#define COLOR_ERROR "\e[01;31m"
-#endif
-
-#define COLOR_END "\e[0m"
-#endif
-
-#if (LOG_LEVEL >= Debug_L)
-# ifdef COLOR_DEBUG
-# define DEBUG(str, ...) \
- fprintf(stdout, COLOR_DEBUG "DEBUG: " str COLOR_END, ##__VA_ARGS__)
-# else
-# define DEBUG(...) \
- fprintf(stdout, "DEBUG: " __VA_ARGS__)
-# endif
-#else
-#define DEBUG(...) do { } while (0)
-#endif
-
-#if (LOG_LEVEL >= Info_L)
-# ifdef COLOR_INFO
-# define INFO(str, ...) \
- fprintf(stdout, COLOR_INFO str COLOR_END, ##__VA_ARGS__)
-# else
-# define INFO(...) \
- fprintf(stdout, __VA_ARGS__)
-# endif
-#else
-#define INFO(...) do { } while (0)
-#endif
-
-#if (LOG_LEVEL >= Warning_L)
-# ifdef COLOR_WARNING
-# define WARNING(str, ...) \
- fprintf(stderr, COLOR_WARNING "WARNING: " str COLOR_END, ##__VA_ARGS__)
-# else
-# define WARNING(...) \
- fprintf(stderr, "WARNING: " __VA_ARGS__)
-# endif
-#else
-#define WARNING(...) do { } while (0)
-#endif
-
-#if (LOG_LEVEL >= Error_L)
-# ifdef COLOR_ERROR
-# define ERROR(str, ...) \
- fprintf(stderr, COLOR_ERROR "ERROR: " str COLOR_END, ##__VA_ARGS__)
-# else
-# define ERROR(...) \
- fprintf(stderr, "ERROR: " __VA_ARGS__)
-# endif
-#else
-#define ERROR(...) do { } while (0)
-#endif
-
-#endif
diff --git a/device.c b/device.c
deleted file mode 100644
index d3ec781..0000000
--- a/device.c
+++ /dev/null
@@ -1,1151 +0,0 @@
-/*
- * 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.
- *
- * */
-
-#include "debug.h"
-#include "iio-private.h"
-
-#include <inttypes.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-static char *get_attr_xml(const char *attr, size_t *length, enum iio_attr_type type)
-{
- size_t len = sizeof("<attribute name=\"\" />") + strlen(attr);
- char *str;
-
- switch(type){
- case IIO_ATTR_TYPE_DEVICE:
- break;
- case IIO_ATTR_TYPE_DEBUG:
- len += (sizeof("debug-") - 1);
- break;
- case IIO_ATTR_TYPE_BUFFER:
- len += (sizeof("buffer-") - 1);
- break;
- default:
- return NULL;
- }
-
- str = malloc(len);
- if (!str)
- return NULL;
-
- *length = len - 1; /* Skip the \0 */
- switch (type) {
- case IIO_ATTR_TYPE_DEVICE:
- iio_snprintf(str, len, "<attribute name=\"%s\" />", attr);
- break;
- case IIO_ATTR_TYPE_DEBUG:
- iio_snprintf(str, len, "<debug-attribute name=\"%s\" />", attr);
- break;
- case IIO_ATTR_TYPE_BUFFER:
- iio_snprintf(str, len, "<buffer-attribute name=\"%s\" />", attr);
- break;
- }
-
- return str;
-}
-
-/* Returns a string containing the XML representation of this device */
-char * iio_device_get_xml(const struct iio_device *dev, size_t *length)
-{
- size_t len = sizeof("<device id=\"\" name=\"\" ></device>")
- + strlen(dev->id) + (dev->name ? strlen(dev->name) : 0);
- char *ptr, *str, **attrs, **channels, **buffer_attrs, **debug_attrs;
- size_t *attrs_len, *channels_len, *buffer_attrs_len, *debug_attrs_len;
- unsigned int i, j, k;
-
- attrs_len = malloc(dev->nb_attrs * sizeof(*attrs_len));
- if (!attrs_len)
- return NULL;
-
- attrs = malloc(dev->nb_attrs * sizeof(*attrs));
- if (!attrs)
- goto err_free_attrs_len;
-
- for (i = 0; i < dev->nb_attrs; i++) {
- char *xml = get_attr_xml(dev->attrs[i], &attrs_len[i], IIO_ATTR_TYPE_DEVICE);
- if (!xml)
- goto err_free_attrs;
- attrs[i] = xml;
- len += attrs_len[i];
- }
-
- channels_len = malloc(dev->nb_channels * sizeof(*channels_len));
- if (!channels_len)
- goto err_free_attrs;
-
- channels = malloc(dev->nb_channels * sizeof(*channels));
- if (!channels)
- goto err_free_channels_len;
-
- for (j = 0; j < dev->nb_channels; j++) {
- char *xml = iio_channel_get_xml(dev->channels[j],
- &channels_len[j]);
- if (!xml)
- goto err_free_channels;
- channels[j] = xml;
- len += channels_len[j];
- }
-
- buffer_attrs_len = malloc(dev->nb_buffer_attrs *
- sizeof(*buffer_attrs_len));
- if (!buffer_attrs_len)
- goto err_free_channels;
-
- buffer_attrs = malloc(dev->nb_buffer_attrs * sizeof(*buffer_attrs));
- if (!buffer_attrs)
- goto err_free_buffer_attrs_len;
-
- for (k = 0; k < dev->nb_buffer_attrs; k++) {
- char *xml = get_attr_xml(dev->buffer_attrs[k],
- &buffer_attrs_len[k], IIO_ATTR_TYPE_BUFFER);
- if (!xml)
- goto err_free_buffer_attrs;
- buffer_attrs[k] = xml;
- len += buffer_attrs_len[k];
- }
-
- debug_attrs_len = malloc(dev->nb_debug_attrs *
- sizeof(*debug_attrs_len));
- if (!debug_attrs_len)
- goto err_free_buffer_attrs;
-
- debug_attrs = malloc(dev->nb_debug_attrs * sizeof(*debug_attrs));
- if (!debug_attrs)
- goto err_free_debug_attrs_len;
-
- for (k = 0; k < dev->nb_debug_attrs; k++) {
- char *xml = get_attr_xml(dev->debug_attrs[k],
- &debug_attrs_len[k], IIO_ATTR_TYPE_DEBUG);
- if (!xml)
- goto err_free_debug_attrs;
- debug_attrs[k] = xml;
- len += debug_attrs_len[k];
- }
-
- str = malloc(len);
- if (!str)
- goto err_free_debug_attrs;
-
- iio_snprintf(str, len, "<device id=\"%s\"", dev->id);
- ptr = strrchr(str, '\0');
-
- if (dev->name) {
- sprintf(ptr, " name=\"%s\"", dev->name);
- ptr = strrchr(ptr, '\0');
- }
-
- strcpy(ptr, " >");
- ptr += 2;
-
- for (i = 0; i < dev->nb_channels; i++) {
- strcpy(ptr, channels[i]);
- ptr += channels_len[i];
- free(channels[i]);
- }
-
- free(channels);
- free(channels_len);
-
- for (i = 0; i < dev->nb_attrs; i++) {
- strcpy(ptr, attrs[i]);
- ptr += attrs_len[i];
- free(attrs[i]);
- }
-
- free(attrs);
- free(attrs_len);
-
- for (i = 0; i < dev->nb_buffer_attrs; i++) {
- strcpy(ptr, buffer_attrs[i]);
- ptr += buffer_attrs_len[i];
- free(buffer_attrs[i]);
- }
-
- free(buffer_attrs);
- free(buffer_attrs_len);
-
- for (i = 0; i < dev->nb_debug_attrs; i++) {
- strcpy(ptr, debug_attrs[i]);
- ptr += debug_attrs_len[i];
- free(debug_attrs[i]);
- }
-
- free(debug_attrs);
- free(debug_attrs_len);
-
- strcpy(ptr, "</device>");
- *length = ptr - str + sizeof("</device>") - 1;
- return str;
-
-err_free_debug_attrs:
- while (k--)
- free(debug_attrs[k]);
- free(debug_attrs);
-err_free_debug_attrs_len:
- free(debug_attrs_len);
-err_free_buffer_attrs:
- while (k--)
- free(buffer_attrs[k]);
- free(buffer_attrs);
-err_free_buffer_attrs_len:
- free(buffer_attrs_len);
-err_free_channels:
- while (j--)
- free(channels[j]);
- free(channels);
-err_free_channels_len:
- free(channels_len);
-err_free_attrs:
- while (i--)
- free(attrs[i]);
- free(attrs);
-err_free_attrs_len:
- free(attrs_len);
- return NULL;
-}
-
-const char * iio_device_get_id(const struct iio_device *dev)
-{
- return dev->id;
-}
-
-const char * iio_device_get_name(const struct iio_device *dev)
-{
- return dev->name;
-}
-
-unsigned int iio_device_get_channels_count(const struct iio_device *dev)
-{
- return dev->nb_channels;
-}
-
-struct iio_channel * iio_device_get_channel(const struct iio_device *dev,
- unsigned int index)
-{
- if (index >= dev->nb_channels)
- return NULL;
- else
- return dev->channels[index];
-}
-
-struct iio_channel * iio_device_find_channel(const struct iio_device *dev,
- const char *name, bool output)
-{
- unsigned int i;
- for (i = 0; i < dev->nb_channels; i++) {
- struct iio_channel *chn = dev->channels[i];
- if (iio_channel_is_output(chn) != output)
- continue;
-
- if (!strcmp(chn->id, name) ||
- (chn->name && !strcmp(chn->name, name)))
- return chn;
- }
- return NULL;
-}
-
-unsigned int iio_device_get_attrs_count(const struct iio_device *dev)
-{
- return dev->nb_attrs;
-}
-
-const char * iio_device_get_attr(const struct iio_device *dev,
- unsigned int index)
-{
- if (index >= dev->nb_attrs)
- return NULL;
- else
- return dev->attrs[index];
-}
-
-const char * iio_device_find_attr(const struct iio_device *dev,
- const char *name)
-{
- unsigned int i;
- for (i = 0; i < dev->nb_attrs; i++) {
- const char *attr = dev->attrs[i];
- if (!strcmp(attr, name))
- return attr;
- }
- return NULL;
-}
-
-unsigned int iio_device_get_buffer_attrs_count(const struct iio_device *dev)
-{
- return dev->nb_buffer_attrs;
-}
-
-const char * iio_device_get_buffer_attr(const struct iio_device *dev,
- unsigned int index)
-{
- if (index >= dev->nb_buffer_attrs)
- return NULL;
- else
- return dev->buffer_attrs[index];
-}
-
-const char * iio_device_find_buffer_attr(const struct iio_device *dev,
- const char *name)
-{
- unsigned int i;
- for (i = 0; i < dev->nb_buffer_attrs; i++) {
- const char *attr = dev->buffer_attrs[i];
- if (!strcmp(attr, name))
- return attr;
- }
- return NULL;
-}
-
-const char * iio_device_find_debug_attr(const struct iio_device *dev,
- const char *name)
-{
- unsigned int i;
- for (i = 0; i < dev->nb_debug_attrs; i++) {
- const char *attr = dev->debug_attrs[i];
- if (!strcmp(attr, name))
- return attr;
- }
- return NULL;
-}
-
-bool iio_device_is_tx(const struct iio_device *dev)
-{
- unsigned int i;
-
- for (i = 0; i < dev->nb_channels; i++) {
- struct iio_channel *ch = dev->channels[i];
- if (iio_channel_is_output(ch) && iio_channel_is_enabled(ch))
- return true;
- }
-
- return false;
-}
-
-int iio_device_open(const struct iio_device *dev,
- size_t samples_count, bool cyclic)
-{
- unsigned int i;
- bool has_channels = false;
-
- for (i = 0; !has_channels && i < dev->words; i++)
- has_channels = !!dev->mask[i];
- if (!has_channels)
- return -EINVAL;
-
- if (dev->ctx->ops->open)
- return dev->ctx->ops->open(dev, samples_count, cyclic);
- else
- return -ENOSYS;
-}
-
-int iio_device_close(const struct iio_device *dev)
-{
- if (dev->ctx->ops->close)
- return dev->ctx->ops->close(dev);
- else
- return -ENOSYS;
-}
-
-int iio_device_get_poll_fd(const struct iio_device *dev)
-{
- if (dev->ctx->ops->get_fd)
- return dev->ctx->ops->get_fd(dev);
- else
- return -ENOSYS;
-}
-
-int iio_device_set_blocking_mode(const struct iio_device *dev, bool blocking)
-{
- if (dev->ctx->ops->set_blocking_mode)
- return dev->ctx->ops->set_blocking_mode(dev, blocking);
- else
- return -ENOSYS;
-}
-
-ssize_t iio_device_read_raw(const struct iio_device *dev,
- void *dst, size_t len, uint32_t *mask, size_t words)
-{
- if (dev->ctx->ops->read)
- return dev->ctx->ops->read(dev, dst, len, mask, words);
- else
- return -ENOSYS;
-}
-
-ssize_t iio_device_write_raw(const struct iio_device *dev,
- const void *src, size_t len)
-{
- if (dev->ctx->ops->write)
- return dev->ctx->ops->write(dev, src, len);
- else
- return -ENOSYS;
-}
-
-ssize_t iio_device_attr_read(const struct iio_device *dev,
- const char *attr, char *dst, size_t len)
-{
- if (dev->ctx->ops->read_device_attr)
- return dev->ctx->ops->read_device_attr(dev,
- attr, dst, len, IIO_ATTR_TYPE_DEVICE);
- else
- return -ENOSYS;
-}
-
-ssize_t iio_device_attr_write_raw(const struct iio_device *dev,
- const char *attr, const void *src, size_t len)
-{
- if (dev->ctx->ops->write_device_attr)
- return dev->ctx->ops->write_device_attr(dev,
- attr, src, len, IIO_ATTR_TYPE_DEVICE);
- else
- return -ENOSYS;
-}
-
-ssize_t iio_device_attr_write(const struct iio_device *dev,
- const char *attr, const char *src)
-{
- return iio_device_attr_write_raw(dev, attr, src, strlen(src) + 1);
-}
-
-ssize_t iio_device_buffer_attr_read(const struct iio_device *dev,
- const char *attr, char *dst, size_t len)
-{
- if (dev->ctx->ops->read_device_attr)
- return dev->ctx->ops->read_device_attr(dev,
- attr, dst, len, IIO_ATTR_TYPE_BUFFER);
- else
- return -ENOSYS;
-}
-
-ssize_t iio_device_buffer_attr_write_raw(const struct iio_device *dev,
- const char *attr, const void *src, size_t len)
-{
- if (dev->ctx->ops->write_device_attr)
- return dev->ctx->ops->write_device_attr(dev,
- attr, src, len, IIO_ATTR_TYPE_BUFFER);
- else
- return -ENOSYS;
-}
-
-ssize_t iio_device_buffer_attr_write(const struct iio_device *dev,
- const char *attr, const char *src)
-{
- return iio_device_buffer_attr_write_raw(dev, attr, src, strlen(src) + 1);
-}
-
-void iio_device_set_data(struct iio_device *dev, void *data)
-{
- dev->userdata = data;
-}
-
-void * iio_device_get_data(const struct iio_device *dev)
-{
- return dev->userdata;
-}
-
-bool iio_device_is_trigger(const struct iio_device *dev)
-{
- /* A trigger has a name, an id which starts by "trigger",
- * and zero channels. */
-
- unsigned int nb = iio_device_get_channels_count(dev);
- const char *name = iio_device_get_name(dev),
- *id = iio_device_get_id(dev);
- return ((nb == 0) && !!name &&
- !strncmp(id, "trigger", sizeof("trigger") - 1));
-}
-
-int iio_device_set_kernel_buffers_count(const struct iio_device *dev,
- unsigned int nb_buffers)
-{
- if (nb_buffers == 0)
- return -EINVAL;
- else if (dev->ctx->ops->set_kernel_buffers_count)
- return dev->ctx->ops->set_kernel_buffers_count(dev, nb_buffers);
- else
- return -ENOSYS;
-}
-
-int iio_device_get_trigger(const struct iio_device *dev,
- const struct iio_device **trigger)
-{
- if (!trigger)
- return -EINVAL;
- else if (dev->ctx->ops->get_trigger)
- return dev->ctx->ops->get_trigger(dev, trigger);
- else
- return -ENOSYS;
-}
-
-int iio_device_set_trigger(const struct iio_device *dev,
- const struct iio_device *trigger)
-{
- if (trigger && !iio_device_is_trigger(trigger))
- return -EINVAL;
- else if (dev->ctx->ops->set_trigger)
- return dev->ctx->ops->set_trigger(dev, trigger);
- else
- return -ENOSYS;
-}
-
-void free_device(struct iio_device *dev)
-{
- unsigned int i;
- for (i = 0; i < dev->nb_attrs; i++)
- free(dev->attrs[i]);
- if (dev->nb_attrs)
- free(dev->attrs);
- for (i = 0; i < dev->nb_buffer_attrs; i++)
- free(dev->buffer_attrs[i]);
- if (dev->nb_buffer_attrs)
- free(dev->buffer_attrs);
- for (i = 0; i < dev->nb_debug_attrs; i++)
- free(dev->debug_attrs[i]);
- if (dev->nb_debug_attrs)
- free(dev->debug_attrs);
- for (i = 0; i < dev->nb_channels; i++)
- free_channel(dev->channels[i]);
- if (dev->nb_channels)
- free(dev->channels);
- if (dev->mask)
- free(dev->mask);
- if (dev->name)
- free(dev->name);
- if (dev->id)
- free(dev->id);
- free(dev);
-}
-
-ssize_t iio_device_get_sample_size_mask(const struct iio_device *dev,
- const uint32_t *mask, size_t words)
-{
- ssize_t size = 0;
- unsigned int i;
- const struct iio_channel *prev = NULL;
-
- if (words != (dev->nb_channels + 31) / 32)
- return -EINVAL;
-
- for (i = 0; i < dev->nb_channels; i++) {
- const struct iio_channel *chn = dev->channels[i];
- unsigned int length = chn->format.length / 8 *
- chn->format.repeat;
-
- if (chn->index < 0)
- break;
- if (!TEST_BIT(mask, chn->number))
- continue;
-
- if (prev && chn->index == prev->index) {
- prev = chn;
- continue;
- }
-
- if (size % length)
- size += 2 * length - (size % length);
- else
- size += length;
-
- prev = chn;
- }
- return size;
-}
-
-ssize_t iio_device_get_sample_size(const struct iio_device *dev)
-{
- return iio_device_get_sample_size_mask(dev, dev->mask, dev->words);
-}
-
-int iio_device_attr_read_longlong(const struct iio_device *dev,
- const char *attr, long long *val)
-{
- char *end, buf[1024];
- long long value;
- ssize_t ret = iio_device_attr_read(dev, attr, buf, sizeof(buf));
- if (ret < 0)
- return (int) ret;
-
- value = strtoll(buf, &end, 0);
- if (end == buf)
- return -EINVAL;
- *val = value;
- return 0;
-}
-
-int iio_device_attr_read_bool(const struct iio_device *dev,
- const char *attr, bool *val)
-{
- long long value;
- int ret = iio_device_attr_read_longlong(dev, attr, &value);
- if (ret < 0)
- return ret;
-
- *val = !!value;
- return 0;
-}
-
-int iio_device_attr_read_double(const struct iio_device *dev,
- const char *attr, double *val)
-{
- char buf[1024];
- ssize_t ret = iio_device_attr_read(dev, attr, buf, sizeof(buf));
- if (ret < 0)
- return (int) ret;
- else
- return read_double(buf, val);
-}
-
-int iio_device_attr_write_longlong(const struct iio_device *dev,
- const char *attr, long long val)
-{
- ssize_t ret;
- char buf[1024];
-
- iio_snprintf(buf, sizeof(buf), "%lld", val);
- ret = iio_device_attr_write(dev, attr, buf);
-
- return ret < 0 ? ret : 0;
-}
-
-int iio_device_attr_write_double(const struct iio_device *dev,
- const char *attr, double val)
-{
- ssize_t ret;
- char buf[1024];
-
- ret = (ssize_t) write_double(buf, sizeof(buf), val);
- if (!ret)
- ret = iio_device_attr_write(dev, attr, buf);
- return ret < 0 ? ret : 0;
-}
-
-int iio_device_attr_write_bool(const struct iio_device *dev,
- const char *attr, bool val)
-{
- ssize_t ret;
-
- if (val)
- ret = iio_device_attr_write(dev, attr, "1");
- else
- ret = iio_device_attr_write(dev, attr, "0");
-
- return ret < 0 ? ret : 0;
-}
-
-int iio_device_buffer_attr_read_longlong(const struct iio_device *dev,
- const char *attr, long long *val)
-{
- char *end, buf[1024];
- long long value;
- ssize_t ret = iio_device_buffer_attr_read(dev, attr, buf, sizeof(buf));
- if (ret < 0)
- return (int) ret;
-
- value = strtoll(buf, &end, 0);
- if (end == buf)
- return -EINVAL;
- *val = value;
- return 0;
-}
-
-int iio_device_buffer_attr_read_bool(const struct iio_device *dev,
- const char *attr, bool *val)
-{
- long long value;
- int ret = iio_device_buffer_attr_read_longlong(dev, attr, &value);
- if (ret < 0)
- return ret;
-
- *val = !!value;
- return 0;
-}
-
-int iio_device_buffer_attr_read_double(const struct iio_device *dev,
- const char *attr, double *val)
-{
- char buf[1024];
- ssize_t ret = iio_device_buffer_attr_read(dev, attr, buf, sizeof(buf));
- if (ret < 0)
- return (int) ret;
- else
- return read_double(buf, val);
-}
-
-int iio_device_buffer_attr_write_longlong(const struct iio_device *dev,
- const char *attr, long long val)
-{
- ssize_t ret;
- char buf[1024];
-
- iio_snprintf(buf, sizeof(buf), "%lld", val);
- ret = iio_device_buffer_attr_write(dev, attr, buf);
-
- return ret < 0 ? ret : 0;
-}
-
-int iio_device_buffer_attr_write_double(const struct iio_device *dev,
- const char *attr, double val)
-{
- ssize_t ret;
- char buf[1024];
-
- ret = (ssize_t) write_double(buf, sizeof(buf), val);
- if (!ret)
- ret = iio_device_buffer_attr_write(dev, attr, buf);
- return ret < 0 ? ret : 0;
-}
-
-int iio_device_buffer_attr_write_bool(const struct iio_device *dev,
- const char *attr, bool val)
-{
- ssize_t ret;
-
- if (val)
- ret = iio_device_buffer_attr_write(dev, attr, "1");
- else
- ret = iio_device_buffer_attr_write(dev, attr, "0");
-
- return ret < 0 ? ret : 0;
-}
-
-ssize_t iio_device_debug_attr_read(const struct iio_device *dev,
- const char *attr, char *dst, size_t len)
-{
- if (dev->ctx->ops->read_device_attr)
- return dev->ctx->ops->read_device_attr(dev,
- attr, dst, len, IIO_ATTR_TYPE_DEBUG);
- else
- return -ENOSYS;
-}
-
-ssize_t iio_device_debug_attr_write_raw(const struct iio_device *dev,
- const char *attr, const void *src, size_t len)
-{
- if (dev->ctx->ops->write_device_attr)
- return dev->ctx->ops->write_device_attr(dev,
- attr, src, len, IIO_ATTR_TYPE_DEBUG);
- else
- return -ENOSYS;
-}
-
-ssize_t iio_device_debug_attr_write(const struct iio_device *dev,
- const char *attr, const char *src)
-{
- return iio_device_debug_attr_write_raw(dev, attr, src, strlen(src) + 1);
-}
-
-unsigned int iio_device_get_debug_attrs_count(const struct iio_device *dev)
-{
- return dev->nb_debug_attrs;
-}
-
-const char * iio_device_get_debug_attr(const struct iio_device *dev,
- unsigned int index)
-{
- if (index >= dev->nb_debug_attrs)
- return NULL;
- else
- return dev->debug_attrs[index];
-}
-
-int iio_device_debug_attr_read_longlong(const struct iio_device *dev,
- const char *attr, long long *val)
-{
- char *end, buf[1024];
- long long value;
- ssize_t ret = iio_device_debug_attr_read(dev, attr, buf, sizeof(buf));
- if (ret < 0)
- return (int) ret;
-
- value = strtoll(buf, &end, 0);
- if (end == buf)
- return -EINVAL;
- *val = value;
- return 0;
-}
-
-int iio_device_debug_attr_read_bool(const struct iio_device *dev,
- const char *attr, bool *val)
-{
- long long value;
- int ret = iio_device_debug_attr_read_longlong(dev, attr, &value);
- if (ret < 0)
- return ret;
-
- *val = !!value;
- return 0;
-}
-
-int iio_device_debug_attr_read_double(const struct iio_device *dev,
- const char *attr, double *val)
-{
- char buf[1024];
- ssize_t ret = iio_device_debug_attr_read(dev, attr, buf, sizeof(buf));
- if (ret < 0)
- return (int) ret;
- else
- return read_double(buf, val);
-}
-
-int iio_device_debug_attr_write_longlong(const struct iio_device *dev,
- const char *attr, long long val)
-{
- ssize_t ret;
- char buf[1024];
-
- iio_snprintf(buf, sizeof(buf), "%lld", val);
- ret = iio_device_debug_attr_write(dev, attr, buf);
-
- return ret < 0 ? ret : 0;
-}
-
-int iio_device_debug_attr_write_double(const struct iio_device *dev,
- const char *attr, double val)
-{
- ssize_t ret;
- char buf[1024];
-
- ret = (ssize_t) write_double(buf, sizeof(buf), val);
- if (!ret)
- ret = iio_device_debug_attr_write(dev, attr, buf);
- return ret < 0 ? ret : 0;
-}
-
-int iio_device_debug_attr_write_bool(const struct iio_device *dev,
- const char *attr, bool val)
-{
- ssize_t ret;
-
- if (val)
- ret = iio_device_debug_attr_write_raw(dev, attr, "1", 2);
- else
- ret = iio_device_debug_attr_write_raw(dev, attr, "0", 2);
-
- return ret < 0 ? ret : 0;
-}
-
-int iio_device_identify_filename(const struct iio_device *dev,
- const char *filename, struct iio_channel **chn,
- const char **attr)
-{
- unsigned int i;
-
- for (i = 0; i < dev->nb_channels; i++) {
- struct iio_channel *ch = dev->channels[i];
- unsigned int j;
-
- for (j = 0; j < ch->nb_attrs; j++) {
- if (!strcmp(ch->attrs[j].filename, filename)) {
- *attr = ch->attrs[j].name;
- *chn = ch;
- return 0;
- }
- }
- }
-
- for (i = 0; i < dev->nb_attrs; i++) {
- /* Devices attributes are named after their filename */
- if (!strcmp(dev->attrs[i], filename)) {
- *attr = dev->attrs[i];
- *chn = NULL;
- return 0;
- }
- }
-
- for (i = 0; i < dev->nb_debug_attrs; i++) {
- if (!strcmp(dev->debug_attrs[i], filename)) {
- *attr = dev->debug_attrs[i];
- *chn = NULL;
- return 0;
- }
- }
-
- return -EINVAL;
-}
-
-int iio_device_reg_write(struct iio_device *dev,
- uint32_t address, uint32_t value)
-{
- ssize_t ret;
- char buf[1024];
-
- iio_snprintf(buf, sizeof(buf), "0x%" PRIx32 " 0x%" PRIx32,
- address, value);
- ret = iio_device_debug_attr_write(dev, "direct_reg_access", buf);
-
- return ret < 0 ? ret : 0;
-}
-
-int iio_device_reg_read(struct iio_device *dev,
- uint32_t address, uint32_t *value)
-{
- /* NOTE: There is a race condition here. But it is extremely unlikely to
- * happen, and as this is a debug function, it shouldn't be used for
- * something else than debug. */
-
- long long val;
- int ret = iio_device_debug_attr_write_longlong(dev,
- "direct_reg_access", (long long) address);
- if (ret < 0)
- return ret;
-
- ret = iio_device_debug_attr_read_longlong(dev,
- "direct_reg_access", &val);
- if (!ret)
- *value = (uint32_t) val;
- return ret;
-}
-
-static int read_each_attr(struct iio_device *dev, enum iio_attr_type type,
- int (*cb)(struct iio_device *dev,
- const char *attr, const char *val, size_t len, void *d),
- void *data)
-{
- int ret, buf_size;
- char *buf, *ptr;
- unsigned int i, count;
-
- /* We need a big buffer here; 1 MiB should be enough */
- buf = malloc(0x100000);
- if (!buf)
- return -ENOMEM;
-
- switch(type){
- case IIO_ATTR_TYPE_DEVICE:
- count = iio_device_get_attrs_count(dev);
- ret = (int) iio_device_attr_read(dev,
- NULL, buf, 0x100000);
- break;
- case IIO_ATTR_TYPE_DEBUG:
- count = iio_device_get_debug_attrs_count(dev);
- ret = (int) iio_device_debug_attr_read(dev,
- NULL, buf, 0x100000);
- break;
- case IIO_ATTR_TYPE_BUFFER:
- count = iio_device_get_buffer_attrs_count(dev);
- ret = (int) iio_device_buffer_attr_read(dev,
- NULL, buf, 0x100000);
- break;
- default:
- ret = -EINVAL;
- count = 0;
- break;
- }
-
- if (ret < 0)
- goto err_free_buf;
-
- ptr = buf;
- buf_size = ret;
-
- for (i = 0; i < count; i++) {
- const char *attr;
- int32_t len;
-
- if (buf_size < 4) {
- ret = -EPROTO;
- break;
- }
-
- len = (int32_t) iio_be32toh(*(uint32_t *) ptr);
- ptr += 4;
- buf_size -= 4;
-
- if (len > 0 && buf_size < len) {
- ret = -EPROTO;
- break;
- }
-
- switch(type){
- case IIO_ATTR_TYPE_DEVICE:
- attr = iio_device_get_attr(dev, i);
- break;
- case IIO_ATTR_TYPE_DEBUG:
- attr = iio_device_get_debug_attr(dev, i);
- break;
- case IIO_ATTR_TYPE_BUFFER:
- attr = iio_device_get_buffer_attr(dev, i);
- break;
- default:
- attr = NULL;
- break;
- }
-
- if (len > 0) {
- ret = cb(dev, attr, ptr, (size_t) len, data);
- if (ret < 0)
- goto err_free_buf;
-
- if (len & 0x3)
- len = ((len >> 2) + 1) << 2;
- ptr += len;
- if (len >= buf_size)
- buf_size = 0;
- else
- buf_size -= len;
- }
- }
-
-err_free_buf:
- free(buf);
- return ret < 0 ? ret : 0;
-}
-
-static int write_each_attr(struct iio_device *dev, enum iio_attr_type type,
- ssize_t (*cb)(struct iio_device *dev,
- const char *attr, void *buf, size_t len, void *d),
- void *data)
-{
- char *buf, *ptr;
- unsigned int i, count;
- size_t len = 0x100000;
- int ret;
-
- /* We need a big buffer here; 1 MiB should be enough */
- buf = malloc(len);
- if (!buf)
- return -ENOMEM;
-
- ptr = buf;
-
- switch(type){
- case IIO_ATTR_TYPE_DEVICE:
- count = iio_device_get_attrs_count(dev);
- break;
- case IIO_ATTR_TYPE_DEBUG:
- count = iio_device_get_debug_attrs_count(dev);
- break;
- case IIO_ATTR_TYPE_BUFFER:
- count = iio_device_get_buffer_attrs_count(dev);
- break;
- default:
- ret = -EINVAL;
- goto err_free_buf;
- }
-
- for (i = 0; i < count; i++) {
- const char *attr;
-
- switch(type){
- case IIO_ATTR_TYPE_DEVICE:
- attr = iio_device_get_attr(dev, i);
- break;
- case IIO_ATTR_TYPE_DEBUG:
- attr = iio_device_get_debug_attr(dev, i);
- break;
- case IIO_ATTR_TYPE_BUFFER:
- attr = iio_device_get_buffer_attr(dev, i);
- break;
- default:
- attr = NULL;
- break;
- }
-
- ret = (int) cb(dev, attr, ptr + 4, len - 4, data);
- if (ret < 0)
- goto err_free_buf;
-
- *(int32_t *) ptr = (int32_t) iio_htobe32((uint32_t) ret);
- ptr += 4;
- len -= 4;
-
- if (ret > 0) {
- if (ret & 0x3)
- ret = ((ret >> 2) + 1) << 2;
- ptr += ret;
- len -= ret;
- }
- }
-
- switch(type){
- case IIO_ATTR_TYPE_DEVICE:
- ret = (int) iio_device_attr_write_raw(dev,
- NULL, buf, ptr - buf);
- break;
- case IIO_ATTR_TYPE_DEBUG:
- ret = (int) iio_device_debug_attr_write_raw(dev,
- NULL, buf, ptr - buf);
- break;
- case IIO_ATTR_TYPE_BUFFER:
- ret = (int) iio_device_buffer_attr_write_raw(dev,
- NULL, buf, ptr - buf);
- break;
- default:
- ret = -EINVAL;
- break;
- }
-
-err_free_buf:
- free(buf);
- return ret < 0 ? ret : 0;
-}
-
-int iio_device_debug_attr_read_all(struct iio_device *dev,
- int (*cb)(struct iio_device *dev,
- const char *attr, const char *val, size_t len, void *d),
- void *data)
-{
- return read_each_attr(dev, IIO_ATTR_TYPE_DEBUG, cb, data);
-}
-
-int iio_device_buffer_attr_read_all(struct iio_device *dev,
- int (*cb)(struct iio_device *dev,
- const char *attr, const char *val, size_t len, void *d),
- void *data)
-{
- return read_each_attr(dev, IIO_ATTR_TYPE_BUFFER, cb, data);
-}
-
-int iio_device_attr_read_all(struct iio_device *dev,
- int (*cb)(struct iio_device *dev,
- const char *attr, const char *val, size_t len, void *d),
- void *data)
-{
- return read_each_attr(dev, IIO_ATTR_TYPE_DEVICE ,cb, data);
-}
-
-int iio_device_debug_attr_write_all(struct iio_device *dev,
- ssize_t (*cb)(struct iio_device *dev,
- const char *attr, void *buf, size_t len, void *d),
- void *data)
-{
- return write_each_attr(dev, IIO_ATTR_TYPE_DEBUG, cb, data);
-}
-
-int iio_device_buffer_attr_write_all(struct iio_device *dev,
- ssize_t (*cb)(struct iio_device *dev,
- const char *attr, void *buf, size_t len, void *d),
- void *data)
-{
- return write_each_attr(dev, IIO_ATTR_TYPE_BUFFER, cb, data);
-}
-
-int iio_device_attr_write_all(struct iio_device *dev,
- ssize_t (*cb)(struct iio_device *dev,
- const char *attr, void *buf, size_t len, void *d),
- void *data)
-{
- return write_each_attr(dev, IIO_ATTR_TYPE_DEVICE, cb, data);
-}
-
-const struct iio_context * iio_device_get_context(const struct iio_device *dev)
-{
- return dev->ctx;
-}
diff --git a/doc/codemodel.svg b/doc/codemodel.svg
deleted file mode 100644
index a4e22e4..0000000
--- a/doc/codemodel.svg
+++ /dev/null
@@ -1,319 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!-- Created with Inkscape (http://www.inkscape.org/) -->
-
-<svg
- xmlns:dc="http://purl.org/dc/elements/1.1/"
- xmlns:cc="http://creativecommons.org/ns#"
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- xmlns:svg="http://www.w3.org/2000/svg"
- xmlns="http://www.w3.org/2000/svg"
- xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
- xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
- id="svg3004"
- version="1.1"
- inkscape:version="0.48.5 r10040"
- width="438.33322"
- height="168.27065"
- xml:space="preserve"
- sodipodi:docname="codemodel.svg"><metadata
- id="metadata3010"><rdf:RDF><cc:Work
- rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
- rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
- id="defs3008" /><sodipodi:namedview
- pagecolor="#ffffff"
- bordercolor="#666666"
- borderopacity="1"
- objecttolerance="10"
- gridtolerance="10"
- guidetolerance="10"
- inkscape:pageopacity="0"
- inkscape:pageshadow="2"
- inkscape:window-width="1920"
- inkscape:window-height="1014"
- id="namedview3006"
- showgrid="false"
- inkscape:zoom="2.1956594"
- inkscape:cx="118.025"
- inkscape:cy="105.83073"
- inkscape:window-x="0"
- inkscape:window-y="27"
- inkscape:window-maximized="1"
- inkscape:current-layer="g3012"
- fit-margin-top="0"
- fit-margin-left="0"
- fit-margin-right="0"
- fit-margin-bottom="0" /><g
- id="g3012"
- inkscape:groupmode="layer"
- inkscape:label="ink_ext_XXXXXX"
- transform="matrix(1.25,0,0,-1.25,5.6900994e-5,287.00339)"><g
- id="g3014"
- transform="matrix(0.05863009,0,0,0.05863009,-4.5520795e-5,94.986197)"><path
- d="m 1998.39,1714.93 1984.22,0 0,566.918 -1984.22,0 0,-566.918 z"
- style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3016"
- inkscape:connector-curvature="0" /><path
- d="m 1998.39,1714.93 1984.22,0 0,566.918 -1984.22,0 0,-566.918 z"
- style="fill:none;stroke:#000000;stroke-width:28.34600067;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none"
- id="path3018"
- inkscape:connector-curvature="0" /><path
- d="m 2271.22,2044.19 39.89,0 0,-129.07 -39.89,0 0,129.07 m 0,49.28 39.89,0 0,-32.85 -39.89,0 0,32.85"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3020"
- inkscape:connector-curvature="0" /><path
- d="m 2353.34,2044.19 39.89,0 0,-129.07 -39.89,0 0,129.07 m 0,49.28 39.89,0 0,-32.85 -39.89,0 0,32.85"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3022"
- inkscape:connector-curvature="0" /><path
- d="m 2496.66,2018.38 c -9.21,0 -16.24,-3.23 -21.08,-9.68 -4.84,-6.43 -7.26,-15.72 -7.26,-27.87 0,-12.15 2.42,-21.45 7.26,-27.9 4.84,-6.43 11.87,-9.64 21.08,-9.64 9.05,0 15.97,3.21 20.76,9.64 4.81,6.45 7.22,15.75 7.22,27.9 0,12.15 -2.41,21.44 -7.22,27.87 -4.79,6.45 -11.71,9.68 -20.76,9.68 m 0,30.51 c 22.03,0 39.24,-6.03 51.63,-18.08 12.39,-12.03 18.59,-28.69 18.59,-49.98 0,-21.29 -6.2,-37.96 -18.59,-50.01 -12.39,-12.03 -29.6,-18.04 -51.63,-18.04 -22.12,0 -39.41,6.01 -51.88,18.04 -12.46,12.05 -18.7,28.72 -18.7,50.01 0,21.29 6.24,37.95 18.7,49.98 12.47,12.05 29.76,18.08 51.88,18.08"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3024"
- inkscape:connector-curvature="0" /><path
- d="m 2581.66,1858.81 117.332,0 0,21.1172 -117.332,0 0,-21.1172 z"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3026"
- inkscape:connector-curvature="0" /><path
- d="m 2824.04,2039.5 0,-32.86 c -5.58,3.99 -11.16,6.93 -16.76,8.84 -5.6,1.93 -11.4,2.9 -17.41,2.9 -11.42,0 -20.32,-3.3 -26.7,-9.9 -6.35,-6.6 -9.53,-15.82 -9.53,-27.65 0,-11.83 3.18,-21.04 9.53,-27.64 6.38,-6.6 15.28,-9.9 26.7,-9.9 6.4,0 12.47,0.99 18.22,2.97 5.77,1.98 11.09,4.9 15.95,8.76 l 0,-32.85 c -6.38,-3.13 -12.86,-5.48 -19.43,-7.05 -6.56,-1.56 -13.14,-2.34 -19.77,-2.34 -23,0 -40.99,6 -53.97,18.01 -12.98,12 -19.47,28.68 -19.47,50.04 0,21.37 6.49,38.05 19.47,50.05 12.98,12 30.97,18.01 53.97,18.01 6.7,0 13.29,-0.79 19.77,-2.35 6.5,-1.57 12.98,-3.91 19.43,-7.04"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3028"
- inkscape:connector-curvature="0" /><path
- d="m 2924.29,2018.38 c -9.22,0 -16.25,-3.23 -21.09,-9.68 -4.84,-6.43 -7.25,-15.72 -7.25,-27.87 0,-12.15 2.41,-21.45 7.25,-27.9 4.84,-6.43 11.87,-9.64 21.09,-9.64 9.04,0 15.96,3.21 20.75,9.64 4.82,6.45 7.22,15.75 7.22,27.9 0,12.15 -2.4,21.44 -7.22,27.87 -4.79,6.45 -11.71,9.68 -20.75,9.68 m 0,30.51 c 22.02,0 39.23,-6.03 51.62,-18.08 12.39,-12.03 18.59,-28.69 18.59,-49.98 0,-21.29 -6.2,-37.96 -18.59,-50.01 -12.39,-12.03 -29.6,-18.04 -51.62,-18.04 -22.13,0 -39.42,6.01 -51.88,18.04 -12.47,12.05 -18.71,28.72 -18.71,50.01 0,21.29 6.24,37.95 18.71,49.98 12.46,12.05 29.75,18.08 51.88,18.08"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3030"
- inkscape:connector-curvature="0" /><path
- d="m 3157.12,1995.43 0,-80.31 -39.9,0 0,61.46 c 0,11.39 -0.27,19.24 -0.8,23.54 -0.52,4.33 -1.42,7.5 -2.72,9.53 -1.68,2.76 -3.98,4.9 -6.89,6.42 -2.88,1.54 -6.17,2.31 -9.86,2.31 -9.02,0 -16.11,-3.4 -21.27,-10.19 -5.16,-6.8 -7.73,-16.2 -7.73,-28.2 l 0,-64.87 -39.9,0 0,129.07 39.9,0 0,-16.42 c 6.28,7.23 12.94,12.56 19.98,15.98 7.04,3.43 14.81,5.14 23.32,5.14 15.03,0 26.43,-4.56 34.21,-13.68 7.77,-9.12 11.66,-22.38 11.66,-39.78"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3032"
- inkscape:connector-curvature="0" /><path
- d="m 3243.26,2079.39 0,-35.2 42.24,0 0,-30.5 -42.24,0 0,-53.17 c 0,-5.82 1.22,-9.75 3.67,-11.81 2.45,-2.05 7.28,-3.08 14.52,-3.08 l 21.71,0 0,-30.51 -36.23,0 c -15.82,0 -27.04,3.44 -33.66,10.31 -6.6,6.89 -9.9,18.59 -9.9,35.09 l 0,53.17 -21.12,0 0,30.5 21.12,0 0,35.2 39.89,0"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3034"
- inkscape:connector-curvature="0" /><path
- d="m 3442.43,1983.36 0,-11.91 -98.55,0 c 1,-10.17 4.53,-17.8 10.59,-22.88 6.09,-5.09 14.58,-7.63 25.48,-7.63 8.8,0 17.81,1.36 27.03,4.07 9.21,2.71 18.68,6.83 28.41,12.36 l 0,-30.51 c -9.68,-4.65 -19.36,-8.15 -29.04,-10.52 -9.68,-2.38 -19.37,-3.56 -29.07,-3.56 -23.17,0 -41.19,5.95 -54.05,17.86 -12.83,11.93 -19.25,28.66 -19.25,50.19 0,21.15 6.36,37.77 19.07,49.87 12.71,12.12 30.2,18.19 52.47,18.19 20.26,0 36.48,-5.96 48.65,-17.86 12.18,-11.88 18.26,-27.77 18.26,-47.67 m -39.89,13.9 c 0,7.04 -2.48,12.71 -7.44,17.01 -4.97,4.3 -11.44,6.46 -19.44,6.46 -8.68,0 -15.73,-2.02 -21.15,-6.05 -5.4,-4.04 -8.78,-9.84 -10.12,-17.42 l 58.15,0"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3036"
- inkscape:connector-curvature="0" /><path
- d="m 3510.34,1981.16 -45.87,63.03 43.05,0 26,-38.24 26.36,38.24 43.04,0 -45.87,-62.81 48.22,-66.26 -43.08,0 -28.67,40.82 -28.31,-40.82 -43.09,0 48.22,66.04"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3038"
- inkscape:connector-curvature="0" /><path
- d="m 3675.84,2079.39 0,-35.2 42.24,0 0,-30.5 -42.24,0 0,-53.17 c 0,-5.82 1.22,-9.75 3.66,-11.81 2.45,-2.05 7.29,-3.08 14.52,-3.08 l 21.71,0 0,-30.51 -36.23,0 c -15.81,0 -27.03,3.44 -33.66,10.31 -6.59,6.89 -9.89,18.59 -9.89,35.09 l 0,53.17 -21.13,0 0,30.5 21.13,0 0,35.2 39.89,0"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3040"
- inkscape:connector-curvature="0" /><path
- d="m 14.1719,864.555 1984.22,0 0,566.918 -1984.22,0 0,-566.918 z"
- style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3042"
- inkscape:connector-curvature="0" /><path
- d="m 14.1719,864.555 1984.22,0 0,566.918 -1984.22,0 0,-566.918 z"
- style="fill:none;stroke:#000000;stroke-width:28.34600067;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none"
- id="path3044"
- inkscape:connector-curvature="0" /><path
- d="m 360.344,1193.81 39.89,0 0,-129.06 -39.89,0 0,129.06 m 0,49.28 39.89,0 0,-32.85 -39.89,0 0,32.85"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3046"
- inkscape:connector-curvature="0" /><path
- d="m 442.469,1193.81 39.894,0 0,-129.06 -39.894,0 0,129.06 m 0,49.28 39.894,0 0,-32.85 -39.894,0 0,32.85"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3048"
- inkscape:connector-curvature="0" /><path
- d="m 585.789,1168 c -9.215,0 -16.242,-3.23 -21.082,-9.68 -4.84,-6.43 -7.262,-15.72 -7.262,-27.87 0,-12.15 2.422,-21.45 7.262,-27.9 4.84,-6.43 11.867,-9.64 21.082,-9.64 9.047,0 15.965,3.21 20.754,9.64 4.816,6.45 7.223,15.75 7.223,27.9 0,12.15 -2.407,21.44 -7.223,27.87 -4.789,6.45 -11.707,9.68 -20.754,9.68 m 0,30.5 c 22.023,0 39.234,-6.02 51.629,-18.07 12.391,-12.03 18.59,-28.69 18.59,-49.98 0,-21.29 -6.199,-37.96 -18.59,-50.01 -12.395,-12.03 -29.606,-18.04 -51.629,-18.04 -22.121,0 -39.414,6.01 -51.883,18.04 -12.465,12.05 -18.699,28.72 -18.699,50.01 0,21.29 6.234,37.95 18.699,49.98 12.469,12.05 29.762,18.07 51.883,18.07"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3050"
- inkscape:connector-curvature="0" /><path
- d="m 670.781,1008.43 117.332,0 0,21.1211 -117.332,0 0,-21.1211 z"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3052"
- inkscape:connector-curvature="0" /><path
- d="m 899.082,1177.39 0,65.7 39.895,0 0,-178.34 -39.895,0 0,18.77 c -5.766,-7.31 -12.121,-12.66 -19.066,-16.06 -6.942,-3.37 -14.985,-5.06 -24.125,-5.06 -16.157,0 -29.43,6.34 -39.821,19.03 -10.363,12.69 -15.547,29.03 -15.547,49.02 0,20 5.184,36.34 15.547,49.03 10.391,12.68 23.664,19.02 39.821,19.02 9.043,0 17.062,-1.71 24.054,-5.13 6.989,-3.42 13.371,-8.75 19.137,-15.98 m -28.23,-84.48 c 9.164,0 16.156,3.2 20.972,9.6 4.84,6.41 7.258,15.72 7.258,27.94 0,12.23 -2.418,21.54 -7.258,27.94 -4.816,6.41 -11.808,9.61 -20.972,9.61 -9.071,0 -16.024,-3.2 -20.864,-9.61 -4.816,-6.4 -7.222,-15.71 -7.222,-27.94 0,-12.22 2.406,-21.53 7.222,-27.94 4.84,-6.4 11.793,-9.6 20.864,-9.6"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3054"
- inkscape:connector-curvature="0" /><path
- d="m 1111.02,1132.98 0,-11.91 -98.56,0 c 1,-10.17 4.53,-17.8 10.59,-22.88 6.09,-5.09 14.59,-7.63 25.49,-7.63 8.8,0 17.8,1.36 27.02,4.07 9.22,2.71 18.69,6.83 28.42,12.36 l 0,-30.51 c -9.68,-4.64 -19.36,-8.15 -29.04,-10.52 -9.68,-2.37 -19.37,-3.56 -29.08,-3.56 -23.17,0 -41.19,5.95 -54.048,17.86 -12.832,11.92 -19.25,28.66 -19.25,50.19 0,21.15 6.356,37.77 19.067,49.87 12.711,12.13 30.201,18.18 52.471,18.18 20.26,0 36.48,-5.95 48.66,-17.85 12.17,-11.88 18.26,-27.77 18.26,-47.67 m -39.9,13.9 c 0,7.04 -2.48,12.71 -7.44,17.01 -4.96,4.31 -11.44,6.46 -19.43,6.46 -8.68,0 -15.73,-2.02 -21.16,-6.05 -5.4,-4.04 -8.77,-9.84 -10.12,-17.42 l 58.15,0"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3056"
- inkscape:connector-curvature="0" /><path
- d="m 1130.71,1193.81 40.88,0 31.86,-89.21 31.76,89.21 40.99,0 -50.38,-129.06 -44.88,0 -50.23,129.06"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3058"
- inkscape:connector-curvature="0" /><path
- d="m 1301.25,1193.81 39.89,0 0,-129.06 -39.89,0 0,129.06 m 0,49.28 39.89,0 0,-32.85 -39.89,0 0,32.85"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3060"
- inkscape:connector-curvature="0" /><path
- d="m 1486.63,1189.12 0,-32.85 c -5.57,3.98 -11.16,6.93 -16.75,8.83 -5.6,1.94 -11.41,2.9 -17.42,2.9 -11.42,0 -20.32,-3.3 -26.69,-9.9 -6.36,-6.6 -9.54,-15.81 -9.54,-27.65 0,-11.83 3.18,-21.04 9.54,-27.65 6.37,-6.59 15.27,-9.89 26.69,-9.89 6.4,0 12.48,0.99 18.22,2.97 5.77,1.98 11.09,4.9 15.95,8.76 l 0,-32.85 c -6.38,-3.13 -12.86,-5.48 -19.43,-7.04 -6.56,-1.57 -13.14,-2.35 -19.77,-2.35 -23,0 -40.99,6 -53.97,18 -12.98,12.01 -19.47,28.69 -19.47,50.05 0,21.37 6.49,38.05 19.47,50.05 12.98,12 30.97,18 53.97,18 6.7,0 13.29,-0.78 19.77,-2.34 6.5,-1.57 12.98,-3.91 19.43,-7.04"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3062"
- inkscape:connector-curvature="0" /><path
- d="m 1654.75,1132.98 0,-11.91 -98.56,0 c 1,-10.17 4.53,-17.8 10.6,-22.88 6.08,-5.09 14.58,-7.63 25.48,-7.63 8.8,0 17.81,1.36 27.02,4.07 9.22,2.71 18.69,6.83 28.42,12.36 l 0,-30.51 c -9.68,-4.64 -19.36,-8.15 -29.04,-10.52 -9.68,-2.37 -19.37,-3.56 -29.08,-3.56 -23.17,0 -41.19,5.95 -54.04,17.86 -12.84,11.92 -19.25,28.66 -19.25,50.19 0,21.15 6.35,37.77 19.06,49.87 12.71,12.13 30.2,18.18 52.47,18.18 20.27,0 36.49,-5.95 48.66,-17.85 12.17,-11.88 18.26,-27.77 18.26,-47.67 m -39.89,13.9 c 0,7.04 -2.48,12.71 -7.45,17.01 -4.96,4.31 -11.44,6.46 -19.43,6.46 -8.68,0 -15.73,-2.02 -21.16,-6.05 -5.4,-4.04 -8.77,-9.84 -10.12,-17.42 l 58.16,0"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3064"
- inkscape:connector-curvature="0" /><path
- d="m 1998.39,14.1719 1984.22,0 0,566.922 -1984.22,0 0,-566.922 z"
- style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3066"
- inkscape:connector-curvature="0" /><path
- d="m 1998.39,14.1719 1984.22,0 0,566.922 -1984.22,0 0,-566.922 z"
- style="fill:none;stroke:#000000;stroke-width:28.34600067;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none"
- id="path3068"
- inkscape:connector-curvature="0" /><path
- d="m 2253.15,343.434 39.89,0 0,-129.067 -39.89,0 0,129.067 m 0,49.277 39.89,0 0,-32.852 -39.89,0 0,32.852"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3070"
- inkscape:connector-curvature="0" /><path
- d="m 2335.27,343.434 39.89,0 0,-129.067 -39.89,0 0,129.067 m 0,49.277 39.89,0 0,-32.852 -39.89,0 0,32.852"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3072"
- inkscape:connector-curvature="0" /><path
- d="m 2478.59,317.617 c -9.21,0 -16.24,-3.226 -21.08,-9.679 -4.84,-6.426 -7.26,-15.715 -7.26,-27.864 0,-12.148 2.42,-21.453 7.26,-27.906 4.84,-6.426 11.87,-9.641 21.08,-9.641 9.05,0 15.97,3.215 20.76,9.641 4.81,6.453 7.22,15.758 7.22,27.906 0,12.149 -2.41,21.438 -7.22,27.864 -4.79,6.453 -11.71,9.679 -20.76,9.679 m 0,30.508 c 22.03,0 39.24,-6.023 51.63,-18.074 12.39,-12.028 18.59,-28.688 18.59,-49.977 0,-21.293 -6.2,-37.965 -18.59,-50.015 -12.39,-12.024 -29.6,-18.039 -51.63,-18.039 -22.12,0 -39.41,6.015 -51.88,18.039 -12.46,12.05 -18.7,28.722 -18.7,50.015 0,21.289 6.24,37.949 18.7,49.977 12.47,12.051 29.76,18.074 51.88,18.074"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3074"
- inkscape:connector-curvature="0" /><path
- d="m 2563.59,158.047 117.332,0 0,21.1211 -117.332,0 0,-21.1211 z"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3076"
- inkscape:connector-curvature="0" /><path
- d="m 2805.97,338.738 0,-32.851 c -5.58,3.984 -11.16,6.929 -16.76,8.836 -5.6,1.929 -11.4,2.894 -17.42,2.894 -11.41,0 -20.31,-3.297 -26.69,-9.898 -6.35,-6.598 -9.53,-15.817 -9.53,-27.645 0,-11.832 3.18,-21.047 9.53,-27.648 6.38,-6.598 15.28,-9.899 26.69,-9.899 6.41,0 12.48,0.989 18.23,2.969 5.77,1.981 11.08,4.902 15.95,8.762 l 0,-32.852 c -6.38,-3.129 -12.86,-5.476 -19.43,-7.039 -6.56,-1.566 -13.15,-2.347 -19.77,-2.347 -23,0 -40.99,6 -53.97,18.003 -12.98,12 -19.47,28.684 -19.47,50.051 0,21.364 6.49,38.047 19.47,50.047 12.98,12.004 30.97,18.004 53.97,18.004 6.7,0 13.29,-0.781 19.77,-2.348 6.5,-1.562 12.98,-3.91 19.43,-7.039"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3078"
- inkscape:connector-curvature="0" /><path
- d="m 2974.09,294.664 0,-80.297 -39.9,0 0,61.231 c 0,11.539 -0.26,19.461 -0.8,23.761 -0.51,4.329 -1.42,7.504 -2.72,9.532 -1.68,2.765 -3.98,4.902 -6.89,6.418 -2.89,1.539 -6.17,2.308 -9.86,2.308 -9.02,0 -16.11,-3.394 -21.27,-10.191 -5.16,-6.797 -7.74,-16.196 -7.74,-28.196 l 0,-64.863 -39.89,0 0,178.344 39.89,0 0,-65.707 c 6.29,7.238 12.95,12.566 19.99,15.988 7.04,3.422 14.81,5.133 23.31,5.133 15.04,0 26.44,-4.559 34.22,-13.676 7.77,-9.117 11.66,-22.379 11.66,-39.785"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3080"
- inkscape:connector-curvature="0" /><path
- d="m 3073.14,273.031 c -8.95,0 -15.68,-1.418 -20.21,-4.25 -4.52,-2.812 -6.78,-6.969 -6.78,-12.469 0,-5.035 1.82,-8.984 5.46,-11.843 3.65,-2.86 8.69,-4.289 15.15,-4.289 8.09,0 14.88,2.687 20.38,8.066 5.53,5.379 8.29,12.113 8.29,20.203 l 0,4.582 -22.29,0 m 62.18,14.887 0,-73.551 -39.89,0 0,21.121 c -5.55,-8.191 -11.79,-14.156 -18.73,-17.894 -6.92,-3.715 -15.34,-5.574 -25.27,-5.574 -13.39,0 -24.27,3.824 -32.63,11.476 -8.36,7.676 -12.54,17.625 -12.54,29.848 0,14.886 5.13,25.801 15.4,32.742 10.29,6.941 26.45,10.414 48.47,10.414 l 25.3,0 0,3.301 c 0,6.965 -2.57,12.062 -7.7,15.289 -5.13,3.25 -13.14,4.875 -24.02,4.875 -8.8,0 -17,-0.977 -24.6,-2.934 -7.57,-1.953 -14.62,-4.886 -21.12,-8.797 l 0,30.504 c 8.63,3.082 17.3,5.414 26,7.004 8.72,1.59 17.44,2.383 26.14,2.383 23.03,0 39.65,-4.73 49.87,-14.187 10.21,-9.438 15.32,-24.778 15.32,-46.02"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3082"
- inkscape:connector-curvature="0" /><path
- d="m 3306.84,294.664 0,-80.297 -39.89,0 0,61.453 c 0,11.391 -0.27,19.239 -0.81,23.539 -0.52,4.329 -1.42,7.504 -2.71,9.532 -1.69,2.765 -3.99,4.902 -6.9,6.418 -2.88,1.539 -6.17,2.308 -9.86,2.308 -9.02,0 -16.11,-3.394 -21.27,-10.191 -5.15,-6.797 -7.73,-16.196 -7.73,-28.196 l 0,-64.863 -39.9,0 0,129.067 39.9,0 0,-16.43 c 6.28,7.238 12.94,12.566 19.98,15.988 7.04,3.422 14.81,5.133 23.32,5.133 15.03,0 26.44,-4.559 34.21,-13.676 7.77,-9.117 11.66,-22.379 11.66,-39.785"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3084"
- inkscape:connector-curvature="0" /><path
- d="m 3477.46,294.664 0,-80.297 -39.89,0 0,61.453 c 0,11.391 -0.27,19.239 -0.8,23.539 -0.52,4.329 -1.42,7.504 -2.72,9.532 -1.69,2.765 -3.98,4.902 -6.89,6.418 -2.89,1.539 -6.18,2.308 -9.87,2.308 -9.02,0 -16.1,-3.394 -21.26,-10.191 -5.16,-6.797 -7.74,-16.196 -7.74,-28.196 l 0,-64.863 -39.89,0 0,129.067 39.89,0 0,-16.43 c 6.28,7.238 12.94,12.566 19.98,15.988 7.05,3.422 14.82,5.133 23.32,5.133 15.04,0 26.44,-4.559 34.21,-13.676 7.78,-9.117 11.66,-22.379 11.66,-39.785"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3086"
- inkscape:connector-curvature="0" /><path
- d="m 3648.09,282.602 0,-11.914 -98.56,0 c 1,-10.172 4.53,-17.797 10.59,-22.883 6.09,-5.082 14.59,-7.625 25.49,-7.625 8.8,0 17.81,1.355 27.02,4.07 9.22,2.715 18.69,6.832 28.42,12.355 l 0,-30.503 c -9.68,-4.645 -19.36,-8.153 -29.04,-10.524 -9.68,-2.371 -19.37,-3.558 -29.08,-3.558 -23.17,0 -41.19,5.953 -54.04,17.855 -12.84,11.93 -19.25,28.664 -19.25,50.199 0,21.145 6.35,37.766 19.06,49.864 12.71,12.124 30.2,18.187 52.47,18.187 20.27,0 36.49,-5.953 48.66,-17.855 12.17,-11.879 18.26,-27.77 18.26,-47.668 M 3608.2,296.5 c 0,7.039 -2.49,12.711 -7.45,17.012 -4.96,4.304 -11.44,6.453 -19.43,6.453 -8.68,0 -15.73,-2.016 -21.16,-6.051 -5.4,-4.031 -8.77,-9.836 -10.12,-17.414 l 58.16,0"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3088"
- inkscape:connector-curvature="0" /><path
- d="m 3681.86,214.367 39.8945,0 0,178.344 -39.8945,0 0,-178.344 z"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3090"
- inkscape:connector-curvature="0" /><path
- d="m 3982.61,864.555 1984.22,0 0,566.918 -1984.22,0 0,-566.918 z"
- style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3092"
- inkscape:connector-curvature="0" /><path
- d="m 3982.61,864.555 1984.22,0 0,566.918 -1984.22,0 0,-566.918 z"
- style="fill:none;stroke:#000000;stroke-width:28.34600067;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none"
- id="path3094"
- inkscape:connector-curvature="0" /><path
- d="m 4359.25,1193.81 39.9,0 0,-129.06 -39.9,0 0,129.06 m 0,49.28 39.9,0 0,-32.85 -39.9,0 0,32.85"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3096"
- inkscape:connector-curvature="0" /><path
- d="m 4441.38,1193.81 39.89,0 0,-129.06 -39.89,0 0,129.06 m 0,49.28 39.89,0 0,-32.85 -39.89,0 0,32.85"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3098"
- inkscape:connector-curvature="0" /><path
- d="m 4584.7,1168 c -9.21,0 -16.24,-3.23 -21.08,-9.68 -4.84,-6.43 -7.26,-15.72 -7.26,-27.87 0,-12.15 2.42,-21.45 7.26,-27.9 4.84,-6.43 11.87,-9.64 21.08,-9.64 9.05,0 15.96,3.21 20.76,9.64 4.81,6.45 7.22,15.75 7.22,27.9 0,12.15 -2.41,21.44 -7.22,27.87 -4.8,6.45 -11.71,9.68 -20.76,9.68 m 0,30.5 c 22.03,0 39.23,-6.02 51.63,-18.07 12.39,-12.03 18.59,-28.69 18.59,-49.98 0,-21.29 -6.2,-37.96 -18.59,-50.01 -12.4,-12.03 -29.6,-18.04 -51.63,-18.04 -22.12,0 -39.41,6.01 -51.88,18.04 -12.47,12.05 -18.7,28.72 -18.7,50.01 0,21.29 6.23,37.95 18.7,49.98 12.47,12.05 29.76,18.07 51.88,18.07"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3100"
- inkscape:connector-curvature="0" /><path
- d="m 4669.69,1008.43 117.332,0 0,21.1211 -117.332,0 0,-21.1211 z"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3102"
- inkscape:connector-curvature="0" /><path
- d="m 4876.99,1092.91 c 9.12,0 16.07,3.2 20.86,9.6 4.79,6.41 7.19,15.72 7.19,27.94 0,12.23 -2.4,21.54 -7.19,27.94 -4.79,6.41 -11.74,9.61 -20.86,9.61 -9.1,0 -16.09,-3.23 -20.98,-9.68 -4.86,-6.45 -7.3,-15.74 -7.3,-27.87 0,-12.12 2.44,-21.41 7.3,-27.86 4.89,-6.46 11.88,-9.68 20.98,-9.68 m -28.28,84.48 c 5.77,7.23 12.16,12.56 19.15,15.98 7.01,3.42 15.08,5.13 24.19,5.13 16.11,0 29.34,-6.34 39.68,-19.02 10.36,-12.69 15.55,-29.03 15.55,-49.03 0,-19.99 -5.19,-36.33 -15.55,-49.02 -10.34,-12.69 -23.57,-19.03 -39.68,-19.03 -9.11,0 -17.18,1.71 -24.19,5.14 -6.99,3.42 -13.38,8.75 -19.15,15.98 l 0,-18.77 -39.89,0 0,178.34 39.89,0 0,-65.7"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3104"
- inkscape:connector-curvature="0" /><path
- d="m 4980.86,1115.2 0,78.61 39.9,0 0,-12.87 c 0,-6.96 -0.04,-15.71 -0.11,-26.25 -0.08,-10.54 -0.11,-17.57 -0.11,-21.08 0,-10.37 0.28,-17.84 0.84,-22.41 0.56,-4.54 1.53,-7.84 2.9,-9.9 1.78,-2.69 4.09,-4.76 6.93,-6.23 2.86,-1.44 6.15,-2.16 9.86,-2.16 9.02,0 16.1,3.29 21.23,9.86 5.16,6.6 7.74,15.77 7.74,27.5 l 0,63.54 39.89,0 0,-129.06 -39.89,0 0,18.77 c -6.26,-7.23 -12.9,-12.56 -19.92,-15.98 -7.01,-3.43 -14.73,-5.14 -23.17,-5.14 -15,0 -26.45,4.5 -34.32,13.49 -7.84,9.02 -11.77,22.13 -11.77,39.31"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3106"
- inkscape:connector-curvature="0" /><path
- d="m 5238.32,1243.09 0,-28.16 -23.66,0 c -6.06,0 -10.27,-0.94 -12.64,-2.82 -2.4,-1.98 -3.6,-5.34 -3.6,-10.08 l 0,-8.22 49.28,0 0,8.8 c 0,13.81 3.8,24 11.41,30.55 7.62,6.62 19.41,9.93 35.38,9.93 l 30.65,0 0,-28.16 -22.26,0 c -5.69,0 -9.67,-0.94 -11.91,-2.82 -2.25,-1.98 -3.38,-5.34 -3.38,-10.08 l 0,-8.22 35.2,0 0,-30.51 -35.2,0 0,-98.55 -39.89,0 0,98.55 -49.28,0 0,-98.55 -39.89,0 0,98.55 -21.12,0 0,30.51 21.12,0 0,8.8 c 0,13.81 3.92,24 11.77,30.55 7.82,6.62 19.96,9.93 36.41,9.93 l 31.61,0"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3108"
- inkscape:connector-curvature="0" /><path
- d="m 5474.54,1132.98 0,-11.91 -98.56,0 c 1,-10.17 4.54,-17.8 10.6,-22.88 6.08,-5.09 14.58,-7.63 25.48,-7.63 8.8,0 17.81,1.36 27.03,4.07 9.21,2.71 18.68,6.83 28.41,12.36 l 0,-30.51 c -9.68,-4.64 -19.36,-8.15 -29.04,-10.52 -9.68,-2.37 -19.37,-3.56 -29.08,-3.56 -23.17,0 -41.18,5.95 -54.04,17.86 -12.84,11.92 -19.25,28.66 -19.25,50.19 0,21.15 6.36,37.77 19.07,49.87 12.71,12.13 30.2,18.18 52.46,18.18 20.27,0 36.49,-5.95 48.66,-17.85 12.17,-11.88 18.26,-27.77 18.26,-47.67 m -39.89,13.9 c 0,7.04 -2.48,12.71 -7.45,17.01 -4.96,4.31 -11.43,6.46 -19.43,6.46 -8.68,0 -15.73,-2.02 -21.16,-6.05 -5.4,-4.04 -8.77,-9.84 -10.11,-17.42 l 58.15,0"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3110"
- inkscape:connector-curvature="0" /><path
- d="m 5604.52,1160.96 c -3.71,1.59 -7.41,2.76 -11.11,3.52 -3.69,0.78 -7.39,1.17 -11.11,1.17 -10.92,0 -19.34,-3.45 -25.26,-10.37 -5.89,-6.9 -8.84,-16.77 -8.84,-29.63 l 0,-60.9 -39.89,0 0,129.06 39.89,0 0,-18.77 c 5.48,8.16 11.76,14.12 18.85,17.85 7.09,3.75 15.58,5.61 25.49,5.61 1.41,0 2.95,-0.08 4.61,-0.25 1.67,-0.17 4.08,-0.55 7.26,-1.14 l 0.11,-36.15"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3112"
- inkscape:connector-curvature="0" /><path
- d="m 1998.39,1998.39 -992.11,0 0,-566.92"
- style="fill:none;stroke:#000000;stroke-width:28.34600067;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none"
- id="path3114"
- inkscape:connector-curvature="0" /><path
- d="m 1856.04,2054.99 28.16,0 0,100.91 -30.51,-7.04 0,14.08 30.76,7.04 18.52,0 0,-114.99 28.16,0 0,-14.08 -75.09,0 0,14.08"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3116"
- inkscape:connector-curvature="0" /><path
- d="m 1105.21,1553.84 c 0,3.2 1.13,5.96 3.38,8.28 2.27,2.32 4.98,3.49 8.14,3.49 3.27,0 6.09,-1.17 8.43,-3.49 2.35,-2.32 3.52,-5.08 3.52,-8.28 0,-3.26 -1.16,-6.02 -3.48,-8.29 -2.3,-2.28 -5.12,-3.41 -8.47,-3.41 -3.28,0 -6.02,1.1 -8.21,3.3 -2.2,2.22 -3.31,5.02 -3.31,8.4 m 11.7,51.66 c -7.87,0 -13.75,-4.36 -17.64,-13.05 -3.86,-8.71 -5.79,-21.97 -5.79,-39.79 0,-17.77 1.93,-31.01 5.79,-39.71 3.89,-8.7 9.77,-13.05 17.64,-13.05 7.92,0 13.81,4.35 17.68,13.05 3.88,8.7 5.82,21.94 5.82,39.71 0,17.82 -1.94,31.08 -5.82,39.79 -3.87,8.69 -9.76,13.05 -17.68,13.05 m 0,14.08 c 13.91,0 24.43,-5.65 31.57,-16.94 7.14,-11.27 10.71,-27.93 10.71,-49.98 0,-22 -3.57,-38.64 -10.71,-49.94 -7.14,-11.27 -17.66,-16.9 -31.57,-16.9 -13.93,0 -24.46,5.63 -31.57,16.9 -7.09,11.3 -10.63,27.94 -10.63,49.94 0,22.05 3.54,38.71 10.63,49.98 7.11,11.29 17.64,16.94 31.57,16.94"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3118"
- inkscape:connector-curvature="0" /><path
- d="m 1214.24,1488.16 21.1211,0 0,25.8125 -21.1211,0 0,-25.8125 z"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3120"
- inkscape:connector-curvature="0" /><path
- d="m 1323.27,1488.16 21.1211,0 0,25.8125 -21.1211,0 0,-25.8125 z"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3122"
- inkscape:connector-curvature="0" /><path
- d="m 1483.93,1596.77 -32.08,-17.09 32.08,-17.19 -5.1,-8.62 -30.1,17.9 0,-31.98 -9.39,0 0,31.98 -30.1,-17.9 -5.1,8.62 32.09,17.19 -32.09,17.09 5.1,8.73 30.1,-17.89 0,31.97 9.39,0 0,-31.97 30.1,17.89 5.1,-8.73"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3124"
- inkscape:connector-curvature="0" /><path
- d="m 1006.28,850.309 0,-552.676 992.11,0"
- style="fill:none;stroke:#000000;stroke-width:28.34600067;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none"
- id="path3126"
- inkscape:connector-curvature="0" /><path
- d="m 1086.44,694.312 28.16,0 0,100.907 -30.51,-7.043 0,14.082 30.77,7.039 18.52,0 0,-114.985 28.16,0 0,-14.082 -75.1,0 0,14.082"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3128"
- inkscape:connector-curvature="0" /><path
- d="m 1547.41,405.82 c 0,3.203 1.13,5.965 3.38,8.289 2.27,2.321 4.98,3.481 8.14,3.481 3.27,0 6.08,-1.16 8.43,-3.481 2.35,-2.324 3.52,-5.086 3.52,-8.289 0,-3.25 -1.16,-6.011 -3.49,-8.285 -2.29,-2.273 -5.12,-3.41 -8.46,-3.41 -3.28,0 -6.02,1.102 -8.22,3.301 -2.2,2.222 -3.3,5.023 -3.3,8.394 m 11.7,51.664 c -7.87,0 -13.75,-4.351 -17.64,-13.054 -3.86,-8.7 -5.79,-21.961 -5.79,-39.782 0,-17.769 1.93,-31.007 5.79,-39.71 3.89,-8.704 9.77,-13.051 17.64,-13.051 7.92,0 13.81,4.347 17.67,13.051 3.89,8.703 5.83,21.941 5.83,39.71 0,17.821 -1.94,31.082 -5.83,39.782 -3.86,8.703 -9.75,13.054 -17.67,13.054 m 0,14.078 c 13.91,0 24.43,-5.644 31.57,-16.937 7.14,-11.27 10.71,-27.93 10.71,-49.977 0,-22 -3.57,-38.648 -10.71,-49.941 -7.14,-11.266 -17.66,-16.902 -31.57,-16.902 -13.93,0 -24.46,5.636 -31.57,16.902 -7.09,11.293 -10.63,27.941 -10.63,49.941 0,22.047 3.54,38.707 10.63,49.977 7.11,11.293 17.64,16.937 31.57,16.937"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3130"
- inkscape:connector-curvature="0" /><path
- d="m 1656.44,340.152 21.1211,0 0,25.8125 -21.1211,0 0,-25.8125 z"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3132"
- inkscape:connector-curvature="0" /><path
- d="m 1765.47,340.152 21.1172,0 0,25.8125 -21.1172,0 0,-25.8125 z"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3134"
- inkscape:connector-curvature="0" /><path
- d="m 1926.13,448.758 -32.09,-17.086 32.09,-17.199 -5.1,-8.614 -30.1,17.891 0,-31.973 -9.39,0 0,31.973 -30.1,-17.891 -5.1,8.614 32.09,17.199 -32.09,17.086 5.1,8.726 30.1,-17.894 0,31.972 9.39,0 0,-31.972 30.1,17.894 5.1,-8.726"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3136"
- inkscape:connector-curvature="0" /><path
- d="m 2012.69,1148.01 1955.63,0"
- style="fill:none;stroke:#000000;stroke-width:28.34600067;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none"
- id="path3138"
- inkscape:connector-curvature="0" /><path
- d="m 2092.85,1204.61 28.16,0 0,100.91 -30.51,-7.04 0,14.08 30.76,7.04 18.52,0 0,-114.99 28.16,0 0,-14.08 -75.09,0 0,14.08"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3140"
- inkscape:connector-curvature="0" /><path
- d="m 3517.34,1256.2 c 0,3.2 1.12,5.96 3.37,8.29 2.27,2.32 4.99,3.48 8.14,3.48 3.27,0 6.09,-1.16 8.44,-3.48 2.34,-2.33 3.51,-5.09 3.51,-8.29 0,-3.25 -1.16,-6.01 -3.48,-8.29 -2.3,-2.27 -5.12,-3.41 -8.47,-3.41 -3.28,0 -6.01,1.11 -8.21,3.3 -2.2,2.23 -3.3,5.03 -3.3,8.4 m 11.7,51.66 c -7.88,0 -13.75,-4.35 -17.64,-13.05 -3.86,-8.7 -5.79,-21.96 -5.79,-39.78 0,-17.77 1.93,-31.01 5.79,-39.71 3.89,-8.7 9.76,-13.05 17.64,-13.05 7.91,0 13.8,4.35 17.67,13.05 3.88,8.7 5.83,21.94 5.83,39.71 0,17.82 -1.95,31.08 -5.83,39.78 -3.87,8.7 -9.76,13.05 -17.67,13.05 m 0,14.09 c 13.9,0 24.42,-5.65 31.56,-16.95 7.14,-11.27 10.71,-27.92 10.71,-49.97 0,-22 -3.57,-38.65 -10.71,-49.94 -7.14,-11.27 -17.66,-16.91 -31.56,-16.91 -13.94,0 -24.46,5.64 -31.58,16.91 -7.08,11.29 -10.63,27.94 -10.63,49.94 0,22.05 3.55,38.7 10.63,49.97 7.12,11.3 17.64,16.95 31.58,16.95"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3142"
- inkscape:connector-curvature="0" /><path
- d="m 3626.37,1190.53 21.1172,0 0,25.8125 -21.1172,0 0,-25.8125 z"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3144"
- inkscape:connector-curvature="0" /><path
- d="m 3735.39,1190.53 21.1211,0 0,25.8125 -21.1211,0 0,-25.8125 z"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3146"
- inkscape:connector-curvature="0" /><path
- d="m 3825.65,1204.61 28.16,0 0,100.91 -30.51,-7.04 0,14.08 30.77,7.04 18.52,0 0,-114.99 28.16,0 0,-14.08 -75.1,0 0,14.08"
- style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
- id="path3148"
- inkscape:connector-curvature="0" /></g></g></svg> \ No newline at end of file
diff --git a/examples/.gitignore b/examples/.gitignore
deleted file mode 100644
index bd88afb..0000000
--- a/examples/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-ad9361-iiostream
-iio-monitor
-!Makefile
diff --git a/examples/Makefile b/examples/Makefile
deleted file mode 100644
index 896835a..0000000
--- a/examples/Makefile
+++ /dev/null
@@ -1,46 +0,0 @@
-# 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.
-
-
-TARGETS := ad9361-iiostream ad9371-iiostream dummy-iiostream iio-monitor
-
-CFLAGS = -Wall
-
-UNAME_S := $(shell uname -s)
-
-ifeq ($(UNAME_S),Darwin)
- CFLAGS += -framework iio
-else
- LDFLAGS += -liio
-endif
-
-.PHONY: all clean
-
-all: $(TARGETS)
-
-iio-monitor: iio-monitor.o
- $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) -lpthread -lncurses -lcdk
-
-ad9361-iiostream : ad9361-iiostream.o
- $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
-
-ad9371-iiostream : ad9371-iiostream.o
- $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
-
-dummy-iiostream : dummy-iiostream.o
- $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
-
-clean:
- rm -f $(TARGETS) $(TARGETS:%=%.o)
diff --git a/examples/ad9361-iiostream.c b/examples/ad9361-iiostream.c
deleted file mode 100644
index 0756b7b..0000000
--- a/examples/ad9361-iiostream.c
+++ /dev/null
@@ -1,294 +0,0 @@
-/*
- * libiio - AD9361 IIO streaming example
- *
- * Copyright (C) 2014 IABG mbH
- * Author: Michael Feilen <feilen_at_iabg.de>
- *
- * 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.
- *
- **/
-
-#include <stdbool.h>
-#include <stdint.h>
-#include <string.h>
-#include <signal.h>
-#include <stdio.h>
-
-#ifdef __APPLE__
-#include <iio/iio.h>
-#else
-#include <iio.h>
-#endif
-
-/* helper macros */
-#define MHZ(x) ((long long)(x*1000000.0 + .5))
-#define GHZ(x) ((long long)(x*1000000000.0 + .5))
-
-#define ASSERT(expr) { \
- if (!(expr)) { \
- (void) fprintf(stderr, "assertion failed (%s:%d)\n", __FILE__, __LINE__); \
- (void) abort(); \
- } \
-}
-
-/* RX is input, TX is output */
-enum iodev { RX, TX };
-
-/* common RX and TX streaming params */
-struct stream_cfg {
- long long bw_hz; // Analog banwidth in Hz
- long long fs_hz; // Baseband sample rate in Hz
- long long lo_hz; // Local oscillator frequency in Hz
- const char* rfport; // Port name
-};
-
-/* static scratch mem for strings */
-static char tmpstr[64];
-
-/* IIO structs required for streaming */
-static struct iio_context *ctx = NULL;
-static struct iio_channel *rx0_i = NULL;
-static struct iio_channel *rx0_q = NULL;
-static struct iio_channel *tx0_i = NULL;
-static struct iio_channel *tx0_q = NULL;
-static struct iio_buffer *rxbuf = NULL;
-static struct iio_buffer *txbuf = NULL;
-
-static bool stop;
-
-/* cleanup and exit */
-static void shutdown()
-{
- printf("* Destroying buffers\n");
- if (rxbuf) { iio_buffer_destroy(rxbuf); }
- if (txbuf) { iio_buffer_destroy(txbuf); }
-
- printf("* Disabling streaming channels\n");
- if (rx0_i) { iio_channel_disable(rx0_i); }
- if (rx0_q) { iio_channel_disable(rx0_q); }
- if (tx0_i) { iio_channel_disable(tx0_i); }
- if (tx0_q) { iio_channel_disable(tx0_q); }
-
- printf("* Destroying context\n");
- if (ctx) { iio_context_destroy(ctx); }
- exit(0);
-}
-
-static void handle_sig(int sig)
-{
- printf("Waiting for process to finish...\n");
- stop = true;
-}
-
-/* check return value of attr_write function */
-static void errchk(int v, const char* what) {
- if (v < 0) { fprintf(stderr, "Error %d writing to channel \"%s\"\nvalue may not be supported.\n", v, what); shutdown(); }
-}
-
-/* write attribute: long long int */
-static void wr_ch_lli(struct iio_channel *chn, const char* what, long long val)
-{
- errchk(iio_channel_attr_write_longlong(chn, what, val), what);
-}
-
-/* write attribute: string */
-static void wr_ch_str(struct iio_channel *chn, const char* what, const char* str)
-{
- errchk(iio_channel_attr_write(chn, what, str), what);
-}
-
-/* helper function generating channel names */
-static char* get_ch_name(const char* type, int id)
-{
- snprintf(tmpstr, sizeof(tmpstr), "%s%d", type, id);
- return tmpstr;
-}
-
-/* returns ad9361 phy device */
-static struct iio_device* get_ad9361_phy(struct iio_context *ctx)
-{
- struct iio_device *dev = iio_context_find_device(ctx, "ad9361-phy");
- ASSERT(dev && "No ad9361-phy found");
- return dev;
-}
-
-/* finds AD9361 streaming IIO devices */
-static bool get_ad9361_stream_dev(struct iio_context *ctx, enum iodev d, struct iio_device **dev)
-{
- switch (d) {
- case TX: *dev = iio_context_find_device(ctx, "cf-ad9361-dds-core-lpc"); return *dev != NULL;
- case RX: *dev = iio_context_find_device(ctx, "cf-ad9361-lpc"); return *dev != NULL;
- default: ASSERT(0); return false;
- }
-}
-
-/* finds AD9361 streaming IIO channels */
-static bool get_ad9361_stream_ch(struct iio_context *ctx, enum iodev d, struct iio_device *dev, int chid, struct iio_channel **chn)
-{
- *chn = iio_device_find_channel(dev, get_ch_name("voltage", chid), d == TX);
- if (!*chn)
- *chn = iio_device_find_channel(dev, get_ch_name("altvoltage", chid), d == TX);
- return *chn != NULL;
-}
-
-/* finds AD9361 phy IIO configuration channel with id chid */
-static bool get_phy_chan(struct iio_context *ctx, enum iodev d, int chid, struct iio_channel **chn)
-{
- switch (d) {
- case RX: *chn = iio_device_find_channel(get_ad9361_phy(ctx), get_ch_name("voltage", chid), false); return *chn != NULL;
- case TX: *chn = iio_device_find_channel(get_ad9361_phy(ctx), get_ch_name("voltage", chid), true); return *chn != NULL;
- default: ASSERT(0); return false;
- }
-}
-
-/* finds AD9361 local oscillator IIO configuration channels */
-static bool get_lo_chan(struct iio_context *ctx, enum iodev d, struct iio_channel **chn)
-{
- switch (d) {
- // LO chan is always output, i.e. true
- case RX: *chn = iio_device_find_channel(get_ad9361_phy(ctx), get_ch_name("altvoltage", 0), true); return *chn != NULL;
- case TX: *chn = iio_device_find_channel(get_ad9361_phy(ctx), get_ch_name("altvoltage", 1), true); return *chn != NULL;
- default: ASSERT(0); return false;
- }
-}
-
-/* applies streaming configuration through IIO */
-bool cfg_ad9361_streaming_ch(struct iio_context *ctx, struct stream_cfg *cfg, enum iodev type, int chid)
-{
- struct iio_channel *chn = NULL;
-
- // Configure phy and lo channels
- printf("* Acquiring AD9361 phy channel %d\n", chid);
- if (!get_phy_chan(ctx, type, chid, &chn)) { return false; }
- wr_ch_str(chn, "rf_port_select", cfg->rfport);
- wr_ch_lli(chn, "rf_bandwidth", cfg->bw_hz);
- wr_ch_lli(chn, "sampling_frequency", cfg->fs_hz);
-
- // Configure LO channel
- printf("* Acquiring AD9361 %s lo channel\n", type == TX ? "TX" : "RX");
- if (!get_lo_chan(ctx, type, &chn)) { return false; }
- wr_ch_lli(chn, "frequency", cfg->lo_hz);
- return true;
-}
-
-/* simple configuration and streaming */
-int main (int argc, char **argv)
-{
- // Streaming devices
- struct iio_device *tx;
- struct iio_device *rx;
-
- // RX and TX sample counters
- size_t nrx = 0;
- size_t ntx = 0;
-
- // Stream configurations
- struct stream_cfg rxcfg;
- struct stream_cfg txcfg;
-
- // Listen to ctrl+c and ASSERT
- signal(SIGINT, handle_sig);
-
- // RX stream config
- rxcfg.bw_hz = MHZ(2); // 2 MHz rf bandwidth
- rxcfg.fs_hz = MHZ(2.5); // 2.5 MS/s rx sample rate
- rxcfg.lo_hz = GHZ(2.5); // 2.5 GHz rf frequency
- rxcfg.rfport = "A_BALANCED"; // port A (select for rf freq.)
-
- // TX stream config
- txcfg.bw_hz = MHZ(1.5); // 1.5 MHz rf bandwidth
- txcfg.fs_hz = MHZ(2.5); // 2.5 MS/s tx sample rate
- txcfg.lo_hz = GHZ(2.5); // 2.5 GHz rf frequency
- txcfg.rfport = "A"; // port A (select for rf freq.)
-
- printf("* Acquiring IIO context\n");
- ASSERT((ctx = iio_create_default_context()) && "No context");
- ASSERT(iio_context_get_devices_count(ctx) > 0 && "No devices");
-
- printf("* Acquiring AD9361 streaming devices\n");
- ASSERT(get_ad9361_stream_dev(ctx, TX, &tx) && "No tx dev found");
- ASSERT(get_ad9361_stream_dev(ctx, RX, &rx) && "No rx dev found");
-
- printf("* Configuring AD9361 for streaming\n");
- ASSERT(cfg_ad9361_streaming_ch(ctx, &rxcfg, RX, 0) && "RX port 0 not found");
- ASSERT(cfg_ad9361_streaming_ch(ctx, &txcfg, TX, 0) && "TX port 0 not found");
-
- printf("* Initializing AD9361 IIO streaming channels\n");
- ASSERT(get_ad9361_stream_ch(ctx, RX, rx, 0, &rx0_i) && "RX chan i not found");
- ASSERT(get_ad9361_stream_ch(ctx, RX, rx, 1, &rx0_q) && "RX chan q not found");
- ASSERT(get_ad9361_stream_ch(ctx, TX, tx, 0, &tx0_i) && "TX chan i not found");
- ASSERT(get_ad9361_stream_ch(ctx, TX, tx, 1, &tx0_q) && "TX chan q not found");
-
- printf("* Enabling IIO streaming channels\n");
- iio_channel_enable(rx0_i);
- iio_channel_enable(rx0_q);
- iio_channel_enable(tx0_i);
- iio_channel_enable(tx0_q);
-
- printf("* Creating non-cyclic IIO buffers with 1 MiS\n");
- rxbuf = iio_device_create_buffer(rx, 1024*1024, false);
- if (!rxbuf) {
- perror("Could not create RX buffer");
- shutdown();
- }
- txbuf = iio_device_create_buffer(tx, 1024*1024, false);
- if (!txbuf) {
- perror("Could not create TX buffer");
- shutdown();
- }
-
- printf("* Starting IO streaming (press CTRL+C to cancel)\n");
- while (!stop)
- {
- ssize_t nbytes_rx, nbytes_tx;
- char *p_dat, *p_end;
- ptrdiff_t p_inc;
-
- // Schedule TX buffer
- nbytes_tx = iio_buffer_push(txbuf);
- if (nbytes_tx < 0) { printf("Error pushing buf %d\n", (int) nbytes_tx); shutdown(); }
-
- // Refill RX buffer
- nbytes_rx = iio_buffer_refill(rxbuf);
- if (nbytes_rx < 0) { printf("Error refilling buf %d\n",(int) nbytes_rx); shutdown(); }
-
- // READ: Get pointers to RX buf and read IQ from RX buf port 0
- p_inc = iio_buffer_step(rxbuf);
- p_end = iio_buffer_end(rxbuf);
- for (p_dat = (char *)iio_buffer_first(rxbuf, rx0_i); p_dat < p_end; p_dat += p_inc) {
- // Example: swap I and Q
- const int16_t i = ((int16_t*)p_dat)[0]; // Real (I)
- const int16_t q = ((int16_t*)p_dat)[1]; // Imag (Q)
- ((int16_t*)p_dat)[0] = q;
- ((int16_t*)p_dat)[1] = i;
- }
-
- // WRITE: Get pointers to TX buf and write IQ to TX buf port 0
- p_inc = iio_buffer_step(txbuf);
- p_end = iio_buffer_end(txbuf);
- for (p_dat = (char *)iio_buffer_first(txbuf, tx0_i); p_dat < p_end; p_dat += p_inc) {
- // Example: fill with zeros
- // 12-bit sample needs to be MSB alligned so shift by 4
- // https://wiki.analog.com/resources/eval/user-guides/ad-fmcomms2-ebz/software/basic_iq_datafiles#binary_format
- ((int16_t*)p_dat)[0] = 0 << 4; // Real (I)
- ((int16_t*)p_dat)[1] = 0 << 4; // Imag (Q)
- }
-
- // Sample counter increment and status output
- nrx += nbytes_rx / iio_device_get_sample_size(rx);
- ntx += nbytes_tx / iio_device_get_sample_size(tx);
- printf("\tRX %8.2f MSmp, TX %8.2f MSmp\n", nrx/1e6, ntx/1e6);
- }
-
- shutdown();
-
- return 0;
-}
diff --git a/examples/ad9371-iiostream.c b/examples/ad9371-iiostream.c
deleted file mode 100644
index f330377..0000000
--- a/examples/ad9371-iiostream.c
+++ /dev/null
@@ -1,306 +0,0 @@
-/*
- * libiio - AD9371 IIO streaming example
- *
- * Copyright (C) 2014 IABG mbH
- * Author: Michael Feilen <feilen_at_iabg.de>
- * Copyright (C) 2017 Analog Devices Inc.
- *
- * 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.
- *
- **/
-
-#include <stdbool.h>
-#include <stdint.h>
-#include <string.h>
-#include <signal.h>
-#include <stdio.h>
-
-#ifdef __APPLE__
-#include <iio/iio.h>
-#else
-#include <iio.h>
-#endif
-
-/* helper macros */
-#define MHZ(x) ((long long)(x*1000000.0 + .5))
-#define GHZ(x) ((long long)(x*1000000000.0 + .5))
-
-#define ASSERT(expr) { \
- if (!(expr)) { \
- (void) fprintf(stderr, "assertion failed (%s:%d)\n", __FILE__, __LINE__); \
- (void) abort(); \
- } \
-}
-
-/* RX is input, TX is output */
-enum iodev { RX, TX };
-
-/* common RX and TX streaming params */
-struct stream_cfg {
- long long lo_hz; // Local oscillator frequency in Hz
-};
-
-/* static scratch mem for strings */
-static char tmpstr[64];
-
-/* IIO structs required for streaming */
-static struct iio_context *ctx = NULL;
-static struct iio_channel *rx0_i = NULL;
-static struct iio_channel *rx0_q = NULL;
-static struct iio_channel *tx0_i = NULL;
-static struct iio_channel *tx0_q = NULL;
-static struct iio_buffer *rxbuf = NULL;
-static struct iio_buffer *txbuf = NULL;
-
-static bool stop;
-
-/* cleanup and exit */
-static void shutdown()
-{
- printf("* Destroying buffers\n");
- if (rxbuf) { iio_buffer_destroy(rxbuf); }
- if (txbuf) { iio_buffer_destroy(txbuf); }
-
- printf("* Disabling streaming channels\n");
- if (rx0_i) { iio_channel_disable(rx0_i); }
- if (rx0_q) { iio_channel_disable(rx0_q); }
- if (tx0_i) { iio_channel_disable(tx0_i); }
- if (tx0_q) { iio_channel_disable(tx0_q); }
-
- printf("* Destroying context\n");
- if (ctx) { iio_context_destroy(ctx); }
- exit(0);
-}
-
-static void handle_sig(int sig)
-{
- printf("Waiting for process to finish...\n");
- stop = true;
-}
-
-/* check return value of attr_write function */
-static void errchk(int v, const char* what) {
- if (v < 0) { fprintf(stderr, "Error %d writing to channel \"%s\"\nvalue may not be supported.\n", v, what); shutdown(); }
-}
-
-/* write attribute: long long int */
-static void wr_ch_lli(struct iio_channel *chn, const char* what, long long val)
-{
- errchk(iio_channel_attr_write_longlong(chn, what, val), what);
-}
-
-/* write attribute: long long int */
-static long long rd_ch_lli(struct iio_channel *chn, const char* what)
-{
- long long val;
-
- errchk(iio_channel_attr_read_longlong(chn, what, &val), what);
-
- printf("\t %s: %lld\n", what, val);
- return val;
-}
-
-#if 0
-/* write attribute: string */
-static void wr_ch_str(struct iio_channel *chn, const char* what, const char* str)
-{
- errchk(iio_channel_attr_write(chn, what, str), what);
-}
-#endif
-
-/* helper function generating channel names */
-static char* get_ch_name_mod(const char* type, int id, char modify)
-{
- snprintf(tmpstr, sizeof(tmpstr), "%s%d_%c", type, id, modify);
- return tmpstr;
-}
-
-/* helper function generating channel names */
-static char* get_ch_name(const char* type, int id)
-{
- snprintf(tmpstr, sizeof(tmpstr), "%s%d", type, id);
- return tmpstr;
-}
-
-/* returns ad9371 phy device */
-static struct iio_device* get_ad9371_phy(struct iio_context *ctx)
-{
- struct iio_device *dev = iio_context_find_device(ctx, "ad9371-phy");
- ASSERT(dev && "No ad9371-phy found");
- return dev;
-}
-
-/* finds AD9371 streaming IIO devices */
-static bool get_ad9371_stream_dev(struct iio_context *ctx, enum iodev d, struct iio_device **dev)
-{
- switch (d) {
- case TX: *dev = iio_context_find_device(ctx, "axi-ad9371-tx-hpc"); return *dev != NULL;
- case RX: *dev = iio_context_find_device(ctx, "axi-ad9371-rx-hpc"); return *dev != NULL;
- default: ASSERT(0); return false;
- }
-}
-
-/* finds AD9371 streaming IIO channels */
-static bool get_ad9371_stream_ch(struct iio_context *ctx, enum iodev d, struct iio_device *dev, int chid, char modify, struct iio_channel **chn)
-{
- *chn = iio_device_find_channel(dev, modify ? get_ch_name_mod("voltage", chid, modify) : get_ch_name("voltage", chid), d == TX);
- if (!*chn)
- *chn = iio_device_find_channel(dev, modify ? get_ch_name_mod("voltage", chid, modify) : get_ch_name("voltage", chid), d == TX);
- return *chn != NULL;
-}
-
-/* finds AD9371 phy IIO configuration channel with id chid */
-static bool get_phy_chan(struct iio_context *ctx, enum iodev d, int chid, struct iio_channel **chn)
-{
- switch (d) {
- case RX: *chn = iio_device_find_channel(get_ad9371_phy(ctx), get_ch_name("voltage", chid), false); return *chn != NULL;
- case TX: *chn = iio_device_find_channel(get_ad9371_phy(ctx), get_ch_name("voltage", chid), true); return *chn != NULL;
- default: ASSERT(0); return false;
- }
-}
-
-/* finds AD9371 local oscillator IIO configuration channels */
-static bool get_lo_chan(struct iio_context *ctx, enum iodev d, struct iio_channel **chn)
-{
- switch (d) {
- // LO chan is always output, i.e. true
- case RX: *chn = iio_device_find_channel(get_ad9371_phy(ctx), get_ch_name("altvoltage", 0), true); return *chn != NULL;
- case TX: *chn = iio_device_find_channel(get_ad9371_phy(ctx), get_ch_name("altvoltage", 1), true); return *chn != NULL;
- default: ASSERT(0); return false;
- }
-}
-
-/* applies streaming configuration through IIO */
-bool cfg_ad9371_streaming_ch(struct iio_context *ctx, struct stream_cfg *cfg, enum iodev type, int chid)
-{
- struct iio_channel *chn = NULL;
-
- // Configure phy and lo channels
- printf("* Acquiring AD9371 phy %s channel %d\n", type == TX ? "TX" : "RX", chid);
- if (!get_phy_chan(ctx, type, chid, &chn)) { return false; }
-
- rd_ch_lli(chn, "rf_bandwidth");
- rd_ch_lli(chn, "sampling_frequency");
-
- // Configure LO channel
- printf("* Acquiring AD9371 %s lo channel\n", type == TX ? "TX" : "RX");
- if (!get_lo_chan(ctx, type, &chn)) { return false; }
- wr_ch_lli(chn, type == TX ? "TX_LO_frequency" : "RX_LO_frequency" , cfg->lo_hz);
- return true;
-}
-
-/* simple configuration and streaming */
-int main (int argc, char **argv)
-{
- // Streaming devices
- struct iio_device *tx;
- struct iio_device *rx;
-
- // RX and TX sample counters
- size_t nrx = 0;
- size_t ntx = 0;
-
- // Stream configurations
- struct stream_cfg rxcfg;
- struct stream_cfg txcfg;
-
- // Listen to ctrl+c and ASSERT
- signal(SIGINT, handle_sig);
-
- // RX stream config
- rxcfg.lo_hz = GHZ(2.5); // 2.5 GHz rf frequency
-
- // TX stream config
- txcfg.lo_hz = GHZ(2.5); // 2.5 GHz rf frequency
-
- printf("* Acquiring IIO context\n");
- ASSERT((ctx = iio_create_default_context()) && "No context");
- ASSERT(iio_context_get_devices_count(ctx) > 0 && "No devices");
-
- printf("* Acquiring AD9371 streaming devices\n");
- ASSERT(get_ad9371_stream_dev(ctx, TX, &tx) && "No tx dev found");
- ASSERT(get_ad9371_stream_dev(ctx, RX, &rx) && "No rx dev found");
-
- printf("* Configuring AD9371 for streaming\n");
- ASSERT(cfg_ad9371_streaming_ch(ctx, &rxcfg, RX, 0) && "RX port 0 not found");
- ASSERT(cfg_ad9371_streaming_ch(ctx, &txcfg, TX, 0) && "TX port 0 not found");
-
- printf("* Initializing AD9371 IIO streaming channels\n");
- ASSERT(get_ad9371_stream_ch(ctx, RX, rx, 0, 'i', &rx0_i) && "RX chan i not found");
- ASSERT(get_ad9371_stream_ch(ctx, RX, rx, 0, 'q', &rx0_q) && "RX chan q not found");
- ASSERT(get_ad9371_stream_ch(ctx, TX, tx, 0, 0, &tx0_i) && "TX chan i not found");
- ASSERT(get_ad9371_stream_ch(ctx, TX, tx, 1, 0, &tx0_q) && "TX chan q not found");
-
- printf("* Enabling IIO streaming channels\n");
- iio_channel_enable(rx0_i);
- iio_channel_enable(rx0_q);
- iio_channel_enable(tx0_i);
- iio_channel_enable(tx0_q);
-
- printf("* Creating non-cyclic IIO buffers with 1 MiS\n");
- rxbuf = iio_device_create_buffer(rx, 1024*1024, false);
- if (!rxbuf) {
- perror("Could not create RX buffer");
- shutdown();
- }
- txbuf = iio_device_create_buffer(tx, 1024*1024, false);
- if (!txbuf) {
- perror("Could not create TX buffer");
- shutdown();
- }
-
- printf("* Starting IO streaming (press CTRL+C to cancel)\n");
- while (!stop)
- {
- ssize_t nbytes_rx, nbytes_tx;
- char *p_dat, *p_end;
- ptrdiff_t p_inc;
-
- // Schedule TX buffer
- nbytes_tx = iio_buffer_push(txbuf);
- if (nbytes_tx < 0) { printf("Error pushing buf %d\n", (int) nbytes_tx); shutdown(); }
-
- // Refill RX buffer
- nbytes_rx = iio_buffer_refill(rxbuf);
- if (nbytes_rx < 0) { printf("Error refilling buf %d\n",(int) nbytes_rx); shutdown(); }
-
- // READ: Get pointers to RX buf and read IQ from RX buf port 0
- p_inc = iio_buffer_step(rxbuf);
- p_end = iio_buffer_end(rxbuf);
- for (p_dat = iio_buffer_first(rxbuf, rx0_i); p_dat < p_end; p_dat += p_inc) {
- // Example: swap I and Q
- const int16_t i = ((int16_t*)p_dat)[0]; // Real (I)
- const int16_t q = ((int16_t*)p_dat)[1]; // Imag (Q)
- ((int16_t*)p_dat)[0] = q;
- ((int16_t*)p_dat)[1] = i;
- }
-
- // WRITE: Get pointers to TX buf and write IQ to TX buf port 0
- p_inc = iio_buffer_step(txbuf);
- p_end = iio_buffer_end(txbuf);
- for (p_dat = iio_buffer_first(txbuf, tx0_i); p_dat < p_end; p_dat += p_inc) {
- // Example: fill with zeros
- // 14-bit sample needs to be MSB alligned so shift by 2
- // https://wiki.analog.com/resources/eval/user-guides/ad-fmcomms2-ebz/software/basic_iq_datafiles#binary_format
- ((int16_t*)p_dat)[0] = 0 << 2; // Real (I)
- ((int16_t*)p_dat)[1] = 0 << 2; // Imag (Q)
- }
-
- // Sample counter increment and status output
- nrx += nbytes_rx / iio_device_get_sample_size(rx);
- ntx += nbytes_tx / iio_device_get_sample_size(tx);
- printf("\tRX %8.2f MSmp, TX %8.2f MSmp\n", nrx/1e6, ntx/1e6);
- }
-
- shutdown();
-
- return 0;
-}
diff --git a/examples/dummy-iiostream.c b/examples/dummy-iiostream.c
deleted file mode 100644
index 0f74808..0000000
--- a/examples/dummy-iiostream.c
+++ /dev/null
@@ -1,374 +0,0 @@
-/*
- * libiio - Dummy IIO streaming example
- *
- * This example libiio program is meant to exercise the features of IIO present
- * in the sample dummy IIO device. For buffered access it relies on the hrtimer
- * trigger but could be modified to use the sysfs trigger. No hardware should
- * be required to run this program.
- *
- * Copyright (c) 2016, DAQRI. All rights reserved.
- * Author: Lucas Magasweran <lucas.magasweran@daqri.com>
- *
- * Based on AD9361 example:
- * Copyright (C) 2014 IABG mbH
- * Author: Michael Feilen <feilen_at_iabg.de>
- *
- * 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.
- *
- * How to setup the sample IIO dummy device and hrtimer trigger:
- *
- * 1. Check if `configfs` is already mounted
- *
- * $ mount | grep 'config'
- * configfs on /sys/kernel/config type configfs (rw,relatime)
- *
- * 1.b. Mount `configfs` if it is not already mounted
- * $ sudo mount -t configfs none /sys/kernel/config
- *
- * 2. Load modules one by one
- *
- * $ sudo modprobe industrialio
- * $ sudo modprobe industrialio-configfs
- * $ sudo modprobe industrialio-sw-device
- * $ sudo modprobe industrialio-sw-trigger
- * $ sudo modprobe iio-trig-hrtimer
- * $ sudo modprobe iio_dummy
- *
- * 3. Create trigger and dummy device under `/sys/kernel/config`
- *
- * $ sudo mkdir /sys/kernel/config/iio/triggers/hrtimer/instance1
- * $ sudo mkdir /sys/kernel/config/iio/devices/dummy/my_dummy_device
- *
- * 4. Run `iio_info` to see that all worked properly
- *
- * $ iio_info
- * Library version: 0.14 (git tag: c9909f2)
- * Compiled with backends: local xml ip
- * IIO context created with local backend.
- * Backend version: 0.14 (git tag: c9909f2)
- * Backend description string: Linux ...
- * IIO context has 1 attributes:
- * local,kernel: 4.13.0-39-generic
- * IIO context has 2 devices:
- * iio:device0: my_dummy_device
- * 10 channels found:
- * activity_walking: (input)
- * 1 channel-specific attributes found:
- * attr 0: input value: 4
- * ...
- *
- **/
-
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include <signal.h>
-#include <stdio.h>
-#include <errno.h>
-#include <getopt.h>
-
-#ifdef __APPLE__
-#include <iio/iio.h>
-#else
-#include <iio.h>
-#endif
-
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-
-static char *name = "iio_dummy_part_no";
-static char *trigger_str = "instance1";
-static int buffer_length = 1;
-static int count = -1;
-
-// libiio supports multiple methods for reading data from a buffer
-enum {
- BUFFER_POINTER,
- SAMPLE_CALLBACK,
- CHANNEL_READ_RAW,
- CHANNEL_READ,
- MAX_READ_METHOD,
-};
-static int buffer_read_method = BUFFER_POINTER;
-
-// Streaming devices
-static struct iio_device *dev;
-
-/* IIO structs required for streaming */
-static struct iio_context *ctx;
-static struct iio_buffer *rxbuf;
-static struct iio_channel **channels;
-static int channel_count;
-
-static bool stop;
-static bool has_repeat;
-
-/* cleanup and exit */
-static void shutdown()
-{
- if (channels) { free(channels); }
-
- printf("* Destroying buffers\n");
- if (rxbuf) { iio_buffer_destroy(rxbuf); }
-
- printf("* Disassociate trigger\n");
- if (dev) { iio_device_set_trigger(dev, NULL); }
-
- printf("* Destroying context\n");
- if (ctx) { iio_context_destroy(ctx); }
- exit(0);
-}
-
-static void handle_sig(int sig)
-{
- printf("Waiting for process to finish...\n");
- stop = true;
-}
-
-static ssize_t sample_cb(const struct iio_channel *chn, void *src, size_t bytes, void *d)
-{
- const struct iio_data_format *fmt = iio_channel_get_data_format(chn);
- unsigned int repeat = has_repeat ? fmt->repeat : 1;
-
- printf("%s ", iio_channel_get_id(chn));
- for (int j = 0; j < repeat; ++j) {
- if (bytes == sizeof(int16_t))
- printf("%i ", ((int16_t *)src)[j]);
- else if (bytes == sizeof(int64_t))
- printf("%ld ", ((int64_t *)src)[j]);
- }
-
- return bytes * repeat;
-}
-
-static void usage(int argc, char *argv[])
-{
- printf("Usage: %s [OPTION]\n", argv[0]);
- printf(" -d\tdevice name (default \"iio_dummy_part_no\")\n");
- printf(" -t\ttrigger name (default \"instance1\")\n");
- printf(" -b\tbuffer length (default 1)\n");
- printf(" -r\tread method (default 0 pointer, 1 callback, 2 read, 3 read raw)\n");
- printf(" -c\tread count (default no limit)\n");
-}
-
-static void parse_options(int argc, char *argv[])
-{
- int c;
-
- while ((c = getopt(argc, argv, "d:t:b:r:c:h")) != -1) {
- switch (c)
- {
- case 'd':
- name = optarg;
- break;
- case 't':
- trigger_str = optarg;
- break;
- case 'b':
- buffer_length = atoi(optarg);
- break;
- case 'r':
- if (atoi(optarg) >= 0 && atoi(optarg) < MAX_READ_METHOD) {
- buffer_read_method = atoi(optarg);
- } else {
- usage(argc, argv);
- exit(1);
- }
- break;
- case 'c':
- if (atoi(optarg) > 0) {
- count = atoi(optarg);
- } else {
- usage(argc, argv);
- exit(1);
- }
- break;
- case 'h':
- default:
- usage(argc, argv);
- exit(1);
- }
- }
-}
-
-/* simple configuration and streaming */
-int main (int argc, char **argv)
-{
- // Hardware trigger
- struct iio_device *trigger;
-
- parse_options(argc, argv);
-
- // Listen to ctrl+c and assert
- signal(SIGINT, handle_sig);
-
- unsigned int major, minor;
- char git_tag[8];
- iio_library_get_version(&major, &minor, git_tag);
- printf("Library version: %u.%u (git tag: %s)\n", major, minor, git_tag);
-
- /* check for struct iio_data_format.repeat support */
- has_repeat = major >= 0 && minor >= 8 ? true : false;
-
- printf("* Acquiring IIO context\n");
- assert((ctx = iio_create_default_context()) && "No context");
- assert(iio_context_get_devices_count(ctx) > 0 && "No devices");
-
- printf("* Acquiring device %s\n", name);
- dev = iio_context_find_device(ctx, name);
- if (!dev) {
- perror("No device found");
- shutdown();
- }
-
- printf("* Initializing IIO streaming channels:\n");
- for (int i = 0; i < iio_device_get_channels_count(dev); ++i) {
- struct iio_channel *chn = iio_device_get_channel(dev, i);
- if (iio_channel_is_scan_element(chn)) {
- printf("%s\n", iio_channel_get_id(chn));
- channel_count++;
- }
- }
- if (channel_count == 0) {
- printf("No scan elements found (make sure the driver built with 'CONFIG_IIO_SIMPLE_DUMMY_BUFFER=y')\n");
- shutdown();
- }
- channels = calloc(channel_count, sizeof *channels);
- if (!channels) {
- perror("Channel array allocation failed");
- shutdown();
- }
- for (int i = 0; i < channel_count; ++i) {
- struct iio_channel *chn = iio_device_get_channel(dev, i);
- if (iio_channel_is_scan_element(chn))
- channels[i] = chn;
- }
-
- printf("* Acquiring trigger %s\n", trigger_str);
- trigger = iio_context_find_device(ctx, trigger_str);
- if (!trigger || !iio_device_is_trigger(trigger)) {
- perror("No trigger found (try setting up the iio-trig-hrtimer module)");
- shutdown();
- }
-
- printf("* Enabling IIO streaming channels for buffered capture\n");
- for (int i = 0; i < channel_count; ++i)
- iio_channel_enable(channels[i]);
-
- printf("* Enabling IIO buffer trigger\n");
- if (iio_device_set_trigger(dev, trigger)) {
- perror("Could not set trigger\n");
- shutdown();
- }
-
- printf("* Creating non-cyclic IIO buffers with %d samples\n", buffer_length);
- rxbuf = iio_device_create_buffer(dev, buffer_length, false);
- if (!rxbuf) {
- perror("Could not create buffer");
- shutdown();
- }
-
- printf("* Starting IO streaming (press CTRL+C to cancel)\n");
- bool has_ts = strcmp(iio_channel_get_id(channels[channel_count-1]), "timestamp") == 0;
- int64_t last_ts = 0;
- while (!stop)
- {
- ssize_t nbytes_rx;
- void *p_dat, *p_end;
- ptrdiff_t p_inc;
- int64_t now_ts;
-
- // Refill RX buffer
- nbytes_rx = iio_buffer_refill(rxbuf);
- if (nbytes_rx < 0) {
- printf("Error refilling buf: %d\n", (int)nbytes_rx);
- shutdown();
- }
-
- p_inc = iio_buffer_step(rxbuf);
- p_end = iio_buffer_end(rxbuf);
-
- // Print timestamp delta in ms
- if (has_ts)
- for (p_dat = iio_buffer_first(rxbuf, channels[channel_count-1]); p_dat < p_end; p_dat += p_inc) {
- now_ts = (((int64_t *)p_dat)[0]);
- printf("[%04ld] ", last_ts > 0 ? (now_ts - last_ts)/1000/1000 : 0);
- last_ts = now_ts;
- }
-
- // Print each captured sample
- switch (buffer_read_method)
- {
- case BUFFER_POINTER:
- for (int i = 0; i < channel_count; ++i) {
- const struct iio_data_format *fmt = iio_channel_get_data_format(channels[i]);
- unsigned int repeat = has_repeat ? fmt->repeat : 1;
-
- printf("%s ", iio_channel_get_id(channels[i]));
- for (p_dat = iio_buffer_first(rxbuf, channels[i]); p_dat < p_end; p_dat += p_inc) {
- for (int j = 0; j < repeat; ++j) {
- if (fmt->length/8 == sizeof(int16_t))
- printf("%i ", ((int16_t *)p_dat)[j]);
- else if (fmt->length/8 == sizeof(int64_t))
- printf("%ld ", ((int64_t *)p_dat)[j]);
- }
- }
- }
- printf("\n");
- break;
-
- case SAMPLE_CALLBACK:
- iio_buffer_foreach_sample(rxbuf, sample_cb, NULL);
- printf("\n");
- break;
-
- case CHANNEL_READ_RAW:
- case CHANNEL_READ:
- for (int i = 0; i < channel_count; ++i) {
- uint8_t *buf;
- size_t bytes;
- const struct iio_data_format *fmt = iio_channel_get_data_format(channels[i]);
- unsigned int repeat = has_repeat ? fmt->repeat : 1;
- size_t sample_size = fmt->length / 8 * repeat;
-
- buf = malloc(sample_size * buffer_length);
-
- if (buffer_read_method == CHANNEL_READ_RAW)
- bytes = iio_channel_read_raw(channels[i], rxbuf, buf, sample_size * buffer_length);
- else
- bytes = iio_channel_read(channels[i], rxbuf, buf, sample_size * buffer_length);
-
- printf("%s ", iio_channel_get_id(channels[i]));
- for (int sample = 0; sample < bytes / sample_size; ++sample) {
- for (int j = 0; j < repeat; ++j) {
- if (fmt->length / 8 == sizeof(int16_t))
- printf("%i ", ((int16_t *)buf)[sample+j]);
- else if (fmt->length / 8 == sizeof(int64_t))
- printf("%li ", ((int64_t *)buf)[sample+j]);
- }
- }
-
- free(buf);
- }
- printf("\n");
- break;
- }
-
- if (count != -1 && --count == 0)
- break;
- }
-
- shutdown();
-
- return 0;
-}
-
diff --git a/examples/iio-monitor.c b/examples/iio-monitor.c
deleted file mode 100644
index b508049..0000000
--- a/examples/iio-monitor.c
+++ /dev/null
@@ -1,359 +0,0 @@
-/*
- * 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.
- *
- * */
-
-#define _BSD_SOURCE
-#define _GNU_SOURCE
-#define _DEFAULT_SOURCE
-
-#include <cdk/cdk.h>
-#include <locale.h>
-#include <pthread.h>
-#include <stdbool.h>
-#include <unistd.h>
-#include <string.h>
-
-#ifdef __APPLE__
-#include <iio/iio.h>
-#else
-#include <iio.h>
-#endif
-
-#define ARRAY_SIZE(x) (sizeof(x) ? sizeof(x) / sizeof((x)[0]) : 0)
-
-#define RED 020
-#define YELLOW 040
-#define BLUE 050
-
-static int selected = -1;
-
-static WINDOW *win, *left, *right;
-static bool stop;
-
-static bool channel_has_attr(struct iio_channel *chn, const char *attr)
-{
- unsigned int i, nb = iio_channel_get_attrs_count(chn);
- for (i = 0; i < nb; i++)
- if (!strcmp(attr, iio_channel_get_attr(chn, i)))
- return true;
- return false;
-}
-
-static bool is_valid_channel(struct iio_channel *chn)
-{
- return !iio_channel_is_output(chn) &&
- (channel_has_attr(chn, "raw") ||
- channel_has_attr(chn, "input"));
-}
-
-static double get_channel_value(struct iio_channel *chn)
-{
- char *old_locale;
- char buf[1024];
- double val;
-
- old_locale = strdup(setlocale(LC_NUMERIC, NULL));
- setlocale(LC_NUMERIC, "C");
-
- if (channel_has_attr(chn, "input")) {
- iio_channel_attr_read(chn, "input", buf, sizeof(buf));
- val = strtod(buf, NULL);
- } else {
- iio_channel_attr_read(chn, "raw", buf, sizeof(buf));
- val = strtod(buf, NULL);
-
- if (channel_has_attr(chn, "offset")) {
- iio_channel_attr_read(chn, "offset", buf, sizeof(buf));
- val += strtod(buf, NULL);
- }
-
- if (channel_has_attr(chn, "scale")) {
- iio_channel_attr_read(chn, "scale", buf, sizeof(buf));
- val *= strtod(buf, NULL);
- }
- }
-
- setlocale(LC_NUMERIC, old_locale);
- free(old_locale);
-
- return val / 1000.0;
-}
-
-static struct {
- const char *id;
- const char *unit;
-} map[] = {
- { "current", "A" },
- { "power", "W" },
- { "temp", "°C" },
- { "voltage", "V" },
- { 0, },
-};
-
-static const char *id_to_unit(const char *id)
-{
- unsigned int i;
-
- for (i = 0; map[i].id; i++) {
- if (!strncmp(id, map[i].id, strlen(map[i].id)))
- return map[i].unit;
- }
-
- return "";
-}
-
-static void * read_thd(void *d)
-{
- struct iio_context *ctx = d;
-
- while (!stop) {
- struct iio_device *dev;
- const char *name;
- int row, col, len, align, line = 2;
- unsigned int i, nb_channels, nb = 0;
- char buf[1024];
- chtype *str;
- (void) row; /* Prevent warning */
-
- usleep(100000);
-
- if (selected < 0)
- continue;
-
- dev = iio_context_get_device(ctx, selected);
-
- name = iio_device_get_name(dev);
- if (!name)
- name = iio_device_get_id(dev);
-
- getmaxyx(right, row, col);
-
- werase(right);
-
- sprintf(buf, "</B>Device selected: </%u>%s<!%u><!B>",
- RED, name, RED);
- str = char2Chtype(buf, &len, &align);
- writeChtype(right, 2, line, str, HORIZONTAL, 0, len);
- freeChtype(str);
- line += 2;
-
- nb_channels = iio_device_get_channels_count(dev);
- for (i = 0; i < nb_channels; i++) {
- const char *id;
- const char *unit;
- struct iio_channel *chn =
- iio_device_get_channel(dev, i);
- if (!is_valid_channel(chn))
- continue;
-
- nb++;
- name = iio_channel_get_name(chn);
- id = iio_channel_get_id(chn);
- if (!name)
- name = id;
- unit = id_to_unit(id);
-
- sprintf(buf, "</%u></B>%s<!B><!%u>",
- BLUE, name, BLUE);
- str = char2Chtype(buf, &len, &align);
- writeChtype(right, 2, line, str,
- HORIZONTAL, 0, len);
- freeChtype(str);
-
- sprintf(buf, "</%u></B>%.3lf %s<!B><!%u>",
- YELLOW, get_channel_value(chn), unit,
- YELLOW);
- str = char2Chtype(buf, &len, &align);
- writeChtype(right, col / 2, line++,
- str, HORIZONTAL, 0, len);
- freeChtype(str);
- }
-
- if (nb == 0) {
- char msg[] = "No valid input channels found.";
- writeChar(right, 2, line++, msg,
- HORIZONTAL, 0, sizeof(msg) - 1);
- }
-
- boxWindow(right, 0);
- }
- return NULL;
-}
-
-static struct iio_context *show_contexts_screen(void)
-{
- struct iio_context *ctx = NULL;
- struct iio_scan_context *scan_ctx;
- struct iio_context_info **info;
- unsigned int num_contexts;
- CDKSCREEN *screen;
- CDKSCROLL *list;
- const char *uri;
- unsigned int i;
- bool free_uri;
- char **items;
- int ret;
-
- scan_ctx = iio_create_scan_context(NULL, 0);
- if (!scan_ctx)
- return NULL;
-
- screen = initCDKScreen(win);
-
- do {
- ret = iio_scan_context_get_info_list(scan_ctx, &info);
- if (ret < 0)
- break;
-
- num_contexts = ret;
-
- items = calloc(num_contexts + 1, sizeof(*items));
-
- for (i = 0; i < num_contexts; i++) {
- asprintf(&items[i], "</%d>%s<!%d> </%d>[%s]<!%d>", YELLOW,
- iio_context_info_get_description(info[i]),
- YELLOW, BLUE,
- iio_context_info_get_uri(info[i]),
- BLUE);
- }
-
- items[i] = "Enter location";
-
- list = newCDKScroll(screen, LEFT, TOP, RIGHT, 0, 0,
- "\n Select a IIO context to use:\n",
- items, num_contexts + 1, TRUE,
- A_BOLD | A_REVERSE, TRUE, FALSE);
-
- drawCDKScroll(list, TRUE);
-
- ret = activateCDKScroll(list, NULL);
- if (ret < num_contexts) {
- uri = iio_context_info_get_uri(info[ret]);
- free_uri = FALSE;
- } else if (ret == num_contexts) {
- uri = getString(screen,
- "Please enter the location of the server",
- "Location: ", "ip:localhost");
- free_uri = TRUE;
- } else {
- uri = NULL;
- }
-
- if (uri) {
- ctx = iio_create_context_from_uri(uri);
- if (ctx == NULL) {
- char *msg[] = { "</16>Failed to create IIO context.<!16>" };
- popupLabel(screen, msg, 1);
- }
-
- if (free_uri)
- freeChar((char *)uri);
- }
-
- destroyCDKScroll(list);
- iio_context_info_list_free(info);
- for (i = 0; i < num_contexts; i++)
- free(items[i]);
- free(items);
-
- } while (!ctx && ret >= 0);
-
- destroyCDKScreen(screen);
-
- iio_scan_context_destroy(scan_ctx);
-
- return ctx;
-}
-
-static void show_main_screen(struct iio_context *ctx)
-{
- unsigned int i, nb_devices;
- CDKSCREEN *screen;
- char **dev_names;
- CDKSCROLL *list;
- pthread_t thd;
-
- stop = FALSE;
- screen = initCDKScreen(left);
-
- pthread_create(&thd, NULL, read_thd, ctx);
-
- nb_devices = iio_context_get_devices_count(ctx);
- dev_names = malloc(nb_devices * sizeof(char *));
-
- for (i = 0; i < nb_devices; i++) {
- char buf[1024];
- struct iio_device *dev = iio_context_get_device(ctx, i);
- const char *name = iio_device_get_name(dev);
- if (!name)
- name = iio_device_get_id(dev);
- sprintf(buf, "</B> %s", name);
- dev_names[i] = strdup(buf);
- }
-
- boxWindow(right, 0);
- list = newCDKScroll(screen, LEFT, TOP, RIGHT, 0, 0,
- "\n List of available IIO devices:\n",
- dev_names, nb_devices, FALSE,
- A_BOLD | A_REVERSE, TRUE, FALSE);
-
- drawCDKScroll(list, TRUE);
-
- while (!stop) {
- int ret = activateCDKScroll(list, NULL);
- stop = ret < 0;
- selected = ret;
- usleep(100000);
- }
-
- pthread_join(thd, NULL);
-
- destroyCDKScroll(list);
- for (i = 0; i < nb_devices; i++)
- free(dev_names[i]);
- free(dev_names);
- destroyCDKScreen(screen);
-}
-
-int main(void)
-{
- struct iio_context *ctx;
- int row, col;
-
- win = initscr();
- noecho();
- keypad(win, TRUE);
- getmaxyx(win, row, col);
- initCDKColor();
-
- left = newwin(row, col / 2, 0, 0);
- right = newwin(row, col / 2, 0, col / 2);
-
- while (TRUE) {
- ctx = show_contexts_screen();
- if (!ctx)
- break;
-
- show_main_screen(ctx);
- iio_context_destroy(ctx);
- }
-
- endCDK();
- delwin(left);
- delwin(right);
- return 0;
-}
diff --git a/iio-config.h b/iio-config.h
deleted file mode 100644
index a689f85..0000000
--- a/iio-config.h
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifndef IIO_CONFIG_H
-#define IIO_CONFIG_H
-
-#define LIBIIO_VERSION_MAJOR 0
-#define LIBIIO_VERSION_MINOR 18
-#define LIBIIO_VERSION_GIT "4e22517"
-
-#define LOG_LEVEL Info_L
-
-#define WITH_LOCAL_BACKEND
-#undef WITH_XML_BACKEND
-#undef WITH_NETWORK_BACKEND
-#undef WITH_USB_BACKEND
-#undef WITH_SERIAL_BACKEND
-#undef WITH_MATLAB_BINDINGS_API
-
-#undef WITH_NETWORK_GET_BUFFER
-#undef WITH_NETWORK_EVENTFD
-#undef WITH_IIOD_USBD
-#undef WITH_LOCAL_CONFIG
-#define HAS_PIPE2
-#define HAS_STRDUP
-#define HAS_STRERROR_R
-#define HAS_NEWLOCALE
-#define HAS_PTHREAD_SETNAME_NP
-#undef HAVE_IPV6
-#undef HAVE_AVAHI
-#undef NO_THREADS
-#undef HAS_LIBUSB_GETVERSION
-
-#endif /* IIO_CONFIG_H */
diff --git a/iio-config.h.cmakein b/iio-config.h.cmakein
deleted file mode 100644
index 580e78a..0000000
--- a/iio-config.h.cmakein
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifndef IIO_CONFIG_H
-#define IIO_CONFIG_H
-
-#define LIBIIO_VERSION_MAJOR @LIBIIO_VERSION_MAJOR@
-#define LIBIIO_VERSION_MINOR @LIBIIO_VERSION_MINOR@
-#define LIBIIO_VERSION_GIT "@LIBIIO_VERSION_GIT@"
-
-#define LOG_LEVEL @LOG_LEVEL@_L
-
-#cmakedefine WITH_LOCAL_BACKEND
-#cmakedefine WITH_XML_BACKEND
-#cmakedefine WITH_NETWORK_BACKEND
-#cmakedefine WITH_USB_BACKEND
-#cmakedefine WITH_SERIAL_BACKEND
-#cmakedefine WITH_MATLAB_BINDINGS_API
-
-#cmakedefine WITH_NETWORK_GET_BUFFER
-#cmakedefine WITH_NETWORK_EVENTFD
-#cmakedefine WITH_IIOD_USBD
-#cmakedefine WITH_LOCAL_CONFIG
-#cmakedefine HAS_PIPE2
-#cmakedefine HAS_STRDUP
-#cmakedefine HAS_STRERROR_R
-#cmakedefine HAS_NEWLOCALE
-#cmakedefine HAS_PTHREAD_SETNAME_NP
-#cmakedefine HAVE_IPV6
-#cmakedefine HAVE_AVAHI
-#cmakedefine NO_THREADS
-#cmakedefine HAS_LIBUSB_GETVERSION
-
-#endif /* IIO_CONFIG_H */
diff --git a/iio-lock.h b/iio-lock.h
deleted file mode 100644
index 612a925..0000000
--- a/iio-lock.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2015 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.
- *
- */
-
-#ifndef _IIO_LOCK_H
-#define _IIO_LOCK_H
-
-struct iio_mutex;
-
-struct iio_mutex * iio_mutex_create(void);
-void iio_mutex_destroy(struct iio_mutex *lock);
-
-void iio_mutex_lock(struct iio_mutex *lock);
-void iio_mutex_unlock(struct iio_mutex *lock);
-
-#endif /* _IIO_LOCK_H */
diff --git a/iio-private.h b/iio-private.h
deleted file mode 100644
index 685c290..0000000
--- a/iio-private.h
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * 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.
- *
- * */
-
-#ifndef __IIO_PRIVATE_H__
-#define __IIO_PRIVATE_H__
-
-/* Include public interface */
-#include "iio.h"
-
-#include "iio-config.h"
-
-#include <stdbool.h>
-
-#ifdef _MSC_BUILD
-#define inline __inline
-#define iio_snprintf sprintf_s
-#else
-#define iio_snprintf snprintf
-#endif
-
-#ifdef _WIN32
-# ifdef LIBIIO_EXPORTS
-# define __api __declspec(dllexport)
-# else
-# define __api __declspec(dllimport)
-# endif
-#elif __GNUC__ >= 4
-# define __api __attribute__((visibility ("default")))
-#else
-# define __api
-#endif
-
-#ifdef WITH_MATLAB_BINDINGS_API
-#include "bindings/matlab/iio-wrapper.h"
-#endif
-
-#define ARRAY_SIZE(x) (sizeof(x) ? sizeof(x) / sizeof((x)[0]) : 0)
-#define BIT(x) (1 << (x))
-#define BIT_MASK(bit) BIT((bit) % 32)
-#define BIT_WORD(bit) ((bit) / 32)
-#define TEST_BIT(addr, bit) (!!(*(((uint32_t *) addr) + BIT_WORD(bit)) \
- & BIT_MASK(bit)))
-#define SET_BIT(addr, bit) \
- *(((uint32_t *) addr) + BIT_WORD(bit)) |= BIT_MASK(bit)
-#define CLEAR_BIT(addr, bit) \
- *(((uint32_t *) addr) + BIT_WORD(bit)) &= ~BIT_MASK(bit)
-
-
-/* ntohl/htonl are a nightmare to use in cross-platform applications,
- * since they are defined in different headers on different platforms.
- * iio_be32toh/iio_htobe32 are just clones of ntohl/htonl. */
-static inline uint32_t iio_be32toh(uint32_t word)
-{
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-#ifdef __GNUC__
- return __builtin_bswap32(word);
-#else
- return ((word & 0xff) << 24) | ((word & 0xff00) << 8) |
- ((word >> 8) & 0xff00) | ((word >> 24) & 0xff);
-#endif
-#else
- return word;
-#endif
-}
-
-static inline uint32_t iio_htobe32(uint32_t word)
-{
- return iio_be32toh(word);
-}
-
-/* Allocate zeroed out memory */
-static inline void *zalloc(size_t size)
-{
- return calloc(1, size);
-}
-
-enum iio_attr_type {
- IIO_ATTR_TYPE_DEVICE = 0,
- IIO_ATTR_TYPE_DEBUG,
- IIO_ATTR_TYPE_BUFFER,
-};
-
-struct iio_backend_ops {
- struct iio_context * (*clone)(const struct iio_context *ctx);
- ssize_t (*read)(const struct iio_device *dev, void *dst, size_t len,
- uint32_t *mask, size_t words);
- ssize_t (*write)(const struct iio_device *dev,
- const void *src, size_t len);
- int (*open)(const struct iio_device *dev,
- size_t samples_count, bool cyclic);
- int (*close)(const struct iio_device *dev);
- int (*get_fd)(const struct iio_device *dev);
- int (*set_blocking_mode)(const struct iio_device *dev, bool blocking);
-
- void (*cancel)(const struct iio_device *dev);
-
- int (*set_kernel_buffers_count)(const struct iio_device *dev,
- unsigned int nb_blocks);
- ssize_t (*get_buffer)(const struct iio_device *dev,
- void **addr_ptr, size_t bytes_used,
- uint32_t *mask, size_t words);
-
- ssize_t (*read_device_attr)(const struct iio_device *dev,
- const char *attr, char *dst, size_t len, enum iio_attr_type);
- ssize_t (*write_device_attr)(const struct iio_device *dev,
- const char *attr, const char *src,
- size_t len, enum iio_attr_type);
- ssize_t (*read_channel_attr)(const struct iio_channel *chn,
- const char *attr, char *dst, size_t len);
- ssize_t (*write_channel_attr)(const struct iio_channel *chn,
- const char *attr, const char *src, size_t len);
-
- int (*get_trigger)(const struct iio_device *dev,
- const struct iio_device **trigger);
- int (*set_trigger)(const struct iio_device *dev,
- const struct iio_device *trigger);
-
- void (*shutdown)(struct iio_context *ctx);
-
- int (*get_version)(const struct iio_context *ctx, unsigned int *major,
- unsigned int *minor, char git_tag[8]);
-
- int (*set_timeout)(struct iio_context *ctx, unsigned int timeout);
-};
-
-/*
- * If these structures are updated, the qsort functions defined in sort.c
- * may need to be updated.
- */
-
-struct iio_context_pdata;
-struct iio_device_pdata;
-struct iio_channel_pdata;
-struct iio_scan_backend_context;
-
-struct iio_channel_attr {
- char *name;
- char *filename;
-};
-
-struct iio_context {
- struct iio_context_pdata *pdata;
- const struct iio_backend_ops *ops;
- const char *name;
- char *description;
-
- struct iio_device **devices;
- unsigned int nb_devices;
-
- char *xml;
-
- char **attrs;
- char **values;
- unsigned int nb_attrs;
-};
-
-struct iio_channel {
- struct iio_device *dev;
- struct iio_channel_pdata *pdata;
- void *userdata;
-
- bool is_output;
- bool is_scan_element;
- struct iio_data_format format;
- char *name, *id;
- long index;
- enum iio_modifier modifier;
- enum iio_chan_type type;
-
- struct iio_channel_attr *attrs;
- unsigned int nb_attrs;
-
- unsigned int number;
-};
-
-struct iio_device {
- const struct iio_context *ctx;
- struct iio_device_pdata *pdata;
- void *userdata;
-
- char *name, *id;
-
- char **attrs;
- unsigned int nb_attrs;
-
- char **buffer_attrs;
- unsigned int nb_buffer_attrs;
-
- char **debug_attrs;
- unsigned int nb_debug_attrs;
-
- struct iio_channel **channels;
- unsigned int nb_channels;
-
- uint32_t *mask;
- size_t words;
-};
-
-struct iio_buffer {
- const struct iio_device *dev;
- void *buffer, *userdata;
- size_t length, data_length;
-
- uint32_t *mask;
- unsigned int dev_sample_size;
- unsigned int sample_size;
- bool is_output, dev_is_high_speed;
-};
-
-struct iio_context_info {
- char *description;
- char *uri;
-};
-
-struct iio_scan_result {
- size_t size;
- struct iio_context_info **info;
-};
-
-struct iio_context_info ** iio_scan_result_add(
- struct iio_scan_result *scan_result, size_t num);
-
-void free_channel(struct iio_channel *chn);
-void free_device(struct iio_device *dev);
-
-char *iio_channel_get_xml(const struct iio_channel *chn, size_t *len);
-char *iio_device_get_xml(const struct iio_device *dev, size_t *len);
-
-char *iio_context_create_xml(const struct iio_context *ctx);
-int iio_context_init(struct iio_context *ctx);
-
-bool iio_device_is_tx(const struct iio_device *dev);
-int iio_device_open(const struct iio_device *dev,
- size_t samples_count, bool cyclic);
-int iio_device_close(const struct iio_device *dev);
-int iio_device_set_blocking_mode(const struct iio_device *dev, bool blocking);
-ssize_t iio_device_read_raw(const struct iio_device *dev,
- void *dst, size_t len, uint32_t *mask, size_t words);
-ssize_t iio_device_write_raw(const struct iio_device *dev,
- const void *src, size_t len);
-int iio_device_get_poll_fd(const struct iio_device *dev);
-
-int read_double(const char *str, double *val);
-int write_double(char *buf, size_t len, double val);
-
-struct iio_context * local_create_context(void);
-struct iio_context * network_create_context(const char *hostname);
-struct iio_context * xml_create_context_mem(const char *xml, size_t len);
-struct iio_context * xml_create_context(const char *xml_file);
-struct iio_context * usb_create_context(unsigned int bus, unsigned int address,
- unsigned int interface);
-struct iio_context * usb_create_context_from_uri(const char *uri);
-struct iio_context * serial_create_context_from_uri(const char *uri);
-
-int local_context_scan(struct iio_scan_result *scan_result);
-
-struct iio_scan_backend_context * usb_context_scan_init(void);
-void usb_context_scan_free(struct iio_scan_backend_context *ctx);
-
-int usb_context_scan(struct iio_scan_backend_context *ctx,
- struct iio_scan_result *scan_result);
-
-/* This function is not part of the API, but is used by the IIO daemon */
-__api ssize_t iio_device_get_sample_size_mask(const struct iio_device *dev,
- const uint32_t *mask, size_t words);
-
-void iio_channel_init_finalize(struct iio_channel *chn);
-unsigned int find_channel_modifier(const char *s, size_t *len_p);
-
-char *iio_strdup(const char *str);
-
-int iio_context_add_attr(struct iio_context *ctx,
- const char *key, const char *value);
-
-#undef __api
-
-#endif /* __IIO_PRIVATE_H__ */
diff --git a/iio.h b/iio.h
deleted file mode 100644
index b9d78a0..0000000
--- a/iio.h
+++ /dev/null
@@ -1,1777 +0,0 @@
-/*
- * 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 <limits.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <stddef.h>
-
-#if (defined(_WIN32) || defined(__MBED__))
-#ifndef _SSIZE_T_DEFINED
-typedef ptrdiff_t ssize_t;
-#define _SSIZE_T_DEFINED
-#endif
-#else
-#include <sys/types.h>
-#endif
-
-#if defined(_MSC_VER) && (_MSC_VER < 1800) && !defined(__BOOL_DEFINED)
-#undef bool
-#undef false
-#undef true
-#define bool char
-#define false 0
-#define true 1
-#else
-#include <stdbool.h>
-#endif
-
-#if defined(__GNUC__) && !defined(MATLAB_MEX_FILE) && !defined(MATLAB_LOADLIBRARY)
-#ifndef __cnst
-#define __cnst __attribute__((const))
-#endif
-#ifndef __pure
-#define __pure __attribute__((pure))
-#endif
-#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
-#elif __GNUC__ >= 4 && !defined(MATLAB_MEX_FILE) && !defined(MATLAB_LOADLIBRARY)
-# define __api __attribute__((visibility ("default")))
-#else
-# define __api
-#endif
-
-struct iio_context;
-struct iio_device;
-struct iio_channel;
-struct iio_buffer;
-
-struct iio_context_info;
-struct iio_scan_context;
-
-/**
- * @enum iio_chan_type
- * @brief IIO channel type
- *
- * A IIO channel has a type specifying the type of data associated with the
- * channel.
- */
-enum iio_chan_type {
- IIO_VOLTAGE,
- IIO_CURRENT,
- IIO_POWER,
- IIO_ACCEL,
- IIO_ANGL_VEL,
- IIO_MAGN,
- IIO_LIGHT,
- IIO_INTENSITY,
- IIO_PROXIMITY,
- IIO_TEMP,
- IIO_INCLI,
- IIO_ROT,
- IIO_ANGL,
- IIO_TIMESTAMP,
- IIO_CAPACITANCE,
- IIO_ALTVOLTAGE,
- IIO_CCT,
- IIO_PRESSURE,
- IIO_HUMIDITYRELATIVE,
- IIO_ACTIVITY,
- IIO_STEPS,
- IIO_ENERGY,
- IIO_DISTANCE,
- IIO_VELOCITY,
- IIO_CONCENTRATION,
- IIO_RESISTANCE,
- IIO_PH,
- IIO_UVINDEX,
- IIO_ELECTRICALCONDUCTIVITY,
- IIO_COUNT,
- IIO_INDEX,
- IIO_GRAVITY,
- IIO_CHAN_TYPE_UNKNOWN = INT_MAX
-};
-
-/**
- * @enum iio_modifier
- * @brief IIO channel modifier
- *
- * In a addition to a type a IIO channel can optionally have a channel modifier
- * further specifying the data type of of the channel.
- */
-enum iio_modifier {
- IIO_NO_MOD,
- IIO_MOD_X,
- IIO_MOD_Y,
- IIO_MOD_Z,
- IIO_MOD_X_AND_Y,
- IIO_MOD_X_AND_Z,
- IIO_MOD_Y_AND_Z,
- IIO_MOD_X_AND_Y_AND_Z,
- IIO_MOD_X_OR_Y,
- IIO_MOD_X_OR_Z,
- IIO_MOD_Y_OR_Z,
- IIO_MOD_X_OR_Y_OR_Z,
- IIO_MOD_LIGHT_BOTH,
- IIO_MOD_LIGHT_IR,
- IIO_MOD_ROOT_SUM_SQUARED_X_Y,
- IIO_MOD_SUM_SQUARED_X_Y_Z,
- IIO_MOD_LIGHT_CLEAR,
- IIO_MOD_LIGHT_RED,
- IIO_MOD_LIGHT_GREEN,
- IIO_MOD_LIGHT_BLUE,
- IIO_MOD_QUATERNION,
- IIO_MOD_TEMP_AMBIENT,
- IIO_MOD_TEMP_OBJECT,
- IIO_MOD_NORTH_MAGN,
- IIO_MOD_NORTH_TRUE,
- IIO_MOD_NORTH_MAGN_TILT_COMP,
- IIO_MOD_NORTH_TRUE_TILT_COMP,
- IIO_MOD_RUNNING,
- IIO_MOD_JOGGING,
- IIO_MOD_WALKING,
- IIO_MOD_STILL,
- IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z,
- IIO_MOD_I,
- IIO_MOD_Q,
- IIO_MOD_CO2,
- IIO_MOD_VOC,
- IIO_MOD_LIGHT_UV,
-};
-
-/* ---------------------------------------------------------------------------*/
-/* ------------------------- Scan functions ----------------------------------*/
-/** @defgroup Scan Functions for scanning available contexts
- * @{
- * @struct iio_scan_context
- * @brief The scanning context
- *
- * @struct iio_context_info
- * @brief The information related to a discovered context
- */
-
-
-/** @brief Create a scan context
- * @param backend A NULL-terminated string containing the backend to use for
- * scanning. If NULL, all the available backends are used.
- * @param flags Unused for now. Set to 0.
- * @return on success, a pointer to a iio_scan_context structure
- * @return On failure, NULL is returned and errno is set appropriately */
-__api struct iio_scan_context * iio_create_scan_context(
- const char *backend, unsigned int flags);
-
-
-/** @brief Destroy the given scan context
- * @param ctx A pointer to an iio_scan_context structure
- *
- * <b>NOTE:</b> After that function, the iio_scan_context pointer shall be invalid. */
-__api void iio_scan_context_destroy(struct iio_scan_context *ctx);
-
-
-/** @brief Enumerate available contexts
- * @param ctx A pointer to an iio_scan_context structure
- * @param info A pointer to a 'const struct iio_context_info **' typed variable.
- * The pointed variable will be initialized on success.
- * @returns On success, the number of contexts found.
- * @returns On failure, a negative error number.
- */
-__api ssize_t iio_scan_context_get_info_list(struct iio_scan_context *ctx,
- struct iio_context_info ***info);
-
-
-/** @brief Free a context info list
- * @param info A pointer to a 'const struct iio_context_info *' typed variable
- */
-__api void iio_context_info_list_free(struct iio_context_info **info);
-
-
-/** @brief Get a description of a discovered context
- * @param info A pointer to an iio_context_info structure
- * @return A pointer to a static NULL-terminated string
- */
-__api __pure const char * iio_context_info_get_description(
- const struct iio_context_info *info);
-
-
-/** @brief Get the URI of a discovered context
- * @param info A pointer to an iio_context_info structure
- * @return A pointer to a static NULL-terminated string
- */
-__api __pure const char * iio_context_info_get_uri(
- const struct iio_context_info *info);
-
-
-/** @} *//* ------------------------------------------------------------------*/
-/* ------------------------- 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]);
-
-
-/** @brief Get a string description of an error code
- * @param err The error code
- * @param dst A pointer to the memory area where the NULL-terminated string
- * corresponding to the error message will be stored
- * @param len The available length of the memory area, in bytes */
-__api void iio_strerror(int err, char *dst, size_t len);
-
-
-/** @brief Check if the specified backend is available
- * @param backend The name of the backend to query
- * @return True if the backend is available, false otherwise
- *
- * Introduced in version 0.9. */
-__api __cnst bool iio_has_backend(const char *backend);
-
-
-/** @brief Get the number of available backends
- * @return The number of available backends
- *
- * Introduced in version 0.9. */
-__api __cnst unsigned int iio_get_backends_count(void);
-
-
-/** @brief Retrieve the name of a given backend
- * @param index The index corresponding to the attribute
- * @return On success, a pointer to a static NULL-terminated string
- * @return If the index is invalid, NULL is returned
- *
- * Introduced in version 0.9. */
-__api __cnst const char * iio_get_backend(unsigned int index);
-
-
-/** @} *//* ------------------------------------------------------------------*/
-/* ------------------------- 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 Create a context from a URI description
- * @param uri A URI describing the context location
- * @return On success, a pointer to a iio_context structure
- * @return On failure, NULL is returned and errno is set appropriately */
-__api struct iio_context * iio_create_context_from_uri(const char *uri);
-
-
-/** @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 Get the number of context-specific attributes
- * @param ctx A pointer to an iio_context structure
- * @return The number of context-specific attributes
- *
- * Introduced in version 0.9. */
-__api __pure unsigned int iio_context_get_attrs_count(
- const struct iio_context *ctx);
-
-
-/** @brief Retrieve the name and value of a context-specific attribute
- * @param ctx A pointer to an iio_context structure
- * @param index The index corresponding to the attribute
- * @param name A pointer to a const char * pointer (NULL accepted)
- * @param value A pointer to a const char * pointer (NULL accepted)
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned
- *
- * Introduced in version 0.9. */
-__api int iio_context_get_attr(
- const struct iio_context *ctx, unsigned int index,
- const char **name, const char **value);
-
-
-/** @brief Retrieve the value of a context-specific attribute
- * @param ctx A pointer to an iio_context structure
- * @param name The name of the context attribute to read
- * @return On success, a pointer to a static NULL-terminated string
- * @return If the name does not correspond to any attribute, NULL is
- * returned
- *
- * Introduced in version 0.9. */
-__api const char * iio_context_get_attr_value(
- const struct iio_context *ctx, const char *name);
-
-
-/** @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. A value of 0 is used to specify that no
- * timeout should occur.
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_context_set_timeout(
- struct iio_context *ctx, unsigned int timeout_ms);
-
-
-/** @} *//* ------------------------------------------------------------------*/
-/* ------------------------- Device functions --------------------------------*/
-/** @defgroup Device Device
- * @{
- * @struct iio_device
- * @brief Represents a device in the IIO context */
-
-
-/** @brief Retrieve a pointer to the iio_context structure
- * @param dev A pointer to an iio_device structure
- * @return A pointer to an iio_context structure */
-__api __pure const struct iio_context * iio_device_get_context(
- const struct iio_device *dev);
-
-
-/** @brief Retrieve the device ID (e.g. <b><i>iio:device0</i></b>)
- * @param dev A pointer to an iio_device structure
- * @return A pointer to a static NULL-terminated string */
-__api __pure const char * iio_device_get_id(const struct iio_device *dev);
-
-
-/** @brief Retrieve the device name (e.g. <b><i>xadc</i></b>)
- * @param dev A pointer to an iio_device structure
- * @return A pointer to a static NULL-terminated string
- *
- * <b>NOTE:</b> if the device has no name, NULL is returned. */
-__api __pure const char * iio_device_get_name(const struct iio_device *dev);
-
-
-/** @brief Enumerate the channels of the given device
- * @param dev A pointer to an iio_device structure
- * @return The number of channels found */
-__api __pure unsigned int iio_device_get_channels_count(
- const struct iio_device *dev);
-
-
-/** @brief Enumerate the device-specific attributes of the given device
- * @param dev A pointer to an iio_device structure
- * @return The number of device-specific attributes found */
-__api __pure unsigned int iio_device_get_attrs_count(
- const struct iio_device *dev);
-
-/** @brief Enumerate the buffer-specific attributes of the given device
- * @param dev A pointer to an iio_device structure
- * @return The number of buffer-specific attributes found */
-__api __pure unsigned int iio_device_get_buffer_attrs_count(
- const struct iio_device *dev);
-
-/** @brief Get the channel present at the given index
- * @param dev A pointer to an iio_device structure
- * @param index The index corresponding to the channel
- * @return On success, a pointer to an iio_channel structure
- * @return If the index is invalid, NULL is returned */
-__api __pure struct iio_channel * iio_device_get_channel(
- const struct iio_device *dev, unsigned int index);
-
-
-/** @brief Get the device-specific attribute present at the given index
- * @param dev A pointer to an iio_device structure
- * @param index The index corresponding to the attribute
- * @return On success, a pointer to a static NULL-terminated string
- * @return If the index is invalid, NULL is returned */
-__api __pure const char * iio_device_get_attr(
- const struct iio_device *dev, unsigned int index);
-
-/** @brief Get the buffer-specific attribute present at the given index
- * @param dev A pointer to an iio_device structure
- * @param index The index corresponding to the attribute
- * @return On success, a pointer to a static NULL-terminated string
- * @return If the index is invalid, NULL is returned */
-__api __pure const char * iio_device_get_buffer_attr(
- const struct iio_device *dev, unsigned int index);
-
-/** @brief Try to find a channel structure by its name of ID
- * @param dev A pointer to an iio_device structure
- * @param name A NULL-terminated string corresponding to the name or the ID of
- * the channel to search for
- * @param output True if the searched channel is output, False otherwise
- * @return On success, a pointer to an iio_channel structure
- * @return If the name or ID does not correspond to any known channel of the
- * given device, NULL is returned */
-__api __pure struct iio_channel * iio_device_find_channel(
- const struct iio_device *dev, const char *name, bool output);
-
-
-/** @brief Try to find a device-specific attribute by its name
- * @param dev A pointer to an iio_device structure
- * @param name A NULL-terminated string corresponding to the name of the
- * attribute
- * @return On success, a pointer to a static NULL-terminated string
- * @return If the name does not correspond to any known attribute of the given
- * device, NULL is returned
- *
- * <b>NOTE:</b> This function is useful to detect the presence of an attribute.
- * It can also be used to retrieve the name of an attribute as a pointer to a
- * static string from a dynamically allocated string. */
-__api __pure const char * iio_device_find_attr(
- const struct iio_device *dev, const char *name);
-
-/** @brief Try to find a buffer-specific attribute by its name
- * @param dev A pointer to an iio_device structure
- * @param name A NULL-terminated string corresponding to the name of the
- * attribute
- * @return On success, a pointer to a static NULL-terminated string
- * @return If the name does not correspond to any known attribute of the given
- * device, NULL is returned
- *
- * <b>NOTE:</b> This function is useful to detect the presence of an attribute.
- * It can also be used to retrieve the name of an attribute as a pointer to a
- * static string from a dynamically allocated string. */
-__api __pure const char * iio_device_find_buffer_attr(
- const struct iio_device *dev, const char *name);
-
-/** @brief Read the content of the given device-specific attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param dst A pointer to the memory area where the NULL-terminated string
- * corresponding to the value read will be stored
- * @param len The available length of the memory area, in bytes
- * @return On success, the number of bytes written to the buffer
- * @return On error, a negative errno code is returned
- *
- * <b>NOTE:</b>By passing NULL as the "attr" argument to iio_device_attr_read,
- * it is now possible to read all of the attributes of a device.
- *
- * The buffer is filled with one block of data per attribute of the device,
- * by the order they appear in the iio_device structure.
- *
- * The first four bytes of one block correspond to a 32-bit signed value in
- * network order. If negative, it corresponds to the errno code that were
- * returned when reading the attribute; if positive, it corresponds to the
- * length of the data read. In that case, the rest of the block contains
- * the data. */
- __api ssize_t iio_device_attr_read(const struct iio_device *dev,
- const char *attr, char *dst, size_t len);
-
-
-/** @brief Read the content of all device-specific attributes
- * @param dev A pointer to an iio_device structure
- * @param cb A pointer to a callback function
- * @param data A pointer that will be passed to the callback function
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned
- *
- * <b>NOTE:</b> This function is especially useful when used with the network
- * backend, as all the device-specific attributes are read in one single
- * command. */
-__api int iio_device_attr_read_all(struct iio_device *dev,
- int (*cb)(struct iio_device *dev, const char *attr,
- const char *value, size_t len, void *d),
- void *data);
-
-
-/** @brief Read the content of the given device-specific attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param val A pointer to a bool variable where the value should be stored
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_attr_read_bool(const struct iio_device *dev,
- const char *attr, bool *val);
-
-
-/** @brief Read the content of the given device-specific attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param val A pointer to a long long variable where the value should be stored
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_attr_read_longlong(const struct iio_device *dev,
- const char *attr, long long *val);
-
-
-/** @brief Read the content of the given device-specific attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param val A pointer to a double variable where the value should be stored
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_attr_read_double(const struct iio_device *dev,
- const char *attr, double *val);
-
-
-/** @brief Set the value of the given device-specific attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param src A NULL-terminated string to set the attribute to
- * @return On success, the number of bytes written
- * @return On error, a negative errno code is returned
- *
- * <b>NOTE:</b>By passing NULL as the "attr" argument to iio_device_attr_write,
- * it is now possible to write all of the attributes of a device.
- *
- * The buffer must contain one block of data per attribute of the device,
- * by the order they appear in the iio_device structure.
- *
- * The first four bytes of one block correspond to a 32-bit signed value in
- * network order. If negative, the attribute is not written; if positive,
- * it corresponds to the length of the data to write. In that case, the rest
- * of the block must contain the data. */
-__api ssize_t iio_device_attr_write(const struct iio_device *dev,
- const char *attr, const char *src);
-
-
-/** @brief Set the value of the given device-specific attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param src A pointer to the data to be written
- * @param len The number of bytes that should be written
- * @return On success, the number of bytes written
- * @return On error, a negative errno code is returned */
-__api ssize_t iio_device_attr_write_raw(const struct iio_device *dev,
- const char *attr, const void *src, size_t len);
-
-
-/** @brief Set the values of all device-specific attributes
- * @param dev A pointer to an iio_device structure
- * @param cb A pointer to a callback function
- * @param data A pointer that will be passed to the callback function
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned
- *
- * <b>NOTE:</b> This function is especially useful when used with the network
- * backend, as all the device-specific attributes are written in one single
- * command. */
-__api int iio_device_attr_write_all(struct iio_device *dev,
- ssize_t (*cb)(struct iio_device *dev,
- const char *attr, void *buf, size_t len, void *d),
- void *data);
-
-
-/** @brief Set the value of the given device-specific attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param val A bool value to set the attribute to
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_attr_write_bool(const struct iio_device *dev,
- const char *attr, bool val);
-
-
-/** @brief Set the value of the given device-specific attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param val A long long value to set the attribute to
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_attr_write_longlong(const struct iio_device *dev,
- const char *attr, long long val);
-
-
-/** @brief Set the value of the given device-specific attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param val A double value to set the attribute to
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_attr_write_double(const struct iio_device *dev,
- const char *attr, double val);
-
-/** @brief Read the content of the given buffer-specific attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param dst A pointer to the memory area where the NULL-terminated string
- * corresponding to the value read will be stored
- * @param len The available length of the memory area, in bytes
- * @return On success, the number of bytes written to the buffer
- * @return On error, a negative errno code is returned
- *
- * <b>NOTE:</b>By passing NULL as the "attr" argument to
- * iio_device_buffer_attr_read, it is now possible to read all of the attributes
- * of a device.
- *
- * The buffer is filled with one block of data per attribute of the buffer,
- * by the order they appear in the iio_device structure.
- *
- * The first four bytes of one block correspond to a 32-bit signed value in
- * network order. If negative, it corresponds to the errno code that were
- * returned when reading the attribute; if positive, it corresponds to the
- * length of the data read. In that case, the rest of the block contains
- * the data. */
- __api ssize_t iio_device_buffer_attr_read(const struct iio_device *dev,
- const char *attr, char *dst, size_t len);
-
-/** @brief Read the content of all buffer-specific attributes
- * @param dev A pointer to an iio_device structure
- * @param cb A pointer to a callback function
- * @param data A pointer that will be passed to the callback function
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned
- *
- * <b>NOTE:</b> This function is especially useful when used with the network
- * backend, as all the buffer-specific attributes are read in one single
- * command. */
-__api int iio_device_buffer_attr_read_all(struct iio_device *dev,
- int (*cb)(struct iio_device *dev, const char *attr,
- const char *value, size_t len, void *d),
- void *data);
-
-
-/** @brief Read the content of the given buffer-specific attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param val A pointer to a bool variable where the value should be stored
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_buffer_attr_read_bool(const struct iio_device *dev,
- const char *attr, bool *val);
-
-
-/** @brief Read the content of the given buffer-specific attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param val A pointer to a long long variable where the value should be stored
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_buffer_attr_read_longlong(const struct iio_device *dev,
- const char *attr, long long *val);
-
-
-/** @brief Read the content of the given buffer-specific attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param val A pointer to a double variable where the value should be stored
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_buffer_attr_read_double(const struct iio_device *dev,
- const char *attr, double *val);
-
-
-/** @brief Set the value of the given buffer-specific attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param src A NULL-terminated string to set the attribute to
- * @return On success, the number of bytes written
- * @return On error, a negative errno code is returned
- *
- * <b>NOTE:</b>By passing NULL as the "attr" argument to
- * iio_device_buffer_attr_write, it is now possible to write all of the
- * attributes of a device.
- *
- * The buffer must contain one block of data per attribute of the buffer,
- * by the order they appear in the iio_device structure.
- *
- * The first four bytes of one block correspond to a 32-bit signed value in
- * network order. If negative, the attribute is not written; if positive,
- * it corresponds to the length of the data to write. In that case, the rest
- * of the block must contain the data. */
-__api ssize_t iio_device_buffer_attr_write(const struct iio_device *dev,
- const char *attr, const char *src);
-
-
-/** @brief Set the value of the given buffer-specific attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param src A pointer to the data to be written
- * @param len The number of bytes that should be written
- * @return On success, the number of bytes written
- * @return On error, a negative errno code is returned */
-__api ssize_t iio_device_buffer_attr_write_raw(const struct iio_device *dev,
- const char *attr, const void *src, size_t len);
-
-
-/** @brief Set the values of all buffer-specific attributes
- * @param dev A pointer to an iio_device structure
- * @param cb A pointer to a callback function
- * @param data A pointer that will be passed to the callback function
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned
- *
- * <b>NOTE:</b> This function is especially useful when used with the network
- * backend, as all the buffer-specific attributes are written in one single
- * command. */
-__api int iio_device_buffer_attr_write_all(struct iio_device *dev,
- ssize_t (*cb)(struct iio_device *dev,
- const char *attr, void *buf, size_t len, void *d),
- void *data);
-
-
-/** @brief Set the value of the given buffer-specific attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param val A bool value to set the attribute to
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_buffer_attr_write_bool(const struct iio_device *dev,
- const char *attr, bool val);
-
-
-/** @brief Set the value of the given buffer-specific attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param val A long long value to set the attribute to
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_buffer_attr_write_longlong(const struct iio_device *dev,
- const char *attr, long long val);
-
-
-/** @brief Set the value of the given buffer-specific attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param val A double value to set the attribute to
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_buffer_attr_write_double(const struct iio_device *dev,
- const char *attr, double val);
-
-
-/** @brief Associate a pointer to an iio_device structure
- * @param dev A pointer to an iio_device structure
- * @param data The pointer to be associated */
-__api void iio_device_set_data(struct iio_device *dev, void *data);
-
-
-/** @brief Retrieve a previously associated pointer of an iio_device structure
- * @param dev A pointer to an iio_device structure
- * @return The pointer previously associated if present, or NULL */
-__api void * iio_device_get_data(const struct iio_device *dev);
-
-
-/** @brief Retrieve the trigger of a given device
- * @param dev A pointer to an iio_device structure
- * @param trigger a pointer to a pointer of an iio_device structure. The pointed
- * pointer will be set to the address of the iio_device structure corresponding
- * to the associated trigger device.
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_get_trigger(const struct iio_device *dev,
- const struct iio_device **trigger);
-
-
-/** @brief Associate a trigger to a given device
- * @param dev A pointer to an iio_device structure
- * @param trigger a pointer to the iio_device structure corresponding to the
- * trigger that should be associated.
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_set_trigger(const struct iio_device *dev,
- const struct iio_device *trigger);
-
-
-/** @brief Return True if the given device is a trigger
- * @param dev A pointer to an iio_device structure
- * @return True if the device is a trigger, False otherwise */
-__api __pure bool iio_device_is_trigger(const struct iio_device *dev);
-
-/**
- * @brief Configure the number of kernel buffers for a device
- *
- * This function allows to change the number of buffers on kernel side.
- * @param dev A pointer to an iio_device structure
- * @param nb_buffers The number of buffers
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_set_kernel_buffers_count(const struct iio_device *dev,
- unsigned int nb_buffers);
-
-/** @} *//* ------------------------------------------------------------------*/
-/* ------------------------- Channel functions -------------------------------*/
-/** @defgroup Channel Channel
- * @{
- * @struct iio_channel
- * @brief Represents an input or output channel of a device */
-
-
-/** @brief Retrieve a pointer to the iio_device structure
- * @param chn A pointer to an iio_channel structure
- * @return A pointer to an iio_device structure */
-__api __pure const struct iio_device * iio_channel_get_device(
- const struct iio_channel *chn);
-
-
-/** @brief Retrieve the channel ID (e.g. <b><i>voltage0</i></b>)
- * @param chn A pointer to an iio_channel structure
- * @return A pointer to a static NULL-terminated string */
-__api __pure const char * iio_channel_get_id(const struct iio_channel *chn);
-
-
-/** @brief Retrieve the channel name (e.g. <b><i>vccint</i></b>)
- * @param chn A pointer to an iio_channel structure
- * @return A pointer to a static NULL-terminated string
- *
- * <b>NOTE:</b> if the channel has no name, NULL is returned. */
-__api __pure const char * iio_channel_get_name(const struct iio_channel *chn);
-
-
-/** @brief Return True if the given channel is an output channel
- * @param chn A pointer to an iio_channel structure
- * @return True if the channel is an output channel, False otherwise */
-__api __pure bool iio_channel_is_output(const struct iio_channel *chn);
-
-
-/** @brief Return True if the given channel is a scan element
- * @param chn A pointer to an iio_channel structure
- * @return True if the channel is a scan element, False otherwise
- *
- * <b>NOTE:</b> a channel that is a scan element is a channel that can
- * generate samples (for an input channel) or receive samples (for an output
- * channel) after being enabled. */
-__api __pure bool iio_channel_is_scan_element(const struct iio_channel *chn);
-
-
-/** @brief Enumerate the channel-specific attributes of the given channel
- * @param chn A pointer to an iio_channel structure
- * @return The number of channel-specific attributes found */
-__api __pure unsigned int iio_channel_get_attrs_count(
- const struct iio_channel *chn);
-
-
-/** @brief Get the channel-specific attribute present at the given index
- * @param chn A pointer to an iio_channel structure
- * @param index The index corresponding to the attribute
- * @return On success, a pointer to a static NULL-terminated string
- * @return If the index is invalid, NULL is returned */
-__api __pure const char * iio_channel_get_attr(
- const struct iio_channel *chn, unsigned int index);
-
-
-/** @brief Try to find a channel-specific attribute by its name
- * @param chn A pointer to an iio_channel structure
- * @param name A NULL-terminated string corresponding to the name of the
- * attribute
- * @return On success, a pointer to a static NULL-terminated string
- * @return If the name does not correspond to any known attribute of the given
- * channel, NULL is returned
- *
- * <b>NOTE:</b> This function is useful to detect the presence of an attribute.
- * It can also be used to retrieve the name of an attribute as a pointer to a
- * static string from a dynamically allocated string. */
-__api __pure const char * iio_channel_find_attr(
- const struct iio_channel *chn, const char *name);
-
-
-/** @brief Retrieve the filename of an attribute
- * @param chn A pointer to an iio_channel structure
- * @param attr a NULL-terminated string corresponding to the name of the
- * attribute
- * @return On success, a pointer to a static NULL-terminated string
- * @return If the attribute name is unknown, NULL is returned */
-__api __pure const char * iio_channel_attr_get_filename(
- const struct iio_channel *chn, const char *attr);
-
-
-/** @brief Read the content of the given channel-specific attribute
- * @param chn A pointer to an iio_channel structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param dst A pointer to the memory area where the NULL-terminated string
- * corresponding to the value read will be stored
- * @param len The available length of the memory area, in bytes
- * @return On success, the number of bytes written to the buffer
- * @return On error, a negative errno code is returned
- *
- * <b>NOTE:</b>By passing NULL as the "attr" argument to iio_channel_attr_read,
- * it is now possible to read all of the attributes of a channel.
- *
- * The buffer is filled with one block of data per attribute of the channel,
- * by the order they appear in the iio_channel structure.
- *
- * The first four bytes of one block correspond to a 32-bit signed value in
- * network order. If negative, it corresponds to the errno code that were
- * returned when reading the attribute; if positive, it corresponds to the
- * length of the data read. In that case, the rest of the block contains
- * the data. */
-__api ssize_t iio_channel_attr_read(const struct iio_channel *chn,
- const char *attr, char *dst, size_t len);
-
-
-/** @brief Read the content of all channel-specific attributes
- * @param chn A pointer to an iio_channel structure
- * @param cb A pointer to a callback function
- * @param data A pointer that will be passed to the callback function
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned
- *
- * <b>NOTE:</b> This function is especially useful when used with the network
- * backend, as all the channel-specific attributes are read in one single
- * command. */
-__api int iio_channel_attr_read_all(struct iio_channel *chn,
- int (*cb)(struct iio_channel *chn,
- const char *attr, const char *val, size_t len, void *d),
- void *data);
-
-
-/** @brief Read the content of the given channel-specific attribute
- * @param chn A pointer to an iio_channel structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param val A pointer to a bool variable where the value should be stored
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_channel_attr_read_bool(const struct iio_channel *chn,
- const char *attr, bool *val);
-
-
-/** @brief Read the content of the given channel-specific attribute
- * @param chn A pointer to an iio_channel structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param val A pointer to a long long variable where the value should be stored
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_channel_attr_read_longlong(const struct iio_channel *chn,
- const char *attr, long long *val);
-
-
-/** @brief Read the content of the given channel-specific attribute
- * @param chn A pointer to an iio_channel structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param val A pointer to a double variable where the value should be stored
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_channel_attr_read_double(const struct iio_channel *chn,
- const char *attr, double *val);
-
-
-/** @brief Set the value of the given channel-specific attribute
- * @param chn A pointer to an iio_channel structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param src A NULL-terminated string to set the attribute to
- * @return On success, the number of bytes written
- * @return On error, a negative errno code is returned
- *
- * <b>NOTE:</b>By passing NULL as the "attr" argument to iio_channel_attr_write,
- * it is now possible to write all of the attributes of a channel.
- *
- * The buffer must contain one block of data per attribute of the channel,
- * by the order they appear in the iio_channel structure.
- *
- * The first four bytes of one block correspond to a 32-bit signed value in
- * network order. If negative, the attribute is not written; if positive,
- * it corresponds to the length of the data to write. In that case, the rest
- * of the block must contain the data. */
-__api ssize_t iio_channel_attr_write(const struct iio_channel *chn,
- const char *attr, const char *src);
-
-
-/** @brief Set the value of the given channel-specific attribute
- * @param chn A pointer to an iio_channel structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param src A pointer to the data to be written
- * @param len The number of bytes that should be written
- * @return On success, the number of bytes written
- * @return On error, a negative errno code is returned */
-__api ssize_t iio_channel_attr_write_raw(const struct iio_channel *chn,
- const char *attr, const void *src, size_t len);
-
-
-/** @brief Set the values of all channel-specific attributes
- * @param chn A pointer to an iio_channel structure
- * @param cb A pointer to a callback function
- * @param data A pointer that will be passed to the callback function
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned
- *
- * <b>NOTE:</b> This function is especially useful when used with the network
- * backend, as all the channel-specific attributes are written in one single
- * command. */
-__api int iio_channel_attr_write_all(struct iio_channel *chn,
- ssize_t (*cb)(struct iio_channel *chn,
- const char *attr, void *buf, size_t len, void *d),
- void *data);
-
-
-/** @brief Set the value of the given channel-specific attribute
- * @param chn A pointer to an iio_channel structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param val A bool value to set the attribute to
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_channel_attr_write_bool(const struct iio_channel *chn,
- const char *attr, bool val);
-
-
-/** @brief Set the value of the given channel-specific attribute
- * @param chn A pointer to an iio_channel structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param val A long long value to set the attribute to
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_channel_attr_write_longlong(const struct iio_channel *chn,
- const char *attr, long long val);
-
-
-/** @brief Set the value of the given channel-specific attribute
- * @param chn A pointer to an iio_channel structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * attribute
- * @param val A double value to set the attribute to
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_channel_attr_write_double(const struct iio_channel *chn,
- const char *attr, double val);
-
-
-/** @brief Enable the given channel
- * @param chn A pointer to an iio_channel structure
- *
- * <b>NOTE:</b>Before creating an iio_buffer structure with
- * iio_device_create_buffer, it is required to enable at least one channel of
- * the device to read from. */
-__api void iio_channel_enable(struct iio_channel *chn);
-
-
-/** @brief Disable the given channel
- * @param chn A pointer to an iio_channel structure */
-__api void iio_channel_disable(struct iio_channel *chn);
-
-
-/** @brief Returns True if the channel is enabled
- * @param chn A pointer to an iio_channel structure
- * @return True if the channel is enabled, False otherwise */
-__api bool iio_channel_is_enabled(const struct iio_channel *chn);
-
-
-/** Demultiplex the samples of a given channel
- * @param chn A pointer to an iio_channel structure
- * @param buffer A pointer to an iio_buffer structure
- * @param dst A pointer to the memory area where the demultiplexed data will be
- * stored
- * @param len The available length of the memory area, in bytes
- * @return The size of the demultiplexed data, in bytes */
-__api size_t iio_channel_read_raw(const struct iio_channel *chn,
- struct iio_buffer *buffer, void *dst, size_t len);
-
-
-/** Demultiplex and convert the samples of a given channel
- * @param chn A pointer to an iio_channel structure
- * @param buffer A pointer to an iio_buffer structure
- * @param dst A pointer to the memory area where the converted data will be
- * stored
- * @param len The available length of the memory area, in bytes
- * @return The size of the converted data, in bytes */
-__api size_t iio_channel_read(const struct iio_channel *chn,
- struct iio_buffer *buffer, void *dst, size_t len);
-
-
-/** Multiplex the samples of a given channel
- * @param chn A pointer to an iio_channel structure
- * @param buffer A pointer to an iio_buffer structure
- * @param src A pointer to the memory area where the sequential data will
- * be read from
- * @param len The length of the memory area, in bytes
- * @return The number of bytes actually multiplexed */
-__api size_t iio_channel_write_raw(const struct iio_channel *chn,
- struct iio_buffer *buffer, const void *src, size_t len);
-
-
-/** Convert and multiplex the samples of a given channel
- * @param chn A pointer to an iio_channel structure
- * @param buffer A pointer to an iio_buffer structure
- * @param src A pointer to the memory area where the sequential data will
- * be read from
- * @param len The length of the memory area, in bytes
- * @return The number of bytes actually converted and multiplexed */
-__api size_t iio_channel_write(const struct iio_channel *chn,
- struct iio_buffer *buffer, const void *src, size_t len);
-
-
-/** @brief Associate a pointer to an iio_channel structure
- * @param chn A pointer to an iio_channel structure
- * @param data The pointer to be associated */
-__api void iio_channel_set_data(struct iio_channel *chn, void *data);
-
-
-/** @brief Retrieve a previously associated pointer of an iio_channel structure
- * @param chn A pointer to an iio_channel structure
- * @return The pointer previously associated if present, or NULL */
-__api void * iio_channel_get_data(const struct iio_channel *chn);
-
-
-/** @brief Get the type of the given channel
- * @param chn A pointer to an iio_channel structure
- * @return The type of the channel */
-__api __pure enum iio_chan_type iio_channel_get_type(
- const struct iio_channel *chn);
-
-
-/** @brief Get the modifier type of the given channel
- * @param chn A pointer to an iio_channel structure
- * @return The modifier type of the channel */
-__api __pure enum iio_modifier iio_channel_get_modifier(
- const struct iio_channel *chn);
-
-
-/** @} *//* ------------------------------------------------------------------*/
-/* ------------------------- Buffer functions --------------------------------*/
-/** @defgroup Buffer Buffer
- * @{
- * @struct iio_buffer
- * @brief An input or output buffer, used to read or write samples */
-
-
-/** @brief Retrieve a pointer to the iio_device structure
- * @param buf A pointer to an iio_buffer structure
- * @return A pointer to an iio_device structure */
-__api __pure const struct iio_device * iio_buffer_get_device(
- const struct iio_buffer *buf);
-
-
-/** @brief Create an input or output buffer associated to the given device
- * @param dev A pointer to an iio_device structure
- * @param samples_count The number of samples that the buffer should contain
- * @param cyclic If True, enable cyclic mode
- * @return On success, a pointer to an iio_buffer structure
- * @return On error, NULL is returned, and errno is set to the error code
- *
- * <b>NOTE:</b> Channels that have to be written to / read from must be enabled
- * before creating the buffer. */
-__api struct iio_buffer * iio_device_create_buffer(const struct iio_device *dev,
- size_t samples_count, bool cyclic);
-
-
-/** @brief Destroy the given buffer
- * @param buf A pointer to an iio_buffer structure
- *
- * <b>NOTE:</b> After that function, the iio_buffer pointer shall be invalid. */
-__api void iio_buffer_destroy(struct iio_buffer *buf);
-
-/** @brief Get a pollable file descriptor
- *
- * Can be used to know when iio_buffer_refill() or iio_buffer_push() can be
- * called
- * @param buf A pointer to an iio_buffer structure
- * @return On success, valid file descriptor
- * @return On error, a negative errno code is returned
- */
-__api int iio_buffer_get_poll_fd(struct iio_buffer *buf);
-
-/** @brief Make iio_buffer_refill() and iio_buffer_push() blocking or not
- *
- * After this function has been called with blocking == false,
- * iio_buffer_refill() and iio_buffer_push() will return -EAGAIN if no data is
- * ready.
- * A device is blocking by default.
- * @param buf A pointer to an iio_buffer structure
- * @param blocking true if the buffer API should be blocking, else false
- * @return On success, 0
- * @return On error, a negative errno code is returned
- */
-__api int iio_buffer_set_blocking_mode(struct iio_buffer *buf, bool blocking);
-
-
-/** @brief Fetch more samples from the hardware
- * @param buf A pointer to an iio_buffer structure
- * @return On success, the number of bytes read is returned
- * @return On error, a negative errno code is returned
- *
- * <b>NOTE:</b> Only valid for input buffers */
-__api ssize_t iio_buffer_refill(struct iio_buffer *buf);
-
-
-/** @brief Send the samples to the hardware
- * @param buf A pointer to an iio_buffer structure
- * @return On success, the number of bytes written is returned
- * @return On error, a negative errno code is returned
- *
- * <b>NOTE:</b> Only valid for output buffers */
-__api ssize_t iio_buffer_push(struct iio_buffer *buf);
-
-
-/** @brief Send a given number of samples to the hardware
- * @param buf A pointer to an iio_buffer structure
- * @param samples_count The number of samples to submit
- * @return On success, the number of bytes written is returned
- * @return On error, a negative errno code is returned
- *
- * <b>NOTE:</b> Only valid for output buffers */
-__api ssize_t iio_buffer_push_partial(struct iio_buffer *buf,
- size_t samples_count);
-
-/** @brief Cancel all buffer operations
- * @param buf The buffer for which operations should be canceled
- *
- * This function cancels all outstanding buffer operations previously scheduled.
- * This means any pending iio_buffer_push() or iio_buffer_refill() operation
- * will abort and return immediately, any further invocations of these functions
- * on the same buffer will return immediately with an error.
- *
- * Usually iio_buffer_push() and iio_buffer_refill() will block until either all
- * data has been transferred or a timeout occurs. This can depending on the
- * configuration take a significant amount of time. iio_buffer_cancel() is
- * useful to bypass these conditions if the buffer operation is supposed to be
- * stopped in response to an external event (e.g. user input).
- *
- * To be able to capture additional data after calling this function the buffer
- * should be destroyed and then re-created.
- *
- * This function can be called multiple times for the same buffer, but all but
- * the first invocation will be without additional effect.
- *
- * This function is thread-safe, but not signal-safe, i.e. it must not be called
- * from a signal handler.
- */
-__api void iio_buffer_cancel(struct iio_buffer *buf);
-
-
-/** @brief Get the start address of the buffer
- * @param buf A pointer to an iio_buffer structure
- * @return A pointer corresponding to the start address of the buffer */
-__api void * iio_buffer_start(const struct iio_buffer *buf);
-
-
-/** @brief Find the first sample of a channel in a buffer
- * @param buf A pointer to an iio_buffer structure
- * @param chn A pointer to an iio_channel structure
- * @return A pointer to the first sample found, or to the end of the buffer if
- * no sample for the given channel is present in the buffer
- *
- * <b>NOTE:</b> This function, coupled with iio_buffer_step and iio_buffer_end,
- * can be used to iterate on all the samples of a given channel present in the
- * buffer, doing the following:
- *
- * @verbatim
- for (void *ptr = iio_buffer_first(buffer, chn); ptr < iio_buffer_end(buffer); ptr += iio_buffer_step(buffer)) {
- ....
- }
- @endverbatim */
-__api void * iio_buffer_first(const struct iio_buffer *buf,
- const struct iio_channel *chn);
-
-
-/** @brief Get the step size between two samples of one channel
- * @param buf A pointer to an iio_buffer structure
- * @return the difference between the addresses of two consecutive samples of
- * one same channel */
-__api ptrdiff_t iio_buffer_step(const struct iio_buffer *buf);
-
-
-/** @brief Get the address that follows the last sample in a buffer
- * @param buf A pointer to an iio_buffer structure
- * @return A pointer corresponding to the address that follows the last sample
- * present in the buffer */
-__api void * iio_buffer_end(const struct iio_buffer *buf);
-
-
-/** @brief Call the supplied callback for each sample found in a buffer
- * @param buf A pointer to an iio_buffer structure
- * @param callback A pointer to a function to call for each sample found
- * @param data A user-specified pointer that will be passed to the callback
- * @return number of bytes processed.
- *
- * <b>NOTE:</b> The callback receives four arguments:
- * * A pointer to the iio_channel structure corresponding to the sample,
- * * A pointer to the sample itself,
- * * The length of the sample in bytes,
- * * The user-specified pointer passed to iio_buffer_foreach_sample. */
-__api ssize_t iio_buffer_foreach_sample(struct iio_buffer *buf,
- ssize_t (*callback)(const struct iio_channel *chn,
- void *src, size_t bytes, void *d), void *data);
-
-
-/** @brief Associate a pointer to an iio_buffer structure
- * @param buf A pointer to an iio_buffer structure
- * @param data The pointer to be associated */
-__api void iio_buffer_set_data(struct iio_buffer *buf, void *data);
-
-
-/** @brief Retrieve a previously associated pointer of an iio_buffer structure
- * @param buf A pointer to an iio_buffer structure
- * @return The pointer previously associated if present, or NULL */
-__api void * iio_buffer_get_data(const struct iio_buffer *buf);
-
-
-/** @} *//* ------------------------------------------------------------------*/
-/* ------------------------- Low-level functions -----------------------------*/
-/** @defgroup Debug Debug and low-level functions
- * @{
- * @struct iio_data_format
- * @brief Contains the format of a data sample.
- *
- * The different fields inform about the correct way to convert one sample from
- * its raw format (as read from / generated by the hardware) to its real-world
- * value.
- */
-struct iio_data_format {
- /** @brief Total length of the sample, in bits */
- unsigned int length;
-
- /** @brief Length of valuable data in the sample, in bits */
- unsigned int bits;
-
- /** @brief Right-shift to apply when converting sample */
- unsigned int shift;
-
- /** @brief Contains True if the sample is signed */
- bool is_signed;
-
- /** @brief Contains True if the sample is fully defined, sign extended, etc. */
- bool is_fully_defined;
-
- /** @brief Contains True if the sample is in big-endian format */
- bool is_be;
-
- /** @brief Contains True if the sample should be scaled when converted */
- bool with_scale;
-
- /** @brief Contains the scale to apply if with_scale is set */
- double scale;
-
- /** @brief Number of times length repeats (added in v0.8) */
- unsigned int repeat;
-};
-
-
-/** @brief Get the current sample size
- * @param dev A pointer to an iio_device structure
- * @return On success, the sample size in bytes
- * @return On error, a negative errno code is returned
- *
- * <b>NOTE:</b> The sample size is not constant and will change when channels
- * get enabled or disabled. */
-__api ssize_t iio_device_get_sample_size(const struct iio_device *dev);
-
-
-/** @brief Get the index of the given channel
- * @param chn A pointer to an iio_channel structure
- * @return On success, the index of the specified channel
- * @return On error, a negative errno code is returned */
-__api __pure long iio_channel_get_index(const struct iio_channel *chn);
-
-
-/** @brief Get a pointer to a channel's data format structure
- * @param chn A pointer to an iio_channel structure
- * @return A pointer to the channel's iio_data_format structure */
-__api __cnst const struct iio_data_format * iio_channel_get_data_format(
- const struct iio_channel *chn);
-
-
-/** @brief Convert the sample from hardware format to host format
- * @param chn A pointer to an iio_channel structure
- * @param dst A pointer to the destination buffer where the converted sample
- * should be written
- * @param src A pointer to the source buffer containing the sample */
-__api void iio_channel_convert(const struct iio_channel *chn,
- void *dst, const void *src);
-
-
-/** @brief Convert the sample from host format to hardware format
- * @param chn A pointer to an iio_channel structure
- * @param dst A pointer to the destination buffer where the converted sample
- * should be written
- * @param src A pointer to the source buffer containing the sample */
-__api void iio_channel_convert_inverse(const struct iio_channel *chn,
- void *dst, const void *src);
-
-
-/** @brief Enumerate the debug attributes of the given device
- * @param dev A pointer to an iio_device structure
- * @return The number of debug attributes found */
-__api __pure unsigned int iio_device_get_debug_attrs_count(
- const struct iio_device *dev);
-
-
-/** @brief Get the debug attribute present at the given index
- * @param dev A pointer to an iio_device structure
- * @param index The index corresponding to the debug attribute
- * @return On success, a pointer to a static NULL-terminated string
- * @return If the index is invalid, NULL is returned */
-__api __pure const char * iio_device_get_debug_attr(
- const struct iio_device *dev, unsigned int index);
-
-
-/** @brief Try to find a debug attribute by its name
- * @param dev A pointer to an iio_device structure
- * @param name A NULL-terminated string corresponding to the name of the
- * debug attribute
- * @return On success, a pointer to a static NULL-terminated string
- * @return If the name does not correspond to any known debug attribute of the
- * given device, NULL is returned
- *
- * <b>NOTE:</b> This function is useful to detect the presence of a debug
- * attribute.
- * It can also be used to retrieve the name of a debug attribute as a pointer
- * to a static string from a dynamically allocated string. */
-__api __pure const char * iio_device_find_debug_attr(
- const struct iio_device *dev, const char *name);
-
-
-/** @brief Read the content of the given debug attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * debug attribute
- * @param dst A pointer to the memory area where the NULL-terminated string
- * corresponding to the value read will be stored
- * @param len The available length of the memory area, in bytes
- * @return On success, the number of bytes written to the buffer
- * @return On error, a negative errno code is returned
- *
- * <b>NOTE:</b>By passing NULL as the "attr" argument to
- * iio_device_debug_attr_read, it is now possible to read all of the debug
- * attributes of a device.
- *
- * The buffer is filled with one block of data per debug attribute of the
- * device, by the order they appear in the iio_device structure.
- *
- * The first four bytes of one block correspond to a 32-bit signed value in
- * network order. If negative, it corresponds to the errno code that were
- * returned when reading the debug attribute; if positive, it corresponds
- * to the length of the data read. In that case, the rest of the block contains
- * the data. */
-__api ssize_t iio_device_debug_attr_read(const struct iio_device *dev,
- const char *attr, char *dst, size_t len);
-
-
-/** @brief Read the content of all debug attributes
- * @param dev A pointer to an iio_device structure
- * @param cb A pointer to a callback function
- * @param data A pointer that will be passed to the callback function
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned
- *
- * <b>NOTE:</b> This function is especially useful when used with the network
- * backend, as all the debug attributes are read in one single command. */
-__api int iio_device_debug_attr_read_all(struct iio_device *dev,
- int (*cb)(struct iio_device *dev, const char *attr,
- const char *value, size_t len, void *d),
- void *data);
-
-
-/** @brief Set the value of the given debug attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * debug attribute
- * @param src A NULL-terminated string to set the debug attribute to
- * @return On success, the number of bytes written
- * @return On error, a negative errno code is returned
- *
- * <b>NOTE:</b>By passing NULL as the "attr" argument to
- * iio_device_debug_attr_write, it is now possible to write all of the
- * debug attributes of a device.
- *
- * The buffer must contain one block of data per debug attribute of the device,
- * by the order they appear in the iio_device structure.
- *
- * The first four bytes of one block correspond to a 32-bit signed value in
- * network order. If negative, the debug attribute is not written; if positive,
- * it corresponds to the length of the data to write. In that case, the rest
- * of the block must contain the data. */
-__api ssize_t iio_device_debug_attr_write(const struct iio_device *dev,
- const char *attr, const char *src);
-
-
-/** @brief Set the value of the given debug attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * debug attribute
- * @param src A pointer to the data to be written
- * @param len The number of bytes that should be written
- * @return On success, the number of bytes written
- * @return On error, a negative errno code is returned */
-__api ssize_t iio_device_debug_attr_write_raw(const struct iio_device *dev,
- const char *attr, const void *src, size_t len);
-
-
-/** @brief Set the values of all debug attributes
- * @param dev A pointer to an iio_device structure
- * @param cb A pointer to a callback function
- * @param data A pointer that will be passed to the callback function
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned
- *
- * <b>NOTE:</b> This function is especially useful when used with the network
- * backend, as all the debug attributes are written in one single command. */
-__api int iio_device_debug_attr_write_all(struct iio_device *dev,
- ssize_t (*cb)(struct iio_device *dev,
- const char *attr, void *buf, size_t len, void *d),
- void *data);
-
-
-/** @brief Read the content of the given debug attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * debug attribute
- * @param val A pointer to a bool variable where the value should be stored
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_debug_attr_read_bool(const struct iio_device *dev,
- const char *attr, bool *val);
-
-
-/** @brief Read the content of the given debug attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * debug attribute
- * @param val A pointer to a long long variable where the value should be stored
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_debug_attr_read_longlong(const struct iio_device *dev,
- const char *attr, long long *val);
-
-
-/** @brief Read the content of the given debug attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * debug attribute
- * @param val A pointer to a double variable where the value should be stored
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_debug_attr_read_double(const struct iio_device *dev,
- const char *attr, double *val);
-
-
-/** @brief Set the value of the given debug attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * debug attribute
- * @param val A bool value to set the debug attribute to
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_debug_attr_write_bool(const struct iio_device *dev,
- const char *attr, bool val);
-
-
-/** @brief Set the value of the given debug attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * debug attribute
- * @param val A long long value to set the debug attribute to
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_debug_attr_write_longlong(const struct iio_device *dev,
- const char *attr, long long val);
-
-
-/** @brief Set the value of the given debug attribute
- * @param dev A pointer to an iio_device structure
- * @param attr A NULL-terminated string corresponding to the name of the
- * debug attribute
- * @param val A double value to set the debug attribute to
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_debug_attr_write_double(const struct iio_device *dev,
- const char *attr, double val);
-
-
-/** @brief Identify the channel or debug attribute corresponding to a filename
- * @param dev A pointer to an iio_device structure
- * @param filename A NULL-terminated string corresponding to the filename
- * @param chn A pointer to a pointer of an iio_channel structure. The pointed
- * pointer will be set to the address of the iio_channel structure if the
- * filename correspond to the attribute of a channel, or NULL otherwise.
- * @param attr A pointer to a NULL-terminated string. The pointer
- * pointer will be set to point to the name of the attribute corresponding to
- * the filename.
- * @return On success, 0 is returned, and *chn and *attr are modified.
- * @return On error, a negative errno code is returned. *chn and *attr are not
- * modified. */
-__api int iio_device_identify_filename(const struct iio_device *dev,
- const char *filename, struct iio_channel **chn,
- const char **attr);
-
-
-/** @brief Set the value of a hardware register
- * @param dev A pointer to an iio_device structure
- * @param address The address of the register
- * @param value The value to set the register to
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_reg_write(struct iio_device *dev,
- uint32_t address, uint32_t value);
-
-
-/** @brief Get the value of a hardware register
- * @param dev A pointer to an iio_device structure
- * @param address The address of the register
- * @param value A pointer to the variable where the value will be written
- * @return On success, 0 is returned
- * @return On error, a negative errno code is returned */
-__api int iio_device_reg_read(struct iio_device *dev,
- uint32_t address, uint32_t *value);
-
-
-/** @} */
-
-#ifdef __cplusplus
-}
-#endif
-
-#undef __api
-
-#endif /* __IIO_H__ */
diff --git a/iiod-client.c b/iiod-client.c
deleted file mode 100644
index 1798cd6..0000000
--- a/iiod-client.c
+++ /dev/null
@@ -1,674 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2014-2016 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.
- *
- */
-
-#include "debug.h"
-#include "iiod-client.h"
-#include "iio-lock.h"
-#include "iio-private.h"
-
-#include <errno.h>
-#include <inttypes.h>
-#include <string.h>
-#include <stdio.h>
-
-struct iiod_client {
- struct iio_context_pdata *pdata;
- const struct iiod_client_ops *ops;
- struct iio_mutex *lock;
-};
-
-static ssize_t iiod_client_read_integer(struct iiod_client *client,
- void *desc, int *val)
-{
- unsigned int i;
- char buf[1024], *ptr = NULL, *end;
- ssize_t ret;
- int value;
-
- do {
- ret = client->ops->read_line(client->pdata,
- desc, buf, sizeof(buf));
- if (ret < 0)
- return ret;
-
- for (i = 0; i < (unsigned int) ret; i++) {
- if (buf[i] != '\n') {
- if (!ptr)
- ptr = &buf[i];
- } else if (!!ptr) {
- break;
- }
- }
- } while (!ptr);
-
- buf[i] = '\0';
-
- value = (int) strtol(ptr, &end, 10);
- if (ptr == end)
- return -EINVAL;
-
- *val = value;
- return 0;
-}
-
-static int iiod_client_exec_command(struct iiod_client *client,
- void *desc, const char *cmd)
-{
- int resp;
- ssize_t ret;
-
- ret = client->ops->write(client->pdata, desc, cmd, strlen(cmd));
- if (ret < 0)
- return (int) ret;
-
- ret = iiod_client_read_integer(client, desc, &resp);
- return ret < 0 ? (int) ret : resp;
-}
-
-static ssize_t iiod_client_write_all(struct iiod_client *client,
- void *desc, const void *src, size_t len)
-{
- struct iio_context_pdata *pdata = client->pdata;
- const struct iiod_client_ops *ops = client->ops;
- uintptr_t ptr = (uintptr_t) src;
-
- while (len) {
- ssize_t ret = ops->write(pdata, desc, (const void *) ptr, len);
-
- if (ret < 0) {
- if (ret == -EINTR)
- continue;
- else
- return ret;
- }
-
- if (ret == 0)
- return -EPIPE;
-
- ptr += ret;
- len -= ret;
- }
-
- return (ssize_t) (ptr - (uintptr_t) src);
-}
-
-static ssize_t iiod_client_read_all(struct iiod_client *client,
- void *desc, void *dst, size_t len)
-{
- struct iio_context_pdata *pdata = client->pdata;
- const struct iiod_client_ops *ops = client->ops;
- uintptr_t ptr = (uintptr_t) dst;
-
- while (len) {
- ssize_t ret = ops->read(pdata, desc, (void *) ptr, len);
-
- if (ret < 0) {
- if (ret == -EINTR)
- continue;
- else
- return ret;
- }
-
- if (ret == 0)
- return -EPIPE;
-
- ptr += ret;
- len -= ret;
- }
-
- return (ssize_t) (ptr - (uintptr_t) dst);
-}
-
-struct iiod_client * iiod_client_new(struct iio_context_pdata *pdata,
- struct iio_mutex *lock, const struct iiod_client_ops *ops)
-{
- struct iiod_client *client;
-
- client = malloc(sizeof(*client));
- if (!client) {
- errno = ENOMEM;
- return NULL;
- }
-
- client->lock = lock;
- client->pdata = pdata;
- client->ops = ops;
- return client;
-}
-
-void iiod_client_destroy(struct iiod_client *client)
-{
- free(client);
-}
-
-int iiod_client_get_version(struct iiod_client *client, void *desc,
- unsigned int *major, unsigned int *minor, char *git_tag)
-{
- struct iio_context_pdata *pdata = client->pdata;
- const struct iiod_client_ops *ops = client->ops;
- char buf[256], *ptr = buf, *end;
- long maj, min;
- int ret;
-
- iio_mutex_lock(client->lock);
-
- ret = ops->write(pdata, desc, "VERSION\r\n", sizeof("VERSION\r\n") - 1);
- if (ret < 0) {
- iio_mutex_unlock(client->lock);
- return ret;
- }
-
- ret = ops->read_line(pdata, desc, buf, sizeof(buf));
- iio_mutex_unlock(client->lock);
-
- if (ret < 0)
- return ret;
-
- maj = strtol(ptr, &end, 10);
- if (ptr == end)
- return -EIO;
-
- ptr = end + 1;
- min = strtol(ptr, &end, 10);
- if (ptr == end)
- return -EIO;
-
- ptr = end + 1;
- if (buf + ret < ptr + 8)
- return -EIO;
-
- /* Strip the \n */
- ptr[buf + ret - ptr - 1] = '\0';
-
- if (major)
- *major = (unsigned int) maj;
- if (minor)
- *minor = (unsigned int) min;
- if (git_tag)
- strncpy(git_tag, ptr, 8);
- return 0;
-}
-
-int iiod_client_get_trigger(struct iiod_client *client, void *desc,
- const struct iio_device *dev, const struct iio_device **trigger)
-{
- const struct iio_context *ctx = iio_device_get_context(dev);
- unsigned int i, nb_devices = iio_context_get_devices_count(ctx);
- char buf[1024];
- unsigned int name_len;
- int ret;
-
- iio_snprintf(buf, sizeof(buf), "GETTRIG %s\r\n",
- iio_device_get_id(dev));
-
- iio_mutex_lock(client->lock);
- ret = iiod_client_exec_command(client, desc, buf);
-
- if (ret == 0)
- *trigger = NULL;
- if (ret <= 0)
- goto out_unlock;
-
- if ((unsigned int) ret > sizeof(buf) - 1) {
- ret = -EIO;
- goto out_unlock;
- }
-
- name_len = ret;
-
- ret = (int) iiod_client_read_all(client, desc, buf, name_len + 1);
- if (ret < 0)
- goto out_unlock;
-
- ret = -ENXIO;
-
- for (i = 0; i < nb_devices; i++) {
- struct iio_device *cur = iio_context_get_device(ctx, i);
-
- if (iio_device_is_trigger(cur)) {
- const char *name = iio_device_get_name(cur);
-
- if (!name)
- continue;
-
- if (!strncmp(name, buf, name_len)) {
- *trigger = cur;
- ret = 0;
- goto out_unlock;
- }
- }
- }
-
-out_unlock:
- iio_mutex_unlock(client->lock);
- return ret;
-}
-
-int iiod_client_set_trigger(struct iiod_client *client, void *desc,
- const struct iio_device *dev, const struct iio_device *trigger)
-{
- char buf[1024];
- int ret;
-
- if (trigger) {
- iio_snprintf(buf, sizeof(buf), "SETTRIG %s %s\r\n",
- iio_device_get_id(dev),
- iio_device_get_id(trigger));
- } else {
- iio_snprintf(buf, sizeof(buf), "SETTRIG %s\r\n",
- iio_device_get_id(dev));
- }
-
- iio_mutex_lock(client->lock);
- ret = iiod_client_exec_command(client, desc, buf);
- iio_mutex_unlock(client->lock);
- return ret;
-}
-
-int iiod_client_set_kernel_buffers_count(struct iiod_client *client, void *desc,
- const struct iio_device *dev, unsigned int nb_blocks)
-{
- int ret;
- char buf[1024];
-
- iio_snprintf(buf, sizeof(buf), "SET %s BUFFERS_COUNT %u\r\n",
- iio_device_get_id(dev), nb_blocks);
-
- iio_mutex_lock(client->lock);
- ret = iiod_client_exec_command(client, desc, buf);
- iio_mutex_unlock(client->lock);
- return ret;
-}
-
-int iiod_client_set_timeout(struct iiod_client *client,
- void *desc, unsigned int timeout)
-{
- int ret;
- char buf[1024];
-
- iio_snprintf(buf, sizeof(buf), "TIMEOUT %u\r\n", timeout);
-
- iio_mutex_lock(client->lock);
- ret = iiod_client_exec_command(client, desc, buf);
- iio_mutex_unlock(client->lock);
- return ret;
-}
-
-static int iiod_client_discard(struct iiod_client *client, void *desc,
- char *buf, size_t buf_len, size_t to_discard)
-{
- do {
- size_t read_len;
- ssize_t ret;
-
- if (to_discard > buf_len)
- read_len = buf_len;
- else
- read_len = to_discard;
-
- ret = iiod_client_read_all(client, desc, buf, read_len);
- if (ret < 0)
- return ret;
-
- to_discard -= (size_t) ret;
- } while (to_discard);
-
- return 0;
-}
-
-ssize_t iiod_client_read_attr(struct iiod_client *client, void *desc,
- const struct iio_device *dev, const struct iio_channel *chn,
- const char *attr, char *dest, size_t len, enum iio_attr_type type)
-{
- const char *id = iio_device_get_id(dev);
- char buf[1024];
- ssize_t ret;
-
- if (attr) {
- if (chn) {
- if (!iio_channel_find_attr(chn, attr))
- return -ENOENT;
- } else {
- switch (type) {
- case IIO_ATTR_TYPE_DEVICE:
- if (!iio_device_find_attr(dev, attr))
- return -ENOENT;
- break;
- case IIO_ATTR_TYPE_DEBUG:
- if (!iio_device_find_debug_attr(dev, attr))
- return -ENOENT;
- break;
- case IIO_ATTR_TYPE_BUFFER:
- if (!iio_device_find_buffer_attr(dev, attr))
- return -ENOENT;
- break;
- default:
- return -EINVAL;
- }
- }
- }
-
- if (chn) {
- iio_snprintf(buf, sizeof(buf), "READ %s %s %s %s\r\n", id,
- iio_channel_is_output(chn) ? "OUTPUT" : "INPUT",
- iio_channel_get_id(chn), attr ? attr : "");
- } else {
- switch (type) {
- case IIO_ATTR_TYPE_DEVICE:
- iio_snprintf(buf, sizeof(buf), "READ %s %s\r\n",
- id, attr ? attr : "");
- break;
- case IIO_ATTR_TYPE_DEBUG:
- iio_snprintf(buf, sizeof(buf), "READ %s DEBUG %s\r\n",
- id, attr ? attr : "");
- break;
- case IIO_ATTR_TYPE_BUFFER:
- iio_snprintf(buf, sizeof(buf), "READ %s BUFFER %s\r\n",
- id, attr ? attr : "");
- break;
- }
- }
-
- iio_mutex_lock(client->lock);
-
- ret = (ssize_t) iiod_client_exec_command(client, desc, buf);
- if (ret < 0)
- goto out_unlock;
-
- if ((size_t) ret + 1 > len) {
- iiod_client_discard(client, desc, dest, len, ret + 1);
- ret = -EIO;
- goto out_unlock;
- }
-
- /* +1: Also read the trailing \n */
- ret = iiod_client_read_all(client, desc, dest, ret + 1);
-
- if (ret > 0) {
- /* Discard the trailing \n */
- ret--;
-
- /* Replace it with a \0 just in case */
- dest[ret] = '\0';
- }
-
-out_unlock:
- iio_mutex_unlock(client->lock);
- return ret;
-}
-
-ssize_t iiod_client_write_attr(struct iiod_client *client, void *desc,
- const struct iio_device *dev, const struct iio_channel *chn,
- const char *attr, const char *src, size_t len, enum iio_attr_type type)
-{
- struct iio_context_pdata *pdata = client->pdata;
- const struct iiod_client_ops *ops = client->ops;
- const char *id = iio_device_get_id(dev);
- char buf[1024];
- ssize_t ret;
- int resp;
-
- if (attr) {
- if (chn) {
- if (!iio_channel_find_attr(chn, attr))
- return -ENOENT;
- } else {
- switch (type) {
- case IIO_ATTR_TYPE_DEVICE:
- if (!iio_device_find_attr(dev, attr))
- return -ENOENT;
- break;
- case IIO_ATTR_TYPE_DEBUG:
- if (!iio_device_find_debug_attr(dev, attr))
- return -ENOENT;
- break;
- case IIO_ATTR_TYPE_BUFFER:
- if (!iio_device_find_buffer_attr(dev, attr))
- return -ENOENT;
- break;
- default:
- return -EINVAL;
- }
- }
- }
-
- if (chn) {
- iio_snprintf(buf, sizeof(buf), "WRITE %s %s %s %s %lu\r\n", id,
- iio_channel_is_output(chn) ? "OUTPUT" : "INPUT",
- iio_channel_get_id(chn), attr ? attr : "",
- (unsigned long) len);
- } else {
- switch (type) {
- case IIO_ATTR_TYPE_DEVICE:
- iio_snprintf(buf, sizeof(buf), "WRITE %s %s %lu\r\n",
- id, attr ? attr : "", (unsigned long) len);
- break;
- case IIO_ATTR_TYPE_DEBUG:
- iio_snprintf(buf, sizeof(buf), "WRITE %s DEBUG %s %lu\r\n",
- id, attr ? attr : "", (unsigned long) len);
- break;
- case IIO_ATTR_TYPE_BUFFER:
- iio_snprintf(buf, sizeof(buf), "WRITE %s BUFFER %s %lu\r\n",
- id, attr ? attr : "", (unsigned long) len);
- break;
- }
- }
-
- iio_mutex_lock(client->lock);
- ret = ops->write(pdata, desc, buf, strlen(buf));
- if (ret < 0)
- goto out_unlock;
-
- ret = iiod_client_write_all(client, desc, src, len);
- if (ret < 0)
- goto out_unlock;
-
- ret = iiod_client_read_integer(client, desc, &resp);
- if (ret < 0)
- goto out_unlock;
-
- ret = (ssize_t) resp;
-
-out_unlock:
- iio_mutex_unlock(client->lock);
- return ret;
-}
-
-struct iio_context * iiod_client_create_context(
- struct iiod_client *client, void *desc)
-{
- struct iio_context *ctx = NULL;
- size_t xml_len;
- char *xml;
- int ret;
-
- iio_mutex_lock(client->lock);
- ret = iiod_client_exec_command(client, desc, "PRINT\r\n");
- if (ret < 0)
- goto out_unlock;
-
- xml_len = (size_t) ret;
- xml = malloc(xml_len + 1);
- if (!xml) {
- ret = -ENOMEM;
- goto out_unlock;
- }
-
- /* +1: Also read the trailing \n */
- ret = (int) iiod_client_read_all(client, desc, xml, xml_len + 1);
- if (ret < 0)
- goto out_free_xml;
-
- ctx = iio_create_xml_context_mem(xml, xml_len);
- if (!ctx)
- ret = -errno;
-
-out_free_xml:
- free(xml);
-out_unlock:
- iio_mutex_unlock(client->lock);
- if (!ctx)
- errno = -ret;
- return ctx;
-}
-
-int iiod_client_open_unlocked(struct iiod_client *client, void *desc,
- const struct iio_device *dev, size_t samples_count, bool cyclic)
-{
- char buf[1024], *ptr;
- size_t i;
-
- iio_snprintf(buf, sizeof(buf), "OPEN %s %lu ",
- iio_device_get_id(dev), (unsigned long) samples_count);
- ptr = buf + strlen(buf);
-
- for (i = dev->words; i > 0; i--, ptr += 8) {
- iio_snprintf(ptr, (ptr - buf) + i * 8, "%08" PRIx32,
- dev->mask[i - 1]);
- }
-
- strcpy(ptr, cyclic ? " CYCLIC\r\n" : "\r\n");
-
- return iiod_client_exec_command(client, desc, buf);
-}
-
-int iiod_client_close_unlocked(struct iiod_client *client, void *desc,
- const struct iio_device *dev)
-{
- char buf[1024];
-
- iio_snprintf(buf, sizeof(buf), "CLOSE %s\r\n", iio_device_get_id(dev));
- return iiod_client_exec_command(client, desc, buf);
-}
-
-static int iiod_client_read_mask(struct iiod_client *client,
- void *desc, uint32_t *mask, size_t words)
-{
- size_t i;
- ssize_t ret;
- char *buf, *ptr;
-
- buf = malloc(words * 8 + 1);
- if (!buf)
- return -ENOMEM;
-
- ret = iiod_client_read_all(client, desc, buf, words * 8 + 1);
- if (ret < 0)
- goto out_buf_free;
- else
- ret = 0;
-
- buf[words*8] = '\0';
-
- DEBUG("Reading mask\n");
-
- for (i = words, ptr = buf; i > 0; i--) {
- sscanf(ptr, "%08" PRIx32, &mask[i - 1]);
- DEBUG("mask[%lu] = 0x%08" PRIx32 "\n",
- (unsigned long)(i - 1), mask[i - 1]);
-
- ptr = (char *) ((uintptr_t) ptr + 8);
- }
-
-out_buf_free:
- free(buf);
- return (int) ret;
-}
-
-ssize_t iiod_client_read_unlocked(struct iiod_client *client, void *desc,
- const struct iio_device *dev, void *dst, size_t len,
- uint32_t *mask, size_t words)
-{
- unsigned int nb_channels = iio_device_get_channels_count(dev);
- uintptr_t ptr = (uintptr_t) dst;
- char buf[1024];
- ssize_t ret, read = 0;
-
- if (!len || words != (nb_channels + 31) / 32)
- return -EINVAL;
-
- iio_snprintf(buf, sizeof(buf), "READBUF %s %lu\r\n",
- iio_device_get_id(dev), (unsigned long) len);
-
- ret = iiod_client_write_all(client, desc, buf, strlen(buf));
- if (ret < 0)
- return ret;
-
- do {
- int to_read;
-
- ret = iiod_client_read_integer(client, desc, &to_read);
- if (ret < 0)
- return ret;
- if (to_read < 0)
- return (ssize_t) to_read;
- if (!to_read)
- break;
-
- if (mask) {
- ret = iiod_client_read_mask(client, desc, mask, words);
- if (ret < 0)
- return ret;
-
- mask = NULL; /* We read the mask only once */
- }
-
- ret = iiod_client_read_all(client, desc, (char *) ptr, to_read);
- if (ret < 0)
- return ret;
-
- ptr += ret;
- read += ret;
- len -= ret;
- } while (len);
-
- return read;
-}
-
-ssize_t iiod_client_write_unlocked(struct iiod_client *client, void *desc,
- const struct iio_device *dev, const void *src, size_t len)
-{
- ssize_t ret;
- char buf[1024];
- int val;
-
- iio_snprintf(buf, sizeof(buf), "WRITEBUF %s %lu\r\n",
- dev->id, (unsigned long) len);
-
- ret = iiod_client_write_all(client, desc, buf, strlen(buf));
- if (ret < 0)
- return ret;
-
- ret = iiod_client_read_integer(client, desc, &val);
- if (ret < 0)
- return ret;
- if (val < 0)
- return (ssize_t) val;
-
- ret = iiod_client_write_all(client, desc, src, len);
- if (ret < 0)
- return ret;
-
- ret = iiod_client_read_integer(client, desc, &val);
- if (ret < 0)
- return ret;
- if (val < 0)
- return (ssize_t) val;
-
- return (ssize_t) len;
-}
diff --git a/iiod-client.h b/iiod-client.h
deleted file mode 100644
index dcf2482..0000000
--- a/iiod-client.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2015 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.
- *
- */
-
-#ifndef _IIOD_CLIENT_H
-#define _IIOD_CLIENT_H
-
-#include "iio-private.h"
-
-struct iio_mutex;
-struct iiod_client;
-struct iio_context_pdata;
-
-struct iiod_client_ops {
- ssize_t (*write)(struct iio_context_pdata *pdata,
- void *desc, const char *src, size_t len);
- ssize_t (*read)(struct iio_context_pdata *pdata,
- void *desc, char *dst, size_t len);
- ssize_t (*read_line)(struct iio_context_pdata *pdata,
- void *desc, char *dst, size_t len);
-};
-
-struct iiod_client * iiod_client_new(struct iio_context_pdata *pdata,
- struct iio_mutex *lock, const struct iiod_client_ops *ops);
-void iiod_client_destroy(struct iiod_client *client);
-
-int iiod_client_get_version(struct iiod_client *client, void *desc,
- unsigned int *major, unsigned int *minor, char *git_tag);
-int iiod_client_get_trigger(struct iiod_client *client, void *desc,
- const struct iio_device *dev,
- const struct iio_device **trigger);
-int iiod_client_set_trigger(struct iiod_client *client, void *desc,
- const struct iio_device *dev, const struct iio_device *trigger);
-int iiod_client_set_kernel_buffers_count(struct iiod_client *client,
- void *desc, const struct iio_device *dev, unsigned int nb_blocks);
-int iiod_client_set_timeout(struct iiod_client *client,
- void *desc, unsigned int timeout);
-ssize_t iiod_client_read_attr(struct iiod_client *client, void *desc,
- const struct iio_device *dev, const struct iio_channel *chn,
- const char *attr, char *dest, size_t len, enum iio_attr_type type);
-ssize_t iiod_client_write_attr(struct iiod_client *client, void *desc,
- const struct iio_device *dev, const struct iio_channel *chn,
- const char *attr, const char *src, size_t len, enum iio_attr_type type);
-int iiod_client_open_unlocked(struct iiod_client *client, void *desc,
- const struct iio_device *dev, size_t samples_count,
- bool cyclic);
-int iiod_client_close_unlocked(struct iiod_client *client, void *desc,
- const struct iio_device *dev);
-ssize_t iiod_client_read_unlocked(struct iiod_client *client, void *desc,
- const struct iio_device *dev, void *dst, size_t len,
- uint32_t *mask, size_t words);
-ssize_t iiod_client_write_unlocked(struct iiod_client *client, void *desc,
- const struct iio_device *dev, const void *src, size_t len);
-struct iio_context * iiod_client_create_context(
- struct iiod_client *client, void *desc);
-
-#endif /* _IIOD_CLIENT_H */
diff --git a/iiod/.gitignore b/iiod/.gitignore
deleted file mode 100644
index 81ef20f..0000000
--- a/iiod/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-iiod
-parser.c
-parser.h
-lexer.c
diff --git a/iiod/CMakeLists.txt b/iiod/CMakeLists.txt
deleted file mode 100644
index ab30605..0000000
--- a/iiod/CMakeLists.txt
+++ /dev/null
@@ -1,81 +0,0 @@
-cmake_minimum_required(VERSION 2.8.7)
-project(iiod C)
-
-include(FindBISON)
-include(FindFLEX)
-
-flex_target(lexer
- ${CMAKE_CURRENT_SOURCE_DIR}/lexer.l ${CMAKE_CURRENT_BINARY_DIR}/lexer.c)
-bison_target(parser
- ${CMAKE_CURRENT_SOURCE_DIR}/parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.c)
-add_flex_bison_dependency(lexer parser)
-include_directories(${CMAKE_CURRENT_BINARY_DIR})
-include_directories(${CMAKE_CURRENT_SOURCE_DIR})
-
-set(IIOD_CFILES iiod.c ops.c thread-pool.c ${BISON_parser_OUTPUTS} ${FLEX_lexer_OUTPUTS})
-
-find_library(LIBAIO_LIBRARIES aio)
-find_path(LIBAIO_INCLUDE_DIR libaio.h)
-
-if (LIBAIO_LIBRARIES AND LIBAIO_INCLUDE_DIR)
- option(ENABLE_AIO "Build IIOD with async. I/O support" ON)
-endif ()
-
-include(CheckTypeSize)
-set(CMAKE_EXTRA_INCLUDE_FILES linux/usb/functionfs.h)
-check_type_size("struct usb_functionfs_descs_head_v2" FUNCTIONFS_V2)
-set(CMAKE_EXTRA_INCLUDE_FILES)
-
-if (HAVE_FUNCTIONFS_V2)
- OPTION(WITH_IIOD_USBD "Add support for USB through FunctionFS within IIOD" ${ENABLE_AIO})
-
- if (WITH_IIOD_USBD)
- if (NOT ENABLE_AIO)
- message(SEND_ERROR "USB support in IIOD requires async. I/O support")
- endif (NOT ENABLE_AIO)
-
- set(IIOD_CFILES ${IIOD_CFILES} usbd.c)
- endif (WITH_IIOD_USBD)
-endif (HAVE_FUNCTIONFS_V2)
-
-include(CheckSymbolExists)
-set(CMAKE_REQUIRED_LIBRARIES ${PTHREAD_LIBRARIES})
-check_symbol_exists(pthread_setname_np "pthread.h" HAS_PTHREAD_SETNAME_NP)
-set(CMAKE_REQUIRED_LIBRARIES)
-
-add_executable(iiod ${IIOD_CFILES})
-set_target_properties(iiod PROPERTIES
- C_STANDARD 99
- C_STANDARD_REQUIRED ON
- C_EXTENSIONS OFF
-)
-target_link_libraries(iiod iio ${PTHREAD_LIBRARIES} ${AVAHI_LIBRARIES})
-
-if (ENABLE_AIO)
- add_definitions(-DWITH_AIO=1)
- include_directories(${LIBAIO_INCLUDE_DIR})
- target_link_libraries(iiod ${LIBAIO_LIBRARIES})
-endif ()
-
-add_definitions(-D_GNU_SOURCE=1)
-
-if(NOT SKIP_INSTALL_ALL)
- install(TARGETS iiod RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR})
-endif()
-
-if (WITH_SYSTEMD)
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/init/iiod.service.cmakein ${PROJECT_BINARY_DIR}/init/iiod.service)
- install(FILES ${PROJECT_BINARY_DIR}/init/iiod.service DESTINATION ${SYSTEMD_UNIT_INSTALL_DIR})
-endif()
-
-if (WITH_SYSVINIT)
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/init/iiod.init.cmakein ${PROJECT_BINARY_DIR}/init/iiod)
- install(FILES ${PROJECT_BINARY_DIR}/init/iiod
- PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
- DESTINATION ${SYSVINIT_INSTALL_DIR})
-endif()
-
-if (WITH_UPSTART)
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/init/iiod.conf.cmakein ${PROJECT_BINARY_DIR}/init/iiod.conf)
- install(FILES ${PROJECT_BINARY_DIR}/init/iiod.conf DESTINATION ${UPSTART_CONF_INSTALL_DIR})
-endif()
diff --git a/iiod/iiod.c b/iiod/iiod.c
deleted file mode 100644
index 9d38426..0000000
--- a/iiod/iiod.c
+++ /dev/null
@@ -1,471 +0,0 @@
-/*
- * 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.
- *
- * */
-
-#include "../debug.h"
-#include "../iio.h"
-#include "../iio-config.h"
-#include "ops.h"
-#include "thread-pool.h"
-
-#include <arpa/inet.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <getopt.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <poll.h>
-#include <pthread.h>
-#include <signal.h>
-#include <stdbool.h>
-#include <string.h>
-#include <sys/eventfd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <unistd.h>
-
-#ifdef HAVE_AVAHI
-#include <avahi-common/simple-watch.h>
-#include <avahi-client/client.h>
-#include <avahi-client/publish.h>
-#endif
-
-#define MY_NAME "iiod"
-
-#define IIOD_PORT 30431
-
-struct client_data {
- int fd;
- bool debug;
- struct iio_context *ctx;
-};
-
-bool server_demux;
-
-struct thread_pool *main_thread_pool;
-
-
-static struct sockaddr_in sockaddr = {
- .sin_family = AF_INET,
-#if __BYTE_ORDER == __LITTLE_ENDIAN
- .sin_addr.s_addr = __bswap_constant_32(INADDR_ANY),
- .sin_port = __bswap_constant_16(IIOD_PORT),
-#else
- .sin_addr.s_addr = INADDR_ANY,
- .sin_port = IIOD_PORT,
-#endif
-};
-
-#ifdef HAVE_IPV6
-static struct sockaddr_in6 sockaddr6 = {
- .sin6_family = AF_INET6,
- .sin6_addr = IN6ADDR_ANY_INIT,
-#if __BYTE_ORDER == __LITTLE_ENDIAN
- .sin6_port = __bswap_constant_16(IIOD_PORT),
-#else
- .sin6_port = IIOD_PORT,
-#endif
-};
-#endif /* HAVE_IPV6 */
-
-static const struct option options[] = {
- {"help", no_argument, 0, 'h'},
- {"version", no_argument, 0, 'V'},
- {"debug", no_argument, 0, 'd'},
- {"demux", no_argument, 0, 'D'},
- {"interactive", no_argument, 0, 'i'},
- {"aio", no_argument, 0, 'a'},
- {"ffs", required_argument, 0, 'F'},
- {"nb-pipes", required_argument, 0, 'n'},
- {0, 0, 0, 0},
-};
-
-static const char *options_descriptions[] = {
- "Show this help and quit.",
- "Display the version of this program.",
- "Use alternative (incompatible) debug interface.",
- "Demux channels directly on the server.",
- "Run " MY_NAME " in the controlling terminal.",
- "Use asynchronous I/O.",
- "Use the given FunctionFS mountpoint to serve over USB",
- "Specify the number of USB pipes (ep couples) to use",
-};
-
-#ifdef HAVE_AVAHI
-static AvahiSimplePoll *avahi_poll;
-static AvahiClient *avahi_client;
-
-static void __avahi_group_cb(AvahiEntryGroup *group,
- AvahiEntryGroupState state, void *d)
-{
-}
-
-static void __avahi_client_cb(AvahiClient *client,
- AvahiClientState state, void *d)
-{
- AvahiEntryGroup *group;
-
- if (state != AVAHI_CLIENT_S_RUNNING)
- return;
-
- group = avahi_entry_group_new(client, __avahi_group_cb, NULL);
-
- if (group && !avahi_entry_group_add_service(group,
- AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
- 0, "iio", "_iio._tcp", NULL, NULL, IIOD_PORT, NULL)) {
- avahi_entry_group_commit(group);
- INFO("Registered to ZeroConf server %s\n",
- avahi_client_get_version_string(client));
- }
-
- /* NOTE: group is freed by avahi_client_free */
-}
-
-static int start_avahi(void)
-{
- int ret = ENOMEM;
-
- avahi_poll = avahi_simple_poll_new();
- if (!avahi_poll)
- return -ENOMEM;
-
- avahi_client = avahi_client_new(avahi_simple_poll_get(avahi_poll),
- 0, __avahi_client_cb, NULL, &ret);
- if (!avahi_client) {
- avahi_simple_poll_free(avahi_poll);
- return -ret;
- }
-
- return 0;
-}
-
-static void stop_avahi(void)
-{
- avahi_client_free(avahi_client);
- avahi_simple_poll_free(avahi_poll);
-}
-#endif /* HAVE_AVAHI */
-
-
-static void usage(void)
-{
- unsigned int i;
-
- printf("Usage:\n\t" MY_NAME " [OPTIONS ...]\n\nOptions:\n");
- for (i = 0; options[i].name; i++)
- printf("\t-%c, --%s\n\t\t\t%s\n",
- options[i].val, options[i].name,
- options_descriptions[i]);
-}
-
-static void client_thd(struct thread_pool *pool, void *d)
-{
- struct client_data *cdata = d;
-
- interpreter(cdata->ctx, cdata->fd, cdata->fd, cdata->debug,
- true, false, pool);
-
- INFO("Client exited\n");
- close(cdata->fd);
- free(cdata);
-}
-
-static void set_handler(int signal, void (*handler)(int))
-{
- struct sigaction sig;
- sigaction(signal, NULL, &sig);
- sig.sa_handler = handler;
- sigaction(signal, &sig, NULL);
-}
-
-static void sig_handler(int sig)
-{
- thread_pool_stop(main_thread_pool);
-}
-
-static int main_interactive(struct iio_context *ctx, bool verbose, bool use_aio)
-{
- int flags;
-
- if (!use_aio) {
- flags = fcntl(STDIN_FILENO, F_GETFL);
- fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK);
- flags = fcntl(STDOUT_FILENO, F_GETFL);
- fcntl(STDOUT_FILENO, F_SETFL, flags | O_NONBLOCK);
- }
-
- interpreter(ctx, STDIN_FILENO, STDOUT_FILENO, verbose,
- false, use_aio, main_thread_pool);
- return EXIT_SUCCESS;
-}
-
-static int main_server(struct iio_context *ctx, bool debug)
-{
- int ret, fd = -1, yes = 1,
- keepalive_time = 10,
- keepalive_intvl = 10,
- keepalive_probes = 6;
- struct pollfd pfd[2];
- char err_str[1024];
- bool ipv6;
-#ifdef HAVE_AVAHI
- bool avahi_started;
-#endif
-
- INFO("Starting IIO Daemon version %u.%u\n",
- LIBIIO_VERSION_MAJOR, LIBIIO_VERSION_MINOR);
-
-#ifdef HAVE_IPV6
- fd = socket(AF_INET6, SOCK_STREAM | SOCK_NONBLOCK, 0);
-#endif
- ipv6 = (fd >= 0);
- if (!ipv6)
- fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
- if (fd < 0) {
- iio_strerror(errno, err_str, sizeof(err_str));
- ERROR("Unable to create socket: %s\n", err_str);
- return EXIT_FAILURE;
- }
-
- setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
-
-#ifdef HAVE_IPV6
- if (ipv6)
- ret = bind(fd, (struct sockaddr *) &sockaddr6,
- sizeof(sockaddr6));
-#endif
- if (!ipv6)
- ret = bind(fd, (struct sockaddr *) &sockaddr, sizeof(sockaddr));
- if (ret < 0) {
- iio_strerror(errno, err_str, sizeof(err_str));
- ERROR("Bind failed: %s\n", err_str);
- goto err_close_socket;
- }
-
- if (ipv6)
- INFO("IPv6 support enabled\n");
-
- if (listen(fd, 16) < 0) {
- iio_strerror(errno, err_str, sizeof(err_str));
- ERROR("Unable to mark as passive socket: %s\n", err_str);
- goto err_close_socket;
- }
-
-#ifdef HAVE_AVAHI
- avahi_started = !start_avahi();
-#endif
-
- pfd[0].fd = fd;
- pfd[0].events = POLLIN;
- pfd[0].revents = 0;
- pfd[1].fd = thread_pool_get_poll_fd(main_thread_pool);
- pfd[1].events = POLLIN;
- pfd[1].revents = 0;
-
- while (true) {
- struct client_data *cdata;
- struct sockaddr_in caddr;
- socklen_t addr_len = sizeof(caddr);
- int new;
-
- poll_nointr(pfd, 2);
-
- if (pfd[1].revents & POLLIN) /* STOP event */
- break;
-
- new = accept4(fd, (struct sockaddr *) &caddr, &addr_len,
- SOCK_NONBLOCK);
- if (new == -1) {
- if (errno == EAGAIN || errno == EINTR)
- continue;
- iio_strerror(errno, err_str, sizeof(err_str));
- ERROR("Failed to create connection socket: %s\n",
- err_str);
- continue;
- }
-
- cdata = malloc(sizeof(*cdata));
- if (!cdata) {
- WARNING("Unable to allocate memory for client\n");
- close(new);
- continue;
- }
-
- /* Configure the socket to send keep-alive packets every 10s,
- * and disconnect the client if no reply was received for one
- * minute. */
- setsockopt(new, SOL_SOCKET, SO_KEEPALIVE, &yes, sizeof(yes));
- setsockopt(new, IPPROTO_TCP, TCP_KEEPCNT, &keepalive_probes,
- sizeof(keepalive_probes));
- setsockopt(new, IPPROTO_TCP, TCP_KEEPIDLE, &keepalive_time,
- sizeof(keepalive_time));
- setsockopt(new, IPPROTO_TCP, TCP_KEEPINTVL, &keepalive_intvl,
- sizeof(keepalive_intvl));
- setsockopt(new, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
-
- cdata->fd = new;
- cdata->ctx = ctx;
- cdata->debug = debug;
-
- INFO("New client connected from %s\n",
- inet_ntoa(caddr.sin_addr));
-
- ret = thread_pool_add_thread(main_thread_pool, client_thd, cdata, "net_client_thd");
- if (ret) {
- iio_strerror(ret, err_str, sizeof(err_str));
- ERROR("Failed to create new client thread: %s\n",
- err_str);
- close(new);
- free(cdata);
- }
- }
-
- DEBUG("Cleaning up\n");
-#ifdef HAVE_AVAHI
- if (avahi_started)
- stop_avahi();
-#endif
- close(fd);
- return EXIT_SUCCESS;
-
-err_close_socket:
- close(fd);
- return EXIT_FAILURE;
-}
-
-int main(int argc, char **argv)
-{
- bool debug = false, interactive = false, use_aio = false;
-#ifdef WITH_IIOD_USBD
- long nb_pipes = 3;
- char *end;
-#endif
- struct iio_context *ctx;
- int c, option_index = 0;
- char *ffs_mountpoint = NULL;
- char err_str[1024];
- int ret;
-
- while ((c = getopt_long(argc, argv, "+hVdDiaF:n:",
- options, &option_index)) != -1) {
- switch (c) {
- case 'd':
- debug = true;
- break;
- case 'D':
- server_demux = true;
- break;
- case 'i':
- interactive = true;
- break;
- case 'a':
-#ifdef WITH_AIO
- use_aio = true;
- break;
-#else
- ERROR("IIOD was not compiled with AIO support.\n");
- return EXIT_FAILURE;
-#endif
- case 'F':
-#ifdef WITH_IIOD_USBD
- ffs_mountpoint = optarg;
- break;
-#else
- ERROR("IIOD was not compiled with USB support.\n");
- return EXIT_FAILURE;
-#endif
- case 'n':
-#ifdef WITH_IIOD_USBD
- nb_pipes = strtol(optarg, &end, 10);
- if (optarg == end || nb_pipes < 1) {
- ERROR("--nb-pipes: Invalid parameter\n");
- return EXIT_FAILURE;
- }
- break;
-#else
- ERROR("IIOD was not compiled with USB support.\n");
- return EXIT_FAILURE;
-#endif
- case 'h':
- usage();
- return EXIT_SUCCESS;
- case 'V':
- printf("%u.%u\n", LIBIIO_VERSION_MAJOR,
- LIBIIO_VERSION_MINOR);
- return EXIT_SUCCESS;
- case '?':
- return EXIT_FAILURE;
- }
- }
-
- ctx = iio_create_local_context();
- if (!ctx) {
- iio_strerror(errno, err_str, sizeof(err_str));
- ERROR("Unable to create local context: %s\n", err_str);
- return EXIT_FAILURE;
- }
-
- main_thread_pool = thread_pool_new();
- if (!main_thread_pool) {
- iio_strerror(errno, err_str, sizeof(err_str));
- ERROR("Unable to create thread pool: %s\n", err_str);
- ret = EXIT_FAILURE;
- goto out_destroy_context;
- }
-
- set_handler(SIGHUP, sig_handler);
- set_handler(SIGPIPE, sig_handler);
- set_handler(SIGINT, sig_handler);
- set_handler(SIGTERM, sig_handler);
-
- if (ffs_mountpoint) {
-#ifdef WITH_IIOD_USBD
- /* We pass use_aio == true directly, this is ensured to be true
- * by the CMake script. */
- ret = start_usb_daemon(ctx, ffs_mountpoint,
- debug, true, (unsigned int) nb_pipes,
- main_thread_pool);
- if (ret) {
- iio_strerror(-ret, err_str, sizeof(err_str));
- ERROR("Unable to start USB daemon: %s\n", err_str);
- ret = EXIT_FAILURE;
- goto out_destroy_thread_pool;
- }
-#endif
- }
-
- if (interactive)
- ret = main_interactive(ctx, debug, use_aio);
- else
- ret = main_server(ctx, debug);
-
- /*
- * In case we got here through an error in the main thread make sure all
- * the worker threads are signaled to shutdown.
- */
-
-#ifdef WITH_IIOD_USBD
-out_destroy_thread_pool:
-#endif
- thread_pool_stop_and_wait(main_thread_pool);
- thread_pool_destroy(main_thread_pool);
-
-out_destroy_context:
- iio_context_destroy(ctx);
-
- return ret;
-}
diff --git a/iiod/init/iiod.conf.cmakein b/iiod/init/iiod.conf.cmakein
deleted file mode 100644
index 1ac3c88..0000000
--- a/iiod/init/iiod.conf.cmakein
+++ /dev/null
@@ -1,13 +0,0 @@
-# iiod - Upstart script
-#
-# Copyright (C) 2016 Analog Devices Inc.
-
-description "IIO Daemon"
-author "Paul Cercueil <paul.cercueil@analog.com>"
-
-start on (local-filesystems)
-stop on runlevel [!2345]
-
-respawn
-
-exec @CMAKE_INSTALL_FULL_SBINDIR@/iiod -D
diff --git a/iiod/init/iiod.init.cmakein b/iiod/init/iiod.init.cmakein
deleted file mode 100644
index 2799925..0000000
--- a/iiod/init/iiod.init.cmakein
+++ /dev/null
@@ -1,60 +0,0 @@
-#!/bin/sh
-#
-### BEGIN INIT INFO
-# Provides: iiod
-# Required-Start: $local_fs $remote_fs
-# Required-Stop: $local_fs $remote_fs
-# Default-Start: 2 3 4 5
-# Default-Stop: 0 1 6
-# Short-Description: IIO Daemon
-### END INIT INFO
-# Debian init.d script for the IIO Daemon
-# Copyright (C) 2016 Analog Devices Inc.
-
-. /lib/lsb/init-functions
-
-# Server-side demuxing by default
-IIOD_OPTS=-D
-
-if test -f /etc/default/iiod; then
- . /etc/default/iiod
-fi
-
-case "$1" in
- start)
- log_daemon_msg "Starting IIO Daemon" "iiod" || true
- if start-stop-daemon -S -b -q -m -p /var/run/iiod.pid -x @CMAKE_INSTALL_FULL_SBINDIR@/iiod -- $IIOD_OPTS; then
- log_end_msg 0 || true
- else
- log_end_msg 1 || true
- fi
- ;;
-
- stop)
- log_daemon_msg "Stopping IIO Daemon" "iiod" || true
- if start-stop-daemon -K -q -p /var/run/iiod.pid; then
- log_end_msg 0 || true
- else
- log_end_msg 1 || true
- fi
- ;;
-
- restart|force-reload)
- $0 stop
- $0 start
- ;;
-
- status)
- if [ -f /var/run/iiod.pid ] ; then
- status_of_proc -p /var/run/iiod.pid @CMAKE_INSTALL_FULL_SBINDIR@/iiod iiod && exit 0 || exit $?
- else
- status_of_proc @CMAKE_INSTALL_FULL_SBINDIR@/iiod iiod && exit 0 || exit $?
- fi
- ;;
-
- *)
- log_action_msg "Usage: /etc/init.d/iiod.sh {start|stop|restart|status}" || true
- exit 1
-esac
-
-exit 0
diff --git a/iiod/init/iiod.service.cmakein b/iiod/init/iiod.service.cmakein
deleted file mode 100644
index 1b6d2ac..0000000
--- a/iiod/init/iiod.service.cmakein
+++ /dev/null
@@ -1,17 +0,0 @@
-# iiod - Systemd init script
-#
-# Copyright (C) 2016 Analog Devices Inc.
-
-[Unit]
-Description=IIO Daemon
-After=network.target
-ConditionPathExists=/sys/bus/iio
-
-[Service]
-ExecStart=@CMAKE_INSTALL_FULL_SBINDIR@/iiod
-KillMode=process
-Restart=on-failure
-
-[Install]
-WantedBy=multi-user.target
-Alias=iiod.service
diff --git a/iiod/lexer.l b/iiod/lexer.l
deleted file mode 100644
index c1c0ad4..0000000
--- a/iiod/lexer.l
+++ /dev/null
@@ -1,170 +0,0 @@
-%{
-/*
- * 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.
- *
- * */
-
-#include "parser.h"
-#include "ops.h"
-
-#include <string.h>
-%}
-
-%option noyywrap reentrant bison-bridge nounistd nounput noinput
-
-WORD (([[:alpha:]]+,)|(iio:))?(-|_|\.|[[:alnum:]])+
-
-%s WANT_DEVICE
-%s WANT_CHN_OR_ATTR
-%s WANT_CHN
-%s WANT_ATTR
-%s WANT_VALUE
-%%
-
-<INITIAL>VERSION|version {
- return VERSION;
-}
-
-<INITIAL>PRINT|print {
- return PRINT;
-}
-
-<INITIAL>EXIT|exit|QUIT|quit {
- return EXIT;
-}
-
-<INITIAL>HELP|help {
- return HELP;
-}
-
-<INITIAL>TIMEOUT|timeout {
- return TIMEOUT;
-}
-
-<INITIAL>OPEN|open {
- BEGIN(WANT_DEVICE);
- return OPEN;
-}
-
-<INITIAL>CLOSE|close {
- BEGIN(WANT_DEVICE);
- return CLOSE;
-}
-
-<INITIAL>READ|read {
- BEGIN(WANT_DEVICE);
- return READ;
-}
-
-<INITIAL>READBUF|readbuf {
- BEGIN(WANT_DEVICE);
- return READBUF;
-}
-
-<INITIAL>WRITEBUF|writebuf {
- BEGIN(WANT_DEVICE);
- return WRITEBUF;
-}
-
-<INITIAL>WRITE|write {
- BEGIN(WANT_DEVICE);
- return WRITE;
-}
-
-<INITIAL>SETTRIG|settrig {
- BEGIN(WANT_DEVICE);
- return SETTRIG;
-}
-
-<INITIAL>GETTRIG|gettrig {
- BEGIN(WANT_DEVICE);
- return GETTRIG;
-}
-
-<INITIAL>SET|set {
- BEGIN(WANT_DEVICE);
- return SET;
-}
-
-<WANT_DEVICE>{WORD} {
- struct parser_pdata *pdata = yyget_extra(yyscanner);
- struct iio_device *dev = iio_context_find_device(pdata->ctx, yytext);
- yylval->dev = dev;
- pdata->dev = dev;
- BEGIN(WANT_CHN_OR_ATTR);
- return DEVICE;
-}
-
-<WANT_CHN_OR_ATTR>BUFFERS_COUNT|buffers_count {
- BEGIN(WANT_VALUE);
- return BUFFERS_COUNT;
-}
-
-<WANT_CHN_OR_ATTR>DEBUG|debug {
- BEGIN(WANT_ATTR);
- return DEBUG_ATTR;
-}
-
-<WANT_CHN_OR_ATTR>BUFFER|buffer {
- BEGIN(WANT_ATTR);
- return BUFFER_ATTR;
-}
-
-<WANT_CHN_OR_ATTR>INPUT|input|OUTPUT|output {
- struct parser_pdata *pdata = yyget_extra(yyscanner);
- pdata->channel_is_output = yytext[0] == 'o' || yytext[0] == 'O';
- BEGIN(WANT_CHN);
- return IN_OUT;
-}
-
-<WANT_CHN>{WORD} {
- struct parser_pdata *pdata = yyget_extra(yyscanner);
- struct iio_channel *chn = NULL;
- if (pdata->dev)
- chn = iio_device_find_channel(pdata->dev,
- yytext, pdata->channel_is_output);
- yylval->chn = chn;
- pdata->chn = chn;
- BEGIN(WANT_ATTR);
- return CHANNEL;
-}
-
-<WANT_VALUE>{WORD} {
- yylval->value = strtol(yytext, NULL, 10);
- return VALUE;
-}
-
-CYCLIC|cyclic {
- return CYCLIC;
-}
-
-{WORD} {
- yylval->word = strdup(yytext);
- return WORD;
-}
-
-[ \t]+ {
- return SPACE;
-}
-
-[ \t]*\r?\n {
- BEGIN(INITIAL);
- return END;
-}
-
-. {
- BEGIN(INITIAL);
-}
diff --git a/iiod/ops.c b/iiod/ops.c
deleted file mode 100644
index bf26bc1..0000000
--- a/iiod/ops.c
+++ /dev/null
@@ -1,1421 +0,0 @@
-/*
- * 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.
- *
- * */
-
-#include "ops.h"
-#include "parser.h"
-#include "thread-pool.h"
-#include "../debug.h"
-#include "../iio-private.h"
-
-#include <errno.h>
-#include <limits.h>
-#include <pthread.h>
-#include <poll.h>
-#include <stdbool.h>
-#include <string.h>
-#include <sys/eventfd.h>
-#include <time.h>
-#include <fcntl.h>
-#include <signal.h>
-
-int yyparse(yyscan_t scanner);
-
-struct DevEntry;
-
-/* Corresponds to a thread reading from a device */
-struct ThdEntry {
- SLIST_ENTRY(ThdEntry) parser_list_entry;
- SLIST_ENTRY(ThdEntry) dev_list_entry;
- unsigned int nb, sample_size, samples_count;
- ssize_t err;
-
- int eventfd;
-
- struct parser_pdata *pdata;
- struct iio_device *dev;
- struct DevEntry *entry;
-
- uint32_t *mask;
- bool active, is_writer, new_client, wait_for_open;
-};
-
-static void thd_entry_event_signal(struct ThdEntry *thd)
-{
- uint64_t e = 1;
- int ret;
-
- do {
- ret = write(thd->eventfd, &e, sizeof(e));
- } while (ret == -1 && errno == EINTR);
-}
-
-static int thd_entry_event_wait(struct ThdEntry *thd, pthread_mutex_t *mutex,
- int fd_in)
-{
- struct pollfd pfd[3];
- uint64_t e;
- int ret;
-
- pthread_mutex_unlock(mutex);
-
- pfd[0].fd = thd->eventfd;
- pfd[0].events = POLLIN;
- pfd[1].fd = fd_in;
- pfd[1].events = POLLRDHUP;
- pfd[2].fd = thread_pool_get_poll_fd(thd->pdata->pool);
- pfd[2].events = POLLIN;
-
- do {
- poll_nointr(pfd, 3);
-
- if ((pfd[1].revents & POLLRDHUP) || (pfd[2].revents & POLLIN)) {
- pthread_mutex_lock(mutex);
- return -EPIPE;
- }
-
- do {
- ret = read(thd->eventfd, &e, sizeof(e));
- } while (ret == -1 && errno == EINTR);
- } while (ret == -1 && errno == EAGAIN);
-
- pthread_mutex_lock(mutex);
-
- return 0;
-}
-
-/* Corresponds to an opened device */
-struct DevEntry {
- unsigned int ref_count;
-
- struct iio_device *dev;
- struct iio_buffer *buf;
- unsigned int sample_size, nb_clients;
- bool update_mask;
- bool cyclic;
- bool closed;
- bool cancelled;
-
- /* Linked list of ThdEntry structures corresponding
- * to all the threads who opened the device */
- SLIST_HEAD(ThdHead, ThdEntry) thdlist_head;
- pthread_mutex_t thdlist_lock;
-
- pthread_cond_t rw_ready_cond;
-
- uint32_t *mask;
- size_t nb_words;
-};
-
-struct sample_cb_info {
- struct parser_pdata *pdata;
- unsigned int nb_bytes, cpt;
- uint32_t *mask;
-};
-
-/* Protects iio_device_{set,get}_data() from concurrent access from multiple
- * clients */
-static pthread_mutex_t devlist_lock = PTHREAD_MUTEX_INITIALIZER;
-
-#if WITH_AIO
-static ssize_t async_io(struct parser_pdata *pdata, void *buf, size_t len,
- bool do_read)
-{
- ssize_t ret;
- struct pollfd pfd[2];
- unsigned int num_pfds;
- struct iocb iocb;
- struct iocb *ios[1];
- struct io_event e[1];
-
- ios[0] = &iocb;
-
- if (do_read)
- io_prep_pread(&iocb, pdata->fd_in, buf, len, 0);
- else
- io_prep_pwrite(&iocb, pdata->fd_out, buf, len, 0);
-
- io_set_eventfd(&iocb, pdata->aio_eventfd);
-
- pthread_mutex_lock(&pdata->aio_mutex);
-
- ret = io_submit(pdata->aio_ctx, 1, ios);
- if (ret != 1) {
- pthread_mutex_unlock(&pdata->aio_mutex);
- ERROR("Failed to submit IO operation: %zd\n", ret);
- return -EIO;
- }
-
- pfd[0].fd = pdata->aio_eventfd;
- pfd[0].events = POLLIN;
- pfd[0].revents = 0;
- pfd[1].fd = thread_pool_get_poll_fd(pdata->pool);
- pfd[1].events = POLLIN;
- pfd[1].revents = 0;
- num_pfds = 2;
-
- do {
- poll_nointr(pfd, num_pfds);
-
- if (pfd[0].revents & POLLIN) {
- uint64_t event;
- ret = read(pdata->aio_eventfd, &event, sizeof(event));
- if (ret != sizeof(event)) {
- ERROR("Failed to read from eventfd: %d\n", -errno);
- ret = -EIO;
- break;
- }
-
- ret = io_getevents(pdata->aio_ctx, 0, 1, e, NULL);
- if (ret != 1) {
- ERROR("Failed to read IO events: %zd\n", ret);
- ret = -EIO;
- break;
- } else {
- ret = (long)e[0].res;
- }
- } else if ((num_pfds > 1 && pfd[1].revents & POLLIN)) {
- /* Got a STOP event to abort this whole session */
- ret = io_cancel(pdata->aio_ctx, &iocb, e);
- if (ret != -EINPROGRESS && ret != -EINVAL) {
- ERROR("Failed to cancel IO transfer: %zd\n", ret);
- ret = -EIO;
- break;
- }
- /* It should not be long now until we get the cancellation event */
- num_pfds = 1;
- }
- } while (!(pfd[0].revents & POLLIN));
-
- pthread_mutex_unlock(&pdata->aio_mutex);
-
- /* Got STOP event, treat it as EOF */
- if (num_pfds == 1)
- return 0;
-
- return ret;
-}
-
-#define MAX_AIO_REQ_SIZE (1024 * 1024)
-
-static ssize_t readfd_aio(struct parser_pdata *pdata, void *dest, size_t len)
-{
- if (len > MAX_AIO_REQ_SIZE)
- len = MAX_AIO_REQ_SIZE;
- return async_io(pdata, dest, len, true);
-}
-
-static ssize_t writefd_aio(struct parser_pdata *pdata, const void *dest,
- size_t len)
-{
- if (len > MAX_AIO_REQ_SIZE)
- len = MAX_AIO_REQ_SIZE;
- return async_io(pdata, (void *)dest, len, false);
-}
-#endif /* WITH_AIO */
-
-static ssize_t readfd_io(struct parser_pdata *pdata, void *dest, size_t len)
-{
- ssize_t ret;
- struct pollfd pfd[2];
-
- pfd[0].fd = pdata->fd_in;
- pfd[0].events = POLLIN | POLLRDHUP;
- pfd[0].revents = 0;
- pfd[1].fd = thread_pool_get_poll_fd(pdata->pool);
- pfd[1].events = POLLIN;
- pfd[1].revents = 0;
-
- do {
- poll_nointr(pfd, 2);
-
- /* Got STOP event, or client closed the socket: treat it as EOF */
- if (pfd[1].revents & POLLIN || pfd[0].revents & POLLRDHUP)
- return 0;
- if (pfd[0].revents & POLLERR)
- return -EIO;
- if (!(pfd[0].revents & POLLIN))
- continue;
-
- do {
- if (pdata->fd_in_is_socket)
- ret = recv(pdata->fd_in, dest, len, MSG_NOSIGNAL);
- else
- ret = read(pdata->fd_in, dest, len);
- } while (ret == -1 && errno == EINTR);
-
- if (ret != -1 || errno != EAGAIN)
- break;
- } while (true);
-
- if (ret == -1)
- return -errno;
-
- return ret;
-}
-
-static ssize_t writefd_io(struct parser_pdata *pdata, const void *src, size_t len)
-{
- ssize_t ret;
- struct pollfd pfd[2];
-
- pfd[0].fd = pdata->fd_out;
- pfd[0].events = POLLOUT;
- pfd[0].revents = 0;
- pfd[1].fd = thread_pool_get_poll_fd(pdata->pool);
- pfd[1].events = POLLIN;
- pfd[1].revents = 0;
-
- do {
- poll_nointr(pfd, 2);
-
- /* Got STOP event, or client closed the socket: treat it as EOF */
- if (pfd[1].revents & POLLIN || pfd[0].revents & POLLHUP)
- return 0;
- if (pfd[0].revents & POLLERR)
- return -EIO;
- if (!(pfd[0].revents & POLLOUT))
- continue;
-
- do {
- if (pdata->fd_out_is_socket)
- ret = send(pdata->fd_out, src, len, MSG_NOSIGNAL);
- else
- ret = write(pdata->fd_out, src, len);
- } while (ret == -1 && errno == EINTR);
-
- if (ret != -1 || errno != EAGAIN)
- break;
- } while (true);
-
- if (ret == -1)
- return -errno;
-
- return ret;
-}
-
-ssize_t write_all(struct parser_pdata *pdata, const void *src, size_t len)
-{
- uintptr_t ptr = (uintptr_t) src;
-
- while (len) {
- ssize_t ret = pdata->writefd(pdata, (void *) ptr, len);
- if (ret < 0)
- return ret;
- if (!ret)
- return -EPIPE;
- ptr += ret;
- len -= ret;
- }
-
- return ptr - (uintptr_t) src;
-}
-
-static ssize_t read_all(struct parser_pdata *pdata,
- void *dst, size_t len)
-{
- uintptr_t ptr = (uintptr_t) dst;
-
- while (len) {
- ssize_t ret = pdata->readfd(pdata, (void *) ptr, len);
- if (ret < 0)
- return ret;
- if (!ret)
- return -EPIPE;
- ptr += ret;
- len -= ret;
- }
-
- return ptr - (uintptr_t) dst;
-}
-
-static void print_value(struct parser_pdata *pdata, long value)
-{
- if (pdata->verbose && value < 0) {
- char buf[1024];
- iio_strerror(-value, buf, sizeof(buf));
- output(pdata, "ERROR: ");
- output(pdata, buf);
- output(pdata, "\n");
- } else {
- char buf[128];
- sprintf(buf, "%li\n", value);
- output(pdata, buf);
- }
-}
-
-static ssize_t send_sample(const struct iio_channel *chn,
- void *src, size_t length, void *d)
-{
- struct sample_cb_info *info = d;
- if (chn->index < 0 || !TEST_BIT(info->mask, chn->number))
- return 0;
- if (info->nb_bytes < length)
- return 0;
-
- if (info->cpt % length) {
- unsigned int i, goal = length - info->cpt % length;
- char zero = 0;
- ssize_t ret;
-
- for (i = 0; i < goal; i++) {
- ret = info->pdata->writefd(info->pdata, &zero, 1);
- if (ret < 0)
- return ret;
- }
- info->cpt += goal;
- }
-
- info->cpt += length;
- info->nb_bytes -= length;
- return write_all(info->pdata, src, length);
-}
-
-static ssize_t receive_sample(const struct iio_channel *chn,
- void *dst, size_t length, void *d)
-{
- struct sample_cb_info *info = d;
- if (chn->index < 0 || !TEST_BIT(info->mask, chn->number))
- return 0;
- if (info->cpt == info->nb_bytes)
- return 0;
-
- /* Skip the padding if needed */
- if (info->cpt % length) {
- unsigned int i, goal = length - info->cpt % length;
- char foo;
- ssize_t ret;
-
- for (i = 0; i < goal; i++) {
- ret = info->pdata->readfd(info->pdata, &foo, 1);
- if (ret < 0)
- return ret;
- }
- info->cpt += goal;
- }
-
- info->cpt += length;
- return read_all(info->pdata, dst, length);
-}
-
-static ssize_t send_data(struct DevEntry *dev, struct ThdEntry *thd, size_t len)
-{
- struct parser_pdata *pdata = thd->pdata;
- bool demux = server_demux && dev->sample_size != thd->sample_size;
-
- if (demux)
- len = (len / dev->sample_size) * thd->sample_size;
- if (len > thd->nb)
- len = thd->nb;
-
- print_value(pdata, len);
-
- if (thd->new_client) {
- unsigned int i;
- char buf[129], *ptr = buf;
- uint32_t *mask = demux ? thd->mask : dev->mask;
- ssize_t ret;
-
- /* Send the current mask */
- for (i = dev->nb_words; i > 0 && ptr < buf + sizeof(buf);
- i--, ptr += 8)
- sprintf(ptr, "%08x", mask[i - 1]);
-
- *ptr = '\n';
- ret = write_all(pdata, buf, ptr + 1 - buf);
- if (ret < 0)
- return ret;
-
- thd->new_client = false;
- }
-
- if (!demux) {
- /* Short path */
- return write_all(pdata, dev->buf->buffer, len);
- } else {
- struct sample_cb_info info = {
- .pdata = pdata,
- .cpt = 0,
- .nb_bytes = len,
- .mask = thd->mask,
- };
-
- return iio_buffer_foreach_sample(dev->buf, send_sample, &info);
- }
-}
-
-static ssize_t receive_data(struct DevEntry *dev, struct ThdEntry *thd)
-{
- struct parser_pdata *pdata = thd->pdata;
-
- /* Inform that no error occured, and that we'll start reading data */
- if (thd->new_client) {
- print_value(thd->pdata, 0);
- thd->new_client = false;
- }
-
- if (dev->sample_size == thd->sample_size) {
- /* Short path: Receive directly in the buffer */
-
- size_t len = dev->buf->length;
- if (thd->nb < len)
- len = thd->nb;
-
- return read_all(pdata, dev->buf->buffer, len);
- } else {
- /* Long path: Mux the samples to the buffer */
-
- struct sample_cb_info info = {
- .pdata = pdata,
- .cpt = 0,
- .nb_bytes = thd->nb,
- .mask = thd->mask,
- };
-
- return iio_buffer_foreach_sample(dev->buf,
- receive_sample, &info);
- }
-}
-
-static void dev_entry_put(struct DevEntry *entry)
-{
- bool free_entry = false;
-
- pthread_mutex_lock(&entry->thdlist_lock);
- entry->ref_count--;
- if (entry->ref_count == 0)
- free_entry = true;
- pthread_mutex_unlock(&entry->thdlist_lock);
-
- if (free_entry) {
- pthread_mutex_destroy(&entry->thdlist_lock);
- pthread_cond_destroy(&entry->rw_ready_cond);
-
- free(entry->mask);
- free(entry);
- }
-}
-
-static void signal_thread(struct ThdEntry *thd, ssize_t ret)
-{
- thd->err = ret;
- thd->nb = 0;
- thd->active = false;
- thd_entry_event_signal(thd);
-}
-
-static void rw_thd(struct thread_pool *pool, void *d)
-{
- struct DevEntry *entry = d;
- struct ThdEntry *thd, *next_thd;
- struct iio_device *dev = entry->dev;
- unsigned int nb_words = entry->nb_words;
- ssize_t ret = 0;
-
- DEBUG("R/W thread started for device %s\n",
- dev->name ? dev->name : dev->id);
-
- while (true) {
- bool has_readers = false, has_writers = false,
- mask_updated = false;
- unsigned int sample_size;
-
- /* NOTE: this while loop must exit with thdlist_lock locked. */
- pthread_mutex_lock(&entry->thdlist_lock);
-
- if (SLIST_EMPTY(&entry->thdlist_head))
- break;
-
- if (entry->update_mask) {
- unsigned int i;
- unsigned int samples_count = 0;
-
- memset(entry->mask, 0, nb_words * sizeof(*entry->mask));
- SLIST_FOREACH(thd, &entry->thdlist_head, dev_list_entry) {
- for (i = 0; i < nb_words; i++)
- entry->mask[i] |= thd->mask[i];
-
- if (thd->samples_count > samples_count)
- samples_count = thd->samples_count;
- }
-
- if (entry->buf)
- iio_buffer_destroy(entry->buf);
-
- for (i = 0; i < dev->nb_channels; i++) {
- struct iio_channel *chn = dev->channels[i];
- long index = chn->index;
-
- if (index < 0)
- continue;
-
- if (TEST_BIT(entry->mask, chn->number))
- iio_channel_enable(chn);
- else
- iio_channel_disable(chn);
- }
-
- entry->buf = iio_device_create_buffer(dev,
- samples_count, entry->cyclic);
- if (!entry->buf) {
- ret = -errno;
- ERROR("Unable to create buffer\n");
- break;
- }
- entry->cancelled = false;
-
- /* Signal the threads that we opened the device */
- SLIST_FOREACH(thd, &entry->thdlist_head, dev_list_entry) {
- if (thd->wait_for_open) {
- thd->wait_for_open = false;
- signal_thread(thd, 0);
- }
- }
-
- DEBUG("IIO device %s reopened with new mask:\n",
- dev->id);
- for (i = 0; i < nb_words; i++)
- DEBUG("Mask[%i] = 0x%08x\n", i, entry->mask[i]);
- entry->update_mask = false;
-
- entry->sample_size = iio_device_get_sample_size(dev);
- mask_updated = true;
- }
-
- sample_size = entry->sample_size;
-
- SLIST_FOREACH(thd, &entry->thdlist_head, dev_list_entry) {
- thd->active = !thd->err && thd->nb >= sample_size;
- if (mask_updated && thd->active)
- signal_thread(thd, thd->nb);
-
- if (thd->is_writer)
- has_writers |= thd->active;
- else
- has_readers |= thd->active;
- }
-
- if (!has_readers && !has_writers) {
- pthread_cond_wait(&entry->rw_ready_cond,
- &entry->thdlist_lock);
- }
-
- pthread_mutex_unlock(&entry->thdlist_lock);
-
- if (!has_readers && !has_writers)
- continue;
-
- if (has_readers) {
- ssize_t nb_bytes;
-
- ret = iio_buffer_refill(entry->buf);
-
- pthread_mutex_lock(&entry->thdlist_lock);
-
- /*
- * When the last client disconnects the buffer is
- * cancelled and iio_buffer_refill() returns an error. A
- * new client might have connected before we got here
- * though, in that case the rw thread has to stay active
- * and a new buffer is created. If the list is still empty the loop
- * will exit normally.
- */
- if (entry->cancelled) {
- pthread_mutex_unlock(&entry->thdlist_lock);
- continue;
- }
-
- if (ret < 0) {
- ERROR("Reading from device failed: %i\n",
- (int) ret);
- break;
- }
-
- nb_bytes = ret;
-
- /* We don't use SLIST_FOREACH here. As soon as a thread is
- * signaled, its "thd" structure might be freed;
- * SLIST_FOREACH would then cause a segmentation fault, as it
- * reads "thd" to get the address of the next element. */
- for (thd = SLIST_FIRST(&entry->thdlist_head);
- thd; thd = next_thd) {
- next_thd = SLIST_NEXT(thd, dev_list_entry);
-
- if (!thd->active || thd->is_writer)
- continue;
-
- ret = send_data(entry, thd, nb_bytes);
- if (ret > 0)
- thd->nb -= ret;
-
- if (ret < 0 || thd->nb < sample_size)
- signal_thread(thd, (ret < 0) ?
- ret : thd->nb);
- }
-
- pthread_mutex_unlock(&entry->thdlist_lock);
- }
-
- if (has_writers) {
- ssize_t nb_bytes = 0;
-
- pthread_mutex_lock(&entry->thdlist_lock);
-
- /* Reset the size of the buffer to its maximum size */
- entry->buf->data_length = entry->buf->length;
-
- /* Same comment as above */
- for (thd = SLIST_FIRST(&entry->thdlist_head);
- thd; thd = next_thd) {
- next_thd = SLIST_NEXT(thd, dev_list_entry);
-
- if (!thd->active || !thd->is_writer)
- continue;
-
- ret = receive_data(entry, thd);
- if (ret > 0) {
- thd->nb -= ret;
- if (ret > nb_bytes)
- nb_bytes = ret;
- }
-
- if (ret < 0)
- signal_thread(thd, ret);
- }
-
- ret = iio_buffer_push_partial(entry->buf,
- nb_bytes / sample_size);
- if (entry->cancelled) {
- pthread_mutex_unlock(&entry->thdlist_lock);
- continue;
- }
- if (ret < 0) {
- ERROR("Writing to device failed: %i\n",
- (int) ret);
- break;
- }
-
- /* Signal threads which completed their RW command */
- for (thd = SLIST_FIRST(&entry->thdlist_head);
- thd; thd = next_thd) {
- next_thd = SLIST_NEXT(thd, dev_list_entry);
- if (thd->active && thd->is_writer &&
- thd->nb < sample_size)
- signal_thread(thd, thd->nb);
- }
-
- pthread_mutex_unlock(&entry->thdlist_lock);
- }
- }
-
- /* Signal all remaining threads */
- for (thd = SLIST_FIRST(&entry->thdlist_head); thd; thd = next_thd) {
- next_thd = SLIST_NEXT(thd, dev_list_entry);
- SLIST_REMOVE(&entry->thdlist_head, thd, ThdEntry, dev_list_entry);
- thd->wait_for_open = false;
- signal_thread(thd, ret);
- }
- if (entry->buf) {
- iio_buffer_destroy(entry->buf);
- entry->buf = NULL;
- }
- entry->closed = true;
- pthread_mutex_unlock(&entry->thdlist_lock);
-
- pthread_mutex_lock(&devlist_lock);
- /* It is possible that a new thread has already started, make sure to
- * not overwrite it. */
- if (iio_device_get_data(dev) == entry)
- iio_device_set_data(dev, NULL);
- pthread_mutex_unlock(&devlist_lock);
-
- DEBUG("Stopping R/W thread for device %s\n",
- dev->name ? dev->name : dev->id);
-
- dev_entry_put(entry);
-}
-
-static struct ThdEntry *parser_lookup_thd_entry(struct parser_pdata *pdata,
- struct iio_device *dev)
-{
- struct ThdEntry *t;
-
- SLIST_FOREACH(t, &pdata->thdlist_head, parser_list_entry) {
- if (t->dev == dev)
- return t;
- }
-
- return NULL;
-}
-
-static ssize_t rw_buffer(struct parser_pdata *pdata,
- struct iio_device *dev, unsigned int nb, bool is_write)
-{
- struct DevEntry *entry;
- struct ThdEntry *thd;
- ssize_t ret;
-
- if (!dev)
- return -ENODEV;
-
- thd = parser_lookup_thd_entry(pdata, dev);
- if (!thd)
- return -EBADF;
-
- entry = thd->entry;
-
- if (nb < entry->sample_size)
- return 0;
-
- pthread_mutex_lock(&entry->thdlist_lock);
- if (entry->closed) {
- pthread_mutex_unlock(&entry->thdlist_lock);
- return -EBADF;
- }
-
- if (thd->nb) {
- pthread_mutex_unlock(&entry->thdlist_lock);
- return -EBUSY;
- }
-
- thd->new_client = true;
- thd->nb = nb;
- thd->err = 0;
- thd->is_writer = is_write;
- thd->active = true;
-
- pthread_cond_signal(&entry->rw_ready_cond);
-
- DEBUG("Waiting for completion...\n");
- while (thd->active) {
- ret = thd_entry_event_wait(thd, &entry->thdlist_lock, pdata->fd_in);
- if (ret)
- break;
- }
- if (ret == 0)
- ret = thd->err;
- pthread_mutex_unlock(&entry->thdlist_lock);
-
- if (ret > 0 && ret < nb)
- print_value(thd->pdata, 0);
-
- DEBUG("Exiting rw_buffer with code %li\n", (long) ret);
- if (ret < 0)
- return ret;
- else
- return nb - ret;
-}
-
-static uint32_t *get_mask(const char *mask, size_t *len)
-{
- size_t nb = (*len + 7) / 8;
- uint32_t *ptr, *words = calloc(nb, sizeof(*words));
- if (!words)
- return NULL;
-
- ptr = words + nb;
- while (*mask) {
- char buf[9];
- sprintf(buf, "%.*s", 8, mask);
- sscanf(buf, "%08x", --ptr);
- mask += 8;
- DEBUG("Mask[%lu]: 0x%08x\n",
- (unsigned long) (words - ptr) / 4, *ptr);
- }
-
- *len = nb;
- return words;
-}
-
-static void free_thd_entry(struct ThdEntry *t)
-{
- close(t->eventfd);
- free(t->mask);
- free(t);
-}
-
-static void remove_thd_entry(struct ThdEntry *t)
-{
- struct DevEntry *entry = t->entry;
-
- pthread_mutex_lock(&entry->thdlist_lock);
- if (!entry->closed) {
- entry->update_mask = true;
- SLIST_REMOVE(&entry->thdlist_head, t, ThdEntry, dev_list_entry);
- if (SLIST_EMPTY(&entry->thdlist_head) && entry->buf) {
- entry->cancelled = true;
- iio_buffer_cancel(entry->buf); /* Wakeup the rw thread */
- }
-
- pthread_cond_signal(&entry->rw_ready_cond);
- }
- pthread_mutex_unlock(&entry->thdlist_lock);
- dev_entry_put(entry);
-
- free_thd_entry(t);
-}
-
-static int open_dev_helper(struct parser_pdata *pdata, struct iio_device *dev,
- size_t samples_count, const char *mask, bool cyclic)
-{
- int ret = -ENOMEM;
- struct DevEntry *entry;
- struct ThdEntry *thd;
- size_t len = strlen(mask);
- uint32_t *words;
- unsigned int nb_channels;
- unsigned int cyclic_retry = 500;
-
- if (!dev)
- return -ENODEV;
-
- nb_channels = dev->nb_channels;
- if (len != ((nb_channels + 31) / 32) * 8)
- return -EINVAL;
-
- words = get_mask(mask, &len);
- if (!words)
- return -ENOMEM;
-
- thd = zalloc(sizeof(*thd));
- if (!thd)
- goto err_free_words;
-
- thd->wait_for_open = true;
- thd->mask = words;
- thd->nb = 0;
- thd->samples_count = samples_count;
- thd->sample_size = iio_device_get_sample_size_mask(dev, words, len);
- thd->pdata = pdata;
- thd->dev = dev;
- thd->eventfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
-
-retry:
- /* Atomically look up the thread and make sure that it is still active
- * or allocate new one. */
- pthread_mutex_lock(&devlist_lock);
- entry = iio_device_get_data(dev);
- if (entry) {
- if (cyclic || entry->cyclic) {
- /* Only one client allowed in cyclic mode */
- pthread_mutex_unlock(&devlist_lock);
-
- /* There is an inherent race condition if a client
- * creates a new cyclic buffer shortly after destroying
- * a previous. E.g. like
- *
- * iio_buffer_destroy(buf);
- * buf = iio_device_create_buffer(dev, n, true);
- *
- * In this case the two buffers each use their own
- * communication channel which are unordered to each
- * other. E.g. the socket open might arrive before the
- * socket close on the host side, even though they were
- * sent in the opposite order on the client side. This
- * race condition can cause an error being reported back
- * to the client, even though the code on the client
- * side was well formed and would work fine e.g. using
- * the local backend.
- *
- * To avoid this issue go to sleep for up to 50ms in
- * intervals of 100us. This should be enough time for
- * the issue to resolve itself. If there actually is
- * contention on the buffer an error will eventually be
- * returned in which case the additional delay cause by
- * the retires should not matter too much.
- *
- * This is not pretty but it works.
- */
- if (cyclic_retry) {
- cyclic_retry--;
- usleep(100);
- goto retry;
- }
-
- ret = -EBUSY;
- goto err_free_thd;
- }
-
- pthread_mutex_lock(&entry->thdlist_lock);
- if (!entry->closed) {
- pthread_mutex_unlock(&devlist_lock);
-
- entry->ref_count++;
-
- SLIST_INSERT_HEAD(&entry->thdlist_head, thd, dev_list_entry);
- thd->entry = entry;
- entry->update_mask = true;
- DEBUG("Added thread to client list\n");
-
- pthread_cond_signal(&entry->rw_ready_cond);
-
- /* Wait until the device is opened by the rw thread */
- while (thd->wait_for_open) {
- ret = thd_entry_event_wait(thd, &entry->thdlist_lock, pdata->fd_in);
- if (ret)
- break;
- }
- pthread_mutex_unlock(&entry->thdlist_lock);
-
- if (ret == 0)
- ret = (int) thd->err;
- if (ret < 0)
- remove_thd_entry(thd);
- else
- SLIST_INSERT_HEAD(&pdata->thdlist_head, thd, parser_list_entry);
- return ret;
- } else {
- pthread_mutex_unlock(&entry->thdlist_lock);
- }
- }
-
- entry = zalloc(sizeof(*entry));
- if (!entry) {
- pthread_mutex_unlock(&devlist_lock);
- goto err_free_thd;
- }
-
- entry->ref_count = 2; /* One for thread, one for the client */
-
- entry->mask = malloc(len * sizeof(*words));
- if (!entry->mask) {
- pthread_mutex_unlock(&devlist_lock);
- goto err_free_entry;
- }
-
- entry->cyclic = cyclic;
- entry->nb_words = len;
- entry->update_mask = true;
- entry->dev = dev;
- entry->buf = NULL;
- SLIST_INIT(&entry->thdlist_head);
- SLIST_INSERT_HEAD(&entry->thdlist_head, thd, dev_list_entry);
- thd->entry = entry;
- DEBUG("Added thread to client list\n");
-
- pthread_mutex_init(&entry->thdlist_lock, NULL);
- pthread_cond_init(&entry->rw_ready_cond, NULL);
-
- ret = thread_pool_add_thread(main_thread_pool, rw_thd, entry, "rw_thd");
- if (ret) {
- pthread_mutex_unlock(&devlist_lock);
- goto err_free_entry_mask;
- }
-
- DEBUG("Adding new device thread to device list\n");
- iio_device_set_data(dev, entry);
- pthread_mutex_unlock(&devlist_lock);
-
- pthread_mutex_lock(&entry->thdlist_lock);
- /* Wait until the device is opened by the rw thread */
- while (thd->wait_for_open) {
- ret = thd_entry_event_wait(thd, &entry->thdlist_lock, pdata->fd_in);
- if (ret)
- break;
- }
- pthread_mutex_unlock(&entry->thdlist_lock);
-
- if (ret == 0)
- ret = (int) thd->err;
- if (ret < 0)
- remove_thd_entry(thd);
- else
- SLIST_INSERT_HEAD(&pdata->thdlist_head, thd, parser_list_entry);
- return ret;
-
-err_free_entry_mask:
- free(entry->mask);
-err_free_entry:
- free(entry);
-err_free_thd:
- close(thd->eventfd);
- free(thd);
-err_free_words:
- free(words);
- return ret;
-}
-
-static int close_dev_helper(struct parser_pdata *pdata, struct iio_device *dev)
-{
- struct ThdEntry *t;
-
- if (!dev)
- return -ENODEV;
-
- t = parser_lookup_thd_entry(pdata, dev);
- if (!t)
- return -ENXIO;
-
- SLIST_REMOVE(&pdata->thdlist_head, t, ThdEntry, parser_list_entry);
- remove_thd_entry(t);
-
- return 0;
-}
-
-int open_dev(struct parser_pdata *pdata, struct iio_device *dev,
- size_t samples_count, const char *mask, bool cyclic)
-{
- int ret = open_dev_helper(pdata, dev, samples_count, mask, cyclic);
- print_value(pdata, ret);
- return ret;
-}
-
-int close_dev(struct parser_pdata *pdata, struct iio_device *dev)
-{
- int ret = close_dev_helper(pdata, dev);
- print_value(pdata, ret);
- return ret;
-}
-
-ssize_t rw_dev(struct parser_pdata *pdata, struct iio_device *dev,
- unsigned int nb, bool is_write)
-{
- ssize_t ret = rw_buffer(pdata, dev, nb, is_write);
- if (ret <= 0 || is_write)
- print_value(pdata, ret);
- return ret;
-}
-
-ssize_t read_dev_attr(struct parser_pdata *pdata, struct iio_device *dev,
- const char *attr, enum iio_attr_type type)
-{
- /* We use a very large buffer here, as if attr is NULL all the
- * attributes will be read, which may represents a few kilobytes worth
- * of data. */
- char buf[0x10000];
- ssize_t ret = -EINVAL;
-
- if (!dev) {
- print_value(pdata, -ENODEV);
- return -ENODEV;
- }
-
- switch (type) {
- case IIO_ATTR_TYPE_DEVICE:
- ret = iio_device_attr_read(dev, attr, buf, sizeof(buf) - 1);
- break;
- case IIO_ATTR_TYPE_DEBUG:
- ret = iio_device_debug_attr_read(dev,
- attr, buf, sizeof(buf) - 1);
- break;
- case IIO_ATTR_TYPE_BUFFER:
- ret = iio_device_buffer_attr_read(dev,
- attr, buf, sizeof(buf) - 1);
- break;
- default:
- ret = -EINVAL;
- break;
- }
- print_value(pdata, ret);
- if (ret < 0)
- return ret;
-
- buf[ret] = '\n';
- return write_all(pdata, buf, ret + 1);
-}
-
-ssize_t write_dev_attr(struct parser_pdata *pdata, struct iio_device *dev,
- const char *attr, size_t len, enum iio_attr_type type)
-{
- ssize_t ret = -ENOMEM;
- char *buf;
-
- if (!dev) {
- ret = -ENODEV;
- goto err_print_value;
- }
-
- buf = malloc(len);
- if (!buf)
- goto err_print_value;
-
- ret = read_all(pdata, buf, len);
- if (ret < 0)
- goto err_free_buffer;
-
- switch (type) {
- case IIO_ATTR_TYPE_DEVICE:
- ret = iio_device_attr_write_raw(dev, attr, buf, len);
- break;
- case IIO_ATTR_TYPE_DEBUG:
- ret = iio_device_debug_attr_write_raw(dev, attr, buf, len);
- break;
- case IIO_ATTR_TYPE_BUFFER:
- ret = iio_device_buffer_attr_write_raw(dev, attr, buf, len);
- break;
- default:
- ret = -EINVAL;
- break;
- }
-
-err_free_buffer:
- free(buf);
-err_print_value:
- print_value(pdata, ret);
- return ret;
-}
-
-ssize_t read_chn_attr(struct parser_pdata *pdata,
- struct iio_channel *chn, const char *attr)
-{
- char buf[1024];
- ssize_t ret = -ENODEV;
-
- if (chn)
- ret = iio_channel_attr_read(chn, attr, buf, sizeof(buf) - 1);
- else if (pdata->dev)
- ret = -ENXIO;
- print_value(pdata, ret);
- if (ret < 0)
- return ret;
-
- buf[ret] = '\n';
- return write_all(pdata, buf, ret + 1);
-}
-
-ssize_t write_chn_attr(struct parser_pdata *pdata,
- struct iio_channel *chn, const char *attr, size_t len)
-{
- ssize_t ret = -ENOMEM;
- char *buf = malloc(len);
- if (!buf)
- goto err_print_value;
-
- ret = read_all(pdata, buf, len);
- if (ret < 0)
- goto err_free_buffer;
-
- if (chn)
- ret = iio_channel_attr_write_raw(chn, attr, buf, len);
- else if (pdata->dev)
- ret = -ENXIO;
- else
- ret = -ENODEV;
-err_free_buffer:
- free(buf);
-err_print_value:
- print_value(pdata, ret);
- return ret;
-}
-
-ssize_t set_trigger(struct parser_pdata *pdata,
- struct iio_device *dev, const char *trigger)
-{
- struct iio_device *trig = NULL;
- ssize_t ret = -ENOENT;
-
- if (!dev) {
- ret = -ENODEV;
- goto err_print_value;
- }
-
- if (trigger) {
- trig = iio_context_find_device(pdata->ctx, trigger);
- if (!trig)
- goto err_print_value;
- }
-
- ret = iio_device_set_trigger(dev, trig);
-err_print_value:
- print_value(pdata, ret);
- return ret;
-}
-
-ssize_t get_trigger(struct parser_pdata *pdata, struct iio_device *dev)
-{
- const struct iio_device *trigger;
- ssize_t ret;
-
- if (!dev) {
- print_value(pdata, -ENODEV);
- return -ENODEV;
- }
-
- ret = iio_device_get_trigger(dev, &trigger);
- if (!ret && trigger) {
- char buf[256];
-
- ret = strlen(trigger->name);
- print_value(pdata, ret);
-
- snprintf(buf, sizeof(buf), "%s\n", trigger->name);
- ret = write_all(pdata, buf, ret + 1);
- } else {
- print_value(pdata, ret);
- }
- return ret;
-}
-
-int set_timeout(struct parser_pdata *pdata, unsigned int timeout)
-{
- int ret = iio_context_set_timeout(pdata->ctx, timeout);
- print_value(pdata, ret);
- return ret;
-}
-
-int set_buffers_count(struct parser_pdata *pdata,
- struct iio_device *dev, long value)
-{
- int ret = -EINVAL;
-
- if (!dev) {
- ret = -ENODEV;
- goto err_print_value;
- }
-
- if (value >= 1)
- ret = iio_device_set_kernel_buffers_count(
- dev, (unsigned int) value);
-err_print_value:
- print_value(pdata, ret);
- return ret;
-}
-
-ssize_t read_line(struct parser_pdata *pdata, char *buf, size_t len)
-{
- ssize_t ret;
-
- if (pdata->fd_in_is_socket) {
- struct pollfd pfd[2];
- bool found;
- size_t bytes_read = 0;
-
- pfd[0].fd = pdata->fd_in;
- pfd[0].events = POLLIN | POLLRDHUP;
- pfd[0].revents = 0;
- pfd[1].fd = thread_pool_get_poll_fd(pdata->pool);
- pfd[1].events = POLLIN;
- pfd[1].revents = 0;
-
- do {
- size_t i, to_trunc;
-
- poll_nointr(pfd, 2);
-
- if (pfd[1].revents & POLLIN ||
- pfd[0].revents & POLLRDHUP)
- return 0;
-
- /* First read from the socket, without advancing the
- * read offset */
- ret = recv(pdata->fd_in, buf, len,
- MSG_NOSIGNAL | MSG_PEEK);
- if (ret < 0)
- return -errno;
-
- /* Lookup for the trailing \n */
- for (i = 0; i < (size_t) ret && buf[i] != '\n'; i++);
- found = i < (size_t) ret;
-
- len -= ret;
- buf += ret;
-
- to_trunc = found ? i + 1 : (size_t) ret;
-
- /* Advance the read offset after the \n if found, or
- * after the last character read otherwise */
- ret = recv(pdata->fd_in, NULL, to_trunc,
- MSG_NOSIGNAL | MSG_TRUNC);
- if (ret < 0)
- return -errno;
-
- bytes_read += to_trunc;
- } while (!found && len);
-
- /* No \n found? Just garbage data */
- if (!found)
- ret = -EIO;
- else
- ret = bytes_read;
- } else {
- ret = pdata->readfd(pdata, buf, len);
- }
-
- return ret;
-}
-
-void interpreter(struct iio_context *ctx, int fd_in, int fd_out, bool verbose,
- bool is_socket, bool use_aio, struct thread_pool *pool)
-{
- yyscan_t scanner;
- struct parser_pdata pdata;
- unsigned int i;
- int ret;
-
- pdata.ctx = ctx;
- pdata.stop = false;
- pdata.fd_in = fd_in;
- pdata.fd_out = fd_out;
- pdata.verbose = verbose;
- pdata.pool = pool;
-
- pdata.fd_in_is_socket = is_socket;
- pdata.fd_out_is_socket = is_socket;
-
- SLIST_INIT(&pdata.thdlist_head);
-
- if (use_aio) {
- /* Note: if WITH_AIO is not defined, use_aio is always false.
- * We ensure that in iiod.c. */
-#if WITH_AIO
- char err_str[1024];
-
- pdata.aio_eventfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
- if (pdata.aio_eventfd < 0) {
- iio_strerror(errno, err_str, sizeof(err_str));
- ERROR("Failed to create AIO eventfd: %s\n", err_str);
- return;
- }
-
- pdata.aio_ctx = 0;
- ret = io_setup(1, &pdata.aio_ctx);
- if (ret < 0) {
- iio_strerror(-ret, err_str, sizeof(err_str));
- ERROR("Failed to create AIO context: %s\n", err_str);
- close(pdata.aio_eventfd);
- return;
- }
- pthread_mutex_init(&pdata.aio_mutex, NULL);
- pdata.readfd = readfd_aio;
- pdata.writefd = writefd_aio;
-#endif
- } else {
- pdata.readfd = readfd_io;
- pdata.writefd = writefd_io;
- }
-
- yylex_init_extra(&pdata, &scanner);
-
- do {
- if (verbose)
- output(&pdata, "iio-daemon > ");
- ret = yyparse(scanner);
- } while (!pdata.stop && ret >= 0);
-
- yylex_destroy(scanner);
-
- /* Close all opened devices */
- for (i = 0; i < ctx->nb_devices; i++)
- close_dev_helper(&pdata, ctx->devices[i]);
-
-#if WITH_AIO
- if (use_aio) {
- io_destroy(pdata.aio_ctx);
- close(pdata.aio_eventfd);
- }
-#endif
-}
diff --git a/iiod/ops.h b/iiod/ops.h
deleted file mode 100644
index 107e2ca..0000000
--- a/iiod/ops.h
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * 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.
- *
- * */
-
-#ifndef __OPS_H__
-#define __OPS_H__
-
-#include "../iio-private.h"
-#include "queue.h"
-
-#include <endian.h>
-#include <errno.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-#include <poll.h>
-#include <sys/socket.h>
-#include <unistd.h>
-
-#if WITH_AIO
-#include <libaio.h>
-#endif
-
-#ifndef __bswap_constant_16
-#define __bswap_constant_16(x) \
- ((unsigned short int) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))
-#endif
-
-#ifndef __bswap_constant_32
-#define __bswap_constant_32(x) \
- ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
- (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
-#endif
-
-struct thread_pool;
-extern struct thread_pool *main_thread_pool;
-
-struct parser_pdata {
- struct iio_context *ctx;
- bool stop, verbose;
- int fd_in, fd_out;
-
- SLIST_HEAD(ParserDataThdHead, ThdEntry) thdlist_head;
-
- /* Used as temporaries placements by the lexer */
- struct iio_device *dev;
- struct iio_channel *chn;
- bool channel_is_output;
- bool fd_in_is_socket, fd_out_is_socket;
-#if WITH_AIO
- io_context_t aio_ctx;
- int aio_eventfd;
- pthread_mutex_t aio_mutex;
-#endif
- struct thread_pool *pool;
-
- ssize_t (*writefd)(struct parser_pdata *pdata, const void *buf, size_t len);
- ssize_t (*readfd)(struct parser_pdata *pdata, void *buf, size_t len);
-};
-
-extern bool server_demux; /* Defined in iiod.c */
-
-void interpreter(struct iio_context *ctx, int fd_in, int fd_out, bool verbose,
- bool is_socket, bool use_aio, struct thread_pool *pool);
-
-int start_usb_daemon(struct iio_context *ctx, const char *ffs,
- bool debug, bool use_aio, unsigned int nb_pipes,
- struct thread_pool *pool);
-
-int open_dev(struct parser_pdata *pdata, struct iio_device *dev,
- size_t samples_count, const char *mask, bool cyclic);
-int close_dev(struct parser_pdata *pdata, struct iio_device *dev);
-
-ssize_t rw_dev(struct parser_pdata *pdata, struct iio_device *dev,
- unsigned int nb, bool is_write);
-
-ssize_t read_dev_attr(struct parser_pdata *pdata, struct iio_device *dev,
- const char *attr, enum iio_attr_type type);
-ssize_t write_dev_attr(struct parser_pdata *pdata, struct iio_device *dev,
- const char *attr, size_t len, enum iio_attr_type type);
-
-ssize_t read_chn_attr(struct parser_pdata *pdata, struct iio_channel *chn,
- const char *attr);
-ssize_t write_chn_attr(struct parser_pdata *pdata, struct iio_channel *chn,
- const char *attr, size_t len);
-
-ssize_t get_trigger(struct parser_pdata *pdata, struct iio_device *dev);
-ssize_t set_trigger(struct parser_pdata *pdata,
- struct iio_device *dev, const char *trig);
-
-int set_timeout(struct parser_pdata *pdata, unsigned int timeout);
-int set_buffers_count(struct parser_pdata *pdata,
- struct iio_device *dev, long value);
-
-ssize_t read_line(struct parser_pdata *pdata, char *buf, size_t len);
-ssize_t write_all(struct parser_pdata *pdata, const void *src, size_t len);
-
-static __inline__ void output(struct parser_pdata *pdata, const char *text)
-{
- if (write_all(pdata, text, strlen(text)) <= 0)
- pdata->stop = true;
-}
-
-static __inline__ int poll_nointr(struct pollfd *pfd, unsigned int num_pfd)
-{
- int ret;
-
- do {
- ret = poll(pfd, num_pfd, -1);
- } while (ret == -1 && errno == EINTR);
-
- return ret;
-}
-
-#endif /* __OPS_H__ */
diff --git a/iiod/parser.y b/iiod/parser.y
deleted file mode 100644
index 64c32b8..0000000
--- a/iiod/parser.y
+++ /dev/null
@@ -1,463 +0,0 @@
-%{
-/*
- * 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.
- *
- * */
-
-#include "ops.h"
-#include "parser.h"
-
-#include <errno.h>
-#include <string.h>
-
-void yyerror(yyscan_t scanner, const char *msg);
-%}
-
-%code requires {
-#ifndef YY_TYPEDEF_YY_SCANNER_T
-#define YY_TYPEDEF_YY_SCANNER_T
-typedef void *yyscan_t;
-#endif
-
-#include "../iio-config.h"
-#include "../debug.h"
-
-#include <stdbool.h>
-#include <sys/socket.h>
-
-int yylex();
-int yylex_init_extra(void *d, yyscan_t *scanner);
-int yylex_destroy(yyscan_t yyscanner);
-
-void * yyget_extra(yyscan_t scanner);
-ssize_t yy_input(yyscan_t scanner, char *buf, size_t max_size);
-
-#define ECHO do { \
- struct parser_pdata *pdata = yyget_extra(yyscanner); \
- write_all(pdata, yytext, yyleng); \
- } while (0)
-
-#define YY_INPUT(buf,result,max_size) do { \
- ssize_t res = yy_input(yyscanner, buf, max_size); \
- result = res <= 0 ? YY_NULL : (size_t) res; \
- } while (0)
-}
-
-%define api.pure
-%lex-param { yyscan_t scanner }
-%parse-param { yyscan_t scanner }
-
-%union {
- char *word;
- struct iio_device *dev;
- struct iio_channel *chn;
- long value;
-}
-
-%token SPACE
-%token END
-
-%token VERSION
-%token EXIT
-%token HELP
-%token OPEN
-%token CLOSE
-%token PRINT
-%token READ
-%token READBUF
-%token WRITEBUF
-%token WRITE
-%token SETTRIG
-%token GETTRIG
-%token TIMEOUT
-%token DEBUG_ATTR
-%token BUFFER_ATTR
-%token IN_OUT
-%token CYCLIC
-%token SET
-%token BUFFERS_COUNT
-
-%token <word> WORD
-%token <dev> DEVICE
-%token <chn> CHANNEL
-%token <value> VALUE;
-
-%destructor { DEBUG("Freeing token \"%s\"\n", $$); free($$); } <word>
-
-%start Line
-%%
-
-Line:
- END {
- YYACCEPT;
- }
- | EXIT END {
- struct parser_pdata *pdata = yyget_extra(scanner);
- pdata->stop = true;
- YYACCEPT;
- }
- | HELP END {
- struct parser_pdata *pdata = yyget_extra(scanner);
- output(pdata, "Available commands:\n\n"
- "\tHELP\n"
- "\t\tPrint this help message\n"
- "\tEXIT\n"
- "\t\tClose the current session\n"
- "\tPRINT\n"
- "\t\tDisplays a XML string corresponding to the current IIO context\n"
- "\tVERSION\n"
- "\t\tGet the version of libiio in use\n"
- "\tTIMEOUT <timeout_ms>\n"
- "\t\tSet the timeout (in ms) for I/O operations\n"
- "\tOPEN <device> <samples_count> <mask> [CYCLIC]\n"
- "\t\tOpen the specified device with the given mask of channels\n"
- "\tCLOSE <device>\n"
- "\t\tClose the specified device\n"
- "\tREAD <device> DEBUG|BUFFER|[INPUT|OUTPUT <channel>] [<attribute>]\n"
- "\t\tRead the value of an attribute\n"
- "\tWRITE <device> DEBUG|BUFFER|[INPUT|OUTPUT <channel>] [<attribute>] <bytes_count>\n"
- "\t\tSet the value of an attribute\n"
- "\tREADBUF <device> <bytes_count>\n"
- "\t\tRead raw data from the specified device\n"
- "\tWRITEBUF <device> <bytes_count>\n"
- "\t\tWrite raw data to the specified device\n"
- "\tGETTRIG <device>\n"
- "\t\tGet the name of the trigger used by the specified device\n"
- "\tSETTRIG <device> [<trigger>]\n"
- "\t\tSet the trigger to use for the specified device\n"
- "\tSET <device> BUFFERS_COUNT <count>\n"
- "\t\tSet the number of kernel buffers for the specified device\n");
- YYACCEPT;
- }
- | VERSION END {
- struct parser_pdata *pdata = yyget_extra(scanner);
- char buf[128];
- snprintf(buf, sizeof(buf), "%u.%u.%-7.7s\n", LIBIIO_VERSION_MAJOR,
- LIBIIO_VERSION_MINOR, LIBIIO_VERSION_GIT);
- output(pdata, buf);
- YYACCEPT;
- }
- | PRINT END {
- struct parser_pdata *pdata = yyget_extra(scanner);
- const char *xml = iio_context_get_xml(pdata->ctx);
- if (!pdata->verbose) {
- char buf[128];
- sprintf(buf, "%lu\n", (unsigned long) strlen(xml));
- output(pdata, buf);
- }
- output(pdata, xml);
- output(pdata, "\n");
- YYACCEPT;
- }
- | TIMEOUT SPACE WORD END {
- char *word = $3;
- struct parser_pdata *pdata = yyget_extra(scanner);
- unsigned int timeout = (unsigned int) atoi(word);
- int ret = set_timeout(pdata, timeout);
- free(word);
- if (ret < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | OPEN SPACE DEVICE SPACE WORD SPACE WORD SPACE CYCLIC END {
- char *nb = $5, *mask = $7;
- struct parser_pdata *pdata = yyget_extra(scanner);
- unsigned long samples_count = atol(nb);
- int ret = open_dev(pdata, $3, samples_count, mask, true);
- free(nb);
- free(mask);
- if (ret < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | OPEN SPACE DEVICE SPACE WORD SPACE WORD END {
- char *nb = $5, *mask = $7;
- struct parser_pdata *pdata = yyget_extra(scanner);
- unsigned long samples_count = atol(nb);
- int ret = open_dev(pdata, $3, samples_count, mask, false);
- free(nb);
- free(mask);
- if (ret < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | CLOSE SPACE DEVICE END {
- struct parser_pdata *pdata = yyget_extra(scanner);
- int ret = close_dev(pdata, $3);
- if (ret < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | READ SPACE DEVICE END {
- struct parser_pdata *pdata = yyget_extra(scanner);
- if (read_dev_attr(pdata, $3, NULL, IIO_ATTR_TYPE_DEVICE) < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | READ SPACE DEVICE SPACE WORD END {
- char *attr = $5;
- struct parser_pdata *pdata = yyget_extra(scanner);
- ssize_t ret = read_dev_attr(pdata, $3, attr, IIO_ATTR_TYPE_DEVICE);
- free(attr);
- if (ret < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | READ SPACE DEVICE SPACE DEBUG_ATTR END {
- struct parser_pdata *pdata = yyget_extra(scanner);
- if (read_dev_attr(pdata, $3, NULL, IIO_ATTR_TYPE_DEBUG) < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | READ SPACE DEVICE SPACE DEBUG_ATTR SPACE WORD END {
- char *attr = $7;
- struct parser_pdata *pdata = yyget_extra(scanner);
- ssize_t ret = read_dev_attr(pdata, $3, attr, IIO_ATTR_TYPE_DEBUG);
- free(attr);
- if (ret < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | READ SPACE DEVICE SPACE BUFFER_ATTR END {
- struct parser_pdata *pdata = yyget_extra(scanner);
- if (read_dev_attr(pdata, $3, NULL, IIO_ATTR_TYPE_BUFFER) < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | READ SPACE DEVICE SPACE BUFFER_ATTR SPACE WORD END {
- char *attr = $7;
- struct parser_pdata *pdata = yyget_extra(scanner);
- ssize_t ret = read_dev_attr(pdata, $3, attr, IIO_ATTR_TYPE_BUFFER);
- free(attr);
- if (ret < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | READ SPACE DEVICE SPACE IN_OUT SPACE CHANNEL END {
- struct parser_pdata *pdata = yyget_extra(scanner);
- if (read_chn_attr(pdata, $7, NULL) < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | READ SPACE DEVICE SPACE IN_OUT SPACE CHANNEL SPACE WORD END {
- char *attr = $9;
- struct parser_pdata *pdata = yyget_extra(scanner);
- ssize_t ret = read_chn_attr(pdata, $7, attr);
- free(attr);
- if (ret < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | READBUF SPACE DEVICE SPACE WORD END {
- char *len = $5;
- unsigned long nb = atol(len);
- struct parser_pdata *pdata = yyget_extra(scanner);
- ssize_t ret = rw_dev(pdata, $3, nb, false);
- free(len);
- if (ret < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | WRITEBUF SPACE DEVICE SPACE WORD END {
- char *len = $5;
- unsigned long nb = atol(len);
- struct parser_pdata *pdata = yyget_extra(scanner);
- ssize_t ret = rw_dev(pdata, $3, nb, true);
-
- /* Discard additional data */
- yyclearin;
-
- free(len);
- if (ret < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | WRITE SPACE DEVICE SPACE WORD END {
- char *len = $5;
- unsigned long nb = atol(len);
- struct parser_pdata *pdata = yyget_extra(scanner);
- ssize_t ret = write_dev_attr(pdata, $3, NULL, nb, IIO_ATTR_TYPE_DEVICE);
- free(len);
- if (ret < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | WRITE SPACE DEVICE SPACE WORD SPACE WORD END {
- char *attr = $5, *len = $7;
- unsigned long nb = atol(len);
- struct parser_pdata *pdata = yyget_extra(scanner);
- ssize_t ret = write_dev_attr(pdata, $3, attr, nb, IIO_ATTR_TYPE_DEVICE);
- free(attr);
- free(len);
- if (ret < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | WRITE SPACE DEVICE SPACE DEBUG_ATTR SPACE WORD END {
- char *len = $7;
- unsigned long nb = atol(len);
- struct parser_pdata *pdata = yyget_extra(scanner);
- ssize_t ret = write_dev_attr(pdata, $3, NULL, nb, IIO_ATTR_TYPE_DEBUG);
- free(len);
- if (ret < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | WRITE SPACE DEVICE SPACE DEBUG_ATTR SPACE WORD SPACE WORD END {
- char *attr = $7, *len = $9;
- unsigned long nb = atol(len);
- struct parser_pdata *pdata = yyget_extra(scanner);
- ssize_t ret = write_dev_attr(pdata, $3, attr, nb, IIO_ATTR_TYPE_DEBUG);
- free(attr);
- free(len);
- if (ret < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | WRITE SPACE DEVICE SPACE BUFFER_ATTR SPACE WORD END {
- char *len = $7;
- unsigned long nb = atol(len);
- struct parser_pdata *pdata = yyget_extra(scanner);
- ssize_t ret = write_dev_attr(pdata, $3, NULL, nb, IIO_ATTR_TYPE_BUFFER);
- free(len);
- if (ret < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | WRITE SPACE DEVICE SPACE BUFFER_ATTR SPACE WORD SPACE WORD END {
- char *attr = $7, *len = $9;
- unsigned long nb = atol(len);
- struct parser_pdata *pdata = yyget_extra(scanner);
- ssize_t ret = write_dev_attr(pdata, $3, attr, nb, IIO_ATTR_TYPE_BUFFER);
- free(attr);
- free(len);
- if (ret < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | WRITE SPACE DEVICE SPACE IN_OUT SPACE CHANNEL SPACE WORD END {
- char *len = $9;
- unsigned long nb = atol(len);
- struct parser_pdata *pdata = yyget_extra(scanner);
- ssize_t ret = write_chn_attr(pdata, $7, NULL, nb);
- free(len);
- if (ret < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | WRITE SPACE DEVICE SPACE IN_OUT SPACE CHANNEL SPACE WORD SPACE WORD END {
- char *attr = $9, *len = $11;
- unsigned long nb = atol(len);
- struct parser_pdata *pdata = yyget_extra(scanner);
- ssize_t ret = write_chn_attr(pdata, $7, attr, nb);
- free(attr);
- free(len);
- if (ret < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | SETTRIG SPACE DEVICE SPACE WORD END {
- char *trig = $5;
- struct parser_pdata *pdata = yyget_extra(scanner);
- ssize_t ret = set_trigger(pdata, $3, trig);
- free(trig);
- if (ret < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | SETTRIG SPACE DEVICE END {
- struct parser_pdata *pdata = yyget_extra(scanner);
- if (set_trigger(pdata, $3, NULL) < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | GETTRIG SPACE DEVICE END {
- struct parser_pdata *pdata = yyget_extra(scanner);
- if (get_trigger(pdata, $3) < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | SET SPACE DEVICE SPACE BUFFERS_COUNT SPACE VALUE END {
- struct parser_pdata *pdata = yyget_extra(scanner);
- if (set_buffers_count(pdata, $3, $7) < 0)
- YYABORT;
- else
- YYACCEPT;
- }
- | error END {
- yyclearin;
- yyerrok;
- YYACCEPT;
- }
- ;
-
-%%
-
-void yyerror(yyscan_t scanner, const char *msg)
-{
- struct parser_pdata *pdata = yyget_extra(scanner);
- if (pdata->verbose) {
- output(pdata, "ERROR: ");
- output(pdata, msg);
- output(pdata, "\n");
- } else {
- char buf[128];
- sprintf(buf, "%i\n", -EINVAL);
- output(pdata, buf);
- }
-}
-
-ssize_t yy_input(yyscan_t scanner, char *buf, size_t max_size)
-{
- struct parser_pdata *pdata = yyget_extra(scanner);
- ssize_t ret;
-
- ret = read_line(pdata, buf, max_size);
- if (ret < 0)
- return ret;
- if (ret == 0)
- return -EIO;
-
- if ((size_t) ret == max_size)
- buf[max_size - 1] = '\0';
-
- return ret;
-}
diff --git a/iiod/queue.h b/iiod/queue.h
deleted file mode 100644
index daf4553..0000000
--- a/iiod/queue.h
+++ /dev/null
@@ -1,574 +0,0 @@
-/*
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)queue.h 8.5 (Berkeley) 8/20/94
- */
-
-#ifndef _SYS_QUEUE_H_
-#define _SYS_QUEUE_H_
-
-/*
- * This file defines five types of data structures: singly-linked lists,
- * lists, simple queues, tail queues, and circular queues.
- *
- * A singly-linked list is headed by a single forward pointer. The
- * elements are singly linked for minimum space and pointer manipulation
- * overhead at the expense of O(n) removal for arbitrary elements. New
- * elements can be added to the list after an existing element or at the
- * head of the list. Elements being removed from the head of the list
- * should use the explicit macro for this purpose for optimum
- * efficiency. A singly-linked list may only be traversed in the forward
- * direction. Singly-linked lists are ideal for applications with large
- * datasets and few or no removals or for implementing a LIFO queue.
- *
- * A list is headed by a single forward pointer (or an array of forward
- * pointers for a hash table header). The elements are doubly linked
- * so that an arbitrary element can be removed without a need to
- * traverse the list. New elements can be added to the list before
- * or after an existing element or at the head of the list. A list
- * may only be traversed in the forward direction.
- *
- * A simple queue is headed by a pair of pointers, one the head of the
- * list and the other to the tail of the list. The elements are singly
- * linked to save space, so elements can only be removed from the
- * head of the list. New elements can be added to the list after
- * an existing element, at the head of the list, or at the end of the
- * list. A simple queue may only be traversed in the forward direction.
- *
- * A tail queue is headed by a pair of pointers, one to the head of the
- * list and the other to the tail of the list. The elements are doubly
- * linked so that an arbitrary element can be removed without a need to
- * traverse the list. New elements can be added to the list before or
- * after an existing element, at the head of the list, or at the end of
- * the list. A tail queue may be traversed in either direction.
- *
- * A circle queue is headed by a pair of pointers, one to the head of the
- * list and the other to the tail of the list. The elements are doubly
- * linked so that an arbitrary element can be removed without a need to
- * traverse the list. New elements can be added to the list before or after
- * an existing element, at the head of the list, or at the end of the list.
- * A circle queue may be traversed in either direction, but has a more
- * complex end of list detection.
- *
- * For details on the use of these macros, see the queue(3) manual page.
- */
-
-/*
- * List definitions.
- */
-#define LIST_HEAD(name, type) \
-struct name { \
- struct type *lh_first; /* first element */ \
-}
-
-#define LIST_HEAD_INITIALIZER(head) \
- { NULL }
-
-#define LIST_ENTRY(type) \
-struct { \
- struct type *le_next; /* next element */ \
- struct type **le_prev; /* address of previous next element */ \
-}
-
-/*
- * List functions.
- */
-#define LIST_INIT(head) do { \
- (head)->lh_first = NULL; \
-} while (/*CONSTCOND*/0)
-
-#define LIST_INSERT_AFTER(listelm, elm, field) do { \
- if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
- (listelm)->field.le_next->field.le_prev = \
- &(elm)->field.le_next; \
- (listelm)->field.le_next = (elm); \
- (elm)->field.le_prev = &(listelm)->field.le_next; \
-} while (/*CONSTCOND*/0)
-
-#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
- (elm)->field.le_prev = (listelm)->field.le_prev; \
- (elm)->field.le_next = (listelm); \
- *(listelm)->field.le_prev = (elm); \
- (listelm)->field.le_prev = &(elm)->field.le_next; \
-} while (/*CONSTCOND*/0)
-
-#define LIST_INSERT_HEAD(head, elm, field) do { \
- if (((elm)->field.le_next = (head)->lh_first) != NULL) \
- (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
- (head)->lh_first = (elm); \
- (elm)->field.le_prev = &(head)->lh_first; \
-} while (/*CONSTCOND*/0)
-
-#define LIST_REMOVE(elm, field) do { \
- if ((elm)->field.le_next != NULL) \
- (elm)->field.le_next->field.le_prev = \
- (elm)->field.le_prev; \
- *(elm)->field.le_prev = (elm)->field.le_next; \
-} while (/*CONSTCOND*/0)
-
-#define LIST_FOREACH(var, head, field) \
- for ((var) = ((head)->lh_first); \
- (var); \
- (var) = ((var)->field.le_next))
-
-/*
- * List access methods.
- */
-#define LIST_EMPTY(head) ((head)->lh_first == NULL)
-#define LIST_FIRST(head) ((head)->lh_first)
-#define LIST_NEXT(elm, field) ((elm)->field.le_next)
-
-
-/*
- * Singly-linked List definitions.
- */
-#define SLIST_HEAD(name, type) \
-struct name { \
- struct type *slh_first; /* first element */ \
-}
-
-#define SLIST_HEAD_INITIALIZER(head) \
- { NULL }
-
-#define SLIST_ENTRY(type) \
-struct { \
- struct type *sle_next; /* next element */ \
-}
-
-/*
- * Singly-linked List functions.
- */
-#define SLIST_INIT(head) do { \
- (head)->slh_first = NULL; \
-} while (/*CONSTCOND*/0)
-
-#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
- (elm)->field.sle_next = (slistelm)->field.sle_next; \
- (slistelm)->field.sle_next = (elm); \
-} while (/*CONSTCOND*/0)
-
-#define SLIST_INSERT_HEAD(head, elm, field) do { \
- (elm)->field.sle_next = (head)->slh_first; \
- (head)->slh_first = (elm); \
-} while (/*CONSTCOND*/0)
-
-#define SLIST_REMOVE_HEAD(head, field) do { \
- (head)->slh_first = (head)->slh_first->field.sle_next; \
-} while (/*CONSTCOND*/0)
-
-#define SLIST_REMOVE(head, elm, type, field) do { \
- if ((head)->slh_first == (elm)) { \
- SLIST_REMOVE_HEAD((head), field); \
- } \
- else { \
- struct type *curelm = (head)->slh_first; \
- while(curelm->field.sle_next != (elm)) \
- curelm = curelm->field.sle_next; \
- curelm->field.sle_next = \
- curelm->field.sle_next->field.sle_next; \
- } \
-} while (/*CONSTCOND*/0)
-
-#define SLIST_FOREACH(var, head, field) \
- for((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next)
-
-/*
- * Singly-linked List access methods.
- */
-#define SLIST_EMPTY(head) ((head)->slh_first == NULL)
-#define SLIST_FIRST(head) ((head)->slh_first)
-#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
-
-
-/*
- * Singly-linked Tail queue declarations.
- */
-#define STAILQ_HEAD(name, type) \
-struct name { \
- struct type *stqh_first; /* first element */ \
- struct type **stqh_last; /* addr of last next element */ \
-}
-
-#define STAILQ_HEAD_INITIALIZER(head) \
- { NULL, &(head).stqh_first }
-
-#define STAILQ_ENTRY(type) \
-struct { \
- struct type *stqe_next; /* next element */ \
-}
-
-/*
- * Singly-linked Tail queue functions.
- */
-#define STAILQ_INIT(head) do { \
- (head)->stqh_first = NULL; \
- (head)->stqh_last = &(head)->stqh_first; \
-} while (/*CONSTCOND*/0)
-
-#define STAILQ_INSERT_HEAD(head, elm, field) do { \
- if (((elm)->field.stqe_next = (head)->stqh_first) == NULL) \
- (head)->stqh_last = &(elm)->field.stqe_next; \
- (head)->stqh_first = (elm); \
-} while (/*CONSTCOND*/0)
-
-#define STAILQ_INSERT_TAIL(head, elm, field) do { \
- (elm)->field.stqe_next = NULL; \
- *(head)->stqh_last = (elm); \
- (head)->stqh_last = &(elm)->field.stqe_next; \
-} while (/*CONSTCOND*/0)
-
-#define STAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
- if (((elm)->field.stqe_next = (listelm)->field.stqe_next) == NULL)\
- (head)->stqh_last = &(elm)->field.stqe_next; \
- (listelm)->field.stqe_next = (elm); \
-} while (/*CONSTCOND*/0)
-
-#define STAILQ_REMOVE_HEAD(head, field) do { \
- if (((head)->stqh_first = (head)->stqh_first->field.stqe_next) == NULL) \
- (head)->stqh_last = &(head)->stqh_first; \
-} while (/*CONSTCOND*/0)
-
-#define STAILQ_REMOVE(head, elm, type, field) do { \
- if ((head)->stqh_first == (elm)) { \
- STAILQ_REMOVE_HEAD((head), field); \
- } else { \
- struct type *curelm = (head)->stqh_first; \
- while (curelm->field.stqe_next != (elm)) \
- curelm = curelm->field.stqe_next; \
- if ((curelm->field.stqe_next = \
- curelm->field.stqe_next->field.stqe_next) == NULL) \
- (head)->stqh_last = &(curelm)->field.stqe_next; \
- } \
-} while (/*CONSTCOND*/0)
-
-#define STAILQ_FOREACH(var, head, field) \
- for ((var) = ((head)->stqh_first); \
- (var); \
- (var) = ((var)->field.stqe_next))
-
-#define STAILQ_CONCAT(head1, head2) do { \
- if (!STAILQ_EMPTY((head2))) { \
- *(head1)->stqh_last = (head2)->stqh_first; \
- (head1)->stqh_last = (head2)->stqh_last; \
- STAILQ_INIT((head2)); \
- } \
-} while (/*CONSTCOND*/0)
-
-/*
- * Singly-linked Tail queue access methods.
- */
-#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
-#define STAILQ_FIRST(head) ((head)->stqh_first)
-#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
-
-
-/*
- * Simple queue definitions.
- */
-#define SIMPLEQ_HEAD(name, type) \
-struct name { \
- struct type *sqh_first; /* first element */ \
- struct type **sqh_last; /* addr of last next element */ \
-}
-
-#define SIMPLEQ_HEAD_INITIALIZER(head) \
- { NULL, &(head).sqh_first }
-
-#define SIMPLEQ_ENTRY(type) \
-struct { \
- struct type *sqe_next; /* next element */ \
-}
-
-/*
- * Simple queue functions.
- */
-#define SIMPLEQ_INIT(head) do { \
- (head)->sqh_first = NULL; \
- (head)->sqh_last = &(head)->sqh_first; \
-} while (/*CONSTCOND*/0)
-
-#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
- if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
- (head)->sqh_last = &(elm)->field.sqe_next; \
- (head)->sqh_first = (elm); \
-} while (/*CONSTCOND*/0)
-
-#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
- (elm)->field.sqe_next = NULL; \
- *(head)->sqh_last = (elm); \
- (head)->sqh_last = &(elm)->field.sqe_next; \
-} while (/*CONSTCOND*/0)
-
-#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
- if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
- (head)->sqh_last = &(elm)->field.sqe_next; \
- (listelm)->field.sqe_next = (elm); \
-} while (/*CONSTCOND*/0)
-
-#define SIMPLEQ_REMOVE_HEAD(head, field) do { \
- if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
- (head)->sqh_last = &(head)->sqh_first; \
-} while (/*CONSTCOND*/0)
-
-#define SIMPLEQ_REMOVE(head, elm, type, field) do { \
- if ((head)->sqh_first == (elm)) { \
- SIMPLEQ_REMOVE_HEAD((head), field); \
- } else { \
- struct type *curelm = (head)->sqh_first; \
- while (curelm->field.sqe_next != (elm)) \
- curelm = curelm->field.sqe_next; \
- if ((curelm->field.sqe_next = \
- curelm->field.sqe_next->field.sqe_next) == NULL) \
- (head)->sqh_last = &(curelm)->field.sqe_next; \
- } \
-} while (/*CONSTCOND*/0)
-
-#define SIMPLEQ_FOREACH(var, head, field) \
- for ((var) = ((head)->sqh_first); \
- (var); \
- (var) = ((var)->field.sqe_next))
-
-/*
- * Simple queue access methods.
- */
-#define SIMPLEQ_EMPTY(head) ((head)->sqh_first == NULL)
-#define SIMPLEQ_FIRST(head) ((head)->sqh_first)
-#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
-
-
-/*
- * Tail queue definitions.
- */
-#define _TAILQ_HEAD(name, type, qual) \
-struct name { \
- qual type *tqh_first; /* first element */ \
- qual type *qual *tqh_last; /* addr of last next element */ \
-}
-#define TAILQ_HEAD(name, type) _TAILQ_HEAD(name, struct type,)
-
-#define TAILQ_HEAD_INITIALIZER(head) \
- { NULL, &(head).tqh_first }
-
-#define _TAILQ_ENTRY(type, qual) \
-struct { \
- qual type *tqe_next; /* next element */ \
- qual type *qual *tqe_prev; /* address of previous next element */\
-}
-#define TAILQ_ENTRY(type) _TAILQ_ENTRY(struct type,)
-
-/*
- * Tail queue functions.
- */
-#define TAILQ_INIT(head) do { \
- (head)->tqh_first = NULL; \
- (head)->tqh_last = &(head)->tqh_first; \
-} while (/*CONSTCOND*/0)
-
-#define TAILQ_INSERT_HEAD(head, elm, field) do { \
- if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
- (head)->tqh_first->field.tqe_prev = \
- &(elm)->field.tqe_next; \
- else \
- (head)->tqh_last = &(elm)->field.tqe_next; \
- (head)->tqh_first = (elm); \
- (elm)->field.tqe_prev = &(head)->tqh_first; \
-} while (/*CONSTCOND*/0)
-
-#define TAILQ_INSERT_TAIL(head, elm, field) do { \
- (elm)->field.tqe_next = NULL; \
- (elm)->field.tqe_prev = (head)->tqh_last; \
- *(head)->tqh_last = (elm); \
- (head)->tqh_last = &(elm)->field.tqe_next; \
-} while (/*CONSTCOND*/0)
-
-#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
- if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
- (elm)->field.tqe_next->field.tqe_prev = \
- &(elm)->field.tqe_next; \
- else \
- (head)->tqh_last = &(elm)->field.tqe_next; \
- (listelm)->field.tqe_next = (elm); \
- (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
-} while (/*CONSTCOND*/0)
-
-#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
- (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
- (elm)->field.tqe_next = (listelm); \
- *(listelm)->field.tqe_prev = (elm); \
- (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
-} while (/*CONSTCOND*/0)
-
-#define TAILQ_REMOVE(head, elm, field) do { \
- if (((elm)->field.tqe_next) != NULL) \
- (elm)->field.tqe_next->field.tqe_prev = \
- (elm)->field.tqe_prev; \
- else \
- (head)->tqh_last = (elm)->field.tqe_prev; \
- *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
-} while (/*CONSTCOND*/0)
-
-#define TAILQ_FOREACH(var, head, field) \
- for ((var) = ((head)->tqh_first); \
- (var); \
- (var) = ((var)->field.tqe_next))
-
-#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
- for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last)); \
- (var); \
- (var) = (*(((struct headname *)((var)->field.tqe_prev))->tqh_last)))
-
-#define TAILQ_CONCAT(head1, head2, field) do { \
- if (!TAILQ_EMPTY(head2)) { \
- *(head1)->tqh_last = (head2)->tqh_first; \
- (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
- (head1)->tqh_last = (head2)->tqh_last; \
- TAILQ_INIT((head2)); \
- } \
-} while (/*CONSTCOND*/0)
-
-/*
- * Tail queue access methods.
- */
-#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
-#define TAILQ_FIRST(head) ((head)->tqh_first)
-#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
-
-#define TAILQ_LAST(head, headname) \
- (*(((struct headname *)((head)->tqh_last))->tqh_last))
-#define TAILQ_PREV(elm, headname, field) \
- (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
-
-
-/*
- * Circular queue definitions.
- */
-#define CIRCLEQ_HEAD(name, type) \
-struct name { \
- struct type *cqh_first; /* first element */ \
- struct type *cqh_last; /* last element */ \
-}
-
-#define CIRCLEQ_HEAD_INITIALIZER(head) \
- { (void *)&head, (void *)&head }
-
-#define CIRCLEQ_ENTRY(type) \
-struct { \
- struct type *cqe_next; /* next element */ \
- struct type *cqe_prev; /* previous element */ \
-}
-
-/*
- * Circular queue functions.
- */
-#define CIRCLEQ_INIT(head) do { \
- (head)->cqh_first = (void *)(head); \
- (head)->cqh_last = (void *)(head); \
-} while (/*CONSTCOND*/0)
-
-#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
- (elm)->field.cqe_next = (listelm)->field.cqe_next; \
- (elm)->field.cqe_prev = (listelm); \
- if ((listelm)->field.cqe_next == (void *)(head)) \
- (head)->cqh_last = (elm); \
- else \
- (listelm)->field.cqe_next->field.cqe_prev = (elm); \
- (listelm)->field.cqe_next = (elm); \
-} while (/*CONSTCOND*/0)
-
-#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
- (elm)->field.cqe_next = (listelm); \
- (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
- if ((listelm)->field.cqe_prev == (void *)(head)) \
- (head)->cqh_first = (elm); \
- else \
- (listelm)->field.cqe_prev->field.cqe_next = (elm); \
- (listelm)->field.cqe_prev = (elm); \
-} while (/*CONSTCOND*/0)
-
-#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
- (elm)->field.cqe_next = (head)->cqh_first; \
- (elm)->field.cqe_prev = (void *)(head); \
- if ((head)->cqh_last == (void *)(head)) \
- (head)->cqh_last = (elm); \
- else \
- (head)->cqh_first->field.cqe_prev = (elm); \
- (head)->cqh_first = (elm); \
-} while (/*CONSTCOND*/0)
-
-#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
- (elm)->field.cqe_next = (void *)(head); \
- (elm)->field.cqe_prev = (head)->cqh_last; \
- if ((head)->cqh_first == (void *)(head)) \
- (head)->cqh_first = (elm); \
- else \
- (head)->cqh_last->field.cqe_next = (elm); \
- (head)->cqh_last = (elm); \
-} while (/*CONSTCOND*/0)
-
-#define CIRCLEQ_REMOVE(head, elm, field) do { \
- if ((elm)->field.cqe_next == (void *)(head)) \
- (head)->cqh_last = (elm)->field.cqe_prev; \
- else \
- (elm)->field.cqe_next->field.cqe_prev = \
- (elm)->field.cqe_prev; \
- if ((elm)->field.cqe_prev == (void *)(head)) \
- (head)->cqh_first = (elm)->field.cqe_next; \
- else \
- (elm)->field.cqe_prev->field.cqe_next = \
- (elm)->field.cqe_next; \
-} while (/*CONSTCOND*/0)
-
-#define CIRCLEQ_FOREACH(var, head, field) \
- for ((var) = ((head)->cqh_first); \
- (var) != (const void *)(head); \
- (var) = ((var)->field.cqe_next))
-
-#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
- for ((var) = ((head)->cqh_last); \
- (var) != (const void *)(head); \
- (var) = ((var)->field.cqe_prev))
-
-/*
- * Circular queue access methods.
- */
-#define CIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head))
-#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
-#define CIRCLEQ_LAST(head) ((head)->cqh_last)
-#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
-#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
-
-#define CIRCLEQ_LOOP_NEXT(head, elm, field) \
- (((elm)->field.cqe_next == (void *)(head)) \
- ? ((head)->cqh_first) \
- : (elm->field.cqe_next))
-#define CIRCLEQ_LOOP_PREV(head, elm, field) \
- (((elm)->field.cqe_prev == (void *)(head)) \
- ? ((head)->cqh_last) \
- : (elm->field.cqe_prev))
-
-#endif /* sys/queue.h */
diff --git a/iiod/thread-pool.c b/iiod/thread-pool.c
deleted file mode 100644
index b3a152d..0000000
--- a/iiod/thread-pool.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2016 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.
- */
-
-#include "thread-pool.h"
-
-#include <errno.h>
-#include <pthread.h>
-#include <signal.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <sys/eventfd.h>
-#include <unistd.h>
-
-/*
- * This is used to make sure that all active threads have finished cleanup when
- * a STOP event is received. We don't use pthread_join() since for most threads
- * we are OK with them exiting asynchronously and there really is no place to
- * call pthread_join() to free the thread's resources. We only need to
- * synchronize the threads that are still active when the iiod is shutdown to
- * give them a chance to release all resources, disable buffers etc, before
- * iio_context_destroy() is called.
- */
-
-struct thread_pool {
- pthread_mutex_t thread_count_lock;
- pthread_cond_t thread_count_cond;
- unsigned int thread_count;
- int stop_fd;
-};
-
-struct thread_body_data {
- struct thread_pool *pool;
- void (*f)(struct thread_pool *, void *);
- void *d;
-};
-
-static void thread_pool_thread_started(struct thread_pool *pool)
-{
- pthread_mutex_lock(&pool->thread_count_lock);
- pool->thread_count++;
- pthread_mutex_unlock(&pool->thread_count_lock);
-}
-
-static void thread_pool_thread_stopped(struct thread_pool *pool)
-{
- pthread_mutex_lock(&pool->thread_count_lock);
- pool->thread_count--;
- pthread_cond_signal(&pool->thread_count_cond);
- pthread_mutex_unlock(&pool->thread_count_lock);
-}
-
-static void * thread_body(void *d)
-{
- struct thread_body_data *pdata = d;
-
- (*pdata->f)(pdata->pool, pdata->d);
-
- thread_pool_thread_stopped(pdata->pool);
- free(pdata);
-
- return NULL;
-}
-
-int thread_pool_add_thread(struct thread_pool *pool,
- void (*f)(struct thread_pool *, void *),
- void *d, const char *name)
-{
- struct thread_body_data *pdata;
- sigset_t sigmask, oldsigmask;
- pthread_attr_t attr;
- pthread_t thd;
- int ret;
-
- pdata = malloc(sizeof(*pdata));
- if (!pdata)
- return -ENOMEM;
-
- pdata->f = f;
- pdata->d = d;
- pdata->pool = pool;
-
- sigfillset(&sigmask);
- pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask);
-
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
- /* In order to avoid race conditions thread_pool_thread_started() must
- * be called before the thread is created and
- * thread_pool_thread_stopped() must be called right before leaving
- * the thread. */
- thread_pool_thread_started(pool);
-
- ret = pthread_create(&thd, &attr, thread_body, pdata);
- if (ret) {
- free(pdata);
- thread_pool_thread_stopped(pool);
- } else {
-#ifdef HAS_PTHREAD_SETNAME_NP
- pthread_setname_np(thd, name);
-#endif
- }
-
- pthread_attr_destroy(&attr);
- pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
- return ret;
-}
-
-struct thread_pool * thread_pool_new(void)
-{
- struct thread_pool *pool;
-
- pool = malloc(sizeof(*pool));
- if (!pool) {
- errno = ENOMEM;
- return NULL;
- }
-
- pool->stop_fd = eventfd(0, EFD_NONBLOCK);
- if (pool->stop_fd == -1) {
- int err = errno;
-
- free(pool);
- errno = err;
- return NULL;
- }
-
- pthread_mutex_init(&pool->thread_count_lock, NULL);
- pthread_cond_init(&pool->thread_count_cond, NULL);
- pool->thread_count = 0;
-
- return pool;
-}
-
-int thread_pool_get_poll_fd(const struct thread_pool *pool)
-{
- return pool->stop_fd;
-}
-
-void thread_pool_stop(struct thread_pool *pool)
-{
- uint64_t e = 1;
- int ret;
-
- do {
- ret = write(pool->stop_fd, &e, sizeof(e));
- } while (ret == -1 && errno == EINTR);
-}
-
-void thread_pool_stop_and_wait(struct thread_pool *pool)
-{
- uint64_t e;
- int ret;
-
- thread_pool_stop(pool);
-
- pthread_mutex_lock(&pool->thread_count_lock);
- while (pool->thread_count)
- pthread_cond_wait(&pool->thread_count_cond,
- &pool->thread_count_lock);
- pthread_mutex_unlock(&pool->thread_count_lock);
-
- do {
- ret = read(pool->stop_fd, &e, sizeof(e));
- } while (ret != -1 || errno == EINTR);
-}
-
-void thread_pool_destroy(struct thread_pool *pool)
-{
- pthread_mutex_destroy(&pool->thread_count_lock);
- pthread_cond_destroy(&pool->thread_count_cond);
-
- close(pool->stop_fd);
- free(pool);
-}
diff --git a/iiod/thread-pool.h b/iiod/thread-pool.h
deleted file mode 100644
index 9dbe72a..0000000
--- a/iiod/thread-pool.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2016 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.
- */
-
-#ifndef __THREAD_POOL_H__
-#define __THREAD_POOL_H__
-
-struct thread_pool;
-
-struct thread_pool * thread_pool_new(void);
-
-int thread_pool_get_poll_fd(const struct thread_pool *pool);
-void thread_pool_stop(struct thread_pool *pool);
-void thread_pool_stop_and_wait(struct thread_pool *pool);
-
-void thread_pool_destroy(struct thread_pool *pool);
-
-int thread_pool_add_thread(struct thread_pool *pool,
- void (*func)(struct thread_pool *, void *),
- void *data, const char *name);
-
-#endif /* __THREAD_POOL_H__ */
diff --git a/iiod/usbd.c b/iiod/usbd.c
deleted file mode 100644
index ea58c79..0000000
--- a/iiod/usbd.c
+++ /dev/null
@@ -1,408 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2016 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.
- */
-
-#include "../debug.h"
-#include "../iio-private.h"
-#include "ops.h"
-#include "thread-pool.h"
-
-#include <fcntl.h>
-#include <linux/usb/functionfs.h>
-#include <stdint.h>
-#include <string.h>
-
-/* u8"IIO" for non-c11 compilers */
-#define NAME "\x0049\x0049\x004F"
-
-#define LE32(x) ((__BYTE_ORDER != __BIG_ENDIAN) ? (x) : __bswap_constant_32(x))
-#define LE16(x) ((__BYTE_ORDER != __BIG_ENDIAN) ? (x) : __bswap_constant_16(x))
-
-#define IIO_USD_CMD_RESET_PIPES 0
-#define IIO_USD_CMD_OPEN_PIPE 1
-#define IIO_USD_CMD_CLOSE_PIPE 2
-
-
-struct usb_ffs_header {
- struct usb_functionfs_descs_head_v2 header;
- uint32_t nb_fs, nb_hs, nb_ss;
-} __attribute__((packed));
-
-struct usb_ffs_strings {
- struct usb_functionfs_strings_head head;
- uint16_t lang;
- const char string[sizeof(NAME)];
-} __attribute__((packed));
-
-struct usbd_pdata {
- struct iio_context *ctx;
- char *ffs;
- int ep0_fd;
- bool debug, use_aio;
- struct thread_pool **pool;
- unsigned int nb_pipes;
-};
-
-struct usbd_client_pdata {
- struct usbd_pdata *pdata;
- int ep_in, ep_out;
-};
-
-static const struct usb_ffs_strings ffs_strings = {
- .head = {
- .magic = LE32(FUNCTIONFS_STRINGS_MAGIC),
- .length = LE32(sizeof(ffs_strings)),
- .str_count = LE32(1),
- .lang_count = LE32(1),
- },
-
- .lang = LE16(0x409),
- .string = NAME,
-};
-
-static void usbd_client_thread(struct thread_pool *pool, void *d)
-{
- struct usbd_client_pdata *pdata = d;
-
- interpreter(pdata->pdata->ctx, pdata->ep_in, pdata->ep_out,
- pdata->pdata->debug, false,
- pdata->pdata->use_aio, pool);
-
- close(pdata->ep_in);
- close(pdata->ep_out);
- free(pdata);
-}
-
-static int usb_open_pipe(struct usbd_pdata *pdata, unsigned int pipe_id)
-{
- struct usbd_client_pdata *cpdata;
- char buf[256];
- int err;
-
- if (pipe_id >= pdata->nb_pipes)
- return -EINVAL;
-
- cpdata = malloc(sizeof(*cpdata));
- if (!pdata)
- return -ENOMEM;
-
- /* Either we open this pipe for the first time, or it was closed before.
- * In that case we called thread_pool_stop() without waiting for all the
- * threads to finish. We do that here. Since the running thread might still
- * have a open handle to the endpoints make sure that they have exited
- * before opening the endpoints again. */
- thread_pool_stop_and_wait(pdata->pool[pipe_id]);
-
- snprintf(buf, sizeof(buf), "%s/ep%u", pdata->ffs, pipe_id * 2 + 1);
- cpdata->ep_out = open(buf, O_WRONLY);
- if (cpdata->ep_out < 0) {
- err = -errno;
- goto err_free_cpdata;
- }
-
- snprintf(buf, sizeof(buf), "%s/ep%u", pdata->ffs, pipe_id * 2 + 2);
- cpdata->ep_in = open(buf, O_RDONLY);
- if (cpdata->ep_in < 0) {
- err = -errno;
- goto err_close_ep_out;
- }
-
- cpdata->pdata = pdata;
-
- err = thread_pool_add_thread(pdata->pool[pipe_id],
- usbd_client_thread, cpdata, "usbd_client_thd");
- if (!err)
- return 0;
-
- close(cpdata->ep_in);
-err_close_ep_out:
- close(cpdata->ep_out);
-err_free_cpdata:
- free(cpdata);
- return err;
-}
-
-static int usb_close_pipe(struct usbd_pdata *pdata, unsigned int pipe_id)
-{
- if (pipe_id >= pdata->nb_pipes)
- return -EINVAL;
-
- thread_pool_stop(pdata->pool[pipe_id]);
- return 0;
-}
-
-static void usb_close_pipes(struct usbd_pdata *pdata)
-{
- unsigned int i;
-
- for (i = 0; i < pdata->nb_pipes; i++)
- usb_close_pipe(pdata, i);
-}
-
-static int handle_event(struct usbd_pdata *pdata,
- const struct usb_functionfs_event *event)
-{
- int ret = 0;
-
- if (event->type == FUNCTIONFS_SETUP) {
- const struct usb_ctrlrequest *req = &event->u.setup;
-
- switch (req->bRequest) {
- case IIO_USD_CMD_RESET_PIPES:
- usb_close_pipes(pdata);
- break;
- case IIO_USD_CMD_OPEN_PIPE:
- ret = usb_open_pipe(pdata, le16toh(req->wValue));
- break;
- case IIO_USD_CMD_CLOSE_PIPE:
- ret = usb_close_pipe(pdata, le16toh(req->wValue));
- break;
- }
- }
-
- return ret;
-}
-
-static void usbd_main(struct thread_pool *pool, void *d)
-{
- int stop_fd = thread_pool_get_poll_fd(pool);
- struct usbd_pdata *pdata = d;
- unsigned int i;
-
- for (;;) {
- struct usb_functionfs_event event;
- struct pollfd pfd[2];
- int ret;
-
- pfd[0].fd = pdata->ep0_fd;
- pfd[0].events = POLLIN;
- pfd[0].revents = 0;
- pfd[1].fd = stop_fd;
- pfd[1].events = POLLIN;
- pfd[1].revents = 0;
-
- poll_nointr(pfd, 2);
-
- if (pfd[1].revents & POLLIN) /* STOP event */
- break;
-
- if (!(pfd[0].revents & POLLIN)) /* Should never happen. */
- continue;
-
- ret = read(pdata->ep0_fd, &event, sizeof(event));
- if (ret != sizeof(event)) {
- WARNING("Short read!\n");
- continue;
- }
-
- ret = handle_event(pdata, &event);
- if (ret) {
- ERROR("Unable to handle event: %i\n", ret);
- break;
- }
-
- /* Clear out the errors on ep0 when we close endpoints */
- ret = read(pdata->ep0_fd, NULL, 0);
- }
-
- for (i = 0; i < pdata->nb_pipes; i++) {
- thread_pool_stop_and_wait(pdata->pool[i]);
- thread_pool_destroy(pdata->pool[i]);
- }
-
- close(pdata->ep0_fd);
- free(pdata->ffs);
- free(pdata->pool);
- free(pdata);
-}
-
-static struct usb_ffs_header * create_header(
- unsigned int nb_pipes, uint32_t size)
-{
- /* Packet sizes for USB high-speed, full-speed, super-speed */
- const unsigned int packet_sizes[3] = { 64, 512, 1024, };
- struct usb_ffs_header *hdr;
- unsigned int i, pipe_id;
- uintptr_t ptr;
-
- hdr = zalloc(size);
- if (!hdr) {
- errno = ENOMEM;
- return NULL;
- }
-
- hdr->header.magic = LE32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2);
- hdr->header.length = htole32(size);
- hdr->header.flags = LE32(FUNCTIONFS_HAS_FS_DESC |
- FUNCTIONFS_HAS_HS_DESC |
- FUNCTIONFS_HAS_SS_DESC);
-
- hdr->nb_fs = htole32(nb_pipes * 2 + 1);
- hdr->nb_hs = htole32(nb_pipes * 2 + 1);
- hdr->nb_ss = htole32(nb_pipes * 4 + 1);
-
- ptr = ((uintptr_t) hdr) + sizeof(*hdr);
-
- for (i = 0; i < 3; i++) {
- struct usb_interface_descriptor *desc =
- (struct usb_interface_descriptor *) ptr;
- struct usb_endpoint_descriptor_no_audio *ep;
- struct usb_ss_ep_comp_descriptor *comp;
-
- desc->bLength = sizeof(*desc);
- desc->bDescriptorType = USB_DT_INTERFACE;
- desc->bNumEndpoints = nb_pipes * 2;
- desc->bInterfaceClass = USB_CLASS_COMM;
- desc->iInterface = 1;
-
- ep = (struct usb_endpoint_descriptor_no_audio *)
- (ptr + sizeof(*desc));
-
- for (pipe_id = 0; pipe_id < nb_pipes; pipe_id++) {
- ep->bLength = sizeof(*ep);
- ep->bDescriptorType = USB_DT_ENDPOINT;
- ep->bEndpointAddress = (pipe_id + 1) | USB_DIR_IN;
- ep->bmAttributes = USB_ENDPOINT_XFER_BULK;
- ep->wMaxPacketSize = htole16(packet_sizes[i]);
- ep++;
-
- if (i == 2) {
- comp = (struct usb_ss_ep_comp_descriptor *) ep;
- comp->bLength = USB_DT_SS_EP_COMP_SIZE;
- comp->bDescriptorType = USB_DT_SS_ENDPOINT_COMP;
- comp++;
- ep = (struct usb_endpoint_descriptor_no_audio *) comp;
- }
-
- ep->bLength = sizeof(*ep);
- ep->bDescriptorType = USB_DT_ENDPOINT;
- ep->bEndpointAddress = (pipe_id + 1) | USB_DIR_OUT;
- ep->bmAttributes = USB_ENDPOINT_XFER_BULK;
- ep->wMaxPacketSize = htole16(packet_sizes[i]);
- ep++;
-
- if (i == 2) {
- comp = (struct usb_ss_ep_comp_descriptor *) ep;
- comp->bLength = USB_DT_SS_EP_COMP_SIZE;
- comp->bDescriptorType = USB_DT_SS_ENDPOINT_COMP;
- comp++;
- ep = (struct usb_endpoint_descriptor_no_audio *) comp;
- }
- }
-
- ptr += sizeof(*desc) + nb_pipes * 2 * sizeof(*ep);
- }
-
- return hdr;
-}
-
-static int write_header(int fd, unsigned int nb_pipes)
-{
- uint32_t size = sizeof(struct usb_ffs_header) +
- 3 * sizeof(struct usb_interface_descriptor) +
- 6 * nb_pipes * sizeof(struct usb_endpoint_descriptor_no_audio) +
- 2 * nb_pipes * sizeof(struct usb_ss_ep_comp_descriptor);
- struct usb_ffs_header *hdr;
- int ret;
-
- hdr = create_header(nb_pipes, size);
- if (!hdr)
- return -errno;
-
- ret = write(fd, hdr, size);
- free(hdr);
- if (ret < 0)
- return -errno;
-
- ret = write(fd, &ffs_strings, sizeof(ffs_strings));
- if (ret < 0)
- return -errno;
-
- return 0;
-}
-
-int start_usb_daemon(struct iio_context *ctx, const char *ffs,
- bool debug, bool use_aio, unsigned int nb_pipes,
- struct thread_pool *pool)
-{
- struct usbd_pdata *pdata;
- unsigned int i;
- char buf[256];
- int ret;
-
- pdata = zalloc(sizeof(*pdata));
- if (!pdata)
- return -ENOMEM;
-
- pdata->nb_pipes = nb_pipes;
-
- pdata->pool = calloc(nb_pipes, sizeof(*pdata->pool));
- if (!pdata->pool) {
- ret = -ENOMEM;
- goto err_free_pdata;
- }
-
- pdata->ffs = strdup(ffs);
- if (!pdata->ffs) {
- ret = -ENOMEM;
- goto err_free_pdata_pool;
- }
-
- snprintf(buf, sizeof(buf), "%s/ep0", ffs);
-
- pdata->ep0_fd = open(buf, O_RDWR);
- if (pdata->ep0_fd < 0) {
- ret = -errno;
- goto err_free_ffs;
- }
-
- ret = write_header(pdata->ep0_fd, nb_pipes);
- if (ret < 0)
- goto err_close_ep0;
-
- for (i = 0; i < nb_pipes; i++) {
- pdata->pool[i] = thread_pool_new();
- if (!pdata->pool[i]) {
- ret = -errno;
- goto err_free_pools;
- }
- }
-
- pdata->ctx = ctx;
- pdata->debug = debug;
- pdata->use_aio = use_aio;
-
- ret = thread_pool_add_thread(pool, usbd_main, pdata, "usbd_main_thd");
- if (!ret)
- return 0;
-
-err_free_pools:
- /* If we get here, usbd_main was not started, so the pools can be
- * destroyed directly */
- for (i = 0; i < nb_pipes; i++) {
- if (pdata->pool[i])
- thread_pool_destroy(pdata->pool[i]);
- }
-err_close_ep0:
- close(pdata->ep0_fd);
-err_free_ffs:
- free(pdata->ffs);
-err_free_pdata_pool:
- free(pdata->pool);
-err_free_pdata:
- free(pdata);
- return ret;
-}
diff --git a/include/iio.h b/include/iio.h
deleted file mode 120000
index 4d63392..0000000
--- a/include/iio.h
+++ /dev/null
@@ -1 +0,0 @@
-../src/iio.h \ No newline at end of file
diff --git a/libiio.iss.cmakein b/libiio.iss.cmakein
deleted file mode 100644
index e3bf542..0000000
--- a/libiio.iss.cmakein
+++ /dev/null
@@ -1,69 +0,0 @@
-[Setup]
-AppId={{D386A5F6-D38D-4738-94A2-E163DC1896F1}
-AppName="Libiio"
-AppVersion="@VERSION@"
-AppPublisher="Analog Devices, Inc."
-AppPublisherURL="http://www.analog.com"
-AppSupportURL="http://www.analog.com"
-AppUpdatesURL="http://www.analog.com"
-AppCopyright="Copyright 2015-@BUILD_YEAR@ ADI and other contributors"
-CreateAppDir=no
-LicenseFile="C:\projects\libiio\COPYING.txt"
-OutputBaseFilename=libiio-setup
-OutputDir="C:\"
-Compression=lzma
-SolidCompression=yes
-ArchitecturesInstallIn64BitMode=x64
-
-[Languages]
-Name: "english"; MessagesFile: "compiler:Default.isl"
-Name: "brazilianportuguese"; MessagesFile: "compiler:Languages\BrazilianPortuguese.isl"
-Name: "catalan"; MessagesFile: "compiler:Languages\Catalan.isl"
-Name: "corsican"; MessagesFile: "compiler:Languages\Corsican.isl"
-Name: "czech"; MessagesFile: "compiler:Languages\Czech.isl"
-Name: "danish"; MessagesFile: "compiler:Languages\Danish.isl"
-Name: "dutch"; MessagesFile: "compiler:Languages\Dutch.isl"
-Name: "finnish"; MessagesFile: "compiler:Languages\Finnish.isl"
-Name: "french"; MessagesFile: "compiler:Languages\French.isl"
-Name: "german"; MessagesFile: "compiler:Languages\German.isl"
-Name: "greek"; MessagesFile: "compiler:Languages\Greek.isl"
-Name: "hebrew"; MessagesFile: "compiler:Languages\Hebrew.isl"
-Name: "hungarian"; MessagesFile: "compiler:Languages\Hungarian.isl"
-Name: "italian"; MessagesFile: "compiler:Languages\Italian.isl"
-Name: "japanese"; MessagesFile: "compiler:Languages\Japanese.isl"
-Name: "norwegian"; MessagesFile: "compiler:Languages\Norwegian.isl"
-Name: "polish"; MessagesFile: "compiler:Languages\Polish.isl"
-Name: "portuguese"; MessagesFile: "compiler:Languages\Portuguese.isl"
-Name: "russian"; MessagesFile: "compiler:Languages\Russian.isl"
-Name: "scottishgaelic"; MessagesFile: "compiler:Languages\ScottishGaelic.isl"
-Name: "serbiancyrillic"; MessagesFile: "compiler:Languages\SerbianCyrillic.isl"
-Name: "serbianlatin"; MessagesFile: "compiler:Languages\SerbianLatin.isl"
-Name: "slovenian"; MessagesFile: "compiler:Languages\Slovenian.isl"
-Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl"
-Name: "turkish"; MessagesFile: "compiler:Languages\Turkish.isl"
-Name: "ukrainian"; MessagesFile: "compiler:Languages\Ukrainian.isl"
-
-[Files]
-Source: "C:\projects\libiio\build-win32\Release\libiio.dll"; DestDir: "{sys}"; Flags: 32bit
-Source: "C:\projects\libiio\build-win64\Release\libiio.dll"; DestDir: "{sys}"; Check: Is64BitInstallMode
-
-Source: "C:\projects\libiio\build-win32\tests\Release\*.exe"; DestDir: "{sys}"; Check: not Is64BitInstallMode
-Source: "C:\projects\libiio\build-win64\tests\Release\*.exe"; DestDir: "{sys}"; Check: Is64BitInstallMode
-
-Source: "C:\projects\libiio\build-win32\Release\libiio.lib"; DestDir: "{pf32}\Microsoft Visual Studio 12.0\VC\lib"; Check: not Is64BitInstallMode
-Source: "C:\projects\libiio\build-win64\Release\libiio.lib"; DestDir: "{pf32}\Microsoft Visual Studio 12.0\VC\lib\amd64"; Check: Is64BitInstallMode
-Source: "C:\projects\libiio\iio.h"; DestDir: "{pf32}\Microsoft Visual Studio 12.0\VC\include"
-
-Source: "C:\libs\32\libxml2.dll"; DestDir: "{sys}"; Flags: onlyifdoesntexist 32bit
-Source: "C:\libs\64\libxml2.dll"; DestDir: "{sys}"; Check: Is64BitInstallMode; Flags: onlyifdoesntexist
-
-Source: "C:\libs\32\libusb-1.0.dll"; DestDir: "{sys}"; Flags: onlyifdoesntexist 32bit
-Source: "C:\libs\64\libusb-1.0.dll"; DestDir: "{sys}"; Check: Is64BitInstallMode; Flags: onlyifdoesntexist
-
-Source: "C:\libs\32\libserialport-0.dll"; DestDir: "{sys}"; Flags: onlyifdoesntexist 32bit
-Source: "C:\libs\64\libserialport-0.dll"; DestDir: "{sys}"; Check: Is64BitInstallMode; Flags: onlyifdoesntexist
-
-Source: "C:\projects\libiio\build-win32\bindings\csharp\libiio-sharp.dll"; DestDir: "{cf}\libiio"
-
-Source: "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\redist\x86\Microsoft.VC120.CRT\msvcr120.dll"; DestDir: "{sys}"; Flags: onlyifdoesntexist 32bit
-Source: "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\redist\x64\Microsoft.VC120.CRT\msvcr120.dll"; DestDir: "{sys}"; Check: Is64BitInstallMode; Flags: onlyifdoesntexist
diff --git a/libiio.pc.cmakein b/libiio.pc.cmakein
deleted file mode 100644
index 468da5b..0000000
--- a/libiio.pc.cmakein
+++ /dev/null
@@ -1,12 +0,0 @@
-prefix=@CMAKE_INSTALL_PREFIX@
-exec_prefix=${prefix}
-libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
-includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
-
-Name: libiio
-Description: Library for interfacing IIO devices
-Version: @VERSION@
-
-Requires:
-Libs: -L${libdir} -liio
-Cflags: -I${includedir}
diff --git a/libiio.rules.cmakein b/libiio.rules.cmakein
deleted file mode 100644
index 912d278..0000000
--- a/libiio.rules.cmakein
+++ /dev/null
@@ -1 +0,0 @@
-SUBSYSTEM=="usb", PROGRAM=="/bin/sh -c '@CMAKE_INSTALL_FULL_BINDIR@/iio_info -s | grep %s{idVendor}:%s{idProduct}'", RESULT!="", MODE="666"
diff --git a/local.c b/local.c
deleted file mode 100644
index d05afb6..0000000
--- a/local.c
+++ /dev/null
@@ -1,2076 +0,0 @@
-/*
- * 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.
- *
- * */
-
-#include "debug.h"
-#include "iio-private.h"
-#include "sort.h"
-
-#include <dirent.h>
-#include <errno.h>
-#include <limits.h>
-#include <poll.h>
-#include <stdbool.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/eventfd.h>
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/utsname.h>
-#include <time.h>
-#include <unistd.h>
-#include <fcntl.h>
-#ifdef WITH_LOCAL_CONFIG
-#include <ini.h>
-#endif
-
-#define DEFAULT_TIMEOUT_MS 1000
-
-#define NB_BLOCKS 4
-
-#define BLOCK_ALLOC_IOCTL _IOWR('i', 0xa0, struct block_alloc_req)
-#define BLOCK_FREE_IOCTL _IO('i', 0xa1)
-#define BLOCK_QUERY_IOCTL _IOWR('i', 0xa2, struct block)
-#define BLOCK_ENQUEUE_IOCTL _IOWR('i', 0xa3, struct block)
-#define BLOCK_DEQUEUE_IOCTL _IOWR('i', 0xa4, struct block)
-
-#define BLOCK_FLAG_CYCLIC BIT(1)
-
-/* Forward declarations */
-static ssize_t local_read_dev_attr(const struct iio_device *dev,
- const char *attr, char *dst, size_t len, enum iio_attr_type type);
-static ssize_t local_read_chn_attr(const struct iio_channel *chn,
- const char *attr, char *dst, size_t len);
-static ssize_t local_write_dev_attr(const struct iio_device *dev,
- const char *attr, const char *src, size_t len, enum iio_attr_type type);
-static ssize_t local_write_chn_attr(const struct iio_channel *chn,
- const char *attr, const char *src, size_t len);
-
-struct block_alloc_req {
- uint32_t type,
- size,
- count,
- id;
-};
-
-struct block {
- uint32_t id,
- size,
- bytes_used,
- type,
- flags,
- offset;
- uint64_t timestamp;
-};
-
-struct iio_context_pdata {
- unsigned int rw_timeout_ms;
-};
-
-struct iio_device_pdata {
- int fd;
- bool blocking;
- unsigned int samples_count;
- unsigned int max_nb_blocks;
- unsigned int allocated_nb_blocks;
-
- struct block *blocks;
- void **addrs;
- int last_dequeued;
- bool is_high_speed, cyclic, cyclic_buffer_enqueued, buffer_enabled;
-
- int cancel_fd;
-};
-
-struct iio_channel_pdata {
- char *enable_fn;
- struct iio_channel_attr *protected_attrs;
- unsigned int nb_protected_attrs;
-};
-
-static const char * const device_attrs_blacklist[] = {
- "dev",
- "uevent",
-};
-
-static const char * const buffer_attrs_reserved[] = {
- "length",
- "enable",
-};
-
-static int ioctl_nointr(int fd, unsigned long request, void *data)
-{
- int ret;
-
- do {
- ret = ioctl(fd, request, data);
- } while (ret == -1 && errno == EINTR);
-
- return ret;
-}
-
-static void local_free_channel_pdata(struct iio_channel *chn)
-{
- if (chn->pdata) {
- free(chn->pdata->enable_fn);
- free(chn->pdata);
- }
-}
-
-static void local_free_pdata(struct iio_device *device)
-{
- unsigned int i;
-
- for (i = 0; i < device->nb_channels; i++)
- local_free_channel_pdata(device->channels[i]);
-
- if (device->pdata) {
- free(device->pdata->blocks);
- free(device->pdata->addrs);
- free(device->pdata);
- }
-}
-
-static void local_shutdown(struct iio_context *ctx)
-{
- /* Free the backend data stored in every device structure */
- unsigned int i;
-
- for (i = 0; i < ctx->nb_devices; i++) {
- struct iio_device *dev = ctx->devices[i];
-
- iio_device_close(dev);
- local_free_pdata(dev);
- }
-
- free(ctx->pdata);
-}
-
-/** Shrinks the first nb characters of a string
- * e.g. strcut("foobar", 4) replaces the content with "ar". */
-static void strcut(char *str, int nb)
-{
- char *ptr = str + nb;
- while (*ptr)
- *str++ = *ptr++;
- *str = 0;
-}
-
-static int set_channel_name(struct iio_channel *chn)
-{
- struct iio_channel_pdata *pdata = chn->pdata;
- size_t prefix_len = 0;
- const char *attr0;
- const char *ptr;
- unsigned int i;
-
- if (chn->nb_attrs + pdata->nb_protected_attrs < 2)
- return 0;
-
- if (chn->nb_attrs)
- attr0 = ptr = chn->attrs[0].name;
- else
- attr0 = ptr = pdata->protected_attrs[0].name;
-
- while (true) {
- bool can_fix = true;
- size_t len;
-
- ptr = strchr(ptr, '_');
- if (!ptr)
- break;
-
- len = ptr - attr0 + 1;
- for (i = 1; can_fix && i < chn->nb_attrs; i++)
- can_fix = !strncmp(attr0, chn->attrs[i].name, len);
-
- for (i = !chn->nb_attrs;
- can_fix && i < pdata->nb_protected_attrs; i++) {
- can_fix = !strncmp(attr0,
- pdata->protected_attrs[i].name, len);
- }
-
- if (!can_fix)
- break;
-
- prefix_len = len;
- ptr = ptr + 1;
- }
-
- if (prefix_len) {
- char *name;
-
- name = malloc(prefix_len);
- if (!name)
- return -ENOMEM;
- strncpy(name, attr0, prefix_len - 1);
- name[prefix_len - 1] = '\0';
- DEBUG("Setting name of channel %s to %s\n", chn->id, name);
- chn->name = name;
-
- /* Shrink the attribute name */
- for (i = 0; i < chn->nb_attrs; i++)
- strcut(chn->attrs[i].name, prefix_len);
- for (i = 0; i < pdata->nb_protected_attrs; i++)
- strcut(pdata->protected_attrs[i].name, prefix_len);
- }
-
- return 0;
-}
-
-/*
- * Used to generate the timeout parameter for operations like poll. Returns the
- * number of ms until it is timeout_rel ms after the time specified in start. If
- * timeout_rel is 0 returns -1 to indicate no timeout.
- *
- * The timeout that is specified for IIO operations is the maximum time a buffer
- * push() or refill() operation should take before returning. poll() is used to
- * wait for either data activity or for the timeout to elapse. poll() might get
- * interrupted in which case it is called again or the read()/write() operation
- * might not complete the full buffer size in one call in which case we go back
- * to poll() again as well. Passing the same timeout as before would increase
- * the total timeout and if repeated interruptions occur (e.g. by a timer
- * signal) the operation might never time out or with significant delay. Hence
- * before each poll() invocation the timeout is recalculated relative to the
- * start of refill() or push() operation.
- */
-static int get_rel_timeout_ms(struct timespec *start, unsigned int timeout_rel)
-{
- struct timespec now;
- int diff_ms;
-
- if (timeout_rel == 0) /* No timeout */
- return -1;
-
- clock_gettime(CLOCK_MONOTONIC, &now);
-
- diff_ms = (now.tv_sec - start->tv_sec) * 1000;
- diff_ms += (now.tv_nsec - start->tv_nsec) / 1000000;
-
- if (diff_ms >= timeout_rel) /* Expired */
- return 0;
- if (diff_ms > 0) /* Should never be false, but lets be safe */
- timeout_rel -= diff_ms;
- if (timeout_rel > INT_MAX)
- return INT_MAX;
-
- return (int) timeout_rel;
-}
-
-static int device_check_ready(const struct iio_device *dev, short events,
- struct timespec *start)
-{
- struct pollfd pollfd[2] = {
- {
- .fd = dev->pdata->fd,
- .events = events,
- }, {
- .fd = dev->pdata->cancel_fd,
- .events = POLLIN,
- }
- };
- unsigned int rw_timeout_ms = dev->ctx->pdata->rw_timeout_ms;
- int timeout_rel;
- int ret;
-
- if (!dev->pdata->blocking)
- return 0;
-
- do {
- timeout_rel = get_rel_timeout_ms(start, rw_timeout_ms);
- ret = poll(pollfd, 2, timeout_rel);
- } while (ret == -1 && errno == EINTR);
-
- if ((pollfd[1].revents & POLLIN))
- return -EBADF;
-
- if (ret < 0)
- return -errno;
- if (!ret)
- return -ETIMEDOUT;
- if (pollfd[0].revents & POLLNVAL)
- return -EBADF;
- if (!(pollfd[0].revents & events))
- return -EIO;
- return 0;
-}
-
-static ssize_t local_read(const struct iio_device *dev,
- void *dst, size_t len, uint32_t *mask, size_t words)
-{
- struct iio_device_pdata *pdata = dev->pdata;
- uintptr_t ptr = (uintptr_t) dst;
- struct timespec start;
- ssize_t readsize;
- ssize_t ret;
-
- if (pdata->fd == -1)
- return -EBADF;
- if (words != dev->words)
- return -EINVAL;
-
- memcpy(mask, dev->mask, words);
-
- if (len == 0)
- return 0;
-
- clock_gettime(CLOCK_MONOTONIC, &start);
-
- while (len > 0) {
- ret = device_check_ready(dev, POLLIN, &start);
- if (ret < 0)
- break;
-
- do {
- ret = read(pdata->fd, (void *) ptr, len);
- } while (ret == -1 && errno == EINTR);
-
- if (ret == -1) {
- if (pdata->blocking && errno == EAGAIN)
- continue;
- ret = -errno;
- break;
- } else if (ret == 0) {
- ret = -EIO;
- break;
- }
-
- ptr += ret;
- len -= ret;
- }
-
- readsize = (ssize_t)(ptr - (uintptr_t) dst);
- if ((ret > 0 || ret == -EAGAIN) && (readsize > 0))
- return readsize;
- else
- return ret;
-}
-
-static ssize_t local_write(const struct iio_device *dev,
- const void *src, size_t len)
-{
- struct iio_device_pdata *pdata = dev->pdata;
- uintptr_t ptr = (uintptr_t) src;
- struct timespec start;
- ssize_t writtensize;
- ssize_t ret;
-
- if (pdata->fd == -1)
- return -EBADF;
-
- if (len == 0)
- return 0;
-
- clock_gettime(CLOCK_MONOTONIC, &start);
-
- while (len > 0) {
- ret = device_check_ready(dev, POLLOUT, &start);
- if (ret < 0)
- break;
-
- do {
- ret = write(pdata->fd, (void *) ptr, len);
- } while (ret == -1 && errno == EINTR);
-
- if (ret == -1) {
- if (pdata->blocking && errno == EAGAIN)
- continue;
-
- ret = -errno;
- break;
- } else if (ret == 0) {
- ret = -EIO;
- break;
- }
-
- ptr += ret;
- len -= ret;
- }
-
- writtensize = (ssize_t)(ptr - (uintptr_t) src);
- if ((ret > 0 || ret == -EAGAIN) && (writtensize > 0))
- return writtensize;
- else
- return ret;
-}
-
-static ssize_t local_enable_buffer(const struct iio_device *dev)
-{
- struct iio_device_pdata *pdata = dev->pdata;
- ssize_t ret = 0;
-
- if (!pdata->buffer_enabled) {
- ret = local_write_dev_attr(dev,
- "buffer/enable", "1", 2, false);
- if (ret >= 0)
- pdata->buffer_enabled = true;
- }
-
- return ret;
-}
-
-static int local_set_kernel_buffers_count(const struct iio_device *dev,
- unsigned int nb_blocks)
-{
- struct iio_device_pdata *pdata = dev->pdata;
-
- if (pdata->fd != -1)
- return -EBUSY;
-
- pdata->max_nb_blocks = nb_blocks;
-
- return 0;
-}
-
-static ssize_t local_get_buffer(const struct iio_device *dev,
- void **addr_ptr, size_t bytes_used,
- uint32_t *mask, size_t words)
-{
- struct block block;
- struct iio_device_pdata *pdata = dev->pdata;
- struct timespec start;
- char err_str[1024];
- int f = pdata->fd;
- ssize_t ret;
-
- if (!pdata->is_high_speed)
- return -ENOSYS;
- if (f == -1)
- return -EBADF;
- if (!addr_ptr)
- return -EINVAL;
-
- if (pdata->last_dequeued >= 0) {
- struct block *last_block = &pdata->blocks[pdata->last_dequeued];
-
- if (pdata->cyclic) {
- if (pdata->cyclic_buffer_enqueued)
- return -EBUSY;
- pdata->blocks[0].flags |= BLOCK_FLAG_CYCLIC;
- pdata->cyclic_buffer_enqueued = true;
- }
-
- last_block->bytes_used = bytes_used;
- ret = (ssize_t) ioctl_nointr(f,
- BLOCK_ENQUEUE_IOCTL, last_block);
- if (ret) {
- ret = (ssize_t) -errno;
- iio_strerror(errno, err_str, sizeof(err_str));
- ERROR("Unable to enqueue block: %s\n", err_str);
- return ret;
- }
-
- if (pdata->cyclic) {
- *addr_ptr = pdata->addrs[pdata->last_dequeued];
- return (ssize_t) last_block->bytes_used;
- }
-
- pdata->last_dequeued = -1;
- }
-
- clock_gettime(CLOCK_MONOTONIC, &start);
-
- do {
- ret = (ssize_t) device_check_ready(dev, POLLIN | POLLOUT, &start);
- if (ret < 0)
- return ret;
-
- memset(&block, 0, sizeof(block));
- ret = (ssize_t) ioctl_nointr(f, BLOCK_DEQUEUE_IOCTL, &block);
- } while (pdata->blocking && ret == -1 && errno == EAGAIN);
-
- if (ret) {
- ret = (ssize_t) -errno;
- if ((!pdata->blocking && ret != -EAGAIN) ||
- (pdata->blocking && ret != -ETIMEDOUT)) {
- iio_strerror(errno, err_str, sizeof(err_str));
- ERROR("Unable to dequeue block: %s\n", err_str);
- }
- return ret;
- }
-
- /* Requested buffer size is too big! */
- if (pdata->last_dequeued < 0 && bytes_used != block.size)
- return -EFBIG;
-
- pdata->last_dequeued = block.id;
- *addr_ptr = pdata->addrs[block.id];
- return (ssize_t) block.bytes_used;
-}
-
-static ssize_t local_read_all_dev_attrs(const struct iio_device *dev,
- char *dst, size_t len, enum iio_attr_type type)
-{
- unsigned int i, nb;
- char **attrs;
- char *ptr = dst;
-
- switch (type) {
- case IIO_ATTR_TYPE_DEVICE:
- nb = dev->nb_attrs;
- attrs = dev->attrs;
- break;
- case IIO_ATTR_TYPE_DEBUG:
- nb = dev->nb_debug_attrs;
- attrs = dev->debug_attrs;
- break;
- case IIO_ATTR_TYPE_BUFFER:
- nb = dev->nb_buffer_attrs;
- attrs = dev->buffer_attrs;
- break;
- default:
- return -EINVAL;
- break;
- }
-
- for (i = 0; len >= 4 && i < nb; i++) {
- /* Recursive! */
- ssize_t ret = local_read_dev_attr(dev, attrs[i],
- ptr + 4, len - 4, type);
- *(uint32_t *) ptr = iio_htobe32(ret);
-
- /* Align the length to 4 bytes */
- if (ret > 0 && ret & 3)
- ret = ((ret >> 2) + 1) << 2;
- ptr += 4 + (ret < 0 ? 0 : ret);
- len -= 4 + (ret < 0 ? 0 : ret);
- }
-
- return ptr - dst;
-}
-
-static ssize_t local_read_all_chn_attrs(const struct iio_channel *chn,
- char *dst, size_t len)
-{
- unsigned int i;
- char *ptr = dst;
-
- for (i = 0; len >= 4 && i < chn->nb_attrs; i++) {
- /* Recursive! */
- ssize_t ret = local_read_chn_attr(chn,
- chn->attrs[i].name, ptr + 4, len - 4);
- *(uint32_t *) ptr = iio_htobe32(ret);
-
- /* Align the length to 4 bytes */
- if (ret > 0 && ret & 3)
- ret = ((ret >> 2) + 1) << 2;
- ptr += 4 + (ret < 0 ? 0 : ret);
- len -= 4 + (ret < 0 ? 0 : ret);
- }
-
- return ptr - dst;
-}
-
-static int local_buffer_analyze(unsigned int nb, const char *src, size_t len)
-{
- while (nb--) {
- int32_t val;
-
- if (len < 4)
- return -EINVAL;
-
- val = (int32_t) iio_be32toh(*(uint32_t *) src);
- src += 4;
- len -= 4;
-
- if (val > 0) {
- if ((uint32_t) val > len)
- return -EINVAL;
-
- /* Align the length to 4 bytes */
- if (val & 3)
- val = ((val >> 2) + 1) << 2;
- len -= val;
- src += val;
- }
- }
-
- /* We should have analyzed the whole buffer by now */
- return !len ? 0 : -EINVAL;
-}
-
-static ssize_t local_write_all_dev_attrs(const struct iio_device *dev,
- const char *src, size_t len, enum iio_attr_type type)
-{
- unsigned int i, nb;
- char **attrs;
- const char *ptr = src;
-
- switch (type) {
- case IIO_ATTR_TYPE_DEVICE:
- nb = dev->nb_attrs;
- attrs = dev->attrs;
- break;
- case IIO_ATTR_TYPE_DEBUG:
- nb = dev->nb_debug_attrs;
- attrs = dev->debug_attrs;
- break;
- case IIO_ATTR_TYPE_BUFFER:
- nb = dev->nb_buffer_attrs;
- attrs = dev->buffer_attrs;
- break;
- default:
- return -EINVAL;
- break;
- }
-
- /* First step: Verify that the buffer is in the correct format */
- if (local_buffer_analyze(nb, src, len))
- return -EINVAL;
-
- /* Second step: write the attributes */
- for (i = 0; i < nb; i++) {
- int32_t val = (int32_t) iio_be32toh(*(uint32_t *) ptr);
- ptr += 4;
-
- if (val > 0) {
- local_write_dev_attr(dev, attrs[i], ptr, val, type);
-
- /* Align the length to 4 bytes */
- if (val & 3)
- val = ((val >> 2) + 1) << 2;
- ptr += val;
- }
- }
-
- return ptr - src;
-}
-
-static ssize_t local_write_all_chn_attrs(const struct iio_channel *chn,
- const char *src, size_t len)
-{
- unsigned int i, nb = chn->nb_attrs;
- const char *ptr = src;
-
- /* First step: Verify that the buffer is in the correct format */
- if (local_buffer_analyze(nb, src, len))
- return -EINVAL;
-
- /* Second step: write the attributes */
- for (i = 0; i < nb; i++) {
- int32_t val = (int32_t) iio_be32toh(*(uint32_t *) ptr);
- ptr += 4;
-
- if (val > 0) {
- local_write_chn_attr(chn, chn->attrs[i].name, ptr, val);
-
- /* Align the length to 4 bytes */
- if (val & 3)
- val = ((val >> 2) + 1) << 2;
- ptr += val;
- }
- }
-
- return ptr - src;
-}
-
-static ssize_t local_read_dev_attr(const struct iio_device *dev,
- const char *attr, char *dst, size_t len, enum iio_attr_type type)
-{
- FILE *f;
- char buf[1024];
- ssize_t ret;
-
- if (!attr)
- return local_read_all_dev_attrs(dev, dst, len, type);
-
- switch (type) {
- case IIO_ATTR_TYPE_DEVICE:
- iio_snprintf(buf, sizeof(buf), "/sys/bus/iio/devices/%s/%s",
- dev->id, attr);
- break;
- case IIO_ATTR_TYPE_DEBUG:
- iio_snprintf(buf, sizeof(buf), "/sys/kernel/debug/iio/%s/%s",
- dev->id, attr);
- break;
- case IIO_ATTR_TYPE_BUFFER:
- iio_snprintf(buf, sizeof(buf), "/sys/bus/iio/devices/%s/buffer/%s",
- dev->id, attr);
- break;
- default:
- return -EINVAL;
- }
-
- f = fopen(buf, "re");
- if (!f)
- return -errno;
-
- ret = fread(dst, 1, len, f);
- if (ret > 0)
- dst[ret - 1] = '\0';
- fflush(f);
- if (ferror(f))
- ret = -errno;
- fclose(f);
- return ret ? ret : -EIO;
-}
-
-static ssize_t local_write_dev_attr(const struct iio_device *dev,
- const char *attr, const char *src, size_t len, enum iio_attr_type type)
-{
- FILE *f;
- char buf[1024];
- ssize_t ret;
-
- if (!attr)
- return local_write_all_dev_attrs(dev, src, len, type);
-
- switch (type) {
- case IIO_ATTR_TYPE_DEVICE:
- iio_snprintf(buf, sizeof(buf), "/sys/bus/iio/devices/%s/%s",
- dev->id, attr);
- break;
- case IIO_ATTR_TYPE_DEBUG:
- iio_snprintf(buf, sizeof(buf), "/sys/kernel/debug/iio/%s/%s",
- dev->id, attr);
- break;
- case IIO_ATTR_TYPE_BUFFER:
- iio_snprintf(buf, sizeof(buf), "/sys/bus/iio/devices/%s/buffer/%s",
- dev->id, attr);
- break;
- default:
- return -EINVAL;
- }
-
- f = fopen(buf, "we");
- if (!f)
- return -errno;
-
- ret = fwrite(src, 1, len, f);
- fflush(f);
- if (ferror(f))
- ret = -errno;
- fclose(f);
- return ret ? ret : -EIO;
-}
-
-static const char * get_filename(const struct iio_channel *chn,
- const char *attr)
-{
- unsigned int i;
- for (i = 0; i < chn->nb_attrs; i++)
- if (!strcmp(attr, chn->attrs[i].name))
- return chn->attrs[i].filename;
- return attr;
-}
-
-static ssize_t local_read_chn_attr(const struct iio_channel *chn,
- const char *attr, char *dst, size_t len)
-{
- if (!attr)
- return local_read_all_chn_attrs(chn, dst, len);
-
- attr = get_filename(chn, attr);
- return local_read_dev_attr(chn->dev, attr, dst, len, false);
-}
-
-static ssize_t local_write_chn_attr(const struct iio_channel *chn,
- const char *attr, const char *src, size_t len)
-{
- if (!attr)
- return local_write_all_chn_attrs(chn, src, len);
-
- attr = get_filename(chn, attr);
- return local_write_dev_attr(chn->dev, attr, src, len, false);
-}
-
-static int channel_write_state(const struct iio_channel *chn, bool en)
-{
- ssize_t ret;
-
- if (!chn->pdata->enable_fn) {
- ERROR("Libiio bug: No \"en\" attribute parsed\n");
- return -EINVAL;
- }
-
- ret = local_write_chn_attr(chn, chn->pdata->enable_fn, en ? "1" : "0", 2);
- if (ret < 0)
- return (int) ret;
- else
- return 0;
-}
-
-static int enable_high_speed(const struct iio_device *dev)
-{
- struct block_alloc_req req;
- struct iio_device_pdata *pdata = dev->pdata;
- unsigned int nb_blocks;
- unsigned int i;
- int ret, fd = pdata->fd;
-
- /*
- * For the BLOCK_ALLOC_IOCTL ioctl it is not possible to distingush
- * between an error during the allocation (e.g. incorrect size) or
- * whether the high-speed interface is not supported. BLOCK_FREE_IOCTL does
- * never fail if the device supports the high-speed interface, so we use it
- * here. Calling it when no blocks are allocated the ioctl has no effect.
- */
- ret = ioctl_nointr(fd, BLOCK_FREE_IOCTL, NULL);
- if (ret < 0)
- return -ENOSYS;
-
- if (pdata->cyclic) {
- nb_blocks = 1;
- DEBUG("Enabling cyclic mode\n");
- } else {
- nb_blocks = pdata->max_nb_blocks;
- DEBUG("Cyclic mode not enabled\n");
- }
-
- pdata->blocks = calloc(nb_blocks, sizeof(*pdata->blocks));
- if (!pdata->blocks)
- return -ENOMEM;
-
- pdata->addrs = calloc(nb_blocks, sizeof(*pdata->addrs));
- if (!pdata->addrs) {
- free(pdata->blocks);
- pdata->blocks = NULL;
- return -ENOMEM;
- }
-
- req.id = 0;
- req.type = 0;
- req.size = pdata->samples_count *
- iio_device_get_sample_size_mask(dev, dev->mask, dev->words);
- req.count = nb_blocks;
-
- ret = ioctl_nointr(fd, BLOCK_ALLOC_IOCTL, &req);
- if (ret < 0) {
- ret = -errno;
- goto err_freemem;
- }
-
- if (req.count == 0) {
- ret = -ENOMEM;
- goto err_block_free;
- }
-
- /* We might get less blocks than what we asked for */
- pdata->allocated_nb_blocks = req.count;
-
- /* mmap all the blocks */
- for (i = 0; i < pdata->allocated_nb_blocks; i++) {
- pdata->blocks[i].id = i;
- ret = ioctl_nointr(fd, BLOCK_QUERY_IOCTL, &pdata->blocks[i]);
- if (ret) {
- ret = -errno;
- goto err_munmap;
- }
-
- ret = ioctl_nointr(fd, BLOCK_ENQUEUE_IOCTL, &pdata->blocks[i]);
- if (ret) {
- ret = -errno;
- goto err_munmap;
- }
-
- pdata->addrs[i] = mmap(0, pdata->blocks[i].size,
- PROT_READ | PROT_WRITE,
- MAP_SHARED, fd, pdata->blocks[i].offset);
- if (pdata->addrs[i] == MAP_FAILED) {
- ret = -errno;
- goto err_munmap;
- }
- }
-
- pdata->last_dequeued = -1;
- return 0;
-
-err_munmap:
- for (; i > 0; i--)
- munmap(pdata->addrs[i - 1], pdata->blocks[i - 1].size);
-err_block_free:
- ioctl_nointr(fd, BLOCK_FREE_IOCTL, 0);
- pdata->allocated_nb_blocks = 0;
-err_freemem:
- free(pdata->addrs);
- pdata->addrs = NULL;
- free(pdata->blocks);
- pdata->blocks = NULL;
- return ret;
-}
-
-static int local_open(const struct iio_device *dev,
- size_t samples_count, bool cyclic)
-{
- unsigned int i;
- int ret;
- char buf[1024];
- struct iio_device_pdata *pdata = dev->pdata;
-
- if (pdata->fd != -1)
- return -EBUSY;
-
- ret = local_write_dev_attr(dev, "buffer/enable", "0", 2, false);
- if (ret < 0)
- return ret;
-
- iio_snprintf(buf, sizeof(buf), "%lu", (unsigned long) samples_count);
- ret = local_write_dev_attr(dev, "buffer/length",
- buf, strlen(buf) + 1, false);
- if (ret < 0)
- return ret;
-
- pdata->cancel_fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
- if (pdata->cancel_fd == -1)
- return -errno;
-
- iio_snprintf(buf, sizeof(buf), "/dev/%s", dev->id);
- pdata->fd = open(buf, O_RDWR | O_CLOEXEC | O_NONBLOCK);
- if (pdata->fd == -1) {
- ret = -errno;
- goto err_close_cancel_fd;
- }
-
- /* Disable channels */
- for (i = 0; i < dev->nb_channels; i++) {
- struct iio_channel *chn = dev->channels[i];
- if (chn->index >= 0 && !iio_channel_is_enabled(chn)) {
- ret = channel_write_state(chn, false);
- if (ret < 0)
- goto err_close;
- }
- }
- /* Enable channels */
- for (i = 0; i < dev->nb_channels; i++) {
- struct iio_channel *chn = dev->channels[i];
- if (chn->index >= 0 && iio_channel_is_enabled(chn)) {
- ret = channel_write_state(chn, true);
- if (ret < 0)
- goto err_close;
- }
- }
-
- pdata->cyclic = cyclic;
- pdata->cyclic_buffer_enqueued = false;
- pdata->buffer_enabled = false;
- pdata->samples_count = samples_count;
-
- ret = enable_high_speed(dev);
- if (ret < 0 && ret != -ENOSYS)
- goto err_close;
-
- pdata->is_high_speed = !ret;
-
- if (!pdata->is_high_speed) {
- unsigned long size = samples_count * pdata->max_nb_blocks;
- WARNING("High-speed mode not enabled\n");
-
- /* Cyclic mode is only supported in high-speed mode */
- if (cyclic) {
- ret = -EPERM;
- goto err_close;
- }
-
- /* Increase the size of the kernel buffer, when using the
- * low-speed interface. This avoids losing samples when
- * refilling the iio_buffer. */
- iio_snprintf(buf, sizeof(buf), "%lu", size);
- ret = local_write_dev_attr(dev, "buffer/length",
- buf, strlen(buf) + 1, false);
- if (ret < 0)
- goto err_close;
- }
-
- ret = local_enable_buffer(dev);
- if (ret < 0)
- goto err_close;
-
- return 0;
-err_close:
- close(pdata->fd);
- pdata->fd = -1;
-err_close_cancel_fd:
- close(pdata->cancel_fd);
- pdata->cancel_fd = -1;
- return ret;
-}
-
-static int local_close(const struct iio_device *dev)
-{
- struct iio_device_pdata *pdata = dev->pdata;
- unsigned int i;
- int ret;
-
- if (pdata->fd == -1)
- return -EBADF;
-
- if (pdata->is_high_speed) {
- unsigned int i;
- for (i = 0; i < pdata->allocated_nb_blocks; i++)
- munmap(pdata->addrs[i], pdata->blocks[i].size);
- ioctl_nointr(pdata->fd, BLOCK_FREE_IOCTL, 0);
- pdata->allocated_nb_blocks = 0;
- free(pdata->addrs);
- pdata->addrs = NULL;
- free(pdata->blocks);
- pdata->blocks = NULL;
- }
-
- ret = close(pdata->fd);
- if (ret)
- return ret;
-
- close(pdata->cancel_fd);
-
- pdata->fd = -1;
- pdata->cancel_fd = -1;
-
- ret = local_write_dev_attr(dev, "buffer/enable", "0", 2, false);
-
- for (i = 0; i < dev->nb_channels; i++) {
- struct iio_channel *chn = dev->channels[i];
-
- if (chn->pdata->enable_fn)
- channel_write_state(chn, false);
- }
-
- return (ret < 0) ? ret : 0;
-}
-
-static int local_get_fd(const struct iio_device *dev)
-{
- if (dev->pdata->fd == -1)
- return -EBADF;
- else
- return dev->pdata->fd;
-}
-
-static int local_set_blocking_mode(const struct iio_device *dev, bool blocking)
-{
- if (dev->pdata->fd == -1)
- return -EBADF;
-
- if (dev->pdata->cyclic)
- return -EPERM;
-
- dev->pdata->blocking = blocking;
-
- return 0;
-}
-
-static int local_get_trigger(const struct iio_device *dev,
- const struct iio_device **trigger)
-{
- char buf[1024];
- unsigned int i;
- ssize_t nb = local_read_dev_attr(dev, "trigger/current_trigger",
- buf, sizeof(buf), false);
- if (nb < 0) {
- *trigger = NULL;
- return (int) nb;
- }
-
- if (buf[0] == '\0') {
- *trigger = NULL;
- return 0;
- }
-
- nb = dev->ctx->nb_devices;
- for (i = 0; i < (size_t) nb; i++) {
- const struct iio_device *cur = dev->ctx->devices[i];
- if (cur->name && !strcmp(cur->name, buf)) {
- *trigger = cur;
- return 0;
- }
- }
- return -ENXIO;
-}
-
-static int local_set_trigger(const struct iio_device *dev,
- const struct iio_device *trigger)
-{
- ssize_t nb;
- const char *value = trigger ? trigger->name : "";
- nb = local_write_dev_attr(dev, "trigger/current_trigger",
- value, strlen(value) + 1, false);
- if (nb < 0)
- return (int) nb;
- else
- return 0;
-}
-
-static bool is_channel(const char *attr, bool strict)
-{
- char *ptr = NULL;
- if (!strncmp(attr, "in_timestamp_", sizeof("in_timestamp_") - 1))
- return true;
- if (!strncmp(attr, "in_", 3))
- ptr = strchr(attr + 3, '_');
- else if (!strncmp(attr, "out_", 4))
- ptr = strchr(attr + 4, '_');
- if (!ptr)
- return false;
- if (!strict)
- return true;
- if (*(ptr - 1) >= '0' && *(ptr - 1) <= '9')
- return true;
-
- if (find_channel_modifier(ptr + 1, NULL) != IIO_NO_MOD)
- return true;
- return false;
-}
-
-static char * get_channel_id(const char *attr)
-{
- char *res, *ptr;
- size_t len;
-
- attr = strchr(attr, '_') + 1;
- ptr = strchr(attr, '_');
- if (find_channel_modifier(ptr + 1, &len) != IIO_NO_MOD)
- ptr += len + 1;
-
- res = malloc(ptr - attr + 1);
- if (!res)
- return NULL;
-
- memcpy(res, attr, ptr - attr);
- res[ptr - attr] = 0;
- return res;
-}
-
-static char * get_short_attr_name(struct iio_channel *chn, const char *attr)
-{
- char *ptr = strchr(attr, '_') + 1;
- size_t len;
-
- ptr = strchr(ptr, '_') + 1;
- if (find_channel_modifier(ptr, &len) != IIO_NO_MOD)
- ptr += len + 1;
-
- if (chn->name) {
- size_t len = strlen(chn->name);
- if (strncmp(chn->name, ptr, len) == 0 && ptr[len] == '_')
- ptr += len + 1;
- }
-
- return iio_strdup(ptr);
-}
-
-static int read_device_name(struct iio_device *dev)
-{
- char buf[1024];
- ssize_t ret = iio_device_attr_read(dev, "name", buf, sizeof(buf));
- if (ret < 0)
- return ret;
- else if (ret == 0)
- return -EIO;
-
- dev->name = iio_strdup(buf);
- if (!dev->name)
- return -ENOMEM;
- else
- return 0;
-}
-
-static int add_attr_to_device(struct iio_device *dev, const char *attr)
-{
- char **attrs, *name;
- unsigned int i;
-
- for (i = 0; i < ARRAY_SIZE(device_attrs_blacklist); i++)
- if (!strcmp(device_attrs_blacklist[i], attr))
- return 0;
-
- if (!strcmp(attr, "name"))
- return read_device_name(dev);
-
- name = iio_strdup(attr);
- if (!name)
- return -ENOMEM;
-
- attrs = realloc(dev->attrs, (1 + dev->nb_attrs) * sizeof(char *));
- if (!attrs) {
- free(name);
- return -ENOMEM;
- }
-
- attrs[dev->nb_attrs++] = name;
- dev->attrs = attrs;
- DEBUG("Added attr \'%s\' to device \'%s\'\n", attr, dev->id);
- return 0;
-}
-
-static int handle_protected_scan_element_attr(struct iio_channel *chn,
- const char *name, const char *path)
-{
- struct iio_device *dev = chn->dev;
- char buf[1024];
- int ret;
-
- if (!strcmp(name, "index")) {
- ret = local_read_dev_attr(dev, path, buf, sizeof(buf), false);
- if (ret > 0)
- chn->index = atol(buf);
-
- } else if (!strcmp(name, "type")) {
- ret = local_read_dev_attr(dev, path, buf, sizeof(buf), false);
- if (ret > 0) {
- char endian, sign;
-
- if (strchr(buf, 'X')) {
- sscanf(buf, "%ce:%c%u/%uX%u>>%u", &endian, &sign,
- &chn->format.bits, &chn->format.length,
- &chn->format.repeat, &chn->format.shift);
- } else {
- chn->format.repeat = 1;
- sscanf(buf, "%ce:%c%u/%u>>%u", &endian, &sign,
- &chn->format.bits, &chn->format.length,
- &chn->format.shift);
- }
- chn->format.is_signed = (sign == 's' || sign == 'S');
- chn->format.is_fully_defined =
- (sign == 'S' || sign == 'U'||
- chn->format.bits == chn->format.length);
- chn->format.is_be = endian == 'b';
- }
-
- } else if (!strcmp(name, "en")) {
- if (chn->pdata->enable_fn) {
- ERROR("Libiio bug: \"en\" attribute already parsed for channel %s!\n",
- chn->id);
- return -EINVAL;
- }
-
- chn->pdata->enable_fn = iio_strdup(path);
- if (!chn->pdata->enable_fn)
- return -ENOMEM;
-
- } else {
- return -EINVAL;
- }
-
- return 0;
-}
-
-static int handle_scan_elements(struct iio_channel *chn)
-{
- struct iio_channel_pdata *pdata = chn->pdata;
- unsigned int i;
-
- for (i = 0; i < pdata->nb_protected_attrs; i++) {
- int ret = handle_protected_scan_element_attr(chn,
- pdata->protected_attrs[i].name,
- pdata->protected_attrs[i].filename);
- if (ret < 0)
- return ret;
- }
-
- return 0;
-}
-
-static int add_protected_attr(struct iio_channel *chn, char *name, char *fn)
-{
- struct iio_channel_pdata *pdata = chn->pdata;
- struct iio_channel_attr *attrs;
-
- attrs = realloc(pdata->protected_attrs,
- (1 + pdata->nb_protected_attrs) * sizeof(*attrs));
- if (!attrs)
- return -ENOMEM;
-
- attrs[pdata->nb_protected_attrs].name = name;
- attrs[pdata->nb_protected_attrs++].filename = fn;
- pdata->protected_attrs = attrs;
-
- DEBUG("Add protected attr \'%s\' to channel \'%s\'\n", name, chn->id);
- return 0;
-}
-
-static void free_protected_attrs(struct iio_channel *chn)
-{
- struct iio_channel_pdata *pdata = chn->pdata;
- unsigned int i;
-
- for (i = 0; i < pdata->nb_protected_attrs; i++) {
- free(pdata->protected_attrs[i].name);
- free(pdata->protected_attrs[i].filename);
- }
-
- free(pdata->protected_attrs);
- pdata->nb_protected_attrs = 0;
- pdata->protected_attrs = NULL;
-}
-
-static int add_attr_to_channel(struct iio_channel *chn,
- const char *attr, const char *path, bool is_scan_element)
-{
- struct iio_channel_attr *attrs;
- char *fn, *name = get_short_attr_name(chn, attr);
- if (!name)
- return -ENOMEM;
-
- fn = iio_strdup(path);
- if (!fn)
- goto err_free_name;
-
- if (is_scan_element) {
- int ret = add_protected_attr(chn, name, fn);
-
- if (ret < 0)
- goto err_free_fn;
-
- return 0;
- }
-
- attrs = realloc(chn->attrs, (1 + chn->nb_attrs) *
- sizeof(struct iio_channel_attr));
- if (!attrs)
- goto err_free_fn;
-
- attrs[chn->nb_attrs].filename = fn;
- attrs[chn->nb_attrs++].name = name;
- chn->attrs = attrs;
- DEBUG("Added attr \'%s\' to channel \'%s\'\n", name, chn->id);
- return 0;
-
-err_free_fn:
- free(fn);
-err_free_name:
- free(name);
- return -ENOMEM;
-}
-
-static int add_channel_to_device(struct iio_device *dev,
- struct iio_channel *chn)
-{
- struct iio_channel **channels = realloc(dev->channels,
- (dev->nb_channels + 1) * sizeof(struct iio_channel *));
- if (!channels)
- return -ENOMEM;
-
- channels[dev->nb_channels++] = chn;
- dev->channels = channels;
- DEBUG("Added %s channel \'%s\' to device \'%s\'\n",
- chn->is_output ? "output" : "input", chn->id, dev->id);
-
- return 0;
-}
-
-static int add_device_to_context(struct iio_context *ctx,
- struct iio_device *dev)
-{
- struct iio_device **devices = realloc(ctx->devices,
- (ctx->nb_devices + 1) * sizeof(struct iio_device *));
- if (!devices)
- return -ENOMEM;
-
- devices[ctx->nb_devices++] = dev;
- ctx->devices = devices;
- DEBUG("Added device \'%s\' to context \'%s\'\n", dev->id, ctx->name);
- return 0;
-}
-
-static struct iio_channel *create_channel(struct iio_device *dev,
- char *id, const char *attr, const char *path,
- bool is_scan_element)
-{
- struct iio_channel *chn = zalloc(sizeof(*chn));
- if (!chn)
- return NULL;
-
- chn->pdata = zalloc(sizeof(*chn->pdata));
- if (!chn->pdata)
- goto err_free_chn;
-
- if (!strncmp(attr, "out_", 4))
- chn->is_output = true;
- else if (strncmp(attr, "in_", 3))
- goto err_free_chn_pdata;
-
- chn->dev = dev;
- chn->id = id;
- chn->is_scan_element = is_scan_element;
- chn->index = -ENOENT;
-
- if (!add_attr_to_channel(chn, attr, path, is_scan_element))
- return chn;
-
-err_free_chn_pdata:
- free(chn->pdata->enable_fn);
- free(chn->pdata);
-err_free_chn:
- free(chn);
- return NULL;
-}
-
-static int add_channel(struct iio_device *dev, const char *name,
- const char *path, bool dir_is_scan_elements)
-{
- struct iio_channel *chn;
- char *channel_id;
- unsigned int i;
- int ret;
-
- channel_id = get_channel_id(name);
- if (!channel_id)
- return -ENOMEM;
-
- for (i = 0; i < dev->nb_channels; i++) {
- chn = dev->channels[i];
- if (!strcmp(chn->id, channel_id)
- && chn->is_output == (name[0] == 'o')) {
- free(channel_id);
- ret = add_attr_to_channel(chn, name, path,
- dir_is_scan_elements);
- chn->is_scan_element = dir_is_scan_elements && !ret;
- return ret;
- }
- }
-
- chn = create_channel(dev, channel_id, name, path, dir_is_scan_elements);
- if (!chn) {
- free(channel_id);
- return -ENXIO;
- }
-
- iio_channel_init_finalize(chn);
-
- ret = add_channel_to_device(dev, chn);
- if (ret) {
- free(chn->pdata->enable_fn);
- free(chn->pdata);
- free_channel(chn);
- }
- return ret;
-}
-
-/*
- * Possible return values:
- * 0 = Attribute should not be moved to the channel
- * 1 = Attribute should be moved to the channel and it is a shared attribute
- * 2 = Attribute should be moved to the channel and it is a private attribute
- */
-static unsigned int is_global_attr(struct iio_channel *chn, const char *attr)
-{
- unsigned int len;
- char *ptr;
-
- if (!chn->is_output && !strncmp(attr, "in_", 3))
- attr += 3;
- else if (chn->is_output && !strncmp(attr, "out_", 4))
- attr += 4;
- else
- return 0;
-
- ptr = strchr(attr, '_');
- if (!ptr)
- return 0;
-
- len = ptr - attr;
-
- if (strncmp(chn->id, attr, len))
- return 0;
-
- DEBUG("Found match: %s and %s\n", chn->id, attr);
- if (chn->id[len] >= '0' && chn->id[len] <= '9') {
- if (chn->name) {
- size_t name_len = strlen(chn->name);
- if (strncmp(chn->name, attr + len + 1, name_len) == 0 &&
- attr[len + 1 + name_len] == '_')
- return 2;
- }
- return 1;
- } else if (chn->id[len] != '_') {
- return 0;
- }
-
- if (find_channel_modifier(chn->id + len + 1, NULL) != IIO_NO_MOD)
- return 1;
-
- return 0;
-}
-
-static int detect_global_attr(struct iio_device *dev, const char *attr,
- unsigned int level, bool *match)
-{
- unsigned int i;
-
- *match = false;
- for (i = 0; i < dev->nb_channels; i++) {
- struct iio_channel *chn = dev->channels[i];
- if (is_global_attr(chn, attr) == level) {
- int ret;
- *match = true;
- ret = add_attr_to_channel(chn, attr, attr, false);
- if (ret)
- return ret;
- }
- }
-
- return 0;
-}
-
-static int detect_and_move_global_attrs(struct iio_device *dev)
-{
- unsigned int i;
- char **ptr = dev->attrs;
-
- for (i = 0; i < dev->nb_attrs; i++) {
- const char *attr = dev->attrs[i];
- bool match;
- int ret;
-
- ret = detect_global_attr(dev, attr, 2, &match);
- if (ret)
- return ret;
-
- if (!match) {
- ret = detect_global_attr(dev, attr, 1, &match);
- if (ret)
- return ret;
- }
-
- if (match) {
- free(dev->attrs[i]);
- dev->attrs[i] = NULL;
- }
- }
-
- /* Find channels without an index */
- for (i = 0; i < dev->nb_attrs; i++) {
- const char *attr = dev->attrs[i];
- int ret;
-
- if (!dev->attrs[i])
- continue;
-
- if (is_channel(attr, false)) {
- ret = add_channel(dev, attr, attr, false);
- if (ret)
- return ret;
-
- free(dev->attrs[i]);
- dev->attrs[i] = NULL;
- }
- }
-
- for (i = 0; i < dev->nb_attrs; i++) {
- if (dev->attrs[i])
- *ptr++ = dev->attrs[i];
- }
-
- dev->nb_attrs = ptr - dev->attrs;
- if (!dev->nb_attrs) {
- free(dev->attrs);
- dev->attrs = NULL;
- }
-
- return 0;
-}
-
-static int add_buffer_attr(void *d, const char *path)
-{
- struct iio_device *dev = (struct iio_device *) d;
- const char *name = strrchr(path, '/') + 1;
- char **attrs, *attr;
- int i;
-
- for (i = 0; i < ARRAY_SIZE(buffer_attrs_reserved); i++)
- if (!strcmp(buffer_attrs_reserved[i], name))
- return 0;
-
- attr = iio_strdup(name);
- if (!attr)
- return -ENOMEM;
-
- attrs = realloc(dev->buffer_attrs, (1 + dev->nb_buffer_attrs) * sizeof(char *));
- if (!attrs) {
- free(attr);
- return -ENOMEM;
- }
-
- attrs[dev->nb_buffer_attrs++] = attr;
- dev->buffer_attrs = attrs;
- DEBUG("Added buffer attr \'%s\' to device \'%s\'\n", attr, dev->id);
- return 0;
-}
-
-static int add_attr_or_channel_helper(struct iio_device *dev,
- const char *path, bool dir_is_scan_elements)
-{
- char buf[1024];
- const char *name = strrchr(path, '/') + 1;
-
- if (dir_is_scan_elements) {
- iio_snprintf(buf, sizeof(buf), "scan_elements/%s", name);
- path = buf;
- } else {
- if (!is_channel(name, true))
- return add_attr_to_device(dev, name);
- path = name;
- }
-
- return add_channel(dev, name, path, dir_is_scan_elements);
-}
-
-static int add_attr_or_channel(void *d, const char *path)
-{
- return add_attr_or_channel_helper((struct iio_device *) d, path, false);
-}
-
-static int add_scan_element(void *d, const char *path)
-{
- return add_attr_or_channel_helper((struct iio_device *) d, path, true);
-}
-
-static int foreach_in_dir(void *d, const char *path, bool is_dir,
- int (*callback)(void *, const char *))
-{
- struct dirent *entry;
- DIR *dir;
- int ret = 0;
-
- dir = opendir(path);
- if (!dir)
- return -errno;
-
- while (true) {
- struct stat st;
- char buf[1024];
-
- errno = 0;
- entry = readdir(dir);
- if (!entry) {
- if (!errno)
- break;
-
- ret = -errno;
- iio_strerror(errno, buf, sizeof(buf));
- ERROR("Unable to open directory %s: %s\n", path, buf);
- goto out_close_dir;
- }
-
- iio_snprintf(buf, sizeof(buf), "%s/%s", path, entry->d_name);
- if (stat(buf, &st) < 0) {
- ret = -errno;
- iio_strerror(errno, buf, sizeof(buf));
- ERROR("Unable to stat file: %s\n", buf);
- goto out_close_dir;
- }
-
- if (is_dir && S_ISDIR(st.st_mode) && entry->d_name[0] != '.')
- ret = callback(d, buf);
- else if (!is_dir && S_ISREG(st.st_mode))
- ret = callback(d, buf);
- else
- continue;
-
- if (ret < 0)
- goto out_close_dir;
- }
-
-out_close_dir:
- closedir(dir);
- return ret;
-}
-
-static int add_scan_elements(struct iio_device *dev, const char *devpath)
-{
- struct stat st;
- char buf[1024];
-
- iio_snprintf(buf, sizeof(buf), "%s/scan_elements", devpath);
-
- if (!stat(buf, &st) && S_ISDIR(st.st_mode)) {
- int ret = foreach_in_dir(dev, buf, false, add_scan_element);
- if (ret < 0)
- return ret;
- }
-
- return 0;
-}
-
-static int add_buffer_attributes(struct iio_device *dev, const char *devpath)
-{
- struct stat st;
- char buf[1024];
-
- iio_snprintf(buf, sizeof(buf), "%s/buffer", devpath);
-
- if (!stat(buf, &st) && S_ISDIR(st.st_mode)) {
- int ret = foreach_in_dir(dev, buf, false, add_buffer_attr);
- if (ret < 0)
- return ret;
-
- qsort(dev->buffer_attrs, dev->nb_buffer_attrs, sizeof(char *),
- iio_buffer_attr_compare);
- }
-
- return 0;
-}
-
-static int create_device(void *d, const char *path)
-{
- uint32_t *mask = NULL;
- unsigned int i;
- int ret;
- struct iio_context *ctx = d;
- struct iio_device *dev = zalloc(sizeof(*dev));
- if (!dev)
- return -ENOMEM;
-
- dev->pdata = zalloc(sizeof(*dev->pdata));
- if (!dev->pdata) {
- free(dev);
- return -ENOMEM;
- }
-
- dev->pdata->fd = -1;
- dev->pdata->blocking = true;
- dev->pdata->max_nb_blocks = NB_BLOCKS;
-
- dev->ctx = ctx;
- dev->id = iio_strdup(strrchr(path, '/') + 1);
- if (!dev->id) {
- local_free_pdata(dev);
- free(dev);
- return -ENOMEM;
- }
-
- ret = foreach_in_dir(dev, path, false, add_attr_or_channel);
- if (ret < 0)
- goto err_free_device;
-
- ret = add_buffer_attributes(dev, path);
- if (ret < 0)
- goto err_free_device;
-
- ret = add_scan_elements(dev, path);
- if (ret < 0)
- goto err_free_scan_elements;
-
- for (i = 0; i < dev->nb_channels; i++) {
- struct iio_channel *chn = dev->channels[i];
-
- set_channel_name(chn);
- ret = handle_scan_elements(chn);
- free_protected_attrs(chn);
- if (ret < 0)
- goto err_free_scan_elements;
- }
-
- ret = detect_and_move_global_attrs(dev);
- if (ret < 0)
- goto err_free_device;
-
- /* sorting is done after global attrs are added */
- for (i = 0; i < dev->nb_channels; i++) {
- struct iio_channel *chn = dev->channels[i];
- qsort(chn->attrs, chn->nb_attrs, sizeof(struct iio_channel_attr),
- iio_channel_attr_compare);
- }
- qsort(dev->attrs, dev->nb_attrs, sizeof(char *),
- iio_device_attr_compare);
-
- dev->words = (dev->nb_channels + 31) / 32;
- if (dev->words) {
- mask = calloc(dev->words, sizeof(*mask));
- if (!mask) {
- ret = -ENOMEM;
- goto err_free_device;
- }
- }
-
- dev->mask = mask;
-
- ret = add_device_to_context(ctx, dev);
- if (!ret)
- return 0;
-
-err_free_scan_elements:
- for (i = 0; i < dev->nb_channels; i++)
- free_protected_attrs(dev->channels[i]);
-err_free_device:
- local_free_pdata(dev);
- free_device(dev);
- return ret;
-}
-
-static int add_debug_attr(void *d, const char *path)
-{
- struct iio_device *dev = d;
- const char *attr = strrchr(path, '/') + 1;
- char **attrs, *name = iio_strdup(attr);
- if (!name)
- return -ENOMEM;
-
- attrs = realloc(dev->debug_attrs,
- (1 + dev->nb_debug_attrs) * sizeof(char *));
- if (!attrs) {
- free(name);
- return -ENOMEM;
- }
-
- attrs[dev->nb_debug_attrs++] = name;
- dev->debug_attrs = attrs;
- DEBUG("Added debug attr \'%s\' to device \'%s\'\n", name, dev->id);
- return 0;
-}
-
-static int add_debug(void *d, const char *path)
-{
- struct iio_context *ctx = d;
- const char *name = strrchr(path, '/') + 1;
- struct iio_device *dev = iio_context_find_device(ctx, name);
- if (!dev)
- return -ENODEV;
- else
- return foreach_in_dir(dev, path, false, add_debug_attr);
-}
-
-static int local_set_timeout(struct iio_context *ctx, unsigned int timeout)
-{
- ctx->pdata->rw_timeout_ms = timeout;
- return 0;
-}
-
-static void local_cancel(const struct iio_device *dev)
-{
- struct iio_device_pdata *pdata = dev->pdata;
- uint64_t event = 1;
- int ret;
-
- ret = write(pdata->cancel_fd, &event, sizeof(event));
- if (ret == -1) {
- /* If this happens something went very seriously wrong */
- char err_str[1024];
- iio_strerror(errno, err_str, sizeof(err_str));
- ERROR("Unable to signal cancellation event: %s\n", err_str);
- }
-}
-
-static struct iio_context * local_clone(
- const struct iio_context *ctx __attribute__((unused)))
-{
- return local_create_context();
-}
-
-static const struct iio_backend_ops local_ops = {
- .clone = local_clone,
- .open = local_open,
- .close = local_close,
- .get_fd = local_get_fd,
- .set_blocking_mode = local_set_blocking_mode,
- .read = local_read,
- .write = local_write,
- .set_kernel_buffers_count = local_set_kernel_buffers_count,
- .get_buffer = local_get_buffer,
- .read_device_attr = local_read_dev_attr,
- .write_device_attr = local_write_dev_attr,
- .read_channel_attr = local_read_chn_attr,
- .write_channel_attr = local_write_chn_attr,
- .get_trigger = local_get_trigger,
- .set_trigger = local_set_trigger,
- .shutdown = local_shutdown,
- .set_timeout = local_set_timeout,
- .cancel = local_cancel,
-};
-
-static void init_data_scale(struct iio_channel *chn)
-{
- char buf[1024];
- ssize_t ret;
-
- ret = iio_channel_attr_read(chn, "scale", buf, sizeof(buf));
- if (ret < 0) {
- chn->format.with_scale = false;
- } else {
- chn->format.with_scale = true;
- chn->format.scale = atof(buf);
- }
-}
-
-static void init_scan_elements(struct iio_context *ctx)
-{
- unsigned int i, j;
-
- for (i = 0; i < ctx->nb_devices; i++) {
- struct iio_device *dev = ctx->devices[i];
-
- for (j = 0; j < dev->nb_channels; j++)
- init_data_scale(dev->channels[j]);
- }
-}
-
-#ifdef WITH_LOCAL_CONFIG
-static int populate_context_attrs(struct iio_context *ctx, const char *file)
-{
- struct INI *ini;
- int ret;
-
- ini = ini_open(file);
- if (!ini) {
- /* INI file not present -> not an error */
- if (errno == ENOENT)
- return 0;
- else
- return -errno;
- }
-
- while (true) {
- const char *section;
- size_t len;
-
- ret = ini_next_section(ini, &section, &len);
- if (ret <= 0)
- goto out_close_ini;
-
- if (!strncmp(section, "Context Attributes", len))
- break;
- }
-
- do {
- const char *key, *value;
- char *new_key, *new_val;
- size_t klen, vlen;
-
- ret = ini_read_pair(ini, &key, &klen, &value, &vlen);
- if (ret <= 0)
- break;
-
- /* Create a dup of the strings read from the INI, since they are
- * not NULL-terminated. */
- new_key = strndup(key, klen);
- new_val = strndup(value, vlen);
-
- if (!new_key || !new_val)
- ret = -ENOMEM;
- else
- ret = iio_context_add_attr(ctx, new_key, new_val);
-
- free(new_key);
- free(new_val);
- } while (!ret);
-
-out_close_ini:
- ini_close(ini);
- return ret;
-}
-#endif
-
-struct iio_context * local_create_context(void)
-{
- int ret = -ENOMEM;
- unsigned int len;
- struct utsname uts;
- struct iio_context *ctx = zalloc(sizeof(*ctx));
- if (!ctx)
- goto err_set_errno;
-
- ctx->ops = &local_ops;
- ctx->name = "local";
-
- ctx->pdata = zalloc(sizeof(*ctx->pdata));
- if (!ctx->pdata) {
- free(ctx);
- goto err_set_errno;
- }
-
- local_set_timeout(ctx, DEFAULT_TIMEOUT_MS);
-
- uname(&uts);
- len = strlen(uts.sysname) + strlen(uts.nodename) + strlen(uts.release)
- + strlen(uts.version) + strlen(uts.machine);
- ctx->description = malloc(len + 5); /* 4 spaces + EOF */
- if (!ctx->description) {
- free(ctx->pdata);
- free(ctx);
- goto err_set_errno;
- }
-
- iio_snprintf(ctx->description, len + 5, "%s %s %s %s %s", uts.sysname,
- uts.nodename, uts.release, uts.version, uts.machine);
-
- ret = foreach_in_dir(ctx, "/sys/bus/iio/devices", true, create_device);
- if (ret < 0)
- goto err_context_destroy;
-
- qsort(ctx->devices, ctx->nb_devices, sizeof(struct iio_device *),
- iio_device_compare);
-
- foreach_in_dir(ctx, "/sys/kernel/debug/iio", true, add_debug);
-
- init_scan_elements(ctx);
-
-#ifdef WITH_LOCAL_CONFIG
- ret = populate_context_attrs(ctx, "/etc/libiio.ini");
- if (ret < 0)
- goto err_context_destroy;
-#endif
-
- ret = iio_context_add_attr(ctx, "local,kernel", uts.release);
- if (ret < 0)
- goto err_context_destroy;
-
- ret = iio_context_init(ctx);
- if (ret < 0)
- goto err_context_destroy;
-
- return ctx;
-
-err_context_destroy:
- iio_context_destroy(ctx);
-err_set_errno:
- errno = -ret;
- return NULL;
-}
-
-static int check_device(void *d, const char *path)
-{
- *(bool *)d = true;
- return 0;
-}
-
-int local_context_scan(struct iio_scan_result *scan_result)
-{
- struct iio_context_info **info;
- bool exists = false;
- char *desc, *uri;
- int ret;
-
- ret = foreach_in_dir(&exists, "/sys/bus/iio", true, check_device);
- if (ret < 0 || !exists)
- return 0;
-
- desc = iio_strdup("Local devices");
- if (!desc)
- return -ENOMEM;
-
- uri = iio_strdup("local:");
- if (!uri)
- goto err_free_desc;
-
- info = iio_scan_result_add(scan_result, 1);
- if (!info)
- goto err_free_uri;
-
- info[0]->description = desc;
- info[0]->uri = uri;
- return 0;
-
-err_free_uri:
- free(uri);
-err_free_desc:
- free(desc);
- return -ENOMEM;
-}
diff --git a/lock.c b/lock.c
deleted file mode 100644
index cabb214..0000000
--- a/lock.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2015 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.
- *
- */
-
-#include "iio-config.h"
-
-#ifdef _WIN32
-#include <windows.h>
-#elif !defined(NO_THREADS)
-#include <pthread.h>
-#endif
-
-#include <stdlib.h>
-
-struct iio_mutex {
-#ifdef NO_THREADS
- int foo; /* avoid complaints about empty structure */
-#else
-#ifdef _WIN32
- CRITICAL_SECTION lock;
-#else
- pthread_mutex_t lock;
-#endif
-#endif
-};
-
-struct iio_mutex * iio_mutex_create(void)
-{
- struct iio_mutex *lock = malloc(sizeof(*lock));
-
- if (!lock)
- return NULL;
-
-#ifndef NO_THREADS
-#ifdef _WIN32
- InitializeCriticalSection(&lock->lock);
-#else
- pthread_mutex_init(&lock->lock, NULL);
-#endif
-#endif
- return lock;
-}
-
-void iio_mutex_destroy(struct iio_mutex *lock)
-{
-#ifndef NO_THREADS
-#ifdef _WIN32
- DeleteCriticalSection(&lock->lock);
-#else
- pthread_mutex_destroy(&lock->lock);
-#endif
-#endif
- free(lock);
-}
-
-void iio_mutex_lock(struct iio_mutex *lock)
-{
-#ifndef NO_THREADS
-#ifdef _WIN32
- EnterCriticalSection(&lock->lock);
-#else
- pthread_mutex_lock(&lock->lock);
-#endif
-#endif
-}
-
-void iio_mutex_unlock(struct iio_mutex *lock)
-{
-#ifndef NO_THREADS
-#ifdef _WIN32
- LeaveCriticalSection(&lock->lock);
-#else
- pthread_mutex_unlock(&lock->lock);
-#endif
-#endif
-}
diff --git a/mainpage.dox b/mainpage.dox
deleted file mode 100644
index 0965351..0000000
--- a/mainpage.dox
+++ /dev/null
@@ -1,256 +0,0 @@
-/**
-@mainpage
-
-@tableofcontents
-
-@section license License
-Libiio has been developed and is released under the terms of the GNU Lesser General Public
-License, version 2. This open-source license allows anyone to use the library for proprietary or
-open-source, commercial or non-commercial applications. This choice was motivated by the fact
-that Analog Devices is a company that principally sells hardware, and this library provides the
-clients with a better and easier way of using this hardware.
-
-The full terms of the license can be found here: http://opensource.org/licenses/LGPL-2.1
-
-@section code_model Code Model
-The basic bricks of the libiio API are the iio_context, iio_device, iio_channel and iio_buffer classes.
-
-![Caption text](doc/codemodel.svg)
-
-- A iio_context object may contain zero or more iio_device objects.
- A iio_device object is associated with only one iio_context.
- This object represents an instance of the library.
-- A iio_device object may contain zero or more iio_channel objects. A iio_channel object is associated with only one iio_device.
-- A iio_device object may be associated with one iio_buffer object, and a iio_buffer object is associated with only one iio_device.
-
-@section creating_context Creating a context
-Different functions are available to create the iio_context object. Depending on what backends were enabled when compiling the library, some of them may not be available.
-Each function will result in a different backend being used.
-
-Those functions are:
-- iio_create_local_context(): Create a "local" context, to use the IIO devices connected to the system (typically for cross-compiled applications).
-- iio_create_network_context(): Create a "network" context that will work with a remotely connected target.
-
-Note that every function that compose the API of libiio will work independently of the function that was used to create the iio_context object.
-
-The iio_context object can later be destroyed with iio_context_destroy().
-
-@subsection navigation Navigation
-@subsubsection device_obj Device objects
-- From the iio_context object, you can obtain the number of available devices with iio_context_get_devices_count().
-- Then, each iio_device object can be accessed with iio_context_get_device().
-- Alternatively, it is possible to lookup for a device name or ID with iio_context_find_device().
-
-Each iio_device object has an ID that can be used as identifier. This ID can be retrieved with iio_device_get_id().
-It optionally also has a name, that can be retrieved with iio_device_get_name().
-
-@subsubsection channel_obj Channel objects
-- From the iio_device object, you can obtain the number of available channels with iio_device_get_channels_count().
-- Then, each iio_channel object can be accessed with iio_device_get_channel().
-- Alternatively, it is possible to lookup for a channel name or ID with iio_device_find_channel().
-
-Each iio_channel can be either input, or output. This information can be retrieved with iio_channel_is_output().
-As for the Device objects, the iio_channel object features an ID and optionally a name.
-The ID can be obtained with iio_channel_get_id(), and the name can be obtained with iio_channel_get_name().
-Important note: two iio_channel can have the same ID, as long as one is input and the other is output.
-
-@subsection list_params Parameters
-Different kinds of parameters are available: parameters that apply to a iio_device, and parameters that apply to one or more iio_channel.
-- The number of device-specific parameters can be obtained with iio_device_get_attrs_count(). Each attribute name can be obtained with iio_device_get_attr().
-- The number of channel-specific attributes can be obtained with iio_channel_get_attrs_count(). Each attribute name can be obtained with iio_channel_get_attr().
-
-Alternatively, it is possible to lookup for the name of an attribute with iio_device_find_attr() and iio_channel_find_attr().
-
-@section reading_modify_params Reading and modifying parameters
-
-@subsection read_param Reading a parameter
-Read device-specific attributes with those functions:
-- iio_device_attr_read()
-- iio_device_attr_read_all()
-- iio_device_attr_read_bool()
-- iio_device_attr_read_longlong()
-- iio_device_attr_read_double()
-
-Read channel-specific attributes with those functions:
-- iio_channel_attr_read()
-- iio_channel_attr_read_all()
-- iio_channel_attr_read_bool()
-- iio_channel_attr_read_longlong()
-- iio_channel_attr_read_double()
-
-Read debug attributes with those functions:
-- iio_device_debug_attr_read()
-- iio_device_debug_attr_read_all()
-- iio_device_debug_attr_read_bool()
-- iio_device_debug_attr_read_longlong()
-- iio_device_debug_attr_read_double()
-
-@subsection write_param Modifying a parameter
-Write device-specific attributes with those functions:
-- iio_device_attr_write()
-- iio_device_attr_write_all()
-- iio_device_attr_write_bool()
-- iio_device_attr_write_longlong()
-- iio_device_attr_write_double()
-
-Write channel-specific attributes with those functions:
-- iio_channel_attr_write()
-- iio_channel_attr_write_all()
-- iio_channel_attr_write_bool()
-- iio_channel_attr_write_longlong()
-- iio_channel_attr_write_double()
-
-Write debug attributes with those functions:
-- iio_device_debug_attr_write()
-- iio_device_debug_attr_write_all()
-- iio_device_debug_attr_write_bool()
-- iio_device_debug_attr_write_longlong()
-- iio_device_debug_attr_write_double()
-
-@section trigger Triggers
-Some devices, mostly low-speed ADCs and DACs, require a trigger to be set for the capture or upload process to work.
-
-In libiio, triggers are just regular iio_device objects. To check if an iio_device can be used as a trigger, you can use iio_device_is_trigger().
-
-To see if one device is associated with a trigger, use iio_device_get_trigger().
-
-To assign one trigger to a iio_device, you can use iio_device_set_trigger(). If you want to disassociate a iio_device from its trigger, pass NULL to the "trigger" parameter of this function.
-
-@section capture_upload Capturing or uploading samples
-The process of capturing samples from the hardware and uploading samples to the hardware is done using the functions that apply to the iio_buffer object.
-
-@subsection create_buffer Enabling channels and creating the Buffer object
-The very first step is to enable the capture channels that we want to use, and disable those that we don't need.
-This is done with the functions iio_channel_enable() and iio_channel_disable().
-Note that the channels will really be enabled or disabled when the iio_buffer object is created.
-
-Also, not all channels can be enabled. To know whether or not one channel can be enabled, use iio_channel_is_scan_element().
-
-Once the channels have been enabled, and triggers assigned (for triggered buffers) the iio_buffer object can be created from the iio_device object that will be used, with the function iio_device_create_buffer().
-This call will fail if no channels have been enabled, or for triggered buffers, if the trigger has not been assigned.
-
-When the object is no more needed, it can be destroyed with iio_buffer_destroy().
-
-@subsection refill Refilling the Buffer (input devices only)
-If the Buffer object has been created from a device with input channels, then it must be updated first. This is done with the iio_buffer_refill() function.
-
-@subsection read_write Reading or writing samples to the Buffer
-Libiio offers various ways to interact with the iio_buffer object.
-
-@subsubsection memcpy Direct copy
-If you already have a buffer of samples, correctly interleaved and in the format that the hardware expects,
-it is possible to copy the samples directly into the iio_buffer object using `memcpy`:
-
-~~~{.c}
-size_t iio_buf_size = iio_buffer_end(buffer) - iio_buffer_start(buffer);
-size_t count = MAX(sizeof(samples_buffer), iio_buf_size);
-memcpy(iio_buffer_start(buffer), samples_buffer, count);
-~~~
-
-Using `memcpy` to copy samples from the iio_buffer is <b>not recommended</b>.
-When capturing samples from an input device, you cannot assume that the iio_buffer object contains only the samples you're interested in.
-
-@subsubsection iterating_cb Iterating over the buffer with a callback
-Libiio provides a way to iterate over the buffer by registering a callback function, with the iio_buffer_foreach_sample() function.
-
-The callback function will be called for each "sample slot" of the buffer,
-which will contain a valid sample if the buffer has been refilled,
-or correspond to an area where a sample should be stored if using an output device.
-
-~~~{.c}
-ssize_t sample_cb(const struct iio_channel *chn, void *src, size_t bytes, void *d)
-{
- /* Use "src" to read or write a sample for this channel */
-}
-
-int main(void)
-{
- ...
- iio_buffer_foreach_sample(buffer, sample_cb, NULL);
- ...
-}
-~~~
-
-Note that the callback will be called in the order that the samples appear in the buffer,
-and only for samples that correspond to channels that were enabled.
-
-@subsubsection iterating_for Iterating on the samples with a for loop
-This method allows you to iterate over the samples slots that correspond to one channel.
-As such, it is interesting if you want to process the data channel by channel.
-
-It basically consists in a for loop that uses the functions iio_buffer_first(), iio_buffer_step() and iio_buffer_end():
-
-~~~{.c}
-for (void *ptr = iio_buffer_first(buffer, channel);
- ptr < iio_buffer_end(buffer);
- ptr += iio_buffer_step(buffer)) {
- /* Use "ptr" to read or write a sample for this channel */
-}
-~~~
-
-@subsubsection deinterleave Extracting from/to a second buffer
-
-Finally, it is possible to use the iio_channel_read() and iio_channel_read_raw()
-functions to read samples from the iio_buffer to a second byte array.
-The samples will be deinterleaved if needed.
-The "raw" variant will only deinterleave the samples, while the other variant will deinterleave and convert the samples.
-
-For output devices, the iio_channel_write() and iio_channel_write_raw() functions are also available.
-The "raw" variant will only interleave the samples (if needed), while the other variant will interleave and convert the samples
-back to their hardware format.
-
-@subsection convert Convert the samples from/to hardware format
-The raw stream of samples generally isn't in a format that can be directly used in algorithms.
-Some operations, like endianness conversion and bit-shifting of the samples, have to be performed first.
-
-Libiio offers two functions that can be used to convert samples:
-- iio_channel_convert(), to convert from the hardware format
-- iio_channel_convert_inverse(), to convert to the hardware format.
-
-Those two functions should always be used when manipulating the samples of the iio_buffer.
-The exception is when iio_channel_read() or iio_channel_write() are used, as the conversion is then done internally.
-
-@subsection push Submitting the Buffer (output devices only)
-When all the samples have been written to the iio_buffer object, you can submit the buffer to the hardware with a call to iio_buffer_push().
-As soon as the buffer has been submitted, it can be re-used to store new samples.
-
-If the iio_buffer object has been created with the "cyclic" parameter set, and the kernel driver supports cyclic buffers,
-the submitted buffer will be repeated until the iio_buffer is destroyed, and no subsequent call to iio_buffer_push() will be allowed.
-
-@section advanced Advanced options
-
-@subsection userdata Register and retrieve a pointer
-The iio_device and iio_channel allow you to register a pointer, that can then be retrieved at a later moment.
-- A pointer can be registered with a iio_device object using iio_device_set_data(), and can be retrieved with iio_device_get_data().
-- A pointer can be registered with a iio_channel object using iio_channel_set_data(), and can be retrieved with iio_channel_get_data().
-
-@subsection debug_attr Debug attributes
-Some IIO devices provide debug parameters, but their presence is optional. In a similar way than with regular device parameters,
-the number of debug parameters can be obtained with iio_device_get_debug_attrs_count(). Each individual parameter can be retrieved with iio_device_get_debug_attr().
-Alternatively, it is possible to lookup for the name of a debug attribute with iio_device_find_debug_attr().
-
-Those debug parameters can be read using the following functions:
-- iio_device_debug_attr_read(),
-- iio_device_debug_attr_read_all(),
-- iio_device_debug_attr_read_bool(),
-- iio_device_debug_attr_read_longlong(),
-- iio_device_debug_attr_read_double().
-
-Those debug parameters can be written using the following functions:
-- iio_device_debug_attr_write(),
-- iio_device_debug_attr_write_all(),
-- iio_device_debug_attr_write_bool(),
-- iio_device_debug_attr_write_longlong(),
-- iio_device_debug_attr_write_double().
-
-@subsection registers Reading and writing registers
-As for debug attributes, some IIO devices also offer the possibility to read and write hardware registers directly.
-In libiio, this can be done with two functions, iio_device_reg_read() and iio_device_reg_write().
-
-@section abi Application Binary Interface
-
-The libiio ABI tries to be both backwards and forwards compatible.
-This means applications compiled against an older version will work fine with a newer dynamically linked library. Applications compiled against a newer version will work fine with an older dynamically linked library so long as they don't access any new features. Applications using new features should ensure the libiio version is compatible by using iio_library_get_version() to avoid undefined behavior.
-
-
-*/
diff --git a/network.c b/network.c
deleted file mode 100644
index ab6fe38..0000000
--- a/network.c
+++ /dev/null
@@ -1,1627 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2014-2015 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.
- *
- * */
-
-#include "iio-config.h"
-#include "iio-private.h"
-#include "iio-lock.h"
-#include "iiod-client.h"
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stdbool.h>
-#include <string.h>
-#include <sys/types.h>
-#include <time.h>
-
-#ifdef _WIN32
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#define close(s) closesocket(s)
-
-/* winsock2.h defines ERROR, we don't want that */
-#undef ERROR
-
-#else /* _WIN32 */
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <net/if.h>
-#include <sys/mman.h>
-#include <poll.h>
-#include <sys/socket.h>
-#include <unistd.h>
-#endif /* _WIN32 */
-
-#ifdef HAVE_AVAHI
-#include <avahi-client/client.h>
-#include <avahi-common/error.h>
-#include <avahi-client/lookup.h>
-#include <avahi-common/simple-watch.h>
-#endif
-
-#include "debug.h"
-
-#define DEFAULT_TIMEOUT_MS 5000
-
-#define _STRINGIFY(x) #x
-#define STRINGIFY(x) _STRINGIFY(x)
-
-#define IIOD_PORT 30431
-#define IIOD_PORT_STR STRINGIFY(IIOD_PORT)
-
-struct iio_network_io_context {
- int fd;
-
- /* Only buffer IO contexts can be cancelled. */
- bool cancellable;
- bool cancelled;
-#if defined(_WIN32)
- WSAEVENT events[2];
-#elif defined(WITH_NETWORK_EVENTFD)
- int cancel_fd[1]; /* eventfd */
-#else
- int cancel_fd[2]; /* pipe */
-#endif
- unsigned int timeout_ms;
-};
-
-struct iio_context_pdata {
- struct iio_network_io_context io_ctx;
- struct addrinfo *addrinfo;
- struct iio_mutex *lock;
- struct iiod_client *iiod_client;
- bool msg_trunc_supported;
-};
-
-struct iio_device_pdata {
- struct iio_network_io_context io_ctx;
-#ifdef WITH_NETWORK_GET_BUFFER
- int memfd;
- void *mmap_addr;
- size_t mmap_len;
-#endif
- bool wait_for_err_code, is_cyclic, is_tx;
- struct iio_mutex *lock;
-};
-
-#ifdef _WIN32
-
-static int set_blocking_mode(int s, bool blocking)
-{
- unsigned long nonblock;
- int ret;
-
- nonblock = blocking ? 0 : 1;
-
- ret = ioctlsocket(s, FIONBIO, &nonblock);
- if (ret == SOCKET_ERROR) {
- ret = -WSAGetLastError();
- return ret;
- }
-
- return 0;
-}
-
-static int setup_cancel(struct iio_network_io_context *io_ctx)
-{
- io_ctx->events[0] = WSACreateEvent();
- if (io_ctx->events[0] == WSA_INVALID_EVENT)
- return -ENOMEM; /* Pretty much the only error that can happen */
-
- io_ctx->events[1] = WSACreateEvent();
- if (io_ctx->events[1] == WSA_INVALID_EVENT) {
- WSACloseEvent(io_ctx->events[0]);
- return -ENOMEM;
- }
-
- return 0;
-}
-
-static void cleanup_cancel(struct iio_network_io_context *io_ctx)
-{
- WSACloseEvent(io_ctx->events[0]);
- WSACloseEvent(io_ctx->events[1]);
-}
-
-static void do_cancel(struct iio_network_io_context *io_ctx)
-{
- WSASetEvent(io_ctx->events[1]);
-}
-
-static int wait_cancellable(struct iio_network_io_context *io_ctx, bool read)
-{
- long wsa_events = FD_CLOSE;
- DWORD ret;
-
- if (!io_ctx->cancellable)
- return 0;
-
- if (read)
- wsa_events |= FD_READ;
- else
- wsa_events |= FD_WRITE;
-
- WSAEventSelect(io_ctx->fd, NULL, 0);
- WSAResetEvent(io_ctx->events[0]);
- WSAEventSelect(io_ctx->fd, io_ctx->events[0], wsa_events);
-
- ret = WSAWaitForMultipleEvents(2, io_ctx->events, FALSE,
- WSA_INFINITE, FALSE);
-
- if (ret == WSA_WAIT_EVENT_0 + 1)
- return -EBADF;
-
- return 0;
-}
-
-static int network_get_error(void)
-{
- return -WSAGetLastError();
-}
-
-static bool network_should_retry(int err)
-{
- return err == -WSAEWOULDBLOCK || err == -WSAETIMEDOUT;
-}
-
-static bool network_is_interrupted(int err)
-{
- return false;
-}
-
-static bool network_connect_in_progress(int err)
-{
- return err == -WSAEWOULDBLOCK;
-}
-
-#define NETWORK_ERR_TIMEOUT WSAETIMEDOUT
-
-#else
-
-static int set_blocking_mode(int fd, bool blocking)
-{
- int ret = fcntl(fd, F_GETFL, 0);
- if (ret < 0)
- return -errno;
-
- if (blocking)
- ret &= ~O_NONBLOCK;
- else
- ret |= O_NONBLOCK;
-
- ret = fcntl(fd, F_SETFL, ret);
- return ret < 0 ? -errno : 0;
-}
-
-#include <poll.h>
-
-#if defined(WITH_NETWORK_EVENTFD)
-
-#include <sys/eventfd.h>
-
-static int create_cancel_fd(struct iio_network_io_context *io_ctx)
-{
- io_ctx->cancel_fd[0] = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
- if (io_ctx->cancel_fd[0] < 0)
- return -errno;
- return 0;
-}
-
-static void cleanup_cancel(struct iio_network_io_context *io_ctx)
-{
- close(io_ctx->cancel_fd[0]);
-}
-
-#define CANCEL_WR_FD 0
-
-#else
-
-static int create_cancel_fd(struct iio_network_io_context *io_ctx)
-{
- int ret;
-
-#ifdef HAS_PIPE2
- ret = pipe2(io_ctx->cancel_fd, O_CLOEXEC | O_NONBLOCK);
- if (ret < 0 && errno != ENOSYS) /* If ENOSYS try pipe() */
- return -errno;
-#endif
- ret = pipe(io_ctx->cancel_fd);
- if (ret < 0)
- return -errno;
- ret = set_blocking_mode(io_ctx->cancel_fd[0], false);
- if (ret < 0)
- goto err_close;
- ret = set_blocking_mode(io_ctx->cancel_fd[1], false);
- if (ret < 0)
- goto err_close;
-
- return 0;
-err_close:
- close(io_ctx->cancel_fd[0]);
- close(io_ctx->cancel_fd[1]);
- return ret;
-}
-
-static void cleanup_cancel(struct iio_network_io_context *io_ctx)
-{
- close(io_ctx->cancel_fd[0]);
- close(io_ctx->cancel_fd[1]);
-}
-
-#define CANCEL_WR_FD 1
-
-#endif
-
-static int setup_cancel(struct iio_network_io_context *io_ctx)
-{
- int ret;
-
- ret = set_blocking_mode(io_ctx->fd, false);
- if (ret)
- return ret;
-
- return create_cancel_fd(io_ctx);
-}
-
-static void do_cancel(struct iio_network_io_context *io_ctx)
-{
- uint64_t event = 1;
- int ret;
-
- ret = write(io_ctx->cancel_fd[CANCEL_WR_FD], &event, sizeof(event));
- if (ret == -1) {
- /* If this happens something went very seriously wrong */
- char err_str[1024];
- iio_strerror(errno, err_str, sizeof(err_str));
- ERROR("Unable to signal cancellation event: %s\n", err_str);
- }
-}
-
-static int wait_cancellable(struct iio_network_io_context *io_ctx, bool read)
-{
- struct pollfd pfd[2];
- int ret;
-
- if (!io_ctx->cancellable)
- return 0;
-
- memset(pfd, 0, sizeof(pfd));
-
- pfd[0].fd = io_ctx->fd;
- if (read)
- pfd[0].events = POLLIN;
- else
- pfd[0].events = POLLOUT;
- pfd[1].fd = io_ctx->cancel_fd[0];
- pfd[1].events = POLLIN;
-
- do {
- int timeout_ms;
-
- if (io_ctx->timeout_ms > 0)
- timeout_ms = (int) io_ctx->timeout_ms;
- else
- timeout_ms = -1;
-
- do {
- ret = poll(pfd, 2, timeout_ms);
- } while (ret == -1 && errno == EINTR);
-
- if (ret == -1)
- return -errno;
- if (!ret)
- return -EPIPE;
-
- if (pfd[1].revents & POLLIN)
- return -EBADF;
- } while (!(pfd[0].revents & (pfd[0].events | POLLERR | POLLHUP)));
-
- return 0;
-}
-
-static int network_get_error(void)
-{
- return -errno;
-}
-
-static bool network_should_retry(int err)
-{
- return err == -EAGAIN;
-}
-
-static bool network_is_interrupted(int err)
-{
- return err == -EINTR;
-}
-
-static bool network_connect_in_progress(int err)
-{
- return err == -EINPROGRESS;
-}
-
-#define NETWORK_ERR_TIMEOUT ETIMEDOUT
-
-#endif
-
-#ifdef HAVE_AVAHI
-struct avahi_discovery_data {
- AvahiSimplePoll *poll;
- AvahiAddress *address;
- uint16_t *port;
- bool found, resolved;
-};
-
-static void __avahi_resolver_cb(AvahiServiceResolver *resolver,
- __notused AvahiIfIndex iface, __notused AvahiProtocol proto,
- __notused AvahiResolverEvent event, __notused const char *name,
- __notused const char *type, __notused const char *domain,
- __notused const char *host_name, const AvahiAddress *address,
- uint16_t port, __notused AvahiStringList *txt,
- __notused AvahiLookupResultFlags flags, void *d)
-{
- struct avahi_discovery_data *ddata = (struct avahi_discovery_data *) d;
-
- memcpy(ddata->address, address, sizeof(*address));
- *ddata->port = port;
- ddata->resolved = true;
- avahi_service_resolver_free(resolver);
-}
-
-static void __avahi_browser_cb(AvahiServiceBrowser *browser,
- AvahiIfIndex iface, AvahiProtocol proto,
- AvahiBrowserEvent event, const char *name,
- const char *type, const char *domain,
- __notused AvahiLookupResultFlags flags, void *d)
-{
- struct avahi_discovery_data *ddata = (struct avahi_discovery_data *) d;
- struct AvahiClient *client = avahi_service_browser_get_client(browser);
-
- switch (event) {
- default:
- case AVAHI_BROWSER_NEW:
- ddata->found = !!avahi_service_resolver_new(client, iface,
- proto, name, type, domain,
- AVAHI_PROTO_UNSPEC, 0,
- __avahi_resolver_cb, d);
- break;
- case AVAHI_BROWSER_ALL_FOR_NOW:
- if (ddata->found) {
- while (!ddata->resolved) {
- struct timespec ts;
- ts.tv_sec = 0;
- ts.tv_nsec = 4000000;
- nanosleep(&ts, NULL);
- }
- }
- /* fall-through */
- case AVAHI_BROWSER_FAILURE:
- avahi_simple_poll_quit(ddata->poll);
- /* fall-through */
- case AVAHI_BROWSER_CACHE_EXHAUSTED:
- break;
- }
-}
-
-static int discover_host(AvahiAddress *addr, uint16_t *port)
-{
- struct avahi_discovery_data ddata;
- int ret = 0;
- AvahiClient *client;
- AvahiServiceBrowser *browser;
- AvahiSimplePoll *poll = avahi_simple_poll_new();
- if (!poll)
- return -ENOMEM;
-
- client = avahi_client_new(avahi_simple_poll_get(poll),
- 0, NULL, NULL, &ret);
- if (!client) {
- ERROR("Unable to start ZeroConf client :%s\n",
- avahi_strerror(ret));
- goto err_free_poll;
- }
-
- memset(&ddata, 0, sizeof(ddata));
- ddata.poll = poll;
- ddata.address = addr;
- ddata.port = port;
-
- browser = avahi_service_browser_new(client,
- AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
- "_iio._tcp", NULL, 0, __avahi_browser_cb, &ddata);
- if (!browser) {
- ret = avahi_client_errno(client);
- ERROR("Unable to create ZeroConf browser: %s\n",
- avahi_strerror(ret));
- goto err_free_client;
- }
-
- DEBUG("Trying to discover host\n");
- avahi_simple_poll_loop(poll);
-
- if (!ddata.found)
- ret = ENXIO;
-
- avahi_service_browser_free(browser);
-err_free_client:
- avahi_client_free(client);
-err_free_poll:
- avahi_simple_poll_free(poll);
- return -ret; /* we want a negative error code */
-}
-#endif /* HAVE_AVAHI */
-
-static ssize_t network_recv(struct iio_network_io_context *io_ctx,
- void *data, size_t len, int flags)
-{
- ssize_t ret;
- int err;
-
- while (1) {
- ret = wait_cancellable(io_ctx, true);
- if (ret < 0)
- return ret;
-
- ret = recv(io_ctx->fd, data, (int) len, flags);
- if (ret == 0)
- return -EPIPE;
- else if (ret > 0)
- break;
-
- err = network_get_error();
- if (network_should_retry(err)) {
- if (io_ctx->cancellable)
- continue;
- else
- return -EPIPE;
- } else if (!network_is_interrupted(err)) {
- return (ssize_t) err;
- }
- }
- return ret;
-}
-
-static ssize_t network_send(struct iio_network_io_context *io_ctx,
- const void *data, size_t len, int flags)
-{
- ssize_t ret;
- int err;
-
- while (1) {
- ret = wait_cancellable(io_ctx, false);
- if (ret < 0)
- return ret;
-
- ret = send(io_ctx->fd, data, (int) len, flags);
- if (ret == 0)
- return -EPIPE;
- else if (ret > 0)
- break;
-
- err = network_get_error();
- if (network_should_retry(err)) {
- if (io_ctx->cancellable)
- continue;
- else
- return -EPIPE;
- } else if (!network_is_interrupted(err)) {
- return (ssize_t) err;
- }
- }
-
- return ret;
-}
-
-static ssize_t write_all(struct iio_network_io_context *io_ctx,
- const void *src, size_t len)
-{
- uintptr_t ptr = (uintptr_t) src;
- while (len) {
- ssize_t ret = network_send(io_ctx, (const void *) ptr, len, 0);
- if (ret < 0)
- return ret;
- ptr += ret;
- len -= ret;
- }
- return (ssize_t)(ptr - (uintptr_t) src);
-}
-
-static ssize_t write_command(struct iio_network_io_context *io_ctx,
- const char *cmd)
-{
- ssize_t ret;
-
- DEBUG("Writing command: %s\n", cmd);
- ret = write_all(io_ctx, cmd, strlen(cmd));
- if (ret < 0) {
- char buf[1024];
- iio_strerror(-ret, buf, sizeof(buf));
- ERROR("Unable to send command: %s\n", buf);
- }
- return ret;
-}
-
-static void network_cancel(const struct iio_device *dev)
-{
- struct iio_device_pdata *ppdata = dev->pdata;
-
- do_cancel(&ppdata->io_ctx);
-
- ppdata->io_ctx.cancelled = true;
-}
-
-#ifndef _WIN32
-
-/* Use it if available */
-#ifndef SOCK_CLOEXEC
-#define SOCK_CLOEXEC 0
-#endif
-
-static int do_create_socket(const struct addrinfo *addrinfo)
-{
- int fd;
-
- fd = socket(addrinfo->ai_family, addrinfo->ai_socktype | SOCK_CLOEXEC, 0);
- if (fd < 0)
- return -errno;
-
- return fd;
-}
-
-static int set_socket_timeout(int fd, unsigned int timeout)
-{
- struct timeval tv;
-
- tv.tv_sec = timeout / 1000;
- tv.tv_usec = (timeout % 1000) * 1000;
- if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) < 0 ||
- setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO,
- &tv, sizeof(tv)) < 0)
- return -errno;
- else
- return 0;
-}
-#else
-
-/* Use it if available */
-#ifndef WSA_FLAG_NO_HANDLE_INHERIT
-#define WSA_FLAG_NO_HANDLE_INHERIT 0
-#endif
-
-static int do_create_socket(const struct addrinfo *addrinfo)
-{
- SOCKET s;
-
- s = WSASocketW(addrinfo->ai_family, addrinfo->ai_socktype, 0, NULL, 0,
- WSA_FLAG_NO_HANDLE_INHERIT | WSA_FLAG_OVERLAPPED);
- if (s == INVALID_SOCKET)
- return -WSAGetLastError();
-
- return (int) s;
-}
-
-static int set_socket_timeout(int fd, unsigned int timeout)
-{
- if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO,
- (const char *) &timeout, sizeof(timeout)) < 0 ||
- setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO,
- (const char *) &timeout, sizeof(timeout)) < 0)
- return -WSAGetLastError();
- else
- return 0;
-}
-#endif /* !_WIN32 */
-
-/* The purpose of this function is to provide a version of connect()
- * that does not ignore timeouts... */
-static int do_connect(int fd, const struct addrinfo *addrinfo,
- unsigned int timeout)
-{
- int ret, error;
- socklen_t len;
-#ifdef _WIN32
- struct timeval tv;
- struct timeval *ptv;
- fd_set set;
-#else
- struct pollfd pfd;
-#endif
-
- ret = set_blocking_mode(fd, false);
- if (ret < 0)
- return ret;
-
- ret = connect(fd, addrinfo->ai_addr, (int) addrinfo->ai_addrlen);
- if (ret < 0) {
- ret = network_get_error();
- if (!network_connect_in_progress(ret))
- return ret;
- }
-
-#ifdef _WIN32
- FD_ZERO(&set);
- FD_SET(fd, &set);
-
- if (timeout != 0) {
- tv.tv_sec = timeout / 1000;
- tv.tv_usec = (timeout % 1000) * 1000;
- ptv = &tv;
- } else {
- ptv = NULL;
- }
-
- ret = select(fd + 1, NULL, &set, &set, ptv);
-#else
- pfd.fd = fd;
- pfd.events = POLLOUT | POLLERR;
- pfd.revents = 0;
-
- do {
- ret = poll(&pfd, 1, timeout);
- } while (ret == -1 && errno == EINTR);
-#endif
-
- if (ret < 0)
- return network_get_error();
-
- if (ret == 0)
- return -NETWORK_ERR_TIMEOUT;
-
- /* Verify that we don't have an error */
- len = sizeof(error);
- ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, (char *)&error, &len);
- if(ret < 0)
- return network_get_error();
-
- if (error)
- return -error;
-
- ret = set_blocking_mode(fd, true);
- if (ret < 0)
- return ret;
-
- return 0;
-}
-
-static int create_socket(const struct addrinfo *addrinfo, unsigned int timeout)
-{
- int ret, fd, yes = 1;
-
- fd = do_create_socket(addrinfo);
- if (fd < 0)
- return fd;
-
- ret = do_connect(fd, addrinfo, timeout);
- if (ret < 0) {
- close(fd);
- return ret;
- }
-
- set_socket_timeout(fd, timeout);
- if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
- (const char *) &yes, sizeof(yes)) < 0) {
- ret = -errno;
- close(fd);
- return ret;
- }
-
- return fd;
-}
-
-static int network_open(const struct iio_device *dev,
- size_t samples_count, bool cyclic)
-{
- struct iio_context_pdata *pdata = dev->ctx->pdata;
- struct iio_device_pdata *ppdata = dev->pdata;
- int ret = -EBUSY;
-
- iio_mutex_lock(ppdata->lock);
- if (ppdata->io_ctx.fd >= 0)
- goto out_mutex_unlock;
-
- ret = create_socket(pdata->addrinfo, DEFAULT_TIMEOUT_MS);
- if (ret < 0)
- goto out_mutex_unlock;
-
- ppdata->io_ctx.fd = ret;
- ppdata->io_ctx.cancelled = false;
- ppdata->io_ctx.cancellable = false;
- ppdata->io_ctx.timeout_ms = DEFAULT_TIMEOUT_MS;
-
- ret = iiod_client_open_unlocked(pdata->iiod_client,
- &ppdata->io_ctx, dev, samples_count, cyclic);
- if (ret < 0)
- goto err_close_socket;
-
- ret = setup_cancel(&ppdata->io_ctx);
- if (ret < 0)
- goto err_close_socket;
-
- set_socket_timeout(ppdata->io_ctx.fd, pdata->io_ctx.timeout_ms);
-
- ppdata->io_ctx.timeout_ms = pdata->io_ctx.timeout_ms;
- ppdata->io_ctx.cancellable = true;
- ppdata->is_tx = iio_device_is_tx(dev);
- ppdata->is_cyclic = cyclic;
- ppdata->wait_for_err_code = false;
-#ifdef WITH_NETWORK_GET_BUFFER
- ppdata->mmap_len = samples_count * iio_device_get_sample_size(dev);
-#endif
-
- iio_mutex_unlock(ppdata->lock);
-
- return 0;
-
-err_close_socket:
- close(ppdata->io_ctx.fd);
- ppdata->io_ctx.fd = -1;
-out_mutex_unlock:
- iio_mutex_unlock(ppdata->lock);
- return ret;
-}
-
-static int network_close(const struct iio_device *dev)
-{
- struct iio_device_pdata *pdata = dev->pdata;
- int ret = -EBADF;
-
- iio_mutex_lock(pdata->lock);
-
- if (pdata->io_ctx.fd >= 0) {
- if (!pdata->io_ctx.cancelled) {
- ret = iiod_client_close_unlocked(
- dev->ctx->pdata->iiod_client,
- &pdata->io_ctx, dev);
-
- write_command(&pdata->io_ctx, "\r\nEXIT\r\n");
- } else {
- ret = 0;
- }
-
- cleanup_cancel(&pdata->io_ctx);
- close(pdata->io_ctx.fd);
- pdata->io_ctx.fd = -1;
- }
-
-#ifdef WITH_NETWORK_GET_BUFFER
- if (pdata->memfd >= 0)
- close(pdata->memfd);
- pdata->memfd = -1;
-
- if (pdata->mmap_addr) {
- munmap(pdata->mmap_addr, pdata->mmap_len);
- pdata->mmap_addr = NULL;
- }
-#endif
-
- iio_mutex_unlock(pdata->lock);
- return ret;
-}
-
-static ssize_t network_read(const struct iio_device *dev, void *dst, size_t len,
- uint32_t *mask, size_t words)
-{
- struct iio_device_pdata *pdata = dev->pdata;
- ssize_t ret;
-
- iio_mutex_lock(pdata->lock);
- ret = iiod_client_read_unlocked(dev->ctx->pdata->iiod_client,
- &pdata->io_ctx, dev, dst, len, mask, words);
- iio_mutex_unlock(pdata->lock);
-
- return ret;
-}
-
-static ssize_t network_write(const struct iio_device *dev,
- const void *src, size_t len)
-{
- struct iio_device_pdata *pdata = dev->pdata;
- ssize_t ret;
-
- iio_mutex_lock(pdata->lock);
- ret = iiod_client_write_unlocked(dev->ctx->pdata->iiod_client,
- &pdata->io_ctx, dev, src, len);
- iio_mutex_unlock(pdata->lock);
-
- return ret;
-}
-
-#ifdef WITH_NETWORK_GET_BUFFER
-
-static ssize_t read_all(struct iio_network_io_context *io_ctx,
- void *dst, size_t len)
-{
- uintptr_t ptr = (uintptr_t) dst;
- while (len) {
- ssize_t ret = network_recv(io_ctx, (void *) ptr, len, 0);
- if (ret < 0)
- return ret;
- ptr += ret;
- len -= ret;
- }
- return (ssize_t)(ptr - (uintptr_t) dst);
-}
-
-static int read_integer(struct iio_network_io_context *io_ctx, long *val)
-{
- unsigned int i;
- char buf[1024], *ptr;
- ssize_t ret;
- bool found = false;
-
- for (i = 0; i < sizeof(buf) - 1; i++) {
- ret = read_all(io_ctx, buf + i, 1);
- if (ret < 0)
- return (int) ret;
-
- /* Skip the eventual first few carriage returns.
- * Also stop when a dot is found (for parsing floats) */
- if (buf[i] != '\n' && buf[i] != '.')
- found = true;
- else if (found)
- break;
- }
-
- buf[i] = '\0';
- ret = (ssize_t) strtol(buf, &ptr, 10);
- if (ptr == buf)
- return -EINVAL;
- *val = (long) ret;
- return 0;
-}
-
-static ssize_t network_read_mask(struct iio_network_io_context *io_ctx,
- uint32_t *mask, size_t words)
-{
- long read_len;
- ssize_t ret;
-
- ret = read_integer(io_ctx, &read_len);
- if (ret < 0)
- return ret;
-
- if (read_len > 0 && mask) {
- size_t i;
- char buf[9];
-
- buf[8] = '\0';
- DEBUG("Reading mask\n");
-
- for (i = words; i > 0; i--) {
- ret = read_all(io_ctx, buf, 8);
- if (ret < 0)
- return ret;
-
- sscanf(buf, "%08x", &mask[i - 1]);
- DEBUG("mask[%lu] = 0x%x\n",
- (unsigned long)(i - 1), mask[i - 1]);
- }
- }
-
- if (read_len > 0) {
- char c;
- ssize_t nb = read_all(io_ctx, &c, 1);
- if (nb > 0 && c != '\n')
- read_len = -EIO;
- }
-
- return (ssize_t) read_len;
-}
-
-static ssize_t read_error_code(struct iio_network_io_context *io_ctx)
-{
- /*
- * The server returns two integer codes.
- * The first one is returned right after the WRITEBUF command is issued,
- * and corresponds to the error code returned when the server attempted
- * to open the device.
- * If zero, a second error code is returned, that corresponds (if positive)
- * to the number of bytes written.
- *
- * To speed up things, we delay error reporting. We just send out the
- * data without reading the error code that the server gives us, because
- * the answer will take too much time. If an error occured, it will be
- * reported by the next call to iio_buffer_push().
- */
-
- unsigned int i;
- long resp = 0;
-
- for (i = 0; i < 2; i++) {
- ssize_t ret = read_integer(io_ctx, &resp);
- if (ret < 0)
- return ret;
- if (resp < 0)
- return (ssize_t) resp;
- }
-
- return (ssize_t) resp;
-}
-
-static ssize_t write_rwbuf_command(const struct iio_device *dev,
- const char *cmd)
-{
- struct iio_device_pdata *pdata = dev->pdata;
-
- if (pdata->wait_for_err_code) {
- ssize_t ret = read_error_code(&pdata->io_ctx);
-
- pdata->wait_for_err_code = false;
- if (ret < 0)
- return ret;
- }
-
- return write_command(&pdata->io_ctx, cmd);
-}
-
-static ssize_t network_do_splice(struct iio_device_pdata *pdata, size_t len,
- bool read)
-{
- int pipefd[2];
- int fd_in, fd_out;
- ssize_t ret, read_len = len, write_len = 0;
-
- ret = (ssize_t) pipe2(pipefd, O_CLOEXEC);
- if (ret < 0)
- return -errno;
-
- if (read) {
- fd_in = pdata->io_ctx.fd;
- fd_out = pdata->memfd;
- } else {
- fd_in = pdata->memfd;
- fd_out = pdata->io_ctx.fd;
- }
-
- do {
- ret = wait_cancellable(&pdata->io_ctx, read);
- if (ret < 0)
- goto err_close_pipe;
-
- if (read_len) {
- /*
- * SPLICE_F_NONBLOCK is just here to avoid a deadlock when
- * splicing from a socket. As the socket is not in
- * non-blocking mode, it should never return -EAGAIN.
- * TODO(pcercuei): Find why it locks...
- * */
- ret = splice(fd_in, NULL, pipefd[1], NULL, read_len,
- SPLICE_F_MOVE | SPLICE_F_NONBLOCK);
- if (!ret)
- ret = -EIO;
- if (ret < 0 && errno != EAGAIN) {
- ret = -errno;
- goto err_close_pipe;
- } else if (ret > 0) {
- write_len += ret;
- read_len -= ret;
- }
- }
-
- if (write_len) {
- ret = splice(pipefd[0], NULL, fd_out, NULL, write_len,
- SPLICE_F_MOVE | SPLICE_F_NONBLOCK);
- if (!ret)
- ret = -EIO;
- if (ret < 0 && errno != EAGAIN) {
- ret = -errno;
- goto err_close_pipe;
- } else if (ret > 0) {
- write_len -= ret;
- }
- }
-
- } while (write_len || read_len);
-
-err_close_pipe:
- close(pipefd[0]);
- close(pipefd[1]);
- return ret < 0 ? ret : len;
-}
-
-static ssize_t network_get_buffer(const struct iio_device *dev,
- void **addr_ptr, size_t bytes_used,
- uint32_t *mask, size_t words)
-{
- struct iio_device_pdata *pdata = dev->pdata;
- ssize_t ret, read = 0;
- int memfd;
-
- if (pdata->is_cyclic)
- return -ENOSYS;
-
- /* We check early that the temporary file can be created, so that we can
- * return -ENOSYS in case it fails, which will indicate that the
- * high-speed interface is not available.
- *
- * O_TMPFILE -> Linux 3.11.
- * TODO: use memfd_create (Linux 3.17) */
- memfd = open(P_tmpdir, O_RDWR | O_TMPFILE | O_EXCL | O_CLOEXEC, S_IRWXU);
- if (memfd < 0)
- return -ENOSYS;
-
- if (!addr_ptr || words != (dev->nb_channels + 31) / 32) {
- close(memfd);
- return -EINVAL;
- }
-
- if (pdata->mmap_addr)
- munmap(pdata->mmap_addr, pdata->mmap_len);
-
- if (pdata->mmap_addr && pdata->is_tx) {
- char buf[1024];
-
- iio_snprintf(buf, sizeof(buf), "WRITEBUF %s %lu\r\n",
- dev->id, (unsigned long) bytes_used);
-
- iio_mutex_lock(pdata->lock);
-
- ret = write_rwbuf_command(dev, buf);
- if (ret < 0)
- goto err_close_memfd;
-
- ret = network_do_splice(pdata, bytes_used, false);
- if (ret < 0)
- goto err_close_memfd;
-
- pdata->wait_for_err_code = true;
- iio_mutex_unlock(pdata->lock);
- }
-
- if (pdata->memfd >= 0)
- close(pdata->memfd);
-
- pdata->memfd = memfd;
-
- ret = (ssize_t) ftruncate(pdata->memfd, pdata->mmap_len);
- if (ret < 0) {
- ret = -errno;
- ERROR("Unable to truncate temp file: %zi\n", -ret);
- return ret;
- }
-
- if (!pdata->is_tx) {
- char buf[1024];
- size_t len = pdata->mmap_len;
-
- iio_snprintf(buf, sizeof(buf), "READBUF %s %lu\r\n",
- dev->id, (unsigned long) len);
-
- iio_mutex_lock(pdata->lock);
- ret = write_rwbuf_command(dev, buf);
- if (ret < 0)
- goto err_unlock;
-
- do {
- ret = network_read_mask(&pdata->io_ctx, mask, words);
- if (!ret)
- break;
- if (ret < 0)
- goto err_unlock;
-
- mask = NULL; /* We read the mask only once */
-
- ret = network_do_splice(pdata, ret, true);
- if (ret < 0)
- goto err_unlock;
-
- read += ret;
- len -= ret;
- } while (len);
-
- iio_mutex_unlock(pdata->lock);
- }
-
- pdata->mmap_addr = mmap(NULL, pdata->mmap_len,
- PROT_READ | PROT_WRITE, MAP_SHARED, pdata->memfd, 0);
- if (pdata->mmap_addr == MAP_FAILED) {
- pdata->mmap_addr = NULL;
- ret = -errno;
- ERROR("Unable to mmap: %zi\n", -ret);
- return ret;
- }
-
- *addr_ptr = pdata->mmap_addr;
- return read ? read : (ssize_t) bytes_used;
-
-err_close_memfd:
- close(memfd);
-err_unlock:
- iio_mutex_unlock(pdata->lock);
- return ret;
-}
-#endif
-
-static ssize_t network_read_dev_attr(const struct iio_device *dev,
- const char *attr, char *dst, size_t len, enum iio_attr_type type)
-{
- struct iio_context_pdata *pdata = dev->ctx->pdata;
-
- return iiod_client_read_attr(pdata->iiod_client,
- &pdata->io_ctx, dev, NULL, attr, dst, len, type);
-}
-
-static ssize_t network_write_dev_attr(const struct iio_device *dev,
- const char *attr, const char *src, size_t len, enum iio_attr_type type)
-{
- struct iio_context_pdata *pdata = dev->ctx->pdata;
-
- return iiod_client_write_attr(pdata->iiod_client,
- &pdata->io_ctx, dev, NULL, attr, src, len, type);
-}
-
-static ssize_t network_read_chn_attr(const struct iio_channel *chn,
- const char *attr, char *dst, size_t len)
-{
- struct iio_context_pdata *pdata = chn->dev->ctx->pdata;
-
- return iiod_client_read_attr(pdata->iiod_client,
- &pdata->io_ctx, chn->dev, chn, attr, dst, len, false);
-}
-
-static ssize_t network_write_chn_attr(const struct iio_channel *chn,
- const char *attr, const char *src, size_t len)
-{
- struct iio_context_pdata *pdata = chn->dev->ctx->pdata;
-
- return iiod_client_write_attr(pdata->iiod_client,
- &pdata->io_ctx, chn->dev, chn, attr, src, len, false);
-}
-
-static int network_get_trigger(const struct iio_device *dev,
- const struct iio_device **trigger)
-{
- struct iio_context_pdata *pdata = dev->ctx->pdata;
-
- return iiod_client_get_trigger(pdata->iiod_client,
- &pdata->io_ctx, dev, trigger);
-}
-
-static int network_set_trigger(const struct iio_device *dev,
- const struct iio_device *trigger)
-{
- struct iio_context_pdata *pdata = dev->ctx->pdata;
-
- return iiod_client_set_trigger(pdata->iiod_client,
- &pdata->io_ctx, dev, trigger);
-}
-
-static void network_shutdown(struct iio_context *ctx)
-{
- struct iio_context_pdata *pdata = ctx->pdata;
- unsigned int i;
-
- iio_mutex_lock(pdata->lock);
- write_command(&pdata->io_ctx, "\r\nEXIT\r\n");
- close(pdata->io_ctx.fd);
- iio_mutex_unlock(pdata->lock);
-
- for (i = 0; i < ctx->nb_devices; i++) {
- struct iio_device *dev = ctx->devices[i];
- struct iio_device_pdata *dpdata = dev->pdata;
-
- if (dpdata) {
- network_close(dev);
- iio_mutex_destroy(dpdata->lock);
- free(dpdata);
- }
- }
-
- iiod_client_destroy(pdata->iiod_client);
- iio_mutex_destroy(pdata->lock);
- freeaddrinfo(pdata->addrinfo);
- free(pdata);
-}
-
-static int network_get_version(const struct iio_context *ctx,
- unsigned int *major, unsigned int *minor, char git_tag[8])
-{
- return iiod_client_get_version(ctx->pdata->iiod_client,
- &ctx->pdata->io_ctx, major, minor, git_tag);
-}
-
-static unsigned int calculate_remote_timeout(unsigned int timeout)
-{
- /* XXX(pcercuei): We currently hardcode timeout / 2 for the backend used
- * by the remote. Is there something better to do here? */
- return timeout / 2;
-}
-
-static int network_set_timeout(struct iio_context *ctx, unsigned int timeout)
-{
- struct iio_context_pdata *pdata = ctx->pdata;
- int ret, fd = pdata->io_ctx.fd;
-
- ret = set_socket_timeout(fd, timeout);
- if (!ret) {
- unsigned int remote_timeout = calculate_remote_timeout(timeout);
-
- ret = iiod_client_set_timeout(pdata->iiod_client,
- &pdata->io_ctx, remote_timeout);
- if (!ret)
- pdata->io_ctx.timeout_ms = timeout;
- }
- if (ret < 0) {
- char buf[1024];
- iio_strerror(-ret, buf, sizeof(buf));
- WARNING("Unable to set R/W timeout: %s\n", buf);
- }
- return ret;
-}
-
-static int network_set_kernel_buffers_count(const struct iio_device *dev,
- unsigned int nb_blocks)
-{
- struct iio_context_pdata *pdata = dev->ctx->pdata;
-
- return iiod_client_set_kernel_buffers_count(pdata->iiod_client,
- &pdata->io_ctx, dev, nb_blocks);
-}
-
-static struct iio_context * network_clone(const struct iio_context *ctx)
-{
- const char *addr = iio_context_get_attr_value(ctx, "ip,ip-addr");
-
- return iio_create_network_context(addr);
-}
-
-static const struct iio_backend_ops network_ops = {
- .clone = network_clone,
- .open = network_open,
- .close = network_close,
- .read = network_read,
- .write = network_write,
-#ifdef WITH_NETWORK_GET_BUFFER
- .get_buffer = network_get_buffer,
-#endif
- .read_device_attr = network_read_dev_attr,
- .write_device_attr = network_write_dev_attr,
- .read_channel_attr = network_read_chn_attr,
- .write_channel_attr = network_write_chn_attr,
- .get_trigger = network_get_trigger,
- .set_trigger = network_set_trigger,
- .shutdown = network_shutdown,
- .get_version = network_get_version,
- .set_timeout = network_set_timeout,
- .set_kernel_buffers_count = network_set_kernel_buffers_count,
-
- .cancel = network_cancel,
-};
-
-static ssize_t network_write_data(struct iio_context_pdata *pdata,
- void *io_data, const char *src, size_t len)
-{
- struct iio_network_io_context *io_ctx = io_data;
-
- return network_send(io_ctx, src, len, 0);
-}
-
-static ssize_t network_read_data(struct iio_context_pdata *pdata,
- void *io_data, char *dst, size_t len)
-{
- struct iio_network_io_context *io_ctx = io_data;
-
- return network_recv(io_ctx, dst, len, 0);
-}
-
-static ssize_t network_read_line(struct iio_context_pdata *pdata,
- void *io_data, char *dst, size_t len)
-{
- bool found = false;
- size_t i;
-#ifdef __linux__
- struct iio_network_io_context *io_ctx = io_data;
- ssize_t ret;
- size_t bytes_read = 0;
-
- do {
- size_t to_trunc;
-
- ret = network_recv(io_ctx, dst, len, MSG_PEEK);
- if (ret < 0)
- return ret;
-
- /* Lookup for the trailing \n */
- for (i = 0; i < (size_t) ret && dst[i] != '\n'; i++);
- found = i < (size_t) ret;
-
- len -= ret;
- dst += ret;
-
- if (found)
- to_trunc = i + 1;
- else
- to_trunc = (size_t) ret;
-
- /* Advance the read offset to the byte following the \n if
- * found, or after the last charater read otherwise */
- if (pdata->msg_trunc_supported)
- ret = network_recv(io_ctx, NULL, to_trunc, MSG_TRUNC);
- else
- ret = network_recv(io_ctx, dst - ret, to_trunc, 0);
- if (ret < 0)
- return ret;
-
- bytes_read += to_trunc;
- } while (!found && len);
-
- if (!found)
- return -EIO;
- else
- return bytes_read;
-#else
- for (i = 0; i < len - 1; i++) {
- ssize_t ret = network_read_data(pdata, io_data, dst + i, 1);
-
- if (ret < 0)
- return ret;
-
- if (dst[i] != '\n')
- found = true;
- else if (found)
- break;
- }
-
- if (!found || i == len - 1)
- return -EIO;
-
- return (ssize_t) i + 1;
-#endif
-}
-
-static const struct iiod_client_ops network_iiod_client_ops = {
- .write = network_write_data,
- .read = network_read_data,
- .read_line = network_read_line,
-};
-
-#ifdef __linux__
-/*
- * As of build 16299, Windows Subsystem for Linux presents a Linux API but
- * without support for MSG_TRUNC. Since WSL allows running native Linux
- * applications this is not something that can be detected at compile time. If
- * we want to support WSL we have to have a runtime workaround.
- */
-static bool msg_trunc_supported(struct iio_network_io_context *io_ctx)
-{
- int ret;
-
- ret = network_recv(io_ctx, NULL, 0, MSG_TRUNC | MSG_DONTWAIT);
-
- return ret != -EFAULT && ret != -EINVAL;
-}
-#else
-static bool msg_trunc_supported(struct iio_network_io_context *io_ctx)
-{
- return false;
-}
-#endif
-
-struct iio_context * network_create_context(const char *host)
-{
- struct addrinfo hints, *res;
- struct iio_context *ctx;
- struct iio_context_pdata *pdata;
- size_t i, len;
- int fd, ret;
- char *description;
-#ifdef _WIN32
- WSADATA wsaData;
-
- ret = WSAStartup(MAKEWORD(2, 0), &wsaData);
- if (ret < 0) {
- ERROR("WSAStartup failed with error %i\n", ret);
- errno = -ret;
- return NULL;
- }
-#endif
-
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
-
-#ifdef HAVE_AVAHI
- if (!host) {
- char addr_str[AVAHI_ADDRESS_STR_MAX];
- char port_str[6];
- AvahiAddress address;
- uint16_t port = IIOD_PORT;
-
- memset(&address, 0, sizeof(address));
-
- ret = discover_host(&address, &port);
- if (ret < 0) {
- char buf[1024];
- iio_strerror(-ret, buf, sizeof(buf));
- DEBUG("Unable to find host: %s\n", buf);
- errno = -ret;
- return NULL;
- }
-
- avahi_address_snprint(addr_str, sizeof(addr_str), &address);
- iio_snprintf(port_str, sizeof(port_str), "%hu", port);
- ret = getaddrinfo(addr_str, port_str, &hints, &res);
- } else
-#endif
- {
- ret = getaddrinfo(host, IIOD_PORT_STR, &hints, &res);
- }
-
- if (ret) {
- ERROR("Unable to find host: %s\n", gai_strerror(ret));
-#ifndef _WIN32
- if (ret != EAI_SYSTEM)
- errno = -ret;
-#endif
- return NULL;
- }
-
- fd = create_socket(res, DEFAULT_TIMEOUT_MS);
- if (fd < 0) {
- errno = -fd;
- goto err_free_addrinfo;
- }
-
- pdata = zalloc(sizeof(*pdata));
- if (!pdata) {
- errno = ENOMEM;
- goto err_close_socket;
- }
-
- pdata->io_ctx.fd = fd;
- pdata->addrinfo = res;
- pdata->io_ctx.timeout_ms = DEFAULT_TIMEOUT_MS;
-
- pdata->lock = iio_mutex_create();
- if (!pdata->lock) {
- errno = ENOMEM;
- goto err_free_pdata;
- }
-
- pdata->iiod_client = iiod_client_new(pdata, pdata->lock,
- &network_iiod_client_ops);
-
- pdata->msg_trunc_supported = msg_trunc_supported(&pdata->io_ctx);
- if (pdata->msg_trunc_supported)
- DEBUG("MSG_TRUNC is supported\n");
- else
- DEBUG("MSG_TRUNC is NOT supported\n");
-
- if (!pdata->iiod_client)
- goto err_destroy_mutex;
-
- DEBUG("Creating context...\n");
- ctx = iiod_client_create_context(pdata->iiod_client, &pdata->io_ctx);
- if (!ctx)
- goto err_destroy_iiod_client;
-
- /* Override the name and low-level functions of the XML context
- * with those corresponding to the network context */
- ctx->name = "network";
- ctx->ops = &network_ops;
- ctx->pdata = pdata;
-
-#ifdef HAVE_IPV6
- len = INET6_ADDRSTRLEN + IF_NAMESIZE + 2;
-#else
- len = INET_ADDRSTRLEN + 1;
-#endif
-
- description = malloc(len);
- if (!description) {
- ret = -ENOMEM;
- goto err_network_shutdown;
- }
-
- description[0] = '\0';
-
-#ifdef HAVE_IPV6
- if (res->ai_family == AF_INET6) {
- struct sockaddr_in6 *in = (struct sockaddr_in6 *) res->ai_addr;
- char *ptr;
- inet_ntop(AF_INET6, &in->sin6_addr,
- description, INET6_ADDRSTRLEN);
-
- ptr = if_indextoname(in->sin6_scope_id, description +
- strlen(description) + 1);
- if (!ptr) {
- ret = -errno;
- ERROR("Unable to lookup interface of IPv6 address\n");
- goto err_free_description;
- }
-
- *(ptr - 1) = '%';
- }
-#endif
- if (res->ai_family == AF_INET) {
- struct sockaddr_in *in = (struct sockaddr_in *) res->ai_addr;
-#if (!_WIN32 || _WIN32_WINNT >= 0x600)
- inet_ntop(AF_INET, &in->sin_addr, description, INET_ADDRSTRLEN);
-#else
- char *tmp = inet_ntoa(in->sin_addr);
- strncpy(description, tmp, len);
-#endif
- }
-
- ret = iio_context_add_attr(ctx, "ip,ip-addr", description);
- if (ret < 0)
- goto err_free_description;
-
- for (i = 0; i < ctx->nb_devices; i++) {
- struct iio_device *dev = ctx->devices[i];
-
- dev->pdata = zalloc(sizeof(*dev->pdata));
- if (!dev->pdata) {
- ret = -ENOMEM;
- goto err_free_description;
- }
-
- dev->pdata->io_ctx.fd = -1;
- dev->pdata->io_ctx.timeout_ms = DEFAULT_TIMEOUT_MS;
-#ifdef WITH_NETWORK_GET_BUFFER
- dev->pdata->memfd = -1;
-#endif
-
- dev->pdata->lock = iio_mutex_create();
- if (!dev->pdata->lock) {
- ret = -ENOMEM;
- goto err_free_description;
- }
- }
-
- if (ctx->description) {
- size_t desc_len = strlen(description);
- size_t new_size = desc_len + strlen(ctx->description) + 2;
- char *ptr, *new_description = realloc(description, new_size);
- if (!new_description) {
- ret = -ENOMEM;
- goto err_free_description;
- }
-
- ptr = strrchr(new_description, '\0');
- iio_snprintf(ptr, new_size - desc_len, " %s", ctx->description);
- free(ctx->description);
-
- ctx->description = new_description;
- } else {
- ctx->description = description;
- }
-
- iiod_client_set_timeout(pdata->iiod_client, &pdata->io_ctx,
- calculate_remote_timeout(DEFAULT_TIMEOUT_MS));
- return ctx;
-
-err_free_description:
- free(description);
-err_network_shutdown:
- iio_context_destroy(ctx);
- errno = -ret;
- return NULL;
-
-err_destroy_iiod_client:
- iiod_client_destroy(pdata->iiod_client);
-err_destroy_mutex:
- iio_mutex_destroy(pdata->lock);
-err_free_pdata:
- free(pdata);
-err_close_socket:
- close(fd);
-err_free_addrinfo:
- freeaddrinfo(res);
- return NULL;
-}
diff --git a/properties.rc.cmakein b/properties.rc.cmakein
deleted file mode 100644
index b9d0db5..0000000
--- a/properties.rc.cmakein
+++ /dev/null
@@ -1,24 +0,0 @@
-#include <windows.h>
-LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
-VS_VERSION_INFO VERSIONINFO
-BEGIN
- BLOCK "StringFileInfo"
- BEGIN
- BLOCK "040904E4"
- BEGIN
- VALUE "CompanyName", "Analog Devices"
- VALUE "FileDescription", "libiio - Library for interface to IIO devices"
- VALUE "InternalName", "libiio"
- VALUE "LegalCopyright", "Copyright 2015-@BUILD_YEAR@ ADI and other contributors"
- VALUE "LegalTrademarks", "http://www.gnu.org/licenses/lgpl-2.1.html"
- VALUE "ProductName", "libiio"
- VALUE "ProductVersion", "@LIBIIO_VERSION_MAJOR@.@LIBIIO_VERSION_MINOR@-g@LIBIIO_VERSION_GIT@"
- VALUE "OriginalFilename", "@LIBIIO_ORIGINAL_FILENAME@"
- END
- END
-
- BLOCK "VarFileInfo"
- BEGIN
- VALUE "Translation", 0x409, 1252
- END
-END
diff --git a/scan.c b/scan.c
deleted file mode 100644
index dc1be04..0000000
--- a/scan.c
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2016 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.
- */
-
-#include "iio-config.h"
-#include "iio-private.h"
-
-#include <errno.h>
-#include <stdbool.h>
-#include <string.h>
-
-struct iio_scan_context {
-#ifdef WITH_USB_BACKEND
- struct iio_scan_backend_context *usb_ctx;
-#endif
- bool scan_local;
-};
-
-const char * iio_context_info_get_description(
- const struct iio_context_info *info)
-{
- return info->description;
-}
-
-const char * iio_context_info_get_uri(
- const struct iio_context_info *info)
-{
- return info->uri;
-}
-
-ssize_t iio_scan_context_get_info_list(struct iio_scan_context *ctx,
- struct iio_context_info ***info)
-{
- struct iio_scan_result scan_result = { 0, NULL };
-
-#ifdef WITH_LOCAL_BACKEND
- if (ctx->scan_local) {
- int ret = local_context_scan(&scan_result);
- if (ret < 0) {
- if (scan_result.info)
- iio_context_info_list_free(scan_result.info);
- return ret;
- }
- }
-#endif
-
-#ifdef WITH_USB_BACKEND
- if (ctx->usb_ctx) {
- int ret = usb_context_scan(ctx->usb_ctx, &scan_result);
- if (ret < 0) {
- if (scan_result.info)
- iio_context_info_list_free(scan_result.info);
- return ret;
- }
- }
-#endif
-
- *info = scan_result.info;
-
- return (ssize_t) scan_result.size;
-}
-
-void iio_context_info_list_free(struct iio_context_info **list)
-{
- struct iio_context_info **it;
-
- if (!list)
- return;
-
- for (it = list; *it; it++) {
- struct iio_context_info *info = *it;
-
- if (info->description)
- free(info->description);
- if (info->uri)
- free(info->uri);
- free(info);
- }
-
- free(list);
-}
-
-struct iio_context_info ** iio_scan_result_add(
- struct iio_scan_result *scan_result, size_t num)
-{
- struct iio_context_info **info;
- size_t old_size, new_size;
- size_t i;
-
- old_size = scan_result->size;
- new_size = old_size + num;
-
- info = realloc(scan_result->info, (new_size + 1) * sizeof(*info));
- if (!info)
- return NULL;
-
- scan_result->info = info;
- scan_result->size = new_size;
-
- for (i = old_size; i < new_size; i++) {
- /* Make sure iio_context_info_list_free won't overflow */
- info[i + 1] = NULL;
-
- info[i] = zalloc(sizeof(**info));
- if (!info[i])
- return NULL;
- }
-
- return &info[old_size];
-}
-
-struct iio_scan_context * iio_create_scan_context(
- const char *backend, unsigned int flags)
-{
- struct iio_scan_context *ctx;
-
- /* "flags" must be zero for now */
- if (flags != 0) {
- errno = EINVAL;
- return NULL;
- }
-
- ctx = calloc(1, sizeof(*ctx));
- if (!ctx) {
- errno = ENOMEM;
- return NULL;
- }
-
- if (!backend || !strcmp(backend, "local"))
- ctx->scan_local = true;
-
-#ifdef WITH_USB_BACKEND
- if (!backend || !strcmp(backend, "usb"))
- ctx->usb_ctx = usb_context_scan_init();
-#endif
-
- return ctx;
-}
-
-void iio_scan_context_destroy(struct iio_scan_context *ctx)
-{
-#ifdef WITH_USB_BACKEND
- if (ctx->usb_ctx)
- usb_context_scan_free(ctx->usb_ctx);
-#endif
- free(ctx);
-}
-
-#ifdef WITH_MATLAB_BINDINGS_API
-
-struct iio_scan_block {
- struct iio_scan_context *ctx;
- struct iio_context_info **info;
- ssize_t ctx_cnt;
-};
-
-ssize_t iio_scan_block_scan(struct iio_scan_block *blk)
-{
- iio_context_info_list_free(blk->info);
- blk->info = NULL;
- blk->ctx_cnt = iio_scan_context_get_info_list(blk->ctx, &blk->info);
- return blk->ctx_cnt;
-}
-
-struct iio_context_info *iio_scan_block_get_info(
- struct iio_scan_block *blk, unsigned int index)
-{
- if (!blk->info || (ssize_t)index >= blk->ctx_cnt) {
- errno = EINVAL;
- return NULL;
- }
- return blk->info[index];
-}
-
-struct iio_scan_block *iio_create_scan_block(
- const char *backend, unsigned int flags)
-{
- struct iio_scan_block *blk;
-
- blk = calloc(1, sizeof(*blk));
- if (!blk) {
- errno = ENOMEM;
- return NULL;
- }
-
- blk->ctx = iio_create_scan_context(backend, flags);
- if (!blk->ctx) {
- free(blk);
- return NULL;
- }
-
- return blk;
-}
-
-void iio_scan_block_destroy(struct iio_scan_block *blk)
-{
- iio_context_info_list_free(blk->info);
- iio_scan_context_destroy(blk->ctx);
- free(blk);
-}
-#endif
diff --git a/serial.c b/serial.c
deleted file mode 100644
index af424a2..0000000
--- a/serial.c
+++ /dev/null
@@ -1,535 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2014-2016 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.
- *
- * */
-
-#include "debug.h"
-#include "iio-private.h"
-#include "iio-lock.h"
-#include "iiod-client.h"
-
-#include <errno.h>
-#include <libserialport.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define DEFAULT_TIMEOUT_MS 1000
-
-struct iio_context_pdata {
- struct sp_port *port;
- struct iio_mutex *lock;
- struct iiod_client *iiod_client;
-
- unsigned int timeout_ms;
-};
-
-struct iio_device_pdata {
- bool opened;
-};
-
-static inline int libserialport_to_errno(enum sp_return ret)
-{
- switch (ret) {
- case SP_ERR_ARG:
- return -EINVAL;
- case SP_ERR_FAIL:
- return -sp_last_error_code();
- case SP_ERR_MEM:
- return -ENOMEM;
- case SP_ERR_SUPP:
- return -ENOSYS;
- default:
- return (int) ret;
- }
-}
-
-static int serial_get_version(const struct iio_context *ctx,
- unsigned int *major, unsigned int *minor, char git_tag[8])
-{
- struct iio_context_pdata *pdata = ctx->pdata;
-
- return iiod_client_get_version(pdata->iiod_client, NULL,
- major, minor, git_tag);
-}
-
-static int serial_open(const struct iio_device *dev,
- size_t samples_count, bool cyclic)
-{
- const struct iio_context *ctx = iio_device_get_context(dev);
- struct iio_context_pdata *ctx_pdata = ctx->pdata;
- struct iio_device_pdata *pdata = dev->pdata;
- int ret = -EBUSY;
-
- iio_mutex_lock(ctx_pdata->lock);
- if (pdata->opened)
- goto out_unlock;
-
- ret = iiod_client_open_unlocked(ctx_pdata->iiod_client, NULL,
- dev, samples_count, cyclic);
-
- pdata->opened = !ret;
-
-out_unlock:
- iio_mutex_unlock(ctx_pdata->lock);
- return ret;
-}
-
-static int serial_close(const struct iio_device *dev)
-{
- const struct iio_context *ctx = iio_device_get_context(dev);
- struct iio_context_pdata *ctx_pdata = ctx->pdata;
- struct iio_device_pdata *pdata = dev->pdata;
- int ret = -EBADF;
-
- iio_mutex_lock(ctx_pdata->lock);
- if (!pdata->opened)
- goto out_unlock;
-
- ret = iiod_client_close_unlocked(ctx_pdata->iiod_client, NULL, dev);
- pdata->opened = false;
-
-out_unlock:
- iio_mutex_unlock(ctx_pdata->lock);
- return ret;
-}
-
-static ssize_t serial_read(const struct iio_device *dev, void *dst, size_t len,
- uint32_t *mask, size_t words)
-{
- const struct iio_context *ctx = iio_device_get_context(dev);
- struct iio_context_pdata *pdata = ctx->pdata;
- ssize_t ret;
-
- iio_mutex_lock(pdata->lock);
- ret = iiod_client_read_unlocked(pdata->iiod_client, NULL,
- dev, dst, len, mask, words);
- iio_mutex_unlock(pdata->lock);
-
- return ret;
-}
-
-static ssize_t serial_write(const struct iio_device *dev,
- const void *src, size_t len)
-{
- const struct iio_context *ctx = iio_device_get_context(dev);
- struct iio_context_pdata *pdata = ctx->pdata;
- ssize_t ret;
-
- iio_mutex_lock(pdata->lock);
- ret = iiod_client_write_unlocked(pdata->iiod_client, NULL, dev, src, len);
- iio_mutex_unlock(pdata->lock);
-
- return ret;
-}
-
-static ssize_t serial_read_dev_attr(const struct iio_device *dev,
- const char *attr, char *dst, size_t len, enum iio_attr_type type)
-{
- const struct iio_context *ctx = iio_device_get_context(dev);
- struct iio_context_pdata *pdata = ctx->pdata;
-
- return iiod_client_read_attr(pdata->iiod_client, NULL,
- dev, NULL, attr, dst, len, type);
-}
-
-static ssize_t serial_write_dev_attr(const struct iio_device *dev,
- const char *attr, const char *src, size_t len, enum iio_attr_type type)
-{
- const struct iio_context *ctx = iio_device_get_context(dev);
- struct iio_context_pdata *pdata = ctx->pdata;
-
- return iiod_client_write_attr(pdata->iiod_client, NULL,
- dev, NULL, attr, src, len, type);
-}
-
-static ssize_t serial_read_chn_attr(const struct iio_channel *chn,
- const char *attr, char *dst, size_t len)
-{
- const struct iio_device *dev = iio_channel_get_device(chn);
- const struct iio_context *ctx = iio_device_get_context(dev);
- struct iio_context_pdata *pdata = ctx->pdata;
-
- return iiod_client_read_attr(pdata->iiod_client, NULL,
- chn->dev, chn, attr, dst, len, false);
-}
-
-static ssize_t serial_write_chn_attr(const struct iio_channel *chn,
- const char *attr, const char *src, size_t len)
-{
- const struct iio_device *dev = iio_channel_get_device(chn);
- const struct iio_context *ctx = iio_device_get_context(dev);
- struct iio_context_pdata *pdata = ctx->pdata;
-
- return iiod_client_write_attr(pdata->iiod_client, NULL,
- dev, chn, attr, src, len, false);
-}
-
-static int serial_set_kernel_buffers_count(const struct iio_device *dev,
- unsigned int nb_blocks)
-{
- const struct iio_context *ctx = iio_device_get_context(dev);
- struct iio_context_pdata *pdata = ctx->pdata;
-
- return iiod_client_set_kernel_buffers_count(pdata->iiod_client, NULL,
- dev, nb_blocks);
-}
-
-static ssize_t serial_write_data(struct iio_context_pdata *pdata,
- void *io_data, const char *data, size_t len)
-{
- ssize_t ret = (ssize_t) libserialport_to_errno(sp_blocking_write(
- pdata->port, data, len, pdata->timeout_ms));
-
- DEBUG("Write returned %li: %s\n", (long) ret, data);
- return ret;
-}
-
-static ssize_t serial_read_data(struct iio_context_pdata *pdata,
- void *io_data, char *buf, size_t len)
-{
- ssize_t ret = (ssize_t) libserialport_to_errno(sp_blocking_read_next(
- pdata->port, buf, len, pdata->timeout_ms));
-
- DEBUG("Read returned %li: %.*s\n", (long) ret, (int) ret, buf);
- return ret;
-}
-
-static ssize_t serial_read_line(struct iio_context_pdata *pdata,
- void *io_data, char *buf, size_t len)
-{
- size_t i;
- bool found = false;
- int ret;
-
- DEBUG("Readline size 0x%lx\n", (unsigned long) len);
-
- for (i = 0; i < len - 1; i++) {
- ret = libserialport_to_errno(sp_blocking_read_next(
- pdata->port, &buf[i], 1,
- pdata->timeout_ms));
- if (ret < 0) {
- ERROR("sp_blocking_read_next returned %i\n", ret);
- return (ssize_t) ret;
- }
-
- DEBUG("Character: %c\n", buf[i]);
-
- if (buf[i] != '\n')
- found = true;
- else if (found)
- break;
- }
-
- /* No \n found? Just garbage data */
- if (!found || i == len - 1)
- return -EIO;
-
- return (ssize_t) i + 1;
-}
-
-static void serial_shutdown(struct iio_context *ctx)
-{
- struct iio_context_pdata *ctx_pdata = ctx->pdata;
- unsigned int i;
-
- iiod_client_destroy(ctx_pdata->iiod_client);
- iio_mutex_destroy(ctx_pdata->lock);
- sp_close(ctx_pdata->port);
- sp_free_port(ctx_pdata->port);
-
- for (i = 0; i < iio_context_get_devices_count(ctx); i++) {
- const struct iio_device *dev = iio_context_get_device(ctx, i);
- struct iio_device_pdata *pdata = dev->pdata;
-
- free(pdata);
- }
-
- free(ctx_pdata);
-}
-
-static int serial_set_timeout(struct iio_context *ctx, unsigned int timeout)
-{
- ctx->pdata->timeout_ms = timeout;
- return 0;
-}
-
-static const struct iio_backend_ops serial_ops = {
- .get_version = serial_get_version,
- .open = serial_open,
- .close = serial_close,
- .read = serial_read,
- .write = serial_write,
- .read_device_attr = serial_read_dev_attr,
- .write_device_attr = serial_write_dev_attr,
- .read_channel_attr = serial_read_chn_attr,
- .write_channel_attr = serial_write_chn_attr,
- .set_kernel_buffers_count = serial_set_kernel_buffers_count,
- .shutdown = serial_shutdown,
- .set_timeout = serial_set_timeout,
-};
-
-static const struct iiod_client_ops serial_iiod_client_ops = {
- .write = serial_write_data,
- .read = serial_read_data,
- .read_line = serial_read_line,
-};
-
-static int apply_settings(struct sp_port *port, unsigned int baud_rate,
- unsigned int bits, unsigned int stop_bits,
- enum sp_parity parity, enum sp_flowcontrol flow)
-{
- int ret;
-
- ret = libserialport_to_errno(sp_set_baudrate(port, (int) baud_rate));
- if (ret)
- return ret;
-
- ret = libserialport_to_errno(sp_set_bits(port, (int) bits));
- if (ret)
- return ret;
-
- ret = libserialport_to_errno(sp_set_stopbits(port, (int) stop_bits));
- if (ret)
- return ret;
-
- ret = libserialport_to_errno(sp_set_parity(port, parity));
- if (ret)
- return ret;
-
- return libserialport_to_errno(sp_set_flowcontrol(port, flow));
-}
-
-static struct iio_context * serial_create_context(const char *port_name,
- unsigned int baud_rate, unsigned int bits,
- enum sp_parity parity, enum sp_flowcontrol flow)
-{
- struct sp_port *port;
- struct iio_context_pdata *pdata;
- struct iio_context *ctx;
- char *name, *desc, *description;
- size_t desc_len;
- unsigned int i;
- int ret;
-
- ret = libserialport_to_errno(sp_get_port_by_name(port_name, &port));
- if (ret) {
- errno = -ret;
- return NULL;
- }
-
- ret = libserialport_to_errno(sp_open(port, SP_MODE_READ_WRITE));
- if (ret) {
- errno = -ret;
- goto err_free_port;
- }
-
- ret = apply_settings(port, baud_rate, bits, 1, parity, flow);
- if (ret) {
- errno = -ret;
- goto err_close_port;
- }
-
- /* Empty the buffers */
- sp_flush(port, SP_BUF_BOTH);
-
- name = sp_get_port_name(port);
- desc = sp_get_port_description(port);
-
- desc_len = sizeof(": \0") + strlen(name) + strlen(desc);
- description = malloc(desc_len);
- if (!description) {
- errno = ENOMEM;
- goto err_close_port;
- }
-
- iio_snprintf(description, desc_len, "%s: %s", name, desc);
-
- pdata = zalloc(sizeof(*pdata));
- if (!pdata) {
- errno = ENOMEM;
- goto err_free_description;
- }
-
- pdata->port = port;
- pdata->timeout_ms = DEFAULT_TIMEOUT_MS;
-
- pdata->lock = iio_mutex_create();
- if (!pdata->lock) {
- errno = ENOMEM;
- goto err_free_pdata;
- }
-
- pdata->iiod_client = iiod_client_new(pdata, pdata->lock,
- &serial_iiod_client_ops);
- if (!pdata->iiod_client)
- goto err_destroy_mutex;
-
- ctx = iiod_client_create_context(pdata->iiod_client, NULL);
- if (!ctx)
- goto err_destroy_iiod_client;
-
- ctx->name = "serial";
- ctx->ops = &serial_ops;
- ctx->pdata = pdata;
- ctx->description = description;
-
- for (i = 0; i < iio_context_get_devices_count(ctx); i++) {
- struct iio_device *dev = iio_context_get_device(ctx, i);
-
- dev->pdata = zalloc(sizeof(*dev->pdata));
- if (!dev->pdata) {
- ret = -ENOMEM;
- goto err_context_destroy;
- }
- }
-
- return ctx;
-
-err_context_destroy:
- iio_context_destroy(ctx);
- errno = -ret;
- return NULL;
-
-err_destroy_iiod_client:
- iiod_client_destroy(pdata->iiod_client);
-err_destroy_mutex:
- iio_mutex_destroy(pdata->lock);
-err_free_pdata:
- free(pdata);
-err_free_description:
- free(description);
-err_close_port:
- sp_close(port);
-err_free_port:
- sp_free_port(port);
- return NULL;
-}
-
-static int serial_parse_params(const char *params,
- unsigned int *baud_rate, unsigned int *bits,
- enum sp_parity *parity, enum sp_flowcontrol *flow)
-{
- char *end;
-
- *baud_rate = strtoul(params, &end, 10);
- if (params == end)
- return -EINVAL;
-
- switch (*end) {
- case '\0':
- /* Default settings */
- *bits = 8;
- *parity = SP_PARITY_NONE;
- *flow = SP_FLOWCONTROL_NONE;
- return 0;
- case 'n':
- *parity = SP_PARITY_NONE;
- break;
- case 'o':
- *parity = SP_PARITY_ODD;
- break;
- case 'e':
- *parity = SP_PARITY_EVEN;
- break;
- case 'm':
- *parity = SP_PARITY_MARK;
- break;
- case 's':
- *parity = SP_PARITY_SPACE;
- break;
- default:
- return -EINVAL;
- }
-
- params = (const char *)((uintptr_t) end + 1);
-
- if (!*params) {
- *bits = 8;
- *flow = SP_FLOWCONTROL_NONE;
- return 0;
- }
-
- *bits = strtoul(params, &end, 10);
- if (params == end)
- return -EINVAL;
-
- switch (*end) {
- case '\0':
- *flow = SP_FLOWCONTROL_NONE;
- return 0;
- case 'x':
- *flow = SP_FLOWCONTROL_XONXOFF;
- break;
- case 'r':
- *flow = SP_FLOWCONTROL_RTSCTS;
- break;
- case 'd':
- *flow = SP_FLOWCONTROL_DTRDSR;
- break;
- default:
- return -EINVAL;
- }
-
- /* We should have a '\0' after the flow character */
- if (end[1])
- return -EINVAL;
- else
- return 0;
-}
-
-struct iio_context * serial_create_context_from_uri(const char *uri)
-{
- struct iio_context *ctx = NULL;
- char *comma, *uri_dup;
- unsigned int baud_rate, bits;
- enum sp_parity parity;
- enum sp_flowcontrol flow;
- int ret;
-
- if (strncmp(uri, "serial:", sizeof("serial:") - 1) != 0)
- goto err_bad_uri;
-
- uri_dup = iio_strdup((const char *)
- ((uintptr_t) uri + sizeof("serial:") - 1));
- if (!uri_dup) {
- errno = ENOMEM;
- return NULL;
- }
-
- comma = strchr(uri_dup, ',');
- if (!comma)
- goto err_free_dup;
-
- *comma = '\0';
-
- ret = serial_parse_params((char *)((uintptr_t) comma + 1),
- &baud_rate, &bits, &parity, &flow);
- if (ret)
- goto err_free_dup;
-
- ctx = serial_create_context(uri_dup, baud_rate, bits, parity, flow);
-
- free(uri_dup);
- return ctx;
-
-err_free_dup:
- free(uri_dup);
-err_bad_uri:
- ERROR("Bad URI: \'%s\'\n", uri);
- errno = EINVAL;
- return NULL;
-}
diff --git a/sort.c b/sort.c
deleted file mode 100644
index f90123c..0000000
--- a/sort.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2018 Analog Devices, Inc.
- * Author: Robin Getz <robin.getz@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.
- *
- * */
-
-#include "iio-private.h"
-#include <string.h>
-
-/* These are a few functions to do sorting via qsort for various
- * iio structures. For more info, see the qsort(3) man page.
- *
- * The qsort comparison function must return an integer less than, equal to,
- * or greater than zero if the first argument is considered to be
- * respectively less than, equal to, or greater than the second. If two
- * members compare as equal, their order in the sort order is undefined.
- *
- * If the structures are updated, the compare functions may
- * need to be updated.
- *
- * The actual arguments to these function are "pointers to
- * pointers to char", but strcmp(3) arguments are "pointers
- * to char", hence the cast plus dereference
- */
-
-int iio_channel_compare(const void *p1, const void *p2)
-{
- const struct iio_channel *tmp1 = *(struct iio_channel **)p1;
- const struct iio_channel *tmp2 = *(struct iio_channel **)p2;
-
- /* make sure buffer enabled channels are first */
- if (iio_channel_is_scan_element(tmp1) && !iio_channel_is_scan_element(tmp2))
- return -1;
- if (!iio_channel_is_scan_element(tmp1) && iio_channel_is_scan_element(tmp2))
- return 1;
- /* and sort them by index */
- if (iio_channel_is_scan_element(tmp1) && iio_channel_is_scan_element(tmp2)){
- if (iio_channel_get_index(tmp1) > iio_channel_get_index(tmp2))
- return 1;
- return -1;
- }
- /* otherwise, if the ID is the same, input channels first */
- if (strcmp(tmp1->id, tmp2->id) == 0)
- return !iio_channel_is_output(tmp1);
-
- /* finally by ID */
- return strcmp(tmp1->id, tmp2->id);
-}
-
-int iio_channel_attr_compare(const void *p1, const void *p2)
-{
- const struct iio_channel_attr *tmp1 = (struct iio_channel_attr *)p1;
- const struct iio_channel_attr *tmp2 = (struct iio_channel_attr *)p2;
- /* qsort channel attributes by name */
- return strcmp(tmp1->name, tmp2->name);
-}
-
-int iio_device_compare(const void *p1, const void *p2)
-{
- const struct iio_device *tmp1 = *(struct iio_device **)p1;
- const struct iio_device *tmp2 = *(struct iio_device **)p2;
- /* qsort devices by ID */
- return strcmp(tmp1->id, tmp2->id);
-}
-
-int iio_device_attr_compare(const void *p1, const void *p2)
-{
- const char *tmp1 = *(const char **)p1;
- const char *tmp2 = *(const char **)p2;
- /* qsort device attributes by name */
- return strcmp(tmp1, tmp2);
-}
-
-int iio_buffer_attr_compare(const void *p1, const void *p2)
-{
- const char *tmp1 = *(const char **)p1;
- const char *tmp2 = *(const char **)p2;
- /* qsort buffer attributes by name */
- return strcmp(tmp1, tmp2);
-}
-
diff --git a/sort.h b/sort.h
deleted file mode 100644
index 9f7cf33..0000000
--- a/sort.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2018 Analog Devices, Inc.
- * Author: Robin Getz <robin.getz@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.
- *
- * */
-
-#ifndef __IIO_QSORT_H__
-#define __IIO_QSORT_H__
-
-int iio_channel_compare(const void *p1, const void *p2);
-int iio_channel_attr_compare(const void *p1, const void *p2);
-int iio_device_compare(const void *p1, const void *p2);
-int iio_device_attr_compare(const void *p1, const void *p2);
-int iio_buffer_attr_compare(const void *p1, const void *p2);
-
-#endif /* __IIO_QSORT_H__ */
diff --git a/tests/.gitignore b/tests/.gitignore
deleted file mode 100644
index 312b993..0000000
--- a/tests/.gitignore
+++ /dev/null
@@ -1,5 +0,0 @@
-iio_adi_xflow_check
-iio_genxml
-iio_info
-iio_readdev
-iio_reg
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
deleted file mode 100644
index e734e1d..0000000
--- a/tests/CMakeLists.txt
+++ /dev/null
@@ -1,60 +0,0 @@
-cmake_minimum_required(VERSION 2.8.7)
-
-project(iio_genxml C)
-project(iio_info C)
-project(iio_attr C)
-project(iio_readdev C)
-project(iio_reg C)
-
-if (MSVC)
- include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../deps/wingetopt/src)
- set(GETOPT_C_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../deps/wingetopt/src/getopt.c)
-endif (MSVC)
-
-if (WIN32)
- set(LIBIIO_ORIGINAL_FILENAME )
- set(LIBIIO_RC ${CMAKE_CURRENT_BINARY_DIR}/properties.rc)
- configure_file(../properties.rc.cmakein ${LIBIIO_RC} @ONLY)
-endif()
-add_executable(iio_genxml iio_genxml.c ${GETOPT_C_FILE} ${LIBIIO_RC})
-add_executable(iio_info iio_info.c ${GETOPT_C_FILE} ${LIBIIO_RC})
-add_executable(iio_attr iio_attr.c ${GETOPT_C_FILE} ${LIBIIO_RC})
-add_executable(iio_readdev iio_readdev.c ${GETOPT_C_FILE} ${LIBIIO_RC})
-add_executable(iio_reg iio_reg.c ${GETOPT_C_FILE} ${LIBIIO_RC})
-add_executable(iio_writedev iio_writedev.c ${GETOPT_C_FILE} ${LIBIIO_RC})
-
-target_link_libraries(iio_genxml iio)
-target_link_libraries(iio_info iio)
-target_link_libraries(iio_attr iio)
-target_link_libraries(iio_readdev iio)
-target_link_libraries(iio_reg iio)
-target_link_libraries(iio_writedev iio)
-
-set(IIO_TESTS_TARGETS iio_genxml iio_info iio_attr iio_readdev iio_reg iio_writedev)
-
-if(PTHREAD_LIBRARIES)
- project(iio_adi_xflow_check C)
- add_executable(iio_adi_xflow_check iio_adi_xflow_check.c)
- target_link_libraries(iio_adi_xflow_check iio ${PTHREAD_LIBRARIES})
- set(IIO_TESTS_TARGETS ${IIO_TESTS_TARGETS} iio_adi_xflow_check)
-
- target_link_libraries(iio_readdev ${PTHREAD_LIBRARIES})
- target_link_libraries(iio_writedev ${PTHREAD_LIBRARIES})
-endif()
-
-set_target_properties(${IIO_TESTS_TARGETS} PROPERTIES
- C_STANDARD 99
- C_STANDARD_REQUIRED ON
- C_EXTENSIONS OFF
-)
-
-if(NOT SKIP_INSTALL_ALL)
- if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
- install(TARGETS ${IIO_TESTS_TARGETS} RUNTIME DESTINATION /Library/Frameworks/iio.framework/Tools)
- else()
- install(TARGETS ${IIO_TESTS_TARGETS} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
- endif()
-endif()
-
-# Make the test targets available to the main CMakeLists.txt
-set(IIO_TESTS_TARGETS ${IIO_TESTS_TARGETS} PARENT_SCOPE)
diff --git a/tests/iio_adi_xflow_check.c b/tests/iio_adi_xflow_check.c
deleted file mode 100644
index a1d4be8..0000000
--- a/tests/iio_adi_xflow_check.c
+++ /dev/null
@@ -1,348 +0,0 @@
-/*
- * iio_adi_dac_overflow_test
- *
- * Copyright (C) 2015 Analog Devices, Inc.
- *
- * 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.
- *
- * */
-
-#include <errno.h>
-#include <getopt.h>
-#include <iio.h>
-#include <math.h>
-#include <pthread.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-struct xflow_pthread_data {
- struct iio_context *ctx;
- const char *device_name;
-};
-
-static const struct option options[] = {
- {"help", no_argument, 0, 'h'},
- {"network", required_argument, 0, 'n'},
- {"uri", required_argument, 0, 'u'},
- {"buffer-size", required_argument, 0, 's'},
- {"auto", no_argument, 0, 'a'},
- {0, 0, 0, 0},
-};
-
-static const char *options_descriptions[] = {
- "Show this help and quit.",
- "Use the network backend with the provided hostname.",
- "Use the context with the provided URI.",
- "Size of the buffer in sample sets. Default is 1Msample",
- "Scan for available contexts and if only one is available use it.",
-};
-
-static void usage(char *argv[])
-{
- unsigned int i;
-
- printf("Usage:\n\t%s [-n <hostname>] [-u <uri>] [ -a ][-s <size>] <iio_device>\n\nOptions:\n", argv[0]);
- for (i = 0; options[i].name; i++)
- printf("\t-%c, --%s\n\t\t\t%s\n",
- options[i].val, options[i].name,
- options_descriptions[i]);
-}
-
-static bool app_running = true;
-static bool device_is_tx;
-
-static void quit_all(int sig)
-{
- app_running = false;
-}
-
-static void set_handler(int signal_nb, void (*handler)(int))
-{
-#ifdef _WIN32
- signal(signal_nb, handler);
-#else
- struct sigaction sig;
- sigaction(signal_nb, NULL, &sig);
- sig.sa_handler = handler;
- sigaction(signal_nb, &sig, NULL);
-#endif
-}
-
-static struct iio_device *get_device(const struct iio_context *ctx,
- const char *id)
-{
-
- unsigned int i, nb_devices = iio_context_get_devices_count(ctx);
- struct iio_device *device;
-
- for (i = 0; i < nb_devices; i++) {
- const char *name;
- device = iio_context_get_device(ctx, i);
- name = iio_device_get_name(device);
- if (name && !strcmp(name, id))
- break;
- if (!strcmp(id, iio_device_get_id(device)))
- break;
- }
-
- if (i < nb_devices)
- return device;
-
- fprintf(stderr, "Device %s not found\n", id);
- return NULL;
-}
-
-
-static void *monitor_thread_fn(void *data)
-{
- struct xflow_pthread_data *xflow_pthread_data = data;
- struct iio_context *ctx;
- struct iio_device *dev;
- uint32_t val;
- int ret;
-
- ctx = xflow_pthread_data->ctx;
-
- dev = get_device(ctx, xflow_pthread_data->device_name);
- if (!dev) {
- fprintf(stderr, "Unable to find IIO device\n");
- return (void *)-1;
- }
-
- /* Give the main thread a moment to start the DMA */
- sleep(1);
-
- /* Clear all status bits */
- iio_device_reg_write(dev, 0x80000088, 0x6);
-
- while (app_running) {
- ret = iio_device_reg_read(dev, 0x80000088, &val);
- if (ret) {
- fprintf(stderr, "Failed to read status register: %s\n",
- strerror(-ret));
- continue;
- }
-
- if (device_is_tx) {
- if (val & 1)
- fprintf(stderr, "Underflow detected\n");
- } else {
- if (val & 4)
- fprintf(stderr, "Overflow detected\n");
- }
-
- /* Clear bits */
- if (val)
- iio_device_reg_write(dev, 0x80000088, val);
- sleep(1);
- }
-
- return (void *)0;
-}
-
-static struct iio_context *scan(void)
-{
- struct iio_scan_context *scan_ctx;
- struct iio_context_info **info;
- struct iio_context *ctx = NULL;
- unsigned int i;
- ssize_t ret;
-
- scan_ctx = iio_create_scan_context(NULL, 0);
- if (!scan_ctx) {
- fprintf(stderr, "Unable to create scan context\n");
- return NULL;
- }
-
- ret = iio_scan_context_get_info_list(scan_ctx, &info);
- if (ret < 0) {
- char err_str[1024];
- iio_strerror(-ret, err_str, sizeof(err_str));
- fprintf(stderr, "Scanning for IIO contexts failed: %s\n", err_str);
- goto err_free_ctx;
- }
-
- if (ret == 0) {
- printf("No IIO context found.\n");
- goto err_free_info_list;
- }
-
- if (ret == 1) {
- ctx = iio_create_context_from_uri(iio_context_info_get_uri(info[0]));
- } else {
- fprintf(stderr, "Multiple contexts found. Please select one using --uri:\n");
-
- for (i = 0; i < (size_t) ret; i++) {
- fprintf(stderr, "\t%d: %s [%s]\n", i,
- iio_context_info_get_description(info[i]),
- iio_context_info_get_uri(info[i]));
- }
- }
-
- err_free_info_list:
- iio_context_info_list_free(info);
- err_free_ctx:
- iio_scan_context_destroy(scan_ctx);
-
- return ctx;
-}
-
-int main(int argc, char **argv)
-{
- unsigned int buffer_size = 1024 * 1024;
- int c, option_index = 0;
- const char *arg_uri = NULL;
- const char *arg_ip = NULL;
- unsigned int n_tx = 0, n_rx = 0;
- static struct iio_context *ctx;
- static struct xflow_pthread_data xflow_pthread_data;
- bool scan_for_context = false;
- unsigned int i, nb_channels;
- struct iio_buffer *buffer;
- pthread_t monitor_thread;
- const char *device_name;
- struct iio_device *dev;
- char unit;
- int ret;
-
- while ((c = getopt_long(argc, argv, "+hn:u:s:a",
- options, &option_index)) != -1) {
- switch (c) {
- case 'h':
- usage(argv);
- return EXIT_SUCCESS;
- case 's':
- ret = sscanf(optarg, "%u%c", &buffer_size, &unit);
- if (ret == 0)
- return EXIT_FAILURE;
- if (ret == 2) {
- if (unit == 'k')
- buffer_size *= 1024;
- else if (unit == 'M')
- buffer_size *= 1024 * 1024;
- }
- break;
- case 'n':
- arg_ip = optarg;
- break;
- case 'u':
- arg_uri = optarg;
- break;
- case 'a':
- scan_for_context = true;
- break;
- case '?':
- return EXIT_FAILURE;
- }
- }
-
- if (optind + 1 != argc) {
- fprintf(stderr, "Incorrect number of arguments.\n\n");
- usage(argv);
- return EXIT_FAILURE;
- }
-
-#ifndef _WIN32
- set_handler(SIGHUP, &quit_all);
-#endif
- set_handler(SIGINT, &quit_all);
- set_handler(SIGSEGV, &quit_all);
- set_handler(SIGTERM, &quit_all);
-
-
- if (scan_for_context)
- ctx = scan();
- else if (arg_uri)
- ctx = iio_create_context_from_uri(arg_uri);
- else if (arg_ip)
- ctx = iio_create_network_context(arg_ip);
- else
- ctx = iio_create_default_context();
-
- if (!ctx) {
- fprintf(stderr, "Unable to create IIO context\n");
- return EXIT_FAILURE;
- }
-
- device_name = argv[optind];
-
- dev = get_device(ctx, device_name);
- if (!dev) {
- iio_context_destroy(ctx);
- return EXIT_FAILURE;
- }
-
- nb_channels = iio_device_get_channels_count(dev);
- for (i = 0; i < nb_channels; i++) {
- struct iio_channel *ch = iio_device_get_channel(dev, i);
- if (!iio_channel_is_scan_element(ch))
- continue;
- iio_channel_enable(ch);
- if (iio_channel_is_output(ch))
- n_tx++;
- else
- n_rx++;
- }
-
- if (n_tx >= n_rx)
- device_is_tx = true;
- else
- device_is_tx = false;
-
- printf("Monitoring %s for underflows/overflows\n",
- iio_device_get_name(dev));
-
- buffer = iio_device_create_buffer(dev, buffer_size, false);
- if (!buffer) {
- fprintf(stderr, "Unable to allocate buffer\n");
- iio_context_destroy(ctx);
- return EXIT_FAILURE;
- }
-
- xflow_pthread_data.ctx = ctx;
- xflow_pthread_data.device_name = device_name;
-
- ret = pthread_create(&monitor_thread, NULL, monitor_thread_fn,
- (void *)&xflow_pthread_data);
- if (ret) {
- fprintf(stderr, "Failed to create monitor thread: %s\n",
- strerror(-ret));
- }
-
- while (app_running) {
- if (device_is_tx) {
- ret = iio_buffer_push(buffer);
- if (ret < 0) {
- fprintf(stderr, "Unable to push buffer: %s\n",
- strerror(-ret));
- app_running = false;
- break;
- }
- } else {
- ret = iio_buffer_refill(buffer);
- if (ret < 0) {
- fprintf(stderr, "Unable to refill buffer: %s\n",
- strerror(-ret));
- app_running = false;
- break;
- }
- }
- }
-
- pthread_join(monitor_thread, NULL);
-
- iio_buffer_destroy(buffer);
- iio_context_destroy(ctx);
-
- return 0;
-}
diff --git a/tests/iio_attr.c b/tests/iio_attr.c
deleted file mode 100644
index 03dfcfd..0000000
--- a/tests/iio_attr.c
+++ /dev/null
@@ -1,754 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2014, 2017 Analog Devices, Inc.
- * Author: Paul Cercueil <paul.cercueil@analog.com>
- * Robin Getz <robin.getz@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.
- *
- * */
-
-#include <errno.h>
-#include <getopt.h>
-#include <iio.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <sys/types.h>
-
-#define MY_NAME "iio_attr"
-
-#ifdef _WIN32
-#define snprintf sprintf_s
-#else
-#define _strdup strdup
-#endif
-
-enum backend {
- LOCAL,
- XML,
- AUTO
-};
-
-static bool str_match(const char * haystack, char * needle, bool ignore)
-{
- bool ret = false;
- int i;
- char *ncpy, *hcpy, *idx, first, last;
-
- if (!haystack || !needle)
- return false;
-
- if (!strlen(haystack) || !strlen(needle))
- return false;
-
- /* '.' means match any */
- if (!strcmp(".", needle) || !strcmp("*", needle))
- return true;
-
- ncpy = _strdup(needle);
- hcpy = _strdup(haystack);
-
- if (!ncpy || !hcpy)
- goto eek;
-
- if (ignore) {
- for (i = 0; hcpy[i]; i++)
- hcpy[i] = tolower(hcpy[i]);
- for (i = 0; ncpy[i]; i++)
- ncpy[i] = tolower(ncpy[i]);
- }
-
- first = ncpy[0];
- last = ncpy[strlen(ncpy) - 1];
-
- if (first != '*' && last == '*') {
- /* 'key*' */
- ret = !strncmp(hcpy, ncpy, strlen(ncpy) - 1);
- } else if ((first == '*') && (last == '*')) {
- /* '*key*' */
- ncpy[strlen(ncpy) - 1] = 0;
- ret = strstr(hcpy, &ncpy[1]);
- } else if ((first == '*') && (last != '*')) {
- /* '*key' */
- idx = strstr(hcpy, &ncpy[1]);
- if ((idx + strlen(&ncpy[1])) == (hcpy + strlen(hcpy)))
- ret = true;
- } else {
- /* 'key' */
- ret = !strcmp(hcpy, ncpy);
- }
-
-eek:
- free(ncpy);
- free(hcpy);
-
- return ret;
-}
-
-static struct iio_context * autodetect_context(void)
-{
- struct iio_scan_context *scan_ctx;
- struct iio_context_info **info;
- struct iio_context *ctx = NULL;
- unsigned int i;
- ssize_t ret;
-
- scan_ctx = iio_create_scan_context(NULL, 0);
- if (!scan_ctx) {
- fprintf(stderr, "Unable to create scan context\n");
- return NULL;
- }
-
- ret = iio_scan_context_get_info_list(scan_ctx, &info);
- if (ret < 0) {
- char err_str[1024];
- iio_strerror(-ret, err_str, sizeof(err_str));
- fprintf(stderr, "Scanning for IIO contexts failed: %s\n", err_str);
- goto err_free_ctx;
- }
-
- if (ret == 0) {
- printf("No IIO context found.\n");
- goto err_free_info_list;
- }
- if (ret == 1) {
- printf("Using auto-detected IIO context at URI \"%s\"\n",
- iio_context_info_get_uri(info[0]));
- ctx = iio_create_context_from_uri(iio_context_info_get_uri(info[0]));
- } else {
- fprintf(stderr, "Multiple contexts found. Please select one using --uri:\n");
- for (i = 0; i < (size_t) ret; i++) {
- fprintf(stderr, "\t%d: %s [%s]\n",
- i, iio_context_info_get_description(info[i]),
- iio_context_info_get_uri(info[i]));
- }
- }
-
-err_free_info_list:
- iio_context_info_list_free(info);
-err_free_ctx:
- iio_scan_context_destroy(scan_ctx);
-
- return ctx;
-}
-
-
-static void dump_device_attributes(const struct iio_device *dev,
- const char *attr, const char *wbuf, bool quiet)
-{
- ssize_t ret;
- char buf[1024];
-
- if (!wbuf || !quiet) {
- if (!quiet)
- printf("dev '%s', attr '%s', value :",
- iio_device_get_name(dev), attr);
- ret = iio_device_attr_read(dev, attr, buf, sizeof(buf));
- if (ret > 0) {
- if (quiet)
- printf("%s\n", buf);
- else
- printf("'%s'\n", buf);
- } else {
- iio_strerror(-ret, buf, sizeof(buf));
- printf("ERROR: %s (%li)\n", buf, (long)ret);
- }
- }
- if (wbuf) {
- ret = iio_device_attr_write(dev, attr, wbuf);
- if (ret > 0) {
- if (!quiet)
- printf("wrote %li bytes to %s\n", (long)ret, attr);
- } else {
- iio_strerror(-ret, buf, sizeof(buf));
- printf("ERROR: %s (%li) while writing '%s' with '%s'\n",
- buf, (long)ret, attr, wbuf);
- }
- dump_device_attributes(dev, attr, NULL, quiet);
- }
-}
-
-static void dump_buffer_attributes(const struct iio_device *dev,
- const char *attr, const char *wbuf, bool quiet)
-{
- ssize_t ret;
- char buf[1024];
-
- if (!wbuf || !quiet) {
- ret = iio_device_buffer_attr_read(dev, attr, buf, sizeof(buf));
-
- if (!quiet)
- printf("dev '%s', buffer attr '%s', value :",
- iio_device_get_name(dev), attr);
-
- if (ret > 0) {
- if (quiet)
- printf("%s\n", buf);
- else
- printf("'%s'\n", buf);
- } else {
- iio_strerror(-ret, buf, sizeof(buf));
- printf("ERROR: %s (%li)\n", buf, (long)ret);
- }
- }
-
- if (wbuf) {
- ret = iio_device_buffer_attr_write(dev, attr, wbuf);
- if (ret > 0) {
- if (!quiet)
- printf("wrote %li bytes to %s\n", (long)ret, attr);
- } else {
- iio_strerror(-ret, buf, sizeof(buf));
- printf("ERROR: %s (%li) while writing '%s' with '%s'\n",
- buf, (long)ret, attr, wbuf);
- }
- dump_buffer_attributes(dev, attr, NULL, quiet);
- }
-}
-
-static void dump_debug_attributes(const struct iio_device *dev,
- const char *attr, const char *wbuf, bool quiet)
-{
- ssize_t ret;
- char buf[1024];
-
- if (!wbuf || !quiet) {
- ret = iio_device_debug_attr_read(dev, attr, buf, sizeof(buf));
-
- if (!quiet)
- printf("dev '%s', debug attr '%s', value :",
- iio_device_get_name(dev), attr);
-
- if (ret > 0) {
- if (quiet)
- printf("%s\n", buf);
- else
- printf("'%s'\n", buf);
- } else {
- iio_strerror(-ret, buf, sizeof(buf));
- printf("ERROR: %s (%li)\n", buf, (long)ret);
- }
- }
-
- if (wbuf) {
- ret = iio_device_debug_attr_write(dev, attr, wbuf);
- if (ret > 0) {
- if (!quiet)
- printf("wrote %li bytes to %s\n", (long)ret, attr);
- } else {
- iio_strerror(-ret, buf, sizeof(buf));
- printf("ERROR: %s (%li) while writing '%s' with '%s'\n",
- buf, (long)ret, attr, wbuf);
- }
- dump_debug_attributes(dev, attr, NULL, quiet);
- }
-}
-
-static void dump_channel_attributes(const struct iio_device *dev,
- struct iio_channel *ch, const char *attr, const char *wbuf, bool quiet)
-{
- ssize_t ret;
- char buf[1024];
- const char *type_name;
-
- if (!wbuf || !quiet) {
- if (iio_channel_is_output(ch))
- type_name = "output";
- else
- type_name = "input";
-
- ret = iio_channel_attr_read(ch, attr, buf, sizeof(buf));
- if (!quiet)
- printf("dev '%s', channel '%s' (%s), ",
- iio_device_get_name(dev),
- iio_channel_get_id(ch),
- type_name);
- if (iio_channel_get_name(ch) && !quiet)
- printf("id '%s', ", iio_channel_get_name(ch));
-
- if (!quiet)
- printf("attr '%s', ", attr);
-
- if (ret > 0) {
- if (quiet)
- printf("%s\n", buf);
- else
- printf("value '%s'\n", buf);
- } else {
- iio_strerror(-ret, buf, sizeof(buf));
- printf("ERROR: %s (%li)\n", buf, (long)ret);
- }
- }
- if (wbuf) {
- ret = iio_channel_attr_write(ch, attr, wbuf);
- if (ret > 0) {
- if (!quiet)
- printf("wrote %li bytes to %s\n", (long)ret, attr);
- } else {
- iio_strerror(-ret, buf, sizeof(buf));
- printf("error %s (%li) while writing '%s' with '%s'\n",
- buf, (long)ret, attr, wbuf);
- }
- dump_channel_attributes(dev, ch, attr, NULL, quiet);
- }
-}
-
-static const struct option options[] = {
- /* help */
- {"help", no_argument, 0, 'h'},
- {"ignore-case", no_argument, 0, 'I'},
- {"quiet", no_argument, 0, 'q'},
- /* context connection */
- {"auto", no_argument, 0, 'a'},
- {"uri", required_argument, 0, 'u'},
- /* Channel qualifiers */
- {"input-channel", no_argument, 0, 'i'},
- {"output-channel", no_argument, 0, 'o'},
- {"scan-channel", no_argument, 0, 's'},
- /* Attribute type */
- {"device-attr", no_argument, 0, 'd'},
- {"channel-attr", no_argument, 0, 'c'},
- {"context-attr", no_argument, 0, 'C'},
- {"buffer-attr", no_argument, 0, 'B'},
- {"debug-attr", no_argument, 0, 'D'},
- {0, 0, 0, 0},
-};
-
-static const char *options_descriptions[] = {
- /* help */
- "Show this help and quit.",
- "Ignore case distinctions.",
- "Return result only.",
- /* context connection */
- "Use the first context found.",
- "Use the context at the provided URI.",
- /* Channel qualifiers */
- "Filter Input Channels only.",
- "Filter Output Channels only.",
- "Filter Scan Channels only.",
- /* attribute type */
- "Read/Write device attributes",
- "Read/Write channel attributes.",
- "Read IIO context attributes.",
- "Read/Write buffer attributes.",
- "Read/Write debug attributes.",
-};
-
-static void usage(void)
-{
- unsigned int i, j = 0, k;
-
- printf("Usage:\n\t" MY_NAME " [OPTION]...\t-d [device] [attr] [value]\n"
- "\t\t\t\t-c [device] [channel] [attr] [value]\n"
- "\t\t\t\t-B [device] [attr] [value]\n"
- "\t\t\t\t-D [device] [attr] [value]\n"
- "\t\t\t\t-C [attr]\nOptions:\n");
- for (i = 0; options[i].name; i++) {
- k = strlen(options[i].name);
- if (k > j)
- j = k;
- }
- j++;
- for (i = 0; options[i].name; i++) {
- printf("\t-%c, --%s%*c: %s\n",
- options[i].val, options[i].name,
- j - (int)strlen(options[i].name), ' ',
- options_descriptions[i]);
- if (i == 3)
- printf("Optional qualifiers:\n");
- if (i == 6)
- printf("Attribute types:\n");
- }
-}
-
-int main(int argc, char **argv)
-{
- struct iio_context *ctx;
- int c, option_index = 0;
- int device_index = 0, channel_index = 0, attr_index = 0;
- const char *arg_uri = NULL;
- enum backend backend = LOCAL;
- bool detect_context = false, search_device = false, ignore_case = false,
- search_channel = false, search_buffer = false, search_debug = false,
- search_context = false, input_only = false, output_only = false,
- scan_only = false, quiet = false;
- unsigned int i;
- char *wbuf = NULL;
-
- while ((c = getopt_long(argc, argv, "+hau:CdcBDiosIq",
- options, &option_index)) != -1) {
- switch (c) {
- /* help */
- case 'h':
- usage();
- return EXIT_SUCCESS;
- /* context connection */
- case 'a':
- detect_context = true;
- break;
- case 'u':
- backend = AUTO;
- arg_uri = optarg;
- break;
- /* Attribute type
- * 'd'evice, 'c'hannel, 'C'ontext, 'B'uffer or 'D'ebug
- */
- case 'd':
- search_device = true;
- break;
- case 'c':
- search_channel = true;
- break;
- case 'B':
- search_buffer = true;
- break;
- case 'D':
- search_debug = true;
- break;
- case 'C':
- search_context = true;
- break;
- /* Channel qualifiers */
- case 'i':
- input_only = true;
- break;
- case 'o':
- output_only = true;
- break;
- case 's':
- scan_only = true;
- break;
- /* options */
- case 'I':
- ignore_case = true;
- break;
- case 'q':
- quiet = true;
- break;
- case '?':
- printf("Unknown argument '%c'\n", c);
- return EXIT_FAILURE;
- }
- }
-
- if ((search_device + search_channel + search_context + search_debug + search_buffer) >= 2 ) {
- fprintf(stderr, "The options -d, -c, -C, -B, and -D are exclusive"
- " (can use only one).\n");
- return EXIT_FAILURE;
- }
-
- if (!(search_device + search_channel + search_context + search_debug + search_buffer)) {
- if (argc == 1) {
- usage();
- return EXIT_SUCCESS;
- }
- fprintf(stderr, "must specify one of -d, -c, -C, -B or -D.\n");
- return EXIT_FAILURE;
- }
-
- if (search_context) {
- /* -C [IIO_attribute] */
- if (argc >= optind + 1)
- attr_index = optind;
- if (argc >= optind + 2) {
- fprintf(stderr, "Too many options for searching for context attributes\n");
- return EXIT_FAILURE;
- }
- } else if (search_device) {
- /* -d [device] [attr] [value] */
- if (argc >= optind + 1)
- device_index = optind;
- if (argc >= optind + 2)
- attr_index = optind + 1;
- if (argc >= optind + 3)
- wbuf = argv[optind + 2];
- if (argc >= optind + 4) {
- fprintf(stderr, "Too many options for searching for device attributes\n");
- return EXIT_FAILURE;
- }
- } else if (search_channel) {
- /* -c [device] [channel] [attr] [value] */
- if (argc >= optind + 1)
- device_index = optind;
- if (argc >= optind + 2)
- channel_index = optind + 1;
- if (argc >= optind + 3)
- attr_index = optind + 2;
- if (argc >= optind + 4)
- wbuf = argv[optind + 3];
- if (argc >= optind + 5) {
- fprintf(stderr, "Too many options for searching for channel attributes\n");
- return EXIT_FAILURE;
- }
- } else if (search_buffer) {
- /* -B [device] [attribute] [value] */
- if (argc >= optind + 1)
- device_index = optind;
- if (argc >= optind + 2)
- attr_index = optind + 1;
- if (argc >= optind + 3)
- wbuf = argv[optind + 2];
- if (argc >= optind + 4) {
- fprintf(stderr, "Too many options for searching for buffer attributes\n");
- return EXIT_FAILURE;
- }
- } else if (search_debug) {
- /* -D [device] [attribute] [value] */
- if (argc >= optind + 1)
- device_index = optind;
- if (argc >= optind + 2)
- attr_index = optind + 1;
- if (argc >= optind + 3)
- wbuf = argv[optind + 2];
- if (argc >= optind + 4) {
- fprintf(stderr, "Too many options for searching for device attributes\n");
- return EXIT_FAILURE;
- }
- } else {
- fprintf(stderr, "error in application\n");
- return EXIT_FAILURE;
- }
-
- if (device_index && !argv[device_index])
- return EXIT_FAILURE;
- if (channel_index && !argv[channel_index])
- return EXIT_FAILURE;
- if (attr_index && !argv[attr_index])
- return EXIT_FAILURE;
- if (wbuf && !wbuf)
- return EXIT_FAILURE;
- if (wbuf && ((device_index && (!strcmp(".", argv[device_index]) ||
- strchr(argv[device_index], '*'))) ||
- (channel_index && (!strcmp(".", argv[channel_index]) ||
- strchr(argv[channel_index], '*'))) ||
- (attr_index && (!strcmp(".", argv[attr_index]) ||
- strchr(argv[attr_index], '*'))))) {
- printf("can't write value with wildcard match\n");
- return EXIT_FAILURE;
- }
-
- if (detect_context)
- ctx = autodetect_context();
- else if (backend == AUTO)
- ctx = iio_create_context_from_uri(arg_uri);
- else
- ctx = iio_create_default_context();
-
- if (!ctx) {
- if (!detect_context) {
- char buf[1024];
-
- iio_strerror(errno, buf, sizeof(buf));
- fprintf(stderr, "Unable to create IIO context: %s\n",
- buf);
- }
-
- return EXIT_FAILURE;
- }
-
- if (search_context) {
- unsigned int nb_ctx_attrs = iio_context_get_attrs_count(ctx);
- if (!attr_index && nb_ctx_attrs > 0)
- printf("IIO context with %u attributes:\n", nb_ctx_attrs);
-
- for (i = 0; i < nb_ctx_attrs; i++) {
- const char *key, *value;
-
- iio_context_get_attr(ctx, i, &key, &value);
- if (!attr_index || str_match(key, argv[attr_index], ignore_case)) {
- printf("%s: %s\n", key, value);
- }
- }
- }
-
- if (search_device || search_channel || search_buffer || search_debug) {
- unsigned int nb_devices = iio_context_get_devices_count(ctx);
-
- if (!device_index)
- printf("IIO context has %u devices:\n", nb_devices);
-
- for (i = 0; i < nb_devices; i++) {
- const struct iio_device *dev = iio_context_get_device(ctx, i);
- const char *name = iio_device_get_name(dev);
- unsigned int nb_attrs, nb_channels, j;
-
-
- if (device_index && !str_match(name, argv[device_index], ignore_case))
- continue;
-
- if ((search_device && !device_index) || (search_channel && !device_index) ||
- (search_buffer && !device_index) || (search_debug && !device_index)) {
- printf("\t%s:", iio_device_get_id(dev));
- if (name)
- printf(" %s", name);
- printf(", ");
- }
-
- if (search_channel && !device_index)
- printf("found %u channels\n", iio_device_get_channels_count(dev));
-
- nb_channels = iio_device_get_channels_count(dev);
- for (j = 0; j < nb_channels; j++) {
- struct iio_channel *ch;
- const char *type_name;
- unsigned int k, nb_attrs;
-
- if (!search_channel || !device_index)
- continue;
-
- ch = iio_device_get_channel(dev, j);
-
- if (input_only && iio_channel_is_output(ch))
- continue;
- if (output_only && !iio_channel_is_output(ch))
- continue;
- if (scan_only && !iio_channel_is_scan_element(ch))
- continue;
-
- if (iio_channel_is_output(ch))
- type_name = "output";
- else
- type_name = "input";
-
- name = iio_channel_get_name(ch);
- if (channel_index &&
- !str_match(iio_channel_get_id(ch),
- argv[channel_index], ignore_case) &&
- (!name || (name &&
- !str_match( name,argv[channel_index], ignore_case))))
- continue;
-
- if ((!scan_only && !channel_index) ||
- ( scan_only && iio_channel_is_scan_element(ch))) {
- printf("dev '%s', channel '%s'",
- iio_device_get_name(dev),
- iio_channel_get_id(ch));
-
- if (name)
- printf(", id '%s'", name);
-
- printf(" (%s", type_name);
-
- if (iio_channel_is_scan_element(ch)) {
- const struct iio_data_format *format =
- iio_channel_get_data_format(ch);
- char sign = format->is_signed ? 's' : 'u';
- char repeat[12] = "";
-
- if (format->is_fully_defined)
- sign += 'A' - 'a';
-
- if (format->repeat > 1)
- snprintf(repeat, sizeof(repeat), "X%u",
- format->repeat);
- printf(", index: %lu, format: %ce:%c%u/%u%s>>%u)",
- iio_channel_get_index(ch),
- format->is_be ? 'b' : 'l',
- sign, format->bits,
- format->length, repeat,
- format->shift);
- if (scan_only)
- printf("\n");
- else
- printf(", ");
- } else {
- printf("), ");
- }
-
- }
-
- nb_attrs = iio_channel_get_attrs_count(ch);
- if (!channel_index)
- printf("found %u channel-specific attributes\n",
- nb_attrs);
-
- if (!nb_attrs || !channel_index)
- continue;
-
- for (k = 0; k < nb_attrs; k++) {
- const char *attr =
- iio_channel_get_attr(ch, k);
-
- if (attr_index &&
- !str_match(attr, argv[attr_index],
- ignore_case))
- continue;
-
- dump_channel_attributes(dev, ch, attr, wbuf,
- attr_index ? quiet : false);
- }
- }
-
- nb_attrs = iio_device_get_attrs_count(dev);
- if (search_device && !device_index)
- printf("found %u device attributes\n", nb_attrs);
-
- if (search_device && device_index && nb_attrs) {
- unsigned int j;
- for (j = 0; j < nb_attrs; j++) {
- const char *attr = iio_device_get_attr(dev, j);
-
- if (attr_index &&
- !str_match(attr, argv[attr_index], ignore_case))
- continue;
-
- dump_device_attributes(dev, attr, wbuf,
- attr_index ? quiet : false);
- }
- }
-
- nb_attrs = iio_device_get_buffer_attrs_count(dev);
-
- if (search_buffer && !device_index)
- printf("found %u buffer attributes\n", nb_attrs);
-
- if (search_buffer && device_index && nb_attrs) {
- unsigned int j;
-
- for (j = 0; j < nb_attrs; j++) {
- const char *attr = iio_device_get_buffer_attr(dev, j);
-
- if ((attr_index && str_match(attr, argv[attr_index],
- ignore_case)) || !attr_index)
- dump_buffer_attributes(dev, attr, wbuf,
- attr_index ? quiet : false);
- }
-
- }
-
- nb_attrs = iio_device_get_debug_attrs_count(dev);
-
- if (search_debug && !device_index)
- printf("found %u debug attributes\n", nb_attrs);
-
- if (search_debug && device_index && nb_attrs) {
- unsigned int j;
-
- for (j = 0; j < nb_attrs; j++) {
- const char *attr = iio_device_get_debug_attr(dev, j);
-
- if ((attr_index && str_match(attr, argv[attr_index],
- ignore_case)) || !attr_index)
- dump_debug_attributes(dev, attr, wbuf,
- attr_index ? quiet : false);
- }
-
- }
- }
-
- }
-
- iio_context_destroy(ctx);
- return EXIT_SUCCESS;
-}
diff --git a/tests/iio_genxml.c b/tests/iio_genxml.c
deleted file mode 100644
index 4a83c8c..0000000
--- a/tests/iio_genxml.c
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * 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.
- *
- * */
-
-#include <getopt.h>
-#include <iio.h>
-#include <stdio.h>
-#include <string.h>
-
-#ifndef _WIN32
-#define _strdup strdup
-#endif
-
-#define MY_NAME "iio_genxml"
-
-enum backend {
- LOCAL,
- XML,
- NETWORK,
- AUTO,
-};
-
-static const struct option options[] = {
- {"help", no_argument, 0, 'h'},
- {"xml", required_argument, 0, 'x'},
- {"network", required_argument, 0, 'n'},
- {"uri", required_argument, 0, 'u'},
- {0, 0, 0, 0},
-};
-
-static const char *options_descriptions[] = {
- "Show this help and quit.",
- "Use the XML backend with the provided XML file.",
- "Use the network backend with the provided hostname.",
- "Use the context with the provided URI.",
-};
-
-static void usage(void)
-{
- unsigned int i;
-
- printf("Usage:\n\t" MY_NAME " [-x <xml_file>]\n\t"
- MY_NAME " [-u <uri>]\n\t"
- MY_NAME " [-n <hostname>]\n\nOptions:\n");
- for (i = 0; options[i].name; i++)
- printf("\t-%c, --%s\n\t\t\t%s\n",
- options[i].val, options[i].name,
- options_descriptions[i]);
-}
-
-int main(int argc, char **argv)
-{
- char *xml;
- struct iio_context *ctx;
- int c, option_index = 0;
- const char *arg_uri = NULL;
- const char *arg_xml = NULL;
- const char *arg_ip = NULL;
- enum backend backend = LOCAL;
-
- while ((c = getopt_long(argc, argv, "+hn:x:u:",
- options, &option_index)) != -1) {
- switch (c) {
- case 'h':
- usage();
- return EXIT_SUCCESS;
- case 'n':
- if (backend != LOCAL) {
- fprintf(stderr, "-x and -n are mutually exclusive\n");
- return EXIT_FAILURE;
- }
- backend = NETWORK;
- arg_ip = optarg;
- break;
- case 'x':
- if (backend != LOCAL) {
- fprintf(stderr, "-x and -n are mutually exclusive\n");
- return EXIT_FAILURE;
- }
- backend = XML;
- arg_xml = optarg;
- break;
- case 'u':
- arg_uri = optarg;
- backend = AUTO;
- break;
- case '?':
- return EXIT_FAILURE;
- }
- }
-
- if (optind != argc) {
- fprintf(stderr, "Incorrect number of arguments.\n\n");
- usage();
- return EXIT_FAILURE;
- }
-
- if (backend == AUTO)
- ctx = iio_create_context_from_uri(arg_uri);
- else if (backend == XML)
- ctx = iio_create_xml_context(arg_xml);
- else if (backend == NETWORK)
- ctx = iio_create_network_context(arg_ip);
- else
- ctx = iio_create_default_context();
-
- if (!ctx) {
- fprintf(stderr, "Unable to create IIO context\n");
- return EXIT_FAILURE;
- }
-
- xml = _strdup(iio_context_get_xml(ctx));
- if (!xml) {
- iio_context_destroy(ctx);
- return EXIT_FAILURE;
- }
-
- printf("XML generated:\n\n%s\n\n", xml);
-
- iio_context_destroy(ctx);
-
- ctx = iio_create_xml_context_mem(xml, strlen(xml));
- if (!ctx) {
- fprintf(stderr, "Unable to re-generate context\n");
- } else {
- printf("Context re-creation from generated XML succeeded!\n");
- iio_context_destroy(ctx);
- }
- free(xml);
- return EXIT_SUCCESS;
-}
diff --git a/tests/iio_info.c b/tests/iio_info.c
deleted file mode 100644
index a7ef57f..0000000
--- a/tests/iio_info.c
+++ /dev/null
@@ -1,452 +0,0 @@
-/*
- * 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.
- *
- * */
-
-#include <errno.h>
-#include <getopt.h>
-#include <iio.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define MY_NAME "iio_info"
-
-#ifdef _WIN32
-#define snprintf sprintf_s
-#endif
-
-enum backend {
- LOCAL,
- XML,
- NETWORK,
- AUTO,
-};
-
-static const struct option options[] = {
- {"help", no_argument, 0, 'h'},
- {"xml", required_argument, 0, 'x'},
- {"network", required_argument, 0, 'n'},
- {"uri", required_argument, 0, 'u'},
- {"scan", no_argument, 0, 's'},
- {"auto", no_argument, 0, 'a'},
- {0, 0, 0, 0},
-};
-
-static const char *options_descriptions[] = {
- "Show this help and quit.",
- "Use the XML backend with the provided XML file.",
- "Use the network backend with the provided hostname.",
- "Use the context at the provided URI.",
- "Scan for available backends.",
- "Scan for available contexts and if only one is available use it.",
-};
-
-static void usage(void)
-{
- unsigned int i;
-
- printf("Usage:\n\t" MY_NAME " [-x <xml_file>]\n\t"
- MY_NAME " [-n <hostname>]\n\t"
- MY_NAME " [-u <uri>]\n\nOptions:\n");
- for (i = 0; options[i].name; i++)
- printf("\t-%c, --%s\n\t\t\t%s\n",
- options[i].val, options[i].name,
- options_descriptions[i]);
-}
-
-static void scan(void)
-{
- struct iio_scan_context *ctx;
- struct iio_context_info **info;
- unsigned int i;
- ssize_t ret;
-
- ctx = iio_create_scan_context(NULL, 0);
- if (!ctx) {
- fprintf(stderr, "Unable to create scan context\n");
- return;
- }
-
- ret = iio_scan_context_get_info_list(ctx, &info);
- if (ret < 0) {
- fprintf(stderr, "Unable to scan: %li\n", (long) ret);
- goto err_free_ctx;
- }
-
- if (ret == 0) {
- printf("No contexts found.\n");
- goto err_free_info_list;
- }
-
- printf("Available contexts:\n");
-
- for (i = 0; i < (size_t) ret; i++) {
- printf("\t%d: %s [%s]\n", i,
- iio_context_info_get_description(info[i]),
- iio_context_info_get_uri(info[i]));
- }
-
-err_free_info_list:
- iio_context_info_list_free(info);
-err_free_ctx:
- iio_scan_context_destroy(ctx);
-}
-
-static struct iio_context * autodetect_context(void)
-{
- struct iio_scan_context *scan_ctx;
- struct iio_context_info **info;
- struct iio_context *ctx = NULL;
- unsigned int i;
- ssize_t ret;
-
- scan_ctx = iio_create_scan_context(NULL, 0);
- if (!scan_ctx) {
- fprintf(stderr, "Unable to create scan context\n");
- return NULL;
- }
-
- ret = iio_scan_context_get_info_list(scan_ctx, &info);
- if (ret < 0) {
- char err_str[1024];
- iio_strerror(-ret, err_str, sizeof(err_str));
- fprintf(stderr, "Scanning for IIO contexts failed: %s\n", err_str);
- goto err_free_ctx;
- }
-
- if (ret == 0) {
- printf("No IIO context found.\n");
- goto err_free_info_list;
- }
-
- if (ret == 1) {
- printf("Using auto-detected IIO context at URI \"%s\"\n",
- iio_context_info_get_uri(info[0]));
- ctx = iio_create_context_from_uri(iio_context_info_get_uri(info[0]));
- } else {
- fprintf(stderr, "Multiple contexts found. Please select one using --uri:\n");
-
- for (i = 0; i < (size_t) ret; i++) {
- fprintf(stderr, "\t%d: %s [%s]\n", i,
- iio_context_info_get_description(info[i]),
- iio_context_info_get_uri(info[i]));
- }
- }
-
-err_free_info_list:
- iio_context_info_list_free(info);
-err_free_ctx:
- iio_scan_context_destroy(scan_ctx);
-
- return ctx;
-}
-
-static int dev_is_buffer_capable(const struct iio_device *dev)
-{
- unsigned int i;
-
- for (i = 0; i < iio_device_get_channels_count(dev); i++) {
- struct iio_channel *chn = iio_device_get_channel(dev, i);
-
- if (iio_channel_is_scan_element(chn))
- return true;
- }
-
- return false;
-}
-
-int main(int argc, char **argv)
-{
- struct iio_context *ctx;
- int c, option_index = 0;
- const char *arg_uri = NULL;
- const char *arg_ip = NULL;
- const char *arg_xml = NULL;
- enum backend backend = LOCAL;
- bool do_scan = false, detect_context = false;
- unsigned int i, major, minor;
- char git_tag[8];
- int ret;
-
- while ((c = getopt_long(argc, argv, "+hn:x:u:sa",
- options, &option_index)) != -1) {
- switch (c) {
- case 'h':
- usage();
- return EXIT_SUCCESS;
- case 'n':
- if (backend != LOCAL) {
- fprintf(stderr, "-x, -n and -u are mutually exclusive\n");
- return EXIT_FAILURE;
- }
- backend = NETWORK;
- arg_ip = optarg;
- break;
- case 'x':
- if (backend != LOCAL) {
- fprintf(stderr, "-x, -n and -u are mutually exclusive\n");
- return EXIT_FAILURE;
- }
- backend = XML;
- arg_xml = optarg;
- break;
- case 's':
- do_scan = true;
- break;
- case 'u':
- if (backend != LOCAL) {
- fprintf(stderr, "-x, -n and -u are mutually exclusive\n");
- return EXIT_FAILURE;
- }
- backend = AUTO;
- arg_uri = optarg;
- break;
- case 'a':
- detect_context = true;
- break;
- case '?':
- return EXIT_FAILURE;
- }
- }
-
- if (optind != argc) {
- fprintf(stderr, "Incorrect number of arguments.\n\n");
- usage();
- return EXIT_FAILURE;
- }
-
- iio_library_get_version(&major, &minor, git_tag);
- printf("Library version: %u.%u (git tag: %s)\n", major, minor, git_tag);
-
- printf("Compiled with backends:");
- for (i = 0; i < iio_get_backends_count(); i++)
- printf(" %s", iio_get_backend(i));
- printf("\n");
-
- if (do_scan) {
- scan();
- return EXIT_SUCCESS;
- }
-
- if (detect_context)
- ctx = autodetect_context();
- else if (backend == XML)
- ctx = iio_create_xml_context(arg_xml);
- else if (backend == NETWORK)
- ctx = iio_create_network_context(arg_ip);
- else if (backend == AUTO)
- ctx = iio_create_context_from_uri(arg_uri);
- else
- ctx = iio_create_default_context();
-
- if (!ctx) {
- if (!detect_context) {
- char buf[1024];
-
- iio_strerror(errno, buf, sizeof(buf));
- fprintf(stderr, "Unable to create IIO context: %s\n",
- buf);
- }
-
- return EXIT_FAILURE;
- }
-
- printf("IIO context created with %s backend.\n",
- iio_context_get_name(ctx));
-
- ret = iio_context_get_version(ctx, &major, &minor, git_tag);
- if (!ret)
- printf("Backend version: %u.%u (git tag: %s)\n",
- major, minor, git_tag);
- else
- fprintf(stderr, "Unable to get backend version: %i\n", ret);
-
- printf("Backend description string: %s\n",
- iio_context_get_description(ctx));
-
- unsigned int nb_ctx_attrs = iio_context_get_attrs_count(ctx);
- if (nb_ctx_attrs > 0)
- printf("IIO context has %u attributes:\n", nb_ctx_attrs);
-
- for (i = 0; i < nb_ctx_attrs; i++) {
- const char *key, *value;
-
- iio_context_get_attr(ctx, i, &key, &value);
- printf("\t%s: %s\n", key, value);
- }
-
- unsigned int nb_devices = iio_context_get_devices_count(ctx);
- printf("IIO context has %u devices:\n", nb_devices);
-
- for (i = 0; i < nb_devices; i++) {
- const struct iio_device *dev = iio_context_get_device(ctx, i);
- const char *name = iio_device_get_name(dev);
- printf("\t%s:", iio_device_get_id(dev));
- if (name)
- printf(" %s", name);
- if (dev_is_buffer_capable(dev))
- printf(" (buffer capable)");
- printf("\n");
-
- unsigned int nb_channels = iio_device_get_channels_count(dev);
- printf("\t\t%u channels found:\n", nb_channels);
-
- unsigned int j;
- for (j = 0; j < nb_channels; j++) {
- struct iio_channel *ch = iio_device_get_channel(dev, j);
- const char *type_name;
-
- if (iio_channel_is_output(ch))
- type_name = "output";
- else
- type_name = "input";
-
- name = iio_channel_get_name(ch);
- printf("\t\t\t%s: %s (%s",
- iio_channel_get_id(ch),
- name ? name : "", type_name);
-
- if (iio_channel_is_scan_element(ch)) {
- const struct iio_data_format *format =
- iio_channel_get_data_format(ch);
- char sign = format->is_signed ? 's' : 'u';
- char repeat[12] = "";
-
- if (format->is_fully_defined)
- sign += 'A' - 'a';
-
- if (format->repeat > 1)
- snprintf(repeat, sizeof(repeat), "X%u",
- format->repeat);
-
- printf(", index: %lu, format: %ce:%c%u/%u%s>>%u)\n",
- iio_channel_get_index(ch),
- format->is_be ? 'b' : 'l',
- sign, format->bits,
- format->length, repeat,
- format->shift);
- } else {
- printf(")\n");
- }
-
- unsigned int nb_attrs = iio_channel_get_attrs_count(ch);
- if (!nb_attrs)
- continue;
-
- printf("\t\t\t%u channel-specific attributes found:\n",
- nb_attrs);
-
- unsigned int k;
- for (k = 0; k < nb_attrs; k++) {
- const char *attr = iio_channel_get_attr(ch, k);
- char buf[1024];
- ret = (int) iio_channel_attr_read(ch,
- attr, buf, sizeof(buf));
-
- printf("\t\t\t\tattr %2u: %s ", k, attr);
-
- if (ret > 0) {
- printf("value: %s\n", buf);
- } else {
- iio_strerror(-ret, buf, sizeof(buf));
- printf("ERROR: %s (%i)\n", buf, ret);
- }
- }
- }
-
- unsigned int nb_attrs = iio_device_get_attrs_count(dev);
- if (nb_attrs) {
- printf("\t\t%u device-specific attributes found:\n",
- nb_attrs);
- for (j = 0; j < nb_attrs; j++) {
- const char *attr = iio_device_get_attr(dev, j);
- char buf[1024];
- ret = (int) iio_device_attr_read(dev,
- attr, buf, sizeof(buf));
-
- printf("\t\t\t\tattr %2u: %s ",
- j, attr);
-
- if (ret > 0) {
- printf("value: %s\n", buf);
- } else {
- iio_strerror(-ret, buf, sizeof(buf));
- printf("ERROR: %s (%i)\n", buf, ret);
- }
- }
- }
-
- nb_attrs = iio_device_get_buffer_attrs_count(dev);
- if (nb_attrs) {
- printf("\t\t%u buffer-specific attributes found:\n",
- nb_attrs);
- for (j = 0; j < nb_attrs; j++) {
- const char *attr = iio_device_get_buffer_attr(dev, j);
- char buf[1024];
- ret = (int) iio_device_buffer_attr_read(dev,
- attr, buf, sizeof(buf));
-
- printf("\t\t\t\tattr %2u: %s ",
- j, attr);
-
- if (ret > 0) {
- printf("value: %s\n", buf);
- } else {
- iio_strerror(-ret, buf, sizeof(buf));
- printf("ERROR: %s (%i)\n", buf, ret);
- }
- }
- }
-
- nb_attrs = iio_device_get_debug_attrs_count(dev);
- if (nb_attrs) {
- printf("\t\t%u debug attributes found:\n", nb_attrs);
- for (j = 0; j < nb_attrs; j++) {
- const char *attr =
- iio_device_get_debug_attr(dev, j);
- char buf[1024];
-
- ret = (int) iio_device_debug_attr_read(dev,
- attr, buf, sizeof(buf));
- printf("\t\t\t\tdebug attr %2u: %s ",
- j, attr);
- if (ret > 0) {
- printf("value: %s\n", buf);
- } else {
- iio_strerror(-ret, buf, sizeof(buf));
- printf("ERROR: %s (%i)\n", buf, ret);
- }
- }
- }
-
- const struct iio_device *trig;
- ret = iio_device_get_trigger(dev, &trig);
- if (ret == 0) {
- if (trig == NULL) {
- printf("\t\tNo trigger assigned to device\n");
- } else {
- name = iio_device_get_name(trig);
- printf("\t\tCurrent trigger: %s(%s)\n",
- iio_device_get_id(trig),
- name ? name : "");
- }
- }
- }
-
- iio_context_destroy(ctx);
- return EXIT_SUCCESS;
-}
diff --git a/tests/iio_readdev.c b/tests/iio_readdev.c
deleted file mode 100644
index 8305621..0000000
--- a/tests/iio_readdev.c
+++ /dev/null
@@ -1,425 +0,0 @@
-/*
- * 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.
- *
- * */
-
-#include <errno.h>
-#include <getopt.h>
-#include <iio.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-
-#define MY_NAME "iio_readdev"
-
-#define SAMPLES_PER_READ 256
-#define DEFAULT_FREQ_HZ 100
-
-static const struct option options[] = {
- {"help", no_argument, 0, 'h'},
- {"network", required_argument, 0, 'n'},
- {"uri", required_argument, 0, 'u'},
- {"trigger", required_argument, 0, 't'},
- {"buffer-size", required_argument, 0, 'b'},
- {"samples", required_argument, 0, 's' },
- {"timeout", required_argument, 0, 'T'},
- {"auto", no_argument, 0, 'a'},
- {0, 0, 0, 0},
-};
-
-static const char *options_descriptions[] = {
- "Show this help and quit.",
- "Use the network backend with the provided hostname.",
- "Use the context with the provided URI.",
- "Use the specified trigger.",
- "Size of the capture buffer. Default is 256.",
- "Number of samples to capture, 0 = infinite. Default is 0.",
- "Buffer timeout in milliseconds. 0 = no timeout",
- "Scan for available contexts and if only one is available use it.",
-};
-
-static void usage(void)
-{
- unsigned int i;
-
- printf("Usage:\n\t" MY_NAME " [-n <hostname>] [-t <trigger>] "
- "[-T <timeout-ms>] [-b <buffer-size>] [-s <samples>] "
- "<iio_device> [<channel> ...]\n\nOptions:\n");
- for (i = 0; options[i].name; i++)
- printf("\t-%c, --%s\n\t\t\t%s\n",
- options[i].val, options[i].name,
- options_descriptions[i]);
-}
-
-static struct iio_context *ctx;
-static struct iio_buffer *buffer;
-static const char *trigger_name = NULL;
-static size_t num_samples;
-
-static volatile sig_atomic_t app_running = true;
-static int exit_code = EXIT_SUCCESS;
-
-static void quit_all(int sig)
-{
- exit_code = sig;
- app_running = false;
- if (buffer)
- iio_buffer_cancel(buffer);
-}
-
-#ifdef _WIN32
-
-#include <windows.h>
-
-BOOL WINAPI sig_handler_fn(DWORD dwCtrlType)
-{
- /* Runs in its own thread */
-
- switch (dwCtrlType) {
- case CTRL_C_EVENT:
- case CTRL_CLOSE_EVENT:
- quit_all(SIGTERM);
- return TRUE;
- default:
- return FALSE;
- }
-}
-
-static void setup_sig_handler(void)
-{
- SetConsoleCtrlHandler(sig_handler_fn, TRUE);
-}
-
-#elif NO_THREADS
-
-static void sig_handler(int sig)
-{
- /*
- * If the main function is stuck waiting for data it will not abort. If the
- * user presses Ctrl+C a second time we abort without cleaning up.
- */
- if (!app_running)
- exit(sig);
- app_running = false;
-}
-
-static void set_handler(int sig)
-{
- struct sigaction action;
-
- sigaction(sig, NULL, &action);
- action.sa_handler = sig_handler;
- sigaction(sig, &action, NULL);
-}
-
-static void setup_sig_handler(void)
-{
- set_handler(SIGHUP);
- set_handler(SIGPIPE);
- set_handler(SIGINT);
- set_handler(SIGSEGV);
- set_handler(SIGTERM);
-}
-
-#else
-
-#include <pthread.h>
-
-static void * sig_handler_thd(void *data)
-{
- sigset_t *mask = data;
- int ret, sig;
-
- /* Blocks until one of the termination signals is received */
- do {
- ret = sigwait(mask, &sig);
- } while (ret == EINTR);
-
- quit_all(ret);
-
- return NULL;
-}
-
-static void setup_sig_handler(void)
-{
- sigset_t mask, oldmask;
- pthread_t thd;
- int ret;
-
- /*
- * Async signals are difficult to handle and the IIO API is not signal
- * safe. Use a seperate thread and handle the signals synchronous so we
- * can call iio_buffer_cancel().
- */
-
- sigemptyset(&mask);
- sigaddset(&mask, SIGHUP);
- sigaddset(&mask, SIGPIPE);
- sigaddset(&mask, SIGINT);
- sigaddset(&mask, SIGSEGV);
- sigaddset(&mask, SIGTERM);
-
- pthread_sigmask(SIG_BLOCK, &mask, &oldmask);
-
- ret = pthread_create(&thd, NULL, sig_handler_thd, &mask);
- if (ret) {
- fprintf(stderr, "Failed to create signal handler thread: %d\n", ret);
- pthread_sigmask(SIG_SETMASK, &oldmask, NULL);
- }
-}
-
-#endif
-
-static ssize_t print_sample(const struct iio_channel *chn,
- void *buf, size_t len, void *d)
-{
- fwrite(buf, 1, len, stdout);
- if (num_samples != 0) {
- num_samples--;
- if (num_samples == 0) {
- quit_all(EXIT_SUCCESS);
- return -1;
- }
- }
- return (ssize_t) len;
-}
-
-static struct iio_context *scan(void)
-{
- struct iio_scan_context *scan_ctx;
- struct iio_context_info **info;
- struct iio_context *ctx = NULL;
- unsigned int i;
- ssize_t ret;
-
- scan_ctx = iio_create_scan_context(NULL, 0);
- if (!scan_ctx) {
- fprintf(stderr, "Unable to create scan context\n");
- return NULL;
- }
-
- ret = iio_scan_context_get_info_list(scan_ctx, &info);
- if (ret < 0) {
- char err_str[1024];
- iio_strerror(-ret, err_str, sizeof(err_str));
- fprintf(stderr, "Scanning for IIO contexts failed: %s\n", err_str);
- goto err_free_ctx;
- }
-
- if (ret == 0) {
- printf("No IIO context found.\n");
- goto err_free_info_list;
- }
-
- if (ret == 1) {
- ctx = iio_create_context_from_uri(iio_context_info_get_uri(info[0]));
- } else {
- fprintf(stderr, "Multiple contexts found. Please select one using --uri:\n");
-
- for (i = 0; i < (size_t) ret; i++) {
- fprintf(stderr, "\t%d: %s [%s]\n", i,
- iio_context_info_get_description(info[i]),
- iio_context_info_get_uri(info[i]));
- }
- }
-
-err_free_info_list:
- iio_context_info_list_free(info);
-err_free_ctx:
- iio_scan_context_destroy(scan_ctx);
-
- return ctx;
-}
-
-int main(int argc, char **argv)
-{
- unsigned int i, nb_channels;
- unsigned int buffer_size = SAMPLES_PER_READ;
- const char *arg_uri = NULL;
- const char *arg_ip = NULL;
- int c, option_index = 0;
- struct iio_device *dev;
- size_t sample_size;
- int timeout = -1;
- bool scan_for_context = false;
-
- while ((c = getopt_long(argc, argv, "+hn:u:t:b:s:T:a",
- options, &option_index)) != -1) {
- switch (c) {
- case 'h':
- usage();
- return EXIT_SUCCESS;
- case 'n':
- arg_ip = optarg;
- break;
- case 'u':
- arg_uri = optarg;
- break;
- case 'a':
- scan_for_context = true;
- break;
- case 't':
- trigger_name = optarg;
- break;
- case 'b':
- buffer_size = atoi(optarg);
- break;
- case 's':
- num_samples = atoi(optarg);
- break;
- case 'T':
- timeout = atoi(optarg);
- break;
- case '?':
- return EXIT_FAILURE;
- }
- }
-
- if (argc == optind) {
- fprintf(stderr, "Incorrect number of arguments.\n\n");
- usage();
- return EXIT_FAILURE;
- }
-
- setup_sig_handler();
-
- if (scan_for_context)
- ctx = scan();
- else if (arg_uri)
- ctx = iio_create_context_from_uri(arg_uri);
- else if (arg_ip)
- ctx = iio_create_network_context(arg_ip);
- else
- ctx = iio_create_default_context();
-
- if (!ctx) {
- fprintf(stderr, "Unable to create IIO context\n");
- return EXIT_FAILURE;
- }
-
- if (timeout >= 0)
- iio_context_set_timeout(ctx, timeout);
-
- dev = iio_context_find_device(ctx, argv[optind]);
- if (!dev) {
- fprintf(stderr, "Device %s not found\n", argv[optind]);
- iio_context_destroy(ctx);
- return EXIT_FAILURE;
- }
-
- if (trigger_name) {
- struct iio_device *trigger = iio_context_find_device(
- ctx, trigger_name);
- if (!trigger) {
- fprintf(stderr, "Trigger %s not found\n", trigger_name);
- iio_context_destroy(ctx);
- return EXIT_FAILURE;
- }
-
- if (!iio_device_is_trigger(trigger)) {
- fprintf(stderr, "Specified device is not a trigger\n");
- iio_context_destroy(ctx);
- return EXIT_FAILURE;
- }
-
- /*
- * Fixed rate for now. Try new ABI first,
- * fail gracefully to remain compatible.
- */
- if (iio_device_attr_write_longlong(trigger,
- "sampling_frequency", DEFAULT_FREQ_HZ) < 0)
- iio_device_attr_write_longlong(trigger,
- "frequency", DEFAULT_FREQ_HZ);
-
- iio_device_set_trigger(dev, trigger);
- }
-
- nb_channels = iio_device_get_channels_count(dev);
-
- if (argc == optind + 1) {
- /* Enable all channels */
- for (i = 0; i < nb_channels; i++)
- iio_channel_enable(iio_device_get_channel(dev, i));
- } else {
- for (i = 0; i < nb_channels; i++) {
- unsigned int j;
- struct iio_channel *ch = iio_device_get_channel(dev, i);
- for (j = optind + 1; j < (unsigned int) argc; j++) {
- const char *n = iio_channel_get_name(ch);
- if (!strcmp(argv[j], iio_channel_get_id(ch)) ||
- (n && !strcmp(n, argv[j])))
- iio_channel_enable(ch);
- }
- }
- }
-
- sample_size = iio_device_get_sample_size(dev);
-
- buffer = iio_device_create_buffer(dev, buffer_size, false);
- if (!buffer) {
- char buf[256];
- iio_strerror(errno, buf, sizeof(buf));
- fprintf(stderr, "Unable to allocate buffer: %s\n", buf);
- iio_context_destroy(ctx);
- return EXIT_FAILURE;
- }
-
- while (app_running) {
- int ret = iio_buffer_refill(buffer);
- if (ret < 0) {
- if (app_running) {
- char buf[256];
- iio_strerror(-ret, buf, sizeof(buf));
- fprintf(stderr, "Unable to refill buffer: %s\n", buf);
- }
- break;
- }
-
- /* If there are only the samples we requested, we don't need to
- * demux */
- if (iio_buffer_step(buffer) == sample_size) {
- void *start = iio_buffer_start(buffer);
- size_t read_len, len = (intptr_t) iio_buffer_end(buffer)
- - (intptr_t) start;
-
- if (num_samples && len > num_samples * sample_size)
- len = num_samples * sample_size;
-
- for (read_len = len; len; ) {
- size_t nb = fwrite(start, 1, len, stdout);
- if (!nb)
- goto err_destroy_buffer;
-
- len -= nb;
- start = (void *)((intptr_t) start + nb);
- }
-
- if (num_samples) {
- num_samples -= read_len / sample_size;
- if (!num_samples)
- quit_all(EXIT_SUCCESS);
- }
- } else {
- iio_buffer_foreach_sample(buffer, print_sample, NULL);
- }
- }
-
-err_destroy_buffer:
- iio_buffer_destroy(buffer);
- iio_context_destroy(ctx);
- return exit_code;
-}
diff --git a/tests/iio_reg.c b/tests/iio_reg.c
deleted file mode 100644
index 98b84f8..0000000
--- a/tests/iio_reg.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2015 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.
- *
- * */
-
-#include <errno.h>
-#include <iio.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-static int write_reg(const char *name, unsigned long addr, unsigned long val)
-{
- struct iio_device *dev;
- struct iio_context *ctx;
- int ret;
-
- ctx = iio_create_default_context();
- if (!ctx) {
- perror("Unable to create context");
- return EXIT_FAILURE;
- }
-
- dev = iio_context_find_device(ctx, name);
- if (!dev) {
- errno = ENODEV;
- perror("Unable to find device");
- goto err_destroy_context;
- }
-
- ret = iio_device_reg_write(dev, addr, val);
- if (ret < 0) {
- errno = -ret;
- perror("Unable to write register");
- goto err_destroy_context;
- }
-
- iio_context_destroy(ctx);
- return EXIT_SUCCESS;
-
-err_destroy_context:
- iio_context_destroy(ctx);
- return EXIT_FAILURE;
-}
-
-static int read_reg(const char *name, unsigned long addr)
-{
- struct iio_device *dev;
- struct iio_context *ctx;
- uint32_t val;
- int ret;
-
- ctx = iio_create_default_context();
- if (!ctx) {
- perror("Unable to create context");
- return EXIT_FAILURE;
- }
-
- dev = iio_context_find_device(ctx, name);
- if (!dev) {
- errno = ENODEV;
- perror("Unable to find device");
- goto err_destroy_context;
- }
-
- ret = iio_device_reg_read(dev, addr, &val);
- if (ret < 0) {
- errno = -ret;
- perror("Unable to read register");
- goto err_destroy_context;
- }
-
- printf("0x%x\n", val);
- iio_context_destroy(ctx);
- return EXIT_SUCCESS;
-
-err_destroy_context:
- iio_context_destroy(ctx);
- return EXIT_FAILURE;
-}
-
-int main(int argc, char **argv)
-{
- unsigned long addr;
-
- if (argc < 3 || argc > 4) {
- printf("Usage:\n\niio_reg <device> <register> [<value>]\n");
- return 0;
- }
-
- addr = strtoul(argv[2], NULL, 0);
-
- if (argc == 3) {
- return read_reg(argv[1], addr);
- } else {
- unsigned long val = strtoul(argv[3], NULL, 0);
- return write_reg(argv[1], addr, val);
- }
-}
diff --git a/tests/iio_writedev.c b/tests/iio_writedev.c
deleted file mode 100644
index 53ab447..0000000
--- a/tests/iio_writedev.c
+++ /dev/null
@@ -1,453 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2014-2018 Analog Devices, Inc.
- * Author: Paul Cercueil <paul.cercueil@analog.com>
- * that Michael Hennerich <michael.hennerich@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.
- *
- * */
-
-#include <errno.h>
-#include <getopt.h>
-#include <iio.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-
-#ifdef _WIN32
-#include <windows.h>
-#include <fcntl.h>
-#include <io.h>
-#else
-#include <unistd.h>
-#endif
-
-#define MY_NAME "iio_writedev"
-
-#define SAMPLES_PER_READ 256
-#define DEFAULT_FREQ_HZ 100
-
-static const struct option options[] = {
- {"help", no_argument, 0, 'h'},
- {"network", required_argument, 0, 'n'},
- {"uri", required_argument, 0, 'u'},
- {"trigger", required_argument, 0, 't'},
- {"buffer-size", required_argument, 0, 'b'},
- {"samples", required_argument, 0, 's' },
- {"timeout", required_argument, 0, 'T'},
- {"auto", no_argument, 0, 'a'},
- {"cyclic", no_argument, 0, 'c'},
- {0, 0, 0, 0},
-};
-
-static const char *options_descriptions[] = {
- "Show this help and quit.",
- "Use the network backend with the provided hostname.",
- "Use the context with the provided URI.",
- "Use the specified trigger.",
- "Size of the capture buffer. Default is 256.",
- "Number of samples to write, 0 = infinite. Default is 0.",
- "Buffer timeout in milliseconds. 0 = no timeout",
- "Scan for available contexts and if only one is available use it.",
- "Use cyclic buffer mode.",
-};
-
-static void usage(void)
-{
- unsigned int i;
-
- printf("Usage:\n\t" MY_NAME " [-n <hostname>] [-t <trigger>] "
- "[-T <timeout-ms>] [-b <buffer-size>] [-s <samples>] "
- "<iio_device> [<channel> ...]\n\nOptions:\n");
- for (i = 0; options[i].name; i++)
- printf("\t-%c, --%s\n\t\t\t%s\n",
- options[i].val, options[i].name,
- options_descriptions[i]);
-}
-
-static struct iio_context *ctx;
-static struct iio_buffer *buffer;
-static const char *trigger_name = NULL;
-static size_t num_samples;
-
-static volatile sig_atomic_t app_running = true;
-static int exit_code = EXIT_SUCCESS;
-
-static void quit_all(int sig)
-{
- exit_code = sig;
- app_running = false;
- if (buffer)
- iio_buffer_cancel(buffer);
-}
-
-#ifdef _WIN32
-
-#include <windows.h>
-
-BOOL WINAPI sig_handler_fn(DWORD dwCtrlType)
-{
- /* Runs in its own thread */
-
- switch (dwCtrlType) {
- case CTRL_C_EVENT:
- case CTRL_CLOSE_EVENT:
- quit_all(SIGTERM);
- return TRUE;
- default:
- return FALSE;
- }
-}
-
-static void setup_sig_handler(void)
-{
- SetConsoleCtrlHandler(sig_handler_fn, TRUE);
-}
-
-#elif NO_THREADS
-
-static void sig_handler(int sig)
-{
- /*
- * If the main function is stuck waiting for data it will not abort. If the
- * user presses Ctrl+C a second time we abort without cleaning up.
- */
- if (!app_running)
- exit(sig);
- app_running = false;
-}
-
-static void set_handler(int sig)
-{
- struct sigaction action;
-
- sigaction(sig, NULL, &action);
- action.sa_handler = sig_handler;
- sigaction(sig, &action, NULL);
-}
-
-static void setup_sig_handler(void)
-{
- set_handler(SIGHUP);
- set_handler(SIGPIPE);
- set_handler(SIGINT);
- set_handler(SIGSEGV);
- set_handler(SIGTERM);
-}
-
-#else
-
-#include <pthread.h>
-
-static void * sig_handler_thd(void *data)
-{
- sigset_t *mask = data;
- int ret, sig;
-
- /* Blocks until one of the termination signals is received */
- do {
- ret = sigwait(mask, &sig);
- } while (ret == EINTR);
-
- quit_all(ret);
-
- return NULL;
-}
-
-static void setup_sig_handler(void)
-{
- sigset_t mask, oldmask;
- pthread_t thd;
- int ret;
-
- /*
- * Async signals are difficult to handle and the IIO API is not signal
- * safe. Use a seperate thread and handle the signals synchronous so we
- * can call iio_buffer_cancel().
- */
-
- sigemptyset(&mask);
- sigaddset(&mask, SIGHUP);
- sigaddset(&mask, SIGPIPE);
- sigaddset(&mask, SIGINT);
- sigaddset(&mask, SIGSEGV);
- sigaddset(&mask, SIGTERM);
-
- pthread_sigmask(SIG_BLOCK, &mask, &oldmask);
-
- ret = pthread_create(&thd, NULL, sig_handler_thd, &mask);
- if (ret) {
- fprintf(stderr, "Failed to create signal handler thread: %d\n", ret);
- pthread_sigmask(SIG_SETMASK, &oldmask, NULL);
- }
-}
-
-#endif
-
-static ssize_t read_sample(const struct iio_channel *chn,
- void *buf, size_t len, void *d)
-{
- size_t nb = fread(buf, 1, len, stdin);
- if (num_samples != 0) {
- num_samples--;
- if (num_samples == 0) {
- quit_all(EXIT_SUCCESS);
- return -1;
- }
- }
- return (ssize_t) nb;
-}
-
-static struct iio_context *scan(void)
-{
- struct iio_scan_context *scan_ctx;
- struct iio_context_info **info;
- struct iio_context *ctx = NULL;
- unsigned int i;
- ssize_t ret;
-
- scan_ctx = iio_create_scan_context(NULL, 0);
- if (!scan_ctx) {
- fprintf(stderr, "Unable to create scan context\n");
- return NULL;
- }
-
- ret = iio_scan_context_get_info_list(scan_ctx, &info);
- if (ret < 0) {
- char err_str[1024];
- iio_strerror(-ret, err_str, sizeof(err_str));
- fprintf(stderr, "Scanning for IIO contexts failed: %s\n", err_str);
- goto err_free_ctx;
- }
-
- if (ret == 0) {
- printf("No IIO context found.\n");
- goto err_free_info_list;
- }
-
- if (ret == 1) {
- ctx = iio_create_context_from_uri(iio_context_info_get_uri(info[0]));
- } else {
- fprintf(stderr, "Multiple contexts found. Please select one using --uri:\n");
-
- for (i = 0; i < (size_t) ret; i++) {
- fprintf(stderr, "\t%d: %s [%s]\n", i,
- iio_context_info_get_description(info[i]),
- iio_context_info_get_uri(info[i]));
- }
- }
-
-err_free_info_list:
- iio_context_info_list_free(info);
-err_free_ctx:
- iio_scan_context_destroy(scan_ctx);
-
- return ctx;
-}
-
-int main(int argc, char **argv)
-{
- unsigned int i, nb_channels;
- unsigned int buffer_size = SAMPLES_PER_READ;
- const char *arg_uri = NULL;
- const char *arg_ip = NULL;
- int c, option_index = 0;
- struct iio_device *dev;
- size_t sample_size;
- int timeout = -1;
- bool scan_for_context = false;
- bool cyclic_buffer = false;
-
- while ((c = getopt_long(argc, argv, "+hn:u:t:b:s:T:ac",
- options, &option_index)) != -1) {
- switch (c) {
- case 'h':
- usage();
- return EXIT_SUCCESS;
- case 'n':
- arg_ip = optarg;
- break;
- case 'u':
- arg_uri = optarg;
- break;
- case 'a':
- scan_for_context = true;
- break;
- case 't':
- trigger_name = optarg;
- break;
- case 'b':
- buffer_size = atoi(optarg);
- break;
- case 's':
- num_samples = atoi(optarg);
- break;
- case 'T':
- timeout = atoi(optarg);
- break;
- case 'c':
- cyclic_buffer = true;
- break;
- case '?':
- return EXIT_FAILURE;
- }
- }
-
- if (argc == optind) {
- fprintf(stderr, "Incorrect number of arguments.\n\n");
- usage();
- return EXIT_FAILURE;
- }
-
- setup_sig_handler();
-
- if (scan_for_context)
- ctx = scan();
- else if (arg_uri)
- ctx = iio_create_context_from_uri(arg_uri);
- else if (arg_ip)
- ctx = iio_create_network_context(arg_ip);
- else
- ctx = iio_create_default_context();
-
- if (!ctx) {
- fprintf(stderr, "Unable to create IIO context\n");
- return EXIT_FAILURE;
- }
-
- if (timeout >= 0)
- iio_context_set_timeout(ctx, timeout);
-
- dev = iio_context_find_device(ctx, argv[optind]);
- if (!dev) {
- fprintf(stderr, "Device %s not found\n", argv[optind]);
- iio_context_destroy(ctx);
- return EXIT_FAILURE;
- }
-
- if (trigger_name) {
- struct iio_device *trigger = iio_context_find_device(
- ctx, trigger_name);
- if (!trigger) {
- fprintf(stderr, "Trigger %s not found\n", trigger_name);
- iio_context_destroy(ctx);
- return EXIT_FAILURE;
- }
-
- if (!iio_device_is_trigger(trigger)) {
- fprintf(stderr, "Specified device is not a trigger\n");
- iio_context_destroy(ctx);
- return EXIT_FAILURE;
- }
-
- /*
- * Fixed rate for now. Try new ABI first,
- * fail gracefully to remain compatible.
- */
- if (iio_device_attr_write_longlong(trigger,
- "sampling_frequency", DEFAULT_FREQ_HZ) < 0)
- iio_device_attr_write_longlong(trigger,
- "frequency", DEFAULT_FREQ_HZ);
-
- iio_device_set_trigger(dev, trigger);
- }
-
- nb_channels = iio_device_get_channels_count(dev);
-
- if (argc == optind + 1) {
- /* Enable all channels */
- for (i = 0; i < nb_channels; i++)
- iio_channel_enable(iio_device_get_channel(dev, i));
- } else {
- for (i = 0; i < nb_channels; i++) {
- unsigned int j;
- struct iio_channel *ch = iio_device_get_channel(dev, i);
- for (j = optind + 1; j < (unsigned int) argc; j++) {
- const char *n = iio_channel_get_name(ch);
- if (!strcmp(argv[j], iio_channel_get_id(ch)) ||
- (n && !strcmp(n, argv[j])))
- iio_channel_enable(ch);
- }
- }
- }
-
- sample_size = iio_device_get_sample_size(dev);
-
- buffer = iio_device_create_buffer(dev, buffer_size, cyclic_buffer);
- if (!buffer) {
- char buf[256];
- iio_strerror(errno, buf, sizeof(buf));
- fprintf(stderr, "Unable to allocate buffer: %s\n", buf);
- iio_context_destroy(ctx);
- return EXIT_FAILURE;
- }
-
-#ifdef _WIN32
- _setmode(_fileno( stdin ), _O_BINARY);
-#endif
-
- while (app_running) {
- /* If there are only the samples we requested, we don't need to
- * demux */
- if (iio_buffer_step(buffer) == sample_size) {
- void *start = iio_buffer_start(buffer);
- size_t write_len, len = (intptr_t) iio_buffer_end(buffer)
- - (intptr_t) start;
-
- if (num_samples && len > num_samples * sample_size)
- len = num_samples * sample_size;
-
- for (write_len = len; len; ) {
- size_t nb = fread(start, 1, len, stdin);
- if (!nb)
- goto err_destroy_buffer;
-
- len -= nb;
- start = (void *)((intptr_t) start + nb);
- }
-
- if (num_samples) {
- num_samples -= write_len / sample_size;
- if (!num_samples)
- quit_all(EXIT_SUCCESS);
- }
- } else {
- iio_buffer_foreach_sample(buffer, read_sample, NULL);
- }
-
- int ret = iio_buffer_push(buffer);
- if (ret < 0) {
- if (app_running) {
- char buf[256];
- iio_strerror(-ret, buf, sizeof(buf));
- fprintf(stderr, "Unable to push buffer: %s\n", buf);
- }
- break;
- }
-
- while(cyclic_buffer && app_running) {
-#ifdef _WIN32
- Sleep(1000);
-#else
- sleep(1);
-#endif
- }
- }
-
-
-err_destroy_buffer:
- iio_buffer_destroy(buffer);
- iio_context_destroy(ctx);
- return exit_code;
-}
diff --git a/usb.c b/usb.c
deleted file mode 100644
index 141bd41..0000000
--- a/usb.c
+++ /dev/null
@@ -1,1192 +0,0 @@
-/*
- * libiio - Library for interfacing industrial I/O (IIO) devices
- *
- * Copyright (C) 2015 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.
- *
- * */
-
-#include "iio-lock.h"
-#include "iio-private.h"
-#include "iiod-client.h"
-
-#include <ctype.h>
-#include <errno.h>
-#include <libusb-1.0/libusb.h>
-#include <stdbool.h>
-#include <string.h>
-
-#ifdef ERROR
-#undef ERROR
-#endif
-
-#include "debug.h"
-
-#define DEFAULT_TIMEOUT_MS 5000
-
-/* Endpoint for non-streaming operations */
-#define EP_OPS 1
-
-#define IIO_INTERFACE_NAME "IIO"
-
-struct iio_usb_ep_couple {
- unsigned char addr_in, addr_out;
- unsigned int pipe_id;
- bool in_use;
-
- struct iio_mutex *lock;
-};
-
-struct iio_usb_io_context {
- struct iio_usb_ep_couple *ep;
-
- struct iio_mutex *lock;
- bool cancelled;
- struct libusb_transfer *transfer;
-};
-
-struct iio_context_pdata {
- libusb_context *ctx;
- libusb_device_handle *hdl;
- unsigned int interface;
-
- struct iiod_client *iiod_client;
-
- /* Lock for non-streaming operations */
- struct iio_mutex *lock;
-
- /* Lock for endpoint reservation */
- struct iio_mutex *ep_lock;
-
- struct iio_usb_ep_couple *io_endpoints;
- unsigned int nb_ep_couples;
-
- unsigned int timeout_ms;
-
- struct iio_usb_io_context io_ctx;
-};
-
-struct iio_device_pdata {
- struct iio_mutex *lock;
-
- bool opened;
- struct iio_usb_io_context io_ctx;
-};
-
-static const unsigned int libusb_to_errno_codes[] = {
- [- LIBUSB_ERROR_INVALID_PARAM] = EINVAL,
- [- LIBUSB_ERROR_ACCESS] = EACCES,
- [- LIBUSB_ERROR_NO_DEVICE] = ENODEV,
- [- LIBUSB_ERROR_NOT_FOUND] = ENXIO,
- [- LIBUSB_ERROR_BUSY] = EBUSY,
- [- LIBUSB_ERROR_TIMEOUT] = ETIMEDOUT,
- [- LIBUSB_ERROR_OVERFLOW] = EIO,
- [- LIBUSB_ERROR_PIPE] = EPIPE,
- [- LIBUSB_ERROR_INTERRUPTED] = EINTR,
- [- LIBUSB_ERROR_NO_MEM] = ENOMEM,
- [- LIBUSB_ERROR_NOT_SUPPORTED] = ENOSYS,
-};
-
-static unsigned int libusb_to_errno(int error)
-{
- switch ((enum libusb_error) error) {
- case LIBUSB_ERROR_INVALID_PARAM:
- case LIBUSB_ERROR_ACCESS:
- case LIBUSB_ERROR_NO_DEVICE:
- case LIBUSB_ERROR_NOT_FOUND:
- case LIBUSB_ERROR_BUSY:
- case LIBUSB_ERROR_TIMEOUT:
- case LIBUSB_ERROR_PIPE:
- case LIBUSB_ERROR_INTERRUPTED:
- case LIBUSB_ERROR_NO_MEM:
- case LIBUSB_ERROR_NOT_SUPPORTED:
- return libusb_to_errno_codes[- (int) error];
- case LIBUSB_ERROR_IO:
- case LIBUSB_ERROR_OTHER:
- case LIBUSB_ERROR_OVERFLOW:
- default:
- return EIO;
- }
-}
-
-static int usb_io_context_init(struct iio_usb_io_context *io_ctx)
-{
- io_ctx->lock = iio_mutex_create();
- if (!io_ctx->lock)
- return -ENOMEM;
-
- return 0;
-}
-
-static void usb_io_context_exit(struct iio_usb_io_context *io_ctx)
-{
- if (io_ctx->lock) {
- iio_mutex_destroy(io_ctx->lock);
- io_ctx->lock = NULL;
- }
-}
-
-static int usb_get_version(const struct iio_context *ctx,
- unsigned int *major, unsigned int *minor, char git_tag[8])
-{
- return iiod_client_get_version(ctx->pdata->iiod_client,
- &ctx->pdata->io_ctx, major, minor, git_tag);
-}
-
-static unsigned int usb_calculate_remote_timeout(unsigned int timeout)
-{
- /* XXX(pcercuei): We currently hardcode timeout / 2 for the backend used
- * by the remote. Is there something better to do here? */
- return timeout / 2;
-}
-
-#define USB_PIPE_CTRL_TIMEOUT 1000 /* These should not take long */
-
-#define IIO_USD_CMD_RESET_PIPES 0
-#define IIO_USD_CMD_OPEN_PIPE 1
-#define IIO_USD_CMD_CLOSE_PIPE 2
-
-static int usb_reset_pipes(struct iio_context_pdata *pdata)
-{
- int ret;
-
- ret = libusb_control_transfer(pdata->hdl, LIBUSB_REQUEST_TYPE_VENDOR |
- LIBUSB_RECIPIENT_INTERFACE, IIO_USD_CMD_RESET_PIPES,
- 0, pdata->interface, NULL, 0, USB_PIPE_CTRL_TIMEOUT);
- if (ret < 0)
- return -(int) libusb_to_errno(ret);
- return 0;
-}
-
-static int usb_open_pipe(struct iio_context_pdata *pdata, unsigned int pipe_id)
-{
- int ret;
-
- ret = libusb_control_transfer(pdata->hdl, LIBUSB_REQUEST_TYPE_VENDOR |
- LIBUSB_RECIPIENT_INTERFACE, IIO_USD_CMD_OPEN_PIPE,
- pipe_id, pdata->interface, NULL, 0, USB_PIPE_CTRL_TIMEOUT);
- if (ret < 0)
- return -(int) libusb_to_errno(ret);
- return 0;
-}
-
-static int usb_close_pipe(struct iio_context_pdata *pdata, unsigned int pipe_id)
-{
- int ret;
-
- ret = libusb_control_transfer(pdata->hdl, LIBUSB_REQUEST_TYPE_VENDOR |
- LIBUSB_RECIPIENT_INTERFACE, IIO_USD_CMD_CLOSE_PIPE,
- pipe_id, pdata->interface, NULL, 0, USB_PIPE_CTRL_TIMEOUT);
- if (ret < 0)
- return -(int) libusb_to_errno(ret);
- return 0;
-}
-
-static int usb_reserve_ep_unlocked(const struct iio_device *dev)
-{
- struct iio_context_pdata *pdata = dev->ctx->pdata;
- unsigned int i;
-
- for (i = 0; i < pdata->nb_ep_couples; i++) {
- struct iio_usb_ep_couple *ep = &pdata->io_endpoints[i];
-
- if (!ep->in_use) {
- ep->in_use = true;
-
- dev->pdata->io_ctx.ep = ep;
- dev->pdata->lock = ep->lock;
- return 0;
- }
- }
-
- return -EBUSY;
-}
-
-static void usb_free_ep_unlocked(const struct iio_device *dev)
-{
- struct iio_context_pdata *pdata = dev->ctx->pdata;
- unsigned int i;
-
- for (i = 0; i < pdata->nb_ep_couples; i++) {
- struct iio_usb_ep_couple *ep = &pdata->io_endpoints[i];
-
- if (ep->lock == dev->pdata->lock) {
- ep->in_use = false;
- return;
- }
- }
-}
-
-static int usb_open(const struct iio_device *dev,
- size_t samples_count, bool cyclic)
-{
- struct iio_context_pdata *ctx_pdata = dev->ctx->pdata;
- struct iio_device_pdata *pdata = dev->pdata;
- int ret = -EBUSY;
-
- iio_mutex_lock(ctx_pdata->ep_lock);
-
- pdata->io_ctx.cancelled = false;
-
- if (pdata->opened)
- goto out_unlock;
-
- ret = usb_reserve_ep_unlocked(dev);
- if (ret)
- goto out_unlock;
-
- ret = usb_open_pipe(ctx_pdata, pdata->io_ctx.ep->pipe_id);
- if (ret) {
- char err_str[1024];
-
- iio_strerror(-ret, err_str, sizeof(err_str));
- ERROR("Failed to open pipe: %s\n", err_str);
- usb_free_ep_unlocked(dev);
- goto out_unlock;
- }
-
- iio_mutex_lock(pdata->lock);
-
- ret = iiod_client_open_unlocked(ctx_pdata->iiod_client, &pdata->io_ctx,
- dev, samples_count, cyclic);
-
- if (!ret) {
- unsigned int remote_timeout =
- usb_calculate_remote_timeout(ctx_pdata->timeout_ms);
-
- ret = iiod_client_set_timeout(ctx_pdata->iiod_client,
- &pdata->io_ctx, remote_timeout);
- }
-
- pdata->opened = !ret;
-
- iio_mutex_unlock(pdata->lock);
-
- if (ret) {
- usb_close_pipe(ctx_pdata, pdata->io_ctx.ep->pipe_id);
- usb_free_ep_unlocked(dev);
- }
-
-out_unlock:
- iio_mutex_unlock(ctx_pdata->ep_lock);
- return ret;
-}
-
-static int usb_close(const struct iio_device *dev)
-{
- struct iio_context_pdata *ctx_pdata = dev->ctx->pdata;
- struct iio_device_pdata *pdata = dev->pdata;
- int ret = -EBADF;
-
- iio_mutex_lock(ctx_pdata->ep_lock);
- if (!pdata->opened)
- goto out_unlock;
-
- iio_mutex_lock(pdata->lock);
- ret = iiod_client_close_unlocked(ctx_pdata->iiod_client, &pdata->io_ctx,
- dev);
- pdata->opened = false;
-
- iio_mutex_unlock(pdata->lock);
-
- usb_close_pipe(ctx_pdata, pdata->io_ctx.ep->pipe_id);
-
- usb_free_ep_unlocked(dev);
-
-out_unlock:
- iio_mutex_unlock(ctx_pdata->ep_lock);
- return ret;
-}
-
-static ssize_t usb_read(const struct iio_device *dev, void *dst, size_t len,
- uint32_t *mask, size_t words)
-{
- struct iio_device_pdata *pdata = dev->pdata;
- ssize_t ret;
-
- iio_mutex_lock(pdata->lock);
- ret = iiod_client_read_unlocked(dev->ctx->pdata->iiod_client,
- &pdata->io_ctx, dev, dst, len, mask, words);
- iio_mutex_unlock(pdata->lock);
-
- return ret;
-}
-
-static ssize_t usb_write(const struct iio_device *dev,
- const void *src, size_t len)
-{
- struct iio_device_pdata *pdata = dev->pdata;
- ssize_t ret;
-
- iio_mutex_lock(pdata->lock);
- ret = iiod_client_write_unlocked(dev->ctx->pdata->iiod_client,
- &pdata->io_ctx, dev, src, len);
- iio_mutex_unlock(pdata->lock);
-
- return ret;
-}
-
-static ssize_t usb_read_dev_attr(const struct iio_device *dev,
- const char *attr, char *dst, size_t len, enum iio_attr_type type)
-{
- struct iio_context_pdata *pdata = dev->ctx->pdata;
-
- return iiod_client_read_attr(pdata->iiod_client,
- &pdata->io_ctx, dev, NULL, attr,
- dst, len, type);
-}
-
-static ssize_t usb_write_dev_attr(const struct iio_device *dev,
- const char *attr, const char *src, size_t len, enum iio_attr_type type)
-{
- struct iio_context_pdata *pdata = dev->ctx->pdata;
-
- return iiod_client_write_attr(pdata->iiod_client,
- &pdata->io_ctx, dev, NULL, attr,
- src, len, type);
-}
-
-static ssize_t usb_read_chn_attr(const struct iio_channel *chn,
- const char *attr, char *dst, size_t len)
-{
- struct iio_context_pdata *pdata = chn->dev->ctx->pdata;
-
- return iiod_client_read_attr(pdata->iiod_client,
- &pdata->io_ctx, chn->dev, chn, attr,
- dst, len, false);
-}
-
-static ssize_t usb_write_chn_attr(const struct iio_channel *chn,
- const char *attr, const char *src, size_t len)
-{
- struct iio_context_pdata *pdata = chn->dev->ctx->pdata;
-
- return iiod_client_write_attr(pdata->iiod_client,
- &pdata->io_ctx, chn->dev, chn, attr,
- src, len, false);
-}
-
-static int usb_set_kernel_buffers_count(const struct iio_device *dev,
- unsigned int nb_blocks)
-{
- struct iio_context_pdata *pdata = dev->ctx->pdata;
-
- return iiod_client_set_kernel_buffers_count(pdata->iiod_client,
- &pdata->io_ctx, dev, nb_blocks);
-}
-
-static int usb_set_timeout(struct iio_context *ctx, unsigned int timeout)
-{
- struct iio_context_pdata *pdata = ctx->pdata;
- unsigned int remote_timeout = usb_calculate_remote_timeout(timeout);
- int ret;
-
- ret = iiod_client_set_timeout(pdata->iiod_client,
- &pdata->io_ctx, remote_timeout);
- if (!ret)
- pdata->timeout_ms = timeout;
-
- return ret;
-}
-
-static void usb_shutdown(struct iio_context *ctx)
-{
- unsigned int i;
-
- usb_io_context_exit(&ctx->pdata->io_ctx);
-
- for (i = 0; i < ctx->nb_devices; i++)
- usb_close(ctx->devices[i]);
-
- iio_mutex_destroy(ctx->pdata->lock);
- iio_mutex_destroy(ctx->pdata->ep_lock);
-
- for (i = 0; i < ctx->pdata->nb_ep_couples; i++)
- if (ctx->pdata->io_endpoints[i].lock)
- iio_mutex_destroy(ctx->pdata->io_endpoints[i].lock);
- if (ctx->pdata->io_endpoints)
- free(ctx->pdata->io_endpoints);
-
- for (i = 0; i < ctx->nb_devices; i++) {
- struct iio_device *dev = ctx->devices[i];
-
- usb_io_context_exit(&dev->pdata->io_ctx);
- free(dev->pdata);
- }
-
- iiod_client_destroy(ctx->pdata->iiod_client);
-
- usb_reset_pipes(ctx->pdata); /* Close everything */
-
- libusb_close(ctx->pdata->hdl);
- libusb_exit(ctx->pdata->ctx);
- free(ctx->pdata);
-}
-
-static int iio_usb_match_interface(const struct libusb_config_descriptor *desc,
- struct libusb_device_handle *hdl, unsigned int interface)
-{
- const struct libusb_interface *iface;
- unsigned int i;
-
- if (interface >= desc->bNumInterfaces)
- return -EINVAL;
-
- iface = &desc->interface[interface];
-
- for (i = 0; i < (unsigned int) iface->num_altsetting; i++) {
- const struct libusb_interface_descriptor *idesc =
- &iface->altsetting[i];
- char name[64];
- int ret;
-
- if (idesc->iInterface == 0)
- continue;
-
- ret = libusb_get_string_descriptor_ascii(hdl, idesc->iInterface,
- (unsigned char *) name, sizeof(name));
- if (ret < 0)
- return -(int) libusb_to_errno(ret);
-
- if (!strcmp(name, IIO_INTERFACE_NAME))
- return (int) i;
- }
-
- return -EPERM;
-}
-
-static int iio_usb_match_device(struct libusb_device *dev,
- struct libusb_device_handle *hdl,
- unsigned int *interface)
-{
- struct libusb_config_descriptor *desc;
- unsigned int i;
- int ret;
-
- ret = libusb_get_active_config_descriptor(dev, &desc);
- if (ret)
- return -(int) libusb_to_errno(ret);
-
- for (i = 0, ret = -EPERM; ret == -EPERM &&
- i < desc->bNumInterfaces; i++)
- ret = iio_usb_match_interface(desc, hdl, i);
-
- libusb_free_config_descriptor(desc);
- if (ret < 0)
- return ret;
-
- DEBUG("Found IIO interface on device %u:%u using interface %u\n",
- libusb_get_bus_number(dev),
- libusb_get_device_address(dev), i - 1);
-
- *interface = i - 1;
- return ret;
-}
-
-static void usb_cancel(const struct iio_device *dev)
-{
- struct iio_device_pdata *ppdata = dev->pdata;
-
- iio_mutex_lock(ppdata->io_ctx.lock);
- if (ppdata->io_ctx.transfer && !ppdata->io_ctx.cancelled)
- libusb_cancel_transfer(ppdata->io_ctx.transfer);
- ppdata->io_ctx.cancelled = true;
- iio_mutex_unlock(ppdata->io_ctx.lock);
-}
-
-static const struct iio_backend_ops usb_ops = {
- .get_version = usb_get_version,
- .open = usb_open,
- .close = usb_close,
- .read = usb_read,
- .write = usb_write,
- .read_device_attr = usb_read_dev_attr,
- .read_channel_attr = usb_read_chn_attr,
- .write_device_attr = usb_write_dev_attr,
- .write_channel_attr = usb_write_chn_attr,
- .set_kernel_buffers_count = usb_set_kernel_buffers_count,
- .set_timeout = usb_set_timeout,
- .shutdown = usb_shutdown,
-
- .cancel = usb_cancel,
-};
-
-static void LIBUSB_CALL sync_transfer_cb(struct libusb_transfer *transfer)
-{
- int *completed = transfer->user_data;
- *completed = 1;
-}
-
-static int usb_sync_transfer(struct iio_context_pdata *pdata,
- struct iio_usb_io_context *io_ctx, unsigned int ep_type,
- char *data, size_t len, int *transferred)
-{
- unsigned int ep;
- struct libusb_transfer *transfer;
- int completed = 0;
- int ret;
-
- /*
- * If the size of the data to transfer is too big, the
- * IOCTL_USBFS_SUBMITURB ioctl (called by libusb) might fail with
- * errno set to ENOMEM, as the kernel might use contiguous allocation
- * for the URB if the driver doesn't support scatter-gather.
- * To prevent that, we support URBs of 1 MiB maximum. The iiod-client
- * code will handle this properly and ask for a new transfer.
- */
- if (len > 1 * 1024 * 1024)
- len = 1 * 1024 * 1024;
-
- if (ep_type == LIBUSB_ENDPOINT_IN)
- ep = io_ctx->ep->addr_in;
- else
- ep = io_ctx->ep->addr_out;
-
- /*
- * For cancellation support the check whether the buffer has already been
- * cancelled and the allocation as well as the assignment of the new
- * transfer needs to happen in one atomic step. Otherwise it is possible
- * that the cancellation is missed and transfer is not aborted.
- */
- iio_mutex_lock(io_ctx->lock);
- if (io_ctx->cancelled) {
- ret = -EBADF;
- goto unlock;
- }
-
- transfer = libusb_alloc_transfer(0);
- if (!transfer) {
- ret = -ENOMEM;
- goto unlock;
- }
-
- transfer->user_data = &completed;
-
- libusb_fill_bulk_transfer(transfer, pdata->hdl, ep,
- (unsigned char *) data, (int) len, sync_transfer_cb,
- &completed, pdata->timeout_ms);
- transfer->type = LIBUSB_TRANSFER_TYPE_BULK;
-
- ret = libusb_submit_transfer(transfer);
- if (ret) {
- ret = -(int) libusb_to_errno(ret);
- libusb_free_transfer(transfer);
- goto unlock;
- }
-
- io_ctx->transfer = transfer;
-unlock:
- iio_mutex_unlock(io_ctx->lock);
- if (ret)
- return ret;
-
- while (!completed) {
- ret = libusb_handle_events_completed(pdata->ctx, &completed);
- if (ret < 0) {
- if (ret == LIBUSB_ERROR_INTERRUPTED)
- continue;
- libusb_cancel_transfer(transfer);
- continue;
- }
- }
-
- switch (transfer->status) {
- case LIBUSB_TRANSFER_COMPLETED:
- *transferred = transfer->actual_length;
- ret = 0;
- break;
- case LIBUSB_TRANSFER_TIMED_OUT:
- ret = -ETIMEDOUT;
- break;
- case LIBUSB_TRANSFER_STALL:
- ret = -EPIPE;
- break;
- case LIBUSB_TRANSFER_NO_DEVICE:
- ret = -ENODEV;
- break;
- case LIBUSB_TRANSFER_CANCELLED:
- ret = -EBADF;
- break;
- default:
- ret = -EIO;
- break;
- }
-
- /* Same as above. This needs to be atomic in regards to usb_cancel(). */
- iio_mutex_lock(io_ctx->lock);
- io_ctx->transfer = NULL;
- iio_mutex_unlock(io_ctx->lock);
-
- libusb_free_transfer(transfer);
-
- return ret;
-}
-
-static ssize_t write_data_sync(struct iio_context_pdata *pdata,
- void *ep, const char *data, size_t len)
-{
- int transferred, ret;
-
- ret = usb_sync_transfer(pdata, ep, LIBUSB_ENDPOINT_OUT, (char *) data,
- len, &transferred);
- if (ret)
- return ret;
- else
- return (ssize_t) transferred;
-}
-
-static ssize_t read_data_sync(struct iio_context_pdata *pdata,
- void *ep, char *buf, size_t len)
-{
- int transferred, ret;
-
- ret = usb_sync_transfer(pdata, ep, LIBUSB_ENDPOINT_IN, buf, len,
- &transferred);
- if (ret)
- return ret;
- else
- return transferred;
-}
-
-static const struct iiod_client_ops usb_iiod_client_ops = {
- .write = write_data_sync,
- .read = read_data_sync,
- .read_line = read_data_sync,
-};
-
-static int usb_verify_eps(const struct libusb_interface_descriptor *iface)
-{
- unsigned int i, eps = iface->bNumEndpoints;
-
- /* Check that we have an even number of endpoints, and that input/output
- * endpoints are interleaved */
-
- if (eps < 2 || eps % 2)
- return -EINVAL;
-
- for (i = 0; i < eps; i += 2) {
- if (!(iface->endpoint[i + 0].bEndpointAddress
- & LIBUSB_ENDPOINT_IN))
- return -EINVAL;
-
- if (iface->endpoint[i + 1].bEndpointAddress
- & LIBUSB_ENDPOINT_IN)
- return -EINVAL;
- }
-
- return 0;
-}
-
-static int usb_populate_context_attrs(struct iio_context *ctx,
- libusb_device *dev, libusb_device_handle *hdl)
-{
- struct libusb_device_descriptor dev_desc;
- char buffer[64];
- unsigned int i;
- int ret;
-
- struct {
- const char *attr;
- uint8_t idx;
- } attrs[3];
-
- libusb_get_device_descriptor(dev, &dev_desc);
-
- attrs[0].attr = "usb,vendor";
- attrs[0].idx = dev_desc.iManufacturer;
- attrs[1].attr = "usb,product";
- attrs[1].idx = dev_desc.iProduct;
- attrs[2].attr = "usb,serial";
- attrs[2].idx = dev_desc.iSerialNumber;
-
- iio_snprintf(buffer, sizeof(buffer), "%04hx", dev_desc.idVendor);
- ret = iio_context_add_attr(ctx, "usb,idVendor", buffer);
- if (ret < 0)
- return ret;
-
- iio_snprintf(buffer, sizeof(buffer), "%04hx", dev_desc.idProduct);
- ret = iio_context_add_attr(ctx, "usb,idProduct", buffer);
- if (ret < 0)
- return ret;
-
- iio_snprintf(buffer, sizeof(buffer), "%1hhx.%1hhx",
- (unsigned char)((dev_desc.bcdUSB >> 8) & 0xf),
- (unsigned char)((dev_desc.bcdUSB >> 4) & 0xf));
- ret = iio_context_add_attr(ctx, "usb,release", buffer);
- if (ret < 0)
- return ret;
-
- for (i = 0; i < ARRAY_SIZE(attrs); i++) {
- if (attrs[i].idx) {
- ret = libusb_get_string_descriptor_ascii(hdl,
- attrs[i].idx, (unsigned char *) buffer,
- sizeof(buffer));
- if (ret < 0)
- return -(int) libusb_to_errno(ret);
-
- ret = iio_context_add_attr(ctx, attrs[i].attr, buffer);
- if (ret < 0)
- return ret;
- }
- }
-
-#ifdef HAS_LIBUSB_GETVERSION
- /*
- * libusb_get_version was added 2012-04-17: v1.0.10,
- * before LIBUSB_API_VERSION was added - Jan 8, 2014
- * so, you can't use that to determine if it is here
- */
- {
- struct libusb_version const *ver = libusb_get_version();
- iio_snprintf(buffer, sizeof(buffer), "%i.%i.%i.%i%s",
- ver->major, ver->minor, ver->micro,
- ver->nano, ver->rc);
- ret = iio_context_add_attr(ctx, "usb,libusb", buffer);
- if (ret < 0)
- return ret;
- }
-#endif
- return 0;
-}
-
-struct iio_context * usb_create_context(unsigned int bus,
- unsigned int address, unsigned int interface)
-{
- libusb_context *usb_ctx;
- libusb_device_handle *hdl;
- const struct libusb_interface_descriptor *iface;
- libusb_device *usb_dev;
- struct libusb_config_descriptor *conf_desc;
- libusb_device **device_list;
- struct iio_context *ctx;
- struct iio_context_pdata *pdata;
- char err_str[1024];
- unsigned int i;
- int ret;
-
- pdata = zalloc(sizeof(*pdata));
- if (!pdata) {
- ERROR("Unable to allocate pdata\n");
- ret = -ENOMEM;
- goto err_set_errno;
- }
-
- pdata->lock = iio_mutex_create();
- if (!pdata->lock) {
- ERROR("Unable to create mutex\n");
- ret = -ENOMEM;
- goto err_free_pdata;
- }
-
- pdata->ep_lock = iio_mutex_create();
- if (!pdata->ep_lock) {
- ERROR("Unable to create mutex\n");
- ret = -ENOMEM;
- goto err_destroy_mutex;
- }
-
- pdata->iiod_client = iiod_client_new(pdata, pdata->lock,
- &usb_iiod_client_ops);
- if (!pdata->iiod_client) {
- ERROR("Unable to create IIOD client\n");
- ret = -errno;
- goto err_destroy_ep_mutex;
- }
-
- ret = libusb_init(&usb_ctx);
- if (ret) {
- ret = -(int) libusb_to_errno(ret);
- ERROR("Unable to init libusb: %i\n", ret);
- goto err_destroy_iiod_client;
- }
-
- libusb_get_device_list(usb_ctx, &device_list);
-
- usb_dev = NULL;
-
- for (i = 0; device_list[i]; i++) {
- libusb_device *dev = device_list[i];
-
- if (bus == libusb_get_bus_number(dev) &&
- address == libusb_get_device_address(dev)) {
- usb_dev = dev;
-
- ret = libusb_open(usb_dev, &hdl);
- /*
- * Workaround for libusb on Windows >= 8.1. A device
- * might appear twice in the list with one device being
- * bogus and only partially initialized. libusb_open()
- * returns LIBUSB_ERROR_NOT_SUPPORTED for such devices,
- * which should never happen for normal devices. So if
- * we find such a device skip it and keep looking.
- */
- if (ret == LIBUSB_ERROR_NOT_SUPPORTED) {
- WARNING("Skipping broken USB device. Please upgrade libusb.\n");
- usb_dev = NULL;
- continue;
- }
-
- break;
- }
- }
-
- libusb_free_device_list(device_list, true);
-
- if (!usb_dev) {
- ret = -ENODEV;
- goto err_libusb_exit;
- }
-
- if (ret) {
- ret = -(int) libusb_to_errno(ret);
- ERROR("Unable to open device\n");
- goto err_libusb_exit;
- }
-
-#if defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x01000016)
- libusb_set_auto_detach_kernel_driver(hdl, true);
-#endif
-
- ret = libusb_claim_interface(hdl, interface);
- if (ret) {
- ret = -(int) libusb_to_errno(ret);
- ERROR("Unable to claim interface %u:%u:%u: %i\n",
- bus, address, interface, ret);
- goto err_libusb_close;
- }
-
- ret = libusb_get_active_config_descriptor(usb_dev, &conf_desc);
- if (ret) {
- ret = -(int) libusb_to_errno(ret);
- ERROR("Unable to get config descriptor: %i\n", ret);
- goto err_libusb_close;
- }
-
- iface = &conf_desc->interface[interface].altsetting[0];
-
- ret = usb_verify_eps(iface);
- if (ret) {
- ERROR("Invalid configuration of endpoints\n");
- goto err_free_config_descriptor;
- }
-
- pdata->nb_ep_couples = iface->bNumEndpoints / 2;
-
- DEBUG("Found %hhu usable i/o endpoint couples\n", pdata->nb_ep_couples);
-
- pdata->io_endpoints = calloc(pdata->nb_ep_couples,
- sizeof(*pdata->io_endpoints));
- if (!pdata->io_endpoints) {
- ERROR("Unable to allocate endpoints\n");
- ret = -ENOMEM;
- goto err_free_config_descriptor;
- }
-
- for (i = 0; i < pdata->nb_ep_couples; i++) {
- struct iio_usb_ep_couple *ep = &pdata->io_endpoints[i];
-
- ep->addr_in = iface->endpoint[i * 2 + 0].bEndpointAddress;
- ep->addr_out = iface->endpoint[i * 2 + 1].bEndpointAddress;
- ep->pipe_id = i;
-
- DEBUG("Couple %i with endpoints 0x%x / 0x%x\n", i,
- ep->addr_in, ep->addr_out);
-
- ep->lock = iio_mutex_create();
- if (!ep->lock) {
- ERROR("Unable to create mutex\n");
- ret = -ENOMEM;
- goto err_free_endpoints;
- }
- }
-
- pdata->ctx = usb_ctx;
- pdata->hdl = hdl;
- pdata->timeout_ms = DEFAULT_TIMEOUT_MS;
- pdata->interface = interface;
-
- ret = usb_io_context_init(&pdata->io_ctx);
- if (ret)
- goto err_free_endpoints;
-
- /* We reserve the first I/O endpoint couple for global operations */
- pdata->io_ctx.ep = &pdata->io_endpoints[0];
- pdata->io_ctx.ep->in_use = true;
-
- ret = usb_reset_pipes(pdata);
- if (ret) {
- iio_strerror(-ret, err_str, sizeof(err_str));
- ERROR("Failed to reset pipes: %s\n", err_str);
- goto err_io_context_exit;
- }
-
- ret = usb_open_pipe(pdata, 0);
- if (ret) {
- iio_strerror(-ret, err_str, sizeof(err_str));
- ERROR("Failed to open control pipe: %s\n", err_str);
- goto err_io_context_exit;
- }
-
- ctx = iiod_client_create_context(pdata->iiod_client, &pdata->io_ctx);
- if (!ctx) {
- ret = -errno;
- goto err_reset_pipes;
- }
-
- libusb_free_config_descriptor(conf_desc);
-
- ctx->name = "usb";
- ctx->ops = &usb_ops;
- ctx->pdata = pdata;
-
- for (i = 0; i < ctx->nb_devices; i++) {
- struct iio_device *dev = ctx->devices[i];
-
- dev->pdata = zalloc(sizeof(*dev->pdata));
- if (!dev->pdata) {
- ERROR("Unable to allocate memory\n");
- ret = -ENOMEM;
- goto err_context_destroy;
- }
-
- ret = usb_io_context_init(&dev->pdata->io_ctx);
- if (ret)
- goto err_context_destroy;
- }
-
- ret = usb_populate_context_attrs(ctx, usb_dev, hdl);
- if (ret < 0)
- goto err_context_destroy;
-
- return ctx;
-
-err_context_destroy:
- iio_context_destroy(ctx);
- errno = -ret;
- return NULL;
-
-err_reset_pipes:
- usb_reset_pipes(pdata); /* Close everything */
-err_io_context_exit:
- usb_io_context_exit(&pdata->io_ctx);
-err_free_endpoints:
- for (i = 0; i < pdata->nb_ep_couples; i++)
- if (pdata->io_endpoints[i].lock)
- iio_mutex_destroy(pdata->io_endpoints[i].lock);
- if (pdata->io_endpoints)
- free(pdata->io_endpoints);
-err_free_config_descriptor:
- libusb_free_config_descriptor(conf_desc);
-err_libusb_close:
- libusb_close(hdl);
-err_libusb_exit:
- libusb_exit(usb_ctx);
-err_destroy_iiod_client:
- iiod_client_destroy(pdata->iiod_client);
-err_destroy_ep_mutex:
- iio_mutex_destroy(pdata->ep_lock);
-err_destroy_mutex:
- iio_mutex_destroy(pdata->lock);
-err_free_pdata:
- free(pdata);
-err_set_errno:
- errno = -ret;
- return NULL;
-}
-
-struct iio_context * usb_create_context_from_uri(const char *uri)
-{
- long bus, address, interface;
- char *end;
- const char *ptr;
-
- if (strncmp(uri, "usb:", sizeof("usb:") - 1) != 0)
- goto err_bad_uri;
-
- ptr = (const char *) ((uintptr_t) uri + sizeof("usb:") - 1);
- if (!isdigit(*ptr))
- goto err_bad_uri;
-
- bus = strtol(ptr, &end, 10);
- if (ptr == end || *end != '.')
- goto err_bad_uri;
-
- ptr = (const char *) ((uintptr_t) end + 1);
- if (!isdigit(*ptr))
- goto err_bad_uri;
-
- address = strtol(ptr, &end, 10);
- if (ptr == end)
- goto err_bad_uri;
-
- if (*end == '\0') {
- interface = 0;
- } else if (*end == '.') {
- ptr = (const char *) ((uintptr_t) end + 1);
- if (!isdigit(*ptr))
- goto err_bad_uri;
-
- interface = strtol(ptr, &end, 10);
- if (ptr == end || *end != '\0')
- goto err_bad_uri;
- } else {
- goto err_bad_uri;
- }
-
- if (bus < 0 || address < 0 || interface < 0)
- goto err_bad_uri;
-
- return usb_create_context((unsigned int) bus,
- (unsigned int) address, (unsigned int) interface);
-
-err_bad_uri:
- ERROR("Bad URI: \'%s\'\n", uri);
- errno = EINVAL;
- return NULL;
-}
-
-static int usb_fill_context_info(struct iio_context_info *info,
- struct libusb_device *dev, struct libusb_device_handle *hdl,
- unsigned int interface)
-{
- struct libusb_device_descriptor desc;
- char manufacturer[64], product[64], serial[64];
- char uri[sizeof("usb:127.255.255")];
- char description[sizeof(manufacturer) + sizeof(product) +
- sizeof(serial) + sizeof("0000:0000 ( ), serial=")];
- int ret;
-
- libusb_get_device_descriptor(dev, &desc);
-
- iio_snprintf(uri, sizeof(uri), "usb:%d.%d.%u",
- libusb_get_bus_number(dev), libusb_get_device_address(dev),
- interface);
-
- if (desc.iManufacturer == 0) {
- manufacturer[0] = '\0';
- } else {
- ret = libusb_get_string_descriptor_ascii(hdl,
- desc.iManufacturer,
- (unsigned char *) manufacturer,
- sizeof(manufacturer));
- if (ret < 0)
- manufacturer[0] = '\0';
- }
-
- if (desc.iProduct == 0) {
- product[0] = '\0';
- } else {
- ret = libusb_get_string_descriptor_ascii(hdl,
- desc.iProduct, (unsigned char *) product,
- sizeof(product));
- if (ret < 0)
- product[0] = '\0';
- }
-
- if (desc.iSerialNumber == 0) {
- serial[0] = '\0';
- } else {
- ret = libusb_get_string_descriptor_ascii(hdl,
- desc.iSerialNumber, (unsigned char *) serial,
- sizeof(serial));
- if (ret < 0)
- serial[0] = '\0';
- }
-
- iio_snprintf(description, sizeof(description),
- "%04x:%04x (%s %s), serial=%s", desc.idVendor,
- desc.idProduct, manufacturer, product, serial);
-
- info->uri = iio_strdup(uri);
- if (!info->uri)
- return -ENOMEM;
-
- info->description = iio_strdup(description);
- if (!info->description)
- return -ENOMEM;
-
- return 0;
-}
-
-struct iio_scan_backend_context {
- libusb_context *ctx;
-};
-
-struct iio_scan_backend_context * usb_context_scan_init(void)
-{
- struct iio_scan_backend_context *ctx;
- int ret;
-
- ctx = malloc(sizeof(*ctx));
- if (!ctx) {
- errno = ENOMEM;
- return NULL;
- }
-
- ret = libusb_init(&ctx->ctx);
- if (ret) {
- free(ctx);
- errno = (int) libusb_to_errno(ret);
- return NULL;
- }
-
- return ctx;
-}
-
-void usb_context_scan_free(struct iio_scan_backend_context *ctx)
-{
- libusb_exit(ctx->ctx);
- free(ctx);
-}
-
-int usb_context_scan(struct iio_scan_backend_context *ctx,
- struct iio_scan_result *scan_result)
-{
- struct iio_context_info **info;
- libusb_device **device_list;
- unsigned int i;
- int ret;
-
- ret = libusb_get_device_list(ctx->ctx, &device_list);
- if (ret < 0)
- return -(int) libusb_to_errno(ret);
-
- for (i = 0; device_list[i]; i++) {
- struct libusb_device_handle *hdl;
- struct libusb_device *dev = device_list[i];
- unsigned int interface = 0;
-
- ret = libusb_open(dev, &hdl);
- if (ret)
- continue;
-
- if (!iio_usb_match_device(dev, hdl, &interface)) {
- info = iio_scan_result_add(scan_result, 1);
- if (!info)
- ret = -ENOMEM;
- else
- ret = usb_fill_context_info(*info, dev, hdl,
- interface);
- }
-
- libusb_close(hdl);
- if (ret < 0)
- goto cleanup_free_device_list;
- }
-
- ret = 0;
-
-cleanup_free_device_list:
- libusb_free_device_list(device_list, true);
- return ret;
-}
diff --git a/utilities.c b/utilities.c
deleted file mode 100644
index 21dbd10..0000000
--- a/utilities.c
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * 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.
- *
- * */
-
-/* Force the XSI version of strerror_r */
-#undef _GNU_SOURCE
-
-#include "iio-config.h"
-#include "iio-private.h"
-
-#include <errno.h>
-#include <locale.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#if defined(_WIN32) || (defined(__USE_XOPEN2K8) && \
- (!defined(__UCLIBC__) || defined(__UCLIBC_HAS_LOCALE__)))
-#define LOCALE_SUPPORT
-#endif
-
-#ifdef LOCALE_SUPPORT
-#if defined(__MINGW32__) || (!defined(_WIN32) && !defined(HAS_NEWLOCALE))
-static int read_double_locale(const char *str, double *val)
-{
- char *end, *old_locale;
- double value;
-
- /* XXX: This is not thread-safe, but it's the only way we have to
- * support locales under MinGW without linking with Visual Studio
- * libraries. */
- old_locale = iio_strdup(setlocale(LC_NUMERIC, NULL));
- if (!old_locale)
- return -ENOMEM;
-
- setlocale(LC_NUMERIC, "C");
- value = strtod(str, &end);
- setlocale(LC_NUMERIC, old_locale);
- free(old_locale);
-
- if (end == str)
- return -EINVAL;
-
- *val = value;
- return 0;
-}
-
-static int write_double_locale(char *buf, size_t len, double val)
-{
- /* XXX: Not thread-safe, see above */
- char *old_locale = iio_strdup(setlocale(LC_NUMERIC, NULL));
- if (!old_locale)
- return -ENOMEM;
-
- setlocale(LC_NUMERIC, "C");
- iio_snprintf(buf, len, "%f", val);
- setlocale(LC_NUMERIC, old_locale);
- free(old_locale);
- return 0;
-}
-#elif defined(_WIN32)
-static int read_double_locale(const char *str, double *val)
-{
- char *end;
- double value;
- _locale_t locale = _create_locale(LC_NUMERIC, "C");
- if (!locale)
- return -ENOMEM;
-
- value = _strtod_l(str, &end, locale);
- _free_locale(locale);
-
- if (end == str)
- return -EINVAL;
-
- *val = value;
- return 0;
-}
-
-static int write_double_locale(char *buf, size_t len, double val)
-{
- _locale_t locale = _create_locale(LC_NUMERIC, "C");
- if (!locale)
- return -ENOMEM;
-
- _snprintf_l(buf, len, "%f", locale, val);
- _free_locale(locale);
- return 0;
-}
-#else
-static int read_double_locale(const char *str, double *val)
-{
- char *end;
- double value;
- locale_t old_locale, new_locale;
-
- new_locale = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0);
- if (!new_locale)
- return -errno;
-
- old_locale = uselocale(new_locale);
-
- value = strtod(str, &end);
- uselocale(old_locale);
- freelocale(new_locale);
-
- if (end == str)
- return -EINVAL;
-
- *val = value;
- return 0;
-}
-
-static int write_double_locale(char *buf, size_t len, double val)
-{
- locale_t old_locale, new_locale;
-
- new_locale = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0);
- if (!new_locale)
- return -errno;
-
- old_locale = uselocale(new_locale);
-
- iio_snprintf(buf, len, "%f", val);
-
- uselocale(old_locale);
- freelocale(new_locale);
- return 0;
-}
-#endif
-#endif
-
-int read_double(const char *str, double *val)
-{
-#ifdef LOCALE_SUPPORT
- return read_double_locale(str, val);
-#else
- char *end;
- double value = strtod(str, &end);
-
- if (end == str)
- return -EINVAL;
-
- *val = value;
- return 0;
-#endif
-}
-
-int write_double(char *buf, size_t len, double val)
-{
-#ifdef LOCALE_SUPPORT
- return write_double_locale(buf, len, val);
-#else
- iio_snprintf(buf, len, "%f", val);
- return 0;
-#endif
-}
-
-void iio_library_get_version(unsigned int *major,
- unsigned int *minor, char git_tag[8])
-{
- if (major)
- *major = LIBIIO_VERSION_MAJOR;
- if (minor)
- *minor = LIBIIO_VERSION_MINOR;
- if (git_tag) {
- strncpy(git_tag, LIBIIO_VERSION_GIT, 8);
- git_tag[7] = '\0';
- }
-}
-
-void iio_strerror(int err, char *buf, size_t len)
-{
-#if defined(_WIN32)
- int ret = strerror_s(buf, len, err);
-#elif defined(HAS_STRERROR_R)
- int ret = strerror_r(err, buf, len);
-#else
- /* no strerror_s, no strerror_r... just use the default message */
- int ret = 0xf7de;
-#endif
- if (ret != 0)
- iio_snprintf(buf, len, "Unknown error %i", err);
-}
-
-char *iio_strdup(const char *str)
-{
-#if defined(_WIN32)
- return _strdup(str);
-#elif defined(HAS_STRDUP)
- return strdup(str);
-#else
- size_t len = strlen(str);
- char *buf = malloc(len + 1);
-
- if (buf)
- memcpy(buf, str, len + 1);
- return buf;
-#endif
-}
diff --git a/xml.c b/xml.c
deleted file mode 100644
index fae5e75..0000000
--- a/xml.c
+++ /dev/null
@@ -1,458 +0,0 @@
-/*
- * 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.
- *
- * */
-
-#include "debug.h"
-#include "iio-private.h"
-
-#include <errno.h>
-#include <libxml/tree.h>
-#include <string.h>
-
-static int add_attr_to_channel(struct iio_channel *chn, xmlNode *n)
-{
- xmlAttr *attr;
- char *name = NULL, *filename = NULL;
- struct iio_channel_attr *attrs;
-
- for (attr = n->properties; attr; attr = attr->next) {
- if (!strcmp((char *) attr->name, "name")) {
- name = iio_strdup((char *) attr->children->content);
- } else if (!strcmp((char *) attr->name, "filename")) {
- filename = iio_strdup((char *) attr->children->content);
- } else {
- WARNING("Unknown field \'%s\' in channel %s\n",
- attr->name, chn->id);
- }
- }
-
- if (!name) {
- ERROR("Incomplete attribute in channel %s\n", chn->id);
- goto err_free;
- }
-
- if (!filename) {
- filename = iio_strdup(name);
- if (!filename)
- goto err_free;
- }
-
- attrs = realloc(chn->attrs, (1 + chn->nb_attrs) *
- sizeof(struct iio_channel_attr));
- if (!attrs)
- goto err_free;
-
- attrs[chn->nb_attrs].filename = filename;
- attrs[chn->nb_attrs++].name = name;
- chn->attrs = attrs;
- return 0;
-
-err_free:
- if (name)
- free(name);
- if (filename)
- free(filename);
- return -1;
-}
-
-static int add_attr_to_device(struct iio_device *dev, xmlNode *n, enum iio_attr_type type)
-{
- xmlAttr *attr;
- char **attrs, *name = NULL;
-
- for (attr = n->properties; attr; attr = attr->next) {
- if (!strcmp((char *) attr->name, "name")) {
- name = iio_strdup((char *) attr->children->content);
- } else {
- WARNING("Unknown field \'%s\' in device %s\n",
- attr->name, dev->id);
- }
- }
-
- if (!name) {
- ERROR("Incomplete attribute in device %s\n", dev->id);
- goto err_free;
- }
-
- switch(type) {
- case IIO_ATTR_TYPE_DEBUG:
- attrs = realloc(dev->debug_attrs,
- (1 + dev->nb_debug_attrs) * sizeof(char *));
- break;
- case IIO_ATTR_TYPE_DEVICE:
- attrs = realloc(dev->attrs,
- (1 + dev->nb_attrs) * sizeof(char *));
- break;
- case IIO_ATTR_TYPE_BUFFER:
- attrs = realloc(dev->buffer_attrs,
- (1 + dev->nb_buffer_attrs) * sizeof(char *));
- break;
- default:
- attrs = NULL;
- break;
- }
- if (!attrs)
- goto err_free;
-
- switch(type) {
- case IIO_ATTR_TYPE_DEBUG:
- attrs[dev->nb_debug_attrs++] = name;
- dev->debug_attrs = attrs;
- break;
- case IIO_ATTR_TYPE_DEVICE:
- attrs[dev->nb_attrs++] = name;
- dev->attrs = attrs;
- break;
- case IIO_ATTR_TYPE_BUFFER:
- attrs[dev->nb_buffer_attrs++] = name;
- dev->buffer_attrs = attrs;
- break;
- }
-
- return 0;
-
-err_free:
- if (name)
- free(name);
- return -1;
-}
-
-static void setup_scan_element(struct iio_channel *chn, xmlNode *n)
-{
- xmlAttr *attr;
-
- for (attr = n->properties; attr; attr = attr->next) {
- const char *name = (const char *) attr->name,
- *content = (const char *) attr->children->content;
- if (!strcmp(name, "index")) {
- chn->index = atol(content);
- } else if (!strcmp(name, "format")) {
- char e, s;
- if (strchr(content, 'X')) {
- sscanf(content, "%ce:%c%u/%uX%u>>%u", &e, &s,
- &chn->format.bits,
- &chn->format.length,
- &chn->format.repeat,
- &chn->format.shift);
- } else {
- chn->format.repeat = 1;
- sscanf(content, "%ce:%c%u/%u>>%u", &e, &s,
- &chn->format.bits,
- &chn->format.length,
- &chn->format.shift);
- }
- chn->format.is_be = e == 'b';
- chn->format.is_signed = (s == 's' || s == 'S');
- chn->format.is_fully_defined = (s == 'S' || s == 'U' ||
- chn->format.bits == chn->format.length);
- } else if (!strcmp(name, "scale")) {
- chn->format.with_scale = true;
- chn->format.scale = atof(content);
- } else {
- WARNING("Unknown attribute \'%s\' in <scan-element>\n",
- name);
- }
- }
-}
-
-static struct iio_channel * create_channel(struct iio_device *dev, xmlNode *n)
-{
- xmlAttr *attr;
- struct iio_channel *chn = zalloc(sizeof(*chn));
- if (!chn)
- return NULL;
-
- chn->dev = dev;
-
- /* Set the default index value < 0 (== no index) */
- chn->index = -ENOENT;
-
- for (attr = n->properties; attr; attr = attr->next) {
- const char *name = (const char *) attr->name,
- *content = (const char *) attr->children->content;
- if (!strcmp(name, "name")) {
- chn->name = iio_strdup(content);
- } else if (!strcmp(name, "id")) {
- chn->id = iio_strdup(content);
- } else if (!strcmp(name, "type")) {
- if (!strcmp(content, "output"))
- chn->is_output = true;
- else if (strcmp(content, "input"))
- WARNING("Unknown channel type %s\n", content);
- } else {
- WARNING("Unknown attribute \'%s\' in <channel>\n",
- name);
- }
- }
-
- if (!chn->id) {
- ERROR("Incomplete <attribute>\n");
- goto err_free_channel;
- }
-
- for (n = n->children; n; n = n->next) {
- if (!strcmp((char *) n->name, "attribute")) {
- if (add_attr_to_channel(chn, n) < 0)
- goto err_free_channel;
- } else if (!strcmp((char *) n->name, "scan-element")) {
- chn->is_scan_element = true;
- setup_scan_element(chn, n);
- } else if (strcmp((char *) n->name, "text")) {
- WARNING("Unknown children \'%s\' in <channel>\n",
- n->name);
- continue;
- }
- }
-
- iio_channel_init_finalize(chn);
-
- return chn;
-
-err_free_channel:
- free_channel(chn);
- return NULL;
-}
-
-static struct iio_device * create_device(struct iio_context *ctx, xmlNode *n)
-{
- xmlAttr *attr;
- struct iio_device *dev = zalloc(sizeof(*dev));
- if (!dev)
- return NULL;
-
- dev->ctx = ctx;
-
- for (attr = n->properties; attr; attr = attr->next) {
- if (!strcmp((char *) attr->name, "name")) {
- dev->name = iio_strdup(
- (char *) attr->children->content);
- } else if (!strcmp((char *) attr->name, "id")) {
- dev->id = iio_strdup((char *) attr->children->content);
- } else {
- WARNING("Unknown attribute \'%s\' in <device>\n",
- attr->name);
- }
- }
-
- if (!dev->id) {
- ERROR("Unable to read device ID\n");
- goto err_free_device;
- }
-
- for (n = n->children; n; n = n->next) {
- if (!strcmp((char *) n->name, "channel")) {
- struct iio_channel **chns,
- *chn = create_channel(dev, n);
- if (!chn) {
- ERROR("Unable to create channel\n");
- goto err_free_device;
- }
-
- chns = realloc(dev->channels, (1 + dev->nb_channels) *
- sizeof(struct iio_channel *));
- if (!chns) {
- ERROR("Unable to allocate memory\n");
- free(chn);
- goto err_free_device;
- }
-
- chns[dev->nb_channels++] = chn;
- dev->channels = chns;
- } else if (!strcmp((char *) n->name, "attribute")) {
- if (add_attr_to_device(dev, n, IIO_ATTR_TYPE_DEVICE) < 0)
- goto err_free_device;
- } else if (!strcmp((char *) n->name, "debug-attribute")) {
- if (add_attr_to_device(dev, n, IIO_ATTR_TYPE_DEBUG) < 0)
- goto err_free_device;
- } else if (!strcmp((char *) n->name, "buffer-attribute")) {
- if (add_attr_to_device(dev, n, IIO_ATTR_TYPE_BUFFER) < 0)
- goto err_free_device;
- } else if (strcmp((char *) n->name, "text")) {
- WARNING("Unknown children \'%s\' in <device>\n",
- n->name);
- continue;
- }
- }
-
- dev->words = (dev->nb_channels + 31) / 32;
- if (dev->words) {
- dev->mask = calloc(dev->words, sizeof(*dev->mask));
- if (!dev->mask) {
- errno = ENOMEM;
- goto err_free_device;
- }
- }
-
- return dev;
-
-err_free_device:
- free_device(dev);
- return NULL;
-}
-
-static struct iio_context * xml_clone(const struct iio_context *ctx)
-{
- return xml_create_context_mem(ctx->xml, strlen(ctx->xml));
-}
-
-static const struct iio_backend_ops xml_ops = {
- .clone = xml_clone,
-};
-
-static int parse_context_attr(struct iio_context *ctx, xmlNode *n)
-{
- xmlAttr *attr;
- const char *name = NULL, *value = NULL;
-
- for (attr = n->properties; attr; attr = attr->next) {
- if (!strcmp((const char *) attr->name, "name")) {
- name = (const char *) attr->children->content;
- } else if (!strcmp((const char *) attr->name, "value")) {
- value = (const char *) attr->children->content;
- }
- }
-
- if (!name || !value)
- return -EINVAL;
- else
- return iio_context_add_attr(ctx, name, value);
-}
-
-static struct iio_context * iio_create_xml_context_helper(xmlDoc *doc)
-{
- unsigned int i;
- xmlNode *root, *n;
- xmlAttr *attr;
- int err = -ENOMEM;
- struct iio_context *ctx = zalloc(sizeof(*ctx));
- if (!ctx)
- goto err_set_errno;
-
- ctx->name = "xml";
- ctx->ops = &xml_ops;
-
- root = xmlDocGetRootElement(doc);
- if (strcmp((char *) root->name, "context")) {
- ERROR("Unrecognized XML file\n");
- err = -EINVAL;
- goto err_free_ctx;
- }
-
- for (attr = root->properties; attr; attr = attr->next) {
- if (!strcmp((char *) attr->name, "description"))
- ctx->description = iio_strdup(
- (char *) attr->children->content);
- else if (strcmp((char *) attr->name, "name"))
- WARNING("Unknown parameter \'%s\' in <context>\n",
- (char *) attr->children->content);
- }
-
- for (n = root->children; n; n = n->next) {
- struct iio_device **devs, *dev;
-
- if (!strcmp((char *) n->name, "context-attribute")) {
- err = parse_context_attr(ctx, n);
- if (err)
- goto err_free_devices;
- else
- continue;
- } else if (strcmp((char *) n->name, "device")) {
- if (strcmp((char *) n->name, "text"))
- WARNING("Unknown children \'%s\' in "
- "<context>\n", n->name);
- continue;
- }
-
- dev = create_device(ctx, n);
- if (!dev) {
- ERROR("Unable to create device\n");
- goto err_free_devices;
- }
-
- devs = realloc(ctx->devices, (1 + ctx->nb_devices) *
- sizeof(struct iio_device *));
- if (!devs) {
- ERROR("Unable to allocate memory\n");
- free(dev);
- goto err_free_devices;
- }
-
- devs[ctx->nb_devices++] = dev;
- ctx->devices = devs;
- }
-
- err = iio_context_init(ctx);
- if (err)
- goto err_free_devices;
-
- return ctx;
-
-err_free_devices:
- for (i = 0; i < ctx->nb_devices; i++)
- free_device(ctx->devices[i]);
- if (ctx->nb_devices)
- free(ctx->devices);
- for (i = 0; i < ctx->nb_attrs; i++) {
- free(ctx->attrs[i]);
- free(ctx->values[i]);
- }
- free(ctx->attrs);
- free(ctx->values);
-err_free_ctx:
- free(ctx);
-err_set_errno:
- errno = -err;
- return NULL;
-}
-
-struct iio_context * xml_create_context(const char *xml_file)
-{
- struct iio_context *ctx;
- xmlDoc *doc;
-
- LIBXML_TEST_VERSION;
-
- doc = xmlReadFile(xml_file, NULL, XML_PARSE_DTDVALID);
- if (!doc) {
- ERROR("Unable to parse XML file\n");
- errno = EINVAL;
- return NULL;
- }
-
- ctx = iio_create_xml_context_helper(doc);
- xmlFreeDoc(doc);
- return ctx;
-}
-
-struct iio_context * xml_create_context_mem(const char *xml, size_t len)
-{
- struct iio_context *ctx;
- xmlDoc *doc;
-
- LIBXML_TEST_VERSION;
-
- doc = xmlReadMemory(xml, (int) len, NULL, NULL, XML_PARSE_DTDVALID);
- if (!doc) {
- ERROR("Unable to parse XML file\n");
- errno = EINVAL;
- return NULL;
- }
-
- ctx = iio_create_xml_context_helper(doc);
- xmlFreeDoc(doc);
- return ctx;
-}
diff --git a/xml/ad5541a.xml b/xml/ad5541a.xml
deleted file mode 100644
index 2837870..0000000
--- a/xml/ad5541a.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE context [
- <!ELEMENT context (device)*>
- <!ELEMENT device (channel | attribute)*>
- <!ELEMENT channel (attribute)*>
- <!ELEMENT attribute EMPTY>
- <!ATTLIST context name CDATA #REQUIRED>
- <!ATTLIST device id CDATA #REQUIRED name CDATA #IMPLIED>
- <!ATTLIST channel id CDATA #REQUIRED type CDATA #REQUIRED name CDATA #IMPLIED>
- <!ATTLIST attribute name CDATA #REQUIRED>
-]>
-<context name="local">
- <device id="iio:device0" name="ad5541a" >
- <channel id="voltage0" type="output" >
- <attribute name="raw" />
- <attribute name="scale" />
- </channel>
- </device>
-</context>
diff --git a/xml/ad5628-1.xml b/xml/ad5628-1.xml
deleted file mode 100644
index bafa7b7..0000000
--- a/xml/ad5628-1.xml
+++ /dev/null
@@ -1,71 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE context [
- <!ELEMENT context (device)*>
- <!ELEMENT device (channel | attribute)*>
- <!ELEMENT channel (attribute)*>
- <!ELEMENT attribute EMPTY>
- <!ATTLIST context name CDATA #REQUIRED>
- <!ATTLIST device id CDATA #REQUIRED name CDATA #IMPLIED>
- <!ATTLIST channel id CDATA #REQUIRED type CDATA #REQUIRED name CDATA #IMPLIED>
- <!ATTLIST attribute name CDATA #REQUIRED>
-]>
-<context name="local">
- <device id="iio:device0" name="ad5628-1" >
- <channel id="voltage0" type="output" >
- <attribute name="powerdown_mode" />
- <attribute name="powerdown" />
- <attribute name="raw" />
- <attribute name="scale" />
- <attribute name="powerdown_mode_available" />
- </channel>
- <channel id="voltage1" type="output" >
- <attribute name="powerdown_mode" />
- <attribute name="powerdown" />
- <attribute name="raw" />
- <attribute name="scale" />
- <attribute name="powerdown_mode_available" />
- </channel>
- <channel id="voltage2" type="output" >
- <attribute name="powerdown" />
- <attribute name="powerdown_mode" />
- <attribute name="raw" />
- <attribute name="scale" />
- <attribute name="powerdown_mode_available" />
- </channel>
- <channel id="voltage3" type="output" >
- <attribute name="powerdown" />
- <attribute name="powerdown_mode" />
- <attribute name="raw" />
- <attribute name="scale" />
- <attribute name="powerdown_mode_available" />
- </channel>
- <channel id="voltage4" type="output" >
- <attribute name="powerdown_mode" />
- <attribute name="powerdown" />
- <attribute name="raw" />
- <attribute name="scale" />
- <attribute name="powerdown_mode_available" />
- </channel>
- <channel id="voltage5" type="output" >
- <attribute name="powerdown_mode" />
- <attribute name="powerdown" />
- <attribute name="raw" />
- <attribute name="scale" />
- <attribute name="powerdown_mode_available" />
- </channel>
- <channel id="voltage6" type="output" >
- <attribute name="powerdown" />
- <attribute name="powerdown_mode" />
- <attribute name="raw" />
- <attribute name="scale" />
- <attribute name="powerdown_mode_available" />
- </channel>
- <channel id="voltage7" type="output" >
- <attribute name="powerdown" />
- <attribute name="powerdown_mode" />
- <attribute name="raw" />
- <attribute name="scale" />
- <attribute name="powerdown_mode_available" />
- </channel>
- </device>
-</context>
diff --git a/xml/ad7091r.xml b/xml/ad7091r.xml
deleted file mode 100644
index be25580..0000000
--- a/xml/ad7091r.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE context [
- <!ELEMENT context (device)*>
- <!ELEMENT device (channel | attribute)*>
- <!ELEMENT channel (attribute)*>
- <!ELEMENT attribute EMPTY>
- <!ATTLIST context name CDATA #REQUIRED>
- <!ATTLIST device id CDATA #REQUIRED name CDATA #IMPLIED>
- <!ATTLIST channel id CDATA #REQUIRED type CDATA #REQUIRED name CDATA #IMPLIED>
- <!ATTLIST attribute name CDATA #REQUIRED>
-]>
-<context name="local">
- <device id="iio:device0" name="ad7091r" >
- <attribute name="in_voltage_scale" />
- </device>
-</context>
diff --git a/xml/adis16488.xml b/xml/adis16488.xml
deleted file mode 100644
index 5b9e354..0000000
--- a/xml/adis16488.xml
+++ /dev/null
@@ -1,86 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE context [
- <!ELEMENT context (device)*>
- <!ELEMENT device (channel | attribute)*>
- <!ELEMENT channel (attribute)*>
- <!ELEMENT attribute EMPTY>
- <!ATTLIST context name CDATA #REQUIRED>
- <!ATTLIST device id CDATA #REQUIRED name CDATA #IMPLIED>
- <!ATTLIST channel id CDATA #REQUIRED type CDATA #REQUIRED name CDATA #IMPLIED>
- <!ATTLIST attribute name CDATA #REQUIRED>
-]>
-<context name="local">
- <device id="iio:device0" name="adis16488" >
- <channel id="accel_x" type="input" >
- <attribute name="calibbias" />
- <attribute name="calibscale" />
- <attribute name="filter_low_pass_3db_frequency" />
- <attribute name="raw" />
- <attribute name="scale" />
- </channel>
- <channel id="accel_y" type="input" >
- <attribute name="calibbias" />
- <attribute name="calibscale" />
- <attribute name="filter_low_pass_3db_frequency" />
- <attribute name="raw" />
- <attribute name="scale" />
- </channel>
- <channel id="accel_z" type="input" >
- <attribute name="calibbias" />
- <attribute name="calibscale" />
- <attribute name="filter_low_pass_3db_frequency" />
- <attribute name="raw" />
- <attribute name="scale" />
- </channel>
- <channel id="anglvel_x" type="input" >
- <attribute name="calibbias" />
- <attribute name="calibscale" />
- <attribute name="filter_low_pass_3db_frequency" />
- <attribute name="raw" />
- <attribute name="scale" />
- </channel>
- <channel id="anglvel_y" type="input" >
- <attribute name="calibbias" />
- <attribute name="calibscale" />
- <attribute name="filter_low_pass_3db_frequency" />
- <attribute name="raw" />
- <attribute name="scale" />
- </channel>
- <channel id="anglvel_z" type="input" >
- <attribute name="calibbias" />
- <attribute name="calibscale" />
- <attribute name="filter_low_pass_3db_frequency" />
- <attribute name="raw" />
- <attribute name="scale" />
- </channel>
- <channel id="magn_x" type="input" >
- <attribute name="calibbias" />
- <attribute name="filter_low_pass_3db_frequency" />
- <attribute name="raw" />
- <attribute name="scale" />
- </channel>
- <channel id="magn_y" type="input" >
- <attribute name="calibbias" />
- <attribute name="filter_low_pass_3db_frequency" />
- <attribute name="raw" />
- <attribute name="scale" />
- </channel>
- <channel id="magn_z" type="input" >
- <attribute name="calibbias" />
- <attribute name="filter_low_pass_3db_frequency" />
- <attribute name="raw" />
- <attribute name="scale" />
- </channel>
- <channel id="pressure0" type="input" >
- <attribute name="calibbias" />
- <attribute name="raw" />
- <attribute name="scale" />
- </channel>
- <channel id="temp0" type="input" >
- <attribute name="offset" />
- <attribute name="raw" />
- <attribute name="scale" />
- </channel>
- <attribute name="sampling_frequency" />
- </device>
-</context>