From eb7268cd98ecf991b3fe61242dea8ce6bbe3fb63 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 25 Oct 2019 00:42:47 +0200 Subject: [PATCH] lf: change macros to allow float freq, change 134 -> 134.2 --- armsrc/lfops.c | 4 ++-- client/cmddata.c | 10 +++++----- client/cmdlf.c | 6 +++--- client/cmdlfmotorola.c | 2 +- include/pm3_cmd.h | 7 ++++--- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/armsrc/lfops.c b/armsrc/lfops.c index a298af4a9..f4f3a9e7b 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -2418,7 +2418,7 @@ because of this, we can "sample" the data signal but we interpreate it to Manche This behavior looks very similar to old ancient Motorola Flexpass ----------------------------------------------------------------------- -According to patent: +According to patent EP0040544B1: Operating freq reader 132 kHz tag 66 kHz @@ -2453,7 +2453,7 @@ void Cotag(uint32_t arg0) { LED_A_ON(); - LFSetupFPGAForADC(LF_DIVISOR(132), true); + LFSetupFPGAForADC(LF_FREQ2DIV(132), true); //clear buffer now so it does not interfere with timing later BigBuf_Clear_ext(false); diff --git a/client/cmddata.c b/client/cmddata.c index 80c3bf076..5962d6ca6 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -1676,16 +1676,16 @@ int CmdTuneSamples(const char *Cmd) { struct p *package = (struct p *)resp.data.asBytes; if (package->v_lf125 > NON_VOLTAGE) - PrintAndLogEx(SUCCESS, "LF antenna: %5.2f V - %.2f kHz", (package->v_lf125 * ANTENNA_ERROR) / 1000.0, 12000.0 / (LF_DIVISOR_125 + 1)); + PrintAndLogEx(SUCCESS, "LF antenna: %5.2f V - %.2f kHz", (package->v_lf125 * ANTENNA_ERROR) / 1000.0, LF_DIV2FREQ(LF_DIVISOR_125)); if (package->v_lf134 > NON_VOLTAGE) - PrintAndLogEx(SUCCESS, "LF antenna: %5.2f V - %.2f kHz", (package->v_lf134 * ANTENNA_ERROR) / 1000.0, 12000.0 / (LF_DIVISOR_134 + 1)); + PrintAndLogEx(SUCCESS, "LF antenna: %5.2f V - %.2f kHz", (package->v_lf134 * ANTENNA_ERROR) / 1000.0, LF_DIV2FREQ(LF_DIVISOR_134)); if (package->v_lfconf > NON_VOLTAGE && package->divisor > 0 && package->divisor != LF_DIVISOR_125 && package->divisor != LF_DIVISOR_134) - PrintAndLogEx(SUCCESS, "LF antenna: %5.2f V - %.2f kHz", (package->v_lfconf * ANTENNA_ERROR) / 1000.0, 12000.0 / (package->divisor + 1)); + PrintAndLogEx(SUCCESS, "LF antenna: %5.2f V - %.2f kHz", (package->v_lfconf * ANTENNA_ERROR) / 1000.0, LF_DIV2FREQ(package->divisor)); if (package->peak_v > NON_VOLTAGE && package->peak_f > 0) - PrintAndLogEx(SUCCESS, "LF optimal: %5.2f V - %6.2f kHz", (package->peak_v * ANTENNA_ERROR) / 1000.0, 12000.0 / (package->peak_f + 1)); + PrintAndLogEx(SUCCESS, "LF optimal: %5.2f V - %6.2f kHz", (package->peak_v * ANTENNA_ERROR) / 1000.0, LF_DIV2FREQ(package->peak_f)); char judgement[20]; memset(judgement, 0, sizeof(judgement)); @@ -1730,7 +1730,7 @@ int CmdTuneSamples(const char *Cmd) { if (test1 > 0) { PrintAndLogEx(SUCCESS, "\nDisplaying LF tuning graph. Divisor %d is %.2f kHz, %d is %.2f kHz.\n\n", - LF_DIVISOR_134, 12000.0 / (LF_DIVISOR_134 + 1), LF_DIVISOR_125, 12000.0 / (LF_DIVISOR_125 + 1)); + LF_DIVISOR_134, LF_DIV2FREQ(LF_DIVISOR_134), LF_DIVISOR_125, LF_DIV2FREQ(LF_DIVISOR_125)); GraphTraceLen = 256; ShowGraphWindow(); RepaintGraphWindow(); diff --git a/client/cmdlf.c b/client/cmdlf.c index 4d7c72acc..8f5a88923 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -232,7 +232,7 @@ int CmdLFTune(const char *Cmd) { break; case 'f': { int freq = param_get32ex(Cmd, cmdp + 1, 125, 10); - divisor = LF_DIVISOR(freq); + divisor = LF_FREQ2DIV(freq); if (divisor < 19) { PrintAndLogEx(ERR, "freq must be between 47 and 600"); return PM3_EINVARG; @@ -254,7 +254,7 @@ int CmdLFTune(const char *Cmd) { //Validations if (errors) return usage_lf_tune(); - PrintAndLogEx(SUCCESS, "Measuring LF antenna at %.2f kHz, click button or press Enter to exit", 12000.0 / (divisor + 1)); + PrintAndLogEx(SUCCESS, "Measuring LF antenna at %.2f kHz, click button or press Enter to exit", LF_DIV2FREQ(divisor)); uint8_t params[] = {1, 0}; params[1] = divisor; @@ -498,7 +498,7 @@ int CmdLFConfig(const char *Cmd) { break; case 'f': { int freq = param_get32ex(Cmd, cmdp + 1, 125, 10); - divisor = LF_DIVISOR(freq); + divisor = LF_FREQ2DIV(freq); if (divisor < 19) { PrintAndLogEx(ERR, "freq must be between 47 and 600"); return PM3_EINVARG; diff --git a/client/cmdlfmotorola.c b/client/cmdlfmotorola.c index 87ea53a3b..dbcf28e40 100644 --- a/client/cmdlfmotorola.c +++ b/client/cmdlfmotorola.c @@ -127,7 +127,7 @@ static int CmdMotorolaRead(const char *Cmd) { .decimation = 0, .bits_per_sample = 0, .averaging = false, - .divisor = LF_DIVISOR(74), + .divisor = LF_FREQ2DIV(74), .trigger_threshold = -1, .samples_to_skip = 4500, .verbose = false diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index 19ef27afb..544d5e5c2 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -590,9 +590,10 @@ typedef struct { #define PM3_EFATAL -99 // LF -#define LF_DIVISOR(f) (((12000 + (f)/2)/(f))-1) -#define LF_DIVISOR_125 LF_DIVISOR(125) -#define LF_DIVISOR_134 LF_DIVISOR(134) +#define LF_FREQ2DIV(f) ((int)(((12000.0 + (f)/2.0)/(f))-1)) +#define LF_DIVISOR_125 LF_FREQ2DIV(125) +#define LF_DIVISOR_134 LF_FREQ2DIV(134.2) +#define LF_DIV2FREQ(d) (12000.0/((d)+1)) // Receiving from USART need more than 30ms as we used on USB // else we get errors about partial packet reception