My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
RoachBackendMsg.h
Go to the documentation of this file.
1 #ifndef ROACHBACKENDMSG_H
2 #define ROACHBACKENDMSG_H
3 
11 #include <string>
12 #include <map>
13 #include <vector>
14 #include <netinet/in.h>
15 #include <errno.h>
16 
17 #include "gcp/util/common/Exception.h"
18 #include "gcp/util/common/LogStream.h"
19 
20 #include "gcp/util/common/GenericTaskMsg.h"
21 
22 //#include "gcp/antenna/control/specific/roachserver/structUDPCBASSpkt.h"
23 
24 #include "gcp/control/code/unix/libunix_src/common/netobj.h"
25 #include "gcp/util/common/Debug.h"
26 #include "gcp/util/specific/Directives.h"
27 
28 
29 // The hard limit -- pmac can't process more than this in a single
30 // message
31 
32 #define ROACH_DATA_MAX_LEN 40000
33 #define MILLI_SECOND_SAMPLE_RATE 10
34 #define MAX_RESPONSE_SAMPLES 1000/MILLI_SECOND_SAMPLE_RATE*6*2*64
35 
36 // the following should move the specificregs.h eventually
37 #define NUM_ROACH_INTEGRATION_PER_TRANSFER 10
38 #define NUM_CHANNELS_PER_BAND 32
39 #define NUM_PARITY 2
40 
41 #define kDataperPacket 10
42 #define vectorLength 32 //size of FFT (32)
43 #define kMax32bitchans 320 //size of vector to store data (kDataperPacket*vectorLenght
44 
45 #define CC_TO_SEC 128/250000000
46 
47 #define DEFAULT_NUMBER_BYTES_PER_TRANSFER 17680
48 //#define DEFAULT_NUMBER_BYTES_PER_TRANSFER 15632
49 //#define DEFAULT_NUMBER_BYTES_PER_TRANSFER 15472
50 //#define DEFAULT_NUMBER_BYTES_PER_TRANSFER 15432
51 
52 namespace gcp {
53  namespace antenna {
54  namespace control {
55 
56 
57  class RoachBackend;
58 
61 
62  public:
63 
68  void Assign3DVectorMemory();
69  void Assign2DVectorMemory();
70 
75 
79  double currTime_; // in mjd
80  // friend class RoachBackend;
84  enum Request {
85 
86  /* need a PACKBLAHBLAH function to deal with each of these. */
87  INVALID, // Default which will be used to
88  READ_DATA, // test command
89  WRITE_DATA,
90  CONNECT,
91  DISCONNECT,
92  ROACH_COMMAND
93  };
94 
98  unsigned char request_;
99 
103  unsigned short cmdSize_;
104 
108  std::string messageToSend_;
109 
114 
118  std::string expectedResponse_;
119  int numBytesExpected_;
120 
124  char responseReceived_[DEFAULT_NUMBER_BYTES_PER_TRANSFER];
125  int numBytesReceived_;
126 
130  size_t responseLength();
131 
132 
133 
137  void packCommand(Request req);
138  void packCommand(Request req, std::vector<float>& values);
139 
143  void interpretResponse();
144 
148  bool simpleValidityCheck();
149 
153  unsigned char readData_[ROACH_DATA_MAX_LEN];
154 
158  int version_; // roach version number
159  int packetSize_;// numbers of bytes in the transfer
160  int numFrames_; // number of frames being transfer
161  int intCount_; // number of accumulation on fpga
162  std::vector<int> bufferBacklog_; // backlog
163  std::vector<int> tstart_; // start time of integration
164  std::vector<int> seconds_; // roach NTP second
165  std::vector<int> useconds_; // roach NTP usecond
166  std::vector<int> switchstatus_;
167  std::vector<float> Coeffs_;
168  int tstop_; // stop time of integration
169  int intLength_; // integration length in clock cycles
170  int mode_; // backend mode (polarization or power);
171  int res2_; // reserved 4 bytes
172 
173 #if(0)
174  std::vector<std::vector< std::vector<float> > > LL_;
175  std::vector<std::vector<std::vector<float> > > RR_;
176  std::vector<std::vector<std::vector<float> > > Q_;
177  std::vector<std::vector<std::vector<float> > > U_;
178  std::vector<std::vector<std::vector<float> > > TL1_;
179  std::vector<std::vector<std::vector<float> > > TL2_;
180 #endif
181 
182  std::vector<std::vector<float> > LL_;
183  std::vector<std::vector<float> > RR_;
184  std::vector<std::vector<float> > Q_;
185  std::vector<std::vector<float> > U_;
186  std::vector<std::vector<float> > TL1_;
187  std::vector<std::vector<float> > TL2_;
188 
189 
194 
199 
204 
208  float responseValue_[MAX_RESPONSE_SAMPLES];
209 
210 //data structure definition
211 struct UDPCBASSpkt {
212  int version; // 4 byte
213  int data_size; // 4 byte
214  int dataCount; //4 byte
215  int buffBacklog[10]; //40 byte
216  int int_count; // 4 byte
217  int tstart[10]; // 4 byte
218  int tend; // 4 byte
219  int int_len; // 4 byte
220  int reserved1; // 4 byte
221  int reserved2; // 4 byte
222  int data_ch0odd[kDataperPacket*vectorLength];
223  int data_ch0even[kDataperPacket*vectorLength];
224  int data_ch1odd[kDataperPacket*vectorLength];
225  int data_ch1even[kDataperPacket*vectorLength];
226  int data_ch2odd[kDataperPacket*vectorLength];
227  int data_ch2even[kDataperPacket*vectorLength];
228  int data_ch3odd[kDataperPacket*vectorLength];
229  int data_ch3even[kDataperPacket*vectorLength];
230  int data_ch4odd[kDataperPacket*vectorLength];
231  int data_ch4even[kDataperPacket*vectorLength];
232  int data_ch5odd[kDataperPacket*vectorLength];
233  int data_ch5even[kDataperPacket*vectorLength];
234  int data_switchstatus[kDataperPacket];
235  int secondIntegration[kDataperPacket]; //4*10=40
236  int tsecond[10];
237  int tusecond[10];
238  int coeffs[32*16]; // 2048 byte
239 // int amp2real[32]; // 128 byte
240 // int amp3real[32]; // 128 byte
241 // int amp4real[32]; // 128 byte
242 // int amp5real[32]; // 128 byte
243 // int amp6real[32]; // 128 byte
244 // int amp7real[32]; // 128 byte
245 // int amp0imag[32]; // 128 byte
246 // int amp1imag[32]; // 128 byte
247 // int amp2imag[32]; // 128 byte
248 // int amp3imag[32]; // 128 byte
249 // int amp4imag[32]; // 128 byte
250  // int amp5imag[32]; // 128 byte
251 // int amp6imag[32]; // 128 byte
252 // int amp7imag[32]; // 128 byte
253 };
254 
255 
256  UDPCBASSpkt packet_;
257 
258  UDPCBASSpkt* packetPtr_;
259 
260  int packetizeNetworkMsg();
261 
262  void PrintData();
263 
264  //------------------------------------------------------------
265  // Methods for packing messages
266  //------------------------------------------------------------
267 
268  //------------------------------------------------------------
269  // Pack a command to read data from the roach
270  //------------------------------------------------------------
271  inline void packReadDataMsg()
272  {
274  gcp::util::GenericTaskMsg::TASK_SPECIFIC;
275 
276  request_ = READ_DATA;
277  messageToSend_ = "GETDATAXXX";
278  expectsResponse_ = true;
279  numBytesExpected_ = DEFAULT_NUMBER_BYTES_PER_TRANSFER;
280  cmdSize_ = 10;
281  // number of rx = rxNum;
282  }
283 
284 
285  //------------------------------------------------------------
286  // Pack a command to write data from the roach to disk
287  //------------------------------------------------------------
288  inline void packWriteDataMsg(gcp::util::TimeVal& currTime)
289  {
291  gcp::util::GenericTaskMsg::TASK_SPECIFIC;
292 
293  request_ = WRITE_DATA;
294 
295  currTime_ = currTime.getTimeInSeconds();
296 
297  }
298 
299  //------------------------------------------------------------
300  // Pack a command to connected to roach
301  //------------------------------------------------------------
302  inline void packConnectMsg()
303  {
305  gcp::util::GenericTaskMsg::TASK_SPECIFIC;
306 
307  request_ = CONNECT;
308  }
309 
310  //------------------------------------------------------------
311  // Pack a command to disconnect the roach
312  //------------------------------------------------------------
313  inline void packDisconnectMsg()
314  {
316  gcp::util::GenericTaskMsg::TASK_SPECIFIC;
317 
318  request_ = DISCONNECT;
319  }
320 
321 
322  //------------------------------------------------------------
323  // Pack a general command
324  //------------------------------------------------------------
325  inline void packRoachCmdMsg(std::string stringCommand)
326  {
328  gcp::util::GenericTaskMsg::TASK_SPECIFIC;
329 
330  request_ = ROACH_COMMAND;
331  messageToSend_ = stringCommand;
332  expectsResponse_ = true;
333  numBytesExpected_ = 12;
334  cmdSize_ = stringCommand.size();
335 
336  };
337 
338 
339 
340 
341  }; // End class RoachBackendMsg
342 
343  }; // End namespace control
344  }; // End namespace antenna
345 }; // End namespace gcp
346 
347 #endif // End #ifndef
Definition: GenericTaskMsg.h:31
RoachBackendMsg()
Definition: RoachBackendMsg.cc:25
void Assign3DVectorMemory()
Definition: RoachBackendMsg.cc:221
std::string expectedResponse_
Definition: RoachBackendMsg.h:118
unsigned short cmdSize_
Definition: RoachBackendMsg.h:103
void PrintData()
Definition: RoachBackendMsg.cc:328
int version_
Definition: RoachBackendMsg.h:158
unsigned char readData_[ROACH_DATA_MAX_LEN]
Definition: RoachBackendMsg.h:153
~RoachBackendMsg()
Definition: RoachBackendMsg.cc:38
double currTime_
Definition: RoachBackendMsg.h:79
GenericMsgType genericMsgType_
Definition: GenericTaskMsg.h:50
float responseValue_[MAX_RESPONSE_SAMPLES]
Definition: RoachBackendMsg.h:208
bool responseValid_
Definition: RoachBackendMsg.h:193
int packetizeNetworkMsg()
Definition: RoachBackendMsg.cc:44
Definition: RoachBackendMsg.h:59
Definition: TimeVal.h:55
double getTimeInSeconds() const
Definition: TimeVal.cc:589
bool responseValueValid_
Definition: RoachBackendMsg.h:203
bool responseGood_
Definition: RoachBackendMsg.h:198
std::string messageToSend_
Definition: RoachBackendMsg.h:108
char responseReceived_[DEFAULT_NUMBER_BYTES_PER_TRANSFER]
Definition: RoachBackendMsg.h:124
Request
Definition: RoachBackendMsg.h:84
bool expectsResponse_
Definition: RoachBackendMsg.h:113
unsigned char request_
Definition: RoachBackendMsg.h:98
void Assign2DVectorMemory()
Definition: RoachBackendMsg.cc:279