Subversion Repositories HomeAutomation

Rev

Rev 1315 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

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