Skip to content

Commit

Permalink
wsn-main frame: add serial, node-id and sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavid committed Dec 30, 2020
1 parent ad07cbd commit 120f78e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/wsn-main/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ USEMODULE += bme280_i2c
USEMODULE += wsn
EXTERNAL_MODULE_DIRS += $(CURDIR)/../../sys/wsn

CFLAGS += -DNODE_ID=\"$(NODE_ID)\"

include $(RIOTBASE)/Makefile.include
16 changes: 16 additions & 0 deletions apps/wsn-main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#define TICKS_PER_SEC US_PER_SEC
#endif

#ifndef NODE_ID
#define NODE_ID ""
#endif

#define SLEEP 5 // seconds


Expand Down Expand Up @@ -98,6 +102,18 @@ int main(void)
nanocbor_fmt_uint(&enc, 0);
nanocbor_fmt_uint(&enc, now / TICKS_PER_SEC);

// Serial number
nanocbor_fmt_uint(&enc, 1);
nanocbor_fmt_uint(&enc, cpuid);

// Name (Node Identifier)
nanocbor_fmt_uint(&enc, 2);
nanocbor_put_tstr(&enc, NODE_ID);

// Frame sequence number
nanocbor_fmt_uint(&enc, 3);
nanocbor_fmt_uint(&enc, loop);

saul_reg_t *dev = saul_reg;
while (dev) {
// TODO Support 2 BME280 sensors at addresses 0x76 and 0x77
Expand Down
5 changes: 5 additions & 0 deletions sys/include/wsn.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#ifndef WSN_H
#define WSN_H

/**
* @brief Uniquely identifies the mote
*/
extern uint64_t cpuid;

/**
* @brief Code to run at boot
*
Expand Down
2 changes: 2 additions & 0 deletions sys/wsn/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
FEATURES_REQUIRED = periph_cpuid

# Storage
USEMODULE += fatfs_vfs
USEMODULE += mtd_sdcard
Expand Down
25 changes: 25 additions & 0 deletions sys/wsn/wsn.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,39 @@
#include <log.h>
#include <net/netif.h>
#include <net/gnrc/netif.h>
#include <periph/cpuid.h>

// Project
#include "settings.h"
#include "wsn.h"


uint64_t cpuid = 0;


void wsn_boot(void)
{
/*
* ID
*
* XXX In the cc2539 the CPU id is based on the MAC address, which is
* defined by two 32bit little-endian words stored in memory: first the
* most-significat word (IEEE_ADDR_MSWORD), then the less-significat word
* (IEEE_ADDR_MSWORD). But the CPU id is read from memory as-is.
*
* For example if in memory we have 00:4b:12:00 2e:15:40:19 then:
* - MAC address is 00:12:4B:00:19:40:15:2E
* - But CPU id is 00:4b:12:00:2e:15:40:19
*
*/
uint8_t buffer[CPUID_LEN];
cpuid_get(buffer);

for (unsigned int i = 0; i < CPUID_LEN; i++) {
cpuid = cpuid << 8;
cpuid |= buffer[i];
}

/*
* Storage
*/
Expand Down

0 comments on commit 120f78e

Please sign in to comment.