Psyllid  v1.12.4
Project 8 Data Acquisisition Software
roach_packet.hh
Go to the documentation of this file.
1 /*
2  * roach_packet.hh
3  *
4  * Created on: Dec 25, 2015
5  * Author: nsoblath
6  */
7 
8 #ifndef PSYLLID_ROACH_PACKET_HH_
9 #define PSYLLID_ROACH_PACKET_HH_
10 
11 #include <cinttypes>
12 #include <cstddef> // for size_t
13 
14 // number of samples in the roach_packet f_data array
15 #define PAYLOAD_SIZE 8192 // 1KB
16 
17 // number of integers used in the pkt_in_batch counter
18 #define BATCH_COUNTER_SIZE 390626
19 
20 // Packet payloads are divided into 64-bit integers, each of which is loaded in a little-endian way, and then transmitted over the network in big-endian order.
21 // During transmission the payload has this order: r3, i3, r2, i2, r1, i1, r0, i0, r7, i7, . . . .
22 // Therefore just using be64toh will end up reversing real and imaginary components when converting to a little-endian host, and have no effect at all on a big-endian host.
23 // We need to make this shift regardless of the byte ordering of the host, since we're not actually interpreting the payload as 64-bit integers, but as individual bytes.
24 #define payload_swap(x) \
25  ( ( (x & 0xffff000000000000ull) >> 48 ) | \
26  ( (x & 0x0000ffff00000000ull) >> 16 ) | \
27  ( (x & 0x00000000ffff0000ull) << 16 ) | \
28  ( (x & 0x000000000000ffffull) << 48 ) )
29 
30 
31 namespace psyllid
32 {
33 
108  {
109  // first 64bit word
110  uint32_t f_unix_time;
111  uint32_t f_pkt_in_batch:20;
112  uint32_t f_digital_id:6;
113  uint32_t f_if_id:6;
114  // second 64bit word
115  uint32_t f_user_data_1;
116  uint32_t f_user_data_0;
117  // third 64bit word
118  uint64_t f_reserved_0;
119  // fourth 64bit word
120  uint64_t f_reserved_1:63;
121  uint8_t f_freq_not_time:1;
122  // payload
123  int8_t f_data[ PAYLOAD_SIZE ];
124  };
125 
127  {
128  uint64_t f_word_0;
129  uint64_t f_word_1;
130  uint64_t f_word_2;
131  uint64_t f_word_3;
133  };
134 
135  void byteswap_inplace( raw_roach_packet* a_pkt );
136 
137 
139  {
140  public:
142  virtual ~roach_packet_data();
143 
144  public:
145  uint32_t get_unix_time() const;
146  void set_unix_time( uint32_t a_time );
147 
148  uint32_t get_pkt_in_batch() const;
149  void set_pkt_in_batch( uint32_t a_pkt );
150 
151  uint32_t get_digital_id() const;
152  void set_digital_id( uint32_t );
153 
154  uint32_t get_if_id() const;
155  void set_if_id( uint32_t );
156 
157  uint32_t get_user_data_1() const;
158  void set_user_data_1( uint32_t a_data );
159 
160  uint32_t get_user_data_0() const;
161  void set_user_data_0( uint32_t a_data );
162 
163  uint64_t get_reserved_0() const;
164  void set_reserved_0( uint64_t a_res );
165 
166  uint64_t get_reserved_1() const;
167  void set_reserved_1( uint64_t a_res );
168 
169  bool get_freq_not_time() const;
170  void set_freq_not_time( bool a_flag );
171 
172  const int8_t* get_raw_array() const;
173  size_t get_raw_array_size() const;
174 
175  public:
176  const roach_packet& packet() const;
177  roach_packet& packet();
178 
179  protected:
181  };
182 
183 
184  inline uint32_t roach_packet_data::get_unix_time() const
185  {
186  return f_packet.f_unix_time;
187  }
188 
189  inline void roach_packet_data::set_unix_time( uint32_t a_time )
190  {
191  f_packet.f_unix_time = a_time;
192  return;
193  }
194 
195  inline uint32_t roach_packet_data::get_pkt_in_batch() const
196  {
197  return f_packet.f_pkt_in_batch;
198  }
199 
200  inline void roach_packet_data::set_pkt_in_batch( uint32_t a_pkt )
201  {
202  f_packet.f_pkt_in_batch = a_pkt;
203  return;
204  }
205 
206  inline uint32_t roach_packet_data::get_digital_id() const
207  {
208  return f_packet.f_digital_id;
209  }
210 
211  inline void roach_packet_data::set_digital_id( uint32_t a_id )
212  {
213  f_packet.f_digital_id = a_id;
214  return;
215  }
216 
217  inline uint32_t roach_packet_data::get_if_id() const
218  {
219  return f_packet.f_if_id;
220  }
221 
222  inline void roach_packet_data::set_if_id( uint32_t a_id )
223  {
224  f_packet.f_if_id = a_id;
225  return;
226  }
227 
228  inline uint32_t roach_packet_data::get_user_data_1() const
229  {
230  return f_packet.f_user_data_1;
231  }
232 
233  inline void roach_packet_data::set_user_data_1( uint32_t a_data )
234  {
235  f_packet.f_user_data_1 = a_data;
236  return;
237  }
238 
239  inline uint32_t roach_packet_data::get_user_data_0() const
240  {
241  return f_packet.f_user_data_0;
242  }
243 
244  inline void roach_packet_data::set_user_data_0( uint32_t a_data )
245  {
246  f_packet.f_user_data_0 = a_data;
247  return;
248  }
249 
250  inline uint64_t roach_packet_data::get_reserved_0() const
251  {
252  return f_packet.f_reserved_0;
253  }
254 
255  inline void roach_packet_data::set_reserved_0( uint64_t a_res )
256  {
257  f_packet.f_reserved_0 = a_res;
258  return;
259  }
260 
261  inline uint64_t roach_packet_data::get_reserved_1() const
262  {
263  return f_packet.f_reserved_1;
264  }
265 
266  inline void roach_packet_data::set_reserved_1( uint64_t a_res )
267  {
268  f_packet.f_reserved_1 = a_res;
269  return;
270  }
271 
273  {
274  return f_packet.f_freq_not_time;
275  }
276 
277  inline void roach_packet_data::set_freq_not_time( bool a_flag )
278  {
279  f_packet.f_freq_not_time = a_flag;
280  return;
281  }
282 
283  inline const int8_t* roach_packet_data::get_raw_array() const
284  {
285  return f_packet.f_data;
286  }
287 
289  {
290  return PAYLOAD_SIZE;
291  }
292 
294  {
295  return f_packet;
296  }
297 
299  {
300  return f_packet;
301  }
302 
303 } /* namespace psyllid */
304 
305 #endif /* PSYLLID_ROACH_PACKET_HH_ */
void set_freq_not_time(bool a_flag)
void set_digital_id(uint32_t)
void set_reserved_1(uint64_t a_res)
uint32_t get_user_data_0() const
const roach_packet & packet() const
#define PAYLOAD_SIZE
Definition: roach_packet.hh:15
void byteswap_inplace(raw_roach_packet *a_pkt)
Definition: roach_packet.cc:22
const int8_t * get_raw_array() const
void set_reserved_0(uint64_t a_res)
void set_pkt_in_batch(uint32_t a_pkt)
size_t get_raw_array_size() const
uint32_t get_pkt_in_batch() const
uint32_t get_if_id() const
void set_user_data_1(uint32_t a_data)
uint64_t get_reserved_1() const
void set_user_data_0(uint32_t a_data)
uint32_t get_user_data_1() const
uint32_t get_digital_id() const
uint64_t get_reserved_0() const
void set_unix_time(uint32_t a_time)
uint32_t get_unix_time() const