Library for XBee API targeted toward functions with specific use in conjunction with the Pololu 3pi Robot. Work in Progress
XBee_Robot.h@12:a7ec1238373e, 2016-03-04 (annotated)
- Committer:
- sleighton
- Date:
- Fri Mar 04 18:46:05 2016 +0000
- Revision:
- 12:a7ec1238373e
- Parent:
- 11:6b699617fc7f
Before Tidy up
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sleighton | 2:5040ec01dba1 | 1 | #include "mbed.h" |
sleighton | 2:5040ec01dba1 | 2 | #include <vector> |
sleighton | 3:cf539cfd3d59 | 3 | #include <list> |
sleighton | 3:cf539cfd3d59 | 4 | #include <algorithm> |
sleighton | 2:5040ec01dba1 | 5 | |
sleighton | 4:af08c7749f9d | 6 | class NetworkNode{ |
sleighton | 4:af08c7749f9d | 7 | private: |
sleighton | 11:6b699617fc7f | 8 | std::vector<uint8_t> addr; //16 bit network address vector |
sleighton | 11:6b699617fc7f | 9 | std::vector<uint8_t> addr64; //64 bit network address vector |
sleighton | 4:af08c7749f9d | 10 | int nodeNum; //index |
sleighton | 12:a7ec1238373e | 11 | int x; //x coordinate |
sleighton | 12:a7ec1238373e | 12 | int y; //y coordinate |
sleighton | 12:a7ec1238373e | 13 | int heading; //heading |
sleighton | 4:af08c7749f9d | 14 | public: |
sleighton | 4:af08c7749f9d | 15 | NetworkNode(std::vector<uint8_t> & addrIn, int indexIn); |
sleighton | 4:af08c7749f9d | 16 | //constructor |
sleighton | 4:af08c7749f9d | 17 | |
sleighton | 11:6b699617fc7f | 18 | NetworkNode(std::vector<uint8_t> & addrIn, std::vector<uint8_t> & addr64In,int indexIn); |
sleighton | 11:6b699617fc7f | 19 | //constructor including 64 bit address |
sleighton | 11:6b699617fc7f | 20 | |
sleighton | 4:af08c7749f9d | 21 | std::vector<uint8_t> getAddr(); |
sleighton | 4:af08c7749f9d | 22 | //returns address |
sleighton | 4:af08c7749f9d | 23 | |
sleighton | 11:6b699617fc7f | 24 | std::vector<uint8_t> getAddr64(); |
sleighton | 11:6b699617fc7f | 25 | //returns 64 bit address |
sleighton | 11:6b699617fc7f | 26 | |
sleighton | 4:af08c7749f9d | 27 | int getIndex(); |
sleighton | 4:af08c7749f9d | 28 | //returns index |
sleighton | 4:af08c7749f9d | 29 | |
sleighton | 8:7e936dc02dec | 30 | int getX(); |
sleighton | 8:7e936dc02dec | 31 | //returns x coordinate |
sleighton | 8:7e936dc02dec | 32 | |
sleighton | 8:7e936dc02dec | 33 | int getY(); |
sleighton | 8:7e936dc02dec | 34 | //returns y coordinate |
sleighton | 8:7e936dc02dec | 35 | |
sleighton | 9:d5e7e772d5a4 | 36 | int getHeading(); |
sleighton | 9:d5e7e772d5a4 | 37 | //returns heading |
sleighton | 9:d5e7e772d5a4 | 38 | |
sleighton | 9:d5e7e772d5a4 | 39 | void setCoordinates(int x_in, int y_in, int heading_in); |
sleighton | 8:7e936dc02dec | 40 | //sets coordinates |
sleighton | 8:7e936dc02dec | 41 | |
sleighton | 4:af08c7749f9d | 42 | void setAddr(std::vector<uint8_t> & addrIn); |
sleighton | 4:af08c7749f9d | 43 | //sets address |
sleighton | 4:af08c7749f9d | 44 | |
sleighton | 4:af08c7749f9d | 45 | void setIndex(int indexIn); |
sleighton | 4:af08c7749f9d | 46 | //sets index |
sleighton | 4:af08c7749f9d | 47 | }; |
sleighton | 4:af08c7749f9d | 48 | |
sleighton | 5:190b9e1a3cc1 | 49 | |
sleighton | 2:5040ec01dba1 | 50 | class XBee_Robot { |
sleighton | 2:5040ec01dba1 | 51 | private: |
sleighton | 9:d5e7e772d5a4 | 52 | |
sleighton | 12:a7ec1238373e | 53 | std::vector< vector <int> > obstacles; // 2D vector to hold positions of obstacles |
sleighton | 12:a7ec1238373e | 54 | |
sleighton | 8:7e936dc02dec | 55 | int currentIndex; //current index of NetworkNode for received packet, allows coordinates to be updated |
sleighton | 2:5040ec01dba1 | 56 | |
sleighton | 4:af08c7749f9d | 57 | std::vector< NetworkNode > node_list; //list of network nodes |
sleighton | 2:5040ec01dba1 | 58 | |
sleighton | 2:5040ec01dba1 | 59 | Serial dataLink; //declare global serial |
sleighton | 2:5040ec01dba1 | 60 | |
sleighton | 10:cb1d91c06093 | 61 | int commandX; // x coordinate received as commanded by the coordinator |
sleighton | 10:cb1d91c06093 | 62 | |
sleighton | 10:cb1d91c06093 | 63 | int commandY; //y coordinate received as commanded by the coordinator |
sleighton | 10:cb1d91c06093 | 64 | |
sleighton | 10:cb1d91c06093 | 65 | int commandFlag; // flag that indicates if coordinates from the coordinator have been received |
sleighton | 10:cb1d91c06093 | 66 | |
sleighton | 12:a7ec1238373e | 67 | int finishedFlag; // flag that indictates if the router robots have finished their journey (coordinator use only) |
sleighton | 12:a7ec1238373e | 68 | |
sleighton | 2:5040ec01dba1 | 69 | public: |
sleighton | 2:5040ec01dba1 | 70 | |
sleighton | 2:5040ec01dba1 | 71 | XBee_Robot(PinName _txIn, PinName _rxIn); |
sleighton | 2:5040ec01dba1 | 72 | //constructor for XBee |
sleighton | 2:5040ec01dba1 | 73 | |
sleighton | 2:5040ec01dba1 | 74 | void Rx_interrupt(); |
sleighton | 2:5040ec01dba1 | 75 | //ISR for receive pin |
sleighton | 2:5040ec01dba1 | 76 | |
sleighton | 2:5040ec01dba1 | 77 | void transmitRequest(uint8_t *BitAddress64, uint8_t *BitAddress16, uint8_t broadcastRadius, uint8_t options, uint8_t *data,size_t dataLength); |
sleighton | 2:5040ec01dba1 | 78 | //assembles and sends transmission requests |
sleighton | 2:5040ec01dba1 | 79 | |
sleighton | 6:fb0316cafaa6 | 80 | void ATQuery(uint8_t ATu, uint8_t ATl); |
sleighton | 6:fb0316cafaa6 | 81 | //assembled and sends AT requests with no data byte in order to query the AT configuration of the XBee |
sleighton | 6:fb0316cafaa6 | 82 | |
sleighton | 2:5040ec01dba1 | 83 | uint8_t calculateChecksum(std::vector<uint8_t> & packet); |
sleighton | 2:5040ec01dba1 | 84 | //calculates checksum for assembled packets |
sleighton | 3:cf539cfd3d59 | 85 | |
sleighton | 3:cf539cfd3d59 | 86 | void RxPacketControl(std::vector<uint8_t> & packet); |
sleighton | 3:cf539cfd3d59 | 87 | //seperates packets depending on API command |
sleighton | 3:cf539cfd3d59 | 88 | |
sleighton | 11:6b699617fc7f | 89 | void checkSourceAddr(std::vector<uint8_t> & addr, std::vector<uint8_t> & addr64); |
sleighton | 11:6b699617fc7f | 90 | //checks 16 bit source address of received packet against list of known addresses and adds new addresses (16 and 64 bit) |
sleighton | 11:6b699617fc7f | 91 | |
sleighton | 3:cf539cfd3d59 | 92 | void checkSourceAddr(std::vector<uint8_t> & addr); |
sleighton | 11:6b699617fc7f | 93 | //checks 16 bit source address of received packet against list of known addresses and adds new addresses (16 bit only) |
sleighton | 7:c3acafdb70c0 | 94 | |
sleighton | 7:c3acafdb70c0 | 95 | void RxDataHandler(std::vector<uint8_t> & packet); |
sleighton | 7:c3acafdb70c0 | 96 | //handles received data based on data command |
sleighton | 10:cb1d91c06093 | 97 | |
sleighton | 10:cb1d91c06093 | 98 | int getCommandX(); |
sleighton | 10:cb1d91c06093 | 99 | //used by main program to extract received command coordinates |
sleighton | 10:cb1d91c06093 | 100 | |
sleighton | 10:cb1d91c06093 | 101 | int getCommandY(); |
sleighton | 10:cb1d91c06093 | 102 | //used by main program to extract received command coordinates |
sleighton | 10:cb1d91c06093 | 103 | |
sleighton | 10:cb1d91c06093 | 104 | int getCommandFlag(); |
sleighton | 10:cb1d91c06093 | 105 | //used by main program to poll command flag |
sleighton | 10:cb1d91c06093 | 106 | |
sleighton | 12:a7ec1238373e | 107 | int getFinishedFlag(); |
sleighton | 12:a7ec1238373e | 108 | //used by main program to poll finished flag (coordinator use only) |
sleighton | 12:a7ec1238373e | 109 | |
sleighton | 12:a7ec1238373e | 110 | void resetFinishedFlag(); |
sleighton | 12:a7ec1238373e | 111 | //used by main program to reset finished flag (coordinator use only) |
sleighton | 12:a7ec1238373e | 112 | |
sleighton | 10:cb1d91c06093 | 113 | void resetCommandFlag(); |
sleighton | 10:cb1d91c06093 | 114 | //used by main program to reset command flag |
sleighton | 12:a7ec1238373e | 115 | |
sleighton | 12:a7ec1238373e | 116 | int checkObstacle(int x_in, int y_in); |
sleighton | 12:a7ec1238373e | 117 | //used by main program to check if an obstacle exists at given coordinates (coordinator use only) |
sleighton | 12:a7ec1238373e | 118 | |
sleighton | 12:a7ec1238373e | 119 | int convSigned(int int_in); |
sleighton | 12:a7ec1238373e | 120 | //used to convert unsigned 8 bit integers to signed integers |
sleighton | 4:af08c7749f9d | 121 | }; |