Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
PacketGenerator.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/PacketGenerator.h"
25 #include "panda/Log.h"
26 
27 
28 namespace ska {
29 namespace cheetah {
30 namespace rcpt {
31 
32 
33 template<typename DataGenerator>
35  ,data::DimensionSize<data::Frequency> number_of_channels
36  ,data::DimensionSize<data::Time> number_of_time_samples
37  )
38  : _model(model)
39  , _data(number_of_time_samples, number_of_channels)
40  , _data_iterator(_data.cend())
41  , _counter(0)
42  , _interval(1)
43  , _max_buffers(5)
44  , _buffer_index(0)
45 {
46  _buffers.reserve(_max_buffers);
47  for(unsigned i=0; i < _max_buffers; ++i) {
48  _buffers.emplace_back(Packet::size());
49  }
50 }
51 
52 template<typename DataGenerator>
54 {
55 }
56 
57 template<typename DataGenerator>
58 ska::panda::Buffer<char> PacketGenerator<DataGenerator>::next()
59 {
60  ska::panda::Buffer<char>& buffer = _buffers[++_buffer_index%_max_buffers];
61  //ska::panda::Buffer<char>& buffer(BeamFormerPacket::size());
62 
63  char* ptr = buffer.data();
64  auto packet = new(ptr) Packet; // placement new
65 
66  // fill the packet header.
67  packet->packet_count(_counter);
68  packet->first_channel_number(0);
69  packet->packet_type(PacketType::StokesI);
70 
71  for (unsigned i = 0; i < Packet::number_of_samples(); ++i) {
72  if(_data_iterator == _data.cend())
73  {
74  // get next chunk of data from the model
75  _model.next(_data);
76  _data_iterator = _data.cbegin();
77  }
78 
79  // Fill the packet data.
80  packet->insert(i, Sample(
81  *_data_iterator,
82  *_data_iterator,
83  0,
84  0));
85  ++_data_iterator;
86  }
87 
88  // Increment counters for next time.
89  ++_counter;
90  return buffer;
91 }
92 
93 template<typename DataGenerator>
95 {
96  return _interval;
97 }
98 
99 template<typename DataGenerator>
101 {
102 }
103 
104 } // namespace rcpt
105 } // namespace cheetah
106 } // namespace ska
Packs data into a UDP stream Packet Header format of the BeamFormer.
static constexpr std::size_t size()
the total size of the packet (header + payload + footer)
Some limits and constants for FLDO.
Definition: Brdz.h:35
void packet_count(uint64_t)
set the counter in the header
THe incoming RF signal sample from the UDP stream.
Definition: Sample.h:41
PacketGenerator(DataGenerator &model, data::DimensionSize< data::Frequency > number_of_channels, data::DimensionSize< data::Time > number_of_time_samples=data::DimensionSize< data::Time >(100U))
static constexpr std::size_t number_of_samples()
the total number of samples in the rcpt payload