+
+// A simple test to see if there is any data inside Graphbuffer.
+bool HasGraphData(){
+
+ if ( GraphTraceLen <= 0) {
+ PrintAndLog("No data available, try reading something first");
+ return false;
+ }
+ return true;
+}
+
+// Detect high and lows in Grapbuffer.
+// Only loops the first 256 values.
+void DetectHighLowInGraph(int *high, int *low, bool addFuzz) {
+
+ uint8_t loopMax = 255;
+ if ( loopMax > GraphTraceLen)
+ loopMax = GraphTraceLen;
+
+ for (uint8_t i = 0; i < loopMax; ++i) {
+ if (GraphBuffer[i] > *high)
+ *high = GraphBuffer[i];
+ else if (GraphBuffer[i] < *low)
+ *low = GraphBuffer[i];
+ }
+
+ //12% fuzz in case highs and lows aren't clipped
+ if (addFuzz) {
+ *high = (int)(*high * .88);
+ *low = (int)(*low * .88);
+ }
+}
+
+// Get or auto-detect ask clock rate
+int GetAskClock(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;
+ }
+ DetectASKClock(grph, size, &clock, 20);
+ // Only print this message if we're not looping something
+ if (printAns){
+ PrintAndLog("Auto-detected clock rate: %d", clock);
+ }
+ 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;
+ }
+ //uint8_t countPSK_FC(uint8_t *BitStream, size_t size)
+
+ carrier = countPSK_FC(grph,size);
+ // 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;
+}
+
+uint8_t GetNrzClock(const char str[], bool printAns, bool verbose)