From 04864faac5c0bfc38a0e7cfd204cb4607ef62b63 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Tue, 6 Mar 2012 13:05:46 +0100 Subject: [PATCH] add check_ctr.c --- utils/check_ctr.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 utils/check_ctr.c diff --git a/utils/check_ctr.c b/utils/check_ctr.c new file mode 100644 index 0000000..3c0909e --- /dev/null +++ b/utils/check_ctr.c @@ -0,0 +1,86 @@ +/* utility to check a recorded WAV file in fgpa.test_mode=1 for + * discontinuities in the counter increment/decrements */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#define STEP 1 + +static int check_continuity(uint16_t *samples, uint32_t size) +{ + uint16_t *end = samples + size/sizeof(uint16_t); + uint16_t *cur; + int inited = 0; + uint16_t last_i, last_q; + + for (cur = samples; cur < end; cur += 2) { + if (!inited) { + last_i = cur[0]; + last_q = cur[1]; + printf("initial I=%04x, Q=%04x\n", + last_i, last_q); + inited = 1; + continue; + } + + if (cur[0] != (uint16_t)(last_i - STEP) || + cur[1] != (uint16_t)(last_q + STEP)) { + fprintf(stderr, "Disocntinuity at %u: " + "I=%04x/%04x Q=%04x/%04x\n", + cur - samples, last_i, cur[0], + last_q, cur[1]); + } + + last_i = cur[0]; + last_q = cur[1]; + } + + return 0; +} + +int main(int argc, char **argv) +{ + struct stat st; + int fd; + void *map; + uint16_t *samples; + + if (argc < 2) { + fprintf(stderr, "You have to specify a wave file name\n"); + exit(2); + } + + fd = open(argv[1], O_RDONLY); + if (fd < 0) { + perror("opening file"); + exit(2); + } + + if (fstat(fd, &st) < 0) { + perror("stat"); + exit(1); + } + + map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); + if (!map) { + perror("mmap"); + exit(1); + } + + if (memcmp(map, "RIFF", 4)) { + fprintf(stderr, "Doeesn't look like a WAV file\n"); + exit(1); + } + + samples = (uint16_t *)(map + 0x44); + check_continuity(samples, st.st_size-0x44); + + exit(0); +}