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:
Wed Feb 29 23:00:21 2012 +0000
Revision:
4:684f39d0c346
Parent:
3:1cf99502f396

        

Who changed what in which revision?

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