Public Member Functions | Private Member Functions | Private Attributes
msp::MSP Class Reference

The MSP class. More...

#include <MSP.hpp>

List of all members.

Public Member Functions

bool connect (const std::string &device, const uint baudrate=115200)
 connect establish connection to serial device
 MSP ()
 MSP construct MSP communication without establishing a connection.
 MSP (const std::string &device, const uint baudrate=115200)
 MSP constructor for MSP communication.
DataID receiveData ()
 receiveData receive raw data from flight controller
bool request (msp::Request &request)
 request send command and request data from FC once
bool request_block (msp::Request &request)
 request_block continuously send command and request data until data has been received
bool request_wait (msp::Request &request, const uint wait_ms, const uint min_payload_size=0)
 request_wait wait for data while continuously sending command
bool respond (const msp::Response &response)
 respond send data to FC and read acknowledge
bool respond_block (const msp::Response &response)
 respond_block send data to FC until acknowledge has been received
bool send (const msp::Response &response)
 send encode message and send payload
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 sendData (const msp::ID id, const ByteVector &data=ByteVector(0))
 sendData send raw data and ID to flight controller, only accepts registered message ID
void setWait (unsigned int wait_us)
 setWait set time (microseconds) between sending and receiving After sending a request to the FC, we need to wait a small amount of time for the FC to process our request and to respond.

Private Member Functions

void clear ()
 clear flush the serial buffer to remove old data
uint8_t crc (const uint8_t id, const ByteVector &data)
 crc compute checksum of data package
int hasData ()
 hasData check if data is available
size_t read (std::vector< uint8_t > &data)
 read read data vector from device
std::vector< uint8_t > read (std::size_t n_bytes)
 read read given amount of bytes from device
uint8_t read ()
 read read a single byte from device
bool write (const std::vector< uint8_t > &data)
 write write data vector to device

Private Attributes

std::string device
asio::io_service io
 ! io service
std::mutex lock_read
std::mutex lock_write
asio::serial_port port
 ! port for serial device
unsigned int wait
 time (micro seconds) to wait before waiting for response

Detailed Description

The MSP class.

Definition at line 80 of file MSP.hpp.


Constructor & Destructor Documentation

MSP construct MSP communication without establishing a connection.

Definition at line 9 of file MSP.cpp.

msp::MSP::MSP ( const std::string &  device,
const uint  baudrate = 115200 
)

MSP constructor for MSP communication.

Parameters:
devicedevice path
baudrateserial baudrate

Definition at line 11 of file MSP.cpp.


Member Function Documentation

void msp::MSP::clear ( ) [private]

clear flush the serial buffer to remove old data

Definition at line 300 of file MSP.cpp.

bool msp::MSP::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 15 of file MSP.cpp.

uint8_t msp::MSP::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 246 of file MSP.cpp.

int msp::MSP::hasData ( ) [private]

hasData check if data is available

Returns:
>0 amount of bytes ready to read
-1 on error

Definition at line 278 of file MSP.cpp.

size_t msp::MSP::read ( std::vector< uint8_t > &  data) [private]

read read data vector from device

Parameters:
dataraw data vector in which read data will be stored
Returns:
number of read bytes

Definition at line 266 of file MSP.cpp.

std::vector< uint8_t > msp::MSP::read ( std::size_t  n_bytes) [private]

read read given amount of bytes from device

Parameters:
n_bytesnumber of bytes to read
Returns:
data vector with read bytes

Definition at line 271 of file MSP.cpp.

uint8_t msp::MSP::read ( ) [inline, private]

read read a single byte from device

Returns:
single byte

Definition at line 224 of file MSP.hpp.

receiveData receive raw data from flight controller

Returns:
pair of data and message ID

Definition at line 201 of file MSP.cpp.

bool msp::MSP::request ( msp::Request request)

request send command and request data from FC once

Parameters:
requestrequest message
Returns:
true on success
false on failure

Definition at line 36 of file MSP.cpp.

request_block continuously send command and request data until data has been received

Parameters:
requestrequest message
Returns:
true when data has been received

Definition at line 66 of file MSP.cpp.

bool msp::MSP::request_wait ( msp::Request request,
const uint  wait_ms,
const uint  min_payload_size = 0 
)

request_wait wait for data while continuously sending command

Parameters:
requestrequest message
wait_mswaiting time in between sending request and receiving response
min_payload_sizeminimum amount of payload (bytes) that needs to be available before reading and decoding of a message starts
Returns:
true when data has been received

Definition at line 105 of file MSP.cpp.

bool msp::MSP::respond ( const msp::Response response)

respond send data to FC and read acknowledge

Parameters:
responseresponse message
Returns:
true on success
false on failure

Definition at line 145 of file MSP.cpp.

bool msp::MSP::respond_block ( const msp::Response response)

respond_block send data to FC until acknowledge has been received

Parameters:
responseresponse message with data
Returns:
true when acknowledge has been received

Definition at line 162 of file MSP.cpp.

bool msp::MSP::send ( const msp::Response response) [inline]

send encode message and send payload

Parameters:
responsemessage sent to FC
Returns:
true on success
false on failure

Definition at line 168 of file MSP.hpp.

bool msp::MSP::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 186 of file MSP.cpp.

bool msp::MSP::sendData ( const msp::ID  id,
const ByteVector data = ByteVector(0) 
) [inline]

sendData send raw data and ID to flight controller, only accepts registered message ID

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

Definition at line 158 of file MSP.hpp.

void msp::MSP::setWait ( unsigned int  wait_us) [inline]

setWait set time (microseconds) between sending and receiving After sending a request to the FC, we need to wait a small amount of time for the FC to process our request and to respond.

Parameters:
wait_uswaiting time in microseconds

Definition at line 185 of file MSP.hpp.

bool msp::MSP::write ( const std::vector< uint8_t > &  data) [private]

write write data vector to device

Parameters:
dataraw data vector
Returns:
true on success
false on failure

Definition at line 255 of file MSP.cpp.


Member Data Documentation

std::string msp::MSP::device [private]

Definition at line 240 of file MSP.hpp.

asio::io_service msp::MSP::io [private]

! io service

Definition at line 241 of file MSP.hpp.

std::mutex msp::MSP::lock_read [private]

Definition at line 244 of file MSP.hpp.

std::mutex msp::MSP::lock_write [private]

Definition at line 243 of file MSP.hpp.

asio::serial_port msp::MSP::port [private]

! port for serial device

Definition at line 242 of file MSP.hpp.

unsigned int msp::MSP::wait [private]

time (micro seconds) to wait before waiting for response

Definition at line 245 of file MSP.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