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