First class data visualization and communication library with embedded devices. Code is maintained at github.com/Overdrivr/Telemetry

Dependents:   telemetry_car_demo telemetry_demo_FRDM-TFC telemetry_example_01 telemetry_indexed_data_demo ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers telemetry_utils.h Source File

telemetry_utils.h

00001 #ifndef TELEMETRY_UTILS_H_
00002 #define TELEMETRY_UTILS_H_
00003 
00004 #include "stddef.h"
00005 #include "stdint.h"
00006 #include "string.h"
00007 
00008 // Forward declaration of user state
00009 typedef struct TM_state TM_state;
00010 
00011 // Enumeration of supported message payloads
00012 enum TM_type {
00013   TM_float32 = 0,
00014   TM_uint8 = 1,
00015   TM_uint16 = 2,
00016   TM_uint32 = 3,
00017   TM_int8 = 4,
00018   TM_int16 = 5,
00019   TM_int32 = 6,
00020   TM_string = 7
00021 };
00022 
00023 typedef enum TM_type TM_type;
00024 
00025 
00026 // Data structure for received messages
00027 typedef struct TM_msg TM_msg;
00028 struct TM_msg {
00029   TM_type type;
00030   char * topic;
00031   void * buffer;
00032   uint32_t size;
00033 };
00034 
00035 // Data structure for holding transport interface
00036 typedef struct TM_transport TM_transport;
00037 struct TM_transport {
00038   int32_t (*read)(void * buf, uint32_t sizeToRead);
00039   int32_t (*readable)();
00040   int32_t (*write)(void * buf, uint32_t sizeToWrite);
00041   int32_t (*writeable)();
00042 };
00043 
00044 // Decodes TM_msg buffer and emplaces its value into dst
00045 // Returns 1 (true) if decoding was successful
00046 uint32_t emplace(TM_msg * m, char * buf, size_t bufSize);
00047 uint32_t emplace_u8(TM_msg * m, uint8_t * dst);
00048 uint32_t emplace_u16(TM_msg * m, uint16_t * dst);
00049 uint32_t emplace_u32(TM_msg * m, uint32_t * dst);
00050 uint32_t emplace_i8(TM_msg * m, int8_t * dst);
00051 uint32_t emplace_i16(TM_msg * m, int16_t * dst);
00052 uint32_t emplace_i32(TM_msg * m, int32_t * dst);
00053 uint32_t emplace_f32(TM_msg * m, float * dst);
00054 
00055 // Returns 1 if topicToMatch matches m->topic
00056 //         0 otherwise
00057 uint32_t match(TM_msg * m, const char * topicToMatch);
00058 
00059 // Returns 1 if topicToMatch matches m->topic and typeToMatch matches m->type,
00060 //         0 otherwise
00061 uint32_t fullmatch(TM_msg * m, const char * topicToMatch, TM_type typeToMatch);
00062 
00063 // Decodes TM_msg buffer and update its value into dst if matching topic
00064 // Returns 1 (true) if decoding was successful
00065 uint32_t update(TM_msg * msg, const char *topic, char *var, size_t bufSize);
00066 uint32_t update_u8(TM_msg * msg, const char *topic, uint8_t *var);
00067 uint32_t update_u16(TM_msg * msg, const char *topic, uint16_t *var);
00068 uint32_t update_u32(TM_msg * msg, const char *topic, uint32_t *var);
00069 uint32_t update_i8(TM_msg * msg, const char *topic, int8_t *var);
00070 uint32_t update_i16(TM_msg * msg, const char *topic, int16_t *var);
00071 uint32_t update_i32(TM_msg * msg, const char *topic, int32_t *var);
00072 uint32_t update_f32(TM_msg * msg, const char *topic, float *var);
00073 
00074 
00075 #endif