#include "TPCCommandCoderDB.h" #include #include //============================================================================ // Stuff for ARGP const char *argp_program_version = "TPCCommandCoderDB.app"; const char *argp_program_bug_address = ""; static char doc[] = "This program can be used to dump config data from the DB in ascii format."; static char args_doc[] = " SERVERNAME (e.g. TPC-FEE_1_11_1)"; //============================================================================ // The options ARGP understands static struct argp_option options[] = { {"verbose", 'v', "VERBOSITY", 0, "Produce verbose output" }, {"quiet", 'q', 0, 0, "Don't produce any output" }, {"binary", 'b', 0, 0, "Dump binary result to screen" }, {"file", 'f', 0, 0, "Dump binary result to file out.bin" }, {"tag", 't', "TAG", 0, "Specify the configuration tag [1...]" }, {"l0", 'n', 0, 0, "Change configuration to trigger FEE on L0" }, { 0 } }; //============================================================================ // Used by main to communicate with ARGP parse_opt struct arguments { bool silent, binary, file, l0; int verbose; int tag; string server; }; //============================================================================ //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 = true; break; case 'v': arguments->verbose = atoi(arg); break; case 'b': arguments->binary = true; break; case 'f': arguments->file = true; break; case 't': arguments->tag = atoi(arg); break; case 'n': arguments->l0 = true; break; case ARGP_KEY_ARG: arguments->server = arg; 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 ) { // // Create TPCCommandCoderDB object and read data block for rcu prcu and ID ptag // struct arguments arguments; // Default values arguments.silent = false; arguments.binary = false; arguments.file = false; arguments.l0 = false; arguments.verbose = 0; arguments.tag = -1; // Parse arguments; every option seen by parse_opt will be reflected in arguments argp_parse (&argp, argc, argv, 0, 0, &arguments); if ( arguments.tag < 0 ) { cerr << "*No positive tag specified!" << endl; return -1; } if ( arguments.l0 ) arguments.tag = -arguments.tag; uint32_t *instrmem; // The data block to be sent to RCU int32_t length = 0; // Will hold the size of the data block TPCCommandCoderDB *CoCo = new TPCCommandCoderDB(); CoCo->setDebugLevel(arguments.verbose); length = CoCo->createDataBlock( const_cast( arguments.server.c_str() ), arguments.tag ); instrmem = CoCo->getDataBlock(); // Dump data to screen (binary format) if ( arguments.binary && instrmem != NULL ) { cout.write( ( char* ) instrmem, length*4 ); } else if (!arguments.silent) { // Dump data to screen (Asci format) for ( int i = 0; i < length; i++ ) { printf("%06d | 0x%08x\n", i, (uint32_t)instrmem[i]); } } // Write to file if (arguments.file) { ofstream *file = new ofstream(); file->open("out.bin"); file->write((char*)instrmem, length*4*sizeof(uint32_t)); file->close(); delete file; } // 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; } } return 1; }