trace_dumpdiff.c 1.57 KB
Newer Older
Jeroen Vreeken's avatar
Jeroen Vreeken committed
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
	Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007, 2008, 2011
	Copyright Stichting C.A. Muller Radioastronomiestation, 2007, 2008, 2011

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.

 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <math.h>

#include "trace.h"


void handle_val(struct traceval *trc)
{
	float val = trace_val(trc);
	static float lastval = -1337.0;

	if (lastval == val)
		return;
	printf("%f %e\n", 
	    (double)trace_seconds(trc) + 
	    (double)trace_sample(trc) * trace_period(trc),
	    val);
	lastval = val;
}


int main(int argc, char **argv)
{
	struct traceval *trc;
	
	trc = trace_create();
	if (!trc)
		return 1;
        
	trace_handler_add(trc, handle_val);
	
	if (argc < 2) {
		printf("Usage:\n\n");
		printf("%s [trace]\n", argv[0]);
	}

	if (trace_init("localhost", 10000, argv[1], trc)) {
		return 1;
	}
		

	while (1) {
		if (trace_handle(trc))
			return 1;
	}

	return 0;
}