Subversion Repositories HomeAutomation

Rev

Rev 1315 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /*
  2.  * CanNet.h
  3.  *
  4.  *  Created on: Apr 27, 2009
  5.  *      Author: Mattias Runge
  6.  */
  7.  
  8. #ifndef CANNET_H_
  9. #define CANNET_H_
  10.  
  11. #include <boost/make_shared.hpp>
  12. #include <boost/bind.hpp>
  13. #include <boost/signal.hpp>
  14. #include <boost/asio.hpp>
  15. #include <string>
  16. #include "broker/Subscriber.h"
  17. #include "broker/Broker.h"
  18. #include "message/Message.h"
  19. #include "message/Header.h"
  20. #include "utils/BitBuffer.h"
  21. #include "net/UdpServer.h"
  22. #include "log/Logger.h"
  23. #include "utils/convert.h"
  24. #include "types.h"
  25.  
  26. namespace atom {
  27. namespace subscribers {
  28.  
  29. using namespace broker;
  30. using namespace utils;
  31. using namespace message;
  32. using namespace std;
  33. using boost::asio::ip::udp;
  34.  
  35. // public boost::signals::trackable,
  36. class CanNet : public Subscriber
  37. {
  38. public:
  39.     typedef boost::shared_ptr<CanNet> pointer;
  40.  
  41.     CanNet(Broker::pointer broker, string address, unsigned int port);
  42.     virtual ~CanNet();
  43.  
  44. protected:
  45.     void onNewMessage(Message::pointer message);
  46.     void onNewData(const udp::endpoint & sender, const byte_list & bytes);
  47.  
  48.     byte_list buildPacket(unsigned int id, byte_list data);
  49.     void processBuffer();
  50.     void sendPing();
  51.  
  52.     enum
  53.     {
  54.         PACKET_START = 253, PACKET_END = 250, PACKET_PING = 251
  55.     };
  56.  
  57.     net::UdpServer::pointer myUdpServer;
  58.     udp::endpoint myEndpoint;
  59.     // TODO Add mutex lock for access to the buffer or are we safe?
  60.     byte_list myBuffer;
  61.  
  62. private:
  63.     log::Logger LOG;
  64. };
  65.  
  66. }
  67. }
  68.  
  69. #endif /* CANNET_H_ */
  70.