MCPcopy Create free account
hub / github.com/DreamSourceLab/DSView / gen_header

Function gen_header

libsigrok4DSL/output/csv.c:143–212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141}
142
143static GString *gen_header(const struct sr_output *o)
144{
145 struct context *ctx;
146 struct sr_channel *ch;
147 GString *header;
148 GSList *l;
149 time_t t;
150 int num_channels, i;
151
152 ctx = o->priv;
153 header = g_string_sized_new(512);
154
155 /* Some metadata */
156 t = time(NULL);
157 g_string_append_printf(header, "; CSV, generated by %s on %s",
158 PACKAGE_STRING, ctime(&t));
159
160 /* Columns / channels */
161 if (ctx->type == SR_CHANNEL_LOGIC)
162 num_channels = g_slist_length(o->sdi->channels);
163 else
164 num_channels = ctx->num_enabled_channels;
165 g_string_append_printf(header, "; Channels (%d/%d)\n",
166 ctx->num_enabled_channels, num_channels);
167
168
169 char *samplerate_s = sr_samplerate_string(ctx->samplerate);
170 g_string_append_printf(header, "; Sample rate: %s\n", samplerate_s);
171 g_free(samplerate_s);
172
173 char *depth_s = sr_samplecount_string(ctx->limit_samples);
174 g_string_append_printf(header, "; Sample count: %s\n", depth_s);
175 g_free(depth_s);
176
177 if (ctx->type == SR_CHANNEL_LOGIC)
178 g_string_append_printf(header, "Time(s),");
179
180 i = 0;
181
182 for (l = o->sdi->channels; l; l = l->next) {
183 ch = l->data;
184
185 if (ch->type != ctx->type)
186 continue;
187 if (!ch->enabled)
188 continue;
189
190 if (ctx->type == SR_CHANNEL_DSO) {
191 char *unit_s = ctx->channel_unit[i] >= 1000000 ? "kV" :
192 ctx->channel_unit[i] >= 1000 ? "V" : "mV";
193 //sr_info("head %d:%s", i, unit_s);
194 g_string_append_printf(header, " %s (Unit: %s),", ch->name, unit_s);
195 }
196 else if (ctx->type == SR_CHANNEL_ANALOG) {
197 g_string_append_printf(header, " %s (Unit: %s),", ch->name, ch->map_unit);
198 }
199 else {
200 g_string_append_printf(header, " %s,", ch->name);

Callers 1

receiveFunction · 0.70

Calls 2

sr_samplerate_stringFunction · 0.85
sr_samplecount_stringFunction · 0.85

Tested by

no test coverage detected