Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
BeamFormerDataTraits.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/BeamFormerDataTraits.h"
25 #include <panda/Log.h>
26 #include <algorithm>
27 
28 
29 namespace ska {
30 namespace cheetah {
31 namespace rcpt {
32 
33 template<typename ContextType>
34 void BeamFormerDataTraits::deserialise_packet(ContextType& context, PacketInspector const& packet)
35 {
36  // case I: packet > chunk
37  // [-- Packet 0 --][-- Packet 1 --][-- Packet 2 --]
38  // [Chunk 0][Chunk 1][Chunk 2]
39  // chunk_len * chunk_number = packet_num * packet_data
40  // chunk_len * chunk_number = packet_num * (chunk_len + delta) + offset
41  // offset = chunk_len * chunk_number - packet_num * (chunk_len + delta)
42  // = chunk_len(chunk_number - packet_num) - packet_num * delta
43  //
44  unsigned offset = context.offset(); // * (context.chunk().number_of_channels() * context.chunk().number_of_samples()) - (context.sequence_number() * context.data().packet_size());
45  auto packet_it=packet.packet().begin() + context.packet_offset();
46  auto it=context.chunk().begin() + offset; //(BeamFormerDataTraits::sequence_number(packet) - context.start()) + offset;
47  PANDA_LOG_DEBUG << " --- deserialise_packet: sequence_number=" << context.sequence_number(packet)
48  << " " << context;
49  std::for_each(packet_it, packet_it + context.size(), [&](Sample const& sample) { *it=sample.xx(); ++it; } );
50  //do_deserialise_packet(context, packet.packet(), 0U, std::move(it));
51 }
52 
53 template<typename ContextType>
55 {
56  unsigned offset = context.offset();
57  auto it=context.chunk().begin() + offset;
58  PANDA_LOG_DEBUG << "processing missing packet: data=" << (void*)&*it << context;
59  for(std::size_t i=0; i < context.size() ; ++i) {
60  *it = 99;
61  assert(it!=context.chunk().end());
62  ++it;
63  }
64 }
65 
66 template<typename ResizeContextType>
67 void BeamFormerDataTraits::resize_chunk(ResizeContextType& context)
68 {
69  PANDA_LOG_DEBUG << "resizing data: " << context;
70  // drops any incomplete spectra
71  context.chunk().resize(data::DimensionSize<data::Time>(context.size()/context.chunk().number_of_channels()));
72 }
73 
75 {
77 }
78 
79 } // namespace rcpt
80 } // namespace cheetah
81 } // namespace ska
static void resize_chunk(ContextType &data)
return the total number of samples (time_samples * channels) in the data
static void deserialise_packet(ContextType &context, PacketInspector const &)
function responsible for transfering data from the packet in to the data structure ...
static constexpr uint64_t max_sequence_number()
the maximum value a packet sequence number will reach
BeamFormerPacket inspection and data extraction.
Some limits and constants for FLDO.
Definition: Brdz.h:35
THe incoming RF signal sample from the UDP stream.
Definition: Sample.h:41
static void process_missing_slice(ContextType &context)
perform operations to compenste for a missing packet
static constexpr uint64_t max_sequence_number()
return the maximum value the packet_count can take