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

Function loadfile

libsigrok4DSL/input/in_binary.c:99–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97}
98
99static 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
151SR_PRIV struct sr_input_format input_binary = {
152 .id = "binary",

Callers

nothing calls this directly

Calls 4

sr_config_newFunction · 0.85
ds_data_forwardFunction · 0.85
sr_config_freeFunction · 0.85

Tested by

no test coverage detected