#include <Client.hpp>
Public Member Functions | |
| Client () | |
| void | connect (const std::string &device, const uint baudrate=115200) |
| connect establish connection to serial device | |
| SubscriptionBase * | getSubscription (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 > | |
| SubscriptionBase * | subscribe (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< ReceivedMessage > | request_received |
| bool | running |
| std::map< msp::ID, msp::Request * > | subscribed_requests |
| std::map< msp::ID, SubscriptionBase * > | subscriptions |
| std::thread | thread |
Definition at line 133 of file Client.hpp.
Definition at line 49 of file Client.cpp.
Definition at line 51 of file Client.cpp.
| void msp::client::Client::connect | ( | const std::string & | device, |
| const uint | baudrate = 115200 |
||
| ) |
connect establish connection to serial device
| device | path or name of serial device |
| baudrate | serial baudrate (default: 115200) |
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
| id | message ID |
| data | raw data vector |
Definition at line 168 of file Client.cpp.
| SubscriptionBase* msp::client::Client::getSubscription | ( | const msp::ID & | id | ) | [inline] |
getSubscription get pointer to subscription
| id | message ID |
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
| id | message ID |
Definition at line 288 of file Client.hpp.
Definition at line 174 of file Client.cpp.
| uint8_t msp::client::Client::read | ( | ) |
read blocking read a single byte from either the buffer or the serial 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
| request | request whose data will be set by the received payload |
| timeout | (optional) timeout in seconds |
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
| id | message ID |
| data | reference to data buffer at which the received data will be stores |
| timeout | (optional) timeout in seconds |
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
| response | response with payload |
| wait_ack | if set, method will wait for message acknowledgement |
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
| id | message ID |
| data | raw payload |
| wait_ack | if set, method will wait for message acknowledgement |
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
| id | message ID |
| data | raw data |
Definition at line 89 of file Client.cpp.
| bool msp::client::Client::sendRequest | ( | const uint8_t | id | ) | [inline] |
sendRequest request payload from FC
| id | message ID |
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
| response | response with payload |
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.
| void msp::client::Client::start | ( | ) |
start starts the receiver thread that handles incomming messages
Definition at line 68 of file Client.cpp.
| void msp::client::Client::stop | ( | ) |
stop stops the receiver thread
Definition at line 75 of file Client.cpp.
| 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
| callback | pointer to callback function (class method) |
| context | class with callback method |
| tp | period at a timer will send subscribed requests (in seconds), by default this is 0 and requests are not sent periodically |
Definition at line 255 of file Client.hpp.
waitForOneMessage block until one message has been received
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.
std::mutex msp::client::Client::mutex_callbacks [private] |
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.
std::mutex msp::client::Client::mutex_cv_request [private] |
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.
bool msp::client::Client::print_warnings [private] |
Definition at line 334 of file Client.hpp.
std::unique_ptr<ReceivedMessage> msp::client::Client::request_received [private] |
Definition at line 329 of file Client.hpp.
bool msp::client::Client::running [private] |
Definition at line 319 of file Client.hpp.
std::map<msp::ID, msp::Request*> msp::client::Client::subscribed_requests [private] |
Definition at line 332 of file Client.hpp.
std::map<msp::ID, SubscriptionBase*> msp::client::Client::subscriptions [private] |
Definition at line 331 of file Client.hpp.
std::thread msp::client::Client::thread [private] |
Definition at line 318 of file Client.hpp.