μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DummyHardwareOptions.hpp
Go to the documentation of this file.
1
2/*
3---------------------------------------------------------------------------
4
5 This file is part of uHAL.
6
7 uHAL is a hardware access library and programming framework
8 originally developed for upgrades of the Level-1 trigger of the CMS
9 experiment at CERN.
10
11 uHAL is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
15
16 uHAL is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with uHAL. If not, see <http://www.gnu.org/licenses/>.
23
24
25 Andrew Rose, Imperial College, London
26 email: awr01 <AT> imperial.ac.uk
27
28 Marc Magrans de Abril, CERN
29 email: marc.magrans.de.abril <AT> cern.ch
30
31---------------------------------------------------------------------------
32*/
33
34
35#ifndef _uhal_tests_DummyHardwareOptions_hpp_
36#define _uhal_tests_DummyHardwareOptions_hpp_
37
38
39#include <boost/program_options.hpp>
40
42#include "uhal/log/log.hpp"
43
44
45namespace uhal {
46 namespace tests {
47
50 {
52 uint32_t delay;
54 uint16_t port;
58 uint32_t version;
59
65 static DummyHardwareOptions parseFromCommandLine( int argc,char* argv[] );
66 };
67
68 }
69}
70
71// /**
72// Function to parse the command line arguments into a struct containing the information
73// @param argc the number of command line arguments
74// @param argv array of c-strings containing the command line arguments
75// */
77 {
78 // Declare the supported options.
79 boost::program_options::options_description desc ( "Allowed options" );
80 desc.add_options()
81 ( "help,h", "Produce this help message" )
82 ( "delay,d", boost::program_options::value<uint32_t>()->default_value ( 0 ) , "Reply delay for first packet (in seconds) - optional" )
83 ( "port,p", boost::program_options::value<uint16_t>() , "Port number to listen on - required" )
84 ( "big-endian,b", "Include the big-endian hack (version 2 only)" )
85 ( "version,v", boost::program_options::value<uint32_t>() , "IPbus Major version (1 or 2) - required" )
86 ( "verbose,V", "Produce verbose output" )
87 ;
88 boost::program_options::variables_map vm;
89
90 try
91 {
92 boost::program_options::store ( boost::program_options::parse_command_line ( argc, argv, desc ), vm );
93 boost::program_options::notify ( vm );
94
95 if ( vm.count ( "help" ) )
96 {
97 std::cout << "Usage: " << argv[0] << " [OPTIONS]" << std::endl;
98 std::cout << desc << std::endl;
99 exit ( 0 );
100 }
101
103 lResult.delay = vm["delay"].as<uint32_t>();
104 lResult.port = vm["port"].as<uint16_t>();
105 lResult.version = vm["version"].as<uint32_t>();
106 lResult.bigendian = bool ( vm.count ( "big-endian" ) );
107
108 if ( ( lResult.version == 1 ) && ( lResult.bigendian ) )
109 {
110 log ( Error , "-big-endian flag does nothing with version set to 1" );
111 }
112
113 if ( vm.count ( "verbose" ) )
114 {
115 setLogLevelTo ( Debug() );
116 }
117 else
118 {
119 setLogLevelTo ( Notice() );
120 }
121
122 return lResult;
123 }
124 catch ( std::exception& e )
125 {
126 std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
127 std::cout << "Usage: " << argv[0] << " [OPTIONS]" << std::endl;
128 std::cout << desc << std::endl;
129 exit ( 1 );
130 }
131 }
132
133
134#endif
135
None tests(nox.Session session)
Definition: noxfile.py:19
DebugLevel Debug
Definition: LogLevels.cpp:133
void setLogLevelTo(const FatalLevel &)
Function to specify, at runtime, that only messages with a severity level above Fatal should be logge...
Definition: log.cpp:87
ErrorLevel Error
Definition: LogLevels.cpp:61
void log(FatalLevel &aFatal, const T0 &aArg0)
Function to add a log entry at Fatal level.
Definition: log.hxx:18
NoticeLevel Notice
Definition: LogLevels.cpp:97
Struct to store the dummy hardware command line options.
uint16_t port
The port used by the dummy hardware.
uint32_t version
IPbus version number - 1 or 2.
static DummyHardwareOptions parseFromCommandLine(int argc, char *argv[])
Static function to parse the command line arguments into a struct containing the information.
uint32_t delay
The delay in seconds between the request and response of the first IPbus transaction.
bool bigendian
Whether we use the big-endian hack.