Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
BeamFormerPacket.cpp
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2016 The SKA organisation
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "cheetah/rcpt_low/BeamFormerPacket.h"
25 #include <cassert>
26 #include <limits>
27 
28 
29 namespace ska {
30 namespace cheetah {
31 namespace rcpt_low {
32 
33 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
35 {
36  return sizeof(PacketHeader);
37 }
38 
39 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
41 {
42  //return sizeof(Footer);
43  return 0;
44 }
45 
46 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
48 {
49  return _packet_data_size+_packet_weights_size+_packet_data_padding_size+_packet_weights_padding_size;
50 }
51 
52 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
54 {
55  return _packet_data_size;
56 }
57 
58 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
60 {
61  return _number_of_time_samples;
62 }
63 
64 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
66 {
67  return _number_of_samples;
68 }
69 
70 
71 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
73 {
74  return _size;
75 }
76 
77 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
79 {
80  return std::numeric_limits<PacketNumberType>::max();
81 }
82 
83 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
85 {
86 }
87 
88 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
90 {
91 }
92 
93 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
95 {
96  return _number_of_channels;
97 }
98 
99 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
101 ::packet_count(PacketNumberType packet_count)
102 {
103  _header.packet_sequence_number = packet_count;
104 }
105 
106 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
108 {
109  return _header.packet_sequence_number;
110 }
111 
112 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
114 {
115  _header.packet_destination = static_cast<decltype(_header.packet_destination)>(type);
116 }
117 
118 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
119 typename BeamFormerPacket<PacketDataType, TimeSamplesPerPacket, ChannelsPerPacket>::PacketType BeamFormerPacket<PacketDataType, TimeSamplesPerPacket, ChannelsPerPacket>::packet_type() const
120 {
121  return _header.packet_destination;
122 }
123 
124 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
126 {
127  assert(sample_number < number_of_samples());
128  _data[sample_number] = std::move(s); // seems to be faster than using std::swap
129 }
130 
131 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
133 {
134  return _data[sample_number];
135 }
136 
137 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
139 {
140  return &_data[0];
141 }
142 
143 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
145 {
146  return &_data[_packet_data_size/sizeof(Sample)];
147 }
148 
149 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
150 const typename BeamFormerPacket<PacketDataType, TimeSamplesPerPacket, ChannelsPerPacket>::WeightsType* BeamFormerPacket<PacketDataType, TimeSamplesPerPacket, ChannelsPerPacket>::begin_weights() const
151 {
152  return &_weights[0];
153 }
154 
155 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
156 const typename BeamFormerPacket<PacketDataType, TimeSamplesPerPacket, ChannelsPerPacket>::WeightsType* BeamFormerPacket<PacketDataType, TimeSamplesPerPacket, ChannelsPerPacket>::end_weights() const
157 {
158  return &_weights[_packet_weights_size/sizeof(WeightsType)];
159 }
160 
161 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
163 {
164  for(unsigned i=0; i<ChannelsPerPacket; ++i) _weights[i]=1;;
165  return;
166 }
167 
168 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
170 {
171  return _header.first_channel_number;
172 }
173 
174 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
176 ::first_channel_number(ChannelNumberType number)
177 {
178  _header.first_channel_number = number;
179 }
180 
181 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
182 void BeamFormerPacket<PacketDataType, TimeSamplesPerPacket, ChannelsPerPacket>::first_channel_frequency(boost::units::quantity<data::MegaHertz, double> value)
183 {
184  _header.first_channel_frequency = static_cast<decltype(PacketHeader::first_channel_frequency)>(value.value()*1000);
185 }
186 
187 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
189 {
190  double frequency_value = ((double)_header.first_channel_frequency)/1000.0;
191 
192  return (frequency_value * boost::units::si::mega * boost::units::si::hertz);
193 }
194 
195 
196 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
198 {
199  return _header.scan_id;
200 }
201 
202 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
204 {
205  _header.scan_id = number;
206 }
207 
211 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
213 {
214  return _header.beam_number;
215 }
216 
217 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
219 ::beam_number(BeamNumberType number)
220 {
221  _header.beam_number = number;
222 }
223 
224 
225 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
228 {
229  return _header.magic_word;
230 }
231 
232 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
234 ::magic_word(MagicWordType number)
235 {
236  _header.magic_word = number;
237 }
238 
239 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
241 ::timestamp_attoseconds() const -> decltype(PacketHeader::timestamp_attoseconds)
242 {
243  return _header.timestamp_attoseconds;
244 }
245 
246 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
248 ::timestamp_attoseconds(decltype(PacketHeader::timestamp_attoseconds) number)
249 {
250  _header.timestamp_attoseconds = number;
251 }
252 
253 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
255 ::timestamp_seconds() const -> decltype(PacketHeader::timestamp_seconds)
256 {
257  return _header.timestamp_seconds;
258 }
259 
260 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
262 ::timestamp_seconds(decltype(PacketHeader::timestamp_seconds) number)
263 {
264  _header.timestamp_seconds = number;
265 }
266 
267 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
270 {
271  return _header.channel_separation;
272 }
273 
274 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
276 ::channel_separation(ChannelSeperationType number)
277 {
278  _header.channel_separation = number;
279 }
280 
281 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
284 {
285  return _header.data_precision;
286 }
287 
288 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
290 ::data_precision(DataPrecisionType number)
291 {
292  _header.data_precision = number;
293 }
294 
295 
296 } // namespace rcpt_low
297 } // namespace cheetah
298 } // namespace ska
Interface to packing/unpacking rcpt from the BeamFormer rcpt stream UDP packet.
DataPrecisionType data_precision() const
Data precision.
void set_unit_weights()
set all weights to unity
PacketType packet_type() const
return the packet type
static constexpr std::size_t size()
the total size of the packet (header + payload + footer)
auto timestamp_seconds() const -> decltype(PacketHeader::timestamp_seconds)
Timestamp in seconds.
Sample const & sample(std::size_t sample) const
return the named sample
static constexpr PacketNumberType max_sequence_number()
return the maximum value the packet_count can take
boost::units::quantity< data::MegaHertz, double > first_channel_frequency() const
First channel frequency in the packet in MHz.
ChannelSeperationType channel_separation() const
channel_separation
static constexpr std::size_t footer_size()
the total size of the udp packets footer
MagicWordType magic_word() const
scaling factor float scale() const; float scale(float number);
static std::size_t number_of_time_samples()
the total number of time samples in the packet
const Sample * begin() const
Pointers to the begin and end of the data in the packet.
const WeightsType * begin_weights() const
Pointers to the begin and end of the weights in the packet.
The incoming RF signal sample from the UDP stream.
Definition: PacketSample.h:42
void insert(std::size_t sample_number, Sample s)
insert a sample
Some limits and constants for FLDO.
Definition: Brdz.h:35
PacketNumberType packet_count() const
get the counter info from header
ChannelNumberType first_channel_number() const
the number of the first channel in the packet
static constexpr std::size_t header_size()
the total size of the udp packets header
auto timestamp_attoseconds() const -> decltype(PacketHeader::timestamp_attoseconds)
Timestamp in attoseconds.
static constexpr std::size_t number_of_samples()
the total number of samples in the rcpt payload
ScanIdType scan_id() const
scan ID of the packet stream
static constexpr std::size_t payload_size()
the total size in bytes of the channel rcpt
static constexpr std::size_t data_size()
the total size in bytes of the channel rcpt
static std::size_t number_of_channels()
the total number of frequencey channels in the rcpt payload
BeamNumberType beam_number() const
beam id of the packet stream