Rev 1319 | Rev 1326 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1309 | runge | 1 | //============================================================================ |
| 2 | // Name : Atom.cpp |
||
| 3 | // Author : Mattias Runge |
||
| 4 | // Version : 2.0 |
||
| 5 | // Copyright : GPL |
||
| 6 | //============================================================================ |
||
| 7 | |||
| 8 | #include <iostream> |
||
| 9 | #include <istream> |
||
| 10 | #include <ostream> |
||
| 11 | #include <string> |
||
| 12 | #include <fstream> |
||
| 13 | #include <iterator> |
||
| 14 | |||
| 15 | #include <stdio.h> |
||
| 16 | |||
| 1310 | runge | 17 | #include "version.h" |
| 1309 | runge | 18 | #include <boost/asio.hpp> |
| 19 | #include <boost/bind.hpp> |
||
| 20 | #include <boost/foreach.hpp> |
||
| 21 | #include <boost/program_options.hpp> |
||
| 22 | #include "broker/Broker.h" |
||
| 23 | #include "message/Message.h" |
||
| 24 | #include "subscribers/monitor/Monitor.h" |
||
| 25 | #include "subscribers/cannet/CanNet.h" |
||
| 26 | #include "xml/Node.h" |
||
| 1317 | runge | 27 | #include "thread/Thread.h" |
| 28 | #include "net/UdpServer.h" |
||
| 1309 | runge | 29 | #include "xml/Node.h" |
| 1311 | runge | 30 | #include "protocol/Protocol.h" |
| 1315 | runge | 31 | #include "log/Logger.h" |
| 1309 | runge | 32 | |
| 33 | namespace po = boost::program_options; |
||
| 34 | |||
| 35 | #define foreach BOOST_FOREACH |
||
| 36 | #define reverse_foreach BOOST_REVERSE_FOREACH |
||
| 37 | using namespace std; |
||
| 38 | |||
| 39 | |||
| 40 | using namespace atom; |
||
| 41 | |||
| 42 | int main(int argc, char* argv[]) |
||
| 43 | { |
||
| 1315 | runge | 44 | log::Logger LOG; |
| 1310 | runge | 45 | LOG.setName("Main"); |
| 46 | |||
| 47 | LOG.info("Atom (" + string(AutoVersion::FULLVERSION_STRING) + " " + string(AutoVersion::STATUS) + ")"); |
||
| 48 | LOG.info("Written by Mattias Runge 2009"); |
||
| 49 | |||
| 1322 | runge | 50 | float log2_2 = log2f(2); |
| 1310 | runge | 51 | |
| 1322 | runge | 52 | LOG.info("bitcount: 0 :: " + convert::int2string(ceil(log2f(0+1)/log2_2)) + " == " + convert::uint2string(convert::stateCount2bitCount(0))); |
| 53 | LOG.info("bitcount: 1 :: " + convert::int2string(ceil(log2f(1+1)/log2_2)) + " == " + convert::uint2string(convert::stateCount2bitCount(1))); |
||
| 54 | LOG.info("bitcount: 2 :: " + convert::int2string(ceil(log2f(2+1)/log2_2)) + " == " + convert::uint2string(convert::stateCount2bitCount(2))); |
||
| 55 | LOG.info("bitcount: 3 :: " + convert::int2string(ceil(log2f(3+1)/log2_2)) + " == " + convert::uint2string(convert::stateCount2bitCount(3))); |
||
| 56 | LOG.info("bitcount: 4 :: " + convert::int2string(ceil(log2f(4+1)/log2_2)) + " == " + convert::uint2string(convert::stateCount2bitCount(4))); |
||
| 57 | LOG.info("bitcount: 5 :: " + convert::int2string(ceil(log2f(5+1)/log2_2)) + " == " + convert::uint2string(convert::stateCount2bitCount(5))); |
||
| 58 | LOG.info("bitcount: 6 :: " + convert::int2string(ceil(log2f(6+1)/log2_2)) + " == " + convert::uint2string(convert::stateCount2bitCount(6))); |
||
| 59 | LOG.info("bitcount: 7 :: " + convert::int2string(ceil(log2f(7+1)/log2_2)) + " == " + convert::uint2string(convert::stateCount2bitCount(7))); |
||
| 60 | LOG.info("bitcount: 8 :: " + convert::int2string(ceil(log2f(8+1)/log2_2)) + " == " + convert::uint2string(convert::stateCount2bitCount(8))); |
||
| 1318 | runge | 61 | |
| 1311 | runge | 62 | Protocol::pointer protocol = Protocol::getInstance(); |
| 63 | protocol->load("../../Configuration/protocol.xml"); |
||
| 64 | cout << protocol->getRootNode().toString() << endl; |
||
| 1310 | runge | 65 | |
| 66 | |||
| 1309 | runge | 67 | broker::Broker::pointer broker = broker::Broker::getInstance(); |
| 68 | |||
| 69 | subscribers::Monitor::pointer monitorSubscriber(new subscribers::Monitor(broker)); |
||
| 70 | subscribers::CanNet::pointer canNetSubscriber(new subscribers::CanNet(broker, "192.168.1.250", 1100)); |
||
| 71 | |||
| 72 | |||
| 73 | sleep(10000000); |
||
| 74 | |||
| 75 | |||
| 1310 | runge | 76 | return 0; |
| 1309 | runge | 77 | //udpSubscriber->write(utils::BitBuffer(startPacket)); |
| 78 | |||
| 79 | |||
| 80 | cout << "ABC123" << endl; |
||
| 81 | |||
| 82 | return 0; |
||
| 1310 | runge | 83 | /*sleep(1); |
| 1309 | runge | 84 | |
| 1310 | runge | 85 | messagebroker::Message message(""); |
| 1309 | runge | 86 | |
| 87 | |||
| 1310 | runge | 88 | message.data = "test1"; |
| 89 | broker.put(message); |
||
| 1309 | runge | 90 | |
| 1310 | runge | 91 | message.setOrigin(monitorSubscriber); |
| 92 | message.data = "test2"; |
||
| 93 | broker.put(message); |
||
| 94 | sleep(1); |
||
| 95 | delete monitorSubscriber; |
||
| 1309 | runge | 96 | |
| 1310 | runge | 97 | message.data = "test3"; |
| 98 | broker.put(message); |
||
| 99 | sleep(1); |
||
| 100 | delete udpSubscriber; |
||
| 1309 | runge | 101 | |
| 102 | |||
| 1310 | runge | 103 | try |
| 104 | { |
||
| 105 | // Declare a group of options that will be |
||
| 106 | // allowed only on command line |
||
| 107 | po::options_description generic("Generic options"); |
||
| 108 | generic.add_options() ("version,v", "print version string") |
||
| 109 | ("help", "produce help message"); |
||
| 1309 | runge | 110 | |
| 1310 | runge | 111 | // Declare a group of options that will be |
| 112 | // allowed both on command line and in |
||
| 113 | // config file |
||
| 114 | po::options_description config("Configuration"); |
||
| 115 | config.add_options()("optimization", po::value<int>()->default_value(10), "optimization level") |
||
| 116 | ("include-path,I", po::value<vector<string> >()->composing(), "include path"); |
||
| 1309 | runge | 117 | |
| 1310 | runge | 118 | // Hidden options, will be allowed both on command line and |
| 119 | // in config file, but will not be shown to the user. |
||
| 120 | po::options_description hidden("Hidden options"); |
||
| 121 | hidden.add_options()("input-file", po::value<vector<string> >(), "input file"); |
||
| 1309 | runge | 122 | |
| 1310 | runge | 123 | po::options_description cmdline_options; |
| 124 | cmdline_options.add(generic).add(config).add(hidden); |
||
| 1309 | runge | 125 | |
| 1310 | runge | 126 | po::options_description config_file_options; |
| 127 | config_file_options.add(config).add(hidden); |
||
| 1309 | runge | 128 | |
| 1310 | runge | 129 | po::options_description visible("Allowed options"); |
| 130 | visible.add(generic).add(config); |
||
| 1309 | runge | 131 | |
| 1310 | runge | 132 | po::positional_options_description p; |
| 133 | p.add("input-file", -1); |
||
| 1309 | runge | 134 | |
| 1310 | runge | 135 | po::variables_map vm; |
| 136 | store(po::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm); |
||
| 1309 | runge | 137 | |
| 1310 | runge | 138 | ifstream ifs("multiple_sources.cfg"); |
| 139 | store(parse_config_file(ifs, config_file_options), vm); |
||
| 140 | notify(vm); |
||
| 1309 | runge | 141 | |
| 1310 | runge | 142 | if (vm.count("help")) |
| 143 | { |
||
| 144 | cout << visible << "\n"; |
||
| 145 | return 0; |
||
| 146 | } |
||
| 1309 | runge | 147 | |
| 1310 | runge | 148 | if (vm.count("version")) |
| 149 | { |
||
| 150 | cout << "Multiple sources example, version 1.0\n"; |
||
| 151 | return 0; |
||
| 152 | } |
||
| 1309 | runge | 153 | |
| 1310 | runge | 154 | if (vm.count("include-path")) |
| 155 | { |
||
| 156 | //cout << "Include paths are: " << vm["include-path"].as<vector<string>>() << "\n"; |
||
| 157 | } |
||
| 1309 | runge | 158 | |
| 1310 | runge | 159 | if (vm.count("input-file")) |
| 160 | { |
||
| 161 | //cout << "Input files are: " << vm["input-file"].as<vector<string>>() << "\n"; |
||
| 162 | } |
||
| 1309 | runge | 163 | |
| 1310 | runge | 164 | //cout << "Optimization level is " << opt << "\n"; |
| 1309 | runge | 165 | |
| 1310 | runge | 166 | */ |
| 167 | /*if (argc != 3) |
||
| 168 | { |
||
| 169 | std::cout << "Usage: async_client <server> <path>\n"; |
||
| 170 | std::cout << "Example:\n"; |
||
| 171 | std::cout << " async_client www.boost.org /LICENSE_1_0.txt\n"; |
||
| 172 | return 1; |
||
| 173 | } |
||
| 1309 | runge | 174 | |
| 1310 | runge | 175 | boost::asio::io_service io_service; |
| 176 | client c(io_service, argv[1], argv[2]); |
||
| 177 | io_service.run();*/ |
||
| 178 | /* |
||
| 179 | std::string hello( "Hello, world!" ); |
||
| 1309 | runge | 180 | |
| 1310 | runge | 181 | foreach( char ch, hello ) |
| 182 | { |
||
| 183 | std::cout << ch; |
||
| 184 | } |
||
| 185 | |||
| 186 | } |
||
| 187 | catch (std::exception& e) |
||
| 1309 | runge | 188 | { |
| 1310 | runge | 189 | std::cout << "Exception: " << e.what() << "\n"; |
| 1309 | runge | 190 | } |
| 1310 | runge | 191 | */ |
| 1309 | runge | 192 | return 0; |
| 193 | } |