| 560 | } |
| 561 | |
| 562 | static int loadfile(struct sr_input *in, const char *filename) |
| 563 | { |
| 564 | struct sr_datafeed_packet packet; |
| 565 | struct sr_datafeed_meta meta; |
| 566 | struct sr_config *src; |
| 567 | FILE *file; |
| 568 | struct context *ctx; |
| 569 | uint64_t samplerate; |
| 570 | |
| 571 | ctx = in->internal; |
| 572 | packet.status = SR_PKT_OK; |
| 573 | |
| 574 | if ((file = fopen(filename, "r")) == NULL) |
| 575 | return SR_ERR; |
| 576 | |
| 577 | if (!parse_header(file, ctx)) |
| 578 | { |
| 579 | sr_err("VCD parsing failed"); |
| 580 | fclose(file); |
| 581 | return SR_ERR; |
| 582 | } |
| 583 | |
| 584 | /* Send header packet to the session bus. */ |
| 585 | std_session_send_df_header(in->sdi, LOG_PREFIX); |
| 586 | |
| 587 | /* Send metadata about the SR_DF_LOGIC packets to come. */ |
| 588 | packet.type = SR_DF_META; |
| 589 | packet.payload = &meta; |
| 590 | samplerate = ctx->samplerate / ctx->downsample; |
| 591 | src = sr_config_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(samplerate)); |
| 592 | meta.config = g_slist_append(NULL, src); |
| 593 | ds_data_forward(in->sdi, &packet); |
| 594 | sr_config_free(src); |
| 595 | |
| 596 | /* Parse the contents of the VCD file */ |
| 597 | parse_contents(file, in->sdi, ctx); |
| 598 | |
| 599 | /* Send end packet to the session bus. */ |
| 600 | packet.type = SR_DF_END; |
| 601 | ds_data_forward(in->sdi, &packet); |
| 602 | |
| 603 | fclose(file); |
| 604 | release_context(ctx); |
| 605 | in->internal = NULL; |
| 606 | |
| 607 | return SR_OK; |
| 608 | } |
| 609 | |
| 610 | SR_PRIV struct sr_input_format input_vcd = { |
| 611 | .id = "vcd", |
nothing calls this directly
no test coverage detected