From 04d2721b3c7c4113e627d3f953835bde932065db Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Mon, 26 Jan 2015 17:23:19 -0500 Subject: [PATCH] lf psk demods clarify existing as psk1 added psk2 demod --- client/cmddata.c | 53 ++++++++++++++++++++++++++++++++++++------------ common/lfdemod.c | 32 ++++++++++++++++++++--------- common/lfdemod.h | 1 + 3 files changed, 63 insertions(+), 23 deletions(-) diff --git a/client/cmddata.c b/client/cmddata.c index 0a1841bf..0c6cd72c 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -721,8 +721,8 @@ int CmdFSKdemodHID(const char *Cmd) return 1; } -//by marshmellow (based on existing demod + holiman's refactor) -//Paradox Prox demod - FSK RF/50 with preamble of 00011101 (then manchester encoded) +//by marshmellow +//Paradox Prox demod - FSK RF/50 with preamble of 00001111 (then manchester encoded) //print full Paradox Prox ID and some bit format details if found int CmdFSKdemodParadox(const char *Cmd) { @@ -1196,7 +1196,7 @@ int CmdDetectNRZpskClockRate(const char *Cmd) return 0; } -int PSKnrzDemod(const char *Cmd) +int PSKnrzDemod(const char *Cmd, uint8_t verbose) { int invert=0; int clk=0; @@ -1213,7 +1213,7 @@ int PSKnrzDemod(const char *Cmd) if (g_debugMode==1) PrintAndLog("no data found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt); return -1; } - PrintAndLog("Tried PSK/NRZ Demod using Clock: %d - invert: %d - Bits Found: %d",clk,invert,BitLen); + if (verbose) PrintAndLog("Tried PSK/NRZ Demod using Clock: %d - invert: %d - Bits Found: %d",clk,invert,BitLen); //prime demod buffer for output setDemodBuf(BitStream,BitLen,0); @@ -1226,9 +1226,9 @@ int CmdIndalaDecode(const char *Cmd) { int ans; if (strlen(Cmd)>0){ - ans = PSKnrzDemod(Cmd); + ans = PSKnrzDemod(Cmd, 0); } else{ //default to RF/32 - ans = PSKnrzDemod("32"); + ans = PSKnrzDemod("32", 0); } if (ans < 0){ @@ -1305,15 +1305,15 @@ int CmdPskClean(const char *Cmd) return 0; } -//by marshmellow -//takes 2 arguments - clock and invert both as integers -//attempts to demodulate ask only -//prints binary found and saves in graphbuffer for further commands +// by marshmellow +// takes 2 arguments - clock and invert both as integers +// attempts to demodulate psk only +// prints binary found and saves in demodbuffer for further commands int CmdpskNRZrawDemod(const char *Cmd) { int errCnt; - errCnt = PSKnrzDemod(Cmd); + errCnt = PSKnrzDemod(Cmd, 1); //output if (errCnt<0){ if (g_debugMode) PrintAndLog("Error demoding: %d",errCnt); @@ -1335,6 +1335,32 @@ int CmdpskNRZrawDemod(const char *Cmd) return 0; } +// by marshmellow +// takes same args as cmdpsknrzrawdemod +int CmdPSK2rawDemod(const char *Cmd) +{ + int errCnt=0; + errCnt=PSKnrzDemod(Cmd, 1); + if (errCnt<0){ + if (g_debugMode) PrintAndLog("Error demoding: %d",errCnt); + return 0; + } + psk1TOpsk2(DemodBuffer, DemodBufferLen); + if (errCnt>0){ + if (g_debugMode){ + PrintAndLog("# Errors during Demoding (shown as 77 in bit stream): %d",errCnt); + PrintAndLog("PSK2 demoded bitstream:"); + // Now output the bitstream to the scrollback by line of 16 bits + printDemodBuff(); + } + }else{ + PrintAndLog("PSK2 demoded bitstream:"); + // Now output the bitstream to the scrollback by line of 16 bits + printDemodBuff(); + } + return 1; +} + int CmdGrid(const char *Cmd) { sscanf(Cmd, "%i %i", &PlotGridX, &PlotGridY); @@ -1949,8 +1975,9 @@ static command_t CommandTable[] = {"plot", CmdPlot, 1, "Show graph window (hit 'h' in window for keystroke help)"}, {"pskclean", CmdPskClean, 1, "Attempt to clean psk wave"}, {"pskdetectclock",CmdDetectNRZpskClockRate, 1, "Detect ASK, PSK, or NRZ clock rate"}, - {"pskindalademod",CmdIndalaDecode, 1, "[clock] [invert<0|1>] -- Attempt to demodulate psk indala tags and output ID binary & hex (args optional)"}, - {"psknrzrawdemod",CmdpskNRZrawDemod, 1, "[clock] [invert<0|1>] -- Attempt to demodulate psk or nrz tags and output binary (args optional)"}, + {"pskindalademod",CmdIndalaDecode, 1, "[clock] [invert<0|1>] -- Attempt to demodulate psk1 indala tags and output ID binary & hex (args optional)"}, + {"psk1nrzrawdemod",CmdpskNRZrawDemod, 1, "[clock] [invert<0|1>] -- Attempt to demodulate psk1 or nrz tags and output binary (args optional)"}, + {"psk2rawdemod", CmdPSK2rawDemod, 1, "[clock] [invert<0|1>] -- Attempt to demodulate psk2 tags and output binary (args optional)"}, {"samples", CmdSamples, 0, "[512 - 40000] -- Get raw samples for graph window"}, {"save", CmdSave, 1, " -- Save trace (from graph window)"}, {"scale", CmdScale, 1, " -- Set cursor display scale"}, diff --git a/common/lfdemod.c b/common/lfdemod.c index 34194394..810e0357 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -816,7 +816,6 @@ int PyramiddemodFSK(uint8_t *dest, size_t size) return -4; } - // by marshmellow // not perfect especially with lower clocks or VERY good antennas (heavy wave clipping) // maybe somehow adjust peak trimming value based on samples to fix? @@ -885,7 +884,6 @@ int DetectASKClock(uint8_t dest[], size_t size, int clock) return clk[best]; } - //by marshmellow //detect psk clock by reading #peaks vs no peaks(or errors) int DetectpskNRZClock(uint8_t dest[], size_t size, int clock) @@ -963,7 +961,7 @@ int DetectpskNRZClock(uint8_t dest[], size_t size, int clock) return clk[best]; } -//by marshmellow (attempt to get rid of high immediately after a low) +// by marshmellow (attempt to get rid of high immediately after a low) void pskCleanWave(uint8_t *BitStream, size_t size) { int i; @@ -999,9 +997,26 @@ void pskCleanWave(uint8_t *BitStream, size_t size) return; } +// by marshmellow +// convert psk1 demod to psk2 demod +// only transition waves are 1s +void psk1TOpsk2(uint8_t *BitStream, size_t size) +{ + size_t i=1; + uint8_t lastBit=BitStream[0]; + for (; i