Psyllid  v1.12.4
Project 8 Data Acquisisition Software
test_tf_roach_monitor.cc
Go to the documentation of this file.
1 /*
2  * test_tf_roach_monitor.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_monitor [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 #include "tf_roach_monitor.hh"
24 
25 #ifdef BUILD_FPA
26 #include "packet_receiver_fpa.hh"
27 #endif
28 
29 #include "diptera.hh"
30 
31 #include "configurator.hh"
32 #include "logger.hh"
33 #include "param.hh"
34 
35 #include <signal.h>
36 
37 using namespace psyllid;
38 
39 LOGGER( plog, "test_tf_roach_monitor" );
40 
41 scarab::cancelable* f_cancelable = nullptr;
42 
43 void cancel( int )
44 {
45  LINFO( plog, "Attempting to cancel" );
46  if( f_cancelable != nullptr ) f_cancelable->cancel();
47  return;
48 }
49 
50 int main( int argc, char** argv )
51 {
52  try
53  {
54  scarab::param_node t_default_config;
55  t_default_config.add( "ip", scarab::param_value( "127.0.0.1" ) );
56  t_default_config.add( "port", scarab::param_value( 23530 ) );
57  t_default_config.add( "interface", scarab::param_value( "eth1" ) );
58 
59  scarab::configurator t_configurator( argc, argv, t_default_config );
60 
61  std::string t_ip( t_configurator.get< std::string >( "ip" ) );
62  unsigned t_port = t_configurator.get< unsigned >( "port" );
63  std::string t_interface( t_configurator.get< std::string >( "interface" ) );
64  bool t_use_fpa( t_configurator.config().has( "fpa" ) );
65 
66  LINFO( plog, "Creating and configuring nodes" );
67 
68  midge::diptera* t_root = new midge::diptera();
69 
70  if( t_use_fpa )
71  {
72 #ifdef BUILD_FPA
73  packet_receiver_fpa* t_pck_rec = new packet_receiver_fpa();
74  t_pck_rec->set_name( "pck_rec" );
75  t_pck_rec->set_length( 10 );
76  t_pck_rec->set_port( t_port );
77  t_pck_rec->interface() = t_interface;
78  t_root->add( t_pck_rec );
79  f_cancelable = t_pck_rec;
80 #else
81  LERROR( plog, "FPA was requested, but is only available on a Linux machine" );
82  return -1;
83 #endif
84  }
85  else
86  {
88  t_pck_rec->set_name( "pck_rec" );
89  t_pck_rec->set_length( 10 );
90  t_pck_rec->set_port( t_port );
91  t_pck_rec->ip() = t_ip;
92  t_root->add( t_pck_rec );
93  f_cancelable = t_pck_rec;
94  }
95 
96  tf_roach_receiver* t_tfr_rec = new tf_roach_receiver();
97  t_tfr_rec->set_name( "tfr_rec" );
98  t_tfr_rec->set_time_length( 10 );
99  t_tfr_rec->set_start_paused( false );
100  t_root->add( t_tfr_rec );
101 
102  roach_time_monitor* t_tmon = new roach_time_monitor();
103  t_tmon->set_name( "tmon" );
104  t_root->add( t_tmon );
105 
106  roach_freq_monitor* t_fmon = new roach_freq_monitor();
107  t_fmon->set_name( "fmon" );
108  t_root->add( t_fmon );
109 
110  LINFO( plog, "Connecting nodes" );
111 
112  t_root->join( "pck_rec.out_0:tfr_rec.in_0" );
113  t_root->join( "tfr_rec.out_0:tmon.in_0" );
114  t_root->join( "tfr_rec.out_1:fmon.in_0" );
115 
116  LINFO( plog, "Exit with ctrl-c" );
117 
118  // set up signal handling for canceling with ctrl-c
119  signal( SIGINT, cancel );
120 
121  LINFO( plog, "Executing" );
122 
123  std::exception_ptr t_e_ptr = t_root->run( "pck_rec:tfr_rec:tmon:fmon" );
124 
125  if( t_e_ptr ) std::rethrow_exception( t_e_ptr );
126 
127  LINFO( plog, "Execution complete" );
128 
129  // un-setup signal handling
130  f_cancelable = nullptr;
131 
132  delete t_root;
133 
134  return 0;
135  }
136  catch( std::exception& e )
137  {
138  LERROR( plog, "Exception caught: " << e.what() );
139  return -1;
140  }
141 
142 }
static scarab::logger plog("batch_executor")
A consumer to check the continuity of the freq-packet stream from a ROACH.
A consumer to check the continuity of the time-packet stream from a ROACH.
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...
int main(int argc, char **argv)
A transformer to receive raw blocks of memory, parse them, and distribute them as time and frequency ...
LOGGER(plog, "egg_writer")
scarab::cancelable * f_cancelable
void cancel(int)