Commit 37fd0fd2 authored by Piotr Nikiel's avatar Piotr Nikiel
Browse files

Merge branch 'OPCUA-1068_extend_ping_sca' into 'master'

Resolve OPCUA-1068 "Extend ping sca"

Closes OPCUA-1068

See merge request atlas-dcs-common-software/ScaSoftware!23
parents 076d6ac6 09006198
......@@ -10,6 +10,7 @@
#include <sstream>
#include <boost/program_options.hpp>
#include <Sca/Sca.h>
#include <ScaCommon/except.h>
template<typename T>
std::string toStringInHex (T v)
......@@ -26,18 +27,21 @@ struct Config
std::string hostname;
unsigned int from;
unsigned int to;
Log::LOG_LEVEL logLevel;
};
Config parseProgramOptions(int argc, char* argv[])
{
using namespace boost::program_options;
Config config;
options_description options;
std::string logLevelStr;
std::string fromAsStr, toAsStr;
options.add_options()
("help", "show help")
("hostname", value<std::string>(&config.hostname)->default_value("localhost"), "hostname where felixcore is running" )
("from", value<unsigned int>(&config.from)->default_value(0), "elinks range lower bound")
("to", value<unsigned int>(&config.to)->default_value(0xff), "elinks range upper bound")
("help,h", "show help")
("hostname", value<std::string>(&config.hostname)->default_value("127.0.0.1"), "hostname where felixcore is running" ) // in IP address form because netio seems to prefer IPv4
("from", value<std::string>(&fromAsStr)->default_value("0"), "elinks range lower bound - prepend with 0x for hex")
("to", value<std::string>(&toAsStr)->default_value("0xff"), "elinks range upper bound - prepend with 0x for hex")
("trace_level,t", value<std::string>(&logLevelStr)->default_value("INF"), "Trace level, one of: ERR,WRN,INF,DBG,TRC")
;
variables_map vm;
store( parse_command_line (argc, argv, options), vm );
......@@ -47,12 +51,25 @@ Config parseProgramOptions(int argc, char* argv[])
std::cout << options << std::endl;
exit(1);
}
if (! Log::logLevelFromString( logLevelStr, config.logLevel ) )
{
std::cout << "Log level not recognized: '" << logLevelStr << "'" << std::endl;
exit(1);
}
config.from = strtol( fromAsStr.c_str(), nullptr, 0);
config.to = strtol( toAsStr.c_str(), nullptr, 0);
if (config.from > config.to)
{
std::cout << "Given from is higher than given to." << std::endl;
exit(1);
}
return config;
}
int main (int argc, char* argv[])
{
Config config = parseProgramOptions(argc,argv);
Log::initializeLogging( config.logLevel );
const unsigned int numElinks = config.to - config.from + 1;
......@@ -73,12 +90,15 @@ int main (int argc, char* argv[])
Sca::Sca sca (address); // this throws when SCA's not replying at this address
foundSca[elink-config.from].present = true;
foundSca[elink-config.from].id = sca.getChipId();
std::cout << "!! found sca elink=" << toStringInHex(elink) << std::endl;
std::cout << "!! found sca elink=" << toStringInHex(elink) << " ID=" << sca.getChipId() << std::endl;
}
catch (...)
catch (Sca::NoReplyException &e)
{
// do nothing when SCA not found at this address
// take it as a fact of life that not every elink has a SCA attached to it. Do nothing.
}
catch (std::exception &e)
{
LOG(Log::ERR) << "Exception: " << e.what();
}
}
std::cout << "-- scanning results for hostname " << config.hostname << " -- " << std::endl;
......
......@@ -153,7 +153,7 @@ std::vector<Reply> Sca::SynchronousService::SynchronousChannel::sendAndWaitReply
);
if (!gotNotification)
scasw_throw_runtime_error_with_origin("reply hasnt come");
THROW_WITH_ORIGIN(NoReplyException, "reply hasnt come");
return replies;
......
......@@ -11,6 +11,17 @@
#include <stdexcept>
#include <boost/lexical_cast.hpp>
namespace Sca
{
class NoReplyException: std::runtime_error
{
public:
NoReplyException( const std::string& what): std::runtime_error(what) {}
};
}
// note: the following macro should be replaced with more generic THROW_WITH_ORIGIN
#define scasw_throw_runtime_error_with_origin(MSG) throw std::runtime_error(std::string("At ")+__PRETTY_FUNCTION__+" "+MSG)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment