ROS Serial library for Mbed platforms for ROS Indigo Igloo. Check http://wiki.ros.org/rosserial_mbed/ for more information

Dependencies:   BufferedSerial

Dependents:   rosserial_mbed_hello_world_publisher rtos_base_control rosserial_mbed_F64MA ROS-RTOS ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MbedHardware.h Source File

MbedHardware.h

00001 /*
00002  * MbedHardware
00003  *
00004  *  Created on: Aug 17, 2011
00005  *      Author: nucho
00006  */
00007 
00008 #ifndef ROS_MBED_HARDWARE_H_
00009 #define ROS_MBED_HARDWARE_H_
00010 
00011 #include "mbed.h"
00012 
00013 #include "BufferedSerial.h"
00014 
00015 class MbedHardware {
00016   public:
00017     MbedHardware(PinName tx, PinName rx, long baud = 57600)
00018       :iostream(tx, rx){
00019       baud_ = baud;
00020       t.start();
00021     }
00022 
00023     MbedHardware()
00024       :iostream(USBTX, USBRX) {
00025         baud_ = 57600;
00026         t.start();
00027     }
00028 
00029     void setBaud(long baud){
00030       this->baud_= baud;
00031     }
00032 
00033     int getBaud(){return baud_;}
00034 
00035     void init(){
00036         iostream.baud(baud_);
00037     }
00038 
00039     int read(){
00040         if (iostream.readable()) {
00041             return iostream.getc();
00042         } else {
00043             return -1;
00044         }
00045     };
00046     void write(uint8_t* data, int length) {
00047         for (int i=0; i<length; i++)
00048              iostream.putc(data[i]);
00049     }
00050 
00051     unsigned long time(){return t.read_ms();}
00052 
00053 protected:
00054     BufferedSerial iostream;
00055     long baud_;
00056     Timer t;
00057 };
00058 
00059 
00060 #endif /* ROS_MBED_HARDWARE_H_ */