for (; i < size; i++){
DemodBuffer[i]=buff[startIdx++];
}
- DemodBufferLen=size;
- return;
+ DemodBufferLen = size;
}
int CmdSetDebugMode(const char *Cmd)
int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo )
{
size_t idx = 0;
- size_t BitLen = DemodBufferLen;
+ size_t size = DemodBufferLen;
uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
- memcpy(BitStream, DemodBuffer, BitLen);
- if (Em410xDecode(BitStream, &BitLen, &idx, hi, lo)){
- //set GraphBuffer for clone or sim command
- setDemodBuf(BitStream, BitLen, idx);
+ memcpy(BitStream, DemodBuffer, size);
+ int ans = Em410xDecode(BitStream, &size, &idx, hi, lo);
+ if ( ans < 0){
if (g_debugMode){
- PrintAndLog("DEBUG: idx: %d, Len: %d, Printing Demod Buffer:", idx, BitLen);
- printDemodBuff();
- }
- if (verbose){
- PrintAndLog("EM410x pattern found: ");
- printEM410x(*hi, *lo);
+
+ if (ans == -1)
+ PrintAndLog("DEBUG: Error - Em410x not only 0|1 in decoded bitstream");
+ else if (ans == -3)
+ PrintAndLog("DEBUG: Error - Em410x Size not correct: %d", size);
+ else if (ans == -4)
+ PrintAndLog("DEBUG: Error - Em410x preamble not found");
+ else if (ans == -5)
+ PrintAndLog("DEBUG: Error - Em410x parity failed");
}
- return 1;
+ return 0;
}
- return 0;
+
+ //set GraphBuffer for clone or sim command
+ setDemodBuf(BitStream, size, idx);
+ if (g_debugMode){
+ PrintAndLog("DEBUG: idx: %d, Len: %d, Printing Demod Buffer:", idx, size);
+ printDemodBuff();
+ }
+ if (verbose){
+ PrintAndLog("EM410x pattern found: ");
+ printEM410x(*hi, *lo);
+ }
+ return 1;
}
int AskEm410xDemod(const char *Cmd, uint32_t *hi, uint64_t *lo, bool verbose)
//shift graph zero up or down based on input + or -
int CmdGraphShiftZero(const char *Cmd)
{
- int shift=0;
+ int shift = 0, shiftedVal = 0;
//set options from parameters entered with the command
sscanf(Cmd, "%i", &shift);
- int shiftedVal=0;
+
for(int i = 0; i<GraphTraceLen; i++){
shiftedVal=GraphBuffer[i]+shift;
- if (shiftedVal>127)
- shiftedVal=127;
- else if (shiftedVal<-127)
- shiftedVal=-127;
- GraphBuffer[i]= shiftedVal;
+ if (shiftedVal > 127)
+ shiftedVal = 127;
+ else if (shiftedVal < -127)
+ shiftedVal = -127;
+ GraphBuffer[i] = shiftedVal;
}
CmdNorm("");
return 0;
PrintAndLog("Error1: %d",ans);
return 0;
}
- uint8_t invert=0;
+
+ uint8_t invert = 0;
size_t size = DemodBufferLen;
int startIdx = indala26decode(DemodBuffer, &size, &invert);
if (startIdx < 0 || size > 224) {
int CmdPSKNexWatch(const char *Cmd)
{
if (!PSKDemod("", false)) return 0;
+
uint8_t preamble[28] = {0,0,0,0,0,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
size_t startIdx = 0, size = DemodBufferLen;
+
+ // sanity check.
+ if ( size < sizeof(preamble) + 100) return 0;
+
bool invert = false;
if (!preambleSearch(DemodBuffer, preamble, sizeof(preamble), &size, &startIdx)){
// if didn't find preamble try again inverting
if (!PSKDemod("1", false)) return 0;
+
size = DemodBufferLen;
if (!preambleSearch(DemodBuffer, preamble, sizeof(preamble), &size, &startIdx)) return 0;
invert = true;
if (g_debugMode) PrintAndLog("Error demoding: %d",ans);
return 0;
}
-
PrintAndLog("PSK1 demoded bitstream:");
// Now output the bitstream to the scrollback by line of 16 bits
printDemodBuff();
// takes same args as cmdpsk1rawdemod
int CmdPSK2rawDemod(const char *Cmd)
{
- int ans=0;
+ int ans = 0;
char cmdp = param_getchar(Cmd, 0);
if (strlen(Cmd) > 10 || cmdp == 'h' || cmdp == 'H')
return usage_data_rawdemod_p2();
- ans=PSKDemod(Cmd, TRUE);
+ ans = PSKDemod(Cmd, TRUE);
if (!ans){
if (g_debugMode) PrintAndLog("Error demoding: %d",ans);
return 0;
peakf = resp.arg[2] & 0xffff;
peakv = resp.arg[2] >> 16;
PrintAndLog("");
- PrintAndLog("# LF antenna: %5.2f V @ 125.00 kHz", vLf125/1000.0);
- PrintAndLog("# LF antenna: %5.2f V @ 134.00 kHz", vLf134/1000.0);
- PrintAndLog("# LF optimal: %5.2f V @%9.2f kHz", peakv/1000.0, 12000.0/(peakf+1));
- PrintAndLog("# HF antenna: %5.2f V @ 13.56 MHz", vHf/1000.0);
+ if ( vLf125 > 0 )
+ PrintAndLog("# LF antenna: %5.2f V @ 125.00 kHz", vLf125/1000.0);
+ if ( vLf134 > 0 )
+ PrintAndLog("# LF antenna: %5.2f V @ 134.00 kHz", vLf134/1000.0);
+ if ( peakv > 0 && peakf > 0 )
+ PrintAndLog("# LF optimal: %5.2f V @%9.2f kHz", peakv/1000.0, 12000.0/(peakf+1));
+ if ( vHf > 0 )
+ PrintAndLog("# HF antenna: %5.2f V @ 13.56 MHz", vHf/1000.0);
#define LF_UNUSABLE_V 2948 // was 2000. Changed due to bugfix in voltage measurements. LF results are now 47% higher.
#define LF_MARGINAL_V 14739 // was 10000. Changed due to bugfix bug in voltage measurements. LF results are now 47% higher.
GraphBuffer[GraphTraceLen] = atoi(line);
GraphTraceLen++;
}
- fclose(f);
+ if (f) {
+ fclose(f);
+ f = NULL;
+ }
PrintAndLog("loaded %d samples", GraphTraceLen);
RepaintGraphWindow();
return 0;
for (i = 0; i < GraphTraceLen; i++) {
fprintf(f, "%d\n", GraphBuffer[i]);
}
- fclose(f);
+ if (f) {
+ fclose(f);
+ f = NULL;
+ }
PrintAndLog("saved to '%s'", Cmd);
return 0;
}