Psyllid  v1.12.4
Project 8 Data Acquisisition Software
roach_daq_streaming_1chan.cc
Go to the documentation of this file.
1 /*
2  * roach_daq_streaming_1chan.cc
3  *
4  * Created on: Dec 5, 2016
5  * Author: nsoblath
6  *
7  * Streaming DAQ for the ROACH
8  *
9  * Usage: > roach_daq_streaming_1chan [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"
20 #include "psyllid_version.hh"
22 #include "streaming_writer.hh"
23 #include "terminator.hh"
24 #include "tf_roach_receiver.hh"
25 
26 #ifdef __linux__
27 #include "packet_receiver_fpa.hh"
28 #endif
29 
30 #include "diptera.hh"
31 
32 #include "application.hh"
33 #include "logger.hh"
34 #include "param.hh"
35 
36 #include "dripline_constants.hh" // for RETURN constants
37 
38 #include <signal.h>
39 
40 using namespace psyllid;
41 
42 LOGGER( plog, "test_tf_roach_receiver" );
43 
44 scarab::cancelable* f_cancelable = nullptr;
45 
46 void cancel( int )
47 {
48  LINFO( plog, "Attempting to cancel" );
49  if( f_cancelable != nullptr ) f_cancelable->cancel();
50  return;
51 }
52 
53 int main( int argc, char** argv )
54 {
55  try
56  {
57  // The application
58  scarab::main_app the_main;
59 
60  // Default configuration
61  scarab::param_node t_default_config;
62  t_default_config.add( "ip", scarab::param_value( "127.0.0.1" ) );
63  t_default_config.add( "port", scarab::param_value( 23530 ) );
64  t_default_config.add( "interface", scarab::param_value( "eth1" ) );
65  the_main.default_config() = t_default_config;
66 
67  // Command line options
68  the_main.add_config_option< std::string >( "--ip", "ip", "IP address from which to receive packets" );
69  the_main.add_config_option< unsigned >( "-p,--port", "port", "Port on which to receive packets" );
70  the_main.add_config_option< std::string >( "-i,--interface", "interface", "Ethernet interface to grab packets off of" );
71  the_main.add_config_flag< bool >( "-f,--fpa", "fpa", "Enable use of the FPA" );
72 
73  // Package version
74  the_main.set_version( new psyllid::version() );
75 
76  // The main execution callback
77  the_main.callback( [&]() {
78  std::string t_ip( the_main.master_config()["ip"]().as_string() );
79  unsigned t_port = the_main.master_config()["port"]().as_uint();
80  std::string t_interface( the_main.master_config()["interface"]().as_string() );
81  bool t_use_fpa( the_main.master_config().has( "fpa" ) );
82 
83  LINFO( plog, "Creating and configuring nodes" );
84 
85  midge::diptera* t_root = new midge::diptera();
86 
87  if( t_use_fpa )
88  {
89  #ifdef __linux__
90  packet_receiver_fpa* t_pck_rec = new packet_receiver_fpa();
91  t_pck_rec->set_name( "pck_rec" );
92  t_pck_rec->set_length( 10 );
93  t_pck_rec->set_port( t_port );
94  t_pck_rec->interface() = t_interface;
95  t_root->add( t_pck_rec );
96  f_cancelable = t_pck_rec;
97  #else
98  throw error() << "FPA was requested, but is only available on a Linux machine";
99  #endif
100  }
101  else
102  {
104  t_pck_rec->set_name( "pck_rec" );
105  t_pck_rec->set_length( 10 );
106  t_pck_rec->set_port( t_port );
107  t_pck_rec->ip() = t_ip;
108  t_root->add( t_pck_rec );
109  f_cancelable = t_pck_rec;
110  }
111 
112  tf_roach_receiver* t_tfr_rec = new tf_roach_receiver();
113  t_tfr_rec->set_name( "tfr_rec" );
114  t_tfr_rec->set_time_length( 10 );
115  t_tfr_rec->set_start_paused( false );
116  t_root->add( t_tfr_rec );
117 
118  streaming_writer* t_str_wrt = new streaming_writer();
119  t_str_wrt->set_name( "strw" );
120  t_root->add( t_str_wrt );
121 
122  terminator_freq_data* t_term_f = new terminator_freq_data();
123  t_term_f->set_name( "term_f" );
124  t_root->add( t_term_f );
125 
126  LINFO( plog, "Connecting nodes" );
127 
128  t_root->join( "pck_rec.out_0:tfr_rec.in_0" );
129  t_root->join( "tfr_rec.out_0:strw.in_0" );
130  t_root->join( "tfr_rec.out_1:term_f.in_0" );
131 
132  LINFO( plog, "Exit with ctrl-c" );
133 
134  // set up signal handling for canceling with ctrl-c
135  signal( SIGINT, cancel );
136 
137  LINFO( plog, "Executing" );
138 
139  std::exception_ptr t_e_ptr = t_root->run( "pck_rec:tfr_rec:strw:term_f" );
140 
141  if( t_e_ptr ) std::rethrow_exception( t_e_ptr );
142 
143  LINFO( plog, "Execution complete" );
144 
145  // un-setup signal handling
146  f_cancelable = nullptr;
147 
148  delete t_root;
149  } );
150 
151  // Parse CL options and run the application
152  CLI11_PARSE( the_main, argc, argv );
153 
154  return RETURN_SUCCESS;
155  }
156  catch( std::exception& e )
157  {
158  LERROR( plog, "Exception caught: " << e.what() );
159  }
160  return RETURN_ERROR;
161 
162 }
163 
164 
165 
static scarab::logger plog("batch_executor")
void cancel(int)
A producer to receive UDP packets via the standard socket interface and write them as raw blocks of m...
A consumer to that writes all time ROACH packets to an egg file.
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")
int main(int argc, char **argv)
scarab::cancelable * f_cancelable