|
【Atmel SAM R21创意大赛周计划】+ 6lowpan网络单播/多播测试
[复制链接]
好吧,搞了半个月,终于搞定radio部分驱动,at86rf233的数据手册看了不下3遍,算是基本通了
大家有关于这个radio的问题可以跟帖咨询。
发个图在说话
这是单播的例子,一个发一个收。多播的比较简单,就不发图了。
一些测试代码,凑合看一下吧,也没啥用处,玩contiki的不多
发送端
- /**
- * brief unicast_sender_process
- * note 单播发送处理线程
- * param None
- * retval None
- */
- PROCESS_THREAD(unicast_sender_process, ev, data)
- {
- static struct etimer periodic_timer;
- static struct etimer send_timer;
- uip_ipaddr_t *addr;
-
- PROCESS_BEGIN();
-
- servreg_hack_init();
- set_global_address();
- simple_udp_register(&unicast_connection, UDP_PORT, NULL, UDP_PORT, receiver);
-
- etimer_set(&periodic_timer, SEND_INTERVAL);
- while(1) {
-
- PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
- etimer_reset(&periodic_timer);
- etimer_set(&send_timer, SEND_TIME);
-
- PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer));
- addr = servreg_hack_lookup(SERVICE_ID);
- if (addr != NULL) {
- static unsigned int message_number;
- char buf[20];
-
- printf("Sending unicast to ");
- uip_debug_ipaddr_print(addr);
- printf("\n");
- sprintf(buf, "Message %d", message_number);
- message_number++;
- simple_udp_sendto(&unicast_connection, buf, strlen(buf) + 1, addr);
- } else {
- printf("Service %d not found\n", SERVICE_ID);
- }
- }
-
- PROCESS_END();
- }
复制代码
发送端接收回调
- /**
- * brief receiver
- * note 接收回调函数
- * param None
- * retval None
- */
- static void
- receiver(struct simple_udp_connection *c,
- const uip_ipaddr_t *sender_addr,
- uint16_t sender_port,
- const uip_ipaddr_t *receiver_addr,
- uint16_t receiver_port,
- const uint8_t *data,
- uint16_t datalen)
- {
- printf("Data received on port %d from port %d with length %d\n",
- receiver_port, sender_port, datalen);
-
- printf("Context %s\n", data);
- }
复制代码
接收端
- /**
- * brief unicast_receiver_process
- * note 单播接收处理线程
- * param None
- * retval None
- */
- PROCESS_THREAD(unicast_receiver_process, ev, data)
- {
- uip_ipaddr_t *ipaddr;
-
- PROCESS_BEGIN();
-
- servreg_hack_init();
- ipaddr = set_global_address();
- create_rpl_dag(ipaddr);
- servreg_hack_register(SERVICE_ID, ipaddr);
- simple_udp_register(&unicast_connection, UDP_PORT, NULL, UDP_PORT, receiver);
-
- while(1) {
- PROCESS_WAIT_EVENT();
- }
- PROCESS_END();
- }
复制代码
接收端接收回调
- /**
- * brief receiver
- * note 接收回调函数
- * param None
- * retval None
- */
- static void
- receiver(struct simple_udp_connection *c,
- const uip_ipaddr_t *sender_addr,
- uint16_t sender_port,
- const uip_ipaddr_t *receiver_addr,
- uint16_t receiver_port,
- const uint8_t *data,
- uint16_t datalen)
- {
- printf("Data received from ");
- uip_debug_ipaddr_print(sender_addr);
- printf(" on port %d from port %d with length %d: '%s'\n", receiver_port, sender_port, datalen, data);
- }
复制代码
哎,节点太少了,看来要开始买节点了,路由RPL没法测试,后面有机会一定玩一下RIME目前支持俩种算法AODV啥的,和官网那个llmesh使用的算法类似。
|
赞赏
-
3
查看全部赞赏
-
|