X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Foutput%2Fcsv.c;h=db023a476050c59ffdb88ef144c8a84377413442;hb=4b1a9d5d8641080bf10e269aa12a3fc17460365f;hp=5f0d647c3d5605be98cc1c883b85be2a29b377ef;hpb=3cd4b381744eb88fd4ba32565bd408c33b431629;p=libsigrok.git diff --git a/src/output/csv.c b/src/output/csv.c index 5f0d647c..db023a47 100644 --- a/src/output/csv.c +++ b/src/output/csv.c @@ -18,11 +18,11 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include #include #include -#include "config.h" /* Needed for PACKAGE_STRING and others. */ -#include "libsigrok.h" +#include #include "libsigrok-internal.h" #define LOG_PREFIX "output/csv" @@ -118,8 +118,8 @@ static GString *gen_header(const struct sr_output *o) /* Some metadata */ t = time(NULL); - g_string_append_printf(header, "; CSV, generated by %s on %s", - PACKAGE_STRING, ctime(&t)); + g_string_append_printf(header, "; CSV, generated by %s %s on %s", + PACKAGE_NAME, SR_PACKAGE_VERSION_STRING, ctime(&t)); /* Columns / channels */ num_channels = g_slist_length(o->sdi->channels); @@ -164,24 +164,24 @@ static void init_output(GString **out, struct context *ctx, } } -static void handle_analog_frame(struct context *ctx, - const struct sr_datafeed_analog *analog) +static void handle_analog_frame(struct context *ctx, GSList *channels, + unsigned int num_samples, float *data) { unsigned int numch, nums, i, j, s; GSList *l; - numch = g_slist_length(analog->channels); - if ((unsigned int)analog->num_samples > numch) - nums = analog->num_samples / numch; + numch = g_slist_length(channels); + if (num_samples > numch) + nums = num_samples / numch; else nums = 1; s = 0; - l = analog->channels; + l = channels; for (i = 0; i < nums; i++) { for (j = 0; j < ctx->num_analog_channels; j++) { if (ctx->analog_channels[j] == l->data) - ctx->analog_vals[j] = analog->data[s++]; + ctx->analog_vals[j] = data[s++]; } l = l->next; } @@ -192,9 +192,12 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p { const struct sr_datafeed_meta *meta; const struct sr_datafeed_logic *logic; + const struct sr_datafeed_analog_old *analog_old; const struct sr_datafeed_analog *analog; const struct sr_config *src; - GSList *l; + unsigned int num_samples; + float *data; + GSList *l, *channels; struct context *ctx; int idx; uint64_t i, j, k, nums, numch; @@ -224,7 +227,7 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p */ memset(ctx->analog_vals, 0, sizeof(float) * ctx->num_analog_channels); ctx->inframe = TRUE; - ret = SR_OK_CONTINUE; + ret = SR_OK; break; case SR_DF_FRAME_END: /* @@ -265,12 +268,28 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p g_string_append_printf(*out, "\n"); } break; + case SR_DF_ANALOG_OLD: case SR_DF_ANALOG: + analog_old = packet->payload; analog = packet->payload; + if (packet->type == SR_DF_ANALOG_OLD) { + channels = analog_old->channels; + numch = g_slist_length(channels); + num_samples = analog_old->num_samples; + data = analog_old->data; + } else { + channels = analog->meaning->channels; + numch = g_slist_length(channels); + num_samples = analog->num_samples; + data = g_malloc(sizeof(float) * num_samples * numch); + ret = sr_analog_to_float(analog, data); + if (ret != SR_OK) + return ret; + } + if (ctx->inframe) { - handle_analog_frame(ctx, analog); - ret = SR_OK_CONTINUE; + handle_analog_frame(ctx, channels, num_samples, data); break; } @@ -278,9 +297,8 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p k = 0; l = NULL; - numch = g_slist_length(analog->channels); - if ((unsigned int)analog->num_samples > numch) - nums = analog->num_samples / numch; + if (num_samples > numch) + nums = num_samples / numch; else nums = 1; @@ -288,11 +306,11 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p for (j = 0; j < ctx->num_enabled_channels; j++) { if (ctx->channels[j]->type == SR_CHANNEL_ANALOG) { if (!l) - l = analog->channels; + l = channels; if (ctx->channels[j] == l->data) { g_string_append_printf(*out, - "%f", analog->data[k++]); + "%f", data[k++]); } l = l->next; @@ -303,7 +321,6 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p g_string_append_printf(*out, "\n"); } break; - /* TODO case SR_DF_ANALOG2: */ } return ret;