Subversion Repositories HomeAutomation

Rev

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

Rev 2124 Rev 2266
Line 380... Line 380...
380
    return boost::lexical_cast<std::string>(float_value);
380
    return boost::lexical_cast<std::string>(float_value);
381
}
381
}
382
 
382
 
383
void Protocol::EncodeFloat(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value)
383
void Protocol::EncodeFloat(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value)
384
{
384
{
-
 
385
    long int_value = boost::lexical_cast<float>(value) * 64.0f;
-
 
386
    //LOG.Info("Float: " + int_value);
-
 
387
 
-
 
388
    this->EncodeInt(bitset, start_bit, bit_length, boost::lexical_cast<std::string>(int_value));
-
 
389
}
-
 
390
 
-
 
391
std::string Protocol::DecodeIEEE32(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length)
-
 
392
{
-
 
393
    if (bit_length != 32)
-
 
394
    {
-
 
395
      return 0;
-
 
396
    }
-
 
397
    uint64_t result = bitset.Read(start_bit, bit_length);
-
 
398
    LOG.Info("uint32_t: " + boost::lexical_cast<std::string>((uint64_t)result));
-
 
399
    uint32_t result2 = result & 0xFFFFFFFF;
-
 
400
    float *ptr;
-
 
401
    ptr = (float*)&result2;
-
 
402
    float float_value = *ptr;
-
 
403
    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);
-
 
411
}
-
 
412
 
-
 
413
void Protocol::EncodeIEEE32(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value)
-
 
414
{
-
 
415
    if (bit_length != 32)
-
 
416
    {
-
 
417
      return;
-
 
418
    }
385
    long int_value = boost::lexical_cast<float>(value) * 64.0f;
419
    long int_value = boost::lexical_cast<float>(value) * 64.0f;
386
    //LOG.Info("Float: " + int_value);
420
    //LOG.Info("Float: " + int_value);
387
 
421
 
388
    this->EncodeInt(bitset, start_bit, bit_length, boost::lexical_cast<std::string>(int_value));
422
    this->EncodeInt(bitset, start_bit, bit_length, boost::lexical_cast<std::string>(int_value));
389
}
423
}