在 Contiki 中,我需要有两个文件,发送方和接收方,发送方将数据包发送到接收方。我的问题是,接收器没有输出已收到数据包。
我在接收数据包中尝试了一个while循环,我什至尝试创建一个函数,但仍然没有任何效果。
我的 sender.c 文件
#include "contiki.h"
#include "net/rime.h"
#include "random.h"
#include "dev/button-sensor.h"
#include "dev/leds.h"
#include <stdio.h>
PROCESS(sendReceive, "Hello There");
AUTOSTART_PROCESSES(&sendReceive);
PROCESS_THREAD(sendReceive, ev, data)
{
PROCESS_BEGIN();
static struct abc_conn abc;
static struct etimer et;
static const struct abc_callbacks abc_call;
PROCESS_EXITHANDLER(abc_close(&abc);)
abc_open(&abc, 128, &abc_call);
while(1)
{
/* Delay 2-4 seconds */
etimer_set(&et, CLOCK_SECOND * 2 + random_rand() % (CLOCK_SECOND * 2));
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
packetbuf_copyfrom("Hello", 6);
abc_send(&abc);
printf("Message sent\n");
}
PROCESS_END();
}
我的receiver.c 文件
#include "contiki.h"
#include "net/rime.h"
#include "random.h"
#include "dev/button-sensor.h"
#include "dev/leds.h"
#include <stdio.h>
PROCESS(sendReceive, "Receiving Message");
AUTOSTART_PROCESSES(&sendReceive);
PROCESS_THREAD(sendReceive, ev, data)
{
PROCESS_BEGIN();
{
printf("Message received '%s'\n", (char *)packetbuf_dataptr());
}
PROCESS_END();
}
sender.c 文件正在工作,它正在正确发送数据包,问题是接收器似乎没有输出它已被接收。