Subversion Repositories HomeAutomation

Rev

Rev 1610 | Rev 1646 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1610 Rev 1642
Line 30... Line 30...
30
#include "broker/Manager.h"
30
#include "broker/Manager.h"
31
 
31
 
32
#include "Protocol.h"
32
#include "Protocol.h"
33
#include "Message.h"
33
#include "Message.h"
34
 
34
 
35
#include "type/Bitset.h"
35
#include "common/Bitset.h"
36
#include "type/common.h"
36
#include "common/common.h"
37
 
37
 
38
namespace atom {
38
namespace atom {
39
namespace can {
39
namespace can {
40
 
40
 
41
enum
41
enum
Line 52... Line 52...
52
       
52
       
53
    // Examples of address
53
    // Examples of address
54
    // udp:192.168.1.250:1100
54
    // udp:192.168.1.250:1100
55
    // serial:/dev/ttyUSB0:38400
55
    // serial:/dev/ttyUSB0:38400
56
   
56
   
57
    type::StringList parts;
57
    common::StringList parts;
58
    boost::algorithm::split(parts, address, boost::is_any_of(":"), boost::algorithm::token_compress_off);
58
    boost::algorithm::split(parts, address, boost::is_any_of(":"), boost::algorithm::token_compress_off);
59
   
59
   
60
    if (parts.size() < 3)
60
    if (parts.size() < 3)
61
    {
61
    {
62
        LOG.Error("Malformed address string: " + address);
62
        LOG.Error("Malformed address string: " + address);
Line 87... Line 87...
87
        this->client_id_ = net::Manager::Instance()->Connect(this->protocol_, this->address_, this->port_or_baud_);
87
        this->client_id_ = net::Manager::Instance()->Connect(this->protocol_, this->address_, this->port_or_baud_);
88
        LOG.Info("Connected to " + address);
88
        LOG.Info("Connected to " + address);
89
       
89
       
90
        LOG.Info("Sending ping...");
90
        LOG.Info("Sending ping...");
91
 
91
 
92
        type::Byteset buffer(1);
92
        common::Byteset buffer(1);
93
        buffer[0] = PACKET_PING;
93
        buffer[0] = PACKET_PING;
94
       
94
       
95
        net::Manager::Instance()->SendTo(this->client_id_, buffer);
95
        net::Manager::Instance()->SendTo(this->client_id_, buffer);
96
    }
96
    }
97
    catch (std::runtime_error& e)
97
    catch (std::runtime_error& e)
Line 116... Line 116...
116
void Network::SlotOnMessageHandler(broker::Message::Pointer message)
116
void Network::SlotOnMessageHandler(broker::Message::Pointer message)
117
{
117
{
118
    if (message->GetType() == broker::Message::CAN_MESSAGE)
118
    if (message->GetType() == broker::Message::CAN_MESSAGE)
119
    {
119
    {
120
        Message* payload = static_cast<Message*>(message->GetPayload().get());
120
        Message* payload = static_cast<Message*>(message->GetPayload().get());
121
        type::Byteset data(17);
121
        common::Byteset data(17);
122
       
122
       
123
        data[0] = PACKET_START;
123
        data[0] = PACKET_START;
124
       
124
       
125
        unsigned int class_id = Protocol::Instance()->ResolveClassId(payload->GetClassName());
125
        unsigned int class_id = Protocol::Instance()->ResolveClassId(payload->GetClassName());
126
        data[4] = class_id << 1;
126
        data[4] = class_id << 1;
Line 143... Line 143...
143
            unsigned int command_id = Protocol::Instance()->ResolveCommandId(payload->GetCommandName(), payload->GetModuleName());
143
            unsigned int command_id = Protocol::Instance()->ResolveCommandId(payload->GetCommandName(), payload->GetModuleName());
144
            data[1] = command_id;
144
            data[1] = command_id;
145
        }
145
        }
146
       
146
       
147
        unsigned int highest_bit = 0;
147
        unsigned int highest_bit = 0;
148
        type::Bitset databits(64);
148
        common::Bitset databits(64);
149
       
149
       
150
        xml::Node::NodeList variable_nodes;
150
        xml::Node::NodeList variable_nodes;
151
        unsigned int start_bit;
151
        unsigned int start_bit;
152
        unsigned int bit_length;
152
        unsigned int bit_length;
153
        std::string type;
153
        std::string type;
Line 230... Line 230...
230
        //LOG.Debug("Bytes: " + data.ToDebugString());
230
        //LOG.Debug("Bytes: " + data.ToDebugString());
231
        net::Manager::Instance()->SendTo(this->client_id_, data);
231
        net::Manager::Instance()->SendTo(this->client_id_, data);
232
    }
232
    }
233
}
233
}
234
 
234
 
235
void Network::SlotOnNewDataHandler(net::ClientId client_id, net::ServerId server_id, type::Byteset data)
235
void Network::SlotOnNewDataHandler(net::ClientId client_id, net::ServerId server_id, common::Byteset data)
236
{
236
{
237
    if (client_id != this->client_id_)
237
    if (client_id != this->client_id_)
238
    {
238
    {
239
            return;
239
            return;
240
    }
240
    }
Line 343... Line 343...
343
 
343
 
344
        Message* payload = new Message(class_name, direction_name, module_name, id, command_name);
344
        Message* payload = new Message(class_name, direction_name, module_name, id, command_name);
345
 
345
 
346
        unsigned int length = this->buffer_[6];
346
        unsigned int length = this->buffer_[6];
347
       
347
       
348
        type::Byteset data_set(length);
348
        common::Byteset data_set(length);
349
       
349
       
350
        for (unsigned int n = 0; n < length; n++)
350
        for (unsigned int n = 0; n < length; n++)
351
        {
351
        {
352
            data_set.Append(this->buffer_[n + 7]);
352
            data_set.Append(this->buffer_[n + 7]);
353
        }
353
        }
354
 
354
 
355
        type::Bitset databits(data_set);
355
        common::Bitset databits(data_set);
356
        xml::Node::NodeList variable_nodes;
356
        xml::Node::NodeList variable_nodes;
357
        unsigned int start_bit;
357
        unsigned int start_bit;
358
        int bit_length;
358
        int bit_length;
359
        std::string type;
359
        std::string type;
360
        std::string value;
360
        std::string value;