Merge pull request #2258 from wh201906/tune

Show statistical data after tuning
This commit is contained in:
Iceman 2024-01-18 19:21:03 +01:00 committed by GitHub
commit 5b090701f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 54 additions and 22 deletions

View file

@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
## [unreleased][unreleased] ## [unreleased][unreleased]
- Changed `hf tune` and `lf tune` - Added an option to show statistical data after tuning (@wh201906)
- Changed `lf idteck demod --raw` - now supports raw hex string to decode (@iceman1001) - Changed `lf idteck demod --raw` - now supports raw hex string to decode (@iceman1001)
- Changed `lf em 410x demod --bin` - now supports a raw binary string to demodulate. (@iceman1001) - Changed `lf em 410x demod --bin` - now supports a raw binary string to demodulate. (@iceman1001)
- Changed `lf em 4x05 info` - use `-v` verbose flag to see protection bits (@iceman1001) - Changed `lf em 4x05 info` - use `-v` verbose flag to see protection bits (@iceman1001)

View file

@ -288,6 +288,7 @@ int CmdHFTune(const char *Cmd) {
arg_lit0(NULL, "bar", "bar style"), arg_lit0(NULL, "bar", "bar style"),
arg_lit0(NULL, "mix", "mixed style"), arg_lit0(NULL, "mix", "mixed style"),
arg_lit0(NULL, "value", "values style"), arg_lit0(NULL, "value", "values style"),
arg_lit0(NULL, "stat", "show statistical data after tuning"),
arg_param_end arg_param_end
}; };
CLIExecWithReturn(ctx, Cmd, argtable, true); CLIExecWithReturn(ctx, Cmd, argtable, true);
@ -295,6 +296,7 @@ int CmdHFTune(const char *Cmd) {
bool is_bar = arg_get_lit(ctx, 2); bool is_bar = arg_get_lit(ctx, 2);
bool is_mix = arg_get_lit(ctx, 3); bool is_mix = arg_get_lit(ctx, 3);
bool is_value = arg_get_lit(ctx, 4); bool is_value = arg_get_lit(ctx, 4);
bool stat_on = arg_get_lit(ctx, 5);
CLIParserFree(ctx); CLIParserFree(ctx);
if ((is_bar + is_mix + is_value) > 1) { if ((is_bar + is_mix + is_value) > 1) {
@ -324,10 +326,13 @@ int CmdHFTune(const char *Cmd) {
mode[0] = 2; mode[0] = 2;
uint32_t max = 0xFFFF; uint32_t v_max = 0xFFFF;
uint32_t v_min = 0xFFFF;
uint64_t v_sum = 0;
uint64_t v_count = 0;
bool first = true; bool first = true;
print_progress(0, max, style); print_progress(0, v_max, style);
// loop forever (till button pressed) if iter = 0 (default) // loop forever (till button pressed) if iter = 0 (default)
for (uint32_t i = 0; iter == 0 || i < iter; i++) { for (uint32_t i = 0; iter == 0 || i < iter; i++) {
@ -349,13 +354,17 @@ int CmdHFTune(const char *Cmd) {
uint16_t volt = resp.data.asDwords[0] & 0xFFFF; uint16_t volt = resp.data.asDwords[0] & 0xFFFF;
if (first) { if (first) {
max = (volt * 1.03); v_max = volt;
v_min = volt;
first = false; first = false;
} }
if (volt > max) { v_max = (volt > v_max) ? volt : v_max;
max = (volt * 1.03); if (stat_on) {
v_min = (volt < v_min) ? volt : v_min;
v_sum += volt;
v_count++;
} }
print_progress(volt, max, style); print_progress(volt, v_max, style);
} }
mode[0] = 3; mode[0] = 3;
@ -366,6 +375,11 @@ int CmdHFTune(const char *Cmd) {
} }
PrintAndLogEx(NORMAL, "\x1b%c[2K\r", 30); PrintAndLogEx(NORMAL, "\x1b%c[2K\r", 30);
PrintAndLogEx(INFO, "Done."); PrintAndLogEx(INFO, "Done.");
if (stat_on) {
PrintAndLogEx(INFO, "Min:%u mV", v_min);
PrintAndLogEx(INFO, "Max:%u mV", v_max);
PrintAndLogEx(INFO, "Average:%.3lf mV", v_sum / (double)v_count);
}
return PM3_SUCCESS; return PM3_SUCCESS;
} }

View file

@ -116,6 +116,7 @@ static int CmdLFTune(const char *Cmd) {
arg_lit0(NULL, "bar", "bar style"), arg_lit0(NULL, "bar", "bar style"),
arg_lit0(NULL, "mix", "mixed style"), arg_lit0(NULL, "mix", "mixed style"),
arg_lit0(NULL, "value", "values style"), arg_lit0(NULL, "value", "values style"),
arg_lit0(NULL, "stat", "show statistical data after tuning"),
arg_param_end arg_param_end
}; };
CLIExecWithReturn(ctx, Cmd, argtable, true); CLIExecWithReturn(ctx, Cmd, argtable, true);
@ -126,6 +127,7 @@ static int CmdLFTune(const char *Cmd) {
bool is_bar = arg_get_lit(ctx, 4); bool is_bar = arg_get_lit(ctx, 4);
bool is_mix = arg_get_lit(ctx, 5); bool is_mix = arg_get_lit(ctx, 5);
bool is_value = arg_get_lit(ctx, 6); bool is_value = arg_get_lit(ctx, 6);
bool stat_on = arg_get_lit(ctx, 7);
CLIParserFree(ctx); CLIParserFree(ctx);
if (divisor < 19) { if (divisor < 19) {
@ -177,10 +179,13 @@ static int CmdLFTune(const char *Cmd) {
params[0] = 2; params[0] = 2;
// #define MAX_ADC_LF_VOLTAGE 140800 // #define MAX_ADC_LF_VOLTAGE 140800
uint32_t max = 71000; uint32_t v_max = 71000;
uint32_t v_min = 71000;
uint64_t v_sum = 0;
uint64_t v_count = 0;
bool first = true; bool first = true;
print_progress(0, max, style); print_progress(0, v_max, style);
// loop forever (till button pressed) if iter = 0 (default) // loop forever (till button pressed) if iter = 0 (default)
for (uint32_t i = 0; iter == 0 || i < iter; i++) { for (uint32_t i = 0; iter == 0 || i < iter; i++) {
@ -202,13 +207,17 @@ static int CmdLFTune(const char *Cmd) {
uint32_t volt = resp.data.asDwords[0]; uint32_t volt = resp.data.asDwords[0];
if (first) { if (first) {
max = (volt * 1.03); v_max = volt;
v_min = volt;
first = false; first = false;
} }
if (volt > max) { v_max = (volt > v_max) ? volt : v_max;
max = (volt * 1.03); if (stat_on) {
v_min = (volt < v_min) ? volt : v_min;
v_sum += volt;
v_count++;
} }
print_progress(volt, max, style); print_progress(volt, v_max, style);
} }
params[0] = 3; params[0] = 3;
@ -219,6 +228,11 @@ static int CmdLFTune(const char *Cmd) {
} }
PrintAndLogEx(NORMAL, "\x1b%c[2K\r", 30); PrintAndLogEx(NORMAL, "\x1b%c[2K\r", 30);
PrintAndLogEx(INFO, "Done."); PrintAndLogEx(INFO, "Done.");
if (stat_on) {
PrintAndLogEx(INFO, "Min:%u mV", v_min);
PrintAndLogEx(INFO, "Max:%u mV", v_max);
PrintAndLogEx(INFO, "Average:%.3lf mV", v_sum / (double)v_count);
}
return PM3_SUCCESS; return PM3_SUCCESS;
} }

View file

@ -646,8 +646,9 @@ void iceSimple_Filter(int *data, const size_t len, uint8_t k) {
} }
} }
void print_progress(size_t count, uint64_t max, barMode_t style) { void print_progress(uint64_t count, uint64_t max, barMode_t style) {
int cols = 100 + 35; int cols = 100 + 35;
max = (count > max) ? count : max;
#if defined(HAVE_READLINE) #if defined(HAVE_READLINE)
static int prev_cols = 0; static int prev_cols = 0;
int rows; int rows;
@ -698,13 +699,15 @@ void print_progress(size_t count, uint64_t max, barMode_t style) {
for (; i < unit * value; i += unit) { for (; i < unit * value; i += unit) {
memcpy(bar + i, block[mode], unit); memcpy(bar + i, block[mode], unit);
} }
// add last block if (i < unit * width) {
if (mode == 1) { // add last block
memcpy(bar + i, smoothtable[PERCENTAGEFRAC(count, max)], unit); if (mode == 1) {
} else { memcpy(bar + i, smoothtable[PERCENTAGEFRAC(count, max)], unit);
memcpy(bar + i, space[mode], unit); } else {
memcpy(bar + i, space[mode], unit);
}
i += unit;
} }
i += unit;
// add spaces // add spaces
for (; i < unit * width; i += unit) { for (; i < unit * width; i += unit) {
memcpy(bar + i, space[mode], unit); memcpy(bar + i, space[mode], unit);
@ -730,11 +733,11 @@ void print_progress(size_t count, uint64_t max, barMode_t style) {
break; break;
} }
case STYLE_MIXED: { case STYLE_MIXED: {
printf("\b%c[2K\r[" _YELLOW_("=")"] %s [ %zu mV / %2u V / %2u Vmax ]", 27, cbar, count, (uint32_t)(count / 1000), (uint32_t)(max / 1000)); printf("\b%c[2K\r[" _YELLOW_("=")"] %s [ %"PRIu64" mV / %2u V / %2u Vmax ]", 27, cbar, count, (uint32_t)(count / 1000), (uint32_t)(max / 1000));
break; break;
} }
case STYLE_VALUE: { case STYLE_VALUE: {
printf("[" _YELLOW_("=")"] %zu mV / %2u V / %2u Vmax \r", count, (uint32_t)(count / 1000), (uint32_t)(max / 1000)); printf("[" _YELLOW_("=")"] %"PRIu64" mV / %2u V / %2u Vmax \r", count, (uint32_t)(count / 1000), (uint32_t)(max / 1000));
break; break;
} }
} }

View file

@ -84,7 +84,7 @@ int searchHomeFilePath(char **foundpath, const char *subdir, const char *filenam
extern pthread_mutex_t g_print_lock; extern pthread_mutex_t g_print_lock;
void print_progress(size_t count, uint64_t max, barMode_t style); void print_progress(uint64_t count, uint64_t max, barMode_t style);
void iceIIR_Butterworth(int *data, const size_t len); void iceIIR_Butterworth(int *data, const size_t len);
void iceSimple_Filter(int *data, const size_t len, uint8_t k); void iceSimple_Filter(int *data, const size_t len, uint8_t k);