]> git.zerfleddert.de Git - proxmark3-svn/blob - client/graph.c
Inital test for the "lf em4x 410xsim / lf em4x 410xwatch" which I try to verify that...
[proxmark3-svn] / client / graph.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
3 //
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
6 // the license.
7 //-----------------------------------------------------------------------------
8 // Graph utilities
9 //-----------------------------------------------------------------------------
10
11 #include <stdio.h>
12 #include <stdbool.h>
13 #include <string.h>
14 #include "ui.h"
15 #include "graph.h"
16
17 int GraphBuffer[MAX_GRAPH_TRACE_LEN];
18 int GraphTraceLen;
19
20 /* write a bit to the graph */
21 void AppendGraph(int redraw, int clock, int bit)
22 {
23 int i;
24
25 for (i = 0; i < (int)(clock / 2); ++i)
26 GraphBuffer[GraphTraceLen++] = bit ^ 1;
27
28 for (i = (int)(clock / 2); i < clock; ++i)
29 GraphBuffer[GraphTraceLen++] = bit;
30
31 if (redraw)
32 RepaintGraphWindow();
33 }
34
35 /* clear out our graph window */
36 int ClearGraph(int redraw)
37 {
38 int gtl = GraphTraceLen;
39 memset(GraphBuffer, 0x00, GraphTraceLen);
40
41 GraphTraceLen = 0;
42
43 if (redraw)
44 RepaintGraphWindow();
45
46 return gtl;
47 }
48
49 /*
50 * Detect clock rate
51 */
52 int DetectClock(int peak)
53 {
54 int i;
55 int clock = 0xFFFF;
56 int lastpeak = 0;
57
58 /* Detect peak if we don't have one */
59 if (!peak)
60 for (i = 0; i < GraphTraceLen; ++i)
61 if (GraphBuffer[i] > peak)
62 peak = GraphBuffer[i];
63
64 for (i = 1; i < GraphTraceLen; ++i)
65 {
66 /* If this is the beginning of a peak */
67 if (GraphBuffer[i - 1] != GraphBuffer[i] && GraphBuffer[i] == peak)
68 {
69 /* Find lowest difference between peaks */
70 if (lastpeak && i - lastpeak < clock)
71 clock = i - lastpeak;
72 lastpeak = i;
73 }
74 }
75
76 return clock;
77 }
78
79 /* Get or auto-detect clock rate */
80 int GetClock(const char *str, int peak, int verbose)
81 {
82 int clock;
83
84 sscanf(str, "%i", &clock);
85 if (!strcmp(str, ""))
86 clock = 0;
87
88 /* Auto-detect clock */
89 if (!clock)
90 {
91 clock = DetectClock(peak);
92 /* Only print this message if we're not looping something */
93 if (!verbose)
94 PrintAndLog("Auto-detected clock rate: %d", clock);
95 }
96
97 return clock;
98 }
99
100
101 /* A simple test to see if there is any data inside Graphbuffer.
102 */
103 bool HasGraphData(){
104
105 if ( GraphTraceLen <= 0) {
106 PrintAndLog("No data available, try reading something first");
107 return false;
108 }
109 return true;
110 }
Impressum, Datenschutz