Subversion Repositories HomeAutomation

Rev

Rev 1322 | Rev 1328 | Go to most recent revision | 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;
43
 
44
int main(int argc, char* argv[])
45
{
1326 runge 46
	try
47
	{
48
		log::Logger LOG;
49
		LOG.setName("Main");
1310 runge 50
 
1326 runge 51
		LOG.info("Atom (" + string(AutoVersion::FULLVERSION_STRING) + " " + string(AutoVersion::STATUS) + ")");
52
		LOG.info("Written by Mattias Runge 2009");
1310 runge 53
 
1326 runge 54
		Protocol::getInstance()->load("../../Configuration/protocol.xml", "../../Configuration/protocol-cache.xml");
1310 runge 55
 
1326 runge 56
		broker::Broker::pointer broker = broker::Broker::getInstance();
1318 runge 57
 
1326 runge 58
		subscribers::Monitor::pointer monitorSubscriber(new subscribers::Monitor(broker));
59
		//subscribers::CanNet::pointer canNetSubscriber(new subscribers::CanNet(broker, "192.168.1.250", 1100));
1310 runge 60
 
1326 runge 61
		LOG.info("Will now try to send a message...");
1310 runge 62
 
1326 runge 63
		message::Header header(0, "irTranceiver", "temperature");
1309 runge 64
 
1326 runge 65
		LOG.info("Header constructed...");
1309 runge 66
 
1326 runge 67
		message::Message::pointer message(new message::Message(header));
1309 runge 68
 
1326 runge 69
		LOG.info("Message constructed...");
1309 runge 70
 
1326 runge 71
		broker->put(message);
1309 runge 72
 
1326 runge 73
		sleep(10000000);
74
	}
75
	catch (Exception * e)
76
	{
77
		cout << "Exception: " << e->getDescription() << endl;
78
	}
79
 
80
 
81
 
82
 
1310 runge 83
	return 0;
1309 runge 84
	//udpSubscriber->write(utils::BitBuffer(startPacket));
85
 
86
 
87
	cout << "ABC123" << endl;
88
 
89
	return 0;
1310 runge 90
	/*sleep(1);
1309 runge 91
 
1310 runge 92
		messagebroker::Message message("");
1309 runge 93
 
94
 
1310 runge 95
		message.data = "test1";
96
		broker.put(message);
1309 runge 97
 
1310 runge 98
		message.setOrigin(monitorSubscriber);
99
		message.data = "test2";
100
		broker.put(message);
101
		sleep(1);
102
		delete monitorSubscriber;
1309 runge 103
 
1310 runge 104
		message.data = "test3";
105
		broker.put(message);
106
		sleep(1);
107
		delete udpSubscriber;
1309 runge 108
 
109
 
1310 runge 110
		try
111
		{
112
			// Declare a group of options that will be
113
			// allowed only on command line
114
			po::options_description generic("Generic options");
115
			generic.add_options()	("version,v", "print version string")
116
									("help", "produce help message");
1309 runge 117
 
1310 runge 118
			// Declare a group of options that will be
119
			// allowed both on command line and in
120
			// config file
121
			po::options_description config("Configuration");
122
			config.add_options()("optimization", po::value<int>()->default_value(10), "optimization level")
123
								("include-path,I", po::value<vector<string> >()->composing(), "include path");
1309 runge 124
 
1310 runge 125
			// Hidden options, will be allowed both on command line and
126
			// in config file, but will not be shown to the user.
127
			po::options_description hidden("Hidden options");
128
			hidden.add_options()("input-file", po::value<vector<string> >(), "input file");
1309 runge 129
 
1310 runge 130
			po::options_description cmdline_options;
131
			cmdline_options.add(generic).add(config).add(hidden);
1309 runge 132
 
1310 runge 133
			po::options_description config_file_options;
134
			config_file_options.add(config).add(hidden);
1309 runge 135
 
1310 runge 136
			po::options_description visible("Allowed options");
137
			visible.add(generic).add(config);
1309 runge 138
 
1310 runge 139
			po::positional_options_description p;
140
			p.add("input-file", -1);
1309 runge 141
 
1310 runge 142
			po::variables_map vm;
143
			store(po::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm);
1309 runge 144
 
1310 runge 145
			ifstream ifs("multiple_sources.cfg");
146
			store(parse_config_file(ifs, config_file_options), vm);
147
			notify(vm);
1309 runge 148
 
1310 runge 149
			if (vm.count("help"))
150
			{
151
				cout << visible << "\n";
152
				return 0;
153
			}
1309 runge 154
 
1310 runge 155
			if (vm.count("version"))
156
			{
157
				cout << "Multiple sources example, version 1.0\n";
158
				return 0;
159
			}
1309 runge 160
 
1310 runge 161
			if (vm.count("include-path"))
162
			{
163
				//cout << "Include paths are: " << vm["include-path"].as<vector<string>>() << "\n";
164
			}
1309 runge 165
 
1310 runge 166
			if (vm.count("input-file"))
167
			{
168
				//cout << "Input files are: " << vm["input-file"].as<vector<string>>() << "\n";
169
			}
1309 runge 170
 
1310 runge 171
			//cout << "Optimization level is " << opt << "\n";
1309 runge 172
 
1310 runge 173
	*/
174
	/*if (argc != 3)
175
	{
176
		std::cout << "Usage: async_client <server> <path>\n";
177
		std::cout << "Example:\n";
178
		std::cout << "  async_client www.boost.org /LICENSE_1_0.txt\n";
179
		return 1;
180
	}
1309 runge 181
 
1310 runge 182
	boost::asio::io_service io_service;
183
	client c(io_service, argv[1], argv[2]);
184
	io_service.run();*/
185
	/*
186
			 std::string hello( "Hello, world!" );
1309 runge 187
 
1310 runge 188
			foreach( char ch, hello )
189
			{
190
				std::cout << ch;
191
			}
192
 
193
		}
194
		catch (std::exception& e)
1309 runge 195
		{
1310 runge 196
			std::cout << "Exception: " << e.what() << "\n";
1309 runge 197
		}
1310 runge 198
	*/
1309 runge 199
	return 0;
200
}