]> sigrok.org Git - libsigrok.git/commitdiff
std: Add std_session_send_df_trigger().
authorUwe Hermann <redacted>
Wed, 8 Apr 2020 21:02:04 +0000 (23:02 +0200)
committerUwe Hermann <redacted>
Wed, 8 Apr 2020 21:02:04 +0000 (23:02 +0200)
src/libsigrok-internal.h
src/std.c

index 140d11e154b06beba927a4c077a96ff6095c5905..94ac3d1a77d1d3d059a7a88fb76dab54cfe72142 100644 (file)
@@ -1030,6 +1030,7 @@ SR_PRIV int std_serial_dev_acquisition_stop(struct sr_dev_inst *sdi);
 #endif
 SR_PRIV int std_session_send_df_header(const struct sr_dev_inst *sdi);
 SR_PRIV int std_session_send_df_end(const struct sr_dev_inst *sdi);
+SR_PRIV int std_session_send_df_trigger(const struct sr_dev_inst *sdi);
 SR_PRIV int std_session_send_frame_begin(const struct sr_dev_inst *sdi);
 SR_PRIV int std_session_send_frame_end(const struct sr_dev_inst *sdi);
 SR_PRIV int std_dev_clear_with_callback(const struct sr_dev_driver *driver,
index 581e2e467440f7776dc508e5a7d702691062ab92..ff09f46fc5eac5e11d9b54abe22f318c37c29e34 100644 (file)
--- a/src/std.c
+++ b/src/std.c
@@ -231,6 +231,41 @@ SR_PRIV int std_session_send_df_end(const struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
+/**
+ * Standard API helper for sending an SR_DF_TRIGGER packet.
+ *
+ * This function can be used to simplify most drivers' trigger handling.
+ *
+ * @param[in] sdi The device instance to use. Must not be NULL.
+ *
+ * @retval SR_OK Success.
+ * @retval SR_ERR_ARG Invalid argument.
+ * @retval other Other error.
+ */
+SR_PRIV int std_session_send_df_trigger(const struct sr_dev_inst *sdi)
+{
+       const char *prefix;
+       int ret;
+       struct sr_datafeed_packet packet;
+
+       if (!sdi) {
+               sr_err("%s: Invalid argument.", __func__);
+               return SR_ERR_ARG;
+       }
+
+       prefix = (sdi->driver) ? sdi->driver->name : "unknown";
+
+       packet.type = SR_DF_TRIGGER;
+       packet.payload = NULL;
+
+       if ((ret = sr_session_send(sdi, &packet)) < 0) {
+               sr_err("%s: Failed to send SR_DF_TRIGGER packet: %d.", prefix, ret);
+               return ret;
+       }
+
+       return SR_OK;
+}
+
 /**
  * Standard API helper for sending an SR_DF_FRAME_BEGIN packet.
  *