Files
bouwhuim.nikhef.nl dee2668a61 newest version WRPC
2013-09-10 08:08:59 +00:00

74 lines
1.6 KiB
C

/*
* Alessandro Rubini for CERN, 2013 -- GNU LGPL v2.1 or later
*/
#include <stdarg.h>
#include <ppsi/ppsi.h>
static char *thing_name[] = {
[pp_dt_fsm] = "diag-fsm",
[pp_dt_time] = "diag-time",
[pp_dt_frames] = "diag-frames",
[pp_dt_servo] = "diag-servo",
[pp_dt_bmc] = "diag-bmc",
[pp_dt_ext] = "diag-extension",
};
void __pp_diag(struct pp_instance *ppi, enum pp_diag_things th,
int level, char *fmt, ...)
{
va_list args;
if (!__PP_DIAG_ALLOW(ppi, th, level))
return;
#ifdef DIAG_PUTS
/*
* We allow to divert diagnostic messages to a different
* channel. This is done in wrpc-sw, for example. There, we
* have a FIFO buffer to this aim. This allows running the
* wrpc shell on the only physical uart we have.
*/
{
static char buf[128];
extern int DIAG_PUTS(const char *s);
pp_sprintf(buf, "%s-%i-%s: ",
thing_name[th], level, ppi->iface_name);
DIAG_PUTS(buf);
va_start(args, fmt);
pp_vsprintf(buf, fmt, args);
va_end(args);
DIAG_PUTS(buf);
}
#else
/* Use the normal output channel for diagnostics */
pp_printf("%s-%i-%s: ", thing_name[th], level, ppi->iface_name);
va_start(args, fmt);
pp_vprintf(fmt, args);
va_end(args);
#endif
}
unsigned long pp_diag_parse(char *diaglevel)
{
unsigned long res = 0;
int i = 28;
#ifdef VERB_LOG_MSGS /* compatible with older way: this enables all */
return ~0xf;
#endif
while (*diaglevel && i >= 4) {
if (*diaglevel < '0' || *diaglevel > '3')
break;
res |= ((*diaglevel - '0') << i);
i -= 4;
diaglevel++;
}
if (*diaglevel)
pp_printf("%s: error parsing \"%s\"\n", __func__, diaglevel);
return res;
}