#include <Transport.h>
Definition at line 89 of file Transport.h.
Enumerator |
---|
GARBLE_BYTES |
|
INVALID_MSG |
|
IGNORED_ACK |
|
QUEUE_FULL |
|
NUM_COUNTERS |
|
Definition at line 92 of file Transport.h.
sawyer::Transport::Transport |
( |
| ) |
|
|
protected |
Constructs an unconfigured transport instance.
Definition at line 138 of file Transport.cpp.
sawyer::Transport::~Transport |
( |
| ) |
|
|
protected |
int sawyer::Transport::close |
( |
| ) |
|
Close this Transport.
- Returns
- Zero on success, nonzero otherwise
- Postcondition
- Tranport will be unconfigured, regardless of success/failure.
Definition at line 192 of file Transport.cpp.
int sawyer::Transport::closeComm |
( |
| ) |
|
|
private |
void sawyer::Transport::configure |
( |
const char * |
device, |
|
|
int |
retries |
|
) |
| |
Configure this Transport for communication. If this Transport is already configured, it will be closed and reconfigured. The RX buffer and Message queue will be flushed. Counters will be reset.
- Parameters
-
device | The device to communicate over. (Currently, must be serial) |
retries | Number of times to resend an unacknowledged message. |
- Exceptions
-
- Postcondition
- Transport becomes configured.
Definition at line 164 of file Transport.cpp.
void sawyer::Transport::enqueueMessage |
( |
Message * |
msg | ) |
|
|
private |
Add a Message to the Message queue. Checks Message validity, and drops invalid messages. Trims queue down to size if it gets too big.
- Parameters
-
msg | The message to enqueue. |
Definition at line 350 of file Transport.cpp.
void sawyer::Transport::flush |
( |
std::list< Message * > * |
queue = 0 | ) |
|
Message * sawyer::Transport::getAck |
( |
| ) |
|
Read data until an ack message is found. Any data messages received by this function will be queued.
- Returns
- The next ack message, if one is read. Null if no ack message has been read yet.
Definition at line 315 of file Transport.cpp.
unsigned long sawyer::Transport::getCounter |
( |
enum counterTypes |
counter | ) |
|
|
inline |
bool sawyer::Transport::isConfigured |
( |
| ) |
|
|
inline |
int sawyer::Transport::openComm |
( |
const char * |
device | ) |
|
|
private |
Opens a serial port with the default configuration (115200 bps, 8-N-1), using the device specified in the constructor
Definition at line 208 of file Transport.cpp.
void sawyer::Transport::poll |
( |
| ) |
|
Public function which makes sure buffered messages are still being read into the internal buffer. A compromise between forcing a thread-based implementation and blocking on results. This could be placed into a separate thread, but will need to be wrapped for thread safety
Definition at line 379 of file Transport.cpp.
Message * sawyer::Transport::popNext |
( |
| ) |
|
Removes the oldest Message from the Message queue and returns it. All data waiting in the input buffer will be read and queued.
- Returns
- The oldest message in the queue. This Message is removed from the queue. It is dynamically allocated; the caller is responsible for freeing it. Null if no Messages are currently queued.
Definition at line 558 of file Transport.cpp.
Finds the oldest message of a specific type in the Message queue, removes it, and returns it. Older messages of the wrong type will be left in the queue. All data waiting in the input buffer will be read and queued.
- Returns
- The oldest message of the correct type in the queue. This Message is removed from the queue. It is dynamically allocated; the caller is responsible for freeing it. Null if no Messages are currently queued.
Definition at line 581 of file Transport.cpp.
void sawyer::Transport::printCounters |
( |
std::ostream & |
stream = std::cout | ) |
|
Prints a nice list of counter values
Definition at line 741 of file Transport.cpp.
void sawyer::Transport::resetCounters |
( |
| ) |
|
|
private |
Message * sawyer::Transport::rxMessage |
( |
| ) |
|
|
private |
Non-blocking message receive function. !!! Absolutely not reentrant !!! !!! Keeps internal static state !!!
- Returns
- A pointer to a dynamically allocated message, if one has been received this call. Null if no complete message has been received. Bad data are silently eaten.
Definition at line 242 of file Transport.cpp.
void sawyer::Transport::send |
( |
Message * |
m | ) |
|
Send a message. Waits for the firmware to acknowlge and resends the packet a few timew if not acknowledged.
- Parameters
-
- Exceptions
-
Transport::Exception | if never acknowledged. |
Definition at line 408 of file Transport.cpp.
Send a Request message. Waits for the firmware to acknowlge and resends the packet a few timew if not acknowledged.
- Parameters
-
- Exceptions
-
Transport::Exception | if never acknowledged. |
- Returns
- Data Message
Definition at line 485 of file Transport.cpp.
Message * sawyer::Transport::waitNext |
( |
double |
timeout = 0.0 | ) |
|
Fetch a message, blocking if there are no messages currently available.
- Parameters
-
timeout | Maximum time to block, in seconds. Actual resolution is system dependent A timeout of 0.0 indicates no timeout. |
- Returns
- A message. Null if the timeout elapses.
Definition at line 607 of file Transport.cpp.
Fetch a particular type of message, blocking if one isn't available.
- Parameters
-
type | The type of message to fetch |
timeout | Maximum time to block, in seconds. Actual resolution is system dependent A timeout of 0.0 indicates no timeout. |
- Returns
- A message of the requested type. Nul if the timeout elapses.
Definition at line 639 of file Transport.cpp.
bool sawyer::Transport::configured |
|
private |
const char * sawyer::Transport::counter_names |
|
static |
Initial value:= {
"Garbled bytes",
"Invalid messages",
"Ignored acknowledgment",
"Message queue overflow"
}
Definition at line 100 of file Transport.h.
int sawyer::Transport::counter_number |
const size_t sawyer::Transport::MAX_QUEUE_LEN = 10000 |
|
staticprivate |
int sawyer::Transport::retries |
|
private |
const int sawyer::Transport::RETRY_DELAY_MS = 200 |
|
staticprivate |
std::list<Message *> sawyer::Transport::rx_queue |
|
private |
void* sawyer::Transport::serial |
|
private |
The documentation for this class was generated from the following files: