Subversion Repositories HomeAutomation

Rev

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

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