00001 00033 #ifndef __CNTRONBASE_H__ 00034 #define __CNTRONBASE_H__ 00035 00036 #include <termios.h> 00037 #include <string> 00038 #include <time.h> 00039 #include <vector> 00040 #include <map> 00041 00042 #define MAX_AGE 100 00043 #define MAX_NO_ACK 20 00044 #define PENALIZACION 5 00045 #define DEFAULT_ID -1 00046 // Max. time a beacon can be penalized (seconds) 00047 #define MAX_PENALIZATION_TIME 15 00048 00049 #define RANGETO(ID) std::string("RangeTo ") + ID + "\r\n" 00050 #define GETBEACONS(AGE) std::string("GetNodeIDList ") + #AGE + "\r\n" 00051 #define READNODEID std::string("ReadNodeIDAdd\r\n") 00052 00054 struct CNTronRange { 00055 int emitterId; // Unique emitter node ID 00056 int beaconId; // Unique recever node ID 00057 int time; // Age of the range. 00058 float range; // Estimated range in meters 00059 }; 00060 00062 struct CNTronNode { 00063 int failures; 00064 int penalization; 00065 int id; 00066 timespec penalizationTime; 00067 char mac[13]; 00068 }; 00069 00070 class CNTronBase { 00071 public: 00072 00074 CNTronBase(int baseId = DEFAULT_ID); 00075 00077 ~CNTronBase(void); 00078 00092 int init(const char *pDev); 00093 00095 void finish(void); 00096 00114 int readRange(unsigned int node, CNTronRange& pData, std::string& msg); 00115 00119 unsigned int numBeacons() const; 00120 00129 int checkPenalization(CNTronNode& nodeInf); 00130 00132 int getBaseId() const; 00133 00142 int detectBeacons(); 00143 00144 // Print functions 00145 void printBeacons() const; 00146 00147 protected: 00148 00156 int readBaseID(); 00157 00166 int sendCommand(const char* command, int size); 00167 00178 int chartohex(char * cnum); 00179 00181 int m_portHandler; 00182 00184 char m_readBuff[256]; 00185 00187 int m_baseId; 00188 00190 std::vector<int> m_nodeIDs; 00191 00193 std::map<int, CNTronNode> m_nodes; 00194 }; 00195 00196 #endif 00197