Subversion Repositories HomeAutomation

Rev

Rev 1319 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

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