]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/motech-lps-30x/api.c
Various log message cleanups.
[libsigrok.git] / src / hardware / motech-lps-30x / api.c
index 8d87da0280cf47ffd1210943ddd7eb59d52a6c4d..88e4449e55ac385d04bf2a743864cc177e0d5f65 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/** @file
- *  <em>Motech LPS-30x series</em> power supply driver
- *  @internal
+/**
+ * @file
+ *
+ * <em>Motech LPS-30x series</em> power supply driver
+ *
+ * @internal
  */
 
 #include <config.h>
@@ -28,9 +31,6 @@
 #include <math.h>
 #include <string.h>
 #include "protocol.h"
-
-/* Forward declarations */
-SR_PRIV struct sr_dev_driver motech_lps_301_driver_info;
 SR_PRIV int lps_read_reply(struct sr_serial_dev_inst *serial, char **buf, int *buflen);
 SR_PRIV int lps_send_va(struct sr_serial_dev_inst *serial, const char *fmt, va_list args);
 SR_PRIV int lps_cmd_ok(struct sr_serial_dev_inst *serial, const char *fmt, ...);
@@ -133,11 +133,6 @@ static const struct lps_modelspec models[] = {
        },
 };
 
-static int init_lps301(struct sr_dev_driver *di, struct sr_context *sr_ctx)
-{
-       return std_init(di, sr_ctx, LOG_PREFIX);
-}
-
 /** Send command to device with va_list.
  */
 SR_PRIV int lps_send_va(struct sr_serial_dev_inst *serial, const char *fmt, va_list args)
@@ -181,7 +176,7 @@ SR_PRIV int lps_cmd_ok(struct sr_serial_dev_inst *serial, const char *fmt, ...)
        va_list args;
        char buf[LINELEN_MAX];
        char *bufptr;
-       int  buflen;
+       int buflen;
 
        /* Send command */
        va_start(args, fmt);
@@ -202,8 +197,9 @@ SR_PRIV int lps_cmd_ok(struct sr_serial_dev_inst *serial, const char *fmt, ...)
        return SR_ERR;
 }
 
-/** Send command and read reply string.
- *  @param reply Pointer to buffer of size LINELEN_MAX. Will be NUL-terminated.
+/**
+ * Send command and read reply string.
+ * @param reply Pointer to buffer of size LINELEN_MAX. Will be NUL-terminated.
  */
 SR_PRIV int lps_cmd_reply(char *reply, struct sr_serial_dev_inst *serial, const char *fmt, ...)
 {
@@ -211,7 +207,7 @@ SR_PRIV int lps_cmd_reply(char *reply, struct sr_serial_dev_inst *serial, const
        va_list args;
        char buf[LINELEN_MAX];
        char *bufptr;
-       int  buflen;
+       int buflen;
 
        reply[0] = '\0';
 
@@ -315,9 +311,11 @@ static gint64 calc_timeout_ms(gint64 start_us)
        return result;
 }
 
-/** Read message into buf until "OK" received.
- *  @retval SR_OK Msg received; buf and buflen contain result, if any except OK.
- *  @retval SR_ERR Error, including timeout.
+/**
+ * Read message into buf until "OK" received.
+ *
+ * @retval SR_OK Msg received; buf and buflen contain result, if any except OK.
+ * @retval SR_ERR Error, including timeout.
 */
 SR_PRIV int lps_read_reply(struct sr_serial_dev_inst *serial, char **buf, int *buflen)
 {
@@ -374,12 +372,10 @@ SR_PRIV int lps_read_reply(struct sr_serial_dev_inst *serial, char **buf, int *b
 static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *options)
 {
        struct sr_dev_inst *sdi;
-       struct drv_context *drvc;
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
        struct sr_channel *ch;
        struct sr_channel_group *cg;
-       GSList *devices;
        const char *conn, *serialcomm;
        int cnt, ret;
        gchar buf[LINELEN_MAX];
@@ -389,12 +385,6 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
        sdi = NULL;
        devc = NULL;
        conn = serialcomm = NULL;
-       devices = NULL;
-
-       drvc = drv->context;
-       drvc->instances = NULL;
-
-       sr_spew("scan() called!");
 
        /* Process and check options. */
        if (sr_serial_extract_options(options, &conn, &serialcomm) != SR_OK)
@@ -445,7 +435,7 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
                g_strstrip(buf);
                verstr = buf + 4;
        }
-       else  /* Bug in device FW 1.17: Querying version string fails while output is active.
+       else /* Bug in device FW 1.17: Querying version string fails while output is active.
                Therefore just print an error message, but do not exit with error. */
                sr_err("Failed to query for hardware version: %s.",
                        sr_strerror(ret));
@@ -455,7 +445,6 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
        sdi->vendor = g_strdup(VENDOR_MOTECH);
        sdi->model = g_strdup(models[modelid].modelstr);
        sdi->version = g_strdup(verstr);
-       sdi->driver = drv;
        sdi->inst_type = SR_INST_SERIAL;
        sdi->conn = serial;
 
@@ -481,29 +470,22 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
                sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
        }
 
-       drvc->instances = g_slist_append(drvc->instances, sdi);
-       devices = g_slist_append(devices, sdi);
-
        /* Query status */
        if (lps_query_status(sdi) != SR_OK)
                goto exit_err;
 
        serial_close(serial);
-       if (!devices)
-               sr_serial_dev_inst_free(serial);
 
-       return devices;
+       return std_scan_complete(drv, g_slist_append(NULL, sdi));
 
 exit_err:
        sr_info("%s: Error!", __func__);
 
-       if (serial) {
+       if (serial)
                serial_close(serial);
-               sr_serial_dev_inst_free(serial);
-       }
+       sr_serial_dev_inst_free(serial);
        g_free(devc);
-       if (sdi)
-               sr_dev_inst_free(sdi);
+       sr_dev_inst_free(sdi);
 
        return NULL;
 }
@@ -592,9 +574,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
        int idx;
        gboolean found;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        devc = sdi->priv;
 
        /* Cannot change settings while acquisition active, would cause a mess with commands.
@@ -705,7 +684,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                        scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
                return SR_OK;
        case SR_CONF_DEVICE_OPTIONS:
-               if (sdi != NULL)
+               if (sdi)
                        break;
                *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
                        drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
@@ -745,10 +724,10 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        case SR_CONF_DEVICE_OPTIONS:
                if ((ch_idx == 0) || (ch_idx == 1)) /* CH1, CH2 */
                        *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                 devopts_ch12, ARRAY_SIZE(devopts_ch12), sizeof(uint32_t));
+                               devopts_ch12, ARRAY_SIZE(devopts_ch12), sizeof(uint32_t));
                else /* Must be CH3 */
                        *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                 devopts_ch3, ARRAY_SIZE(devopts_ch3), sizeof(uint32_t));
+                               devopts_ch3, ARRAY_SIZE(devopts_ch3), sizeof(uint32_t));
                break;
        case SR_CONF_VOLTAGE_TARGET:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
@@ -780,9 +759,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        devc = sdi->priv;
 
        devc->acq_running = TRUE;
@@ -790,7 +766,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        serial = sdi->conn;
        serial_source_add(sdi->session, serial, G_IO_IN, 50,
                        motech_lps_30x_receive_data, (void *)sdi);
-       std_session_send_df_header(sdi, LOG_PREFIX);
+       std_session_send_df_header(sdi);
 
        sr_sw_limits_acquisition_start(&devc->limits);
 
@@ -800,17 +776,11 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static int dev_acquisition_stop(struct sr_dev_inst *sdi)
-{
-       return std_serial_dev_acquisition_stop(sdi, std_serial_dev_close,
-                       sdi->conn, LOG_PREFIX);
-}
-
-SR_PRIV struct sr_dev_driver motech_lps_301_driver_info = {
+static struct sr_dev_driver motech_lps_301_driver_info = {
        .name = "motech-lps-301",
        .longname = "Motech LPS-301",
        .api_version = 1,
-       .init = init_lps301,
+       .init = std_init,
        .cleanup = std_cleanup,
        .scan = scan_lps301,
        .dev_list = std_dev_list,
@@ -821,6 +791,7 @@ SR_PRIV struct sr_dev_driver motech_lps_301_driver_info = {
        .dev_open = std_serial_dev_open,
        .dev_close = std_serial_dev_close,
        .dev_acquisition_start = dev_acquisition_start,
-       .dev_acquisition_stop = dev_acquisition_stop,
+       .dev_acquisition_stop = std_serial_dev_acquisition_stop,
        .context = NULL,
 };
+SR_REGISTER_DEV_DRIVER(motech_lps_301_driver_info);