oops! clobbered manchester code inversion with last update! :(

This commit is contained in:
adam@algroup.co.uk 2009-07-06 09:36:15 +00:00
parent 959baa89f7
commit 736aea6036

View file

@ -9,7 +9,6 @@
#include <stdio.h> #include <stdio.h>
#include <limits.h> #include <limits.h>
#include <math.h> #include <math.h>
#include <unistd.h>
#include "prox.h" #include "prox.h"
#include "../common/iso14443_crc.c" #include "../common/iso14443_crc.c"
@ -2081,7 +2080,7 @@ static void Cmdmanchestermod(char *str)
* Typical values can be 64, 32, 128... * Typical values can be 64, 32, 128...
*/ */
static void Cmdmanchesterdemod(char *str) { static void Cmdmanchesterdemod(char *str) {
int i, j; int i, j, invert= 0;
int bit; int bit;
int clock; int clock;
int lastval; int lastval;
@ -2093,6 +2092,16 @@ static void Cmdmanchesterdemod(char *str) {
int bit2idx = 0; int bit2idx = 0;
int warnings = 0; int warnings = 0;
/* check if we're inverting output */
if(*str == 'i')
{
PrintToScrollback("Inverting output");
invert= 1;
do
++str;
while(*str == ' '); // in case a 2nd argument was given
}
/* Holds the decoded bitstream: each clock period contains 2 bits */ /* Holds the decoded bitstream: each clock period contains 2 bits */
/* later simplified to 1 bit after manchester decoding. */ /* later simplified to 1 bit after manchester decoding. */
/* Add 10 bits to allow for noisy / uncertain traces without aborting */ /* Add 10 bits to allow for noisy / uncertain traces without aborting */
@ -2163,7 +2172,7 @@ static void Cmdmanchesterdemod(char *str) {
if (!hithigh || !hitlow) if (!hithigh || !hitlow)
bit ^= 1; bit ^= 1;
BitStream[bit2idx++] = bit; BitStream[bit2idx++] = bit ^ invert;
} }
} }
@ -2171,7 +2180,7 @@ static void Cmdmanchesterdemod(char *str) {
else else
{ {
/* Then detect duration between 2 successive transitions */ /* Then detect duration between 2 successive transitions */
for (bitidx = 1; i < GraphTraceLen; i++) for (bitidx = 1; i < GraphTraceLen; i++)
{ {
if (GraphBuffer[i-1] != GraphBuffer[i]) if (GraphBuffer[i-1] != GraphBuffer[i])
@ -2206,18 +2215,18 @@ static void Cmdmanchesterdemod(char *str) {
PrintToScrollback("Error: too many detection errors, aborting."); PrintToScrollback("Error: too many detection errors, aborting.");
return; return;
} }
}
} }
} }
}
// At this stage, we now have a bitstream of "01" ("1") or "10" ("0"), parse it into final decoded bitstream // At this stage, we now have a bitstream of "01" ("1") or "10" ("0"), parse it into final decoded bitstream
// Actually, we overwrite BitStream with the new decoded bitstream, we just need to be careful // Actually, we overwrite BitStream with the new decoded bitstream, we just need to be careful
// to stop output at the final bitidx2 value, not bitidx // to stop output at the final bitidx2 value, not bitidx
for (i = 0; i < bitidx; i += 2) { for (i = 0; i < bitidx; i += 2) {
if ((BitStream[i] == 0) && (BitStream[i+1] == 1)) { if ((BitStream[i] == 0) && (BitStream[i+1] == 1)) {
BitStream[bit2idx++] = 1; BitStream[bit2idx++] = 1 ^ invert;
} else if ((BitStream[i] == 1) && (BitStream[i+1] == 0)) { } else if ((BitStream[i] == 1) && (BitStream[i+1] == 0)) {
BitStream[bit2idx++] = 0; BitStream[bit2idx++] = 0 ^ invert;
} else { } else {
// We cannot end up in this state, this means we are unsynchronized, // We cannot end up in this state, this means we are unsynchronized,
// move up 1 bit: // move up 1 bit:
@ -2231,8 +2240,8 @@ static void Cmdmanchesterdemod(char *str) {
PrintToScrollback("Error: too many decode errors, aborting."); PrintToScrollback("Error: too many decode errors, aborting.");
return; return;
} }
} }
} }
} }
PrintToScrollback("Manchester decoded bitstream"); PrintToScrollback("Manchester decoded bitstream");
@ -2452,16 +2461,15 @@ static struct {
"hisamplest", CmdHi14readt,0, " Get samples HF, for testing", "hisamplest", CmdHi14readt,0, " Get samples HF, for testing",
"hisimlisten", CmdHisimlisten,0, " Get HF samples as fake tag", "hisimlisten", CmdHisimlisten,0, " Get HF samples as fake tag",
"hpf", CmdHpf,1, " Remove DC offset from trace", "hpf", CmdHpf,1, " Remove DC offset from trace",
"indalademod", CmdIndalademod,0, "['224'] -- Demodulate samples for Indala", "indalademod", CmdIndalademod,0, "['224'] -- Demodulate samples for Indala 64 bit UID (option '224' for 224 bit)",
"lcd", CmdLcd,0, "<HEX command> <count> -- Send command/data to LCD", "lcd", CmdLcd,0, "<HEX command> <count> -- Send command/data to LCD",
"lcdreset", CmdLcdReset,0, " Hardware reset LCD", "lcdreset", CmdLcdReset,0, " Hardware reset LCD",
"load", CmdLoad,1, "<filename> -- Load trace (to graph window", "load", CmdLoad,1, "<filename> -- Load trace (to graph window",
"locomread", CmdLoCommandRead,0, "<off period> <'0' period> <'1' period> <command> ['h'] -- Modulate LF reader field to send command before read (all periods in microseconds) (option 'h' for 134)",
"loread", CmdLoread,0, "['h'] -- Read 125/134 kHz LF ID-only tag (option 'h' for 134)", "loread", CmdLoread,0, "['h'] -- Read 125/134 kHz LF ID-only tag (option 'h' for 134)",
"losamples", CmdLosamples,0, "[128 - 16000] -- Get raw samples for LF tag", "losamples", CmdLosamples,0, "[128 - 16000] -- Get raw samples for LF tag",
"losim", CmdLosim,0, " Simulate LF tag", "losim", CmdLosim,0, " Simulate LF tag",
"ltrim", CmdLtrim,1, "<samples> -- Trim samples from left of trace", "ltrim", CmdLtrim,1, "<samples> -- Trim samples from left of trace",
"mandemod", Cmdmanchesterdemod,1, "[clock rate] -- Try a Manchester demodulation on a binary stream", "mandemod", Cmdmanchesterdemod,1, "[i] [clock rate] -- Manchester demodulate binary stream (option 'i' to invert output)",
"manmod", Cmdmanchestermod,1, "[clock rate] -- Manchester modulate a binary stream", "manmod", Cmdmanchestermod,1, "[clock rate] -- Manchester modulate a binary stream",
"norm", CmdNorm,1, " Normalize max/min to +/-500", "norm", CmdNorm,1, " Normalize max/min to +/-500",
"plot", CmdPlot,1, " Show graph window", "plot", CmdPlot,1, " Show graph window",