Subversion Repositories HomeAutomation

Rev

Rev 1317 | 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 "message/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 message;
  31. using namespace std;
  32. using boost::asio::ip::udp;
  33.  
  34. // public boost::signals::trackable,
  35. class CanNet : public Subscriber
  36. {
  37. public:
  38.     typedef boost::shared_ptr<CanNet> pointer;
  39.  
  40.     CanNet(Broker::pointer broker, string address, unsigned int port);
  41.     virtual ~CanNet();
  42.  
  43. protected:
  44.     void onNewMessage(Message::pointer message);
  45.     void onNewData(const udp::endpoint & sender, const byte_list & bytes);
  46.  
  47.     byte_list buildPacket(unsigned int id, byte_list data);
  48.     void processBuffer();
  49.     void sendPing();
  50.  
  51.     enum
  52.     {
  53.         PACKET_START = 253, PACKET_END = 250, PACKET_PING = 251
  54.     };
  55.  
  56.     net::UdpServer::pointer myUdpServer;
  57.     udp::endpoint myEndpoint;
  58.     // TODO Add mutex lock for access to the buffer or are we safe?
  59.     byte_list myBuffer;
  60.  
  61. private:
  62.     log::Logger LOG;
  63. };
  64.  
  65. }
  66. }
  67.  
  68. #endif /* CANNET_H_ */
  69.