diff --git a/include/villas/nodes/comedi.h b/include/villas/nodes/comedi.h index 6da5fd647..311874ca6 100644 --- a/include/villas/nodes/comedi.h +++ b/include/villas/nodes/comedi.h @@ -46,27 +46,27 @@ struct comedi_chanspec { struct comedi_direction { int subdevice; ///< Comedi subdevice - int buffer_size; ///< Comedi's kernel buffer size + int buffer_size; ///< Comedi's kernel buffer size in kB int sample_size; ///< Size of a single measurement sample int sample_rate_hz; ///< Sample rate in Hz bool present; ///< Config present bool enabled; ///< Card is started successfully bool running; ///< Card is actively transfering samples struct timespec started; ///< Timestamp when sampling started - int counter; ///< Number of villas samples transfered + struct timespec last_debug; ///< Timestamp of last debug output + size_t counter; ///< Number of villas samples transfered struct comedi_chanspec *chanspecs; ///< Range and maxdata config of channels unsigned *chanlist; ///< Channel list in comedi's packed format size_t chanlist_len; ///< Number of channels for this direction + char* buffer; char* bufptr; }; struct comedi { char *device; - struct comedi_direction in, out; - comedi_t *dev; #if COMEDI_USE_READ diff --git a/lib/nodes/comedi.c b/lib/nodes/comedi.c index 72026318c..624cec3d8 100644 --- a/lib/nodes/comedi.c +++ b/lib/nodes/comedi.c @@ -329,6 +329,7 @@ static int comedi_start_out(struct node *n) // output will only start after the internal trigger d->running = false; + d->last_debug = time_now(); // allocate buffer for one complete villas sample // TODO: maybe increase buffer size according to c->vectorize @@ -358,6 +359,10 @@ static int comedi_start_out(struct node *n) } } + const size_t villas_samples_in_kernel_buf = d->buffer_size / (d->sample_size * d->chanlist_len); + const double latencyMs = (double)villas_samples_in_kernel_buf / d->sample_rate_hz * 1e3; + info("Added latency due to buffering: %4.1f ms\n", latencyMs); + return 0; } @@ -871,12 +876,19 @@ int comedi_write(struct node *n, struct sample *smps[], unsigned cnt) const size_t raw_samples_in_buffer = bytes_in_buffer / d->sample_size; const size_t villas_samples_in_buffer = raw_samples_in_buffer / d->chanlist_len; + if(villas_samples_in_buffer == buffer_capacity_villas) { warn("Comedi buffer is full"); return 0; - } else if(villas_samples_in_buffer % 1000 == 0) { - info("Comedi buffer: %4ld / %ld villas samples", - villas_samples_in_buffer, buffer_capacity_villas); + } else { + struct timespec now = time_now(); + if(time_delta(&d->last_debug, &now) >= 1) { + debug(LOG_COMEDI | 2, "Comedi write buffer: %4ld villas samples (%2.0f%% of buffer)", + villas_samples_in_buffer, + (100.0f * villas_samples_in_buffer / buffer_capacity_villas)); + + d->last_debug = time_now(); + } } size_t villas_samples_written = 0;