This commit is contained in:
Chris 2018-09-09 19:56:25 +02:00
parent fef85d4caa
commit b66a481581
2 changed files with 20 additions and 20 deletions

View file

@ -57,7 +57,6 @@ void save_restoreGB(uint8_t saveOpt) {
return; return;
} }
// DETECT CLOCK NOW IN LFDEMOD.C
void setGraphBuf(uint8_t *buf, size_t size) { void setGraphBuf(uint8_t *buf, size_t size) {
if ( buf == NULL ) return; if ( buf == NULL ) return;
@ -73,6 +72,7 @@ void setGraphBuf(uint8_t *buf, size_t size) {
RepaintGraphWindow(); RepaintGraphWindow();
return; return;
} }
size_t getFromGraphBuf(uint8_t *buf) { size_t getFromGraphBuf(uint8_t *buf) {
if (buf == NULL ) return 0; if (buf == NULL ) return 0;
uint32_t i; uint32_t i;
@ -102,18 +102,18 @@ int GetAskClock(const char *str, bool printAns) {
return clock; return clock;
// Auto-detect clock // Auto-detect clock
uint8_t grph[MAX_GRAPH_TRACE_LEN] = {0}; uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0};
size_t size = getFromGraphBuf(grph); size_t size = getFromGraphBuf(bits);
if (size == 0) { if (size == 0) {
PrintAndLogEx(WARNING, "Failed to copy from graphbuffer"); PrintAndLogEx(WARNING, "Failed to copy from graphbuffer");
return -1; return -1;
} }
//, size_t *ststart, size_t *stend
size_t ststart = 0, stend = 0; size_t ststart = 0, stend = 0;
bool st = DetectST(grph, &size, &clock, &ststart, &stend); bool st = DetectST(bits, &size, &clock, &ststart, &stend);
int start = stend; int start = stend;
if (st == false) { if (st == false) {
start = DetectASKClock(grph, size, &clock, 20); start = DetectASKClock(bits, size, &clock, 20);
} }
setClockGrid(clock, start); setClockGrid(clock, start);
// Only print this message if we're not looping something // Only print this message if we're not looping something
@ -125,13 +125,13 @@ int GetAskClock(const char *str, bool printAns) {
uint8_t GetPskCarrier(const char *str, bool printAns) { uint8_t GetPskCarrier(const char *str, bool printAns) {
uint8_t carrier = 0; uint8_t carrier = 0;
uint8_t grph[MAX_GRAPH_TRACE_LEN] = {0}; uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0};
size_t size = getFromGraphBuf(grph); size_t size = getFromGraphBuf(bits);
if ( size == 0 ) { if ( size == 0 ) {
PrintAndLogEx(WARNING, "Failed to copy from graphbuffer"); PrintAndLogEx(WARNING, "Failed to copy from graphbuffer");
return 0; return 0;
} }
uint16_t fc = countFC(grph, size, 0); uint16_t fc = countFC(bits, size, false);
carrier = fc & 0xFF; carrier = fc & 0xFF;
if (carrier != 2 && carrier != 4 && carrier != 8) return 0; if (carrier != 2 && carrier != 4 && carrier != 8) return 0;
if (( fc >> 8) == 10 && carrier == 8) return 0; if (( fc >> 8) == 10 && carrier == 8) return 0;
@ -194,12 +194,13 @@ int GetFskClock(const char* str, bool printAns) {
uint8_t fc1 = 0, fc2 = 0, rf1 = 0; uint8_t fc1 = 0, fc2 = 0, rf1 = 0;
int firstClockEdge = 0; int firstClockEdge = 0;
int ans = fskClocks(&fc1, &fc2, &rf1, &firstClockEdge);
if (ans == 0) if ( !fskClocks(&fc1, &fc2, &rf1, &firstClockEdge))
return 0; return 0;
if ((fc1==10 && fc2==8) || (fc1==8 && fc2==5)){ if ((fc1==10 && fc2==8) || (fc1==8 && fc2==5)){
if (printAns) PrintAndLogEx(NORMAL, "Detected Field Clocks: FC/%d, FC/%d - Bit Clock: RF/%d", fc1, fc2, rf1); if (printAns)
PrintAndLogEx(NORMAL, "Detected Field Clocks: FC/%d, FC/%d - Bit Clock: RF/%d", fc1, fc2, rf1);
setClockGrid(rf1, firstClockEdge); setClockGrid(rf1, firstClockEdge);
return rf1; return rf1;
} }
@ -208,26 +209,25 @@ int GetFskClock(const char* str, bool printAns) {
PrintAndLogEx(DEBUG, "Detected Field Clocks: FC/%d, FC/%d - Bit Clock: RF/%d", fc1, fc2, rf1); PrintAndLogEx(DEBUG, "Detected Field Clocks: FC/%d, FC/%d - Bit Clock: RF/%d", fc1, fc2, rf1);
return 0; return 0;
} }
int fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, int *firstClockEdge) { bool fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, int *firstClockEdge) {
uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0}; uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0};
size_t size = getFromGraphBuf(bits); size_t size = getFromGraphBuf(bits);
if (size == 0) if (size == 0)
return 0; return false;
uint16_t ans = countFC(bits, size, 1); uint16_t ans = countFC(bits, size, true);
if (ans == 0) { if (ans == 0) {
PrintAndLogEx(DEBUG, "DEBUG: No data found"); PrintAndLogEx(DEBUG, "DEBUG: No data found");
return 0; return false;
} }
*fc1 = (ans >> 8) & 0xFF; *fc1 = (ans >> 8) & 0xFF;
*fc2 = ans & 0xFF; *fc2 = ans & 0xFF;
//int firstClockEdge = 0;
*rf1 = detectFSKClk(bits, size, *fc1, *fc2, firstClockEdge); *rf1 = detectFSKClk(bits, size, *fc1, *fc2, firstClockEdge);
if (*rf1 == 0) { if (*rf1 == 0) {
PrintAndLogEx(DEBUG, "DEBUG: Clock detect error"); PrintAndLogEx(DEBUG, "DEBUG: Clock detect error");
return 0; return false;
} }
return 1; return true;
} }

View file

@ -26,7 +26,7 @@ int GetPskClock(const char *str, bool printAns);
uint8_t GetPskCarrier(const char *str, bool printAns); uint8_t GetPskCarrier(const char *str, bool printAns);
int GetNrzClock(const char *str, bool printAns); int GetNrzClock(const char *str, bool printAns);
int GetFskClock(const char *str, bool printAns); int GetFskClock(const char *str, bool printAns);
int fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, int *firstClockEdge); bool fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, int *firstClockEdge);
void setGraphBuf(uint8_t *buff, size_t size); void setGraphBuf(uint8_t *buff, size_t size);
void save_restoreGB(uint8_t saveOpt); void save_restoreGB(uint8_t saveOpt);