Add/use std_hw_dev_acquisition_stop_serial().
This commit is contained in:
parent
17548571cc
commit
cd2f0fe22c
|
@ -309,29 +309,8 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
|||
|
||||
static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
|
||||
{
|
||||
struct sr_datafeed_packet packet;
|
||||
struct dev_context *devc;
|
||||
|
||||
if (sdi->status != SR_ST_ACTIVE)
|
||||
return SR_ERR;
|
||||
|
||||
if (!(devc = sdi->priv)) {
|
||||
sr_err("sdi->priv was NULL.");
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
|
||||
sr_dbg("Stopping acquisition.");
|
||||
|
||||
sr_source_remove(devc->serial->fd);
|
||||
hw_dev_close((struct sr_dev_inst *)sdi);
|
||||
|
||||
/* Send end packet to the session bus. */
|
||||
sr_dbg("Sending SR_DF_END.");
|
||||
packet.type = SR_DF_END;
|
||||
sr_session_send(cb_data, &packet);
|
||||
|
||||
|
||||
return SR_OK;
|
||||
return std_hw_dev_acquisition_stop_serial(sdi, cb_data, hw_dev_close,
|
||||
((struct dev_context *)(sdi->priv))->serial, DRIVER_LOG_DOMAIN);
|
||||
}
|
||||
|
||||
SR_PRIV struct sr_dev_driver agdmm_driver_info = {
|
||||
|
|
|
@ -296,30 +296,8 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
|||
|
||||
static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
|
||||
{
|
||||
struct sr_datafeed_packet packet;
|
||||
struct dev_context *devc;
|
||||
|
||||
if (sdi->status != SR_ST_ACTIVE) {
|
||||
sr_err("Device inactive, can't stop acquisition.");
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
if (!(devc = sdi->priv)) {
|
||||
sr_err("sdi->priv was NULL.");
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
|
||||
sr_dbg("Stopping acquisition.");
|
||||
|
||||
sr_source_remove(devc->serial->fd);
|
||||
hw_dev_close((struct sr_dev_inst *)sdi);
|
||||
|
||||
/* Send end packet to the session bus. */
|
||||
sr_dbg("Sending SR_DF_END.");
|
||||
packet.type = SR_DF_END;
|
||||
sr_session_send(cb_data, &packet);
|
||||
|
||||
return SR_OK;
|
||||
return std_hw_dev_acquisition_stop_serial(sdi, cb_data, hw_dev_close,
|
||||
((struct dev_context *)(sdi->priv))->serial, DRIVER_LOG_DOMAIN);
|
||||
}
|
||||
|
||||
SR_PRIV struct sr_dev_driver brymen_bm857_driver_info = {
|
||||
|
|
|
@ -255,28 +255,8 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
|||
|
||||
static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
|
||||
{
|
||||
struct sr_datafeed_packet packet;
|
||||
struct dev_context *devc;
|
||||
|
||||
if (sdi->status != SR_ST_ACTIVE)
|
||||
return SR_ERR;
|
||||
|
||||
if (!(devc = sdi->priv)) {
|
||||
sr_err("sdi->priv was NULL.");
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
|
||||
sr_dbg("Stopping acquisition.");
|
||||
|
||||
sr_source_remove(devc->serial->fd);
|
||||
hw_dev_close((struct sr_dev_inst *)sdi);
|
||||
|
||||
/* Send end packet to the session bus. */
|
||||
sr_dbg("Sending SR_DF_END.");
|
||||
packet.type = SR_DF_END;
|
||||
sr_session_send(cb_data, &packet);
|
||||
|
||||
return SR_OK;
|
||||
return std_hw_dev_acquisition_stop_serial(sdi, cb_data, hw_dev_close,
|
||||
((struct dev_context *)(sdi->priv))->serial, DRIVER_LOG_DOMAIN);
|
||||
}
|
||||
|
||||
SR_PRIV struct sr_dev_driver colead_slm_driver_info = {
|
||||
|
|
|
@ -350,28 +350,8 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
|||
|
||||
static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
|
||||
{
|
||||
struct sr_datafeed_packet packet;
|
||||
struct dev_context *devc;
|
||||
|
||||
if (sdi->status != SR_ST_ACTIVE)
|
||||
return SR_ERR;
|
||||
|
||||
if (!(devc = sdi->priv)) {
|
||||
sr_err("sdi->priv was NULL.");
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
|
||||
sr_dbg("Stopping acquisition.");
|
||||
|
||||
sr_source_remove(devc->serial->fd);
|
||||
hw_dev_close((struct sr_dev_inst *)sdi);
|
||||
|
||||
/* Send end packet to the session bus. */
|
||||
sr_dbg("Sending SR_DF_END.");
|
||||
packet.type = SR_DF_END;
|
||||
sr_session_send(cb_data, &packet);
|
||||
|
||||
return SR_OK;
|
||||
return std_hw_dev_acquisition_stop_serial(sdi, cb_data, hw_dev_close,
|
||||
((struct dev_context *)(sdi->priv))->serial, DRIVER_LOG_DOMAIN);
|
||||
}
|
||||
|
||||
SR_PRIV struct sr_dev_driver flukedmm_driver_info = {
|
||||
|
|
|
@ -277,27 +277,8 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
|||
|
||||
static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
|
||||
{
|
||||
struct sr_datafeed_packet packet;
|
||||
struct dev_context *devc;
|
||||
|
||||
if (sdi->status != SR_ST_ACTIVE) {
|
||||
sr_err("Device inactive, can't stop acquisition.");
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
devc = sdi->priv;
|
||||
|
||||
sr_dbg("Stopping acquisition.");
|
||||
|
||||
sr_source_remove(devc->serial->fd);
|
||||
hw_dev_close((struct sr_dev_inst *)sdi);
|
||||
|
||||
/* Send end packet to the session bus. */
|
||||
sr_dbg("Sending SR_DF_END.");
|
||||
packet.type = SR_DF_END;
|
||||
sr_session_send(cb_data, &packet);
|
||||
|
||||
return SR_OK;
|
||||
return std_hw_dev_acquisition_stop_serial(sdi, cb_data, hw_dev_close,
|
||||
((struct dev_context *)(sdi->priv))->serial, DRIVER_LOG_DOMAIN);
|
||||
}
|
||||
|
||||
/* Driver-specific API function wrappers */
|
||||
|
|
|
@ -439,28 +439,8 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
|||
|
||||
static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
|
||||
{
|
||||
struct sr_datafeed_packet packet;
|
||||
struct dev_context *devc;
|
||||
|
||||
if (sdi->status != SR_ST_ACTIVE)
|
||||
return SR_ERR;
|
||||
|
||||
if (!(devc = sdi->priv)) {
|
||||
sr_err("sdi->priv was NULL.");
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
|
||||
sr_dbg("Stopping acquisition.");
|
||||
|
||||
sr_source_remove(devc->serial->fd);
|
||||
hw_dev_close((struct sr_dev_inst *)sdi);
|
||||
|
||||
/* Send end packet to the session bus. */
|
||||
sr_dbg("Sending SR_DF_END.");
|
||||
packet.type = SR_DF_END;
|
||||
sr_session_send(cb_data, &packet);
|
||||
|
||||
return SR_OK;
|
||||
return std_hw_dev_acquisition_stop_serial(sdi, cb_data, hw_dev_close,
|
||||
((struct dev_context *)(sdi->priv))->serial, DRIVER_LOG_DOMAIN);
|
||||
}
|
||||
|
||||
/* Driver-specific API function wrappers */
|
||||
|
|
|
@ -246,35 +246,8 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
|||
|
||||
static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
|
||||
{
|
||||
int ret, final_ret;
|
||||
struct sr_datafeed_packet packet;
|
||||
struct dev_context *devc;
|
||||
|
||||
final_ret = SR_OK;
|
||||
|
||||
if (sdi->status != SR_ST_ACTIVE) {
|
||||
sr_err("Device inactive, can't stop acquisition.");
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
devc = sdi->priv;
|
||||
|
||||
if ((ret = sr_source_remove(devc->serial->fd)) < 0) {
|
||||
sr_err("Error removing source: %d.", ret);
|
||||
final_ret = SR_ERR;
|
||||
}
|
||||
|
||||
if ((ret = hw_dev_close(sdi)) < 0) {
|
||||
sr_err("Error closing device: %d.", ret);
|
||||
final_ret = SR_ERR;
|
||||
}
|
||||
|
||||
/* Send end packet to the session bus. */
|
||||
sr_dbg("Sending SR_DF_END.");
|
||||
packet.type = SR_DF_END;
|
||||
sr_session_send(cb_data, &packet);
|
||||
|
||||
return final_ret;
|
||||
return std_hw_dev_acquisition_stop_serial(sdi, cb_data, hw_dev_close,
|
||||
((struct dev_context *)(sdi->priv))->serial, DRIVER_LOG_DOMAIN);
|
||||
}
|
||||
|
||||
SR_PRIV struct sr_dev_driver tondaj_sl_814_driver_info = {
|
||||
|
|
|
@ -125,9 +125,13 @@ SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi,
|
|||
|
||||
/*--- std.c -----------------------------------------------------------------*/
|
||||
|
||||
typedef int (*dev_close_t)(struct sr_dev_inst *sdi);
|
||||
|
||||
SR_PRIV int std_hw_init(struct sr_context *sr_ctx, struct sr_dev_driver *di,
|
||||
const char *prefix);
|
||||
|
||||
SR_PRIV int std_hw_dev_acquisition_stop_serial(struct sr_dev_inst *sdi,
|
||||
void *cb_data, dev_close_t hw_dev_close_fn,
|
||||
struct sr_serial_dev_inst *serial, const char *prefix);
|
||||
SR_PRIV int std_session_send_df_header(const struct sr_dev_inst *sdi,
|
||||
const char *prefix);
|
||||
|
||||
|
|
60
std.c
60
std.c
|
@ -99,3 +99,63 @@ SR_PRIV int std_session_send_df_header(const struct sr_dev_inst *sdi,
|
|||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Standard sr_session_stop() API helper.
|
||||
*
|
||||
* This function can be used to simplify most (serial port based) driver's
|
||||
* hw_dev_acquisition_stop() API callback.
|
||||
*
|
||||
* @param sdi The device instance for which acquisition should stop.
|
||||
* Must not be NULL.
|
||||
* @param cb_data Opaque 'cb_data' pointer. Must not be NULL.
|
||||
* @param hw_dev_close_fn Function pointer to the driver's hw_dev_close().
|
||||
* Must not be NULL.
|
||||
* @param serial The serial device instance (struct serial_dev_inst *).
|
||||
* Must not be NULL.
|
||||
* @param prefix A driver-specific prefix string used for log messages.
|
||||
* Must not be NULL. An empty string is allowed.
|
||||
*
|
||||
* @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or
|
||||
* SR_ERR upon other errors.
|
||||
*/
|
||||
SR_PRIV int std_hw_dev_acquisition_stop_serial(struct sr_dev_inst *sdi,
|
||||
void *cb_data, dev_close_t hw_dev_close_fn,
|
||||
struct sr_serial_dev_inst *serial, const char *prefix)
|
||||
{
|
||||
int ret;
|
||||
struct sr_datafeed_packet packet;
|
||||
|
||||
if (!prefix) {
|
||||
sr_err("Invalid prefix.");
|
||||
return SR_ERR_ARG;
|
||||
}
|
||||
|
||||
if (sdi->status != SR_ST_ACTIVE) {
|
||||
sr_err("%sDevice inactive, can't stop acquisition.", prefix);
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
sr_dbg("%sStopping acquisition.", prefix);
|
||||
|
||||
if ((ret = sr_source_remove(serial->fd)) < 0) {
|
||||
sr_err("%sFailed to remove source: %d.", prefix, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((ret = hw_dev_close_fn(sdi)) < 0) {
|
||||
sr_err("%sFailed to close device: %d.", prefix, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Send SR_DF_END packet to the session bus. */
|
||||
sr_dbg("%sSending SR_DF_END packet.", prefix);
|
||||
packet.type = SR_DF_END;
|
||||
packet.payload = NULL;
|
||||
if ((ret = sr_session_send(cb_data, &packet)) < 0) {
|
||||
sr_err("%sFailed to send SR_DF_END packet: %d.", prefix, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue