Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
XBee_Robot.h
00001 #include "mbed.h" 00002 #include <vector> 00003 #include <list> 00004 #include <algorithm> 00005 00006 class NetworkNode{ 00007 private: 00008 std::vector<uint8_t> addr; //16 bit network address vector 00009 std::vector<uint8_t> addr64; //64 bit network address vector 00010 int nodeNum; //index 00011 int x; //x coordinate 00012 int y; //y coordinate 00013 int heading; //heading 00014 public: 00015 NetworkNode(std::vector<uint8_t> & addrIn, int indexIn); 00016 //constructor 00017 00018 NetworkNode(std::vector<uint8_t> & addrIn, std::vector<uint8_t> & addr64In,int indexIn); 00019 //constructor including 64 bit address 00020 00021 std::vector<uint8_t> getAddr(); 00022 //returns address 00023 00024 std::vector<uint8_t> getAddr64(); 00025 //returns 64 bit address 00026 00027 int getIndex(); 00028 //returns index 00029 00030 int getX(); 00031 //returns x coordinate 00032 00033 int getY(); 00034 //returns y coordinate 00035 00036 int getHeading(); 00037 //returns heading 00038 00039 void setCoordinates(int x_in, int y_in, int heading_in); 00040 //sets coordinates 00041 00042 void setAddr(std::vector<uint8_t> & addrIn); 00043 //sets address 00044 00045 void setIndex(int indexIn); 00046 //sets index 00047 }; 00048 00049 00050 class XBee_Robot { 00051 private: 00052 00053 std::vector< vector <int> > obstacles; // 2D vector to hold positions of obstacles 00054 00055 int currentIndex; //current index of NetworkNode for received packet, allows coordinates to be updated 00056 00057 std::vector< NetworkNode > node_list; //list of network nodes 00058 00059 Serial dataLink; //declare global serial 00060 00061 int commandX; // x coordinate received as commanded by the coordinator 00062 00063 int commandY; //y coordinate received as commanded by the coordinator 00064 00065 int commandFlag; // flag that indicates if coordinates from the coordinator have been received 00066 00067 int finishedFlag; // flag that indictates if the router robots have finished their journey (coordinator use only) 00068 00069 public: 00070 00071 XBee_Robot(PinName _txIn, PinName _rxIn); 00072 //constructor for XBee 00073 00074 void Rx_interrupt(); 00075 //ISR for receive pin 00076 00077 void transmitRequest(uint8_t *BitAddress64, uint8_t *BitAddress16, uint8_t broadcastRadius, uint8_t options, uint8_t *data,size_t dataLength); 00078 //assembles and sends transmission requests 00079 00080 void ATQuery(uint8_t ATu, uint8_t ATl); 00081 //assembled and sends AT requests with no data byte in order to query the AT configuration of the XBee 00082 00083 uint8_t calculateChecksum(std::vector<uint8_t> & packet); 00084 //calculates checksum for assembled packets 00085 00086 void RxPacketControl(std::vector<uint8_t> & packet); 00087 //seperates packets depending on API command 00088 00089 void checkSourceAddr(std::vector<uint8_t> & addr, std::vector<uint8_t> & addr64); 00090 //checks 16 bit source address of received packet against list of known addresses and adds new addresses (16 and 64 bit) 00091 00092 void checkSourceAddr(std::vector<uint8_t> & addr); 00093 //checks 16 bit source address of received packet against list of known addresses and adds new addresses (16 bit only) 00094 00095 void RxDataHandler(std::vector<uint8_t> & packet); 00096 //handles received data based on data command 00097 00098 int getCommandX(); 00099 //used by main program to extract received command coordinates 00100 00101 int getCommandY(); 00102 //used by main program to extract received command coordinates 00103 00104 int getCommandFlag(); 00105 //used by main program to poll command flag 00106 00107 int getFinishedFlag(); 00108 //used by main program to poll finished flag (coordinator use only) 00109 00110 void resetFinishedFlag(); 00111 //used by main program to reset finished flag (coordinator use only) 00112 00113 void resetCommandFlag(); 00114 //used by main program to reset command flag 00115 00116 int checkObstacle(int x_in, int y_in); 00117 //used by main program to check if an obstacle exists at given coordinates (coordinator use only) 00118 00119 int convSigned(int int_in); 00120 //used to convert unsigned 8 bit integers to signed integers 00121 };
Generated on Tue Aug 23 2022 14:15:26 by
1.7.2