Rev 1594 | Rev 1596 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1594 | Rev 1595 | ||
|---|---|---|---|
| Line 5... | Line 5... | ||
| 5 | 5 | ||
| 6 | #include <boost/bind.hpp> |
6 | #include <boost/bind.hpp> |
| 7 | #include <boost/program_options.hpp> |
7 | #include <boost/program_options.hpp> |
| 8 | 8 | ||
| 9 | #include "net/Manager.h" |
9 | #include "net/Manager.h" |
| 10 | #include "net/ |
10 | #include "net/types.h" |
| 11 | 11 | ||
| 12 | #include "timer/Manager.h" |
12 | #include "timer/Manager.h" |
| 13 | #include "timer/ |
13 | #include "timer/types.h" |
| 14 | 14 | ||
| 15 | #include "config/Manager.h" |
15 | #include "config/Manager.h" |
| 16 | 16 | ||
| 17 | #include "logging/Logger.h" |
17 | #include "logging/Logger.h" |
| 18 | 18 | ||
| Line 37... | Line 37... | ||
| 37 | 37 | ||
| 38 | net::Buffer out_data; |
38 | net::Buffer out_data; |
| 39 | 39 | ||
| 40 | strncpy(out_data.c_array(), data.data(), out_data.size()); |
40 | strncpy(out_data.c_array(), data.data(), out_data.size()); |
| 41 | 41 | ||
| 42 | NM-> |
42 | NM->Disconnect(client_id); |
| - | 43 | ||
| - | 44 | std::cout << "client after disconnect" << s << std::endl; |
|
| 43 | } |
45 | } |
| 44 | 46 | ||
| 45 | void Main_SlotOnTimeout(timer::TimerId timer_id) |
47 | void Main_SlotOnTimeout(timer::TimerId timer_id) |
| 46 | { |
48 | { |
| 47 | std::cout << "timer:" << timer_id << " - expired" << std::endl; |
49 | std::cout << "timer:" << timer_id << " - expired" << std::endl; |
| Line 50... | Line 52... | ||
| 50 | 52 | ||
| 51 | net::Buffer out_data; |
53 | net::Buffer out_data; |
| 52 | 54 | ||
| 53 | strncpy(out_data.c_array(), out_string.data(), out_data.size()); |
55 | strncpy(out_data.c_array(), out_string.data(), out_data.size()); |
| 54 | 56 | ||
| 55 |
|
57 | // NM->SendToAll(server_id, out_data); |
| 56 | } |
58 | } |
| 57 | 59 | ||
| 58 | int main(int argc, char **argv) |
60 | int main(int argc, char **argv) |
| 59 | { |
61 | { |
| 60 | logging::Logger LOG("Main"); |
62 | logging::Logger LOG("Main"); |
| 61 | 63 | ||
| 62 | config::Manager::Pointer CM = config::Manager::Instance(); |
64 | config::Manager::Pointer CM = config::Manager::Instance(); |
| 63 | 65 | ||
| 64 | if (!CM->Set(argc, argv)) |
66 | if (!CM->Set(argc, argv)) |
| 65 | { |
67 | { |
| 66 | return 0; |
68 | return 0; |
| 67 | } |
69 | } |
| 68 | 70 | ||
| 69 | if (CM->Exist("MonitorPort")) |
71 | if (CM->Exist("MonitorPort")) |
| 70 | { |
72 | { |
| 71 | LOG.Info("MonitorPort: " + boost::lexical_cast<std::string>(CM->GetAsInt("MonitorPort"))); |
73 | LOG.Info("MonitorPort: " + boost::lexical_cast<std::string>(CM->GetAsInt("MonitorPort"))); |
| Line 78... | Line 80... | ||
| 78 | for (int n = 0; n < cannets.size(); n++) |
80 | for (int n = 0; n < cannets.size(); n++) |
| 79 | { |
81 | { |
| 80 | LOG.Info("CanNet[" + boost::lexical_cast<std::string>(n) + "]=" + cannets[n]); |
82 | LOG.Info("CanNet[" + boost::lexical_cast<std::string>(n) + "]=" + cannets[n]); |
| 81 | } |
83 | } |
| 82 | 84 | ||
| 83 | } |
- | |
| 84 | LOG.Info("Done!"); |
- | |
| 85 | - | ||
| 86 | return 0; |
- | |
| 87 | - | ||
| 88 | // Declare a group of options that will be |
- | |
| 89 | // allowed only on command line |
- | |
| 90 | boost::program_options::options_description generic("Generic options"); |
- | |
| 91 | generic.add_options() ("version,v", "print version string") |
- | |
| 92 | ("help", "produce help message"); |
- | |
| 93 | - | ||
| 94 | // Declare a group of options that will be |
- | |
| 95 | // allowed both on command line and in |
- | |
| 96 | // config file |
- | |
| 97 | boost::program_options::options_description config("Configuration"); |
- | |
| 98 | config.add_options() |
- | |
| 99 | ("MonitorPort", boost::program_options::value<int>()->default_value(2000), "TCP port to expose for monitoring") |
- | |
| 100 | ("CommandPort", boost::program_options::value<int>()->default_value(2001), "TCP port to expose for monitoring") |
- | |
| 101 | ("LogFile", boost::program_options::value<std::string>(), "File to log output to") |
- | |
| 102 | ("ScriptsPath", boost::program_options::value<std::string>(), "File to log output to") |
- | |
| 103 | ("ProtocolFile", boost::program_options::value<std::string>(), "File to log output to") |
- | |
| 104 | ("DaemonMode,D", "File to log output to") |
- | |
| 105 | ("CanNet_1", boost::program_options::value<std::vector<std::string> >(), "include path"); |
- | |
| 106 | - | ||
| 107 | LOG.Debug("a"); |
- | |
| 108 | boost::program_options::options_description cmdline_options; |
- | |
| 109 | cmdline_options.add(generic).add(config); |
- | |
| 110 | - | ||
| 111 | boost::program_options::options_description config_file_options; |
- | |
| 112 | config_file_options.add(config); |
- | |
| 113 | - | ||
| 114 | boost::program_options::options_description visible("Allowed options"); |
- | |
| 115 | visible.add(generic).add(config); |
- | |
| 116 | - | ||
| 117 | - | ||
| 118 | boost::program_options::variables_map vm; |
- | |
| 119 | store(boost::program_options::command_line_parser(argc, argv).options(cmdline_options).run(), vm); |
- | |
| 120 | LOG.Debug("b"); |
- | |
| 121 | std::ifstream ifs("atom.conf"); |
- | |
| 122 | store(parse_config_file(ifs, config_file_options), vm); |
- | |
| 123 | notify(vm); |
- | |
| 124 | - | ||
| 125 | LOG.Debug("c"); |
- | |
| 126 | - | ||
| 127 | if (vm.count("help")) |
- | |
| 128 | { |
- | |
| 129 | LOG.Info("Help"); |
- | |
| 130 | } |
- | |
| 131 | - | ||
| 132 | if (vm.count("MonitorPort")) |
- | |
| 133 | { |
- | |
| 134 | LOG.Info("MonitorPort: " + boost::lexical_cast<std::string>(vm["MonitorPort"].as<int>())); |
- | |
| 135 | } |
- | |
| 136 | - | ||
| 137 | if (vm.count("LogFile")) |
- | |
| 138 | { |
- | |
| 139 | LOG.Info("LogFile: " + vm["LogFile"].as<std::string>()); |
- | |
| 140 | } |
- | |
| 141 | - | ||
| 142 | if (vm.count("DaemonMode")) |
- | |
| 143 | { |
- | |
| 144 | LOG.Info("DaemonMode: " + vm["DaemonMode"].as<std::string>()); |
- | |
| 145 | } |
85 | } |
| 146 | - | ||
| 147 | - | ||
| 148 | - | ||
| 149 | - | ||
| 150 | - | ||
| 151 | - | ||
| 152 | - | ||
| 153 | - | ||
| 154 | - | ||
| 155 | - | ||
| 156 | - | ||
| 157 | net::Manager::Delete(); |
- | |
| 158 | - | ||
| 159 | - | ||
| 160 | - | ||
| 161 | - | ||
| 162 | return 0; |
- | |
| 163 | 86 | ||
| 164 | LOG.Error("test sdsdsds sds "); |
- | |
| 165 | return 0; |
- | |
| 166 |
|
87 | /* timer::Manager::Pointer TM = timer::Manager::Instance(); |
| 167 | 88 | |
|
| 168 | 89 | |
|
| 169 |
|
90 | TM->Set(10000, true); |
| 170 | 91 | |
|
| 171 | TM->ConnectSlots(boost::bind(&Main_SlotOnTimeout, _1)); |
92 | TM->ConnectSlots(boost::bind(&Main_SlotOnTimeout, _1)); |
| 172 | 93 | */ |
|
| 173 | 94 | ||
| 174 | std::cout << "connect slots2" << std::endl; |
95 | std::cout << "connect slots2" << std::endl; |
| 175 | NM->ConnectSlots(boost::bind(&Main_SlotOnNewState, _1, _2, _3), boost::bind(&Main_SlotOnNewData, _1, _2, _3)); |
96 | NM->ConnectSlots(boost::bind(&Main_SlotOnNewState, _1, _2, _3), boost::bind(&Main_SlotOnNewData, _1, _2, _3)); |
| 176 | 97 | ||
| 177 | 98 | ||
| 178 | try |
99 | try |
| 179 | { |
100 | { |
| 180 |
|
101 | // server_id = NM->StartServer(net::PROTOCOL_SERIAL, 2000); |
| - | 102 | ||
| - | 103 | // timer_id = TM->Set(10000, true); |
|
| - | 104 | ||
| 181 | 105 | ||
| 182 | timer_id = TM->Set(10000, true); |
- | |
| 183 | - | ||
| 184 | /* |
- | |
| 185 |
|
106 | net::ClientId client_id_udp = NM->Connect(net::PROTOCOL_SERIAL, "/dev/ttyUSB0", 57600); |
| 186 | |
107 | |
| 187 | std::cout << "connected" << std::endl; |
108 | std::cout << "connected" << std::endl; |
| 188 | |
109 | |
| 189 | char c[2] = { 251, 0 }; |
110 | char c[2] = { 251, 0 }; |
| - | 111 | ||
| - | 112 | std::cout << "before send " << std::endl; |
|
| 190 |
|
113 | |
| 191 |
|
114 | NM->SendTo(client_id_udp, std::string(c)); |
| 192 | } |
115 | } |
| 193 | catch (std::exception e) |
116 | catch (std::exception e) |
| 194 | { |
117 | { |
| 195 | std::cerr << e.what() << std::endl; |
118 | std::cerr << e.what() << std::endl; |
| 196 | } |
119 | } |