#include <cntronbase.h>
Public Member Functions | |
int | checkPenalization (CNTronNode &nodeInf) |
CNTronBase (int baseId=DEFAULT_ID) | |
Default constructor. | |
int | detectBeacons () |
void | finish (void) |
Finish the serial communication (closes serial port) | |
int | getBaseId () const |
Returns the unique identifier of the base node (node connected to PC). | |
int | init (const char *pDev) |
unsigned int | numBeacons () const |
void | printBeacons () const |
int | readRange (unsigned int node, CNTronRange &pData, std::string &msg) |
~CNTronBase (void) | |
Default destructor. | |
Protected Member Functions | |
int | chartohex (char *cnum) |
int | readBaseID () |
int | sendCommand (const char *command, int size) |
Protected Attributes | |
int | m_baseId |
Base Id. | |
std::vector< int > | m_nodeIDs |
Nodes unique ID. | |
std::map< int, CNTronNode > | m_nodes |
Nodes information. | |
int | m_portHandler |
Serial port handler. | |
char | m_readBuff [256] |
Reading buffer. |
Definition at line 70 of file cntronbase.h.
CNTronBase::CNTronBase | ( | int | baseId = DEFAULT_ID | ) |
Default constructor.
Software License Agreement (BSD License)
Copyright (c) 2013-2015 Robotics, Vision and Control Group (GRVC), University of Seville. 2013 Fernando Caballero <fcaballero@us.es> 2014 Felipe R.Fabresse <felramfab@us.es> 2014 Alfredo Vazquez <avringeniero@gmail.com> 2015 Felipe R.Fabresse <felramfab@gmail.com> All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Definition at line 42 of file cntronbase.cpp.
CNTronBase::~CNTronBase | ( | void | ) |
Default destructor.
Definition at line 47 of file cntronbase.cpp.
int CNTronBase::chartohex | ( | char * | cnum | ) | [protected] |
Reads the last part of the MAC address given and returns the ID associated.
This function reads the part of the MAC address associated to the unique ID of Nanotron range sensors, i.e. it reads the last 2 bytes of the MAC address.
cnum | Hexadecimal MAC address. |
Definition at line 409 of file cntronbase.cpp.
int CNTronBase::checkPenalization | ( | CNTronNode & | nodeInf | ) |
Checks if the penalization of a node must be set to 0 beacuse of a delay time.
nodeInf | The node information. |
Definition at line 300 of file cntronbase.cpp.
int CNTronBase::detectBeacons | ( | ) |
Detects the list of beacons available.
Definition at line 320 of file cntronbase.cpp.
void CNTronBase::finish | ( | void | ) |
Finish the serial communication (closes serial port)
Definition at line 127 of file cntronbase.cpp.
int CNTronBase::getBaseId | ( | void | ) | const |
Returns the unique identifier of the base node (node connected to PC).
Definition at line 51 of file cntronbase.cpp.
int CNTronBase::init | ( | const char * | pDev | ) |
Intialize the serial port to the given values. The function open the serial port in read-write mode
pDev | Port of the serial device (e.g. '/dev/ttyUSB0') |
Definition at line 79 of file cntronbase.cpp.
unsigned int CNTronBase::numBeacons | ( | ) | const |
Return the current number of detected nodes.
Definition at line 55 of file cntronbase.cpp.
void CNTronBase::printBeacons | ( | ) | const |
Definition at line 59 of file cntronbase.cpp.
int CNTronBase::readBaseID | ( | ) | [protected] |
Reads the base node ID (MAC of node connected to serial port)
return= -1; Error sending command. [ SendCommand() devuelve -6 ]. return= -5; Empty serial buffer. [ read() devuelve 0 ]. return= 0; Success.
Definition at line 136 of file cntronbase.cpp.
int CNTronBase::readRange | ( | unsigned int | node, |
CNTronRange & | pData, | ||
std::string & | msg | ||
) |
This function parse a complete message sent by the sensor board. First sends a RangeTo command and then reads the result. The beacon to be used for range request is selected automatically, reading periodically the list of available beacons and then selecting the next beacon to be ranged.
Sensor information is sent in binary mode.
node | The node to be requested to range. |
pData | Pointer to the structure where range information will be located. |
msg | A reference to a string where any error message will be saved. |
Definition at line 196 of file cntronbase.cpp.
int CNTronBase::sendCommand | ( | const char * | command, |
int | size | ||
) | [protected] |
Sends a stream of data to the configured serial port.
command | Data stream |
size | Length of the data stream. |
Definition at line 183 of file cntronbase.cpp.
int CNTronBase::m_baseId [protected] |
Base Id.
Definition at line 187 of file cntronbase.h.
std::vector<int> CNTronBase::m_nodeIDs [protected] |
Nodes unique ID.
Definition at line 190 of file cntronbase.h.
std::map<int, CNTronNode> CNTronBase::m_nodes [protected] |
Nodes information.
Definition at line 193 of file cntronbase.h.
int CNTronBase::m_portHandler [protected] |
Serial port handler.
Definition at line 181 of file cntronbase.h.
char CNTronBase::m_readBuff[256] [protected] |
Reading buffer.
Definition at line 184 of file cntronbase.h.