-
- return fcs;
-}
-
-//by marshmellow
-//countPSK_FC is to detect the psk carrier clock length.
-//counts and returns the 1 most common wave length
-uint8_t countPSK_FC(uint8_t *BitStream, size_t size)
-{
- uint8_t fcLens[] = {0,0,0,0,0,0,0,0,0,0};
- uint16_t fcCnts[] = {0,0,0,0,0,0,0,0,0,0};
- uint8_t fcLensFnd = 0;
- uint32_t fcCounter = 0;
- size_t i;
- if (size == 0) return 0;
-
- // prime i to first up transition
- for (i = 1; i < size-1; i++)
- if (BitStream[i] > BitStream[i-1] && BitStream[i] >= BitStream[i+1])
- break;
-
- for (; i < size-1; i++){
- if (BitStream[i] > BitStream[i-1] && BitStream[i] >= BitStream[i+1]){
- // new up transition
- fcCounter++;
-
- // save last field clock count (fc/xx)
- // find which fcLens to save it to:
- for (int ii=0; ii<10; ii++){
- if (fcLens[ii]==fcCounter){
- fcCnts[ii]++;
- fcCounter=0;
- break;
- }
- }
- if (fcCounter>0 && fcLensFnd<10){
- //add new fc length
- fcCnts[fcLensFnd]++;
- fcLens[fcLensFnd++]=fcCounter;
- }
- fcCounter=0;
- } else {
- // count sample
- fcCounter++;
- }
- }
-
- uint8_t best1=9;
- uint16_t maxCnt1=0;
- // go through fclens and find which ones are bigest
- for (i=0; i<10; i++){
- //PrintAndLog("DEBUG: FC %d, Cnt %d",fcLens[i],fcCnts[i]);
- // get the best FC value
- if (fcCnts[i]>maxCnt1) {
- maxCnt1=fcCnts[i];
- best1=i;
- }
- }
- return fcLens[best1];