with em410xread, retest if we read our bits the wrong way (1=0 and 0=1)

This commit is contained in:
skamkar 2009-07-03 00:56:12 +00:00
parent 15db5fb71a
commit a91ff4c8e7

View file

@ -262,6 +262,7 @@ static void CmdEM410xread(char *str)
int i, j, clock, header, rows, bit, hithigh, hitlow, first, bit2idx, high, low; int i, j, clock, header, rows, bit, hithigh, hitlow, first, bit2idx, high, low;
int parity[4]; int parity[4];
char id[11]; char id[11];
int retested = 0;
int BitStream[MAX_GRAPH_TRACE_LEN]; int BitStream[MAX_GRAPH_TRACE_LEN];
high = low = 0; high = low = 0;
@ -307,14 +308,15 @@ static void CmdEM410xread(char *str)
if (hithigh && hitlow) if (hithigh && hitlow)
break; break;
} }
/* If we didn't hit both high and low peaks, we had a bit transition */ /* If we didn't hit both high and low peaks, we had a bit transition */
if (!hithigh || !hitlow) if (!hithigh || !hitlow)
bit ^= 1; bit ^= 1;
BitStream[bit2idx++] = bit; BitStream[bit2idx++] = bit;
} }
retest:
/* We go till 5 before the graph ends because we'll get that far below */ /* We go till 5 before the graph ends because we'll get that far below */
for (i = 1; i < bit2idx - 5; i++) for (i = 1; i < bit2idx - 5; i++)
{ {
@ -363,7 +365,7 @@ static void CmdEM410xread(char *str)
/* Stop any loops */ /* Stop any loops */
go = 0; go = 0;
break; return;
} }
/* Crap! Incorrect parity or no stop bit, start all over */ /* Crap! Incorrect parity or no stop bit, start all over */
@ -388,6 +390,16 @@ static void CmdEM410xread(char *str)
header = 0; header = 0;
} }
} }
/* if we've already retested after flipping bits, return */
if (retested++)
return;
/* if this didn't work, try flipping bits */
for (i = 0; i < bit2idx; i++)
BitStream[i] ^= 1;
goto retest;
} }
/* emulate an EM410X tag /* emulate an EM410X tag
@ -1862,7 +1874,7 @@ static void Cmdaskdemod(char *str) {
* - we're high: transition if we hit a low * - we're high: transition if we hit a low
* (we need to do it this way because some tags keep high or * (we need to do it this way because some tags keep high or
* low for long periods, others just reach the peak and go * low for long periods, others just reach the peak and go
* down) * down)
*/ */
if ((GraphBuffer[i]==high) && (GraphBuffer[i-1] == c)) { if ((GraphBuffer[i]==high) && (GraphBuffer[i-1] == c)) {
GraphBuffer[i]=1-c; GraphBuffer[i]=1-c;