]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/graph.c
f41568e4f57c887b3c3a6bc304aecb5ebd8d89bb
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
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
7 //-----------------------------------------------------------------------------
9 //-----------------------------------------------------------------------------
17 int GraphBuffer
[MAX_GRAPH_TRACE_LEN
];
20 /* write a bit to the graph */
21 void AppendGraph(int redraw
, int clock
, int bit
)
25 for (i
= 0; i
< (int)(clock
/ 2); ++i
)
26 GraphBuffer
[GraphTraceLen
++] = bit
^ 1;
28 for (i
= (int)(clock
/ 2); i
< clock
; ++i
)
29 GraphBuffer
[GraphTraceLen
++] = bit
;
35 /* clear out our graph window */
36 int ClearGraph(int redraw
)
38 int gtl
= GraphTraceLen
;
50 //decommissioned - has difficulty detecting rf/32
52 int DetectClockOld(int peak)
58 // Detect peak if we don't have one
60 for (i = 0; i < GraphTraceLen; ++i)
61 if (GraphBuffer[i] > peak)
62 peak = GraphBuffer[i];
64 // peak=(int)(peak*.75);
65 for (i = 1; i < GraphTraceLen; ++i)
67 // If this is the beginning of a peak
68 if (GraphBuffer[i - 1] != GraphBuffer[i] && GraphBuffer[i] >= peak)
70 // Find lowest difference between peaks
71 if (lastpeak && i - lastpeak < clock)
84 // not perfect especially with lower clocks or VERY good antennas (heavy wave clipping)
85 // maybe somehow adjust peak trimming value based on samples to fix?
86 int DetectASKClock(int peak)
90 int clk[]={16,32,40,50,64,100,128,256};
92 if (GraphTraceLen<loopCnt) loopCnt = GraphTraceLen;
94 for (i=0;i<loopCnt;++i){
95 if(GraphBuffer[i]>peak){
96 peak = GraphBuffer[i];
98 if(GraphBuffer[i]<low){
102 peak=(int)(peak*.75);
109 int errCnt[]={0,0,0,0,0,0,0,0};
110 for(clkCnt=0; clkCnt<6;++clkCnt){
111 if (clk[clkCnt]==32){
117 for (ii=0; ii<loopCnt; ++ii){
118 if ((GraphBuffer[ii]>=peak) || (GraphBuffer[ii]<=low)){
120 for (i=0; i<((int)(GraphTraceLen/clk[clkCnt])-1); ++i){
121 if (GraphBuffer[ii+(i*clk[clkCnt])]>=peak || GraphBuffer[ii+(i*clk[clkCnt])]<=low){
122 }else if(GraphBuffer[ii+(i*clk[clkCnt])-tol]>=peak || GraphBuffer[ii+(i*clk[clkCnt])-tol]<=low){
123 }else if(GraphBuffer[ii+(i*clk[clkCnt])+tol]>=peak || GraphBuffer[ii+(i*clk[clkCnt])+tol]<=low){
124 }else{ //error no peak detected
128 if(errCnt[clkCnt]==0) return clk[clkCnt];
129 if(errCnt[clkCnt]<bestErr) bestErr=errCnt[clkCnt];
135 for (iii=0; iii<6;++iii){
136 if (errCnt[iii]<errCnt[best]){
140 // PrintAndLog("DEBUG: clkCnt: %d, ii: %d, i: %d peak: %d, low: %d, errcnt: %d, errCnt64: %d",clkCnt,ii,i,peak,low,errCnt[best],errCnt[4]);
144 void setGraphBuf(uint8_t *buff
, size_t size
)
148 for (; i
< size
; ++i
){
149 GraphBuffer
[i
]=buff
[i
]-128;
152 RepaintGraphWindow();
155 size_t getFromGraphBuf(uint8_t *buff
)
158 for (i
=0;i
<GraphTraceLen
;++i
){
159 if (GraphBuffer
[i
]>127) GraphBuffer
[i
]=127; //trim
160 if (GraphBuffer
[i
]<-127) GraphBuffer
[i
]=-127; //trim
161 buff
[i
]=(uint8_t)(GraphBuffer
[i
]+128);
165 /* Get or auto-detect clock rate */
166 int GetClock(const char *str
, int peak
, int verbose
)
170 sscanf(str
, "%i", &clock
);
171 if (!strcmp(str
, ""))
174 /* Auto-detect clock */
177 uint8_t grph
[MAX_GRAPH_TRACE_LEN
]={0};
178 size_t size
= getFromGraphBuf(grph
);
179 clock
= DetectASKClock(grph
,size
,0);
180 //clock2 = DetectClock2(peak);
181 /* Only print this message if we're not looping something */
183 PrintAndLog("Auto-detected clock rate: %d", clock
);
184 //PrintAndLog("clock2: %d",clock2);
190 int GetNRZpskClock(const char *str
, int peak
, int verbose
)
192 // return GetClock(str,peak,verbose);
195 sscanf(str
, "%i", &clock
);
196 if (!strcmp(str
, ""))
199 /* Auto-detect clock */
202 uint8_t grph
[MAX_GRAPH_TRACE_LEN
]={0};
203 size_t size
= getFromGraphBuf(grph
);
204 clock
= DetectpskNRZClock(grph
,size
,0);
205 //clock2 = DetectClock2(peak);
206 /* Only print this message if we're not looping something */
208 PrintAndLog("Auto-detected clock rate: %d", clock
);
209 //PrintAndLog("clock2: %d",clock2);
214 // Get or auto-detect clock rate
216 int GetNRZpskClock(const char *str, int peak, int verbose)
220 sscanf(str, "%i", &clock);
221 if (!strcmp(str, ""))
227 uint8_t grph[MAX_GRAPH_TRACE_LEN]={0};
228 int size = getFromGraphBuf(grph);
229 clock = DetectASKClock(grph,size,0);
230 //clock2 = DetectClock2(peak);
231 // Only print this message if we're not looping something
233 PrintAndLog("Auto-detected clock rate: %d", clock);
234 //PrintAndLog("clock2: %d",clock2);