-// redesigned by marshmellow adjusted from existing decode functions
-// indala id decoding - only tested on 26 bit tags, but attempted to make it work for more
-int indala26decode(uint8_t *bitStream, size_t *size, uint8_t *invert)
-{
- //26 bit 40134 format (don't know other formats)
- uint8_t preamble[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
- uint8_t preamble_i[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0};
- size_t startidx = 0;
- if (!preambleSearch(bitStream, preamble, sizeof(preamble), size, &startidx)){
- // if didn't find preamble try again inverting
- if (!preambleSearch(bitStream, preamble_i, sizeof(preamble_i), size, &startidx)) return -1;
- *invert ^= 1;
- }
- if (*size != 64 && *size != 224) return -2;
- if (*invert==1)
- for (size_t i = startidx; i < *size; i++)
- bitStream[i] ^= 1;
-
- return (int) startidx;
-}
-
-// by marshmellow - demodulate NRZ wave - requires a read with strong signal
-// peaks invert bit (high=1 low=0) each clock cycle = 1 bit determined by last peak
-int nrzRawDemod(uint8_t *dest, size_t *size, int *clk, int *invert){
- if (justNoise(dest, *size)) return -1;
- *clk = DetectNRZClock(dest, *size, *clk);
- if (*clk==0) return -2;
- size_t i, gLen = 4096;
- if (gLen>*size) gLen = *size-20;
- int high, low;
- if (getHiLo(dest, gLen, &high, &low, 75, 75) < 1) return -3; //25% fuzz on high 25% fuzz on low
-
- uint8_t bit=0;
- //convert wave samples to 1's and 0's
- for(i=20; i < *size-20; i++){
- if (dest[i] >= high) bit = 1;
- if (dest[i] <= low) bit = 0;
- dest[i] = bit;
- }
- //now demod based on clock (rf/32 = 32 1's for one 1 bit, 32 0's for one 0 bit)
- size_t lastBit = 0;
- size_t numBits = 0;
- for(i=21; i < *size-20; i++) {
- //if transition detected or large number of same bits - store the passed bits
- if (dest[i] != dest[i-1] || (i-lastBit) == (10 * *clk)) {
- memset(dest+numBits, dest[i-1] ^ *invert, (i - lastBit + (*clk/4)) / *clk);
- numBits += (i - lastBit + (*clk/4)) / *clk;
- lastBit = i-1;
- }
- }
- *size = numBits;
- return 0;
-}
-
-//by marshmellow
-//detects the bit clock for FSK given the high and low Field Clocks
-uint8_t detectFSKClk(uint8_t *BitStream, size_t size, uint8_t fcHigh, uint8_t fcLow)
-{
- uint8_t clk[] = {8,16,32,40,50,64,100,128,0};
- uint16_t rfLens[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
- uint8_t rfCnts[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
- uint8_t rfLensFnd = 0;
- uint8_t lastFCcnt = 0;
- uint16_t fcCounter = 0;
- uint16_t rfCounter = 0;
- uint8_t firstBitFnd = 0;
- size_t i;
- if (size == 0) return 0;