Subversion Repositories HomeAutomation

Rev

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