]> cvs.zerfleddert.de Git - proxmark3-svn/blame - client/graph.c
FIX: Another try to see if the "lf em4x 410xsim" becomes better, added the clock...
[proxmark3-svn] / client / graph.c
CommitLineData
a553f267 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
7fe9b0b7 11#include <stdio.h>
c6be64da 12#include <stdbool.h>
7fe9b0b7 13#include <string.h>
14#include "ui.h"
15#include "graph.h"
16
17int GraphBuffer[MAX_GRAPH_TRACE_LEN];
18int GraphTraceLen;
19
20/* write a bit to the graph */
21void 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 */
36int ClearGraph(int redraw)
37{
38 int gtl = GraphTraceLen;
2ae8a312 39 memset(GraphBuffer, 0x00, GraphTraceLen);
7fe9b0b7 40
2ae8a312 41 GraphTraceLen = 0;
42
7fe9b0b7 43 if (redraw)
44 RepaintGraphWindow();
45
46 return gtl;
47}
48
49/*
50 * Detect clock rate
51 */
52int 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 */
80int 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}
c6be64da 99
100
101/* A simple test to see if there is any data inside Graphbuffer.
102*/
103bool 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