]> sigrok.org Git - libsigrok.git/blobdiff - src/input/feed_queue.c
output/csv: use intermediate time_t var, silence compiler warning
[libsigrok.git] / src / input / feed_queue.c
index bd5c16c7f621947f55cd43dd8f641acb3874edab..d62f3f6b71fb000e4018135441920bc502891e33 100644 (file)
@@ -57,14 +57,14 @@ SR_API struct feed_queue_logic *feed_queue_logic_alloc(
        return q;
 }
 
-SR_API int feed_queue_logic_submit(struct feed_queue_logic *q,
-       const uint8_t *data, size_t count)
+SR_API int feed_queue_logic_submit_one(struct feed_queue_logic *q,
+       const uint8_t *data, size_t repeat_count)
 {
        uint8_t *wrptr;
        int ret;
 
        wrptr = &q->data_bytes[q->fill_count * q->unit_size];
-       while (count--) {
+       while (repeat_count--) {
                memcpy(wrptr, data, q->unit_size);
                wrptr += q->unit_size;
                q->fill_count++;
@@ -79,6 +79,35 @@ SR_API int feed_queue_logic_submit(struct feed_queue_logic *q,
        return SR_OK;
 }
 
+SR_API int feed_queue_logic_submit_many(struct feed_queue_logic *q,
+       const uint8_t *data, size_t samples_count)
+{
+       uint8_t *wrptr;
+       size_t space, copy_count;
+       int ret;
+
+       wrptr = &q->data_bytes[q->fill_count * q->unit_size];
+       while (samples_count) {
+               space = q->alloc_count - q->fill_count;
+               copy_count = samples_count;
+               if (copy_count > space)
+                       copy_count = space;
+               memcpy(wrptr, data, copy_count * q->unit_size);
+               data += copy_count * q->unit_size;
+               samples_count -= copy_count;
+               wrptr += copy_count * q->unit_size;
+               q->fill_count += copy_count;
+               if (q->fill_count == q->alloc_count) {
+                       ret = feed_queue_logic_flush(q);
+                       if (ret != SR_OK)
+                               return ret;
+                       wrptr = &q->data_bytes[0];
+               }
+       }
+
+       return SR_OK;
+}
+
 SR_API int feed_queue_logic_flush(struct feed_queue_logic *q)
 {
        int ret;
@@ -95,6 +124,21 @@ SR_API int feed_queue_logic_flush(struct feed_queue_logic *q)
        return SR_OK;
 }
 
+SR_API int feed_queue_logic_send_trigger(struct feed_queue_logic *q)
+{
+       int ret;
+
+       ret = feed_queue_logic_flush(q);
+       if (ret != SR_OK)
+               return ret;
+
+       ret = std_session_send_df_trigger(q->sdi);
+       if (ret != SR_OK)
+               return ret;
+
+       return SR_OK;
+}
+
 SR_API void feed_queue_logic_free(struct feed_queue_logic *q)
 {
 
@@ -147,12 +191,51 @@ SR_API struct feed_queue_analog *feed_queue_analog_alloc(
        return q;
 }
 
-SR_API int feed_queue_analog_submit(struct feed_queue_analog *q,
-       float data, size_t count)
+SR_API int feed_queue_analog_mq_unit(struct feed_queue_analog *q,
+       enum sr_mq mq, enum sr_mqflag mq_flag, enum sr_unit unit)
+{
+       int ret;
+
+       if (!q)
+               return SR_ERR_ARG;
+
+       ret = feed_queue_analog_flush(q);
+       if (ret != SR_OK)
+               return ret;
+
+       q->meaning.mq = mq;
+       q->meaning.mqflags = mq_flag;
+       q->meaning.unit = unit;
+
+       return SR_OK;
+}
+
+SR_API int feed_queue_analog_scale_offset(struct feed_queue_analog *q,
+       const struct sr_rational *scale, const struct sr_rational *offset)
+{
+       int ret;
+
+       if (!q)
+               return SR_ERR_ARG;
+
+       ret = feed_queue_analog_flush(q);
+       if (ret != SR_OK)
+               return ret;
+
+       if (scale)
+               q->encoding.scale = *scale;
+       if (offset)
+               q->encoding.offset = *offset;
+
+       return SR_OK;
+}
+
+SR_API int feed_queue_analog_submit_one(struct feed_queue_analog *q,
+       float data, size_t repeat_count)
 {
        int ret;
 
-       while (count--) {
+       while (repeat_count--) {
                q->data_values[q->fill_count++] = data;
                if (q->fill_count == q->alloc_count) {
                        ret = feed_queue_analog_flush(q);