From 2248eadc7f1f883a7c6cdb055a257f5a76d1288f Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Mon, 27 Jun 2022 00:31:15 +0300 Subject: [PATCH] locate start of the sequence and level --- client/src/cmdhftexkom.c | 71 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/client/src/cmdhftexkom.c b/client/src/cmdhftexkom.c index e03dfb910..a2d8e39a8 100644 --- a/client/src/cmdhftexkom.c +++ b/client/src/cmdhftexkom.c @@ -27,6 +27,48 @@ #include "ui.h" #include "cmdhf14a.h" #include "cmddata.h" +#include "graph.h" + +#define TEXKOM_NOISE_THRESHOLD (10) + +inline uint32_t GetGraphBuffer(uint32_t indx) { + if (g_GraphBuffer[indx] < -128) + return 0; + else + return g_GraphBuffer[indx] + 128; +} + +static uint32_t TexkomSearchStart(uint32_t indx, uint8_t threshold) { + // one bit length = 27, minimal noise = 60 + uint32_t lownoisectr = 0; + for (uint32_t i = indx; i < g_GraphTraceLen; i++) { + if (lownoisectr > 60) { + if (GetGraphBuffer(i) > threshold) + return i; + } else { + if (GetGraphBuffer(i) > threshold) + lownoisectr = 0; + else + lownoisectr++; + } + } + + return 0; +} + +static uint32_t TexkomSearchMax(uint32_t indx, uint32_t len) { + uint32_t res = 0; + + for (uint32_t i = 0; i < len; i++) { + if (i + indx > g_GraphTraceLen) + break; + + if (GetGraphBuffer(indx + i) > res) + res = GetGraphBuffer(indx + i); + } + + return res; +} static int CmdHFTexkomReader(const char *Cmd) { CLIParserContext *ctx; @@ -41,7 +83,7 @@ static int CmdHFTexkomReader(const char *Cmd) { CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); - uint32_t samplesCount = 40000; + uint32_t samplesCount = 12000; clearCommandBuffer(); SendCommandNG(CMD_HF_ACQ_RAW_ADC, (uint8_t *)&samplesCount, sizeof(uint32_t)); @@ -52,8 +94,31 @@ static int CmdHFTexkomReader(const char *Cmd) { } uint32_t size = (resp.data.asDwords[0]); - if (size > 0) - getSamples(samplesCount, true); + if (size > 0) { + if (getSamples(samplesCount, true) != PM3_SUCCESS) { + PrintAndLogEx(ERR, "Get samples error"); + return PM3_EFAILED; + }; + } + + uint32_t sindx = 0; + while (sindx < samplesCount - 5) { + sindx = TexkomSearchStart(sindx, TEXKOM_NOISE_THRESHOLD); + if (sindx == 0 || sindx > samplesCount - 5) + break; + + uint32_t maxlvl = TexkomSearchMax(sindx, 1760); + if (maxlvl < TEXKOM_NOISE_THRESHOLD) { + sindx += 1700; + continue; + } + PrintAndLogEx(WARNING, "--- indx: %d, max: %d", sindx, maxlvl); + + + + } + + PrintAndLogEx(WARNING, "Texkom card is not found"); return PM3_SUCCESS; }