Added tiread command to demod TI tags on the PM3

This commit is contained in:
d18c7db 2009-08-06 12:53:06 +00:00
parent c0bc73bc35
commit 7381e8f2f2
5 changed files with 258 additions and 167 deletions

View file

@ -597,10 +597,6 @@ void UsbPacketReceived(BYTE *packet, int len)
LED_D_OFF(); // LED D indicates field ON or OFF
break;
case CMD_ACQUIRE_RAW_BITS_TI_TYPE:
AcquireRawBitsTI();
break;
case CMD_READ_TI_TYPE:
ReadTItag();
break;
@ -609,8 +605,7 @@ void UsbPacketReceived(BYTE *packet, int len)
WriteTItag(c->ext1,c->ext2,c->ext3);
break;
case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K:
case CMD_DOWNLOAD_RAW_BITS_TI_TYPE: {
case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K: {
UsbCommand n;
if(c->cmd == CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K) {
n.cmd = CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K;
@ -632,11 +627,6 @@ void UsbPacketReceived(BYTE *packet, int len)
SimulateTagLowFrequency(c->ext1, 1);
LED_A_OFF();
break;
#ifdef WITH_LCD
case CMD_LCD_RESET:
LCDReset();
break;
#endif
case CMD_READ_MEM:
ReadMem(c->ext1);
break;
@ -644,6 +634,9 @@ void UsbPacketReceived(BYTE *packet, int len)
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, c->ext1);
break;
#ifdef WITH_LCD
case CMD_LCD_RESET:
LCDReset();
break;
case CMD_LCD:
LCDSend(c->ext1);
break;
@ -660,7 +653,6 @@ void UsbPacketReceived(BYTE *packet, int len)
}
break;
default:
DbpString("unknown command");
break;

View file

@ -9,7 +9,7 @@
// The large multi-purpose buffer, typically used to hold A/D samples,
// maybe processed in some way.
DWORD BigBuf[10000];
DWORD BigBuf[12000];
/// appmain.h
void ReadMem(int addr);

View file

@ -115,15 +115,181 @@ void ModThenAcquireRawAdcSamples125k(int delay_off,int period_0,int period_1,BYT
DoAcquisition125k(at134khz);
}
/* blank r/w tag data stream
...0000000000000000 01111111
1010101010101010101010101010101010101010101010101010101010101010
0011010010100001
01111111
101010101010101[0]000...
[5555fe852c5555555555555555fe0000]
*/
void ReadTItag()
{
// some hardcoded initial params
// when we read a TI tag we sample the zerocross line at 2Mhz
// TI tags modulate a 1 as 16 cycles of 123.2Khz
// TI tags modulate a 0 as 16 cycles of 134.2Khz
#define FSAMPLE 2000000
#define FREQLO 123200
#define FREQHI 134200
signed char *dest = (signed char *)BigBuf;
int n = sizeof(BigBuf);
// int *dest = GraphBuffer;
// int n = GraphTraceLen;
// 128 bit shift register [shift3:shift2:shift1:shift0]
DWORD shift3 = 0, shift2 = 0, shift1 = 0, shift0 = 0;
int i, cycles=0, samples=0;
// how many sample points fit in 16 cycles of each frequency
DWORD sampleslo = (FSAMPLE<<4)/FREQLO, sampleshi = (FSAMPLE<<4)/FREQHI;
// when to tell if we're close enough to one freq or another
DWORD threshold = (sampleslo - sampleshi + 1)>>1;
// TI tags charge at 134.2Khz
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz
// Place FPGA in passthrough mode, in this mode the CROSS_LO line
// connects to SSP_DIN and the SSP_DOUT logic level controls
// whether we're modulating the antenna (high)
// or listening to the antenna (low)
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_PASSTHRU);
// get TI tag data into the buffer
AcquireTiType();
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
for (i=0; i<n-1; i++) {
// count cycles by looking for lo to hi zero crossings
if ( (dest[i]<0) && (dest[i+1]>0) ) {
cycles++;
// after 16 cycles, measure the frequency
if (cycles>15) {
cycles=0;
samples=i-samples; // number of samples in these 16 cycles
// TI bits are coming to us lsb first so shift them
// right through our 128 bit right shift register
shift0 = (shift0>>1) | (shift1 << 31);
shift1 = (shift1>>1) | (shift2 << 31);
shift2 = (shift2>>1) | (shift3 << 31);
shift3 >>= 1;
// check if the cycles fall close to the number
// expected for either the low or high frequency
if ( (samples>(sampleslo-threshold)) && (samples<(sampleslo+threshold)) ) {
// low frequency represents a 1
shift3 |= (1<<31);
} else if ( (samples>(sampleshi-threshold)) && (samples<(sampleshi+threshold)) ) {
// high frequency represents a 0
} else {
// probably detected a gay waveform or noise
// use this as gaydar or discard shift register and start again
shift3 = shift2 = shift1 = shift0 = 0;
}
samples = i;
// for each bit we receive, test if we've detected a valid tag
// if we see 17 zeroes followed by 6 ones, we might have a tag
// remember the bits are backwards
if ( ((shift0 & 0x7fffff) == 0x7e0000) ) {
// if start and end bytes match, we have a tag so break out of the loop
if ( ((shift0>>16)&0xff) == ((shift3>>8)&0xff) ) {
cycles = 0xF0B; //use this as a flag (ugly but whatever)
break;
}
}
}
}
}
// if flag is set we have a tag
if (cycles!=0xF0B) {
DbpString("Info: No valid tag detected.");
} else {
// put 64 bit data into shift1 and shift0
shift0 = (shift0>>24) | (shift1 << 8);
shift1 = (shift1>>24) | (shift2 << 8);
// align 16 bit crc into lower half of shift2
shift2 = ((shift2>>24) | (shift3 << 8)) & 0x0ffff;
// if r/w tag, check ident match
if ( shift3&(1<<15) ) {
DbpString("Info: TI tag is rewriteable");
// only 15 bits compare, last bit of ident is not valid
if ( ((shift3>>16)^shift0)&0x7fff ) {
DbpString("Error: Ident mismatch!");
} else {
DbpString("Info: TI tag ident is valid");
}
} else {
DbpString("Info: TI tag is readonly");
}
// WARNING the order of the bytes in which we calc crc below needs checking
// i'm 99% sure the crc algorithm is correct, but it may need to eat the
// bytes in reverse or something
// calculate CRC
DWORD crc=0;
crc = update_crc16(crc, (shift0)&0xff);
crc = update_crc16(crc, (shift0>>8)&0xff);
crc = update_crc16(crc, (shift0>>16)&0xff);
crc = update_crc16(crc, (shift0>>24)&0xff);
crc = update_crc16(crc, (shift1)&0xff);
crc = update_crc16(crc, (shift1>>8)&0xff);
crc = update_crc16(crc, (shift1>>16)&0xff);
crc = update_crc16(crc, (shift1>>24)&0xff);
DbpString("Info: Tag data_hi, data_lo, crc = ");
DbpIntegers(shift1, shift0, shift2&0xffff);
if (crc != (shift2&0xffff)) {
DbpString("Error: CRC mismatch, expected");
DbpIntegers(0, 0, crc);
} else {
DbpString("Info: CRC is good");
}
}
}
void WriteTIbyte(BYTE b)
{
int i = 0;
// modulate 8 bits out to the antenna
for (i=0; i<8; i++)
{
if (b&(1<<i)) {
// stop modulating antenna
PIO_OUTPUT_DATA_CLEAR = (1<<GPIO_SSC_DOUT);
SpinDelayUs(1000);
// modulate antenna
PIO_OUTPUT_DATA_SET = (1<<GPIO_SSC_DOUT);
SpinDelayUs(1000);
} else {
// stop modulating antenna
PIO_OUTPUT_DATA_CLEAR = (1<<GPIO_SSC_DOUT);
SpinDelayUs(300);
// modulate antenna
PIO_OUTPUT_DATA_SET = (1<<GPIO_SSC_DOUT);
SpinDelayUs(1700);
}
}
}
void AcquireTiType(void)
{
int i;
int i, j, n;
// tag transmission is <20ms, sampling at 2M gives us 40K samples max
// each sample is 1 bit stuffed into a DWORD so we need 1250 DWORDS
int n = 1250;
#define TIBUFLEN 1250
// clear buffer
DbpIntegers((DWORD)BigBuf, sizeof(BigBuf), 0x12345678);
memset(BigBuf,0,sizeof(BigBuf));
// Set up the synchronous serial port
@ -163,7 +329,7 @@ void AcquireTiType(void)
for(;;) {
if(SSC_STATUS & SSC_STATUS_RX_READY) {
BigBuf[i] = SSC_RECEIVE_HOLDING; // store 32 bit values in buffer
i++; if(i >= n) return;
i++; if(i >= TIBUFLEN) break;
}
WDT_HIT();
}
@ -171,54 +337,22 @@ void AcquireTiType(void)
// return stolen pin to SSP
PIO_DISABLE = (1<<GPIO_SSC_DOUT);
PIO_PERIPHERAL_A_SEL = (1<<GPIO_SSC_DIN) | (1<<GPIO_SSC_DOUT);
}
void ReadTItag()
{
}
void WriteTIbyte(BYTE b)
{
int i = 0;
// modulate 8 bits out to the antenna
for (i=0; i<8; i++)
{
if (b&(1<<i)) {
// stop modulating antenna
PIO_OUTPUT_DATA_CLEAR = (1<<GPIO_SSC_DOUT);
SpinDelayUs(1000);
// modulate antenna
PIO_OUTPUT_DATA_SET = (1<<GPIO_SSC_DOUT);
SpinDelayUs(1000);
} else {
// stop modulating antenna
PIO_OUTPUT_DATA_CLEAR = (1<<GPIO_SSC_DOUT);
SpinDelayUs(300);
// modulate antenna
PIO_OUTPUT_DATA_SET = (1<<GPIO_SSC_DOUT);
SpinDelayUs(1700);
char *dest = (char *)BigBuf;
n = TIBUFLEN*32;
// unpack buffer
for (i=TIBUFLEN-1; i>=0; i--) {
// DbpIntegers(0, 0, BigBuf[i]);
for (j=0; j<32; j++) {
if(BigBuf[i] & (1 << j)) {
dest[--n] = 1;
} else {
dest[--n] = -1;
}
}
}
}
void AcquireRawBitsTI(void)
{
// TI tags charge at 134.2Khz
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz
// Place FPGA in passthrough mode, in this mode the CROSS_LO line
// connects to SSP_DIN and the SSP_DOUT logic level controls
// whether we're modulating the antenna (high)
// or listening to the antenna (low)
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_PASSTHRU);
// get TI tag data into the buffer
AcquireTiType();
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
}
// arguments: 64bit data split into 32bit idhi:idlo and optional 16bit crc
// if crc provided, it will be written with the data verbatim (even if bogus)
// if not provided a valid crc will be computed from the data and written.
@ -292,7 +426,7 @@ void WriteTItag(DWORD idhi, DWORD idlo, WORD crc)
AcquireTiType();
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
DbpString("Now use tibits and tidemod");
DbpString("Now use tiread to check");
}
void SimulateTagLowFrequency(int period, int ledcontrol)

View file

@ -37,8 +37,6 @@ typedef struct {
#define CMD_READ_MEM 0x0106
// For low-frequency tags
#define CMD_ACQUIRE_RAW_BITS_TI_TYPE 0x0200
#define CMD_DOWNLOAD_RAW_BITS_TI_TYPE 0x0201
#define CMD_READ_TI_TYPE 0x0202
#define CMD_WRITE_TI_TYPE 0x0203
#define CMD_DOWNLOADED_RAW_BITS_TI_TYPE 0x0204

View file

@ -1397,45 +1397,6 @@ static void CmdHi15demod(char *str)
PrintToScrollback("CRC=%04x", Iso15693Crc(outBuf, k-2));
}
static void CmdTIReadRaw(char *str)
{
UsbCommand c;
c.cmd = CMD_ACQUIRE_RAW_BITS_TI_TYPE;
SendCommand(&c, FALSE);
}
static void CmdTIBits(char *str)
{
int cnt = 0;
int i;
// for(i = 0; i < 1536; i += 12) {
for(i = 0; i < 4000; i += 12) {
UsbCommand c;
c.cmd = CMD_DOWNLOAD_RAW_BITS_TI_TYPE;
c.ext1 = i;
SendCommand(&c, FALSE);
ReceiveCommand(&c);
if(c.cmd != CMD_DOWNLOADED_RAW_BITS_TI_TYPE) {
PrintToScrollback("bad resp");
return;
}
int j;
for(j = 0; j < 12; j++) {
int k;
for(k = 31; k >= 0; k--) {
if(c.d.asDwords[j] & (1 << k)) {
GraphBuffer[cnt++] = 1;
} else {
GraphBuffer[cnt++] = -1;
}
}
}
}
// GraphTraceLen = 1536*32;
GraphTraceLen = 4000*32;
RepaintGraphWindow();
}
static void CmdFSKdemod(char *cmdline)
{
static const int LowTone[] = {
@ -1454,13 +1415,13 @@ static void CmdFSKdemod(char *cmdline)
1, 1, 1, 1, -1, -1, -1, -1, -1,
};
int convLen = max(arraylen(HighTone), arraylen(LowTone));
int lowLen = sizeof(LowTone)/sizeof(int);
int highLen = sizeof(HighTone)/sizeof(int);
int convLen = (highLen>lowLen)?highLen:lowLen;
DWORD hi = 0, lo = 0;
int i, j;
int minMark=0, maxMark=0;
int lowLen = arraylen(LowTone);
int highLen = arraylen(HighTone);
for(i = 0; i < GraphTraceLen - convLen; i++) {
int lowSum = 0, highSum = 0;
@ -1499,10 +1460,10 @@ static void CmdFSKdemod(char *cmdline)
int max = 0, maxPos = 0;
for(i = 0; i < 6000; i++) {
int dec = 0;
for(j = 0; j < 3*arraylen(LowTone); j++) {
for(j = 0; j < 3*lowLen; j++) {
dec -= GraphBuffer[i+j];
}
for(; j < 3*(arraylen(LowTone) + arraylen(HighTone) ); j++) {
for(; j < 3*(lowLen + highLen ); j++) {
dec += GraphBuffer[i+j];
}
if(dec > max) {
@ -1522,7 +1483,7 @@ static void CmdFSKdemod(char *cmdline)
GraphBuffer[maxPos+1] = minMark;
PrintToScrollback("actual data bits start at sample %d", maxPos);
PrintToScrollback("length %d/%d", arraylen(HighTone), arraylen(LowTone));
PrintToScrollback("length %d/%d", highLen, lowLen);
BYTE bits[46];
bits[sizeof(bits)-1] = '\0';
@ -1530,10 +1491,10 @@ static void CmdFSKdemod(char *cmdline)
// find bit pairs and manchester decode them
for(i = 0; i < arraylen(bits)-1; i++) {
int dec = 0;
for(j = 0; j < arraylen(LowTone); j++) {
for(j = 0; j < lowLen; j++) {
dec -= GraphBuffer[maxPos+j];
}
for(; j < arraylen(LowTone) + arraylen(HighTone); j++) {
for(; j < lowLen + highLen; j++) {
dec += GraphBuffer[maxPos+j];
}
maxPos += j;
@ -1574,7 +1535,7 @@ static void CmdTIWrite(char *str)
res = sscanf(str, "0x%x 0x%x 0x%x ", &c.ext1, &c.ext2, &c.ext3);
if (res == 2) c.ext3=0;
if (res<2)
PrintToScrollback("Please specify 2 or three hex strings, eg 0x1234 0x5678");
PrintToScrollback("Please specify the data as two hex strings, optionally the CRC as a third");
else
SendCommand(&c, FALSE);
}
@ -1595,52 +1556,57 @@ h = 2*pi*ones(1, floor(f_s*T_h))*(f_h/f_s);
l = sign(sin(cumsum(l)));
h = sign(sin(cumsum(h)));
*/
static const int LowTone[] = {
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1,
};
static const int HighTone[] = {
1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1,
};
int convLen = max(arraylen(HighTone), arraylen(LowTone));
// 2M*16/134.2k = 238
static const int LowTone[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1
};
// 2M*16/123.2k = 260
static const int HighTone[] = {
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1
};
int lowLen = sizeof(LowTone)/sizeof(int);
int highLen = sizeof(HighTone)/sizeof(int);
int convLen = (highLen>lowLen)?highLen:lowLen;
WORD crc;
int i, TagType;
int i, j, TagType;
int lowSum = 0, highSum = 0;;
int lowTot = 0, highTot = 0;
for(i = 0; i < GraphTraceLen - convLen; i++) {
int j;
int lowSum = 0, highSum = 0;;
int lowLen = arraylen(LowTone);
int highLen = arraylen(HighTone);
lowSum = 0;
highSum = 0;;
for(j = 0; j < lowLen; j++) {
lowSum += LowTone[j]*GraphBuffer[i+j];
@ -1650,12 +1616,15 @@ h = sign(sin(cumsum(h)));
}
lowSum = abs((100*lowSum) / lowLen);
highSum = abs((100*highSum) / highLen);
lowSum = (lowSum<0)?-lowSum:lowSum;
highSum = (highSum<0)?-highSum:highSum;
GraphBuffer[i] = (highSum << 16) | lowSum;
}
for(i = 0; i < GraphTraceLen - convLen - 16; i++) {
int j;
int lowTot = 0, highTot = 0;
lowTot = 0;
highTot = 0;
// 16 and 15 are f_s divided by f_l and f_h, rounded
for(j = 0; j < 16; j++) {
lowTot += (GraphBuffer[i+j] & 0xffff);
@ -1688,11 +1657,11 @@ h = sign(sin(cumsum(h)));
int j;
int dec = 0;
// searching 17 consecutive lows
for(j = 0; j < 17*arraylen(LowTone); j++) {
for(j = 0; j < 17*lowLen; j++) {
dec -= GraphBuffer[i+j];
}
// searching 7 consecutive highs
for(; j < 17*arraylen(LowTone) + 6*arraylen(HighTone); j++) {
for(; j < 17*lowLen + 6*highLen; j++) {
dec += GraphBuffer[i+j];
}
if(dec > max) {
@ -1707,8 +1676,8 @@ h = sign(sin(cumsum(h)));
GraphBuffer[maxPos+1] = -800;
// advance pointer to start of actual data stream (after 16 pre and 8 start bits)
maxPos += 17*arraylen(LowTone);
maxPos += 6*arraylen(HighTone);
maxPos += 17*lowLen;
maxPos += 6*highLen;
// place a marker in the buffer to visually aid location
// of the end of sync
@ -1717,7 +1686,7 @@ h = sign(sin(cumsum(h)));
PrintToScrollback("actual data bits start at sample %d", maxPos);
PrintToScrollback("length %d/%d", arraylen(HighTone), arraylen(LowTone));
PrintToScrollback("length %d/%d", highLen, lowLen);
BYTE bits[1+64+16+8+16];
bits[sizeof(bits)-1] = '\0';
@ -1728,21 +1697,21 @@ h = sign(sin(cumsum(h)));
int high = 0;
int low = 0;
int j;
for(j = 0; j < arraylen(LowTone); j++) {
for(j = 0; j < lowLen; j++) {
low -= GraphBuffer[maxPos+j];
}
for(j = 0; j < arraylen(HighTone); j++) {
for(j = 0; j < highLen; j++) {
high += GraphBuffer[maxPos+j];
}
if(high > low) {
bits[i] = '1';
maxPos += arraylen(HighTone);
maxPos += highLen;
// bitstream arrives lsb first so shift right
shift3 |= (1<<31);
} else {
bits[i] = '.';
maxPos += arraylen(LowTone);
maxPos += lowLen;
}
// 128 bit right shift register
@ -2870,9 +2839,7 @@ static struct {
{"scale", CmdScale, 1, "<int> -- Set cursor display scale"},
{"setlfdivisor", CmdSetDivisor, 0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
{"sri512read", CmdSri512read, 0, "<int> -- Read contents of a SRI512 tag"},
{"tibits", CmdTIBits, 0, "Get raw bits for TI-type LF tag"},
{"tidemod", CmdTIDemod, 1, "Demodulate raw bits for TI-type LF tag"},
{"tireadraw", CmdTIReadRaw, 0, "Read a TI-type 134 kHz tag in raw mode"},
{"tiread", CmdTIRead, 0, "Read and decode a TI 134 kHz tag"},
{"tiwrite", CmdTIWrite, 0, "Write new data to a r/w TI 134 kHz tag"},
{"threshold", CmdThreshold, 1, "Maximize/minimize every value in the graph window depending on threshold"},