Subversion Repositories HomeAutomation

Rev

Rev 1309 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1309 Rev 1310
Line 12... Line 12...
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"
Line 25... Line 26...
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
Line 37... Line 39...
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);
-
 
80
 
-
 
81
        messagebroker::Message message("");
-
 
82
 
-
 
83
 
-
 
84
        message.data = "test1";
-
 
85
        broker.put(message);
-
 
86
 
-
 
87
        message.setOrigin(monitorSubscriber);
-
 
88
        message.data = "test2";
-
 
89
        broker.put(message);
-
 
90
        sleep(1);
-
 
91
        delete monitorSubscriber;
-
 
92
 
-
 
93
        message.data = "test3";
-
 
94
        broker.put(message);
-
 
95
        sleep(1);
-
 
96
        delete udpSubscriber;
-
 
97
 
-
 
98
 
-
 
99
        try
-
 
100
        {
-
 
101
            // Declare a group of options that will be
-
 
102
            // allowed only on command line
-
 
103
            po::options_description generic("Generic options");
-
 
104
            generic.add_options()   ("version,v", "print version string")
-
 
105
                                    ("help", "produce help message");
67
 
106
 
-
 
107
            // Declare a group of options that will be
68
    messagebroker::Message message("");
108
            // allowed both on command line and in
-
 
109
            // config file
-
 
110
            po::options_description config("Configuration");
-
 
111
            config.add_options()("optimization", po::value<int>()->default_value(10), "optimization level")
-
 
112
                                ("include-path,I", po::value<vector<string> >()->composing(), "include path");
69
 
113
 
-
 
114
            // Hidden options, will be allowed both on command line and
-
 
115
            // in config file, but will not be shown to the user.
-
 
116
            po::options_description hidden("Hidden options");
-
 
117
            hidden.add_options()("input-file", po::value<vector<string> >(), "input file");
70
 
118
 
71
    message.data = "test1";
119
            po::options_description cmdline_options;
72
    broker.put(message);
120
            cmdline_options.add(generic).add(config).add(hidden);
73
 
121
 
74
    message.setOrigin(monitorSubscriber);
122
            po::options_description config_file_options;
75
    message.data = "test2";
-
 
76
    broker.put(message);
-
 
77
    sleep(1);
-
 
78
    delete monitorSubscriber;
123
            config_file_options.add(config).add(hidden);
79
 
124
 
80
    message.data = "test3";
125
            po::options_description visible("Allowed options");
81
    broker.put(message);
126
            visible.add(generic).add(config);
82
    sleep(1);
-
 
83
    delete udpSubscriber;
-
 
84
 
127
 
-
 
128
            po::positional_options_description p;
-
 
129
            p.add("input-file", -1);
85
 
130
 
86
    try
-
 
87
    {
-
 
88
        // Declare a group of options that will be
-
 
89
        // allowed only on command line
-
 
90
        po::options_description generic("Generic options");
-
 
91
        generic.add_options()   ("version,v", "print version string")
-
 
92
                                ("help", "produce help message");
-
 
93
 
-
 
94
        // Declare a group of options that will be
-
 
95
        // allowed both on command line and in
-
 
96
        // config file
-
 
97
        po::options_description config("Configuration");
-
 
98
        config.add_options()("optimization", po::value<int>()->default_value(10), "optimization level")
-
 
99
                            ("include-path,I", po::value<vector<string> >()->composing(), "include path");
-
 
100
 
-
 
101
        // Hidden options, will be allowed both on command line and
-
 
102
        // in config file, but will not be shown to the user.
-
 
103
        po::options_description hidden("Hidden options");
-
 
104
        hidden.add_options()("input-file", po::value<vector<string> >(), "input file");
-
 
105
 
-
 
106
        po::options_description cmdline_options;
-
 
107
        cmdline_options.add(generic).add(config).add(hidden);
-
 
108
 
-
 
109
        po::options_description config_file_options;
-
 
110
        config_file_options.add(config).add(hidden);
-
 
111
 
-
 
112
        po::options_description visible("Allowed options");
-
 
113
        visible.add(generic).add(config);
-
 
114
 
-
 
115
        po::positional_options_description p;
-
 
116
        p.add("input-file", -1);
-
 
117
 
-
 
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
 
-
 
121
        ifstream ifs("multiple_sources.cfg");
-
 
122
        store(parse_config_file(ifs, config_file_options), vm);
-
 
123
        notify(vm);
-
 
124
 
-
 
125
        if (vm.count("help"))
-
 
126
        {
-
 
127
            cout << visible << "\n";
-
 
128
            return 0;
-
 
129
        }
-
 
130
 
-
 
131
        if (vm.count("version"))
-
 
132
        {
-
 
133
            cout << "Multiple sources example, version 1.0\n";
-
 
134
            return 0;
-
 
135
        }
-
 
136
 
-
 
137
        if (vm.count("include-path"))
-
 
138
        {
-
 
139
            //cout << "Include paths are: " << vm["include-path"].as<vector<string>>() << "\n";
-
 
140
        }
-
 
141
 
-
 
142
        if (vm.count("input-file"))
-
 
143
        {
-
 
144
            //cout << "Input files are: " << vm["input-file"].as<vector<string>>() << "\n";
-
 
145
        }
-
 
146
 
-
 
147
        //cout << "Optimization level is " << opt << "\n";
-
 
148
 
-
 
149
*/
-
 
150
        /*if (argc != 3)
-
 
151
        {
-
 
152
            std::cout << "Usage: async_client <server> <path>\n";
-
 
153
            std::cout << "Example:\n";
-
 
154
            std::cout << "  async_client www.boost.org /LICENSE_1_0.txt\n";
-
 
155
            return 1;
-
 
156
        }
-
 
157
 
133
 
158
        boost::asio::io_service io_service;
134
            ifstream ifs("multiple_sources.cfg");
159
        client c(io_service, argv[1], argv[2]);
135
            store(parse_config_file(ifs, config_file_options), vm);
160
        io_service.run();*/
136
            notify(vm);
161
/*
-
 
162
         std::string hello( "Hello, world!" );
-
 
163
 
137
 
164
        foreach( char ch, hello )
138
            if (vm.count("help"))
165
        {
139
            {
-
 
140
                cout << visible << "\n";
166
            std::cout << ch;
141
                return 0;
167
        }
142
            }
168
 
143
 
-
 
144
            if (vm.count("version"))
-
 
145
            {
-
 
146
                cout << "Multiple sources example, version 1.0\n";
-
 
147
                return 0;
169
    }
148
            }
-
 
149
 
-
 
150
            if (vm.count("include-path"))
-
 
151
            {
-
 
152
                //cout << "Include paths are: " << vm["include-path"].as<vector<string>>() << "\n";
-
 
153
            }
-
 
154
 
170
    catch (std::exception& e)
155
            if (vm.count("input-file"))
-
 
156
            {
-
 
157
                //cout << "Input files are: " << vm["input-file"].as<vector<string>>() << "\n";
-
 
158
            }
-
 
159
 
-
 
160
            //cout << "Optimization level is " << opt << "\n";
-
 
161
 
-
 
162
    */
-
 
163
    /*if (argc != 3)
171
    {
164
    {
172
        std::cout << "Exception: " << e.what() << "\n";
165
        std::cout << "Usage: async_client <server> <path>\n";
-
 
166
        std::cout << "Example:\n";
-
 
167
        std::cout << "  async_client www.boost.org /LICENSE_1_0.txt\n";
-
 
168
        return 1;
173
    }
169
    }
-
 
170
 
-
 
171
    boost::asio::io_service io_service;
-
 
172
    client c(io_service, argv[1], argv[2]);
-
 
173
    io_service.run();*/
-
 
174
    /*
-
 
175
             std::string hello( "Hello, world!" );
-
 
176
 
-
 
177
            foreach( char ch, hello )
-
 
178
            {
-
 
179
                std::cout << ch;
-
 
180
            }
-
 
181
 
-
 
182
        }
-
 
183
        catch (std::exception& e)
-
 
184
        {
-
 
185
            std::cout << "Exception: " << e.what() << "\n";
-
 
186
        }
174
*/
187
    */
175
    return 0;
188
    return 0;
176
}
189
}