]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/graph.c
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
)
25 int half
= (int)(clock
/2);
26 int firstbit
= bit
^ 1;
28 for (i
= 0; i
< half
; ++i
)
29 GraphBuffer
[GraphTraceLen
++] = firstbit
;
31 for (i
= 0; i
<= half
; ++i
)
32 GraphBuffer
[GraphTraceLen
++] = bit
;
38 /* clear out our graph window */
39 int ClearGraph(int redraw
)
41 int gtl
= GraphTraceLen
;
42 memset(GraphBuffer
, 0x00, GraphTraceLen
);
52 void SetGraphBuf(uint8_t *buff
, int 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
];
68 // Copies grahpbuff to buff.
69 // while triming values to the range -127 -- 127.
70 int GetFromGraphBuf(uint8_t *buff
)
72 if ( buff
== NULL
) return -1;
75 for (; i
< GraphTraceLen
; ++i
){
77 // trim upper and lower values.
78 if (GraphBuffer
[i
] > 127)
80 else if (GraphBuffer
[i
] < -127)
81 GraphBuffer
[i
] = -127;
83 buff
[i
] = (uint8_t)(GraphBuffer
[i
] + 128);
87 /* Get or auto-detect clock rate */
88 int GetClock(const char *str
, int verbose
)
92 sscanf(str
, "%i", &clock
);
96 /* Auto-detect clock */
99 uint8_t grph
[MAX_GRAPH_TRACE_LEN
] = {0x00};
100 int size
= GetFromGraphBuf(grph
);
102 PrintAndLog("Failed to copy from graphbuffer");
105 clock
= DetectASKClock(grph
, size
, 0);
107 /* Only print this message if we're not looping something */
109 PrintAndLog("Auto-detected clock rate: %d", clock
);
114 // A simple test to see if there is any data inside Graphbuffer.
117 if ( GraphTraceLen
<= 0) {
118 PrintAndLog("No data available, try reading something first");
124 // Detect high and lows in Grapbuffer.
125 // Only loops the first 256 values.
126 void DetectHighLowInGraph(int *high
, int *low
, bool addFuzz
) {
128 uint8_t loopMax
= 255;
129 if ( loopMax
> GraphTraceLen
)
130 loopMax
= GraphTraceLen
;
132 for (uint8_t i
= 0; i
< loopMax
; ++i
) {
133 if (GraphBuffer
[i
] > *high
)
134 *high
= GraphBuffer
[i
];
135 else if (GraphBuffer
[i
] < *low
)
136 *low
= GraphBuffer
[i
];
139 //12% fuzz in case highs and lows aren't clipped
141 *high
= (int)(*high
* .88);
142 *low
= (int)(*low
* .88);