New platform: TI cc2530 Development Kit
This commits adds support for TI's SmartRF05 Eval. Board with cc2530 EMs Some initial support for cc2531 USB dongles
This commit is contained in:
parent
b7674c3636
commit
ad256e5014
68 changed files with 6824 additions and 0 deletions
14
examples/cc2530dk/udp-ipv6/Makefile
Normal file
14
examples/cc2530dk/udp-ipv6/Makefile
Normal file
|
@ -0,0 +1,14 @@
|
|||
DEFINES+=PROJECT_CONF_H=\"project-conf.h\"
|
||||
|
||||
HAVE_BANKING=1
|
||||
UIP_CONF_IPV6=1
|
||||
|
||||
PROJECT_SOURCEFILES += ping6.c
|
||||
|
||||
CONTIKI_PROJECT = client server
|
||||
|
||||
all: $(CONTIKI_PROJECT)
|
||||
|
||||
CONTIKI = ../../..
|
||||
|
||||
include $(CONTIKI)/Makefile.include
|
1
examples/cc2530dk/udp-ipv6/Makefile.target
Normal file
1
examples/cc2530dk/udp-ipv6/Makefile.target
Normal file
|
@ -0,0 +1 @@
|
|||
TARGET = cc2530dk
|
159
examples/cc2530dk/udp-ipv6/client.c
Normal file
159
examples/cc2530dk/udp-ipv6/client.c
Normal file
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "contiki-lib.h"
|
||||
#include "contiki-net.h"
|
||||
|
||||
#include <string.h>
|
||||
#include "dev/leds.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "debug.h"
|
||||
|
||||
#define DEBUG DEBUG_PRINT
|
||||
#include "net/uip-debug.h"
|
||||
|
||||
#define SEND_INTERVAL 2 * CLOCK_SECOND
|
||||
#define MAX_PAYLOAD_LEN 40
|
||||
|
||||
static char buf[MAX_PAYLOAD_LEN];
|
||||
|
||||
/* Our destinations and udp conns. One link-local and one global */
|
||||
#define LOCAL_CONN_PORT 3001
|
||||
static struct uip_udp_conn *l_conn;
|
||||
#if UIP_CONF_ROUTER
|
||||
#define GLOBAL_CONN_PORT 3002
|
||||
static struct uip_udp_conn *g_conn;
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(udp_client_process, "UDP client process");
|
||||
#if BUTTON_SENSOR_ON
|
||||
PROCESS_NAME(ping6_process);
|
||||
AUTOSTART_PROCESSES(&udp_client_process, &ping6_process);
|
||||
#else
|
||||
AUTOSTART_PROCESSES(&udp_client_process);
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
tcpip_handler(void)
|
||||
{
|
||||
leds_on(LEDS_GREEN);
|
||||
if(uip_newdata()) {
|
||||
putstring("0x");
|
||||
puthex(uip_datalen());
|
||||
putstring(" bytes response=0x");
|
||||
puthex((*(uint16_t *) uip_appdata) >> 8);
|
||||
puthex((*(uint16_t *) uip_appdata) & 0xFF);
|
||||
putchar('\n');
|
||||
}
|
||||
leds_off(LEDS_GREEN);
|
||||
return;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
timeout_handler(void)
|
||||
{
|
||||
static int seq_id;
|
||||
struct uip_udp_conn * this_conn;
|
||||
|
||||
leds_on(LEDS_RED);
|
||||
memset(buf, 0, MAX_PAYLOAD_LEN);
|
||||
seq_id++;
|
||||
|
||||
/* evens / odds */
|
||||
if(seq_id & 0x01) {
|
||||
this_conn = l_conn;
|
||||
} else {
|
||||
this_conn = g_conn;
|
||||
if(uip_ds6_get_global(ADDR_PREFERRED) == NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
PRINTF("Client to: ");
|
||||
PRINT6ADDR(&this_conn->ripaddr);
|
||||
|
||||
memcpy(buf, &seq_id, sizeof(seq_id));
|
||||
|
||||
PRINTF(" Remote Port %u,", UIP_HTONS(this_conn->rport));
|
||||
PRINTF(" (msg=0x%04x), %u bytes\n", *(uint16_t *) buf, sizeof(seq_id));
|
||||
|
||||
uip_udp_packet_send(this_conn, buf, sizeof(seq_id));
|
||||
leds_off(LEDS_RED);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(udp_client_process, ev, data)
|
||||
{
|
||||
static struct etimer et;
|
||||
uip_ipaddr_t ipaddr;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
PRINTF("UDP client process started\n");
|
||||
|
||||
uip_ip6addr(&ipaddr,0xfe80,0,0,0,0x0215,0x2000,0x0002,0x2145);
|
||||
/* new connection with remote host */
|
||||
l_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL);
|
||||
if(!l_conn) {
|
||||
PRINTF("udp_new l_conn error.\n");
|
||||
}
|
||||
udp_bind(l_conn, UIP_HTONS(LOCAL_CONN_PORT));
|
||||
|
||||
PRINTF("Link-Local connection with ");
|
||||
PRINT6ADDR(&l_conn->ripaddr);
|
||||
PRINTF(" local/remote port %u/%u\n",
|
||||
UIP_HTONS(l_conn->lport), UIP_HTONS(l_conn->rport));
|
||||
|
||||
uip_ip6addr(&ipaddr,0xaaaa,0,0,0,0x0215,0x2000,0x0002,0x2145);
|
||||
g_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL);
|
||||
if(!g_conn) {
|
||||
PRINTF("udp_new g_conn error.\n");
|
||||
}
|
||||
udp_bind(g_conn, UIP_HTONS(GLOBAL_CONN_PORT));
|
||||
|
||||
PRINTF("Global connection with ");
|
||||
PRINT6ADDR(&g_conn->ripaddr);
|
||||
PRINTF(" local/remote port %u/%u\n",
|
||||
UIP_HTONS(g_conn->lport), UIP_HTONS(g_conn->rport));
|
||||
|
||||
etimer_set(&et, SEND_INTERVAL);
|
||||
|
||||
while(1) {
|
||||
PROCESS_YIELD();
|
||||
if(etimer_expired(&et)) {
|
||||
timeout_handler();
|
||||
etimer_restart(&et);
|
||||
} else if(ev == tcpip_event) {
|
||||
tcpip_handler();
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
139
examples/cc2530dk/udp-ipv6/ping6.c
Normal file
139
examples/cc2530dk/udp-ipv6/ping6.c
Normal file
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "contiki-lib.h"
|
||||
#include "contiki-net.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "dev/button-sensor.h"
|
||||
#include "debug.h"
|
||||
|
||||
#define DEBUG 1
|
||||
#if DEBUG
|
||||
#include <stdio.h>
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((u8_t *)addr)[0], ((u8_t *)addr)[1], ((u8_t *)addr)[2], ((u8_t *)addr)[3], ((u8_t *)addr)[4], ((u8_t *)addr)[5], ((u8_t *)addr)[6], ((u8_t *)addr)[7], ((u8_t *)addr)[8], ((u8_t *)addr)[9], ((u8_t *)addr)[10], ((u8_t *)addr)[11], ((u8_t *)addr)[12], ((u8_t *)addr)[13], ((u8_t *)addr)[14], ((u8_t *)addr)[15])
|
||||
#define PRINTLLADDR(lladdr) PRINTF(" %02x:%02x:%02x:%02x:%02x:%02x ",lladdr->addr[0], lladdr->addr[1], lladdr->addr[2], lladdr->addr[3],lladdr->addr[4], lladdr->addr[5])
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#define PRINT6ADDR(addr)
|
||||
#endif
|
||||
|
||||
#define PING6_NB 5
|
||||
#define PING6_DATALEN 16
|
||||
|
||||
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
||||
#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
|
||||
|
||||
static struct etimer ping6_periodic_timer;
|
||||
static u8_t count = 0;
|
||||
static u16_t addr[8];
|
||||
static uip_ipaddr_t dest_addr;
|
||||
|
||||
PROCESS(ping6_process, "PING6 process");
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
ping6handler()
|
||||
{
|
||||
if(count < PING6_NB) {
|
||||
UIP_IP_BUF->vtc = 0x60;
|
||||
UIP_IP_BUF->tcflow = 1;
|
||||
UIP_IP_BUF->flow = 0;
|
||||
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
|
||||
UIP_IP_BUF->ttl = uip_ds6_if.cur_hop_limit;
|
||||
uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &dest_addr);
|
||||
uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr);
|
||||
|
||||
UIP_ICMP_BUF->type = ICMP6_ECHO_REQUEST;
|
||||
UIP_ICMP_BUF->icode = 0;
|
||||
/* set identifier and sequence number to 0 */
|
||||
memset((uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN, 0, 4);
|
||||
/* put one byte of data */
|
||||
memset((uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN + UIP_ICMP6_ECHO_REQUEST_LEN,
|
||||
count, PING6_DATALEN);
|
||||
|
||||
|
||||
uip_len = UIP_ICMPH_LEN + UIP_ICMP6_ECHO_REQUEST_LEN + UIP_IPH_LEN + PING6_DATALEN;
|
||||
UIP_IP_BUF->len[0] = (u8_t)((uip_len - 40) >> 8);
|
||||
UIP_IP_BUF->len[1] = (u8_t)((uip_len - 40) & 0x00FF);
|
||||
|
||||
UIP_ICMP_BUF->icmpchksum = 0;
|
||||
UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
|
||||
|
||||
|
||||
PRINTF("Echo Request to");
|
||||
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
|
||||
PRINTF("from");
|
||||
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
|
||||
PRINTF("\n");
|
||||
UIP_STAT(++uip_stat.icmp.sent);
|
||||
|
||||
tcpip_ipv6_output();
|
||||
|
||||
count++;
|
||||
etimer_set(&ping6_periodic_timer, 3 * CLOCK_SECOND);
|
||||
} else {
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(ping6_process, ev, data)
|
||||
{
|
||||
|
||||
PROCESS_BEGIN();
|
||||
PRINTF("ping6 running.\n");
|
||||
PRINTF("Button 1: 5 pings 16 byte payload.\n");
|
||||
|
||||
uip_ip6addr(&dest_addr,0xaaaa,0,0,0,0x0215,0x2000,0x0002,0x2145);
|
||||
count = 0;
|
||||
|
||||
icmp6_new(NULL);
|
||||
|
||||
while(1) {
|
||||
PROCESS_YIELD();
|
||||
|
||||
#if BUTTON_SENSOR_ON
|
||||
if(ev == sensors_event && data == &button_sensor && count == 0) {
|
||||
ping6handler();
|
||||
}
|
||||
#endif
|
||||
if(ev == PROCESS_EVENT_TIMER && etimer_expired(&ping6_periodic_timer)) {
|
||||
ping6handler();
|
||||
}
|
||||
if(ev == tcpip_icmp6_event && *(uint8_t *)data == ICMP6_ECHO_REPLY) {
|
||||
PRINTF("Echo Reply\n");
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
49
examples/cc2530dk/udp-ipv6/project-conf.h
Normal file
49
examples/cc2530dk/udp-ipv6/project-conf.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Loughborough University - Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Project specific configuration defines for the UDP client/server
|
||||
* example.
|
||||
*
|
||||
* \author
|
||||
* George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#ifndef PROJECT_CONF_H_
|
||||
#define PROJECT_CONF_H_
|
||||
|
||||
#define BUTTON_SENSOR_CONF_ON 1
|
||||
#define UIP_CONF_ICMP6 1
|
||||
|
||||
#endif /* PROJECT_CONF_H_ */
|
174
examples/cc2530dk/udp-ipv6/server.c
Normal file
174
examples/cc2530dk/udp-ipv6/server.c
Normal file
|
@ -0,0 +1,174 @@
|
|||
/*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "contiki-lib.h"
|
||||
#include "contiki-net.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define DEBUG DEBUG_PRINT
|
||||
#include "net/uip-debug.h"
|
||||
#include "dev/watchdog.h"
|
||||
#include "dev/leds.h"
|
||||
#include "net/rpl/rpl.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "debug.h"
|
||||
|
||||
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
||||
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
|
||||
|
||||
#define MAX_PAYLOAD_LEN 120
|
||||
|
||||
static struct uip_udp_conn *server_conn;
|
||||
static char buf[MAX_PAYLOAD_LEN];
|
||||
static uint16_t len;
|
||||
|
||||
#if UIP_CONF_ROUTER
|
||||
static uip_ipaddr_t ipaddr;
|
||||
#endif
|
||||
|
||||
#define SERVER_REPLY 1
|
||||
|
||||
/* Should we act as RPL root? */
|
||||
#define SERVER_RPL_ROOT 1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(udp_server_process, "UDP server process");
|
||||
AUTOSTART_PROCESSES(&udp_server_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
tcpip_handler(void)
|
||||
{
|
||||
memset(buf, 0, MAX_PAYLOAD_LEN);
|
||||
if(uip_newdata()) {
|
||||
leds_on(LEDS_RED);
|
||||
len = uip_datalen();
|
||||
memcpy(buf, uip_appdata, len);
|
||||
PRINTF("%u bytes from [", len, *(uint16_t *)buf);
|
||||
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
|
||||
PRINTF("]:%u\n", UIP_HTONS(UIP_UDP_BUF->srcport));
|
||||
#if SERVER_REPLY
|
||||
uip_ipaddr_copy(&server_conn->ripaddr, &UIP_IP_BUF->srcipaddr);
|
||||
server_conn->rport = UIP_UDP_BUF->srcport;
|
||||
|
||||
uip_udp_packet_send(server_conn, buf, len);
|
||||
/* Restore server connection to allow data from any node */
|
||||
uip_create_unspecified(&server_conn->ripaddr);
|
||||
server_conn->rport = 0;
|
||||
#endif
|
||||
}
|
||||
leds_off(LEDS_RED);
|
||||
return;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if (BUTTON_SENSOR_ON && (DEBUG==DEBUG_PRINT))
|
||||
static void
|
||||
print_stats()
|
||||
{
|
||||
PRINTF("tl=%lu, ts=%lu, bs=%lu, bc=%lu\n",
|
||||
rimestats.toolong, rimestats.tooshort, rimestats.badsynch, rimestats.badcrc);
|
||||
PRINTF("llrx=%lu, lltx=%lu, rx=%lu, tx=%lu\n",
|
||||
rimestats.llrx, rimestats.lltx, rimestats.rx, rimestats.tx);
|
||||
}
|
||||
#else
|
||||
#define print_stats()
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
print_local_addresses(void)
|
||||
{
|
||||
int i;
|
||||
uint8_t state;
|
||||
|
||||
PRINTF("Server IPv6 addresses:\n");
|
||||
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
|
||||
state = uip_ds6_if.addr_list[i].state;
|
||||
if(uip_ds6_if.addr_list[i].isused && (state == ADDR_TENTATIVE || state
|
||||
== ADDR_PREFERRED)) {
|
||||
PRINTF(" ");
|
||||
PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
|
||||
PRINTF("\n");
|
||||
if (state == ADDR_TENTATIVE) {
|
||||
uip_ds6_if.addr_list[i].state = ADDR_PREFERRED;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(udp_server_process, ev, data)
|
||||
{
|
||||
#if BUTTON_SENSOR_ON
|
||||
static struct sensors_sensor *b1;
|
||||
#endif
|
||||
#if SERVER_RPL_ROOT
|
||||
rpl_dag_t *dag;
|
||||
#endif
|
||||
PROCESS_BEGIN();
|
||||
putstring("Starting UDP server\n");
|
||||
|
||||
#if BUTTON_SENSOR_ON
|
||||
putstring("Button 1: Print RIME stats\n");
|
||||
#endif
|
||||
|
||||
#if SERVER_RPL_ROOT
|
||||
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
|
||||
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
||||
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
|
||||
|
||||
print_local_addresses();
|
||||
|
||||
dag = rpl_set_root(RPL_DEFAULT_INSTANCE, &uip_ds6_get_global(ADDR_PREFERRED)->ipaddr);
|
||||
if(dag != NULL) {
|
||||
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
|
||||
rpl_set_prefix(dag, &ipaddr, 64);
|
||||
PRINTF("Created a new RPL dag with ID: ");
|
||||
PRINT6ADDR(&dag->dag_id);
|
||||
PRINTF("\n");
|
||||
}
|
||||
#endif /* SERVER_RPL_ROOT */
|
||||
|
||||
server_conn = udp_new(NULL, UIP_HTONS(0), NULL);
|
||||
udp_bind(server_conn, UIP_HTONS(3000));
|
||||
|
||||
PRINTF("Listen port: 3000, TTL=%u\n", server_conn->ttl);
|
||||
|
||||
while(1) {
|
||||
PROCESS_YIELD();
|
||||
if(ev == tcpip_event) {
|
||||
tcpip_handler();
|
||||
#if BUTTON_SENSOR_ON
|
||||
} else if(ev == sensors_event && data == &button_sensor) {
|
||||
print_stats();
|
||||
#endif /* (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) */
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
Loading…
Add table
Add a link
Reference in a new issue