X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=hardware%2Ftondaj-sl-814%2Fapi.c;h=5b7ed363bc3b4b195cf20ae11a113d02de969796;hb=388f9d3e25da89df1fb01412688339b6de54e14e;hp=2247e75a4dec483b2b59b91da0eb3dff7acfa66f;hpb=c073af80f89d8bce8675068d084c96e0cf37bb4f;p=libsigrok.git diff --git a/hardware/tondaj-sl-814/api.c b/hardware/tondaj-sl-814/api.c index 2247e75a..5b7ed363 100644 --- a/hardware/tondaj-sl-814/api.c +++ b/hardware/tondaj-sl-814/api.c @@ -24,6 +24,8 @@ #include "libsigrok-internal.h" #include "protocol.h" +#define SERIALCOMM "9600/8e1" + static const int hwopts[] = { SR_HWOPT_CONN, SR_HWOPT_SERIALCOMM, @@ -37,11 +39,6 @@ static const int hwcaps[] = { 0, }; -static const char *probe_names[] = { - "P1", - NULL, -}; - SR_PRIV struct sr_dev_driver tondaj_sl_814_driver_info; static struct sr_dev_driver *di = &tondaj_sl_814_driver_info; @@ -71,7 +68,7 @@ static int clear_instances(void) return SR_OK; } -static int hw_init(void) +static int hw_init(struct sr_context *sr_ctx) { struct drv_context *drvc; @@ -80,6 +77,7 @@ static int hw_init(void) return SR_ERR_MALLOC; } + drvc->sr_ctx = sr_ctx; di->priv = drvc; return SR_OK; @@ -117,10 +115,10 @@ static GSList *hw_scan(GSList *options) break; } } - if (!conn) { - sr_dbg("Couldn't determine connection options."); + if (!conn) return NULL; - } + if (!serialcomm) + serialcomm = SERIALCOMM; if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, "Tondaj", "SL-814", NULL))) { @@ -133,17 +131,15 @@ static GSList *hw_scan(GSList *options) return NULL; } - if (!serialcomm) - serialcomm = "9600/8e1"; + if (!(devc->serial = sr_serial_dev_inst_new(conn, serialcomm))) + return NULL; - if (!(devc->serial = sr_serial_dev_inst_new(conn, -1))) { - sr_err("Failed to create serial device instance."); + if (serial_open(devc->serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) return NULL; - } - devc->serialcomm = g_strdup(serialcomm); + sdi->priv = devc; sdi->driver = di; - probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, probe_names[0]); + probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1"); if (!probe) { sr_err("Failed to create probe."); return NULL; @@ -166,25 +162,12 @@ static GSList *hw_dev_list(void) static int hw_dev_open(struct sr_dev_inst *sdi) { - int ret; struct dev_context *devc; devc = sdi->priv; - sr_dbg("Opening '%s' with '%s'.", devc->serial->port, devc->serialcomm); - - ret = serial_open(devc->serial->port, O_RDWR | O_NONBLOCK); - if (ret < 0) { - sr_err("Unable to open serial port: %d.", ret); + if (serial_open(devc->serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) return SR_ERR; - } - devc->serial->fd = ret; - - ret = serial_set_paramstr(devc->serial->fd, devc->serialcomm); - if (ret < 0) { - sr_err("Unable to set serial parameters: %d.", ret); - return SR_ERR; - } sdi->status = SR_ST_ACTIVE; @@ -193,29 +176,15 @@ static int hw_dev_open(struct sr_dev_inst *sdi) static int hw_dev_close(struct sr_dev_inst *sdi) { - int ret; struct dev_context *devc; devc = sdi->priv; - if (!devc->serial) { - sr_err("Invalid serial device instance, cannot close."); - return SR_ERR_BUG; - } - - if (devc->serial->fd == -1) { - sr_dbg("Serial device instance FD was -1, no need to close."); - return SR_OK; + if (devc->serial && devc->serial->fd != -1) { + serial_close(devc->serial); + sdi->status = SR_ST_INACTIVE; } - if ((ret = serial_close(devc->serial->fd)) < 0) { - sr_err("Error closing serial port: %d.", ret); - return SR_ERR; - } - - devc->serial->fd = -1; - sdi->status = SR_ST_INACTIVE; - return SR_OK; } @@ -238,14 +207,7 @@ static int hw_info_get(int info_id, const void **data, case SR_DI_HWCAPS: *data = hwcaps; break; - case SR_DI_NUM_PROBES: - *data = GINT_TO_POINTER(1); - break; - case SR_DI_PROBE_NAMES: - *data = probe_names; - break; default: - sr_err("Unknown info_id: %d.", info_id); return SR_ERR_ARG; }