]> git.zerfleddert.de Git - proxmark3-svn/blame - client/graph.c
Minor refactoring
[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>
12#include <string.h>
13#include "ui.h"
14#include "graph.h"
d5a72d2f 15#include "lfdemod.h"
7fe9b0b7 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;
7fe9b0b7 27
7fe9b0b7 28 for (i = (int)(clock / 2); i < clock; ++i)
29 GraphBuffer[GraphTraceLen++] = bit;
30
31 if (redraw)
32 RepaintGraphWindow();
33}
34
c12512e9 35// clear out our graph window
7fe9b0b7 36int ClearGraph(int redraw)
37{
38 int gtl = GraphTraceLen;
52ab55ab 39 memset(GraphBuffer, 0x00, GraphTraceLen);
40
7fe9b0b7 41 GraphTraceLen = 0;
42
43 if (redraw)
44 RepaintGraphWindow();
45
46 return gtl;
47}
48
c12512e9 49// DETECT CLOCK NOW IN LFDEMOD.C
7fe9b0b7 50
ba1a299c 51void setGraphBuf(uint8_t *buff, size_t size)
d5a72d2f 52{
53 int i=0;
54 ClearGraph(0);
55 for (; i < size; ++i){
ba1a299c 56 GraphBuffer[i]=buff[i]-128;
d5a72d2f 57 }
58 GraphTraceLen=size;
59 RepaintGraphWindow();
60 return;
61}
ba1a299c 62size_t getFromGraphBuf(uint8_t *buff)
d5a72d2f 63{
64 uint32_t i;
f822a063 65 for (i=0;i<GraphTraceLen;++i){
66 if (GraphBuffer[i]>127) GraphBuffer[i]=127; //trim
67 if (GraphBuffer[i]<-127) GraphBuffer[i]=-127; //trim
d5a72d2f 68 buff[i]=(uint8_t)(GraphBuffer[i]+128);
f822a063 69 }
d5a72d2f 70 return i;
71}
c12512e9 72// Get or auto-detect clock rate
7fe9b0b7 73int GetClock(const char *str, int peak, int verbose)
74{
75 int clock;
7fe9b0b7 76 sscanf(str, "%i", &clock);
77 if (!strcmp(str, ""))
78 clock = 0;
79
c12512e9 80 // Auto-detect clock
7fe9b0b7 81 if (!clock)
82 {
d5a72d2f 83 uint8_t grph[MAX_GRAPH_TRACE_LEN]={0};
ba1a299c 84 size_t size = getFromGraphBuf(grph);
d5a72d2f 85 clock = DetectASKClock(grph,size,0);
c12512e9 86 // Only print this message if we're not looping something
0e74c023 87 if (!verbose){
7fe9b0b7 88 PrintAndLog("Auto-detected clock rate: %d", clock);
0e74c023 89 }
7fe9b0b7 90 }
91
92 return clock;
93}
ba1a299c 94
4118b74d 95int GetNRZpskClock(const char *str, int peak, int verbose)
96{
ba1a299c 97 int clock;
ba1a299c 98 sscanf(str, "%i", &clock);
99 if (!strcmp(str, ""))
100 clock = 0;
101
102 // Auto-detect clock
103 if (!clock)
104 {
105 uint8_t grph[MAX_GRAPH_TRACE_LEN]={0};
d6d20c54 106 size_t size = getFromGraphBuf(grph);
107 clock = DetectpskNRZClock(grph,size,0);
ba1a299c 108 // Only print this message if we're not looping something
109 if (!verbose){
110 PrintAndLog("Auto-detected clock rate: %d", clock);
ba1a299c 111 }
112 }
113 return clock;
4118b74d 114}
Impressum, Datenschutz