Beispiel #1
0
void vLog
(
    const char *fmt,    ///< printf style format specified
    va_list     args    ///< variable list of arguments
)
{
    // For now we call printf directly. A better way would be to install
    // a callback which does the real work

#if CFG_LOG_ALLOW_DEFERRED_NL
    if ( gDeferredNewline && ( *fmt != '\r' ))
    {
        gDeferredNewline = 0;
        Log( "\r\n" );
    }
#endif

#if defined( AVR )
#   if CFG_LOG_USE_STDIO
    if ( gLogFs != NULL )
    {
        vfprintf_P( gLogFs, fmt, args );
    }
#elif CFG_LOG_USE_USB_DEBUG
    vStrXPrintf_P( LogToUsbDebugFunc, NULL, fmt, args );
#   else
    vStrXPrintf_P( LogToUartFunc, NULL, fmt, args );
#   endif
#else
    if ( gLogFunc != NULL )
    {
        gLogFunc( LOG_LEVEL_NORMAL, fmt, args );
    }
#endif
}
Beispiel #2
0
void vLog
(
    const char *fmt,    ///< printf style format specified
    va_list     args    ///< variable list of arguments
)
{
    // For now we call printf directly. A better way would be to install
    // a callback which does the real work

#if defined( AVR )
#   if CFG_LOG_USE_STDIO
    if ( gLogFs != NULL )
    {
        vfprintf_P( gLogFs, fmt, args );
    }
#   else
    vStrXPrintf_P( LogToUartFunc, NULL, fmt, args );
#   endif
#else
    if ( gLogFunc != NULL )
    {
        gLogFunc( LOG_LEVEL_NORMAL, fmt, args );
    }
#endif
}
Beispiel #3
0
int uart_vprintf_P(const char *fmt, va_list ap) {
    int count;
    acquire(&uart_lock);
    count = vfprintf_P(&uartio, fmt, ap);
    release(&uart_lock);

    return count;
}
Beispiel #4
0
void hci_dump_log_P(int log_level, PGM_P format, ...){
    if (!hci_dump_log_level_active(log_level)) return;
    va_list argptr;
    va_start(argptr, format);
    printf_P(PSTR("LOG -- "));
    vfprintf_P(stdout, format, argptr);
    printf_P(PSTR("\n"));
    va_end(argptr);
}
Beispiel #5
0
void do_csp_debug(csp_debug_level_t level, const char * format, ...) {

	int color = COLOR_RESET;
	va_list args;

	/* Don't print anything if log level is disabled */
	if (level > CSP_LOCK || !levels_enable[level])
		return;

	switch(level) {
	case CSP_INFO:
		color = COLOR_GREEN | COLOR_BOLD;
		break;
	case CSP_ERROR:
		color = COLOR_RED | COLOR_BOLD;
		break;
	case CSP_WARN:
		color = COLOR_YELLOW | COLOR_BOLD;
		break;
	case CSP_BUFFER:
		color = COLOR_MAGENTA;
		break;
	case CSP_PACKET:
		color = COLOR_GREEN;
		break;
	case CSP_PROTOCOL:
		color = COLOR_BLUE;
		break;
	case CSP_LOCK:
		color = COLOR_CYAN;
		break;
	default:
		return;
	}
	
	va_start(args, format);

	/* If csp_debug_hook symbol is defined, pass on the message.
	 * Otherwise, just print with pretty colors ... */
	if (csp_debug_hook_func) {
		char buf[250];
		vsnprintf(buf, 250, format, args);
		csp_debug_hook_func(level, buf);
	} else {
		csp_sys_set_color(color);
#ifdef __AVR__
		vfprintf_P(stdout, format, args);
#else
		vprintf(format, args);
#endif
		csp_sys_set_color(COLOR_RESET);
	}

	va_end(args);

}
Beispiel #6
0
int16_t Print::printf(const __FlashStringHelper *format, ...)
{
	FILE f;
	va_list ap;

	fdev_setup_stream(&f, printf_putchar, NULL, _FDEV_SETUP_WRITE);
	fdev_set_udata(&f, this);
	va_start(ap, format);
	return vfprintf_P(&f, (const char *)format, ap);
}
Beispiel #7
0
/*!
 * \brief Print formatted output to the standard output stream.
 *
 * Similar to printf() except that the format string is located in
 * program memory.
 *
 * \param fmt    Format string in program space containing conversion 
 *               specifications.
 *
 * \return The number of characters written or a negative value to
 *         indicate an error.
 *
 * \warning Do not use this function with a debug device while running 
 *          in interrupt context.
 */
int printf_P(PGM_P fmt, ...)
{
    int rc;
    va_list ap;

    va_start(ap, fmt);
    rc = vfprintf_P(stdout, fmt, ap);
    va_end(ap);

    return rc;
}
Beispiel #8
0
void trace(const prog_char* p_file, uint16_t p_line, const prog_char* p_fmt, ...)
{
	fprintf_P(stdout, PSTR("[TRACE] %S:%d: "), p_file, p_line);
	
	va_list vlist;
	va_start(vlist, p_fmt);
	vfprintf_P(stdout, p_fmt, vlist);
	va_end(vlist);
	
	fprintf_P(stdout, PSTR("\n"));
}
Beispiel #9
0
void halt(const prog_char* p_file, uint16_t p_line, const prog_char* p_fmt, ...)
{
	fprintf_P(stdout, PSTR("ASSERT FAILED at %S:%d: "), p_file, p_line);
	
	va_list vlist;
	va_start(vlist, p_fmt);
	vfprintf_P(stdout, p_fmt, vlist);
	va_end(vlist);
	
	fprintf_P(stdout, PSTR("\n"));
	for (;;) {}
}
Beispiel #10
0
int rprintfRamRom(unsigned char stringInRom, const char *format, ...){
	int rtn;
	va_list args;
	va_start (args, format);
	if(stringInRom == STRING_IN_ROM){
		rtn=vfprintf_P(&io, format, args);
	}else{
		rtn=vfprintf(&io, format, args);
	}
	va_end (args);
	return rtn;
}
int
BetterStream::printf_P(const char *fmt, ...)
{
    va_list ap;
    int     i;

    va_start(ap, fmt);
    i = vfprintf_P(&fd, fmt, ap);
    va_end(ap);

    return(i);
}
Beispiel #12
0
PUBLIC int printf_P(const char *fmt, ...)
{
    int i;
#ifdef __EVENTS__
    if(BermudaEventWait((volatile THREAD**)USART0->mutex, 500) == -1) {
        i = -1;
        goto out;
    }
#endif

    va_list va;
    va_start(va, fmt);
    vfprintf_P(stdout, fmt, va);
    va_end(va);

#ifdef __EVENTS__
    BermudaEventSignal((volatile THREAD**)USART0->mutex);
out:
#endif

    return i;
}
Beispiel #13
0
void log_event(struct error * e, ...)
{
  PGM_P txt_sev;
  uint16_t flags;
  va_list ap;
  time_h tv;

  if( e->severity > log_level)
    return;

  // save flags
  flags = stdout->flags;

  va_start(ap, e);
  tv = time_get_time();
  
  // print timestamp
  printf_P(PSTR("%ld.%3.3ld | "), tv.s, (tv.us/1000UL));
  
  // print severity
  switch(e->severity)
  {
    case ERROR_SEVERITY_EMERG :   txt_sev = PSTR(ERROR_SEVTEXT_EMERG);   break;
    case ERROR_SEVERITY_ERROR :   txt_sev = PSTR(ERROR_SEVTEXT_ERROR);   break;
    case ERROR_SEVERITY_WARNING : txt_sev = PSTR(ERROR_SEVTEXT_WARNING); break;
    case ERROR_SEVERITY_NOTICE :  txt_sev = PSTR(ERROR_SEVTEXT_NOTICE);  break;
    case ERROR_SEVERITY_DEBUG :   txt_sev = PSTR(ERROR_SEVTEXT_DEBUG);   break;
    default :                     txt_sev = PSTR("XXX");                 break;
  }

  printf_P(txt_sev);
  printf_P(PSTR(": "));

  // print message
  vfprintf_P(stdout,e->text,ap);

  printf_P(PSTR("\n"));

  va_end(ap);

  // restore flags
  stdout->flags = flags;


  // dead end
  if( (e->severity == ERROR_SEVERITY_ERROR)
    ||(e->severity == ERROR_SEVERITY_EMERG) )
  {
    printf_P(PSTR("\nprogram stopped, strike a key other than 'x' to reset\n"));
    
#if 0  //TODO:temp
    //XXX Add shutdown procedures here XXX
    
    // breaking motors
    motor_cs_break(1);

    // killing cs & position tasks
    scheduler_del_event(event_cs);
  
    // wait for key
    uint8_t key;
    while(1)
    {
      key = cli_getkey();

      if( (key == -1)||(key == 'x'))
        continue;
      
      break;
    }
#endif
    uart_recv(1);

    // reset MCU 
    reset();
  }

}