]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/graph.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
7 //-----------------------------------------------------------------------------
9 //-----------------------------------------------------------------------------
17 int GraphBuffer
[MAX_GRAPH_TRACE_LEN
];
20 /* write a bit to the graph */
21 void AppendGraph(int redraw
, int clock
, int bit
)
25 for (i
= 0; i
< (int)(clock
/ 2); ++i
)
26 GraphBuffer
[GraphTraceLen
++] = bit
^ 1;
28 for (i
= (int)(clock
/ 2); i
< clock
; ++i
)
29 GraphBuffer
[GraphTraceLen
++] = bit
;
35 /* clear out our graph window */
36 int ClearGraph(int redraw
)
38 int gtl
= GraphTraceLen
;
39 memset(GraphBuffer
, 0x00, GraphTraceLen
);
52 int DetectClock(int peak
)
58 /* Detect peak if we don't have one */
60 for (i
= 0; i
< GraphTraceLen
; ++i
)
61 if (GraphBuffer
[i
] > peak
)
62 peak
= GraphBuffer
[i
];
64 for (i
= 1; i
< GraphTraceLen
; ++i
)
66 /* If this is the beginning of a peak */
67 if (GraphBuffer
[i
- 1] != GraphBuffer
[i
] && GraphBuffer
[i
] == peak
)
69 /* Find lowest difference between peaks */
70 if (lastpeak
&& i
- lastpeak
< clock
)
79 /* Get or auto-detect clock rate */
80 int GetClock(const char *str
, int peak
, int verbose
)
84 sscanf(str
, "%i", &clock
);
88 /* Auto-detect clock */
91 clock
= DetectClock(peak
);
92 /* Only print this message if we're not looping something */
94 PrintAndLog("Auto-detected clock rate: %d", clock
);
101 /* A simple test to see if there is any data inside Graphbuffer.
105 if ( GraphTraceLen
<= 0) {
106 PrintAndLog("No data available, try reading something first");