]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/graph.c
269c2dd98cb8696b149db0d297c3f0b9be81c06c
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 //-----------------------------------------------------------------------------
18 int GraphBuffer
[MAX_GRAPH_TRACE_LEN
];
21 /* write a bit to the graph */
22 void AppendGraph(int redraw
, int clock
, int bit
)
26 for (i
= 0; i
< (int)(clock
/ 2); ++i
)
27 GraphBuffer
[GraphTraceLen
++] = bit
^ 1;
29 for (i
= (int)(clock
/ 2); i
< clock
; ++i
)
30 GraphBuffer
[GraphTraceLen
++] = bit
;
36 // clear out our graph window
37 int ClearGraph(int redraw
)
39 int gtl
= GraphTraceLen
;
40 memset(GraphBuffer
, 0x00, GraphTraceLen
);
50 // DETECT CLOCK NOW IN LFDEMOD.C
52 void setGraphBuf(uint8_t *buff
, size_t size
)
54 if ( buff
== NULL
) return;
57 if ( size
> MAX_GRAPH_TRACE_LEN
)
58 size
= MAX_GRAPH_TRACE_LEN
;
60 for (; i
< size
; ++i
){
61 GraphBuffer
[i
]=buff
[i
]-128;
67 size_t getFromGraphBuf(uint8_t *buff
)
69 if ( buff
== NULL
) return -1;
72 for (i
=0;i
<GraphTraceLen
;++i
){
73 if (GraphBuffer
[i
]>127) GraphBuffer
[i
]=127; //trim
74 if (GraphBuffer
[i
]<-127) GraphBuffer
[i
]=-127; //trim
75 buff
[i
]=(uint8_t)(GraphBuffer
[i
]+128);
79 // Get or auto-detect clock rate
80 int GetClock(const char *str
, int peak
, int verbose
)
83 sscanf(str
, "%i", &clock
);
90 uint8_t grph
[MAX_GRAPH_TRACE_LEN
]={0};
91 size_t size
= getFromGraphBuf(grph
);
93 PrintAndLog("Failed to copy from graphbuffer");
96 clock
= DetectASKClock(grph
,size
,0);
97 // Only print this message if we're not looping something
99 PrintAndLog("Auto-detected clock rate: %d", clock
);
105 // A simple test to see if there is any data inside Graphbuffer.
108 if ( GraphTraceLen
<= 0) {
109 PrintAndLog("No data available, try reading something first");
115 // Detect high and lows in Grapbuffer.
116 // Only loops the first 256 values.
117 void DetectHighLowInGraph(int *high
, int *low
, bool addFuzz
) {
119 uint8_t loopMax
= 255;
120 if ( loopMax
> GraphTraceLen
)
121 loopMax
= GraphTraceLen
;
123 for (uint8_t i
= 0; i
< loopMax
; ++i
) {
124 if (GraphBuffer
[i
] > *high
)
125 *high
= GraphBuffer
[i
];
126 else if (GraphBuffer
[i
] < *low
)
127 *low
= GraphBuffer
[i
];
130 //12% fuzz in case highs and lows aren't clipped
132 *high
= (int)(*high
* .88);
133 *low
= (int)(*low
* .88);
137 int GetNRZpskClock(const char *str
, int peak
, int verbose
)
140 sscanf(str
, "%i", &clock
);
141 if (!strcmp(str
, ""))
147 uint8_t grph
[MAX_GRAPH_TRACE_LEN
]={0};
148 size_t size
= getFromGraphBuf(grph
);
149 clock
= DetectpskNRZClock(grph
,size
,0);
150 // Only print this message if we're not looping something
152 PrintAndLog("Auto-detected clock rate: %d", clock
);