rosserial library for mbed Inspired by nucho's rosserial library This library is still under development
Dependents: mbed_roshydro_test
Library still under development!
MbedHardware.h@0:30537dec6e0b, 2015-02-15 (annotated)
- Committer:
- akashvibhute
- Date:
- Sun Feb 15 10:53:43 2015 +0000
- Revision:
- 0:30537dec6e0b
First commit; Library still need to be debugged, compilation issues with new mbed and modserial updates.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
akashvibhute | 0:30537dec6e0b | 1 | /* |
akashvibhute | 0:30537dec6e0b | 2 | * MbedHardware |
akashvibhute | 0:30537dec6e0b | 3 | * |
akashvibhute | 0:30537dec6e0b | 4 | * Created on: Aug 17, 2011 |
akashvibhute | 0:30537dec6e0b | 5 | * Author: nucho |
akashvibhute | 0:30537dec6e0b | 6 | */ |
akashvibhute | 0:30537dec6e0b | 7 | |
akashvibhute | 0:30537dec6e0b | 8 | #ifndef MBEDHARDWARE_H_ |
akashvibhute | 0:30537dec6e0b | 9 | #define MBEDHARDWARE_H_ |
akashvibhute | 0:30537dec6e0b | 10 | |
akashvibhute | 0:30537dec6e0b | 11 | #include"mbed.h" |
akashvibhute | 0:30537dec6e0b | 12 | #include"MODSERIAL.h" |
akashvibhute | 0:30537dec6e0b | 13 | |
akashvibhute | 0:30537dec6e0b | 14 | #ifndef ROSSERIAL_BAUDRATE |
akashvibhute | 0:30537dec6e0b | 15 | #define ROSSERIAL_BAUDRATE 57600 |
akashvibhute | 0:30537dec6e0b | 16 | #endif |
akashvibhute | 0:30537dec6e0b | 17 | |
akashvibhute | 0:30537dec6e0b | 18 | |
akashvibhute | 0:30537dec6e0b | 19 | class MbedHardware { |
akashvibhute | 0:30537dec6e0b | 20 | public: |
akashvibhute | 0:30537dec6e0b | 21 | MbedHardware(MODSERIAL* io, int baud= ROSSERIAL_BAUDRATE):iostream(*io){ |
akashvibhute | 0:30537dec6e0b | 22 | baud_ = baud; |
akashvibhute | 0:30537dec6e0b | 23 | t.start(); |
akashvibhute | 0:30537dec6e0b | 24 | } |
akashvibhute | 0:30537dec6e0b | 25 | MbedHardware():iostream(USBTX, USBRX) { |
akashvibhute | 0:30537dec6e0b | 26 | baud_ = ROSSERIAL_BAUDRATE; |
akashvibhute | 0:30537dec6e0b | 27 | t.start(); |
akashvibhute | 0:30537dec6e0b | 28 | } |
akashvibhute | 0:30537dec6e0b | 29 | MbedHardware(MbedHardware& h):iostream(h.iostream) { |
akashvibhute | 0:30537dec6e0b | 30 | this->baud_ = h.baud_; |
akashvibhute | 0:30537dec6e0b | 31 | |
akashvibhute | 0:30537dec6e0b | 32 | t.start(); |
akashvibhute | 0:30537dec6e0b | 33 | } |
akashvibhute | 0:30537dec6e0b | 34 | |
akashvibhute | 0:30537dec6e0b | 35 | void setBaud(int baud) { |
akashvibhute | 0:30537dec6e0b | 36 | this->baud_= baud; |
akashvibhute | 0:30537dec6e0b | 37 | } |
akashvibhute | 0:30537dec6e0b | 38 | |
akashvibhute | 0:30537dec6e0b | 39 | int getBaud() { |
akashvibhute | 0:30537dec6e0b | 40 | return baud_; |
akashvibhute | 0:30537dec6e0b | 41 | } |
akashvibhute | 0:30537dec6e0b | 42 | |
akashvibhute | 0:30537dec6e0b | 43 | void init() { |
akashvibhute | 0:30537dec6e0b | 44 | iostream.baud(baud_); |
akashvibhute | 0:30537dec6e0b | 45 | } |
akashvibhute | 0:30537dec6e0b | 46 | |
akashvibhute | 0:30537dec6e0b | 47 | int read() { |
akashvibhute | 0:30537dec6e0b | 48 | if (iostream.readable()) { |
akashvibhute | 0:30537dec6e0b | 49 | return iostream.getc(); |
akashvibhute | 0:30537dec6e0b | 50 | } else { |
akashvibhute | 0:30537dec6e0b | 51 | return -1; |
akashvibhute | 0:30537dec6e0b | 52 | } |
akashvibhute | 0:30537dec6e0b | 53 | }; |
akashvibhute | 0:30537dec6e0b | 54 | void write(uint8_t* data, int length) { |
akashvibhute | 0:30537dec6e0b | 55 | for (int i=0; i<length; i++) iostream.putc(data[i]); |
akashvibhute | 0:30537dec6e0b | 56 | } |
akashvibhute | 0:30537dec6e0b | 57 | |
akashvibhute | 0:30537dec6e0b | 58 | unsigned long time() { |
akashvibhute | 0:30537dec6e0b | 59 | return t.read_ms(); |
akashvibhute | 0:30537dec6e0b | 60 | } |
akashvibhute | 0:30537dec6e0b | 61 | |
akashvibhute | 0:30537dec6e0b | 62 | protected: |
akashvibhute | 0:30537dec6e0b | 63 | int baud_; |
akashvibhute | 0:30537dec6e0b | 64 | MODSERIAL iostream; |
akashvibhute | 0:30537dec6e0b | 65 | Timer t; |
akashvibhute | 0:30537dec6e0b | 66 | }; |
akashvibhute | 0:30537dec6e0b | 67 | |
akashvibhute | 0:30537dec6e0b | 68 | |
akashvibhute | 0:30537dec6e0b | 69 | #endif /* MBEDHARDWARE_H_ */ |