Remi Beges / Mbed 2 deprecated telemetry_indexed_data_demo

Dependencies:   BufferedSerial mbed telemetry

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "Telemetry.hpp"
00003 
00004 /*
00005     Example of the 'Telemetry' library, a portable communication library for embedded devices.
00006     
00007     This code shows how you can use the powerful topic adressing of the library
00008     to send complex, indexed and sparse data such as arrays, lists, etc. 
00009     
00010     You can use the Pytelemetry Command Line Interface to open plots, visualize the received data,
00011     and communicate with the car.
00012     See https://github.com/Overdrivr/pytelemetrycli
00013 */
00014 
00015 int main()
00016 {   
00017     Telemetry TM(115200);
00018     
00019     Timer refresh_timer;
00020     refresh_timer.start();
00021     
00022     // The topic under which the array is published
00023     char topic [] = "sin:000";
00024     
00025     // The sent array contains 16 elements
00026     // Each element takes the value of a sine function, with a phase difference between each element
00027     // In the command-line interface, the generated data will visualize as a moving sine wave
00028     
00029     // Time for simulating sine function
00030     float t = 0;
00031         
00032     for(;;)
00033     {
00034         // 10 times per second
00035         if(refresh_timer.read_ms() > 100)
00036         {
00037             refresh_timer.reset();
00038             
00039             // Compute a 16 points window on a sine function that shifts in time
00040             for(uint16_t i = 0 ; i < 16 ; i++)
00041             {
00042                 // Compute sinus of point i
00043                 float s = sin(2 * 3.14159 * t + i/10.0);
00044                 
00045                 // Build the topic
00046                 // First topic will be 'sin:0'
00047                 // Second topic will be 'sin:1', etc            
00048                 sprintf(topic,"sin:%u",i);
00049                 
00050                 // Publish sine value at index 'i' to topic 'sin:i'
00051                 TM.pub_f32(topic,s);
00052             }
00053             
00054             // Move time forward
00055             t += 0.005;
00056         }
00057     }
00058 }