Parse the data section of VCD */
| 433 | |
| 434 | /* Parse the data section of VCD */ |
| 435 | static void parse_contents(FILE *file, const struct sr_dev_inst *sdi, struct context *ctx) |
| 436 | { |
| 437 | GString *token = g_string_sized_new(32); |
| 438 | |
| 439 | uint64_t prev_timestamp = 0; |
| 440 | uint64_t prev_values = 0; |
| 441 | |
| 442 | /* Read one space-delimited token at a time. */ |
| 443 | while (read_until(file, NULL, 'N') && read_until(file, token, 'W')) |
| 444 | { |
| 445 | if (token->str[0] == '#' && isdigit(token->str[1])) |
| 446 | { |
| 447 | /* Numeric value beginning with # is a new timestamp value */ |
| 448 | uint64_t timestamp; |
| 449 | timestamp = strtoull(token->str + 1, NULL, 10); |
| 450 | |
| 451 | if (ctx->downsample > 1) |
| 452 | timestamp /= ctx->downsample; |
| 453 | |
| 454 | /* Skip < 0 => skip until first timestamp. |
| 455 | * Skip = 0 => don't skip |
| 456 | * Skip > 0 => skip until timestamp >= skip. |
| 457 | */ |
| 458 | if (ctx->skip < 0) |
| 459 | { |
| 460 | ctx->skip = timestamp; |
| 461 | prev_timestamp = timestamp; |
| 462 | } |
| 463 | else if (ctx->skip > 0 && timestamp < (uint64_t)ctx->skip) |
| 464 | { |
| 465 | prev_timestamp = ctx->skip; |
| 466 | } |
| 467 | else if (timestamp == prev_timestamp) |
| 468 | { |
| 469 | /* Ignore repeated timestamps (e.g. sigrok outputs these) */ |
| 470 | } |
| 471 | else |
| 472 | { |
| 473 | if (ctx->compress != 0 && timestamp - prev_timestamp > ctx->compress) |
| 474 | { |
| 475 | /* Compress long idle periods */ |
| 476 | prev_timestamp = timestamp - ctx->compress; |
| 477 | } |
| 478 | |
| 479 | sr_dbg("New timestamp: %llu", (u64_t)timestamp); |
| 480 | |
| 481 | /* Generate samples from prev_timestamp up to timestamp - 1. */ |
| 482 | send_samples(sdi, prev_values, timestamp - prev_timestamp); |
| 483 | prev_timestamp = timestamp; |
| 484 | } |
| 485 | } |
| 486 | else if (token->str[0] == '$' && token->len > 1) |
| 487 | { |
| 488 | /* This is probably a $dumpvars, $comment or similar. |
| 489 | * $dump* contain useful data, but other tags will be skipped until $end. */ |
| 490 | if (g_strcmp0(token->str, "$dumpvars") == 0 || |
| 491 | g_strcmp0(token->str, "$dumpon") == 0 || |
| 492 | g_strcmp0(token->str, "$dumpoff") == 0 || |
no test coverage detected