... | @@ -7,11 +7,7 @@ |
... | @@ -7,11 +7,7 @@ |
|
Chances are that you need a unique node ID for each target device. One way to get such an ID is by defining the symbol `FLOCKLAB_NODE_ID` in your code:
|
|
Chances are that you need a unique node ID for each target device. One way to get such an ID is by defining the symbol `FLOCKLAB_NODE_ID` in your code:
|
|
```
|
|
```
|
|
// must be global (variable will be placed into the .data section)
|
|
// must be global (variable will be placed into the .data section)
|
|
uint16_t FLOCKLAB_NODE_ID = 0xbeef; // any value is ok, will be overwritten by FlockLab
|
|
volatile uint16_t FLOCKLAB_NODE_ID = 0xbeef; // any value is ok, will be overwritten by FlockLab
|
|
volatile uint16_t node_id; // must be volatile
|
|
|
|
|
|
|
|
// somewhere in the code
|
|
|
|
node_id = FLOCKLAB_NODE_ID;
|
|
|
|
```
|
|
```
|
|
FlockLab will then automatically change (by binary patching) this value to the target ID (if specified, otherwise the observer ID is used) before uploading the image to the targets.
|
|
FlockLab will then automatically change (by binary patching) this value to the target ID (if specified, otherwise the observer ID is used) before uploading the image to the targets.
|
|
Note that some compilers might still remove the symbol `FLOCKLAB_NODE_ID`. To make sure is included in the final binary, you can use `objdump` to display the symbol table:
|
|
Note that some compilers might still remove the symbol `FLOCKLAB_NODE_ID`. To make sure is included in the final binary, you can use `objdump` to display the symbol table:
|
... | @@ -23,11 +19,11 @@ Note that assigning node IDs is only supported if you submit your target images |
... | @@ -23,11 +19,11 @@ Note that assigning node IDs is only supported if you submit your target images |
|
|
|
|
|
Note that depending on your compiler, the data section in the ELF may be empty, and thus binary patching will fail (this is e.g. the case if you use the SEGGER compiler for the platform nRF5). As a workaround, you need to place the variable into the read-only memory section by making it constant:
|
|
Note that depending on your compiler, the data section in the ELF may be empty, and thus binary patching will fail (this is e.g. the case if you use the SEGGER compiler for the platform nRF5). As a workaround, you need to place the variable into the read-only memory section by making it constant:
|
|
```
|
|
```
|
|
// must be global (variable will be placed into the .rodata section)
|
|
// must be global (constant will be placed into the .rodata section)
|
|
const uint16_t FLOCKLAB_NODE_ID = 0xbeef;
|
|
const uint16_t FLOCKLAB_NODE_ID = 0xbeef;
|
|
|
|
|
|
// somewhere in the code (note: conversion to volatile forces the compiler to keep the constant in the symbol table)
|
|
// somewhere in the code (note: conversion to volatile avoids constant propagation)
|
|
node_id = *(volatile uint16_t*)&FLOCKLAB_NODE_ID;
|
|
node_id = *(volatile const uint16_t*)&FLOCKLAB_NODE_ID;
|
|
```
|
|
```
|
|
Alternatively, you can place the constant `FLOCKLAB_NODE_ID` into a separate C file and declare it as `extern` in your code.
|
|
Alternatively, you can place the constant `FLOCKLAB_NODE_ID` into a separate C file and declare it as `extern` in your code.
|
|
|
|
|
... | | ... | |