X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Ftesto%2Fprotocol.c;h=def73d42b5d1e6376002e57658b17802518a9e4c;hb=refs%2Fheads%2Flibsigrok-0.5.x;hp=46e9ae62baf6071233c1df660853e14081b8eefd;hpb=329733d92c5004f0fe308eff26b9537fded2cdf3;p=libsigrok.git
diff --git a/src/hardware/testo/protocol.c b/src/hardware/testo/protocol.c
index 46e9ae62..def73d42 100644
--- a/src/hardware/testo/protocol.c
+++ b/src/hardware/testo/protocol.c
@@ -17,6 +17,7 @@
* along with this program. If not, see .
*/
+#include
#include
#include "protocol.h"
@@ -24,28 +25,28 @@ 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;
+ 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;
+ 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;
+ 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;
+ sr_err("Failed to set modem control: %s", libusb_error_name(ret));
+ return SR_ERR;
}
return SR_OK;
@@ -60,13 +61,13 @@ SR_PRIV int testo_probe_channels(struct sr_dev_inst *sdi)
struct sr_usb_dev_inst *usb;
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;
sr_dbg("Probing for channels.");
- if (sdi->driver->dev_open(sdi) != SR_OK)
+ if (sr_dev_open(sdi) != SR_OK)
return SR_ERR;
if (testo_set_serial_params(usb) != SR_OK)
return SR_ERR;
@@ -81,7 +82,7 @@ SR_PRIV int testo_probe_channels(struct sr_dev_inst *sdi)
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;
@@ -107,7 +108,7 @@ SR_PRIV int testo_probe_channels(struct sr_dev_inst *sdi)
/* Got a complete packet. */
break;
}
- sdi->driver->dev_close(sdi);
+ sr_dev_close(sdi);
if (packet[6] > MAX_CHANNELS) {
sr_err("Device says it has %d channels!", packet[6]);
@@ -157,8 +158,7 @@ SR_PRIV int testo_request_packet(const struct sr_dev_inst *sdi)
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);
+ sr_dev_acquisition_stop((struct sr_dev_inst *)sdi);
return SR_ERR;
}
sr_dbg("Requested new packet.");
@@ -170,8 +170,8 @@ SR_PRIV int testo_request_packet(const struct sr_dev_inst *sdi)
* Testo 175/177/400/650/950/435/635/735/445/645/945/946/545. */
SR_PRIV gboolean testo_check_packet_prefix(unsigned char *buf, int len)
{
+ static const unsigned char check[] = { 0x21, 0, 0, 0, 1 };
int i;
- unsigned char check[] = { 0x21, 0, 0, 0, 1 };
if (len < 5)
return FALSE;
@@ -223,6 +223,9 @@ 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_analog_encoding encoding;
+ struct sr_analog_meaning meaning;
+ struct sr_analog_spec spec;
struct sr_channel *ch;
GString *dbg;
float value;
@@ -243,8 +246,10 @@ SR_PRIV void testo_receive_packet(const struct sr_dev_inst *sdi)
packet.type = SR_DF_ANALOG;
packet.payload = &analog;
+ /* TODO: Use proper 'digits' value for this device (and its modes). */
+ sr_analog_init(&analog, &encoding, &meaning, &spec, 2);
analog.num_samples = 1;
- analog.mqflags = 0;
+ analog.meaning->mqflags = 0;
analog.data = &value;
/* Decode 7-byte values */
for (i = 0; i < devc->reply[6]; i++) {
@@ -252,20 +257,20 @@ SR_PRIV void testo_receive_packet(const struct sr_dev_inst *sdi)
value = binary32_le_to_float(buf);
switch (buf[4]) {
case 1:
- analog.mq = SR_MQ_TEMPERATURE;
- analog.unit = SR_UNIT_CELSIUS;
+ analog.meaning->mq = SR_MQ_TEMPERATURE;
+ analog.meaning->unit = SR_UNIT_CELSIUS;
break;
case 3:
- analog.mq = SR_MQ_RELATIVE_HUMIDITY;
- analog.unit = SR_UNIT_HUMIDITY_293K;
+ analog.meaning->mq = SR_MQ_RELATIVE_HUMIDITY;
+ analog.meaning->unit = SR_UNIT_HUMIDITY_293K;
break;
case 5:
- analog.mq = SR_MQ_WIND_SPEED;
- analog.unit = SR_UNIT_METER_SECOND;
+ analog.meaning->mq = SR_MQ_WIND_SPEED;
+ analog.meaning->unit = SR_UNIT_METER_SECOND;
break;
case 24:
- analog.mq = SR_MQ_PRESSURE;
- analog.unit = SR_UNIT_HECTOPASCAL;
+ analog.meaning->mq = SR_MQ_PRESSURE;
+ analog.meaning->unit = SR_UNIT_HECTOPASCAL;
break;
default:
sr_dbg("Unsupported measurement unit %d.", buf[4]);
@@ -283,8 +288,8 @@ SR_PRIV void testo_receive_packet(const struct sr_dev_inst *sdi)
return;
}
ch = g_slist_nth_data(sdi->channels, i);
- analog.channels = g_slist_append(NULL, ch);
+ analog.meaning->channels = g_slist_append(NULL, ch);
sr_session_send(sdi, &packet);
- g_slist_free(analog.channels);
+ g_slist_free(analog.meaning->channels);
}
}