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.cpp Source File

telemetry_utils.cpp

00001 #include "telemetry_utils.h"
00002 
00003 uint32_t emplace(TM_msg* m, char * buf, size_t bufSize)
00004 {
00005   if(m->type != TM_string)
00006     return 0;
00007 
00008   uint32_t size = m->size;
00009 
00010   if(bufSize - 1 < size)
00011     size = bufSize - 1;
00012 
00013   strncpy(buf, (char*)(m->buffer), size);
00014   buf[size] = '\0';
00015 
00016   return 1;
00017 }
00018 
00019 uint32_t emplace_u8(TM_msg* m, uint8_t* dst)
00020 {
00021   if(m->type != TM_uint8)
00022     return 0;
00023 
00024   memcpy(dst,m->buffer,1);
00025   return 1;
00026 }
00027 
00028 uint32_t emplace_u16(TM_msg* m, uint16_t* dst)
00029 {
00030   if(m->type != TM_uint16)
00031     return 0;
00032 
00033   memcpy(dst,m->buffer,2);
00034   return 1;
00035 }
00036 
00037 uint32_t emplace_u32(TM_msg* m, uint32_t* dst)
00038 {
00039   if(m->type != TM_uint32)
00040     return 0;
00041 
00042   memcpy(dst,m->buffer,4);
00043   return 1;
00044 }
00045 
00046 uint32_t emplace_i8(TM_msg* m, int8_t* dst)
00047 {
00048   if(m->type != TM_int8)
00049     return 0;
00050 
00051   memcpy(dst,m->buffer,1);
00052   return 1;
00053 }
00054 
00055 uint32_t emplace_i16(TM_msg* m, int16_t* dst)
00056 {
00057   if(m->type != TM_int16)
00058     return 0;
00059 
00060   memcpy(dst,m->buffer,2);
00061   return 1;
00062 }
00063 
00064 uint32_t emplace_i32(TM_msg* m, int32_t* dst)
00065 {
00066   if(m->type != TM_int32)
00067     return 0;
00068 
00069   memcpy(dst,m->buffer,4);
00070   return 1;
00071 }
00072 
00073 uint32_t emplace_f32(TM_msg* m, float* dst)
00074 {
00075   if(m->type != TM_float32)
00076     return 0;
00077 
00078   memcpy(dst,m->buffer,4);
00079   return 1;
00080 }
00081 
00082 uint32_t match(TM_msg * m, const char * topicToMatch)
00083 {
00084   if(strcmp(m->topic,topicToMatch) == 0)
00085     return 1;
00086 
00087   return 0;
00088 }
00089 
00090 uint32_t fullmatch(TM_msg * m, const char * topicToMatch, TM_type typeToMatch)
00091 {
00092   if(strcmp(m->topic,topicToMatch) == 0 && m->type == typeToMatch)
00093     return 1;
00094 
00095   return 0;
00096 }
00097 
00098 uint32_t update(TM_msg * msg, const char *topic, char *var, size_t bufSize)
00099 {
00100    if(strcmp(topic,msg->topic) == 0)
00101     return emplace(msg, var, bufSize);
00102 
00103    return 0;
00104 }
00105 
00106 uint32_t update_u8(TM_msg * msg, const char *topic, uint8_t *var)
00107 {
00108    if(strcmp(topic,msg->topic) == 0)
00109     return emplace_u8(msg, var);
00110 
00111    return 0;
00112 }
00113 
00114 uint32_t update_u16(TM_msg * msg, const char *topic, uint16_t *var)
00115 {
00116    if(strcmp(topic,msg->topic) == 0)
00117     return emplace_u16(msg, var);
00118 
00119    return 0;
00120 }
00121 
00122 uint32_t update_u32(TM_msg * msg, const char *topic, uint32_t *var)
00123 {
00124    if(strcmp(topic,msg->topic) == 0)
00125      return emplace_u32(msg, var);
00126 
00127    return 0;
00128 }
00129 
00130 uint32_t update_i8(TM_msg * msg, const char *topic, int8_t *var)
00131 {
00132    if(strcmp(topic,msg->topic) == 0)
00133     return emplace_i8(msg, var);
00134 
00135    return 0;
00136 }
00137 
00138 uint32_t update_i16(TM_msg * msg, const char *topic, int16_t *var)
00139 {
00140    if(strcmp(topic,msg->topic) == 0)
00141     return emplace_i16(msg, var);
00142 
00143    return 0;
00144 }
00145 
00146 uint32_t update_i32(TM_msg * msg, const char *topic, int32_t *var)
00147 {
00148     if(strcmp(topic,msg->topic) == 0)
00149       return emplace_i32(msg, var);
00150 
00151    return 0;
00152 }
00153 
00154 uint32_t update_f32(TM_msg * msg, const char *topic, float *var)
00155 {
00156   if(strcmp(topic,msg->topic) == 0)
00157     return emplace_f32(msg, var);
00158 
00159    return 0;
00160 }