Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
1309 runge 1
//============================================================================
2
// Name        : Atom.cpp
3
// Author      : Mattias Runge
4
// Version     : 2.0
5
// Copyright   : GPL
6
//============================================================================
7
 
8
#include <iostream>
9
#include <istream>
10
#include <ostream>
11
#include <string>
12
#include <fstream>
13
#include <iterator>
14
 
15
#include <stdio.h>
16
 
1310 runge 17
#include "version.h"
1309 runge 18
#include <boost/asio.hpp>
19
#include <boost/bind.hpp>
20
#include <boost/foreach.hpp>
21
#include <boost/program_options.hpp>
22
#include "broker/Broker.h"
23
#include "message/Message.h"
24
#include "subscribers/monitor/Monitor.h"
25
#include "subscribers/cannet/CanNet.h"
26
#include "xml/Node.h"
27
#include "utils/Thread.h"
28
#include "utils/BitBuffer.h"
29
#include "utils/UdpServer.h"
30
#include "xml/Node.h"
1310 runge 31
#include "db/Database.h"
1309 runge 32
 
33
namespace po = boost::program_options;
34
 
35
#define foreach         BOOST_FOREACH
36
#define reverse_foreach BOOST_REVERSE_FOREACH
37
using namespace std;
38
 
39
 
40
using namespace atom;
41
 
42
int main(int argc, char* argv[])
43
{
1310 runge 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
 
1309 runge 55
    xml::Node xmlNode("../../Configuration/protocol.xml");
56
    cout << xmlNode.toString() << endl;
57
 
58
    cout << "::" << xmlNode.selectFirst("datatypes").selectFirst("datatype", xml::Node::attributePair("name", "moduleId"))["lenght"] << endl;
59
 
60
 
61
    broker::Broker::pointer broker = broker::Broker::getInstance();
62
 
63
    utils::UdpServer::pointer udpServer = utils::UdpServer::getInstance(1100);
64
 
65
    subscribers::Monitor::pointer monitorSubscriber(new subscribers::Monitor(broker));
66
    subscribers::CanNet::pointer canNetSubscriber(new subscribers::CanNet(broker, "192.168.1.250", 1100));
67
 
68
 
69
    sleep(10000000);
70
 
71
 
1310 runge 72
    return 0;
1309 runge 73
    //udpSubscriber->write(utils::BitBuffer(startPacket));
74
 
75
 
76
    cout << "ABC123" << endl;
77
 
78
    return 0;
1310 runge 79
    /*sleep(1);
1309 runge 80
 
1310 runge 81
        messagebroker::Message message("");
1309 runge 82
 
83
 
1310 runge 84
        message.data = "test1";
85
        broker.put(message);
1309 runge 86
 
1310 runge 87
        message.setOrigin(monitorSubscriber);
88
        message.data = "test2";
89
        broker.put(message);
90
        sleep(1);
91
        delete monitorSubscriber;
1309 runge 92
 
1310 runge 93
        message.data = "test3";
94
        broker.put(message);
95
        sleep(1);
96
        delete udpSubscriber;
1309 runge 97
 
98
 
1310 runge 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");
1309 runge 106
 
1310 runge 107
            // Declare a group of options that will be
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");
1309 runge 113
 
1310 runge 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");
1309 runge 118
 
1310 runge 119
            po::options_description cmdline_options;
120
            cmdline_options.add(generic).add(config).add(hidden);
1309 runge 121
 
1310 runge 122
            po::options_description config_file_options;
123
            config_file_options.add(config).add(hidden);
1309 runge 124
 
1310 runge 125
            po::options_description visible("Allowed options");
126
            visible.add(generic).add(config);
1309 runge 127
 
1310 runge 128
            po::positional_options_description p;
129
            p.add("input-file", -1);
1309 runge 130
 
1310 runge 131
            po::variables_map vm;
132
            store(po::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm);
1309 runge 133
 
1310 runge 134
            ifstream ifs("multiple_sources.cfg");
135
            store(parse_config_file(ifs, config_file_options), vm);
136
            notify(vm);
1309 runge 137
 
1310 runge 138
            if (vm.count("help"))
139
            {
140
                cout << visible << "\n";
141
                return 0;
142
            }
1309 runge 143
 
1310 runge 144
            if (vm.count("version"))
145
            {
146
                cout << "Multiple sources example, version 1.0\n";
147
                return 0;
148
            }
1309 runge 149
 
1310 runge 150
            if (vm.count("include-path"))
151
            {
152
                //cout << "Include paths are: " << vm["include-path"].as<vector<string>>() << "\n";
153
            }
1309 runge 154
 
1310 runge 155
            if (vm.count("input-file"))
156
            {
157
                //cout << "Input files are: " << vm["input-file"].as<vector<string>>() << "\n";
158
            }
1309 runge 159
 
1310 runge 160
            //cout << "Optimization level is " << opt << "\n";
1309 runge 161
 
1310 runge 162
    */
163
    /*if (argc != 3)
164
    {
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;
169
    }
1309 runge 170
 
1310 runge 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!" );
1309 runge 176
 
1310 runge 177
            foreach( char ch, hello )
178
            {
179
                std::cout << ch;
180
            }
181
 
182
        }
183
        catch (std::exception& e)
1309 runge 184
        {
1310 runge 185
            std::cout << "Exception: " << e.what() << "\n";
1309 runge 186
        }
1310 runge 187
    */
1309 runge 188
    return 0;
189
}