From 8f954ebf9db810a7903990cad0e3caf700a16fea Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 24 Oct 2020 11:56:47 +0200 Subject: [PATCH] refactor continuous mode --- client/src/cmdhf.c | 33 +++++++++++++++++++-------------- client/src/cmdhf.h | 1 + client/src/cmdhf14a.c | 38 +++++++++++++------------------------- 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/client/src/cmdhf.c b/client/src/cmdhf.c index 7d462cb6b..8249c28af 100644 --- a/client/src/cmdhf.c +++ b/client/src/cmdhf.c @@ -311,19 +311,8 @@ int CmdHFSniff(const char *Cmd) { return PM3_SUCCESS; } -int CmdHFPlot(const char *Cmd) { - CLIParserContext *ctx; - CLIParserInit(&ctx, "hf plot", - "Plots HF signal after RF signal path and A/D conversion.", - "This can be used after any hf command and will show the last few milliseconds of the HF signal.\n" - "Note: If the last hf command terminated because of a timeout you will most probably see nothing.\n"); - void *argtable[] = { - arg_param_begin, - arg_param_end - }; - CLIExecWithReturn(ctx, Cmd, argtable, true); - CLIParserFree(ctx); - +int handle_hf_plot(void) { + uint8_t buf[FPGA_TRACE_SIZE]; PacketResponseNG response; @@ -333,7 +322,7 @@ int CmdHFPlot(const char *Cmd) { } for (size_t i = 0; i < FPGA_TRACE_SIZE; i++) { - GraphBuffer[i] = ((int)buf[i]) - 127; + GraphBuffer[i] = ((int)buf[i]) - 128; } GraphTraceLen = FPGA_TRACE_SIZE; @@ -349,6 +338,22 @@ int CmdHFPlot(const char *Cmd) { return PM3_SUCCESS; } +int CmdHFPlot(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf plot", + "Plots HF signal after RF signal path and A/D conversion.", + "This can be used after any hf command and will show the last few milliseconds of the HF signal.\n" + "Note: If the last hf command terminated because of a timeout you will most probably see nothing.\n"); + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); + + return handle_hf_plot(); +} + static command_t CommandTable[] = { {"--------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("High Frequency") " -----------------------"}, diff --git a/client/src/cmdhf.h b/client/src/cmdhf.h index 09af16d5e..c54fd076c 100644 --- a/client/src/cmdhf.h +++ b/client/src/cmdhf.h @@ -19,4 +19,5 @@ int CmdHFSearch(const char *Cmd); int CmdHFSniff(const char *Cmd); int CmdHFPlot(const char *Cmd); +int handle_hf_plot(void); #endif diff --git a/client/src/cmdhf14a.c b/client/src/cmdhf14a.c index 981b4417b..68a324952 100644 --- a/client/src/cmdhf14a.c +++ b/client/src/cmdhf14a.c @@ -27,10 +27,8 @@ #include "crc16.h" #include "util_posix.h" // msclock #include "aidsearch.h" -#include "proxgui.h" -#include "cmddata.h" -#include "graph.h" -#include "fpga.h" +#include "cmdhf.h" // handle HF plot + bool APDUInFramingEnable = true; @@ -568,35 +566,25 @@ static int CmdHF14AReader(const char *Cmd) { } } plot: - if (continuous) { - uint8_t buf[FPGA_TRACE_SIZE]; - - PacketResponseNG response; - if (!GetFromDevice(FPGA_MEM, buf, FPGA_TRACE_SIZE, 0, NULL, 0, &response, 4000, true)) { - PrintAndLogEx(WARNING, "timeout while waiting for reply."); - return PM3_ETIMEOUT; + if (continuous) { + res = handle_hf_plot(); + if (res != PM3_SUCCESS) { + break; } - - for (size_t i = 0; i < FPGA_TRACE_SIZE; i++) { - GraphBuffer[i] = ((int)buf[i]) - 127; - } - - GraphTraceLen = FPGA_TRACE_SIZE; - - // remove signal offset - CmdHpf(""); - - setClockGrid(0, 0); - DemodBufferLen = 0; - RepaintGraphWindow(); } + if (kbd_enter_pressed()) { break; } + } while (continuous); + if (disconnectAfter) { - if (!silent) PrintAndLogEx(INFO, "field dropped."); + if (silent == false) { + PrintAndLogEx(INFO, "field dropped."); + } } + if (continuous) return PM3_SUCCESS; else