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

Committer:
sleighton
Date:
Tue Feb 02 11:02:48 2016 +0000
Revision:
11:6b699617fc7f
Parent:
10:cb1d91c06093
Child:
12:a7ec1238373e
Handles more received messages

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 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 8:7e936dc02dec 11 int x;
sleighton 8:7e936dc02dec 12 int y;
sleighton 9:d5e7e772d5a4 13 int 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 8:7e936dc02dec 53 int currentIndex; //current index of NetworkNode for received packet, allows coordinates to be updated
sleighton 2:5040ec01dba1 54
sleighton 4:af08c7749f9d 55 std::vector< NetworkNode > node_list; //list of network nodes
sleighton 2:5040ec01dba1 56
sleighton 2:5040ec01dba1 57 Serial dataLink; //declare global serial
sleighton 2:5040ec01dba1 58
sleighton 10:cb1d91c06093 59 int commandX; // x coordinate received as commanded by the coordinator
sleighton 10:cb1d91c06093 60
sleighton 10:cb1d91c06093 61 int commandY; //y coordinate received as commanded by the coordinator
sleighton 10:cb1d91c06093 62
sleighton 10:cb1d91c06093 63 int commandFlag; // flag that indicates if coordinates from the coordinator have been received
sleighton 10:cb1d91c06093 64
sleighton 2:5040ec01dba1 65 public:
sleighton 2:5040ec01dba1 66
sleighton 2:5040ec01dba1 67 XBee_Robot(PinName _txIn, PinName _rxIn);
sleighton 2:5040ec01dba1 68 //constructor for XBee
sleighton 2:5040ec01dba1 69
sleighton 2:5040ec01dba1 70 void setRxInterrupt();
sleighton 2:5040ec01dba1 71 //enables interrupt for receive pin
sleighton 2:5040ec01dba1 72
sleighton 2:5040ec01dba1 73 void Rx_interrupt();
sleighton 2:5040ec01dba1 74 //ISR for receive pin
sleighton 2:5040ec01dba1 75
sleighton 2:5040ec01dba1 76 void transmitRequest(uint8_t *BitAddress64, uint8_t *BitAddress16, uint8_t broadcastRadius, uint8_t options, uint8_t *data,size_t dataLength);
sleighton 2:5040ec01dba1 77 //assembles and sends transmission requests
sleighton 2:5040ec01dba1 78
sleighton 6:fb0316cafaa6 79 void ATQuery(uint8_t ATu, uint8_t ATl);
sleighton 6:fb0316cafaa6 80 //assembled and sends AT requests with no data byte in order to query the AT configuration of the XBee
sleighton 6:fb0316cafaa6 81
sleighton 2:5040ec01dba1 82 uint8_t calculateChecksum(std::vector<uint8_t> & packet);
sleighton 2:5040ec01dba1 83 //calculates checksum for assembled packets
sleighton 3:cf539cfd3d59 84
sleighton 3:cf539cfd3d59 85 void RxPacketControl(std::vector<uint8_t> & packet);
sleighton 3:cf539cfd3d59 86 //seperates packets depending on API command
sleighton 3:cf539cfd3d59 87
sleighton 11:6b699617fc7f 88 void checkSourceAddr(std::vector<uint8_t> & addr, std::vector<uint8_t> & addr64);
sleighton 11:6b699617fc7f 89 //checks 16 bit source address of received packet against list of known addresses and adds new addresses (16 and 64 bit)
sleighton 11:6b699617fc7f 90
sleighton 3:cf539cfd3d59 91 void checkSourceAddr(std::vector<uint8_t> & addr);
sleighton 11:6b699617fc7f 92 //checks 16 bit source address of received packet against list of known addresses and adds new addresses (16 bit only)
sleighton 7:c3acafdb70c0 93
sleighton 7:c3acafdb70c0 94 void RxDataHandler(std::vector<uint8_t> & packet);
sleighton 7:c3acafdb70c0 95 //handles received data based on data command
sleighton 10:cb1d91c06093 96
sleighton 10:cb1d91c06093 97 int getCommandX();
sleighton 10:cb1d91c06093 98 //used by main program to extract received command coordinates
sleighton 10:cb1d91c06093 99
sleighton 10:cb1d91c06093 100 int getCommandY();
sleighton 10:cb1d91c06093 101 //used by main program to extract received command coordinates
sleighton 10:cb1d91c06093 102
sleighton 10:cb1d91c06093 103 int getCommandFlag();
sleighton 10:cb1d91c06093 104 //used by main program to poll command flag
sleighton 10:cb1d91c06093 105
sleighton 10:cb1d91c06093 106 void resetCommandFlag();
sleighton 10:cb1d91c06093 107 //used by main program to reset command flag
sleighton 4:af08c7749f9d 108 };