Rev 1608 | Rev 1642 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1608 | Rev 1610 | ||
|---|---|---|---|
| Line 172... | Line 172... | ||
| 172 | } |
172 | } |
| 173 | 173 | ||
| 174 | start_bit = boost::lexical_cast<unsigned int>(variable_nodes[n].GetAttributeValue("start_bit")); |
174 | start_bit = boost::lexical_cast<unsigned int>(variable_nodes[n].GetAttributeValue("start_bit")); |
| 175 | bit_length = boost::lexical_cast<unsigned int>(variable_nodes[n].GetAttributeValue("bit_length")); |
175 | bit_length = boost::lexical_cast<unsigned int>(variable_nodes[n].GetAttributeValue("bit_length")); |
| 176 | type = variable_nodes[n].GetAttributeValue("type"); |
176 | type = variable_nodes[n].GetAttributeValue("type"); |
| 177 | - | ||
| 178 | if (highest_bit < start_bit + bit_length - 1) |
- | |
| 179 | { |
- | |
| 180 | highest_bit = start_bit + bit_length - 1; |
- | |
| 181 | } |
- | |
| 182 | 177 | ||
| 183 | if (type == "int") |
178 | if (type == "int") |
| 184 | { |
179 | { |
| 185 | Protocol::Instance()->EncodeInt(databits, start_bit, bit_length, value); |
180 | Protocol::Instance()->EncodeInt(databits, start_bit, bit_length, value); |
| 186 | } |
181 | } |
| 187 | else if (type == "float") |
182 | else if (type == "float") |
| 188 | { |
183 | { |
| 189 | Protocol::Instance()->EncodeFloat(databits, start_bit, bit_length, value); |
184 | Protocol::Instance()->EncodeFloat(databits, start_bit, bit_length, value); |
| 190 | } |
185 | } |
| 191 | else if (type == "ascii") |
186 | else if (type == "ascii") |
| 192 | { |
187 | { |
| 193 | Protocol::Instance()->EncodeAscii(databits, start_bit, bit_length, value); |
188 | Protocol::Instance()->EncodeAscii(databits, start_bit, bit_length, value); |
| - | 189 | bit_length = value.length() * 8; |
|
| 194 | } |
190 | } |
| 195 | else if (type == "hexstring") |
191 | else if (type == "hexstring") |
| 196 | { |
192 | { |
| 197 | Protocol::Instance()->EncodeHexstring(databits, start_bit, bit_length, value); |
193 | Protocol::Instance()->EncodeHexstring(databits, start_bit, bit_length, value); |
| - | 194 | bit_length = value.length() * 4; |
|
| 198 | } |
195 | } |
| 199 | else if (type == "enum") |
196 | else if (type == "enum") |
| 200 | { |
197 | { |
| 201 | value = variable_nodes[n].SelectChild("name", value).GetAttributeValue("id"); |
198 | value = variable_nodes[n].SelectChild("name", value).GetAttributeValue("id"); |
| 202 | Protocol::Instance()->EncodeUint(databits, start_bit, bit_length, value); |
199 | Protocol::Instance()->EncodeUint(databits, start_bit, bit_length, value); |
| 203 | } |
200 | } |
| 204 | else// if (type == "uint") |
201 | else// if (type == "uint") |
| - | 202 | { |
|
| - | 203 | Protocol::Instance()->EncodeUint(databits, start_bit, bit_length, value); |
|
| - | 204 | } |
|
| - | 205 | ||
| - | 206 | if (highest_bit < start_bit + bit_length - 1) |
|
| 205 | { |
207 | { |
| 206 |
|
208 | highest_bit = start_bit + bit_length - 1; |
| 207 | } |
209 | } |
| 208 | } |
210 | } |
| 209 | 211 | ||
| 210 | //LOG.Debug(databits.ToDebugString()); |
212 | //LOG.Debug(databits.ToDebugString()); |
| 211 | 213 | ||
| Line 377... | Line 379... | ||
| 377 | { |
379 | { |
| 378 | bit_length = databits.GetCount() - start_bit; |
380 | bit_length = databits.GetCount() - start_bit; |
| 379 | 381 | ||
| 380 | if (bit_length <= 0) |
382 | if (bit_length <= 0) |
| 381 | { |
383 | { |
| 382 | LOG.Warning("Can not read variable " + name + " for command " + command_name + ", message is to short, |
384 | LOG.Warning("Can not read variable " + name + " for command " + command_name + ", message is to short, is there a match between the module and the protocol XML file?"); |
| 383 | //LOG.Debug("start_bit=" + boost::lexical_cast<std::string>(start_bit) + ", bit_length=" + boost::lexical_cast<std::string>(bit_length) + ", databits.GetCount()=" + boost::lexical_cast<std::string>(databits.GetCount())); |
385 | //LOG.Debug("start_bit=" + boost::lexical_cast<std::string>(start_bit) + ", bit_length=" + boost::lexical_cast<std::string>(bit_length) + ", databits.GetCount()=" + boost::lexical_cast<std::string>(databits.GetCount())); |
| 384 | continue; |
386 | continue; |
| 385 | } |
387 | } |
| 386 | } |
388 | } |
| 387 | 389 | ||