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
c_api/telemetry_utils.h@5:cd94bb58e096, 2016-03-09 (annotated)
- Committer:
- Overdrivr
- Date:
- Wed Mar 09 12:15:13 2016 +0000
- Revision:
- 5:cd94bb58e096
Release 1.0.3. See changelog here https://github.com/Overdrivr/Telemetry/releases/tag/1.0.3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Overdrivr | 5:cd94bb58e096 | 1 | #ifndef TELEMETRY_UTILS_H_ |
Overdrivr | 5:cd94bb58e096 | 2 | #define TELEMETRY_UTILS_H_ |
Overdrivr | 5:cd94bb58e096 | 3 | |
Overdrivr | 5:cd94bb58e096 | 4 | #include "stddef.h" |
Overdrivr | 5:cd94bb58e096 | 5 | #include "stdint.h" |
Overdrivr | 5:cd94bb58e096 | 6 | #include "string.h" |
Overdrivr | 5:cd94bb58e096 | 7 | |
Overdrivr | 5:cd94bb58e096 | 8 | // Forward declaration of user state |
Overdrivr | 5:cd94bb58e096 | 9 | typedef struct TM_state TM_state; |
Overdrivr | 5:cd94bb58e096 | 10 | |
Overdrivr | 5:cd94bb58e096 | 11 | // Enumeration of supported message payloads |
Overdrivr | 5:cd94bb58e096 | 12 | enum TM_type { |
Overdrivr | 5:cd94bb58e096 | 13 | TM_float32 = 0, |
Overdrivr | 5:cd94bb58e096 | 14 | TM_uint8 = 1, |
Overdrivr | 5:cd94bb58e096 | 15 | TM_uint16 = 2, |
Overdrivr | 5:cd94bb58e096 | 16 | TM_uint32 = 3, |
Overdrivr | 5:cd94bb58e096 | 17 | TM_int8 = 4, |
Overdrivr | 5:cd94bb58e096 | 18 | TM_int16 = 5, |
Overdrivr | 5:cd94bb58e096 | 19 | TM_int32 = 6, |
Overdrivr | 5:cd94bb58e096 | 20 | TM_string = 7 |
Overdrivr | 5:cd94bb58e096 | 21 | }; |
Overdrivr | 5:cd94bb58e096 | 22 | |
Overdrivr | 5:cd94bb58e096 | 23 | typedef enum TM_type TM_type; |
Overdrivr | 5:cd94bb58e096 | 24 | |
Overdrivr | 5:cd94bb58e096 | 25 | |
Overdrivr | 5:cd94bb58e096 | 26 | // Data structure for received messages |
Overdrivr | 5:cd94bb58e096 | 27 | typedef struct TM_msg TM_msg; |
Overdrivr | 5:cd94bb58e096 | 28 | struct TM_msg { |
Overdrivr | 5:cd94bb58e096 | 29 | TM_type type; |
Overdrivr | 5:cd94bb58e096 | 30 | char * topic; |
Overdrivr | 5:cd94bb58e096 | 31 | void * buffer; |
Overdrivr | 5:cd94bb58e096 | 32 | uint32_t size; |
Overdrivr | 5:cd94bb58e096 | 33 | }; |
Overdrivr | 5:cd94bb58e096 | 34 | |
Overdrivr | 5:cd94bb58e096 | 35 | // Data structure for holding transport interface |
Overdrivr | 5:cd94bb58e096 | 36 | typedef struct TM_transport TM_transport; |
Overdrivr | 5:cd94bb58e096 | 37 | struct TM_transport { |
Overdrivr | 5:cd94bb58e096 | 38 | int32_t (*read)(void * buf, uint32_t sizeToRead); |
Overdrivr | 5:cd94bb58e096 | 39 | int32_t (*readable)(); |
Overdrivr | 5:cd94bb58e096 | 40 | int32_t (*write)(void * buf, uint32_t sizeToWrite); |
Overdrivr | 5:cd94bb58e096 | 41 | int32_t (*writeable)(); |
Overdrivr | 5:cd94bb58e096 | 42 | }; |
Overdrivr | 5:cd94bb58e096 | 43 | |
Overdrivr | 5:cd94bb58e096 | 44 | // Decodes TM_msg buffer and emplaces its value into dst |
Overdrivr | 5:cd94bb58e096 | 45 | // Returns 1 (true) if decoding was successful |
Overdrivr | 5:cd94bb58e096 | 46 | uint32_t emplace(TM_msg * m, char * buf, size_t bufSize); |
Overdrivr | 5:cd94bb58e096 | 47 | uint32_t emplace_u8(TM_msg * m, uint8_t * dst); |
Overdrivr | 5:cd94bb58e096 | 48 | uint32_t emplace_u16(TM_msg * m, uint16_t * dst); |
Overdrivr | 5:cd94bb58e096 | 49 | uint32_t emplace_u32(TM_msg * m, uint32_t * dst); |
Overdrivr | 5:cd94bb58e096 | 50 | uint32_t emplace_i8(TM_msg * m, int8_t * dst); |
Overdrivr | 5:cd94bb58e096 | 51 | uint32_t emplace_i16(TM_msg * m, int16_t * dst); |
Overdrivr | 5:cd94bb58e096 | 52 | uint32_t emplace_i32(TM_msg * m, int32_t * dst); |
Overdrivr | 5:cd94bb58e096 | 53 | uint32_t emplace_f32(TM_msg * m, float * dst); |
Overdrivr | 5:cd94bb58e096 | 54 | |
Overdrivr | 5:cd94bb58e096 | 55 | // Returns 1 if topicToMatch matches m->topic |
Overdrivr | 5:cd94bb58e096 | 56 | // 0 otherwise |
Overdrivr | 5:cd94bb58e096 | 57 | uint32_t match(TM_msg * m, const char * topicToMatch); |
Overdrivr | 5:cd94bb58e096 | 58 | |
Overdrivr | 5:cd94bb58e096 | 59 | // Returns 1 if topicToMatch matches m->topic and typeToMatch matches m->type, |
Overdrivr | 5:cd94bb58e096 | 60 | // 0 otherwise |
Overdrivr | 5:cd94bb58e096 | 61 | uint32_t fullmatch(TM_msg * m, const char * topicToMatch, TM_type typeToMatch); |
Overdrivr | 5:cd94bb58e096 | 62 | |
Overdrivr | 5:cd94bb58e096 | 63 | // Decodes TM_msg buffer and update its value into dst if matching topic |
Overdrivr | 5:cd94bb58e096 | 64 | // Returns 1 (true) if decoding was successful |
Overdrivr | 5:cd94bb58e096 | 65 | uint32_t update(TM_msg * msg, const char *topic, char *var, size_t bufSize); |
Overdrivr | 5:cd94bb58e096 | 66 | uint32_t update_u8(TM_msg * msg, const char *topic, uint8_t *var); |
Overdrivr | 5:cd94bb58e096 | 67 | uint32_t update_u16(TM_msg * msg, const char *topic, uint16_t *var); |
Overdrivr | 5:cd94bb58e096 | 68 | uint32_t update_u32(TM_msg * msg, const char *topic, uint32_t *var); |
Overdrivr | 5:cd94bb58e096 | 69 | uint32_t update_i8(TM_msg * msg, const char *topic, int8_t *var); |
Overdrivr | 5:cd94bb58e096 | 70 | uint32_t update_i16(TM_msg * msg, const char *topic, int16_t *var); |
Overdrivr | 5:cd94bb58e096 | 71 | uint32_t update_i32(TM_msg * msg, const char *topic, int32_t *var); |
Overdrivr | 5:cd94bb58e096 | 72 | uint32_t update_f32(TM_msg * msg, const char *topic, float *var); |
Overdrivr | 5:cd94bb58e096 | 73 | |
Overdrivr | 5:cd94bb58e096 | 74 | |
Overdrivr | 5:cd94bb58e096 | 75 | #endif |