2015-01-07 12:29:45 +08:00
|
|
|
// Copyright (C) 2014
|
2014-12-29 09:33:32 +08:00
|
|
|
//
|
|
|
|
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
|
|
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
|
|
|
// the license.
|
|
|
|
//-----------------------------------------------------------------------------
|
2015-01-19 07:13:32 +08:00
|
|
|
// Low frequency demod related commands
|
|
|
|
// marshmellow
|
|
|
|
// note that many of these demods are not the slickest code and they often rely
|
2019-03-09 15:59:13 +08:00
|
|
|
// on peaks and clock instead of converting to clean signal.
|
|
|
|
//
|
2014-12-29 09:33:32 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#ifndef LFDEMOD_H__
|
|
|
|
#define LFDEMOD_H__
|
2019-08-08 22:57:33 +08:00
|
|
|
|
|
|
|
#include "common.h"
|
2019-03-09 02:06:55 +08:00
|
|
|
|
|
|
|
//might not be high enough for noisy environments
|
2019-05-28 17:15:12 +08:00
|
|
|
#define NOISE_AMPLITUDE_THRESHOLD 8
|
2019-03-09 02:06:55 +08:00
|
|
|
//ignore buffer with less than x samples
|
|
|
|
#define SIGNAL_MIN_SAMPLES 100
|
|
|
|
//ignore first x samples of the buffer
|
|
|
|
#define SIGNAL_IGNORE_FIRST_SAMPLES 10
|
|
|
|
|
2015-04-08 13:07:39 +08:00
|
|
|
//generic
|
2017-11-06 22:06:42 +08:00
|
|
|
typedef struct {
|
2019-03-10 02:19:50 +08:00
|
|
|
int low;
|
|
|
|
int high;
|
|
|
|
int mean;
|
|
|
|
int amplitude;
|
|
|
|
bool isnoise;
|
2017-11-06 22:06:42 +08:00
|
|
|
} signal_t;
|
2019-03-10 07:00:59 +08:00
|
|
|
signal_t *getSignalProperties(void);
|
2017-11-06 22:06:42 +08:00
|
|
|
|
2019-03-25 21:57:10 +08:00
|
|
|
void computeSignalProperties(uint8_t *samples, uint32_t size);
|
2019-03-09 02:06:55 +08:00
|
|
|
void removeSignalOffset(uint8_t *samples, uint32_t size);
|
2017-11-10 02:30:29 +08:00
|
|
|
void getNextLow(uint8_t *samples, size_t size, int low, size_t *i);
|
|
|
|
void getNextHigh(uint8_t *samples, size_t size, int high, size_t *i);
|
|
|
|
bool loadWaveCounters(uint8_t *samples, size_t size, int lowToLowWaveLen[], int highToLowWaveLen[], int *waveCnt, int *skip, int *minClk, int *high, int *low);
|
|
|
|
size_t pskFindFirstPhaseShift(uint8_t *samples, size_t size, uint8_t *curPhase, size_t waveStart, uint16_t fc, uint16_t *fullWaveLen);
|
|
|
|
|
2019-04-06 07:00:54 +08:00
|
|
|
size_t addParity(uint8_t *src, uint8_t *dest, uint8_t sourceLen, uint8_t pLen, uint8_t pType);
|
|
|
|
int askdemod(uint8_t *bits, size_t *size, int *clk, int *invert, int maxErr, uint8_t amp, uint8_t askType);
|
|
|
|
int askdemod_ext(uint8_t *bits, size_t *size, int *clk, int *invert, int maxErr, uint8_t amp, uint8_t askType, int *startIdx);
|
|
|
|
void askAmp(uint8_t *bits, size_t size);
|
|
|
|
int BiphaseRawDecode(uint8_t *bits, size_t *size, int *offset, int invert);
|
2019-08-05 01:26:53 +08:00
|
|
|
int bits_to_array(const uint8_t *bits, size_t size, uint8_t *dest);
|
2019-04-06 07:00:54 +08:00
|
|
|
uint32_t bytebits_to_byte(uint8_t *src, size_t numbits);
|
|
|
|
uint32_t bytebits_to_byteLSBF(uint8_t *src, size_t numbits);
|
|
|
|
uint16_t countFC(uint8_t *bits, size_t size, bool fskAdj);
|
|
|
|
int DetectASKClock(uint8_t *dest, size_t size, int *clock, int maxErr);
|
|
|
|
bool DetectCleanAskWave(uint8_t *dest, size_t size, uint8_t high, uint8_t low);
|
|
|
|
uint8_t detectFSKClk(uint8_t *bits, size_t size, uint8_t fcHigh, uint8_t fcLow, int *firstClockEdge);
|
|
|
|
int DetectNRZClock(uint8_t *dest, size_t size, int clock, size_t *clockStartIdx);
|
|
|
|
int DetectPSKClock(uint8_t *dest, size_t size, int clock, size_t *firstPhaseShift, uint8_t *curPhase, uint8_t *fc);
|
|
|
|
int DetectStrongAskClock(uint8_t *dest, size_t size, int high, int low, int *clock);
|
2019-04-14 03:54:04 +08:00
|
|
|
int DetectStrongNRZClk(uint8_t *dest, size_t size, int peak, int low, bool *strong);
|
2019-04-06 07:00:54 +08:00
|
|
|
bool DetectST(uint8_t *buffer, size_t *size, int *foundclock, size_t *ststart, size_t *stend);
|
|
|
|
size_t fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *start_idx);
|
|
|
|
//void getHiLo(uint8_t *bits, size_t size, int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo);
|
|
|
|
void getHiLo(int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo);
|
|
|
|
uint32_t manchesterEncode2Bytes(uint16_t datain);
|
2019-09-15 08:09:40 +08:00
|
|
|
void manchesterEncodeUint32(uint32_t data_in, uint8_t bitlen_in, uint8_t *bits_out, uint16_t *index);
|
2019-04-06 07:00:54 +08:00
|
|
|
int ManchesterEncode(uint8_t *bits, size_t size);
|
2019-05-26 01:27:43 +08:00
|
|
|
uint16_t manrawdecode(uint8_t *bits, size_t *size, uint8_t invert, uint8_t *alignPos);
|
2019-04-06 07:00:54 +08:00
|
|
|
int nrzRawDemod(uint8_t *dest, size_t *size, int *clk, int *invert, int *startIdx);
|
|
|
|
bool parityTest(uint32_t bits, uint8_t bitLen, uint8_t pType);
|
|
|
|
bool preambleSearch(uint8_t *bits, uint8_t *preamble, size_t pLen, size_t *size, size_t *startIdx);
|
|
|
|
bool preambleSearchEx(uint8_t *bits, uint8_t *preamble, size_t pLen, size_t *size, size_t *startIdx, bool findone);
|
|
|
|
int pskRawDemod(uint8_t *dest, size_t *size, int *clock, int *invert);
|
|
|
|
int pskRawDemod_ext(uint8_t *dest, size_t *size, int *clock, int *invert, int *startIdx);
|
|
|
|
void psk2TOpsk1(uint8_t *bits, size_t size);
|
|
|
|
void psk1TOpsk2(uint8_t *bits, size_t size);
|
|
|
|
size_t removeParity(uint8_t *bits, size_t startIdx, uint8_t pLen, uint8_t pType, size_t bLen);
|
2015-04-08 13:07:39 +08:00
|
|
|
|
|
|
|
//tag specific
|
2019-04-06 07:00:54 +08:00
|
|
|
int detectAWID(uint8_t *dest, size_t *size, int *waveStartIdx);
|
|
|
|
int Em410xDecode(uint8_t *bits, size_t *size, size_t *start_idx, uint32_t *hi, uint64_t *lo);
|
|
|
|
int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx);
|
|
|
|
int detectIdteck(uint8_t *dest, size_t *size);
|
|
|
|
int detectIOProx(uint8_t *dest, size_t *size, int *waveStartIdx);
|
2019-08-08 22:57:33 +08:00
|
|
|
|
2014-12-29 09:33:32 +08:00
|
|
|
#endif
|