+ sample_size = logic->unitsize;
+ if (logic->length == 0)
+ break;
+
+ /* Don't store any samples until triggered. */
+ if (opt_wait_trigger && !triggered)
+ break;
+
+ if (limit_samples && received_samples >= limit_samples)
+ break;
+
+ ret = sr_filter_probes(sample_size, unitsize, logic_probelist,
+ logic->data, logic->length,
+ &filter_out, &filter_out_len);
+ if (ret != SR_OK)
+ break;
+
+ /* What comes out of the filter is guaranteed to be packed into the
+ * minimum size needed to support the number of samples at this sample
+ * size. however, the driver may have submitted too much -- cut off
+ * the buffer of the last packet according to the sample limit.
+ */
+ if (limit_samples && (received_samples + logic->length / sample_size >
+ limit_samples * sample_size))
+ filter_out_len = limit_samples * sample_size - received_samples;
+
+ if (opt_output_file && default_output_format) {
+ /* Saving to a session file. */
+ g_byte_array_append(savebuf, filter_out, filter_out_len);
+ } else {
+ if (opt_pds) {
+ if (srd_session_send(received_samples, (uint8_t*)filter_out,
+ filter_out_len) != SRD_OK)
+ sr_session_stop();
+ } else {
+ output_len = 0;
+ if (o->format->data && packet->type == o->format->df_type)
+ o->format->data(o, filter_out, filter_out_len,
+ &output_buf, &output_len);
+ if (output_len) {
+ fwrite(output_buf, 1, output_len, outfile);
+ fflush(outfile);
+ g_free(output_buf);
+ }
+ }
+ }
+ g_free(filter_out);
+
+ received_samples += logic->length / sample_size;
+ break;
+
+ case SR_DF_ANALOG:
+ analog = packet->payload;
+ g_message("cli: received SR_DF_ANALOG, %d samples", analog->num_samples);
+ if (analog->num_samples == 0)
+ break;
+
+ if (limit_samples && received_samples >= limit_samples)
+ break;
+
+ if (o->format->data && packet->type == o->format->df_type) {
+ o->format->data(o, (const uint8_t *)analog->data,
+ analog->num_samples * sizeof(float),
+ &output_buf, &output_len);
+ if (output_buf) {
+ fwrite(output_buf, 1, output_len, outfile);
+ fflush(outfile);
+ g_free(output_buf);
+ }
+ }
+
+ received_samples += analog->num_samples;
+ break;
+
+ case SR_DF_FRAME_BEGIN:
+ g_debug("cli: received SR_DF_FRAME_BEGIN");
+ if (o->format->event) {
+ o->format->event(o, SR_DF_FRAME_BEGIN, &output_buf,
+ &output_len);
+ if (output_buf) {
+ fwrite(output_buf, 1, output_len, outfile);
+ fflush(outfile);
+ g_free(output_buf);
+ }
+ }
+ break;
+
+ case SR_DF_FRAME_END:
+ g_debug("cli: received SR_DF_FRAME_END");
+ if (o->format->event) {
+ o->format->event(o, SR_DF_FRAME_END, &output_buf,
+ &output_len);
+ if (output_buf) {
+ fwrite(output_buf, 1, output_len, outfile);
+ fflush(outfile);
+ g_free(output_buf);
+ }
+ }
+ break;
+
+ default: