Subversion Repositories HomeAutomation

Rev

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

Rev 1323 Rev 1326
Line 12... Line 12...
12
namespace atom {
12
namespace atom {
13
namespace message {
13
namespace message {
14
 
14
 
15
Header::Header()
15
Header::Header()
16
{
16
{
-
 
17
    LOG.setName("Header");
-
 
18
    this->loadVariables();
17
}
19
}
18
 
20
 
19
Header::Header(BitBuffer & buffer)
21
Header::Header(BitBuffer & buffer)
20
{
22
{
-
 
23
    LOG.setName("Header");
-
 
24
    this->loadVariables();
21
    this->readBits(buffer);
25
    this->readBits(buffer);
22
}
26
}
23
 
27
 
24
Header::Header(unsigned long moduleId, string moduleType, string messageType)
28
Header::Header(unsigned long moduleId, string moduleType, string messageType)
25
{
29
{
-
 
30
    LOG.setName("Header");
-
 
31
 
-
 
32
    LOG.debug("Start of constructor...");
-
 
33
 
-
 
34
    this->loadVariables();
-
 
35
 
-
 
36
    LOG.debug("Done loading variables...");
-
 
37
 
26
    if (types::UnsignedInteger *moduleIdDatatype = dynamic_cast<types::UnsignedInteger *>(this->myVariables["moduleId"].getDatatype().get()))
38
    if (types::UnsignedInteger *moduleIdDatatype = dynamic_cast<types::UnsignedInteger *>(this->myVariables["moduleId"].getDatatype().get()))
27
    {
39
    {
28
        moduleIdDatatype->setValue(moduleId);
40
        moduleIdDatatype->setValue(moduleId);
29
    }
41
    }
30
    else
42
    else
31
    {
43
    {
32
        // TODO throw exception
44
        throw new Exception("moduleId is not of the type \"unsigned integer\", this is a fatal error, correct the protocol specification");
33
    }
45
    }
-
 
46
 
-
 
47
    LOG.debug("checkpoint 1...");
34
 
48
 
35
    if (types::UnsignedInteger *moduleTypeDatatype = dynamic_cast<types::UnsignedInteger *>(this->myVariables["moduleType"].getDatatype().get()))
49
    if (types::UnsignedInteger *moduleTypeDatatype = dynamic_cast<types::UnsignedInteger *>(this->myVariables["moduleType"].getDatatype().get()))
36
    {
50
    {
37
        unsigned long moduleTypeId;
-
 
38
 
-
 
39
        // TODO convert moduleType to moduleTypeId
51
        unsigned long moduleTypeId = convert::string2uint(Protocol::getInstance()->getRootCacheNode().selectFirst("module", xml::Node::attributePair("name", moduleType))["id"]);
40
 
52
 
41
        moduleTypeDatatype->setValue(moduleTypeId);
53
        moduleTypeDatatype->setValue(moduleTypeId);
42
    }
54
    }
43
    else
55
    else
44
    {
56
    {
45
        // TODO throw exception
57
        throw new Exception("moduletype is not of the type \"unsigned integer\", this is a fatal error, correct the protocol specification");
46
    }
58
    }
-
 
59
 
-
 
60
    LOG.debug("checkpoint 2...");
47
 
61
 
48
    if (types::UnsignedInteger *messageTypeDatatype = dynamic_cast<types::UnsignedInteger *>(this->myVariables["messageType"].getDatatype().get()))
62
    if (types::UnsignedInteger *messageTypeDatatype = dynamic_cast<types::UnsignedInteger *>(this->myVariables["messageType"].getDatatype().get()))
49
    {
63
    {
50
        unsigned long messageTypeId;
-
 
51
 
-
 
52
        // TODO convert messageType to messageTypeId
64
        unsigned long messageTypeId = convert::string2uint(Protocol::getInstance()->getRootCacheNode().selectFirst("messagetype", xml::Node::attributePair("name", messageType))["id"]);
53
 
65
 
54
        messageTypeDatatype->setValue(messageTypeId);
66
        messageTypeDatatype->setValue(messageTypeId);
55
    }
67
    }
56
    else
68
    else
57
    {
69
    {
58
        // TODO throw exception
70
        throw new Exception("messageType is not of the type \"unsigned integer\", this is a fatal error, correct the protocol specification");
59
    }
71
    }
-
 
72
 
-
 
73
    LOG.debug("End of contructor...");
60
}
74
}
61
 
75
 
62
Header::~Header()
76
Header::~Header()
63
{
77
{
64
}
78
}
Line 79... Line 93...
79
unsigned long Header::getModuleId()
93
unsigned long Header::getModuleId()
80
{
94
{
81
    if (types::UnsignedInteger *moduleIdDatatype = dynamic_cast<types::UnsignedInteger *>(this->myVariables["moduleId"].getDatatype().get()))
95
    if (types::UnsignedInteger *moduleIdDatatype = dynamic_cast<types::UnsignedInteger *>(this->myVariables["moduleId"].getDatatype().get()))
82
    {
96
    {
83
        return moduleIdDatatype->getValue();
97
        return moduleIdDatatype->getValue();
84
    }
98
    }
85
    else
-
 
86
    {
99
 
87
        // TODO throw exception
100
    throw new Exception("moduleIdDatatype is not of the type \"unsigned integer\", this is a fatal error, correct the protocol specification");
88
    }
-
 
89
}
101
}
90
 
102
 
91
string Header::getModuleType()
103
string Header::getModuleType()
92
{
104
{
93
    if (types::UnsignedInteger *moduleTypeDatatype = dynamic_cast<types::UnsignedInteger *>(this->myVariables["moduleType"].getDatatype().get()))
105
    if (types::UnsignedInteger *moduleTypeDatatype = dynamic_cast<types::UnsignedInteger *>(this->myVariables["moduleType"].getDatatype().get()))
94
    {
106
    {
95
        unsigned long moduleTypeId = moduleTypeDatatype->getValue();
107
        unsigned long moduleTypeId = moduleTypeDatatype->getValue();
96
 
108
 
97
        string moduleType;
-
 
98
 
-
 
99
        // TODO convert moduleTypeId to moduleType
109
        string moduleType = Protocol::getInstance()->getRootCacheNode().selectFirst("module", xml::Node::attributePair("id", convert::uint2string(moduleTypeId)))["name"];
100
 
110
 
101
        return moduleType;
111
        return moduleType;
102
    }
112
    }
103
    else
-
 
104
    {
113
 
105
        // TODO throw exception
114
    throw new Exception("moduleType is not of the type \"unsigned integer\", this is a fatal error, correct the protocol specification");
106
    }
-
 
107
}
115
}
108
 
116
 
109
string Header::getMessageType()
117
string Header::getMessageType()
110
{
118
{
111
    if (types::UnsignedInteger *messageTypeDatatype = dynamic_cast<types::UnsignedInteger *>(this->myVariables["messageType"].getDatatype().get()))
119
    if (types::UnsignedInteger *messageTypeDatatype = dynamic_cast<types::UnsignedInteger *>(this->myVariables["messageType"].getDatatype().get()))
112
    {
120
    {
113
        unsigned long messageTypeId = messageTypeDatatype->getValue();
121
        unsigned long messageTypeId = messageTypeDatatype->getValue();
114
 
122
 
115
        string messageType;
-
 
116
 
-
 
117
        // TODO convert messageTypeId to messageType
123
        string messageType = Protocol::getInstance()->getRootCacheNode().selectFirst("messagetype", xml::Node::attributePair("id", convert::uint2string(messageTypeId)))["name"];
118
 
124
 
119
        return messageType;
125
        return messageType;
120
    }
126
    }
121
    else
-
 
122
    {
127
 
123
        // TODO throw exception
128
    throw new Exception("messageType is not of the type \"unsigned integer\", this is a fatal error, correct the protocol specification");
124
    }
-
 
125
}
129
}
126
 
130
 
127
void Header::readBits(BitBuffer & buffer)
131
void Header::readBits(BitBuffer & buffer)
128
{
132
{
129
    // Header is only 29 bits but our buffer is whole bytes, padded in front
133
    // Header is only 29 bits but our buffer is whole bytes, padded in front
130
    buffer.incrementPointer(3); // Increment 3 bits
134
    buffer.incrementPointer(3); // Increment 3 bits
131
 
135
 
132
    for (variableMap::iterator iter = this->myVariables.begin(); iter != this->myVariables.end(); iter++)
136
    for (variableMap::iterator iter = this->myVariables.begin(); iter != this->myVariables.end(); iter++)
133
    {
137
    {
134
        iter->second.readBits(buffer);
138
        iter->second.readBits(buffer);
135
    }
139
    }
136
}
140
}
137
 
141
 
138
void Header::writeBits(BitBuffer & buffer)
142
void Header::writeBits(BitBuffer & buffer)
139
{
143
{
140
    // Header is only 29 bits but our buffer is whole bytes, padded in front
144
    // Header is only 29 bits but our buffer is whole bytes, padded in front
141
    buffer.writeBasicType(3, (long) 0); // Write 3 bits
145
    buffer.write(3, (long) 0); // Write 3 bits
-
 
146
 
-
 
147
    for (variableMap::iterator iter = this->myVariables.begin(); iter != this->myVariables.end(); iter++)
-
 
148
    {
-
 
149
        iter->second.writeBits(buffer);
-
 
150
    }
-
 
151
}
-
 
152
 
-
 
153
string Header::toString()
-
 
154
{
-
 
155
    string buffer = "Header(";
142
 
156
 
143
    for (variableMap::iterator iter = this->myVariables.begin(); iter != this->myVariables.end(); iter++)
157
    for (variableMap::iterator iter = this->myVariables.begin(); iter != this->myVariables.end(); iter++)
144
    {
158
    {
145
        iter->second.writeBits(buffer);
159
        buffer += iter->second.toString() + ",";
146
    }
160
    }
-
 
161
 
-
 
162
    trim_if(buffer, is_any_of(","));
-
 
163
 
-
 
164
    buffer += ")";
-
 
165
 
-
 
166
    return buffer;
147
}
167
}
148
 
168
 
149
}
169
}
150
}
170
}