X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=blobdiff_plain;f=src%2Flcr%2Fes51919.c;h=f020de8398d850839d66a00af895c092a3813943;hp=59dc194c5f4d795db1e6379994746f1a92d852b5;hb=6525d819eef098a43b1f438ae4af50e67c9c4335;hpb=bb983c666a074d8e16c5f6c16e20870bc6c5d727 diff --git a/src/lcr/es51919.c b/src/lcr/es51919.c index 59dc194c..f020de83 100644 --- a/src/lcr/es51919.c +++ b/src/lcr/es51919.c @@ -17,11 +17,12 @@ * along with this program. If not, see . */ +#include #include #include #include #include -#include "libsigrok.h" +#include #include "libsigrok-internal.h" #define LOG_PREFIX "es51919" @@ -100,32 +101,33 @@ static uint8_t *dev_buffer_packet_find(struct dev_buffer *dbuf, return NULL; } -struct dev_sample_counter { - /** The current number of already received samples. */ +struct dev_limit_counter { + /** The current number of received samples/frames/etc. */ uint64_t count; - /** The current sampling limit (in number of samples). */ + /** The limit (in number of samples/frames/etc.). */ uint64_t limit; }; -static void dev_sample_counter_start(struct dev_sample_counter *cnt) +static void dev_limit_counter_start(struct dev_limit_counter *cnt) { cnt->count = 0; } -static void dev_sample_counter_inc(struct dev_sample_counter *cnt) +static void dev_limit_counter_inc(struct dev_limit_counter *cnt) { cnt->count++; } -static void dev_sample_limit_set(struct dev_sample_counter *cnt, uint64_t limit) +static void dev_limit_counter_limit_set(struct dev_limit_counter *cnt, + uint64_t limit) { cnt->limit = limit; } -static gboolean dev_sample_limit_reached(struct dev_sample_counter *cnt) +static gboolean dev_limit_counter_limit_reached(struct dev_limit_counter *cnt) { if (cnt->limit && cnt->count >= cnt->limit) { - sr_info("Requested sample limit reached."); + sr_info("Requested counter limit reached."); return TRUE; } @@ -304,7 +306,6 @@ static int send_config_update_key(struct sr_dev_inst *sdi, uint32_t key, sr_config_free(cfg); return ret; - } /* @@ -402,24 +403,10 @@ static int send_config_update_key(struct sr_dev_inst *sdi, uint32_t key, #define PACKET_SIZE 17 -static const uint64_t frequencies[] = { +static const double frequencies[] = { 100, 120, 1000, 10000, 100000, 0, }; -enum { QUANT_AUTO = 5, }; - -static const char *const quantities1[] = { - "NONE", "INDUCTANCE", "CAPACITANCE", "RESISTANCE", "RESISTANCE", "AUTO", -}; - -static const char *const list_quantities1[] = { - "NONE", "INDUCTANCE", "CAPACITANCE", "RESISTANCE", "AUTO", -}; - -static const char *const quantities2[] = { - "NONE", "DISSIPATION", "QUALITY", "RESISTANCE", "ANGLE", "AUTO", -}; - enum { MODEL_NONE, MODEL_PAR, MODEL_SER, MODEL_AUTO, }; static const char *const models[] = { @@ -428,11 +415,8 @@ static const char *const models[] = { /** Private, per-device-instance driver context. */ struct dev_context { - /** Opaque pointer passed in by the frontend. */ - void *cb_data; - - /** The number of samples. */ - struct dev_sample_counter sample_count; + /** The number of frames. */ + struct dev_limit_counter frame_count; /** The time limit counter. */ struct dev_time_counter time_count; @@ -443,12 +427,6 @@ struct dev_context { /** The frequency of the test signal (index to frequencies[]). */ unsigned int freq; - /** Measured primary quantity (index to quantities1[]). */ - unsigned int quant1; - - /** Measured secondary quantity (index to quantities2[]). */ - unsigned int quant2; - /** Equivalent circuit model (index to models[]). */ unsigned int model; }; @@ -466,7 +444,7 @@ static int parse_mq(const uint8_t *pkt, int is_secondary, int is_parallel) switch (is_secondary << 8 | buf[0]) { case 0x001: - return is_parallel ? + return is_parallel ? SR_MQ_PARALLEL_INDUCTANCE : SR_MQ_SERIES_INDUCTANCE; case 0x002: return is_parallel ? @@ -504,7 +482,7 @@ static float parse_value(const uint8_t *buf) } static void parse_measurement(const uint8_t *pkt, float *floatval, - struct sr_datafeed_analog *analog, + struct sr_datafeed_analog_old *analog, int is_secondary) { static const struct { @@ -584,18 +562,6 @@ static unsigned int parse_freq(const uint8_t *pkt) return freq; } -static unsigned int parse_quant(const uint8_t *pkt, int is_secondary) -{ - const uint8_t *buf; - - if (pkt[2] & 0x20) - return QUANT_AUTO; - - buf = pkt_to_buf(pkt, is_secondary); - - return buf[0]; -} - static unsigned int parse_model(const uint8_t *pkt) { if (pkt[2] & 0x40) @@ -606,7 +572,6 @@ static unsigned int parse_model(const uint8_t *pkt) return MODEL_PAR; else return MODEL_SER; - } static gboolean packet_valid(const uint8_t *pkt) @@ -627,29 +592,13 @@ static gboolean packet_valid(const uint8_t *pkt) static int do_config_update(struct sr_dev_inst *sdi, uint32_t key, GVariant *var) { - struct dev_context *devc; - - devc = sdi->priv; - - return send_config_update_key(devc->cb_data, key, var); + return send_config_update_key(sdi, key, var); } static int send_freq_update(struct sr_dev_inst *sdi, unsigned int freq) { return do_config_update(sdi, SR_CONF_OUTPUT_FREQUENCY, - g_variant_new_uint64(frequencies[freq])); -} - -static int send_quant1_update(struct sr_dev_inst *sdi, unsigned int quant) -{ - return do_config_update(sdi, SR_CONF_MEASURED_QUANTITY, - g_variant_new_string(quantities1[quant])); -} - -static int send_quant2_update(struct sr_dev_inst *sdi, unsigned int quant) -{ - return do_config_update(sdi, SR_CONF_MEASURED_2ND_QUANTITY, - g_variant_new_string(quantities2[quant])); + g_variant_new_double(frequencies[freq])); } static int send_model_update(struct sr_dev_inst *sdi, unsigned int model) @@ -661,11 +610,11 @@ static int send_model_update(struct sr_dev_inst *sdi, unsigned int model) static void handle_packet(struct sr_dev_inst *sdi, const uint8_t *pkt) { struct sr_datafeed_packet packet; - struct sr_datafeed_analog analog; + struct sr_datafeed_analog_old analog; struct dev_context *devc; unsigned int val; float floatval; - int count; + gboolean frame; devc = sdi->priv; @@ -677,22 +626,6 @@ static void handle_packet(struct sr_dev_inst *sdi, const uint8_t *pkt) return; } - val = parse_quant(pkt, 0); - if (val != devc->quant1) { - if (send_quant1_update(sdi, val) == SR_OK) - devc->quant1 = val; - else - return; - } - - val = parse_quant(pkt, 1); - if (val != devc->quant2) { - if (send_quant2_update(sdi, val) == SR_OK) - devc->quant2 = val; - else - return; - } - val = parse_model(pkt); if (val != devc->model) { if (send_model_update(sdi, val) == SR_OK) @@ -701,34 +634,53 @@ static void handle_packet(struct sr_dev_inst *sdi, const uint8_t *pkt) return; } - count = 0; + frame = FALSE; memset(&analog, 0, sizeof(analog)); analog.num_samples = 1; analog.data = &floatval; - packet.type = SR_DF_ANALOG; - packet.payload = &analog; - analog.channels = g_slist_append(NULL, sdi->channels->data); parse_measurement(pkt, &floatval, &analog, 0); if (analog.mq >= 0) { - if (sr_session_send(devc->cb_data, &packet) == SR_OK) - count++; + if (!frame) { + packet.type = SR_DF_FRAME_BEGIN; + sr_session_send(sdi, &packet); + frame = TRUE; + } + + packet.type = SR_DF_ANALOG_OLD; + packet.payload = &analog; + + sr_session_send(sdi, &packet); } + g_slist_free(analog.channels); analog.channels = g_slist_append(NULL, sdi->channels->next->data); parse_measurement(pkt, &floatval, &analog, 1); if (analog.mq >= 0) { - if (sr_session_send(devc->cb_data, &packet) == SR_OK) - count++; + if (!frame) { + packet.type = SR_DF_FRAME_BEGIN; + sr_session_send(sdi, &packet); + frame = TRUE; + } + + packet.type = SR_DF_ANALOG_OLD; + packet.payload = &analog; + + sr_session_send(sdi, &packet); } - if (count > 0) - dev_sample_counter_inc(&devc->sample_count); + g_slist_free(analog.channels); + + if (frame) { + packet.type = SR_DF_FRAME_END; + sr_session_send(sdi, &packet); + dev_limit_counter_inc(&devc->frame_count); + } } static int handle_new_data(struct sr_dev_inst *sdi) @@ -768,23 +720,13 @@ static int receive_data(int fd, int revents, void *cb_data) handle_new_data(sdi); } - if (dev_sample_limit_reached(&devc->sample_count) || + if (dev_limit_counter_limit_reached(&devc->frame_count) || dev_time_limit_reached(&devc->time_count)) - sdi->driver->dev_acquisition_stop(sdi, cb_data); + sdi->driver->dev_acquisition_stop(sdi); return TRUE; } -static int add_channel(struct sr_dev_inst *sdi, int idx, const char *name) -{ - struct sr_channel *ch; - - ch = sr_channel_new(idx, SR_CHANNEL_ANALOG, TRUE, name); - sdi->channels = g_slist_append(sdi->channels, ch); - - return SR_OK; -} - static const char *const channel_names[] = { "P1", "P2" }; static int setup_channels(struct sr_dev_inst *sdi) @@ -794,11 +736,8 @@ static int setup_channels(struct sr_dev_inst *sdi) ret = SR_ERR_BUG; - for (i = 0; i < ARRAY_SIZE(channel_names); i++) { - ret = add_channel(sdi, i, channel_names[i]); - if (ret != SR_OK) - break; - } + for (i = 0; i < ARRAY_SIZE(channel_names); i++) + sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_names[i]); return ret; } @@ -875,13 +814,7 @@ SR_PRIV int es51919_serial_config_get(uint32_t key, GVariant **data, switch (key) { case SR_CONF_OUTPUT_FREQUENCY: - *data = g_variant_new_uint64(frequencies[devc->freq]); - break; - case SR_CONF_MEASURED_QUANTITY: - *data = g_variant_new_string(quantities1[devc->quant1]); - break; - case SR_CONF_MEASURED_2ND_QUANTITY: - *data = g_variant_new_string(quantities2[devc->quant2]); + *data = g_variant_new_double(frequencies[devc->freq]); break; case SR_CONF_EQUIV_CIRCUIT_MODEL: *data = g_variant_new_string(models[devc->model]); @@ -912,10 +845,10 @@ SR_PRIV int es51919_serial_config_set(uint32_t key, GVariant *data, dev_time_limit_set(&devc->time_count, val); sr_dbg("Setting time limit to %" PRIu64 ".", val); break; - case SR_CONF_LIMIT_SAMPLES: + case SR_CONF_LIMIT_FRAMES: val = g_variant_get_uint64(data); - dev_sample_limit_set(&devc->sample_count, val); - sr_dbg("Setting sample limit to %" PRIu64 ".", val); + dev_limit_counter_limit_set(&devc->frame_count, val); + sr_dbg("Setting frame limit to %" PRIu64 ".", val); break; default: sr_spew("%s: Unsupported key %u", __func__, key); @@ -933,11 +866,9 @@ static const uint32_t scanopts[] = { static const uint32_t devopts[] = { SR_CONF_LCRMETER, SR_CONF_CONTINUOUS, - SR_CONF_LIMIT_SAMPLES | SR_CONF_SET, + SR_CONF_LIMIT_FRAMES | SR_CONF_SET, SR_CONF_LIMIT_MSEC | SR_CONF_SET, SR_CONF_OUTPUT_FREQUENCY | SR_CONF_GET | SR_CONF_LIST, - SR_CONF_MEASURED_QUANTITY | SR_CONF_GET | SR_CONF_LIST, - SR_CONF_MEASURED_2ND_QUANTITY | SR_CONF_GET | SR_CONF_LIST, SR_CONF_EQUIV_CIRCUIT_MODEL | SR_CONF_GET | SR_CONF_LIST, }; @@ -958,16 +889,8 @@ SR_PRIV int es51919_serial_config_list(uint32_t key, GVariant **data, switch (key) { case SR_CONF_OUTPUT_FREQUENCY: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT64, - frequencies, ARRAY_SIZE(frequencies), sizeof(uint64_t)); - break; - case SR_CONF_MEASURED_QUANTITY: - *data = g_variant_new_strv(list_quantities1, - ARRAY_SIZE(list_quantities1)); - break; - case SR_CONF_MEASURED_2ND_QUANTITY: - *data = g_variant_new_strv(quantities2, - ARRAY_SIZE(quantities2)); + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_DOUBLE, + frequencies, ARRAY_SIZE(frequencies), sizeof(double)); break; case SR_CONF_EQUIV_CIRCUIT_MODEL: *data = g_variant_new_strv(models, ARRAY_SIZE(models)); @@ -980,8 +903,7 @@ SR_PRIV int es51919_serial_config_list(uint32_t key, GVariant **data, return SR_OK; } -SR_PRIV int es51919_serial_acquisition_start(const struct sr_dev_inst *sdi, - void *cb_data) +SR_PRIV int es51919_serial_acquisition_start(const struct sr_dev_inst *sdi) { struct dev_context *devc; struct sr_serial_dev_inst *serial; @@ -992,13 +914,10 @@ SR_PRIV int es51919_serial_acquisition_start(const struct sr_dev_inst *sdi, if (!(devc = sdi->priv)) return SR_ERR_BUG; - devc->cb_data = cb_data; - - dev_sample_counter_start(&devc->sample_count); + dev_limit_counter_start(&devc->frame_count); dev_time_counter_start(&devc->time_count); - /* Send header packet to the session bus. */ - std_session_send_df_header(cb_data, LOG_PREFIX); + std_session_send_df_header(sdi, LOG_PREFIX); /* Poll every 50ms, or whenever some data comes in. */ serial = sdi->conn; @@ -1008,9 +927,8 @@ SR_PRIV int es51919_serial_acquisition_start(const struct sr_dev_inst *sdi, return SR_OK; } -SR_PRIV int es51919_serial_acquisition_stop(struct sr_dev_inst *sdi, - void *cb_data) +SR_PRIV int es51919_serial_acquisition_stop(struct sr_dev_inst *sdi) { - return std_serial_dev_acquisition_stop(sdi, cb_data, + return std_serial_dev_acquisition_stop(sdi, std_serial_dev_close, sdi->conn, LOG_PREFIX); }