diff --git a/winsrc/command.cpp b/winsrc/command.cpp index 4b18d0a7a..a02803db0 100644 --- a/winsrc/command.cpp +++ b/winsrc/command.cpp @@ -1622,15 +1622,24 @@ static void Cmdaskdemod(char *str) { * Typical values can be 64, 32, 128... */ static void Cmdmanchesterdemod(char *str) { - int i; + int i, j; + int bit; int clock; int lastval; + int low = 0; + int high = 0; + int hithigh, hitlow, first; int lc = 0; int bitidx = 0; int bit2idx = 0; - + int warnings = 0; sscanf(str, "%i", &clock); + if (!clock) + { + PrintToScrollback("You must provide a clock rate."); + return; + } int tolerance = clock/4; /* Holds the decoded bitstream: each clock period contains 2 bits */ @@ -1642,21 +1651,77 @@ static void Cmdmanchesterdemod(char *str) { /* large array */ int BitStream[MAX_GRAPH_TRACE_LEN]; + /* Detect high and lows */ + for (i = 0; i < GraphTraceLen; i++) + { + if (GraphBuffer[i] > high) + high = GraphBuffer[i]; + else if (GraphBuffer[i] < low) + low = GraphBuffer[i]; + } + /* Detect first transition */ /* Lo-Hi (arbitrary) */ - for(i=1;i 100) + { + PrintToScrollback("Error: too many detection errors, aborting."); + return; + } } } } @@ -1693,11 +1765,20 @@ static void Cmdmanchesterdemod(char *str) { // We cannot end up in this state, this means we are unsynchronized, // move up 1 bit: i++; + warnings++; PrintToScrollback("Unsynchronized, resync..."); PrintToScrollback("(too many of those messages mean the stream is not Manchester encoded)"); + + if (warnings > 100) + { + PrintToScrollback("Error: too many decode errors, aborting."); + return; + } } } - PrintToScrollback("Manchester decoded bitstream \n---------"); + } + + PrintToScrollback("Manchester decoded bitstream"); // Now output the bitstream to the scrollback by line of 16 bits for (i = 0; i < (bit2idx-16); i+=16) { PrintToScrollback("%i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i",