My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
RoachBackend.h
Go to the documentation of this file.
1 #ifndef ROACHBACKEND_H
2 #define ROACHBACKEND_H
3 
12 #include <iostream>
13 #include <math.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <sys/socket.h>
17 #include <netinet/in.h>
18 #include <termios.h>
19 #include <string>
20 #include "gcp/util/common/String.h"
21 
22 #include <vector>
23 
24 #include "gcp/util/common/FdSet.h"
25 #include "gcp/util/common/Directives.h"
26 #include "gcp/antenna/control/specific/RoachBackendMsg.h"
27 #include "gcp/control/code/unix/libunix_src/common/regmap.h" // RegMapBlock
28 #include "gcp/antenna/control/specific/Board.h"
29 #include <termios.h>
30 #include <string>
31 
32 
36 #define ROACH_TIMEOUT_USEC 10000
37 #define RING_BUFFER_LENGTH 300 // size of our buffer
38 
39 namespace gcp {
40  namespace antenna {
41  namespace control {
42 
43  class SpecificShare;
44 
45  class RoachBackend : public Board {
46 
47  public:
48 
52  RoachBackend(bool sim=false, char* controllerName="pumba");
53  RoachBackend(SpecificShare* share, std::string name, bool sim=false, char* controllerName="pumba", int roachNum=1);
54  void Assign3DRingMemory();
55  void Assign2DRingMemory();
56 
60  virtual ~RoachBackend();
61 
65  bool connect();
66 
71 
76 
81 
85  void disconnect();
86 
90  bool connected_;
91  bool roachIsConnected();
92 
97 
101  int waitForResponse();
102 
106  void wait(int nsec=100000000);
107 
111  int issueCommand(RoachBackendMsg& command);
112 
116  void sendCommand(RoachBackendMsg& command);
117 
123  int readResponse(RoachBackendMsg& command);
124 
129 
133  int parseBackendResponse(RoachBackendMsg& command);
134 
138  void checkOneOutput(RoachBackendMsg& command);
139 
143  void getData();
144 
148  void sendMessage(RoachBackendMsg message);
149 
153  void writeData(gcp::util::TimeVal& currTime);
154  void writeData3D(gcp::util::TimeVal& currTime);
155 
156  // private:
157  void printBits(unsigned char feature);
158 
162  int writeString(std::string message);
163  int readTCPPort(RoachBackendMsg& command);
164 
168  int fd_;
169 
170 
174  gcp::util::FdSet fdSet_;
178  bool sim_;
179 
183  struct termios termioSave_;
184 
185 
189  std::vector<int> version_; // roach version number
190  std::vector<int> packetSize_;// numbers of bytes in the transfer
191  std::vector<int> numFrames_; // number of frames being transfer
192  std::vector<int> intCount_; // number of accumulation on fpga
193  std::vector<int> bufferBacklog_; // buffer backlog on the Roach
194  std::vector<int> tstart_; // start time of integration
195  std::vector<int> switchstatus_; // switching status Noise Diode etc
196  std::vector<int> tstop_; // stop time of integration
197  std::vector<int> intLength_; // integration length in clock cycles
198  std::vector<int> mode_; // backend mode (polarization or power);
199  std::vector<int> res2_; // reserved 4 bytes
200  std::vector<int> seconds_; // seconds from the roach
201  std::vector<int> useconds_; // useconds from the roach
202  std::vector<float> Coeffs_;
203 
204 #if(0) // 3D stuff
205  std::vector<std::vector< std::vector<float> > > LL_;
206  std::vector<std::vector<std::vector<float> > > RR_;
207  std::vector<std::vector<std::vector<float> > > Q_;
208  std::vector<std::vector<std::vector<float> > > U_;
209  std::vector<std::vector<std::vector<float> > > TL1_;
210  std::vector<std::vector<std::vector<float> > > TL2_;
211 #endif
212  std::vector<std::vector<float> > LL_;
213  std::vector<std::vector<float> > RR_;
214  std::vector<std::vector<float> > Q_;
215  std::vector<std::vector<float> > U_;
216  std::vector<std::vector<float> > TL1_;
217  std::vector<std::vector<float> > TL2_;
218 
219  int currentIndex_;
220  int prevSecStart_;
221  int prevSecEnd_;
222  int thisSecStart_;
223  float prevTime_;
224 
228  RegMapBlock* roachUtc_;
229  RegMapBlock* roachVersion_;
230  RegMapBlock* roachCount_;
231  RegMapBlock* roachIntLength_;
232  RegMapBlock* roachBufferBacklog_;
233  RegMapBlock* roachMode_;
234  RegMapBlock* roachSwitchStatus_;
235  RegMapBlock* roachLL_;
236  RegMapBlock* roachRR_;
237  RegMapBlock* roachQ_;
238  RegMapBlock* roachU_;
239  RegMapBlock* roachTL1_;
240  RegMapBlock* roachTL2_;
241  RegMapBlock* roachChan_;
242  RegMapBlock* roachLLfreq_;
243  RegMapBlock* roachRRfreq_;
244  RegMapBlock* roachQfreq_;
245  RegMapBlock* roachUfreq_;
246  RegMapBlock* roachTL1freq_;
247  RegMapBlock* roachTL2freq_;
248  RegMapBlock* roachLLtime_;
249  RegMapBlock* roachRRtime_;
250  RegMapBlock* roachQtime_;
251  RegMapBlock* roachUtime_;
252  RegMapBlock* roachTL1time_;
253  RegMapBlock* roachTL2time_;
254  RegMapBlock* roachNTPSeconds_;
255  RegMapBlock* roachNTPuSeconds_;
256  RegMapBlock* roachFPGAClockStamp_;
257  RegMapBlock* roachCoffs_;
258 
259 
260  }; // End class RoachBackend
261  }; // End namespace control
262  }; // End namespace antenna
263 }; // End namespace gcp
264 #endif
265 
void sendMessage(RoachBackendMsg message)
Definition: RoachBackend.cc:1397
bool connected_
Definition: roachBackend.h:179
char * controllerName_
Definition: RoachBackend.h:75
void checkOneOutput(RoachBackendMsg &command)
Definition: RoachBackend.cc:690
void disconnect()
Definition: RoachBackend.cc:250
bool roachIsConnected()
Definition: RoachBackend.cc:276
RegMapBlock * roachUtc_
Definition: RoachBackend.h:228
std::vector< int > version_
Definition: RoachBackend.h:189
~RoachBackend()
Definition: RoachBackend.cc:154
Definition: FdSet.h:16
bool sim_
Definition: roachBackend.h:181
bool connect()
Definition: RoachBackend.cc:164
int parseBackendDataPacket(RoachBackendMsg &command)
Definition: RoachBackend.cc:635
RoachBackendMsg command_
Definition: roachBackend.h:109
int missedCommCounter_
Definition: RoachBackend.h:70
void Assign3DRingMemory()
Definition: RoachBackend.cc:1422
void writeData(gcp::util::TimeVal &currTime)
Definition: RoachBackend.cc:1061
int issueCommand(RoachBackendMsg &command)
Definition: RoachBackend.cc:543
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 roachIndex_
Definition: RoachBackend.h:80
void writeData3D(gcp::util::TimeVal &currTime)
Definition: RoachBackend.cc:839
void Assign2DRingMemory()
Definition: RoachBackend.cc:1492
int readResponse(RoachBackendMsg &command)
Definition: RoachBackend.cc:380