mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-03-19 11:33:51 +08:00
minor code cleanup
This commit is contained in:
parent
d6d20c5435
commit
c12512e99a
2 changed files with 61 additions and 174 deletions
105
client/graph.c
105
client/graph.c
|
@ -32,7 +32,7 @@ void AppendGraph(int redraw, int clock, int bit)
|
|||
RepaintGraphWindow();
|
||||
}
|
||||
|
||||
/* clear out our graph window */
|
||||
// clear out our graph window
|
||||
int ClearGraph(int redraw)
|
||||
{
|
||||
int gtl = GraphTraceLen;
|
||||
|
@ -44,103 +44,8 @@ int ClearGraph(int redraw)
|
|||
return gtl;
|
||||
}
|
||||
|
||||
/*
|
||||
* Detect clock rate
|
||||
*/
|
||||
//decommissioned - has difficulty detecting rf/32
|
||||
/*
|
||||
int DetectClockOld(int peak)
|
||||
{
|
||||
int i;
|
||||
int clock = 0xFFFF;
|
||||
int lastpeak = 0;
|
||||
// DETECT CLOCK NOW IN LFDEMOD.C
|
||||
|
||||
// Detect peak if we don't have one
|
||||
if (!peak)
|
||||
for (i = 0; i < GraphTraceLen; ++i)
|
||||
if (GraphBuffer[i] > peak)
|
||||
peak = GraphBuffer[i];
|
||||
|
||||
// peak=(int)(peak*.75);
|
||||
for (i = 1; i < GraphTraceLen; ++i)
|
||||
{
|
||||
// If this is the beginning of a peak
|
||||
if (GraphBuffer[i - 1] != GraphBuffer[i] && GraphBuffer[i] >= peak)
|
||||
{
|
||||
// Find lowest difference between peaks
|
||||
if (lastpeak && i - lastpeak < clock)
|
||||
clock = i - lastpeak;
|
||||
lastpeak = i;
|
||||
}
|
||||
}
|
||||
|
||||
return clock;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
NOW IN LFDEMOD.C
|
||||
|
||||
// by marshmellow
|
||||
// not perfect especially with lower clocks or VERY good antennas (heavy wave clipping)
|
||||
// maybe somehow adjust peak trimming value based on samples to fix?
|
||||
int DetectASKClock(int peak)
|
||||
{
|
||||
int i=0;
|
||||
int low=0;
|
||||
int clk[]={16,32,40,50,64,100,128,256};
|
||||
int loopCnt = 256;
|
||||
if (GraphTraceLen<loopCnt) loopCnt = GraphTraceLen;
|
||||
if (!peak){
|
||||
for (i=0;i<loopCnt;++i){
|
||||
if(GraphBuffer[i]>peak){
|
||||
peak = GraphBuffer[i];
|
||||
}
|
||||
if(GraphBuffer[i]<low){
|
||||
low = GraphBuffer[i];
|
||||
}
|
||||
}
|
||||
peak=(int)(peak*.75);
|
||||
low= (int)(low*.75);
|
||||
}
|
||||
int ii;
|
||||
int clkCnt;
|
||||
int tol = 0;
|
||||
int bestErr=1000;
|
||||
int errCnt[]={0,0,0,0,0,0,0,0};
|
||||
for(clkCnt=0; clkCnt<6;++clkCnt){
|
||||
if (clk[clkCnt]==32){
|
||||
tol=1;
|
||||
}else{
|
||||
tol=0;
|
||||
}
|
||||
bestErr=1000;
|
||||
for (ii=0; ii<loopCnt; ++ii){
|
||||
if ((GraphBuffer[ii]>=peak) || (GraphBuffer[ii]<=low)){
|
||||
errCnt[clkCnt]=0;
|
||||
for (i=0; i<((int)(GraphTraceLen/clk[clkCnt])-1); ++i){
|
||||
if (GraphBuffer[ii+(i*clk[clkCnt])]>=peak || GraphBuffer[ii+(i*clk[clkCnt])]<=low){
|
||||
}else if(GraphBuffer[ii+(i*clk[clkCnt])-tol]>=peak || GraphBuffer[ii+(i*clk[clkCnt])-tol]<=low){
|
||||
}else if(GraphBuffer[ii+(i*clk[clkCnt])+tol]>=peak || GraphBuffer[ii+(i*clk[clkCnt])+tol]<=low){
|
||||
}else{ //error no peak detected
|
||||
errCnt[clkCnt]++;
|
||||
}
|
||||
}
|
||||
if(errCnt[clkCnt]==0) return clk[clkCnt];
|
||||
if(errCnt[clkCnt]<bestErr) bestErr=errCnt[clkCnt];
|
||||
}
|
||||
}
|
||||
}
|
||||
int iii=0;
|
||||
int best=0;
|
||||
for (iii=0; iii<6;++iii){
|
||||
if (errCnt[iii]<errCnt[best]){
|
||||
best = iii;
|
||||
}
|
||||
}
|
||||
// PrintAndLog("DEBUG: clkCnt: %d, ii: %d, i: %d peak: %d, low: %d, errcnt: %d, errCnt64: %d",clkCnt,ii,i,peak,low,errCnt[best],errCnt[4]);
|
||||
return clk[best];
|
||||
}
|
||||
*/
|
||||
void setGraphBuf(uint8_t *buff, size_t size)
|
||||
{
|
||||
int i=0;
|
||||
|
@ -162,7 +67,7 @@ size_t getFromGraphBuf(uint8_t *buff)
|
|||
}
|
||||
return i;
|
||||
}
|
||||
/* Get or auto-detect clock rate */
|
||||
// Get or auto-detect clock rate
|
||||
int GetClock(const char *str, int peak, int verbose)
|
||||
{
|
||||
int clock;
|
||||
|
@ -170,13 +75,13 @@ int GetClock(const char *str, int peak, int verbose)
|
|||
if (!strcmp(str, ""))
|
||||
clock = 0;
|
||||
|
||||
/* Auto-detect clock */
|
||||
// Auto-detect clock
|
||||
if (!clock)
|
||||
{
|
||||
uint8_t grph[MAX_GRAPH_TRACE_LEN]={0};
|
||||
size_t size = getFromGraphBuf(grph);
|
||||
clock = DetectASKClock(grph,size,0);
|
||||
/* Only print this message if we're not looping something */
|
||||
// Only print this message if we're not looping something
|
||||
if (!verbose){
|
||||
PrintAndLog("Auto-detected clock rate: %d", clock);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ uint64_t Em410xDecode(uint8_t *BitStream, size_t size)
|
|||
// otherwise could be a void with no arguments
|
||||
//set defaults
|
||||
int high=0, low=128;
|
||||
uint64_t lo=0; //hi=0,
|
||||
uint64_t lo=0;
|
||||
|
||||
uint32_t i = 0;
|
||||
uint32_t initLoopMax = 65;
|
||||
|
@ -48,7 +48,7 @@ uint64_t Em410xDecode(uint8_t *BitStream, size_t size)
|
|||
// search for a start of frame marker
|
||||
if ( memcmp(BitStream+idx, frame_marker_mask, sizeof(frame_marker_mask)) == 0)
|
||||
{ // frame marker found
|
||||
idx+=9;//sizeof(frame_marker_mask);
|
||||
idx+=9;
|
||||
for (i=0; i<10;i++){
|
||||
for(ii=0; ii<5; ++ii){
|
||||
parityTest += BitStream[(i*5)+ii+idx];
|
||||
|
@ -56,7 +56,6 @@ uint64_t Em410xDecode(uint8_t *BitStream, size_t size)
|
|||
if (parityTest== ((parityTest>>1)<<1)){
|
||||
parityTest=0;
|
||||
for (ii=0; ii<4;++ii){
|
||||
//hi = (hi<<1)|(lo>>31);
|
||||
lo=(lo<<1LL)|(BitStream[(i*5)+ii+idx]);
|
||||
}
|
||||
//PrintAndLog("DEBUG: EM parity passed parity val: %d, i:%d, ii:%d,idx:%d, Buffer: %d%d%d%d%d,lo: %d",parityTest,i,ii,idx,BitStream[idx+ii+(i*5)-5],BitStream[idx+ii+(i*5)-4],BitStream[idx+ii+(i*5)-3],BitStream[idx+ii+(i*5)-2],BitStream[idx+ii+(i*5)-1],lo);
|
||||
|
@ -106,8 +105,8 @@ int askmandemod(uint8_t *BinStream, size_t *size, int *clk, int *invert)
|
|||
return -2;
|
||||
}
|
||||
//25% fuzz in case highs and lows aren't clipped [marshmellow]
|
||||
high=(int)((high-128)*.75)+128;
|
||||
low= (int)((low-128)*.75)+128;
|
||||
high=(int)(((high-128)*.75)+128);
|
||||
low= (int)(((low-128)*.75)+128);
|
||||
|
||||
//PrintAndLog("DEBUG - valid high: %d - valid low: %d",high,low);
|
||||
int lastBit = 0; //set first clock check
|
||||
|
@ -306,14 +305,16 @@ int askrawdemod(uint8_t *BinStream, size_t *size, int *clk, int *invert)
|
|||
return -2;
|
||||
}
|
||||
//25% fuzz in case highs and lows aren't clipped [marshmellow]
|
||||
high=(int)((high-128)*.75)+128;
|
||||
low= (int)((low-128)*.75)+128;
|
||||
high=(int)(((high-128)*.75)+128);
|
||||
low= (int)(((low-128)*.75)+128);
|
||||
|
||||
//PrintAndLog("DEBUG - valid high: %d - valid low: %d",high,low);
|
||||
int lastBit = 0; //set first clock check
|
||||
uint32_t bitnum = 0; //output counter
|
||||
uint8_t tol = 0; //clock tolerance adjust - waves will be accepted as within the clock if they fall + or - this value + clock from last valid wave
|
||||
if (*clk==32)tol=1; //clock tolerance may not be needed anymore currently set to + or - 1 but could be increased for poor waves or removed entirely
|
||||
uint8_t tol = 0; //clock tolerance adjust - waves will be accepted as within the clock
|
||||
// if they fall + or - this value + clock from last valid wave
|
||||
if (*clk == 32) tol=1; //clock tolerance may not be needed anymore currently set to
|
||||
// + or - 1 but could be increased for poor waves or removed entirely
|
||||
uint32_t iii = 0;
|
||||
uint32_t gLen = *size;
|
||||
if (gLen > 500) gLen=500;
|
||||
|
@ -366,7 +367,6 @@ int askrawdemod(uint8_t *BinStream, size_t *size, int *clk, int *invert)
|
|||
bitnum++;
|
||||
}
|
||||
|
||||
|
||||
errCnt++;
|
||||
lastBit+=*clk;//skip over until hit too many errors
|
||||
if (errCnt > ((*size/1000))){ //allow 1 error for every 1000 samples else start over
|
||||
|
@ -395,26 +395,10 @@ int askrawdemod(uint8_t *BinStream, size_t *size, int *clk, int *invert)
|
|||
}
|
||||
}
|
||||
if (bitnum>16){
|
||||
|
||||
// PrintAndLog("Data start pos:%d, lastBit:%d, stop pos:%d, numBits:%d",iii,lastBit,i,bitnum);
|
||||
//move BitStream back to BinStream
|
||||
// ClearGraph(0);
|
||||
for (i=0; i < bitnum; ++i){
|
||||
BinStream[i]=BitStream[i];
|
||||
}
|
||||
*size=bitnum;
|
||||
// RepaintGraphWindow();
|
||||
//output
|
||||
// if (errCnt>0){
|
||||
// PrintAndLog("# Errors during Demoding (shown as 77 in bit stream): %d",errCnt);
|
||||
// }
|
||||
// PrintAndLog("ASK decoded bitstream:");
|
||||
// Now output the bitstream to the scrollback by line of 16 bits
|
||||
// printBitStream2(BitStream,bitnum);
|
||||
//int errCnt=0;
|
||||
//errCnt=manrawdemod(BitStream,bitnum);
|
||||
|
||||
// Em410xDecode(Cmd);
|
||||
} else return -1;
|
||||
return errCnt;
|
||||
}
|
||||
|
@ -496,10 +480,8 @@ size_t aggregate_bits(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t maxCons
|
|||
//if lastval was 1, we have a 1->0 crossing
|
||||
if ( dest[idx-1]==1 ) {
|
||||
n=myround2((float)(n+1)/((float)(rfLen)/(float)fclow));
|
||||
//n=(n+1) / h2l_crossing_value;
|
||||
} else {// 0->1 crossing
|
||||
n=myround2((float)(n+1)/((float)(rfLen-2)/(float)fchigh)); //-2 for fudge factor
|
||||
//n=(n+1) / l2h_crossing_value;
|
||||
}
|
||||
if (n == 0) n = 1;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue