24 #include "cheetah/rcpt_low/test/UdpStreamTest.h" 25 #include "cheetah/rcpt_low/UdpStream.h" 26 #include "cheetah/rcpt_low/Config.h" 27 #include "cheetah/rcpt_low/PacketGenerator.h" 28 #include "cheetah/rcpt_low/PacketGeneratorConfig.h" 29 #include "panda/DataManager.h" 30 #include "panda/IpAddress.h" 31 #include "panda/Log.h" 32 #include "panda/Engine.h" 46 UdpStreamTest::UdpStreamTest()
51 UdpStreamTest::~UdpStreamTest()
55 void UdpStreamTest::SetUp()
59 void UdpStreamTest::TearDown()
68 DataType& next(DataType& data) {
70 std::default_random_engine generator;
71 std::normal_distribution<float> distribution(0.0,25.0);
73 std::unique_lock<std::mutex> lk(_mutex);
75 std::generate(data.begin(), data.end(), [&]{
return ((
typename DataType::DataType)distribution(generator)); } );
76 _data.push_back(data);
80 DataType sent_data() {
81 std::lock_guard<std::mutex> lk(_mutex);
82 if(_data.empty())
throw panda::Error(
"no more sent data");
83 DataType d = _data.front();
88 bool has_sent_data()
const {
89 std::lock_guard<std::mutex> lk(_mutex);
90 return !_data.empty();
94 mutable std::mutex _mutex;
95 std::deque<DataType> _data;
99 template<
typename Packet>
100 void test_udp_packets_stream_data_consistency(std::size_t number_of_channels, std::size_t number_of_samples)
102 typedef ska::panda::Connection<ska::panda::ConnectionTraits<ska::panda::Udp>> ConnectionType;
106 generator_config.
interval(std::chrono::microseconds(2000));
108 panda::IpAddress address(0,
"127.0.0.1");
109 boost::asio::ip::udp::endpoint local_endpoint = address.end_point<boost::asio::ip::udp::endpoint>();
113 ASSERT_EQ(number_of_samples, config.spectra_per_chunk());
116 SCOPED_TRACE(number_of_channels);
117 SCOPED_TRACE(
"number_of_channels per time sample:");
118 PANDA_LOG <<
"number_of_channles per time sample=" << number_of_channels;
119 config.number_of_channels(number_of_channels);
120 config.remote_end_point(local_endpoint);
121 ASSERT_EQ(number_of_channels, config.number_of_channels());
126 ska::panda::DataManager<UdpStream> dm(stream);
127 auto endpoint = stream.local_end_point();
132 GeneratorType generator(model, generator_config);
133 panda::Engine& engine = config.engine();
134 ConnectionType connection(engine);
135 connection.set_remote_end_point(endpoint);
139 DataType data_ref(data::DimensionSize<data::Time>(config.spectra_per_chunk())
140 , data::DimensionSize<data::Frequency>(config.number_of_channels()));
146 unsigned received_count=0U;
150 std::size_t packet_tot = delta;
153 unsigned packet_count = 0U;
157 PANDA_LOG <<
" chunk size "<<chunk_size;
158 while(packet_tot < 2 * chunk_size )
161 connection.send(generator.next(), [&](ska::panda::Error e){
168 delta = packet_tot - chunk_size;
171 unsigned max_attempts=1000;
172 while(received_count < packet_count) {
174 if(--max_attempts == 0) FAIL() <<
"time out: expected packets not received";
177 auto data_out_ptr = std::get<0>(dm.next());
179 auto const& data_out = *data_out_ptr;
180 auto it = data_out.cbegin();
183 boost::units::quantity<ska::cheetah::data::MegaHertz, double> bandwidth =
static_cast<boost::units::quantity<ska::cheetah::data::MegaHertz, double>
>(data_out.low_high_frequencies().second);
184 ASSERT_EQ(bandwidth.value(),350.0);
185 ASSERT_LT(data_out.start_time(),ska::cheetah::utils::ModifiedJulianClock::now());
186 ASSERT_GT(data_out.start_time()+std::chrono::seconds(10),ska::cheetah::utils::ModifiedJulianClock::now());
188 auto model_data = model.sent_data();
189 auto sent_it = model_data.cbegin();
190 auto sent_it_end = model_data.cend();
192 ASSERT_NE(
nullptr, &*data_out.begin());
194 for(
int channel=0;channel<9;channel++)
196 for(
int sample=0; sample<128; sample++)
198 if(sent_it_end>sent_it+(channel*512+sample*2+257))
200 int s1 = (int)(*(sent_it+(channel*256+sample)));
201 int s2 = (int)(*(sent_it+(channel*256+sample)));
202 int s3 = (int)(*(sent_it+(channel*256+sample+128)));
203 int s4 = (int)(*(sent_it+(channel*256+sample+128)));
204 uint8_t intensity = uint8_t((s1*s1 + s2*s2)/4096) + uint8_t((s3*s3 + s4*s4)/4096);
205 ASSERT_EQ(*(it+(channel*128+sample)) , intensity);
213 TEST_F(
UdpStreamTest, test_udp_packets_stream_data_consistency_channels_size_equal_packet_size)
216 test_udp_packets_stream_data_consistency<Packet>(128, 7776);
configurable parameters for the rcpt
const std::chrono::microseconds & interval() const
time sepearation between consequetive packets in micro seconds
unsigned spectra_per_chunk() const
return the number of time samples in a chunk
Packs data into a UDP stream Packet Header format of the BeamFormer.
Some limits and constants for FLDO.
NumericalT DataType
the underlying data storage type for the amplitude of the signal
std::size_t number_of_channels() const
Configuration for the packet generator to the time seperation of the packets.
std::size_t number_of_spectra() const