From 615f21dde29ed68c6b9dbb6c79c2a293751d777a Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 3 Jun 2015 21:12:24 +0200 Subject: [PATCH] FIX: a minor bug fix from @marshmellow42 in "data raw" and ask/biphase. ADD: started witha ISO11784/85 demod function. --- client/cmddata.c | 24 ++++++++++++++++++++++-- client/cmddata.h | 1 + common/lfdemod.c | 19 +++++++++++++++++++ common/lfdemod.h | 2 +- 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/client/cmddata.c b/client/cmddata.c index 76552351..90a0921c 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -500,7 +500,7 @@ int ASKbiphaseDemod(const char *Cmd, bool verbose) int offset=0, clk=0, invert=0, maxErr=0, ans=0; ans = sscanf(Cmd, "%i %i %i %i", &offset, &clk, &invert, &maxErr); if (ans>0) - ans = ASKDemod(Cmd+1, FALSE, FALSE, 0); + ans = ASKDemod(Cmd+2, FALSE, FALSE, 0); else ans = ASKDemod(Cmd, FALSE, FALSE, 0); if (!ans) { @@ -512,7 +512,7 @@ int ASKbiphaseDemod(const char *Cmd, bool verbose) size_t size = DemodBufferLen; uint8_t BitStream[MAX_DEMOD_BUF_LEN]; memcpy(BitStream, DemodBuffer, DemodBufferLen); - int errCnt = BiphaseRawDecode(BitStream, &size, offset, 0); + int errCnt = BiphaseRawDecode(BitStream, &size, offset, invert); if (errCnt < 0){ if (g_debugMode || verbose) PrintAndLog("Error BiphaseRawDecode: %d", errCnt); return 0; @@ -1457,6 +1457,25 @@ int CmdFSKdemodPyramid(const char *Cmd) return 1; } +int CmdIso11784demodBI(const char *Cmd){ + //ASK/Biphase demod, + uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0}; + size_t size = getFromGraphBuf(BitStream); + if (size==0) return 0; + + //get binary from Biphase wave + int idx = ISO11784demodBI(BitStream, &size); + setDemodBuf(BitStream,128,idx); + + size = removeParity(BitStream, idx+8, 4, 1, 88); + // if (size != 66){ + // if (g_debugMode==1) PrintAndLog("DEBUG: Error - at parity check-tag size does not match AWID format"); + // return 0; + // } + return 1; +} + + //by marshmellow //attempt to psk1 demod graph buffer int PSKDemod(const char *Cmd, bool verbose) @@ -2212,6 +2231,7 @@ static command_t CommandTable[] = {"hexsamples", CmdHexsamples, 0, " [] -- Dump big buffer as hex bytes"}, {"hide", CmdHide, 1, "Hide graph window"}, {"hpf", CmdHpf, 1, "Remove DC offset from trace"}, + {"iso11784demod", CmdIso11784demodBI, 1, "Demodulate a ISO11784/85 Biphase tag from GraphBuffer"}, {"load", CmdLoad, 1, " -- Load trace (to graph window"}, {"ltrim", CmdLtrim, 1, " -- Trim samples from left of trace"}, {"rtrim", CmdRtrim, 1, " -- Trim samples from right of trace"}, diff --git a/client/cmddata.h b/client/cmddata.h index c6230736..4ad5fbd0 100644 --- a/client/cmddata.h +++ b/client/cmddata.h @@ -33,6 +33,7 @@ int CmdFSKdemodIO(const char *Cmd); int CmdFSKdemodParadox(const char *Cmd); int CmdFSKdemodPyramid(const char *Cmd); int CmdFSKrawdemod(const char *Cmd); +int CmdIso11784demodBI(const char *Cmd); int CmdPSK1rawDemod(const char *Cmd); int CmdPSK2rawDemod(const char *Cmd); int CmdPSKNexWatch(const char *Cmd); diff --git a/common/lfdemod.c b/common/lfdemod.c index 7d40d22e..2c650144 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -589,6 +589,25 @@ size_t removeParity(uint8_t *BitStream, size_t startIdx, uint8_t pLen, uint8_t p //return ID start index and size return bitCnt; } +// Ask/Biphase Demod then try to locate an ISO 11784/85 ID +int ISO11784demodBI(uint8_t *dest, size_t *size) +{ + //make sure buffer has enough data + if (*size < 128*50) return -1; + + if (justNoise(dest, *size)) return -2; + + // FSK demodulator + *size = fskdemod(dest, *size, 50, 1, 10, 8); // fsk2a RF/50 + if (*size < 96) return -3; //did we get a good demod? + + uint8_t preamble[] = {0,0,0,0,0,0,0,0,0,0,1}; + size_t startIdx = 0; + uint8_t errChk = preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx); + if (errChk == 0) return -4; //preamble not found + if (*size != 128) return -5; + return (int)startIdx; +} // by marshmellow // FSK Demod then try to locate an AWID ID diff --git a/common/lfdemod.h b/common/lfdemod.h index ab81c34c..f2cee27f 100644 --- a/common/lfdemod.h +++ b/common/lfdemod.h @@ -47,5 +47,5 @@ int IOdemodFSK(uint8_t *dest, size_t size); int indala26decode(uint8_t *bitStream, size_t *size, uint8_t *invert); int PyramiddemodFSK(uint8_t *dest, size_t *size); int ParadoxdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo); - +int ISO11784demodBI(uint8_t *dest, size_t *size); #endif -- 2.39.2