]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/graph.c
18ff972a6e7449d46b9debefd17533b6a34020cf
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 //-----------------------------------------------------------------------------
16 int GraphBuffer
[MAX_GRAPH_TRACE_LEN
];
19 /* write a bit to the graph */
20 void AppendGraph(int redraw
, int clock
, int bit
)
24 for (i
= 0; i
< (int)(clock
/ 2); ++i
)
25 GraphBuffer
[GraphTraceLen
++] = bit
^ 1;
27 for (i
= (int)(clock
/ 2); i
< clock
; ++i
)
28 GraphBuffer
[GraphTraceLen
++] = bit
;
34 /* clear out our graph window */
35 int ClearGraph(int redraw
)
37 int gtl
= GraphTraceLen
;
49 //decommissioned - has difficulty detecting rf/32 and only works if data is manchester encoded
51 int DetectClock2(int peak)
57 // Detect peak if we don't have one
59 for (i = 0; i < GraphTraceLen; ++i)
60 if (GraphBuffer[i] > peak)
61 peak = GraphBuffer[i];
63 // peak=(int)(peak*.75);
64 for (i = 1; i < GraphTraceLen; ++i)
66 // If this is the beginning of a peak
67 if (GraphBuffer[i - 1] != GraphBuffer[i] && GraphBuffer[i] >= peak)
69 // Find lowest difference between peaks
70 if (lastpeak && i - lastpeak < clock)
81 // not perfect especially with lower clocks or VERY good antennas (heavy wave clipping)
82 // maybe somehow adjust peak trimming value based on samples to fix?
83 int DetectClock(int peak
)
87 int clk
[]={16,32,40,50,64,100,128,256};
89 for (i
=0;i
<GraphTraceLen
;++i
){
90 if(GraphBuffer
[i
]>peak
){
91 peak
= GraphBuffer
[i
];
93 if(GraphBuffer
[i
]<low
){
103 if (GraphTraceLen
<loopCnt
) loopCnt
= GraphTraceLen
;
107 int errCnt
[]={0,0,0,0,0,0,0,0};
109 for(clkCnt
=0; clkCnt
<6;++clkCnt
){
110 if (clk
[clkCnt
]==32){
116 for (ii
=0; ii
<loopCnt
; ++ii
){
117 if ((GraphBuffer
[ii
]>=peak
) || (GraphBuffer
[ii
]<=low
)){
121 for (i
=0; i
<((int)(GraphTraceLen
/clk
[clkCnt
])-1); ++i
){
122 if (GraphBuffer
[ii
+(i
*clk
[clkCnt
])]>=peak
|| GraphBuffer
[ii
+(i
*clk
[clkCnt
])]<=low
){
124 }else if(GraphBuffer
[ii
+(i
*clk
[clkCnt
])-tol
]>=peak
|| GraphBuffer
[ii
+(i
*clk
[clkCnt
])-tol
]<=low
){
125 }else if(GraphBuffer
[ii
+(i
*clk
[clkCnt
])+tol
]>=peak
|| GraphBuffer
[ii
+(i
*clk
[clkCnt
])+tol
]<=low
){
126 }else{ //error no peak detected
133 if(errCnt
[clkCnt
]==0) return clk
[clkCnt
];
134 if(errCnt
[clkCnt
]<bestErr
) bestErr
=errCnt
[clkCnt
];
137 errCnt
[clkCnt
]=bestErr
;
141 for (iii
=0; iii
<6;++iii
){
142 if (errCnt
[iii
]<errCnt
[best
]){
146 PrintAndLog("clkCnt: %d, ii: %d, i: %d peak: %d, low: %d, errcnt: %d, errCnt64: %d",clkCnt
,ii
,i
,peak
,low
,errCnt
[best
],errCnt
[4]);
151 /* Get or auto-detect clock rate */
152 int GetClock(const char *str
, int peak
, int verbose
)
156 sscanf(str
, "%i", &clock
);
157 if (!strcmp(str
, ""))
160 /* Auto-detect clock */
163 clock
= DetectClock(peak
);
164 //clock2 = DetectClock2(peak);
165 /* Only print this message if we're not looping something */
167 PrintAndLog("Auto-detected clock rate: %d", clock
);
168 //PrintAndLog("clock2: %d",clock2);