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

Function receive

libsigrok4DSL/output/vcd.c:174–268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

172}
173
174static int receive(const struct sr_output *o, const struct sr_datafeed_packet *packet,
175 GString **out)
176{
177 const struct sr_datafeed_meta *meta;
178 const struct sr_datafeed_logic *logic;
179 const struct sr_config *src;
180 GSList *l;
181 struct context *ctx;
182 unsigned int i;
183 int p, curbit, prevbit, index;
184 uint8_t *sample;
185 gboolean timestamp_written;
186
187 *out = NULL;
188 if (!o || !o->priv)
189 return SR_ERR_BUG;
190 ctx = o->priv;
191
192 switch (packet->type) {
193 case SR_DF_META:
194 meta = packet->payload;
195 for (l = meta->config; l; l = l->next) {
196 src = l->data;
197 if (src->key != SR_CONF_SAMPLERATE)
198 continue;
199 ctx->samplerate = g_variant_get_uint64(src->data);
200 }
201 break;
202 case SR_DF_LOGIC:
203 logic = packet->payload;
204
205 if (!ctx->header_done) {
206 *out = gen_header(o);
207 ctx->header_done = TRUE;
208 } else {
209 *out = g_string_sized_new(512);
210 }
211
212 if (!ctx->prevsample) {
213 /* Can't allocate this until we know the stream's unitsize. */
214 ctx->prevsample = malloc(logic->unitsize);
215
216 if (ctx->prevsample == NULL){
217 sr_err("%s,ERROR:failed to alloc memory.", __func__);
218 }
219 }
220
221 for (i = 0; i <= logic->length - logic->unitsize; i += logic->unitsize) {
222 sample = logic->data + i;
223 timestamp_written = FALSE;
224
225 for (p = 0; p < ctx->num_enabled_channels; p++) {
226 //index = ctx->channel_index[p];
227 index = p;
228
229 curbit = ((unsigned)sample[index / 8]
230 >> (index % 8)) & 1;
231 prevbit = ((unsigned)ctx->prevsample[index / 8]

Callers

nothing calls this directly

Calls 1

gen_headerFunction · 0.70

Tested by

no test coverage detected