Subversion Repositories HomeAutomation

Rev

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