- int i;
- int clock = 0xFFFF;
- int lastpeak = 0;
-
- // Detect peak if we don't have one
- if (!peak)
- for (i = 0; i < GraphTraceLen; ++i)
- if (GraphBuffer[i] > peak)
- peak = GraphBuffer[i];
-
- // peak=(int)(peak*.75);
- for (i = 1; i < GraphTraceLen; ++i)
- {
- // If this is the beginning of a peak
- if (GraphBuffer[i - 1] != GraphBuffer[i] && GraphBuffer[i] >= peak)
- {
- // Find lowest difference between peaks
- if (lastpeak && i - lastpeak < clock)
- clock = i - lastpeak;
- lastpeak = i;
- }
- }
-
- return clock;
+ int clock;
+ sscanf(str, "%i", &clock);
+ if (!strcmp(str, ""))
+ clock = 0;
+
+ if (clock != 0) return clock;
+
+ // Auto-detect clock
+ uint8_t grph[MAX_GRAPH_TRACE_LEN]={0};
+ size_t size = getFromGraphBuf(grph);
+ if (size == 0) {
+ if (verbose)
+ PrintAndLog("Failed to copy from graphbuffer");
+ return -1;
+ }
+ bool st = DetectST(grph, &size, &clock);
+ int start = 0;
+ if (st == false)
+ start = DetectASKClock(grph, size, &clock, 20);
+
+ // Only print this message if we're not looping something
+ if (printAns)
+ PrintAndLog("Auto-detected clock rate: %d, Best Starting Position: %d", clock, start);
+ return clock;
+}
+
+uint8_t GetPskCarrier(const char str[], bool printAns, bool verbose)
+{
+ uint8_t carrier = 0;
+ uint8_t grph[MAX_GRAPH_TRACE_LEN] = {0};
+ size_t size = getFromGraphBuf(grph);
+ if ( size == 0 ) {
+ if (verbose)
+ PrintAndLog("Failed to copy from graphbuffer");
+ return 0;
+ }
+ carrier = countFC(grph, size, 0);
+ // Only print this message if we're not looping something
+ if (printAns)
+ PrintAndLog("Auto-detected PSK carrier rate: %d", carrier);
+
+ return carrier;
+}
+
+int GetPskClock(const char str[], bool printAns, bool verbose)
+{
+ int clock;
+ sscanf(str, "%i", &clock);
+ if (!strcmp(str, ""))
+ clock = 0;
+
+ if (clock != 0) return clock;
+ // Auto-detect clock
+ uint8_t grph[MAX_GRAPH_TRACE_LEN] = {0};
+ size_t size = getFromGraphBuf(grph);
+ if ( size == 0 ) {
+ if (verbose) PrintAndLog("Failed to copy from graphbuffer");
+ return -1;
+ }
+ clock = DetectPSKClock(grph, size, 0);
+ // Only print this message if we're not looping something
+ if (printAns) PrintAndLog("Auto-detected clock rate: %d", clock);
+ return clock;