├── .codespell-ignore.txt ├── .github ├── CODEOWNERS ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── codespell.yml │ └── freebsd.yml ├── .gitignore ├── .prospector.yml ├── .pylintrc ├── CI ├── azure │ ├── README.txt │ ├── build_mingw.sh │ ├── check_README_BUILD.sh │ ├── check_kernel.sh │ ├── ci-ubuntu.sh │ ├── generateDocumentationAndDeploy.sh.in │ ├── macos_tar_fixup.sh │ ├── prepare_assets.sh │ └── windows_build_deps.cmd ├── build_win_msvc.ps1 ├── generate_exe.ps1 ├── publish_deps.ps1 └── travis │ ├── inside_docker.sh │ └── lib.sh ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── COPYING.txt ├── COPYING_GPL.txt ├── COPYING_MIT.txt ├── Contributors.md ├── Distribution.xml.cmakein ├── Doxyfile.in ├── README.md ├── README_BUILD.md ├── README_DEVELOPERS.md ├── artifact_manifest.txt.cmakein ├── attr.c ├── attr.h ├── azure-pipelines.yml ├── backend.c ├── bindings ├── CMakeLists.txt ├── cpp │ ├── CMakeLists.txt │ ├── examples │ │ └── iiopp-enum.cpp │ └── iio.hpp ├── csharp │ ├── .gitignore │ ├── .vscode │ │ └── tasks.json │ ├── AssemblyInfo.cs.in │ ├── Attr.cs │ ├── Block.cs │ ├── CMakeLists.txt │ ├── Channel.cs │ ├── ChannelsMask.cs │ ├── Context.cs │ ├── Device.cs │ ├── Doxyfile.in │ ├── EventStream.cs │ ├── IIOEvent.cs │ ├── IOBuffer.cs │ ├── IioLib.cs │ ├── Scan.cs │ ├── Stream.cs │ ├── Trigger.cs │ ├── examples │ │ ├── ExampleIIOEvent.cs │ │ └── ExampleProgram.cs │ ├── key.snk │ ├── libiio-sharp.dll.config.cmakein │ ├── libiio-sharp.pc.cmakein │ └── mainpage.dox └── python │ ├── .gitignore │ ├── CMakeLists.txt │ ├── README.md │ ├── doc │ ├── .gitignore │ ├── buffer.rst │ ├── channel.rst │ ├── conf.py.in │ ├── context.rst │ ├── device.rst │ ├── examples.rst │ ├── iio_attr.rst │ ├── iio_info.rst │ ├── iio_readdev.rst │ ├── iio_writedev.rst │ ├── index.rst │ └── trigger.rst │ ├── examples │ ├── iio_attr.py │ ├── iio_info.py │ ├── iio_readdev.py │ └── iio_writedev.py │ ├── iio.py │ └── setup.py.cmakein ├── block.c ├── buffer.c ├── channel.c ├── cmake ├── CheckCaseSensitiveFileSystem.cmake ├── DarwinPackaging.cmake ├── Install.cmake ├── LinuxPackaging.cmake ├── Utilities.cmake ├── add_requirements2tar.sh.in └── cmake_uninstall.cmake.in ├── compat.c ├── context.c ├── deps ├── README.txt ├── libini │ ├── .gitignore │ ├── .gitrepo │ ├── CMakeLists.txt │ ├── LICENSE.txt │ ├── example │ │ ├── Makefile │ │ ├── test.c │ │ └── test.ini │ ├── ini.h │ ├── libini.c │ ├── libini.pc.cmakein │ └── python │ │ ├── ini.py │ │ └── setup.py.cmakein ├── mdns │ ├── .clang-format │ ├── .gitattributes │ ├── .github │ │ └── FUNDING.yml │ ├── .gitignore │ ├── .gitrepo │ ├── CHANGELOG │ ├── CMakeLists.txt │ ├── LICENSE │ ├── README.md │ ├── cmake │ │ └── Config.cmake.in │ ├── mdns.c │ └── mdns.h └── wingetopt │ ├── .gitignore │ ├── .gitrepo │ ├── CMakeLists.txt │ ├── LICENSE │ ├── README.md │ ├── meson.build │ └── src │ ├── getopt.c │ └── getopt.h ├── device.c ├── dns_sd.c ├── dns_sd.h ├── dns_sd_avahi.c ├── dns_sd_bonjour.c ├── dns_sd_windows.c ├── doc ├── codemodel.svg ├── html │ └── img │ │ ├── ADI_Logo_AWP.png │ │ ├── Chromium-OS-Logo.png │ │ ├── GNURadio_logo.png │ │ ├── PyADI-IIO_Logo_72.png │ │ ├── ez.png │ │ ├── favicon.ico │ │ ├── fb.png │ │ ├── gp.png │ │ ├── ig.png │ │ ├── iio_logo.png │ │ ├── legato_logo.png │ │ ├── li.png │ │ ├── mangOH_logo.png │ │ ├── mathworks_logo.png │ │ ├── osc128.png │ │ ├── scopy.png │ │ ├── sdrangel.png │ │ ├── ss.png │ │ ├── style.css │ │ ├── sw.png │ │ ├── tw.png │ │ ├── yk.png │ │ └── yt.png ├── index.html.in └── template │ └── footer.html ├── dynamic-unix.c ├── dynamic-windows.c ├── dynamic.c ├── dynamic.h ├── events.c ├── examples ├── .gitignore ├── CMakeLists.txt ├── README.md ├── ad9361-iiostream.c ├── ad9371-iiostream.c ├── adrv9002-iiostream.c ├── adrv9009-iiostream.c ├── dummy-iiostream.c ├── iio-monitor.c ├── iio_adi_xflow_check.c ├── iiostream-common.c └── iiostream-common.h ├── iio-compat.h ├── iio-config.h.cmakein ├── iio-private.h ├── iiod-client.c ├── iiod-responder.c ├── iiod-responder.h ├── iiod ├── .gitignore ├── CMakeLists.txt ├── debug.h ├── dns-sd.c ├── dns-sd.h ├── iiod.c ├── init │ ├── iiod.conf.cmakein │ ├── iiod.init.cmakein │ └── iiod.service.cmakein ├── interpreter.c ├── lexer.l ├── network.c ├── ops.c ├── ops.h ├── parser.y ├── queue.h ├── responder.c ├── rw.c ├── serial.c ├── thread-pool.c ├── thread-pool.h ├── usb-dmabuf.c └── usbd.c ├── include └── iio │ ├── iio-backend.h │ ├── iio-debug.h │ ├── iio-lock.h │ ├── iio.h │ └── iiod-client.h ├── libiio.iss.cmakein ├── libiio.pc.cmakein ├── libiio.rules.cmakein ├── library.c ├── local-dmabuf.c ├── local-mmap.c ├── local.c ├── local.h ├── lock-dummy.c ├── lock-windows.c ├── lock.c ├── mainpage.dox ├── man ├── CMakeLists.txt ├── README.md ├── iio_attr.1.in ├── iio_common_cmds.1 ├── iio_common_footer.1 ├── iio_common_opts.1 ├── iio_genxml.1.in ├── iio_info.1.in ├── iio_reg.1.in ├── iio_rwdev.1.in ├── iio_stresstest.1.in ├── iiod.1.in ├── make_man.sh.in └── make_util_pages.sh ├── mask.c ├── network-unix.c ├── network-windows.c ├── network.c ├── network.h ├── properties.rc.cmakein ├── scan.c ├── serial.c ├── sort.c ├── sort.h ├── stream.c ├── task.c ├── tinyiiod ├── CMakeLists.txt ├── tinyiiod.c └── tinyiiod.h ├── usb.c ├── utilities.c ├── utils ├── .gitignore ├── CMakeLists.txt ├── gen_code.c ├── gen_code.h ├── iio_attr.c ├── iio_common.c ├── iio_common.h ├── iio_event.c ├── iio_genxml.c ├── iio_info.c ├── iio_reg.c ├── iio_rwdev.c └── iio_stresstest.c ├── xml.c └── xml ├── ad5541a.xml ├── ad5628-1.xml ├── ad7091r.xml └── adis16488.xml /.codespell-ignore.txt: -------------------------------------------------------------------------------- 1 | SOM 2 | som 3 | mitre 4 | mis 5 | tread 6 | elease 7 | tREAD 8 | tRead 9 | tRead 10 | thid 11 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # This document lists the code owners for libiio repo sources, and it is used 2 | # whenever Pull Requests are created, in next way: 3 | # - People listed as CODEOWNERS are automatically added as reviewers to all 4 | # PRs open to branches containing this file, depending on the changed folders. 5 | # - In addition to Code Owners, other reviewers can be added. 6 | # - There can be different code owners for different branches. 7 | # - PRs will require the approval of at least one code owner. 8 | # 9 | # For more details, you can refer to 10 | # https://github.blog/2017-07-06-introducing-code-owners/ 11 | # 12 | # The format of CODEOWNERS is: + 13 | # In case of multiple matches, the last pattern matched will take precedence. 14 | 15 | ##### Global code owners (for folders with no later match) ##### 16 | * cristina.suteu@analog.com dan.nechita@analog.com michael.hennerich@analog.com 17 | 18 | ##### Code owners for CI related files/folders ##### 19 | /CI/ cristina.suteu@analog.com dan.nechita@analog.com michael.hennerich@analog.com stefan.raus@analog.com andreea.andrisan@analog.com 20 | azure-pipelines.yml cristina.suteu@analog.com dan.nechita@analog.com michael.hennerich@analog.com stefan.raus@analog.com andreea.andrisan@analog.com 21 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## PR Description 2 | 3 | - Please replace this comment with a summary of your changes, and add any context 4 | necessary to understand them. List any dependencies required for this change. 5 | - To check the checkboxes below, insert a 'x' between square brackets (without 6 | any space), or simply check them after publishing the PR. 7 | - If you changes include a breaking change, please specify dependent PRs in the 8 | description and try to push all related PRs simultaneously. 9 | 10 | ## PR Type 11 | - [ ] Bug fix (a change that fixes an issue) 12 | - [ ] New feature (a change that adds new functionality) 13 | - [ ] Breaking change (a change that affects other repos or cause CIs to fail) 14 | 15 | ## PR Checklist 16 | - [ ] I have conducted a self-review of my own code changes 17 | - [ ] I have commented new code, particulary complex or unclear areas 18 | - [ ] I have checked that I did not intoduced new warnings or errors (CI output) 19 | - [ ] I have checked that components that use libiio did not get broken 20 | - [ ] I have updated the documentation accordingly (GitHub Pages, READMEs, etc) 21 | -------------------------------------------------------------------------------- /.github/workflows/codespell.yml: -------------------------------------------------------------------------------- 1 | # GitHub Action to automate the identification of common misspellings in text files. 2 | # https://github.com/codespell-project/actions-codespell 3 | # https://github.com/codespell-project/codespell 4 | name: codespell 5 | on: 6 | push: 7 | branches: 8 | - main 9 | - master 10 | pull_request: 11 | branches: 12 | - main 13 | - master 14 | 15 | permissions: 16 | contents: read # to fetch code (actions/checkout) 17 | jobs: 18 | codespell: 19 | name: Check for spelling errors 20 | runs-on: ubuntu-latest 21 | steps: 22 | - uses: actions/checkout@v3 23 | - uses: codespell-project/actions-codespell@v1 # v1.0 24 | with: 25 | check_filenames: true 26 | skip: .git,deps 27 | ignore_words_file: .codespell-ignore.txt 28 | -------------------------------------------------------------------------------- /.github/workflows/freebsd.yml: -------------------------------------------------------------------------------- 1 | 2 | name: FreeBSD Test 3 | 4 | on: [push, pull_request] 5 | 6 | jobs: 7 | build: 8 | runs-on: ubuntu-latest 9 | timeout-minutes: 30 10 | strategy: 11 | fail-fast: false 12 | matrix: 13 | os: ["13.4"] 14 | name: Test FreeBSD 15 | steps: 16 | - uses: actions/checkout@v3 17 | - name: Install libiio dependencies of FreeBSD 18 | id: test 19 | uses: vmactions/freebsd-vm@v1 20 | with: 21 | release: ${{ matrix.os }} 22 | usesh: true 23 | prepare: | 24 | pkg update 25 | pkg install -y git cmake ninja libxml2 bison flex libserialport avahi doxygen graphviz 26 | run: | 27 | mkdir build 28 | cd build 29 | cmake .. -DWITH_SERIAL_BACKEND=ON 30 | make 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.so.* 2 | *.so 3 | *.o 4 | *.plist 5 | obj-* 6 | *.deb 7 | 8 | *.swp 9 | 10 | libiio.iss 11 | libiio.pc 12 | 13 | CMakeCache.txt 14 | CMakeFiles 15 | cmake_install.cmake 16 | install_manifest.txt 17 | Makefile 18 | build/ 19 | 20 | Doxyfile 21 | doxygen_sqlite3.db 22 | -------------------------------------------------------------------------------- /.prospector.yml: -------------------------------------------------------------------------------- 1 | # prospector configuration file 2 | 3 | --- 4 | output-format: grouped 5 | strictness: veryhigh 6 | doc-warnings: true 7 | test-warnings: true 8 | member-warnings: true 9 | 10 | frosted: 11 | run: false 12 | 13 | pyroma: 14 | run: false 15 | 16 | mypy: 17 | run: false 18 | 19 | mccabe: 20 | run: false 21 | 22 | pylint: 23 | run: false 24 | 25 | pydocroma: 26 | run: true 27 | 28 | pyflakes: 29 | run: true 30 | 31 | pep8: 32 | run: true 33 | disable: [ 34 | N811, # false negatives from from ctypes import 35 | E501, # Line-length, already controlled by pylint 36 | E302, # expected 2 blank lines, found 1, controlled by black 37 | ] 38 | 39 | pep257: 40 | run: true 41 | # see http://pep257.readthedocs.io/en/latest/error_codes.html 42 | disable: [ 43 | # numpy convention 44 | D107, # Missing docstring in __init__ 45 | D203, # 1 blank line required before class docstring 46 | # conflicts with D0211, No blank lines allowed before class docstring 47 | D205, # 1 blank line required between summary line and description 48 | D212, # Multi-line docstring summary should start at the first line 49 | # Conflictes with D213 / Multi-line docstring summary should start at the second line 50 | D213, # Multi-line docstring summary should start at the second line 51 | D402, # First line should not be the function's "signature" 52 | # conflicts with D213, Multi-line docstring summary should start at the second line 53 | D406, # Section name should end with a newline 54 | D407, # Missing dashed underline after section 55 | D413, # Missing blank line after last section 56 | ] 57 | -------------------------------------------------------------------------------- /CI/azure/README.txt: -------------------------------------------------------------------------------- 1 | libiio Windows binary snapshot - README 2 | 3 | ********************************************************************* 4 | * The latest version of this snapshot can always be downloaded at: * 5 | * https://github.com/analogdevicesinc/libiio * 6 | ********************************************************************* 7 | 8 | In this archive, you should find the following directories: 9 | o ./include : Common include files 10 | o ./Windows-MinGW-W64 : 64-bit binaries compiled by the MinGW toolchain 11 | o ./Windows-VS-2019-x64 : 64-bit binaries compiled by the MicroSoft toolchain, VS-2019 12 | o ./Windows-VS-2022-x64 : 64-bit binaries compiled by the MicroSoft toolchain, VS-2022 13 | 14 | o Visual Studio: 15 | - Open existing or create a new project for your application 16 | - Copy iio.h, from the include\ directory, into your project and make sure that 17 | the location where the file reside appears in the 'Additional Include 18 | Directories' section (Configuration Properties -> C/C++ -> General). 19 | - Copy the relevant .lib file from Windows-VS-2019-x64\ or Windows-VS-2022-x64\ and add 'libiio.lib' to 20 | your 'Additional Dependencies' (Configuration Properties -> Linker -> Input) 21 | Also make sure that the directory where libiio.lib resides is added to 22 | 'Additional Library Directories' (Configuration Properties -> Linker 23 | -> General) 24 | - If you use the static version of the libiio library, make sure that 25 | 'Runtime Library' is set to 'Multi-threaded DLL (/MD)' (Configuration 26 | Properties -> C/C++ -> Code Generation). 27 | - Compile and run your application. If you use the DLL version of libiio, 28 | remember that you need to have a copy of the DLL either in the runtime 29 | directory or in system32 30 | 31 | o WDK/DDK: 32 | - The following is an example of a sources files that you can use to compile 33 | a libiio 1.0 based console application. In this sample ..\libiio\ is the 34 | directory where you would have copied libiio.h as well as the relevant 35 | libiio.lib 36 | 37 | TARGETNAME=your_app 38 | TARGETTYPE=PROGRAM 39 | USE_MSVCRT=1 40 | UMTYPE=console 41 | INCLUDES=..\libiio;$(DDK_INC_PATH) 42 | TARGETLIBS=..\libiio\libiio.lib 43 | SOURCES=your_app.c 44 | 45 | o MinGW/cygwin 46 | - Copy iio.h, from include/ to your default include directory, 47 | and copy the MinGW32/ or MinGW64/ .a files to your default library directory. 48 | Or, if you don't want to use the default locations, make sure that you feed 49 | the relevant -I and -L options to the compiler. 50 | - Add the '-liio' linker option when compiling. 51 | 52 | o Additional information: 53 | - The libiio API documentation can be accessed at: 54 | http://analogdevicesinc.github.io/libiio/ 55 | - For some libiio samples (including source), please have a look in examples/ 56 | and tests/ directories 57 | - The MinGW and MS generated DLLs are fully interchangeable, provided that you 58 | use the import libs provided or generate one from the .def also provided. 59 | - If you find any issue, please visit 60 | http://analogdevicesinc.github.io/libiio/ 61 | and check the Issues section 62 | -------------------------------------------------------------------------------- /CI/azure/build_mingw.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash.exe 2 | set -xe 3 | 4 | init_env() { 5 | # Define architecture and prefix 6 | export ARCH=x86_64 7 | export MINGW_VERSION=mingw64 8 | 9 | # Set up compilers and tools using absolute Windows paths 10 | export CC=/c/msys64/${MINGW_VERSION}/bin/${ARCH}-w64-mingw32-gcc.exe 11 | export CXX=/c/msys64/${MINGW_VERSION}/bin/${ARCH}-w64-mingw32-g++.exe 12 | export CMAKE=/c/msys64/${MINGW_VERSION}/bin/cmake.exe 13 | 14 | # Prepend to PATH so CMake and compiler are discoverable 15 | export PATH="/c/msys64/${MINGW_VERSION}/bin:$PATH" 16 | } 17 | 18 | install_pacman_deps() { 19 | WINDEPS="mingw-w64-x86_64-libserialport \ 20 | mingw-w64-x86_64-libusb \ 21 | mingw-w64-x86_64-zstd \ 22 | mingw-w64-x86_64-libxml2 \ 23 | mingw-w64-x86_64-python3 \ 24 | mingw-w64-x86_64-python-pip \ 25 | mingw-w64-x86_64-python-setuptools \ 26 | mingw-w64-x86_64-cmake \ 27 | mingw-w64-x86_64-gcc \ 28 | cmake 29 | " 30 | echo "$WINDEPS" | xargs pacman -S --noconfirm --needed 31 | 32 | ls -l "${CC}" 33 | $CC --version 34 | } 35 | 36 | build_libiio() { 37 | $CMAKE -G "MinGW Makefiles" -DPYTHON_EXECUTABLE:FILEPATH=$(python -c "import os, sys; print(os.path.dirname(sys.executable) + '\python.exe')") \ 38 | -DCMAKE_SYSTEM_PREFIX_PATH="C:" -Werror=dev -DCOMPILE_WARNING_AS_ERROR=ON \ 39 | -DENABLE_IPV6=ON -DWITH_USB_BACKEND=ON -DWITH_SERIAL_BACKEND=ON -DPYTHON_BINDINGS=ON -DCPP_BINDINGS=ON \ 40 | -DCSHARP_BINDINGS:BOOL=OFF .. 41 | $CMAKE --build . --config Release 42 | } 43 | 44 | init_env 45 | $@ 46 | -------------------------------------------------------------------------------- /CI/azure/check_README_BUILD.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Check the project CMake for options, which are not described in the README_BUILD.md file 4 | # At the same time, check to make sure the defaults are described properly. 5 | 6 | error=0 7 | 8 | options() { 9 | for file in $(find ./ -not \( -path ./deps -prune \) -name CMakeLists.txt) 10 | do 11 | grep option[[:space:]]*\( "${file}" | \ 12 | sed -e "s/^[[:space:]]*//g" -e "s/(/ /g" | \ 13 | awk '{print $2}' 14 | done | sort | uniq 15 | } 16 | 17 | for opt in $(options) 18 | do 19 | default=$(for file in $(find ./ -not \( -path ./deps -prune \) -name CMakeLists.txt) 20 | do 21 | grep "option[[:space:]]*(${opt} " "${file}" | \ 22 | sed -e "s/^[[:space:]]*//g" -e "s/)[[:space:]]*$//" | \ 23 | awk '{print $NF}' 24 | done) 25 | if ! grep -q "${opt}.*${default}" README_BUILD.md ; then 26 | echo "no match with ${opt} set with ${default}" 27 | grep -R "${opt}" ./* 28 | error=1 29 | fi 30 | done 31 | 32 | # check if any cmake options don't print out at the end of the cmake process 33 | for f in $(find ./ -not \( -path ./deps -prune \) -name CMakeLists.txt) 34 | do 35 | for i in $(grep -i "option[[:space:]]*(" "${f}" | sed -e "s/^[[:space:]]*//g" -e "s/(/ /g" | awk '{print $2}' | sort | uniq) 36 | do 37 | a=$(grep -i "toggle_iio_feature.*${i}" $(find ./ -not \( -path ./deps -prune \) -name CMakeLists.txt)) 38 | if [ -z "${a}" ] ; then 39 | echo "${f} defines \"${i}\" as option, but it is missing toggle_iio_feature" 40 | error=1 41 | fi 42 | done 43 | done 44 | 45 | if [ "${error}" -eq "1" ] ; then 46 | exit 1 47 | fi 48 | -------------------------------------------------------------------------------- /CI/azure/ci-ubuntu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x 3 | uname -a 4 | echo "$PWD" 5 | mkdir build && cd build 6 | cmake .. -Werror=dev -DCOMPILE_WARNING_AS_ERROR=ON -DWITH_SERIAL_BACKEND=ON -DWITH_EXAMPLES=ON -DPYTHON_BINDINGS=ON -DCPP_BINDINGS=ON -DENABLE_PACKAGING=ON -DCPACK_SYSTEM_NAME="${ARTIFACTNAME}" 7 | make 8 | make package 9 | make required2tar 10 | -------------------------------------------------------------------------------- /CI/azure/macos_tar_fixup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -xe 2 | 3 | # Extract tar.gz to temp folder 4 | tarname=$(find . -maxdepth 1 -name '*.tar.gz') 5 | if [ -z "${tarname}" ]; then 6 | echo "tar.gz not found" 7 | exit 1 8 | fi 9 | # Remove .tar.gz from filename 10 | subfoldername=$(echo "${tarname}" | rev | cut -b 8- | rev) 11 | 12 | mkdir -p temp_tar 13 | tar -xzf "${tarname}" -C temp_tar 14 | mv "temp_tar/${subfoldername}" temp 15 | cd temp 16 | 17 | deps_dir=Library/Frameworks/iio.framework/Versions/Current/Dependencies 18 | libiio_loc=Library/Frameworks/iio.framework/Versions/Current/iio 19 | libiioheader_loc=Library/Frameworks/iio.framework/Versions/Current/Headers/iio.h 20 | 21 | mkdir -p "${deps_dir}" 22 | 23 | # Create links to framework files 24 | mkdir -p usr/local/{lib,include} 25 | ln -fs "../../../${libiio_loc}" usr/local/lib/libiio.dylib 26 | ln -fs "../../../${libiioheader_loc}" usr/local/include/iio.h 27 | 28 | # Update rpath of library 29 | install_name_tool -add_rpath @loader_path/. "${libiio_loc}" 30 | 31 | # Copy dependent libs to local libs, and update rpath of dependencies 32 | for each in $(otool -L "${libiio_loc}" |grep '\/usr\/local\|homebrew' |cut -f2 | cut -d' ' -f1) ; do 33 | name=$(basename "${each}") 34 | cp "${each}" "${deps_dir}" 35 | chmod +w "${deps_dir}/${name}" 36 | install_name_tool -id "@rpath/Dependencies/${name}" "${deps_dir}/${name}" 37 | install_name_tool -change "${each}" "@rpath/Dependencies/${name}" "${libiio_loc}" 38 | codesign --force -s - "${deps_dir}/${name}" 39 | done 40 | 41 | # Update tools 42 | for tool in Library/Frameworks/iio.framework/Tools/*; 43 | do 44 | install_name_tool -add_rpath @loader_path/../.. "${tool}" 45 | done 46 | 47 | # Remove old tar and create new one 48 | rm "../${tarname}" 49 | tar -czf "../${tarname}" . 50 | cd .. 51 | rm -rf temp 52 | -------------------------------------------------------------------------------- /CI/azure/windows_build_deps.cmd: -------------------------------------------------------------------------------- 1 | :: this script will download and build the necessary dependencies of libiio for windows operating systems 2 | :: if is run from the root of the libiio project all the dependencies will be found in the deps folder of the project 3 | :: in case you already have some dependencies build just comment them in the script and during compilation of libiio specify the path 4 | :: export as environment variables the ARCH, PLATFORM_TOOLSET and COMPILER used for visual studio build 5 | :: ex: set ARCH=x64, PLATFROM_TOOLSET=v143 and COMPILER='Visual Studio 17 2022' for VS2022 6 | 7 | IF not exist .\deps ( 8 | echo Directory does not exist. Creating it... 9 | mkdir .\deps 10 | ) ELSE ( 11 | echo Directory already exists. 12 | cd .\deps 13 | ) 14 | choco install -y wget 15 | 16 | :: set the msbuild compiler in order to build from terminal the visual studio projects 17 | SETLOCAL ENABLEDELAYEDEXPANSION 18 | IF "%COMPILER%" == "Visual Studio 16 2019" SET vswhere_params=-version [16,17) -products * 19 | IF "%COMPILER%" == "Visual Studio 17 2022" SET vswhere_params=-version [17,18) -products * 20 | SET vswhere="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" 21 | FOR /F "USEBACKQ TOKENS=*" %%F IN (`%vswhere% !vswhere_params! -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe`) DO ( 22 | SET msbuild="%%F" 23 | ) 24 | :: clone or download releases of the libiio dependencies (libzstd, libusb, libxml2, libserialport) 25 | git clone --branch v1.5.6 https://github.com/facebook/zstd.git 26 | git clone --branch libserialport-0.1.2 https://github.com/sigrokproject/libserialport.git 27 | wget https://github.com/libusb/libusb/releases/download/v1.0.27/libusb-1.0.27.7z 28 | 7z x -y .\libusb-1.0.27.7z -o".\libusb" 29 | rm .\libusb-1.0.27.7z 30 | wget https://download.gnome.org/sources/libxml2/2.9/libxml2-2.9.14.tar.xz 31 | cmake -E tar xf .\libxml2-2.9.14.tar.xz 32 | rm .\libxml2-2.9.14.tar.xz 33 | 34 | :: create archive with the dependencies for msvc build 35 | 7z a -tzip ..\Windows-msvc-deps.zip .\* 36 | 37 | :: build libzstd and libserialport with MSBuild 38 | %msbuild% .\zstd\build\VS2010\zstd.sln /p:Platform=%ARCH% /p:Configuration=Release /p:PlatformToolset=%PLATFORM_TOOLSET% 39 | %msbuild% .\libserialport\libserialport.vcxproj /p:Platform=%ARCH% /p:Configuration=Release /p:PlatformToolset=%PLATFORM_TOOLSET% 40 | :: build libxml with cmake 41 | cmake -DCMAKE_INSTALL_PREFIX=libxml2-install -DLIBXML2_WITH_ICONV=OFF -DLIBXML2_WITH_LZMA=OFF -DLIBXML2_WITH_PYTHON=OFF -DLIBXML2_WITH_ZLIB=OFF -S .\libxml2-2.9.14\ -B libxml2-build 42 | cmake --build libxml2-build --config Release --target install 43 | -------------------------------------------------------------------------------- /CI/build_win_msvc.ps1: -------------------------------------------------------------------------------- 1 | # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7.2#erroractionpreference 2 | $ErrorActionPreference = "Stop" 3 | $ErrorView = "NormalView" 4 | 5 | echo "Running cmake for $Env:COMPILER on 64 bit..." 6 | mkdir build-msvc 7 | cp .\libiio.iss.cmakein .\build-msvc 8 | cd build-msvc 9 | if ( "$Env:COMPILER" -eq "Visual Studio 17 2022" ){ 10 | $VS_version="VS2022" 11 | }elseif ( "$Env:COMPILER" -eq "Visual Studio 16 2019" ) { 12 | $VS_version="VS2019" 13 | } 14 | cmake -G "$Env:COMPILER" -DPYTHON_EXECUTABLE:FILEPATH=$(python -c "import os, sys; print(os.path.dirname(sys.executable) + '\python.exe')") -DCMAKE_SYSTEM_PREFIX_PATH="C:" ` 15 | -Werror=dev -DCOMPILE_WARNING_AS_ERROR=ON -DENABLE_IPV6=ON -DWITH_USB_BACKEND=ON -DWITH_SERIAL_BACKEND=ON -DPYTHON_BINDINGS=ON -DCPP_BINDINGS=ON -DCSHARP_BINDINGS:BOOL=ON ` 16 | -DLIBXML2_LIBRARIES="$Env:BUILD_SOURCESDIRECTORY\deps\libxml2-install\lib\libxml2.lib" -DLIBXML2_INCLUDE_DIR="$Env:BUILD_SOURCESDIRECTORY\deps\libxml2-install\include\libxml2" ` 17 | -DLIBUSB_LIBRARIES="$Env:BUILD_SOURCESDIRECTORY\deps\libusb\$VS_version\MS64\dll\libusb-1.0.lib" -DLIBUSB_INCLUDE_DIR="$Env:BUILD_SOURCESDIRECTORY\deps\libusb\include" ` 18 | -DLIBSERIALPORT_LIBRARIES="$Env:BUILD_SOURCESDIRECTORY\deps\libserialport\x64\Release\libserialport.lib" -DLIBSERIALPORT_INCLUDE_DIR="$Env:BUILD_SOURCESDIRECTORY\deps\libserialport" ` 19 | -DLIBZSTD_LIBRARIES="$Env:BUILD_SOURCESDIRECTORY\deps\zstd\build\VS2010\bin\x64_Release\libzstd.lib" -DLIBZSTD_INCLUDE_DIR="$Env:BUILD_SOURCESDIRECTORY\deps\zstd\lib" .. 20 | 21 | cmake --build . --config Release 22 | 23 | if ( $LASTEXITCODE -ne 0 ) { 24 | throw "[*] cmake build failure" 25 | } 26 | cp .\libiio.iss $env:BUILD_ARTIFACTSTAGINGDIRECTORY 27 | 28 | cd bindings/python 29 | python.exe setup.py sdist 30 | Get-ChildItem dist\pylibiio-*.tar.gz | Rename-Item -NewName "libiio-py39-amd64.tar.gz" 31 | mv .\dist\*.gz . 32 | rm .\dist\*.gz 33 | -------------------------------------------------------------------------------- /CI/generate_exe.ps1: -------------------------------------------------------------------------------- 1 | # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7.2#erroractionpreference 2 | $ErrorActionPreference = "Stop" 3 | $ErrorView = "NormalView" 4 | 5 | iscc $env:BUILD_ARTIFACTSTAGINGDIRECTORY\Windows-VS-2019-x64\libiio.iss 6 | 7 | Get-ChildItem $env:BUILD_ARTIFACTSTAGINGDIRECTORY -Force -Recurse | Remove-Item -Force -Recurse 8 | cp C:\libiio-setup.exe $env:BUILD_ARTIFACTSTAGINGDIRECTORY 9 | -------------------------------------------------------------------------------- /CI/publish_deps.ps1: -------------------------------------------------------------------------------- 1 | # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7.2#erroractionpreference 2 | $ErrorActionPreference = "Stop" 3 | $ErrorView = "NormalView" 4 | 5 | if ("$Env:COMPILER" -eq "MinGW Makefiles") { 6 | cp C:\msys64\mingw64\bin\libserialport-0.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY 7 | cp C:\msys64\mingw64\bin\libusb-1.0.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY 8 | cp C:\msys64\mingw64\bin\libxml2-2.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY 9 | cp C:\msys64\mingw64\bin\libzstd.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY 10 | cp C:\msys64\mingw64\bin\libgcc_s_seh-1.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY 11 | cp C:\msys64\mingw64\bin\libiconv-2.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY 12 | cp C:\msys64\mingw64\bin\zlib1.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY 13 | cp C:\msys64\mingw64\bin\liblzma-5.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY 14 | cp C:\msys64\mingw64\bin\libwinpthread-1.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY 15 | cp C:\msys64\mingw64\bin\libstdc++-6.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY 16 | } else { 17 | if ( "$Env:COMPILER" -eq "Visual Studio 17 2022" ){ 18 | $VS_version="VS2022" 19 | cd 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Redist\MSVC\14.29.30133\x64\Microsoft.VC142.CRT' 20 | cp .\msvcp140.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY 21 | cp .\vcruntime140.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY 22 | }elseif ( "$Env:COMPILER" -eq "Visual Studio 16 2019" ) { 23 | $VS_version="VS2019" 24 | cd 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Redist\MSVC\14.29.30133\x64\Microsoft.VC142.CRT' 25 | cp .\msvcp140.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY 26 | cp .\vcruntime140.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY 27 | } 28 | cp $Env:BUILD_SOURCESDIRECTORY\deps\libxml2-install\bin\libxml2.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY 29 | cp $Env:BUILD_SOURCESDIRECTORY\deps\libusb\$VS_version\MS64\dll\libusb-1.0.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY 30 | cp $Env:BUILD_SOURCESDIRECTORY\deps\libserialport\x64\Release\libserialport.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY 31 | cp $Env:BUILD_SOURCESDIRECTORY\deps\zstd\build\VS2010\bin\x64_Release\libzstd.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY 32 | } 33 | -------------------------------------------------------------------------------- /CI/travis/inside_docker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | export INSIDE_DOCKER="1" 4 | 5 | INSIDE_DOCKER_BUILD_DIR=/docker_build_dir 6 | 7 | export TRAVIS_BUILD_DIR="$INSIDE_DOCKER_BUILD_DIR" 8 | 9 | cd "$INSIDE_DOCKER_BUILD_DIR" 10 | 11 | if [ -d "/$INSIDE_DOCKER_BUILD_DIR/CI" ] ; then 12 | CI="/$INSIDE_DOCKER_BUILD_DIR/CI" 13 | elif [ -d "/$INSIDE_DOCKER_BUILD_DIR/ci" ] ; then 14 | CI="/$INSIDE_DOCKER_BUILD_DIR/ci" 15 | else 16 | echo "No CI/ci directory present" 17 | exit 1 18 | fi 19 | 20 | if [ -f "$INSIDE_DOCKER_BUILD_DIR/inside-travis-ci-docker-env" ] ; then 21 | . "$INSIDE_DOCKER_BUILD_DIR/inside-travis-ci-docker-env" 22 | fi 23 | 24 | "$CI/travis/before_install_linux" 25 | 26 | "$CI/travis/make_linux" 27 | 28 | # need to find this out inside the container 29 | . "$CI/travis/lib.sh" 30 | echo "$(get_ldist)" > "${INSIDE_DOCKER_BUILD_DIR}/build/.LDIST" 31 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socioeconomic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at opensource (at) analog (dot) com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to the libIIO 2 | 3 | When contributing to this repository, please first discuss the change you wish to make via the 4 | [issue tracker](https://github.com/analogdevicesinc/libiio/issues) before making a pull request. 5 | 6 | Please note we have a code of conduct, please follow it in all your interactions with the project. 7 | 8 | The [libIIO repository](https://github.com/analogdevicesinc/libiio) is a aggregate of a library 9 | and separate applications/programs/examples and doc which use that library: 10 | * the libiio library (which is released and distributed under the LGPL 2.0 or greater license) and 11 | * examples and test code (which is released and distributed under the GPL 2.1 or greater license). 12 | * groff source for man pages are distributed under the GPL 2.1 or greater. 13 | 14 | Any pull requests will be covered by one of these licenses. 15 | 16 | ## Pull Request Checklist 17 | 18 | 1. Commit message includes a "Signed-off-by: [name] < email >" to the commit message. 19 | This ensures you have the rights to submit your code, by agreeing to the 20 | [Developer Certificate of Origin](https://developercertificate.org/). If you can not agree to 21 | the DCO, don't submit a pull request, as we can not accept it. 22 | 2. Commit should be "atomic", ie : should do one thing only. A pull requests should only contain 23 | multiple commits if that is required to fix the bug or implement the feature. 24 | 3. Commits should have good commit messages. Check out [The git Book](https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project) 25 | for some pointers, and tools to use. 26 | 4. The project must build and run on MacOS, Windows, and Linux. This is checked on every pull request by the 27 | continuous integration system, things that fail to build can not be merged. 28 | 29 | ## Pull Request Process 30 | 31 | 1. Make a fork, if you are not sure on how to make a fork, check out [GitHub help](https://help.github.com/en/github/getting-started-with-github/fork-a-repo) 32 | 2. Make a Pull Request, if you are not sure on how to make a pull request, check out [GitHub help](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork) 33 | 3. Before a Pull Request can be merged, it must be reviewd by at least one reviewer, and tested on as 34 | many different IIO devices as possible. If you have tested it, you can indicated that in your commit 35 | message. 36 | 37 | -------------------------------------------------------------------------------- /COPYING_MIT.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Analog Devices, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | Files covered by the MIT License: 24 | 25 | attr.c 26 | attr.h 27 | backend.c 28 | block.c 29 | buffer.c 30 | channel.c 31 | context.c 32 | device.c 33 | events.c 34 | iiod/ops.h 35 | iiod/responder.c 36 | iiod-responder.h 37 | iio-private.h 38 | include/iio/iio-backend.h 39 | include/iio/iio-debug.h 40 | include/iio/iio.h 41 | include/iio/iio-lock.h 42 | library.c 43 | lock-dummy.c 44 | mask.c 45 | scan.c 46 | sort.c 47 | sort.h 48 | stream.c 49 | task.c 50 | tinyiiod/tinyiiod.c 51 | tinyiiod/tinyiiod.h 52 | utilities.c 53 | xml.c 54 | -------------------------------------------------------------------------------- /Distribution.xml.cmakein: -------------------------------------------------------------------------------- 1 | 2 | 3 | Libiio 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | @LIBIIO_TEMP_PKG@ 20 | 21 | -------------------------------------------------------------------------------- /attr.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2023 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | #ifndef __IIO_ATTR_H__ 10 | #define __IIO_ATTR_H__ 11 | 12 | #include 13 | 14 | struct iio_attr_list; 15 | struct iio_context; 16 | struct iio_device; 17 | 18 | const struct iio_attr * 19 | iio_attr_get(const struct iio_attr_list *attrs, unsigned int idx); 20 | const struct iio_attr * 21 | iio_attr_find(const struct iio_attr_list *attrs, const char *name); 22 | 23 | void iio_free_attr_data(struct iio_attr *attr); 24 | void iio_free_attrs(const struct iio_attr_list *attrs); 25 | 26 | int iio_add_attr(union iio_pointer p, struct iio_attr_list *attrs, 27 | const char *name, const char *filename, 28 | enum iio_attr_type type); 29 | 30 | #endif /* __IIO_ATTR_H__ */ 31 | -------------------------------------------------------------------------------- /backend.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2017 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | #include "dynamic.h" 10 | #include "iio-config.h" 11 | #include "iio-private.h" 12 | 13 | #include 14 | 15 | unsigned int iio_get_builtin_backends_count(void) 16 | { 17 | unsigned int i, count = 0; 18 | 19 | for (i = 0; i < iio_backends_size; i++) 20 | count += !!iio_backends[i]; 21 | 22 | return count; 23 | } 24 | 25 | const char * iio_get_builtin_backend(unsigned int index) 26 | { 27 | unsigned int i; 28 | 29 | for (i = 0; i < iio_backends_size; i++) { 30 | if (index == 0 && iio_backends[i]) 31 | return iio_backends[i]->name; 32 | 33 | index -= !!iio_backends[i]; 34 | } 35 | 36 | return NULL; 37 | } 38 | 39 | bool 40 | iio_has_backend(const struct iio_context_params *params, const char *backend) 41 | { 42 | unsigned int i; 43 | 44 | for (i = 0; i < iio_get_builtin_backends_count(); i++) 45 | if (strcmp(backend, iio_get_builtin_backend(i)) == 0) 46 | return true; 47 | 48 | if (WITH_MODULES) 49 | return iio_has_backend_dynamic(params, backend); 50 | 51 | return false; 52 | } 53 | -------------------------------------------------------------------------------- /bindings/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (CPP_BINDINGS) 2 | add_subdirectory(cpp) 3 | endif() 4 | 5 | if (CSHARP_BINDINGS) 6 | add_subdirectory(csharp) 7 | endif() 8 | 9 | if (PYTHON_BINDINGS) 10 | add_subdirectory(python) 11 | endif() 12 | 13 | toggle_iio_feature("${PYTHON_BINDINGS}" python-bindings) 14 | toggle_iio_feature("${CSHARP_BINDINGS}" "c#-bindings") 15 | toggle_iio_feature("${CPP_BINDINGS}" "c++-bindings") 16 | 17 | set(IIOB_FEATURES_ON "${IIO_FEATURES_ON}" PARENT_SCOPE) 18 | set(IIOB_FEATURES_OFF "${IIO_FEATURES_OFF}" PARENT_SCOPE) 19 | -------------------------------------------------------------------------------- /bindings/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | project(iiopp-enum LANGUAGES CXX) 3 | 4 | # Prefer, but do not require, C++17 5 | set(CMAKE_CXX_STANDARD 17) 6 | set(CMAKE_CXX_STANDARD_REQUIRED OFF) 7 | 8 | include(CheckCXXSourceCompiles) 9 | 10 | # Check for std::optional 11 | check_cxx_source_compiles(" 12 | #include 13 | int main() { 14 | std::optional o; 15 | return 0; 16 | } 17 | " HAS_STD_OPTIONAL) 18 | 19 | if(NOT HAS_STD_OPTIONAL) 20 | find_package(Boost COMPONENTS optional REQUIRED) 21 | if(Boost_FOUND) 22 | set(CMAKE_REQUIRED_INCLUDES ${Boost_INCLUDE_DIRS}) 23 | check_cxx_source_compiles(" 24 | #include 25 | int main() { 26 | boost::optional o; 27 | return 0; 28 | } 29 | " HAS_BOOST_OPTIONAL) 30 | unset(CMAKE_REQUIRED_INCLUDES) 31 | if(HAS_BOOST_OPTIONAL) 32 | set(USE_BOOST_OPTIONAL TRUE) 33 | else() 34 | message(FATAL_ERROR "Neither std::optional nor boost::optional is available") 35 | endif() 36 | else() 37 | message(FATAL_ERROR "Boost not found and std::optional is unavailable") 38 | endif() 39 | else() 40 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 41 | endif() 42 | 43 | add_executable(iiopp-enum examples/iiopp-enum.cpp ${LIBIIO_RC}) 44 | target_include_directories(iiopp-enum PRIVATE ./) 45 | target_link_libraries(iiopp-enum PRIVATE iio) 46 | 47 | if(USE_BOOST_OPTIONAL) 48 | target_include_directories(iiopp-enum PRIVATE ${Boost_INCLUDE_DIRS}) 49 | endif() 50 | -------------------------------------------------------------------------------- /bindings/cpp/examples/iiopp-enum.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | * libiio - C++ API usage 4 | * 5 | * This example libiio program shows the usage of the C++ API for enumerating 6 | * devices, channels and attributes. 7 | * 8 | * Copyright (c) 2023, DIFITEC GmbH 9 | * Author: Tilman Blumhagen 10 | */ 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | using namespace iiopp; 18 | using namespace std; 19 | 20 | string get(Attr const & att) 21 | { 22 | char value[1024] = {0}; // Flawfinder: ignore 23 | att.read_raw(value, sizeof(value)); 24 | return value; 25 | } 26 | 27 | void enumerateIioEntities() 28 | { 29 | cout << boolalpha; 30 | 31 | ContextPtr context = create_context(nullptr, nullptr); 32 | 33 | for (Device device : *context) 34 | { 35 | cout << "Device:" << endl; 36 | cout << " id: " << quoted(string(device.id())) << endl; 37 | 38 | cout << " name: "; 39 | if (auto name = device.name()) 40 | cout << quoted(string(*name)); 41 | cout << endl; 42 | 43 | cout << " is trigger: " << device.is_trigger() << endl; 44 | 45 | for (auto att : device.attrs) 46 | cout << " attribute " << att.name() << " = " << quoted(get(att)) << endl; 47 | 48 | for (auto att : device.debug_attrs) 49 | cout << " debug attribute " << att.name() << " = " << quoted(get(att)) << endl; 50 | 51 | for (Channel channel : device) 52 | { 53 | cout << " Channel: " << channel.id() << endl; 54 | 55 | cout << " name: "; 56 | if (auto name = channel.name()) 57 | cout << quoted(string(*name)); 58 | cout << endl; 59 | 60 | cout << " is output: " << channel.is_output() << endl; 61 | 62 | for (auto att : channel.attrs) 63 | cout << " attribute " << quoted(att.name().c_str()) << " = " << quoted(get(att)) << endl; 64 | } 65 | } 66 | 67 | ScanPtr s = scan(nullptr, nullptr); 68 | 69 | cout << "scan returned " << s->size() << " results" << endl; 70 | for (ScanResult r : *s) 71 | { 72 | cout << " uri: " << quoted(r.uri().c_str()) << endl; 73 | cout << " description: " << quoted(r.description().c_str()) << endl; 74 | } 75 | } 76 | 77 | int main(int argc, char ** argv) 78 | { 79 | try 80 | { 81 | enumerateIioEntities(); 82 | } 83 | catch (error & e) 84 | { 85 | cerr << "ERROR " << e.code().value() << ": " << e.what() << endl; 86 | return EXIT_FAILURE; 87 | } 88 | 89 | return EXIT_SUCCESS; 90 | } 91 | -------------------------------------------------------------------------------- /bindings/csharp/.gitignore: -------------------------------------------------------------------------------- 1 | AssemblyInfo.cs 2 | libiio-sharp-0.5.pc 3 | libiio-sharp.dll.config 4 | -------------------------------------------------------------------------------- /bindings/csharp/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "build", 8 | "command": "dotnet", 9 | "type": "shell", 10 | "args": [ 11 | "build", 12 | // Ask dotnet build to generate full paths for file names. 13 | "/property:GenerateFullPaths=true", 14 | // Do not generate summary otherwise it leads to duplicate errors in Problems panel 15 | "/consoleloggerparameters:NoSummary" 16 | ], 17 | "group": "build", 18 | "presentation": { 19 | "reveal": "silent" 20 | }, 21 | "problemMatcher": "$msCompile" 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /bindings/csharp/AssemblyInfo.cs.in: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | [assembly:AssemblyVersion("@LIBIIO_CS_VERSION@")] 5 | [assembly:AssemblyDelaySign(false)] 6 | -------------------------------------------------------------------------------- /bindings/csharp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | project(libiio-sharp NONE) 3 | 4 | if (WIN32) 5 | set(MCS_EXECUTABLE_NAME csc) 6 | else() 7 | set(MCS_EXECUTABLE_NAME mcs) 8 | endif() 9 | 10 | find_program(MCS_EXECUTABLE 11 | NAMES ${MCS_EXECUTABLE_NAME} 12 | HINTS "C:/Windows/Microsoft.NET/Framework/v4.0.30319" 13 | PATHS ENV MCS_EXECUTABLE_PATH 14 | DOC "C# compiler") 15 | mark_as_advanced(MCS_EXECUTABLE) 16 | 17 | if (MCS_EXECUTABLE) 18 | message(STATUS "Found C#: Building bindings") 19 | set(LIBIIO_CS_PC_IN "${CMAKE_CURRENT_SOURCE_DIR}/libiio-sharp.pc.cmakein") 20 | set(LIBIIO_CS_PC "${CMAKE_CURRENT_BINARY_DIR}/libiio-sharp-${VERSION}.pc") 21 | configure_file(${LIBIIO_CS_PC_IN} ${LIBIIO_CS_PC} @ONLY) 22 | if(NOT SKIP_INSTALL_ALL) 23 | install(FILES ${LIBIIO_CS_PC} DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig") 24 | endif() 25 | 26 | set(LIBIIO_CS_DLL_CONFIG_IN "${CMAKE_CURRENT_SOURCE_DIR}/libiio-sharp.dll.config.cmakein") 27 | set(LIBIIO_CS_DLL_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/libiio-sharp.dll.config") 28 | configure_file(${LIBIIO_CS_DLL_CONFIG_IN} ${LIBIIO_CS_DLL_CONFIG} @ONLY) 29 | if(NOT SKIP_INSTALL_ALL) 30 | install(FILES ${LIBIIO_CS_DLL_CONFIG} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cli/libiio-sharp-${VERSION}) 31 | endif() 32 | 33 | set(LIBIIO_CS_VERSION ${VERSION}.0.0) 34 | set(LIBIIO_CS_INFO_IN ${CMAKE_CURRENT_SOURCE_DIR}/AssemblyInfo.cs.in) 35 | set(LIBIIO_CS_INFO ${CMAKE_CURRENT_BINARY_DIR}/AssemblyInfo.cs) 36 | configure_file(${LIBIIO_CS_INFO_IN} ${LIBIIO_CS_INFO} @ONLY) 37 | 38 | set(LIBIIO_CS_DLL "${CMAKE_CURRENT_BINARY_DIR}/libiio-sharp.dll") 39 | set(LIBIIO_CS_SOURCES 40 | ${CMAKE_CURRENT_SOURCE_DIR}/Attr.cs 41 | ${CMAKE_CURRENT_SOURCE_DIR}/Block.cs 42 | ${CMAKE_CURRENT_SOURCE_DIR}/Channel.cs 43 | ${CMAKE_CURRENT_SOURCE_DIR}/ChannelsMask.cs 44 | ${CMAKE_CURRENT_SOURCE_DIR}/Context.cs 45 | ${CMAKE_CURRENT_SOURCE_DIR}/Device.cs 46 | ${CMAKE_CURRENT_SOURCE_DIR}/EventStream.cs 47 | ${CMAKE_CURRENT_SOURCE_DIR}/IOBuffer.cs 48 | ${CMAKE_CURRENT_SOURCE_DIR}/IIOEvent.cs 49 | ${CMAKE_CURRENT_SOURCE_DIR}/Trigger.cs 50 | ${CMAKE_CURRENT_SOURCE_DIR}/IioLib.cs 51 | ${CMAKE_CURRENT_SOURCE_DIR}/Scan.cs 52 | ${CMAKE_CURRENT_SOURCE_DIR}/Stream.cs 53 | ${LIBIIO_CS_INFO} 54 | ) 55 | 56 | foreach(SRC ${LIBIIO_CS_SOURCES}) 57 | file(TO_NATIVE_PATH ${SRC} TMP) 58 | set(LIBIIO_CS_SOURCES_REALPATH ${LIBIIO_CS_SOURCES_REALPATH} ${TMP}) 59 | endforeach(SRC) 60 | 61 | file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/key.snk SIGN_KEY) 62 | file(TO_NATIVE_PATH ${LIBIIO_CS_DLL} LIBIIO_CS_DLL_OUT) 63 | 64 | add_custom_command(OUTPUT ${LIBIIO_CS_DLL} 65 | COMMAND ${MCS_EXECUTABLE} 66 | /target:library 67 | /langversion:5 68 | /out:${LIBIIO_CS_DLL_OUT} 69 | /debug 70 | /keyfile:${SIGN_KEY} 71 | ${LIBIIO_CS_SOURCES_REALPATH} 72 | DEPENDS ${LIBIIO_CS_SOURCES} 73 | ) 74 | 75 | add_custom_target(libiio-sharp ALL DEPENDS ${LIBIIO_CS_DLL}) 76 | 77 | if(NOT SKIP_INSTALL_ALL) 78 | set(DEBUG_SYMBOLS_FILE "") 79 | if(MCS_EXECUTABLE_NAME STREQUAL "mcs") 80 | set(DEBUG_SYMBOLS_FILE "${LIBIIO_CS_DLL}.mdb") 81 | elseif(MCS_EXECUTABLE_NAME STREQUAL "csc") 82 | set(DEBUG_SYMBOLS_FILE "${CMAKE_CURRENT_BINARY_DIR}/libiio-sharp.pdb") 83 | endif() 84 | install(FILES ${LIBIIO_CS_DLL} ${DEBUG_SYMBOLS_FILE} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cli/libiio-sharp-${VERSION}) 85 | endif() 86 | else() 87 | message(FATAL_ERROR "C# compiler search failed : Can not build C# bindings") 88 | endif() 89 | -------------------------------------------------------------------------------- /bindings/csharp/ChannelsMask.cs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: LGPL-2.1-or-later 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2022 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | using System; 10 | using System.Runtime.InteropServices; 11 | 12 | namespace iio 13 | { 14 | public class ChannelsMask : IIOObject 15 | { 16 | [DllImport(IioLib.dllname, CallingConvention = CallingConvention.Cdecl)] 17 | private static extern IIOPtr iio_create_channels_mask(uint nb_channels); 18 | 19 | [DllImport(IioLib.dllname, CallingConvention = CallingConvention.Cdecl)] 20 | private static extern void iio_channels_mask_destroy(IntPtr mask); 21 | 22 | public ChannelsMask(uint nb_channels) 23 | { 24 | IIOPtr ptr = iio_create_channels_mask(nb_channels); 25 | if (!ptr) 26 | { 27 | throw new IIOException("Failed to create iio.ChannelsMask", ptr); 28 | } 29 | 30 | this.hdl = ptr.ptr; 31 | } 32 | 33 | protected override void Destroy() 34 | { 35 | iio_channels_mask_destroy(hdl); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /bindings/csharp/EventStream.cs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: LGPL-2.1-or-later 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2024 Analog Devices, Inc. 6 | * Author: Alexandra Trifan 7 | */ 8 | 9 | using System; 10 | using System.Runtime.InteropServices; 11 | 12 | namespace iio 13 | { 14 | /// class: 15 | /// Contains the representation of an event stream. 16 | public class EventStream : IIOObject 17 | { 18 | [DllImport(IioLib.dllname, CallingConvention = CallingConvention.Cdecl)] 19 | private static extern IIOPtr iio_device_create_event_stream(IntPtr dev); 20 | 21 | [DllImport(IioLib.dllname, CallingConvention = CallingConvention.Cdecl)] 22 | private static extern void iio_event_stream_destroy(IntPtr stream); 23 | 24 | [DllImport(IioLib.dllname, CallingConvention = CallingConvention.Cdecl)] 25 | private static extern int iio_event_stream_read(IntPtr stream, IntPtr ev, 26 | [MarshalAs(UnmanagedType.I1)] bool nonblock); 27 | 28 | [DllImport(IioLib.dllname, CallingConvention = CallingConvention.Cdecl)] 29 | private static extern IntPtr iio_event_get_channel(IntPtr ev, IntPtr dev, 30 | [MarshalAs(UnmanagedType.I1)] bool diff); 31 | 32 | public readonly Device dev; 33 | 34 | public EventStream(Device device) 35 | { 36 | IIOPtr ptr = iio_device_create_event_stream(device.dev); 37 | if (!ptr) 38 | throw new IIOException("Unable to create iio.EventStream", ptr); 39 | 40 | this.hdl = ptr.ptr; 41 | this.dev = device; 42 | } 43 | 44 | /// Read an event from the event stream. 45 | /// if True, the operation won't block and return -EBUSY if 46 | /// there is currently no event in the queue. 47 | /// It is possible to stop a blocking call of read_event 48 | /// by calling Destroy in a different thread. 49 | /// In that case, read_event will throw an exception. 50 | /// Unable to read event. 51 | public IIOEvent read_event(bool nonblock) 52 | { 53 | IIOEventPtr iioeventptr; 54 | iioeventptr.id = 0; 55 | iioeventptr.timestamp = 0; 56 | IntPtr eventptr = Marshal.AllocHGlobal(Marshal.SizeOf(iioeventptr)); 57 | 58 | int ret = iio_event_stream_read(hdl, eventptr, nonblock); 59 | if (ret < 0) 60 | throw new IIOException("Unable to read event", ret); 61 | 62 | IntPtr chnptr = iio_event_get_channel(eventptr, dev.dev, false); 63 | Channel chn = new Channel(dev, chnptr); 64 | IntPtr diffchnptr = iio_event_get_channel(eventptr, dev.dev, true); 65 | if (diffchnptr != IntPtr.Zero) 66 | { 67 | Channel chndiff = new Channel(dev, diffchnptr); 68 | return new IIOEvent(eventptr, chn, chndiff); 69 | } 70 | return new IIOEvent(eventptr, chn); 71 | } 72 | 73 | protected override void Destroy() 74 | { 75 | iio_event_stream_destroy(hdl); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /bindings/csharp/IIOEvent.cs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: LGPL-2.1-or-later 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2024 Analog Devices, Inc. 6 | * Author: Alexandra Trifan 7 | */ 8 | 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Globalization; 12 | using System.Linq; 13 | using System.Runtime.InteropServices; 14 | using System.Text; 15 | using System.Threading.Tasks; 16 | 17 | namespace iio 18 | { 19 | [StructLayout(LayoutKind.Sequential)] 20 | public struct IIOEventPtr 21 | { 22 | public ulong id; 23 | public long timestamp; 24 | } 25 | 26 | /// class: 27 | /// Contains the representation of an iio_event. 28 | public class IIOEvent 29 | { 30 | /// class: 31 | /// Contains the available event types. 32 | public enum EventType 33 | { 34 | IIO_EV_TYPE_THRESH, 35 | IIO_EV_TYPE_MAG, 36 | IIO_EV_TYPE_ROC, 37 | IIO_EV_TYPE_THRESH_ADAPTIVE, 38 | IIO_EV_TYPE_MAG_ADAPTIVE, 39 | IIO_EV_TYPE_CHANGE, 40 | IIO_EV_TYPE_MAG_REFERENCED, 41 | IIO_EV_TYPE_GESTURE, 42 | IIO_EV_TYPE_FAULT 43 | } 44 | 45 | /// class: 46 | /// Contains the available event directions. 47 | public enum EventDirection 48 | { 49 | IIO_EV_DIR_EITHER, 50 | IIO_EV_DIR_RISING, 51 | IIO_EV_DIR_FALLING, 52 | IIO_EV_DIR_NONE, 53 | IIO_EV_DIR_SINGLETAP, 54 | IIO_EV_DIR_DOUBLETAP, 55 | IIO_EV_DIR_FAULT_OPENWIRE, 56 | } 57 | 58 | internal IntPtr ev; 59 | 60 | [DllImport(IioLib.dllname, CallingConvention = CallingConvention.Cdecl)] 61 | private static extern int iio_event_get_type(IntPtr ev); 62 | 63 | [DllImport(IioLib.dllname, CallingConvention = CallingConvention.Cdecl)] 64 | private static extern int iio_event_get_direction(IntPtr ev); 65 | 66 | internal IIOEventPtr event_ptr; 67 | public readonly Channel chn; 68 | public readonly Channel chn_diff; 69 | public readonly ulong id; 70 | public readonly long timestamp; 71 | 72 | /// The type of this event. 73 | public EventType type { get; private set; } 74 | 75 | /// Represents the direction of the event. 76 | public EventDirection direction { get; private set; } 77 | 78 | internal IIOEvent(IntPtr ev, Channel chn, Channel chndiff = null) 79 | { 80 | this.ev = ev; 81 | event_ptr = (IIOEventPtr) Marshal.PtrToStructure(ev, typeof(IIOEventPtr)); 82 | this.id = event_ptr.id; 83 | this.timestamp = event_ptr.timestamp; 84 | this.chn = chn; 85 | this.chn_diff = chndiff; 86 | this.type = (EventType) ((this.id >> 56) & 0xff); 87 | this.direction = (EventDirection) ((this.id >> 48) & 0x7f); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /bindings/csharp/Scan.cs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: LGPL-2.1-or-later 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2020 Analog Devices, Inc. 6 | * Author: Cristian Iacob 7 | */ 8 | 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Runtime.InteropServices; 13 | 14 | namespace iio 15 | { 16 | /// class: 17 | /// Class for getting information about the available contexts. 18 | public class Scan : IIOObject 19 | { 20 | [DllImport(IioLib.dllname, CallingConvention = CallingConvention.Cdecl)] 21 | private static extern IIOPtr iio_scan(IntPtr ctx_params, [In] string backend); 22 | 23 | [DllImport(IioLib.dllname, CallingConvention = CallingConvention.Cdecl)] 24 | private static extern void iio_scan_destroy(IntPtr scan); 25 | 26 | [DllImport(IioLib.dllname, CallingConvention = CallingConvention.Cdecl)] 27 | private static extern uint iio_scan_get_results_count(IntPtr scan); 28 | 29 | [DllImport(IioLib.dllname, CallingConvention = CallingConvention.Cdecl)] 30 | private static extern IntPtr iio_scan_get_description(IntPtr ctx, uint index); 31 | 32 | [DllImport(IioLib.dllname, CallingConvention = CallingConvention.Cdecl)] 33 | private static extern IntPtr iio_scan_get_uri(IntPtr ctx, uint index); 34 | 35 | [DllImport(IioLib.dllname, CallingConvention = CallingConvention.Cdecl)] 36 | private static extern IntPtr iio_scan_block_get_info(IntPtr blk, uint index); 37 | 38 | [DllImport(IioLib.dllname, CallingConvention = CallingConvention.Cdecl)] 39 | private static extern IntPtr iio_context_info_get_description(IntPtr info); 40 | 41 | [DllImport(IioLib.dllname, CallingConvention = CallingConvention.Cdecl)] 42 | private static extern IntPtr iio_context_info_get_uri(IntPtr info); 43 | 44 | [DllImport(IioLib.dllname, CallingConvention = CallingConvention.Cdecl)] 45 | private static extern long iio_scan_block_scan(IntPtr blk); 46 | 47 | /// The number of contexts scanned. 48 | public readonly uint nb_results; 49 | 50 | /// A containing each context's uri as key and its description as value. 51 | public readonly Dictionary results; 52 | 53 | public Scan(string backends = null) 54 | { 55 | IIOPtr ptr = iio_scan(IntPtr.Zero, backends); 56 | if (!ptr) 57 | { 58 | throw new IIOException("Unable to create iio.Scan", ptr); 59 | } 60 | 61 | hdl = ptr.ptr; 62 | nb_results = iio_scan_get_results_count(hdl); 63 | 64 | results = new Dictionary(); 65 | 66 | for (uint i = 0; i < nb_results; i++) { 67 | string uri = Marshal.PtrToStringAnsi(iio_scan_get_uri(hdl, i)); 68 | string dsc = Marshal.PtrToStringAnsi(iio_scan_get_description(hdl, i)); 69 | 70 | results[uri] = dsc; 71 | } 72 | } 73 | 74 | protected override void Destroy() 75 | { 76 | iio_scan_destroy(hdl); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /bindings/csharp/Stream.cs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: LGPL-2.1-or-later 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2022 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | using System; 10 | using System.Runtime.InteropServices; 11 | 12 | namespace iio 13 | { 14 | public class Stream : IIOObject 15 | { 16 | [DllImport(IioLib.dllname, CallingConvention = CallingConvention.Cdecl)] 17 | private static extern IIOPtr iio_buffer_create_stream(IntPtr buf, 18 | uint nb_blocks, uint samples_count); 19 | 20 | [DllImport(IioLib.dllname, CallingConvention = CallingConvention.Cdecl)] 21 | private static extern void iio_stream_destroy(IntPtr stream); 22 | 23 | [DllImport(IioLib.dllname, CallingConvention = CallingConvention.Cdecl)] 24 | private static extern IIOPtr iio_stream_get_next_block(IntPtr stream); 25 | 26 | public readonly IOBuffer buf; 27 | public readonly uint nb_blocks; 28 | public readonly uint samples_count; 29 | 30 | public Stream(IOBuffer buf, uint nb_blocks, uint samples_count) 31 | { 32 | IIOPtr ptr = iio_buffer_create_stream(buf.hdl, nb_blocks, samples_count); 33 | if (!ptr) 34 | throw new IIOException("Unable to create iio.Stream", ptr); 35 | 36 | this.hdl = ptr.ptr; 37 | this.buf = buf; 38 | this.nb_blocks = nb_blocks; 39 | this.samples_count = samples_count; 40 | } 41 | 42 | public Block next() 43 | { 44 | IIOPtr ptr = iio_stream_get_next_block(hdl); 45 | if (!ptr) 46 | throw new IIOException("Unable to get next block", ptr); 47 | 48 | return new Block(ptr.ptr, buf.step() * samples_count); 49 | } 50 | 51 | protected override void Destroy() 52 | { 53 | iio_stream_destroy(hdl); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /bindings/csharp/Trigger.cs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: LGPL-2.1-or-later 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2015 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Runtime.InteropServices; 13 | using System.Text; 14 | using System.Threading.Tasks; 15 | 16 | namespace iio 17 | { 18 | /// class: 19 | /// Contains the representation of an IIO device that can act as a trigger. 20 | public class Trigger : Device 21 | { 22 | internal Trigger(Context ctx, IntPtr ptr) : base(ctx, ptr) { } 23 | 24 | /// Configure a new frequency for this trigger. 25 | /// The new frequency could not be set. 26 | public void set_rate(ulong rate) 27 | { 28 | foreach (Attr each in attrs) 29 | { 30 | if (each.name.Equals("frequency")) 31 | { 32 | each.write((long) rate); 33 | return; 34 | } 35 | } 36 | throw new IIOException("Trigger has no frequency?"); 37 | } 38 | 39 | /// Get the currently configured frequency of this trigger. 40 | /// The configured frequency could not be obtained. 41 | public ulong get_rate() 42 | { 43 | foreach (Attr each in attrs) 44 | { 45 | if (each.name.Equals("frequency")) 46 | { 47 | return (ulong) each.read_long(); 48 | } 49 | } 50 | throw new IIOException("Trigger has no frequency?"); 51 | } 52 | 53 | /// Set Trigger. 54 | public new void set_trigger(Trigger trig) 55 | { 56 | throw new IIOException("Device is already a trigger"); 57 | } 58 | 59 | /// Get trigger. 60 | public new Trigger get_trigger() 61 | { 62 | throw new IIOException("Device is already a trigger"); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /bindings/csharp/key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/bindings/csharp/key.snk -------------------------------------------------------------------------------- /bindings/csharp/libiio-sharp.dll.config.cmakein: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /bindings/csharp/libiio-sharp.pc.cmakein: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=@CMAKE_INSTALL_PREFIX@ 3 | libdir=@CMAKE_INSTALL_PREFIX@/lib 4 | 5 | Name: libiio-cs 6 | Description: CLI bindings for libiio 7 | Version: @VERSION@ 8 | 9 | Requires: 10 | Libs: -r:${libdir}/cli/libiio-sharp-@VERSION@/libiio-sharp.dll 11 | -------------------------------------------------------------------------------- /bindings/csharp/mainpage.dox: -------------------------------------------------------------------------------- 1 | /** 2 | @mainpage 3 | 4 | @tableofcontents 5 | 6 | Back to libIIO 7 | 8 | @section license License 9 | Libiio and the C# bindings have been developed and is released under the terms of the GNU Lesser General Public 10 | License, version 2 or (at your option) any later version. 11 | This open-source license allows anyone to use the library for C# proprietary or 12 | open-source, commercial or non-commercial applications. 13 | (if you change the bindings or library, send the source of the bindings and library along with the binary). 14 | 15 | The full terms of the library license can be found at: http://opensource.org/licenses/LGPL-2.1 and the iio-utils license can be found at: https://opensource.org/licenses/GPL-2.0 16 | 17 | @section code_model Code Model 18 | The basic bricks of the libiio API, and therefore the C# bindings are the the iio namespace, and the classes of that nameplace: iio.Channel, iio.Context, iio.Device, iio.IOBuffer, iio.Trigger, and iio.Attr (channel or device attributes). 19 | 20 | ![Caption text](doc/codemodel.svg) 21 | 22 | @section creating_context Creating a context 23 | 24 | Creating a context is quite easy with the iio.Context class: 25 | 26 | ~~~{.cs} 27 | Context ctx = new Context("ip:10.44.2.241"); 28 | ~~~ 29 | 30 | @subsection navigation Navigation 31 | @subsubsection device_obj Device objects 32 | 33 | ~~~{.cs} 34 | foreach (Device dev in ctx.devices) 35 | { 36 | Console.WriteLine("\t" + dev.id + ": " + dev.name); 37 | } 38 | ~~~ 39 | 40 | @subsubsection channel_obj Channel objects 41 | 42 | Each iio.Channel can be either input, or output. This information can be retrieved with iio.Channel.output 43 | As for the Device objects, the iio.Channel object features an ID and optionally a name 44 | The ID can be obtained with iio.Channel.id, and the name can be obtained with iio.Channel.name. 45 | Important note: two iio_channel can have the same ID, as long as one is input and the other is output. 46 | 47 | ~~~{.cs} 48 | foreach (Channel chn in dev.channels) 49 | { 50 | string type = "input"; 51 | if (chn.output) 52 | type = "output"; 53 | Console.WriteLine("\t\t\t" + chn.id + ": " + chn.name + " (" + type + ")"); 54 | } 55 | ~~~ 56 | 57 | @subsection list_params Parameters 58 | Different kinds of parameters are available: parameters that apply to a iio_device, and parameters that apply to one or more iio_channel. 59 | 60 | for Channel attributes: iio.Channel.attrs 61 | 62 | ~~~{.cs} 63 | foreach (Attr attr in chn.attrs) 64 | { 65 | Console.WriteLine("\t\t\t\t" + attr.name); 66 | if (attr.name.CompareTo("frequency") == 0) 67 | { 68 | Console.WriteLine("Attribute content: " + attr.read()); 69 | } 70 | } 71 | ~~~ 72 | 73 | For Device Attributes: iio.Device.attrs 74 | 75 | ~~~{.cs} 76 | foreach (Attr attr in dev.attrs) 77 | Console.WriteLine("\t\t\t" + attr.name); 78 | ~~~ 79 | 80 | 81 | \example ExampleProgram.cs Small example program 82 | */ 83 | -------------------------------------------------------------------------------- /bindings/python/.gitignore: -------------------------------------------------------------------------------- 1 | setup.py 2 | *.pyc 3 | __pycache__/ 4 | -------------------------------------------------------------------------------- /bindings/python/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | project(libiio-py NONE) 3 | 4 | if(${CMAKE_VERSION} VERSION_LESS "3.12.0") 5 | message(STATUS "bin=${PYTHON_EXECUTABLE} lib=${PYTHON_LIBRARY} inc=${PYTHON_INCLUDE_DIR}") 6 | include(FindPythonInterp) 7 | 8 | # Set variables as they would be set by module FindPython, 9 | # which is available from CMake 3.12. 10 | set(Python_Interpreter_FOUND ${PYTHONINTERP_FOUND}) 11 | set(Python_EXECUTABLE ${PYTHON_EXECUTABLE}) 12 | else() 13 | if(PYTHON_EXECUTABLE) 14 | set(Python_EXECUTABLE ${PYTHON_EXECUTABLE}) 15 | endif() 16 | if (PYTHON_LIBRARY) 17 | set(Python_LIBRARY ${PYTHON_LIBRARY}) 18 | endif() 19 | if (PYTHON_INCLUDE_DIR) 20 | set(Python_INCLUDE_DIR ${PYTHON_INCLUDE_DIR}) 21 | endif() 22 | message(STATUS "bin=${Python_EXECUTABLE} lib=${Python_LIBRARY} inc=${Python_INCLUDE_DIR}") 23 | find_package (Python COMPONENTS Interpreter) 24 | message(STATUS "Python_EXECUTABLE ${Python_EXECUTABLE}") 25 | endif() 26 | 27 | if (Python_Interpreter_FOUND) 28 | set(SETUP_PY_IN ${CMAKE_CURRENT_SOURCE_DIR}/setup.py.cmakein) 29 | set(SETUP_PY ${CMAKE_CURRENT_BINARY_DIR}/setup.py) 30 | 31 | configure_file(${SETUP_PY_IN} ${SETUP_PY}) 32 | 33 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/iio.py ${CMAKE_CURRENT_BINARY_DIR}/iio.py COPYONLY) 34 | 35 | add_custom_target(libiio-py ALL DEPENDS ${SETUP_PY} COMMAND ${Python_EXECUTABLE} ${SETUP_PY} --quiet build) 36 | 37 | if(NOT SKIP_INSTALL_ALL) 38 | install(CODE "execute_process(WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${Python_EXECUTABLE} ${SETUP_PY} install --root=\$ENV{DESTDIR}/ --prefix=${CMAKE_INSTALL_PREFIX})") 39 | endif() 40 | else() 41 | message(FATAL_ERROR "Python search failed : Can not build Python bindings") 42 | endif() 43 | 44 | if(WITH_DOC) 45 | find_program(SPHINX_EXECUTABLE 46 | NAMES sphinx-build 47 | DOC "Sphinx Documentation Builder (sphinx-doc.org)" 48 | ) 49 | if (NOT SPHINX_EXECUTABLE) 50 | message(FATAL_ERROR "Can not build python doc without sphinx-build") 51 | endif() 52 | message (STATUS "Building with Python Doc (Sphinx)") 53 | configure_file( 54 | ${CMAKE_CURRENT_SOURCE_DIR}/doc/conf.py.in 55 | ${CMAKE_CURRENT_SOURCE_DIR}/doc/conf.py) 56 | add_custom_command(TARGET libiio-py POST_BUILD 57 | COMMAND ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:${CMAKE_BINARY_DIR}" 58 | ${SPHINX_EXECUTABLE} 59 | -b html 60 | -n 61 | -c ${CMAKE_CURRENT_SOURCE_DIR}/doc 62 | -d ${CMAKE_CURRENT_BINARY_DIR}/doctrees 63 | -w ${CMAKE_BINARY_DIR}/Spx_output_python 64 | ${CMAKE_CURRENT_SOURCE_DIR}/doc 65 | ${CMAKE_HTML_DEST_DIR}/python 66 | COMMENT "Generating Python binding documentation with Sphinx" VERBATIM 67 | ) 68 | endif() 69 | -------------------------------------------------------------------------------- /bindings/python/doc/.gitignore: -------------------------------------------------------------------------------- 1 | # Cmake leaves a file in the source dir, so ignore it 2 | conf.py 3 | -------------------------------------------------------------------------------- /bindings/python/doc/buffer.rst: -------------------------------------------------------------------------------- 1 | Buffer 2 | ================== 3 | 4 | Members 5 | -------------- 6 | .. autoclass:: iio.Buffer 7 | :members: 8 | -------------------------------------------------------------------------------- /bindings/python/doc/channel.rst: -------------------------------------------------------------------------------- 1 | Channels 2 | ================== 3 | 4 | Members 5 | -------------- 6 | .. autoclass:: iio.Channel 7 | :members: 8 | 9 | -------------------- 10 | 11 | Channel attributes 12 | -------------------- 13 | .. autoclass:: iio.DataFormat 14 | :members: 15 | .. autoclass:: iio.ChannelModifier 16 | :members: 17 | .. autoclass:: iio.ChannelType 18 | :members: 19 | -------------------------------------------------------------------------------- /bindings/python/doc/conf.py.in: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 6 | 7 | # -- Path setup -------------------------------------------------------------- 8 | 9 | # If extensions (or modules to document with autodoc) are in another directory, 10 | # add these directories to sys.path here. If the directory is relative to the 11 | # documentation root, use os.path.abspath to make it absolute, like shown here. 12 | # 13 | import os 14 | import sys 15 | sys.path.insert(0, os.path.abspath('../.')) 16 | sys.path.insert(0, os.path.abspath('../examples')) 17 | 18 | # -- Project information ----------------------------------------------------- 19 | 20 | project = '@PROJECT_NAME@' 21 | copyright = '2020, Analog Devices, Inc.' 22 | author = 'Paul Cercueil ' 23 | 24 | # The full version, including alpha/beta/rc tags 25 | release = '@LIBIIO_VERSION@' 26 | 27 | 28 | # -- General configuration --------------------------------------------------- 29 | 30 | # Add any Sphinx extension module names here, as strings. They can be 31 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 32 | # ones. 33 | extensions = ["sphinx.ext.githubpages", 'sphinx.ext.viewcode', 'sphinx.ext.autodoc'] 34 | #] 35 | 36 | # Add any paths that contain templates here, relative to this directory. 37 | templates_path = ['_templates'] 38 | 39 | # List of patterns, relative to source directory, that match files and 40 | # directories to ignore when looking for source files. 41 | # This pattern also affects html_static_path and html_extra_path. 42 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] 43 | 44 | 45 | # -- Options for HTML output ------------------------------------------------- 46 | 47 | # Add any paths that contain custom static files (such as style sheets) here, 48 | # relative to this directory. They are copied after the builtin static files, 49 | # so a file named "default.css" will overwrite the builtin "default.css". 50 | #html_static_path = ['_static'] 51 | 52 | master_doc = 'index' 53 | -------------------------------------------------------------------------------- /bindings/python/doc/context.rst: -------------------------------------------------------------------------------- 1 | Contexts 2 | ================== 3 | 4 | Members 5 | -------------- 6 | .. autoclass:: iio.Context 7 | :members: 8 | 9 | .. autoclass:: iio.LocalContext 10 | :members: 11 | :inherited-members: 12 | 13 | .. autoclass:: iio.XMLContext 14 | :members: 15 | :inherited-members: 16 | 17 | .. autoclass:: iio.NetworkContext 18 | :members: 19 | :inherited-members: 20 | 21 | -------------------------------------------------------------------------------- /bindings/python/doc/device.rst: -------------------------------------------------------------------------------- 1 | Device 2 | ================== 3 | 4 | Members 5 | -------------- 6 | .. autoclass:: iio.Device 7 | :members: 8 | :inherited-members: 9 | -------------------------------------------------------------------------------- /bindings/python/doc/examples.rst: -------------------------------------------------------------------------------- 1 | Examples 2 | ================== 3 | 4 | 5 | Complete Application Examples 6 | ------------------------------ 7 | .. toctree:: 8 | iio_readdev 9 | iio_writedev 10 | iio_attr 11 | iio_info 12 | 13 | 14 | Code Snippets 15 | ----------------------------- 16 | 17 | Scan contexts and list channels of each device 18 | 19 | .. code-block:: python 20 | 21 | import iio 22 | 23 | for ctxname in iio.scan_contexts(): 24 | ctx = iio.Context(ctxname) 25 | for dev in ctx.devices: 26 | if dev.channels: 27 | for chan in dev.channels: 28 | print("{} - {} - {}".format(ctxname, dev.name, chan._id)) 29 | else: 30 | print("{} - {}".format(ctxname, dev.name)) 31 | 32 | -------------------------------------------------------------------------------- /bindings/python/doc/iio_attr.rst: -------------------------------------------------------------------------------- 1 | iio_attr 2 | ====================== 3 | | iio_attr is part of the Libiio package, a library that has been developed to ease the development of software interfacing Linux Industrial I/O (IIO) devices. 4 | | This tool is written using the libiio Python bindings. It works in a very similar way of how the base iio_attr works. You can find more information about it on this `page `_. 5 | 6 | .. automodule:: iio_attr 7 | :members: 8 | 9 | .. literalinclude:: ../examples/iio_attr.py 10 | :language: python 11 | 12 | -------------------------------------------------------------------------------- /bindings/python/doc/iio_info.rst: -------------------------------------------------------------------------------- 1 | iio_info 2 | ===================== 3 | | iio_info is part of the Libiio package, a library that has been developed to ease the development of software interfacing Linux Industrial I/O (IIO) devices. 4 | | This tool is written using the libiio Python bindings. It works in the same way as the base iio_info works. You can find more information about it on this `page `_. 5 | 6 | .. automodule:: iio_info 7 | :members: 8 | :undoc-members: 9 | -------------------------------------------------------------------------------- /bindings/python/doc/iio_readdev.rst: -------------------------------------------------------------------------------- 1 | iio_readdev 2 | ===================== 3 | | iio_readdev is part of the Libiio package, a library that has been developed to ease the development of software interfacing Linux Industrial I/O (IIO) devices. 4 | | This tool is written using the libiio Python bindings. It works in the same way as the base iio_readdev works. You can find more information about it on this `page `_. 5 | 6 | .. automodule:: iio_readdev 7 | :members: 8 | -------------------------------------------------------------------------------- /bindings/python/doc/iio_writedev.rst: -------------------------------------------------------------------------------- 1 | iio_writedev 2 | ===================== 3 | | iio_writedev is part of the Libiio package, a library that has been developed to ease the development of software interfacing Linux Industrial I/O (IIO) devices. 4 | | This tool is written using the libiio Python bindings. It works in the same way as the base iio_writedev works. You can find more information about it on this `page `_. 5 | 6 | .. automodule:: iio_writedev 7 | :members: 8 | -------------------------------------------------------------------------------- /bindings/python/doc/index.rst: -------------------------------------------------------------------------------- 1 | libiio Python Bindings 2 | ================================== 3 | 4 | Python bindings for the `Industrial I/O <../index.html>`_ interface library. 5 | 6 | Installation 7 | ================== 8 | 9 | The libiio python bindings can be installed from pip 10 | 11 | .. code-block:: bash 12 | 13 | (sudo) pip install pylibiio 14 | 15 | or by grabbing the source directly 16 | 17 | .. code-block:: bash 18 | 19 | git clone https://github.com/analogdevicesinc/libiio.git 20 | cd bindings/python 21 | (sudo) python3 setup.py install 22 | 23 | .. note:: 24 | 25 | On Linux the libiio python bindings are sometimes installed in locations not on path. On Ubuntu this is a common fix 26 | 27 | .. code-block:: bash 28 | 29 | export PYTHONPATH=$PYTHONPATH:/usr/lib/python{python-version}/site-packages 30 | 31 | .. toctree:: 32 | :maxdepth: 1 33 | :caption: Contents: 34 | 35 | Components 36 | ================== 37 | .. toctree:: 38 | :maxdepth: 1 39 | 40 | context 41 | buffer 42 | device 43 | channel 44 | trigger 45 | examples 46 | 47 | Indices and tables 48 | ================== 49 | 50 | * :ref:`genindex` 51 | * :ref:`modindex` 52 | * :ref:`search` 53 | -------------------------------------------------------------------------------- /bindings/python/doc/trigger.rst: -------------------------------------------------------------------------------- 1 | Trigger 2 | ================== 3 | 4 | Members 5 | -------------- 6 | .. autoclass:: iio.Trigger 7 | :members: 8 | :inherited-members: 9 | -------------------------------------------------------------------------------- /bindings/python/setup.py.cmakein: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # SPDX-License-Identifier: LGPL-2.1-or-later 3 | # 4 | # Copyright (C) 2015 Analog Devices, Inc. 5 | # Author: Paul Cercueil 6 | 7 | import sys 8 | 9 | if sys.version_info[0] < 3: 10 | from distutils.core import setup 11 | from distutils.command.install import install 12 | 13 | config = dict() 14 | else: 15 | from setuptools import setup 16 | from setuptools.command.install import install 17 | 18 | config = dict(long_description_content_type="text/markdown") 19 | 20 | description = "Library for interfacing with Linux IIO devices" 21 | 22 | try: 23 | with open("${CMAKE_CURRENT_SOURCE_DIR}/README.md", "r") as fh: 24 | long_description = fh.read() 25 | except: 26 | long_description = description 27 | 28 | 29 | def find_recursive(folder, filename): 30 | import os 31 | 32 | for root, dirs, files in os.walk(folder): 33 | for file in files: 34 | if file == filename: 35 | return os.path.join(root, file) 36 | 37 | 38 | class InstallWrapper(install): 39 | """Before installing we check if the 40 | libiio library is actually installed""" 41 | 42 | def run(self): 43 | self._check_libiio_installed() 44 | # Run the standard PyPi copy 45 | install.run(self) 46 | 47 | def _check_libiio_installed(self): 48 | cross_compiling = ("${CMAKE_CROSSCOMPILING}" == "TRUE") 49 | if cross_compiling: 50 | # When cross-compiling, we generally cannot dlopen 51 | # the libiio shared lib from the build platform. 52 | # Simply skip this check in that case. 53 | return 54 | 55 | from platform import system as _system 56 | from ctypes import CDLL as _cdll 57 | from ctypes.util import find_library 58 | from os import getenv 59 | from os.path import join 60 | 61 | iiolib = "iio" if "Darwin" in _system() else "libiio${CMAKE_SHARED_LIBRARY_SUFFIX}" 62 | 63 | destdir = getenv("DESTDIR", "") or "" 64 | destdir = join("${CMAKE_INSTALL_FULL_LIBDIR}", destdir) 65 | fulllibpath = find_recursive(destdir, iiolib) 66 | 67 | try: 68 | 69 | _lib = _cdll(fulllibpath, use_errno=True, use_last_error=True) 70 | if not _lib._name: 71 | raise OSError 72 | except OSError: 73 | msg = "The libiio library could not be found.\n\ 74 | libiio needs to be installed first before the python bindings.\n\ 75 | The latest release can be found on GitHub:\n\ 76 | https://github.com/analogdevicesinc/libiio/releases" 77 | raise Exception(msg) 78 | 79 | 80 | config.update( 81 | dict( 82 | name="pylibiio", 83 | version="${VERSION}", 84 | maintainer="Analog Devices, Inc", 85 | maintainer_email="travis.collins@analog.com", 86 | description=description, 87 | long_description=long_description, 88 | url="https://github.com/analogdevicesinc/libiio", 89 | py_modules=["iio"], 90 | cmdclass={"install": InstallWrapper}, 91 | classifiers=[ 92 | "Programming Language :: Python :: 3", 93 | "License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)", 94 | "Operating System :: OS Independent", 95 | ], 96 | ) 97 | ) 98 | 99 | 100 | setup(**config) 101 | -------------------------------------------------------------------------------- /cmake/CheckCaseSensitiveFileSystem.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Check if the file system is case sensitive or not 3 | # Inspired by Andreas Lauser's cmake at: 4 | # https://github.com/OPM/opm-parser/blob/master/cmake/Modules/CheckCaseSensitiveFileSystem.cmake 5 | # Included in libiio (LGPL2) with permission. 6 | # 7 | # Sets the following variable: 8 | # HAVE_CASE_SENSITIVE_FILESYSTEM True if the file system honors the case of files 9 | # 10 | # I dislike that we have to emit a file from CMake, but I can't think of a better way. 11 | 12 | message(STATUS "Check for case-sensitive file systems") 13 | string(RANDOM LENGTH 6 ALPHABET abcdefghijklmnopqrstuvwxyz TMP_FILE_L) 14 | set(TMP_FILE_L "${TMP_FILE_L}.tmp") 15 | string(TOUPPER ${TMP_FILE_L} TMP_FILE_U) 16 | string(TIMESTAMP TMP_TIME) 17 | set(TMP_FILE_CONTENTS "${TMP_FILE_L} ${TMP_TIME}") 18 | # create a uppercase file 19 | file(WRITE "${CMAKE_BINARY_DIR}/${TMP_FILE_U}" "${TMP_FILE_CONTENTS}") 20 | 21 | # test if lowercase file can be opened 22 | set(FileContents "") 23 | if (EXISTS "${CMAKE_BINARY_DIR}/${TMP_FILE_L}") 24 | file(READ "${CMAKE_BINARY_DIR}/${TMP_FILE_L}" FileContents) 25 | endif() 26 | 27 | # remove the file 28 | file(REMOVE "${CMAKE_BINARY_DIR}/${TMP_FILE_U}") 29 | 30 | # check the contents 31 | # If it is empty, the file system is case sensitive. 32 | if ("${FileContents}" STREQUAL "${TMP_FILE_CONTENTS}") 33 | message(STATUS "File system is not case-sensitive") 34 | set(HAVE_CASE_SENSITIVE_FILESYSTEM 0) 35 | else() 36 | message(STATUS "File system is case-sensitive") 37 | set(HAVE_CASE_SENSITIVE_FILESYSTEM 1) 38 | endif() 39 | -------------------------------------------------------------------------------- /cmake/DarwinPackaging.cmake: -------------------------------------------------------------------------------- 1 | # support creating some basic binpkgs via `make package` 2 | 3 | set(CPACK_SET_DESTDIR ON) 4 | set(CPACK_GENERATOR TGZ) 5 | 6 | set(CPACK_PACKAGE_VERSION_MAJOR ${LIBIIO_VERSION_MAJOR}) 7 | set(CPACK_PACKAGE_VERSION_MINOR ${LIBIIO_VERSION_MINOR}) 8 | set(CPACK_PACKAGE_VERSION_PATCH g${LIBIIO_VERSION_GIT}) 9 | set(CPACK_BUNDLE_NAME libiio) 10 | set(CPACK_PACKAGE_VERSION ${LIBIIO_VERSION}) 11 | 12 | include(CPack) 13 | -------------------------------------------------------------------------------- /cmake/Utilities.cmake: -------------------------------------------------------------------------------- 1 | function(check_pthread_set_name HAS_PTHREAD) 2 | include(CheckSymbolExists) 3 | set(CMAKE_REQUIRED_LIBRARIES ${PTHREAD_LIBRARIES}) 4 | set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) 5 | set(TMP_FLAGS "${CMAKE_C_FLAGS}") 6 | set(CMAKE_C_FLAGS "") 7 | check_symbol_exists(pthread_setname_np "pthread.h" ${HAS_PTHREAD}) 8 | set(CMAKE_C_FLAGS "${TMP_FLAGS}") 9 | set(CMAKE_REQUIRED_LIBRARIES) 10 | set(CMAKE_REQUIRED_DEFINITIONS) 11 | endfunction() -------------------------------------------------------------------------------- /cmake/add_requirements2tar.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # should be called from "make required2tar" 3 | set -e 4 | 5 | cd @CMAKE_BINARY_DIR@ 6 | 7 | manifest=./require_manifest.txt 8 | if [ ! -f ${manifest} ] ; then 9 | echo "Can not find manifest at ${manifest}" 10 | exit 1 11 | fi 12 | 13 | gz=$(ls ./libiio*.tar.gz) 14 | if [ -z "${gz}" ] ; then 15 | echo "try make package first" 16 | exit 1 17 | fi 18 | if [ "$(echo -n ${gz} | tr -cd ' \t' | wc -c)" -ne "0" ] ; then 19 | echo "too many tar, there should be only one, but found ${gz}" 20 | exit 1 21 | fi 22 | tar=$(echo ${gz} | sed 's/\.gz$//') 23 | 24 | #unzip the file (can not append while it is gzipped) 25 | #gunzip ${gz} 26 | 27 | # We should be able to just "tar --append -f ${tar} -T manufest.txt, but the tar on 28 | # CenrOS7 doesn't support that - so we we need to split it apart, and add 29 | # files manually. 30 | 31 | if [ -d tarball_fixup ] ; then 32 | rm -rf tarball_fixup 33 | fi 34 | mkdir tarball_fixup 35 | tar -xzf ${gz} -C ./tarball_fixup 36 | 37 | while read -r line 38 | do 39 | if [ -f ${line} ] ; then 40 | echo "adding ${line} to architve" 41 | #make sure the directory exists as a target 42 | mkdir -p ./tarball_fixup$(dirname ${line}) 43 | cp ${line} ./tarball_fixup${line} 44 | 45 | cd ./tarball_fixup$(dirname ${line}) 46 | line=$(basename ${line}) 47 | 48 | until echo ${line} | grep -q \.so.[0-9a-zA-Z.]*$ 49 | do 50 | tmp=$(echo ${line} | sed 's/\.[0-9a-zA-Z.]*$//') 51 | if [ ! -f "${tmp}" ] ; then 52 | ln -s ${line} ${tmp} 53 | else 54 | echo "target ${tmp} already exists" 55 | ls -l ${tmp} 56 | fi 57 | line=${tmp} 58 | done 59 | cd @CMAKE_BINARY_DIR@ 60 | 61 | else 62 | echo "could not find ${line} to copy" 63 | exit 1 64 | fi 65 | done < ${manifest} 66 | 67 | tar -czf ${gz} -C ./tarball_fixup/ . 68 | rm -rf tarball_fixup 69 | 70 | -------------------------------------------------------------------------------- /deps/README.txt: -------------------------------------------------------------------------------- 1 | Commits of the Libiio repository must *not* touch any file or directory 2 | present in the deps/ folder. 3 | 4 | The only commits allowed, are the one that are automatically created 5 | when adding a new dependency with: 6 | git subrepo clone https://... deps/new-dependency 7 | 8 | And the ones created when updating the external repository to the latest 9 | available with: 10 | git subrepo pull deps/my-dependency 11 | 12 | 13 | git-subrepo is an external tool that can be obtained here: 14 | https://github.com/ingydotnet/git-subrepo 15 | -------------------------------------------------------------------------------- /deps/libini/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | python/setup.py 3 | -------------------------------------------------------------------------------- /deps/libini/.gitrepo: -------------------------------------------------------------------------------- 1 | ; DO NOT EDIT (unless you know what you are doing) 2 | ; 3 | ; This subdirectory is a git "subrepo", and this file is maintained by the 4 | ; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme 5 | ; 6 | [subrepo] 7 | remote = https://github.com/pcercuei/libini.git 8 | branch = master 9 | commit = 27b90deb2afd9f9b907f724b7d8e27b2ef65f8be 10 | parent = ac52e1066890d3d6c9eae7ba8deb381e66221809 11 | method = merge 12 | cmdver = 0.4.9 13 | -------------------------------------------------------------------------------- /deps/libini/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1.0) 2 | project(libini LANGUAGES C VERSION 0.1) 3 | 4 | include(GNUInstallDirs) 5 | 6 | set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig" 7 | CACHE PATH "Installation directory for pkgconfig (.pc) files") 8 | 9 | set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries") 10 | if (NOT BUILD_SHARED_LIBS) 11 | set(INI_STATIC_CFLAGS -Dlibini_STATIC) 12 | endif (NOT BUILD_SHARED_LIBS) 13 | 14 | set(LIBINI_PC ${CMAKE_CURRENT_BINARY_DIR}/libini.pc) 15 | configure_file(libini.pc.cmakein ${LIBINI_PC} @ONLY) 16 | install(FILES ${LIBINI_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}") 17 | 18 | set(SETUP_PY ${CMAKE_CURRENT_SOURCE_DIR}/python/setup.py) 19 | configure_file(python/setup.py.cmakein ${SETUP_PY} @ONLY) 20 | 21 | set(LIBINI_CFILES libini.c) 22 | set(LIBINI_HEADERS ini.h) 23 | 24 | if (CMAKE_COMPILER_IS_GNUCC AND NOT WIN32) 25 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") 26 | endif() 27 | 28 | add_library(ini ${LIBINI_CFILES} ${LIBINI_HEADERS}) 29 | set_target_properties(ini PROPERTIES 30 | VERSION ${PROJECT_VERSION} 31 | SOVERSION ${PROJECT_VERSION_MAJOR} 32 | PUBLIC_HEADER ${LIBINI_HEADERS} 33 | ) 34 | 35 | target_compile_definitions(ini PUBLIC ${INI_STATIC_CFLAGS}) 36 | 37 | install(TARGETS ini 38 | ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" 39 | LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" 40 | RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" 41 | PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" 42 | ) 43 | -------------------------------------------------------------------------------- /deps/libini/example/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | TARGET = test 4 | 5 | CC = $(CROSS_COMPILE)gcc 6 | CFLAGS = -Wall -O2 7 | LDFLAGS = -lini 8 | 9 | OBJS = test.o 10 | 11 | .PHONY: all clean 12 | 13 | all: $(TARGET) 14 | 15 | $(TARGET): $(OBJS) 16 | $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ 17 | 18 | clean: 19 | rm -f $(OBJS) $(TARGET) 20 | -------------------------------------------------------------------------------- /deps/libini/example/test.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | int main(int argc, char **argv) 10 | { 11 | struct INI *ini; 12 | 13 | if (argc < 2) { 14 | printf("USAGE: test [INI_FILE]...\n"); 15 | return EXIT_SUCCESS; 16 | } 17 | 18 | ini = ini_open(argv[1]); 19 | if (!ini) 20 | return EXIT_FAILURE; 21 | printf("INI file opened.\n"); 22 | 23 | while (1) { 24 | const char *buf; 25 | char *name; 26 | size_t name_len; 27 | int res = ini_next_section(ini, &buf, &name_len); 28 | if (!res) { 29 | printf("End of file.\n"); 30 | break; 31 | } 32 | if (res < 0) { 33 | printf("ERROR: code %i\n", res); 34 | goto error; 35 | } 36 | 37 | name = alloca(name_len + 1); 38 | name[name_len] = '\0'; 39 | memcpy(name, buf, name_len); 40 | printf("Opening section: \'%s\'\n", name); 41 | 42 | while (1) { 43 | const char *buf2; 44 | char *key, *value; 45 | size_t key_len, value_len; 46 | res = ini_read_pair(ini, &buf, &key_len, &buf2, &value_len); 47 | if (!res) { 48 | printf("No more data.\n"); 49 | break; 50 | } 51 | if (res < 0) { 52 | printf("ERROR: code %i\n", res); 53 | goto error; 54 | } 55 | 56 | key = alloca(key_len + 1); 57 | key[key_len] = '\0'; 58 | memcpy(key, buf, key_len); 59 | value = alloca(value_len + 1); 60 | value[value_len] = '\0'; 61 | memcpy(value, buf2, value_len); 62 | printf("Reading key: \'%s\' value: \'%s\'\n", key, value); 63 | } 64 | } 65 | 66 | ini_close(ini); 67 | return EXIT_SUCCESS; 68 | 69 | error: 70 | ini_close(ini); 71 | return EXIT_FAILURE; 72 | } 73 | -------------------------------------------------------------------------------- /deps/libini/example/test.ini: -------------------------------------------------------------------------------- 1 | 2 | [Desktop Entry] 3 | 4 | # Name of the application 5 | Name = Foo 6 | 7 | # Short description about the application 8 | Comment = Foo's bar 9 | 10 | # Executable. Append ' %f' if a file is required, 11 | # e.g. 'foo %f' to load 'foo' with a file. 12 | Exec = test.elf %f 13 | 14 | # Set to 'true' if the application has to be launched inside a terminal. 15 | Terminal = false 16 | 17 | # Type of the link: always set to 'Applications' 18 | Type = Application 19 | 20 | # Whether or not the menu should notify that the application is being launched. 21 | StartupNotify = true 22 | 23 | # Name of the icon, WITHOUT EXTENSION, that should 24 | # be assignated to this application. 25 | Icon = nx 26 | 27 | # List of categories on which the application should appear. 28 | # A semicolon should separe the categories, and you must leave one 29 | # semicolon at the end of the list. 30 | Categories = games; 31 | 32 | # Alternative actions for this link 33 | Actions = Test; 34 | 35 | [Action Test] 36 | 37 | Test = This is a test. 38 | -------------------------------------------------------------------------------- /deps/libini/ini.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: LGPL-2.1-or-later 2 | /* 3 | * libini - Library to read INI configuration files 4 | * 5 | * Copyright (C) 2014 Paul Cercueil 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | */ 17 | 18 | #ifndef __INI_H 19 | #define __INI_H 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #ifdef _WIN32 26 | # ifdef ini_EXPORTS 27 | # define __api __declspec(dllexport) 28 | # elif !defined(libini_STATIC) 29 | # define __api __declspec(dllimport) 30 | # else 31 | # define __api 32 | # endif 33 | #elif __GNUC__ >= 4 34 | # define __api __attribute__((visibility ("default"))) 35 | #else 36 | # define __api 37 | #endif 38 | 39 | #include 40 | 41 | struct INI; 42 | 43 | __api struct INI *ini_open(const char *file); 44 | __api struct INI *ini_open_mem(const char *buf, size_t len); 45 | 46 | __api void ini_close(struct INI *ini); 47 | 48 | /* Jump to the next section. 49 | * if 'name' is set, the pointer passed as argument 50 | * points to the name of the section. 'name_len' is set to the length 51 | * of the char array. 52 | * XXX: the pointer will be invalid as soon as ini_close() is called. 53 | * 54 | * Returns: 55 | * -EIO if an error occurred while reading the file, 56 | * 0 if no more section can be found, 57 | * 1 otherwise. 58 | */ 59 | __api int ini_next_section(struct INI *ini, 60 | const char **name, size_t *name_len); 61 | 62 | /* Read a key/value pair. 63 | * 'key' and 'value' must be valid pointers. The pointers passed as arguments 64 | * will point to the key and value read. 'key_len' and 'value_len' are 65 | * set to the length of their respective char arrays. 66 | * XXX: the pointers will be invalid as soon as ini_close() is called. 67 | * 68 | * Returns: 69 | * -EIO if an error occurred while reading the file, 70 | * 0 if no more key/value pairs can be found, 71 | * 1 otherwise. 72 | */ 73 | __api int ini_read_pair(struct INI *ini, 74 | const char **key, size_t *key_len, 75 | const char **value, size_t *value_len); 76 | 77 | /* Set the read head to a specified offset. */ 78 | __api void ini_set_read_pointer(struct INI *ini, const char *pointer); 79 | 80 | /* Get the number of the line that contains the specified address. 81 | * 82 | * Returns: 83 | * -EINVAL if the pointer points outside the INI string, 84 | * The line number otherwise. 85 | */ 86 | __api int ini_get_line_number(struct INI *ini, const char *pointer); 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #undef __api 93 | 94 | #endif /* __INI_H */ 95 | -------------------------------------------------------------------------------- /deps/libini/libini.pc.cmakein: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ 4 | includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ 5 | 6 | Name: libini 7 | Description: library to read INI configuration files 8 | Version: @PROJECT_VERSION@ 9 | 10 | Requires: 11 | Libs: -L${libdir} -lini 12 | Cflags: -I${includedir} @INI_STATIC_CFLAGS@ 13 | -------------------------------------------------------------------------------- /deps/libini/python/ini.py: -------------------------------------------------------------------------------- 1 | from ctypes import POINTER, Structure, cdll, c_char_p, c_int, c_uint, byref 2 | from sys import argv 3 | 4 | def _checkOpen(result, func, arguments): 5 | if result: 6 | return result 7 | else: 8 | raise IOError("Failed to open INI file: '%s'" % arguments[0]) 9 | 10 | def _checkRead(result, func, arguments): 11 | if result == -1: 12 | raise SyntaxError("Error occured while parsing INI file") 13 | return result 14 | 15 | def _init(): 16 | class _INI(Structure): 17 | pass 18 | IniPtr = POINTER(_INI) 19 | 20 | lib = cdll.LoadLibrary('libini.so.0') 21 | 22 | ini_open = lib.ini_open 23 | ini_open.restype = IniPtr 24 | ini_open.archtypes = (c_char_p, ) 25 | ini_open.errcheck = _checkOpen 26 | global _ini_open 27 | _ini_open = ini_open 28 | 29 | ini_close = lib.ini_close 30 | ini_close.restype = None 31 | ini_close.archtypes = (IniPtr, ) 32 | global _ini_close 33 | _ini_close = ini_close 34 | 35 | ini_next_section = lib.ini_next_section 36 | ini_next_section.restype = c_int 37 | ini_next_section.archtypes = (IniPtr, c_char_p, c_uint) 38 | ini_next_section.errcheck = _checkRead 39 | global _ini_next_section 40 | _ini_next_section = ini_next_section 41 | 42 | ini_read_pair = lib.ini_read_pair 43 | ini_read_pair.restype = c_int 44 | ini_read_pair.archtypes = (IniPtr, c_char_p, c_uint, c_char_p, c_uint) 45 | ini_read_pair.errcheck = _checkRead 46 | global _ini_read_pair 47 | _ini_read_pair = ini_read_pair 48 | 49 | _init() 50 | 51 | class INI(object): 52 | 53 | def __init__(self, path): 54 | self._ini = _ini_open(path) 55 | 56 | def __del__(self): 57 | _ini_close(self._ini) 58 | 59 | def next_section(self): 60 | s = c_char_p() 61 | u = c_uint() 62 | res = _ini_next_section(self._ini, byref(s), byref(u)) 63 | if res == 1: 64 | return s.value[:u.value] 65 | 66 | def read_pair(self): 67 | key = c_char_p() 68 | key_len = c_uint() 69 | val = c_char_p() 70 | val_len = c_uint() 71 | res = _ini_read_pair(self._ini, \ 72 | byref(key), byref(key_len), \ 73 | byref(val), byref(val_len)) 74 | if res == 1: 75 | return (key.value[:key_len.value], val.value[:val_len.value]) 76 | return (None, None) 77 | 78 | 79 | def read_ini(filename): 80 | ini = INI(filename) 81 | ini_dict = {} 82 | first_section = True 83 | 84 | while True: 85 | section = ini.next_section() 86 | if not first_section and not section: 87 | break 88 | first_section = False 89 | 90 | section_dict = {} 91 | while True: 92 | key, value = ini.read_pair() 93 | if not key: 94 | break 95 | section_dict[key] = value 96 | 97 | ini_dict[section] = section_dict 98 | 99 | return ini_dict 100 | 101 | 102 | def main(): 103 | if len(argv) != 2: 104 | print "Usage: ini.py [INI_FILE]..." 105 | return 106 | 107 | ini = read_ini(argv[1]) 108 | print ini 109 | 110 | if __name__ == '__main__': 111 | main() 112 | -------------------------------------------------------------------------------- /deps/libini/python/setup.py.cmakein: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from distutils.core import setup 4 | 5 | setup(name='libini', 6 | version='@VERSION@', 7 | description='Library to handle INI configuration files', 8 | author='Paul Cercueil', 9 | author_email='paul@crapouillou.net', 10 | url='http://github.com/pcercuei/libini', 11 | py_modules=['ini'], 12 | ) 13 | -------------------------------------------------------------------------------- /deps/mdns/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | AlignAfterOpenBracket: Align 3 | AlignConsecutiveAssignments: 'false' 4 | AlignConsecutiveDeclarations: 'false' 5 | AlignOperands: 'true' 6 | AlignTrailingComments: 'true' 7 | AllowAllParametersOfDeclarationOnNextLine: 'false' 8 | AllowShortBlocksOnASingleLine: 'false' 9 | AllowShortCaseLabelsOnASingleLine: 'false' 10 | AllowShortFunctionsOnASingleLine: None 11 | AllowShortIfStatementsOnASingleLine: 'false' 12 | AllowShortLoopsOnASingleLine: 'false' 13 | AlwaysBreakAfterDefinitionReturnType: TopLevel 14 | AlwaysBreakAfterReturnType: TopLevel 15 | AlwaysBreakBeforeMultilineStrings: 'true' 16 | AlwaysBreakTemplateDeclarations: 'true' 17 | BinPackArguments: 'true' 18 | BinPackParameters: 'true' 19 | BreakBeforeBinaryOperators: None 20 | BreakBeforeBraces: Attach 21 | BreakBeforeTernaryOperators: 'false' 22 | ColumnLimit: '100' 23 | ConstructorInitializerAllOnOneLineOrOnePerLine: 'false' 24 | DerivePointerAlignment: 'false' 25 | ExperimentalAutoDetectBinPacking: 'false' 26 | IndentCaseLabels: 'true' 27 | IndentWidth: '4' 28 | IndentWrappedFunctionNames: 'false' 29 | KeepEmptyLinesAtTheStartOfBlocks: 'false' 30 | MaxEmptyLinesToKeep: '1' 31 | NamespaceIndentation: None 32 | ObjCSpaceAfterProperty: 'true' 33 | ObjCSpaceBeforeProtocolList: 'true' 34 | PointerAlignment: Left 35 | SortIncludes: 'false' 36 | SpaceAfterCStyleCast: 'false' 37 | SpaceAfterTemplateKeyword: 'true' 38 | SpaceBeforeAssignmentOperators: 'true' 39 | SpaceBeforeParens: ControlStatements 40 | SpaceInEmptyParentheses: 'false' 41 | SpacesInAngles: 'false' 42 | SpacesInCStyleCastParentheses: 'false' 43 | SpacesInContainerLiterals: 'false' 44 | SpacesInParentheses: 'false' 45 | SpacesInSquareBrackets: 'false' 46 | TabWidth: '4' 47 | UseTab: ForIndentation 48 | -------------------------------------------------------------------------------- /deps/mdns/.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Never mangle resource blob files 5 | *.blob -text 6 | 7 | # Custom for Visual Studio 8 | *.cs diff=csharp 9 | *.sln merge=union 10 | *.csproj merge=union 11 | *.vbproj merge=union 12 | *.fsproj merge=union 13 | *.dbproj merge=union 14 | 15 | # Standard to msysgit 16 | *.doc diff=astextplain 17 | *.DOC diff=astextplain 18 | *.docx diff=astextplain 19 | *.DOCX diff=astextplain 20 | *.dot diff=astextplain 21 | *.DOT diff=astextplain 22 | *.pdf diff=astextplain 23 | *.PDF diff=astextplain 24 | *.rtf diff=astextplain 25 | *.RTF diff=astextplain 26 | 27 | # Ignore build scripts in language stats 28 | build/* linguist-vendored 29 | configure.py linguist-vendored=true 30 | -------------------------------------------------------------------------------- /deps/mdns/.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [mjansson] 4 | -------------------------------------------------------------------------------- /deps/mdns/.gitrepo: -------------------------------------------------------------------------------- 1 | ; DO NOT EDIT (unless you know what you are doing) 2 | ; 3 | ; This subdirectory is a git "subrepo", and this file is maintained by the 4 | ; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme 5 | ; 6 | [subrepo] 7 | remote = https://github.com/mjansson/mdns 8 | branch = main 9 | commit = 23c6f01bb8c68e0e9f6c1ee17b7ae721344925ab 10 | parent = 3cd8a773dfe49c7a6a61bdc0f437b34ff4787f11 11 | method = merge 12 | cmdver = 0.4.9 13 | -------------------------------------------------------------------------------- /deps/mdns/CHANGELOG: -------------------------------------------------------------------------------- 1 | 1.4.3 2 | 3 | Fixed a possible buffer overflow in txt record parse 4 | 5 | Fixed parsing boolean txt records (keys without value) 6 | 7 | Ignore questions field in query receive, allowing replies with multiple questions 8 | 9 | 10 | 1.4.2 11 | 12 | Add mdns_goodbye_multicast function to send end of service announcement 13 | 14 | Fix the rclass and TTL for announce and goodbye to avoid flush flag on shared records 15 | 16 | Fixed an issue with parsing multiple answer records in discovery 17 | 18 | All authority and additional records are now sent to service callback function 19 | 20 | Various code cleanups, making all functions inline declared. 21 | 22 | Added a dump mode to the example application for listing all mDNS traffic on port 5353 23 | 24 | 25 | 1.4.1 26 | 27 | Use const pointers in socket open and setup functions. 28 | 29 | Avoid null pointer arithmetics for standard compliance. 30 | 31 | 32 | 1.4 33 | 34 | Returning non-zero from callback function during record parsing immedediately stops parsing and returns the number of records parsed so far. 35 | 36 | The function to send a query answer has been split in two, one for unicast answer and one for multicast. 37 | 38 | The functions to send query answers have been generalized to send any number of records. 39 | 40 | Added new function to do multicast announce on start/wake-up (unsolicited answer). 41 | 42 | Added parsing of ANY question records and DNS-SD queries with multiple questions 43 | 44 | Removed mdns_discovery_answer in favour of the new generalized answer functions, to handle both unicast and multicast response 45 | -------------------------------------------------------------------------------- /deps/mdns/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | project(mdns VERSION 1.4.2 LANGUAGES C) 3 | 4 | option(MDNS_BUILD_EXAMPLE "build example" ON) 5 | 6 | # Set the output of the libraries and executables. 7 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) 8 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) 9 | 10 | # ############################################################################## 11 | # library 12 | # ############################################################################## 13 | 14 | include(GNUInstallDirs) 15 | 16 | add_library(${PROJECT_NAME} INTERFACE) 17 | target_include_directories( 18 | ${PROJECT_NAME} INTERFACE $ 19 | $) 20 | if(WIN32) 21 | target_link_libraries(${PROJECT_NAME} INTERFACE iphlpapi ws2_32) 22 | endif() 23 | add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) 24 | target_compile_features(${PROJECT_NAME} INTERFACE c_std_99) 25 | 26 | # ############################################################################## 27 | # example 28 | # ############################################################################## 29 | 30 | if(MDNS_BUILD_EXAMPLE) 31 | add_executable(${PROJECT_NAME}_example mdns.c) 32 | target_link_libraries(${PROJECT_NAME}_example ${PROJECT_NAME}) 33 | endif() 34 | 35 | # ############################################################################## 36 | # install 37 | # ############################################################################## 38 | 39 | install( 40 | TARGETS ${PROJECT_NAME} 41 | EXPORT ${PROJECT_NAME}_Targets 42 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 43 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 44 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 45 | 46 | include(CMakePackageConfigHelpers) 47 | if(${CMAKE_VERSION} VERSION_LESS 3.14) 48 | write_basic_package_version_file( 49 | "${PROJECT_NAME}ConfigVersion.cmake" 50 | VERSION ${PROJECT_VERSION} 51 | COMPATIBILITY SameMajorVersion) 52 | else() 53 | write_basic_package_version_file( 54 | "${PROJECT_NAME}ConfigVersion.cmake" 55 | VERSION ${PROJECT_VERSION} 56 | COMPATIBILITY SameMajorVersion 57 | ARCH_INDEPENDENT) 58 | endif() 59 | 60 | configure_package_config_file( 61 | "${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in" 62 | "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" INSTALL_DESTINATION 63 | ${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}) 64 | 65 | install( 66 | EXPORT ${PROJECT_NAME}_Targets 67 | FILE ${PROJECT_NAME}Targets.cmake 68 | NAMESPACE ${PROJECT_NAME}:: 69 | DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}) 70 | 71 | install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" 72 | "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" 73 | DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}) 74 | 75 | install(FILES "${PROJECT_SOURCE_DIR}/mdns.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) 76 | -------------------------------------------------------------------------------- /deps/mdns/LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /deps/mdns/cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") 4 | check_required_components("@PROJECT_NAME@") 5 | -------------------------------------------------------------------------------- /deps/wingetopt/.gitignore: -------------------------------------------------------------------------------- 1 | CMakeCache.txt 2 | CMakeFiles 3 | Makefile 4 | cmake_install.cmake 5 | install_manifest.txt 6 | build 7 | *.lib 8 | *.pdb 9 | -------------------------------------------------------------------------------- /deps/wingetopt/.gitrepo: -------------------------------------------------------------------------------- 1 | ; DO NOT EDIT (unless you know what you are doing) 2 | ; 3 | ; This subdirectory is a git "subrepo", and this file is maintained by the 4 | ; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme 5 | ; 6 | [subrepo] 7 | remote = https://github.com/alex85k/wingetopt.git 8 | branch = master 9 | commit = aaaf910fec3f1fbe9da74eb96241d1f9a99baa93 10 | parent = 44127bc1eb7c5bfe8ac9c4854c6273750c3ceaa8 11 | method = merge 12 | cmdver = 0.4.3 13 | -------------------------------------------------------------------------------- /deps/wingetopt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | PROJECT(wingetopt) 2 | cmake_minimum_required(VERSION 2.8) 3 | 4 | option(BUILD_SHARED_LIBS "Build the shared library" OFF) 5 | 6 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) 7 | 8 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 9 | 10 | if(BUILD_SHARED_LIBS) 11 | set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) 12 | add_definitions(-DBUILDING_WINGETOPT_DLL -DWINGETOPT_SHARED_LIB) 13 | endif() 14 | 15 | add_library(wingetopt src/getopt.c src/getopt.h) 16 | 17 | install(FILES src/getopt.h DESTINATION include) 18 | 19 | install(TARGETS wingetopt 20 | RUNTIME DESTINATION bin 21 | LIBRARY DESTINATION lib 22 | ARCHIVE DESTINATION lib) 23 | 24 | -------------------------------------------------------------------------------- /deps/wingetopt/LICENSE: -------------------------------------------------------------------------------- 1 | #### AUTHORS: 2 | 3 | * Todd C. Miller 4 | * The NetBSD Foundation, Inc. 5 | * Alexei Kasatkin is the author of trivial CMakeLists.txt, build script itself is Public Domain 6 | 7 | #### LICENSE 8 | 9 | Copyright (c) 2002 Todd C. Miller 10 | 11 | Permission to use, copy, modify, and distribute this software for any 12 | purpose with or without fee is hereby granted, provided that the above 13 | copyright notice and this permission notice appear in all copies. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 16 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 17 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 18 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 21 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 22 | 23 | Sponsored in part by the Defense Advanced Research Projects 24 | Agency (DARPA) and Air Force Research Laboratory, Air Force 25 | Materiel Command, USAF, under agreement number F39502-99-1-0512. 26 | 27 | *** 28 | 29 | Copyright (c) 2000 The NetBSD Foundation, Inc. 30 | All rights reserved. 31 | 32 | This code is derived from software contributed to The NetBSD Foundation 33 | by Dieter Baron and Thomas Klausner. 34 | 35 | Redistribution and use in source and binary forms, with or without 36 | modification, are permitted provided that the following conditions 37 | are met: 38 | 1. Redistributions of source code must retain the above copyright 39 | notice, this list of conditions and the following disclaimer. 40 | 2. Redistributions in binary form must reproduce the above copyright 41 | notice, this list of conditions and the following disclaimer in the 42 | documentation and/or other materials provided with the distribution. 43 | 44 | THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 45 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 47 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 48 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 49 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 50 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 51 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 52 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 53 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 54 | POSSIBILITY OF SUCH DAMAGE. 55 | -------------------------------------------------------------------------------- /deps/wingetopt/README.md: -------------------------------------------------------------------------------- 1 | # wingetopt 2 | 3 | getopt library for Windows compilers 4 | 5 | 6 | This library was created to allow compilation Linux-based software on Windows. 7 | http://en.wikipedia.org/wiki/Getopt 8 | 9 | The sources were taken from MinGW-runtime project. 10 | 11 | #### AUTHORS: 12 | 13 | * Todd C. Miller 14 | * The NetBSD Foundation, Inc. 15 | 16 | #### LICENSE 17 | 18 | Copyright (c) 2002 Todd C. Miller 19 | 20 | Permission to use, copy, modify, and distribute this software for any 21 | purpose with or without fee is hereby granted, provided that the above 22 | copyright notice and this permission notice appear in all copies. 23 | 24 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 25 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 27 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 28 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 29 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 30 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 31 | 32 | Sponsored in part by the Defense Advanced Research Projects 33 | Agency (DARPA) and Air Force Research Laboratory, Air Force 34 | Materiel Command, USAF, under agreement number F39502-99-1-0512. 35 | 36 | *** 37 | 38 | Copyright (c) 2000 The NetBSD Foundation, Inc. 39 | All rights reserved. 40 | 41 | This code is derived from software contributed to The NetBSD Foundation 42 | by Dieter Baron and Thomas Klausner. 43 | 44 | Redistribution and use in source and binary forms, with or without 45 | modification, are permitted provided that the following conditions 46 | are met: 47 | 1. Redistributions of source code must retain the above copyright 48 | notice, this list of conditions and the following disclaimer. 49 | 2. Redistributions in binary form must reproduce the above copyright 50 | notice, this list of conditions and the following disclaimer in the 51 | documentation and/or other materials provided with the distribution. 52 | 53 | THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 54 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 55 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 56 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 57 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 58 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 59 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 60 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 61 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 62 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 63 | POSSIBILITY OF SUCH DAMAGE. 64 | -------------------------------------------------------------------------------- /deps/wingetopt/meson.build: -------------------------------------------------------------------------------- 1 | project( 2 | 'wingetopt', 3 | 'c', 4 | version: '0.95', 5 | license : ['ISC', 'BSD-3-Clause'], 6 | meson_version: '>= 0.55', 7 | default_options: [ 8 | 'warning_level=1', 9 | ], 10 | ) 11 | 12 | compiler = meson.get_compiler('c') 13 | 14 | c_args = [] 15 | 16 | if compiler.get_id() == 'msvc' 17 | c_args += [ 18 | '-D_CRT_SECURE_NO_WARNINGS', 19 | ] 20 | 21 | if get_option('default_library') == 'shared' 22 | c_args += [ 23 | '-DBUILDING_WINGETOPT_DLL', 24 | '-DWINGETOPT_SHARED_LIB', 25 | ] 26 | endif 27 | endif 28 | 29 | wingetopt_lib = library( 30 | 'wingetopt', 31 | 'src/getopt.c', 32 | include_directories: include_directories( 33 | 'src', 34 | ), 35 | c_args: c_args, 36 | ) 37 | 38 | wingetopt_dep = declare_dependency( 39 | link_with: wingetopt_lib, 40 | include_directories: include_directories( 41 | 'src', 42 | ), 43 | ) 44 | -------------------------------------------------------------------------------- /dns_sd.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2014-2020 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | * Robin Getz 8 | */ 9 | 10 | #ifndef __IIO_DNS_SD_H 11 | #define __IIO_DNS_SD_H 12 | 13 | #include 14 | #include 15 | 16 | #ifdef _WIN32 17 | #include 18 | #include 19 | #include 20 | #else 21 | #include 22 | #include 23 | #endif 24 | 25 | /* IPv6 Max = 4*8 + 7 + 1 for '%' + interface length */ 26 | #define DNS_SD_ADDRESS_STR_MAX (40 + IF_NAMESIZE) 27 | 28 | /* MacOS doesn't include ENOMEDIUM (No medium found) like Linux does */ 29 | #ifndef ENOMEDIUM 30 | #define ENOMEDIUM ENOENT 31 | #endif 32 | 33 | /* Used everywhere */ 34 | #define IIOD_PORT 30431 35 | 36 | struct addrinfo; 37 | struct AvahiSimplePoll; 38 | struct AvahiAddress; 39 | struct iio_context_params; 40 | struct iio_scan; 41 | 42 | /* Common structure which all dns_sd_[*] files fill out 43 | * Anything that is dynamically allocated (malloc) needs to be managed 44 | */ 45 | struct dns_sd_discovery_data { 46 | struct iio_mutex *lock; 47 | struct AvahiSimplePoll *poll; 48 | struct AvahiAddress *address; 49 | uint16_t found, resolved; 50 | char addr_str[DNS_SD_ADDRESS_STR_MAX]; 51 | char *hostname; 52 | uint16_t port, iface; 53 | struct dns_sd_discovery_data *next; 54 | }; 55 | 56 | struct dns_sd_cb_data { 57 | struct dns_sd_discovery_data *d; 58 | const struct iio_context_params *params; 59 | }; 60 | 61 | /* These functions are common, and implemented in dns_sd_[*].c based on the 62 | * implementations: avahi (linux), bonjour (mac), or ServiceDiscovery (Win10) 63 | */ 64 | 65 | /* Resolves all IIO hosts on the available networks, and passes back a linked list */ 66 | int dnssd_find_hosts(const struct iio_context_params *params, 67 | struct dns_sd_discovery_data **ddata); 68 | 69 | /* Deallocates complete list of discovery data */ 70 | void dnssd_free_all_discovery_data(const struct iio_context_params *params, 71 | struct dns_sd_discovery_data *d); 72 | 73 | /* These functions are common, and found in dns_sd.c, but are used in the 74 | * dns_sd_[*].c implementations or network.c 75 | */ 76 | 77 | /* Passed back the first (random) IIOD service resolved by DNS DS. */ 78 | int dnssd_discover_host(const struct iio_context_params *params, 79 | char *addr_str, size_t addr_len, uint16_t *port); 80 | 81 | /* remove duplicates from the list */ 82 | void remove_dup_discovery_data(const struct iio_context_params *params, 83 | struct dns_sd_discovery_data **ddata); 84 | 85 | /* port knocks */ 86 | void port_knock_discovery_data(const struct iio_context_params *params, 87 | struct dns_sd_discovery_data **ddata); 88 | 89 | /* Use dnssd to resolve a given hostname */ 90 | int dnssd_resolve_host(const struct iio_context_params *params, 91 | const char *hostname, char *ip_addr, const int addr_len); 92 | 93 | int dnssd_context_scan(const struct iio_context_params *params, 94 | struct iio_scan *ctx, const char *args); 95 | 96 | #endif /* __IIO_DNS_SD_H */ 97 | -------------------------------------------------------------------------------- /doc/html/img/ADI_Logo_AWP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/ADI_Logo_AWP.png -------------------------------------------------------------------------------- /doc/html/img/Chromium-OS-Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/Chromium-OS-Logo.png -------------------------------------------------------------------------------- /doc/html/img/GNURadio_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/GNURadio_logo.png -------------------------------------------------------------------------------- /doc/html/img/PyADI-IIO_Logo_72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/PyADI-IIO_Logo_72.png -------------------------------------------------------------------------------- /doc/html/img/ez.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/ez.png -------------------------------------------------------------------------------- /doc/html/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/favicon.ico -------------------------------------------------------------------------------- /doc/html/img/fb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/fb.png -------------------------------------------------------------------------------- /doc/html/img/gp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/gp.png -------------------------------------------------------------------------------- /doc/html/img/ig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/ig.png -------------------------------------------------------------------------------- /doc/html/img/iio_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/iio_logo.png -------------------------------------------------------------------------------- /doc/html/img/legato_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/legato_logo.png -------------------------------------------------------------------------------- /doc/html/img/li.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/li.png -------------------------------------------------------------------------------- /doc/html/img/mangOH_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/mangOH_logo.png -------------------------------------------------------------------------------- /doc/html/img/mathworks_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/mathworks_logo.png -------------------------------------------------------------------------------- /doc/html/img/osc128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/osc128.png -------------------------------------------------------------------------------- /doc/html/img/scopy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/scopy.png -------------------------------------------------------------------------------- /doc/html/img/sdrangel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/sdrangel.png -------------------------------------------------------------------------------- /doc/html/img/ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/ss.png -------------------------------------------------------------------------------- /doc/html/img/sw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/sw.png -------------------------------------------------------------------------------- /doc/html/img/tw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/tw.png -------------------------------------------------------------------------------- /doc/html/img/yk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/yk.png -------------------------------------------------------------------------------- /doc/html/img/yt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analogdevicesinc/libiio/45b6b3e4b8071b8a08b1bd9716472d2889c3856a/doc/html/img/yt.png -------------------------------------------------------------------------------- /doc/template/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /dynamic-unix.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: LGPL-2.1-or-later 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2021 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | #include "dynamic.h" 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | void * iio_dlopen(const char *path) 16 | { 17 | return dlopen(path, RTLD_LAZY | RTLD_LOCAL); 18 | } 19 | 20 | void iio_dlclose(void *lib) 21 | { 22 | dlclose(lib); 23 | } 24 | 25 | void * iio_dlsym(void *lib, const char *symbol) 26 | { 27 | void *ptr; 28 | 29 | dlerror(); 30 | ptr = dlsym(lib, symbol); 31 | 32 | return dlerror() ? iio_ptr(-EINVAL) : ptr; 33 | } 34 | -------------------------------------------------------------------------------- /dynamic-windows.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: LGPL-2.1-or-later 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2021 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | #include "dynamic.h" 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | void * iio_dlopen(const char *path) 16 | { 17 | return LoadLibrary(TEXT(path)); 18 | } 19 | 20 | void iio_dlclose(void *lib) 21 | { 22 | FreeLibrary((void *) lib); 23 | } 24 | 25 | void * iio_dlsym(void *lib, const char *symbol) 26 | { 27 | void *ptr; 28 | 29 | ptr = GetProcAddress(lib, symbol); 30 | 31 | return ptr ? ptr : iio_ptr(-EINVAL); 32 | } 33 | -------------------------------------------------------------------------------- /dynamic.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2022 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | #ifndef __IIO_DYNAMIC_H 10 | #define __IIO_DYNAMIC_H 11 | 12 | #include 13 | 14 | struct iio_context_params; 15 | 16 | void * iio_dlopen(const char *path); 17 | void iio_dlclose(void *lib); 18 | void * iio_dlsym(void *lib, const char *symbol); 19 | 20 | bool iio_has_backend_dynamic(const struct iio_context_params *params, 21 | const char *name); 22 | 23 | #endif /* __IIO_DYNAMIC_H */ 24 | -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | ad9361-iiostream 2 | ad9371-iiostream 3 | adrv9009-iiostream 4 | dummy-iiostream 5 | iio-monitor 6 | !Makefile 7 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # libiio Examples 2 | 3 | The libiio is a cross platform library for interfacing with Linux IIO devices. 4 | 5 | These are some primitive examples of using the libiio library. 6 | 7 | These are only build if the -DWITH_EXAMPLES=ON is provided to the standard Cmake. 8 | 9 | While the libiio library is tested on many operating systems, these examples are only tested on Linux. 10 | 11 | More examples using all languages supported by libiio are encouraged to be added here. 12 | When adding a new example, please update this list. 13 | 14 | ## ad9361-iiostream 15 | * Language : C 16 | 17 | This example libiio program is meant to exercise the features of IIO functionality on the AD9361 found on the AD-FMCOMMS2-EBZ, AD-FMCOMMS3-EBZ, and the ADRV9361-Z7035 RF SOM. 18 | It takes the uri as the only argument. for example : `./ad9361-iiostream usb:3.32.5` 19 | 20 | ## ad9371-iiostream 21 | * Language : C 22 | 23 | This example libiio program is meant to exercise the features of IIO functionality on the AD9371. 24 | It takes the uri as the only argument. for example : `./ad9371-iiostream ip:192.168.2.1` 25 | 26 | ## adrv9009-iiostream 27 | * Language : C 28 | 29 | This example libiio program is meant to exercise the features of IIO functionality on the ADRV9009. 30 | It takes the uri as the only argument. for example : `./adrv9009-iiostream ip:192.168.2.1` 31 | 32 | ## dummy-iiostream 33 | * Language : C 34 | 35 | This example libiio program is meant to exercise the features of IIO present in the sample dummy IIO device in the linux kernel. 36 | For buffered access it relies on the hrtimer trigger but could be modified to use the sysfs trigger. 37 | No hardware should be required to run this program. 38 | 39 | ## iio-monitor 40 | * Language : C 41 | * Requirements : Curses Development Kit (libcdk5-dev); pthreads; ncurses; libiio 42 | 43 | A Curses based application which implements real time monitoring of IIO non-buffer samples. 44 | 45 | ## iopp-enum 46 | * Language : C++ 47 | 48 | Demonstrates the usage of the C++ API. 49 | -------------------------------------------------------------------------------- /examples/iiostream-common.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: LGPL-2.1-or-later 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2022 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | #include "iiostream-common.h" 10 | 11 | #include 12 | #include 13 | 14 | static bool stop = false; 15 | 16 | void stop_stream(void) 17 | { 18 | stop = true; 19 | } 20 | 21 | void stream(size_t rx_sample, size_t tx_sample, size_t block_size, 22 | struct iio_stream *rxstream, struct iio_stream *txstream, 23 | const struct iio_channel *rxchn, const struct iio_channel *txchn) 24 | { 25 | const struct iio_device *dev; 26 | const struct iio_context *ctx; 27 | const struct iio_block *txblock, *rxblock; 28 | ssize_t nrx = 0; 29 | ssize_t ntx = 0; 30 | int err; 31 | 32 | dev = iio_channel_get_device(rxchn); 33 | ctx = iio_device_get_context(dev); 34 | 35 | while (!stop) { 36 | int16_t *p_dat, *p_end; 37 | ptrdiff_t p_inc; 38 | 39 | rxblock = iio_stream_get_next_block(rxstream); 40 | err = iio_err(rxblock); 41 | if (err) { 42 | ctx_perror(ctx, err, "Unable to receive block"); 43 | return; 44 | } 45 | 46 | txblock = iio_stream_get_next_block(txstream); 47 | err = iio_err(txblock); 48 | if (err) { 49 | ctx_perror(ctx, err, "Unable to send block"); 50 | return; 51 | } 52 | 53 | /* READ: Get pointers to RX buf and read IQ from RX buf port 0 */ 54 | p_inc = rx_sample; 55 | p_end = iio_block_end(rxblock); 56 | for (p_dat = iio_block_first(rxblock, rxchn); p_dat < p_end; 57 | p_dat += p_inc / sizeof(*p_dat)) { 58 | /* Example: swap I and Q */ 59 | int16_t i = p_dat[0]; 60 | int16_t q = p_dat[1]; 61 | 62 | p_dat[0] = q; 63 | p_dat[1] = i; 64 | } 65 | 66 | /* WRITE: Get pointers to TX buf and write IQ to TX buf port 0 */ 67 | p_inc = tx_sample; 68 | p_end = iio_block_end(txblock); 69 | for (p_dat = iio_block_first(txblock, txchn); p_dat < p_end; 70 | p_dat += p_inc / sizeof(*p_dat)) { 71 | p_dat[0] = 0; /* Real (I) */ 72 | p_dat[1] = 0; /* Imag (Q) */ 73 | } 74 | 75 | nrx += block_size / rx_sample; 76 | ntx += block_size / tx_sample; 77 | ctx_info(ctx, "\tRX %8.2f MSmp, TX %8.2f MSmp\n", nrx / 1e6, ntx / 1e6); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /examples/iiostream-common.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2022 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | #ifndef __IIOSTREAM_COMMON_H__ 10 | #define __IIOSTREAM_COMMON_H__ 11 | 12 | #include 13 | 14 | struct iio_channel; 15 | struct iio_stream; 16 | 17 | void stop_stream(void); 18 | 19 | void stream(size_t rx_sample, size_t tx_sample, size_t block_size, 20 | struct iio_stream *rxstream, struct iio_stream *txstream, 21 | const struct iio_channel *rxchn, const struct iio_channel *txchn); 22 | 23 | #endif /* __IIOSTREAM_COMMON_H__ */ 24 | -------------------------------------------------------------------------------- /iio-config.h.cmakein: -------------------------------------------------------------------------------- 1 | #ifndef IIO_CONFIG_H 2 | #define IIO_CONFIG_H 3 | 4 | #define LIBIIO_VERSION_MAJOR @LIBIIO_VERSION_MAJOR@ 5 | #define LIBIIO_VERSION_MINOR @LIBIIO_VERSION_MINOR@ 6 | #define LIBIIO_VERSION_GIT "@LIBIIO_VERSION_GIT@" 7 | 8 | #define LOG_LEVEL @LOG_LEVEL@_L 9 | #define DEFAULT_LOG_LEVEL @DEFAULT_LOG_LEVEL@ 10 | #define MAX_LOG_LEVEL @MAX_LOG_LEVEL_VALUE@ 11 | 12 | #define IIO_MODULES_DIR "@IIO_MODULES_DIR@" 13 | #define IIO_LIBRARY_SUFFIX "@CMAKE_SHARED_LIBRARY_SUFFIX@" 14 | 15 | #define IF_ENABLED(cfg, ptr) ((cfg) ? (ptr) : NULL) 16 | 17 | #define LIBIIO_SCAN_BACKENDS "@LIBIIO_SCAN_BACKENDS@" 18 | 19 | #cmakedefine01 WITH_LOCAL_BACKEND 20 | #cmakedefine01 WITH_XML_BACKEND 21 | #cmakedefine01 WITH_NETWORK_BACKEND 22 | #cmakedefine01 WITH_USB_BACKEND 23 | #cmakedefine01 WITH_SERIAL_BACKEND 24 | #cmakedefine01 WITH_EXTERNAL_BACKEND 25 | 26 | #cmakedefine01 WITH_MODULES 27 | #cmakedefine01 WITH_NETWORK_BACKEND_DYNAMIC 28 | #cmakedefine01 WITH_SERIAL_BACKEND_DYNAMIC 29 | #cmakedefine01 WITH_USB_BACKEND_DYNAMIC 30 | 31 | #cmakedefine01 WITH_NETWORK_EVENTFD 32 | #cmakedefine01 WITH_IIOD_NETWORK 33 | #cmakedefine01 WITH_IIOD_USBD 34 | #cmakedefine01 WITH_IIOD_SERIAL 35 | #cmakedefine01 WITH_IIOD_USB_DMABUF 36 | #cmakedefine01 WITH_IIOD_V0_COMPAT 37 | #cmakedefine01 WITH_LOCAL_CONFIG 38 | #cmakedefine01 WITH_LOCAL_DMABUF_API 39 | #cmakedefine01 WITH_LOCAL_MMAP_API 40 | #cmakedefine01 WITH_HWMON 41 | #cmakedefine01 WITH_AIO 42 | #cmakedefine01 HAVE_DNS_SD 43 | #cmakedefine01 HAVE_AVAHI 44 | #cmakedefine01 WITH_ZSTD 45 | #cmakedefine01 NO_THREADS 46 | 47 | #cmakedefine HAS_PIPE2 48 | #cmakedefine HAS_STRDUP 49 | #cmakedefine HAS_STRNDUP 50 | #cmakedefine HAS_STRTOK_R 51 | #cmakedefine HAS_STRERROR_R 52 | #cmakedefine HAS_NEWLOCALE 53 | #cmakedefine HAS_PTHREAD_SETNAME_NP 54 | #cmakedefine HAVE_IPV6 55 | 56 | #define IF_ENABLED(cfg, ptr) ((cfg) ? (ptr) : NULL) 57 | 58 | #endif /* IIO_CONFIG_H */ 59 | -------------------------------------------------------------------------------- /iiod/.gitignore: -------------------------------------------------------------------------------- 1 | iiod 2 | parser.c 3 | parser.h 4 | lexer.c 5 | -------------------------------------------------------------------------------- /iiod/debug.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2014 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | #ifndef __IIOD_DEBUG_H__ 10 | #define __IIOD_DEBUG_H__ 11 | 12 | #include 13 | 14 | extern struct iio_context_params iiod_params; 15 | 16 | #define IIO_DEBUG(...) \ 17 | prm_dbg(&iiod_params, __VA_ARGS__) 18 | 19 | #define IIO_INFO(...) \ 20 | prm_info(&iiod_params, __VA_ARGS__) 21 | 22 | #define IIO_WARNING(...) \ 23 | prm_warn(&iiod_params, __VA_ARGS__) 24 | 25 | #define IIO_ERROR(...) \ 26 | prm_err(&iiod_params, __VA_ARGS__) 27 | 28 | #define IIO_PERROR(err, ...) \ 29 | prm_perror(&iiod_params, err, __VA_ARGS__) 30 | 31 | #endif /* __IIOD_DEBUG_H__ */ 32 | -------------------------------------------------------------------------------- /iiod/dns-sd.h: -------------------------------------------------------------------------------- 1 | /* SPDX-license-identifier: LGPL-v2-or-later */ 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2021 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | #ifndef __IIOD_DNS_SD_H 10 | #define __IIOD_DNS_SD_H 11 | 12 | #include 13 | 14 | struct thread_pool; 15 | 16 | void start_avahi(struct thread_pool *pool, uint16_t port); 17 | void stop_avahi(void); 18 | 19 | #endif /* __IIOD_DNS_SD_H */ 20 | -------------------------------------------------------------------------------- /iiod/init/iiod.conf.cmakein: -------------------------------------------------------------------------------- 1 | # iiod - Upstart script 2 | # 3 | # Copyright (C) 2016 Analog Devices Inc. 4 | 5 | description "IIO Daemon" 6 | author "Paul Cercueil " 7 | 8 | start on (local-filesystems) 9 | stop on runlevel [!2345] 10 | 11 | respawn 12 | 13 | exec @CMAKE_INSTALL_FULL_SBINDIR@/iiod -D 14 | -------------------------------------------------------------------------------- /iiod/init/iiod.init.cmakein: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | ### BEGIN INIT INFO 4 | # Provides: iiod 5 | # Required-Start: $local_fs $remote_fs 6 | # Required-Stop: $local_fs $remote_fs 7 | # Default-Start: 2 3 4 5 8 | # Default-Stop: 0 1 6 9 | # Short-Description: IIO Daemon 10 | ### END INIT INFO 11 | # Debian init.d script for the IIO Daemon 12 | # Copyright (C) 2016 Analog Devices Inc. 13 | 14 | . /lib/lsb/init-functions 15 | 16 | # Server-side demuxing by default 17 | IIOD_OPTS=-D 18 | 19 | if test -f /etc/default/iiod; then 20 | . /etc/default/iiod 21 | fi 22 | 23 | case "$1" in 24 | start) 25 | log_daemon_msg "Starting IIO Daemon" "iiod" || true 26 | if start-stop-daemon -S -b -q -m -p /var/run/iiod.pid -x @CMAKE_INSTALL_FULL_SBINDIR@/iiod -- $IIOD_OPTS; then 27 | log_end_msg 0 || true 28 | else 29 | log_end_msg 1 || true 30 | fi 31 | ;; 32 | 33 | stop) 34 | log_daemon_msg "Stopping IIO Daemon" "iiod" || true 35 | if start-stop-daemon -K -q -p /var/run/iiod.pid; then 36 | log_end_msg 0 || true 37 | else 38 | log_end_msg 1 || true 39 | fi 40 | ;; 41 | 42 | restart|force-reload) 43 | $0 stop 44 | $0 start 45 | ;; 46 | 47 | status) 48 | if [ -f /var/run/iiod.pid ] ; then 49 | status_of_proc -p /var/run/iiod.pid @CMAKE_INSTALL_FULL_SBINDIR@/iiod iiod && exit 0 || exit $? 50 | else 51 | status_of_proc @CMAKE_INSTALL_FULL_SBINDIR@/iiod iiod && exit 0 || exit $? 52 | fi 53 | ;; 54 | 55 | *) 56 | log_action_msg "Usage: /etc/init.d/iiod.sh {start|stop|restart|status}" || true 57 | exit 1 58 | esac 59 | 60 | exit 0 61 | -------------------------------------------------------------------------------- /iiod/init/iiod.service.cmakein: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: LGPL-2.1-or-later 2 | # 3 | # iiod - Systemd init script 4 | # 5 | # Copyright (C) 2016-2024 Analog Devices Inc. 6 | 7 | [Unit] 8 | Description=IIO Daemon 9 | Requires=systemd-udev-settle.service 10 | After=network.target systemd-udev-settle.service 11 | @CMAKE_SERVICE_PATH@ 12 | Documentation=man:iiod(8) 13 | 14 | [Service] 15 | Environment=IIOD_EXTRA_OPTS='' 16 | EnvironmentFile=-/etc/default/iiod 17 | ExecStart=@CMAKE_INSTALL_FULL_SBINDIR@/iiod $IIOD_EXTRA_OPTS 18 | KillMode=process 19 | Restart=on-failure 20 | 21 | [Install] 22 | WantedBy=multi-user.target 23 | Alias=iiod.service 24 | -------------------------------------------------------------------------------- /iiod/lexer.l: -------------------------------------------------------------------------------- 1 | %{ 2 | // SPDX-License-Identifier: LGPL-2.1-or-later 3 | /* 4 | * libiio - Library for interfacing industrial I/O (IIO) devices 5 | * 6 | * Copyright (C) 2014 Analog Devices, Inc. 7 | * Author: Paul Cercueil 8 | */ 9 | 10 | #include "parser.h" 11 | #include "ops.h" 12 | 13 | #include 14 | %} 15 | 16 | %option noyywrap reentrant bison-bridge nounistd nounput noinput 17 | 18 | WORD (([[:alpha:]]+,)|(iio:))?(-|_|\.|[[:alnum:]])+ 19 | 20 | %s WANT_DEVICE 21 | %s WANT_CHN_OR_ATTR 22 | %s WANT_CHN 23 | %s WANT_ATTR 24 | %s WANT_VALUE 25 | %% 26 | 27 | VERSION|version { 28 | return VERSION; 29 | } 30 | 31 | PRINT|print { 32 | return PRINT; 33 | } 34 | 35 | ZPRINT|zprint { 36 | return ZPRINT; 37 | } 38 | 39 | EXIT|exit|QUIT|quit { 40 | return EXIT; 41 | } 42 | 43 | HELP|help { 44 | return HELP; 45 | } 46 | 47 | BINARY|binary { 48 | return BINARY; 49 | } 50 | 51 | TIMEOUT|timeout { 52 | return TIMEOUT; 53 | } 54 | 55 | OPEN|open { 56 | BEGIN(WANT_DEVICE); 57 | return OPEN; 58 | } 59 | 60 | CLOSE|close { 61 | BEGIN(WANT_DEVICE); 62 | return CLOSE; 63 | } 64 | 65 | READ|read { 66 | BEGIN(WANT_DEVICE); 67 | return READ; 68 | } 69 | 70 | READBUF|readbuf { 71 | BEGIN(WANT_DEVICE); 72 | return READBUF; 73 | } 74 | 75 | WRITEBUF|writebuf { 76 | BEGIN(WANT_DEVICE); 77 | return WRITEBUF; 78 | } 79 | 80 | WRITE|write { 81 | BEGIN(WANT_DEVICE); 82 | return WRITE; 83 | } 84 | 85 | SETTRIG|settrig { 86 | BEGIN(WANT_DEVICE); 87 | return SETTRIG; 88 | } 89 | 90 | GETTRIG|gettrig { 91 | BEGIN(WANT_DEVICE); 92 | return GETTRIG; 93 | } 94 | 95 | SET|set { 96 | BEGIN(WANT_DEVICE); 97 | return SET; 98 | } 99 | 100 | {WORD} { 101 | struct parser_pdata *pdata = yyget_extra(yyscanner); 102 | struct iio_device *dev = iio_context_find_device(pdata->ctx, yytext); 103 | yylval->dev = dev; 104 | pdata->dev = dev; 105 | BEGIN(WANT_CHN_OR_ATTR); 106 | return DEVICE; 107 | } 108 | 109 | BUFFERS_COUNT|buffers_count { 110 | BEGIN(WANT_VALUE); 111 | return BUFFERS_COUNT; 112 | } 113 | 114 | DEBUG|debug { 115 | BEGIN(WANT_ATTR); 116 | return DEBUG_ATTR; 117 | } 118 | 119 | BUFFER|buffer { 120 | BEGIN(WANT_ATTR); 121 | return BUFFER_ATTR; 122 | } 123 | 124 | INPUT|input|OUTPUT|output { 125 | struct parser_pdata *pdata = yyget_extra(yyscanner); 126 | pdata->channel_is_output = yytext[0] == 'o' || yytext[0] == 'O'; 127 | BEGIN(WANT_CHN); 128 | return IN_OUT; 129 | } 130 | 131 | {WORD} { 132 | struct parser_pdata *pdata = yyget_extra(yyscanner); 133 | struct iio_channel *chn = NULL; 134 | if (pdata->dev) 135 | chn = iio_device_find_channel(pdata->dev, 136 | yytext, pdata->channel_is_output); 137 | yylval->chn = chn; 138 | pdata->chn = chn; 139 | BEGIN(WANT_ATTR); 140 | return CHANNEL; 141 | } 142 | 143 | {WORD} { 144 | char *end; 145 | char errstr[100]; 146 | 147 | errno = 0; 148 | yylval->value = strtol(yytext, &end, 10); 149 | if (yytext == end || errno == ERANGE) { 150 | snprintf(errstr, sizeof(errstr), "lex : bad long constant: %s",(char*)yytext); 151 | perror(errstr); 152 | } 153 | return VALUE; 154 | } 155 | 156 | CYCLIC|cyclic { 157 | return CYCLIC; 158 | } 159 | 160 | {WORD} { 161 | yylval->word = strdup(yytext); 162 | return WORD; 163 | } 164 | 165 | [ \t]+ { 166 | return SPACE; 167 | } 168 | 169 | [ \t]*\r?\n { 170 | BEGIN(INITIAL); 171 | return END; 172 | } 173 | 174 | . { 175 | BEGIN(INITIAL); 176 | } 177 | -------------------------------------------------------------------------------- /iiod/rw.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: LGPL-2.1-or-later 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2024 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | #include "ops.h" 10 | 11 | ssize_t write_all(struct parser_pdata *pdata, const void *src, size_t len) 12 | { 13 | uintptr_t ptr = (uintptr_t) src; 14 | 15 | while (len) { 16 | ssize_t ret = pdata->writefd(pdata, (void *) ptr, len); 17 | if (ret < 0) 18 | return ret; 19 | if (!ret) 20 | return -EPIPE; 21 | ptr += ret; 22 | len -= ret; 23 | } 24 | 25 | return ptr - (uintptr_t) src; 26 | } 27 | 28 | ssize_t read_all(struct parser_pdata *pdata, void *dst, size_t len) 29 | { 30 | uintptr_t ptr = (uintptr_t) dst; 31 | 32 | while (len) { 33 | ssize_t ret = pdata->readfd(pdata, (void *) ptr, len); 34 | if (ret < 0) 35 | return ret; 36 | if (!ret) 37 | return -EPIPE; 38 | ptr += ret; 39 | len -= ret; 40 | } 41 | 42 | return ptr - (uintptr_t) dst; 43 | } 44 | -------------------------------------------------------------------------------- /iiod/thread-pool.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2016 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | #ifndef __THREAD_POOL_H__ 10 | #define __THREAD_POOL_H__ 11 | 12 | #include 13 | 14 | struct thread_pool; 15 | 16 | struct thread_pool * thread_pool_new(void); 17 | 18 | int thread_pool_get_poll_fd(const struct thread_pool *pool); 19 | void thread_pool_stop(struct thread_pool *pool); 20 | void thread_pool_wait(struct thread_pool *pool); 21 | void thread_pool_stop_and_wait(struct thread_pool *pool); 22 | bool thread_pool_is_stopped(const struct thread_pool *pool); 23 | void thread_pool_restart(struct thread_pool *pool); 24 | 25 | void thread_pool_destroy(struct thread_pool *pool); 26 | 27 | int thread_pool_add_thread(struct thread_pool *pool, 28 | void (*func)(struct thread_pool *, void *), 29 | void *data, const char *name); 30 | 31 | #endif /* __THREAD_POOL_H__ */ 32 | -------------------------------------------------------------------------------- /iiod/usb-dmabuf.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: LGPL-2.1-or-later 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2023 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define IIO_FFS_DMABUF_ATTACH _IOW('g', 131, int) 15 | #define IIO_FFS_DMABUF_DETACH _IOW('g', 132, int) 16 | #define IIO_FFS_DMABUF_TRANSFER _IOW('g', 133, struct iio_ffs_dmabuf_transfer) 17 | 18 | struct iio_ffs_dmabuf_transfer { 19 | int fd; 20 | uint32_t flags; 21 | uint64_t length; 22 | }; 23 | 24 | int usb_attach_dmabuf(int ep_fd, int fd) 25 | { 26 | int ret; 27 | 28 | ret = ioctl(ep_fd, IIO_FFS_DMABUF_ATTACH, &fd); 29 | if (ret == -1) 30 | return -errno; 31 | 32 | return 0; 33 | } 34 | 35 | int usb_detach_dmabuf(int ep_fd, int fd) 36 | { 37 | int ret; 38 | 39 | ret = ioctl(ep_fd, IIO_FFS_DMABUF_DETACH, &fd); 40 | if (ret == -1) 41 | return -errno; 42 | 43 | return 0; 44 | } 45 | 46 | int usb_transfer_dmabuf(int ep_fd, int fd, uint64_t size) 47 | { 48 | struct iio_ffs_dmabuf_transfer req; 49 | int ret; 50 | 51 | req.fd = fd; 52 | req.length = size; 53 | req.flags = 0; 54 | 55 | ret = ioctl(ep_fd, IIO_FFS_DMABUF_TRANSFER, &req); 56 | if (ret == -1) 57 | return -errno; 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /include/iio/iio-lock.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2015 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | #ifndef _IIO_LOCK_H 10 | #define _IIO_LOCK_H 11 | 12 | #include 13 | 14 | #define __api __iio_api 15 | 16 | struct iio_mutex; 17 | struct iio_cond; 18 | struct iio_task; 19 | struct iio_task_token; 20 | struct iio_thrd; 21 | 22 | __api struct iio_mutex *iio_mutex_create(void); 23 | __api void iio_mutex_destroy(struct iio_mutex *lock); 24 | 25 | __api void iio_mutex_lock(struct iio_mutex *lock); 26 | __api void iio_mutex_unlock(struct iio_mutex *lock); 27 | 28 | __api struct iio_cond * iio_cond_create(void); 29 | __api void iio_cond_destroy(struct iio_cond *cond); 30 | 31 | __api int iio_cond_wait(struct iio_cond *cond, struct iio_mutex *lock, 32 | unsigned int timeout_ms); 33 | __api void iio_cond_signal(struct iio_cond *cond); 34 | 35 | __api struct iio_thrd * iio_thrd_create(int (*thrd)(void *), 36 | void *d, const char *name); 37 | __api int iio_thrd_join_and_destroy(struct iio_thrd *thrd); 38 | 39 | __api struct iio_task * iio_task_create(int (*task)(void *firstarg, void *d), 40 | void *firstarg, const char *name); 41 | __api void iio_task_flush(struct iio_task *task); 42 | __api int iio_task_destroy(struct iio_task *task); 43 | 44 | __api void iio_task_start(struct iio_task *task); 45 | __api void iio_task_stop(struct iio_task *task); 46 | 47 | __api void iio_task_token_destroy(struct iio_task_token *token); 48 | __api struct iio_task_token * iio_task_token_create(struct iio_task *task, void *elm); 49 | __api struct iio_task_token * iio_task_enqueue(struct iio_task *task, void *elm); 50 | __api int iio_task_enqueue_autoclear(struct iio_task *task, void *elm); 51 | __api int iio_task_token_enqueue(struct iio_task_token *token); 52 | 53 | __api _Bool iio_task_is_done(struct iio_task_token *token); 54 | __api int iio_task_sync(struct iio_task_token *token, unsigned int timeout_ms); 55 | __api int iio_task_cancel_sync(struct iio_task_token *token, unsigned int timeout_ms); 56 | __api void iio_task_cancel(struct iio_task_token *token); 57 | 58 | #undef __api 59 | 60 | #endif /* _IIO_LOCK_H */ 61 | -------------------------------------------------------------------------------- /libiio.iss.cmakein: -------------------------------------------------------------------------------- 1 | [Setup] 2 | AppId={{D386A5F6-D38D-4738-94A2-E163DC1896F1} 3 | AppName="Libiio" 4 | AppVersion="@VERSION@" 5 | AppPublisher="Analog Devices, Inc." 6 | AppPublisherURL="http://www.analog.com" 7 | AppSupportURL="http://www.analog.com" 8 | AppUpdatesURL="http://www.analog.com" 9 | AppCopyright="Copyright 2015-@BUILD_YEAR@ ADI and other contributors" 10 | CreateAppDir=no 11 | LicenseFile="D:\a\1\s\COPYING.txt" 12 | OutputBaseFilename=libiio-setup 13 | OutputDir="C:\" 14 | Compression=lzma 15 | SolidCompression=yes 16 | ArchitecturesInstallIn64BitMode=x64 17 | 18 | [Languages] 19 | Name: "english"; MessagesFile: "compiler:Default.isl" 20 | Name: "brazilianportuguese"; MessagesFile: "compiler:Languages\BrazilianPortuguese.isl" 21 | Name: "catalan"; MessagesFile: "compiler:Languages\Catalan.isl" 22 | Name: "corsican"; MessagesFile: "compiler:Languages\Corsican.isl" 23 | Name: "czech"; MessagesFile: "compiler:Languages\Czech.isl" 24 | Name: "danish"; MessagesFile: "compiler:Languages\Danish.isl" 25 | Name: "dutch"; MessagesFile: "compiler:Languages\Dutch.isl" 26 | Name: "finnish"; MessagesFile: "compiler:Languages\Finnish.isl" 27 | Name: "french"; MessagesFile: "compiler:Languages\French.isl" 28 | Name: "german"; MessagesFile: "compiler:Languages\German.isl" 29 | Name: "hebrew"; MessagesFile: "compiler:Languages\Hebrew.isl" 30 | Name: "italian"; MessagesFile: "compiler:Languages\Italian.isl" 31 | Name: "japanese"; MessagesFile: "compiler:Languages\Japanese.isl" 32 | Name: "norwegian"; MessagesFile: "compiler:Languages\Norwegian.isl" 33 | Name: "polish"; MessagesFile: "compiler:Languages\Polish.isl" 34 | Name: "portuguese"; MessagesFile: "compiler:Languages\Portuguese.isl" 35 | Name: "russian"; MessagesFile: "compiler:Languages\Russian.isl" 36 | Name: "slovenian"; MessagesFile: "compiler:Languages\Slovenian.isl" 37 | Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl" 38 | Name: "turkish"; MessagesFile: "compiler:Languages\Turkish.isl" 39 | Name: "ukrainian"; MessagesFile: "compiler:Languages\Ukrainian.isl" 40 | 41 | [Files] 42 | Source: "D:\a\1\a\Windows-VS-2019-x64\libiio1.dll"; DestDir: "{sys}"; Check: Is64BitInstallMode; Flags: replacesameversion 43 | Source: "D:\a\1\a\Windows-VS-2019-x64\*.exe"; DestDir: "{sys}"; Check: Is64BitInstallMode; Flags: replacesameversion 44 | Source: "D:\a\1\a\Windows-VS-2019-x64\libiio1.lib"; DestDir: "{commonpf32}\Microsoft Visual Studio 12.0\VC\lib\amd64"; Check: Is64BitInstallMode 45 | Source: "D:\a\1\a\Windows-VS-2019-x64\iio\*.h"; DestDir: "{commonpf32}\Microsoft Visual Studio 12.0\VC\include\iio" 46 | Source: "D:\a\1\a\Windows-VS-2019-x64\libxml2.dll"; DestDir: "{sys}"; Check: Is64BitInstallMode; Flags: onlyifdoesntexist 47 | Source: "D:\a\1\a\Windows-VS-2019-x64\libusb-1.0.dll"; DestDir: "{sys}"; Check: Is64BitInstallMode; Flags: onlyifdoesntexist 48 | Source: "D:\a\1\a\Windows-VS-2019-x64\libserialport.dll"; DestDir: "{sys}"; Check: Is64BitInstallMode; Flags: onlyifdoesntexist 49 | Source: "D:\a\1\a\Windows-VS-2019-x64\libzstd.dll"; DestDir: "{sys}"; Check: Is64BitInstallMode; Flags: onlyifdoesntexist 50 | Source: "D:\a\1\a\Windows-VS-2019-x64\libiio-sharp.dll"; DestDir: "{commoncf}\libiio"; Flags: replacesameversion 51 | Source: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Redist\MSVC\14.29.30133\x64\Microsoft.VC142.CRT\msvcp140.dll"; DestDir: "{sys}"; Check: Is64BitInstallMode; Flags: onlyifdoesntexist 52 | Source: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Redist\MSVC\14.29.30133\x64\Microsoft.VC142.CRT\vcruntime140.dll"; DestDir: "{sys}"; Check: Is64BitInstallMode; Flags: onlyifdoesntexist 53 | -------------------------------------------------------------------------------- /libiio.pc.cmakein: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 4 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 5 | 6 | Name: libiio 7 | Description: Library for interfacing IIO devices 8 | Version: @VERSION@ 9 | 10 | Requires: 11 | Libs: -L${libdir} -liio 12 | Cflags: -I${includedir} 13 | -------------------------------------------------------------------------------- /libiio.rules.cmakein: -------------------------------------------------------------------------------- 1 | SUBSYSTEM=="usb", PROGRAM=="/bin/sh -c '@CMAKE_INSTALL_FULL_BINDIR@/iio_info -S usb=%s{idVendor}:%s{idProduct} | grep %s{idVendor}:%s{idProduct}'", RESULT!="", MODE="666" 2 | -------------------------------------------------------------------------------- /library.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2023 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | #include "iio-private.h" 10 | #include 11 | 12 | uint64_t library_startup_time_us; 13 | 14 | static void libiio_init(void) 15 | { 16 | library_startup_time_us = iio_read_counter_us(); 17 | } 18 | 19 | static void libiio_exit(void) 20 | { 21 | if (WITH_XML_BACKEND) 22 | libiio_cleanup_xml_backend(); 23 | } 24 | 25 | #if defined(_MSC_BUILD) 26 | #pragma section(".CRT$XCU", read) 27 | #define __CONSTRUCTOR(f, p) \ 28 | static void f(void); \ 29 | __declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \ 30 | __pragma(comment(linker,"/include:" p #f "_")) \ 31 | static void f(void) 32 | #ifdef _WIN64 33 | #define _CONSTRUCTOR(f) __CONSTRUCTOR(f, "") 34 | #else 35 | #define _CONSTRUCTOR(f) __CONSTRUCTOR(f, "_") 36 | #endif 37 | #elif defined(__GNUC__) 38 | #define _CONSTRUCTOR(f) static void __attribute__((constructor)) f(void) 39 | #else 40 | #define _CONSTRUCTOR(f) static void f(void) 41 | #endif 42 | 43 | _CONSTRUCTOR(initialize) 44 | { 45 | libiio_init(); 46 | 47 | /* 48 | * When the library loads, register our destructor. 49 | * Do it here and not in the context creation function, 50 | * as it could otherwise end up registering the destructor 51 | * many times. 52 | */ 53 | atexit(libiio_exit); 54 | } 55 | #undef _CONSTRUCTOR 56 | -------------------------------------------------------------------------------- /local.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2022 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | #ifndef __IIO_LOCAL_H 9 | #define __IIO_LOCAL_H 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | struct iio_buffer_impl_pdata; 16 | struct iio_block_impl_pdata; 17 | struct iio_device; 18 | struct iio_buffer_params; 19 | struct timespec; 20 | 21 | struct iio_buffer_pdata { 22 | const struct iio_device *dev; 23 | struct iio_buffer_impl_pdata *pdata; 24 | int fd, cancel_fd; 25 | struct iio_buffer_params *params; 26 | bool dmabuf_supported; 27 | bool mmap_supported; 28 | size_t size; 29 | }; 30 | 31 | struct iio_block_pdata { 32 | struct iio_buffer_pdata *buf; 33 | struct iio_block_impl_pdata *pdata; 34 | size_t size; 35 | void *data; 36 | bool dequeued; 37 | bool cpu_access_disabled; 38 | }; 39 | 40 | int ioctl_nointr(int fd, unsigned long request, void *data); 41 | 42 | int buffer_check_ready(struct iio_buffer_pdata *pdata, int fd, 43 | short events, struct timespec *start); 44 | 45 | struct iio_block_pdata * 46 | local_create_dmabuf(struct iio_buffer_pdata *pdata, size_t size, void **data); 47 | void local_free_dmabuf(struct iio_block_pdata *pdata); 48 | 49 | int local_enqueue_dmabuf(struct iio_block_pdata *pdata, 50 | size_t bytes_used, bool cyclic); 51 | int local_dequeue_dmabuf(struct iio_block_pdata *pdata, bool nonblock); 52 | 53 | int local_dmabuf_get_fd(struct iio_block_pdata *pdata); 54 | int local_dmabuf_disable_cpu_access(struct iio_block_pdata *pdata, bool disable); 55 | 56 | struct iio_block_pdata * 57 | local_create_mmap_block(struct iio_buffer_pdata *pdata, 58 | size_t size, void **data); 59 | void local_free_mmap_block(struct iio_block_pdata *pdata); 60 | 61 | int local_enqueue_mmap_block(struct iio_block_pdata *pdata, 62 | size_t bytes_used, bool cyclic); 63 | int local_dequeue_mmap_block(struct iio_block_pdata *pdata, bool nonblock); 64 | 65 | struct iio_buffer_impl_pdata * local_alloc_mmap_buffer_impl(void); 66 | 67 | #endif /* __IIO_LOCAL_H */ 68 | -------------------------------------------------------------------------------- /lock-dummy.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2024 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | struct iio_mutex { 16 | int dummy; /* Flawfinder: ignore */ 17 | }; 18 | 19 | struct iio_cond { 20 | int dummy; /* Flawfinder: ignore */ 21 | }; 22 | 23 | struct iio_mutex * iio_mutex_create(void) 24 | { 25 | struct iio_mutex *lock = malloc(sizeof(*lock)); 26 | 27 | if (!lock) 28 | return iio_ptr(-ENOMEM); 29 | 30 | return lock; 31 | } 32 | 33 | void iio_mutex_destroy(struct iio_mutex *lock) 34 | { 35 | free(lock); 36 | } 37 | 38 | void iio_mutex_lock(struct iio_mutex *lock) 39 | { 40 | } 41 | 42 | void iio_mutex_unlock(struct iio_mutex *lock) 43 | { 44 | } 45 | 46 | struct iio_cond * iio_cond_create(void) 47 | { 48 | struct iio_cond *cond = malloc(sizeof(*cond)); 49 | 50 | if (!cond) 51 | return iio_ptr(-ENOMEM); 52 | 53 | return cond; 54 | } 55 | 56 | void iio_cond_destroy(struct iio_cond *cond) 57 | { 58 | free(cond); 59 | } 60 | 61 | int iio_cond_wait(struct iio_cond *cond, struct iio_mutex *lock, 62 | unsigned int timeout_ms) 63 | { 64 | return -ETIMEDOUT; 65 | } 66 | 67 | void iio_cond_signal(struct iio_cond *cond) 68 | { 69 | } 70 | 71 | struct iio_thrd * iio_thrd_create(int (*thrd)(void *), 72 | void *d, const char *name) 73 | { 74 | return iio_ptr(-ENOSYS); 75 | } 76 | 77 | int iio_thrd_join_and_destroy(struct iio_thrd *thrd) 78 | { 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /lock-windows.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: LGPL-2.1-or-later 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2015-2021 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | #include "iio-config.h" 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | struct iio_mutex { 19 | CRITICAL_SECTION lock; 20 | }; 21 | 22 | struct iio_cond { 23 | CONDITION_VARIABLE cond; 24 | }; 25 | 26 | struct iio_thrd { 27 | HANDLE thid; 28 | 29 | void *d; 30 | int (*func)(void *d); 31 | }; 32 | 33 | struct iio_mutex * iio_mutex_create(void) 34 | { 35 | struct iio_mutex *lock = malloc(sizeof(*lock)); 36 | 37 | if (!lock) 38 | return iio_ptr(-ENOMEM); 39 | 40 | InitializeCriticalSection(&lock->lock); 41 | 42 | return lock; 43 | } 44 | 45 | void iio_mutex_destroy(struct iio_mutex *lock) 46 | { 47 | DeleteCriticalSection(&lock->lock); 48 | free(lock); 49 | } 50 | 51 | void iio_mutex_lock(struct iio_mutex *lock) 52 | { 53 | EnterCriticalSection(&lock->lock); 54 | } 55 | 56 | void iio_mutex_unlock(struct iio_mutex *lock) 57 | { 58 | LeaveCriticalSection(&lock->lock); 59 | } 60 | 61 | struct iio_cond * iio_cond_create(void) 62 | { 63 | struct iio_cond *cond = malloc(sizeof(*cond)); 64 | 65 | if (!cond) 66 | return iio_ptr(-ENOMEM); 67 | 68 | InitializeConditionVariable(&cond->cond); 69 | 70 | return cond; 71 | } 72 | 73 | void iio_cond_destroy(struct iio_cond *cond) 74 | { 75 | free(cond); 76 | } 77 | 78 | int iio_cond_wait(struct iio_cond *cond, struct iio_mutex *lock, 79 | unsigned int timeout_ms) 80 | { 81 | BOOL ret; 82 | 83 | if (timeout_ms == 0) 84 | timeout_ms = INFINITE; 85 | 86 | ret = SleepConditionVariableCS(&cond->cond, &lock->lock, timeout_ms); 87 | 88 | return ret ? 0 : -ETIMEDOUT; 89 | } 90 | 91 | void iio_cond_signal(struct iio_cond *cond) 92 | { 93 | WakeConditionVariable(&cond->cond); 94 | } 95 | 96 | static DWORD iio_thrd_wrapper(void *d) 97 | { 98 | struct iio_thrd *thrd = d; 99 | 100 | return (DWORD) thrd->func(thrd->d); 101 | } 102 | 103 | struct iio_thrd * iio_thrd_create(int (*thrd)(void *), 104 | void *d, const char *name) 105 | { 106 | struct iio_thrd *iio_thrd; 107 | 108 | if (!thrd) 109 | return iio_ptr(-EINVAL); 110 | 111 | iio_thrd = malloc(sizeof(*iio_thrd)); 112 | if (!iio_thrd) 113 | return iio_ptr(-ENOMEM); 114 | 115 | iio_thrd->func = thrd; 116 | iio_thrd->d = d; 117 | 118 | iio_thrd->thid = CreateThread(NULL, 0, 119 | (LPTHREAD_START_ROUTINE) iio_thrd_wrapper, 120 | iio_thrd, 0, NULL); 121 | if (!iio_thrd->thid) { 122 | free(iio_thrd); 123 | return iio_ptr(-(int) GetLastError()); 124 | } 125 | 126 | /* TODO: set name */ 127 | //SetThreadDescription(thrd->thid, name); 128 | 129 | return iio_thrd; 130 | } 131 | 132 | int iio_thrd_join_and_destroy(struct iio_thrd *thrd) 133 | { 134 | DWORD ret = 0; 135 | 136 | WaitForSingleObject(thrd->thid, INFINITE); 137 | GetExitCodeThread(thrd->thid, &ret); 138 | free(thrd); 139 | 140 | return (int) ret; 141 | } 142 | -------------------------------------------------------------------------------- /man/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # it doesn't make sense to create man pages on windows, so we don't really 2 | # worry about that. 3 | 4 | if (WITH_MAN) 5 | find_program(DATE_EXECUTABLE date) 6 | if (DEFINED ENV{SOURCE_DATE_EPOCH}) 7 | execute_process( 8 | COMMAND ${DATE_EXECUTABLE} "-u" "-d" "@$ENV{SOURCE_DATE_EPOCH}" "+%d %B %Y" 9 | OUTPUT_VARIABLE CMAKE_DATE OUTPUT_STRIP_TRAILING_WHITESPACE) 10 | else () 11 | execute_process( 12 | COMMAND ${DATE_EXECUTABLE} "+%d %B %Y" 13 | OUTPUT_VARIABLE CMAKE_DATE OUTPUT_STRIP_TRAILING_WHITESPACE) 14 | endif () 15 | configure_file( 16 | ${CMAKE_CURRENT_SOURCE_DIR}/make_man.sh.in 17 | ${CMAKE_CURRENT_BINARY_DIR}/make_man.sh @ONLY) 18 | execute_process( 19 | COMMAND ${CMAKE_CURRENT_BINARY_DIR}/make_man.sh 20 | OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/libiio.3.in 21 | ) 22 | 23 | configure_file( 24 | ${CMAKE_CURRENT_BINARY_DIR}/libiio.3.in 25 | ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_MANDIR}/libiio.3 @ONLY) 26 | 27 | if (WITH_DOC) 28 | find_program(MAN2HTML man2html) 29 | if (NOT MAN2HTML) 30 | message(FATAL_ERROR "Can not build html DOC from man without man2html") 31 | endif() 32 | message(STATUS "Building html doc pages with man2html") 33 | file(MAKE_DIRECTORY ${CMAKE_HTML_DEST_DIR}/man1 ${CMAKE_HTML_DEST_DIR}/man3) 34 | execute_process( 35 | COMMAND ${MAN2HTML} -r 36 | INPUT_FILE ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_MANDIR}/libiio.3 37 | OUTPUT_FILE ${CMAKE_HTML_DEST_DIR}/man3/libiio.3.html 38 | ) 39 | endif() 40 | if (WITH_UTILS) 41 | foreach(_page ${IIO_TESTS_TARGETS}) 42 | execute_process( 43 | COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/make_util_pages.sh 44 | ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${_page}.1.in 45 | OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_page}.1.in 46 | ) 47 | configure_file( 48 | ${CMAKE_CURRENT_BINARY_DIR}/${_page}.1.in 49 | ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_MANDIR}/${_page}.1 @ONLY 50 | ) 51 | 52 | if (WITH_DOC) 53 | execute_process( 54 | COMMAND ${MAN2HTML} -r 55 | INPUT_FILE ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_MANDIR}/${_page} 56 | OUTPUT_FILE ${CMAKE_HTML_DEST_DIR}/man1/${_page}.html 57 | ) 58 | endif() 59 | endforeach() 60 | endif() 61 | 62 | if (WITH_IIOD) 63 | configure_file(iiod.1.in 64 | ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_MANDIR}/iiod.1 @ONLY 65 | ) 66 | endif() 67 | 68 | # install man files into the BINARY directories, 69 | # section 3 = library functions 70 | install(DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_MANDIR}/ 71 | DESTINATION ${CMAKE_INSTALL_MANDIR}/man3 72 | COMPONENT doc FILES_MATCHING PATTERN "*.3*") 73 | # section 1 = user commands 74 | install(DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_MANDIR}/ 75 | DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 76 | COMPONENT doc FILES_MATCHING PATTERN "*.1*") 77 | endif() 78 | 79 | toggle_iio_feature("${WITH_MAN}" man) 80 | toggle_iio_feature("${WITH_UTILS}" man-utils) 81 | 82 | set(IIOM_FEATURES_ON "${IIO_FEATURES_ON}" PARENT_SCOPE) 83 | set(IIOM_FEATURES_OFF "${IIO_FEATURES_OFF}" PARENT_SCOPE) 84 | -------------------------------------------------------------------------------- /man/README.md: -------------------------------------------------------------------------------- 1 | # README for the man pages for libiio 2 | 3 | The man pages are all manually maintained, except for the libiio.3 man page, which is autogenerated from the header file. 4 | 5 | If you have questions, please ask on the github issue tracker 6 | https://github.com/analogdevicesinc/libiio/issues 7 | 8 | 9 | -------------------------------------------------------------------------------- /man/iio_attr.1.in: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2018-2020 Robin Getz 2 | .\" Copyright (c) 2018-2020 Analog Devices Inc. 3 | .\" 4 | .\" %%%LICENSE_START(GPLv2+_DOC_FULL) 5 | .\" This is free documentation; you can redistribute it and/or 6 | .\" modify it under the terms of the GNU General Public License as 7 | .\" published by the Free Software Foundation; either version 2 of 8 | .\" the License, or (at your option) any later version. 9 | .\" 10 | .\" The GNU General Public License's references to "object code" 11 | .\" and "executables" are to be interpreted as the output of any 12 | .\" document formatting or typesetting system, including 13 | .\" intermediate and printed output. 14 | .\" 15 | .\" This manual is distributed in the hope that it will be useful, 16 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | .\" GNU General Public License for more details. 19 | .\" 20 | .\" You should have received a copy of the GNU General Public 21 | .\" License along with this manual; if not, see 22 | .\" . 23 | .\" %%%LICENSE_END 24 | .\" 25 | .TH iio_attr 1 "@CMAKE_DATE@" "libiio-@LIBIIO_VERSION_MAJOR@.@LIBIIO_VERSION_MINOR@" "LibIIO Utilities" 26 | .IX iio_attr 27 | .SH NAME 28 | iio_attr \- list IIO devices, and read/write device attributes 29 | .SH SYNOPSIS 30 | .B iio_attr 31 | [ 32 | .I options 33 | ] 34 | -d [device] [attr] [value] 35 | .br 36 | .B iio_attr 37 | [ 38 | .I options 39 | ] 40 | -c [device] [channel] [attr] [value] 41 | .br 42 | .B iio_attr 43 | [ 44 | .I options 45 | ] 46 | -D [device] [attr] [value] 47 | .br 48 | .B iio_attr 49 | [ 50 | .I options 51 | ] 52 | -C [attr] 53 | .br 54 | .B iio_attr 55 | -S 56 | .br 57 | .B iio_attr 58 | -h 59 | 60 | .SH DESCRIPTION 61 | .B iio_attr 62 | is a utility for displaying information about local or remote IIO devices. 63 | By providing an optional value, 64 | .B iio_attr 65 | will attempt to write the new value to the attribute. 66 | 67 | .SH COMMANDS 68 | .TP 69 | The iio_attr utility has a few main options, which control what the main utility of the application is. 70 | .TP 71 | .B \-d, \-\-device-attr 72 | Read and Write IIO device attributes 73 | .TP 74 | .B \-c \-\-channel-attr 75 | Read and Write IIO channel attributes 76 | .TP 77 | .B \-B \-\-buffer-attr 78 | Read and Write IIO Buffer attributes 79 | .TP 80 | .B \-C \-\-context-attr 81 | Read and Write IIO Context attributes 82 | .TP 83 | .B \-D \-\-debug-attr 84 | Read and Write IIO Debug attributes 85 | ##COMMON_COMMANDS_START## 86 | ##COMMON_COMMANDS_STOP## 87 | .SH OPTIONS 88 | ##COMMON_OPTION_START## 89 | ##COMMON_OPTION_STOP## 90 | .TP 91 | .B \-i, \-\-input-channel 92 | Filters channels by input channels only 93 | .TP 94 | .B \-o, \-\-output-channel 95 | Filters channels by output channels only 96 | .TP 97 | .B \-s, \-\-scan-channel 98 | Filters channels by scan channels only 99 | .TP 100 | .B \-I, \-\-ignore-case 101 | When pattern matching devices, channels or attributes, ignore case 102 | .TP 103 | .B \-g, \-\-generate-code 104 | Generate small C or python snippets that emulate what you are doing on the command line. Argument is a file name 'foo.c' or 'foo.py' 105 | .TP 106 | .SH RETURN VALUE 107 | If the specified device is not found, a non-zero exit code is returned. 108 | 109 | -------------------------------------------------------------------------------- /man/iio_common_cmds.1: -------------------------------------------------------------------------------- 1 | .TP 2 | .B \-h, \-\-help 3 | Tells 4 | .I ##APP_NAME## 5 | to display some help, and then quit. 6 | .TP 7 | .B \-V, \-\-version 8 | Prints the version information for this particular copy of 9 | .I ##APP_NAME## 10 | and the version of the libiio library it is using. This is useful for knowing if the version of the library and 11 | .I ##APP_NAME## 12 | on your system are up to date. This is also useful when reporting bugs. 13 | .TP 14 | .B \-S, \-\-scan [backends] 15 | Scan for available IIO contexts, optional arg of specific backend(s) 'ip', 'usb' or 'ip,usb'. 16 | Specific options for USB include Vendor ID, Product ID to limit scanning to specific devices 'usb=0456:b673'. 17 | vid,pid are hexadecimal numbers (no prefix needed), "*" (match any for pid only) 18 | If no argument is given, it checks all that are available. 19 | -------------------------------------------------------------------------------- /man/iio_common_footer.1: -------------------------------------------------------------------------------- 1 | .SH "SEE ALSO" 2 | .ad l 3 | .BR iio_attr (1), 4 | .BR iio_info (1), 5 | .BR iio_rwdev (1), 6 | .BR iio_reg (1), 7 | .BR libiio (3) 8 | .PP 9 | libiio home page: 10 | .BR \%https://wiki.analog.com/resources/tools-software/linux-software/libiio 11 | .PP 12 | libiio code: 13 | .BR \%https://github.com/analogdevicesinc/libiio 14 | .PP 15 | Doxygen for libiio 16 | .BR \%https://analogdevicesinc.github.io/libiio/ 17 | .SH BUGS 18 | All bugs are tracked at: 19 | .BR \%https://github.com/analogdevicesinc/libiio/issues 20 | -------------------------------------------------------------------------------- /man/iio_common_opts.1: -------------------------------------------------------------------------------- 1 | .TP 2 | .B \-u, \-\-uri 3 | The Uniform Resource Identifier 4 | .I (uri) 5 | for connecting to devices, can be one of: 6 | .RS 7 | .IP ip:[address] 8 | network address, either numeric (192.168.0.1) or network hostname 9 | .IP ip: 10 | blank, if compiled with zeroconf support, will find an IIO device on network 11 | .IP usb:[device:port:instance] 12 | normally returned from 13 | .B ##APP_NAME## -S 14 | .IP serial:[port],[baud],[settings] 15 | which are controlled, and need to match the iiod (or tinyiiod) on the other end of the serial port. 16 | .RS 17 | .IP [port] 18 | is something like '/dev/ttyUSB0' on Linux, and 'COM4' on Windows. 19 | .IP [baud] 20 | is is normally one of 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200 [default], 128000 or 256000, but can vary system to system. 21 | .IP [settings] 22 | would normally be configured as '8n1' this is controlled by: 23 | .RS 24 | .IP data_bits: 25 | (5, 6, 7, 8 [default], or 9) 26 | .IP parity_bits: 27 | ('n' none [default], 'o' odd, 'e' even, 'm' mark, or 's' space) 28 | .IP stop_bits: 29 | (1 [default, or 2) 30 | .IP flow_control: 31 | ('0' none [default], 'x' Xon Xoff, 'r' RTSCTS, or 'd' DTRDSR) 32 | .RE 33 | .RE 34 | .IP local: 35 | with no address part. 36 | .RE 37 | -------------------------------------------------------------------------------- /man/iio_genxml.1.in: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2018-2020 Robin Getz 2 | .\" Copyright (c) 2018-2020 Analog Devices Inc. 3 | .\" 4 | .\" %%%LICENSE_START(GPLv2+_DOC_FULL) 5 | .\" This is free documentation; you can redistribute it and/or 6 | .\" modify it under the terms of the GNU General Public License as 7 | .\" published by the Free Software Foundation; either version 2 of 8 | .\" the License, or (at your option) any later version. 9 | .\" 10 | .\" The GNU General Public License's references to "object code" 11 | .\" and "executables" are to be interpreted as the output of any 12 | .\" document formatting or typesetting system, including 13 | .\" intermediate and printed output. 14 | .\" 15 | .\" This manual is distributed in the hope that it will be useful, 16 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | .\" GNU General Public License for more details. 19 | .\" 20 | .\" You should have received a copy of the GNU General Public 21 | .\" License along with this manual; if not, see 22 | .\" . 23 | .\" %%%LICENSE_END 24 | .\" 25 | .TH iio_genxml 1 "@CMAKE_DATE@" "libiio-@LIBIIO_VERSION_MAJOR@.@LIBIIO_VERSION_MINOR@" "LibIIO Utilities" 26 | .IX iio_genxml 27 | .SH NAME 28 | iio_genxml \- Generate XML representation of a Libiio context 29 | .SH SYNOPSIS 30 | .B iio_genxml 31 | [ 32 | .I options 33 | ] 34 | 35 | .SH DESCRIPTION 36 | .B iio_genxml 37 | is a utility for generating a XML representation of a Libiio context. 38 | 39 | .SH OPTIONS 40 | ##COMMON_COMMANDS_START## 41 | ##COMMON_COMMANDS_STOP## 42 | ##COMMON_OPTION_START## 43 | ##COMMON_OPTION_STOP## 44 | 45 | .SH RETURN VALUE 46 | If the specified device is not found, a non-zero exit code is returned. 47 | -------------------------------------------------------------------------------- /man/iio_info.1.in: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2018-2020 Robin Getz 2 | .\" Copyright (c) 2018-2020 Analog Devices Inc. 3 | .\" 4 | .\" %%%LICENSE_START(GPLv2+_DOC_FULL) 5 | .\" This is free documentation; you can redistribute it and/or 6 | .\" modify it under the terms of the GNU General Public License as 7 | .\" published by the Free Software Foundation; either version 2 of 8 | .\" the License, or (at your option) any later version. 9 | .\" 10 | .\" The GNU General Public License's references to "object code" 11 | .\" and "executables" are to be interpreted as the output of any 12 | .\" document formatting or typesetting system, including 13 | .\" intermediate and printed output. 14 | .\" 15 | .\" This manual is distributed in the hope that it will be useful, 16 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | .\" GNU General Public License for more details. 19 | .\" 20 | .\" You should have received a copy of the GNU General Public 21 | .\" License along with this manual; if not, see 22 | .\" . 23 | .\" %%%LICENSE_END 24 | .\" 25 | .TH iio_info 1 "@CMAKE_DATE@" "libiio-@LIBIIO_VERSION_MAJOR@.@LIBIIO_VERSION_MINOR@" "LibIIO Utilities" 26 | .IX iio_info 27 | .SH NAME 28 | iio_info \- list IIO devices and device attributes 29 | .SH SYNOPSIS 30 | .B iio_info 31 | [ 32 | .I options 33 | ] 34 | -u 35 | .SH DESCRIPTION 36 | .B iio_info 37 | is a utility for displaying information about local or remote IIO devices 38 | 39 | .SH OPTIONS 40 | ##COMMON_COMMANDS_START## 41 | ##COMMON_COMMANDS_STOP## 42 | ##COMMON_OPTION_START## 43 | ##COMMON_OPTION_STOP## 44 | .TP 45 | .B \-a, \-\-auto 46 | Scan for available contexts and if only one is available use it. 47 | 48 | .SH RETURN VALUE 49 | If the specified device is not found, a non-zero exit code is returned. 50 | 51 | -------------------------------------------------------------------------------- /man/iio_reg.1.in: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2018-2020 Robin Getz 2 | .\" Copyright (c) 2018-2020 Analog Devices Inc. 3 | .\" 4 | .\" %%%LICENSE_START(GPLv2+_DOC_FULL) 5 | .\" This is free documentation; you can redistribute it and/or 6 | .\" modify it under the terms of the GNU General Public License as 7 | .\" published by the Free Software Foundation; either version 2 of 8 | .\" the License, or (at your option) any later version. 9 | .\" 10 | .\" The GNU General Public License's references to "object code" 11 | .\" and "executables" are to be interpreted as the output of any 12 | .\" document formatting or typesetting system, including 13 | .\" intermediate and printed output. 14 | .\" 15 | .\" This manual is distributed in the hope that it will be useful, 16 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | .\" GNU General Public License for more details. 19 | .\" 20 | .\" You should have received a copy of the GNU General Public 21 | .\" License along with this manual; if not, see 22 | .\" . 23 | .\" %%%LICENSE_END 24 | .\" 25 | .TH iio_reg 1 "@CMAKE_DATE@" "libiio-@LIBIIO_VERSION_MAJOR@.@LIBIIO_VERSION_MINOR@" "LibIIO Utilities" 26 | .IX iio_reg_ 27 | .SH NAME 28 | iio_reg \- do a low level read or write to SPI or I2C register 29 | .SH SYNOPSIS 30 | .B iio_reg 31 | [ 32 | .I options 33 | ] 34 | [] 35 | .SH DESCRIPTION 36 | .B iio_reg 37 | is a utility for debugging local or remote IIO devices. 38 | It should not be used by normal users, and is normally used by driver 39 | developers during development, or by end users debugging a driver, or sending 40 | in a feature request. 41 | It provides a mechanism to read or write SPI or I2C registers for IIO devices. 42 | This can be useful when troubleshooting IIO devices, and understanding how 43 | the Linux IIO subsystem is managing the device. 44 | 45 | .SH OPTIONS 46 | ##COMMON_COMMANDS_START## 47 | ##COMMON_COMMANDS_STOP## 48 | ##COMMON_OPTION_START## 49 | ##COMMON_OPTION_STOP## 50 | .SH RETURN VALUE 51 | If the specified device is not found, a non-zero exit code is returned. 52 | 53 | -------------------------------------------------------------------------------- /man/iio_rwdev.1.in: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2018-2020 Robin Getz 2 | .\" Copyright (c) 2018-2020 Analog Devices Inc. 3 | .\" 4 | .\" %%%LICENSE_START(GPLv2+_DOC_FULL) 5 | .\" This is free documentation; you can redistribute it and/or 6 | .\" modify it under the terms of the GNU General Public License as 7 | .\" published by the Free Software Foundation; either version 2 of 8 | .\" the License, or (at your option) any later version. 9 | .\" 10 | .\" The GNU General Public License's references to "object code" 11 | .\" and "executables" are to be interpreted as the output of any 12 | .\" document formatting or typesetting system, including 13 | .\" intermediate and printed output. 14 | .\" 15 | .\" This manual is distributed in the hope that it will be useful, 16 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | .\" GNU General Public License for more details. 19 | .\" 20 | .\" You should have received a copy of the GNU General Public 21 | .\" License along with this manual; if not, see 22 | .\" . 23 | .\" %%%LICENSE_END 24 | .\" 25 | .TH iio_rwdev 1 "@CMAKE_DATE@" "libiio-@LIBIIO_VERSION_MAJOR@.@LIBIIO_VERSION_MINOR@" "LibIIO Utilities" 26 | .IX iio_rwdev_ 27 | .SH NAME 28 | iio_rwdev \- read/write buffers from/to an IIO device 29 | .SH SYNOPSIS 30 | .B iio_rwdev 31 | [ 32 | .I options 33 | ] 34 | [-n ] [-t ] [-T ] [-b ] [-s ] [-w] [ ...] 35 | .SH DESCRIPTION 36 | .B iio_reg 37 | is a utility for reading buffers from connected IIO devices, and sending results to standard out. 38 | 39 | .SH OPTIONS 40 | ##COMMON_COMMANDS_START## 41 | ##COMMON_COMMANDS_STOP## 42 | .TP 43 | .B \-w \-\-write 44 | Write sample data to the IIO device. The default is to read samples from it. 45 | .TP 46 | .B \-t \-\-trigger 47 | Use the specified trigger, if needed on the specified channel 48 | .TP 49 | .B \-b \-\-buffer-size 50 | Size of the capture buffer. Default is 256. 51 | .TP 52 | .B \-s \-\-samples 53 | Number of samples (not bytes) to capture, 0 = infinite. Default is 0. 54 | .TP 55 | .B \-T \-\-timeout 56 | Buffer timeout in milliseconds. 0 = no timeout. Default is 0. 57 | ##COMMON_OPTION_START## 58 | ##COMMON_OPTION_STOP## 59 | .SH RETURN VALUE 60 | If the specified device is not found, a non-zero exit code is returned. 61 | 62 | .SH "USAGE" 63 | .PP 64 | You use iio_rwdev in the same way you use many of the other libiio utilities. 65 | You should specify a IIO device, and the specific channel to read or write. 66 | When reading, channels must be input; when writing they must be output. 67 | If no channel is provided, iio_rwdev will read from all input channels or write 68 | to all output channels. 69 | If no device is provided, iio_rwdev will print a few examples: 70 | .RS 71 | .B \f(CWiio_rwdev -a\fP 72 | .br 73 | Using auto-detected IIO context at URI "usb:3.10.5" 74 | .br 75 | Example : iio_rwdev -u usb:3.10.5 -b 256 -s 1024 cf-ad9361-lpc voltage0 76 | .br 77 | Example : iio_rwdev -u usb:3.10.5 -b 256 -s 1024 cf-ad9361-lpc voltage1 78 | .br 79 | Example : iio_rwdev -u usb:3.10.5 -b 256 -s 1024 cf-ad9361-lpc voltage2 80 | .br 81 | Example : iio_rwdev -u usb:3.10.5 -b 256 -s 1024 cf-ad9361-lpc voltage3 82 | .br 83 | Example : iio_rwdev -u usb:3.10.5 -b 256 -s 1024 cf-ad9361-lpc 84 | .RE 85 | .PP 86 | This captures 1024 samples of I and Q data from the USB attached AD9361, and 87 | stores it (as raw binary) into the file samples.dat 88 | .RS 89 | .B \f(CWiio_rwdev \-a \-s 1024 cf-ad9361-lpc voltage0 voltage1 > samples.dat\fP 90 | .RE 91 | .PP 92 | And plots the data with gnuplot. 93 | .RS 94 | .B \f(WCgnuplot \-e \(dq\&set term png; set output 'sample.png'; plot 'sample.dat' binary format='%short%short' using 1 with lines, 'sample.dat' binary format='%short%short' using 2 with lines;\(dq\&\fP 95 | .RE 96 | 97 | -------------------------------------------------------------------------------- /man/iio_stresstest.1.in: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2018-2020 Robin Getz 2 | .\" Copyright (c) 2018-2020 Analog Devices Inc. 3 | .\" 4 | .\" %%%LICENSE_START(GPLv2+_DOC_FULL) 5 | .\" This is free documentation; you can redistribute it and/or 6 | .\" modify it under the terms of the GNU General Public License as 7 | .\" published by the Free Software Foundation; either version 2 of 8 | .\" the License, or (at your option) any later version. 9 | .\" 10 | .\" The GNU General Public License's references to "object code" 11 | .\" and "executables" are to be interpreted as the output of any 12 | .\" document formatting or typesetting system, including 13 | .\" intermediate and printed output. 14 | .\" 15 | .\" This manual is distributed in the hope that it will be useful, 16 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | .\" GNU General Public License for more details. 19 | .\" 20 | .\" You should have received a copy of the GNU General Public 21 | .\" License along with this manual; if not, see 22 | .\" . 23 | .\" %%%LICENSE_END 24 | .\" 25 | .TH iio_stresstest 1 "@CMAKE_DATE@" "libiio-@LIBIIO_VERSION_MAJOR@.@LIBIIO_VERSION_MINOR@" "LibIIO Utilities" 26 | .IX iio_stresstest 27 | .SH NAME 28 | iio_stresstest \- Stress test program for Libiio 29 | .SH SYNOPSIS 30 | .B iio_stresstest 31 | [ 32 | .I options 33 | ] 34 | -u 35 | .SH DESCRIPTION 36 | .B iio_stresstest 37 | is a stress-testing program that can be used to find bugs in Libiio or in the Libiio daemon (IIOD). 38 | 39 | 40 | .SH OPTIONS 41 | ##COMMON_COMMANDS_START## 42 | ##COMMON_COMMANDS_STOP## 43 | ##COMMON_OPTION_START## 44 | ##COMMON_OPTION_STOP## 45 | .TP 46 | .B \-a, \-\-auto 47 | Scan for available contexts and if only one is available use it. 48 | .TP 49 | .B \-T, \-\-timeout 50 | Context timeout in milliseconds. 0 = no timeout (wait forever) 51 | .TP 52 | .B \-b, \-\-buffer\-size 53 | Size of the capture buffer. Default is 256. 54 | .TP 55 | .B \-s, \-\-samples 56 | Number of samples to capture, 0 = infinite. Default is 0. 57 | .TP 58 | .B \-d, \-\-duration 59 | Time to wait (in seconds) before stopping all threads 60 | .TP 61 | .B \-t, \-\-threads 62 | Number of threads to use 63 | .TP 64 | .B \-v, \-\-verbose 65 | Increase verbosity (-vv and -vvv for more) 66 | 67 | .SH RETURN VALUE 68 | If the specified device is not found, a non-zero exit code is returned. 69 | 70 | -------------------------------------------------------------------------------- /man/iiod.1.in: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2018-2020 Robin Getz 2 | .\" Copyright (c) 2018-2020 Analog Devices Inc. 3 | .\" 4 | .\" %%%LICENSE_START(GPLv2+_DOC_FULL) 5 | .\" This is free documentation; you can redistribute it and/or 6 | .\" modify it under the terms of the GNU General Public License as 7 | .\" published by the Free Software Foundation; either version 2 of 8 | .\" the License, or (at your option) any later version. 9 | .\" 10 | .\" The GNU General Public License's references to "object code" 11 | .\" and "executables" are to be interpreted as the output of any 12 | .\" document formatting or typesetting system, including 13 | .\" intermediate and printed output. 14 | .\" 15 | .\" This manual is distributed in the hope that it will be useful, 16 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | .\" GNU General Public License for more details. 19 | .\" 20 | .\" You should have received a copy of the GNU General Public 21 | .\" License along with this manual; if not, see 22 | .\" . 23 | .\" %%%LICENSE_END 24 | .\" 25 | .TH iiod 1 "@CMAKE_DATE@" "libiio-@LIBIIO_VERSION_MAJOR@.@LIBIIO_VERSION_MINOR@" "LibIIO Utilities" 26 | .IX iiod 27 | .SH NAME 28 | iiod \- IIO Daemon 29 | .SH SYNOPSIS 30 | .B iiod 31 | [ 32 | .I options 33 | ] 34 | 35 | .SH DESCRIPTION 36 | .B iiod 37 | is a server built on top of Libiio which can share a Libiio context across the 38 | network, USB, or a UART link. 39 | 40 | .SH COMMANDS 41 | .TP 42 | .B \-V, \-\-version 43 | Display the version of this program. 44 | .TP 45 | .B \-d, \-\-debug 46 | Use alternative (incompatible) debug interface. 47 | .TP 48 | .B \-D, \-\-demux 49 | Demux channels directly on the server. 50 | .TP 51 | .B \-i, \-\-interactive 52 | Run iiod in the controlling terminal. 53 | .TP 54 | .B \-a, \-\-aio 55 | Use asynchronous I/O. 56 | .TP 57 | .B \-F, \-\-ffs 58 | Use the given FunctionFS mountpoint to serve over USB. 59 | .TP 60 | .B \-n, \-\-nb\-pipes 61 | Specify the number of USB pipes (ep couples) to use. 62 | .TP 63 | .B \-s, \-\-serial 64 | Run iiod on the specified UART. 65 | .TP 66 | .B \-p, \-\-port 67 | Port to listen on (default = 30431). 68 | Using --port 0 will pick an ephemeral port (dynamic / unused in the range between 32768–60999). 69 | .TP 70 | .B \-u, \-\-uri 71 | The Uniform Resource Identifier 72 | .I (uri) 73 | for connecting to devices, can be one of: 74 | .RS 75 | .IP ip:[address] 76 | network address, either numeric (192.168.0.1) or network hostname 77 | .IP ip: 78 | blank, if compiled with zeroconf support, will find an IIO device on network 79 | .IP usb:[device:port:instance] 80 | normally returned from 81 | .B iio_info -S 82 | .IP serial:[port],[baud],[settings] 83 | which are controlled, and need to match the iiod (or tinyiiod) on the other end of the serial port. 84 | .RS 85 | .IP [port] 86 | is something like '/dev/ttyUSB0' on Linux, and 'COM4' on Windows. 87 | .IP [baud] 88 | is is normally one of 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200 [default], 128000 or 256000, but can vary system to system. 89 | .IP [settings] 90 | would normally be configured as '8n1' this is controlled by: 91 | .RS 92 | .IP data_bits: 93 | (5, 6, 7, 8 [default], or 9) 94 | .IP parity_bits: 95 | ('n' none [default], 'o' odd, 'e' even, 'm' mark, or 's' space) 96 | .IP stop_bits: 97 | (1 [default, or 2) 98 | .IP flow_control: 99 | ('0' none [default], 'x' Xon Xoff, 'r' RTSCTS, or 'd' DTRDSR) 100 | .RE 101 | .RE 102 | .IP local: 103 | with no address part. This is the default. 104 | .RE 105 | .TP 106 | 107 | .SH RETURN VALUE 108 | If the specified device is not found, a non-zero exit code is returned. 109 | -------------------------------------------------------------------------------- /man/make_util_pages.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | dir=$1 4 | if [ -z "${dir}" -o ! -f "${dir}/iio_common_cmds.1" -o ! -f "${dir}/iio_common_opts.1" -o ! -f "${dir}/iio_common_footer.1" ] ; then 5 | echo "not pointing to src directory ${dir}" 1>&2 6 | exit 7 | fi 8 | file=$2 9 | if [ -z "${file}" -o ! -f "${file}" ] ; then 10 | echo "missing 2nd argument file to manipulate ${file}" 1>&2 11 | exit 12 | fi 13 | 14 | app=$(grep "^.TH" "${file}" | head -1 | awk '{print $2}') 15 | 16 | sed '/##COMMON_COMMANDS_START##/Q' "${file}" 17 | sed "s/##APP_NAME##/${app}/g" "${dir}/iio_common_cmds.1" 18 | sed -n '/^##COMMON_COMMANDS_STOP##/,${p;/^##COMMON_OPTION_START##/q}' "${file}" | grep -v "##COMMON_" 19 | sed "s/##APP_NAME##/${app}/g" "${dir}/iio_common_opts.1" 20 | sed -ne '/^##COMMON_OPTION_STOP#/,$ p' "${file}" | grep -v "##COMMON_OPTION_STOP##" 21 | sed "s/##APP_NAME##/${app}/g" "${dir}/iio_common_footer.1" 22 | -------------------------------------------------------------------------------- /mask.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2022 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | #include "iio-private.h" 10 | 11 | #include 12 | #include 13 | 14 | struct iio_channels_mask * iio_create_channels_mask(unsigned int nb_channels) 15 | { 16 | struct iio_channels_mask *mask; 17 | size_t nb_words = (nb_channels + 31) / 32; 18 | 19 | if (!nb_words) 20 | return NULL; 21 | 22 | mask = zalloc(sizeof(*mask) + nb_words * sizeof(uint32_t)); 23 | if (mask) 24 | mask->words = nb_words; 25 | 26 | return mask; 27 | } 28 | 29 | int iio_channels_mask_copy(struct iio_channels_mask *dst, 30 | const struct iio_channels_mask *src) 31 | { 32 | if (dst->words != src->words) 33 | return -EINVAL; 34 | 35 | memcpy(dst->mask, src->mask, src->words * sizeof(uint32_t)); 36 | 37 | return 0; 38 | } 39 | 40 | void iio_channels_mask_destroy(struct iio_channels_mask *mask) 41 | { 42 | free(mask); 43 | } 44 | -------------------------------------------------------------------------------- /network.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2014-2020 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | * Robin Getz 8 | */ 9 | 10 | #ifndef __IIO_NETWORK_H 11 | #define __IIO_NETWORK_H 12 | 13 | #include 14 | 15 | #define FQDN_LEN (255) /* RFC 1035 */ 16 | 17 | struct iio_context_params; 18 | struct iio_context_pdata; 19 | struct addrinfo; 20 | 21 | struct iiod_client_pdata { 22 | int fd; 23 | 24 | bool cancelled; 25 | void * events[2]; 26 | int cancel_fd[2]; 27 | 28 | const struct iio_context_params *params; 29 | struct iio_context_pdata *ctx_pdata; 30 | }; 31 | 32 | int setup_cancel(struct iiod_client_pdata *io_ctx); 33 | void cleanup_cancel(struct iiod_client_pdata *io_ctx); 34 | void do_cancel(struct iiod_client_pdata *io_ctx); 35 | int wait_cancellable(struct iiod_client_pdata *io_ctx, 36 | bool read, unsigned int timeout_ms); 37 | 38 | int create_socket(const struct addrinfo *addrinfo, unsigned int timeout); 39 | int do_create_socket(const struct addrinfo *addrinfo); 40 | int do_select(int fd, unsigned int timeout); 41 | 42 | int set_blocking_mode(int s, bool blocking); 43 | 44 | int network_get_error(void); 45 | bool network_should_retry(int err); 46 | bool network_is_interrupted(int err); 47 | bool network_connect_in_progress(int err); 48 | 49 | #endif /* __IIO_NETWORK_H */ 50 | -------------------------------------------------------------------------------- /properties.rc.cmakein: -------------------------------------------------------------------------------- 1 | #include 2 | LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT 3 | VS_VERSION_INFO VERSIONINFO 4 | FILEVERSION @LIBIIO_FILEVERSION@ 5 | BEGIN 6 | BLOCK "StringFileInfo" 7 | BEGIN 8 | BLOCK "040904E4" 9 | BEGIN 10 | VALUE "CompanyName", "Analog Devices" 11 | VALUE "FileDescription", "libiio - Library for interface to IIO devices" 12 | VALUE "InternalName", "libiio" 13 | VALUE "LegalCopyright", "Copyright 2015-@BUILD_YEAR@ ADI and other contributors" 14 | VALUE "LegalTrademarks", "http://www.gnu.org/licenses/lgpl-2.1.html" 15 | VALUE "ProductName", "libiio" 16 | VALUE "ProductVersion", "@VERSION@-g@LIBIIO_VERSION_GIT@" 17 | VALUE "OriginalFilename", "@LIBIIO_ORIGINAL_FILENAME@" 18 | END 19 | END 20 | 21 | BLOCK "VarFileInfo" 22 | BEGIN 23 | VALUE "Translation", 0x409, 1252 24 | END 25 | END 26 | -------------------------------------------------------------------------------- /sort.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2018 Analog Devices, Inc. 6 | * Author: Robin Getz 7 | */ 8 | 9 | #include "iio-private.h" 10 | #include 11 | #include 12 | 13 | /* These are a few functions to do sorting via qsort for various 14 | * iio structures. For more info, see the qsort(3) man page. 15 | * 16 | * The qsort comparison function must return an integer less than, equal to, 17 | * or greater than zero if the first argument is considered to be 18 | * respectively less than, equal to, or greater than the second. If two 19 | * members compare as equal, their order in the sort order is undefined. 20 | * 21 | * If the structures are updated, the compare functions may 22 | * need to be updated. 23 | * 24 | * The actual arguments to these function are "pointers to 25 | * pointers to char", but strcmp(3) arguments are "pointers 26 | * to char", hence the cast plus dereference 27 | */ 28 | 29 | static int iio_channel_compare(const void *p1, const void *p2) 30 | { 31 | const struct iio_channel *tmp1 = *(struct iio_channel **)p1; 32 | const struct iio_channel *tmp2 = *(struct iio_channel **)p2; 33 | long idx1 = iio_channel_get_index(tmp1); 34 | long idx2 = iio_channel_get_index(tmp2); 35 | 36 | if (idx1 == idx2 && idx1 >= 0) { 37 | idx1 = iio_channel_get_data_format(tmp1)->shift; 38 | idx2 = iio_channel_get_data_format(tmp2)->shift; 39 | } 40 | 41 | if (idx2 >= 0 && (idx1 > idx2 || idx1 < 0)) 42 | return 1; 43 | 44 | return -1; 45 | } 46 | 47 | static int iio_device_compare(const void *p1, const void *p2) 48 | { 49 | const struct iio_device *tmp1 = *(struct iio_device **)p1; 50 | const struct iio_device *tmp2 = *(struct iio_device **)p2; 51 | /* qsort devices by ID */ 52 | return strcmp(tmp1->id, tmp2->id); 53 | } 54 | 55 | static int iio_attr_compare(const void *p1, const void *p2) 56 | { 57 | const struct iio_attr *attr1 = (const struct iio_attr *)p1; 58 | const struct iio_attr *attr2 = (const struct iio_attr *)p2; 59 | 60 | return strcmp(attr1->name, attr2->name); 61 | } 62 | 63 | void iio_sort_attrs(struct iio_attr_list *attrs) 64 | { 65 | if (attrs->num > 0) { 66 | qsort(attrs->attrs, attrs->num, 67 | sizeof(*attrs->attrs), iio_attr_compare); 68 | } 69 | } 70 | 71 | void iio_sort_devices(struct iio_context *ctx) 72 | { 73 | qsort(ctx->devices, ctx->nb_devices, 74 | sizeof(*ctx->devices), iio_device_compare); 75 | } 76 | 77 | void iio_sort_channels(struct iio_device *dev) 78 | { 79 | qsort(dev->channels, dev->nb_channels, 80 | sizeof(*dev->channels), iio_channel_compare); 81 | } 82 | -------------------------------------------------------------------------------- /sort.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2018 Analog Devices, Inc. 6 | * Author: Robin Getz 7 | */ 8 | 9 | #ifndef __IIO_QSORT_H__ 10 | #define __IIO_QSORT_H__ 11 | 12 | struct iio_attr_list; 13 | struct iio_context; 14 | struct iio_device; 15 | 16 | void iio_sort_attrs(struct iio_attr_list *attrs); 17 | void iio_sort_devices(struct iio_context *ctx); 18 | void iio_sort_channels(struct iio_device *dev); 19 | 20 | #endif /* __IIO_QSORT_H__ */ 21 | -------------------------------------------------------------------------------- /tinyiiod/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | project(tinyiiod C) 3 | 4 | add_library(tinyiiod STATIC 5 | tinyiiod.c 6 | ${CMAKE_SOURCE_DIR}/iiod/responder.c 7 | ${CMAKE_SOURCE_DIR}/iiod/rw.c 8 | ) 9 | target_include_directories(tinyiiod PRIVATE 10 | ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} 11 | ) 12 | set_target_properties(tinyiiod PROPERTIES 13 | VERSION ${LIBIIO_VERSION_MAJOR}.${LIBIIO_VERSION_MINOR} 14 | SOVERSION ${LIBIIO_VERSION_MAJOR} 15 | PUBLIC_HEADER tinyiiod.h 16 | C_STANDARD 99 17 | C_STANDARD_REQUIRED ON 18 | C_EXTENSIONS OFF 19 | ) 20 | target_link_libraries(tinyiiod LINK_PRIVATE iio iio_common_config iiod-responder) 21 | -------------------------------------------------------------------------------- /tinyiiod/tinyiiod.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2024 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | #include "../iiod/ops.h" 10 | #include "tinyiiod.h" 11 | 12 | #include 13 | 14 | #define container_of(ptr, type, member) \ 15 | ((type *)(void *)((uintptr_t)(ptr) - offsetof(type, member))) 16 | 17 | struct iiod_pdata; 18 | 19 | struct iio_context_params iiod_params = { 20 | .log_level = LEVEL_INFO, 21 | }; 22 | 23 | struct iiod_ctx { 24 | struct parser_pdata parser_pdata; 25 | struct iiod_pdata *pdata; 26 | ssize_t (*read_cb)(struct iiod_pdata *, void *, size_t); 27 | ssize_t (*write_cb)(struct iiod_pdata *, const void *, size_t); 28 | }; 29 | 30 | static ssize_t iiod_readfd(struct parser_pdata *pdata, void *buf, size_t len) 31 | { 32 | struct iiod_ctx *ctx = container_of(pdata, struct iiod_ctx, parser_pdata); 33 | 34 | return ctx->read_cb(ctx->pdata, buf, len); 35 | } 36 | 37 | static ssize_t iiod_writefd(struct parser_pdata *pdata, const void *buf, size_t len) 38 | { 39 | struct iiod_ctx *ctx = container_of(pdata, struct iiod_ctx, parser_pdata); 40 | 41 | return ctx->write_cb(ctx->pdata, buf, len); 42 | } 43 | 44 | int iiod_interpreter(struct iio_context *ctx, 45 | struct iiod_pdata *pdata, 46 | ssize_t (*read_cb)(struct iiod_pdata *, void *, size_t), 47 | ssize_t (*write_cb)(struct iiod_pdata *, const void *, size_t), 48 | const void *xml_zstd, size_t xml_zstd_len) 49 | { 50 | struct iiod_ctx iiod_ctx = { 51 | .parser_pdata = { 52 | .ctx = ctx, 53 | .xml_zstd = xml_zstd, 54 | .xml_zstd_len = xml_zstd_len, 55 | .readfd = iiod_readfd, 56 | .writefd = iiod_writefd, 57 | }, 58 | .read_cb = read_cb, 59 | .write_cb = write_cb, 60 | .pdata = pdata, 61 | }; 62 | int ret; 63 | 64 | buflist_lock = iio_mutex_create(); 65 | ret = iio_err(buflist_lock); 66 | if (ret) 67 | return ret; 68 | 69 | evlist_lock = iio_mutex_create(); 70 | ret = iio_err(evlist_lock); 71 | if (ret) 72 | goto out_destroy_buflist_lock; 73 | 74 | binary_parse(&iiod_ctx.parser_pdata); 75 | 76 | iio_mutex_destroy(evlist_lock); 77 | out_destroy_buflist_lock: 78 | iio_mutex_destroy(buflist_lock); 79 | return ret; 80 | } 81 | -------------------------------------------------------------------------------- /tinyiiod/tinyiiod.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2024 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | */ 8 | 9 | #ifndef __LIBTINYIIOD_H__ 10 | #define __LIBTINYIIOD_H__ 11 | 12 | #include 13 | 14 | struct iiod_pdata; 15 | 16 | /* Default Libiio context parameters for IIOD. 17 | * You can modify it if needed before calling iiod_interpreter(). */ 18 | extern struct iio_context_params iiod_params; 19 | 20 | /* Execute the IIOD interpreter using the specified read_cb/write_cb callbacks. 21 | * IIOD will run until one of the callbacks returns a negative error code. 22 | * 23 | * ctx: Libiio context to use 24 | * pdata: User-provided data structure (or NULL) that will be passed along to 25 | * the read_cb/write_cb callbacks 26 | * read_cb: Callback to read from the bus. This can block, and the application 27 | * is free to do any unrelated processing in this callback. 28 | * write_cb: Callback to write data to the bus. 29 | * xml: XML representation of the Libiio context. It is recommended to pass a 30 | * ZSTD-compressed buffer here, as it would be much faster to transfer on the 31 | * bus; but a plain XML string works as well. 32 | * xml_len: Size of the ZSTD-compressed data, or length of the XML string. 33 | */ 34 | int iiod_interpreter(struct iio_context *ctx, 35 | struct iiod_pdata *pdata, 36 | ssize_t (*read_cb)(struct iiod_pdata *, void *, size_t), 37 | ssize_t (*write_cb)(struct iiod_pdata *, const void *, size_t), 38 | const void *xml, size_t xml_len); 39 | 40 | /* When a blocking iio_backend_ops.read_ev() is called, and there is no event, 41 | * the callback is expected to return -EAGAIN; only then, when/if an event 42 | * eventually occurs, the application should call iiod_set_event() once to 43 | * answer. */ 44 | void iiod_set_event(struct iio_event_stream *stream, 45 | const struct iio_event *event, 46 | int err_code_or_zero); 47 | 48 | #endif /* __LIBTINYIIOD_H__ */ 49 | -------------------------------------------------------------------------------- /utils/.gitignore: -------------------------------------------------------------------------------- 1 | iio_adi_xflow_check 2 | iio_genxml 3 | iio_info 4 | iio_readdev 5 | iio_reg 6 | -------------------------------------------------------------------------------- /utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | set(IIO_TESTS_TARGETS iio_genxml iio_info iio_attr iio_rwdev iio_reg iio_event) 4 | if (PTHREAD_LIBRARIES OR ANDROID) 5 | LIST(APPEND IIO_TESTS_TARGETS iio_stresstest) 6 | endif() 7 | 8 | if(APPLE) 9 | # Add relative rpath to iio library (which is in the same framework) 10 | set(CMAKE_INSTALL_RPATH "@executable_path/../..") 11 | set(CMAKE_BUILD_WITH_INSTALL_RPATH ON) 12 | endif() 13 | 14 | if (WIN32) 15 | set(LIBIIO_ORIGINAL_FILENAME ) 16 | set(LIBIIO_RC ${CMAKE_CURRENT_BINARY_DIR}/properties.rc) 17 | configure_file(../properties.rc.cmakein ${LIBIIO_RC} @ONLY) 18 | endif() 19 | 20 | add_library(iio_tests_helper STATIC iio_common.c gen_code.c) 21 | target_link_libraries(iio_tests_helper LINK_PRIVATE iio iio_common_config) 22 | if (MSVC) 23 | target_sources(iio_tests_helper PRIVATE ../deps/wingetopt/src/getopt.c) 24 | target_include_directories(iio_tests_helper PUBLIC ../deps/wingetopt/src) 25 | target_compile_definitions(iio_tests_helper PRIVATE _CRT_SECURE_NO_WARNINGS) 26 | target_link_options(iio_tests_helper PUBLIC /DEBUG) 27 | endif() 28 | set_target_properties(iio_tests_helper PROPERTIES 29 | C_STANDARD 99 30 | C_STANDARD_REQUIRED ON 31 | C_EXTENSIONS OFF 32 | ) 33 | 34 | foreach (test ${IIO_TESTS_TARGETS}) 35 | project(${test} LANGUAGES C) 36 | add_executable(${test} ${test}.c ${GETOPT_C_FILE} ${LIBIIO_RC}) 37 | set_target_properties(${test} PROPERTIES 38 | C_STANDARD 99 39 | C_STANDARD_REQUIRED ON 40 | C_EXTENSIONS OFF 41 | ) 42 | if (CMAKE_COMPILER_IS_GNUCC) 43 | target_compile_definitions(${test} PRIVATE IIO_CHECK_RET) 44 | endif() 45 | target_link_libraries(${test} LINK_PRIVATE iio iio_tests_helper) 46 | if (MSVC) 47 | target_link_options(${test} PUBLIC /DEBUG) 48 | endif() 49 | endforeach() 50 | 51 | if(PTHREAD_LIBRARIES) 52 | set(IIO_TESTS_NEED_PTHREAD iio_rwdev iio_stresstest) 53 | 54 | foreach(test ${IIO_TESTS_NEED_PTHREAD}) 55 | target_link_libraries(${test} LINK_PRIVATE ${PTHREAD_LIBRARIES}) 56 | endforeach() 57 | endif() 58 | 59 | # Make the test targets available to the main CMakeLists.txt 60 | set(IIO_TESTS_TARGETS ${IIO_TESTS_TARGETS} PARENT_SCOPE) 61 | -------------------------------------------------------------------------------- /utils/gen_code.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 | /* 3 | * libiio - Library for interfacing industrial I/O (IIO) devices 4 | * 5 | * Copyright (C) 2014, 2019 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | * Robin Getz 8 | */ 9 | 10 | #ifndef GEN_CODE_H 11 | #define GEN_CODE_H 12 | 13 | struct iio_attr; 14 | 15 | void gen_start(const char *gen_file); 16 | bool gen_test_path(const char *gen_file); 17 | void gen_context (const char *uri); 18 | void gen_context_destroy(void); 19 | void gen_context_attr(const char *key); 20 | void gen_dev(const struct iio_device *dev); 21 | void gen_ch(const struct iio_channel *ch); 22 | void gen_function(const char* prefix, const char* target, 23 | const struct iio_attr *attr, const char *wbuf); 24 | void gen_context_timeout(unsigned int timeout_ms); 25 | #endif 26 | -------------------------------------------------------------------------------- /utils/iio_common.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 | /* 3 | * iio_common - Part of libIIO utilities 4 | * 5 | * Copyright (C) 2014-2020 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | * */ 8 | 9 | #ifndef IIO_TESTS_COMMON_H 10 | #define IIO_TESTS_COMMON_H 11 | 12 | #include 13 | #include 14 | 15 | /* 16 | * internal buffers need to be big enough for attributes 17 | * coming back from the kernel. Because of virtual memory, 18 | * only the amount of ram that is needed is used. 19 | */ 20 | #define BUF_SIZE 16384 21 | 22 | enum backend { 23 | IIO_LOCAL, 24 | IIO_XML, 25 | IIO_NETWORK, 26 | IIO_USB, 27 | IIO_URI, 28 | IIO_AUTO, 29 | }; 30 | 31 | struct iio_channels_mask; 32 | struct iio_context; 33 | struct iio_device; 34 | struct option; 35 | 36 | void * xmalloc(size_t n, const char *name); 37 | char *cmn_strndup(const char *str, size_t n); 38 | 39 | struct iio_context * autodetect_context(bool rtn, const char *name, 40 | const char *scan); 41 | unsigned long int sanitize_clamp(const char *name, const char *argv, 42 | uint64_t min, uint64_t max); 43 | int iio_device_enable_channel(const struct iio_device *dev, const char *channel, 44 | bool type, struct iio_channels_mask *mask); 45 | 46 | /* optstring is a string containing the legitimate option characters. 47 | * If such a character is followed by a colon, the option requires an argument. 48 | * Two colons mean an option takes an optional argument. 49 | */ 50 | #define COMMON_OPTIONS "hVu:a::S::T:" 51 | 52 | struct iio_context * handle_common_opts(char * name, int argc, 53 | char * const argv[], const char *optstring, 54 | const struct option *options, const char *options_descriptions[], 55 | int *ret); 56 | struct option * add_common_options(const struct option * longopts); 57 | void usage(char *name, const struct option *options, const char *options_descriptions[]); 58 | void version(char *name); 59 | 60 | char ** dup_argv(char * name, unsigned int argc, char * argv[]); 61 | void free_argw(unsigned int argc, char * argw[]); 62 | 63 | uint64_t get_time_us(void); 64 | 65 | const char * dev_name(const struct iio_device *dev); 66 | 67 | /* https://pubs.opengroup.org/onlinepubs/009695399/basedefs/limits.h.html 68 | * {NAME_MAX} : Maximum number of bytes in a filename 69 | * {PATH_MAX} : Maximum number of bytes in a pathname 70 | * {PAGESIZE} : Size in bytes of a page 71 | * Too bad we work on non-POSIX systems 72 | */ 73 | #ifndef NAME_MAX 74 | #define NAME_MAX 256 75 | #endif 76 | 77 | 78 | #endif /* IIO_TESTS_COMMON_H */ 79 | -------------------------------------------------------------------------------- /utils/iio_genxml.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | * iio_genxml - Part of the Industrial I/O (IIO) utilities 4 | * 5 | * Copyright (C) 2014 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | * */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "iio_common.h" 15 | 16 | #define MY_NAME "iio_genxml" 17 | 18 | #ifdef _WIN32 19 | #define snprintf sprintf_s 20 | #endif 21 | 22 | static const struct option options[] = { 23 | {0, 0, 0, 0}, 24 | }; 25 | 26 | static const char *options_descriptions[] = { 27 | ("\t[-x ]\n" 28 | "\t\t\t\t[-u ]\n" 29 | "\t\t\t\t[-n ]"), 30 | }; 31 | 32 | int main(int argc, char **argv) 33 | { 34 | char **argw, *uri, *xml; 35 | struct iio_context *ctx; 36 | struct option *opts; 37 | size_t buf_len; 38 | int c, ret = EXIT_FAILURE; 39 | int err; 40 | 41 | argw = dup_argv(MY_NAME, argc, argv); 42 | ctx = handle_common_opts(MY_NAME, argc, argw, "", 43 | options, options_descriptions, &ret); 44 | opts = add_common_options(options); 45 | if (!opts) { 46 | fprintf(stderr, "Failed to add common options\n"); 47 | return EXIT_FAILURE; 48 | } 49 | while ((c = getopt_long(argc, argv, "+" COMMON_OPTIONS, /* Flawfinder: ignore */ 50 | opts, NULL)) != -1) { 51 | switch (c) { 52 | /* All these are handled in the common */ 53 | case 'h': 54 | case 'V': 55 | case 'u': 56 | case 'T': 57 | break; 58 | case 'S': 59 | case 'a': 60 | if (!optarg && argc > optind && argv[optind] != NULL 61 | && argv[optind][0] != '-') 62 | optind++; 63 | break; 64 | case '?': 65 | printf("Unknown argument '%c'\n", c); 66 | return EXIT_FAILURE; 67 | } 68 | } 69 | free(opts); 70 | 71 | if (optind != argc) { 72 | fprintf(stderr, "Incorrect number of arguments.\n\n"); 73 | usage(MY_NAME, options, options_descriptions); 74 | return EXIT_FAILURE; 75 | } 76 | 77 | if (!ctx) 78 | return ret; 79 | 80 | xml = iio_context_get_xml(ctx); 81 | err = iio_err(xml); 82 | if (err) { 83 | fprintf(stderr, "Unable to retrieve context xml representation!\n"); 84 | iio_context_destroy(ctx); 85 | return EXIT_FAILURE; 86 | } 87 | printf("XML generated:\n\n%s\n\n", xml); 88 | 89 | buf_len = strlen(xml) + 5; 90 | uri = malloc(buf_len); 91 | if (!uri) { 92 | iio_context_destroy(ctx); 93 | free(xml); 94 | return EXIT_FAILURE; 95 | } 96 | 97 | snprintf(uri, buf_len, "xml:%s", xml); 98 | 99 | iio_context_destroy(ctx); 100 | free(xml); 101 | 102 | ctx = iio_create_context(NULL, uri); 103 | err = iio_err(ctx); 104 | if (err) { 105 | fprintf(stderr, "Unable to re-generate context\n"); 106 | } else { 107 | printf("Context re-creation from generated XML succeeded!\n"); 108 | iio_context_destroy(ctx); 109 | } 110 | 111 | free_argw(argc, argw); 112 | free(uri); 113 | 114 | return EXIT_SUCCESS; 115 | } 116 | -------------------------------------------------------------------------------- /utils/iio_reg.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | * iio_reg - Part of the industrial I/O (IIO) utilities 4 | * 5 | * Copyright (C) 2015 Analog Devices, Inc. 6 | * Author: Paul Cercueil 7 | * */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "iio_common.h" 16 | 17 | #define MY_NAME "iio_reg" 18 | 19 | static const struct option options[] = { 20 | {0, 0, 0, 0}, 21 | }; 22 | 23 | static const char *options_descriptions[] = { 24 | " []\n" 25 | }; 26 | 27 | static int write_reg(struct iio_device *dev, uint32_t addr, uint32_t val) 28 | { 29 | int ret; 30 | 31 | ret = iio_device_reg_write(dev, addr, val); 32 | if (ret < 0) { 33 | errno = -ret; 34 | perror("Unable to write register"); 35 | goto err_destroy_context; 36 | } 37 | 38 | return EXIT_SUCCESS; 39 | 40 | err_destroy_context: 41 | return EXIT_FAILURE; 42 | } 43 | 44 | static int read_reg(struct iio_device *dev, unsigned long addr) 45 | { 46 | uint32_t val; 47 | int ret; 48 | 49 | ret = iio_device_reg_read(dev, addr, &val); 50 | if (ret < 0) { 51 | errno = -ret; 52 | perror("Unable to read register"); 53 | goto err_destroy_context; 54 | } 55 | 56 | printf("0x%x\n", val); 57 | return EXIT_SUCCESS; 58 | 59 | err_destroy_context: 60 | return EXIT_FAILURE; 61 | } 62 | 63 | int main(int argc, char **argv) 64 | { 65 | char **argw; 66 | unsigned long addr; 67 | struct iio_context *ctx; 68 | struct iio_device *dev; 69 | int c, ret = EXIT_FAILURE; 70 | char * name; 71 | struct option *opts; 72 | 73 | argw = dup_argv(MY_NAME, argc, argv); 74 | 75 | ctx = handle_common_opts(MY_NAME, argc, argw, "", 76 | options, options_descriptions, &ret); 77 | opts = add_common_options(options); 78 | if (!opts) { 79 | fprintf(stderr, "Failed to add common options\n"); 80 | return EXIT_FAILURE; 81 | } 82 | while ((c = getopt_long(argc, argw, "+" COMMON_OPTIONS, /* Flawfinder: ignore */ 83 | opts, NULL)) != -1) { 84 | switch (c) { 85 | /* All these are handled in the common */ 86 | case 'h': 87 | case 'V': 88 | case 'u': 89 | case 'T': 90 | break; 91 | case 'S': 92 | case 'a': 93 | if (!optarg && argc > optind && argv[optind] != NULL 94 | && argv[optind][0] != '-') 95 | optind++; 96 | break; 97 | case '?': 98 | printf("Unknown argument '%c'\n", c); 99 | return EXIT_FAILURE; 100 | } 101 | } 102 | free(opts); 103 | 104 | if ((argc - optind) < 2 || (argc - optind) > 3) { 105 | usage(MY_NAME, options, options_descriptions); 106 | return EXIT_SUCCESS; 107 | } 108 | 109 | if (!ctx) 110 | return ret; 111 | 112 | name = cmn_strndup(argw[optind], NAME_MAX); 113 | dev = iio_context_find_device(ctx, name); 114 | if (!dev) { 115 | perror("Unable to find device"); 116 | goto err_destroy_context; 117 | } 118 | 119 | addr = sanitize_clamp("register address", argw[optind + 1], 0, UINT32_MAX); 120 | 121 | if ((argc - optind) == 2) { 122 | return read_reg(dev, addr); 123 | } else { 124 | uint32_t val = sanitize_clamp("register value", argw[optind + 2], 0, UINT32_MAX); 125 | return write_reg(dev, addr, val); 126 | } 127 | 128 | err_destroy_context: 129 | free(name); 130 | iio_context_destroy(ctx); 131 | free_argw(argc, argw); 132 | return EXIT_SUCCESS; 133 | } 134 | -------------------------------------------------------------------------------- /xml/ad5541a.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | ]> 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /xml/ad5628-1.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | ]> 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /xml/ad7091r.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | ]> 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /xml/adis16488.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | ]> 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | --------------------------------------------------------------------------------