Use the Z1 product ID as MAC/Node ID if no value is found in the XMEM

This commit is contained in:
Antonio Lignan 2014-10-13 11:15:05 +02:00
parent 4cc1762851
commit cceb97059c
3 changed files with 71 additions and 43 deletions

View File

@ -67,6 +67,14 @@ ifeq ($(HOST_OS),Darwin)
MOTES = $(shell $(MOTELIST) -c 2>&- | \
cut -f 2 -d ,)
CMOTES=$(MOTES)
REFNUM = $(shell $(MOTELIST) -c 2>&- | \
cut -f 1 -d , | tail -c5)
ifneq (,$(REFNUM))
# No device fo-und
ifeq (,$(findstring und, $(REFNUM)))
CFLAGS += -DSERIALNUM=$(REFNUM)
endif
endif
endif
else
# If we are not running under Mac, we assume Linux
@ -80,6 +88,14 @@ else
cut -f 2 -d , | \
perl -ne 'print $$1 . " " if(m-(/dev/\w+)-);')
CMOTES=$(MOTES)
REFNUM = $(shell $(MOTELIST) -c 2>&- | \
cut -f 1 -d , | tail -c5 )
ifneq (,$(REFNUM))
# No device fo-und
ifeq (,$(findstring und, $(REFNUM)))
CFLAGS += -DSERIALNUM=$(REFNUM)
endif
endif
endif
endif

View File

@ -80,9 +80,9 @@ static struct timer mgt_timer;
#include "net/uip-fw-drv.h"
#include "net/ipv4/uip-over-mesh.h"
static struct uip_fw_netif slipif =
{UIP_FW_NETIF(192,168,1,2, 255,255,255,255, slip_send)};
{ UIP_FW_NETIF(192, 168, 1, 2, 255, 255, 255, 255, slip_send) };
static struct uip_fw_netif meshif =
{UIP_FW_NETIF(172,16,0,0, 255,255,0,0, uip_over_mesh_send)};
{ UIP_FW_NETIF(172, 16, 0, 0, 255, 255, 0, 0, uip_over_mesh_send) };
#endif /* WITH_UIP */
@ -119,7 +119,11 @@ force_float_inclusion()
}
#endif
/*---------------------------------------------------------------------------*/
void uip_log(char *msg) { puts(msg); }
void
uip_log(char *msg)
{
puts(msg);
}
/*---------------------------------------------------------------------------*/
#if 0
void
@ -157,7 +161,7 @@ set_rime_addr(void)
}
/*---------------------------------------------------------------------------*/
static void
print_processes(struct process * const processes[])
print_processes(struct process *const processes[])
{
/* const struct process * const * p = processes;*/
printf("Starting");
@ -213,9 +217,16 @@ main(int argc, char **argv)
/* Restore node id if such has been stored in external mem */
node_id_restore();
/* If no MAC address was burned, we use the node ID. */
/* If no MAC address was burned, we use the node id or the Z1 product ID */
if(!(node_mac[0] | node_mac[1] | node_mac[2] | node_mac[3] |
node_mac[4] | node_mac[5] | node_mac[6] | node_mac[7])) {
#ifdef SERIALNUM
if(!node_id) {
PRINTF("Node id is not set, using Z1 product ID\n");
node_id = SERIALNUM;
}
#endif
node_mac[0] = 0xc1; /* Hardcoded for Z1 */
node_mac[1] = 0x0c; /* Hardcoded for Revision C */
node_mac[2] = 0x00; /* Hardcoded to arbitrary even number so that
@ -231,7 +242,7 @@ main(int argc, char **argv)
/* Overwrite node MAC if desired at compile time */
#ifdef MACID
#warning "***** CHANGING DEFAULT MAC *****"
#warning "***** CHANGING DEFAULT MAC *****"
node_mac[0] = 0xc1; /* Hardcoded for Z1 */
node_mac[1] = 0x0c; /* Hardcoded for Revision C */
node_mac[2] = 0x00; /* Hardcoded to arbitrary even number so that
@ -286,15 +297,17 @@ main(int argc, char **argv)
leds_off(LEDS_ALL);
#ifdef SERIALNUM
PRINTF("Ref ID: %u\n", SERIALNUM);
#endif
PRINTF(CONTIKI_VERSION_STRING " started. ");
if(node_id > 0) {
if(node_id) {
PRINTF("Node id is set to %u.\n", node_id);
} else {
PRINTF("Node id is not set.\n");
PRINTF("Node id not set\n");
}
#if WITH_UIP6
memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr));
/* Setup nullmac-like MAC for 802.15.4 */
@ -310,7 +323,7 @@ main(int argc, char **argv)
printf("%s %s, channel check rate %lu Hz, radio channel %u\n",
NETSTACK_MAC.name, NETSTACK_RDC.name,
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 :
NETSTACK_RDC.channel_check_interval()),
CC2420_CONF_CHANNEL);
@ -351,7 +364,7 @@ main(int argc, char **argv)
printf("%s %s, channel check rate %lu Hz, radio channel %u\n",
NETSTACK_MAC.name, NETSTACK_RDC.name,
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1:
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 :
NETSTACK_RDC.channel_check_interval()),
CC2420_CONF_CHANNEL);
#endif /* WITH_UIP6 */
@ -380,9 +393,9 @@ main(int argc, char **argv)
uip_init();
uip_ipaddr(&hostaddr, 172,16,
linkaddr_node_addr.u8[0],linkaddr_node_addr.u8[1]);
uip_ipaddr(&netmask, 255,255,0,0);
uip_ipaddr(&hostaddr, 172, 16,
linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1]);
uip_ipaddr(&netmask, 255, 255, 0, 0);
uip_ipaddr_copy(&meshif.ipaddr, &hostaddr);
uip_sethostaddr(&hostaddr);
@ -431,7 +444,7 @@ main(int argc, char **argv)
#if DCOSYNCH_CONF_ENABLED
/* before going down to sleep possibly do some management */
if (timer_expired(&mgt_timer)) {
if(timer_expired(&mgt_timer)) {
timer_reset(&mgt_timer);
msp430_sync_dco();
}

View File

@ -42,7 +42,6 @@
#include "dev/xmem.h"
#include <string.h>
unsigned short node_id = 0;
unsigned char node_mac[8];
@ -65,11 +64,11 @@ void
node_id_burn(unsigned short id)
{
unsigned char buf[12];
memset(buf, 0, sizeof(buf));
buf[0] = 0xad;
buf[1] = 0xde;
buf[2] = id >> 8;
buf[3] = id & 0xff;
memcpy(&buf[4], node_mac, 8);
xmem_erase(XMEM_ERASE_UNIT_SIZE, NODE_ID_XMEM_OFFSET);
xmem_pwrite(buf, 12, NODE_ID_XMEM_OFFSET);
}