Public Member Functions | Private Member Functions | Private Attributes
msp::client::Client Class Reference

#include <Client.hpp>

List of all members.

Public Member Functions

 Client ()
void connect (const std::string &device, const uint baudrate=115200)
 connect establish connection to serial device
SubscriptionBasegetSubscription (const msp::ID &id)
 getSubscription get pointer to subscription
bool hasSubscription (const msp::ID &id)
 hasSubscription check if message ID is subscribed
void processOneMessage ()
uint8_t read ()
 read blocking read a single byte from either the buffer or the serial device
int request (msp::Request &request, const double timeout=0)
 request requests payload from FC and block until payload has been received
int request_raw (const uint8_t id, ByteVector &data, const double timeout=0)
 request_raw request raw unstructured payload data
bool respond (const msp::Response &response, const bool wait_ack=true)
 respond send payload to FC and block until an ACK has been received
bool respond_raw (const uint8_t id, const ByteVector &data, const bool wait_ack=true)
 respond_raw send raw unstructured payload data
bool sendData (const uint8_t id, const ByteVector &data=ByteVector(0))
 sendData send raw data and ID to flight controller, accepts any uint8 id
bool sendRequest (const uint8_t id)
 sendRequest request payload from FC
bool sendRequest (const msp::ID id)
bool sendResponse (const msp::Response &response)
 sendResponse send payload to FC
void setPrintWarnings (const bool warnings)
void start ()
 start starts the receiver thread that handles incomming messages
void stop ()
 stop stops the receiver thread
template<typename T , typename C >
SubscriptionBasesubscribe (void(C::*callback)(const T &), C *context, const double tp=0.0)
 subscribe register callback function that is called when type is received
void waitForOneMessage ()
 waitForOneMessage block until one message has been received
void waitForOneMessageBlock ()
 ~Client ()

Private Member Functions

uint8_t crc (const uint8_t id, const ByteVector &data)
 crc compute checksum of data package

Private Attributes

asio::streambuf buffer
std::condition_variable cv_ack
std::condition_variable cv_request
asio::io_service io
std::mutex mutex_buffer
std::mutex mutex_callbacks
std::mutex mutex_cv_ack
std::mutex mutex_cv_request
std::mutex mutex_request
std::mutex mutex_send
asio::serial_port port
bool print_warnings
std::unique_ptr< ReceivedMessagerequest_received
bool running
std::map< msp::ID, msp::Request * > subscribed_requests
std::map< msp::ID,
SubscriptionBase * > 
subscriptions
std::thread thread

Detailed Description

Definition at line 133 of file Client.hpp.


Constructor & Destructor Documentation

Definition at line 49 of file Client.cpp.

Definition at line 51 of file Client.cpp.


Member Function Documentation

void msp::client::Client::connect ( const std::string &  device,
const uint  baudrate = 115200 
)

connect establish connection to serial device

Parameters:
devicepath or name of serial device
baudrateserial baudrate (default: 115200)
Returns:
true on success

Definition at line 59 of file Client.cpp.

uint8_t msp::client::Client::crc ( const uint8_t  id,
const ByteVector data 
) [private]

crc compute checksum of data package

Parameters:
idmessage ID
dataraw data vector
Returns:
checksum

Definition at line 168 of file Client.cpp.

getSubscription get pointer to subscription

Parameters:
idmessage ID
Returns:
pointer to subscription

Definition at line 297 of file Client.hpp.

bool msp::client::Client::hasSubscription ( const msp::ID id) [inline]

hasSubscription check if message ID is subscribed

Parameters:
idmessage ID
Returns:
true if there is already a subscription
false if ID is not subscribed

Definition at line 288 of file Client.hpp.

Definition at line 174 of file Client.cpp.

read blocking read a single byte from either the buffer or the serial device

Returns:
byte from buffer or device

Definition at line 81 of file Client.cpp.

int msp::client::Client::request ( msp::Request request,
const double  timeout = 0 
)

request requests payload from FC and block until payload has been received

Parameters:
requestrequest whose data will be set by the received payload
timeout(optional) timeout in seconds
Returns:
true on success
false on failure
-1 on timeout

Definition at line 105 of file Client.cpp.

int msp::client::Client::request_raw ( const uint8_t  id,
ByteVector data,
const double  timeout = 0 
)

request_raw request raw unstructured payload data

Parameters:
idmessage ID
datareference to data buffer at which the received data will be stores
timeout(optional) timeout in seconds
Returns:
1 on success
0 on failure
-1 on timeout

Definition at line 112 of file Client.cpp.

bool msp::client::Client::respond ( const msp::Response response,
const bool  wait_ack = true 
)

respond send payload to FC and block until an ACK has been received

Parameters:
responseresponse with payload
wait_ackif set, method will wait for message acknowledgement
Returns:
true on success
false on failure

Definition at line 141 of file Client.cpp.

bool msp::client::Client::respond_raw ( const uint8_t  id,
const ByteVector data,
const bool  wait_ack = true 
)

respond_raw send raw unstructured payload data

Parameters:
idmessage ID
dataraw payload
wait_ackif set, method will wait for message acknowledgement
Returns:
true on success
false on failure

Definition at line 145 of file Client.cpp.

bool msp::client::Client::sendData ( const uint8_t  id,
const ByteVector data = ByteVector(0) 
)

sendData send raw data and ID to flight controller, accepts any uint8 id

Parameters:
idmessage ID
dataraw data
Returns:
true on success
false on failure

Definition at line 89 of file Client.cpp.

bool msp::client::Client::sendRequest ( const uint8_t  id) [inline]

sendRequest request payload from FC

Parameters:
idmessage ID
Returns:
true on success
false on failure

Definition at line 189 of file Client.hpp.

bool msp::client::Client::sendRequest ( const msp::ID  id) [inline]

Definition at line 193 of file Client.hpp.

bool msp::client::Client::sendResponse ( const msp::Response response) [inline]

sendResponse send payload to FC

Parameters:
responseresponse with payload
Returns:
true on success
false on failure

Definition at line 203 of file Client.hpp.

void msp::client::Client::setPrintWarnings ( const bool  warnings) [inline]

Definition at line 139 of file Client.hpp.

start starts the receiver thread that handles incomming messages

Definition at line 68 of file Client.cpp.

stop stops the receiver thread

Definition at line 75 of file Client.cpp.

template<typename T , typename C >
SubscriptionBase* msp::client::Client::subscribe ( void(C::*)(const T &)  callback,
C *  context,
const double  tp = 0.0 
) [inline]

subscribe register callback function that is called when type is received

Parameters:
callbackpointer to callback function (class method)
contextclass with callback method
tpperiod at a timer will send subscribed requests (in seconds), by default this is 0 and requests are not sent periodically
Returns:
pointer to subscription that is added to internal list

Definition at line 255 of file Client.hpp.

waitForOneMessage block until one message has been received


Member Data Documentation

asio::streambuf msp::client::Client::buffer [private]

Definition at line 316 of file Client.hpp.

std::condition_variable msp::client::Client::cv_ack [private]

Definition at line 321 of file Client.hpp.

std::condition_variable msp::client::Client::cv_request [private]

Definition at line 320 of file Client.hpp.

asio::io_service msp::client::Client::io [private]

Definition at line 314 of file Client.hpp.

std::mutex msp::client::Client::mutex_buffer [private]

Definition at line 327 of file Client.hpp.

Definition at line 325 of file Client.hpp.

std::mutex msp::client::Client::mutex_cv_ack [private]

Definition at line 323 of file Client.hpp.

Definition at line 322 of file Client.hpp.

std::mutex msp::client::Client::mutex_request [private]

Definition at line 324 of file Client.hpp.

std::mutex msp::client::Client::mutex_send [private]

Definition at line 326 of file Client.hpp.

asio::serial_port msp::client::Client::port [private]

Definition at line 315 of file Client.hpp.

Definition at line 334 of file Client.hpp.

Definition at line 329 of file Client.hpp.

Definition at line 319 of file Client.hpp.

Definition at line 332 of file Client.hpp.

Definition at line 331 of file Client.hpp.

std::thread msp::client::Client::thread [private]

Definition at line 318 of file Client.hpp.


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


msp
Author(s): Christian Rauch
autogenerated on Mon Oct 9 2017 03:02:14