Transport.h
Go to the documentation of this file.
1 
39 #ifndef SAWYER_TRANSPORT_H
40 #define SAWYER_TRANSPORT_H
41 
42 #include <list>
43 #include <iostream>
44 
45 #include "roch_base/core/Message.h"
47 #include "roch_base/core/serial.h"
48 
49 namespace sawyer
50 {
51 
53  {
54  public:
55  enum errors
56  {
62  };
63  public:
64  enum errors type;
65 
66  TransportException(const char *msg, enum errors ex_type = ERROR_BASE);
67  };
68 
70  {
71  public:
72  enum ackFlags
73  {
74  BAD_CHECKSUM = 0x01,
75  BAD_TYPE = 0x02,
76  BAD_FORMAT = 0x04,
77  RANGE = 0x08,
78  NO_BANDWIDTH = 0x10,
79  OVER_FREQ = 0x20,
80  OVER_SUBSCRIBE = 0x40
81  } ack_flag;
82 
83  BadAckException(unsigned int flag);
84  };
85 
86 /*
87  * Transport class
88  */
89  class Transport
90  {
91  public:
93  {
94  GARBLE_BYTES, // bytes with no SOH / bad length
95  INVALID_MSG, // bad format / CRC wrong
96  IGNORED_ACK, // ack we didn't care about
97  QUEUE_FULL, // dropped msg because of overfull queue
98  NUM_COUNTERS // end of list, not actual counter
99  };
100  static const char *counter_names[NUM_COUNTERS]; // N.B: must be updated with counterTypes
102 
103  roch_driver::RawData getdata(){return rochDriver.rawData_.rawData ;}
104  private:
106  void *serial;
107  int retries;
109  static const int RETRY_DELAY_MS = 200;
110 
111  std::list<Message *> rx_queue;
112  static const size_t MAX_QUEUE_LEN = 10000;
113 
114  unsigned long counters[NUM_COUNTERS];
115 
116  private:
117  Message *rxMessage();
118 
119  void enqueueMessage(Message *msg);
120 
121  int openComm(const char *device);
122 
123  int closeComm();
124 
125  void resetCounters();
126 
127  protected:
128  Transport();
129 
130  ~Transport();
131 
132  public:
133  static Transport &instance();
134 
135  Message *getAck();
136  void configure(const char *device, int retries);
137 
139  {
140  return configured;
141  }
142 
143  int close();
144 
145  void poll();
146 
147  void send(Message *m);
148 
149  Message * sendRequest(Message *m);
150  Message *popNext();
151 
152  Message *popNext(enum MessageTypes type);
153 
154  Message *waitNext(double timeout = 0.0);
155 
156  Message *waitNext(enum MessageTypes type, double timeout = 0.0);
157 
158  void flush(std::list<Message *> *queue = 0);
159 
160  void flush(enum MessageTypes type, std::list<Message *> *queue = 0);
161 
162  unsigned long getCounter(enum counterTypes counter)
163  {
164  return counters[counter];
165  }
166 
167  void printCounters(std::ostream &stream = std::cout);
168  };
169 
170 }; // namespace sawyer
171 
172 #endif // sawyer_TRANSPORT_H
173 
unsigned long getCounter(enum counterTypes counter)
Definition: Transport.h:162
roch_driver::RawData getdata()
Definition: Transport.h:103
MessageTypes
Definition: Message.h:207
bool isConfigured()
Definition: Transport.h:138
std::list< Message * > rx_queue
Definition: Transport.h:111
TransportException(const char *msg, enum errors ex_type=ERROR_BASE)
Definition: Transport.cpp:76
roch_driver rochDriver
Definition: Transport.h:108


roch_base
Author(s): Mike Purvis , Paul Bovbel , Chen
autogenerated on Mon Jun 10 2019 14:41:14