X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Farachnid-labs-re-load-pro%2Fprotocol.c;h=cbca8e53f38efa9ba6d0dcdce8779ed551faa16e;hb=f6e7b6124a646b0ece644681d4e0172ffb30a561;hp=8bc8935246e7b1f69959c68828f2ca3749382c01;hpb=803db07a1af036a5da65581ddbac23b7f84a4388;p=libsigrok.git diff --git a/src/hardware/arachnid-labs-re-load-pro/protocol.c b/src/hardware/arachnid-labs-re-load-pro/protocol.c index 8bc89352..cbca8e53 100644 --- a/src/hardware/arachnid-labs-re-load-pro/protocol.c +++ b/src/hardware/arachnid-labs-re-load-pro/protocol.c @@ -89,6 +89,21 @@ SR_PRIV int reloadpro_set_current_limit(const struct sr_dev_inst *sdi, return SR_OK; } +SR_PRIV int reloadpro_set_on_off(const struct sr_dev_inst *sdi, gboolean on) +{ + int ret; + char buf[100]; + const char *cmd; + + cmd = (on) ? "on\n" : "off\n"; + if ((ret = send_cmd(sdi, cmd, (char *)&buf, sizeof(buf))) < 0) { + sr_err("Error sending on/off command: %d.", ret); + return SR_ERR; + } + + return SR_OK; +} + SR_PRIV int reloadpro_get_current_limit(const struct sr_dev_inst *sdi, float *current) { @@ -133,7 +148,10 @@ static void handle_packet(const struct sr_dev_inst *sdi) { float voltage, current; struct sr_datafeed_packet packet; - struct sr_datafeed_analog_old analog; + struct sr_datafeed_analog analog; + struct sr_analog_encoding encoding; + struct sr_analog_meaning meaning; + struct sr_analog_spec spec; struct dev_context *devc; char **tokens; GSList *l; @@ -141,11 +159,17 @@ static void handle_packet(const struct sr_dev_inst *sdi) devc = sdi->priv; if (g_str_has_prefix((const char *)devc->buf, "overtemp")) { - sr_dbg("Overtemperature condition!"); + sr_warn("Overtemperature condition!"); devc->otp_active = TRUE; return; } + if (g_str_has_prefix((const char *)devc->buf, "undervolt")) { + sr_warn("Undervoltage condition!"); + devc->uvc_active = TRUE; + return; + } + if (!g_str_has_prefix((const char *)devc->buf, "read ")) { sr_dbg("Unknown packet: '%s'.", devc->buf); return; @@ -156,23 +180,24 @@ static void handle_packet(const struct sr_dev_inst *sdi) current = g_ascii_strtod(tokens[1], NULL) / 1000; g_strfreev(tokens); - memset(&analog, 0, sizeof(struct sr_datafeed_analog_old)); - /* Begin frame. */ packet.type = SR_DF_FRAME_BEGIN; + packet.payload = NULL; sr_session_send(sdi, &packet); - packet.type = SR_DF_ANALOG_OLD; + sr_analog_init(&analog, &encoding, &meaning, &spec, 4); + + packet.type = SR_DF_ANALOG; packet.payload = &analog; analog.num_samples = 1; /* Voltage */ l = g_slist_copy(sdi->channels); l = g_slist_remove_link(l, g_slist_nth(l, 1)); - analog.channels = l; - analog.mq = SR_MQ_VOLTAGE; - analog.mqflags = SR_MQFLAG_DC; - analog.unit = SR_UNIT_VOLT; + meaning.channels = l; + meaning.mq = SR_MQ_VOLTAGE; + meaning.mqflags = SR_MQFLAG_DC; + meaning.unit = SR_UNIT_VOLT; analog.data = &voltage; sr_session_send(sdi, &packet); g_slist_free(l); @@ -180,19 +205,20 @@ static void handle_packet(const struct sr_dev_inst *sdi) /* Current */ l = g_slist_copy(sdi->channels); l = g_slist_remove_link(l, g_slist_nth(l, 0)); - analog.channels = l; - analog.mq = SR_MQ_CURRENT; - analog.mqflags = SR_MQFLAG_DC; - analog.unit = SR_UNIT_AMPERE; + meaning.channels = l; + meaning.mq = SR_MQ_CURRENT; + meaning.mqflags = SR_MQFLAG_DC; + meaning.unit = SR_UNIT_AMPERE; analog.data = ¤t; sr_session_send(sdi, &packet); g_slist_free(l); /* End frame. */ packet.type = SR_DF_FRAME_END; + packet.payload = NULL; sr_session_send(sdi, &packet); - devc->num_samples++; + sr_sw_limits_update_samples_read(&devc->limits, 1); } static void handle_new_data(const struct sr_dev_inst *sdi) @@ -226,7 +252,6 @@ SR_PRIV int reloadpro_receive_data(int fd, int revents, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; - int64_t t; (void)fd; @@ -238,20 +263,8 @@ SR_PRIV int reloadpro_receive_data(int fd, int revents, void *cb_data) handle_new_data(sdi); - if (devc->limit_samples && (devc->num_samples >= devc->limit_samples)) { - sr_info("Requested number of samples reached."); - sdi->driver->dev_acquisition_stop(sdi, cb_data); - return TRUE; - } - - if (devc->limit_msec) { - t = (g_get_monotonic_time() - devc->starttime) / 1000; - if (t > (int64_t)devc->limit_msec) { - sr_info("Requested time limit reached."); - sdi->driver->dev_acquisition_stop(sdi, cb_data); - return TRUE; - } - } + if (sr_sw_limits_check(&devc->limits)) + sdi->driver->dev_acquisition_stop(sdi); return TRUE; }