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

Function gen_header

libsigrok4DSL/output/vcd.c:97–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

95}
96
97static GString *gen_header(const struct sr_output *o)
98{
99 struct context *ctx;
100 struct sr_channel *ch;
101 GVariant *gvar;
102 GString *header;
103 GSList *l;
104 time_t t;
105 int num_channels, i, p;
106 char *samplerate_s, *frequency_s, *timestamp;
107
108 ctx = o->priv;
109 header = g_string_sized_new(512);
110 num_channels = g_slist_length(o->sdi->channels);
111
112 /* timestamp */
113 t = time(NULL);
114 timestamp = g_strdup(ctime(&t));
115 timestamp[strlen(timestamp)-1] = 0;
116 g_string_printf(header, "$date %s $end\n", timestamp);
117 g_free(timestamp);
118
119 /* generator */
120 g_string_append_printf(header, "$version %s %s $end\n",
121 PACKAGE, PACKAGE_VERSION);
122 g_string_append_printf(header, "$comment\n Acquisition with "
123 "%d/%d channels", ctx->num_enabled_channels, num_channels);
124
125 if (ctx->samplerate == 0) {
126 if (sr_config_get(o->sdi->driver, o->sdi, NULL, NULL, SR_CONF_SAMPLERATE,
127 &gvar) == SR_OK) {
128 if (gvar != NULL) {
129 ctx->samplerate = g_variant_get_uint64(gvar);
130 g_variant_unref(gvar);
131 }
132 }
133 }
134 if (ctx->samplerate != 0) {
135 samplerate_s = sr_samplerate_string(ctx->samplerate);
136 g_string_append_printf(header, " at %s", samplerate_s);
137 g_free(samplerate_s);
138 }
139 g_string_append_printf(header, "\n$end\n");
140
141 /* timescale */
142 /* VCD can only handle 1/10/100 (s - fs), so scale up first */
143 if (ctx->samplerate > SR_MHZ(1))
144 ctx->period = SR_GHZ(1);
145 else if (ctx->samplerate > SR_KHZ(1))
146 ctx->period = SR_MHZ(1);
147 else
148 ctx->period = SR_KHZ(1);
149 frequency_s = sr_period_string(ctx->period);
150 g_string_append_printf(header, "$timescale %s $end\n", frequency_s);
151 g_free(frequency_s);
152
153 /* scope */
154 g_string_append_printf(header, "$scope module %s $end\n", PACKAGE);

Callers 1

receiveFunction · 0.70

Calls 3

sr_config_getFunction · 0.85
sr_samplerate_stringFunction · 0.85
sr_period_stringFunction · 0.85

Tested by

no test coverage detected