]> sigrok.org Git - libsigrok.git/commitdiff
teleinfo: Use software limit helpers
authorLars-Peter Clausen <redacted>
Sun, 1 May 2016 11:54:26 +0000 (13:54 +0200)
committerUwe Hermann <redacted>
Mon, 9 May 2016 10:44:41 +0000 (12:44 +0200)
Signed-off-by: Lars-Peter Clausen <redacted>
src/hardware/teleinfo/api.c
src/hardware/teleinfo/protocol.c
src/hardware/teleinfo/protocol.h

index 302373d6b27d2cbe53d7b06e668ca4fa8dd71d23..be4261c976c0d8da3d35775d693989de048df33e 100644 (file)
@@ -148,18 +148,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                return SR_ERR_BUG;
        }
 
-       switch (key) {
-       case SR_CONF_LIMIT_SAMPLES:
-               devc->limit_samples = g_variant_get_uint64(data);
-               break;
-       case SR_CONF_LIMIT_MSEC:
-               devc->limit_msec = g_variant_get_uint64(data);
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return sr_sw_limits_config_set(&devc->sw_limits, key, data);
 }
 
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
@@ -194,13 +183,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
 
        devc = sdi->priv;
 
-       /*
-        * Reset the number of samples to take. If we've already collected our
-        * quota, but we start a new session, and don't reset this, we'll just
-        * quit without acquiring any new samples.
-        */
-       devc->num_samples = 0;
-       devc->start_time = g_get_monotonic_time();
+       sr_sw_limits_acquisition_start(&devc->sw_limits);
 
        std_session_send_df_header(sdi, LOG_PREFIX);
 
index fbbc044d4b96f75b6daf57e8e760556d39efecdb..9cb9ca82f717f94806db7d4b6b3ee9e070a2496f 100644 (file)
@@ -93,7 +93,7 @@ static void teleinfo_handle_measurement(struct sr_dev_inst *sdi,
        }
 
        if (!strcmp(label, "ADCO")) {
-               devc->num_samples++;
+               sr_sw_limits_update_samples_read(&devc->sw_limits, 1);
        } else if (!strcmp(label, "BASE")) {
                teleinfo_send_value(sdi, "BASE", v, SR_MQ_POWER, SR_UNIT_WATT_HOUR);
        } else if (!strcmp(label, "HCHP")) {
@@ -184,7 +184,6 @@ SR_PRIV int teleinfo_receive_data(int fd, int revents, void *cb_data)
        struct sr_serial_dev_inst *serial;
        const uint8_t *ptr, *next_ptr, *end_ptr;
        int len;
-       int64_t time;
 
        (void)fd;
 
@@ -217,19 +216,8 @@ SR_PRIV int teleinfo_receive_data(int fd, int revents, void *cb_data)
                return FALSE;
        }
 
-       if (devc->limit_samples && devc->num_samples >= devc->limit_samples) {
-               sr_info("Requested number of samples reached.");
+       if (sr_sw_limits_check(&devc->sw_limits))
                sdi->driver->dev_acquisition_stop(sdi);
-               return TRUE;
-       }
 
-       if (devc->limit_msec) {
-               time = (g_get_monotonic_time() - devc->start_time) / 1000;
-               if (time > (int64_t)devc->limit_msec) {
-                       sr_info("Requested time limit reached.");
-                       sdi->driver->dev_acquisition_stop(sdi);
-                       return TRUE;
-               }
-       }
        return TRUE;
 }
index b4aa0fef1244148d3573de4ed6f0f58e39701731..3f896523c8bc1f9c0927c7d81144e991ab30e8df 100644 (file)
@@ -40,13 +40,10 @@ enum optarif {
 /** Private, per-device-instance driver context. */
 struct dev_context {
        /* Acquisition settings */
-       uint64_t limit_samples;   /**< The sampling limit (in number of samples). */
-       uint64_t limit_msec;      /**< The time limit (in milliseconds). */
+       struct sr_sw_limits sw_limits;
 
        /* Operational state */
        enum optarif optarif;     /**< The device mode (which measures are reported) */
-       uint64_t num_samples;     /**< The number of already received samples. */
-       int64_t start_time;       /**< The time at which sampling started. */
 
        /* Temporary state across callbacks */
        uint8_t buf[TELEINFO_BUF_SIZE];