#include "TPCCommandCoderHardcoded.h" #include //============================================================================ // Stuff for ARGP const char *argp_program_version = "TPCCommandCoderHardcoded.app"; const char *argp_program_bug_address = ""; static char doc[] = "This program can be used to send dummy data (hardcoded)."; static char args_doc[] = " [OPTIONS ...]"; //============================================================================ // The options ARGP understands static struct argp_option options[] = { {"binary", 'b', 0, 0, "Dump binary result to screen" }, {"verbose", 'v', 0, 0, "Produce verbose output" }, {"quiet", 'q', 0, 0, "Don't produce any output" }, {"fecs", 'f', "FECs", 0, "specify how many fecs to configure" }, {"altros", 'a', "ALTROs", 0, "specify how many altros per fec to configure" }, {"channels", 'c', "CHANNELs", 0, "specify how many channels per altro to configure" }, {"store", 's', 0, 0, "store configuration data in feeserver (default=false)" }, {"read", 'r', 0, 0, "read altro data (default=false)" }, {"partition", 'p', "rcu", 0, "specify RCU (e.g. TPC-FEE_1_12_4)" }, {"bc", 'y', 0, 0, "configure also FEC board controllers" }, { 0 } }; //============================================================================ // Used by main to communicate with ARGP parse_opt struct arguments { int32_t silent, verbose; int32_t nfecs, naltros, nchannels; bool store, read, bc, binary; string rcu; }; //============================================================================ //Get the input argument from argp_parse, which is a pointer to the ARGP arguments structure. static error_t parse_opt (int key, char *arg, struct argp_state *state) { struct arguments *arguments = (struct arguments*)state->input; switch (key) { // Parse a single option case 'q': arguments->silent = 1; break; case 'v': arguments->verbose = 1; break; case 'f': arguments->nfecs = atoi(arg); break; case 'a': arguments->naltros = atoi(arg); break; case 'c': arguments->nchannels = atoi(arg); break; case 'p': arguments->rcu = arg; break; case 'b': arguments->binary = true; break; case 'y': arguments->bc = true; break; case 's': arguments->store = true; break; case 'r': arguments->read = true; break; case ARGP_KEY_ARG: //arguments->input_files = &state->argv[state->next-1]; //state->next = state->argc; break; case ARGP_KEY_END: //if (state->arg_num < 1) argp_usage(state); // Not enough arguments break; default: return ARGP_ERR_UNKNOWN; } return 0; } //============================================================================ static struct argp argp = { options, parse_opt, args_doc, doc }; //============================================================================ //============================================================================ //============================================================================ int main( int argc, char** argv ) { struct arguments arguments; // Default values arguments.silent = 0; arguments.verbose = 0; arguments.nfecs = 1; arguments.naltros = 8; arguments.nchannels = 16; arguments.rcu = "TPC-FEE_1_11_1"; arguments.binary = false; arguments.store = false; arguments.read = false; arguments.bc = false; // Parse arguments; every option seen by parse_opt will be reflected in arguments argp_parse (&argp, argc, argv, 0, 0, &arguments); int32_t ptag = 5; // dummy tag uint32_t *instrmem; // the intruction memory to be sent to RCU int32_t length = 0; // Will hold the intruction Mem length // Create the TPC CommandCoder object TPCCommandCoderHardcoded *CoCo = new TPCCommandCoderHardcoded(); CoCo->setNfecs(arguments.nfecs); CoCo->setNaltros(arguments.naltros); CoCo->setNchannels(arguments.nchannels); CoCo->setUseStore(arguments.store); CoCo->setConfigBCs(arguments.bc); CoCo->setReadResult(arguments.read, 2*arguments.nfecs*arguments.naltros *(5+7*arguments.nchannels)); // Create the data block. length = CoCo->createDataBlock( const_cast( arguments.rcu.c_str() ), ptag ); cerr << "length in bytes:" << length << endl; // // Fill data into instruction memory buffer. // instrmem = CoCo->getDataBlock(); // Dump data to screen (binary format) if ( arguments.binary && instrmem != NULL ) { cout.write( ( char* ) instrmem, length ); } else if (!arguments.silent) { // Dump data to screen (Asci format) for ( int32_t i = 0; i < length/4; i++ ) { printf("%06d | 0x%08x\n", i, (uint32_t)instrmem[i]); } } // Dump errors: vector errors = CoCo->getError(); if ( errors.size()>0 ) { for(uint32_t i = 0; i < errors.size(); i++){ cerr << i << "\t" << errors.at(i) << endl << endl; } } instrmem = 0; delete CoCo; CoCo = 0; return 1; }