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
driver.cpp@2:b7a3ac7bcec8, 2016-02-11 (annotated)
- Committer:
- Overdrivr
- Date:
- Thu Feb 11 08:10:08 2016 +0000
- Revision:
- 2:b7a3ac7bcec8
- Parent:
- 1:e51abb43c074
Replaced MODSERIAL by BufferedSerial for increasing amount of supported devices
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Overdrivr | 2:b7a3ac7bcec8 | 1 | #include "BufferedSerial.h" |
Overdrivr | 1:e51abb43c074 | 2 | #include "driver.hpp" |
Overdrivr | 1:e51abb43c074 | 3 | |
Overdrivr | 2:b7a3ac7bcec8 | 4 | static BufferedSerial pc(USBTX, USBRX); |
Overdrivr | 1:e51abb43c074 | 5 | |
Overdrivr | 1:e51abb43c074 | 6 | // Physical driver |
Overdrivr | 1:e51abb43c074 | 7 | |
Overdrivr | 1:e51abb43c074 | 8 | int32_t read(void * buf, uint32_t sizeToRead) |
Overdrivr | 1:e51abb43c074 | 9 | { |
Overdrivr | 1:e51abb43c074 | 10 | *(uint8_t*)(buf) = pc.getc(); |
Overdrivr | 1:e51abb43c074 | 11 | return 1; |
Overdrivr | 1:e51abb43c074 | 12 | } |
Overdrivr | 1:e51abb43c074 | 13 | |
Overdrivr | 1:e51abb43c074 | 14 | int32_t write(void * buf, uint32_t sizeToWrite) |
Overdrivr | 1:e51abb43c074 | 15 | { |
Overdrivr | 2:b7a3ac7bcec8 | 16 | pc.write(buf,sizeToWrite); |
Overdrivr | 1:e51abb43c074 | 17 | return 0; |
Overdrivr | 1:e51abb43c074 | 18 | } |
Overdrivr | 1:e51abb43c074 | 19 | |
Overdrivr | 2:b7a3ac7bcec8 | 20 | int32_t readable() |
Overdrivr | 2:b7a3ac7bcec8 | 21 | { |
Overdrivr | 2:b7a3ac7bcec8 | 22 | return pc.readable(); |
Overdrivr | 2:b7a3ac7bcec8 | 23 | } |
Overdrivr | 2:b7a3ac7bcec8 | 24 | |
Overdrivr | 1:e51abb43c074 | 25 | int32_t writeable() |
Overdrivr | 1:e51abb43c074 | 26 | { |
Overdrivr | 1:e51abb43c074 | 27 | return pc.writeable(); |
Overdrivr | 1:e51abb43c074 | 28 | } |
Overdrivr | 1:e51abb43c074 | 29 | |
Overdrivr | 1:e51abb43c074 | 30 | // C++ interface |
Overdrivr | 1:e51abb43c074 | 31 | |
Overdrivr | 2:b7a3ac7bcec8 | 32 | Telemetry::Telemetry(TM_state* userData, uint32_t bauds) |
Overdrivr | 1:e51abb43c074 | 33 | { |
Overdrivr | 1:e51abb43c074 | 34 | transport.read = read; |
Overdrivr | 1:e51abb43c074 | 35 | transport.write = write; |
Overdrivr | 1:e51abb43c074 | 36 | transport.readable = readable; |
Overdrivr | 1:e51abb43c074 | 37 | transport.writeable = writeable; |
Overdrivr | 1:e51abb43c074 | 38 | |
Overdrivr | 1:e51abb43c074 | 39 | init_telemetry(userData, &transport); |
Overdrivr | 1:e51abb43c074 | 40 | |
Overdrivr | 2:b7a3ac7bcec8 | 41 | pc.baud(bauds); |
Overdrivr | 1:e51abb43c074 | 42 | } |
Overdrivr | 1:e51abb43c074 | 43 | |
Overdrivr | 1:e51abb43c074 | 44 | uint32_t Telemetry::cast(TM_msg * m, char * buf, size_t bufSize) |
Overdrivr | 1:e51abb43c074 | 45 | { |
Overdrivr | 1:e51abb43c074 | 46 | return emplace(m,buf,bufSize); |
Overdrivr | 1:e51abb43c074 | 47 | } |
Overdrivr | 1:e51abb43c074 | 48 | |
Overdrivr | 1:e51abb43c074 | 49 | uint32_t Telemetry::cast_u8(TM_msg * m, uint8_t * dst) |
Overdrivr | 1:e51abb43c074 | 50 | { |
Overdrivr | 1:e51abb43c074 | 51 | return emplace_u8(m,dst); |
Overdrivr | 1:e51abb43c074 | 52 | } |
Overdrivr | 1:e51abb43c074 | 53 | |
Overdrivr | 1:e51abb43c074 | 54 | uint32_t Telemetry::cast_u16(TM_msg * m, uint16_t * dst) |
Overdrivr | 1:e51abb43c074 | 55 | { |
Overdrivr | 1:e51abb43c074 | 56 | return emplace_u16(m,dst); |
Overdrivr | 1:e51abb43c074 | 57 | } |
Overdrivr | 1:e51abb43c074 | 58 | |
Overdrivr | 1:e51abb43c074 | 59 | uint32_t Telemetry::cast_u32(TM_msg * m, uint32_t * dst) |
Overdrivr | 1:e51abb43c074 | 60 | { |
Overdrivr | 1:e51abb43c074 | 61 | return emplace_u32(m,dst); |
Overdrivr | 1:e51abb43c074 | 62 | } |
Overdrivr | 1:e51abb43c074 | 63 | |
Overdrivr | 1:e51abb43c074 | 64 | uint32_t Telemetry::cast_i8(TM_msg * m, int8_t * dst) |
Overdrivr | 1:e51abb43c074 | 65 | { |
Overdrivr | 1:e51abb43c074 | 66 | return emplace_i8(m,dst); |
Overdrivr | 1:e51abb43c074 | 67 | } |
Overdrivr | 1:e51abb43c074 | 68 | |
Overdrivr | 1:e51abb43c074 | 69 | uint32_t Telemetry::cast_i16(TM_msg * m, int16_t * dst) |
Overdrivr | 1:e51abb43c074 | 70 | { |
Overdrivr | 1:e51abb43c074 | 71 | return emplace_i16(m,dst); |
Overdrivr | 1:e51abb43c074 | 72 | } |
Overdrivr | 1:e51abb43c074 | 73 | |
Overdrivr | 1:e51abb43c074 | 74 | uint32_t Telemetry::cast_i32(TM_msg * m, int32_t * dst) |
Overdrivr | 1:e51abb43c074 | 75 | { |
Overdrivr | 1:e51abb43c074 | 76 | return emplace_i32(m,dst); |
Overdrivr | 1:e51abb43c074 | 77 | } |
Overdrivr | 1:e51abb43c074 | 78 | |
Overdrivr | 1:e51abb43c074 | 79 | uint32_t Telemetry::cast_f32(TM_msg * m, float * dst) |
Overdrivr | 1:e51abb43c074 | 80 | { |
Overdrivr | 1:e51abb43c074 | 81 | return emplace_f32(m,dst); |
Overdrivr | 1:e51abb43c074 | 82 | } |
Overdrivr | 1:e51abb43c074 | 83 | |
Overdrivr | 1:e51abb43c074 | 84 | void Telemetry::pub(const char * topic, char * msg) |
Overdrivr | 1:e51abb43c074 | 85 | { |
Overdrivr | 1:e51abb43c074 | 86 | publish(topic,msg); |
Overdrivr | 1:e51abb43c074 | 87 | } |
Overdrivr | 1:e51abb43c074 | 88 | |
Overdrivr | 1:e51abb43c074 | 89 | void Telemetry::pub_u8(const char * topic, uint8_t msg) |
Overdrivr | 1:e51abb43c074 | 90 | { |
Overdrivr | 1:e51abb43c074 | 91 | publish_u8(topic,msg); |
Overdrivr | 1:e51abb43c074 | 92 | } |
Overdrivr | 1:e51abb43c074 | 93 | |
Overdrivr | 1:e51abb43c074 | 94 | void Telemetry::pub_u16(const char * topic, uint16_t msg) |
Overdrivr | 1:e51abb43c074 | 95 | { |
Overdrivr | 1:e51abb43c074 | 96 | publish_u16(topic,msg); |
Overdrivr | 1:e51abb43c074 | 97 | } |
Overdrivr | 1:e51abb43c074 | 98 | |
Overdrivr | 1:e51abb43c074 | 99 | void Telemetry::pub_u32(const char * topic, uint32_t msg) |
Overdrivr | 1:e51abb43c074 | 100 | { |
Overdrivr | 1:e51abb43c074 | 101 | publish_u32(topic,msg); |
Overdrivr | 1:e51abb43c074 | 102 | } |
Overdrivr | 1:e51abb43c074 | 103 | |
Overdrivr | 1:e51abb43c074 | 104 | void Telemetry::pub_i8(const char * topic, int8_t msg) |
Overdrivr | 1:e51abb43c074 | 105 | { |
Overdrivr | 1:e51abb43c074 | 106 | publish_i8(topic,msg); |
Overdrivr | 1:e51abb43c074 | 107 | } |
Overdrivr | 1:e51abb43c074 | 108 | |
Overdrivr | 1:e51abb43c074 | 109 | void Telemetry::pub_i16(const char * topic, int16_t msg) |
Overdrivr | 1:e51abb43c074 | 110 | { |
Overdrivr | 1:e51abb43c074 | 111 | publish_i16(topic,msg); |
Overdrivr | 1:e51abb43c074 | 112 | } |
Overdrivr | 1:e51abb43c074 | 113 | |
Overdrivr | 1:e51abb43c074 | 114 | void Telemetry::pub_i32(const char * topic, int32_t msg) |
Overdrivr | 1:e51abb43c074 | 115 | { |
Overdrivr | 1:e51abb43c074 | 116 | publish_i32(topic,msg); |
Overdrivr | 1:e51abb43c074 | 117 | } |
Overdrivr | 1:e51abb43c074 | 118 | |
Overdrivr | 1:e51abb43c074 | 119 | void Telemetry::pub_f32(const char * topic, float msg) |
Overdrivr | 1:e51abb43c074 | 120 | { |
Overdrivr | 1:e51abb43c074 | 121 | publish_f32(topic,msg); |
Overdrivr | 1:e51abb43c074 | 122 | } |
Overdrivr | 1:e51abb43c074 | 123 | |
Overdrivr | 1:e51abb43c074 | 124 | void Telemetry::sub(void (*callback)(TM_state * s, TM_msg * m)) |
Overdrivr | 1:e51abb43c074 | 125 | { |
Overdrivr | 1:e51abb43c074 | 126 | subscribe(callback); |
Overdrivr | 1:e51abb43c074 | 127 | } |
Overdrivr | 1:e51abb43c074 | 128 | |
Overdrivr | 1:e51abb43c074 | 129 | void Telemetry::update() |
Overdrivr | 1:e51abb43c074 | 130 | { |
Overdrivr | 1:e51abb43c074 | 131 | update_telemetry(0); |
Overdrivr | 1:e51abb43c074 | 132 | } |