Skip to content

Commit

Permalink
xbee: enriched debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonezawa-T2 committed Mar 14, 2016
1 parent a9ce1e8 commit 468f30b
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions drivers/xbee/xbee.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ static uint8_t _cksum(uint8_t *buf, size_t size)

static void _at_cmd(xbee_t *dev, const char *cmd)
{
DEBUG("xbee: AT_CMD: %s", cmd);
DEBUG("xbee: AT_CMD: %s\n", cmd);

uart_write(dev->uart, (uint8_t *)cmd, strlen(cmd));
}

static void _api_at_cmd(xbee_t *dev, uint8_t *cmd, uint8_t size, resp_t *resp)
{
DEBUG("xbee: AT_CMD: %s\n", cmd);

/* acquire TX lock */
mutex_lock(&(dev->tx_lock));
/* construct API frame */
Expand Down Expand Up @@ -561,6 +563,7 @@ static int _send(gnrc_netdev_t *netdev, gnrc_pktsnip_t *pkt)
dev->tx_buf[4] = 0; /* set to zero to disable response frame */
/* set size, API id and address field depending on dst address length */
if (_is_broadcast(hdr)) {
DEBUG("xbee: sending broadcast");
dev->tx_buf[1] = (uint8_t)((size + 5) >> 8);
dev->tx_buf[2] = (uint8_t)(size + 5);
dev->tx_buf[3] = API_ID_TX_SHORT_ADDR;
Expand All @@ -569,24 +572,44 @@ static int _send(gnrc_netdev_t *netdev, gnrc_pktsnip_t *pkt)
pos = 7;
}
else if (hdr->dst_l2addr_len == 2) {
uint8_t *destination = gnrc_netif_hdr_get_dst_addr(hdr);

DEBUG("xbee: sending unicast to %02x:%02x",
(uint8_t) destination[0], (uint8_t) destination[1]);

dev->tx_buf[1] = (uint8_t)((size + 5) >> 8);
dev->tx_buf[2] = (uint8_t)(size + 5);
dev->tx_buf[3] = API_ID_TX_SHORT_ADDR;
memcpy(dev->tx_buf + 5, gnrc_netif_hdr_get_dst_addr(hdr), 2);
memcpy(dev->tx_buf + 5, destination, 2);
pos = 7;
}
else {
uint8_t *destination = gnrc_netif_hdr_get_dst_addr(hdr);

DEBUG("xbee: sending unicast to %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
(uint8_t) destination[0], (uint8_t) destination[1],
(uint8_t) destination[2], (uint8_t) destination[3],
(uint8_t) destination[4], (uint8_t) destination[5],
(uint8_t) destination[6], (uint8_t) destination[7]);

dev->tx_buf[1] = (uint8_t)((size + 11) >> 8);
dev->tx_buf[2] = (uint8_t)(size + 11);
dev->tx_buf[3] = API_ID_TX_LONG_ADDR;
memcpy(dev->tx_buf + 5, gnrc_netif_hdr_get_dst_addr(hdr), 8);
memcpy(dev->tx_buf + 5, destination, 8);
pos = 13;
}
/* set options */
DEBUG(", option: %02x", dev->options);
dev->tx_buf[pos++] = dev->options;
/* copy payload */
DEBUG(", payload:");
payload = pkt->next;
while (payload) {
#if ENABLE_DEBUG
for (size_t i = 0; i < payload->size; i++) {
DEBUG(" %02x", ((uint8_t *) payload->data)[i]);
}
#endif
memcpy(&(dev->tx_buf[pos]), payload->data, payload->size);
pos += payload->size;
payload = payload->next;
Expand All @@ -600,6 +623,7 @@ static int _send(gnrc_netdev_t *netdev, gnrc_pktsnip_t *pkt)
/* release TX lock */
mutex_unlock(&(dev->tx_lock));
/* return number of payload byte */
DEBUG("\n");
return (int)size;
}

Expand Down Expand Up @@ -792,6 +816,22 @@ static void _isr_event(gnrc_netdev_t *netdev, uint32_t event_type)
return;
}

#if ENABLE_DEBUG
DEBUG("xbee: received packet from");
for (size_t i = 0; i < addr_len; i++) {
DEBUG(" %02x", (uint8_t) gnrc_netif_hdr_get_src_addr(hdr)[i]);
}

DEBUG(", RSSI: -%d dBm", hdr->rssi);
DEBUG(", options: %02x", (uint8_t) dev->rx_buf[1 + addr_len + 1]); // API ID + source address + RSSI
DEBUG(", payload:");

for (size_t i = 0; i < pkt->size; i++) {
DEBUG(" %02x", ((uint8_t *) pkt->data)[i]);
}
DEBUG("\n");
#endif

/* pass on the received packet */
dev->event_cb(NETDEV_EVENT_RX_COMPLETE, pkt);
/* reset RX byte counter to enable receiving of the next packet */
Expand Down

0 comments on commit 468f30b

Please sign in to comment.