CHG: centralized the LF signal properties LOW/HIGH/MEAN/AMPLITUDE/ISNOISE into one struct.
CHG: 'data raw ar' - didn't take in consideration the command line parameter CLOCK.
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "cmddata.h"
|
||||
|
||||
|
||||
uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN];
|
||||
uint8_t g_debugMode = 0;
|
||||
size_t DemodBufferLen = 0;
|
||||
@@ -252,21 +251,19 @@ void setDemodBuf(uint8_t *buf, size_t size, size_t startIdx) {
|
||||
DemodBufferLen = size;
|
||||
}
|
||||
|
||||
|
||||
bool getDemodBuf(uint8_t *buff, size_t *size) {
|
||||
if (buff == NULL) return false;
|
||||
bool getDemodBuf(uint8_t *buf, size_t *size) {
|
||||
if (buf == NULL) return false;
|
||||
if (size == NULL) return false;
|
||||
if (*size == 0) return false;
|
||||
|
||||
*size = (*size > DemodBufferLen) ? DemodBufferLen : *size;
|
||||
|
||||
memcpy(buff, DemodBuffer, *size);
|
||||
memcpy(buf, DemodBuffer, *size);
|
||||
return true;
|
||||
}
|
||||
|
||||
// option '1' to save DemodBuffer any other to restore
|
||||
void save_restoreDB(uint8_t saveOpt)
|
||||
{
|
||||
void save_restoreDB(uint8_t saveOpt) {
|
||||
static uint8_t SavedDB[MAX_DEMOD_BUF_LEN];
|
||||
static size_t SavedDBlen;
|
||||
static bool DB_Saved = false;
|
||||
@@ -286,7 +283,6 @@ void save_restoreDB(uint8_t saveOpt)
|
||||
g_DemodClock = savedDemodClock;
|
||||
g_DemodStartIdx = savedDemodStartIdx;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int CmdSetDebugMode(const char *Cmd) {
|
||||
@@ -1001,7 +997,6 @@ int PSKDemod(const char *Cmd, bool verbose)
|
||||
//prime demod buffer for output
|
||||
setDemodBuf(BitStream, BitLen, 0);
|
||||
setClockGrid(clk, startIdx);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1312,8 +1307,7 @@ uint8_t getByte(uint8_t bits_per_sample, BitstreamOut* b)
|
||||
return val;
|
||||
}
|
||||
|
||||
int getSamples(int n, bool silent)
|
||||
{
|
||||
int getSamples(int n, bool silent) {
|
||||
//If we get all but the last byte in bigbuf,
|
||||
// we don't have to worry about remaining trash
|
||||
// in the last byte in case the bits-per-sample
|
||||
@@ -1334,6 +1328,9 @@ int getSamples(int n, bool silent)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// set signal properties low/high/mean/amplitude and isnoice detection
|
||||
justNoise(got, n);
|
||||
|
||||
uint8_t bits_per_sample = 8;
|
||||
|
||||
//Old devices without this feature would send 0 at arg[0]
|
||||
@@ -1466,6 +1463,9 @@ int CmdLoad(const char *Cmd)
|
||||
setClockGrid(0,0);
|
||||
DemodBufferLen = 0;
|
||||
RepaintGraphWindow();
|
||||
|
||||
// set signal properties low/high/mean/amplitude and isnoice detection
|
||||
justNoise_int(GraphBuffer, GraphTraceLen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1913,7 +1913,7 @@ static command_t CommandTable[] =
|
||||
{"biphaserawdecode",CmdBiphaseDecodeRaw,1, "[offset] [invert<0|1>] [maxErr] -- Biphase decode bin stream in DemodBuffer (offset = 0|1 bits to shift the decode start)"},
|
||||
{"bin2hex", Cmdbin2hex, 1, "<digits> -- Converts binary to hexadecimal"},
|
||||
{"bitsamples", CmdBitsamples, 0, "Get raw samples as bitstring"},
|
||||
{"buffclear", CmdBuffClear, 1, "Clears bigbuff on deviceside. d graph window"},
|
||||
{"buffclear", CmdBuffClear, 1, "Clears bigbuff on deviceside and graph window"},
|
||||
{"dec", CmdDec, 1, "Decimate samples"},
|
||||
{"detectclock", CmdDetectClockRate, 1, "[<a|f|n|p>] Detect ASK, FSK, NRZ, PSK clock rate of wave in GraphBuffer"},
|
||||
{"fsktonrz", CmdFSKToNRZ, 1, "Convert fsk2 to nrz wave for alternate fsk demodulating (for weak fsk)"},
|
||||
|
||||
@@ -875,7 +875,8 @@ int CmdLFfind(const char *Cmd) {
|
||||
if (isOnline) {
|
||||
// only run if graphbuffer is just noise as it should be for hitag
|
||||
// The improved noise detection will find Cotag.
|
||||
if (is_justnoise(GraphBuffer, minLength)) {
|
||||
signal_t *sp = getSignalProperties();
|
||||
if (sp->isnoise) {
|
||||
|
||||
PrintAndLog("Signal looks just like noise. Looking for Hitag signal now.");
|
||||
if (CmdLFHitagReader("26") == 0) { PrintAndLog("\nValid Hitag Found!"); return 1;}
|
||||
|
||||
@@ -41,7 +41,8 @@ int detectParadox(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint
|
||||
//make sure buffer has data
|
||||
if (*size < 96*50) return -1;
|
||||
|
||||
if (justNoise(dest, *size)) return -2;
|
||||
signal_t *sp = getSignalProperties();
|
||||
if (sp->isnoise) return -2;
|
||||
|
||||
// FSK demodulator
|
||||
*size = fskdemod(dest, *size, 50, 1, 10, 8, waveStartIdx); // paradox fsk2a
|
||||
|
||||
@@ -50,7 +50,8 @@ int detectPyramid(uint8_t *dest, size_t *size, int *waveStartIdx) {
|
||||
if (*size < 128*50) return -1;
|
||||
|
||||
//test samples are not just noise
|
||||
if (justNoise(dest, *size)) return -2;
|
||||
signal_t *sp = getSignalProperties();
|
||||
if (sp->isnoise) return -2;
|
||||
|
||||
// FSK demodulator RF/50 FSK 10,8
|
||||
*size = fskdemod(dest, *size, 50, 0, 10, 8, waveStartIdx); // pyramid fsk2
|
||||
|
||||
@@ -1316,10 +1316,7 @@ bool AquireData( uint8_t page, uint8_t block, bool pwdmode, uint32_t password ){
|
||||
}
|
||||
setGraphBuf(got, sizeof(got));
|
||||
|
||||
if (is_justnoise(GraphBuffer, sizeof(got)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return justNoise(got, sizeof(got));
|
||||
}
|
||||
|
||||
char * GetBitRateStr(uint32_t id, bool xmode) {
|
||||
|
||||
@@ -265,37 +265,3 @@ uint8_t fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, bool verbose, int *f
|
||||
return 1;
|
||||
}
|
||||
|
||||
//test samples are not just noise
|
||||
// By measuring mean and look at amplitude of signal from HIGH / LOW,
|
||||
// we can detect noise
|
||||
bool is_justnoise(int *bits, uint32_t size) {
|
||||
|
||||
if ( bits == NULL ) return true;
|
||||
if ( size < 100 ) return true;
|
||||
|
||||
//might not be high enough for noisy environments
|
||||
#define NOICE_AMPLITUDE_THRESHOLD 10;
|
||||
|
||||
int32_t sum = 0, mean = 0, high = -127, low = 127;
|
||||
for ( size_t i = 0; i < size; i++) {
|
||||
if ( bits[i] < low ) low = bits[i];
|
||||
if ( bits[i] > high ) high = bits[i];
|
||||
sum += bits[i];
|
||||
}
|
||||
|
||||
mean = sum / (int)size;
|
||||
// measure amplitude of signal
|
||||
bool isnoise = ABS(high - mean) < NOICE_AMPLITUDE_THRESHOLD;
|
||||
|
||||
if (g_debugMode == 1)
|
||||
PrintAndLog("DEBUG: (is_justnoise) mean %i | hi %i | low %i | IS NOISE %c", mean, high, low, isnoise?'Y':'N');
|
||||
|
||||
return isnoise;
|
||||
|
||||
/*
|
||||
bool isNoise = true;
|
||||
for(int i=0; i < size && isNoise; i++)
|
||||
isNoise = bits[i] < THRESHOLD;
|
||||
return isNoise;
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ uint8_t GetPskCarrier(const char str[], bool printAns, bool verbose);
|
||||
uint8_t GetNrzClock(const char str[], bool printAns, bool verbose);
|
||||
uint8_t GetFskClock(const char str[], bool printAns, bool verbose);
|
||||
uint8_t fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, bool verbose, int *firstClockEdge);
|
||||
bool is_justnoise(int *bits, uint32_t size);
|
||||
void setGraphBuf(uint8_t *buff, size_t size);
|
||||
void save_restoreGB(uint8_t saveOpt);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user