69 const char *Transport::counter_names[] = {
72 "Ignored acknowledgment",
73 "Message queue overflow" 76 TransportException::TransportException(
const char *msg,
enum errors ex_type)
104 message =
"Requested frequency too high";
107 message =
"Too many subscriptions";
110 message =
"Unknown error code.";
115 CPR_EXCEPT() <<
"BadAckException (0x" << hex << flag << dec <<
"): " <<
message << endl << flush;
118 #define CHECK_THROW_CONFIGURED() \ 120 if( ! configured ) { \ 121 throw new TransportException("Transport not configured", TransportException::NOT_CONFIGURED); \ 248 static size_t rx_inx = 0;
249 static size_t msg_len = 0;
277 msg_len = rx_buf[1] + 3;
280 if (static_cast<unsigned char>(rx_buf[1] ^ rx_buf[2]) != 0xFF ||
297 if (rx_inx < msg_len) {
break; }
412 int transmit_times = 0;
420 if (transmit_times > this->
retries)
431 if ((ack =
getAck())) {
break; }
482 if (
rx_queue.empty()) {
return NULL; }
506 list<Message *>::iterator iter;
509 if ((*iter)->getType() == type)
529 double elapsed = 0.0;
537 if ((timeout != 0.0) && (elapsed > timeout))
561 double elapsed = 0.0;
571 if (msg) {
return msg; }
574 if ((timeout != 0.0) && (elapsed > timeout))
601 list<Message *>::iterator iter;
606 queue->push_back(*iter);
632 list<Message *>::iterator iter =
rx_queue.begin();
635 if ((*iter)->getType() == type)
641 queue->push_back(*iter);
663 stream <<
"Transport Counters" << endl;
664 stream <<
"==================" << endl;
666 size_t longest_name = 0;
671 if (cur_len > longest_name) { longest_name = cur_len; }
676 cout.width(longest_name);
680 cout.width(longest_name);
681 cout << left <<
"Queue length" <<
": " <<
rx_queue.size() << endl;
BadAckException(unsigned int flag)
uint8_t data[MAX_MSG_LENGTH]
static const char * counter_names[NUM_COUNTERS]
enum clearpath::BadAckException::ackFlags ack_flag
static Transport & instance()
int OpenSerial(void **handle, const char *port_name)
int openComm(const char *device)
int CloseSerial(void *handle)
static Message * factory(void *input, size_t msg_len)
std::list< Message * > rx_queue
static const int RETRY_DELAY_MS
int ReadData(void *handle, char *buffer, int length)
uint64_t btou(void *src, size_t src_len)
unsigned long counters[NUM_COUNTERS]
void enqueueMessage(Message *msg)
Message * waitNext(double timeout=0.0)
uint8_t * getPayloadPointer(size_t offset=0)
int WriteData(void *handle, const char *buffer, int length)
int SetupSerial(void *handle)
static const size_t MAX_QUEUE_LEN
static const size_t MAX_MSG_LENGTH
static const size_t MIN_MSG_LENGTH
#define CHECK_THROW_CONFIGURED()
bool isValid(char *whyNot=NULL, size_t strLen=0)
void printCounters(std::ostream &stream=std::cout)
void flush(std::list< Message * > *queue=0)
void configure(const char *device, int retries)