mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-22 10:30:13 +00:00
minor cleanup of example (changed to use uiplib to parse IPv6 address)
This commit is contained in:
parent
7887559d56
commit
351325b7f4
@ -33,17 +33,8 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define DEBUG 1
|
#define DEBUG DEBUG_PRINT
|
||||||
#if DEBUG
|
#include "net/uip-debug.h"
|
||||||
#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)
|
|
||||||
#define PRINTLLADDR(addr)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define SEND_INTERVAL 15 * CLOCK_SECOND
|
#define SEND_INTERVAL 15 * CLOCK_SECOND
|
||||||
#define MAX_PAYLOAD_LEN 40
|
#define MAX_PAYLOAD_LEN 40
|
||||||
@ -114,15 +105,17 @@ set_global_address(void)
|
|||||||
static void
|
static void
|
||||||
set_connection_address(uip_ipaddr_t *ipaddr)
|
set_connection_address(uip_ipaddr_t *ipaddr)
|
||||||
{
|
{
|
||||||
#ifdef UDP_ADDR_A
|
#define _QUOTEME(x) #x
|
||||||
uip_ip6addr(ipaddr,
|
#define QUOTEME(x) _QUOTEME(x)
|
||||||
UDP_ADDR_A,UDP_ADDR_B,UDP_ADDR_C,UDP_ADDR_D,
|
#ifdef UDP_CONNECTION_ADDR
|
||||||
UDP_ADDR_E,UDP_ADDR_F,UDP_ADDR_G,UDP_ADDR_H);
|
if(uiplib_ipaddrconv(QUOTEME(UDP_CONNECTION_ADDR), ipaddr) == 0) {
|
||||||
|
PRINTF("UDP client failed to parse address '%s'\n", QUOTEME(UDP_CONNECTION_ADDR));
|
||||||
|
}
|
||||||
#elif UIP_CONF_ROUTER
|
#elif UIP_CONF_ROUTER
|
||||||
uip_ip6addr(ipaddr,0xaaaa,0,0,0,0x0212,0x7404,0x0004,0x0404);
|
uip_ip6addr(ipaddr,0xaaaa,0,0,0,0x0212,0x7404,0x0004,0x0404);
|
||||||
#else
|
#else
|
||||||
uip_ip6addr(ipaddr,0xfe80,0,0,0,0x6466,0x6666,0x6666,0x6666);
|
uip_ip6addr(ipaddr,0xfe80,0,0,0,0x6466,0x6666,0x6666,0x6666);
|
||||||
#endif /* UDP_ADDR_A */
|
#endif /* UDP_CONNECTION_ADDR */
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
PROCESS_THREAD(udp_client_process, ev, data)
|
PROCESS_THREAD(udp_client_process, ev, data)
|
||||||
@ -147,7 +140,7 @@ PROCESS_THREAD(udp_client_process, ev, data)
|
|||||||
|
|
||||||
PRINTF("Created a connection with the server ");
|
PRINTF("Created a connection with the server ");
|
||||||
PRINT6ADDR(&client_conn->ripaddr);
|
PRINT6ADDR(&client_conn->ripaddr);
|
||||||
PRINTF("local/remote port %u/%u\n",
|
PRINTF(" local/remote port %u/%u\n",
|
||||||
HTONS(client_conn->lport), HTONS(client_conn->rport));
|
HTONS(client_conn->lport), HTONS(client_conn->rport));
|
||||||
|
|
||||||
etimer_set(&et, SEND_INTERVAL);
|
etimer_set(&et, SEND_INTERVAL);
|
||||||
|
@ -33,17 +33,8 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define DEBUG 1
|
#define DEBUG DEBUG_PRINT
|
||||||
#if DEBUG
|
#include "net/uip-debug.h"
|
||||||
#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)
|
|
||||||
#define PRINTLLADDR(addr)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
||||||
|
|
||||||
@ -114,11 +105,6 @@ PROCESS_THREAD(udp_server_process, ev, data)
|
|||||||
server_conn = udp_new(NULL, HTONS(3001), NULL);
|
server_conn = udp_new(NULL, HTONS(3001), NULL);
|
||||||
udp_bind(server_conn, HTONS(3000));
|
udp_bind(server_conn, HTONS(3000));
|
||||||
|
|
||||||
PRINTF("Created a server connection with remote address ");
|
|
||||||
PRINT6ADDR(&server_conn->ripaddr);
|
|
||||||
PRINTF("local/remote port %u/%u\n", HTONS(server_conn->lport),
|
|
||||||
HTONS(server_conn->rport));
|
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
PROCESS_YIELD();
|
PROCESS_YIELD();
|
||||||
if(ev == tcpip_event) {
|
if(ev == tcpip_event) {
|
||||||
|
@ -24,7 +24,8 @@
|
|||||||
<identifier>mtype783</identifier>
|
<identifier>mtype783</identifier>
|
||||||
<description>Receiver</description>
|
<description>Receiver</description>
|
||||||
<contikiapp>[CONTIKI_DIR]/examples/udp-ipv6/udp-server.c</contikiapp>
|
<contikiapp>[CONTIKI_DIR]/examples/udp-ipv6/udp-server.c</contikiapp>
|
||||||
<commands>make udp-server.cooja TARGET=cooja DEFINES=UDP_ADDR_A=0xfe80,UDP_ADDR_B=0,UDP_ADDR_C=0,UDP_ADDR_D=0,UDP_ADDR_E=0x2,UDP_ADDR_F=0x2ff,UDP_ADDR_G=0xfe02,UDP_ADDR_H=0x0202</commands>
|
<commands>make TARGET=cooja clean
|
||||||
|
make udp-server.cooja TARGET=cooja</commands>
|
||||||
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
|
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
|
||||||
<moteinterface>se.sics.cooja.interfaces.Battery</moteinterface>
|
<moteinterface>se.sics.cooja.interfaces.Battery</moteinterface>
|
||||||
<moteinterface>se.sics.cooja.contikimote.interfaces.ContikiVib</moteinterface>
|
<moteinterface>se.sics.cooja.contikimote.interfaces.ContikiVib</moteinterface>
|
||||||
@ -48,7 +49,7 @@
|
|||||||
<identifier>mtype512</identifier>
|
<identifier>mtype512</identifier>
|
||||||
<description>Sender</description>
|
<description>Sender</description>
|
||||||
<contikiapp>[CONTIKI_DIR]/examples/udp-ipv6/udp-client.c</contikiapp>
|
<contikiapp>[CONTIKI_DIR]/examples/udp-ipv6/udp-client.c</contikiapp>
|
||||||
<commands>make udp-client.cooja TARGET=cooja DEFINES=UDP_ADDR_A=0xfe80,UDP_ADDR_B=0,UDP_ADDR_C=0,UDP_ADDR_D=0,UDP_ADDR_E=0x301,UDP_ADDR_F=0x1ff,UDP_ADDR_G=0xfe01,UDP_ADDR_H=0x101</commands>
|
<commands>make udp-client.cooja TARGET=cooja DEFINES=UDP_CONNECTION_ADDR=fe80::301:1ff:fe01:101</commands>
|
||||||
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
|
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
|
||||||
<moteinterface>se.sics.cooja.interfaces.Battery</moteinterface>
|
<moteinterface>se.sics.cooja.interfaces.Battery</moteinterface>
|
||||||
<moteinterface>se.sics.cooja.contikimote.interfaces.ContikiVib</moteinterface>
|
<moteinterface>se.sics.cooja.contikimote.interfaces.ContikiVib</moteinterface>
|
||||||
@ -146,12 +147,6 @@
|
|||||||
se.sics.cooja.plugins.ScriptRunner
|
se.sics.cooja.plugins.ScriptRunner
|
||||||
<plugin_config>
|
<plugin_config>
|
||||||
<script>TIMEOUT(100000, log.log("last msg: " + msg + "\n")); /* print last msg at timeout */
|
<script>TIMEOUT(100000, log.log("last msg: " + msg + "\n")); /* print last msg at timeout */
|
||||||
|
|
||||||
WAIT_UNTIL(msg.contains("Created a server connection"));
|
|
||||||
YIELD_THEN_WAIT_UNTIL(msg.contains("Created a connection"));
|
|
||||||
|
|
||||||
log.log("Both nodes booted\n");
|
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
while (count++ < 5) {
|
while (count++ < 5) {
|
||||||
/* Message from sender process to receiver process */
|
/* Message from sender process to receiver process */
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mrm</project>
|
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mrm</project>
|
||||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mspsim</project>
|
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mspsim</project>
|
||||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/avrora</project>
|
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/avrora</project>
|
||||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mobility</project>
|
|
||||||
<simulation>
|
<simulation>
|
||||||
<title>My simulation</title>
|
<title>My simulation</title>
|
||||||
<delaytime>0</delaytime>
|
<delaytime>0</delaytime>
|
||||||
@ -25,7 +24,7 @@
|
|||||||
<description>Sky Mote Type #1</description>
|
<description>Sky Mote Type #1</description>
|
||||||
<source EXPORT="discard">[CONTIKI_DIR]/examples/udp-ipv6/udp-client.c</source>
|
<source EXPORT="discard">[CONTIKI_DIR]/examples/udp-ipv6/udp-client.c</source>
|
||||||
<commands EXPORT="discard">make clean TARGET=sky
|
<commands EXPORT="discard">make clean TARGET=sky
|
||||||
make udp-client.sky TARGET=sky DEFINES=WITH_UIP6,UDP_ADDR_A=0xfe80,UDP_ADDR_B=0,UDP_ADDR_C=0,UDP_ADDR_D=0,UDP_ADDR_E=0x0212,UDP_ADDR_F=0x7402,UDP_ADDR_G=0x02,UDP_ADDR_H=0x202</commands>
|
make udp-client.sky TARGET=sky DEFINES=UDP_CONNECTION_ADDR=fe80::212:7402:2:202</commands>
|
||||||
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/udp-ipv6/udp-client.sky</firmware>
|
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/udp-ipv6/udp-client.sky</firmware>
|
||||||
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
|
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
|
||||||
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
|
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
|
||||||
@ -43,8 +42,7 @@ make udp-client.sky TARGET=sky DEFINES=WITH_UIP6,UDP_ADDR_A=0xfe80,UDP_ADDR_B=0,
|
|||||||
<identifier>sky2</identifier>
|
<identifier>sky2</identifier>
|
||||||
<description>Sky Mote Type #2</description>
|
<description>Sky Mote Type #2</description>
|
||||||
<source EXPORT="discard">[CONTIKI_DIR]/examples/udp-ipv6/udp-server.c</source>
|
<source EXPORT="discard">[CONTIKI_DIR]/examples/udp-ipv6/udp-server.c</source>
|
||||||
<commands EXPORT="discard">make clean TARGET=sky
|
<commands EXPORT="discard">make udp-server.sky TARGET=sky</commands>
|
||||||
make udp-server.sky TARGET=sky DEFINES=WITH_UIP6,UDP_ADDR_A=0xfe80,UDP_ADDR_B=0,UDP_ADDR_C=0,UDP_ADDR_D=0,UDP_ADDR_E=0x0212,UDP_ADDR_F=0x7401,UDP_ADDR_G=0x01,UDP_ADDR_H=0x101</commands>
|
|
||||||
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/udp-ipv6/udp-server.sky</firmware>
|
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/udp-ipv6/udp-server.sky</firmware>
|
||||||
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
|
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
|
||||||
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
|
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mrm</project>
|
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mrm</project>
|
||||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mspsim</project>
|
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mspsim</project>
|
||||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/avrora</project>
|
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/avrora</project>
|
||||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mobility</project>
|
|
||||||
<simulation>
|
<simulation>
|
||||||
<title>My simulation</title>
|
<title>My simulation</title>
|
||||||
<delaytime>0</delaytime>
|
<delaytime>0</delaytime>
|
||||||
@ -25,7 +24,7 @@
|
|||||||
<description>Sky Mote Type #1</description>
|
<description>Sky Mote Type #1</description>
|
||||||
<source EXPORT="discard">[CONTIKI_DIR]/examples/udp-ipv6/udp-client.c</source>
|
<source EXPORT="discard">[CONTIKI_DIR]/examples/udp-ipv6/udp-client.c</source>
|
||||||
<commands EXPORT="discard">make clean TARGET=sky
|
<commands EXPORT="discard">make clean TARGET=sky
|
||||||
make udp-client.sky TARGET=sky DEFINES=WITH_UIP6,UDP_ADDR_A=0xfe80,UDP_ADDR_B=0,UDP_ADDR_C=0,UDP_ADDR_D=0,UDP_ADDR_E=0x0212,UDP_ADDR_F=0x7402,UDP_ADDR_G=0x02,UDP_ADDR_H=0x202,SICSLOWPAN_CONF_FRAG=1,SEND_TOO_LARGE_PACKET_TO_TEST_FRAGMENTATION=1</commands>
|
make udp-client.sky TARGET=sky DEFINES=UDP_CONNECTION_ADDR=fe80::212:7402:2:202,SICSLOWPAN_CONF_FRAG=1,SEND_TOO_LARGE_PACKET_TO_TEST_FRAGMENTATION=1</commands>
|
||||||
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/udp-ipv6/udp-client.sky</firmware>
|
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/udp-ipv6/udp-client.sky</firmware>
|
||||||
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
|
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
|
||||||
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
|
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
|
||||||
@ -43,8 +42,7 @@ make udp-client.sky TARGET=sky DEFINES=WITH_UIP6,UDP_ADDR_A=0xfe80,UDP_ADDR_B=0,
|
|||||||
<identifier>sky2</identifier>
|
<identifier>sky2</identifier>
|
||||||
<description>Sky Mote Type #2</description>
|
<description>Sky Mote Type #2</description>
|
||||||
<source EXPORT="discard">[CONTIKI_DIR]/examples/udp-ipv6/udp-server.c</source>
|
<source EXPORT="discard">[CONTIKI_DIR]/examples/udp-ipv6/udp-server.c</source>
|
||||||
<commands EXPORT="discard">make clean TARGET=sky
|
<commands EXPORT="discard">make udp-server.sky TARGET=sky DEFINES=SICSLOWPAN_CONF_FRAG=1</commands>
|
||||||
make udp-server.sky TARGET=sky DEFINES=WITH_UIP6,UDP_ADDR_A=0xfe80,UDP_ADDR_B=0,UDP_ADDR_C=0,UDP_ADDR_D=0,UDP_ADDR_E=0x0212,UDP_ADDR_F=0x7401,UDP_ADDR_G=0x01,UDP_ADDR_H=0x101,SICSLOWPAN_CONF_FRAG=1</commands>
|
|
||||||
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/udp-ipv6/udp-server.sky</firmware>
|
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/udp-ipv6/udp-server.sky</firmware>
|
||||||
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
|
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
|
||||||
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
|
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
|
||||||
|
Loading…
Reference in New Issue
Block a user