]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
create Dbprintf convenience function
authorbushing <bushing@ef4ab9da-24cd-11de-8aaa-f3a34680c41f>
Fri, 1 Jan 2010 23:36:17 +0000 (23:36 +0000)
committerbushing <bushing@ef4ab9da-24cd-11de-8aaa-f3a34680c41f>
Fri, 1 Jan 2010 23:36:17 +0000 (23:36 +0000)
armsrc/appmain.c
armsrc/apps.h
armsrc/lfops.c

index 11047b1cbdc75820e41ef104c1b3ab7447da05bd..8d6c1812f08a522e1a0a811725f2af8fc340d160 100644 (file)
 #include "LCD.h"\r
 #endif\r
 \r
+#define va_list __builtin_va_list\r
+#define va_start __builtin_va_start\r
+#define va_arg __builtin_va_arg\r
+#define va_end __builtin_va_end\r
+int kvsprintf(char const *fmt, void *arg, int radix, va_list ap);\r
+       \r
 //=============================================================================\r
 // A buffer where we can queue things up to be sent through the FPGA, for\r
 // any purpose (fake tag, as reader, whatever). We go MSB first, since that\r
@@ -94,6 +100,18 @@ void DbpIntegers(int x1, int x2, int x3)
        SpinDelay(50);\r
 }\r
 \r
+void Dbprintf(const char *fmt, ...) {\r
+// should probably limit size here; oh well, let's just use a big buffer\r
+       char output_string[128];\r
+       va_list ap;\r
+\r
+       va_start(ap, fmt);\r
+       kvsprintf(fmt, output_string, 10, ap);\r
+       va_end(ap);\r
\r
+       DbpString(output_string);\r
+}\r
+\r
 //-----------------------------------------------------------------------------\r
 // Read an ADC channel and block till it completes, then return the result\r
 // in ADC units (0 to 1023). Also a routine to average 32 samples and\r
index fba62365b9678484207de769f796f537e059aab4..b15ae6ad5c55cb7bcc85dcda7f846474f5947e24 100644 (file)
@@ -21,6 +21,8 @@ void __attribute__((noreturn)) AppMain(void);
 void SamyRun(void);\r
 void DbpIntegers(int a, int b, int c);\r
 void DbpString(char *str);\r
+void Dbprintf(const char *fmt, ...);\r
+\r
 void ToSendStuffBit(int b);\r
 void ToSendReset(void);\r
 void ListenReaderField(int limit);\r
index eeaa5782948173f2cf6af575551d4915e1dc2b11..7ba0ad130918333fd314391e6206884cb92d9199 100644 (file)
@@ -39,7 +39,6 @@ void DoAcquisition125k(void)
        BYTE *dest = (BYTE *)BigBuf;\r
        int n = sizeof(BigBuf);\r
        int i;\r
-       char output_string[64];\r
        \r
        memset(dest, 0, n);\r
        i = 0;\r
@@ -55,9 +54,7 @@ void DoAcquisition125k(void)
                        if (i >= n) break;\r
                }\r
        }\r
-       sprintf(output_string, "read samples, dest[0]=%x dest[1]=%x",\r
-               dest[0], dest[1]);\r
-       DbpString(output_string);\r
+       Dbprintf("read samples, dest[0]=%x dest[1]=%x", dest[0], dest[1]);\r
 }\r
 \r
 void ModThenAcquireRawAdcSamples125k(int delay_off, int period_0, int period_1, BYTE *command)\r
@@ -251,13 +248,10 @@ void ReadTItag(void)
                crc = update_crc16(crc, (shift1>>16)&0xff);\r
                crc = update_crc16(crc, (shift1>>24)&0xff);\r
 \r
-               char output_string[64];\r
-               sprintf(output_string, "Info: Tag data_hi=%x, data_lo=%x, crc=%x",\r
+               Dbprintf("Info: Tag data_hi=%x, data_lo=%x, crc=%x",\r
                        (unsigned int)shift1, (unsigned int)shift0, (unsigned int)shift2 & 0xFFFF);\r
-               DbpString(output_string);\r
                if (crc != (shift2&0xffff)) {\r
-                       sprintf(output_string, "Error: CRC mismatch, expected %x", (unsigned int)crc);\r
-                       DbpString(output_string);\r
+                       Dbprintf("Error: CRC mismatch, expected %x", (unsigned int)crc);\r
                } else {\r
                        DbpString("Info: CRC is good");\r
                }\r
@@ -380,10 +374,8 @@ void WriteTItag(DWORD idhi, DWORD idlo, WORD crc)
                crc = update_crc16(crc, (idhi>>16)&0xff);\r
                crc = update_crc16(crc, (idhi>>24)&0xff);\r
        }\r
-       char output_string[64];\r
-       sprintf(output_string, "Writing the following data to tag: %x, %x, %x",\r
+       Dbprintf("Writing the following data to tag: %x, %x, %x",\r
                (unsigned int) idhi, (unsigned int) idlo, crc);\r
-       DbpString(output_string);\r
 \r
        // TI tags charge at 134.2Khz\r
        FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz\r
@@ -927,10 +919,8 @@ void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol)
                                found=1;\r
                                idx+=6;\r
                                if (found && (hi|lo)) {\r
-                                       char output_string[64];\r
-                                       sprintf(output_string, "TAG ID: %x %x %x", \r
+                                       Dbprintf("TAG ID: %x %x %x", \r
                                                (unsigned int) hi, (unsigned int) lo, (unsigned int) (lo>>1) & 0xFFFF);\r
-                                       DbpString(output_string);\r
                                        /* if we're only looking for one tag */\r
                                        if (findone)\r
                                        {\r
@@ -962,10 +952,8 @@ void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol)
                                found=1;\r
                                idx+=6;\r
                                if (found && (hi|lo)) {\r
-                                       char output_string[64];\r
-                                       sprintf(output_string, "TAG ID: %x %x %x", \r
+                                       Dbprintf("TAG ID: %x %x %x", \r
                                                (unsigned int) hi, (unsigned int) lo, (unsigned int) (lo>>1) & 0xFFFF);\r
-                                       DbpString(output_string);\r
                                        /* if we're only looking for one tag */\r
                                        if (findone)\r
                                        {\r
Impressum, Datenschutz