├── contrib ├── libsigrok.png ├── libsigrok_112x112.png ├── vnd.sigrok.session.xml ├── 61-libsigrok-plugdev.rules └── 61-libsigrok-uaccess.rules ├── bindings ├── cxx │ ├── ConfigKey_methods.i │ ├── QuantityFlag_methods.hpp │ ├── libsigrokcxx.pc.in │ ├── QuantityFlag_methods.cpp │ └── ConfigKey_methods.hpp ├── java │ └── org │ │ └── sigrok │ │ └── core │ │ └── interfaces │ │ ├── LogCallback.java │ │ └── DatafeedCallback.java ├── python │ └── sigrok │ │ ├── __init__.py │ │ └── core │ │ └── __init__.py └── swig │ └── templates.i ├── ChangeLog ├── AUTHORS ├── libsigrok.pc.in ├── autogen.sh ├── src ├── fallback.c ├── crc.c ├── hardware │ ├── tondaj-sl-814 │ │ └── protocol.h │ ├── conrad-digi-35-cpu │ │ ├── protocol.h │ │ └── protocol.c │ ├── colead-slm │ │ └── protocol.h │ ├── hp-59306a │ │ ├── protocol.h │ │ └── protocol.c │ ├── baylibre-acme │ │ ├── gpio.h │ │ └── protocol.h │ ├── uni-t-ut32x │ │ └── protocol.h │ ├── teleinfo │ │ └── protocol.h │ ├── ftdi-la │ │ ├── protocol.h │ │ └── protocol.c │ ├── appa-55ii │ │ └── protocol.h │ ├── kern-scale │ │ └── protocol.h │ ├── mastech-ms6514 │ │ └── protocol.h │ ├── uni-t-dmm │ │ └── protocol.h │ ├── rohde-schwarz-sme-0x │ │ ├── protocol.h │ │ └── protocol.c │ ├── bkprecision-1856d │ │ └── protocol.h │ ├── ikalogic-scanaplus │ │ └── protocol.h │ ├── icstation-usbrelay │ │ └── protocol.h │ ├── asix-omega-rtm-cli │ │ └── protocol.h │ ├── center-3xx │ │ └── protocol.h │ ├── zeroplus-logic-cube │ │ ├── protocol.h │ │ ├── gl_usb.h │ │ └── protocol.c │ ├── atorch │ │ └── protocol.h │ ├── dcttech-usbrelay │ │ └── protocol.h │ ├── gwinstek-gds-800 │ │ └── protocol.h │ ├── microchip-pickit2 │ │ └── protocol.h │ ├── hung-chang-dso-2100 │ │ └── protocol.h │ ├── mic-985xx │ │ └── protocol.h │ ├── rdtech-um │ │ └── protocol.h │ ├── fluke-dmm │ │ └── protocol.h │ ├── saleae-logic-pro │ │ └── protocol.h │ ├── siglent-sdl10x0 │ │ └── protocol.h │ ├── arachnid-labs-re-load-pro │ │ └── protocol.h │ ├── norma-dmm │ │ └── protocol.h │ ├── serial-lcr │ │ └── protocol.h │ ├── gwinstek-gpd │ │ └── protocol.h │ ├── beaglelogic │ │ └── protocol.h │ ├── zketech-ebd-usb │ │ └── protocol.h │ ├── rdtech-tc │ │ └── protocol.h │ ├── testo │ │ └── protocol.h │ ├── lascar-el-usb │ │ └── protocol.h │ ├── ipdbg-la │ │ └── protocol.h │ ├── atten-pps3xxx │ │ └── protocol.h │ ├── kecheng-kc-330b │ │ └── protocol.h │ ├── manson-hcs-3xxx │ │ └── protocol.h │ ├── greatfet │ │ └── protocol.h │ ├── juntek-jds6600 │ │ └── protocol.h │ ├── hp-3457a │ │ └── protocol.h │ ├── lecroy-xstream │ │ └── protocol.h │ ├── agilent-dmm │ │ └── protocol.h │ ├── devantech-eth008 │ │ └── protocol.h │ ├── gwinstek-psp │ │ └── protocol.h │ ├── sysclk-sla5032 │ │ └── protocol.h │ ├── lecroy-logicstudio │ │ └── protocol.h │ └── mooshimeter-dmm │ │ └── protocol.h ├── driver_list_stop.c ├── driver_list_start.c ├── output │ ├── null.c │ └── binary.c ├── input │ └── null.c ├── transform │ ├── nop.c │ ├── invert.c │ └── scale.c ├── serial_hid.h ├── drivers.c ├── dmm │ └── m2110.c ├── minilzo │ ├── Makefile │ └── minilzo.h ├── binary_helpers.c ├── conversion.c └── serial_hid_bu86x.c ├── tests ├── input_all.c ├── main.c ├── lib.h ├── driver_all.c ├── device.c ├── output_all.c └── transform_all.c ├── .gitignore └── include └── libsigrok └── version.h.in /contrib/libsigrok.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/sigrok_slogic/HEAD/contrib/libsigrok.png -------------------------------------------------------------------------------- /bindings/cxx/ConfigKey_methods.i: -------------------------------------------------------------------------------- 1 | %attributestring(sigrok::ConfigKey, std::string, identifier, identifier); 2 | -------------------------------------------------------------------------------- /contrib/libsigrok_112x112.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/sigrok_slogic/HEAD/contrib/libsigrok_112x112.png -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | The ChangeLog is auto-generated when releasing. If you 2 | are seeing this, use 'git log' for a detailed list of changes. 3 | -------------------------------------------------------------------------------- /bindings/java/org/sigrok/core/interfaces/LogCallback.java: -------------------------------------------------------------------------------- 1 | package org.sigrok.core.interfaces; 2 | 3 | import org.sigrok.core.classes.LogLevel; 4 | 5 | public interface LogCallback 6 | { 7 | public void run(LogLevel loglevel, String message); 8 | } 9 | -------------------------------------------------------------------------------- /bindings/java/org/sigrok/core/interfaces/DatafeedCallback.java: -------------------------------------------------------------------------------- 1 | package org.sigrok.core.interfaces; 2 | 3 | import org.sigrok.core.classes.Device; 4 | import org.sigrok.core.classes.Packet; 5 | 6 | public interface DatafeedCallback 7 | { 8 | public void run(Device device, Packet packet); 9 | } 10 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | AUTHORS 3 | ------------------------------------------------------------------------------- 4 | 5 | Please check the source code files and/or git history and/or ChangeLog for 6 | a list of all authors and contributors. 7 | 8 | -------------------------------------------------------------------------------- /bindings/cxx/QuantityFlag_methods.hpp: -------------------------------------------------------------------------------- 1 | /** Get flags corresponding to a bitmask. */ 2 | static std::vector 3 | flags_from_mask(unsigned int mask); 4 | 5 | /** Get bitmask corresponding to a set of flags. */ 6 | static unsigned int mask_from_flags( 7 | std::vector flags); 8 | -------------------------------------------------------------------------------- /bindings/cxx/libsigrokcxx.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libsigrokcxx 7 | Description: C++ bindings for libsigrok 8 | URL: http://www.sigrok.org 9 | Requires: libsigrok @SR_GLIBMM_REQUIRES@ 10 | Version: @SR_PACKAGE_VERSION@ 11 | Libs: -L${libdir} -lsigrokcxx 12 | Libs.private: -lm 13 | Cflags: -I${includedir} 14 | -------------------------------------------------------------------------------- /contrib/vnd.sigrok.session.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | sigrok session 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /libsigrok.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libsigrok 7 | Description: Backend library for the sigrok signal analysis software suite 8 | URL: http://www.sigrok.org 9 | Requires: glib-2.0 10 | Requires.private: @SR_PKGLIBS@ 11 | Version: @SR_PACKAGE_VERSION@ 12 | Libs: -L${libdir} -lsigrok 13 | Libs.private: @SR_EXTRA_LIBS@ 14 | Cflags: -I${includedir} 15 | -------------------------------------------------------------------------------- /bindings/cxx/QuantityFlag_methods.cpp: -------------------------------------------------------------------------------- 1 | std::vector 2 | QuantityFlag::flags_from_mask(unsigned int mask) 3 | { 4 | auto result = std::vector(); 5 | while (mask) 6 | { 7 | unsigned int new_mask = mask & (mask - 1); 8 | result.push_back(QuantityFlag::get( 9 | static_cast(mask ^ new_mask))); 10 | mask = new_mask; 11 | } 12 | return result; 13 | } 14 | 15 | unsigned int QuantityFlag::mask_from_flags(std::vector flags) 16 | { 17 | unsigned int result = 0; 18 | for (auto flag : flags) 19 | result |= flag->id(); 20 | return result; 21 | } 22 | -------------------------------------------------------------------------------- /bindings/cxx/ConfigKey_methods.hpp: -------------------------------------------------------------------------------- 1 | /** Data type used for this configuration key. */ 2 | const DataType *data_type() const; 3 | /** String identifier for this configuration key, suitable for CLI use. */ 4 | std::string identifier() const; 5 | /** Description of this configuration key. */ 6 | std::string description() const; 7 | /** Get configuration key by string identifier. */ 8 | static const ConfigKey *get_by_identifier(std::string identifier); 9 | /** Parse a string argument into the appropriate type for this key. */ 10 | static Glib::VariantBase parse_string(std::string value, enum sr_datatype dt); 11 | Glib::VariantBase parse_string(std::string value) const; 12 | -------------------------------------------------------------------------------- /bindings/python/sigrok/__init__.py: -------------------------------------------------------------------------------- 1 | ## 2 | ## This file is part of the libsigrok project. 3 | ## 4 | ## Copyright (C) 2013 Martin Ling 5 | ## 6 | ## This program is free software: you can redistribute it and/or modify 7 | ## it under the terms of the GNU General Public License as published by 8 | ## the Free Software Foundation, either version 3 of the License, or 9 | ## (at your option) any later version. 10 | ## 11 | ## This program is distributed in the hope that it will be useful, 12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ## GNU General Public License for more details. 15 | ## 16 | ## You should have received a copy of the GNU General Public License 17 | ## along with this program. If not, see . 18 | ## 19 | -------------------------------------------------------------------------------- /bindings/python/sigrok/core/__init__.py: -------------------------------------------------------------------------------- 1 | ## 2 | ## This file is part of the libsigrok project. 3 | ## 4 | ## Copyright (C) 2013 Martin Ling 5 | ## 6 | ## This program is free software: you can redistribute it and/or modify 7 | ## it under the terms of the GNU General Public License as published by 8 | ## the Free Software Foundation, either version 3 of the License, or 9 | ## (at your option) any later version. 10 | ## 11 | ## This program is distributed in the hope that it will be useful, 12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ## GNU General Public License for more details. 15 | ## 16 | ## You should have received a copy of the GNU General Public License 17 | ## along with this program. If not, see . 18 | ## 19 | 20 | from . import classes 21 | from .classes import * 22 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | ## 3 | ## This file is part of the libsigrok project. 4 | ## 5 | ## Copyright (C) 2010-2012 Bert Vermeulen 6 | ## 7 | ## This program is free software: you can redistribute it and/or modify 8 | ## it under the terms of the GNU General Public License as published by 9 | ## the Free Software Foundation, either version 3 of the License, or 10 | ## (at your option) any later version. 11 | ## 12 | ## This program 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 15 | ## GNU General Public License for more details. 16 | ## 17 | ## You should have received a copy of the GNU General Public License 18 | ## along with this program. If not, see . 19 | ## 20 | 21 | test -n "$srcdir" || srcdir=`dirname "$0"` 22 | test -n "$srcdir" || srcdir=. 23 | 24 | autoreconf --force --install --verbose "$srcdir" 25 | -------------------------------------------------------------------------------- /src/fallback.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2014 Aurelien Jacobs 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "libsigrok-internal.h" 24 | 25 | #ifndef HAVE_SERIAL_COMM 26 | 27 | SR_API GSList *sr_serial_list(const struct sr_dev_driver *driver) 28 | { 29 | (void)driver; 30 | 31 | return NULL; 32 | } 33 | 34 | SR_API void sr_serial_free(struct sr_serial_port *serial) 35 | { 36 | (void)serial; 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/crc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2015 Aurelien Jacobs 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "libsigrok-internal.h" 24 | 25 | SR_PRIV uint16_t sr_crc16(uint16_t crc, const uint8_t *buffer, int len) 26 | { 27 | int i; 28 | 29 | if (!buffer || len < 0) 30 | return crc; 31 | 32 | while (len--) { 33 | crc ^= *buffer++; 34 | for (i = 0; i < 8; i++) { 35 | int carry = crc & 1; 36 | crc >>= 1; 37 | if (carry) 38 | crc ^= 0xA001; 39 | } 40 | } 41 | 42 | return crc; 43 | } 44 | -------------------------------------------------------------------------------- /contrib/61-libsigrok-plugdev.rules: -------------------------------------------------------------------------------- 1 | ## 2 | ## This file is part of the libsigrok project. 3 | ## 4 | ## Copyright (C) 2017 Stefan Bruens 5 | ## 6 | ## This program is free software; you can redistribute it and/or modify 7 | ## it under the terms of the GNU General Public License as published by 8 | ## the Free Software Foundation; either version 2 of the License, or 9 | ## (at your option) any later version. 10 | ## 11 | ## This program is distributed in the hope that it will be useful, 12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ## GNU General Public License for more details. 15 | ## 16 | ## You should have received a copy of the GNU General Public License 17 | ## along with this program; if not, see . 18 | ## 19 | 20 | # Grant access permissions to users who are in the "plugdev" group. 21 | # "plugdev" is typically used on Debian based distributions and may not 22 | # exist elsewhere. 23 | # 24 | # This file, when installed, must be installed with a name lexicographically 25 | # sorted later than the accompanied 60-libsigrok.rules 26 | 27 | ACTION!="add|change", GOTO="libsigrok_rules_plugdev_end" 28 | 29 | ENV{ID_SIGROK}=="1", MODE="660", GROUP="plugdev" 30 | 31 | LABEL="libsigrok_rules_plugdev_end" 32 | -------------------------------------------------------------------------------- /src/hardware/tondaj-sl-814/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2012 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_TONDAJ_SL_814_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_TONDAJ_SL_814_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include "libsigrok-internal.h" 26 | 27 | #define LOG_PREFIX "tondaj-sl-814" 28 | 29 | struct dev_context { 30 | struct sr_sw_limits limits; 31 | int state; 32 | 33 | uint8_t buf[4]; 34 | uint8_t buflen; 35 | }; 36 | 37 | SR_PRIV int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/hardware/conrad-digi-35-cpu/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2014 Matthias Heidbrink 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_CONRAD_DIGI_35_CPU_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_CONRAD_DIGI_35_CPU_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "libsigrok-internal.h" 28 | 29 | #define LOG_PREFIX "conrad-digi-35-cpu" 30 | 31 | struct dev_context { 32 | struct sr_sw_limits limits; 33 | }; 34 | 35 | SR_PRIV int send_msg1(const struct sr_dev_inst *sdi, char cmd, int param); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/driver_list_stop.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2017 Marcus Comstedt 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "libsigrok-internal.h" 24 | 25 | /* 26 | * This marks the end of the driver list. This file must be linked 27 | * after any actual drivers. 28 | */ 29 | 30 | SR_PRIV const struct sr_dev_driver *sr_driver_list__stop[] 31 | SR_DRIVER_LIST_NOREORDER 32 | __attribute__((section (SR_DRIVER_LIST_SECTION), 33 | used, aligned(sizeof(struct sr_dev_driver *)))) 34 | = { NULL /* Dummy item, as zero length arrays are not allowed by C99 */ }; 35 | -------------------------------------------------------------------------------- /src/driver_list_start.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2017 Marcus Comstedt 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "libsigrok-internal.h" 24 | 25 | /* 26 | * This marks the start of the driver list. This file must be linked 27 | * before any actual drivers. 28 | */ 29 | 30 | SR_PRIV const struct sr_dev_driver *sr_driver_list__start[] 31 | SR_DRIVER_LIST_NOREORDER 32 | __attribute__((section (SR_DRIVER_LIST_SECTION), 33 | used, aligned(sizeof(struct sr_dev_driver *)))) 34 | = { NULL /* Dummy item, as zero length arrays are not allowed by C99 */ }; 35 | -------------------------------------------------------------------------------- /src/hardware/colead-slm/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2012 Bert Vermeulen 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_COLEAD_SLM_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_COLEAD_SLM_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include "libsigrok-internal.h" 26 | 27 | #define LOG_PREFIX "colead-slm" 28 | 29 | enum { 30 | IDLE, 31 | COMMAND_SENT, 32 | }; 33 | 34 | struct dev_context { 35 | struct sr_sw_limits limits; 36 | 37 | int state; 38 | char buf[10]; 39 | int buflen; 40 | }; 41 | 42 | SR_PRIV int colead_slm_receive_data(int fd, int revents, void *cb_data); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /contrib/61-libsigrok-uaccess.rules: -------------------------------------------------------------------------------- 1 | ## 2 | ## This file is part of the libsigrok project. 3 | ## 4 | ## Copyright (C) 2017 Stefan Bruens 5 | ## 6 | ## This program is free software; you can redistribute it and/or modify 7 | ## it under the terms of the GNU General Public License as published by 8 | ## the Free Software Foundation; either version 2 of the License, or 9 | ## (at your option) any later version. 10 | ## 11 | ## This program is distributed in the hope that it will be useful, 12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ## GNU General Public License for more details. 15 | ## 16 | ## You should have received a copy of the GNU General Public License 17 | ## along with this program; if not, see . 18 | ## 19 | 20 | # Grant access permissions to users who are currently logged in locally. 21 | # This is the default policy for systems using systemd-logind (or a 22 | # compatible replacement). 23 | # 24 | # This file, when installed, must be installed with a name lexicographically 25 | # sorted later than the accompanied 60-libsigrok.rules, and earlier than 26 | # the systemd upstream 71-seat.rules. 27 | 28 | ACTION!="add|change", GOTO="libsigrok_rules_uaccess_end" 29 | 30 | ENV{ID_SIGROK}=="1", TAG+="uaccess" 31 | 32 | LABEL="libsigrok_rules_uaccess_end" 33 | -------------------------------------------------------------------------------- /src/output/null.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2018 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "libsigrok-internal.h" 24 | 25 | #define LOG_PREFIX "output/null" 26 | 27 | static int receive(const struct sr_output *o, const struct sr_datafeed_packet *packet, 28 | GString **out) 29 | { 30 | (void)o; 31 | (void)packet; 32 | 33 | *out = NULL; 34 | 35 | return SR_OK; 36 | } 37 | 38 | SR_PRIV struct sr_output_module output_null = { 39 | .id = "null", 40 | .name = "Null output", 41 | .desc = "Null output (discards all data)", 42 | .exts = NULL, 43 | .flags = 0, 44 | .options = NULL, 45 | .receive = receive, 46 | }; 47 | -------------------------------------------------------------------------------- /src/hardware/hp-59306a/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2021 Frank Stettner 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_HP_59306A_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_HP_59306A_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | 28 | #define LOG_PREFIX "hp-59306a" 29 | 30 | struct dev_context { 31 | size_t channel_count; 32 | }; 33 | 34 | struct channel_group_context { 35 | /** The number of the channel group, as labled on the device. */ 36 | size_t number; 37 | }; 38 | 39 | SR_PRIV int hp_59306a_switch_cg(const struct sr_dev_inst *sdi, 40 | const struct sr_channel_group *cg, gboolean enabled); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /tests/input_all.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2013-2014 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "lib.h" 25 | 26 | /* Check whether at least one input module is available. */ 27 | START_TEST(test_input_available) 28 | { 29 | const struct sr_input_module **inputs; 30 | 31 | inputs = sr_input_list(); 32 | fail_unless(inputs != NULL, "No input modules found."); 33 | } 34 | END_TEST 35 | 36 | Suite *suite_input_all(void) 37 | { 38 | Suite *s; 39 | TCase *tc; 40 | 41 | s = suite_create("input-all"); 42 | 43 | tc = tcase_create("basic"); 44 | tcase_add_test(tc, test_input_available); 45 | suite_add_tcase(s, tc); 46 | 47 | return s; 48 | } 49 | -------------------------------------------------------------------------------- /src/hardware/hp-59306a/protocol.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2021 Frank Stettner 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include "scpi.h" 22 | #include "protocol.h" 23 | 24 | SR_PRIV int hp_59306a_switch_cg(const struct sr_dev_inst *sdi, 25 | const struct sr_channel_group *cg, gboolean enabled) 26 | { 27 | char *cmd; 28 | struct channel_group_context *cgc; 29 | struct sr_scpi_dev_inst *scpi; 30 | int ret; 31 | 32 | if (!cg) { 33 | if (enabled) 34 | cmd = g_strdup("A123456"); 35 | else 36 | cmd = g_strdup("B123456"); 37 | } else { 38 | cgc = cg->priv; 39 | if (enabled) 40 | cmd = g_strdup_printf("A%zu", cgc->number); 41 | else 42 | cmd = g_strdup_printf("B%zu", cgc->number); 43 | } 44 | 45 | scpi = sdi->conn; 46 | ret = sr_scpi_send(scpi, cmd); 47 | g_free(cmd); 48 | 49 | return ret; 50 | } 51 | -------------------------------------------------------------------------------- /src/input/null.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2018 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include "libsigrok-internal.h" 23 | 24 | #define LOG_PREFIX "input/null" 25 | 26 | static int init(struct sr_input *in, GHashTable *options) 27 | { 28 | (void)in; 29 | (void)options; 30 | 31 | return SR_OK; 32 | } 33 | 34 | static int receive(struct sr_input *in, GString *buf) 35 | { 36 | (void)in; 37 | (void)buf; 38 | 39 | return SR_OK; 40 | } 41 | 42 | static int end(struct sr_input *in) 43 | { 44 | (void)in; 45 | 46 | return SR_OK; 47 | } 48 | 49 | SR_PRIV struct sr_input_module input_null = { 50 | .id = "null", 51 | .name = "Null", 52 | .desc = "Null input (discards all input)", 53 | .exts = NULL, 54 | .options = NULL, 55 | .init = init, 56 | .receive = receive, 57 | .end = end, 58 | .reset = NULL, 59 | }; 60 | -------------------------------------------------------------------------------- /src/hardware/baylibre-acme/gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2015 Bartosz Golaszewski 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /* 21 | * Linux-specific GPIO interface helpers. These functions could be moved out 22 | * of this directory if any other driver would happen to want to use them. 23 | */ 24 | 25 | #ifndef LIBSIGROK_HARDWARE_BAYLIBRE_ACME_GPIO_H 26 | #define LIBSIGROK_HARDWARE_BAYLIBRE_ACME_GPIO_H 27 | 28 | enum { 29 | GPIO_DIR_IN, 30 | GPIO_DIR_OUT, 31 | }; 32 | 33 | SR_PRIV int sr_gpio_export(unsigned gpio); 34 | SR_PRIV int sr_gpio_set_direction(unsigned gpio, unsigned direction); 35 | SR_PRIV int sr_gpio_set_value(unsigned gpio, unsigned value); 36 | SR_PRIV int sr_gpio_get_value(int gpio); 37 | /* These functions export given GPIO if it's not already exported. */ 38 | SR_PRIV int sr_gpio_setval_export(int gpio, int value); 39 | SR_PRIV int sr_gpio_getval_export(int gpio); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/transform/nop.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2015 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "libsigrok-internal.h" 24 | 25 | #define LOG_PREFIX "transform/nop" 26 | 27 | static int receive(const struct sr_transform *t, 28 | struct sr_datafeed_packet *packet_in, 29 | struct sr_datafeed_packet **packet_out) 30 | { 31 | if (!t || !t->sdi || !packet_in || !packet_out) 32 | return SR_ERR_ARG; 33 | 34 | /* Do nothing, just pass on packets unmodified. */ 35 | sr_spew("Received packet of type %d, passing on unmodified.", packet_in->type); 36 | *packet_out = packet_in; 37 | 38 | return SR_OK; 39 | } 40 | 41 | SR_PRIV struct sr_transform_module transform_nop = { 42 | .id = "nop", 43 | .name = "NOP", 44 | .desc = "Do nothing", 45 | .options = NULL, 46 | .init = NULL, 47 | .receive = receive, 48 | .cleanup = NULL, 49 | }; 50 | -------------------------------------------------------------------------------- /src/output/binary.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2010 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include "libsigrok-internal.h" 26 | 27 | #define LOG_PREFIX "output/binary" 28 | 29 | static int receive(const struct sr_output *o, const struct sr_datafeed_packet *packet, 30 | GString **out) 31 | { 32 | const struct sr_datafeed_logic *logic; 33 | 34 | (void)o; 35 | 36 | *out = NULL; 37 | if (packet->type != SR_DF_LOGIC) 38 | return SR_OK; 39 | logic = packet->payload; 40 | *out = g_string_new_len(logic->data, logic->length); 41 | 42 | return SR_OK; 43 | } 44 | 45 | SR_PRIV struct sr_output_module output_binary = { 46 | .id = "binary", 47 | .name = "Binary", 48 | .desc = "Raw binary logic data", 49 | .exts = NULL, 50 | .flags = 0, 51 | .options = NULL, 52 | .receive = receive, 53 | }; 54 | -------------------------------------------------------------------------------- /src/hardware/uni-t-ut32x/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2013 Bert Vermeulen 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_UNI_T_UT32X_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_UNI_T_UT32X_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | 28 | #define LOG_PREFIX "uni-t-ut32x" 29 | 30 | #define DEFAULT_DATA_SOURCE DATA_SOURCE_LIVE 31 | 32 | #define PACKET_SIZE 19 33 | 34 | enum ut32x_data_source { 35 | DATA_SOURCE_LIVE, 36 | DATA_SOURCE_MEMORY, 37 | }; 38 | 39 | enum ut32x_cmd_code { 40 | CMD_GET_LIVE = 1, 41 | CMD_STOP = 2, 42 | CMD_GET_STORED = 7, 43 | }; 44 | 45 | struct dev_context { 46 | struct sr_sw_limits limits; 47 | enum ut32x_data_source data_source; 48 | uint8_t packet[PACKET_SIZE]; 49 | size_t packet_len; 50 | }; 51 | 52 | SR_PRIV int ut32x_handle_events(int fd, int revents, void *cb_data); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/hardware/teleinfo/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2013 Aurelien Jacobs 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_TELEINFO_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_TELEINFO_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | 28 | #define LOG_PREFIX "teleinfo" 29 | 30 | enum optarif { 31 | OPTARIF_NONE, 32 | OPTARIF_BASE, 33 | OPTARIF_HC, 34 | OPTARIF_EJP, 35 | OPTARIF_BBR, 36 | }; 37 | 38 | #define TELEINFO_BUF_SIZE 256 39 | 40 | struct dev_context { 41 | struct sr_sw_limits sw_limits; 42 | enum optarif optarif; /**< The device mode (which measures are reported) */ 43 | uint8_t buf[TELEINFO_BUF_SIZE]; 44 | int buf_len; 45 | }; 46 | 47 | SR_PRIV gboolean teleinfo_packet_valid(const uint8_t *buf); 48 | SR_PRIV int teleinfo_receive_data(int fd, int revents, void *cb_data); 49 | SR_PRIV int teleinfo_get_optarif(const uint8_t *buf); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/hardware/ftdi-la/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2015 Sergey Alirzaev 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_FTID_LA_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_FTID_LA_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | 28 | #define LOG_PREFIX "ftdi-la" 29 | 30 | #define DATA_BUF_SIZE (16 * 1024) 31 | 32 | struct ftdi_chip_desc { 33 | uint16_t vendor; 34 | uint16_t product; 35 | int samplerate_div; 36 | char *channel_names[]; 37 | }; 38 | 39 | struct dev_context { 40 | struct ftdi_context *ftdic; 41 | const struct ftdi_chip_desc *desc; 42 | 43 | uint64_t limit_samples; 44 | uint32_t cur_samplerate; 45 | 46 | unsigned char *data_buf; 47 | uint64_t samples_sent; 48 | uint64_t bytes_received; 49 | }; 50 | 51 | SR_PRIV int ftdi_la_set_samplerate(struct dev_context *devc); 52 | SR_PRIV int ftdi_la_receive_data(int fd, int revents, void *cb_data); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/hardware/appa-55ii/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2013 Aurelien Jacobs 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_APPA_55II_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_APPA_55II_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | 28 | #define LOG_PREFIX "appa-55ii" 29 | 30 | #define APPA_55II_NUM_CHANNELS 2 31 | #define APPA_55II_BUF_SIZE (4 + 32 + 1) 32 | #define DEFAULT_DATA_SOURCE DATA_SOURCE_LIVE 33 | 34 | enum { 35 | DATA_SOURCE_LIVE, 36 | DATA_SOURCE_MEMORY, 37 | }; 38 | 39 | struct dev_context { 40 | struct sr_sw_limits limits; 41 | gboolean data_source; /**< Whether to read live samples or memory */ 42 | 43 | uint8_t buf[APPA_55II_BUF_SIZE]; 44 | unsigned int buf_len; 45 | uint8_t log_buf[64]; 46 | unsigned int log_buf_len; 47 | unsigned int num_log_records; 48 | }; 49 | 50 | SR_PRIV gboolean appa_55ii_packet_valid(const uint8_t *buf); 51 | SR_PRIV int appa_55ii_receive_data(int fd, int revents, void *cb_data); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/hardware/kern-scale/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2015 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_KERN_SCALE_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_KERN_SCALE_PROTOCOL_H 22 | 23 | #define LOG_PREFIX "kern-scale" 24 | 25 | struct scale_info { 26 | /** libsigrok driver info struct. */ 27 | struct sr_dev_driver di; 28 | /** Manufacturer/brand. */ 29 | const char *vendor; 30 | /** Model. */ 31 | const char *device; 32 | /** serialconn string. */ 33 | const char *conn; 34 | /** Packet size in bytes. */ 35 | int packet_size; 36 | /** Packet validation function. */ 37 | gboolean (*packet_valid)(const uint8_t *); 38 | /** Packet parsing function. */ 39 | int (*packet_parse)(const uint8_t *, float *, 40 | struct sr_datafeed_analog *, void *); 41 | /** Size of chipset info struct. */ 42 | gsize info_size; 43 | }; 44 | 45 | #define SCALE_BUFSIZE 256 46 | 47 | struct dev_context { 48 | struct sr_sw_limits limits; 49 | 50 | uint8_t buf[SCALE_BUFSIZE]; 51 | int bufoffset; 52 | int buflen; 53 | }; 54 | 55 | SR_PRIV int kern_scale_receive_data(int fd, int revents, void *cb_data); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/hardware/mastech-ms6514/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2019 Dave Buechi 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_MASTECH_MS6514_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_MASTECH_MS6514_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | 28 | #define LOG_PREFIX "mastech-ms6514" 29 | 30 | #define MASTECH_MS6514_NUM_CHANNELS 2 31 | #define MASTECH_MS6514_BUF_SIZE (3 * 18) 32 | #define MASTECH_MS6514_FRAME_SIZE 18 33 | #define DEFAULT_DATA_SOURCE DATA_SOURCE_LIVE 34 | 35 | enum mastech_ms6614_data_source { 36 | DATA_SOURCE_LIVE, 37 | DATA_SOURCE_MEMORY, 38 | }; 39 | 40 | enum mastech_ms6614_command { 41 | CMD_GET_STORED = 0xA1 42 | }; 43 | 44 | struct dev_context { 45 | struct sr_sw_limits limits; 46 | enum mastech_ms6614_data_source data_source; 47 | unsigned int buf_len; 48 | uint8_t buf[MASTECH_MS6514_BUF_SIZE]; 49 | unsigned int log_buf_len; 50 | }; 51 | 52 | SR_PRIV int mastech_ms6514_receive_data(int fd, int revents, void *cb_data); 53 | SR_PRIV gboolean mastech_ms6514_packet_valid(const uint8_t *buf); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/hardware/uni-t-dmm/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2012-2013 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_UNI_T_DMM_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_UNI_T_DMM_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "libsigrok-internal.h" 28 | 29 | #define LOG_PREFIX "uni-t-dmm" 30 | 31 | struct dmm_info { 32 | struct sr_dev_driver di; 33 | const char *vendor; 34 | const char *device; 35 | uint32_t baudrate; 36 | int packet_size; 37 | gboolean (*packet_valid)(const uint8_t *); 38 | int (*packet_parse)(const uint8_t *, float *, 39 | struct sr_datafeed_analog *, void *); 40 | void (*dmm_details)(struct sr_datafeed_analog *, void *); 41 | gsize info_size; 42 | }; 43 | 44 | #define CHUNK_SIZE 8 45 | 46 | #define DMM_BUFSIZE 256 47 | 48 | struct dev_context { 49 | struct sr_sw_limits limits; 50 | 51 | gboolean first_run; 52 | 53 | uint8_t protocol_buf[DMM_BUFSIZE]; 54 | uint8_t bufoffset; 55 | uint8_t buflen; 56 | }; 57 | 58 | SR_PRIV int uni_t_dmm_receive_data(int fd, int revents, void *cb_data); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/hardware/rohde-schwarz-sme-0x/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2016 Vlad Ivanov 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_ROHDE_SCHWARZ_SME_0X_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_ROHDE_SCHWARZ_SME_0X_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | 28 | #define LOG_PREFIX "rohde-schwarz-sme-0x" 29 | 30 | struct rs_sme0x_info { 31 | struct sr_dev_driver di; 32 | char *vendor; 33 | char *device; 34 | }; 35 | 36 | struct rs_device_model { 37 | const char *model_str; 38 | double freq_max; 39 | double freq_min; 40 | double power_max; 41 | double power_min; 42 | }; 43 | 44 | struct dev_context { 45 | const struct rs_device_model *model_config; 46 | }; 47 | 48 | SR_PRIV int rs_sme0x_mode_remote(struct sr_scpi_dev_inst *scpi); 49 | SR_PRIV int rs_sme0x_get_freq(const struct sr_dev_inst *sdi, double *freq); 50 | SR_PRIV int rs_sme0x_get_power(const struct sr_dev_inst *sdi, double *power); 51 | SR_PRIV int rs_sme0x_set_freq(const struct sr_dev_inst *sdi, double freq); 52 | SR_PRIV int rs_sme0x_set_power(const struct sr_dev_inst *sdi, double power); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/hardware/conrad-digi-35-cpu/protocol.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2014 Matthias Heidbrink 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include "protocol.h" 22 | 23 | /** 24 | * Send command with parameter. 25 | * 26 | * @param[in] cmd Command 27 | * @param[in] param Parameter (0..999, depending on command). 28 | * 29 | * @retval SR_OK Success. 30 | * @retval SR_ERR_ARG Invalid argument. 31 | * @retval SR_ERR Error. 32 | */ 33 | SR_PRIV int send_msg1(const struct sr_dev_inst *sdi, char cmd, int param) 34 | { 35 | struct sr_serial_dev_inst *serial; 36 | char buf[5]; 37 | 38 | if (!sdi || !(serial = sdi->conn)) 39 | return SR_ERR_ARG; 40 | 41 | snprintf(buf, sizeof(buf), "%c%03d", cmd, param); 42 | buf[4] = '\r'; 43 | 44 | sr_spew("send_msg1(): %c%c%c%c\\r", buf[0], buf[1], buf[2], buf[3]); 45 | 46 | if (serial_write_blocking(serial, buf, sizeof(buf), 47 | serial_timeout(serial, sizeof(buf))) < (int)sizeof(buf)) { 48 | sr_err("Write error for cmd=%c", cmd); 49 | return SR_ERR; 50 | } 51 | 52 | /* 53 | * Wait 50ms to ensure that the device does not swallow any of the 54 | * following commands. 55 | */ 56 | g_usleep(50 * 1000); 57 | 58 | return SR_OK; 59 | } 60 | -------------------------------------------------------------------------------- /src/hardware/bkprecision-1856d/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2021 LUMERIIX 5 | * Copyright (C) 2024 Daniel Anselmi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program 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 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef LIBSIGROK_HARDWARE_BKPRECISION_1856D_PROTOCOL_H 22 | #define LIBSIGROK_HARDWARE_BKPRECISION_1856D_PROTOCOL_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include "libsigrok-internal.h" 28 | 29 | #define LOG_PREFIX "bkprecision-1856d" 30 | #define BKPRECISION1856D_MSG_SIZE 15 31 | #define BKPRECISION1856D_MSG_NUMBER_SIZE 10 32 | 33 | 34 | enum { 35 | InputA = 0, 36 | InputC = 1, 37 | }; 38 | 39 | struct dev_context { 40 | struct sr_sw_limits sw_limits; 41 | unsigned int sel_input; 42 | unsigned int curr_sel_input; 43 | unsigned int gate_time; 44 | 45 | char buffer[BKPRECISION1856D_MSG_SIZE]; 46 | unsigned int buffer_level; 47 | }; 48 | 49 | SR_PRIV int bkprecision_1856d_receive_data(int fd, int revents, void *cb_data); 50 | SR_PRIV void bkprecision_1856d_init(const struct sr_dev_inst *sdi); 51 | SR_PRIV void bkprecision_1856d_set_gate_time(struct dev_context *devc, 52 | int time); 53 | SR_PRIV void bkprecision_1856d_select_input(struct dev_context *devc, 54 | int intput); 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/hardware/ikalogic-scanaplus/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2013 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_IKALOGIC_SCANAPLUS_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_IKALOGIC_SCANAPLUS_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "libsigrok-internal.h" 29 | 30 | #define LOG_PREFIX "ikalogic-scanaplus" 31 | 32 | #define COMPRESSED_BUF_SIZE (64 * 1024) 33 | 34 | struct dev_context { 35 | struct ftdi_context *ftdic; 36 | uint64_t limit_msec; 37 | uint64_t limit_samples; 38 | 39 | uint8_t *compressed_buf; 40 | uint64_t compressed_bytes_ignored; 41 | uint8_t *sample_buf; 42 | uint64_t bytes_received; 43 | uint64_t samples_sent; 44 | 45 | /** ScanaPLUS unique device ID (3 bytes). */ 46 | uint8_t devid[3]; 47 | }; 48 | 49 | SR_PRIV int scanaplus_close(struct dev_context *devc); 50 | SR_PRIV int scanaplus_get_device_id(struct dev_context *devc); 51 | SR_PRIV int scanaplus_init(struct dev_context *devc); 52 | SR_PRIV int scanaplus_start_acquisition(struct dev_context *devc); 53 | SR_PRIV int scanaplus_receive_data(int fd, int revents, void *cb_data); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/hardware/icstation-usbrelay/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2021-2023 Frank Stettner 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_ICSTATION_USBRELAY_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_ICSTATION_USBRELAY_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "libsigrok-internal.h" 28 | 29 | #define LOG_PREFIX "icstation-usbrelay" 30 | 31 | /* Known models. */ 32 | enum icstation_model { 33 | ICSE012A = 1, 34 | ICSE013A, 35 | ICSE014A, 36 | }; 37 | 38 | /* Supported device profiles */ 39 | struct ics_usbrelay_profile { 40 | enum icstation_model model; 41 | uint8_t id; 42 | const char *modelname; 43 | size_t nb_channels; 44 | }; 45 | 46 | struct dev_context { 47 | size_t relay_count; 48 | uint8_t relay_mask; 49 | uint8_t relay_state; 50 | }; 51 | 52 | struct channel_group_context { 53 | size_t index; 54 | }; 55 | 56 | SR_PRIV int icstation_usbrelay_identify(struct sr_serial_dev_inst *serial, 57 | uint8_t *id); 58 | SR_PRIV int icstation_usbrelay_start(const struct sr_dev_inst *sdi); 59 | SR_PRIV int icstation_usbrelay_switch_cg(const struct sr_dev_inst *sdi, 60 | const struct sr_channel_group *cg, gboolean on); 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /tests/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2013 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "lib.h" 25 | 26 | int main(void) 27 | { 28 | int ret; 29 | Suite *s; 30 | SRunner *srunner; 31 | 32 | s = suite_create("mastersuite"); 33 | srunner = srunner_create(s); 34 | 35 | /* Add all testsuites to the master suite. */ 36 | srunner_add_suite(srunner, suite_core()); 37 | srunner_add_suite(srunner, suite_driver_all()); 38 | srunner_add_suite(srunner, suite_input_all()); 39 | srunner_add_suite(srunner, suite_input_binary()); 40 | srunner_add_suite(srunner, suite_output_all()); 41 | srunner_add_suite(srunner, suite_transform_all()); 42 | srunner_add_suite(srunner, suite_session()); 43 | srunner_add_suite(srunner, suite_strutil()); 44 | srunner_add_suite(srunner, suite_version()); 45 | srunner_add_suite(srunner, suite_device()); 46 | srunner_add_suite(srunner, suite_trigger()); 47 | srunner_add_suite(srunner, suite_analog()); 48 | srunner_add_suite(srunner, suite_conv()); 49 | 50 | srunner_run_all(srunner, CK_VERBOSE); 51 | ret = srunner_ntests_failed(srunner); 52 | srunner_free(srunner); 53 | 54 | return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 55 | } 56 | -------------------------------------------------------------------------------- /src/hardware/asix-omega-rtm-cli/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2021 Gerhard Sittig 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_ASIX_OMEGA_RTM_CLI_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_ASIX_OMEGA_RTM_CLI_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "libsigrok-internal.h" 28 | 29 | #define LOG_PREFIX "asix-omega-rtm-cli" 30 | 31 | #define RTMCLI_STDOUT_CHUNKSIZE (1024 * 1024) 32 | #define FEED_QUEUE_DEPTH (256 * 1024) 33 | 34 | struct dev_context { 35 | char **channel_names; 36 | struct sr_sw_limits limits; 37 | struct { 38 | gchar **argv; 39 | GSpawnFlags flags; 40 | gboolean running; 41 | GPid pid; 42 | gint fd_stdin_write; 43 | gint fd_stdout_read; 44 | } child; 45 | struct { 46 | uint8_t buff[RTMCLI_STDOUT_CHUNKSIZE]; 47 | size_t fill; 48 | } rawdata; 49 | struct { 50 | struct feed_queue_logic *queue; 51 | uint8_t last_sample[sizeof(uint16_t)]; 52 | uint64_t remain_count; 53 | gboolean check_count; 54 | } samples; 55 | }; 56 | 57 | SR_PRIV int omega_rtm_cli_open(const struct sr_dev_inst *sdi); 58 | SR_PRIV int omega_rtm_cli_close(const struct sr_dev_inst *sdi); 59 | SR_PRIV int omega_rtm_cli_receive_data(int fd, int revents, void *cb_data); 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /src/hardware/center-3xx/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2013 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_CENTER_3XX_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_CENTER_3XX_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "libsigrok-internal.h" 30 | 31 | #define LOG_PREFIX "center-3xx" 32 | 33 | enum { 34 | CENTER_309, 35 | VOLTCRAFT_K204, 36 | }; 37 | 38 | struct center_dev_info { 39 | const char *vendor; 40 | const char *device; 41 | const char *conn; 42 | int num_channels; 43 | uint32_t max_sample_points; 44 | uint8_t packet_size; 45 | gboolean (*packet_valid)(const uint8_t *); 46 | struct sr_dev_driver *di; 47 | int (*receive_data)(int, int, void *); 48 | }; 49 | 50 | extern SR_PRIV const struct center_dev_info center_devs[]; 51 | 52 | #define SERIAL_BUFSIZE 256 53 | 54 | struct dev_context { 55 | struct sr_sw_limits sw_limits; 56 | 57 | uint8_t buf[SERIAL_BUFSIZE]; 58 | int bufoffset; 59 | int buflen; 60 | }; 61 | 62 | SR_PRIV gboolean center_3xx_packet_valid(const uint8_t *buf); 63 | 64 | SR_PRIV int receive_data_CENTER_309(int fd, int revents, void *cb_data); 65 | SR_PRIV int receive_data_VOLTCRAFT_K204(int fd, int revents, void *cb_data); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /src/hardware/zeroplus-logic-cube/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2013 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_ZEROPLUS_LOGIC_CUBE_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_ZEROPLUS_LOGIC_CUBE_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "libsigrok-internal.h" 29 | 30 | #define LOG_PREFIX "zeroplus-logic-cube" 31 | 32 | typedef enum { 33 | LAPC_CLOCK_EDGE_RISING, 34 | LAPC_CLOCK_EDGE_FALLING, 35 | } ext_clock_edge_t; 36 | 37 | struct zp_model; 38 | struct dev_context { 39 | uint64_t cur_samplerate; 40 | uint64_t max_samplerate; 41 | uint64_t limit_samples; 42 | size_t num_channels; 43 | size_t memory_size; 44 | size_t max_sample_depth; 45 | int trigger; 46 | uint64_t capture_ratio; 47 | double cur_threshold; 48 | const struct zp_model *prof; 49 | gboolean use_ext_clock; 50 | ext_clock_edge_t ext_clock_edge; 51 | }; 52 | 53 | SR_PRIV size_t get_memory_size(int type); 54 | SR_PRIV int zp_set_samplerate(struct dev_context *devc, uint64_t samplerate); 55 | SR_PRIV int set_limit_samples(struct dev_context *devc, uint64_t samples); 56 | SR_PRIV int set_voltage_threshold(struct dev_context *devc, double thresh); 57 | SR_PRIV void set_triggerbar(struct dev_context *devc); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # autotools cruft 2 | /INSTALL 3 | /Makefile.in 4 | /aclocal.m4 5 | /autom4te.cache/ 6 | /autostuff/ 7 | /configure 8 | /configure.lineno 9 | /m4/libtool.m4 10 | /m4/lt*.m4 11 | 12 | # Editor/IDE cruft 13 | *.kate-swp 14 | *~ 15 | .*.sw* 16 | /*.kdev4 17 | /Makefile.am.user 18 | 19 | # clangd language server cruft 20 | .cache/ 21 | /compile_commands.json 22 | 23 | # Configure/build cruft 24 | *.[ao] 25 | *.l[ao] 26 | .deps/ 27 | .dirstamp 28 | .libs/ 29 | /Makefile 30 | /config.* 31 | /doxy/ 32 | /include/libsigrok/version.h 33 | /include/libsigrok/git-version.h 34 | /libsigrok-*.tar.* 35 | /libsigrok.pc 36 | /libtool 37 | stamp-h? 38 | 39 | # Files generated by building C++ bindings 40 | /bindings/cxx/doxy/ 41 | /bindings/cxx/enums.cpp 42 | /bindings/cxx/enums.timestamp 43 | /bindings/cxx/include/libsigrokcxx/enums.hpp 44 | /bindings/cxx/libsigrokcxx.pc 45 | /bindings/swig/enums.i 46 | 47 | # Files generated by building Python bindings 48 | *.pyc 49 | /bindings/python/build/ 50 | /bindings/python/dist/ 51 | /bindings/python/doxy/ 52 | /bindings/python/libsigrok.egg-info/ 53 | /bindings/python/libsigrok.py 54 | /bindings/python/libsigrok_python_wrap.c 55 | /bindings/python/sigrok/__pycache__/ 56 | /bindings/python/sigrok/core/classes.py 57 | /bindings/python/sigrok/core/classes_wrap.cpp 58 | /bindings/python/sigrok/core/doc_start.i 59 | /bindings/python/sigrok/core/doc_end.i 60 | /bindings/python/sigrok/core/lowlevel.py 61 | /bindings/python/sigrok/core/lowlevel_wrap.c 62 | /bindings/python/timestamp 63 | 64 | # Files generated by building Ruby bindings 65 | /bindings/ruby/classes_wrap.cpp 66 | /bindings/ruby/doc.i 67 | /bindings/ruby/sigrok.so 68 | 69 | # Files generated by building Java bindings 70 | *.class 71 | /bindings/java/libsigrok_java_core_classes.so 72 | /bindings/java/org/sigrok/core/classes/*.java 73 | /bindings/java/org/sigrok/core/classes/classes_wrap.cxx 74 | /bindings/java/org/sigrok/core/classes/doc.i 75 | /bindings/java/sigrok-core.jar 76 | /bindings/java/doxy/ 77 | 78 | # Files generated by the testsuite 79 | /test-suite.log 80 | /tests/*.log 81 | /tests/*.trs 82 | /tests/main 83 | -------------------------------------------------------------------------------- /src/hardware/atorch/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2023 Mathieu Pilato 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_ATORCH_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_ATORCH_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "libsigrok-internal.h" 28 | 29 | #define LOG_PREFIX "atorch" 30 | 31 | #define ATORCH_BUFSIZE 128 32 | 33 | struct atorch_device_profile { 34 | uint8_t device_type; 35 | const char *device_name; 36 | const struct atorch_channel_desc *channels; 37 | size_t channel_count; 38 | }; 39 | 40 | struct atorch_channel_desc { 41 | const char *name; 42 | struct binary_value_spec spec; 43 | struct sr_rational scale; 44 | int digits; 45 | enum sr_mq mq; 46 | enum sr_unit unit; 47 | enum sr_mqflag flags; 48 | }; 49 | 50 | enum atorch_msg_type { 51 | MSG_REPORT = 0x01, 52 | MSG_REPLY = 0x02, 53 | MSG_COMMAND = 0x11, 54 | }; 55 | 56 | struct dev_context { 57 | const struct atorch_device_profile *profile; 58 | struct sr_sw_limits limits; 59 | struct feed_queue_analog **feeds; 60 | uint8_t buf[ATORCH_BUFSIZE]; 61 | size_t wr_idx; 62 | size_t rd_idx; 63 | }; 64 | 65 | SR_PRIV int atorch_probe(struct sr_serial_dev_inst *serial, struct dev_context *devc); 66 | SR_PRIV int atorch_receive_data_callback(int fd, int revents, void *cb_data); 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /src/serial_hid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2017-2019 Gerhard Sittig 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_SERIAL_HID_H 21 | #define LIBSIGROK_SERIAL_HID_H 22 | 23 | /* The prefix for port names which are HID based. */ 24 | #define SER_HID_CONN_PREFIX "hid" 25 | #define SER_HID_USB_PREFIX "usb=" 26 | #define SER_HID_RAW_PREFIX "raw=" 27 | #define SER_HID_IOKIT_PREFIX "iokit=" 28 | #define SER_HID_SNR_PREFIX "sn=" 29 | 30 | /* 31 | * The maximum number of bytes any supported HID chip can communicate 32 | * within a single request. 33 | * 34 | * Brymen BU-86X: up to 8 bytes 35 | * SiLabs CP2110: up to 63 bytes 36 | * Victor DMM: up to 14 bytes 37 | * WCH CH9325: up to 7 bytes 38 | */ 39 | #define SER_HID_CHUNK_SIZE 64 40 | 41 | /* 42 | * Routines to get/set reports/data, provided by serial_hid.c and used 43 | * in serial_hid_.c files. 44 | */ 45 | SR_PRIV int ser_hid_hidapi_get_report(struct sr_serial_dev_inst *serial, 46 | uint8_t *data, size_t len); 47 | SR_PRIV int ser_hid_hidapi_set_report(struct sr_serial_dev_inst *serial, 48 | const uint8_t *data, size_t len); 49 | SR_PRIV int ser_hid_hidapi_get_data(struct sr_serial_dev_inst *serial, 50 | uint8_t ep, uint8_t *data, size_t len, int timeout); 51 | SR_PRIV int ser_hid_hidapi_set_data(struct sr_serial_dev_inst *serial, 52 | uint8_t ep, const uint8_t *data, size_t len, int timeout); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/hardware/dcttech-usbrelay/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2021 Gerhard Sittig 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_DCTTECH_USBRELAY_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_DCTTECH_USBRELAY_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "libsigrok-internal.h" 29 | 30 | #define LOG_PREFIX "dcttech-usbrelay" 31 | 32 | /* USB identification. */ 33 | #define VENDOR_ID 0x16c0 34 | #define PRODUCT_ID 0x05df 35 | #define VENDOR_STRING "www.dcttech.com" 36 | #define PRODUCT_STRING_PREFIX "USBRelay" 37 | 38 | /* HID report layout. */ 39 | #define REPORT_NUMBER 0 40 | #define REPORT_BYTECOUNT 8 41 | #define SERNO_LENGTH 5 42 | #define STATE_INDEX 7 43 | 44 | struct dev_context { 45 | char *hid_path; 46 | uint16_t usb_vid, usb_pid; 47 | hid_device *hid_dev; 48 | size_t relay_count; 49 | uint32_t relay_mask; 50 | uint32_t relay_state; 51 | }; 52 | 53 | struct channel_group_context { 54 | size_t number; 55 | }; 56 | 57 | SR_PRIV int dcttech_usbrelay_update_state(const struct sr_dev_inst *sdi); 58 | SR_PRIV int dcttech_usbrelay_switch_cg(const struct sr_dev_inst *sdi, 59 | const struct sr_channel_group *cg, gboolean on); 60 | SR_PRIV int dcttech_usbrelay_query_cg(const struct sr_dev_inst *sdi, 61 | const struct sr_channel_group *cg, gboolean *on); 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /tests/lib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2013 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_TESTS_LIB_H 21 | #define LIBSIGROK_TESTS_LIB_H 22 | 23 | #include 24 | 25 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) 26 | 27 | extern struct sr_context *srtest_ctx; 28 | 29 | void srtest_setup(void); 30 | void srtest_teardown(void); 31 | 32 | struct sr_dev_driver *srtest_driver_get(const char *drivername); 33 | 34 | void srtest_driver_init(struct sr_context *sr_ctx, struct sr_dev_driver *driver); 35 | void srtest_driver_init_all(struct sr_context *sr_ctx); 36 | 37 | void srtest_set_samplerate(struct sr_dev_driver *driver, uint64_t samplerate); 38 | uint64_t srtest_get_samplerate(struct sr_dev_driver *driver); 39 | void srtest_check_samplerate(struct sr_context *sr_ctx, const char *drivername, 40 | uint64_t samplerate); 41 | 42 | GArray *srtest_get_enabled_logic_channels(const struct sr_dev_inst *sdi); 43 | 44 | Suite *suite_core(void); 45 | Suite *suite_driver_all(void); 46 | Suite *suite_input_all(void); 47 | Suite *suite_input_binary(void); 48 | Suite *suite_output_all(void); 49 | Suite *suite_transform_all(void); 50 | Suite *suite_session(void); 51 | Suite *suite_strutil(void); 52 | Suite *suite_version(void); 53 | Suite *suite_device(void); 54 | Suite *suite_trigger(void); 55 | Suite *suite_analog(void); 56 | Suite *suite_conv(void); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/hardware/gwinstek-gds-800/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2015 Martin Lederhilger 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_GWINSTEK_GDS_800_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_GWINSTEK_GDS_800_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | #include "scpi.h" 28 | 29 | #define LOG_PREFIX "gwinstek-gds-800" 30 | 31 | #define MAX_SAMPLES 125000 32 | #define MAX_RCV_BUFFER_SIZE (MAX_SAMPLES * 2) 33 | 34 | enum gds_state 35 | { 36 | START_ACQUISITION, 37 | START_TRANSFER_OF_CHANNEL_DATA, 38 | WAIT_FOR_TRANSFER_OF_BEGIN_TRANSMISSION_COMPLETE, 39 | WAIT_FOR_TRANSFER_OF_DATA_SIZE_DIGIT_COMPLETE, 40 | WAIT_FOR_TRANSFER_OF_DATA_SIZE_COMPLETE, 41 | WAIT_FOR_TRANSFER_OF_SAMPLE_RATE_COMPLETE, 42 | WAIT_FOR_TRANSFER_OF_CHANNEL_INDICATOR_COMPLETE, 43 | WAIT_FOR_TRANSFER_OF_RESERVED_DATA_COMPLETE, 44 | WAIT_FOR_TRANSFER_OF_CHANNEL_DATA_COMPLETE, 45 | }; 46 | 47 | struct dev_context { 48 | enum gds_state state; 49 | uint64_t cur_acq_frame; 50 | uint64_t frame_limit; 51 | int cur_acq_channel; 52 | int cur_rcv_buffer_position; 53 | char rcv_buffer[MAX_RCV_BUFFER_SIZE]; 54 | int data_size_digits; 55 | int data_size; 56 | float sample_rate; 57 | gboolean df_started; 58 | }; 59 | 60 | SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data); 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/hardware/microchip-pickit2/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2018 Gerhard Sittig 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_MICROCHIP_PICKIT2_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_MICROCHIP_PICKIT2_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "libsigrok-internal.h" 28 | 29 | #define LOG_PREFIX "microchip-pickit2" 30 | 31 | #define PICKIT2_CHANNEL_COUNT 3 32 | #define PICKIT2_SAMPLE_COUNT 1024 33 | #define PICKIT2_SAMPLE_RAWLEN (4 * 128) 34 | 35 | enum pickit_state { 36 | STATE_IDLE, 37 | STATE_CONF, 38 | STATE_WAIT, 39 | STATE_DATA, 40 | }; 41 | 42 | struct dev_context { 43 | char **channel_names; 44 | enum pickit_state state; 45 | const uint64_t *samplerates; 46 | size_t num_samplerates; 47 | size_t curr_samplerate_idx; 48 | const uint64_t *captureratios; 49 | size_t num_captureratios; 50 | size_t curr_captureratio_idx; 51 | struct sr_sw_limits sw_limits; 52 | gboolean detached_kernel_driver; 53 | int32_t triggers[PICKIT2_CHANNEL_COUNT]; /**@< see @ref SR_TRIGGER_ZERO et al */ 54 | size_t trigpos; 55 | uint8_t samples_raw[PICKIT2_SAMPLE_RAWLEN]; 56 | uint8_t samples_conv[PICKIT2_SAMPLE_COUNT]; 57 | }; 58 | 59 | SR_PRIV int microchip_pickit2_setup_trigger(const struct sr_dev_inst *sdi); 60 | SR_PRIV int microchip_pickit2_receive_data(int fd, int revents, void *cb_data); 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/hardware/hung-chang-dso-2100/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2015 Daniel Glöckner 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_HUNG_CHANG_DSO_2100_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_HUNG_CHANG_DSO_2100_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | 28 | #define LOG_PREFIX "hung-chang-dso-2100" 29 | 30 | #define MAX_RETRIES 4 31 | #define NUM_CHANNELS 2 32 | 33 | struct dev_context { 34 | GSList *enabled_channel; 35 | uint8_t channel; 36 | uint8_t rate; 37 | uint8_t cctl[2]; 38 | uint8_t edge; 39 | uint8_t tlevel; 40 | uint8_t pos[2]; 41 | uint8_t offset[2]; 42 | uint8_t gain[2]; 43 | 44 | uint64_t frame_limit; 45 | uint64_t frame; 46 | uint64_t probe[2]; 47 | uint8_t step; 48 | uint8_t last_step; 49 | uint8_t retries; 50 | gboolean adc2; 51 | 52 | float *samples; 53 | float factor; 54 | gboolean state_known; 55 | }; 56 | 57 | SR_PRIV void hung_chang_dso_2100_reset_port(struct parport *port); 58 | SR_PRIV gboolean hung_chang_dso_2100_check_id(struct parport *port); 59 | SR_PRIV void hung_chang_dso_2100_write_mbox(struct parport *port, uint8_t val); 60 | SR_PRIV uint8_t hung_chang_dso_2100_read_mbox(struct parport *port, float timeout); 61 | SR_PRIV int hung_chang_dso_2100_move_to(const struct sr_dev_inst *sdi, uint8_t target); 62 | SR_PRIV int hung_chang_dso_2100_poll(int fd, int revents, void *cb_data); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /src/hardware/mic-985xx/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2013 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_MIC_985XX_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_MIC_985XX_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "libsigrok-internal.h" 29 | 30 | #define LOG_PREFIX "mic-985xx" 31 | 32 | enum { 33 | MIC_98581, 34 | MIC_98583, 35 | }; 36 | 37 | struct mic_dev_info { 38 | const char *vendor; 39 | const char *device; 40 | const char *conn; 41 | uint32_t max_sample_points; 42 | gboolean has_temperature; 43 | gboolean has_humidity; 44 | uint8_t packet_size; 45 | gboolean (*packet_valid)(const uint8_t *); 46 | struct sr_dev_driver *di; 47 | int (*receive_data)(int, int, void *); 48 | }; 49 | 50 | extern SR_PRIV const struct mic_dev_info mic_devs[]; 51 | 52 | #define SERIAL_BUFSIZE 256 53 | 54 | struct dev_context { 55 | struct sr_sw_limits limits; 56 | 57 | uint8_t buf[SERIAL_BUFSIZE]; 58 | int bufoffset; 59 | int buflen; 60 | }; 61 | 62 | SR_PRIV gboolean packet_valid_temp(const uint8_t *buf); 63 | SR_PRIV gboolean packet_valid_temp_hum(const uint8_t *buf); 64 | 65 | SR_PRIV int receive_data_MIC_98581(int fd, int revents, void *cb_data); 66 | SR_PRIV int receive_data_MIC_98583(int fd, int revents, void *cb_data); 67 | 68 | SR_PRIV int mic_cmd_get_device_info(struct sr_serial_dev_inst *serial); 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/hardware/rdtech-um/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2018-2020 Andreas Sandberg 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_RDTECH_UM_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_RDTECH_UM_PROTOCOL_H 22 | 23 | #include 24 | #include "libsigrok-internal.h" 25 | 26 | #define LOG_PREFIX "rdtech-um" 27 | 28 | #define RDTECH_UM_BUFSIZE 256 29 | 30 | enum rdtech_um_model_id { 31 | RDTECH_UM24C = 0x0963, 32 | RDTECH_UM25C = 0x09c9, 33 | RDTECH_UM34C = 0x0d4c, 34 | }; 35 | 36 | struct rdtech_um_channel_desc { 37 | const char *name; 38 | struct binary_value_spec spec; 39 | struct sr_rational scale; 40 | int digits; 41 | enum sr_mq mq; 42 | enum sr_unit unit; 43 | }; 44 | 45 | struct rdtech_um_profile { 46 | const char *model_name; 47 | enum rdtech_um_model_id model_id; 48 | const struct rdtech_um_channel_desc *channels; 49 | size_t channel_count; 50 | gboolean (*csum_ok)(const uint8_t *buf, size_t len); 51 | }; 52 | 53 | struct dev_context { 54 | const struct rdtech_um_profile *profile; 55 | struct sr_sw_limits limits; 56 | struct feed_queue_analog **feeds; 57 | uint8_t buf[RDTECH_UM_BUFSIZE]; 58 | size_t buflen; 59 | int64_t cmd_sent_at; 60 | }; 61 | 62 | SR_PRIV const struct rdtech_um_profile *rdtech_um_probe(struct sr_serial_dev_inst *serial); 63 | SR_PRIV int rdtech_um_receive_data(int fd, int revents, void *cb_data); 64 | SR_PRIV int rdtech_um_poll(const struct sr_dev_inst *sdi, gboolean force); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/hardware/zeroplus-logic-cube/gl_usb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2010 Sven Peter 5 | * Copyright (C) 2010 Haxx Enterprises 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or 9 | * without modification, are permitted provided that the following 10 | * conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 15 | * * Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 29 | * THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef LIBSIGROK_HARDWARE_ZEROPLUS_LOGIC_CUBE_GL_USB_H 33 | #define LIBSIGROK_HARDWARE_ZEROPLUS_LOGIC_CUBE_GL_USB_H 34 | 35 | #include 36 | #include 37 | 38 | SR_PRIV int gl_read_bulk(libusb_device_handle *devh, void *buffer, 39 | unsigned int size); 40 | SR_PRIV int gl_reg_write(libusb_device_handle *devh, unsigned int reg, 41 | unsigned int val); 42 | SR_PRIV int gl_reg_read(libusb_device_handle *devh, unsigned int reg); 43 | SR_PRIV int gl_reg_read_buf(libusb_device_handle *devh, unsigned int reg, 44 | unsigned char *buf, unsigned int len); 45 | #endif 46 | -------------------------------------------------------------------------------- /src/hardware/fluke-dmm/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2012 Bert Vermeulen 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_FLUKE_DMM_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_FLUKE_DMM_PROTOCOL_H 22 | 23 | #define LOG_PREFIX "fluke-dmm" 24 | 25 | #define FLUKEDMM_BUFSIZE 256 26 | 27 | /* Always USB-serial, 1ms is plenty. */ 28 | #define SERIAL_WRITE_TIMEOUT_MS 1 29 | 30 | /* Supported models */ 31 | enum { 32 | FLUKE_87 = 1, 33 | FLUKE_89, 34 | FLUKE_187, 35 | FLUKE_189, 36 | FLUKE_190, 37 | FLUKE_287, 38 | FLUKE_289, 39 | }; 40 | 41 | /* Supported device profiles */ 42 | struct flukedmm_profile { 43 | int model; 44 | const char *modelname; 45 | /* How often to poll, in ms. */ 46 | int poll_period; 47 | /* If no response received, how long to wait before retrying. */ 48 | int timeout; 49 | }; 50 | 51 | struct dev_context { 52 | const struct flukedmm_profile *profile; 53 | struct sr_sw_limits limits; 54 | 55 | char buf[FLUKEDMM_BUFSIZE]; 56 | int buflen; 57 | int64_t cmd_sent_at; 58 | int expect_response; 59 | int meas_type; 60 | int is_relative; 61 | enum sr_mq mq; 62 | enum sr_unit unit; 63 | enum sr_mqflag mqflags; 64 | }; 65 | 66 | SR_PRIV void fluke_handle_qm_18x(const struct sr_dev_inst *sdi, char **tokens); 67 | SR_PRIV void fluke_handle_qm_190(const struct sr_dev_inst *sdi, char **tokens); 68 | SR_PRIV void fluke_handle_qm_28x(const struct sr_dev_inst *sdi, char **tokens); 69 | 70 | SR_PRIV int fluke_receive_data(int fd, int revents, void *cb_data); 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /src/hardware/saleae-logic-pro/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2017 Jan Luebbe 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_SALEAE_LOGIC_PRO_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_SALEAE_LOGIC_PRO_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | 28 | #define LOG_PREFIX "saleae-logic-pro" 29 | 30 | /* 16 channels * 32 samples */ 31 | #define CONV_BATCH_SIZE (2 * 32) 32 | 33 | /* 34 | * One packet + one partial conversion: Worst case is only one active 35 | * channel converted to 2 bytes per sample, with 8 * 16384 samples per packet. 36 | */ 37 | #define CONV_BUFFER_SIZE (2 * 8 * 16384 + CONV_BATCH_SIZE) 38 | 39 | struct dev_context { 40 | unsigned int dig_channel_cnt; 41 | uint16_t dig_channel_mask; 42 | uint16_t dig_channel_masks[16]; 43 | uint64_t dig_samplerate; 44 | 45 | uint32_t lfsr; 46 | 47 | unsigned int num_transfers; 48 | unsigned int submitted_transfers; 49 | struct libusb_transfer **transfers; 50 | 51 | uint8_t *conv_buffer; 52 | unsigned int conv_size; 53 | unsigned int batch_index; 54 | }; 55 | 56 | SR_PRIV int saleae_logic_pro_init(const struct sr_dev_inst *sdi); 57 | SR_PRIV int saleae_logic_pro_prepare(const struct sr_dev_inst *sdi); 58 | SR_PRIV int saleae_logic_pro_start(const struct sr_dev_inst *sdi); 59 | SR_PRIV int saleae_logic_pro_stop(const struct sr_dev_inst *sdi); 60 | SR_PRIV void LIBUSB_CALL saleae_logic_pro_receive_data(struct libusb_transfer *transfer); 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/drivers.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2016 Lars-Peter Clausen 5 | * Copyright (C) 2016 Aurelien Jacobs 6 | * Copyright (C) 2017 Marcus Comstedt 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include "libsigrok-internal.h" 26 | 27 | /* 28 | * The special __sr_driver_list section contains pointers to all hardware 29 | * drivers which were built into the library according to its configuration 30 | * (will depend on the availability of dependencies, as well as user provided 31 | * specs). The __start and __stop symbols point to the start and end of the 32 | * section. They are used to iterate over the list of all drivers which were 33 | * included in the library. 34 | */ 35 | SR_PRIV extern const struct sr_dev_driver *sr_driver_list__start[]; 36 | SR_PRIV extern const struct sr_dev_driver *sr_driver_list__stop[]; 37 | 38 | /** 39 | * Initialize the driver list in a fresh libsigrok context. 40 | * 41 | * @param ctx Pointer to a libsigrok context struct. Must not be NULL. 42 | * 43 | * @private 44 | */ 45 | SR_API void sr_drivers_init(struct sr_context *ctx) 46 | { 47 | GArray *array; 48 | 49 | array = g_array_new(TRUE, FALSE, sizeof(struct sr_dev_driver *)); 50 | #ifdef HAVE_DRIVERS 51 | for (const struct sr_dev_driver **drivers = sr_driver_list__start + 1; 52 | drivers < sr_driver_list__stop; drivers++) 53 | g_array_append_val(array, *drivers); 54 | #endif 55 | ctx->driver_list = (struct sr_dev_driver **)g_array_free(array, FALSE); 56 | } 57 | -------------------------------------------------------------------------------- /src/dmm/m2110.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2013 Matthias Heidbrink 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @file 22 | * 23 | * BBC Goerz Metrawatt M2110 ASCII protocol parser. 24 | * 25 | * Most probably the simplest multimeter protocol ever ;-) . 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "libsigrok-internal.h" 34 | 35 | #define LOG_PREFIX "m2110" 36 | 37 | SR_PRIV gboolean sr_m2110_packet_valid(const uint8_t *buf) 38 | { 39 | float val; 40 | 41 | if ((buf[7] != '\r') || (buf[8] != '\n')) 42 | return FALSE; 43 | 44 | if (!strncmp((const char *)buf, "OVERRNG", 7)) 45 | return TRUE; 46 | 47 | if (sr_atof_ascii((const char *)buf, &val) == SR_OK) 48 | return TRUE; 49 | else 50 | return FALSE; 51 | } 52 | 53 | SR_PRIV int sr_m2110_parse(const uint8_t *buf, float *floatval, 54 | struct sr_datafeed_analog *analog, void *info) 55 | { 56 | int dot_pos, digits = 0; 57 | float val; 58 | 59 | (void)info; 60 | 61 | /* We don't know the unit, so that's the best we can do. */ 62 | analog->meaning->mq = SR_MQ_GAIN; 63 | analog->meaning->unit = SR_UNIT_UNITLESS; 64 | analog->meaning->mqflags = 0; 65 | 66 | if (!strncmp((const char *)buf, "OVERRNG", 7)) 67 | *floatval = INFINITY; 68 | else if (sr_atof_ascii((const char *)buf, &val) == SR_OK) { 69 | *floatval = val; 70 | dot_pos = strcspn((const char *)buf, "."); 71 | if (dot_pos < 7) 72 | digits = 6 - dot_pos; 73 | } 74 | 75 | analog->encoding->digits = digits; 76 | analog->spec->spec_digits = digits; 77 | 78 | return SR_OK; 79 | } 80 | -------------------------------------------------------------------------------- /src/hardware/siglent-sdl10x0/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2024 Timo Boettcher 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_SIGLENT_SDL10X0_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_SIGLENT_SDL10X0_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | 28 | #define LOG_PREFIX "siglent-sdl10x0" 29 | 30 | /* 31 | * Operating modes. 32 | */ 33 | enum siglent_sdl10x0_modes { 34 | CC = 0, 35 | CV = 1, 36 | CP = 2, 37 | CR = 3, 38 | LED = 4, 39 | SDL10x0_MODES, /* Total count, for internal use. */ 40 | }; 41 | 42 | /* 43 | * Possible states in an acquisition. 44 | */ 45 | enum acquisition_state { 46 | ACQ_REQUESTED_VOLTAGE, 47 | ACQ_REQUESTED_CURRENT, 48 | ACQ_REQUESTED_POWER, 49 | ACQ_REQUESTED_RESISTANCE, 50 | }; 51 | 52 | struct dev_context { 53 | struct sr_sw_limits limits; 54 | enum acquisition_state acq_state; 55 | float voltage; 56 | float current; 57 | double maxpower; 58 | }; 59 | 60 | SR_PRIV const char *siglent_sdl10x0_mode_to_string(enum siglent_sdl10x0_modes mode); 61 | SR_PRIV const char *siglent_sdl10x0_mode_to_longstring(enum siglent_sdl10x0_modes mode); 62 | SR_PRIV int siglent_sdl10x0_string_to_mode(const char *modename, enum siglent_sdl10x0_modes *mode); 63 | 64 | SR_PRIV void siglent_sdl10x0_send_value(const struct sr_dev_inst *sdi, float value, enum sr_mq mq, enum sr_mqflag mqflags, enum sr_unit unit, int digits); 65 | 66 | SR_PRIV int siglent_sdl10x0_receive_data(struct sr_dev_inst *sdi); 67 | SR_PRIV int siglent_sdl10x0_handle_events(int fd, int revents, void *cb_data); 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /src/hardware/arachnid-labs-re-load-pro/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2015-2016 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_ARACHNID_LABS_RE_LOAD_PRO_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_ARACHNID_LABS_RE_LOAD_PRO_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | 28 | #define LOG_PREFIX "arachnid-labs-re-load-pro" 29 | 30 | #define RELOADPRO_BUFSIZE 100 31 | 32 | struct dev_context { 33 | struct sr_sw_limits limits; 34 | 35 | char buf[RELOADPRO_BUFSIZE]; 36 | int buflen; 37 | 38 | float current_limit; 39 | float voltage; 40 | float current; 41 | gboolean otp_active; 42 | gboolean uvc_active; 43 | float uvc_threshold; 44 | 45 | gboolean acquisition_running; 46 | GMutex acquisition_mutex; 47 | 48 | GCond current_limit_cond; 49 | GCond voltage_cond; 50 | GCond uvc_threshold_cond; 51 | }; 52 | 53 | SR_PRIV int reloadpro_set_current_limit(const struct sr_dev_inst *sdi, 54 | float current); 55 | SR_PRIV int reloadpro_set_on_off(const struct sr_dev_inst *sdi, gboolean on); 56 | SR_PRIV int reloadpro_set_under_voltage_threshold(const struct sr_dev_inst *sdi, 57 | float uvc_threshold); 58 | SR_PRIV int reloadpro_get_current_limit(const struct sr_dev_inst *sdi, 59 | float *current_limit); 60 | SR_PRIV int reloadpro_get_under_voltage_threshold(const struct sr_dev_inst *sdi, 61 | float *uvc_threshold); 62 | SR_PRIV int reloadpro_get_voltage_current(const struct sr_dev_inst *sdi, 63 | float *voltage, float *current); 64 | SR_PRIV int reloadpro_receive_data(int fd, int revents, void *cb_data); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/hardware/norma-dmm/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2013 Matthias Heidbrink 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_NORMA_DMM_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_NORMA_DMM_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "libsigrok-internal.h" 30 | 31 | #define LOG_PREFIX "norma-dmm" 32 | 33 | #define NMADMM_BUFSIZE 256 34 | 35 | #define NMADMM_TIMEOUT_MS 2000 /**< Request timeout. */ 36 | 37 | /** Norma DMM request types (used ones only, the DMMs support about 50). */ 38 | enum { 39 | NMADMM_REQ_IDN = 0, /**< Request identity */ 40 | NMADMM_REQ_STATUS, /**< Request device status (value + ...) */ 41 | }; 42 | 43 | /** Defines requests used to communicate with device. */ 44 | struct nmadmm_req { 45 | int req_type; /**< Request type. */ 46 | const char *req_str; /**< Request string. */ 47 | }; 48 | 49 | /** Strings for requests. */ 50 | extern const struct nmadmm_req nmadmm_requests[]; 51 | 52 | struct dev_context { 53 | int type; /**< DM9x0, e.g. 5 = DM950 */ 54 | 55 | struct sr_sw_limits limits; 56 | 57 | int last_req; /**< Last request. */ 58 | int64_t req_sent_at; /**< Request sent. */ 59 | gboolean last_req_pending; /**< Last request not answered yet. */ 60 | int lowbatt; /**< Low battery. 1=low, 2=critical. */ 61 | 62 | uint8_t buf[NMADMM_BUFSIZE]; /**< Buffer for read callback */ 63 | int buflen; /**< Data len in buf */ 64 | }; 65 | 66 | SR_PRIV int norma_dmm_receive_data(int fd, int revents, void *cb_data); 67 | SR_PRIV int xgittoint(char xgit); 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /tests/driver_all.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2013 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "lib.h" 25 | 26 | /* Check whether at least one driver is available. */ 27 | START_TEST(test_driver_available) 28 | { 29 | struct sr_dev_driver **drivers; 30 | 31 | drivers = sr_driver_list(srtest_ctx); 32 | fail_unless(drivers != NULL, "No drivers found."); 33 | } 34 | END_TEST 35 | 36 | /* Check whether initializing all drivers works. */ 37 | START_TEST(test_driver_init_all) 38 | { 39 | srtest_driver_init_all(srtest_ctx); 40 | } 41 | END_TEST 42 | 43 | /* 44 | * Check whether setting a samplerate works. 45 | * 46 | * Additionally, this also checks whether SR_CONF_SAMPLERATE can be both 47 | * set and read back properly. 48 | */ 49 | #if 0 50 | START_TEST(test_config_get_set_samplerate) 51 | { 52 | /* 53 | * Note: This currently only works for the demo driver. 54 | * For other drivers, a scan is needed and the respective 55 | * hardware must be attached to the host running the testsuite. 56 | */ 57 | srtest_check_samplerate(sr_ctx, "demo", SR_KHZ(19)); 58 | } 59 | END_TEST 60 | #endif 61 | 62 | Suite *suite_driver_all(void) 63 | { 64 | Suite *s; 65 | TCase *tc; 66 | 67 | s = suite_create("driver-all"); 68 | 69 | tc = tcase_create("config"); 70 | tcase_add_checked_fixture(tc, srtest_setup, srtest_teardown); 71 | tcase_add_test(tc, test_driver_available); 72 | tcase_add_test(tc, test_driver_init_all); 73 | // TODO: Currently broken. 74 | // tcase_add_test(tc, test_config_get_set_samplerate); 75 | suite_add_tcase(s, tc); 76 | 77 | return s; 78 | } 79 | -------------------------------------------------------------------------------- /src/hardware/serial-lcr/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2014 Janne Huttunen 5 | * Copyright (C) 2019 Gerhard Sittig 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program 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 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef LIBSIGROK_HARDWARE_SERIAL_LCR_PROTOCOL_H 22 | #define LIBSIGROK_HARDWARE_SERIAL_LCR_PROTOCOL_H 23 | 24 | #define LOG_PREFIX "serial-lcr" 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | struct lcr_info { 32 | struct sr_dev_driver di; 33 | const char *vendor; 34 | const char *model; 35 | size_t channel_count; 36 | const char **channel_formats; 37 | const char *comm; 38 | size_t packet_size; 39 | int64_t req_timeout_ms; 40 | int (*packet_request)(struct sr_serial_dev_inst *serial); 41 | gboolean (*packet_valid)(const uint8_t *pkt); 42 | int (*packet_parse)(const uint8_t *pkt, float *value, 43 | struct sr_datafeed_analog *analog, void *info); 44 | int (*config_get)(uint32_t key, GVariant **data, 45 | const struct sr_dev_inst *sdi, 46 | const struct sr_channel_group *cg); 47 | int (*config_set)(uint32_t key, GVariant *data, 48 | const struct sr_dev_inst *sdi, 49 | const struct sr_channel_group *cg); 50 | int (*config_list)(uint32_t key, GVariant **data, 51 | const struct sr_dev_inst *sdi, 52 | const struct sr_channel_group *cg); 53 | }; 54 | 55 | #define LCR_BUFSIZE 128 56 | 57 | struct dev_context { 58 | const struct lcr_info *lcr_info; 59 | struct sr_sw_limits limits; 60 | uint8_t buf[LCR_BUFSIZE]; 61 | size_t buf_rxpos, buf_rdpos; 62 | struct lcr_parse_info parse_info; 63 | uint64_t output_freq; 64 | const char *circuit_model; 65 | int64_t req_next_at; 66 | }; 67 | 68 | SR_PRIV int lcr_receive_data(int fd, int revents, void *cb_data); 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/hardware/gwinstek-gpd/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2018 Bastian Schmitz 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_GWINSTEK_GPD_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_GWINSTEK_GPD_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | 28 | #define LOG_PREFIX "gwinstek-gpd" 29 | 30 | enum { 31 | GPD_2303S, 32 | GPD_3303S, 33 | }; 34 | 35 | /* Maximum number of output channels handled by this driver. */ 36 | #define MAX_CHANNELS 2 37 | 38 | #define CHANMODE_INDEPENDENT (1 << 0) 39 | #define CHANMODE_SERIES (1 << 1) 40 | #define CHANMODE_PARALLEL (1 << 2) 41 | 42 | struct channel_spec { 43 | /* Min, max, step. */ 44 | gdouble voltage[3]; 45 | gdouble current[3]; 46 | }; 47 | 48 | struct gpd_model { 49 | int modelid; 50 | const char *name; 51 | int channel_modes; 52 | unsigned int num_channels; 53 | struct channel_spec channels[MAX_CHANNELS]; 54 | }; 55 | 56 | struct per_channel_config { 57 | /* Received from device. */ 58 | float output_voltage_last; 59 | float output_current_last; 60 | /* Set by frontend. */ 61 | float output_voltage_max; 62 | float output_current_max; 63 | }; 64 | 65 | struct dev_context { 66 | /* Received from device. */ 67 | gboolean output_enabled; 68 | int64_t req_sent_at; 69 | gboolean reply_pending; 70 | 71 | struct sr_sw_limits limits; 72 | int channel_mode; 73 | struct per_channel_config *config; 74 | const struct gpd_model *model; 75 | }; 76 | 77 | SR_PRIV int gpd_send_cmd(struct sr_serial_dev_inst *serial, const char *cmd, ...); 78 | SR_PRIV int gpd_receive_data(int fd, int revents, void *cb_data); 79 | SR_PRIV int gpd_receive_reply(struct sr_serial_dev_inst *serial, char *buf, int buflen); 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/hardware/beaglelogic/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2014-2017 Kumar Abhishek 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_BEAGLELOGIC_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_BEAGLELOGIC_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | 28 | #define LOG_PREFIX "beaglelogic" 29 | 30 | /* Maximum possible input channels */ 31 | #define NUM_CHANNELS 14 32 | 33 | #define SAMPLEUNIT_TO_BYTES(x) ((x) == 1 ? 1 : 2) 34 | 35 | #define TCP_BUFFER_SIZE (128 * 1024) 36 | 37 | /** Private, per-device-instance driver context. */ 38 | struct dev_context { 39 | int max_channels; 40 | uint32_t fw_ver; 41 | 42 | /* Operations */ 43 | const struct beaglelogic_ops *beaglelogic; 44 | 45 | /* TCP Settings */ 46 | char *address; 47 | char *port; 48 | int socket; 49 | unsigned int read_timeout; 50 | unsigned char *tcp_buffer; 51 | 52 | /* Acquisition settings: see beaglelogic.h */ 53 | uint64_t cur_samplerate; 54 | uint64_t limit_samples; 55 | uint32_t sampleunit; 56 | uint32_t triggerflags; 57 | uint64_t capture_ratio; 58 | 59 | /* Buffers: size of each buffer block and the total buffer area */ 60 | uint32_t bufunitsize; 61 | uint32_t buffersize; 62 | 63 | int fd; 64 | GPollFD pollfd; 65 | int last_error; 66 | 67 | uint64_t bytes_read; 68 | uint64_t sent_samples; 69 | uint32_t offset; 70 | uint8_t *sample_buf; /* mmap'd kernel buffer here */ 71 | 72 | /* Trigger logic */ 73 | struct soft_trigger_logic *stl; 74 | gboolean trigger_fired; 75 | }; 76 | 77 | SR_PRIV int beaglelogic_native_receive_data(int fd, int revents, void *cb_data); 78 | SR_PRIV int beaglelogic_tcp_receive_data(int fd, int revents, void *cb_data); 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /src/transform/invert.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2015 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "libsigrok-internal.h" 24 | 25 | #define LOG_PREFIX "transform/invert" 26 | 27 | static int receive(const struct sr_transform *t, 28 | struct sr_datafeed_packet *packet_in, 29 | struct sr_datafeed_packet **packet_out) 30 | { 31 | const struct sr_datafeed_logic *logic; 32 | const struct sr_datafeed_analog *analog; 33 | uint8_t *b; 34 | int64_t p; 35 | uint64_t i, j, q; 36 | 37 | if (!t || !t->sdi || !packet_in || !packet_out) 38 | return SR_ERR_ARG; 39 | 40 | switch (packet_in->type) { 41 | case SR_DF_LOGIC: 42 | logic = packet_in->payload; 43 | for (i = 0; i <= logic->length - logic->unitsize; i += logic->unitsize) { 44 | for (j = 0; j < logic->unitsize; j++) { 45 | /* For now invert every bit in every byte. */ 46 | b = (uint8_t *)logic->data + i + logic->unitsize - 1 - j; 47 | *b = ~(*b); 48 | } 49 | } 50 | break; 51 | case SR_DF_ANALOG: 52 | analog = packet_in->payload; 53 | p = analog->encoding->scale.p; 54 | q = analog->encoding->scale.q; 55 | if (q > INT64_MAX) 56 | return SR_ERR; 57 | analog->encoding->scale.p = (p < 0) ? -q : q; 58 | analog->encoding->scale.q = (p < 0) ? -p : p; 59 | break; 60 | default: 61 | sr_spew("Unsupported packet type %d, ignoring.", packet_in->type); 62 | break; 63 | } 64 | 65 | /* Return the in-place-modified packet. */ 66 | *packet_out = packet_in; 67 | 68 | return SR_OK; 69 | } 70 | 71 | SR_PRIV struct sr_transform_module transform_invert = { 72 | .id = "invert", 73 | .name = "Invert", 74 | .desc = "Invert values", 75 | .options = NULL, 76 | .init = NULL, 77 | .receive = receive, 78 | .cleanup = NULL, 79 | }; 80 | -------------------------------------------------------------------------------- /src/hardware/zketech-ebd-usb/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2018 Sven Bursch-Osewold 5 | * Copyright (C) 2019 King Kévin 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program 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 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef LIBSIGROK_HARDWARE_ZKETECH_EBD_USB_PROTOCOL_H 22 | #define LIBSIGROK_HARDWARE_ZKETECH_EBD_USB_PROTOCOL_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include "libsigrok-internal.h" 28 | 29 | #define LOG_PREFIX "zketech-ebd-usb" 30 | 31 | #define MSG_MAX_LEN 19 32 | #define MSG_FRAME_BEGIN 0xfa 33 | #define MSG_FRAME_END 0xf8 34 | 35 | struct dev_context { 36 | struct sr_sw_limits limits; 37 | GMutex rw_mutex; 38 | float current_limit; 39 | float uvc_threshold; 40 | gboolean running; 41 | gboolean load_activated; 42 | }; 43 | 44 | /* Communication via serial. */ 45 | SR_PRIV int ebd_read_message(struct sr_serial_dev_inst *serial, size_t length, 46 | uint8_t *buf); 47 | 48 | /* Commands. */ 49 | SR_PRIV int ebd_init(struct sr_serial_dev_inst *serial, 50 | struct dev_context *devc); 51 | SR_PRIV int ebd_loadstart(struct sr_serial_dev_inst *serial, 52 | struct dev_context *devc); 53 | SR_PRIV int ebd_receive_data(int fd, int revents, void *cb_data); 54 | SR_PRIV int ebd_stop(struct sr_serial_dev_inst *serial, 55 | struct dev_context *devc); 56 | SR_PRIV int ebd_loadtoggle(struct sr_serial_dev_inst *serial, 57 | struct dev_context *devc); 58 | 59 | /* Configuration. */ 60 | SR_PRIV int ebd_get_current_limit(const struct sr_dev_inst *sdi, float *current); 61 | SR_PRIV int ebd_set_current_limit(const struct sr_dev_inst *sdi, float current); 62 | SR_PRIV int ebd_get_uvc_threshold(const struct sr_dev_inst *sdi, float *voltage); 63 | SR_PRIV int ebd_set_uvc_threshold(const struct sr_dev_inst *sdi, float voltage); 64 | SR_PRIV gboolean ebd_current_is0(struct dev_context *devc); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/hardware/rdtech-tc/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2020 Andreas Sandberg 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_RDTECH_TC_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_RDTECH_TC_PROTOCOL_H 22 | 23 | #include 24 | #include "libsigrok-internal.h" 25 | 26 | #define LOG_PREFIX "rdtech-tc" 27 | 28 | /* 29 | * Keep request and response buffers of sufficient size. The maximum 30 | * request text currently involved is "bgetva\r\n" which translates 31 | * to 9 bytes. The poll response (a measurement, the largest amount 32 | * of data that is currently received) is 192 bytes in length. Add 33 | * some slack for alignment, and for in-flight messages or adjacent 34 | * data during synchronization to the data stream. 35 | */ 36 | #define RDTECH_TC_MAXREQLEN 12 37 | #define RDTECH_TC_RSPBUFSIZE 256 38 | 39 | struct rdtech_dev_info { 40 | char *model_name; 41 | char *fw_ver; 42 | uint32_t serial_num; 43 | }; 44 | 45 | struct rdtech_tc_channel_desc { 46 | const char *name; 47 | struct binary_value_spec spec; 48 | struct sr_rational scale; 49 | int digits; 50 | enum sr_mq mq; 51 | enum sr_unit unit; 52 | }; 53 | 54 | struct dev_context { 55 | gboolean is_bluetooth; 56 | char req_text[RDTECH_TC_MAXREQLEN]; 57 | struct rdtech_dev_info dev_info; 58 | const struct rdtech_tc_channel_desc *channels; 59 | size_t channel_count; 60 | struct feed_queue_analog **feeds; 61 | struct sr_sw_limits limits; 62 | uint8_t buf[RDTECH_TC_RSPBUFSIZE]; 63 | size_t rdlen; 64 | int64_t cmd_sent_at; 65 | size_t rx_after_tx; 66 | }; 67 | 68 | SR_PRIV int rdtech_tc_probe(struct sr_serial_dev_inst *serial, struct dev_context *devc); 69 | SR_PRIV int rdtech_tc_receive_data(int fd, int revents, void *cb_data); 70 | SR_PRIV int rdtech_tc_poll(const struct sr_dev_inst *sdi, gboolean force); 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /src/minilzo/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # a very simple Makefile for miniLZO 3 | # 4 | # Copyright (C) 1996-2017 Markus F.X.J. Oberhumer 5 | # 6 | 7 | PROGRAM = testmini 8 | SOURCES = testmini.c minilzo.c 9 | 10 | default: 11 | @echo "" 12 | @echo "Welcome to miniLZO. Please choose one of the following 'make' targets:" 13 | @echo "" 14 | @echo " gcc: gcc" 15 | @echo " unix: hpux hpux9" 16 | @echo " win32: win32-bc win32-cygwin win32-dm win32-lccwin32" 17 | @echo " win32-intelc win32-mingw win32-vc win32-watcomc" 18 | @echo " dos32: dos32-djgpp2 dos32-wc" 19 | @echo "" 20 | 21 | 22 | # Make sure that minilzo.h, lzoconf.h and lzodefs.h are in the 23 | # current dircectory. Otherwise you may want to adjust CPPFLAGS. 24 | CPPFLAGS = -I. -I../include/lzo 25 | 26 | GCC_CFLAGS = -s -Wall -O2 -fomit-frame-pointer 27 | 28 | 29 | # 30 | # gcc (generic) 31 | # 32 | 33 | gcc: 34 | gcc $(CPPFLAGS) $(GCC_CFLAGS) -o $(PROGRAM) $(SOURCES) 35 | 36 | cc: 37 | cc $(CPPFLAGS) -o $(PROGRAM) $(SOURCES) 38 | 39 | 40 | # 41 | # UNIX 42 | # 43 | 44 | hpux: 45 | cc -Ae $(CPPFLAGS) -o $(PROGRAM) $(SOURCES) 46 | 47 | hpux9: 48 | cc -Aa -D_HPUX_SOURCE $(CPPFLAGS) -o $(PROGRAM) $(SOURCES) 49 | 50 | 51 | # 52 | # Windows (32-bit) 53 | # 54 | 55 | win32-borlandc win32-bc: 56 | bcc32 -O2 -d -w -w-aus $(CPPFLAGS) $(SOURCES) 57 | 58 | win32-cygwin32 win32-cygwin: 59 | gcc -mcygwin $(CPPFLAGS) $(GCC_CFLAGS) -o $(PROGRAM).exe $(SOURCES) 60 | 61 | win32-digitalmars win32-dm: 62 | dmc -mn -o -w- $(CPPFLAGS) $(SOURCES) 63 | 64 | win32-intelc win32-ic: 65 | icl -nologo -MT -W3 -O2 -GF $(CPPFLAGS) $(SOURCES) 66 | 67 | win32-lccwin32: 68 | @echo "NOTE: need lcc 2002-07-25 or newer, older versions have bugs" 69 | lc -A -unused -O $(CPPFLAGS) $(SOURCES) 70 | 71 | win32-mingw32 win32-mingw: 72 | gcc -mno-cygwin $(CPPFLAGS) $(GCC_CFLAGS) -o $(PROGRAM).exe $(SOURCES) 73 | 74 | win32-visualc win32-vc: 75 | cl -nologo -MT -W3 -O2 -GF $(CPPFLAGS) $(SOURCES) 76 | 77 | win32-watcomc win32-wc: 78 | wcl386 -bt=nt -zq -mf -5r -zc -w5 -oneatx $(CPPFLAGS) $(SOURCES) 79 | 80 | 81 | # 82 | # DOS (32-bit) 83 | # 84 | 85 | dos32-djgpp2 dos32-dj2: 86 | gcc $(CPPFLAGS) $(GCC_CFLAGS) -o $(PROGRAM).exe $(SOURCES) 87 | 88 | dos32-watcomc dos32-wc: 89 | wcl386 -zq -mf -bt=dos -l=dos4g -5r -ox -zc $(CPPFLAGS) $(SOURCES) 90 | 91 | 92 | # 93 | # other targets 94 | # 95 | 96 | clean: 97 | rm -f $(PROGRAM) $(PROGRAM).exe $(PROGRAM).map $(PROGRAM).tds 98 | rm -f *.err *.o *.obj 99 | 100 | .PHONY: default clean 101 | -------------------------------------------------------------------------------- /tests/device.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2014 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "lib.h" 25 | 26 | START_TEST(test_user_new) 27 | { 28 | struct sr_dev_inst *sdi; 29 | 30 | sdi = sr_dev_inst_user_new("Vendor", "Model", "Version"); 31 | 32 | fail_unless(sdi != NULL, "sr_dev_inst_user_new() failed."); 33 | 34 | fail_unless(!strcmp("Vendor", sr_dev_inst_vendor_get(sdi))); 35 | fail_unless(!strcmp("Model", sr_dev_inst_model_get(sdi))); 36 | fail_unless(!strcmp("Version", sr_dev_inst_version_get(sdi))); 37 | } 38 | END_TEST 39 | 40 | START_TEST(test_channel_add) 41 | { 42 | int ret; 43 | struct sr_dev_inst *sdi; 44 | GSList *channels; 45 | 46 | sdi = sr_dev_inst_user_new("Vendor", "Model", "Version"); 47 | fail_unless(sdi != NULL, "sr_dev_inst_user_new() failed."); 48 | 49 | channels = sr_dev_inst_channels_get(sdi); 50 | fail_unless(g_slist_length(channels) == 0, "More than 0 channels."); 51 | 52 | ret = sr_dev_inst_channel_add(sdi, 0, SR_CHANNEL_LOGIC, "D1"); 53 | channels = sr_dev_inst_channels_get(sdi); 54 | fail_unless(ret == SR_OK); 55 | fail_unless(g_slist_length(channels) == 1); 56 | 57 | ret = sr_dev_inst_channel_add(sdi, 1, SR_CHANNEL_ANALOG, "A1"); 58 | channels = sr_dev_inst_channels_get(sdi); 59 | fail_unless(ret == SR_OK); 60 | fail_unless(g_slist_length(channels) == 2); 61 | } 62 | END_TEST 63 | 64 | Suite *suite_device(void) 65 | { 66 | Suite *s; 67 | TCase *tc; 68 | 69 | s = suite_create("device"); 70 | 71 | tc = tcase_create("sr_dev_inst_user_new"); 72 | tcase_add_test(tc, test_user_new); 73 | suite_add_tcase(s, tc); 74 | 75 | tc = tcase_create("sr_dev_inst_channel_add"); 76 | tcase_add_test(tc, test_channel_add); 77 | suite_add_tcase(s, tc); 78 | 79 | return s; 80 | } 81 | -------------------------------------------------------------------------------- /src/hardware/testo/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2014 Bert Vermeulen 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_TESTO_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_TESTO_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | 28 | #define LOG_PREFIX "testo" 29 | 30 | #define MAX_REPLY_SIZE 128 31 | #define MAX_CHANNELS 16 32 | 33 | /* FTDI commands */ 34 | #define FTDI_SET_MODEMCTRL 0x01 35 | #define FTDI_SET_FLOWCTRL 0x02 36 | #define FTDI_SET_BAUDRATE 0x03 37 | #define FTDI_SET_PARAMS 0x04 38 | /* FTDI command values */ 39 | #define FTDI_BAUDRATE_115200 0x001a 40 | #define FTDI_PARAMS_8N1 0x0008 41 | #define FTDI_FLOW_NONE 0x0008 42 | #define FTDI_MODEM_ALLHIGH 0x0303 43 | #define FTDI_INDEX 0x0000 44 | /* FTDI USB stuff */ 45 | #define EP_IN 1 | LIBUSB_ENDPOINT_IN 46 | #define EP_OUT 2 | LIBUSB_ENDPOINT_OUT 47 | 48 | struct testo_model { 49 | const char *name; 50 | int request_size; 51 | const uint8_t *request; 52 | }; 53 | 54 | struct dev_context { 55 | const struct testo_model *model; 56 | struct sr_sw_limits sw_limits; 57 | 58 | uint8_t channel_units[MAX_CHANNELS]; 59 | int num_channels; 60 | 61 | struct libusb_transfer *out_transfer; 62 | uint8_t reply[MAX_REPLY_SIZE]; 63 | int reply_size; 64 | }; 65 | 66 | SR_PRIV int testo_set_serial_params(struct sr_usb_dev_inst *usb); 67 | SR_PRIV int testo_probe_channels(struct sr_dev_inst *sdi); 68 | SR_PRIV void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer); 69 | SR_PRIV int testo_request_packet(const struct sr_dev_inst *sdi); 70 | SR_PRIV gboolean testo_check_packet_prefix(uint8_t *buf, int len); 71 | SR_PRIV uint16_t crc16_mcrf4xx(uint16_t crc, uint8_t *data, size_t len); 72 | SR_PRIV void testo_receive_packet(const struct sr_dev_inst *sdi); 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /src/hardware/rohde-schwarz-sme-0x/protocol.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2016 Vlad Ivanov 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "protocol.h" 25 | 26 | enum { 27 | RS_CMD_CONTROL_REMOTE, 28 | RS_CMD_SET_FREQ, 29 | RS_CMD_SET_POWER, 30 | RS_CMD_GET_FREQ, 31 | RS_CMD_GET_POWER, 32 | }; 33 | 34 | static char *commands[] = { 35 | [RS_CMD_CONTROL_REMOTE] = "\n", 36 | [RS_CMD_SET_FREQ] = "FREQ %.1fHz", 37 | [RS_CMD_SET_POWER] = "POW %.1fdBm", 38 | [RS_CMD_GET_FREQ] = "FREQ?", 39 | [RS_CMD_GET_POWER] = "POW?", 40 | }; 41 | 42 | SR_PRIV int rs_sme0x_mode_remote(struct sr_scpi_dev_inst *scpi) 43 | { 44 | return sr_scpi_send(scpi, commands[RS_CMD_CONTROL_REMOTE]); 45 | } 46 | 47 | SR_PRIV int rs_sme0x_get_freq(const struct sr_dev_inst *sdi, double *freq) 48 | { 49 | if (sr_scpi_get_double(sdi->conn, commands[RS_CMD_GET_FREQ], freq) != SR_OK) 50 | return SR_ERR; 51 | 52 | return SR_OK; 53 | } 54 | 55 | SR_PRIV int rs_sme0x_get_power(const struct sr_dev_inst *sdi, double *power) 56 | { 57 | if (sr_scpi_get_double(sdi->conn, commands[RS_CMD_GET_POWER], power) != SR_OK) 58 | return SR_ERR; 59 | 60 | return SR_OK; 61 | } 62 | 63 | SR_PRIV int rs_sme0x_set_freq(const struct sr_dev_inst *sdi, double freq) 64 | { 65 | struct dev_context *devc; 66 | const struct rs_device_model *config; 67 | 68 | devc = sdi->priv; 69 | config = devc->model_config; 70 | 71 | if ((freq > config->freq_max) || (freq < config->freq_min)) 72 | return SR_ERR_ARG; 73 | 74 | return sr_scpi_send(sdi->conn, commands[RS_CMD_SET_FREQ], freq); 75 | } 76 | 77 | SR_PRIV int rs_sme0x_set_power(const struct sr_dev_inst *sdi, double power) 78 | { 79 | struct dev_context *devc; 80 | const struct rs_device_model *config; 81 | 82 | devc = sdi->priv; 83 | config = devc->model_config; 84 | 85 | if ((power > config->power_max) || (power < config->power_min)) 86 | return SR_ERR_ARG; 87 | 88 | return sr_scpi_send(sdi->conn, commands[RS_CMD_SET_POWER], power); 89 | } 90 | -------------------------------------------------------------------------------- /src/hardware/lascar-el-usb/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2012 Bert Vermeulen 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_LASCAR_EL_USB_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_LASCAR_EL_USB_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include "libsigrok-internal.h" 26 | 27 | #define LOG_PREFIX "lascar-el-usb" 28 | 29 | #define LASCAR_INTERFACE 0 30 | #define LASCAR_EP_IN 0x82 31 | #define LASCAR_EP_OUT 2 32 | #define MAX_CONFIGBLOCK_SIZE 256 33 | 34 | /* Max 100ms for a device to positively identify. */ 35 | #define SCAN_TIMEOUT (100 * 1000) 36 | #define BULK_XFER_TIMEOUT (10 * 1000) 37 | #define EVENTS_TIMEOUT (10 * 1000) 38 | #define SLEEP_US_LONG (5 * 1000) 39 | #define SLEEP_US_SHORT (1 * 1000) 40 | 41 | struct dev_context { 42 | const struct elusb_profile *profile; 43 | 44 | /* Generic EL-USB */ 45 | unsigned char config[MAX_CONFIGBLOCK_SIZE]; 46 | unsigned int log_size; 47 | unsigned int rcvd_bytes; 48 | unsigned int sample_size; 49 | unsigned int logged_samples; 50 | unsigned int rcvd_samples; 51 | uint64_t limit_samples; 52 | 53 | /* Model-specific */ 54 | /* EL-USB-CO: these are something like scaling and calibration values 55 | * fixed per device, used to convert the sample values to CO ppm. */ 56 | float co_high; 57 | float co_low; 58 | /* Temperature units as stored in the device config. */ 59 | int temp_unit; 60 | }; 61 | 62 | enum { 63 | LOG_UNSUPPORTED, 64 | LOG_TEMP_RH, 65 | LOG_CO, 66 | }; 67 | 68 | struct elusb_profile { 69 | int modelid; 70 | const char *modelname; 71 | int logformat; 72 | }; 73 | 74 | SR_PRIV int lascar_get_config(libusb_device_handle *dev_hdl, 75 | unsigned char *configblock, int *configlen); 76 | SR_PRIV struct sr_dev_inst *lascar_scan(int bus, int address); 77 | SR_PRIV int lascar_el_usb_handle_events(int fd, int revents, void *cb_data); 78 | SR_PRIV void LIBUSB_CALL lascar_el_usb_receive_transfer(struct libusb_transfer *transfer); 79 | SR_PRIV int lascar_start_logging(const struct sr_dev_inst *sdi); 80 | SR_PRIV int lascar_stop_logging(const struct sr_dev_inst *sdi); 81 | SR_PRIV int lascar_is_logging(const struct sr_dev_inst *sdi); 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /src/binary_helpers.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2020 Andreas Sandberg 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "libsigrok-internal.h" 24 | 25 | SR_PRIV int bv_get_value_len(float *out, const struct binary_value_spec *spec, 26 | const uint8_t *data, size_t length) 27 | { 28 | float value; 29 | 30 | if (!out || !spec || !data) 31 | return SR_ERR_ARG; 32 | 33 | #define VALUE_TYPE(T, R, L) \ 34 | case T: \ 35 | if (spec->offset + (L) > length) \ 36 | return SR_ERR_DATA; \ 37 | value = R(data + spec->offset); \ 38 | break 39 | 40 | switch (spec->type) { 41 | VALUE_TYPE(BVT_UINT8, read_u8, sizeof(uint8_t)); 42 | 43 | VALUE_TYPE(BVT_BE_UINT16, read_u16be, sizeof(uint16_t)); 44 | VALUE_TYPE(BVT_BE_UINT24, read_u24be, 3 * sizeof(uint8_t)); 45 | VALUE_TYPE(BVT_BE_UINT32, read_u32be, sizeof(uint32_t)); 46 | 47 | VALUE_TYPE(BVT_LE_UINT16, read_u16le, sizeof(uint16_t)); 48 | VALUE_TYPE(BVT_LE_UINT24, read_u24le, 3 * sizeof(uint8_t)); 49 | VALUE_TYPE(BVT_LE_UINT32, read_u32le, sizeof(uint32_t)); 50 | 51 | default: 52 | return SR_ERR_ARG; 53 | } 54 | 55 | #undef VALUE_TYPE 56 | 57 | if (out) 58 | *out = value; 59 | return SR_OK; 60 | } 61 | 62 | SR_PRIV int bv_get_value(float *out, const struct binary_value_spec *spec, 63 | const uint8_t *data) 64 | { 65 | float value; 66 | const uint8_t *ptr; 67 | 68 | ptr = &data[spec->offset]; 69 | 70 | switch (spec->type) { 71 | case BVT_UINT8: 72 | value = read_u8(ptr); 73 | break; 74 | case BVT_BE_UINT16: 75 | value = read_u16be(ptr); 76 | break; 77 | case BVT_BE_UINT24: 78 | value = read_u24be(ptr); 79 | break; 80 | case BVT_BE_UINT32: 81 | value = read_u32be(ptr); 82 | break; 83 | case BVT_LE_UINT16: 84 | value = read_u16le(ptr); 85 | break; 86 | case BVT_LE_UINT24: 87 | value = read_u24le(ptr); 88 | break; 89 | case BVT_LE_UINT32: 90 | value = read_u32le(ptr); 91 | break; 92 | default: 93 | return SR_ERR_ARG; 94 | } 95 | 96 | if (out) 97 | *out = value; 98 | return SR_OK; 99 | } 100 | -------------------------------------------------------------------------------- /src/hardware/ipdbg-la/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2016 Eva Kissling 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_IPDBG_LA_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_IPDBG_LA_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | 28 | #define LOG_PREFIX "ipdbg-la" 29 | 30 | struct ipdbg_la_tcp { 31 | char *address; 32 | char *port; 33 | int socket; 34 | }; 35 | 36 | /** Private, per-device-instance driver context. */ 37 | struct dev_context { 38 | uint32_t data_width; 39 | uint32_t data_width_bytes; 40 | uint32_t addr_width; 41 | uint32_t addr_width_bytes; 42 | 43 | uint64_t limit_samples; 44 | uint64_t limit_samples_max; 45 | uint8_t capture_ratio; 46 | uint8_t *trigger_mask; 47 | uint8_t *trigger_value; 48 | uint8_t *trigger_mask_last; 49 | uint8_t *trigger_value_last; 50 | uint8_t *trigger_edge_mask; 51 | uint64_t delay_value; 52 | int num_stages; 53 | uint64_t num_transfers; 54 | uint8_t *raw_sample_buf; 55 | }; 56 | 57 | SR_PRIV struct ipdbg_la_tcp *ipdbg_la_tcp_new(void); 58 | SR_PRIV void ipdbg_la_tcp_free(struct ipdbg_la_tcp *tcp); 59 | SR_PRIV int ipdbg_la_tcp_open(struct ipdbg_la_tcp *tcp); 60 | SR_PRIV int ipdbg_la_tcp_close(struct ipdbg_la_tcp *tcp); 61 | SR_PRIV int ipdbg_la_tcp_receive(struct ipdbg_la_tcp *tcp, 62 | uint8_t *buf, size_t bufsize); 63 | 64 | SR_PRIV int ipdbg_la_convert_trigger(const struct sr_dev_inst *sdi); 65 | 66 | SR_PRIV struct dev_context *ipdbg_la_dev_new(void); 67 | SR_PRIV void ipdbg_la_get_addrwidth_and_datawidth( 68 | struct ipdbg_la_tcp *tcp, struct dev_context *devc); 69 | SR_PRIV int ipdbg_la_send_reset(struct ipdbg_la_tcp *tcp); 70 | SR_PRIV int ipdbg_la_request_id(struct ipdbg_la_tcp *tcp); 71 | SR_PRIV int ipdbg_la_send_start(struct ipdbg_la_tcp *tcp); 72 | SR_PRIV int ipdbg_la_send_trigger(struct dev_context *devc, 73 | struct ipdbg_la_tcp *tcp); 74 | SR_PRIV int ipdbg_la_send_delay(struct dev_context *devc, 75 | struct ipdbg_la_tcp *tcp); 76 | SR_PRIV int ipdbg_la_receive_data(int fd, int revents, void *cb_data); 77 | SR_PRIV void ipdbg_la_abort_acquisition(const struct sr_dev_inst *sdi); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /include/libsigrok/version.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2010-2012 Bert Vermeulen 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_VERSION_H 21 | #define LIBSIGROK_VERSION_H 22 | 23 | /* 24 | * Only libsigrok library builds, and only parts of the library build, 25 | * need to reference the git-version.h header file. Which contains the 26 | * version suffix, which is relevant to local development, but is not 27 | * applicable to release builds. Application builds need not bother with 28 | * internal library version details, and always can get this information 29 | * in text form for display purposes from the library at runtime. 30 | */ 31 | #if defined WANT_LIBSIGROK_GIT_VERSION_H 32 | # include 33 | #else 34 | # undef SR_PACKAGE_VERSION_STRING_SUFFIX 35 | # define SR_PACKAGE_VERSION_STRING_SUFFIX "" 36 | #endif 37 | 38 | /** 39 | * @file 40 | * 41 | * Version number definitions and macros. 42 | */ 43 | 44 | /** 45 | * @ingroup grp_versions 46 | * 47 | * @{ 48 | */ 49 | 50 | /* 51 | * Package version macros (can be used for conditional compilation). 52 | */ 53 | 54 | /** The libsigrok package 'major' version number. */ 55 | #undef SR_PACKAGE_VERSION_MAJOR 56 | 57 | /** The libsigrok package 'minor' version number. */ 58 | #undef SR_PACKAGE_VERSION_MINOR 59 | 60 | /** The libsigrok package 'micro' version number. */ 61 | #undef SR_PACKAGE_VERSION_MICRO 62 | 63 | /** The libsigrok package version ("major.minor.micro") as string. */ 64 | #define SR_PACKAGE_VERSION_STRING_PREFIX 65 | 66 | /** The libsigrok package version with git commit suffix. */ 67 | #define SR_PACKAGE_VERSION_STRING (SR_PACKAGE_VERSION_STRING_PREFIX SR_PACKAGE_VERSION_STRING_SUFFIX) 68 | 69 | /* 70 | * Library/libtool version macros (can be used for conditional compilation). 71 | */ 72 | 73 | /** The libsigrok libtool 'current' version number. */ 74 | #undef SR_LIB_VERSION_CURRENT 75 | 76 | /** The libsigrok libtool 'revision' version number. */ 77 | #undef SR_LIB_VERSION_REVISION 78 | 79 | /** The libsigrok libtool 'age' version number. */ 80 | #undef SR_LIB_VERSION_AGE 81 | 82 | /** The libsigrok libtool version ("current:revision:age") as string. */ 83 | #undef SR_LIB_VERSION_STRING 84 | 85 | /** @} */ 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /src/hardware/atten-pps3xxx/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2014 Bert Vermeulen 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_ATTEN_PPS3XXX_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_ATTEN_PPS3XXX_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | 28 | #define LOG_PREFIX "atten-pps3xxx" 29 | 30 | /* Packets to/from the device. */ 31 | #define PACKET_SIZE 24 32 | 33 | enum { 34 | PPS_3203T_3S, 35 | PPS_3203T_2S, 36 | PPS_3205T_3S, 37 | PPS_3205T_2S, 38 | PPS_3003S, 39 | PPS_3005S, 40 | }; 41 | 42 | /* Maximum number of output channels handled by this driver. */ 43 | #define MAX_CHANNELS 3 44 | 45 | #define CHANMODE_INDEPENDENT 1 << 0 46 | #define CHANMODE_SERIES 1 << 1 47 | #define CHANMODE_PARALLEL 1 << 2 48 | 49 | struct channel_spec { 50 | /* Min, max, step. */ 51 | gdouble voltage[3]; 52 | gdouble current[3]; 53 | }; 54 | 55 | struct pps_model { 56 | int modelid; 57 | const char *name; 58 | int channel_modes; 59 | int num_channels; 60 | struct channel_spec channels[MAX_CHANNELS]; 61 | }; 62 | 63 | struct per_channel_config { 64 | /* Received from device. */ 65 | gdouble output_voltage_last; 66 | gdouble output_current_last; 67 | gboolean output_enabled; 68 | /* Set by frontend. */ 69 | gdouble output_voltage_max; 70 | gdouble output_current_max; 71 | gboolean output_enabled_set; 72 | }; 73 | 74 | struct dev_context { 75 | const struct pps_model *model; 76 | 77 | gboolean acquisition_running; 78 | 79 | gboolean config_dirty; 80 | struct per_channel_config *config; 81 | /* Blocking write timeout for packet. */ 82 | int delay_ms; 83 | /* Received from device. */ 84 | int channel_mode; 85 | gboolean over_current_protection; 86 | /* Set by frontend. */ 87 | int channel_mode_set; 88 | gboolean over_current_protection_set; 89 | 90 | uint8_t packet[PACKET_SIZE]; 91 | int packet_size; 92 | 93 | }; 94 | 95 | SR_PRIV int atten_pps3xxx_receive_data(int fd, int revents, void *cb_data); 96 | SR_PRIV void send_packet(const struct sr_dev_inst *sdi, uint8_t *packet); 97 | SR_PRIV void send_config(const struct sr_dev_inst *sdi); 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /src/hardware/kecheng-kc-330b/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2013 Bert Vermeulen 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_KECHENG_KC_330B_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_KECHENG_KC_330B_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | 28 | #define LOG_PREFIX "kecheng-kc-330b" 29 | 30 | #define EP_IN (0x80 | 1) 31 | #define EP_OUT 2 32 | 33 | /* 500ms */ 34 | #define DEFAULT_SAMPLE_INTERVAL 0 35 | #define DEFAULT_ALARM_LOW 40 36 | #define DEFAULT_ALARM_HIGH 120 37 | #define DEFAULT_WEIGHT_TIME SR_MQFLAG_SPL_TIME_WEIGHT_F 38 | #define DEFAULT_WEIGHT_FREQ SR_MQFLAG_SPL_FREQ_WEIGHT_A 39 | /* Live */ 40 | #define DEFAULT_DATA_SOURCE DATA_SOURCE_LIVE 41 | 42 | enum { 43 | LIVE_SPL_IDLE, 44 | LIVE_SPL_WAIT, 45 | LOG_DATA_IDLE, 46 | LOG_DATA_WAIT, 47 | }; 48 | 49 | enum { 50 | CMD_CONFIGURE = 0x01, 51 | CMD_IDENTIFY = 0x02, 52 | CMD_SET_DATE_TIME = 0x03, 53 | CMD_GET_STATUS = 0x04, 54 | CMD_GET_LOG_INFO = 0x05, 55 | CMD_GET_LOG_DATA = 0x07, 56 | CMD_GET_LIVE_SPL = 0x08, 57 | }; 58 | 59 | enum { 60 | DATA_SOURCE_LIVE, 61 | DATA_SOURCE_MEMORY, 62 | }; 63 | 64 | enum { 65 | DEVICE_ACTIVE, 66 | DEVICE_INACTIVE, 67 | }; 68 | 69 | struct dev_context { 70 | uint64_t limit_samples; 71 | int sample_interval; 72 | int alarm_low; 73 | int alarm_high; 74 | enum sr_mqflag mqflags; 75 | int data_source; 76 | 77 | int state; 78 | gboolean config_dirty; 79 | uint64_t num_samples; 80 | uint64_t stored_samples; 81 | struct libusb_transfer *xfer; 82 | unsigned char buf[128]; 83 | 84 | gint64 last_live_request; 85 | }; 86 | 87 | SR_PRIV int kecheng_kc_330b_handle_events(int fd, int revents, void *cb_data); 88 | SR_PRIV void LIBUSB_CALL kecheng_kc_330b_receive_transfer(struct libusb_transfer *transfer); 89 | SR_PRIV int kecheng_kc_330b_configure(const struct sr_dev_inst *sdi); 90 | SR_PRIV int kecheng_kc_330b_set_date_time(struct sr_dev_inst *sdi); 91 | SR_PRIV int kecheng_kc_330b_recording_get(const struct sr_dev_inst *sdi, 92 | gboolean *tmp); 93 | SR_PRIV int kecheng_kc_330b_status_get(const struct sr_dev_inst *sdi, 94 | int *status); 95 | SR_PRIV int kecheng_kc_330b_log_info_get(const struct sr_dev_inst *sdi, 96 | unsigned char *buf); 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /src/hardware/manson-hcs-3xxx/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2014 Uwe Hermann 5 | * Copyright (C) 2014 Matthias Heidbrink 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program 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 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, see . 19 | */ 20 | 21 | #ifndef LIBSIGROK_HARDWARE_MANSON_HCS_3XXX_PROTOCOL_H 22 | #define LIBSIGROK_HARDWARE_MANSON_HCS_3XXX_PROTOCOL_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "libsigrok-internal.h" 30 | 31 | #define LOG_PREFIX "manson-hcs-3xxx" 32 | 33 | enum { 34 | MANSON_HCS_3100, 35 | MANSON_HCS_3102, 36 | MANSON_HCS_3104, 37 | MANSON_HCS_3150, 38 | MANSON_HCS_3200, 39 | MANSON_HCS_3202, 40 | MANSON_HCS_3204, 41 | MANSON_HCS_3300, 42 | MANSON_HCS_3302, 43 | MANSON_HCS_3304, 44 | MANSON_HCS_3400, 45 | MANSON_HCS_3402, 46 | MANSON_HCS_3404, 47 | MANSON_HCS_3600, 48 | MANSON_HCS_3602, 49 | MANSON_HCS_3604, 50 | }; 51 | 52 | /** Information on a single model. */ 53 | struct hcs_model { 54 | int model_id; /**< Model info */ 55 | const char *name; /**< Model name */ 56 | const char *id; /**< Model ID, like delivered by interface */ 57 | double voltage[3]; /**< Min, max, step */ 58 | double current[3]; /**< Min, max, step */ 59 | }; 60 | 61 | struct dev_context { 62 | const struct hcs_model *model; /**< Model information. */ 63 | 64 | struct sr_sw_limits limits; 65 | int64_t req_sent_at; 66 | gboolean reply_pending; 67 | 68 | float current; /**< Last current value [A] read from device. */ 69 | float current_max; /**< Output current set. */ 70 | float current_max_device;/**< Device-provided maximum output current. */ 71 | float voltage; /**< Last voltage value [V] read from device. */ 72 | float voltage_max; /**< Output voltage set. */ 73 | float voltage_max_device;/**< Device-provided maximum output voltage. */ 74 | gboolean cc_mode; /**< Device is in constant current mode (otherwise constant voltage). */ 75 | 76 | gboolean output_enabled; /**< Is the output enabled? */ 77 | 78 | char buf[50]; 79 | int buflen; 80 | }; 81 | 82 | SR_PRIV int hcs_parse_volt_curr_mode(struct sr_dev_inst *sdi, char **tokens); 83 | SR_PRIV int hcs_read_reply(struct sr_serial_dev_inst *serial, int lines, char *buf, int buflen); 84 | SR_PRIV int hcs_send_cmd(struct sr_serial_dev_inst *serial, const char *cmd, ...); 85 | SR_PRIV int hcs_receive_data(int fd, int revents, void *cb_data); 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /src/hardware/greatfet/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2019 Katherine J. Temkin 5 | * Copyright (C) 2019 Mikaela Szekely 6 | * Copyright (C) 2023 Gerhard Sittig 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef LIBSIGROK_HARDWARE_GREATFET_PROTOCOL_H 23 | #define LIBSIGROK_HARDWARE_GREATFET_PROTOCOL_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include "libsigrok-internal.h" 30 | 31 | #define LOG_PREFIX "greatfet" 32 | 33 | struct dev_context { 34 | struct sr_dev_inst *sdi; 35 | GString *usb_comm_buffer; 36 | char *firmware_version; 37 | char *serial_number; 38 | size_t channel_count; 39 | char **channel_names; 40 | size_t feed_unit_size; 41 | struct sr_sw_limits sw_limits; 42 | uint64_t samplerate; 43 | struct dev_acquisition_t { 44 | uint64_t bandwidth_threshold; 45 | size_t wire_unit_size; 46 | struct feed_queue_logic *feed_queue; 47 | size_t capture_channels; 48 | gboolean use_upper_pins; 49 | size_t channel_shift; 50 | size_t points_per_byte; 51 | uint64_t capture_samplerate; 52 | size_t firmware_bufsize; 53 | uint8_t samples_endpoint; 54 | uint8_t control_interface; 55 | uint8_t samples_interface; 56 | enum { 57 | ACQ_IDLE, 58 | ACQ_PREPARE, 59 | ACQ_RECEIVE, 60 | ACQ_SHUTDOWN, 61 | } acquisition_state; 62 | gboolean frame_begin_sent; 63 | gboolean control_interface_claimed; 64 | gboolean samples_interface_claimed; 65 | gboolean start_req_sent; 66 | } acquisition; 67 | struct dev_transfers_t { 68 | size_t transfer_bufsize; 69 | size_t transfers_count; 70 | uint8_t *transfer_buffer; 71 | struct libusb_transfer **transfers; 72 | size_t active_transfers; 73 | size_t capture_bufsize; 74 | } transfers; 75 | }; 76 | 77 | SR_PRIV int greatfet_get_serial_number(const struct sr_dev_inst *sdi); 78 | SR_PRIV int greatfet_get_version_number(const struct sr_dev_inst *sdi); 79 | 80 | SR_PRIV int greatfet_setup_acquisition(const struct sr_dev_inst *sdi); 81 | SR_PRIV int greatfet_start_acquisition(const struct sr_dev_inst *sdi); 82 | SR_PRIV void greatfet_abort_acquisition(const struct sr_dev_inst *sdi); 83 | SR_PRIV int greatfet_stop_acquisition(const struct sr_dev_inst *sdi); 84 | SR_PRIV void greatfet_release_resources(const struct sr_dev_inst *sdi); 85 | 86 | SR_PRIV int greatfet_receive_data(int fd, int revents, void *cb_data); 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /src/hardware/juntek-jds6600/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2023 Gerhard Sittig 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_JUNTEK_JDS6600_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_JUNTEK_JDS6600_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "libsigrok-internal.h" 28 | 29 | #define LOG_PREFIX "juntek-jds6600" 30 | 31 | #define MAX_GEN_CHANNELS 2 32 | 33 | struct dev_context { 34 | struct devc_dev { 35 | unsigned int device_type; 36 | char *serial_number; 37 | uint64_t max_output_frequency; 38 | size_t channel_count_gen; 39 | } device; 40 | struct devc_wave { 41 | size_t builtin_count; 42 | size_t arbitrary_count; 43 | size_t names_count; 44 | const char **names; 45 | uint32_t *fw_codes; 46 | } waveforms; 47 | struct devc_chan { 48 | gboolean enabled; 49 | uint32_t waveform_code; 50 | size_t waveform_index; 51 | double output_frequency; 52 | double amplitude; 53 | double offset; 54 | double dutycycle; 55 | } channel_config[MAX_GEN_CHANNELS]; 56 | double channels_phase; 57 | GString *quick_req; 58 | }; 59 | 60 | SR_PRIV int jds6600_identify(struct sr_dev_inst *sdi); 61 | SR_PRIV int jds6600_setup_devc(struct sr_dev_inst *sdi); 62 | 63 | SR_PRIV int jds6600_get_chans_enable(const struct sr_dev_inst *sdi); 64 | SR_PRIV int jds6600_get_waveform(const struct sr_dev_inst *sdi, size_t ch_idx); 65 | SR_PRIV int jds6600_get_frequency(const struct sr_dev_inst *sdi, size_t ch_idx); 66 | SR_PRIV int jds6600_get_amplitude(const struct sr_dev_inst *sdi, size_t ch_idx); 67 | SR_PRIV int jds6600_get_offset(const struct sr_dev_inst *sdi, size_t ch_idx); 68 | SR_PRIV int jds6600_get_dutycycle(const struct sr_dev_inst *sdi, size_t ch_idx); 69 | SR_PRIV int jds6600_get_phase_chans(const struct sr_dev_inst *sdi); 70 | 71 | SR_PRIV int jds6600_set_chans_enable(const struct sr_dev_inst *sdi); 72 | SR_PRIV int jds6600_set_waveform(const struct sr_dev_inst *sdi, size_t ch_idx); 73 | SR_PRIV int jds6600_set_frequency(const struct sr_dev_inst *sdi, size_t ch_idx); 74 | SR_PRIV int jds6600_set_amplitude(const struct sr_dev_inst *sdi, size_t ch_idx); 75 | SR_PRIV int jds6600_set_offset(const struct sr_dev_inst *sdi, size_t ch_idx); 76 | SR_PRIV int jds6600_set_dutycycle(const struct sr_dev_inst *sdi, size_t ch_idx); 77 | SR_PRIV int jds6600_set_phase_chans(const struct sr_dev_inst *sdi); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /src/hardware/hp-3457a/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2016 Alexandru Gagniuc 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_HP_3457A_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_HP_3457A_PROTOCOL_H 22 | 23 | #include 24 | #include "libsigrok-internal.h" 25 | 26 | #define LOG_PREFIX "hp-3457a" 27 | 28 | /* Information about the rear card option currently installed. */ 29 | enum card_type { 30 | CARD_UNKNOWN, 31 | REAR_TERMINALS, 32 | HP_44491A, 33 | HP_44492A, 34 | }; 35 | 36 | struct rear_card_info { 37 | unsigned int card_id; 38 | enum card_type type; 39 | const char *name; 40 | const char *cg_name; 41 | unsigned int num_channels; 42 | }; 43 | 44 | /* Possible states in an acquisition. */ 45 | enum acquisition_state { 46 | ACQ_TRIGGERED_MEASUREMENT, 47 | ACQ_REQUESTED_HIRES, 48 | ACQ_REQUESTED_RANGE, 49 | ACQ_GOT_MEASUREMENT, 50 | ACQ_REQUESTED_CHANNEL_SYNC, 51 | ACQ_GOT_CHANNEL_SYNC, 52 | }; 53 | 54 | /* Channel connector (front terminals, or rear card. */ 55 | enum channel_conn { 56 | CONN_FRONT, 57 | CONN_REAR, 58 | }; 59 | 60 | struct dev_context { 61 | /* Information about rear card option, or NULL if unknown */ 62 | const struct rear_card_info *rear_card; 63 | 64 | enum sr_mq measurement_mq; 65 | enum sr_mqflag measurement_mq_flags; 66 | enum sr_unit measurement_unit; 67 | uint64_t limit_samples; 68 | float nplc; 69 | GSList *active_channels; 70 | unsigned int num_active_channels; 71 | struct sr_channel *current_channel; 72 | 73 | enum acquisition_state acq_state; 74 | enum channel_conn input_loc; 75 | uint64_t num_samples; 76 | double base_measurement; 77 | double hires_register; 78 | double measurement_range; 79 | double last_channel_sync; 80 | }; 81 | 82 | struct channel_context { 83 | enum channel_conn location; 84 | int index; 85 | }; 86 | 87 | SR_PRIV const struct rear_card_info *hp_3457a_probe_rear_card(struct sr_scpi_dev_inst *scpi); 88 | SR_PRIV int hp_3457a_receive_data(int fd, int revents, void *cb_data); 89 | SR_PRIV int hp_3457a_set_mq(const struct sr_dev_inst *sdi, enum sr_mq mq, 90 | enum sr_mqflag mq_flags); 91 | SR_PRIV int hp_3457a_set_nplc(const struct sr_dev_inst *sdi, float nplc); 92 | SR_PRIV int hp_3457a_select_input(const struct sr_dev_inst *sdi, 93 | enum channel_conn loc); 94 | SR_PRIV int hp_3457a_send_scan_list(const struct sr_dev_inst *sdi, 95 | unsigned int *channels, size_t len); 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /src/hardware/baylibre-acme/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2015 Bartosz Golaszewski 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_BAYLIBRE_ACME_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_BAYLIBRE_ACME_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "libsigrok-internal.h" 28 | 29 | #define LOG_PREFIX "baylibre-acme" 30 | 31 | /* We support up to 8 energy/temperature probes. */ 32 | #define MAX_PROBES 8 33 | 34 | /* 35 | * Temperature probes can be connected to the last four ports on the 36 | * ACME cape. When scanning, first look for temperature probes starting 37 | * from this index. 38 | */ 39 | #define TEMP_PRB_START_INDEX 4 40 | 41 | #define ENRG_PROBE_NAME "ina226" 42 | #define TEMP_PROBE_NAME "tmp435" 43 | 44 | /* For the user we number the probes starting from 1. */ 45 | #define PROBE_NUM(n) ((n) + 1) 46 | 47 | enum probe_type { 48 | PROBE_ENRG = 1, 49 | PROBE_TEMP, 50 | }; 51 | 52 | struct dev_context { 53 | uint64_t samplerate; 54 | struct sr_sw_limits limits; 55 | 56 | uint32_t num_channels; 57 | uint64_t samples_missed; 58 | int timer_fd; 59 | GIOChannel *channel; 60 | }; 61 | 62 | SR_PRIV uint8_t bl_acme_get_enrg_addr(int index); 63 | SR_PRIV uint8_t bl_acme_get_temp_addr(int index); 64 | 65 | SR_PRIV gboolean bl_acme_is_sane(void); 66 | 67 | SR_PRIV gboolean bl_acme_detect_probe(unsigned int addr, 68 | int prb_num, const char *prb_name); 69 | SR_PRIV gboolean bl_acme_register_probe(struct sr_dev_inst *sdi, int type, 70 | unsigned int addr, int prb_num); 71 | 72 | SR_PRIV int bl_acme_get_probe_type(const struct sr_channel_group *cg); 73 | SR_PRIV int bl_acme_probe_has_pws(const struct sr_channel_group *cg); 74 | 75 | SR_PRIV void bl_acme_maybe_set_update_interval(const struct sr_dev_inst *sdi, 76 | uint64_t samplerate); 77 | 78 | SR_PRIV int bl_acme_get_shunt(const struct sr_channel_group *cg, 79 | uint64_t *shunt); 80 | SR_PRIV int bl_acme_set_shunt(const struct sr_channel_group *cg, 81 | uint64_t shunt); 82 | SR_PRIV int bl_acme_read_power_state(const struct sr_channel_group *cg, 83 | gboolean *off); 84 | SR_PRIV int bl_acme_set_power_off(const struct sr_channel_group *cg, 85 | gboolean off); 86 | 87 | SR_PRIV int bl_acme_receive_data(int fd, int revents, void *cb_data); 88 | 89 | SR_PRIV int bl_acme_open_channel(struct sr_channel *ch); 90 | 91 | SR_PRIV void bl_acme_close_channel(struct sr_channel *ch); 92 | #endif 93 | -------------------------------------------------------------------------------- /src/transform/scale.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2015 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "libsigrok-internal.h" 24 | 25 | #define LOG_PREFIX "transform/scale" 26 | 27 | struct context { 28 | struct sr_rational factor; 29 | }; 30 | 31 | static int init(struct sr_transform *t, GHashTable *options) 32 | { 33 | struct context *ctx; 34 | 35 | if (!t || !t->sdi || !options) 36 | return SR_ERR_ARG; 37 | 38 | t->priv = ctx = g_malloc0(sizeof(struct context)); 39 | 40 | g_variant_get(g_hash_table_lookup(options, "factor"), "(xt)", 41 | &ctx->factor.p, &ctx->factor.q); 42 | 43 | return SR_OK; 44 | } 45 | 46 | static int receive(const struct sr_transform *t, 47 | struct sr_datafeed_packet *packet_in, 48 | struct sr_datafeed_packet **packet_out) 49 | { 50 | struct context *ctx; 51 | const struct sr_datafeed_analog *analog; 52 | 53 | if (!t || !t->sdi || !packet_in || !packet_out) 54 | return SR_ERR_ARG; 55 | ctx = t->priv; 56 | 57 | switch (packet_in->type) { 58 | case SR_DF_ANALOG: 59 | analog = packet_in->payload; 60 | analog->encoding->scale.p *= ctx->factor.p; 61 | analog->encoding->scale.q *= ctx->factor.q; 62 | break; 63 | default: 64 | sr_spew("Unsupported packet type %d, ignoring.", packet_in->type); 65 | break; 66 | } 67 | 68 | /* Return the in-place-modified packet. */ 69 | *packet_out = packet_in; 70 | 71 | return SR_OK; 72 | } 73 | 74 | static int cleanup(struct sr_transform *t) 75 | { 76 | struct context *ctx; 77 | 78 | if (!t || !t->sdi) 79 | return SR_ERR_ARG; 80 | ctx = t->priv; 81 | 82 | g_free(ctx); 83 | t->priv = NULL; 84 | 85 | return SR_OK; 86 | } 87 | 88 | static struct sr_option options[] = { 89 | { "factor", "Factor", "Factor by which to scale the analog values", NULL, NULL }, 90 | ALL_ZERO 91 | }; 92 | 93 | static const struct sr_option *get_options(void) 94 | { 95 | int64_t p = 1; 96 | uint64_t q = 1; 97 | 98 | /* Default to a scaling factor of 1.0. */ 99 | if (!options[0].def) 100 | options[0].def = g_variant_ref_sink(g_variant_new("(xt)", &p, &q)); 101 | 102 | return options; 103 | } 104 | 105 | SR_PRIV struct sr_transform_module transform_scale = { 106 | .id = "scale", 107 | .name = "Scale", 108 | .desc = "Scale analog values by a specified factor", 109 | .options = get_options, 110 | .init = init, 111 | .receive = receive, 112 | .cleanup = cleanup, 113 | }; 114 | -------------------------------------------------------------------------------- /src/hardware/lecroy-xstream/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2013 poljar (Damir Jelić) 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_LECROY_XSTREAM_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_LECROY_XSTREAM_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "libsigrok-internal.h" 28 | 29 | #define LOG_PREFIX "lecroy-xstream" 30 | 31 | #define MAX_INSTRUMENT_VERSIONS 10 32 | #define MAX_COMMAND_SIZE 48 33 | #define MAX_ANALOG_CHANNEL_COUNT 4 34 | 35 | struct scope_config { 36 | const char *name[MAX_INSTRUMENT_VERSIONS]; 37 | const uint8_t analog_channels; 38 | 39 | const char *(*analog_names)[]; 40 | 41 | const char *(*coupling_options)[]; 42 | const uint8_t num_coupling_options; 43 | 44 | const char *(*trigger_sources)[]; 45 | const uint8_t num_trigger_sources; 46 | 47 | const char *(*trigger_slopes)[]; 48 | const uint8_t num_trigger_slopes; 49 | 50 | const uint64_t (*timebases)[][2]; 51 | const uint8_t num_timebases; 52 | 53 | const uint64_t (*vdivs)[][2]; 54 | const uint8_t num_vdivs; 55 | 56 | const uint8_t num_xdivs; 57 | const uint8_t num_ydivs; 58 | }; 59 | 60 | struct analog_channel_state { 61 | int coupling; 62 | 63 | int vdiv; 64 | float vertical_offset; 65 | 66 | gboolean state; 67 | }; 68 | 69 | struct scope_state { 70 | struct analog_channel_state *analog_channels; 71 | 72 | int timebase; 73 | float horiz_triggerpos; 74 | 75 | int trigger_source; 76 | int trigger_slope; 77 | uint64_t sample_rate; 78 | }; 79 | 80 | struct dev_context { 81 | const void *model_config; 82 | void *model_state; 83 | 84 | struct sr_channel_group **analog_groups; 85 | 86 | GSList *enabled_channels; 87 | GSList *current_channel; 88 | uint64_t num_frames; 89 | 90 | uint64_t frame_limit; 91 | }; 92 | 93 | SR_PRIV int lecroy_xstream_init_device(struct sr_dev_inst *sdi); 94 | SR_PRIV int lecroy_xstream_request_data(const struct sr_dev_inst *sdi); 95 | SR_PRIV int lecroy_xstream_receive_data(int fd, int revents, void *cb_data); 96 | 97 | SR_PRIV void lecroy_xstream_state_free(struct scope_state *state); 98 | SR_PRIV int lecroy_xstream_state_get(struct sr_dev_inst *sdi); 99 | SR_PRIV int lecroy_xstream_channel_state_set(const struct sr_dev_inst *sdi, 100 | const int ch_index, gboolean ch_state); 101 | SR_PRIV int lecroy_xstream_update_sample_rate(const struct sr_dev_inst *sdi, 102 | int num_of_samples); 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /bindings/swig/templates.i: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2015 Martin Ling 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | %{ 21 | #include 22 | using namespace std; 23 | %} 24 | 25 | %include "std_string.i" 26 | %include "std_shared_ptr.i" 27 | %include "std_vector.i" 28 | %include "std_map.i" 29 | #ifdef SWIGJAVA 30 | namespace std { 31 | template class set {}; 32 | } 33 | #else 34 | %include "std_set.i" 35 | #endif 36 | 37 | %template(StringMap) std::map; 38 | 39 | %template(DriverMap) 40 | std::map >; 41 | %template(InputFormatMap) 42 | std::map >; 43 | %template(OutputFormatMap) 44 | std::map >; 45 | 46 | %template(HardwareDeviceVector) 47 | std::vector >; 48 | 49 | %template(DeviceVector) 50 | std::vector >; 51 | 52 | %template(ChannelVector) 53 | std::vector >; 54 | 55 | %template(ChannelGroupMap) 56 | std::map >; 57 | 58 | /* Workaround for SWIG bug. The vector template instantiation 59 | isn't needed but somehow fixes a bug that stops the wrapper 60 | for the map instantiation from compiling. */ 61 | %template(ConfigVector) 62 | std::vector; 63 | 64 | %template(ConfigMap) 65 | std::map; 66 | 67 | %template(ConfigSet) 68 | std::set; 69 | 70 | /* Workaround for SWIG bug. The vector template instantiation 71 | isn't needed but somehow fixes a bug that stops the wrapper 72 | for the set instantiation from compiling. */ 73 | %template(CapabilityVector) 74 | std::vector; 75 | 76 | %template(CapabilitySet) 77 | std::set; 78 | 79 | %template(OptionVector) 80 | std::vector >; 81 | %template(OptionMap) 82 | std::map >; 83 | 84 | %template(VariantVector) 85 | std::vector; 86 | %template(VariantMap) 87 | std::map; 88 | 89 | %template(QuantityFlagVector) 90 | std::vector; 91 | 92 | %template(TriggerStageVector) 93 | std::vector >; 94 | 95 | %template(TriggerMatchVector) 96 | std::vector >; 97 | -------------------------------------------------------------------------------- /src/hardware/ftdi-la/protocol.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2015 Sergey Alirzaev 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include "protocol.h" 23 | 24 | static void send_samples(struct sr_dev_inst *sdi, uint64_t samples_to_send) 25 | { 26 | struct sr_datafeed_packet packet; 27 | struct sr_datafeed_logic logic; 28 | struct dev_context *devc; 29 | 30 | sr_spew("Sending %" PRIu64 " samples.", samples_to_send); 31 | 32 | devc = sdi->priv; 33 | 34 | packet.type = SR_DF_LOGIC; 35 | packet.payload = &logic; 36 | logic.length = samples_to_send; 37 | logic.unitsize = 1; 38 | logic.data = devc->data_buf; 39 | sr_session_send(sdi, &packet); 40 | 41 | devc->samples_sent += samples_to_send; 42 | devc->bytes_received -= samples_to_send; 43 | } 44 | 45 | SR_PRIV int ftdi_la_set_samplerate(struct dev_context *devc) 46 | { 47 | int ret; 48 | 49 | ret = ftdi_set_baudrate(devc->ftdic, 50 | devc->cur_samplerate / devc->desc->samplerate_div); 51 | if (ret < 0) { 52 | sr_err("Failed to set baudrate (%d): %s.", devc->cur_samplerate, 53 | ftdi_get_error_string(devc->ftdic)); 54 | return SR_ERR; 55 | } 56 | return SR_OK; 57 | } 58 | 59 | SR_PRIV int ftdi_la_receive_data(int fd, int revents, void *cb_data) 60 | { 61 | struct sr_dev_inst *sdi; 62 | struct dev_context *devc; 63 | int bytes_read; 64 | uint64_t n; 65 | 66 | (void)fd; 67 | (void)revents; 68 | 69 | if (!(sdi = cb_data)) 70 | return TRUE; 71 | if (!(devc = sdi->priv)) 72 | return TRUE; 73 | if (!(revents == G_IO_IN || revents == 0)) 74 | return TRUE; 75 | if (!devc->ftdic) 76 | return TRUE; 77 | 78 | /* Get a block of data. */ 79 | bytes_read = ftdi_read_data(devc->ftdic, devc->data_buf, DATA_BUF_SIZE); 80 | if (bytes_read < 0) { 81 | sr_err("Failed to read FTDI data (%d): %s.", 82 | bytes_read, ftdi_get_error_string(devc->ftdic)); 83 | sr_dev_acquisition_stop(sdi); 84 | return FALSE; 85 | } 86 | if (bytes_read == 0) { 87 | sr_spew("Received 0 bytes, nothing to do."); 88 | return TRUE; 89 | } 90 | sr_spew("Got some data."); 91 | devc->bytes_received += bytes_read; 92 | 93 | n = devc->samples_sent + devc->bytes_received; 94 | 95 | if (devc->limit_samples && (n >= devc->limit_samples)) { 96 | send_samples(sdi, devc->limit_samples - devc->samples_sent); 97 | sr_info("Requested number of samples reached."); 98 | sr_dev_acquisition_stop(sdi); 99 | return TRUE; 100 | } else { 101 | send_samples(sdi, devc->bytes_received); 102 | } 103 | 104 | return TRUE; 105 | } 106 | -------------------------------------------------------------------------------- /src/hardware/agilent-dmm/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2012 Bert Vermeulen 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_AGILENT_DMM_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_AGILENT_DMM_PROTOCOL_H 22 | 23 | #define LOG_PREFIX "agilent-dmm" 24 | 25 | #define MAX_CHANNELS 3 26 | #define AGDMM_BUFSIZE 256 27 | 28 | /* Always USB-serial, 1ms is plenty. */ 29 | #define SERIAL_WRITE_TIMEOUT_MS 1 30 | 31 | #define DEFAULT_DATA_SOURCE DATA_SOURCE_LIVE 32 | 33 | enum { 34 | DATA_SOURCE_LIVE, 35 | DATA_SOURCE_LOG_HAND, 36 | DATA_SOURCE_LOG_TRIG, 37 | DATA_SOURCE_LOG_AUTO, 38 | DATA_SOURCE_LOG_EXPO, 39 | }; 40 | 41 | /* Supported models */ 42 | enum { 43 | AGILENT_U1231 = 1, 44 | AGILENT_U1232, 45 | AGILENT_U1233, 46 | 47 | AGILENT_U1241, 48 | AGILENT_U1242, 49 | 50 | KEYSIGHT_U1241C, 51 | KEYSIGHT_U1242C, 52 | 53 | AGILENT_U1251, 54 | AGILENT_U1252, 55 | AGILENT_U1253, 56 | 57 | AGILENT_U1271, 58 | AGILENT_U1272, 59 | AGILENT_U1273, 60 | AGILENT_U1273AX, 61 | 62 | KEYSIGHT_U1281, 63 | KEYSIGHT_U1282, 64 | }; 65 | 66 | /* Supported device profiles */ 67 | struct agdmm_profile { 68 | int model; 69 | const char *modelname; 70 | int nb_channels; 71 | const struct agdmm_job *jobs_live; 72 | const struct agdmm_job *jobs_log; 73 | const struct agdmm_recv *recvs; 74 | }; 75 | 76 | struct dev_context { 77 | const struct agdmm_profile *profile; 78 | struct sr_sw_limits limits; 79 | int data_source; 80 | 81 | const struct agdmm_job *jobs; 82 | int current_job; 83 | gboolean job_running; 84 | gboolean job_again; 85 | int64_t jobs_start[8]; 86 | unsigned char buf[AGDMM_BUFSIZE]; 87 | int buflen; 88 | uint64_t cur_samplerate; 89 | struct sr_channel *cur_channel; 90 | struct sr_channel *cur_conf; 91 | int cur_sample; 92 | int cur_mq[MAX_CHANNELS]; 93 | int cur_unit[MAX_CHANNELS]; 94 | int cur_mqflags[MAX_CHANNELS]; 95 | int cur_digits[MAX_CHANNELS]; 96 | int cur_encoding[MAX_CHANNELS]; 97 | int cur_exponent[MAX_CHANNELS]; 98 | int mode_tempaux; 99 | int mode_continuity; 100 | int mode_squarewave; 101 | int mode_dbm_dbv; 102 | }; 103 | 104 | enum job_type { 105 | JOB_AGAIN = 1, 106 | JOB_STOP, 107 | JOB_CONF, 108 | JOB_STAT, 109 | JOB_FETC, 110 | JOB_LOG, 111 | }; 112 | 113 | struct agdmm_job { 114 | enum job_type type; 115 | int interval; 116 | int (*send) (const struct sr_dev_inst *sdi); 117 | }; 118 | 119 | struct agdmm_recv { 120 | const char *recv_regex; 121 | int (*recv) (const struct sr_dev_inst *sdi, GMatchInfo *match); 122 | }; 123 | 124 | SR_PRIV int agdmm_receive_data(int fd, int revents, void *cb_data); 125 | 126 | #endif 127 | -------------------------------------------------------------------------------- /src/hardware/devantech-eth008/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2023 Gerhard Sittig 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_DEVANTECH_ETH008_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_DEVANTECH_ETH008_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "libsigrok-internal.h" 28 | 29 | #define LOG_PREFIX "devantech-eth008" 30 | 31 | /* 32 | * See developer notes in the protocol.c source file for details on the 33 | * feature set and communication protocol variants across the series. 34 | * This 'model' description tells their discriminating properties apart. 35 | */ 36 | struct devantech_eth008_model { 37 | uint8_t code; /**!< model ID */ 38 | const char *name; /**!< model name */ 39 | size_t ch_count_do; /**!< digital output channel count */ 40 | size_t ch_count_di; /**!< digital input channel count */ 41 | size_t ch_count_ai; /**!< analog input channel count */ 42 | uint8_t min_serno_fw; /**!< min FW version to get serial nr */ 43 | size_t width_do; /**!< digital output image width */ 44 | size_t width_di; /**!< digital input image width */ 45 | uint32_t mask_do_missing; /**!< missing digital output channels */ 46 | }; 47 | 48 | struct channel_group_context { 49 | size_t index; 50 | size_t number; 51 | enum devantech_eth008_channel_type { 52 | DV_CH_DIGITAL_OUTPUT, 53 | DV_CH_DIGITAL_INPUT, 54 | DV_CH_ANALOG_INPUT, 55 | DV_CH_SUPPLY_VOLTAGE, 56 | } ch_type; 57 | }; 58 | 59 | struct dev_context { 60 | uint8_t model_code, hardware_version, firmware_version; 61 | const struct devantech_eth008_model *model; 62 | uint32_t mask_do; 63 | uint32_t curr_do; 64 | uint32_t curr_di; 65 | }; 66 | 67 | SR_PRIV int devantech_eth008_get_model(struct sr_serial_dev_inst *serial, 68 | uint8_t *model_code, uint8_t *hw_version, uint8_t *fw_version); 69 | SR_PRIV int devantech_eth008_get_serno(struct sr_serial_dev_inst *serial, 70 | char *text_buffer, size_t text_length); 71 | SR_PRIV int devantech_eth008_cache_state(const struct sr_dev_inst *sdi); 72 | SR_PRIV int devantech_eth008_query_do(const struct sr_dev_inst *sdi, 73 | const struct sr_channel_group *cg, gboolean *on); 74 | SR_PRIV int devantech_eth008_setup_do(const struct sr_dev_inst *sdi, 75 | const struct sr_channel_group *cg, gboolean on); 76 | SR_PRIV int devantech_eth008_query_di(const struct sr_dev_inst *sdi, 77 | const struct sr_channel_group *cg, gboolean *on); 78 | SR_PRIV int devantech_eth008_query_ai(const struct sr_dev_inst *sdi, 79 | const struct sr_channel_group *cg, uint16_t *adc_value); 80 | SR_PRIV int devantech_eth008_query_supply(const struct sr_dev_inst *sdi, 81 | const struct sr_channel_group *cg, uint16_t *millivolts); 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /src/hardware/gwinstek-psp/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2023 ettom <36895504+ettom@users.noreply.github.com> 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_GWINSTEK_PSP_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_GWINSTEK_PSP_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | 28 | #define LOG_PREFIX "gwinstek-psp" 29 | 30 | #define GWINSTEK_PSP_PROCESSING_TIME_MS 50 31 | #define GWINSTEK_PSP_STATUS_POLL_TIME_MS 245 /**< 'L' query response time. */ 32 | 33 | /* Information on single model */ 34 | struct gwinstek_psp_model { 35 | const char *vendor; /**< Vendor name */ 36 | const char *name; /**< Model name */ 37 | const double *voltage; /**< References: Min, max, step */ 38 | const double *current; /**< References: Min, max, step */ 39 | }; 40 | 41 | struct dev_context { 42 | const struct gwinstek_psp_model *model; /**< Model information. */ 43 | 44 | struct sr_sw_limits limits; 45 | int64_t next_req_time; 46 | int64_t last_status_query_time; 47 | GMutex rw_mutex; 48 | 49 | float power; /**< Last power value [W] read from device. */ 50 | float current; /**< Last current value [A] read from device. */ 51 | float current_limit; /**< Output current set. */ 52 | float voltage; /**< Last voltage value [V] read from device. */ 53 | float voltage_or_0; /**< Same, but 0 if output is off. */ 54 | int voltage_limit; /**< Output voltage limit. */ 55 | 56 | /*< Output voltage target. The device has no means to query this 57 | * directly. It's equal to the voltage if the output is disabled 58 | * (detectable) or the device is in CV mode (undetectable).*/ 59 | float voltage_target; 60 | int64_t voltage_target_updated; /**< When device last reported a voltage target. */ 61 | 62 | float set_voltage_target; /**< The last set output voltage target. */ 63 | int64_t set_voltage_target_updated; /**< When the voltage target was last set. */ 64 | 65 | gboolean output_enabled; /**< Is the output enabled? */ 66 | gboolean otp_active; /**< Is the overtemperature protection active? */ 67 | 68 | int msg_terminator_len; /** < 2 or 3, depending on the URPSP1/2 setting */ 69 | }; 70 | 71 | SR_PRIV int gwinstek_psp_send_cmd(struct sr_serial_dev_inst *serial, 72 | struct dev_context *devc, const char* cmd, gboolean lock); 73 | SR_PRIV int gwinstek_psp_check_terminator(struct sr_serial_dev_inst *serial, 74 | struct dev_context *devc); 75 | SR_PRIV int gwinstek_psp_get_initial_voltage_target(struct dev_context *devc); 76 | SR_PRIV int gwinstek_psp_get_all_values(struct sr_serial_dev_inst *serial, 77 | struct dev_context *devc); 78 | SR_PRIV int gwinstek_psp_receive_data(int fd, int revents, void *cb_data); 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /src/hardware/sysclk-sla5032/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2019 Vitaliy Vorobyov 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_SYSCLK_SLA5032_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_SYSCLK_SLA5032_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #define LOG_PREFIX "sysclk-sla5032" 30 | 31 | /* Maximum configurable sample count limit. */ 32 | #define MAX_LIMIT_SAMPLES (64 * 1024 * 1024) 33 | #define MIN_LIMIT_SAMPLES 512 34 | 35 | /* USB vendor and product IDs. */ 36 | enum { 37 | USB_VID_SYSCLK = 0x2961, 38 | USB_PID_SLA5032 = 0x66B0, 39 | }; 40 | 41 | /* USB device characteristics. */ 42 | enum { 43 | USB_CONFIG = 1, 44 | USB_INTERFACE = 0, 45 | USB_CMD_TIMEOUT_MS = 5000, 46 | USB_REPLY_TIMEOUT_MS = 500000, 47 | USB_DATA_TIMEOUT_MS = 2000, 48 | }; 49 | 50 | /* USB device end points. */ 51 | enum usb_endpoint { 52 | EP_COMMAND = 4 | LIBUSB_ENDPOINT_OUT, 53 | EP_REPLY = 8 | LIBUSB_ENDPOINT_IN, 54 | EP_DATA = 6 | LIBUSB_ENDPOINT_IN, 55 | }; 56 | 57 | 58 | /* Common indicator for no or unknown FPGA config. */ 59 | enum { 60 | FPGA_NOCONF = -1, 61 | FPGA_CONF, 62 | }; 63 | 64 | /** Acquisition protocol states. */ 65 | enum protocol_state { 66 | /* idle states */ 67 | STATE_IDLE = 0, 68 | STATE_STATUS_WAIT, 69 | /* device command states */ 70 | STATE_START_CAPTURE, 71 | STATE_STOP_CAPTURE, 72 | STATE_READ_PREPARE, 73 | STATE_READ_FINISH, 74 | /* command followed by response */ 75 | STATE_EXPECT_RESPONSE = 1 << 3, 76 | STATE_STATUS_REQUEST = STATE_EXPECT_RESPONSE, 77 | STATE_LENGTH_REQUEST, 78 | STATE_READ_REQUEST, 79 | }; 80 | 81 | /** SLA5032 protocol command ID codes. */ 82 | enum command_id { 83 | CMD_INIT_FW_UPLOAD = 1, 84 | CMD_UPLOAD_FW_CHUNK = 2, 85 | CMD_READ_REG = 3, 86 | CMD_WRITE_REG = 4, 87 | CMD_READ_MEM = 5, 88 | CMD_READ_DATA = 7, 89 | }; 90 | 91 | struct dev_context { 92 | uint64_t samplerate; /* requested samplerate */ 93 | uint64_t limit_samples; /* requested capture length (samples) */ 94 | uint64_t capture_ratio; 95 | 96 | uint64_t channel_mask; /* bit mask of enabled channels */ 97 | uint64_t trigger_mask; /* trigger enable mask */ 98 | uint64_t trigger_edge_mask; /* trigger type mask */ 99 | uint64_t trigger_values; /* trigger level/slope bits */ 100 | 101 | struct soft_trigger_logic *stl; 102 | gboolean trigger_fired; 103 | 104 | int active_fpga_config; /* FPGA configuration index */ 105 | 106 | enum protocol_state state; /* async protocol state */ 107 | }; 108 | 109 | SR_PRIV int sla5032_start_acquisition(const struct sr_dev_inst *sdi); 110 | SR_PRIV int sla5032_apply_fpga_config(const struct sr_dev_inst *sdi); 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /src/conversion.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2017 Soeren Apel 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | /** 21 | * @file 22 | * 23 | * Conversion helper functions. 24 | */ 25 | 26 | #include 27 | #include "libsigrok-internal.h" 28 | 29 | /** @cond PRIVATE */ 30 | #define LOG_PREFIX "conv" 31 | /** @endcond */ 32 | 33 | /** 34 | * Convert analog values to logic values by using a fixed threshold. 35 | * 36 | * @param[in] analog The analog input values. 37 | * @param[in] threshold The threshold to use. 38 | * @param[out] output The converted output values; either 0 or 1. Must provide 39 | * space for count bytes. 40 | * @param[in] count The number of samples to process. 41 | * 42 | * @return SR_OK on success or SR_ERR on failure. 43 | */ 44 | SR_API int sr_a2l_threshold(const struct sr_datafeed_analog *analog, 45 | float threshold, uint8_t *output, uint64_t count) 46 | { 47 | float *input; 48 | 49 | if (!analog->encoding->is_float) { 50 | input = g_try_malloc(sizeof(float) * count); 51 | if (!input) 52 | return SR_ERR; 53 | 54 | sr_analog_to_float(analog, input); 55 | } else 56 | input = analog->data; 57 | 58 | for (uint64_t i = 0; i < count; i++) 59 | output[i] = (input[i] >= threshold) ? 1 : 0; 60 | 61 | if (!analog->encoding->is_float) 62 | g_free(input); 63 | 64 | return SR_OK; 65 | } 66 | 67 | /** 68 | * Convert analog values to logic values by using a Schmitt-trigger algorithm. 69 | * 70 | * @param analog The analog input values. 71 | * @param lo_thr The low threshold - result becomes 0 below it. 72 | * @param hi_thr The high threshold - result becomes 1 above it. 73 | * @param state The internal converter state. Must contain the state of logic 74 | * sample n-1, will contain the state of logic sample n+count upon exit. 75 | * @param output The converted output values; either 0 or 1. Must provide 76 | * space for count bytes. 77 | * @param count The number of samples to process. 78 | * 79 | * @return SR_OK on success or SR_ERR on failure. 80 | */ 81 | SR_API int sr_a2l_schmitt_trigger(const struct sr_datafeed_analog *analog, 82 | float lo_thr, float hi_thr, uint8_t *state, uint8_t *output, 83 | uint64_t count) 84 | { 85 | float *input; 86 | 87 | if (!analog->encoding->is_float) { 88 | input = g_try_malloc(sizeof(float) * count); 89 | if (!input) 90 | return SR_ERR; 91 | 92 | sr_analog_to_float(analog, input); 93 | } else 94 | input = analog->data; 95 | 96 | for (uint64_t i = 0; i < count; i++) { 97 | if (input[i] < lo_thr) 98 | *state = 0; 99 | else if (input[i] > hi_thr) 100 | *state = 1; 101 | 102 | output[i] = *state; 103 | } 104 | 105 | if (!analog->encoding->is_float) 106 | g_free(input); 107 | 108 | return SR_OK; 109 | } 110 | -------------------------------------------------------------------------------- /src/hardware/lecroy-logicstudio/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2015 Tilman Sauerbeck 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_LECROY_LOGICSTUDIO_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_LECROY_LOGICSTUDIO_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | 28 | #define LOG_PREFIX "lecroy-logicstudio" 29 | 30 | #define SAMPLE_BUF_SIZE 40960u 31 | #define CONV_8TO16_BUF_SIZE 8192 32 | #define INTR_BUF_SIZE 32 33 | 34 | struct samplerate_info; 35 | 36 | struct dev_context { 37 | struct libusb_transfer *intr_xfer; 38 | struct libusb_transfer *bulk_xfer; 39 | 40 | const struct samplerate_info *samplerate_info; 41 | 42 | /** 43 | * When the device is opened, this will point at a buffer 44 | * of SAMPLE_BUF_SIZE bytes. 45 | */ 46 | uint8_t *fetched_samples; 47 | 48 | /** 49 | * Used to convert 8 bit samples (8 channels) to 16 bit samples 50 | * (16 channels), thus only used in 8 channel mode. 51 | * Holds CONV_8TO16_BUF_SIZE bytes. 52 | */ 53 | uint16_t *conv8to16; 54 | 55 | int64_t fw_updated; /* Time of last FX2 firmware upload. */ 56 | 57 | /** The pre-trigger capture ratio in percent. */ 58 | uint64_t capture_ratio; 59 | 60 | uint64_t earliest_sample; 61 | uint64_t trigger_sample; 62 | 63 | /** The number of eight-channel groups enabled (either 1 or 2). */ 64 | uint32_t num_enabled_channel_groups; 65 | 66 | /** 67 | * The number of samples to acquire (in thousands). 68 | * This is not customizable, but depending on the number 69 | * of enabled channel groups. 70 | */ 71 | uint32_t num_thousand_samples; 72 | 73 | uint32_t total_received_sample_bytes; 74 | 75 | /** Mask of enabled channels. */ 76 | uint16_t channel_mask; 77 | 78 | uint16_t acquisition_id; 79 | 80 | gboolean want_trigger; 81 | gboolean abort_acquisition; 82 | 83 | /** 84 | * These two magic values are required in order to fix a sample 85 | * buffer corruption. Before the first acquisition is run, they 86 | * need to be set to 0. 87 | */ 88 | uint8_t magic_arm_trigger; 89 | uint8_t magic_fetch_samples; 90 | 91 | /** 92 | * Buffer for interrupt transfers (acquisition state notifications). 93 | */ 94 | uint8_t intr_buf[INTR_BUF_SIZE]; 95 | }; 96 | 97 | SR_PRIV void lls_update_channel_mask(const struct sr_dev_inst *sdi); 98 | 99 | SR_PRIV int lls_set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate); 100 | SR_PRIV uint64_t lls_get_samplerate(const struct sr_dev_inst *sdi); 101 | 102 | SR_PRIV int lls_setup_acquisition(const struct sr_dev_inst *sdi); 103 | SR_PRIV int lls_start_acquisition(const struct sr_dev_inst *sdi); 104 | SR_PRIV int lls_stop_acquisition(const struct sr_dev_inst *sdi); 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /src/minilzo/minilzo.h: -------------------------------------------------------------------------------- 1 | /* minilzo.h -- mini subset of the LZO real-time data compression library 2 | 3 | This file is part of the LZO real-time data compression library. 4 | 5 | Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer 6 | All Rights Reserved. 7 | 8 | The LZO library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU General Public License as 10 | published by the Free Software Foundation; either version 2 of 11 | the License, or (at your option) any later version. 12 | 13 | The LZO library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with the LZO library; see the file COPYING. 20 | If not, write to the Free Software Foundation, Inc., 21 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 22 | 23 | Markus F.X.J. Oberhumer 24 | 25 | http://www.oberhumer.com/opensource/lzo/ 26 | */ 27 | 28 | /* 29 | * NOTE: 30 | * the full LZO package can be found at 31 | * http://www.oberhumer.com/opensource/lzo/ 32 | */ 33 | 34 | 35 | #ifndef __MINILZO_H_INCLUDED 36 | #define __MINILZO_H_INCLUDED 1 37 | 38 | #define MINILZO_VERSION 0x20a0 /* 2.10 */ 39 | 40 | #if defined(__LZOCONF_H_INCLUDED) 41 | # error "you cannot use both LZO and miniLZO" 42 | #endif 43 | 44 | /* internal Autoconf configuration file - only used when building miniLZO */ 45 | #ifdef MINILZO_HAVE_CONFIG_H 46 | # include 47 | #endif 48 | #include 49 | #include 50 | 51 | #ifndef __LZODEFS_H_INCLUDED 52 | #include "lzodefs.h" 53 | #endif 54 | #undef LZO_HAVE_CONFIG_H 55 | #include "lzoconf.h" 56 | 57 | #if !defined(LZO_VERSION) || (LZO_VERSION != MINILZO_VERSION) 58 | # error "version mismatch in header files" 59 | #endif 60 | 61 | 62 | #ifdef __cplusplus 63 | extern "C" { 64 | #endif 65 | 66 | 67 | /*********************************************************************** 68 | // 69 | ************************************************************************/ 70 | 71 | /* Memory required for the wrkmem parameter. 72 | * When the required size is 0, you can also pass a NULL pointer. 73 | */ 74 | 75 | #define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS 76 | #define LZO1X_1_MEM_COMPRESS ((lzo_uint32_t) (16384L * lzo_sizeof_dict_t)) 77 | #define LZO1X_MEM_DECOMPRESS (0) 78 | 79 | 80 | /* compression */ 81 | LZO_EXTERN(int) 82 | lzo1x_1_compress ( const lzo_bytep src, lzo_uint src_len, 83 | lzo_bytep dst, lzo_uintp dst_len, 84 | lzo_voidp wrkmem ); 85 | 86 | /* decompression */ 87 | LZO_EXTERN(int) 88 | lzo1x_decompress ( const lzo_bytep src, lzo_uint src_len, 89 | lzo_bytep dst, lzo_uintp dst_len, 90 | lzo_voidp wrkmem /* NOT USED */ ); 91 | 92 | /* safe decompression with overrun testing */ 93 | LZO_EXTERN(int) 94 | lzo1x_decompress_safe ( const lzo_bytep src, lzo_uint src_len, 95 | lzo_bytep dst, lzo_uintp dst_len, 96 | lzo_voidp wrkmem /* NOT USED */ ); 97 | 98 | 99 | #ifdef __cplusplus 100 | } /* extern "C" */ 101 | #endif 102 | 103 | #endif /* already included */ 104 | 105 | 106 | /* vim:set ts=4 sw=4 et: */ 107 | -------------------------------------------------------------------------------- /tests/output_all.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2013 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "lib.h" 25 | 26 | /* Check whether at least one output module is available. */ 27 | START_TEST(test_output_available) 28 | { 29 | const struct sr_output_module **outputs; 30 | 31 | outputs = sr_output_list(); 32 | fail_unless(outputs != NULL, "No output modules found."); 33 | } 34 | END_TEST 35 | 36 | /* Check whether sr_output_id_get() works. */ 37 | START_TEST(test_output_id) 38 | { 39 | const struct sr_output_module **outputs; 40 | const char *id; 41 | 42 | outputs = sr_output_list(); 43 | 44 | id = sr_output_id_get(outputs[0]); 45 | fail_unless(id != NULL, "No id found in output module."); 46 | } 47 | END_TEST 48 | 49 | /* Check whether sr_output_name_get() works. */ 50 | START_TEST(test_output_name) 51 | { 52 | const struct sr_output_module **outputs; 53 | const char *name; 54 | 55 | outputs = sr_output_list(); 56 | 57 | name = sr_output_name_get(outputs[0]); 58 | fail_unless(name != NULL, "No name found in output module."); 59 | } 60 | END_TEST 61 | 62 | /* Check whether sr_output_description_get() works. */ 63 | START_TEST(test_output_desc) 64 | { 65 | const struct sr_output_module **outputs; 66 | const char *desc; 67 | 68 | outputs = sr_output_list(); 69 | 70 | desc = sr_output_description_get(outputs[0]); 71 | fail_unless(desc != NULL, "No description found in output module."); 72 | } 73 | END_TEST 74 | 75 | /* Check whether sr_output_find() works. */ 76 | START_TEST(test_output_find) 77 | { 78 | const struct sr_output_module *omod; 79 | const char *id; 80 | 81 | omod = sr_output_find("bits"); 82 | fail_unless(omod != NULL, "Couldn't find the 'bits' output module."); 83 | id = sr_output_id_get(omod); 84 | fail_unless(!strcmp(id, "bits"), "That is not the 'bits' module!"); 85 | } 86 | END_TEST 87 | 88 | /* Check whether sr_output_options_get() works. */ 89 | START_TEST(test_output_options) 90 | { 91 | const struct sr_option **opt; 92 | 93 | opt = sr_output_options_get(sr_output_find("bits")); 94 | fail_unless(opt != NULL, "Couldn't find 'bits' options."); 95 | fail_unless(!strcmp((*opt)->id, "width"), "Wrong 'bits' option found!"); 96 | } 97 | END_TEST 98 | 99 | Suite *suite_output_all(void) 100 | { 101 | Suite *s; 102 | TCase *tc; 103 | 104 | s = suite_create("output-all"); 105 | 106 | tc = tcase_create("basic"); 107 | tcase_add_test(tc, test_output_available); 108 | tcase_add_test(tc, test_output_id); 109 | tcase_add_test(tc, test_output_name); 110 | tcase_add_test(tc, test_output_desc); 111 | tcase_add_test(tc, test_output_find); 112 | tcase_add_test(tc, test_output_options); 113 | suite_add_tcase(s, tc); 114 | 115 | return s; 116 | } 117 | -------------------------------------------------------------------------------- /src/hardware/zeroplus-logic-cube/protocol.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2010-2012 Bert Vermeulen 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include "protocol.h" 23 | #include "analyzer.h" 24 | 25 | SR_PRIV size_t get_memory_size(int type) 26 | { 27 | if (type == MEMORY_SIZE_8K) 28 | return (8 * 1024); 29 | if (type <= MEMORY_SIZE_8M) 30 | return (32 * 1024) << type; 31 | return 0; 32 | } 33 | 34 | static int clz(unsigned int x) 35 | { 36 | int n = 0; 37 | if (x == 0) 38 | return 32; 39 | if (!(x & 0xFFFF0000)) { 40 | n = n + 16; 41 | x = x << 16; 42 | } 43 | if (!(x & 0xFF000000)) { 44 | n = n + 8; 45 | x = x << 8; 46 | } 47 | if (!(x & 0xF0000000)) { 48 | n = n + 4; 49 | x = x << 4; 50 | } 51 | if (!(x & 0xC0000000)) { 52 | n = n + 2; 53 | x = x << 2; 54 | } 55 | if (!(x & 0x80000000)) 56 | n = n + 1; 57 | return n; 58 | } 59 | 60 | SR_PRIV int set_limit_samples(struct dev_context *devc, uint64_t samples) 61 | { 62 | size_t mem_kb; 63 | 64 | if (samples > devc->max_sample_depth) 65 | samples = devc->max_sample_depth; 66 | 67 | devc->limit_samples = samples; 68 | 69 | if (samples <= (2 * 1024)) 70 | devc->memory_size = MEMORY_SIZE_8K; 71 | else if (samples <= (16 * 1024)) 72 | devc->memory_size = MEMORY_SIZE_64K; 73 | else 74 | devc->memory_size = 19 - clz(samples - 1); 75 | 76 | mem_kb = get_memory_size(devc->memory_size) / 1024; 77 | sr_info("Setting memory size to %zuK.", mem_kb); 78 | 79 | analyzer_set_memory_size(devc->memory_size); 80 | 81 | return SR_OK; 82 | } 83 | 84 | SR_PRIV int set_voltage_threshold(struct dev_context *devc, double thresh) 85 | { 86 | if (thresh > 6.0) 87 | thresh = 6.0; 88 | if (thresh < -6.0) 89 | thresh = -6.0; 90 | 91 | devc->cur_threshold = thresh; 92 | 93 | analyzer_set_voltage_threshold((int) round(-9.1*thresh + 62.6)); 94 | 95 | sr_info("Setting voltage threshold to %fV.", devc->cur_threshold); 96 | 97 | return SR_OK; 98 | } 99 | 100 | SR_PRIV void set_triggerbar(struct dev_context *devc) 101 | { 102 | unsigned int trigger_depth, triggerbar, ramsize_trigger; 103 | 104 | trigger_depth = get_memory_size(devc->memory_size) / 4; 105 | if (devc->limit_samples < trigger_depth) 106 | trigger_depth = devc->limit_samples; 107 | 108 | if (devc->trigger) 109 | triggerbar = (trigger_depth * devc->capture_ratio) / 100; 110 | else 111 | triggerbar = 0; 112 | 113 | ramsize_trigger = trigger_depth - triggerbar; 114 | /* Matches USB packet captures from official app/driver */ 115 | if (triggerbar > 2) 116 | triggerbar -= 2; 117 | else { 118 | ramsize_trigger -= 1; 119 | triggerbar = 0; 120 | } 121 | 122 | analyzer_set_triggerbar_address(triggerbar); 123 | analyzer_set_ramsize_trigger_address(ramsize_trigger); 124 | 125 | sr_dbg("triggerbar_address = %d(0x%x)", triggerbar, triggerbar); 126 | sr_dbg("ramsize_triggerbar_address = %d(0x%x)", 127 | ramsize_trigger, ramsize_trigger); 128 | } 129 | -------------------------------------------------------------------------------- /tests/transform_all.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2015 Uwe Hermann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "lib.h" 25 | 26 | /* Check whether at least one transform module is available. */ 27 | START_TEST(test_transform_available) 28 | { 29 | const struct sr_transform_module **transforms; 30 | 31 | transforms = sr_transform_list(); 32 | fail_unless(transforms != NULL, "No transform modules found."); 33 | } 34 | END_TEST 35 | 36 | /* Check whether sr_transform_id_get() works. */ 37 | START_TEST(test_transform_id) 38 | { 39 | const struct sr_transform_module **transforms; 40 | const char *id; 41 | 42 | transforms = sr_transform_list(); 43 | 44 | id = sr_transform_id_get(transforms[0]); 45 | fail_unless(id != NULL, "No ID found in transform module."); 46 | } 47 | END_TEST 48 | 49 | /* Check whether sr_transform_name_get() works. */ 50 | START_TEST(test_transform_name) 51 | { 52 | const struct sr_transform_module **transforms; 53 | const char *name; 54 | 55 | transforms = sr_transform_list(); 56 | 57 | name = sr_transform_name_get(transforms[0]); 58 | fail_unless(name != NULL, "No name found in transform module."); 59 | } 60 | END_TEST 61 | 62 | /* Check whether sr_transform_description_get() works. */ 63 | START_TEST(test_transform_desc) 64 | { 65 | const struct sr_transform_module **transforms; 66 | const char *desc; 67 | 68 | transforms = sr_transform_list(); 69 | 70 | desc = sr_transform_description_get(transforms[0]); 71 | fail_unless(desc != NULL, "No description found in transform module."); 72 | } 73 | END_TEST 74 | 75 | /* Check whether sr_transform_find() works. */ 76 | START_TEST(test_transform_find) 77 | { 78 | const struct sr_transform_module *tmod; 79 | const char *id; 80 | 81 | tmod = sr_transform_find("nop"); 82 | fail_unless(tmod != NULL, "Couldn't find the 'nop' transform module."); 83 | id = sr_transform_id_get(tmod); 84 | fail_unless(id != NULL, "No ID found in transform module."); 85 | fail_unless(!strcmp(id, "nop"), "That is not the 'nop' module!"); 86 | } 87 | END_TEST 88 | 89 | /* Check whether sr_transform_options_get() works. */ 90 | START_TEST(test_transform_options) 91 | { 92 | const struct sr_option **opt; 93 | 94 | opt = sr_transform_options_get(sr_transform_find("nop")); 95 | fail_unless(opt == NULL, "Transform module 'nop' doesn't have options."); 96 | } 97 | END_TEST 98 | 99 | Suite *suite_transform_all(void) 100 | { 101 | Suite *s; 102 | TCase *tc; 103 | 104 | s = suite_create("transform-all"); 105 | 106 | tc = tcase_create("basic"); 107 | tcase_add_test(tc, test_transform_available); 108 | tcase_add_test(tc, test_transform_id); 109 | tcase_add_test(tc, test_transform_name); 110 | tcase_add_test(tc, test_transform_desc); 111 | tcase_add_test(tc, test_transform_find); 112 | tcase_add_test(tc, test_transform_options); 113 | suite_add_tcase(s, tc); 114 | 115 | return s; 116 | } 117 | -------------------------------------------------------------------------------- /src/hardware/mooshimeter-dmm/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2019 Derek Hageman 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LIBSIGROK_HARDWARE_MOOSHIMETER_DMM_PROTOCOL_H 21 | #define LIBSIGROK_HARDWARE_MOOSHIMETER_DMM_PROTOCOL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "libsigrok-internal.h" 27 | 28 | #define LOG_PREFIX "mooshimeter-dmm" 29 | 30 | struct packet_rx { 31 | int sequence_number; 32 | GSList *reorder_buffer; 33 | GByteArray *contents; 34 | }; 35 | 36 | struct packet_tx { 37 | int sequence_number; 38 | }; 39 | 40 | enum tree_node_datatype { 41 | TREE_NODE_DATATYPE_PLAIN = 0, 42 | TREE_NODE_DATATYPE_LINK, 43 | TREE_NODE_DATATYPE_CHOOSER, 44 | TREE_NODE_DATATYPE_U8, 45 | TREE_NODE_DATATYPE_U16, 46 | TREE_NODE_DATATYPE_U32, 47 | TREE_NODE_DATATYPE_S8, 48 | TREE_NODE_DATATYPE_S16, 49 | TREE_NODE_DATATYPE_S32, 50 | TREE_NODE_DATATYPE_STRING, 51 | TREE_NODE_DATATYPE_BINARY, 52 | TREE_NODE_DATATYPE_FLOAT, 53 | }; 54 | 55 | union tree_value { 56 | int32_t i; 57 | float f; 58 | GByteArray *b; 59 | }; 60 | 61 | struct config_tree_node { 62 | char *name; 63 | int id; 64 | size_t index_in_parent; 65 | 66 | enum tree_node_datatype type; 67 | union tree_value value; 68 | 69 | size_t count_children; 70 | struct config_tree_node *children; 71 | 72 | uint32_t update_number; 73 | void (*on_update)(struct config_tree_node *node, void *param); 74 | void *on_update_param; 75 | }; 76 | 77 | struct dev_context { 78 | struct packet_rx rx; 79 | struct packet_tx tx; 80 | struct config_tree_node tree_root; 81 | struct config_tree_node *tree_id_lookup[0x7F]; 82 | uint32_t buffer_bps[2]; 83 | float buffer_lsb2native[2]; 84 | 85 | void (*channel_autorange[3])(const struct sr_dev_inst *sdi, float value); 86 | 87 | struct sr_sw_limits limits; 88 | struct sr_analog_meaning channel_meaning[3]; 89 | 90 | gboolean enable_value_stream; 91 | }; 92 | 93 | SR_PRIV int mooshimeter_dmm_open(const struct sr_dev_inst *sdi); 94 | SR_PRIV int mooshimeter_dmm_close(const struct sr_dev_inst *sdi); 95 | SR_PRIV int mooshimeter_dmm_set_chooser(const struct sr_dev_inst *sdi, const char *path, const char *choice); 96 | SR_PRIV int mooshimeter_dmm_set_integer(const struct sr_dev_inst *sdi, const char *path, int value); 97 | SR_PRIV int mooshimeter_dmm_set_larger_number(const struct sr_dev_inst *sdi, const char *path, const char *parent, float number); 98 | SR_PRIV gboolean mooshimeter_dmm_set_autorange(const struct sr_dev_inst *sdi, const char *path, const char *parent, float latest); 99 | SR_PRIV int mooshimeter_dmm_get_chosen_number(const struct sr_dev_inst *sdi, const char *path, const char *parent, float *number); 100 | SR_PRIV int mooshimeter_dmm_get_available_number_choices(const struct sr_dev_inst *sdi, const char *path, float **numbers, size_t *count); 101 | SR_PRIV int mooshimeter_dmm_poll(int fd, int revents, void *cb_data); 102 | SR_PRIV int mooshimeter_dmm_heartbeat(int fd, int revents, void *cb_data); 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /src/serial_hid_bu86x.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libsigrok project. 3 | * 4 | * Copyright (C) 2019 Gerhard Sittig 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /* 21 | * This implements serial communication primitives for the Brymen BU-86X 22 | * infrared adapter for handheld multimeters. The vendor's protocol spec 23 | * http://brymen.com/product-html/images/DownloadList/ProtocolList/BM860-BM860s_List/BM860-BM860s-500000-count-dual-display-DMMs-protocol.pdf 24 | * suggests that HID reports get communicated, but only report number 0 25 | * is involved, which carries a mere byte stream in 8 byte chunks each. 26 | * The frame format and bitrate are fixed, and need not get configured. 27 | * 28 | * The meter's packet consists of 24 bytes which get received in three 29 | * HID reports. Packet reception gets initiated by sending a short HID 30 | * report to the meter. It's uncertain which parts of this exchange are 31 | * specific to the adapter and to the meter. Using the IR adapter with 32 | * other devices, or using the meter with other cables/adapters may need 33 | * a little more adjustment with respect to layering. 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | #include "libsigrok-internal.h" 40 | #include "serial_hid.h" 41 | #include 42 | 43 | #define LOG_PREFIX "serial-bu86x" 44 | 45 | #ifdef HAVE_SERIAL_COMM 46 | #ifdef HAVE_LIBHIDAPI 47 | 48 | /** 49 | * @file 50 | * 51 | * Support serial-over-HID, specifically the Brymen BU-86X infrared adapter. 52 | */ 53 | 54 | #define BU86X_MAX_BYTES_PER_REQUEST 8 55 | 56 | static const struct vid_pid_item vid_pid_items_bu86x[] = { 57 | { 0x0820, 0x0001, }, 58 | ALL_ZERO 59 | }; 60 | 61 | static int bu86x_read_bytes(struct sr_serial_dev_inst *serial, 62 | uint8_t *data, int space, unsigned int timeout) 63 | { 64 | int rc; 65 | 66 | if (space > BU86X_MAX_BYTES_PER_REQUEST) 67 | space = BU86X_MAX_BYTES_PER_REQUEST; 68 | rc = ser_hid_hidapi_get_data(serial, 0, data, space, timeout); 69 | if (rc == SR_ERR_TIMEOUT) 70 | return 0; 71 | if (rc < 0) 72 | return rc; 73 | if (rc == 0) 74 | return 0; 75 | return rc; 76 | } 77 | 78 | static int bu86x_write_bytes(struct sr_serial_dev_inst *serial, 79 | const uint8_t *data, int size) 80 | { 81 | return ser_hid_hidapi_set_data(serial, 0, data, size, 0); 82 | } 83 | 84 | static struct ser_hid_chip_functions chip_bu86x = { 85 | .chipname = "bu86x", 86 | .chipdesc = "Brymen BU-86X", 87 | .vid_pid_items = vid_pid_items_bu86x, 88 | .max_bytes_per_request = BU86X_MAX_BYTES_PER_REQUEST, 89 | /* 90 | * The IR adapter's communication parameters are fixed and need 91 | * not get configured. Just silently ignore the caller's spec. 92 | */ 93 | .set_params = std_dummy_set_params, 94 | .read_bytes = bu86x_read_bytes, 95 | .write_bytes = bu86x_write_bytes, 96 | }; 97 | SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_bu86x = &chip_bu86x; 98 | 99 | #else 100 | 101 | SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_bu86x = NULL; 102 | 103 | #endif 104 | #endif 105 | --------------------------------------------------------------------------------