]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmddata.c
CHG: generic code clean up. Removal of commented code.
[proxmark3-svn] / client / cmddata.c
index f10d7b536703831b66a1ec85d72b4bb13e8f8b25..38917a33c7793b5e27bdcbf33c9fef0c74b6c3d3 100644 (file)
@@ -234,8 +234,9 @@ int Cmdaskmandemod(const char *Cmd)
     setGraphBuf(BitStream,BitLen); 
     PrintAndLog("EM410x pattern found: ");
     printEM410x(lo);
+    return 1;
   }
-  if (BitLen>16) return 1;
+  //if (BitLen>16) return 1;
   return 0;
 }
 
@@ -328,7 +329,7 @@ int CmdBiphaseDecodeRaw(const char *Cmd)
 //prints binary found and saves in graphbuffer for further commands
 int Cmdaskrawdemod(const char *Cmd)
 {
-  uint32_t i;
+  
   int invert=0; 
   int clk=0; 
   uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
@@ -339,7 +340,7 @@ int Cmdaskrawdemod(const char *Cmd)
   }
   int BitLen = getFromGraphBuf(BitStream);
   int errCnt=0;
-  errCnt = askrawdemod(BitStream, &BitLen,&clk,&invert);
+  errCnt = askrawdemod(BitStream, &BitLen, &clk, &invert);
   if (errCnt==-1){  //throw away static - allow 1 and -1 (in case of threshold command first)
     PrintAndLog("no data found"); 
     return 0;
@@ -348,19 +349,14 @@ int Cmdaskrawdemod(const char *Cmd)
   PrintAndLog("Using Clock: %d - invert: %d - Bits Found: %d",clk,invert,BitLen);
     //PrintAndLog("Data start pos:%d, lastBit:%d, stop pos:%d, numBits:%d",iii,lastBit,i,bitnum);
     //move BitStream back to GraphBuffer
-    
-  ClearGraph(0);
-  for (i=0; i < BitLen; ++i){
-    GraphBuffer[i]=BitStream[i];
-  }
-  GraphTraceLen=BitLen;
-  RepaintGraphWindow();
-    
-    //output
+       setGraphBuf(BitStream, BitLen);
+       
   if (errCnt>0){
     PrintAndLog("# Errors during Demoding (shown as 77 in bit stream): %d",errCnt);
   }
+
   PrintAndLog("ASK demoded bitstream:");
+       
   // Now output the bitstream to the scrollback by line of 16 bits
   printBitStream(BitStream,BitLen);
   
@@ -476,10 +472,6 @@ int CmdBitstream(const char *Cmd)
       bit ^= 1;
 
     AppendGraph(0, clock, bit);
-  //    for (j = 0; j < (int)(clock/2); j++)
-  //      GraphBuffer[(i * clock) + j] = bit ^ 1;
-  //    for (j = (int)(clock/2); j < clock; j++)
-  //      GraphBuffer[(i * clock) + j] = bit;
   }
 
   RepaintGraphWindow();
@@ -509,8 +501,6 @@ int CmdDec(const char *Cmd)
 int CmdDetectClockRate(const char *Cmd)
 {
   GetClock("",0,0);
-  //int clock = DetectASKClock(0);
-  //PrintAndLog("Auto-detected clock rate: %d", clock);
   return 0;
 }
 
@@ -772,8 +762,7 @@ int CmdFSKdemod(const char *Cmd) //old CmdFSKdemod needs updating
   PrintAndLog("actual data bits start at sample %d", maxPos);
   PrintAndLog("length %d/%d", highLen, lowLen);
 
-  uint8_t bits[46];
-  bits[sizeof(bits)-1] = '\0';
+  uint8_t bits[46] = {0x00};
 
   // find bit pairs and manchester decode them
   for (i = 0; i < arraylen(bits) - 1; ++i) {
@@ -880,22 +869,21 @@ int CmdHpf(const char *Cmd)
 
 int CmdSamples(const char *Cmd)
 {
-  int cnt = 0;
-  int n;
-  uint8_t got[40000];
-
-  n = strtol(Cmd, NULL, 0);
-  if (n == 0) n = 6000;
-  if (n > sizeof(got)) n = sizeof(got);
+       uint8_t got[40000] = {0x00};
+
+       int n = strtol(Cmd, NULL, 0);
+       if (n == 0) 
+               n = 20000;
+               
+       if (n > sizeof(got)) 
+               n = sizeof(got);
   
-  PrintAndLog("Reading %d samples\n", n);
+       PrintAndLog("Reading %d samples from device memory\n", n);
   GetFromBigBuf(got,n,0);
   WaitForResponse(CMD_ACK,NULL);
-  for (int j = 0; j < n; j++) {
-    GraphBuffer[cnt++] = ((int)got[j]) - 128;
+       for (int j = 0; j < n; ++j) {
+               GraphBuffer[j] = ((int)got[j]) - 128;
   }
-  
-  PrintAndLog("Done!\n");
   GraphTraceLen = n;
   RepaintGraphWindow();
   return 0;
@@ -952,6 +940,15 @@ int CmdLtrim(const char *Cmd)
   RepaintGraphWindow();
   return 0;
 }
+int CmdRtrim(const char *Cmd)
+{
+  int ds = atoi(Cmd);
+
+  GraphTraceLen = ds;
+
+  RepaintGraphWindow();
+  return 0;
+}
 
 /*
  * Manchester demodulate a bitstream. The bitstream needs to be already in
@@ -1330,8 +1327,8 @@ static command_t CommandTable[] =
   {"help",          CmdHelp,            1, "This help"},
   {"amp",           CmdAmp,             1, "Amplify peaks"},
   {"askdemod",      Cmdaskdemod,        1, "<0 or 1> -- Attempt to demodulate simple ASK tags"},
-  {"askmandemod",   Cmdaskmandemod,     1, "[clock] [invert<0 or 1>] -- Attempt to demodulate ASK/Manchester tags and output binary (args optional[clock will try Auto-detect])"},
-  {"askrawdemod",   Cmdaskrawdemod,     1, "[clock] [invert<0 or 1>] -- Attempt to demodulate ASK tags and output binary (args optional[clock will try Auto-detect])"},
+  {"askmandemod",   Cmdaskmandemod,     1, "[clock] [invert <0|1>] -- Attempt to demodulate ASK/Manchester tags and output binary"},
+  {"askrawdemod",   Cmdaskrawdemod,     1, "[clock] [invert <0|1>] -- Attempt to demodulate ASK tags and output binary"},
   {"autocorr",      CmdAutoCorr,        1, "<window length> -- Autocorrelation over window"},
   {"biphaserawdecode",CmdBiphaseDecodeRaw,1,"[offset] Biphase decode binary stream already in graph buffer (offset = bit to start decode from)"},
   {"bitsamples",    CmdBitsamples,      0, "Get raw samples as bitstring"},
@@ -1342,13 +1339,14 @@ static command_t CommandTable[] =
   {"fskdemod",      CmdFSKdemod,        1, "Demodulate graph window as a HID FSK"},
   {"fskhiddemod",   CmdFSKdemodHID,     1, "Demodulate graph window as a HID FSK using raw"},
   {"fskiodemod",    CmdFSKdemodIO,      1, "Demodulate graph window as an IO Prox FSK using raw"},
-  {"fskrawdemod",   CmdFSKrawdemod,     1, "[clock rate] [invert] Demodulate graph window from FSK to binary (clock = 64 or 50)(invert = 1 or 0)"},
+  {"fskrawdemod",   CmdFSKrawdemod,     1, "[clock rate] [invert] [rchigh] [rclow] Demodulate graph window from FSK to binary (clock = 50)(invert = 1 or 0)(rchigh = 10)(rclow=8)"},
   {"grid",          CmdGrid,            1, "<x> <y> -- overlay grid on graph window, use zero value to turn off either"},
   {"hexsamples",    CmdHexsamples,      0, "<bytes> [<offset>] -- Dump big buffer as hex bytes"},  
   {"hide",          CmdHide,            1, "Hide graph window"},
   {"hpf",           CmdHpf,             1, "Remove DC offset from trace"},
   {"load",          CmdLoad,            1, "<filename> -- Load trace (to graph window"},
   {"ltrim",         CmdLtrim,           1, "<samples> -- Trim samples from left of trace"},
+  {"rtrim",         CmdRtrim,           1, "<location to end trace> -- Trim samples from right of trace"},
   {"mandemod",      CmdManchesterDemod, 1, "[i] [clock rate] -- Manchester demodulate binary stream (option 'i' to invert output)"},
   {"manrawdecode",  Cmdmandecoderaw,    1, "Manchester decode binary stream already in graph buffer"},
   {"manmod",        CmdManchesterMod,   1, "[clock rate] -- Manchester modulate a binary stream"},
Impressum, Datenschutz