Subversion Repositories HomeAutomation

Rev

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

Rev 1328 Rev 1403
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/Header.h"
23
#include "message/Header.h"
24
#include "message/Message.h"
24
#include "message/Message.h"
25
#include "subscribers/monitor/Monitor.h"
25
#include "subscribers/monitor/Monitor.h"
26
#include "subscribers/cannet/CanNet.h"
26
#include "subscribers/cannet/CanNet.h"
27
#include "xml/Node.h"
27
#include "xml/Node.h"
28
#include "thread/Thread.h"
28
#include "thread/Thread.h"
29
#include "net/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
#include "Exception.hpp"
33
#include "Exception.hpp"
34
 
34
 
35
namespace po = boost::program_options;
35
namespace po = boost::program_options;
36
 
36
 
37
#define foreach         BOOST_FOREACH
37
#define foreach         BOOST_FOREACH
38
#define reverse_foreach BOOST_REVERSE_FOREACH
38
#define reverse_foreach BOOST_REVERSE_FOREACH
39
using namespace std;
39
using namespace std;
40
 
40
 
41
 
41
 
42
using namespace atom;
42
using namespace atom;
43
/*
43
/*
44
#
44
#
45
#include <unistd.h>
45
#include <unistd.h>
46
 
46
 
47
#
47
#
48
#include <stdlib.h>// for MAX_PATH
48
#include <stdlib.h>// for MAX_PATH
49
#
49
#
50
#include <iostream> // for cout and cin
50
#include <iostream> // for cout and cin
51
#
51
#
52
 
52
 
53
#
53
#
54
using namespace std;
54
using namespace std;
55
#
55
#
56
// function to return the current working directory
56
// function to return the current working directory
57
#
57
#
58
// this is generally the application path
58
// this is generally the application path
59
#
59
#
60
void GetCurrentPath(char* buffer)
60
void GetCurrentPath(char* buffer)
61
#
61
#
62
{
62
{
63
#
63
#
64
getcwd(buffer, 1024);
64
getcwd(buffer, 1024);
65
#
65
#
66
}
66
}
67
#
67
#
68
 
68
 
69
#
69
#
70
int main()
70
int main()
71
#
71
#
72
{
72
{
73
#
73
#
74
 
74
 
75
#
75
#
76
// _MAX_PATH is the maximum length allowed for a path
76
// _MAX_PATH is the maximum length allowed for a path
77
#
77
#
78
char CurrentPath[1024];
78
char CurrentPath[1024];
79
#
79
#
80
// use the function to get the path
80
// use the function to get the path
81
#
81
#
82
GetCurrentPath(CurrentPath);
82
GetCurrentPath(CurrentPath);
83
#
83
#
84
 
84
 
85
#
85
#
86
// display the path for demo purposes only
86
// display the path for demo purposes only
87
#
87
#
88
char temp[1024];
88
char temp[1024];
89
#
89
#
90
cout << CurrentPath << endl;
90
cout << CurrentPath << endl;
91
#
91
#
92
cout << "Press Enter to continue";
92
cout << "Press Enter to continue";
93
#
93
#
94
cin.getline(temp,1024);
94
cin.getline(temp,1024);
95
#
95
#
96
return 0;
96
return 0;
97
#
97
#
98
}
98
}
99
*/
99
*/
-
 
100
 
-
 
101
float stof(const string s)
-
 
102
{
-
 
103
    istringstream in(s);
-
 
104
    float f;
-
 
105
    in >> f;
-
 
106
    return f;
-
 
107
}
-
 
108
 
-
 
109
 
100
int main(int argc, char* argv[])
110
int main(int argc, char* argv[])
101
{
111
{
-
 
112
 
-
 
113
    float a = stof("1,44");
-
 
114
 
-
 
115
 
-
 
116
 
-
 
117
    cout << a << endl;
-
 
118
 
-
 
119
    return 0;
102
    try
120
    try
103
    {
121
    {
104
        log::Logger LOG;
122
        log::Logger LOG;
105
        LOG.setName("Main");
123
        LOG.setName("Main");
106
 
124
 
107
        LOG.info("Atom (" + string(AutoVersion::FULLVERSION_STRING) + " " + string(AutoVersion::STATUS) + ")");
125
        LOG.info("Atom (" + string(AutoVersion::FULLVERSION_STRING) + " " + string(AutoVersion::STATUS) + ")");
108
        LOG.info("Written by Mattias Runge 2009");
126
        LOG.info("Written by Mattias Runge 2009");
109
 
127
 
110
        Protocol::getInstance()->load("../../Configuration/protocol.xml", "../../Configuration/protocol-cache.xml");
128
        Protocol::getInstance()->load("../../Configuration/protocol.xml", "../../Configuration/protocol-cache.xml");
111
 
129
 
112
        broker::Broker::pointer broker = broker::Broker::getInstance();
130
        broker::Broker::pointer broker = broker::Broker::getInstance();
113
 
131
 
114
        subscribers::Monitor::pointer monitorSubscriber(new subscribers::Monitor(broker));
132
        subscribers::Monitor::pointer monitorSubscriber(new subscribers::Monitor(broker));
115
        subscribers::CanNet::pointer canNetSubscriber(new subscribers::CanNet(broker, "192.168.1.250", 1100));
133
        subscribers::CanNet::pointer canNetSubscriber(new subscribers::CanNet(broker, "192.168.1.250", 1100));
116
 
134
 
117
        /*LOG.info("Will now try to send a message...");
135
        /*LOG.info("Will now try to send a message...");
118
 
136
 
119
        message::Header header(0, "irTranceiver", "temperature");
137
        message::Header header(0, "irTranceiver", "temperature");
120
 
138
 
121
        LOG.info("Header constructed...");
139
        LOG.info("Header constructed...");
122
 
140
 
123
        message::Message::pointer message(new message::Message(header));
141
        message::Message::pointer message(new message::Message(header));
124
 
142
 
125
        LOG.info("Message constructed...");
143
        LOG.info("Message constructed...");
126
 
144
 
127
        broker->put(message);*/
145
        broker->put(message);*/
128
 
146
 
129
        sleep(10000000);
147
        sleep(10000000);
130
    }
148
    }
131
    catch (Exception * e)
149
    catch (Exception * e)
132
    {
150
    {
133
        cout << "Exception: " << e->getDescription() << endl;
151
        cout << "Exception: " << e->getDescription() << endl;
134
    }
152
    }
135
 
153
 
136
 
154
 
137
 
155
 
138
 
156
 
139
    return 0;
157
    return 0;
140
    //udpSubscriber->write(utils::BitBuffer(startPacket));
158
    //udpSubscriber->write(utils::BitBuffer(startPacket));
141
 
159
 
142
 
160
 
143
    cout << "ABC123" << endl;
161
    cout << "ABC123" << endl;
144
 
162
 
145
    return 0;
163
    return 0;
146
    /*sleep(1);
164
    /*sleep(1);
147
 
165
 
148
        messagebroker::Message message("");
166
        messagebroker::Message message("");
149
 
167
 
150
 
168
 
151
        message.data = "test1";
169
        message.data = "test1";
152
        broker.put(message);
170
        broker.put(message);
153
 
171
 
154
        message.setOrigin(monitorSubscriber);
172
        message.setOrigin(monitorSubscriber);
155
        message.data = "test2";
173
        message.data = "test2";
156
        broker.put(message);
174
        broker.put(message);
157
        sleep(1);
175
        sleep(1);
158
        delete monitorSubscriber;
176
        delete monitorSubscriber;
159
 
177
 
160
        message.data = "test3";
178
        message.data = "test3";
161
        broker.put(message);
179
        broker.put(message);
162
        sleep(1);
180
        sleep(1);
163
        delete udpSubscriber;
181
        delete udpSubscriber;
164
 
182
 
165
 
183
 
166
        try
184
        try
167
        {
185
        {
168
            // Declare a group of options that will be
186
            // Declare a group of options that will be
169
            // allowed only on command line
187
            // allowed only on command line
170
            po::options_description generic("Generic options");
188
            po::options_description generic("Generic options");
171
            generic.add_options()   ("version,v", "print version string")
189
            generic.add_options()   ("version,v", "print version string")
172
                                    ("help", "produce help message");
190
                                    ("help", "produce help message");
173
 
191
 
174
            // Declare a group of options that will be
192
            // Declare a group of options that will be
175
            // allowed both on command line and in
193
            // allowed both on command line and in
176
            // config file
194
            // config file
177
            po::options_description config("Configuration");
195
            po::options_description config("Configuration");
178
            config.add_options()("optimization", po::value<int>()->default_value(10), "optimization level")
196
            config.add_options()("optimization", po::value<int>()->default_value(10), "optimization level")
179
                                ("include-path,I", po::value<vector<string> >()->composing(), "include path");
197
                                ("include-path,I", po::value<vector<string> >()->composing(), "include path");
180
 
198
 
181
            // Hidden options, will be allowed both on command line and
199
            // Hidden options, will be allowed both on command line and
182
            // in config file, but will not be shown to the user.
200
            // in config file, but will not be shown to the user.
183
            po::options_description hidden("Hidden options");
201
            po::options_description hidden("Hidden options");
184
            hidden.add_options()("input-file", po::value<vector<string> >(), "input file");
202
            hidden.add_options()("input-file", po::value<vector<string> >(), "input file");
185
 
203
 
186
            po::options_description cmdline_options;
204
            po::options_description cmdline_options;
187
            cmdline_options.add(generic).add(config).add(hidden);
205
            cmdline_options.add(generic).add(config).add(hidden);
188
 
206
 
189
            po::options_description config_file_options;
207
            po::options_description config_file_options;
190
            config_file_options.add(config).add(hidden);
208
            config_file_options.add(config).add(hidden);
191
 
209
 
192
            po::options_description visible("Allowed options");
210
            po::options_description visible("Allowed options");
193
            visible.add(generic).add(config);
211
            visible.add(generic).add(config);
194
 
212
 
195
            po::positional_options_description p;
213
            po::positional_options_description p;
196
            p.add("input-file", -1);
214
            p.add("input-file", -1);
197
 
215
 
198
            po::variables_map vm;
216
            po::variables_map vm;
199
            store(po::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm);
217
            store(po::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm);
200
 
218
 
201
            ifstream ifs("multiple_sources.cfg");
219
            ifstream ifs("multiple_sources.cfg");
202
            store(parse_config_file(ifs, config_file_options), vm);
220
            store(parse_config_file(ifs, config_file_options), vm);
203
            notify(vm);
221
            notify(vm);
204
 
222
 
205
            if (vm.count("help"))
223
            if (vm.count("help"))
206
            {
224
            {
207
                cout << visible << "\n";
225
                cout << visible << "\n";
208
                return 0;
226
                return 0;
209
            }
227
            }
210
 
228
 
211
            if (vm.count("version"))
229
            if (vm.count("version"))
212
            {
230
            {
213
                cout << "Multiple sources example, version 1.0\n";
231
                cout << "Multiple sources example, version 1.0\n";
214
                return 0;
232
                return 0;
215
            }
233
            }
216
 
234
 
217
            if (vm.count("include-path"))
235
            if (vm.count("include-path"))
218
            {
236
            {
219
                //cout << "Include paths are: " << vm["include-path"].as<vector<string>>() << "\n";
237
                //cout << "Include paths are: " << vm["include-path"].as<vector<string>>() << "\n";
220
            }
238
            }
221
 
239
 
222
            if (vm.count("input-file"))
240
            if (vm.count("input-file"))
223
            {
241
            {
224
                //cout << "Input files are: " << vm["input-file"].as<vector<string>>() << "\n";
242
                //cout << "Input files are: " << vm["input-file"].as<vector<string>>() << "\n";
225
            }
243
            }
226
 
244
 
227
            //cout << "Optimization level is " << opt << "\n";
245
            //cout << "Optimization level is " << opt << "\n";
228
 
246
 
229
    */
247
    */
230
    /*if (argc != 3)
248
    /*if (argc != 3)
231
    {
249
    {
232
        std::cout << "Usage: async_client <server> <path>\n";
250
        std::cout << "Usage: async_client <server> <path>\n";
233
        std::cout << "Example:\n";
251
        std::cout << "Example:\n";
234
        std::cout << "  async_client www.boost.org /LICENSE_1_0.txt\n";
252
        std::cout << "  async_client www.boost.org /LICENSE_1_0.txt\n";
235
        return 1;
253
        return 1;
236
    }
254
    }
237
 
255
 
238
    boost::asio::io_service io_service;
256
    boost::asio::io_service io_service;
239
    client c(io_service, argv[1], argv[2]);
257
    client c(io_service, argv[1], argv[2]);
240
    io_service.run();*/
258
    io_service.run();*/
241
    /*
259
    /*
242
             std::string hello( "Hello, world!" );
260
             std::string hello( "Hello, world!" );
243
 
261
 
244
            foreach( char ch, hello )
262
            foreach( char ch, hello )
245
            {
263
            {
246
                std::cout << ch;
264
                std::cout << ch;
247
            }
265
            }
248
 
266
 
249
        }
267
        }
250
        catch (std::exception& e)
268
        catch (std::exception& e)
251
        {
269
        {
252
            std::cout << "Exception: " << e.what() << "\n";
270
            std::cout << "Exception: " << e.what() << "\n";
253
        }
271
        }
254
    */
272
    */
255
    return 0;
273
    return 0;
256
}
274
}
257
 
275