Skip to content
Snippets Groups Projects
Commit 168e79f1 authored by Jonathan Hanks's avatar Jonathan Hanks
Browse files

Update the dix_recv/xmit programs to use the args command line parser.

Give them a consistent (and working) argument parser with help.  A quality of life improvement.
parent 5e80c1f7
No related branches found
No related tags found
1 merge request!67Update the dix_recv/xmit programs to use the args command line parser.
...@@ -3,9 +3,16 @@ add_executable(ix_test ix_test.c) ...@@ -3,9 +3,16 @@ add_executable(ix_test ix_test.c)
target_link_libraries(ix_test PUBLIC dolphin::sisci) target_link_libraries(ix_test PUBLIC dolphin::sisci)
add_executable(dix_xmit dix_xmit.c) add_executable(dix_xmit dix_xmit.c)
target_link_libraries(dix_xmit PUBLIC driver::shmem dolphin::sisci pv::simple_pv) target_link_libraries(dix_xmit PUBLIC
args
driver::shmem
dolphin::sisci
pv::simple_pv)
install(TARGETS dix_xmit DESTINATION bin) install(TARGETS dix_xmit DESTINATION bin)
add_executable(dix_recv dix_recv.c) add_executable(dix_recv dix_recv.c)
target_link_libraries(dix_recv PUBLIC driver::shmem dolphin::sisci) target_link_libraries(dix_recv PUBLIC
args
driver::shmem
dolphin::sisci)
install(TARGETS dix_recv DESTINATION bin) install(TARGETS dix_recv DESTINATION bin)
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include "../drv/crc.c" #include "../drv/crc.c"
#include "../include/daq_core.h" #include "../include/daq_core.h"
#include "args.h"
#define __CDECL #define __CDECL
#define MY_DCU_OFFSET 0x00000 #define MY_DCU_OFFSET 0x00000
...@@ -31,22 +33,6 @@ static volatile int keepRunning = 1; ...@@ -31,22 +33,6 @@ static volatile int keepRunning = 1;
/* */ /* */
/*********************************************************************************/ /*********************************************************************************/
void
Usage( )
{
printf( "Usage of dix_recv:\n" );
printf( "dix_recv -g <group>\n" );
printf( " -b <name> : Destination buffer name (default local_dc)\n" );
printf( " -m <value> : Size in MB of the destination buffer [20-100] "
"(default=100)\n" );
printf( " -a <value> : Local adapter number (default %d)\n",
localAdapterNo );
printf( " -g <value> : Reflective group identifier (0..5))\n" );
printf( " -v <value> : Diagnostics level (0..1) \n" );
printf( " -h : This help screen\n" );
printf( "\n" );
}
void void
intHandler( int dummy ) intHandler( int dummy )
{ {
...@@ -101,46 +87,49 @@ int __CDECL ...@@ -101,46 +87,49 @@ int __CDECL
int do_verbose = 0; int do_verbose = 0;
int max_data_size_mb = 100; int max_data_size_mb = 100;
int max_data_size = 0; int max_data_size = 0;
char* dest_mbuf_name = "local_dc"; const char* default_dest_mbuf_name = "local_dc";
const char* dest_mbuf_name = 0;
args_handle arg_parser = 0;
printf( "\n %s compiled %s : %s\n\n", argv[ 0 ], __DATE__, __TIME__ ); printf( "\n %s compiled %s : %s\n\n", argv[ 0 ], __DATE__, __TIME__ );
if ( argc < 2 ) arg_parser = args_create_parser( "IX Dolphin based receiver." );
args_add_string_ptr( arg_parser,
'b',
ARGS_NO_LONG,
"mbuf name",
"Output buffer name",
&dest_mbuf_name,
default_dest_mbuf_name );
args_add_int( arg_parser,
'm',
ARGS_NO_LONG,
"[20-100]",
"Output buffer size in mb",
&max_data_size_mb,
100 );
args_add_int( arg_parser,
'g',
ARGS_NO_LONG,
"[0-3]",
"The IX memory group to read from",
&segmentId,
0 );
args_add_int( arg_parser,
'a',
ARGS_NO_LONG,
"number",
"Local adapter number",
&localAdapterNo,
localAdapterNo );
args_add_flag(
arg_parser, 'v', ARGS_NO_LONG, "Verbose output", &do_verbose );
if ( args_parse( arg_parser, argc, argv ) <= 0 )
{ {
printf( "Exiting here \n" ); exit( 1 );
Usage( );
return ( -1 );
} }
args_destroy( &arg_parser );
/* Get the parameters */
while ( ( counter = getopt( argc, argv, "m:g:a:v:b:" ) ) != EOF )
switch ( counter )
{
case 'b':
dest_mbuf_name = optarg;
break;
case 'm':
max_data_size_mb = atoi( optarg );
break;
case 'g':
segmentId = atoi( optarg );
break;
case 'a':
localAdapterNo = atoi( optarg );
break;
case 'v':
do_verbose = atoi( optarg );
break;
case 'h':
printf( "Exiting here 2 \n" );
Usage( );
return ( 0 );
}
if ( max_data_size_mb < 20 || max_data_size_mb > 100 ) if ( max_data_size_mb < 20 || max_data_size_mb > 100 )
{ {
fprintf( stderr, "The data size parameter must be between 20 & 100\n" ); fprintf( stderr, "The data size parameter must be between 20 & 100\n" );
...@@ -149,7 +138,8 @@ int __CDECL ...@@ -149,7 +138,8 @@ int __CDECL
max_data_size = max_data_size_mb * 1024 * 1024; max_data_size = max_data_size_mb * 1024 * 1024;
// Attach to local shared memory // Attach to local shared memory
char* ifo = (char*)findSharedMemorySize( dest_mbuf_name, max_data_size_mb ); char* ifo =
(char*)findSharedMemorySize( (char*)dest_mbuf_name, max_data_size_mb );
daq_multi_cycle_data_t* ifo_shm = (daq_multi_cycle_data_t*)ifo; daq_multi_cycle_data_t* ifo_shm = (daq_multi_cycle_data_t*)ifo;
// char *ifo_data = (char *)ifo + sizeof(daq_multi_cycle_header_t); // char *ifo_data = (char *)ifo + sizeof(daq_multi_cycle_header_t);
char* ifo_data = (char*)&( ifo_shm->dataBlock[ 0 ] ); char* ifo_data = (char*)&( ifo_shm->dataBlock[ 0 ] );
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#include "simple_pv.h" #include "simple_pv.h"
#include "args.h"
#define __CDECL #define __CDECL
#include "./dolphin_common.c" #include "./dolphin_common.c"
...@@ -45,22 +47,6 @@ int do_verbose = 0; ...@@ -45,22 +47,6 @@ int do_verbose = 0;
static volatile int keepRunning = 1; static volatile int keepRunning = 1;
void
usage( )
{
fprintf( stderr,
"Usage: dix_ix_xmit [args] -m shared memory size -g IX "
"channel \n" );
fprintf( stderr, "-l filename - log file name\n" );
fprintf( stderr, "-b buffer name - Input buffer [local_dc]\n" );
fprintf( stderr,
"-m buffer size - Sizer of the input buffer in MB [20-100]\n" );
fprintf( stderr, "-v - verbose prints diag test data\n" );
fprintf( stderr, "-g - Dolphin IX channel to xmit on (0-3)\n" );
fprintf( stderr, "-p - Debug pv prefix\n" );
fprintf( stderr, "-h - help\n" );
}
// ************************************************************************* // *************************************************************************
// Timing Diagnostic Routine // Timing Diagnostic Routine
// ************************************************************************* // *************************************************************************
...@@ -91,7 +77,7 @@ void ...@@ -91,7 +77,7 @@ void
print_diags( int nsys, print_diags( int nsys,
int lastCycle, int lastCycle,
int sendLength, int sendLength,
daq_multi_dcu_data_t* ixDataBlock) daq_multi_dcu_data_t* ixDataBlock )
{ {
// ********************************************************************************************** // **********************************************************************************************
int ii = 0; int ii = 0;
...@@ -163,14 +149,16 @@ wait_for_cycle( volatile daq_multi_cycle_header_t* header, ...@@ -163,14 +149,16 @@ wait_for_cycle( volatile daq_multi_cycle_header_t* header,
int int
main( int argc, char** argv ) main( int argc, char** argv )
{ {
char* buffer_name = "local_dc"; const char* default_buffer_name = "local_dc";
int c; const char* buffer_name = default_buffer_name;
int ii; // Loop counter const char* logfile_name = 0;
int c;
int ii; // Loop counter
extern char* optarg; // Needed to get arguments to program extern char* optarg; // Needed to get arguments to program
// PV/debug information // PV/debug information
char* pv_prefix = 0; const char* pv_prefix = 0;
simple_pv_handle pcas_server = NULL; simple_pv_handle pcas_server = NULL;
// Declare shared memory data variables // Declare shared memory data variables
...@@ -184,54 +172,72 @@ main( int argc, char** argv ) ...@@ -184,54 +172,72 @@ main( int argc, char** argv )
int max_data_size = 0; int max_data_size = 0;
char* mywriteaddr; char* mywriteaddr;
int xmitBlockNum = 0; int xmitBlockNum = 0;
args_handle arg_parser = 0;
/* set up defaults */ /* set up defaults */
int xmitData = 0; arg_parser = args_create_parser( "IX Dolphin based transmitter" );
args_add_string_ptr( arg_parser,
// Get arguments sent to process 'b',
while ( ( c = getopt( argc, argv, "b:hm:g:vp:l:" ) ) != EOF ) ARGS_NO_LONG,
switch ( c ) "mbuf name",
"Input buffer name",
&buffer_name,
default_buffer_name );
args_add_int( arg_parser,
'm',
ARGS_NO_LONG,
"[20-100]",
"Input buffer size in mb",
&max_data_size_mb,
100 );
args_add_int( arg_parser,
'g',
ARGS_NO_LONG,
"[0-3]",
"The IX memory group to output to",
&segmentId,
0 );
args_add_string_ptr( arg_parser,
'p',
ARGS_NO_LONG,
"epics prefix",
"The prefix for epics PVs that report status",
&pv_prefix,
0 );
args_add_string_ptr( arg_parser,
'l',
ARGS_NO_LONG,
"filename",
"Log file name",
&logfile_name,
0 );
args_add_flag(
arg_parser, 'v', ARGS_NO_LONG, "Verbose output", &do_verbose );
if ( args_parse( arg_parser, argc, argv ) <= 0 )
{
exit( 1 );
}
args_destroy( &arg_parser );
if ( max_data_size_mb < 20 )
{
fprintf( stderr, "Min data block size is 20 MB\n" );
return -1;
}
if ( max_data_size_mb > 100 )
{
fprintf( stderr, "Max data block size is 100 MB\n" );
return -1;
}
if ( logfile_name )
{
if ( 0 == freopen( logfile_name, "w", stdout ) )
{ {
case 'v': perror( "freopen" );
do_verbose = 1;
break;
case 'm':
max_data_size_mb = atoi( optarg );
if ( max_data_size_mb < 20 )
{
fprintf( stderr, "Min data block size is 20 MB\n" );
return -1;
}
if ( max_data_size_mb > 100 )
{
fprintf( stderr, "Max data block size is 100 MB\n" );
return -1;
}
break;
case 'g':
segmentId = atoi( optarg );
xmitData = 1;
break;
case 'b':
buffer_name = optarg;
break;
case 'p':
pv_prefix = optarg;
break;
case 'l':
if ( 0 == freopen( optarg, "w", stdout ) )
{
perror( "freopen" );
exit( 1 );
}
setvbuf( stdout, NULL, _IOLBF, 0 );
stderr = stdout;
break;
case 'h':
default:
usage( );
exit( 1 ); exit( 1 );
} }
setvbuf( stdout, NULL, _IOLBF, 0 );
stderr = stdout;
}
max_data_size = max_data_size_mb * 1024 * 1024; max_data_size = max_data_size_mb * 1024 * 1024;
// set up to catch Control C // set up to catch Control C
...@@ -555,58 +561,55 @@ main( int argc, char** argv ) ...@@ -555,58 +561,55 @@ main( int argc, char** argv )
missed_flag <<= 1; missed_flag <<= 1;
} }
if ( xmitData ) if ( sendLength > IX_BLOCK_SIZE )
{ {
if ( sendLength > IX_BLOCK_SIZE ) fprintf( stderr,
{ "Buffer overflow. Sending %d bytes into a "
fprintf( stderr, "dolphin block that holds %d\n",
"Buffer overflow. Sending %d bytes into a " (int)sendLength,
"dolphin block that holds %d\n", (int)IX_BLOCK_SIZE );
(int)sendLength, abort( );
(int)IX_BLOCK_SIZE );
abort( );
}
// WRITEDATA to Dolphin Network
SCIMemCpy( sequence,
nextData,
remoteMap,
xmitDataOffset[ xmitBlockNum ],
sendLength,
memcpyFlag,
&error );
error = SCI_ERR_OK;
if ( error != SCI_ERR_OK )
{
fprintf(
stderr, "SCIMemCpy failed - Error code 0x%x\n", error );
fprintf( stderr,
"For reference the expected error codes are:\n" );
fprintf( stderr,
"SCI_ERR_OUT_OF_RANGE = 0x%x\n",
SCI_ERR_OUT_OF_RANGE );
fprintf( stderr,
"SCI_ERR_SIZE_ALIGNMENT = 0x%x\n",
SCI_ERR_SIZE_ALIGNMENT );
fprintf( stderr,
"SCI_ERR_OFFSET_ALIGNMENT = 0x%x\n",
SCI_ERR_OFFSET_ALIGNMENT );
fprintf( stderr,
"SCI_ERR_TRANSFER_FAILED = 0x%x\n",
SCI_ERR_TRANSFER_FAILED );
return error;
}
// Set data header information
unsigned int maxCycle = ifo_header->maxCycle;
unsigned int curCycle = ifo_header->curCycle;
xmitHeader[ xmitBlockNum ]->maxCycle = maxCycle;
xmitHeader[ xmitBlockNum ]->cycleDataSize = sendLength;
;
// Send cycle last as indication of data ready for receivers
xmitHeader[ xmitBlockNum ]->curCycle = curCycle;
// Have to flush the buffers to make data go onto Dolphin
// network
SCIFlush( sequence, SCI_FLAG_FLUSH_CPU_BUFFERS_ONLY );
} }
// WRITEDATA to Dolphin Network
SCIMemCpy( sequence,
nextData,
remoteMap,
xmitDataOffset[ xmitBlockNum ],
sendLength,
memcpyFlag,
&error );
error = SCI_ERR_OK;
if ( error != SCI_ERR_OK )
{
fprintf(
stderr, "SCIMemCpy failed - Error code 0x%x\n", error );
fprintf( stderr,
"For reference the expected error codes are:\n" );
fprintf( stderr,
"SCI_ERR_OUT_OF_RANGE = 0x%x\n",
SCI_ERR_OUT_OF_RANGE );
fprintf( stderr,
"SCI_ERR_SIZE_ALIGNMENT = 0x%x\n",
SCI_ERR_SIZE_ALIGNMENT );
fprintf( stderr,
"SCI_ERR_OFFSET_ALIGNMENT = 0x%x\n",
SCI_ERR_OFFSET_ALIGNMENT );
fprintf( stderr,
"SCI_ERR_TRANSFER_FAILED = 0x%x\n",
SCI_ERR_TRANSFER_FAILED );
return error;
}
// Set data header information
unsigned int maxCycle = ifo_header->maxCycle;
unsigned int curCycle = ifo_header->curCycle;
xmitHeader[ xmitBlockNum ]->maxCycle = maxCycle;
xmitHeader[ xmitBlockNum ]->cycleDataSize = sendLength;
;
// Send cycle last as indication of data ready for receivers
xmitHeader[ xmitBlockNum ]->curCycle = curCycle;
// Have to flush the buffers to make data go onto Dolphin
// network
SCIFlush( sequence, SCI_FLAG_FLUSH_CPU_BUFFERS_ONLY );
} }
// Increment cycle count // Increment cycle count
...@@ -614,12 +617,9 @@ main( int argc, char** argv ) ...@@ -614,12 +617,9 @@ main( int argc, char** argv )
nextCycle %= 16; nextCycle %= 16;
} while ( keepRunning ); // End of infinite loop } while ( keepRunning ); // End of infinite loop
if ( xmitData ) fprintf( stderr, "closing out ix\n" );
{ // Cleanup the Dolphin connections
fprintf( stderr, "closing out ix\n" ); error = dolphin_closeout( );
// Cleanup the Dolphin connections
error = dolphin_closeout( );
}
simple_pv_server_destroy( &pcas_server ); simple_pv_server_destroy( &pcas_server );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment