From: Soeren Apel Date: Sat, 12 Aug 2017 13:50:13 +0000 (+0200) Subject: Add std_session_send_frame_begin/end helpers X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=b7602846fd2d8388e3462237e2c60927efcff744;p=libsigrok.git Add std_session_send_frame_begin/end helpers --- diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 7bde2b1e..044aa9da 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -940,6 +940,8 @@ 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_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, std_dev_clear_callback clear_private); SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver); diff --git a/src/std.c b/src/std.c index 4219042e..48f83b53 100644 --- a/src/std.c +++ b/src/std.c @@ -230,6 +230,82 @@ 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_FRAME_BEGIN packet. + * + * This function can be used to simplify most drivers' + * frame 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_frame_begin(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"; + + sr_dbg("%s: Sending SR_DF_FRAME_BEGIN packet.", prefix); + + packet.type = SR_DF_FRAME_BEGIN; + packet.payload = NULL; + + if ((ret = sr_session_send(sdi, &packet)) < 0) { + sr_err("%s: Failed to send SR_DF_FRAME_BEGIN packet: %d.", prefix, ret); + return ret; + } + + return SR_OK; +} + +/** + * Standard API helper for sending an SR_DF_FRAME_END packet. + * + * This function can be used to simplify most drivers' + * frame 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_frame_end(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"; + + sr_dbg("%s: Sending SR_DF_FRAME_END packet.", prefix); + + packet.type = SR_DF_FRAME_END; + packet.payload = NULL; + + if ((ret = sr_session_send(sdi, &packet)) < 0) { + sr_err("%s: Failed to send SR_DF_FRAME_END packet: %d.", prefix, ret); + return ret; + } + + return SR_OK; +} + #ifdef HAVE_LIBSERIALPORT /**