예제 #1
0
// DebugPrintf - really trivial implementation, however, it's reentrant!
// ToDo - This needs a rewrite! Add code to check we're not overflowing.
// ============================================================================
void vDebugPrintf(const char *fmt, ...) {
	char sTmp[80];	// String build area.  String lives on the stack!
	uint8_t pos=0;
	char *bp = (char *)fmt;
    va_list ap;
    char c;
    char *p;
    int i;

    va_start(ap, fmt);

    while ((c = *bp++)) {
        if (c != '%') {
            sTmp[pos++] = c;
            continue;
        }

        switch ((c = *bp++)) {
			// d - decimal value
			case 'd':
				vNum2String( sTmp, &pos, va_arg(ap, uint32_t), 10);
				break;

			// %x - value in hex
			case 'x':
				sTmp[pos++] = '0';
				sTmp[pos++] = 'x';
				vNum2String( sTmp, &pos, va_arg(ap, uint32_t), 16);
				break;

			// %b - binary
			case 'b':
				sTmp[pos++] = '0';
				sTmp[pos++] = 'b';
				vNum2String( sTmp, &pos, va_arg(ap, uint32_t), 2);
				break;

			// %c - character
			case 'c':
				sTmp[pos++] = va_arg(ap, int);
				break;

			// %i - integer
			case 'i':
				i = va_arg(ap, int32_t);
				if(i < 0){
					sTmp[pos++] = '-';
					vNum2String( sTmp, &pos, (~i)+1, 10);
				} else {
					vNum2String( sTmp, &pos, i, 10);
				}
				break;

			// %s - string
			case 's':
				p = va_arg(ap, char *);
				do {
					sTmp[pos++] = *p++;
				} while (*p);
				break;

			// %% - output % character
			case '%':
				sTmp[pos++] = '%';
				break;

			// Else, must be something else not handled.
			default:
				sTmp[pos++] = '?';
				break;
        }
    }
    sTmp[pos++] = 0;		// Mark the end of the string.
    vDebugString( sTmp );	// Copy the string into the OS queue.
    return;
}
예제 #2
0
파일: debug.c 프로젝트: clkv5/Quadrotor
// TODO - check for overflows
void vDebugPrintf(const char *fmt, ...) {
    
/*----------------------------------------------------------
Local variables
----------------------------------------------------------*/
char sTmp[ 80 ];
uint8_t pos=0;
char *bp = (char *)fmt;
va_list ap;
char c;
char *p;
int i;

va_start(ap, fmt);
    
/*----------------------------------------------------------
Parse all given parameters
----------------------------------------------------------*/
while ( ( c = *bp++ ) )
    {
    if (c != '%')
        {
        sTmp[pos++] = c;
        continue;
        }

    switch ((c = *bp++))
        {
        /* d - decimal value */
        case 'd':
            vNum2String( sTmp, &pos, va_arg( ap, uint32_t), 10 );
            break;

        /* %x - value in hex */
        case 'x':
            sTmp[pos++] = '0';
            sTmp[pos++] = 'x';
            vNum2String( sTmp, &pos, va_arg( ap, uint32_t), 16 );
            break;

        /* %b - binary */
        case 'b':
            sTmp[pos++] = '0';
            sTmp[pos++] = 'b';
            vNum2String( sTmp, &pos, va_arg( ap, uint32_t), 2 );
            break;

        /* %c - character */
        case 'c':
            sTmp[pos++] = va_arg( ap, int );
            break;

        /* %i - integer */
        case 'i':
            i = va_arg( ap, int32_t );
            if(i < 0){
                sTmp[pos++] = '-';
                vNum2String( sTmp, &pos, (~i)+1, 10);
            } else {
                vNum2String( sTmp, &pos, i, 10);
            }
            break;

        /* %s - string */
        case 's':
            p = va_arg(ap, char *);
            do {
                sTmp[pos++] = *p++;
            } while (*p);
            break;

        /* %% - output % character */
        case '%':
            sTmp[pos++] = '%';
            break;

        /* Else, must be something else not handled. */
        default:
            sTmp[pos++] = '?';
            break;
        }
    }
    
/*----------------------------------------------------------
Mark end of string and copy into OS queue
----------------------------------------------------------*/
sTmp[pos++] = 0;
vDebugString( sTmp );
return;

}