X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/a60612db65bd92709d6807406c52453b0f931ee6..30f2a7d38fd35b2427a7eb42e1cd75fb1105f927:/winsrc/command.cpp diff --git a/winsrc/command.cpp b/winsrc/command.cpp index 43a8e2ac..f947f45c 100644 --- a/winsrc/command.cpp +++ b/winsrc/command.cpp @@ -1598,6 +1598,7 @@ static void Cmdaskdemod(char *str) { * routine, feel free to improve... * * 1st argument: clock rate (as number of samples per clock rate) + * Typical values can be 64, 32, 128... */ static void Cmdmanchesterdemod(char *str) { int i; @@ -1605,18 +1606,23 @@ static void Cmdmanchesterdemod(char *str) { int lastval; int lc = 0; int bitidx = 0; - int bitidx2; + int bit2idx = 0; sscanf(str, "%i", &clock); int tolerance = clock/4; - /* Holds the decoded bitstream. */ - int BitStream[MAX_GRAPH_TRACE_LEN*2]; - int BitStream2[MAX_GRAPH_TRACE_LEN]; + /* Holds the decoded bitstream: each clock period contains 2 bits */ + /* later simplified to 1 bit after manchester decoding. */ + /* Add 10 bits to allow for noisy / uncertain traces without aborting */ + /* int BitStream[GraphTraceLen*2/clock+10]; */ + + /* But it does not work if compiling on WIndows: therefore we just allocate a */ + /* large array */ + int BitStream[MAX_GRAPH_TRACE_LEN]; /* Detect first transition */ - /* Lo-Hi (arbitrary) */ + /* Lo-Hi (arbitrary) */ for(i=1;i (GraphTraceLen*2/clock+8) ) { + PrintToScrollback("Error: the clock you gave is probably wrong, aborting."); + return; + } // Then switch depending on lc length: // Tolerance is 1/4 of clock rate (arbitrary) - if ((lc-clock/2) < tolerance) { - // Short pulse + if (abs(lc-clock/2) < tolerance) { + // Short pulse : either "1" or "0" BitStream[bitidx++]=GraphBuffer[i-1]; - } else if ((lc-clock) < tolerance) { - // Long pulse + } else if (abs(lc-clock) < tolerance) { + // Long pulse: either "11" or "00" BitStream[bitidx++]=GraphBuffer[i-1]; BitStream[bitidx++]=GraphBuffer[i-1]; } else { @@ -1649,39 +1661,41 @@ static void Cmdmanchesterdemod(char *str) { } // At this stage, we now have a bitstream of "01" ("1") or "10" ("0"), parse it into final decoded bitstream - for (bitidx2 = 0; bitidx2255)) { + PrintToScrollback("divisor must be between 19 and 255"); + } else { + SendCommand(&c, FALSE); + PrintToScrollback("Divisor set, expected freq=%dHz", 12000000/(c.ext1+1)); + } +} + +static void CmdSweepLF(char *str) +{ + UsbCommand c; + c.cmd = CMD_SWEEP_LF; + SendCommand(&c, FALSE); +} + + typedef void HandlerFunction(char *cmdline); @@ -1863,6 +1903,8 @@ static struct { "lcdreset", CmdLcdReset, "Hardware reset LCD", "lcd", CmdLcd, "Send command/data to LCD", "test", CmdTest, "Placeholder command for testing new code", + "setlfdivisor", CmdSetDivisor, "Drive LF antenna at 12Mhz/(divisor+1)", + "sweeplf", CmdSweepLF, "Sweep through LF freq range and store results in buffer", "quit", CmdQuit, "quit program" };