From 87dfe421d6a9d20246b2b30a4d0819159ed5a0ca Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Fri, 23 Dec 2011 17:19:11 +0100 Subject: [PATCH] more Contiki handling --- debug.c | 56 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/debug.c b/debug.c index bbf60ba7..3b025962 100644 --- a/debug.c +++ b/debug.c @@ -217,21 +217,14 @@ coap_print_addr(const struct __coap_address_t *addr, unsigned char *buf, size_t #endif } +#ifndef WITH_CONTIKI void coap_show_pdu(const coap_pdu_t *pdu) { -#ifndef WITH_CONTIKI unsigned char buf[COAP_MAX_PDU_SIZE]; /* need some space for output creation */ fprintf(COAP_DEBUG_FD, "v:%d t:%d oc:%d c:%d id:%u", pdu->hdr->version, pdu->hdr->type, pdu->hdr->optcnt, pdu->hdr->code, ntohs(pdu->hdr->id)); -#else /* WITH_CONTIKI */ - unsigned char buf[80]; /* need some space for output creation */ - - PRINTF("v:%d t:%d oc:%d c:%d id:%u", - pdu->hdr->version, pdu->hdr->type, - pdu->hdr->optcnt, pdu->hdr->code, uip_ntohs(pdu->hdr->id)); -#endif /* WITH_CONTIKI */ /* show options, if any */ if (pdu->hdr->optcnt) { @@ -244,11 +237,7 @@ coap_show_pdu(const coap_pdu_t *pdu) { if (print_readable(COAP_OPT_VALUE(opt_iter.option), COAP_OPT_LENGTH(opt_iter.option), buf, sizeof(buf), 0 )) -#ifndef WITH_CONTIKI fprintf(COAP_DEBUG_FD, " %d:%s", opt_iter.type, buf); -#else /* WITH_CONTIKI */ - PRINTF(" %d:%s", opt_iter.type, buf); -#endif /* WITH_CONTIKI */ } } @@ -256,20 +245,47 @@ coap_show_pdu(const coap_pdu_t *pdu) { print_readable(pdu->data, (unsigned char *)pdu->hdr + pdu->length - pdu->data, buf, sizeof(buf), 0 ); -#ifndef WITH_CONTIKI fprintf(COAP_DEBUG_FD, " d:%s", buf); -#else /* WITH_CONTIKI */ - PRINTF(" d:%s", buf); -#endif /* WITH_CONTIKI */ } -#ifndef WITH_CONTIKI fprintf(COAP_DEBUG_FD, "\n"); fflush(COAP_DEBUG_FD); -#else /* WITH_CONTIKI */ - PRINTF("\r\n"); -#endif /* WITH_CONTIKI */ } +#else /* WITH_CONTIKI */ + +void +coap_show_pdu(const coap_pdu_t *pdu) { + unsigned char buf[80]; /* need some space for output creation */ + + PRINTF("v:%d t:%d oc:%d c:%d id:%u", + pdu->hdr->version, pdu->hdr->type, + pdu->hdr->optcnt, pdu->hdr->code, uip_ntohs(pdu->hdr->id)); + + /* show options, if any */ + if (pdu->hdr->optcnt) { + coap_opt_iterator_t opt_iter; + coap_option_iterator_init((coap_pdu_t *)pdu, &opt_iter, COAP_OPT_ALL); + + PRINTF(" o:"); + while (coap_option_next(&opt_iter)) { + + if (print_readable(COAP_OPT_VALUE(opt_iter.option), + COAP_OPT_LENGTH(opt_iter.option), + buf, sizeof(buf), 0 )) + PRINTF(" %d:%s", opt_iter.type, buf); + } + } + + if (pdu->data < (unsigned char *)pdu->hdr + pdu->length) { + print_readable(pdu->data, + (unsigned char *)pdu->hdr + pdu->length - pdu->data, + buf, sizeof(buf), 0 ); + PRINTF(" d:%s", buf); + } + PRINTF("\r\n"); +} +#endif /* WITH_CONTIKI */ + #endif /* NDEBUG */ #ifndef WITH_CONTIKI