Subversion Repositories HomeAutomation

Rev

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