-
Notifications
You must be signed in to change notification settings - Fork 27
Advanced usage
So far in the basic examples, only global variables were modified from the subscribed function.
static uint8_t myInc;
void myCustomFunction(TM_state * state, TM_msg * msg)
{
myInc++;
}
struct TM_state {
};
void main()
{
myInc = 0;
init_telemetry();
subscribe(myCustomFunction, &state); // Subscribe our function to be notified
for( ; ; )
{
update_telemetry(0.0);
}
}
While this is easy to understand, it is usually better to avoid using global variables. This is where the TM_state
data structure becomes useful.
TM_state
can be seen as a shared space where you will store writeable parameters. Shared, because it will be possible to access it from the main function, but also from the subscribed function.
This is an equivalent of the previous code using TM_state
instead of global variables.
void myCustomFunction(TM_state * state, TM_msg * msg)
{
state->myInc++;
}
struct TM_state {
uint8_t myInc; // myInc is no longer a global variable
};
void main()
{
TM_state state; // the shared space for writeable parameters
state.myInc = 0;
init_telemetry();
// Pass the shared state by pointer so we can access it inside myCustomFunction(..)
subscribe(myCustomFunction, &state);
for( ; ; )
{
update_telemetry(0.0);
}
}
Of course, you can add as many parameters to the TM_state structure.
Sometimes, you will need to send from the embedded device some more complex data than just plain numbers. Telemetry offers some support for several complex structures by inserting extra indentifiers inside the topic character string.
Special character : /
(slash)
foo/bar
, somedata
foo/qux
, 123
Special character : :
(two-points)
foo:1
, myArray[1]
foo:2
, myArray[2]
foo:5
, myArray[5]
Special character : #
(hashtag)
foo#xy
, 0.1, 0.5
foo#xyz
, 0.1, 0.5, 0.8
foo#m22
, 11, 12, 21, 22
Back Wiki home
- Fast data visualization with the command line interface (todo)
- Fast prototyping remote program control with python (todo)
- Overview of the library
- Protocol description
- All the good stuff inside Telemetry
- List of supported platforms
- Good practices (Must-read !) in writing
- Frequently Asked Questions todo
- List of official examples
- List of projects using telemetry