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
Revision 1:e51abb43c074, committed 2016-01-28
- Comitter:
- Overdrivr
- Date:
- Thu Jan 28 10:00:45 2016 +0000
- Parent:
- 0:3a30eba5d8f7
- Child:
- 2:b7a3ac7bcec8
- Commit message:
- Wrote wrapper to simplify use
Changed in this revision
driver.cpp | Show annotated file Show diff for this revision Revisions of this file |
driver.hpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/driver.cpp Thu Jan 28 10:00:45 2016 +0000 @@ -0,0 +1,136 @@ +#include "MODSERIAL.h" +#include "driver.hpp" + +static MODSERIAL pc(USBTX, USBRX); + +// Physical driver + +int32_t read(void * buf, uint32_t sizeToRead) +{ + *(uint8_t*)(buf) = pc.getc(); + return 1; +} + +int32_t readable() +{ + return pc.rxBufferGetCount(); +} + +int32_t write(void * buf, uint32_t sizeToWrite) +{ + char * ptr = (char *)buf; + for(uint32_t i = 0 ; i < sizeToWrite ; i++) + { + pc.putc(ptr[i]); + } + return 0; +} + +int32_t writeable() +{ + return pc.writeable(); +} + +// C++ interface + +Telemetry::Telemetry(TM_state* userData) +{ + transport.read = read; + transport.write = write; + transport.readable = readable; + transport.writeable = writeable; + + init_telemetry(userData, &transport); + + pc.baud(9600); +} + +uint32_t Telemetry::cast(TM_msg * m, char * buf, size_t bufSize) +{ + return emplace(m,buf,bufSize); +} + +uint32_t Telemetry::cast_u8(TM_msg * m, uint8_t * dst) +{ + return emplace_u8(m,dst); +} + +uint32_t Telemetry::cast_u16(TM_msg * m, uint16_t * dst) +{ + return emplace_u16(m,dst); +} + +uint32_t Telemetry::cast_u32(TM_msg * m, uint32_t * dst) +{ + return emplace_u32(m,dst); +} + +uint32_t Telemetry::cast_i8(TM_msg * m, int8_t * dst) +{ + return emplace_i8(m,dst); +} + +uint32_t Telemetry::cast_i16(TM_msg * m, int16_t * dst) +{ + return emplace_i16(m,dst); +} + +uint32_t Telemetry::cast_i32(TM_msg * m, int32_t * dst) +{ + return emplace_i32(m,dst); +} + +uint32_t Telemetry::cast_f32(TM_msg * m, float * dst) +{ + return emplace_f32(m,dst); +} + +void Telemetry::pub(const char * topic, char * msg) +{ + publish(topic,msg); +} + +void Telemetry::pub_u8(const char * topic, uint8_t msg) +{ + publish_u8(topic,msg); +} + +void Telemetry::pub_u16(const char * topic, uint16_t msg) +{ + publish_u16(topic,msg); +} + +void Telemetry::pub_u32(const char * topic, uint32_t msg) +{ + publish_u32(topic,msg); +} + +void Telemetry::pub_i8(const char * topic, int8_t msg) +{ + publish_i8(topic,msg); +} + +void Telemetry::pub_i16(const char * topic, int16_t msg) +{ + publish_i16(topic,msg); +} + +void Telemetry::pub_i32(const char * topic, int32_t msg) +{ + publish_i32(topic,msg); +} + +void Telemetry::pub_f32(const char * topic, float msg) +{ + publish_f32(topic,msg); +} + +void Telemetry::sub(void (*callback)(TM_state * s, TM_msg * m)) +{ + subscribe(callback); +} + +void Telemetry::update() +{ + update_telemetry(0); +} \ No newline at end of file
--- a/driver.hpp Wed Jan 27 17:39:36 2016 +0000 +++ b/driver.hpp Thu Jan 28 10:00:45 2016 +0000 @@ -1,44 +1,37 @@ -#include "MODSERIAL.h" +#include "mbed.h" +#include "telemetry/telemetry.hpp" -// Driver implementation for telemetry (github.com/Overdrivr/Telemetry) -// Don't forget in your main to aggregate the driver to telemetry (see below) -/* - // Add this code to your main - - TM_transport transport; - transport.read = read; - transport.write = write; - transport.readable = readable; - transport.writeable = writeable; +// C++ Wrapper and driver implementation for telemetry (github.com/Overdrivr/Telemetry) - // Feed to transport to telemetry on init - init_telemetry(.., &transport); -*/ - -MODSERIAL pc(USBTX, USBRX); - -int32_t read(void * buf, uint32_t sizeToRead) +class Telemetry { - *(uint8_t*)(buf) = pc.getc(); - return 1; -} - -int32_t readable() -{ - return pc.rxBufferGetCount(); -} + public: + Telemetry(TM_state* userData); + + uint32_t cast(TM_msg * m, char * buf, size_t bufSize); + uint32_t cast_u8(TM_msg * m, uint8_t * dst); + uint32_t cast_u16(TM_msg * m, uint16_t * dst); + uint32_t cast_u32(TM_msg * m, uint32_t * dst); + uint32_t cast_i8(TM_msg * m, int8_t * dst); + uint32_t cast_i16(TM_msg * m, int16_t * dst); + uint32_t cast_i32(TM_msg * m, int32_t * dst); + uint32_t cast_f32(TM_msg * m, float * dst); + + void pub(const char * topic, char * msg); + void pub_u8(const char * topic, uint8_t msg); + void pub_u16(const char * topic, uint16_t msg); + void pub_u32(const char * topic, uint32_t msg); + void pub_i8(const char * topic, int8_t msg); + void pub_i16(const char * topic, int16_t msg); + void pub_i32(const char * topic, int32_t msg); + void pub_f32(const char * topic, float msg); + + void sub(void (*callback)(TM_state * s, TM_msg * m)); -int32_t write(void * buf, uint32_t sizeToWrite) -{ - char * ptr = (char *)buf; - for(uint32_t i = 0 ; i < sizeToWrite ; i++) - { - pc.putc(ptr[i]); - } - return 0; -} + void update(); + + private: + TM_transport transport; +}; -int32_t writeable() -{ - return pc.writeable(); -} +