Merge pull request #533 from simonduq/contrib/nodeid

Simplify and homogenize node-id across all platforms
This commit is contained in:
Simon Duquennoy 2018-05-25 20:12:26 +02:00 committed by GitHub
commit 6cc65261d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 69 additions and 326 deletions

View File

@ -64,6 +64,7 @@
#include "dev/button-sensor.h" #include "dev/button-sensor.h"
#include "dev/pir-sensor.h" #include "dev/pir-sensor.h"
#include "dev/vib-sensor.h" #include "dev/vib-sensor.h"
#include "dev/moteid.h"
#include "sys/node-id.h" #include "sys/node-id.h"
#include "services/rpl-border-router/rpl-border-router.h" #include "services/rpl-border-router/rpl-border-router.h"
@ -151,13 +152,13 @@ set_lladdr(void)
{ {
int i; int i;
for(i = 0; i < sizeof(uip_lladdr.addr); i += 2) { for(i = 0; i < sizeof(uip_lladdr.addr); i += 2) {
addr.u8[i + 1] = node_id & 0xff; addr.u8[i + 1] = simMoteID & 0xff;
addr.u8[i + 0] = node_id >> 8; addr.u8[i + 0] = simMoteID >> 8;
} }
} }
#else /* NETSTACK_CONF_WITH_IPV6 */ #else /* NETSTACK_CONF_WITH_IPV6 */
addr.u8[0] = node_id & 0xff; addr.u8[0] = simMoteID & 0xff;
addr.u8[1] = node_id >> 8; addr.u8[1] = simMoteID >> 8;
#endif /* NETSTACK_CONF_WITH_IPV6 */ #endif /* NETSTACK_CONF_WITH_IPV6 */
linkaddr_set_node_addr(&addr); linkaddr_set_node_addr(&addr);
} }
@ -177,11 +178,6 @@ platform_init_stage_two()
void void
platform_init_stage_three() platform_init_stage_three()
{ {
if(node_id > 0) {
LOG_INFO("Node id is set to %u.\n", node_id);
} else {
LOG_INFO("Node id is not set.\n");
}
/* Initialize eeprom */ /* Initialize eeprom */
eeprom_init(); eeprom_init();
/* Start serial process */ /* Start serial process */

View File

@ -82,7 +82,7 @@ OBJDUMP:=$(CROSS_COMPILE)-objdump
ARCH = jn516x-ccm-star.c exceptions.c rtimer-arch.c rtimer-arch-slow.c \ ARCH = jn516x-ccm-star.c exceptions.c rtimer-arch.c rtimer-arch-slow.c \
slip_uart0.c clock.c micromac-radio.c int-master.c \ slip_uart0.c clock.c micromac-radio.c int-master.c \
node-id.c watchdog.c slip.c dbg.c watchdog.c slip.c dbg.c
# Default uart0 for printf and slip # Default uart0 for printf and slip
TARGET_WITH_UART0 ?= 1 TARGET_WITH_UART0 ?= 1
TARGET_WITH_UART1 ?= 0 TARGET_WITH_UART1 ?= 0

View File

@ -1,61 +0,0 @@
/*
* Copyright (c) 2014, SICS Swedish ICT.
* 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.
*
*/
/**
* \file
* For compatibility with Contiki node-id interface
*
* \author
* Beshr Al Nahas <beshr@sics.se>
*/
#include "contiki.h"
#include "sys/node-id.h"
#include "contiki.h"
/*---------------------------------------------------------------------------*/
extern unsigned char node_mac[8];
unsigned short node_id = 0;
/*---------------------------------------------------------------------------*/
void
node_id_restore(void)
{
/* base node-id on MAC address */
node_id = (node_mac[6] << 8) | node_mac[7];
}
/*---------------------------------------------------------------------------*/
void
node_id_burn(unsigned short id)
{
/* does not burn anything */
node_id = id;
}

View File

@ -113,8 +113,7 @@ static uint32_t sleep_start_ticks;
#define LOG_LEVEL LOG_LEVEL_MAIN #define LOG_LEVEL LOG_LEVEL_MAIN
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Reads MAC from SoC /* Reads MAC from SoC
* Must be called before node_id_restore() * Must be called before network addresses initialization */
* and network addresses initialization */
static void static void
init_node_mac(void) init_node_mac(void)
{ {
@ -139,14 +138,9 @@ set_linkaddr(void)
#if NETSTACK_CONF_WITH_IPV6 #if NETSTACK_CONF_WITH_IPV6
memcpy(addr.u8, node_mac, sizeof(addr.u8)); memcpy(addr.u8, node_mac, sizeof(addr.u8));
#else #else
if(node_id == 0) { int i;
int i; for(i = 0; i < LINKADDR_SIZE; ++i) {
for(i = 0; i < LINKADDR_SIZE; ++i) { addr.u8[i] = node_mac[LINKADDR_SIZE - 1 - i];
addr.u8[i] = node_mac[LINKADDR_SIZE - 1 - i];
}
} else {
addr.u8[0] = node_id & 0xff;
addr.u8[1] = node_id >> 8;
} }
#endif #endif
linkaddr_set_node_addr(&addr); linkaddr_set_node_addr(&addr);
@ -194,20 +188,6 @@ platform_init_stage_one(void)
leds_init(); leds_init();
leds_on(LEDS_ALL); leds_on(LEDS_ALL);
init_node_mac(); init_node_mac();
node_id_restore();
#if WITH_TINYOS_AUTO_IDS
node_id = TOS_NODE_ID;
#endif /* WITH_TINYOS_AUTO_IDS */
/* for setting "hardcoded" IEEE 802.15.4 MAC addresses */
#ifdef IEEE_802154_MAC_ADDRESS
{
uint8_t ieee[] = IEEE_802154_MAC_ADDRESS;
memcpy(node_mac, ieee, sizeof(uip_lladdr.addr));
node_mac[7] = node_id & 0xff;
}
#endif
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
@ -225,12 +205,6 @@ platform_init_stage_two(void)
void void
platform_init_stage_three(void) platform_init_stage_three(void)
{ {
if(node_id > 0) {
LOG_INFO("Node id is set to %u.\n", node_id);
} else {
LOG_INFO("Node id is not set.\n");
}
#ifndef UIP_FALLBACK_INTERFACE #ifndef UIP_FALLBACK_INTERFACE
uart0_set_input(serial_line_input_byte); uart0_set_input(serial_line_input_byte);
serial_line_init(); serial_line_init();

View File

@ -120,9 +120,6 @@ static uint8_t mac_addr[] = PLATFORM_CONF_MAC_ADDR;
static uint8_t mac_addr[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; static uint8_t mac_addr[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
#endif /* PLATFORM_CONF_MAC_ADDR */ #endif /* PLATFORM_CONF_MAC_ADDR */
#if !NETSTACK_CONF_WITH_IPV6
static uint16_t node_id = 0x0102;
#endif /* !NETSTACK_CONF_WITH_IPV6 */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
select_set_callback(int fd, const struct select_callback *callback) select_set_callback(int fd, const struct select_callback *callback)
@ -187,14 +184,9 @@ set_lladdr(void)
#if NETSTACK_CONF_WITH_IPV6 #if NETSTACK_CONF_WITH_IPV6
memcpy(addr.u8, mac_addr, sizeof(addr.u8)); memcpy(addr.u8, mac_addr, sizeof(addr.u8));
#else #else
if(node_id == 0) { int i;
int i; for(i = 0; i < sizeof(linkaddr_t); ++i) {
for(i = 0; i < sizeof(linkaddr_t); ++i) { addr.u8[i] = mac_addr[7 - i];
addr.u8[i] = mac_addr[7 - i];
}
} else {
addr.u8[0] = node_id & 0xff;
addr.u8[1] = node_id >> 8;
} }
#endif #endif
linkaddr_set_node_addr(&addr); linkaddr_set_node_addr(&addr);

View File

@ -1,6 +1,6 @@
# $Id: Makefile.common,v 1.3 2010/08/24 16:24:11 joxe Exp $ # $Id: Makefile.common,v 1.3 2010/08/24 16:24:11 joxe Exp $
ARCH=spi-legacy.c ds2411.c xmem.c i2c.c node-id.c sensors.c cfs-coffee.c \ ARCH=spi-legacy.c ds2411.c xmem.c i2c.c sensors.c cfs-coffee.c \
cc2420.c cc2420-arch.c cc2420-arch-sfd.c \ cc2420.c cc2420-arch.c cc2420-arch-sfd.c \
sky-sensors.c uip-ipchksum.c \ sky-sensors.c uip-ipchksum.c \
uart1.c slip_uart1.c uart1-putchar.c platform.c uart1.c slip_uart1.c uart1-putchar.c platform.c

View File

@ -1,80 +0,0 @@
/*
* Copyright (c) 2006, Swedish Institute of 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.
*
*/
/**
* \file
* A program for burning a node ID into the flash ROM of a Tmote Sky node.
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "dev/leds.h"
#include "dev/watchdog.h"
#include "sys/node-id.h"
#include "contiki.h"
#include "sys/etimer.h"
#include <stdio.h>
static struct etimer etimer;
PROCESS(burn_process, "Burn node id");
AUTOSTART_PROCESSES(&burn_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(burn_process, ev, data)
{
PROCESS_BEGIN();
etimer_set(&etimer, 5*CLOCK_SECOND);
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
watchdog_stop();
leds_on(LEDS_RED);
#if NODEID
printf("Burning node id %d\n", NODEID);
node_id_burn(NODEID);
leds_on(LEDS_BLUE);
node_id_restore();
printf("Restored node id %d\n", node_id);
#else
#error "burn-nodeid must be compiled with nodeid=<the ID of the node>"
node_id_restore();
printf("Restored node id %d\n", node_id);
#endif
leds_off(LEDS_RED + LEDS_BLUE);
watchdog_start();
while(1) {
PROCESS_WAIT_EVENT();
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View File

@ -1,71 +0,0 @@
/*
* Copyright (c) 2006, Swedish Institute of 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.
*
*/
/**
* \file
* Utility to store a node id in the external flash
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "sys/node-id.h"
#include "contiki.h"
#include "dev/xmem.h"
unsigned short node_id = 0;
/*---------------------------------------------------------------------------*/
void
node_id_restore(void)
{
unsigned char buf[4];
xmem_pread(buf, 4, NODE_ID_XMEM_OFFSET);
if(buf[0] == 0xad &&
buf[1] == 0xde) {
node_id = (buf[2] << 8) | buf[3];
} else {
node_id = 0;
}
}
/*---------------------------------------------------------------------------*/
void
node_id_burn(unsigned short id)
{
unsigned char buf[4];
buf[0] = 0xad;
buf[1] = 0xde;
buf[2] = id >> 8;
buf[3] = id & 0xff;
xmem_erase(XMEM_ERASE_UNIT_SIZE, NODE_ID_XMEM_OFFSET);
xmem_pwrite(buf, 4, NODE_ID_XMEM_OFFSET);
}
/*---------------------------------------------------------------------------*/

View File

@ -103,14 +103,9 @@ set_lladdr(void)
#if NETSTACK_CONF_WITH_IPV6 #if NETSTACK_CONF_WITH_IPV6
memcpy(addr.u8, ds2411_id, sizeof(addr.u8)); memcpy(addr.u8, ds2411_id, sizeof(addr.u8));
#else #else
if(node_id == 0) { int i;
int i; for(i = 0; i < sizeof(linkaddr_t); ++i) {
for(i = 0; i < sizeof(linkaddr_t); ++i) { addr.u8[i] = ds2411_id[7 - i];
addr.u8[i] = ds2411_id[7 - i];
}
} else {
addr.u8[0] = node_id & 0xff;
addr.u8[1] = node_id >> 8;
} }
#endif #endif
linkaddr_set_node_addr(&addr); linkaddr_set_node_addr(&addr);
@ -153,23 +148,7 @@ platform_init_stage_two(void)
* Hardware initialization done! * Hardware initialization done!
*/ */
#if WITH_TINYOS_AUTO_IDS random_init(ds2411_id[0]);
node_id = TOS_NODE_ID;
#else /* WITH_TINYOS_AUTO_IDS */
/* Restore node id if such has been stored in external mem */
node_id_restore();
#endif /* WITH_TINYOS_AUTO_IDS */
/* for setting "hardcoded" IEEE 802.15.4 MAC addresses */
#ifdef IEEE_802154_MAC_ADDRESS
{
uint8_t ieee[] = IEEE_802154_MAC_ADDRESS;
memcpy(ds2411_id, ieee, sizeof(uip_lladdr.addr));
ds2411_id[7] = node_id & 0xff;
}
#endif
random_init(ds2411_id[0] + node_id);
leds_off(LEDS_BLUE); leds_off(LEDS_BLUE);
@ -198,12 +177,6 @@ platform_init_stage_three(void)
cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr); cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
if(node_id > 0) {
LOG_INFO("Node id: %u\n", node_id);
} else {
LOG_INFO("Node id: N/A\n");
}
LOG_INFO("CC2420 CCA threshold %i\n", CC2420_CONF_CCA_THRESH); LOG_INFO("CC2420 CCA threshold %i\n", CC2420_CONF_CCA_THRESH);
#if !NETSTACK_CONF_WITH_IPV6 #if !NETSTACK_CONF_WITH_IPV6

View File

@ -81,8 +81,6 @@
#define LOG_MODULE "CC26xx/CC13xx" #define LOG_MODULE "CC26xx/CC13xx"
#define LOG_LEVEL LOG_LEVEL_MAIN #define LOG_LEVEL LOG_LEVEL_MAIN
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
unsigned short node_id = 0;
/*---------------------------------------------------------------------------*/
/** \brief Board specific iniatialisation */ /** \brief Board specific iniatialisation */
void board_init(void); void board_init(void);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -130,9 +128,6 @@ set_rf_params(void)
NETSTACK_RADIO.set_value(RADIO_PARAM_16BIT_ADDR, short_addr); NETSTACK_RADIO.set_value(RADIO_PARAM_16BIT_ADDR, short_addr);
NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, IEEE802154_DEFAULT_CHANNEL); NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, IEEE802154_DEFAULT_CHANNEL);
NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8); NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8);
/* also set the global node id */
node_id = short_addr;
#endif #endif
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -227,8 +222,6 @@ platform_init_stage_three()
} }
LOG_INFO_("\n"); LOG_INFO_("\n");
LOG_INFO(" Node ID: %d\n", node_id);
#if BOARD_HAS_SENSORS #if BOARD_HAS_SENSORS
process_start(&sensors_process, NULL); process_start(&sensors_process, NULL);
#endif #endif

View File

@ -37,7 +37,7 @@
*/ */
#include "contiki.h" #include "contiki.h"
#include "node-id.h" #include "sys/node-id.h"
#include "sys/log.h" #include "sys/log.h"
#include "net/ipv6/uip-ds6-route.h" #include "net/ipv6/uip-ds6-route.h"
#include "net/mac/tsch/tsch.h" #include "net/mac/tsch/tsch.h"

View File

@ -37,7 +37,7 @@
*/ */
#include "contiki.h" #include "contiki.h"
#include "node-id.h" #include "sys/node-id.h"
#include "sys/log.h" #include "sys/log.h"
#include "net/ipv6/uip-ds6-route.h" #include "net/ipv6/uip-ds6-route.h"
#include "net/ipv6/uip-sr.h" #include "net/ipv6/uip-sr.h"

View File

@ -38,7 +38,7 @@
*/ */
#include "contiki.h" #include "contiki.h"
#include "node-id.h" #include "sys/node-id.h"
#include "sys/log.h" #include "sys/log.h"
#include "net/ipv6/uip-ds6-route.h" #include "net/ipv6/uip-ds6-route.h"
#include "net/mac/tsch/tsch.h" #include "net/mac/tsch/tsch.h"

View File

@ -38,7 +38,7 @@
#include "net/routing/routing.h" #include "net/routing/routing.h"
#include "net/ipv6/uip-debug.h" #include "net/ipv6/uip-debug.h"
#include "lib/random.h" #include "lib/random.h"
#include "node-id.h" #include "sys/node-id.h"
#include "waveform.h" #include "waveform.h"
#include "leds.h" #include "leds.h"
#include "net/ipv6/uiplib.h" #include "net/ipv6/uiplib.h"

View File

@ -42,6 +42,7 @@
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#include "contiki.h" #include "contiki.h"
#include "contiki-net.h" #include "contiki-net.h"
#include "sys/node-id.h"
#include "sys/platform.h" #include "sys/platform.h"
#include "sys/energest.h" #include "sys/energest.h"
#include "sys/stack-check.h" #include "sys/stack-check.h"
@ -86,6 +87,9 @@ main(void)
platform_init_stage_two(); platform_init_stage_two();
netstack_init();
node_id_init();
LOG_INFO("Starting " CONTIKI_VERSION_STRING "\n"); LOG_INFO("Starting " CONTIKI_VERSION_STRING "\n");
LOG_INFO("- Routing: %s\n", NETSTACK_ROUTING.name); LOG_INFO("- Routing: %s\n", NETSTACK_ROUTING.name);
LOG_INFO("- Net: %s\n", NETSTACK_NETWORK.name); LOG_INFO("- Net: %s\n", NETSTACK_NETWORK.name);
@ -97,9 +101,8 @@ main(void)
LOG_INFO("- 802.15.4 Default channel: %u\n", IEEE802154_DEFAULT_CHANNEL); LOG_INFO("- 802.15.4 Default channel: %u\n", IEEE802154_DEFAULT_CHANNEL);
#endif /* MAC_CONF_WITH_TSCH */ #endif /* MAC_CONF_WITH_TSCH */
netstack_init(); LOG_INFO("Node ID: %u\n", node_id);
LOG_INFO("Link-layer address: ");
LOG_INFO("Link-layer address ");
LOG_INFO_LLADDR(&linkaddr_node_addr); LOG_INFO_LLADDR(&linkaddr_node_addr);
LOG_INFO_("\n"); LOG_INFO_("\n");
@ -110,7 +113,7 @@ main(void)
process_start(&tcpip_process, NULL); process_start(&tcpip_process, NULL);
lladdr = uip_ds6_get_link_local(-1); lladdr = uip_ds6_get_link_local(-1);
LOG_INFO("Tentative link-local IPv6 address "); LOG_INFO("Tentative link-local IPv6 address: ");
LOG_INFO_6ADDR(lladdr != NULL ? &lladdr->ipaddr : NULL); LOG_INFO_6ADDR(lladdr != NULL ? &lladdr->ipaddr : NULL);
LOG_INFO_("\n"); LOG_INFO_("\n");
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, Swedish Institute of Computer Science. * Copyright (c) 2018, RISE SICS.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -26,14 +26,26 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* * This file is part of the Contiki operating system.
*
*/ */
#ifndef NODE_ID_H_ /**
#define NODE_ID_H_ * \file
* Node-id management
* \author
* Simon Duquennoy <simon.duquennoy@ri.se>
*/
#include "dev/moteid.h" #include "contiki.h"
#include "sys/node-id.h"
#include "net/linkaddr.h"
#define node_id simMoteID uint16_t node_id = 0;
#endif /* NODE_ID_H_ */ void
node_id_init(void) {
/* Initialize with a default value derived from linkaddr */
node_id = linkaddr_node_addr.u8[LINKADDR_SIZE - 1]
+ (linkaddr_node_addr.u8[LINKADDR_SIZE - 2] << 8);
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2006, Swedish Institute of Computer Science. * Copyright (c) 2018, RISE SICS.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -28,16 +28,28 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* Author: Adam Dunkels <adam@sics.se>
*
*/ */
/**
* \addtogroup node-id
* @{
*
* \file
* Node-id (simple 16-bit identifiers) handling
* \author Simon Duquennoy <simon.duquennoy@ri.se>
*
*/
#ifndef NODE_ID_H_ #ifndef NODE_ID_H_
#define NODE_ID_H_ #define NODE_ID_H_
void node_id_restore(void); /* A global variable that hosts the node ID */
void node_id_burn(unsigned short node_id); extern uint16_t node_id;
/**
extern unsigned short node_id; * Initialize the node ID. Must be called after initialized of linkaddr
*/
void node_id_init(void);
#endif /* NODE_ID_H_ */ #endif /* NODE_ID_H_ */
/** @} */

View File

@ -8,7 +8,7 @@ while(1) {
YIELD(); YIELD();
log.log(time + " " + id + " "+ msg + "\n"); log.log(time + " " + id + " "+ msg + "\n");
if(msg.contains("Node id is set to")) { if(msg.contains("Node ID: ")) {
if(id == 1) { if(id == 1) {
write(sim.getMoteWithID(1), "rpl-set-root 1"); write(sim.getMoteWithID(1), "rpl-set-root 1");
} }

View File

@ -9,7 +9,7 @@ while(1) {
YIELD(); YIELD();
log.log(time + " " + id + " "+ msg + "\n"); log.log(time + " " + id + " "+ msg + "\n");
if(msg.contains("Node id is set to")) { if(msg.contains("Node ID: ")) {
if(id == 1) { if(id == 1) {
write(sim.getMoteWithID(1), "rpl-set-root 1"); write(sim.getMoteWithID(1), "rpl-set-root 1");
} }