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


husky_base
Author(s): Mike Purvis , Paul Bovbel
autogenerated on Fri Oct 2 2020 03:40:07