Skip to content

Commit 120f78e

Browse files
committed
wsn-main frame: add serial, node-id and sequence
1 parent ad07cbd commit 120f78e

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

apps/wsn-main/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ USEMODULE += bme280_i2c
1212
USEMODULE += wsn
1313
EXTERNAL_MODULE_DIRS += $(CURDIR)/../../sys/wsn
1414

15+
CFLAGS += -DNODE_ID=\"$(NODE_ID)\"
16+
1517
include $(RIOTBASE)/Makefile.include

apps/wsn-main/main.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#define TICKS_PER_SEC US_PER_SEC
2525
#endif
2626

27+
#ifndef NODE_ID
28+
#define NODE_ID ""
29+
#endif
30+
2731
#define SLEEP 5 // seconds
2832

2933

@@ -98,6 +102,18 @@ int main(void)
98102
nanocbor_fmt_uint(&enc, 0);
99103
nanocbor_fmt_uint(&enc, now / TICKS_PER_SEC);
100104

105+
// Serial number
106+
nanocbor_fmt_uint(&enc, 1);
107+
nanocbor_fmt_uint(&enc, cpuid);
108+
109+
// Name (Node Identifier)
110+
nanocbor_fmt_uint(&enc, 2);
111+
nanocbor_put_tstr(&enc, NODE_ID);
112+
113+
// Frame sequence number
114+
nanocbor_fmt_uint(&enc, 3);
115+
nanocbor_fmt_uint(&enc, loop);
116+
101117
saul_reg_t *dev = saul_reg;
102118
while (dev) {
103119
// TODO Support 2 BME280 sensors at addresses 0x76 and 0x77

sys/include/wsn.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
#ifndef WSN_H
1414
#define WSN_H
1515

16+
/**
17+
* @brief Uniquely identifies the mote
18+
*/
19+
extern uint64_t cpuid;
20+
1621
/**
1722
* @brief Code to run at boot
1823
*

sys/wsn/Makefile.dep

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
FEATURES_REQUIRED = periph_cpuid
2+
13
# Storage
24
USEMODULE += fatfs_vfs
35
USEMODULE += mtd_sdcard

sys/wsn/wsn.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,39 @@
22
#include <log.h>
33
#include <net/netif.h>
44
#include <net/gnrc/netif.h>
5+
#include <periph/cpuid.h>
56

67
// Project
78
#include "settings.h"
89
#include "wsn.h"
910

1011

12+
uint64_t cpuid = 0;
13+
14+
1115
void wsn_boot(void)
1216
{
17+
/*
18+
* ID
19+
*
20+
* XXX In the cc2539 the CPU id is based on the MAC address, which is
21+
* defined by two 32bit little-endian words stored in memory: first the
22+
* most-significat word (IEEE_ADDR_MSWORD), then the less-significat word
23+
* (IEEE_ADDR_MSWORD). But the CPU id is read from memory as-is.
24+
*
25+
* For example if in memory we have 00:4b:12:00 2e:15:40:19 then:
26+
* - MAC address is 00:12:4B:00:19:40:15:2E
27+
* - But CPU id is 00:4b:12:00:2e:15:40:19
28+
*
29+
*/
30+
uint8_t buffer[CPUID_LEN];
31+
cpuid_get(buffer);
32+
33+
for (unsigned int i = 0; i < CPUID_LEN; i++) {
34+
cpuid = cpuid << 8;
35+
cpuid |= buffer[i];
36+
}
37+
1338
/*
1439
* Storage
1540
*/

0 commit comments

Comments
 (0)