/alps/ipecamera

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/ipecamera

« back to all changes in this revision

Viewing changes to apps/compare_to_value.c

  • Committer: Suren A. Chilingaryan
  • Date: 2015-04-27 00:28:57 UTC
  • Revision ID: csa@suren.me-20150427002857-82fk6r3e8rfgy4wr
First stand-alone ipecamera implementation

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <stdio.h>
2
 
#include <stdlib.h>
3
 
#include <stdint.h>
4
 
 
5
 
int main(int argc, char *argv[]) {
6
 
    long i, j, size, num;
7
 
    size_t count = 0, total = 0;
8
 
    int offset = 0, toread = 1, toskip = 0;
9
 
    uint32_t value;
10
 
    uint32_t *buf;
11
 
    
12
 
    if ((argc != 4)&&(argc != 7)) {
13
 
        printf("Usage: %s <file> <dwords> <value> [offset_dwords read_dwords skip_dwords] \n", argv[0]);
14
 
        exit(0);
15
 
    }
16
 
    
17
 
    FILE *f = fopen(argv[1], "r");
18
 
    if (!f) {
19
 
        printf("Can't open %s\n", argv[1]);
20
 
        exit(1);
21
 
    }
22
 
    
23
 
    size = atol(argv[2]);
24
 
    if (size <= 0) {
25
 
        printf("Can't parse size %s\n", argv[2]);
26
 
        exit(1);
27
 
    }
28
 
    
29
 
    if (sscanf(argv[3], "%x", &value) != 1) {
30
 
        printf("Can't parse register %s\n", argv[3]);
31
 
        exit(1);
32
 
    }
33
 
 
34
 
    buf = malloc(size * sizeof(uint32_t));
35
 
    if (!buf) {
36
 
        printf("Can't allocate %lu bytes of memory\n", size * sizeof(uint32_t));
37
 
        exit(1);
38
 
    }
39
 
    
40
 
    if (argc == 7) {
41
 
        offset = atoi(argv[4]);
42
 
        toread = atoi(argv[5]);
43
 
        toskip = atoi(argv[6]);
44
 
    }
45
 
    
46
 
 
47
 
    num = fread(buf, 4, size, f);
48
 
    if (num != size) {
49
 
        printf("Only %lu of %lu dwords in the file\n", num, size);
50
 
        exit(1);
51
 
    }
52
 
    fclose(f);
53
 
    
54
 
    for (i = offset; i < size; i += toskip) {
55
 
        for (j = 0; j < toread; j++, i++) {
56
 
            total++;
57
 
            if (buf[i] != value) {
58
 
                count++;
59
 
            }
60
 
        }
61
 
    }
62
 
    free(buf);
63
 
    
64
 
    printf("%lu of %lu is wrong\n", count, total);
65
 
    return 0;
66
 
}