]> sigrok.org Git - libsigrok.git/blobdiff - include/libsigrok/libsigrok.h
serial: extend stream detect for variable length packet checkers
[libsigrok.git] / include / libsigrok / libsigrok.h
index 12bbb171a7fde5564b5bd548a6c2af1bc1429edc..5d3d23c9963f102bf0aac1b7127a412bf784829a 100644 (file)
@@ -80,15 +80,22 @@ enum sr_error_code {
        /* Update sr_strerror()/sr_strerror_name() (error.c) upon changes! */
 };
 
+/** Ternary return type for DMM/LCR/etc packet parser validity checks. */
+enum sr_valid_code {
+       SR_PACKET_INVALID = -1, /**< Certainly invalid. */
+       SR_PACKET_VALID = 0,    /**< Certainly valid. */
+       SR_PACKET_NEED_RX = +1, /**< Need more RX data. */
+};
+
 #define SR_MAX_CHANNELNAME_LEN 32
 
 /* Handy little macros */
 #define SR_HZ(n)  (n)
-#define SR_KHZ(n) ((n) * (uint64_t)(1000ULL))
-#define SR_MHZ(n) ((n) * (uint64_t)(1000000ULL))
-#define SR_GHZ(n) ((n) * (uint64_t)(1000000000ULL))
+#define SR_KHZ(n) ((n) * UINT64_C(1000))
+#define SR_MHZ(n) ((n) * UINT64_C(1000000))
+#define SR_GHZ(n) ((n) * UINT64_C(1000000000))
 
-#define SR_HZ_TO_NS(n) ((uint64_t)(1000000000ULL) / (n))
+#define SR_HZ_TO_NS(n) (UINT64_C(1000000000) / (n))
 
 /** libsigrok loglevels. */
 enum sr_loglevel {
@@ -162,8 +169,6 @@ enum sr_packettype {
        SR_DF_TRIGGER,
        /** Payload is struct sr_datafeed_logic. */
        SR_DF_LOGIC,
-       /** DEPRECATED! Use SR_DF_ANALOG instead. */
-       SR_DF_ANALOG_OLD,
        /** Beginning of frame. No payload. */
        SR_DF_FRAME_BEGIN,
        /** End of frame. No payload. */
@@ -233,6 +238,12 @@ enum sr_mq {
        SR_MQ_APPARENT_POWER,
        /** Mass */
        SR_MQ_MASS,
+       /** Harmonic ratio */
+       SR_MQ_HARMONIC_RATIO,
+       /** Energy. */
+       SR_MQ_ENERGY,
+       /** Electric charge. */
+       SR_MQ_ELECTRIC_CHARGE,
 
        /* Update sr_key_info_mq[] (hwdriver.c) upon changes! */
 };
@@ -265,7 +276,7 @@ enum sr_unit {
        SR_UNIT_SIEMENS,
        /**
         * An absolute measurement of power, in decibels, referenced to
-        * 1 milliwatt (dBu).
+        * 1 milliwatt (dBm).
         */
        SR_UNIT_DECIBEL_MW,
        /** Voltage in decibel, referenced to 1 volt (dBV). */
@@ -290,7 +301,7 @@ enum sr_unit {
        SR_UNIT_VOLT_AMPERE,
        /** Real power [W]. */
        SR_UNIT_WATT,
-       /** Consumption [Wh]. */
+       /** Energy (consumption) in watt hour [Wh]. */
        SR_UNIT_WATT_HOUR,
        /** Wind speed in meters per second. */
        SR_UNIT_METER_SECOND,
@@ -324,6 +335,12 @@ enum sr_unit {
        SR_UNIT_TOLA,
        /** Pieces (number of items). */
        SR_UNIT_PIECE,
+       /** Energy in joule. */
+       SR_UNIT_JOULE,
+       /** Electric charge in coulomb. */
+       SR_UNIT_COULOMB,
+       /** Electric charge in ampere hour [Ah]. */
+       SR_UNIT_AMPERE_HOUR,
 
        /*
         * Update unit_strings[] (analog.c) and fancyprint() (output/analog.c)
@@ -383,6 +400,8 @@ enum sr_mqflag {
        SR_MQFLAG_REFERENCE = 0x80000,
        /** Unstable value (hasn't settled yet). */
        SR_MQFLAG_UNSTABLE = 0x100000,
+       /** Measurement is four wire (e.g. Kelvin connection). */
+       SR_MQFLAG_FOUR_WIRE = 0x200000,
 
        /*
         * Update mq_strings[] (analog.c) and fancyprint() (output/analog.c)
@@ -494,24 +513,6 @@ struct sr_datafeed_logic {
        void *data;
 };
 
-/** Analog datafeed payload for type SR_DF_ANALOG_OLD. */
-struct sr_datafeed_analog_old {
-       /** The channels for which data is included in this packet. */
-       GSList *channels;
-       /** Number of samples in data */
-       int num_samples;
-       /** Measured quantity (voltage, current, temperature, and so on).
-        *  Use SR_MQ_VOLTAGE, ... */
-       int mq;
-       /** Unit in which the MQ is measured. Use SR_UNIT_VOLT, ... */
-       int unit;
-       /** Bitmap with extra information about the MQ. Use SR_MQFLAG_AC, ... */
-       uint64_t mqflags;
-       /** The analog value(s). The data is interleaved according to
-        * the channels list. */
-       float *data;
-};
-
 /** Analog datafeed payload for type SR_DF_ANALOG. */
 struct sr_datafeed_analog {
        void *data;
@@ -526,7 +527,12 @@ struct sr_analog_encoding {
        gboolean is_signed;
        gboolean is_float;
        gboolean is_bigendian;
-       uint8_t digits;
+       /**
+        * Number of significant digits after the decimal point if positive,
+        * or number of non-significant digits before the decimal point if
+        * negative (refers to the value we actually read on the wire).
+        */
+       int8_t digits;
        gboolean is_digits_decimal;
        struct sr_rational scale;
        struct sr_rational offset;
@@ -540,17 +546,23 @@ struct sr_analog_meaning {
 };
 
 struct sr_analog_spec {
-       uint8_t spec_digits;
+       /**
+        * Number of significant digits after the decimal point if positive,
+        * or number of non-significant digits before the decimal point if
+        * negative (refers to vendor specifications/datasheet or actual
+        * device display).
+        */
+       int8_t spec_digits;
 };
 
 /** Generic option struct used by various subsystems. */
 struct sr_option {
        /* Short name suitable for commandline usage, [a-z0-9-]. */
-       char *id;
+       const char *id;
        /* Short name suitable for GUI usage, can contain UTF-8. */
-       char *name;
+       const char *name;
        /* Description of the option, in a sentence. */
-       char *desc;
+       const char *desc;
        /* Default value for this option. */
        GVariant *def;
        /* List of possible values, if this is an option with few values. */
@@ -645,17 +657,22 @@ struct sr_key_info {
        /** Data type like SR_T_STRING, etc if applicable. */
        int datatype;
        /** Short, lowercase ID string, e.g. "serialcomm", "voltage". */
-       char *id;
+       const char *id;
        /** Full capitalized name, e.g. "Serial communication". */
-       char *name;
+       const char *name;
        /** Verbose description (unused currently). */
-       char *description;
+       const char *description;
 };
 
-#define SR_CONF_GET  (1 << 31)
-#define SR_CONF_SET  (1 << 30)
-#define SR_CONF_LIST (1 << 29)
-#define SR_CONF_MASK 0x1fffffff
+/** Configuration capabilities. */
+enum sr_configcap {
+       /** Value can be read. */
+       SR_CONF_GET = (1UL << 31),
+       /** Value can be written. */
+       SR_CONF_SET = (1UL << 30),
+       /** Possible values can be enumerated. */
+       SR_CONF_LIST = (1UL << 29),
+};
 
 /** Configuration keys */
 enum sr_configkey {
@@ -700,6 +717,12 @@ enum sr_configkey {
        /** The device can act as a scale. */
        SR_CONF_SCALE,
 
+       /** The device can act as a function generator. */
+       SR_CONF_SIGNAL_GENERATOR,
+
+       /** The device can measure power. */
+       SR_CONF_POWERMETER,
+
        /* Update sr_key_info_config[] (hwdriver.c) upon changes! */
 
        /*--- Driver scan options -------------------------------------------*/
@@ -745,6 +768,16 @@ enum sr_configkey {
         */
        SR_CONF_MODBUSADDR,
 
+       /**
+        * User specified forced driver attachment to unknown devices.
+        *
+        * By design the interpretation of the string depends on the
+        * specific driver. It typically would be either a replacement
+        * '*IDN?' response value, or a sub-driver name. But could also
+        * be anything else and totally arbitrary.
+        */
+       SR_CONF_FORCE_DETECT,
+
        /* Update sr_key_info_config[] (hwdriver.c) upon changes! */
 
        /*--- Device (or channel group) configuration -----------------------*/
@@ -794,7 +827,7 @@ enum sr_configkey {
        /** Coupling. */
        SR_CONF_COUPLING,
 
-       /** Trigger matches.  */
+       /** Trigger matches. */
        SR_CONF_TRIGGER_MATCH,
 
        /** The device supports setting its sample interval, in ms. */
@@ -803,16 +836,16 @@ enum sr_configkey {
        /** Number of horizontal divisions, as related to SR_CONF_TIMEBASE. */
        SR_CONF_NUM_HDIV,
 
-       /** Number of vertical divisions, as related to SR_CONF_VDIV.  */
+       /** Number of vertical divisions, as related to SR_CONF_VDIV. */
        SR_CONF_NUM_VDIV,
 
-       /** Sound pressure level frequency weighting.  */
+       /** Sound pressure level frequency weighting. */
        SR_CONF_SPL_WEIGHT_FREQ,
 
-       /** Sound pressure level time weighting.  */
+       /** Sound pressure level time weighting. */
        SR_CONF_SPL_WEIGHT_TIME,
 
-       /** Sound pressure level measurement range.  */
+       /** Sound pressure level measurement range. */
        SR_CONF_SPL_MEASUREMENT_RANGE,
 
        /** Max hold mode. */
@@ -950,6 +983,8 @@ enum sr_configkey {
         * Channel regulation
         * get: "CV", "CC" or "UR", denoting constant voltage, constant current
         *      or unregulated.
+        *      "CC-" denotes a power supply in current sink mode (e.g. HP 66xxB).
+        *      "" is used when there is no regulation, e.g. the output is disabled.
         */
        SR_CONF_REGULATION,
 
@@ -971,18 +1006,83 @@ enum sr_configkey {
        /** Over-temperature protection (OTP) active. */
        SR_CONF_OVER_TEMPERATURE_PROTECTION_ACTIVE,
 
-       /* Update sr_key_info_config[] (hwdriver.c) upon changes! */
+       /** Under-voltage condition. */
+       SR_CONF_UNDER_VOLTAGE_CONDITION,
 
-       /*--- Special stuff -------------------------------------------------*/
+       /** Under-voltage condition active. */
+       SR_CONF_UNDER_VOLTAGE_CONDITION_ACTIVE,
+
+       /** Trigger level. */
+       SR_CONF_TRIGGER_LEVEL,
+
+       /** Under-voltage condition threshold. */
+       SR_CONF_UNDER_VOLTAGE_CONDITION_THRESHOLD,
+
+       /**
+        * Which external clock source to use if the device supports
+        * multiple external clock channels.
+        */
+       SR_CONF_EXTERNAL_CLOCK_SOURCE,
 
-       /** Scan options supported by the driver. */
-       SR_CONF_SCAN_OPTIONS = 40000,
+       /** Offset of a source without strictly-defined MQ. */
+       SR_CONF_OFFSET,
 
-       /** Device options for a particular device. */
-       SR_CONF_DEVICE_OPTIONS,
+       /** The device supports setting a pattern for the logic trigger. */
+       SR_CONF_TRIGGER_PATTERN,
+
+       /** High resolution mode. */
+       SR_CONF_HIGH_RESOLUTION,
+
+       /** Peak detection. */
+       SR_CONF_PEAK_DETECTION,
+
+       /** Logic threshold: predefined levels (TTL, ECL, CMOS, etc). */
+       SR_CONF_LOGIC_THRESHOLD,
+
+       /** Logic threshold: custom numerical value. */
+       SR_CONF_LOGIC_THRESHOLD_CUSTOM,
+
+       /** The measurement range of a DMM or the output range of a power supply. */
+       SR_CONF_RANGE,
+
+       /** The number of digits (e.g. for a DMM). */
+       SR_CONF_DIGITS,
+
+       /** Phase of a source signal. */
+       SR_CONF_PHASE,
+
+       /** Duty cycle of a source signal. */
+       SR_CONF_DUTY_CYCLE,
+
+       /**
+        * Current power.
+        * @arg type: double
+        * @arg get: get measured power
+        */
+       SR_CONF_POWER,
+
+       /**
+        * Power target.
+        * @arg type: double
+        * @arg get: get power target
+        * @arg set: change power target
+        */
+       SR_CONF_POWER_TARGET,
+
+       /**
+        * Resistance target.
+        * @arg type: double
+        * @arg get: get resistance target
+        * @arg set: change resistance target
+        */
+       SR_CONF_RESISTANCE_TARGET,
+
+       /* Update sr_key_info_config[] (hwdriver.c) upon changes! */
+
+       /*--- Special stuff -------------------------------------------------*/
 
        /** Session filename. */
-       SR_CONF_SESSIONFILE,
+       SR_CONF_SESSIONFILE = 40000,
 
        /** The device supports specifying a capturefile to inject. */
        SR_CONF_CAPTUREFILE,
@@ -1010,6 +1110,9 @@ enum sr_configkey {
        /** The device supports setting a probe factor. */
        SR_CONF_PROBE_FACTOR,
 
+       /** Number of powerline cycles for ADC integration time. */
+       SR_CONF_ADC_POWERLINE_CYCLES,
+
        /* Update sr_key_info_config[] (hwdriver.c) upon changes! */
 
        /*--- Acquisition modes, sample limiting ----------------------------*/
@@ -1091,9 +1194,9 @@ enum sr_dev_inst_status {
 struct sr_dev_driver {
        /* Driver-specific */
        /** Driver name. Lowercase a-z, 0-9 and dashes (-) only. */
-       char *name;
+       const char *name;
        /** Long name. Verbose driver name shown to user. */
-       char *longname;
+       const char *longname;
        /** API version (currently 1).  */
        int api_version;
        /** Called when driver is loaded, e.g. program startup. */
@@ -1146,11 +1249,9 @@ struct sr_dev_driver {
        /** Close device */
        int (*dev_close) (struct sr_dev_inst *sdi);
        /** Begin data acquisition on the specified device. */
-       int (*dev_acquisition_start) (const struct sr_dev_inst *sdi,
-                       void *cb_data);
+       int (*dev_acquisition_start) (const struct sr_dev_inst *sdi);
        /** End data acquisition on the specified device. */
-       int (*dev_acquisition_stop) (struct sr_dev_inst *sdi,
-                       void *cb_data);
+       int (*dev_acquisition_stop) (struct sr_dev_inst *sdi);
 
        /* Dynamic */
        /** Device driver context, considered private. Initialized by init(). */