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

@ -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
@ -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
@ -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 */

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);
}