My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
roachBackend.h
1 #ifndef ROACHBACKEND_H
2 #define ROACHBACKEND_H
3 
12 // Required C header files from the array control code
13 
14 #include "gcp/control/code/unix/libunix_src/common/regmap.h" // RegMapBlock
15 
16 #include "gcp/antenna/control/specific/Board.h"
17 #include "gcp/antenna/control/specific/RoachBackendMsg.h"
18 #include "gcp/util/common/FdSet.h"
19 
20 #include <sys/socket.h>
21 #include <netinet/in.h>
22 #include <stdio.h>
23 #include <termios.h>
24 #include <string>
25 
29 #define ROACH_TIMEOUT_USEC 5000
30 
31 namespace gcp {
32  namespace antenna {
33  namespace control {
34 
35  class SpecificShare;
36 
37  class RoachBackend : public Board {
38 
39  public:
40 
44  RoachBackend(SpecificShare* share, std::string name, bool sim);
45 
49  RoachBackend();
50 
54  ~RoachBackend();
55 
59  void queryStatus();
60  void queryStatus(gcp::util::TimeVal& currTime);
61 
66  void fillUtc(gcp::util::TimeVal& currTime);
67 
68 
74  bool connect();
75 
79  void disconnect();
80 
84  bool roachIsConnected();
85 
89  sockaddr_in servaddr_;
90 
94  void getData();
95 
96 
100  void sendCommand(RoachBackendMsg& command);
101 
107  int readResponse(RoachBackendMsg& command);
108 
110 
111  // Return true if the roach is not ready for another command
112 
113  bool isBusy();
114 
115  //------------------------------------------------------------
116  // Methods which will be used to read and write register values.
117  // These methods will send a the appropriate command to the servo,
118  // and time out waiting for a response.
119  //------------------------------------------------------------
120 
124  int writeString(std::string message);
125 
126  private:
127 
131  int fd_;
132 
136  struct termios termioSave_;
137 
141  RegMapBlock* Utc_;
142  RegMapBlock* LL_;
143  RegMapBlock* RR_;
144  RegMapBlock* Q_;
145  RegMapBlock* U_;
146  RegMapBlock* TL1_;
147  RegMapBlock* TL2_;
148 
149  /*
150  RegMapBlock* azPositions_;
151  RegMapBlock* azErrors_;
152  RegMapBlock* elPositions_;
153  RegMapBlock* elErrors_;
154  RegMapBlock* slowAzPos_;
155  RegMapBlock* slowElPos_;
156  RegMapBlock* servoStatus_;
157  RegMapBlock* servoThermalCutouts_;
158  RegMapBlock* servoContactors_;
159  RegMapBlock* servoCircuitBreakers_;
160  RegMapBlock* servoBrakes_;
161  RegMapBlock* driveLids_;
162  RegMapBlock* azWrap_;
163  */
164 
168  gcp::util::FdSet fdSet_;
169 
175  public:
180 
181  bool sim_;
182 
183 
184 
185 
186  private:
190  bool responsePending_;
191 
195  void serviceMsgQ();
196 
201  void zeroReadFds();
202 
207  void registerReadFd(int fd);
208 
213  int waitForNextMessage();
214 
218  int readTCPPort(RoachBackendMsg& command);
219 
220 
224  int parseBackendResponse(RoachBackendMsg& command);
225 
229  void waitForResponse();
230 
234  void recordStatusResponse(RoachBackendMsg& command);
235 
239  void wait(long nsec=100000000);
240 
241 
242  }; // End class RoachBackend
243 
244  }; // End namespace control
245  }; // End namespace antenna
246 }; // End namespace gcp
247 
248 
249 
250 
251 #endif // End
252 
bool connected_
Definition: roachBackend.h:179
void disconnect()
Definition: RoachBackend.cc:250
bool roachIsConnected()
Definition: RoachBackend.cc:276
Definition: Board.h:24
Definition: roachBackend.h:37
~RoachBackend()
Definition: RoachBackend.cc:154
void fillUtc(gcp::util::TimeVal &currTime)
Definition: FdSet.h:16
bool sim_
Definition: roachBackend.h:181
bool connect()
Definition: RoachBackend.cc:164
RoachBackendMsg command_
Definition: roachBackend.h:109
void getData()
Definition: RoachBackend.cc:718
Definition: RoachBackendMsg.h:59
int writeString(std::string message)
Definition: RoachBackend.cc:361
Definition: TimeVal.h:55
void sendCommand(RoachBackendMsg &command)
Definition: RoachBackend.cc:330
int readResponse(RoachBackendMsg &command)
Definition: RoachBackend.cc:380