Subversion Repositories HomeAutomation

Rev

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

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