]>
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
)
24 int half
= (int)(clock
/2);
25 int firstbit
= bit
^ 1;
27 for (i
= 0; i
< half
; ++i
)
28 GraphBuffer
[GraphTraceLen
++] = firstbit
;
30 for (i
= 0; i
<= half
; ++i
)
31 GraphBuffer
[GraphTraceLen
++] = bit
;
37 /* clear out our graph window */
38 int ClearGraph(int redraw
)
40 int gtl
= GraphTraceLen
;
41 memset(GraphBuffer
, 0x00, GraphTraceLen
);
54 int DetectClock(int peak
)
60 /* Detect peak if we don't have one */
62 for (i
= 0; i
< GraphTraceLen
; ++i
)
63 if (GraphBuffer
[i
] > peak
)
64 peak
= GraphBuffer
[i
];
66 for (i
= 1; i
< GraphTraceLen
; ++i
)
68 /* If this is the beginning of a peak */
69 if (GraphBuffer
[i
- 1] != GraphBuffer
[i
] && GraphBuffer
[i
] == peak
)
71 /* Find lowest difference between peaks */
72 if (lastpeak
&& i
- lastpeak
< clock
)
78 int clockmod
= clock
%8;
82 // When detected clock is 31 or 33 then return 32
84 printf("Found clock at %d ", clock
);
87 case 7: clock
++; break;
88 case 6: clock
+= 2 ; break;
89 case 1: clock
--; break;
90 case 2: clock
-= 2; break;
95 printf("- adjusted it to %d \n", clock
);
99 /* Get or auto-detect clock rate */
100 int GetClock(const char *str
, int peak
, int verbose
)
104 sscanf(str
, "%i", &clock
);
105 if (!strcmp(str
, ""))
108 /* Auto-detect clock */
111 clock
= DetectClock(peak
);
112 /* Only print this message if we're not looping something */
114 PrintAndLog("Auto-detected clock rate: %d", clock
);
121 /* A simple test to see if there is any data inside Graphbuffer.
125 if ( GraphTraceLen
<= 0) {
126 PrintAndLog("No data available, try reading something first");