Subversion Repositories HomeAutomation

Rev

Rev 1319 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
1309 runge 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
 
1311 runge 11
#include <boost/make_shared.hpp>
12
#include <boost/bind.hpp>
13
#include <boost/signal.hpp>
1317 runge 14
#include <boost/asio.hpp>
1311 runge 15
#include <string>
1310 runge 16
#include "broker/Subscriber.h"
17
#include "broker/Broker.h"
18
#include "message/Message.h"
19
#include "message/Header.h"
1319 runge 20
#include "message/BitBuffer.h"
1317 runge 21
#include "net/UdpServer.h"
1315 runge 22
#include "log/Logger.h"
1314 runge 23
#include "utils/convert.h"
1310 runge 24
#include "types.h"
1309 runge 25
 
26
namespace atom {
27
namespace subscribers {
28
 
29
// public boost::signals::trackable,
30
class CanNet : public Subscriber
31
{
32
public:
1403 runge 33
    typedef boost::shared_ptr<CanNet> Pointer;
1309 runge 34
 
1403 runge 35
    CanNet(std::string address, unsigned int port);
1309 runge 36
    virtual ~CanNet();
37
 
1403 runge 38
private:
39
    log::Logger LOG;
1309 runge 40
 
1403 runge 41
    void OnMessage(Message::Pointer message);
42
    void Slot_OnNewData(const udp::endpoint &sender, const ByteList &bytes);
1309 runge 43
 
1403 runge 44
    ByteList BuildPacket(unsigned int id, ByteList data);
45
    void ProcessBuffer();
46
    void SendPing();
47
 
1309 runge 48
    enum
49
    {
50
        PACKET_START = 253, PACKET_END = 250, PACKET_PING = 251
51
    };
52
 
1403 runge 53
    net::UdpServer::pointer udp_server_;
54
    boost::asio::ip::udp::endpoint endpoint_;
55
 
1309 runge 56
    // TODO Add mutex lock for access to the buffer or are we safe?
1403 runge 57
    ByteList buffer_;
1309 runge 58
};
59
 
1403 runge 60
} // namespace subscribers
61
} // namespace atom
1309 runge 62
 
63
#endif /* CANNET_H_ */