]>
Commit | Line | Data |
---|---|---|
a553f267 | 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 | ||
7fe9b0b7 | 11 | #include <stdio.h> |
12 | #include <string.h> | |
13 | #include "ui.h" | |
14 | #include "graph.h" | |
d5a72d2f | 15 | #include "lfdemod.h" |
7fe9b0b7 | 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 | { | |
ba1a299c | 23 | int i; |
7fe9b0b7 | 24 | |
ba1a299c | 25 | for (i = 0; i < (int)(clock / 2); ++i) |
26 | GraphBuffer[GraphTraceLen++] = bit ^ 1; | |
7fe9b0b7 | 27 | |
ba1a299c | 28 | for (i = (int)(clock / 2); i < clock; ++i) |
29 | GraphBuffer[GraphTraceLen++] = bit; | |
30 | ||
31 | if (redraw) | |
32 | RepaintGraphWindow(); | |
7fe9b0b7 | 33 | } |
34 | ||
c12512e9 | 35 | // clear out our graph window |
7fe9b0b7 | 36 | int ClearGraph(int redraw) |
37 | { | |
ba1a299c | 38 | int gtl = GraphTraceLen; |
39 | GraphTraceLen = 0; | |
7fe9b0b7 | 40 | |
ba1a299c | 41 | if (redraw) |
42 | RepaintGraphWindow(); | |
7fe9b0b7 | 43 | |
ba1a299c | 44 | return gtl; |
7fe9b0b7 | 45 | } |
46 | ||
c12512e9 | 47 | // DETECT CLOCK NOW IN LFDEMOD.C |
7fe9b0b7 | 48 | |
ba1a299c | 49 | void setGraphBuf(uint8_t *buff, size_t size) |
d5a72d2f | 50 | { |
ba1a299c | 51 | int i=0; |
52 | ClearGraph(0); | |
53 | for (; i < size; ++i){ | |
54 | GraphBuffer[i]=buff[i]-128; | |
55 | } | |
56 | GraphTraceLen=size; | |
57 | RepaintGraphWindow(); | |
58 | return; | |
d5a72d2f | 59 | } |
ba1a299c | 60 | size_t getFromGraphBuf(uint8_t *buff) |
d5a72d2f | 61 | { |
ba1a299c | 62 | uint32_t i; |
63 | for (i=0;i<GraphTraceLen;++i){ | |
64 | if (GraphBuffer[i]>127) GraphBuffer[i]=127; //trim | |
65 | if (GraphBuffer[i]<-127) GraphBuffer[i]=-127; //trim | |
66 | buff[i]=(uint8_t)(GraphBuffer[i]+128); | |
67 | } | |
68 | return i; | |
d5a72d2f | 69 | } |
c12512e9 | 70 | // Get or auto-detect clock rate |
7fe9b0b7 | 71 | int GetClock(const char *str, int peak, int verbose) |
72 | { | |
ba1a299c | 73 | int clock; |
ba1a299c | 74 | sscanf(str, "%i", &clock); |
75 | if (!strcmp(str, "")) | |
76 | clock = 0; | |
77 | ||
c12512e9 | 78 | // Auto-detect clock |
ba1a299c | 79 | if (!clock) |
80 | { | |
81 | uint8_t grph[MAX_GRAPH_TRACE_LEN]={0}; | |
82 | size_t size = getFromGraphBuf(grph); | |
83 | clock = DetectASKClock(grph,size,0); | |
c12512e9 | 84 | // Only print this message if we're not looping something |
ba1a299c | 85 | if (!verbose){ |
86 | PrintAndLog("Auto-detected clock rate: %d", clock); | |
ba1a299c | 87 | } |
88 | } | |
89 | ||
90 | return clock; | |
7fe9b0b7 | 91 | } |
ba1a299c | 92 | |
4118b74d | 93 | int GetNRZpskClock(const char *str, int peak, int verbose) |
94 | { | |
ba1a299c | 95 | int clock; |
ba1a299c | 96 | sscanf(str, "%i", &clock); |
97 | if (!strcmp(str, "")) | |
98 | clock = 0; | |
99 | ||
100 | // Auto-detect clock | |
101 | if (!clock) | |
102 | { | |
103 | uint8_t grph[MAX_GRAPH_TRACE_LEN]={0}; | |
d6d20c54 | 104 | size_t size = getFromGraphBuf(grph); |
105 | clock = DetectpskNRZClock(grph,size,0); | |
ba1a299c | 106 | // Only print this message if we're not looping something |
107 | if (!verbose){ | |
108 | PrintAndLog("Auto-detected clock rate: %d", clock); | |
ba1a299c | 109 | } |
110 | } | |
111 | return clock; | |
4118b74d | 112 | } |