1

我正在使用 TelosB mote,我们正在尝试从一个 mote 发送两个不同的数据包(字符串),并尝试在另一个 mote 上接收和打印这两个字符串,但在接收端它只接收一个字符串。我无法理解为什么它不打印第二个字符串?这是缓冲区的问题还是其他问题?

#include "contiki.h"
#include "net/rime.h"

#include "dev/button-sensor.h"
//#include "powertrace.h"
#include "dev/leds.h"
#include "net/queuebuf.h"
#include <stdio.h>
#include "net/packetbuf.h"
#define QUEUEBUF_NUM 8

/*---------------------------------------------------------------------------*/
PROCESS(example_unicast_process, "Example unicast");
AUTOSTART_PROCESSES(&example_unicast_process);
/*---------------------------------------------------------------------------*/
static void
recv_uc(struct unicast_conn *c, const rimeaddr_t *from)

{
  static struct queuebuf *queuebuf;
  void queuebuf_init(void);
  queuebuf = queuebuf_new_from_packetbuf();
  queuebuf_to_packetbuf(queuebuf);
  printf("unicast message received from %d.%d: '%s'\n",
     from->u8[0], from->u8[1],(char *)queuebuf_dataptr(void static struct queuebuf *b));

  printf("unicast message received from %d.%d: '%s'\n",
     from->u8[0], from->u8[1],(char *)packetbuf_dataptr());


}
static const struct unicast_callbacks unicast_callbacks = {recv_uc};
static struct unicast_conn uc;
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(example_unicast_process, ev, data)
{
  PROCESS_EXITHANDLER(unicast_close(&uc);)

  PROCESS_BEGIN();
  //powertrace_start(CLOCK_SECOND * 2);
  unicast_open(&uc, 146, &unicast_callbacks);






  while(1) {
    static struct etimer et;
    rimeaddr_t addr;

    etimer_set(&et, CLOCK_SECOND*10);

    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

    packetbuf_copyfrom("Hello", 6);
    addr.u8[0] = 4;
    addr.u8[1] = 0;

      printf("unicast message sent to %d.%d: '%s'\n",
     addr.u8[0], addr.u8[1],(char *)packetbuf_dataptr());

    etimer_set(&et, CLOCK_SECOND*11);

    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

    packetbuf_copyfrom("norway",7);

    addr.u8[0] = 4;
    addr.u8[1] = 0;
   printf("unicast message sent to %d.%d: '%s'\n",
    addr.u8[0], addr.u8[1],(char *)packetbuf_dataptr());

    //leds_toggle(LEDS_BLUE);
    if(!rimeaddr_cmp(&addr, &rimeaddr_node_addr)) {
      unicast_send(&uc, &addr);
    }

  }


  PROCESS_END();
}
4

0 回答 0