Public Member Functions | Private Types | Private Member Functions | Private Attributes
Comm Class Reference

Handles the communication between host computer and the HighLevel Processor (HLP) of the AscTec Autopilot board. More...

#include <comm.h>

List of all members.

Public Member Functions

void close ()
 closes the serial port(s)
 Comm ()
bool connect (const std::string &port_rx, const std::string &port_tx, uint32_t baudrate)
 connects to the specified serial port(s) with the given baudrate. The HLP sets it's baudrate automatically.
uint32_t getRxPackets ()
uint32_t getRxPacketsGood ()
void loopOnce ()
template<class T >
void registerCallback (uint8_t id, void(T::*cb_func)(uint8_t *, uint32_t), T *p_obj)
 registers a class method that gets called when the packet specified by id was sent from the HLP
template<typename T >
bool sendPacket (uint8_t packet_id, const T &data)
 sends a packet to the HLP
template<typename T >
bool sendPacketAck (uint8_t packet_id, const T &data, const double &timeout=1.0)
 sends a packet to the HLP and blocks until it got acknowledged or until the timeout is reached
 ~Comm ()

Private Types

typedef boost::asio::serial_port SerialPort
typedef boost::shared_ptr
< SerialPort
SerialPortPtr

Private Member Functions

bool configurePort (SerialPortPtr &serial_port, uint32_t *baudrate)
bool connect (SerialPortPtr &serial_port, const std::string &port, uint32_t baudrate)
uint16_t crc16 (void *data, uint16_t cnt, uint16_t crc=0xff)
uint16_t crc_update (uint16_t crc, uint8_t data)
void processPacketAck (uint8_t *buf, uint32_t length)
void rxReadCallback (const boost::system::error_code &error, size_t bytes_transferred)
void rxReadStart (uint32_t length, uint32_t timeout=0)
void rxTimeoutCallback (const boost::system::error_code &error)
void serializePacket (uint8_t packet_id, const void *data, const int32_t &packet_size, uint8_t flag=0)
bool validateChecksum (uint8_t *buf, uint32_t length, uint16_t checksum)
bool waitForPacketAck (uint8_t ack_id, const double &timeout=1.0)

Private Attributes

CommCallbackMap callbacks_
std::vector< uint8_t > packet_acks_
SerialPortPtr port_rx_
std::string port_rx_name_
SerialPortPtr port_tx_
std::string port_tx_name_
uint8_t rx_buffer_ [256]
uint32_t rx_packet_cnt_
uint32_t rx_packet_good_cnt_
int rx_state_
boost::asio::deadline_timer rx_timeout_
bool rx_timeout_occurred_
uint8_t tx_buffer_ [256]
uint32_t tx_bytes2send_
const int TX_HEADER_SIZE
boost::mutex tx_mutex_
boost::asio::io_service uart_service_
boost::thread uart_thread_ [2]

Detailed Description

Handles the communication between host computer and the HighLevel Processor (HLP) of the AscTec Autopilot board.

Can connect to either one or two (e.g. for separate rx/tx wireless links) serial ports. The default baudrate can be changed up to 921600 baud. Messages can be sent with Comm::sendPacket or Comm::sendPacketAck . Messages are received by setting a callback function with Comm::registerCallback for the message id to receive.

Definition at line 62 of file comm.h.


Member Typedef Documentation

typedef boost::asio::serial_port Comm::SerialPort [private]

Definition at line 64 of file comm.h.

typedef boost::shared_ptr<SerialPort> Comm::SerialPortPtr [private]

Definition at line 65 of file comm.h.


Constructor & Destructor Documentation

Definition at line 35 of file comm.cpp.

Definition at line 46 of file comm.cpp.


Member Function Documentation

void Comm::close ( )

closes the serial port(s)

Definition at line 156 of file comm.cpp.

bool Comm::configurePort ( SerialPortPtr serial_port,
uint32_t *  baudrate 
) [private]

Definition at line 118 of file comm.cpp.

bool Comm::connect ( SerialPortPtr serial_port,
const std::string &  port,
uint32_t  baudrate 
) [private]

Definition at line 51 of file comm.cpp.

bool Comm::connect ( const std::string &  port_rx,
const std::string &  port_tx,
uint32_t  baudrate 
)

connects to the specified serial port(s) with the given baudrate. The HLP sets it's baudrate automatically.

The port names can be equal, then it connects only to one serial port (most common operation). It can also connect to different ports for rx and tx. This is useful when e.g. two wireless modules (one for rx, one for tx) such as XBee are used to connect to the helicopter and bandwidth of one link is to low. rx/tx is seen from the host computer running the communication node. Any baudrate can be set. If it doesn't match a standard baudrate, the closest standard baudrate is chosen. If the HLP doesn't "hear" anything from the node for ~10s, it will go into autobaud mode. During connection setup, the node sends 'a' to the HLP, which will then configure its baudrate automatically.

Parameters:
port_rxport to use for rx
port_txport to use for tx
baudratebaudrate to connect with. equal for both ports. The baudrate finally chosen is written to baudrate.
Returns:
connection successful

Definition at line 72 of file comm.cpp.

uint16_t Comm::crc16 ( void *  data,
uint16_t  cnt,
uint16_t  crc = 0xff 
) [private]

Definition at line 358 of file comm.cpp.

uint16_t Comm::crc_update ( uint16_t  crc,
uint8_t  data 
) [inline, private]

Definition at line 350 of file comm.cpp.

uint32_t Comm::getRxPackets ( ) [inline]

Definition at line 130 of file comm.h.

uint32_t Comm::getRxPacketsGood ( ) [inline]

Definition at line 135 of file comm.h.

void Comm::loopOnce ( ) [inline]

Definition at line 183 of file comm.h.

void Comm::processPacketAck ( uint8_t *  buf,
uint32_t  length 
) [private]

Definition at line 319 of file comm.cpp.

template<class T >
void Comm::registerCallback ( uint8_t  id,
void(T::*)(uint8_t *, uint32_t)  cb_func,
T *  p_obj 
) [inline]

registers a class method that gets called when the packet specified by id was sent from the HLP

Currently, only one method/function can be registered per message id. The method has to be prototyped as follows (see e.g. Comm::processBaudrate):

 void class::method(uint8_t *buffer, uint32_t length) 
Parameters:
idthe message id to subscribe to
cb_functhe method that gets called
p_objpointer to the object whose cb_func should get called

Definition at line 176 of file comm.h.

void Comm::rxReadCallback ( const boost::system::error_code &  error,
size_t  bytes_transferred 
) [private]

Definition at line 194 of file comm.cpp.

void Comm::rxReadStart ( uint32_t  length,
uint32_t  timeout = 0 
) [private]

Definition at line 171 of file comm.cpp.

void Comm::rxTimeoutCallback ( const boost::system::error_code &  error) [private]

Definition at line 184 of file comm.cpp.

template<typename T >
bool Comm::sendPacket ( uint8_t  packet_id,
const T &  data 
) [inline]

sends a packet to the HLP

Definition at line 142 of file comm.h.

template<typename T >
bool Comm::sendPacketAck ( uint8_t  packet_id,
const T &  data,
const double &  timeout = 1.0 
) [inline]

sends a packet to the HLP and blocks until it got acknowledged or until the timeout is reached

Definition at line 151 of file comm.h.

void Comm::serializePacket ( uint8_t  packet_id,
const void *  data,
const int32_t &  packet_size,
uint8_t  flag = 0 
) [private]

Definition at line 305 of file comm.cpp.

bool Comm::validateChecksum ( uint8_t *  buf,
uint32_t  length,
uint16_t  checksum 
) [private]

Definition at line 166 of file comm.cpp.

bool Comm::waitForPacketAck ( uint8_t  ack_id,
const double &  timeout = 1.0 
) [private]

Definition at line 327 of file comm.cpp.


Member Data Documentation

Definition at line 90 of file comm.h.

std::vector<uint8_t> Comm::packet_acks_ [private]

Definition at line 86 of file comm.h.

Definition at line 69 of file comm.h.

std::string Comm::port_rx_name_ [private]

Definition at line 76 of file comm.h.

Definition at line 70 of file comm.h.

std::string Comm::port_tx_name_ [private]

Definition at line 77 of file comm.h.

uint8_t Comm::rx_buffer_[256] [private]

Definition at line 83 of file comm.h.

uint32_t Comm::rx_packet_cnt_ [private]

Definition at line 79 of file comm.h.

uint32_t Comm::rx_packet_good_cnt_ [private]

Definition at line 80 of file comm.h.

int Comm::rx_state_ [private]

Definition at line 85 of file comm.h.

boost::asio::deadline_timer Comm::rx_timeout_ [private]

Definition at line 72 of file comm.h.

Definition at line 73 of file comm.h.

uint8_t Comm::tx_buffer_[256] [private]

Definition at line 82 of file comm.h.

uint32_t Comm::tx_bytes2send_ [private]

Definition at line 84 of file comm.h.

const int Comm::TX_HEADER_SIZE [private]

Definition at line 88 of file comm.h.

boost::mutex Comm::tx_mutex_ [private]

Definition at line 87 of file comm.h.

boost::asio::io_service Comm::uart_service_ [private]

Definition at line 71 of file comm.h.

boost::thread Comm::uart_thread_[2] [private]

Definition at line 74 of file comm.h.


The documentation for this class was generated from the following files:


asctec_hl_interface
Author(s): Markus Achtelik, Michael Achtelik, Stephan Weiss, Laurent Kneip
autogenerated on Sun Oct 5 2014 22:21:01