-//by marshmellow
-//takes 4 arguments - clock, invert, maxErr as integers and amplify as char
-//attempts to demodulate ask only
-//prints binary found and saves in graphbuffer for further commands
-int ASKrawDemod(const char *Cmd, bool verbose)
-{
- int invert=0;
- int clk=0;
- int maxErr=100;
- uint8_t askAmp = 0;
- char amp = param_getchar(Cmd, 0);
- uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
- sscanf(Cmd, "%i %i %i %c", &clk, &invert, &maxErr, &);
- if (invert != 0 && invert != 1) {
- if (verbose || g_debugMode) PrintAndLog("Invalid argument: %s", Cmd);
- return 0;
- }
- if (clk==1){
- invert=1;
- clk=0;
- }
- if (amp == 'a' || amp == 'A') askAmp=1;
- size_t BitLen = getFromGraphBuf(BitStream);
- if (BitLen==0) return 0;
- int errCnt = askrawdemod(BitStream, &BitLen, &clk, &invert, maxErr, askAmp);
- if (errCnt==-1||BitLen<16){ //throw away static - allow 1 and -1 (in case of threshold command first)
- if (verbose || g_debugMode) PrintAndLog("no data found");
- if (g_debugMode) PrintAndLog("errCnt: %d, BitLen: %d, clk: %d, invert: %d", errCnt, BitLen, clk, invert);
- return 0;
- }
- if (errCnt>maxErr) {
- if (g_debugMode)
- PrintAndLog("Too many errors found, errCnt: %d, BitLen: %d, clk: %d, invert: %d", errCnt, BitLen, clk, invert);
- return 0;
- }
- if (verbose || g_debugMode)
- PrintAndLog("Using Clock: %d - invert: %d - Bits Found: %d", clk, invert, BitLen);
-
- //move BitStream back to DemodBuffer
- setDemodBuf(BitStream,BitLen,0);
-
- //output
- if (errCnt>0 && (verbose || g_debugMode)){
- PrintAndLog("# Errors during Demoding (shown as 7 in bit stream): %d", errCnt);
- }
- if (verbose || g_debugMode){
- PrintAndLog("ASK demoded bitstream:");
- // Now output the bitstream to the scrollback by line of 16 bits
- printDemodBuff();
- }
- return 1;
-}
-