Subversion Repositories HomeAutomation

Rev

Rev 1319 | 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. // public boost::signals::trackable,
  30. class CanNet : public Subscriber
  31. {
  32. public:
  33.     typedef boost::shared_ptr<CanNet> Pointer;
  34.  
  35.     CanNet(std::string address, unsigned int port);
  36.     virtual ~CanNet();
  37.  
  38. private:
  39.     log::Logger LOG;
  40.  
  41.     void OnMessage(Message::Pointer message);
  42.     void Slot_OnNewData(const udp::endpoint &sender, const ByteList &bytes);
  43.  
  44.     ByteList BuildPacket(unsigned int id, ByteList data);
  45.     void ProcessBuffer();
  46.     void SendPing();
  47.  
  48.     enum
  49.     {
  50.         PACKET_START = 253, PACKET_END = 250, PACKET_PING = 251
  51.     };
  52.  
  53.     net::UdpServer::pointer udp_server_;
  54.     boost::asio::ip::udp::endpoint endpoint_;
  55.  
  56.     // TODO Add mutex lock for access to the buffer or are we safe?
  57.     ByteList buffer_;
  58. };
  59.  
  60. } // namespace subscribers
  61. } // namespace atom
  62.  
  63. #endif /* CANNET_H_ */
  64.