DoAcquisition125k(at134khz);\r
}\r
\r
+/* blank r/w tag data stream\r
+...0000000000000000 01111111\r
+1010101010101010101010101010101010101010101010101010101010101010\r
+0011010010100001\r
+01111111\r
+101010101010101[0]000...\r
+\r
+[5555fe852c5555555555555555fe0000]\r
+*/\r
+void ReadTItag()\r
+{\r
+ // some hardcoded initial params\r
+ // when we read a TI tag we sample the zerocross line at 2Mhz\r
+ // TI tags modulate a 1 as 16 cycles of 123.2Khz\r
+ // TI tags modulate a 0 as 16 cycles of 134.2Khz\r
+ #define FSAMPLE 2000000\r
+ #define FREQLO 123200\r
+ #define FREQHI 134200\r
+\r
+ signed char *dest = (signed char *)BigBuf;\r
+ int n = sizeof(BigBuf);\r
+// int *dest = GraphBuffer;\r
+// int n = GraphTraceLen;\r
+\r
+ // 128 bit shift register [shift3:shift2:shift1:shift0]\r
+ DWORD shift3 = 0, shift2 = 0, shift1 = 0, shift0 = 0;\r
+\r
+ int i, cycles=0, samples=0;\r
+ // how many sample points fit in 16 cycles of each frequency\r
+ DWORD sampleslo = (FSAMPLE<<4)/FREQLO, sampleshi = (FSAMPLE<<4)/FREQHI;\r
+ // when to tell if we're close enough to one freq or another\r
+ DWORD threshold = (sampleslo - sampleshi + 1)>>1;\r
+\r
+ // TI tags charge at 134.2Khz\r
+ FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz\r
+\r
+ // Place FPGA in passthrough mode, in this mode the CROSS_LO line\r
+ // connects to SSP_DIN and the SSP_DOUT logic level controls\r
+ // whether we're modulating the antenna (high)\r
+ // or listening to the antenna (low)\r
+ FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_PASSTHRU);\r
+\r
+ // get TI tag data into the buffer\r
+ AcquireTiType();\r
+\r
+ FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
+\r
+ for (i=0; i<n-1; i++) {\r
+ // count cycles by looking for lo to hi zero crossings\r
+ if ( (dest[i]<0) && (dest[i+1]>0) ) {\r
+ cycles++;\r
+ // after 16 cycles, measure the frequency\r
+ if (cycles>15) {\r
+ cycles=0;\r
+ samples=i-samples; // number of samples in these 16 cycles\r
+\r
+ // TI bits are coming to us lsb first so shift them\r
+ // right through our 128 bit right shift register\r
+ shift0 = (shift0>>1) | (shift1 << 31);\r
+ shift1 = (shift1>>1) | (shift2 << 31);\r
+ shift2 = (shift2>>1) | (shift3 << 31);\r
+ shift3 >>= 1;\r
+\r
+ // check if the cycles fall close to the number\r
+ // expected for either the low or high frequency\r
+ if ( (samples>(sampleslo-threshold)) && (samples<(sampleslo+threshold)) ) {\r
+ // low frequency represents a 1\r
+ shift3 |= (1<<31);\r
+ } else if ( (samples>(sampleshi-threshold)) && (samples<(sampleshi+threshold)) ) {\r
+ // high frequency represents a 0\r
+ } else {\r
+ // probably detected a gay waveform or noise\r
+ // use this as gaydar or discard shift register and start again\r
+ shift3 = shift2 = shift1 = shift0 = 0;\r
+ }\r
+ samples = i;\r
+\r
+ // for each bit we receive, test if we've detected a valid tag\r
+\r
+ // if we see 17 zeroes followed by 6 ones, we might have a tag\r
+ // remember the bits are backwards\r
+ if ( ((shift0 & 0x7fffff) == 0x7e0000) ) {\r
+ // if start and end bytes match, we have a tag so break out of the loop\r
+ if ( ((shift0>>16)&0xff) == ((shift3>>8)&0xff) ) {\r
+ cycles = 0xF0B; //use this as a flag (ugly but whatever)\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ // if flag is set we have a tag\r
+ if (cycles!=0xF0B) {\r
+ DbpString("Info: No valid tag detected.");\r
+ } else {\r
+ // put 64 bit data into shift1 and shift0\r
+ shift0 = (shift0>>24) | (shift1 << 8);\r
+ shift1 = (shift1>>24) | (shift2 << 8);\r
+\r
+ // align 16 bit crc into lower half of shift2\r
+ shift2 = ((shift2>>24) | (shift3 << 8)) & 0x0ffff;\r
+\r
+ // if r/w tag, check ident match\r
+ if ( shift3&(1<<15) ) {\r
+ DbpString("Info: TI tag is rewriteable");\r
+ // only 15 bits compare, last bit of ident is not valid\r
+ if ( ((shift3>>16)^shift0)&0x7fff ) {\r
+ DbpString("Error: Ident mismatch!");\r
+ } else {\r
+ DbpString("Info: TI tag ident is valid");\r
+ }\r
+ } else {\r
+ DbpString("Info: TI tag is readonly");\r
+ }\r
+\r
+ // WARNING the order of the bytes in which we calc crc below needs checking\r
+ // i'm 99% sure the crc algorithm is correct, but it may need to eat the\r
+ // bytes in reverse or something\r
+ // calculate CRC\r
+ DWORD crc=0;\r
+\r
+ crc = update_crc16(crc, (shift0)&0xff);\r
+ crc = update_crc16(crc, (shift0>>8)&0xff);\r
+ crc = update_crc16(crc, (shift0>>16)&0xff);\r
+ crc = update_crc16(crc, (shift0>>24)&0xff);\r
+ crc = update_crc16(crc, (shift1)&0xff);\r
+ crc = update_crc16(crc, (shift1>>8)&0xff);\r
+ crc = update_crc16(crc, (shift1>>16)&0xff);\r
+ crc = update_crc16(crc, (shift1>>24)&0xff);\r
+\r
+ DbpString("Info: Tag data_hi, data_lo, crc = ");\r
+ DbpIntegers(shift1, shift0, shift2&0xffff);\r
+ if (crc != (shift2&0xffff)) {\r
+ DbpString("Error: CRC mismatch, expected");\r
+ DbpIntegers(0, 0, crc);\r
+ } else {\r
+ DbpString("Info: CRC is good");\r
+ }\r
+ }\r
+}\r
+\r
+void WriteTIbyte(BYTE b)\r
+{\r
+ int i = 0;\r
+\r
+ // modulate 8 bits out to the antenna\r
+ for (i=0; i<8; i++)\r
+ {\r
+ if (b&(1<<i)) {\r
+ // stop modulating antenna\r
+ PIO_OUTPUT_DATA_CLEAR = (1<<GPIO_SSC_DOUT);\r
+ SpinDelayUs(1000);\r
+ // modulate antenna\r
+ PIO_OUTPUT_DATA_SET = (1<<GPIO_SSC_DOUT);\r
+ SpinDelayUs(1000);\r
+ } else {\r
+ // stop modulating antenna\r
+ PIO_OUTPUT_DATA_CLEAR = (1<<GPIO_SSC_DOUT);\r
+ SpinDelayUs(300);\r
+ // modulate antenna\r
+ PIO_OUTPUT_DATA_SET = (1<<GPIO_SSC_DOUT);\r
+ SpinDelayUs(1700);\r
+ }\r
+ }\r
+}\r
+\r
void AcquireTiType(void)\r
{\r
- int i;\r
+ int i, j, n;\r
// tag transmission is <20ms, sampling at 2M gives us 40K samples max\r
// each sample is 1 bit stuffed into a DWORD so we need 1250 DWORDS\r
- int n = 1250;\r
+ #define TIBUFLEN 1250\r
\r
// clear buffer\r
- DbpIntegers((DWORD)BigBuf, sizeof(BigBuf), 0x12345678);\r
memset(BigBuf,0,sizeof(BigBuf));\r
\r
// Set up the synchronous serial port\r
for(;;) {\r
if(SSC_STATUS & SSC_STATUS_RX_READY) {\r
BigBuf[i] = SSC_RECEIVE_HOLDING; // store 32 bit values in buffer\r
- i++; if(i >= n) return;\r
+ i++; if(i >= TIBUFLEN) break;\r
}\r
WDT_HIT();\r
}\r
// return stolen pin to SSP\r
PIO_DISABLE = (1<<GPIO_SSC_DOUT);\r
PIO_PERIPHERAL_A_SEL = (1<<GPIO_SSC_DIN) | (1<<GPIO_SSC_DOUT);\r
-}\r
-\r
-void ReadTItag()\r
-{\r
-}\r
-\r
-void WriteTIbyte(BYTE b)\r
-{\r
- int i = 0;\r
\r
- // modulate 8 bits out to the antenna\r
- for (i=0; i<8; i++)\r
- {\r
- if (b&(1<<i)) {\r
- // stop modulating antenna\r
- PIO_OUTPUT_DATA_CLEAR = (1<<GPIO_SSC_DOUT);\r
- SpinDelayUs(1000);\r
- // modulate antenna\r
- PIO_OUTPUT_DATA_SET = (1<<GPIO_SSC_DOUT);\r
- SpinDelayUs(1000);\r
- } else {\r
- // stop modulating antenna\r
- PIO_OUTPUT_DATA_CLEAR = (1<<GPIO_SSC_DOUT);\r
- SpinDelayUs(300);\r
- // modulate antenna\r
- PIO_OUTPUT_DATA_SET = (1<<GPIO_SSC_DOUT);\r
- SpinDelayUs(1700);\r
+ char *dest = (char *)BigBuf;\r
+ n = TIBUFLEN*32;\r
+ // unpack buffer\r
+ for (i=TIBUFLEN-1; i>=0; i--) {\r
+// DbpIntegers(0, 0, BigBuf[i]);\r
+ for (j=0; j<32; j++) {\r
+ if(BigBuf[i] & (1 << j)) {\r
+ dest[--n] = 1;\r
+ } else {\r
+ dest[--n] = -1;\r
+ }\r
}\r
}\r
}\r
\r
-void AcquireRawBitsTI(void)\r
-{\r
- // TI tags charge at 134.2Khz\r
- FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz\r
-\r
- // Place FPGA in passthrough mode, in this mode the CROSS_LO line\r
- // connects to SSP_DIN and the SSP_DOUT logic level controls\r
- // whether we're modulating the antenna (high)\r
- // or listening to the antenna (low)\r
- FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_PASSTHRU);\r
-\r
- // get TI tag data into the buffer\r
- AcquireTiType();\r
-\r
- FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
-}\r
-\r
// arguments: 64bit data split into 32bit idhi:idlo and optional 16bit crc\r
// if crc provided, it will be written with the data verbatim (even if bogus)\r
// if not provided a valid crc will be computed from the data and written.\r
AcquireTiType();\r
\r
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
- DbpString("Now use tibits and tidemod");\r
+ DbpString("Now use tiread to check");\r
}\r
\r
void SimulateTagLowFrequency(int period, int ledcontrol)\r
PrintToScrollback("CRC=%04x", Iso15693Crc(outBuf, k-2));\r
}\r
\r
-static void CmdTIReadRaw(char *str)\r
-{\r
- UsbCommand c;\r
- c.cmd = CMD_ACQUIRE_RAW_BITS_TI_TYPE;\r
- SendCommand(&c, FALSE);\r
-}\r
-\r
-static void CmdTIBits(char *str)\r
-{\r
- int cnt = 0;\r
- int i;\r
-// for(i = 0; i < 1536; i += 12) {\r
- for(i = 0; i < 4000; i += 12) {\r
- UsbCommand c;\r
- c.cmd = CMD_DOWNLOAD_RAW_BITS_TI_TYPE;\r
- c.ext1 = i;\r
- SendCommand(&c, FALSE);\r
- ReceiveCommand(&c);\r
- if(c.cmd != CMD_DOWNLOADED_RAW_BITS_TI_TYPE) {\r
- PrintToScrollback("bad resp");\r
- return;\r
- }\r
- int j;\r
- for(j = 0; j < 12; j++) {\r
- int k;\r
- for(k = 31; k >= 0; k--) {\r
- if(c.d.asDwords[j] & (1 << k)) {\r
- GraphBuffer[cnt++] = 1;\r
- } else {\r
- GraphBuffer[cnt++] = -1;\r
- }\r
- }\r
- }\r
- }\r
-// GraphTraceLen = 1536*32;\r
- GraphTraceLen = 4000*32;\r
- RepaintGraphWindow();\r
-}\r
-\r
static void CmdFSKdemod(char *cmdline)\r
{\r
static const int LowTone[] = {\r
1, 1, 1, 1, -1, -1, -1, -1, -1,\r
};\r
\r
- int convLen = max(arraylen(HighTone), arraylen(LowTone));\r
+ int lowLen = sizeof(LowTone)/sizeof(int);\r
+ int highLen = sizeof(HighTone)/sizeof(int);\r
+ int convLen = (highLen>lowLen)?highLen:lowLen;\r
DWORD hi = 0, lo = 0;\r
\r
int i, j;\r
int minMark=0, maxMark=0;\r
- int lowLen = arraylen(LowTone);\r
- int highLen = arraylen(HighTone);\r
\r
for(i = 0; i < GraphTraceLen - convLen; i++) {\r
int lowSum = 0, highSum = 0;\r
int max = 0, maxPos = 0;\r
for(i = 0; i < 6000; i++) {\r
int dec = 0;\r
- for(j = 0; j < 3*arraylen(LowTone); j++) {\r
+ for(j = 0; j < 3*lowLen; j++) {\r
dec -= GraphBuffer[i+j];\r
}\r
- for(; j < 3*(arraylen(LowTone) + arraylen(HighTone) ); j++) {\r
+ for(; j < 3*(lowLen + highLen ); j++) {\r
dec += GraphBuffer[i+j];\r
}\r
if(dec > max) {\r
GraphBuffer[maxPos+1] = minMark;\r
\r
PrintToScrollback("actual data bits start at sample %d", maxPos);\r
- PrintToScrollback("length %d/%d", arraylen(HighTone), arraylen(LowTone));\r
+ PrintToScrollback("length %d/%d", highLen, lowLen);\r
\r
BYTE bits[46];\r
bits[sizeof(bits)-1] = '\0';\r
// find bit pairs and manchester decode them\r
for(i = 0; i < arraylen(bits)-1; i++) {\r
int dec = 0;\r
- for(j = 0; j < arraylen(LowTone); j++) {\r
+ for(j = 0; j < lowLen; j++) {\r
dec -= GraphBuffer[maxPos+j];\r
}\r
- for(; j < arraylen(LowTone) + arraylen(HighTone); j++) {\r
+ for(; j < lowLen + highLen; j++) {\r
dec += GraphBuffer[maxPos+j];\r
}\r
maxPos += j;\r
res = sscanf(str, "0x%x 0x%x 0x%x ", &c.ext1, &c.ext2, &c.ext3);\r
if (res == 2) c.ext3=0;\r
if (res<2)\r
- PrintToScrollback("Please specify 2 or three hex strings, eg 0x1234 0x5678");\r
+ PrintToScrollback("Please specify the data as two hex strings, optionally the CRC as a third");\r
else\r
SendCommand(&c, FALSE);\r
}\r
l = sign(sin(cumsum(l)));\r
h = sign(sin(cumsum(h)));\r
*/\r
+\r
+// 2M*16/134.2k = 238\r
static const int LowTone[] = {\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, -1, -1\r
};\r
+// 2M*16/123.2k = 260\r
static const int HighTone[] = {\r
- 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
- 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1\r
};\r
-\r
- int convLen = max(arraylen(HighTone), arraylen(LowTone));\r
+ int lowLen = sizeof(LowTone)/sizeof(int);\r
+ int highLen = sizeof(HighTone)/sizeof(int);\r
+ int convLen = (highLen>lowLen)?highLen:lowLen;\r
WORD crc;\r
- int i, TagType;\r
+ int i, j, TagType;\r
+ int lowSum = 0, highSum = 0;;\r
+ int lowTot = 0, highTot = 0;\r
+\r
for(i = 0; i < GraphTraceLen - convLen; i++) {\r
- int j;\r
- int lowSum = 0, highSum = 0;;\r
- int lowLen = arraylen(LowTone);\r
- int highLen = arraylen(HighTone);\r
+ lowSum = 0;\r
+ highSum = 0;;\r
\r
for(j = 0; j < lowLen; j++) {\r
lowSum += LowTone[j]*GraphBuffer[i+j];\r
}\r
lowSum = abs((100*lowSum) / lowLen);\r
highSum = abs((100*highSum) / highLen);\r
+ lowSum = (lowSum<0)?-lowSum:lowSum;\r
+ highSum = (highSum<0)?-highSum:highSum;\r
+\r
GraphBuffer[i] = (highSum << 16) | lowSum;\r
}\r
\r
for(i = 0; i < GraphTraceLen - convLen - 16; i++) {\r
- int j;\r
- int lowTot = 0, highTot = 0;\r
+ lowTot = 0;\r
+ highTot = 0;\r
// 16 and 15 are f_s divided by f_l and f_h, rounded\r
for(j = 0; j < 16; j++) {\r
lowTot += (GraphBuffer[i+j] & 0xffff);\r
int j;\r
int dec = 0;\r
// searching 17 consecutive lows\r
- for(j = 0; j < 17*arraylen(LowTone); j++) {\r
+ for(j = 0; j < 17*lowLen; j++) {\r
dec -= GraphBuffer[i+j];\r
}\r
// searching 7 consecutive highs\r
- for(; j < 17*arraylen(LowTone) + 6*arraylen(HighTone); j++) {\r
+ for(; j < 17*lowLen + 6*highLen; j++) {\r
dec += GraphBuffer[i+j];\r
}\r
if(dec > max) {\r
GraphBuffer[maxPos+1] = -800;\r
\r
// advance pointer to start of actual data stream (after 16 pre and 8 start bits)\r
- maxPos += 17*arraylen(LowTone);\r
- maxPos += 6*arraylen(HighTone);\r
+ maxPos += 17*lowLen;\r
+ maxPos += 6*highLen;\r
\r
// place a marker in the buffer to visually aid location\r
// of the end of sync\r
\r
PrintToScrollback("actual data bits start at sample %d", maxPos);\r
\r
- PrintToScrollback("length %d/%d", arraylen(HighTone), arraylen(LowTone));\r
+ PrintToScrollback("length %d/%d", highLen, lowLen);\r
\r
BYTE bits[1+64+16+8+16];\r
bits[sizeof(bits)-1] = '\0';\r
int high = 0;\r
int low = 0;\r
int j;\r
- for(j = 0; j < arraylen(LowTone); j++) {\r
+ for(j = 0; j < lowLen; j++) {\r
low -= GraphBuffer[maxPos+j];\r
}\r
- for(j = 0; j < arraylen(HighTone); j++) {\r
+ for(j = 0; j < highLen; j++) {\r
high += GraphBuffer[maxPos+j];\r
}\r
\r
if(high > low) {\r
bits[i] = '1';\r
- maxPos += arraylen(HighTone);\r
+ maxPos += highLen;\r
// bitstream arrives lsb first so shift right\r
shift3 |= (1<<31);\r
} else {\r
bits[i] = '.';\r
- maxPos += arraylen(LowTone);\r
+ maxPos += lowLen;\r
}\r
\r
// 128 bit right shift register\r
{"scale", CmdScale, 1, "<int> -- Set cursor display scale"},\r
{"setlfdivisor", CmdSetDivisor, 0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},\r
{"sri512read", CmdSri512read, 0, "<int> -- Read contents of a SRI512 tag"},\r
- {"tibits", CmdTIBits, 0, "Get raw bits for TI-type LF tag"},\r
{"tidemod", CmdTIDemod, 1, "Demodulate raw bits for TI-type LF tag"},\r
- {"tireadraw", CmdTIReadRaw, 0, "Read a TI-type 134 kHz tag in raw mode"},\r
{"tiread", CmdTIRead, 0, "Read and decode a TI 134 kHz tag"},\r
{"tiwrite", CmdTIWrite, 0, "Write new data to a r/w TI 134 kHz tag"},\r
{"threshold", CmdThreshold, 1, "Maximize/minimize every value in the graph window depending on threshold"},\r