Library for XBee API targeted toward functions with specific use in conjunction with the Pololu 3pi Robot. Work in Progress

Committer:
sleighton
Date:
Sun Jan 31 20:01:54 2016 +0000
Revision:
10:cb1d91c06093
Parent:
9:d5e7e772d5a4
Child:
11:6b699617fc7f
Includes commandX, commandY and commandFlag and recognises coordinator commands

Who changed what in which revision?

UserRevisionLine numberNew 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 4:af08c7749f9d 8 std::vector<uint8_t> addr; //network address vector
sleighton 4:af08c7749f9d 9 int nodeNum; //index
sleighton 8:7e936dc02dec 10 int x;
sleighton 8:7e936dc02dec 11 int y;
sleighton 9:d5e7e772d5a4 12 int heading;
sleighton 4:af08c7749f9d 13 public:
sleighton 4:af08c7749f9d 14 NetworkNode(std::vector<uint8_t> & addrIn, int indexIn);
sleighton 4:af08c7749f9d 15 //constructor
sleighton 4:af08c7749f9d 16
sleighton 4:af08c7749f9d 17 std::vector<uint8_t> getAddr();
sleighton 4:af08c7749f9d 18 //returns address
sleighton 4:af08c7749f9d 19
sleighton 4:af08c7749f9d 20 int getIndex();
sleighton 4:af08c7749f9d 21 //returns index
sleighton 4:af08c7749f9d 22
sleighton 8:7e936dc02dec 23 int getX();
sleighton 8:7e936dc02dec 24 //returns x coordinate
sleighton 8:7e936dc02dec 25
sleighton 8:7e936dc02dec 26 int getY();
sleighton 8:7e936dc02dec 27 //returns y coordinate
sleighton 8:7e936dc02dec 28
sleighton 9:d5e7e772d5a4 29 int getHeading();
sleighton 9:d5e7e772d5a4 30 //returns heading
sleighton 9:d5e7e772d5a4 31
sleighton 9:d5e7e772d5a4 32 void setCoordinates(int x_in, int y_in, int heading_in);
sleighton 8:7e936dc02dec 33 //sets coordinates
sleighton 8:7e936dc02dec 34
sleighton 4:af08c7749f9d 35 void setAddr(std::vector<uint8_t> & addrIn);
sleighton 4:af08c7749f9d 36 //sets address
sleighton 4:af08c7749f9d 37
sleighton 4:af08c7749f9d 38 void setIndex(int indexIn);
sleighton 4:af08c7749f9d 39 //sets index
sleighton 4:af08c7749f9d 40 };
sleighton 4:af08c7749f9d 41
sleighton 5:190b9e1a3cc1 42
sleighton 2:5040ec01dba1 43 class XBee_Robot {
sleighton 2:5040ec01dba1 44 private:
sleighton 9:d5e7e772d5a4 45
sleighton 8:7e936dc02dec 46 int currentIndex; //current index of NetworkNode for received packet, allows coordinates to be updated
sleighton 2:5040ec01dba1 47
sleighton 4:af08c7749f9d 48 std::vector< NetworkNode > node_list; //list of network nodes
sleighton 2:5040ec01dba1 49
sleighton 2:5040ec01dba1 50 Serial dataLink; //declare global serial
sleighton 2:5040ec01dba1 51
sleighton 10:cb1d91c06093 52 int commandX; // x coordinate received as commanded by the coordinator
sleighton 10:cb1d91c06093 53
sleighton 10:cb1d91c06093 54 int commandY; //y coordinate received as commanded by the coordinator
sleighton 10:cb1d91c06093 55
sleighton 10:cb1d91c06093 56 int commandFlag; // flag that indicates if coordinates from the coordinator have been received
sleighton 10:cb1d91c06093 57
sleighton 2:5040ec01dba1 58 public:
sleighton 2:5040ec01dba1 59
sleighton 2:5040ec01dba1 60 XBee_Robot(PinName _txIn, PinName _rxIn);
sleighton 2:5040ec01dba1 61 //constructor for XBee
sleighton 2:5040ec01dba1 62
sleighton 2:5040ec01dba1 63 void setRxInterrupt();
sleighton 2:5040ec01dba1 64 //enables interrupt for receive pin
sleighton 2:5040ec01dba1 65
sleighton 2:5040ec01dba1 66 void Rx_interrupt();
sleighton 2:5040ec01dba1 67 //ISR for receive pin
sleighton 2:5040ec01dba1 68
sleighton 2:5040ec01dba1 69 void transmitRequest(uint8_t *BitAddress64, uint8_t *BitAddress16, uint8_t broadcastRadius, uint8_t options, uint8_t *data,size_t dataLength);
sleighton 2:5040ec01dba1 70 //assembles and sends transmission requests
sleighton 2:5040ec01dba1 71
sleighton 6:fb0316cafaa6 72 void ATQuery(uint8_t ATu, uint8_t ATl);
sleighton 6:fb0316cafaa6 73 //assembled and sends AT requests with no data byte in order to query the AT configuration of the XBee
sleighton 6:fb0316cafaa6 74
sleighton 2:5040ec01dba1 75 uint8_t calculateChecksum(std::vector<uint8_t> & packet);
sleighton 2:5040ec01dba1 76 //calculates checksum for assembled packets
sleighton 3:cf539cfd3d59 77
sleighton 3:cf539cfd3d59 78 void RxPacketControl(std::vector<uint8_t> & packet);
sleighton 3:cf539cfd3d59 79 //seperates packets depending on API command
sleighton 3:cf539cfd3d59 80
sleighton 3:cf539cfd3d59 81 void checkSourceAddr(std::vector<uint8_t> & addr);
sleighton 3:cf539cfd3d59 82 //checks source address of received packet against list of known addresses and adds new addresses
sleighton 7:c3acafdb70c0 83
sleighton 7:c3acafdb70c0 84 void RxDataHandler(std::vector<uint8_t> & packet);
sleighton 7:c3acafdb70c0 85 //handles received data based on data command
sleighton 10:cb1d91c06093 86
sleighton 10:cb1d91c06093 87 int getCommandX();
sleighton 10:cb1d91c06093 88 //used by main program to extract received command coordinates
sleighton 10:cb1d91c06093 89
sleighton 10:cb1d91c06093 90 int getCommandY();
sleighton 10:cb1d91c06093 91 //used by main program to extract received command coordinates
sleighton 10:cb1d91c06093 92
sleighton 10:cb1d91c06093 93 int getCommandFlag();
sleighton 10:cb1d91c06093 94 //used by main program to poll command flag
sleighton 10:cb1d91c06093 95
sleighton 10:cb1d91c06093 96 void resetCommandFlag();
sleighton 10:cb1d91c06093 97 //used by main program to reset command flag
sleighton 4:af08c7749f9d 98 };