]> cvs.zerfleddert.de Git - proxmark3-svn/blame - client/graph.c
add LEGIC decoder (submitted by Sourcerer, untested by me)
[proxmark3-svn] / client / graph.c
CommitLineData
7fe9b0b7 1#include <stdio.h>
2#include <string.h>
3#include "ui.h"
4#include "graph.h"
5
6int GraphBuffer[MAX_GRAPH_TRACE_LEN];
7int GraphTraceLen;
8
9/* write a bit to the graph */
10void AppendGraph(int redraw, int clock, int bit)
11{
12 int i;
13
14 for (i = 0; i < (int)(clock / 2); ++i)
15 GraphBuffer[GraphTraceLen++] = bit ^ 1;
16
17 for (i = (int)(clock / 2); i < clock; ++i)
18 GraphBuffer[GraphTraceLen++] = bit;
19
20 if (redraw)
21 RepaintGraphWindow();
22}
23
24/* clear out our graph window */
25int ClearGraph(int redraw)
26{
27 int gtl = GraphTraceLen;
28 GraphTraceLen = 0;
29
30 if (redraw)
31 RepaintGraphWindow();
32
33 return gtl;
34}
35
36/*
37 * Detect clock rate
38 */
39int DetectClock(int peak)
40{
41 int i;
42 int clock = 0xFFFF;
43 int lastpeak = 0;
44
45 /* Detect peak if we don't have one */
46 if (!peak)
47 for (i = 0; i < GraphTraceLen; ++i)
48 if (GraphBuffer[i] > peak)
49 peak = GraphBuffer[i];
50
51 for (i = 1; i < GraphTraceLen; ++i)
52 {
53 /* If this is the beginning of a peak */
54 if (GraphBuffer[i - 1] != GraphBuffer[i] && GraphBuffer[i] == peak)
55 {
56 /* Find lowest difference between peaks */
57 if (lastpeak && i - lastpeak < clock)
58 clock = i - lastpeak;
59 lastpeak = i;
60 }
61 }
62
63 return clock;
64}
65
66/* Get or auto-detect clock rate */
67int GetClock(const char *str, int peak, int verbose)
68{
69 int clock;
70
71 sscanf(str, "%i", &clock);
72 if (!strcmp(str, ""))
73 clock = 0;
74
75 /* Auto-detect clock */
76 if (!clock)
77 {
78 clock = DetectClock(peak);
79 /* Only print this message if we're not looping something */
80 if (!verbose)
81 PrintAndLog("Auto-detected clock rate: %d", clock);
82 }
83
84 return clock;
85}
Impressum, Datenschutz