This program is porting rosserial_arduino for mbed http://www.ros.org/wiki/rosserial_arduino This program supported the revision of 169 of rosserial.

Dependencies:  

Dependents:   rosserial_mbed robot_S2

Committer:
nucho
Date:
Fri Aug 19 09:06:30 2011 +0000
Revision:
0:77afd7560544
Child:
1:ff0ec969dad1

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nucho 0:77afd7560544 1 /*
nucho 0:77afd7560544 2 * mbedHardware
nucho 0:77afd7560544 3 *
nucho 0:77afd7560544 4 * Created on: Aug 17, 2011
nucho 0:77afd7560544 5 * Author: nucho
nucho 0:77afd7560544 6 */
nucho 0:77afd7560544 7
nucho 0:77afd7560544 8 #ifndef MBEDHARDWARE_H_
nucho 0:77afd7560544 9 #define MBEDHARDWARE_H_
nucho 0:77afd7560544 10
nucho 0:77afd7560544 11 #include"mbed.h"
nucho 0:77afd7560544 12
nucho 0:77afd7560544 13 class MbedHardware {
nucho 0:77afd7560544 14 public:
nucho 0:77afd7560544 15 MbedHardware(Serial* io , long baud= 57600)
nucho 0:77afd7560544 16 :iostream(*io){
nucho 0:77afd7560544 17 baud_ = baud;
nucho 0:77afd7560544 18 t.start();
nucho 0:77afd7560544 19 }
nucho 0:77afd7560544 20 MbedHardware()
nucho 0:77afd7560544 21 :iostream(USBTX, USBRX) {
nucho 0:77afd7560544 22 baud_ = 57600;
nucho 0:77afd7560544 23 t.start();
nucho 0:77afd7560544 24 }
nucho 0:77afd7560544 25 MbedHardware(MbedHardware& h)
nucho 0:77afd7560544 26 :iostream(h.iostream) {
nucho 0:77afd7560544 27 this->baud_ = h.baud_;
nucho 0:77afd7560544 28
nucho 0:77afd7560544 29 t.start();
nucho 0:77afd7560544 30 }
nucho 0:77afd7560544 31
nucho 0:77afd7560544 32 void setBaud(long baud) {
nucho 0:77afd7560544 33 this->baud_= baud;
nucho 0:77afd7560544 34 }
nucho 0:77afd7560544 35
nucho 0:77afd7560544 36 int getBaud() {
nucho 0:77afd7560544 37 return baud_;
nucho 0:77afd7560544 38 }
nucho 0:77afd7560544 39
nucho 0:77afd7560544 40 void init() {
nucho 0:77afd7560544 41 iostream.baud(baud_);
nucho 0:77afd7560544 42 }
nucho 0:77afd7560544 43
nucho 0:77afd7560544 44 int read() {
nucho 0:77afd7560544 45 if (iostream.readable()) {
nucho 0:77afd7560544 46 return iostream.getc();
nucho 0:77afd7560544 47 } else {
nucho 0:77afd7560544 48 return -1;
nucho 0:77afd7560544 49 }
nucho 0:77afd7560544 50 };
nucho 0:77afd7560544 51 void write(uint8_t* data, int length) {
nucho 0:77afd7560544 52 for (int i=0; i<length; i++) iostream.putc(data[i]);
nucho 0:77afd7560544 53 }
nucho 0:77afd7560544 54
nucho 0:77afd7560544 55 unsigned long time() {
nucho 0:77afd7560544 56 return t.read_ms();
nucho 0:77afd7560544 57 }
nucho 0:77afd7560544 58
nucho 0:77afd7560544 59 protected:
nucho 0:77afd7560544 60 long baud_;
nucho 0:77afd7560544 61 Serial iostream;
nucho 0:77afd7560544 62 Timer t;
nucho 0:77afd7560544 63 };
nucho 0:77afd7560544 64
nucho 0:77afd7560544 65
nucho 0:77afd7560544 66 #endif /* MBEDHARDWARE_H_ */