]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/manson-hcs-3xxx/protocol.c
output/csv: use intermediate time_t var, silence compiler warning
[libsigrok.git] / src / hardware / manson-hcs-3xxx / protocol.c
index 6521a4510b9b2b1a3ec81390cd56d741b70623fa..30017d1cdcbaeea092676db753ca31bdab4d8b42 100644 (file)
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-/** @file
-  *  <em>Manson HCS-3xxx Series</em> power supply driver
-  *  @internal
-  */
-
 #include <config.h>
 #include "protocol.h"
 
@@ -56,10 +50,12 @@ SR_PRIV int hcs_send_cmd(struct sr_serial_dev_inst *serial, const char *cmd, ...
 /**
  * Read data from interface into buffer blocking until @a lines number of \\r chars
  * received.
+ *
  * @param serial Previously initialized serial port structure.
  * @param[in] lines Number of \\r-terminated lines to read (1-n).
- * @param     buf Buffer for result. Contents is NUL-terminated on success.
+ * @param buf Buffer for result. Contents is NUL-terminated on success.
  * @param[in] buflen Buffer length (>0).
+ *
  * @retval SR_OK Lines received and ending with "OK\r" (success).
  * @retval SR_ERR Error.
  * @retval SR_ERR_ARG Invalid argument.
@@ -124,27 +120,33 @@ static void send_sample(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;
 
        devc = sdi->priv;
 
+       sr_analog_init(&analog, &encoding, &meaning, &spec, 2);
+
        packet.type = SR_DF_ANALOG;
        packet.payload = &analog;
-       analog.channels = sdi->channels;
+       analog.meaning->channels = sdi->channels;
        analog.num_samples = 1;
 
-       analog.mq = SR_MQ_VOLTAGE;
-       analog.unit = SR_UNIT_VOLT;
-       analog.mqflags = SR_MQFLAG_DC;
+       analog.meaning->mq = SR_MQ_VOLTAGE;
+       analog.meaning->unit = SR_UNIT_VOLT;
+       analog.meaning->mqflags = SR_MQFLAG_DC;
        analog.data = &devc->voltage;
        sr_session_send(sdi, &packet);
 
-       analog.mq = SR_MQ_CURRENT;
-       analog.unit = SR_UNIT_AMPERE;
-       analog.mqflags = 0;
+       analog.meaning->mq = SR_MQ_CURRENT;
+       analog.meaning->unit = SR_UNIT_AMPERE;
+       analog.meaning->mqflags = 0;
        analog.data = &devc->current;
        sr_session_send(sdi, &packet);
 
-       devc->num_samples++;
+
+       sr_sw_limits_update_samples_read(&devc->limits, 1);
 }
 
 static int parse_reply(struct sr_dev_inst *sdi)
@@ -206,7 +208,7 @@ SR_PRIV int hcs_receive_data(int fd, int revents, void *cb_data)
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
-       int64_t t, elapsed_us;
+       uint64_t elapsed_us;
 
        (void)fd;
 
@@ -225,21 +227,11 @@ SR_PRIV int hcs_receive_data(int fd, int revents, void *cb_data)
                /* Timeout. */
        }
 
-       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);
+       if (sr_sw_limits_check(&devc->limits)) {
+               sr_dev_acquisition_stop(sdi);
                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;
-               }
-       }
-
        /* Request next packet, if required. */
        if (sdi->status == SR_ST_ACTIVE) {
                if (devc->reply_pending) {