-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
151 lines (121 loc) · 5.66 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* factory-hardware-emulator - modbus industrial network over TCP emulator console application.
*
* This app is test simulation tool for FactoryController.
*
* This file is part of FactoryController project.
*
* factory-hardware-emulator is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* factory-hardware-emulator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with factory-hardware-emulator; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Copyright (C) Dmitry Ognyannikov, 2014-2016
* dmogn@mail.ru
*/
#include "factory-hardware-emulator/factory-hardware-emulator.h"
// command line argument parser
#include <boost/program_options.hpp>
#include <boost/program_options/cmdline.hpp>
#include <log4cxx/basicconfigurator.h>
// Global EmulatorApplication object
std::shared_ptr<oldportal::fhe::EmulatorApplication> application;
static void close_signal(int dummy)
{
application->_network->close();
exit(dummy);
}
void init_logging()
{
// BasicConfigurator replaced with PropertyConfigurator.
//PropertyConfigurator::configure("log4cxx.properties");
log4cxx::BasicConfigurator::configure();
//log4cxx::LoggerPtr logger = log4cxx::Logger::getRootLogger();
}
int main(int argc, char *argv[])
{
// command line parser
boost::program_options::options_description desc("General options");
desc.add_options()
("help,h", "produce help message")
("version", "print program version")
("config,c", boost::program_options::value<std::string>(), "initialize with configuration file")
;
// without unnamed parameters
//boost::program_options::variables_map vm;
//boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
//boost::program_options::notify(vm);
// with unnamed parameters
boost::program_options::positional_options_description p;
p.add("project", -1);
boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::command_line_parser(argc, argv).
options(desc).positional(p).run(), vm);
boost::program_options::notify(vm);
// init log
init_logging();
// print general program description
// std::cout << "factory-hardware-emulator - modbus network over TCP emulator console application" << std::endl;
// std::cout << "This app is test emulation tool for factorycontroller." << std::endl;
// std::cout << "Copyright (C) Dmitry Ognyannikov, 2012-2015" << std::endl;
LOG4CXX_INFO(log4cxx::Logger::getRootLogger(), "factory-hardware-emulator - modbus network over TCP emulator console application");
LOG4CXX_INFO(log4cxx::Logger::getRootLogger(), "This app is test emulation tool for factorycontroller");
LOG4CXX_INFO(log4cxx::Logger::getRootLogger(), "Copyright (C) Dmitry Ognyannikov, 2012-2015");
if (vm.count("help"))
{
std::cout << desc << std::endl;
return 1;
}
if (vm.count("version"))
{
std::cout << "version 0.1 alpha" << std::endl;
return 1;
}
LOG4CXX_INFO(log4cxx::Logger::getRootLogger(), "factory hardware emulator start");
// init factory
if (vm.count("config"))
{
// file configuration loader
std::string config_filename = vm["config"].as<std::string>();
//std::cout << "Initialize with configuration file: " << config_filename << std::endl;
LOG4CXX_INFO(log4cxx::Logger::getRootLogger(), std::string("Initialize with configuration file: ") + config_filename);
application = std::make_shared<oldportal::fhe::EmulatorApplication>();
// init loader
//auto loader = std::make_shared<oldportal::fc::factory::manufacturing::proc::FactoryConfigurationFileLoader>(config_filename);
//loader->init();
//factory = std::make_shared<oldportal::fc::factory::manufacturing::Factory>
// (std::static_pointer_cast<oldportal::fc::factory::manufacturing::FactoryLoader>(loader));
// free loader
//loader.reset();
//TODO: load application configuration
application->_network->init();
// set exit signal cutch before enter main cycle
signal(SIGTERM, close_signal);
application->_network->run();
}
else
{
// pure program loader (default)
//std::cout << "Initialize with default configuration" << std::endl;
LOG4CXX_INFO(log4cxx::Logger::getRootLogger(), "Initialize with default configuration (pure program loader)");
application = std::make_shared<oldportal::fhe::EmulatorApplication>();
application->_network = std::make_shared<oldportal::fhe::network::ModbusNetworkController>(application);
std::shared_ptr<oldportal::fhe::device::Device> device = std::make_shared<oldportal::fhe::hardware::mechatronics::StepMotor>();
device->_modbus_address = 18;
application->_devices.push_back(device);
LOG4CXX_INFO(log4cxx::Logger::getRootLogger(), "StepMotor device added, modbus_address: ");
application->_network->init();
// set exit signal cutch before enter main cycle
signal(SIGTERM, close_signal);
application->_network->run();
}
}