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); \ 250 static size_t rx_inx = 0;
251 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 ||
292 if (rx_inx < msg_len) {
break; }
418 int transmit_times = 0;
424 if (transmit_times > this->
retries)
446 cout <<
"No message received yet" << endl;
456 if (result_code > 0 && !ack_temp->
isData())
468 if (ack_temp == NULL)
493 int transmit_times = 0;
499 if (transmit_times > this->
retries)
521 cout <<
"No message received yet" << endl;
528 if(ack_temp->
isData()) {
return ack_temp;}
530 if (result_code > 0 && !ack_temp->
isData())
542 if (ack_temp == NULL)
564 if (
rx_queue.empty()) {
return NULL; }
588 list<Message *>::iterator iter;
591 if ((*iter)->getType() == type)
611 double elapsed = 0.0;
619 if ((timeout != 0.0) && (elapsed > timeout))
643 double elapsed = 0.0;
656 if ((timeout != 0.0) && (elapsed > timeout))
682 list<Message *>::iterator iter;
687 queue->push_back(*iter);
712 list<Message *>::iterator iter =
rx_queue.begin();
715 if ((*iter)->getType() == type)
721 queue->push_back(*iter);
743 stream <<
"Transport Counters" << endl;
744 stream <<
"==================" << endl;
746 size_t longest_name = 0;
751 if (cur_len > longest_name) { longest_name = cur_len; }
756 cout.width(longest_name);
760 cout.width(longest_name);
761 cout << left <<
"Queue length" <<
": " <<
rx_queue.size() << endl;
static const size_t MAX_QUEUE_LEN
Message * sendRequest(Message *m)
static const int RETRY_DELAY_MS
static const size_t MAX_MSG_LENGTH
bool isValid(char *whyNot=NULL, size_t strLen=0)
unsigned long counters[NUM_COUNTERS]
uint64_t btou(void *src, size_t src_len)
static Transport & instance()
static const size_t MIN_MSG_LENGTH
static Message * factory(void *input, size_t msg_len)
uint8_t * getPayloadPointer(size_t offset=0)
int SetupSerial(void *handle)
void printCounters(std::ostream &stream=std::cout)
int OpenSerial(void **handle, const char *port_name)
BadAckException(unsigned int flag)
void flush(std::list< Message * > *queue=0)
int CloseSerial(void *handle)
Message * waitNext(double timeout=0.0)
int WriteData(void *handle, const char *buffer, int length)
std::list< Message * > rx_queue
static const char * counter_names[NUM_COUNTERS]
unsigned char data[MAX_MSG_LENGTH]
#define CHECK_THROW_CONFIGURED()
int ReadData(void *handle, char *buffer, int length)
void configure(const char *device, int retries)
int openComm(const char *device)
void enqueueMessage(Message *msg)
uint8_t data[MAX_MSG_LENGTH]
enum sawyer::BadAckException::ackFlags ack_flag
struct sawyer::base_data::RawData rawData