#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include <stdint.h>
#include <string.h>
#include <signal.h>
#include <time.h>
#include <pthread.h>
#include <getopt.h>
#include "nsds_util.h"
#include "flog.h"
Go to the source code of this file.
Data Structures | |
struct | data_thread_arg |
Struct passed to data thread. More... | |
Functions | |
void | sighandler (int signal) |
Control-break handler. Sets global flag to indicate exit request. | |
int | tcp_send_driverids (const uint16_t control_socket, const uint16_t data_socket, const char *daq_name) |
Send 'driver IDs' on control and data sockets to NSDS. | |
void * | data_thread_main (void *arg) |
Thread for data forwarding. | |
int | data_thread_startup (data_thread_arg d_arg) |
Data channel thread clean- and start-up. | |
int | cmd_handler (const uint16_t nsds_s_ctrl, const uint16_t nsds_s_data, const uint16_t daq_control, const uint16_t daq_data, const char *daq_name) |
Read commands on control channel and respond. | |
void | main_loop (const char *daq_machine, const uint16_t daq_port, const char *nsds_machine, const uint16_t nsds_port, const char *driver_name) |
Connect up the net, do the plumbing, call the worker. | |
int | main (int argc, char *argv[]) |
Parse command line, setup + run main loop. | |
Variables | |
const int | SRV_PORT = 42420 |
TCP server port on NSDS that we should connect to. Cmd-line override-able. | |
const int | QUEUE_LENGTH = 1 |
TCP connection queue length. | |
const int | NUM_THREADS = 2 |
Number of threads - main and data. | |
const size_t | DATA_READ_SIZE = 256 |
Number of bytes to read at a time on the data thread. | |
const time_t | RATE_UPDATE_PERIOD = 10 |
Screen update rate, in seconds, for data rate printout. | |
bool | control_break |
Global boolean set by signal handler to force exit. | |
bool | streaming_active |
Global boolean, tells data thread to exit. |
Definition in file driver.c.
|
Read commands on control channel and respond. Currently handles welcome. All others forwarded verbatim to the DAQ. The only complexity is polling the command channel, and then checking the status of the data stream now and then. This is a patch around broken idiocy in the NSDS, which operates on the don't-ask-don't-tell blinders mode.
Definition at line 367 of file driver.c. References MAX_CMD_LEN, streaming_active, tcp_nl_read(), tcp_nl_write(), and tcp_send_driverids(). Referenced by main_loop(). |
|
Thread for data forwarding. Read the data, parse it, forward channels that are in use.
Definition at line 217 of file driver.c. References control_break, data_thread_arg::daq_data, DATA_READ_SIZE, MAX_CMD_LEN, data_thread_arg::nsds_data, RATE_UPDATE_PERIOD, and streaming_active. Referenced by data_thread_startup(). |
|
Data channel thread clean- and start-up. Starts thread w/data struct defining various file descriptors.
Definition at line 320 of file driver.c. References data_thread_main(), NUM_THREADS, pthread_setconcurrency(), and streaming_active. Referenced by main_loop(). |
|
Parse command line, setup + run main loop. Set up logging, install signal handler, parse command line, run the work routine.
Definition at line 661 of file driver.c. References control_break, main_loop(), and sighandler(). |
|
Connect up the net, do the plumbing, call the worker. This calls connect four times - control & data for both DAQ and NSDS. We do the DAQ first, since there's no point talking to the NSDS unless we can reach the DAQ system. Quite a bit of smarts - connections are retried, knows how to restart, fairly robust against network failure.
Definition at line 502 of file driver.c. References cmd_handler(), control_break, data_thread_arg::daq_data, data_thread_startup(), data_thread_arg::nsds_data, streaming_active, tcp_close(), tcp_connect_retry(), and tcp_peername(). Referenced by main(). |
|
Control-break handler. Sets global flag to indicate exit request. Assumes Installed in interrupt chain by someone else
Definition at line 138 of file driver.c. References control_break. Referenced by main(). |
|
Send 'driver IDs' on control and data sockets to NSDS. Sends out driver IDs on control and data channels to NSDS. The base name can be set my the corresponding command line option, so that you can run more than one per host. Note that the DAQ never sees the 'welcome' command - its entirely handled by the driver. It is, after all, a driver ID.
Definition at line 175 of file driver.c. References tcp_nl_write(). Referenced by cmd_handler(). |
|
Global boolean set by signal handler to force exit.
Definition at line 113 of file driver.c. Referenced by data_thread_main(), main(), main_loop(), and sighandler(). |
|
Number of bytes to read at a time on the data thread.
Definition at line 107 of file driver.c. Referenced by data_thread_main(). |
|
Number of threads - main and data.
Definition at line 104 of file driver.c. Referenced by data_thread_startup(). |
|
TCP connection queue length.
Definition at line 101 of file driver.c. Referenced by tcp_socket_make(). |
|
Screen update rate, in seconds, for data rate printout.
Definition at line 110 of file driver.c. Referenced by data_thread_main(). |
|
TCP server port on NSDS that we should connect to. Cmd-line override-able.
Definition at line 98 of file driver.c. Referenced by tcp_socket_make(). |
|
Global boolean, tells data thread to exit.
Definition at line 116 of file driver.c. Referenced by cmd_handler(), data_thread_main(), data_thread_startup(), and main_loop(). |