aboutsummaryrefslogtreecommitdiff
path: root/tools/disambiguate/disambiguate.c
blob: dcaf9d8d9324c68b4c281adb0a08031612bbe49c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "../../include/disambiguator.h"

int main() {

	FILE * f = fopen( "raw_light_data_from_watchman.csv", "r" );
	if (f == NULL) {
		fprintf(stderr, "ERROR OPENING INPUT FILE\n");
		return -1;
	}

	long last = 0, lastl = 0;

	disambiguator d;
	disambiguator_init(&d);
	for (;;) {
		char controller[10];
		int sensor;
		int unknown;
		int length;
		long time;

		if (fscanf(f, "%s %d %d %d %li", controller, &sensor, &unknown, &length, &time) != 5) {
			break;
		}
		if (lastl > time) {
			printf("BACKWARDS: %li %li\n", lastl, time);
		}
		lastl = time;

		switch (disambiguator_step(&d, time, length)) {
			default:
			case P_UNKNOWN:
				//printf("UNKN  %s %2d %li %d\n", controller, sensor, time - last, length);
				continue;
			case P_SYNC:
				{
					double l = length;
					char cc = round(l / 500) - 6;
					int ll = (length+125)/250;
					printf("SYNC  %s %2d %10li %5d %c%d %10li %d %d\n", controller, sensor, time, length, (cc & 0x1) ? 'k' : 'j', (cc >> 1) & 0x3, time-last, ll & 1, (ll >> 1) - 6);
					last = time;
				}
				continue;
			case P_SWEEP:
				printf("SWEEP %s %2d %10li %5d\n", controller, sensor, time - last, length);
				continue;
		}
	}
	fclose(f);
}