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