| 97 | } |
| 98 | |
| 99 | static int loadfile(struct sr_input *in, const char *filename) |
| 100 | { |
| 101 | struct sr_datafeed_packet packet; |
| 102 | struct sr_datafeed_meta meta; |
| 103 | struct sr_datafeed_logic logic; |
| 104 | struct sr_config *src; |
| 105 | unsigned char buffer[CHUNKSIZE]; |
| 106 | int fd, size, num_probes; |
| 107 | struct context *ctx; |
| 108 | |
| 109 | ctx = in->internal; |
| 110 | packet.status = SR_PKT_OK; |
| 111 | |
| 112 | if ((fd = open(filename, O_RDONLY)) == -1) |
| 113 | return SR_ERR; |
| 114 | |
| 115 | num_probes = g_slist_length(in->sdi->channels); |
| 116 | |
| 117 | /* Send header packet to the session bus. */ |
| 118 | std_session_send_df_header(in->sdi, LOG_PREFIX); |
| 119 | |
| 120 | if (ctx->samplerate) { |
| 121 | packet.type = SR_DF_META; |
| 122 | packet.payload = &meta; |
| 123 | src = sr_config_new(SR_CONF_SAMPLERATE, |
| 124 | g_variant_new_uint64(ctx->samplerate)); |
| 125 | meta.config = g_slist_append(NULL, src); |
| 126 | ds_data_forward(in->sdi, &packet); |
| 127 | sr_config_free(src); |
| 128 | } |
| 129 | |
| 130 | /* Chop up the input file into chunks & send it to the session bus. */ |
| 131 | packet.type = SR_DF_LOGIC; |
| 132 | packet.payload = &logic; |
| 133 | logic.unitsize = (num_probes + 7) / 8; |
| 134 | logic.data = buffer; |
| 135 | while ((size = read(fd, buffer, CHUNKSIZE)) > 0) { |
| 136 | logic.length = size; |
| 137 | ds_data_forward(in->sdi, &packet); |
| 138 | } |
| 139 | close(fd); |
| 140 | |
| 141 | /* Send end packet to the session bus. */ |
| 142 | packet.type = SR_DF_END; |
| 143 | ds_data_forward(in->sdi, &packet); |
| 144 | |
| 145 | g_free(ctx); |
| 146 | in->internal = NULL; |
| 147 | |
| 148 | return SR_OK; |
| 149 | } |
| 150 | |
| 151 | SR_PRIV struct sr_input_format input_binary = { |
| 152 | .id = "binary", |
nothing calls this directly
no test coverage detected