From d51b2eda8f91b17dd02cdbd931b089fc8f8d61db Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Wed, 11 Jun 2014 08:42:37 +0200 Subject: [PATCH] Added enios dirthreshold command, patch from http://www.proxmark.org/forum/viewtopic.php?pid=11577#p11577 --- client/cmddata.c | 37 +++++++++++++++++++++++++++++++++++++ client/cmddata.h | 1 + 2 files changed, 38 insertions(+) diff --git a/client/cmddata.c b/client/cmddata.c index a7b80480..fa54d01a 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -17,6 +17,7 @@ #include "ui.h" #include "graph.h" #include "cmdparser.h" +#include "util.h" #include "cmdmain.h" #include "cmddata.h" @@ -818,6 +819,41 @@ int CmdThreshold(const char *Cmd) return 0; } +int CmdDirectionalThreshold(const char *Cmd) +{ + int8_t upThres = param_get8(Cmd, 0); + int8_t downThres = param_get8(Cmd, 1); + + printf("Applying Up Threshold: %d, Down Threshold: %d\n", upThres, downThres); + + int lastValue = GraphBuffer[0]; + GraphBuffer[0] = 0; // Will be changed at the end, but init 0 as we adjust to last samples value if no threshold kicks in. + + for (int i = 1; i < GraphTraceLen; ++i) { + // Apply first threshold to samples heading up + if (GraphBuffer[i] >= upThres && GraphBuffer[i] > lastValue) + { + lastValue = GraphBuffer[i]; // Buffer last value as we overwrite it. + GraphBuffer[i] = 1; + } + // Apply second threshold to samples heading down + else if (GraphBuffer[i] <= downThres && GraphBuffer[i] < lastValue) + { + lastValue = GraphBuffer[i]; // Buffer last value as we overwrite it. + GraphBuffer[i] = -1; + } + else + { + lastValue = GraphBuffer[i]; // Buffer last value as we overwrite it. + GraphBuffer[i] = GraphBuffer[i-1]; + + } + } + GraphBuffer[0] = GraphBuffer[1]; // Aline with first edited sample. + RepaintGraphWindow(); + return 0; +} + int CmdZerocrossings(const char *Cmd) { // Zero-crossings aren't meaningful unless the signal is zero-mean. @@ -874,6 +910,7 @@ static command_t CommandTable[] = {"scale", CmdScale, 1, " -- Set cursor display scale"}, {"threshold", CmdThreshold, 1, " -- Maximize/minimize every value in the graph window depending on threshold"}, {"zerocrossings", CmdZerocrossings, 1, "Count time between zero-crossings"}, + {"dirthreshold", CmdDirectionalThreshold, 1, " -- Max rising higher up-thres/ Min falling lower down-thres, keep rest as prev."}, {NULL, NULL, 0, NULL} }; diff --git a/client/cmddata.h b/client/cmddata.h index 2f86a941..716c9c39 100644 --- a/client/cmddata.h +++ b/client/cmddata.h @@ -38,6 +38,7 @@ int CmdSamples(const char *Cmd); int CmdSave(const char *Cmd); int CmdScale(const char *Cmd); int CmdThreshold(const char *Cmd); +int CmdDirectionalThreshold(const char *Cmd); int CmdZerocrossings(const char *Cmd); #endif -- 2.39.5