mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-04 00:45:40 +03:00
more Contiki handling
This commit is contained in:
1 parent
b8c84ba0e4
commit
87dfe421d6
1 file changed
+36
-20
@@ -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
|
||||
|
||||
Reference in new issue
Block a user