| 152 | } |
| 153 | |
| 154 | static int receive(const struct sr_output *o, const struct sr_datafeed_packet *packet, |
| 155 | GString **out) |
| 156 | { |
| 157 | const struct sr_datafeed_meta *meta; |
| 158 | const struct sr_datafeed_logic *logic; |
| 159 | const struct sr_config *src; |
| 160 | GSList *l; |
| 161 | struct context *ctx; |
| 162 | const uint8_t *sample; |
| 163 | unsigned int curbit, p, idx, i; |
| 164 | |
| 165 | *out = NULL; |
| 166 | if (!o || !o->priv) |
| 167 | return SR_ERR_BUG; |
| 168 | ctx = o->priv; |
| 169 | |
| 170 | if (packet->type == SR_DF_META) { |
| 171 | meta = packet->payload; |
| 172 | for (l = meta->config; l; l = l->next) { |
| 173 | src = l->data; |
| 174 | if (src->key != SR_CONF_SAMPLERATE) |
| 175 | continue; |
| 176 | ctx->samplerate = g_variant_get_uint64(src->data); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | if (packet->type != SR_DF_LOGIC) |
| 181 | return SR_OK; |
| 182 | logic = packet->payload; |
| 183 | |
| 184 | if (!ctx->prevsample) { |
| 185 | /* Can't allocate this until we know the stream's unitsize. */ |
| 186 | ctx->prevsample = malloc(logic->unitsize); |
| 187 | |
| 188 | if (ctx->prevsample == NULL){ |
| 189 | sr_err("%s,ERROR:failed to alloc memory.", __func__); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | if (!ctx->header_done) { |
| 194 | *out = gen_header(o); |
| 195 | ctx->header_done = TRUE; |
| 196 | } else { |
| 197 | *out = g_string_sized_new(512); |
| 198 | } |
| 199 | |
| 200 | for (i = 0; i <= logic->length - logic->unitsize; i += logic->unitsize) { |
| 201 | sample = logic->data + i; |
| 202 | ctx->samplecount++; |
| 203 | |
| 204 | /* |
| 205 | * Don't output the same sample multiple times, but make |
| 206 | * sure to output at least the first and last sample. |
| 207 | */ |
| 208 | if (i > 0 && i < logic->length - logic->unitsize) { |
| 209 | if (!memcmp(sample, ctx->prevsample, logic->unitsize)) |
| 210 | continue; |
| 211 | } |
nothing calls this directly
no test coverage detected