Subversion Repositories HomeAutomation

Rev

Rev 1319 | Rev 1326 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

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