]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/testo/protocol.c
Random cosmetics and whitespace fixes.
[libsigrok.git] / src / hardware / testo / protocol.c
index bdfaf1fd3103cf9340c686adaa05c39b538166bb..89f5bc9c2ff063383acb5c4f91285ae01d2f8a5e 100644 (file)
@@ -17,6 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <config.h>
 #include <string.h>
 #include "protocol.h"
 
@@ -24,25 +25,25 @@ SR_PRIV int testo_set_serial_params(struct sr_usb_dev_inst *usb)
 {
        int ret;
 
-    if ((ret = libusb_control_transfer(usb->devhdl, 0x40, FTDI_SET_BAUDRATE,
+       if ((ret = libusb_control_transfer(usb->devhdl, 0x40, FTDI_SET_BAUDRATE,
                        FTDI_BAUDRATE_115200, FTDI_INDEX, NULL, 0, 10)) < 0) {
                        sr_err("Failed to set baudrate: %s", libusb_error_name(ret));
                        return SR_ERR;
        }
 
-    if ((ret = libusb_control_transfer(usb->devhdl, 0x40, FTDI_SET_PARAMS,
+       if ((ret = libusb_control_transfer(usb->devhdl, 0x40, FTDI_SET_PARAMS,
                        FTDI_PARAMS_8N1, FTDI_INDEX, NULL, 0, 10)) < 0) {
                        sr_err("Failed to set comm parameters: %s", libusb_error_name(ret));
                        return SR_ERR;
        }
 
-    if ((ret = libusb_control_transfer(usb->devhdl, 0x40, FTDI_SET_FLOWCTRL,
+       if ((ret = libusb_control_transfer(usb->devhdl, 0x40, FTDI_SET_FLOWCTRL,
                        FTDI_FLOW_NONE, FTDI_INDEX, NULL, 0, 10)) < 0) {
                        sr_err("Failed to set flow control: %s", libusb_error_name(ret));
                        return SR_ERR;
        }
 
-    if ((ret = libusb_control_transfer(usb->devhdl, 0x40, FTDI_SET_MODEMCTRL,
+       if ((ret = libusb_control_transfer(usb->devhdl, 0x40, FTDI_SET_MODEMCTRL,
                        FTDI_MODEM_ALLHIGH, FTDI_INDEX, NULL, 0, 10)) < 0) {
                        sr_err("Failed to set modem control: %s", libusb_error_name(ret));
                        return SR_ERR;
@@ -51,7 +52,6 @@ SR_PRIV int testo_set_serial_params(struct sr_usb_dev_inst *usb)
        return SR_OK;
 }
 
-
 /* Due to the modular nature of the Testo hardware, you can't assume
  * which measurements the device will supply. Fetch a single result
  * set synchronously to see which measurements it has. */
@@ -59,10 +59,9 @@ SR_PRIV int testo_probe_channels(struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
        struct sr_usb_dev_inst *usb;
-       struct sr_channel *ch;
        int unit, packet_len, len, i;
        unsigned char packet[MAX_REPLY_SIZE], buf[MAX_REPLY_SIZE];
-       char *probe_name;
+       const char *probe_name;
 
        devc = sdi->priv;
        usb = sdi->conn;
@@ -78,12 +77,12 @@ SR_PRIV int testo_probe_channels(struct sr_dev_inst *sdi)
                libusb_bulk_transfer(usb->devhdl, EP_IN, buf, MAX_REPLY_SIZE, &len, 10);
        } while (len > 2);
 
-       if (libusb_bulk_transfer(usb->devhdl, EP_OUT, devc->model->request,
+       if (libusb_bulk_transfer(usb->devhdl, EP_OUT, (unsigned char *)devc->model->request,
                        devc->model->request_size, &devc->reply_size, 10) < 0)
                return SR_ERR;
 
        packet_len = 0;
-       while(TRUE) {
+       while (TRUE) {
                if (libusb_bulk_transfer(usb->devhdl, EP_IN, buf, MAX_REPLY_SIZE,
                                &len, 250) < 0)
                        return SR_ERR;
@@ -136,8 +135,7 @@ SR_PRIV int testo_probe_channels(struct sr_dev_inst *sdi)
                        sr_dbg("Unsupported measurement unit %d", unit);
                        return SR_ERR;
                }
-               ch = sr_channel_new(i, SR_CHANNEL_ANALOG, TRUE, probe_name);
-               sdi->channels = g_slist_append(sdi->channels, ch);
+               sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, probe_name);
        }
        devc->num_channels = packet[6];
        sr_dbg("Found %d channel%s.", devc->num_channels,
@@ -156,12 +154,11 @@ SR_PRIV int testo_request_packet(const struct sr_dev_inst *sdi)
        usb = sdi->conn;
 
        libusb_fill_bulk_transfer(devc->out_transfer, usb->devhdl, EP_OUT,
-                       devc->model->request, devc->model->request_size,
+                       (unsigned char *)devc->model->request, devc->model->request_size,
                        receive_transfer, (void *)sdi, 100);
        if ((ret = libusb_submit_transfer(devc->out_transfer) != 0)) {
                sr_err("Failed to request packet: %s.", libusb_error_name(ret));
-               sdi->driver->dev_acquisition_stop((struct sr_dev_inst *)sdi,
-                               devc->cb_data);
+               sdi->driver->dev_acquisition_stop((struct sr_dev_inst *)sdi);
                return SR_ERR;
        }
        sr_dbg("Requested new packet.");
@@ -225,7 +222,7 @@ SR_PRIV void testo_receive_packet(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
        struct sr_datafeed_packet packet;
-       struct sr_datafeed_analog analog;
+       struct sr_datafeed_analog_old analog;
        struct sr_channel *ch;
        GString *dbg;
        float value;
@@ -244,7 +241,7 @@ SR_PRIV void testo_receive_packet(const struct sr_dev_inst *sdi)
                g_string_free(dbg, TRUE);
        }
 
-       packet.type = SR_DF_ANALOG;
+       packet.type = SR_DF_ANALOG_OLD;
        packet.payload = &analog;
        analog.num_samples = 1;
        analog.mqflags = 0;
@@ -291,4 +288,3 @@ SR_PRIV void testo_receive_packet(const struct sr_dev_inst *sdi)
                g_slist_free(analog.channels);
        }
 }
-