Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
BeamFormerPacket.h
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 #ifndef SKA_CHEETAH_RCPT_LOW_BEAMFORMERPACKET_LOW_H
25 #define SKA_CHEETAH_RCPT_LOW_BEAMFORMERPACKET_LOW_H
26 
27 #include "PacketSample.h"
28 #include "cheetah/data/Units.h"
29 #include "cheetah/rcpt_low/Config.h"
30 #include "ska/cbf_psr_interface/CbfPsrHeader.h"
31 #include <cstdlib>
32 #include <cstdint>
33 #include <array>
34 
35 namespace ska {
36 namespace cheetah {
37 namespace rcpt_low {
38 
46 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
48 {
49 
50  public:
51  enum class PacketType { PssLow, PssMid, PstLow, PstMid};
52 
53  private:
55  typedef struct ska::cbf_psr_interface::CbfPsrHeader PacketHeader;
56  typedef decltype(PacketHeader::packet_sequence_number) PacketNumberType;
57  typedef decltype(PacketHeader::first_channel_number) ChannelNumberType;
58  typedef decltype(PacketHeader::scan_id) ScanIdType;
59  typedef decltype(PacketHeader::beam_number) BeamNumberType;
60  typedef decltype(PacketHeader::data_precision) DataPrecisionType;
61  typedef decltype(PacketHeader::magic_word) MagicWordType;
62  typedef decltype(PacketHeader::channel_separation) ChannelSeperationType;
63  typedef uint16_t WeightsType;
64 
65  public:
68 
72  constexpr static std::size_t header_size();
73 
77  constexpr static std::size_t footer_size();
78 
82  constexpr static std::size_t payload_size();
83 
87  constexpr static std::size_t data_size();
88 
92  static std::size_t number_of_time_samples();
93 
97  constexpr static std::size_t number_of_samples();
98 
102  static std::size_t number_of_channels();
103 
107  constexpr static std::size_t size();
108 
112  void packet_count(PacketNumberType);
113 
117  PacketNumberType packet_count() const;
118 
122  void packet_type(PacketType const);
123 
127  PacketType packet_type() const;
128 
132  void insert(std::size_t sample_number, Sample s);
133 
137  Sample const& sample(std::size_t sample) const;
138 
142  const Sample* begin() const;
143  const Sample* end() const;
144 
148  const WeightsType* begin_weights() const;
149  const WeightsType* end_weights() const;
150 
154  static constexpr PacketNumberType max_sequence_number();
155 
159  ChannelNumberType first_channel_number() const;
160  void first_channel_number(ChannelNumberType number);
161 
165  ScanIdType scan_id() const;
166  void scan_id(ScanIdType number);
167 
168 
172  BeamNumberType beam_number() const;
173  void beam_number(BeamNumberType number);
174 
178  boost::units::quantity<data::MegaHertz, double> first_channel_frequency() const;
179  void first_channel_frequency(boost::units::quantity<data::MegaHertz, double> value);
180 
184  DataPrecisionType data_precision() const;
185  void data_precision(DataPrecisionType number);
186 
196  MagicWordType magic_word() const;
197  void magic_word(MagicWordType number);
198 
202  auto channels_per_packet() const -> decltype(PacketHeader::channels_per_packet);
203  void channels_per_packet(decltype(PacketHeader::channels_per_packet) number);
204 
208  auto timestamp_seconds() const -> decltype(PacketHeader::timestamp_seconds);
209  void timestamp_seconds(decltype(PacketHeader::timestamp_seconds) number);
210 
214  auto timestamp_attoseconds() const -> decltype(PacketHeader::timestamp_attoseconds);
215  void timestamp_attoseconds(decltype(PacketHeader::timestamp_attoseconds) number);
216 
220  ChannelSeperationType channel_separation() const;
221  void channel_separation(ChannelSeperationType number);
222 
226  void set_unit_weights();
227 
228  private: // static variables
229  static constexpr std::size_t _packet_data_size = ChannelsPerPacket*TimeSamplesPerPacket*sizeof(Sample)*2;
230  static constexpr std::size_t _packet_weights_size = ChannelsPerPacket*sizeof(WeightsType);
231  static constexpr std::size_t _packet_data_padding_size = (16-(_packet_data_size%16))%16;
232  static constexpr std::size_t _packet_weights_padding_size = (16-(_packet_weights_size%16))%16;
233 
234  private:
235  PacketHeader _header;
236  static_assert(sizeof(_header)==96,"poor alignment detected in header");
237  WeightsType _weights[(_packet_weights_size+_packet_weights_padding_size)/sizeof(WeightsType)];
238  Sample _data[(_packet_data_size+_packet_data_padding_size)/sizeof(Sample)];
239  static const std::size_t _number_of_samples = _packet_data_size/(sizeof(Sample));
240  static const std::size_t _number_of_channels = _packet_weights_size/sizeof(uint16_t);
241  static const std::size_t _size = _packet_data_padding_size + _packet_weights_padding_size + _packet_data_size + _packet_weights_size + sizeof(PacketHeader);
242  static const std::size_t _number_of_time_samples = _packet_data_size/(2*sizeof(Sample)*_number_of_channels);
243 
244 };
245 
246 
248 static_assert(sizeof(BeamFormerPacketLow)==4736,"BeamFormerPacketLow Packet size is not as expected");
249 
250 static constexpr uint32_t number_of_channels_low = 7776;
251 
252 
253 } // namespace rcpt_low
254 } // namespace cheetah
255 } // namespace ska
256 #include "cheetah/rcpt_low/detail/BeamFormerPacket.cpp"
257 
258 #endif // SKA_CHEETAH_RCPT_LOW_BEAMFORMERPACKET_LOW_H
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
auto channels_per_packet() const -> decltype(PacketHeader::channels_per_packet)
Number of channels in each packet.