Subversion Repositories HomeAutomation

Rev

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

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