drivers/xbee: how to send packets without shell

Hi,

The Xbee driver test uses the shell to send packets. Because I don’t need the shell, what’s the correct code to send data through the Xbee?

I try this:


char data[] = " hello";
size_t addr_len = 8;
uint8_t addr[8]={0x00, 0x13, 0xa2, 0x00, 0x40, 0xc4, 0x36, 0x57};
ng_pktsnip_t *pkt;
ng_netif_hdr_t *nethdr;
pkt = ng_pktbuf_add(NULL,(char *)data, strlen(data), NG_NETTYPE_UNDEF);
pkt = ng_pktbuf_add(pkt, NULL, sizeof(ng_netif_hdr_t) + addr_len,
NG_NETTYPE_NETIF);
nethdr = (ng_netif_hdr_t *)pkt->data;
ng_netif_hdr_init(nethdr, 0, addr_len);
ng_netif_hdr_set_dst_addr(nethdr, addr, addr_len);
ng_netapi_send( dev.mac_pid, pkt);

But It don’t works.

Thanks, Francesco

Hey Francesco, Though you don’t use the shell to send packets you can use the implementation as an example. It can be found in sys/shell/commands/sc_netif.c. This should work:

char data[] = "hello"
size_t addr_len = 8;
uint8_t addr[8]={0x00, 0x13, 0xa2, 0x00, 0x40, 0xc4, 0x36, 0x57};

ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, data, sizeof(data), NG_NETTYPE_UNDEF);

ng_pktsnip_t *hdr = ng_netif_hdr_build(NULL, 0, addr, addr_len);
LL_PREPEND(pkt, hdr);
ng_netapi_send(dev.mac_pid, pkt);

I’m not sure how the addressing is working in the Xbee driver (since I know that pairings like short source/long destination are not possible with the Xbee device), so since the source is configured to be used with short addresses it might be not working with long addresses. So if it is not working, try again with either short destination address or after configuring the source configured to be used as long:

uint16_t src_len = 8;

ng_netapi_set(dev.mac_pid, NETCONF_OPT_SRC_LEN, 0, &src_len, sizeof(src_len));