Rev 2266 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 2266 | Rev 2267 | ||
|---|---|---|---|
| Line 359... | Line 359... | ||
| 359 | return boost::lexical_cast<std::string>((uint64_t)raw_bit_value); |
359 | return boost::lexical_cast<std::string>((uint64_t)raw_bit_value); |
| 360 | } |
360 | } |
| 361 | 361 | ||
| 362 | void Protocol::EncodeUint(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value) |
362 | void Protocol::EncodeUint(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value) |
| 363 | { |
363 | { |
| 364 | LOG. |
364 | //LOG.Debug("start_bit:" + boost::lexical_cast<std::string>(start_bit) + ", bit_lengt:" + boost::lexical_cast<std::string>(bit_length) + ", value:\"" + value + "\""); |
| 365 | uint64_t raw_bit_value = boost::lexical_cast<uint64_t>(value); |
365 | uint64_t raw_bit_value = boost::lexical_cast<uint64_t>(value); |
| 366 | 366 | ||
| 367 | bitset.Write(start_bit, bit_length, raw_bit_value); |
367 | bitset.Write(start_bit, bit_length, raw_bit_value); |
| 368 | } |
368 | } |
| 369 | 369 | ||
| Line 388... | Line 388... | ||
| 388 | this->EncodeInt(bitset, start_bit, bit_length, boost::lexical_cast<std::string>(int_value)); |
388 | this->EncodeInt(bitset, start_bit, bit_length, boost::lexical_cast<std::string>(int_value)); |
| 389 | } |
389 | } |
| 390 | 390 | ||
| 391 | std::string Protocol::DecodeIEEE32(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length) |
391 | std::string Protocol::DecodeIEEE32(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length) |
| 392 | { |
392 | { |
| 393 | if (bit_length != 32) |
393 | if (bit_length != 32) { return 0; } |
| - | 394 | uint32_t result = bitset.Read(start_bit, bit_length); |
|
| - | 395 | //LOG.Info("uint32_t: " + boost::lexical_cast<std::string>((uint32_t)result)); |
|
| 394 |
|
396 | |
| - | 397 | uint32_t result2 = (0xFF000000 & result) >> 24; |
|
| 395 |
|
398 | result2 += (0x00FF0000 & result) >> 8; |
| 396 | |
399 | result2 += (0x0000FF00 & result) << 8; |
| 397 |
|
400 | result2 += (0x000000FF & result) << 24; |
| 398 | LOG. |
401 | //LOG.Info("uint32_t: " + boost::lexical_cast<std::string>((uint32_t)result2)); |
| 399 | uint32_t result2 = result & 0xFFFFFFFF; |
- | |
| 400 | float *ptr; |
402 | float *ptr; |
| 401 | ptr = (float*)&result2; |
403 | ptr = (float*)&result2; |
| 402 | float float_value = *ptr; |
404 | float float_value = *ptr; |
| 403 | LOG. |
405 | //LOG.Info("float: " + boost::lexical_cast<std::string>(float_value)); |
| 404 | //LOG.Debug("DecodeFloat::float_value1=" + boost::lexical_cast<std::string>(float_value));; |
- | |
| 405 | - | ||
| 406 | //LOG.Debug("DecodeFloat::float_value2=" + boost::lexical_cast<std::string>(float_value)); |
- | |
| 407 | float_value = boost::lexical_cast<float>(this->DecodeInt(bitset, start_bit, bit_length)); |
- | |
| 408 | LOG.Info("float: " + boost::lexical_cast<std::string>(float_value)); |
- | |
| 409 | - | ||
| 410 | return boost::lexical_cast<std::string>(float_value); |
406 | return boost::lexical_cast<std::string>(float_value); |
| 411 | } |
407 | } |
| 412 | 408 | ||
| 413 | void Protocol::EncodeIEEE32(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value) |
409 | void Protocol::EncodeIEEE32(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value) |
| 414 | { |
410 | { |
| 415 | if (bit_length != 32) |
411 | if (bit_length != 32) { return; } |
| 416 | { |
- | |
| 417 | return; |
- | |
| 418 | } |
- | |
| 419 |
|
412 | float float_value = boost::lexical_cast<float>(value); |
| 420 | //LOG.Info("Float: " + int_value); |
413 | //LOG.Info("Float: " + int_value); |
| - | 414 | uint32_t *ptr; |
|
| - | 415 | ptr = (uint32_t*)&float_value; |
|
| - | 416 | uint32_t result = *ptr; |
|
| - | 417 | uint32_t raw_bit_value = (0xFF000000 & result) >> 24; |
|
| - | 418 | raw_bit_value += (0x00FF0000 & result) >> 8; |
|
| - | 419 | raw_bit_value += (0x0000FF00 & result) << 8; |
|
| 421 | - | ||
| - | 420 | raw_bit_value += (0x000000FF & result) << 24; |
|
| 422 |
|
421 | bitset.Write(start_bit, bit_length, raw_bit_value); |
| 423 | } |
422 | } |
| 424 | 423 | ||
| 425 | std::string Protocol::DecodeAscii(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length) |
424 | std::string Protocol::DecodeAscii(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length) |
| 426 | { |
425 | { |
| 427 | std::string value; |
426 | std::string value; |