/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/check_counter.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
 
    int block = 0;
7
 
    uint32_t value = 0;
8
 
    uint32_t buf[1024];
9
 
    
10
 
    if (argc < 2) {
11
 
        printf("Usage:\n\t\t%s <file-to-check>\n", argv[0]);
12
 
        exit(0);
13
 
    }
14
 
    
15
 
    FILE *f = fopen(argv[1], "r");
16
 
    if (!f) {
17
 
        printf("Failed to open file %s\n", argv[1]);
18
 
        exit(1);
19
 
    }
20
 
    
21
 
    
22
 
    while (!feof(f)) {
23
 
        int i, n = fread(buf, 4, 1024, f);
24
 
 
25
 
        if (block) i = 0;
26
 
        else {
27
 
            i = 1;
28
 
            value = (buf[0]);
29
 
        }
30
 
 
31
 
        for (; i < n; i++) {
32
 
            if ((buf[i]) != ++value) {
33
 
                printf("Pos %lx (Block %i, dword %i) expected %x, but got %x\n", block * 4096 + i * 4, block, i, value, (buf[i]));
34
 
                exit(1);
35
 
            }
36
 
        }
37
 
        
38
 
        if (n) block++;
39
 
    }
40
 
 
41
 
    fclose(f);
42
 
    
43
 
    printf("Checked %i blocks. All is fine\n", block);
44
 
    return 0;
45
 
}