Subversion Repositories HomeAutomation

Rev

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