]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/hantek-dso/api.c
scpi-pps: Add support for Owon P4000 series.
[libsigrok.git] / src / hardware / hantek-dso / api.c
index 8d3e037ee8be8ed4d1a09270720c5240caaa10f6..a3cc8a283304ae233ebb1c857ad13eb08be2e094 100644 (file)
@@ -55,7 +55,7 @@ static const uint32_t drvopts[] = {
 static const uint32_t devopts[] = {
        SR_CONF_CONTINUOUS,
        SR_CONF_CONN | SR_CONF_GET,
-       SR_CONF_LIMIT_FRAMES | SR_CONF_SET,
+       SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET,
        SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
        SR_CONF_NUM_HDIV | SR_CONF_GET,
        SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET,
@@ -315,7 +315,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 
                libusb_get_device_descriptor(devlist[i], &des);
 
-               usb_get_port_path(devlist[i], connection_id, sizeof(connection_id));
+               if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0)
+                       continue;
 
                prof = NULL;
                for (j = 0; dev_profiles[j].orig_vid; j++) {
@@ -329,11 +330,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                                devices = g_slist_append(devices, sdi);
                                devc = sdi->priv;
                                if (ezusb_upload_firmware(drvc->sr_ctx, devlist[i],
-                                               USB_CONFIGURATION, prof->firmware) == SR_OK)
+                                               USB_CONFIGURATION, prof->firmware) == SR_OK) {
                                        /* Remember when the firmware on this device was updated */
                                        devc->fw_updated = g_get_monotonic_time();
-                               else
-                                       sr_err("Firmware upload failed");
+                               } else {
+                                       sr_err("Firmware upload failed, name %s", prof->firmware);
+                               }
                                /* Dummy USB address of 0xff will get overwritten later. */
                                sdi->conn = sr_usb_dev_inst_new(
                                                libusb_get_bus_number(devlist[i]), 0xff, NULL);
@@ -475,6 +477,9 @@ static int config_get(uint32_t key, GVariant **data,
                case SR_CONF_CAPTURE_RATIO:
                        *data = g_variant_new_uint64(devc->capture_ratio);
                        break;
+               case SR_CONF_LIMIT_FRAMES:
+                       *data = g_variant_new_uint64(devc->limit_frames);
+                       break;
                default:
                        return SR_ERR_NA;
                }
@@ -506,7 +511,6 @@ static int config_set(uint32_t key, GVariant *data,
        const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
 {
        struct dev_context *devc;
-       int rat;
        int ch_idx, idx;
        float flt;
 
@@ -532,12 +536,7 @@ static int config_set(uint32_t key, GVariant *data,
                        devc->triggerslope = idx;
                        break;
                case SR_CONF_CAPTURE_RATIO:
-                       rat = g_variant_get_uint64(data);
-                       if (rat < 0 || rat > 100) {
-                               sr_err("Capture ratio must be in [0,100].");
-                               return SR_ERR_ARG;
-                       } else
-                               devc->capture_ratio = rat;
+                       devc->capture_ratio = g_variant_get_uint64(data);
                        break;
                case SR_CONF_BUFFERSIZE:
                        if ((idx = std_u64_idx(data, devc->profile->buffersizes, NUM_BUFFER_SIZES)) < 0)
@@ -708,7 +707,6 @@ static void send_chunk(struct sr_dev_inst *sdi, unsigned char *buf,
  */
 static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer)
 {
-       struct sr_datafeed_packet packet;
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
        int num_samples, pre;
@@ -786,8 +784,7 @@ static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer)
                devc->framebuf = NULL;
 
                /* Mark the end of this frame. */
-               packet.type = SR_DF_FRAME_END;
-               sr_session_send(sdi, &packet);
+               std_session_send_df_frame_end(sdi);
 
                if (devc->limit_frames && ++devc->num_frames >= devc->limit_frames) {
                        /* Terminate session */
@@ -801,7 +798,6 @@ static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer)
 static int handle_event(int fd, int revents, void *cb_data)
 {
        const struct sr_dev_inst *sdi;
-       struct sr_datafeed_packet packet;
        struct timeval tv;
        struct sr_dev_driver *di;
        struct dev_context *devc;
@@ -893,8 +889,7 @@ static int handle_event(int fd, int revents, void *cb_data)
                devc->dev_state = FETCH_DATA;
 
                /* Tell the frontend a new frame is on the way. */
-               packet.type = SR_DF_FRAME_BEGIN;
-               sr_session_send(sdi, &packet);
+               std_session_send_df_frame_begin(sdi);
                break;
        case CAPTURE_READY_9BIT:
                /* TODO */