Mario Bambagini / ssWi

Dependents:   rover_car rover_pc supervisor watering_unit ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers xbee.hpp Source File

xbee.hpp

Go to the documentation of this file.
00001 /** \file xbee.hpp
00002  *  \brief header of the ssWi channel using the XBee module
00003  *
00004  */
00005 
00006 #ifndef __XBEE_MODULE_HPP__
00007 #define __XBEE_MODULE_HPP__
00008 
00009 #include "mbed.h"
00010 
00011 #include <ssWiChannel.hpp>
00012 
00013 #include "string"
00014 
00015 
00016 class XBeeAddress
00017 {
00018     uint32_t low;
00019     uint32_t high;
00020 
00021 public:
00022 
00023     XBeeAddress () : low(0), high(0) {}
00024 
00025     XBeeAddress (uint32_t low, uint32_t high) {
00026         this->low = low;
00027         this->high = high;
00028     }
00029     
00030     void setAddress(uint32_t low, uint32_t high) {
00031         this->low = low;
00032         this->high = high;
00033     }
00034     
00035     uint32_t getLowAddr () {
00036         return low;
00037     }
00038     
00039     uint32_t getHighAddr () {
00040         return high;
00041     }
00042 };
00043 
00044 
00045 class XBeeBroadcastAddress: public XBeeAddress
00046 {
00047 public:
00048     XBeeBroadcastAddress () : XBeeAddress(0x00FFFF, 0) {}
00049 };
00050 
00051 
00052 class XBeeModule: public ssWiChannel
00053 {
00054 
00055     Serial serial_xbee;
00056     XBeeAddress local;
00057 
00058     bool status;
00059 
00060     bool executeWithOk (const char* cmd);
00061     void executeWithRes (const char* cmd, char* res);
00062     void readResponse (char* msg);
00063 
00064     bool _getLocalAddr ();
00065     bool _setChannel (int channel);
00066     bool _setPanID (int id);
00067     
00068     bool initSequence();
00069 
00070  public:
00071 
00072     XBeeModule (PinName tx, PinName rx, int panID, int channel);
00073 
00074     /*
00075      * specific for the XBee module
00076      */
00077     XBeeAddress getLocalAddress () {
00078         return local;
00079     }
00080 
00081     bool setDstAddress (XBeeAddress addr);
00082 
00083     bool getDstAddress(XBeeAddress &addr);
00084 
00085     int getChannel ();
00086     
00087     int getPanID ();
00088 
00089 
00090     /*
00091      * inherited from ssWiChannel
00092      */
00093     virtual bool init (int TXRate, int RXRate) {
00094         return _init(this, TXRate, RXRate);
00095     }
00096 
00097     virtual int read (char* msg);
00098     
00099     virtual void write (const char* msg, int n);
00100     
00101 };
00102 
00103 #endif //__XBEE_MODULE_HPP__