Subversion Repositories HomeAutomation

Rev

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

Rev 1689 Rev 1766
Line 325... Line 325...
325
 
325
 
326
void Protocol::EncodeInt(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value)
326
void Protocol::EncodeInt(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value)
327
{
327
{
328
    unsigned long raw_bit_value = 0;
328
    unsigned long raw_bit_value = 0;
329
    int raw_value = boost::lexical_cast<int>(value);
329
    int raw_value = boost::lexical_cast<int>(value);
-
 
330
    //LOG.Info("Float as int: " + raw_value);
330
   
331
 
331
    raw_bit_value = raw_bit_value;
332
    raw_bit_value = raw_value;
332
   
333
   
333
    if (raw_value < 0)
334
    if (raw_value < 0)
334
    {
335
    {
335
        long mask = 0;
336
        long mask = 0;
336
       
337
       
Line 362... Line 363...
362
}
363
}
363
 
364
 
364
std::string Protocol::DecodeFloat(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length)
365
std::string Protocol::DecodeFloat(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length)
365
{
366
{
366
    float float_value = boost::lexical_cast<float>(this->DecodeInt(bitset, start_bit, bit_length));
367
    float float_value = boost::lexical_cast<float>(this->DecodeInt(bitset, start_bit, bit_length));
367
    LOG.Debug("DecodeFloat::float_value1=" + boost::lexical_cast<std::string>(float_value));
368
    //LOG.Debug("DecodeFloat::float_value1=" + boost::lexical_cast<std::string>(float_value));
368
   
369
   
369
   
370
   
370
    float_value = float_value / 64.0f;
371
    float_value = float_value / 64.0f;
371
   
372
   
372
    LOG.Debug("DecodeFloat::float_value2=" + boost::lexical_cast<std::string>(float_value));
373
    //LOG.Debug("DecodeFloat::float_value2=" + boost::lexical_cast<std::string>(float_value));
373
   
374
   
374
    return boost::lexical_cast<std::string>(float_value);
375
    return boost::lexical_cast<std::string>(float_value);
375
}
376
}
376
 
377
 
377
void Protocol::EncodeFloat(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value)
378
void Protocol::EncodeFloat(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value)
378
{
379
{
379
    int int_value = boost::lexical_cast<float>(value) * 64.0f;
380
    int int_value = boost::lexical_cast<float>(value) * 64.0f;
-
 
381
    //LOG.Info("Float: " + int_value);
380
   
382
 
381
    this->EncodeInt(bitset, start_bit, bit_length, boost::lexical_cast<std::string>(int_value));
383
    this->EncodeInt(bitset, start_bit, bit_length, boost::lexical_cast<std::string>(int_value));
382
}
384
}
383
 
385
 
384
std::string Protocol::DecodeAscii(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length)
386
std::string Protocol::DecodeAscii(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length)