Subversion Repositories HomeAutomation

Rev

Rev 1310 | Blame | Last modification | View Log | SVN | RSS feed

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