X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Funi-t-ut32x%2Fprotocol.c;h=904ed5ba30f71a0ed6ce4e928de8769611bfbe41;hb=0d8a3063e315064ff73f154ea7d94acb41fe8ba6;hp=65cb756bd87774dc4b275d5673710507d9654d94;hpb=155b680da482cea2381becb73c51cfb838bff31e;p=libsigrok.git diff --git a/src/hardware/uni-t-ut32x/protocol.c b/src/hardware/uni-t-ut32x/protocol.c index 65cb756b..904ed5ba 100644 --- a/src/hardware/uni-t-ut32x/protocol.c +++ b/src/hardware/uni-t-ut32x/protocol.c @@ -17,13 +17,10 @@ * along with this program. If not, see . */ -#include "protocol.h" - +#include #include #include - -extern struct sr_dev_driver uni_t_ut32x_driver_info; -static struct sr_dev_driver *di = &uni_t_ut32x_driver_info; +#include "protocol.h" static float parse_temperature(unsigned char *buf) { @@ -64,6 +61,9 @@ static void process_packet(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; GString *spew; float temp; int i; @@ -90,18 +90,18 @@ static void process_packet(struct sr_dev_inst *sdi) is_valid = FALSE; if (is_valid) { - memset(&analog, 0, sizeof(struct sr_datafeed_analog)); - analog.mq = SR_MQ_TEMPERATURE; - analog.mqflags = 0; + sr_analog_init(&analog, &encoding, &meaning, &spec, 0); + analog.meaning->mq = SR_MQ_TEMPERATURE; + analog.meaning->mqflags = 0; switch (devc->packet[5] - 0x30) { case 1: - analog.unit = SR_UNIT_CELSIUS; + analog.meaning->unit = SR_UNIT_CELSIUS; break; case 2: - analog.unit = SR_UNIT_FAHRENHEIT; + analog.meaning->unit = SR_UNIT_FAHRENHEIT; break; case 3: - analog.unit = SR_UNIT_KELVIN; + analog.meaning->unit = SR_UNIT_KELVIN; break; default: /* We can still pass on the measurement, whatever it is. */ @@ -110,17 +110,17 @@ static void process_packet(struct sr_dev_inst *sdi) switch (devc->packet[13] - 0x30) { case 0: /* Channel T1. */ - analog.channels = g_slist_append(NULL, g_slist_nth_data(sdi->channels, 0)); + analog.meaning->channels = g_slist_append(NULL, g_slist_nth_data(sdi->channels, 0)); break; case 1: /* Channel T2. */ - analog.channels = g_slist_append(NULL, g_slist_nth_data(sdi->channels, 1)); + analog.meaning->channels = g_slist_append(NULL, g_slist_nth_data(sdi->channels, 1)); break; case 2: case 3: /* Channel T1-T2. */ - analog.channels = g_slist_append(NULL, g_slist_nth_data(sdi->channels, 2)); - analog.mqflags |= SR_MQFLAG_RELATIVE; + analog.meaning->channels = g_slist_append(NULL, g_slist_nth_data(sdi->channels, 2)); + analog.meaning->mqflags |= SR_MQFLAG_RELATIVE; break; default: sr_err("Unknown channel 0x%.2x.", devc->packet[13]); @@ -131,8 +131,8 @@ static void process_packet(struct sr_dev_inst *sdi) analog.data = &temp; packet.type = SR_DF_ANALOG; packet.payload = &analog; - sr_session_send(devc->cb_data, &packet); - g_slist_free(analog.channels); + sr_session_send(sdi, &packet); + g_slist_free(analog.meaning->channels); } } @@ -141,13 +141,12 @@ static void process_packet(struct sr_dev_inst *sdi) * memory slots come through as "----" measurements. */ devc->num_samples++; if (devc->limit_samples && devc->num_samples >= devc->limit_samples) { - sdi->driver->dev_acquisition_stop((struct sr_dev_inst *)sdi, - devc->cb_data); + sdi->driver->dev_acquisition_stop(sdi); } } -SR_PRIV void uni_t_ut32x_receive_transfer(struct libusb_transfer *transfer) +SR_PRIV void LIBUSB_CALL uni_t_ut32x_receive_transfer(struct libusb_transfer *transfer) { struct dev_context *devc; struct sr_dev_inst *sdi; @@ -194,8 +193,8 @@ SR_PRIV int uni_t_ut32x_handle_events(int fd, int revents, void *cb_data) { struct drv_context *drvc; struct dev_context *devc; + struct sr_dev_driver *di; struct sr_dev_inst *sdi; - struct sr_datafeed_packet packet; struct sr_usb_dev_inst *usb; struct timeval tv; int len, ret; @@ -204,11 +203,12 @@ SR_PRIV int uni_t_ut32x_handle_events(int fd, int revents, void *cb_data) (void)fd; (void)revents; - drvc = di->priv; - if (!(sdi = cb_data)) return TRUE; + di = sdi->driver; + drvc = di->context; + if (!(devc = sdi->priv)) return TRUE; @@ -218,8 +218,7 @@ SR_PRIV int uni_t_ut32x_handle_events(int fd, int revents, void *cb_data) if (sdi->status == SR_ST_STOPPING) { usb_source_remove(sdi->session, drvc->sr_ctx); - packet.type = SR_DF_END; - sr_session_send(cb_data, &packet); + std_session_send_df_end(sdi); /* Tell the device to stop sending USB packets. */ usb = sdi->conn; @@ -237,4 +236,3 @@ SR_PRIV int uni_t_ut32x_handle_events(int fd, int revents, void *cb_data) return TRUE; } -