Psyllid  v1.12.4
Project 8 Data Acquisisition Software
test_tf_roach_receiver.cc
Go to the documentation of this file.
1 /*
2  * test_tf_roach_receiver.cc
3  *
4  * Created on: Dec 28, 2015
5  * Author: nsoblath
6  *
7  * Suggested UDP client: roach_simulator.go
8  *
9  * Usage: > test_tf_roach_receiver [options]
10  *
11  * Parameters:
12  * - port: (uint) port number to listen on for packets
13  * - interface: (string) network interface name to listen on for packets; this is only needed if using the FPA receiver; default is "eth1"
14  * - ip: (string) IP address to listen on for packets; this is only needed if using the socket receiver; default is "127.0.0.1"
15  * - fpa: (null) Flag to request use of the FPA receiver; only valid on linux machines
16  */
17 
18 
19 #include "psyllid_error.hh"
21 #include "terminator.hh"
22 #include "tf_roach_receiver.hh"
23 
24 #ifdef BUILD_FPA
25 #include "packet_receiver_fpa.hh"
26 #endif
27 
28 #include "diptera.hh"
29 
30 #include "configurator.hh"
31 #include "logger.hh"
32 #include "param.hh"
33 
34 #include <signal.h>
35 
36 using namespace psyllid;
37 
38 LOGGER( plog, "test_tf_roach_receiver" );
39 
40 scarab::cancelable* f_cancelable = nullptr;
41 
42 void cancel( int )
43 {
44  LINFO( plog, "Attempting to cancel" );
45  if( f_cancelable != nullptr ) f_cancelable->cancel();
46  return;
47 }
48 
49 int main( int argc, char** argv )
50 {
51  try
52  {
53  scarab::param_node t_default_config;
54  t_default_config.add( "ip", scarab::param_value( "127.0.0.1" ) );
55  t_default_config.add( "port", scarab::param_value( 23530 ) );
56  t_default_config.add( "interface", scarab::param_value( "eth1" ) );
57 
58  scarab::configurator t_configurator( argc, argv, t_default_config );
59 
60  std::string t_ip( t_configurator.get< std::string >( "ip" ) );
61  unsigned t_port = t_configurator.get< unsigned >( "port" );
62  std::string t_interface( t_configurator.get< std::string >( "interface" ) );
63  bool t_use_fpa( t_configurator.config().has( "fpa" ) );
64 
65  LINFO( plog, "Creating and configuring nodes" );
66 
67  midge::diptera* t_root = new midge::diptera();
68 
69  if( t_use_fpa )
70  {
71 #ifdef BUILD_FPA
72  packet_receiver_fpa* t_pck_rec = new packet_receiver_fpa();
73  t_pck_rec->set_name( "pck_rec" );
74  t_pck_rec->set_length( 10 );
75  t_pck_rec->set_port( t_port );
76  t_pck_rec->interface() = t_interface;
77  t_root->add( t_pck_rec );
78  f_cancelable = t_pck_rec;
79 #else
80  LERROR( plog, "FPA was requested, but is only available on a Linux machine" );
81  return -1;
82 #endif
83  }
84  else
85  {
87  t_pck_rec->set_name( "pck_rec" );
88  t_pck_rec->set_length( 10 );
89  t_pck_rec->set_port( t_port );
90  t_pck_rec->ip() = t_ip;
91  t_root->add( t_pck_rec );
92  f_cancelable = t_pck_rec;
93  }
94 
95  tf_roach_receiver* t_tfr_rec = new tf_roach_receiver();
96  t_tfr_rec->set_name( "tfr_rec" );
97  t_tfr_rec->set_time_length( 10 );
98  t_tfr_rec->set_start_paused( false );
99  t_root->add( t_tfr_rec );
100 
101  terminator_time_data* t_term_t = new terminator_time_data();
102  t_term_t->set_name( "term_t" );
103  t_root->add( t_term_t );
104 
105  terminator_freq_data* t_term_f = new terminator_freq_data();
106  t_term_f->set_name( "term_f" );
107  t_root->add( t_term_f );
108 
109  LINFO( plog, "Connecting nodes" );
110 
111  t_root->join( "pck_rec.out_0:tfr_rec.in_0" );
112  t_root->join( "tfr_rec.out_0:term_t.in_0" );
113  t_root->join( "tfr_rec.out_1:term_f.in_0" );
114 
115  LINFO( plog, "Exit with ctrl-c" );
116 
117  // set up signal handling for canceling with ctrl-c
118  signal( SIGINT, cancel );
119 
120  LINFO( plog, "Executing" );
121 
122  std::exception_ptr t_e_ptr = t_root->run( "pck_rec:tfr_rec:term_t:term_f" );
123 
124  if( t_e_ptr ) std::rethrow_exception( t_e_ptr );
125 
126  LINFO( plog, "Execution complete" );
127 
128  // un-setup signal handling
129  f_cancelable = nullptr;
130 
131  delete t_root;
132 
133  return 0;
134  }
135  catch( std::exception& e )
136  {
137  LERROR( plog, "Exception caught: " << e.what() );
138  return -1;
139  }
140 
141 }
static scarab::logger plog("batch_executor")
scarab::cancelable * f_cancelable
int main(int argc, char **argv)
A producer to receive UDP packets via the standard socket interface and write them as raw blocks of m...
A producer to receive UDP packets via the fast-packet-acquisition interface and write them as raw blo...
A transformer to receive raw blocks of memory, parse them, and distribute them as time and frequency ...
LOGGER(plog, "egg_writer")
void cancel(int)