Subversion Repositories HomeAutomation

Rev

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

Rev 1999 Rev 2066
Line 296... Line 296...
296
 
296
 
297
  static bool have_start = false;
297
  static bool have_start = false;
298
 
298
 
299
  for (unsigned int n = 0; n < data.size(); n++)
299
  for (unsigned int n = 0; n < data.size(); n++)
300
  {
300
  {
301
    log::Debug(log_module_, "data[%u] = %u, have_start = %s, this->buffer_.size() = %u", n, (unsigned int)data[n], have_start ? "true" : "false", this->buffer_.size());
301
    log::Extreme(log_module_, "data[%u] = %u, have_start = %s, this->buffer_.size() = %u", n, (unsigned int)data[n], have_start ? "true" : "false", this->buffer_.size());
302
   
302
   
303
    if (have_start)
303
    if (have_start)
304
    {
304
    {
305
      if (data[n] == PACKET_END)
305
      if (data[n] == PACKET_END)
306
      {
306
      {
307
        log::Debug(log_module_, "PACKET_END");
307
        log::Extreme(log_module_, "PACKET_END");
308
       
308
       
309
        while (this->buffer_.size() < 15)
309
        while (this->buffer_.size() < 15)
310
        {
310
        {
311
          this->buffer_.push_back(0);
311
          this->buffer_.push_back(0);
312
        }
312
        }
313
       
313
       
314
        for (unsigned int k = 0; k < this->buffer_.size(); k++)
314
        for (unsigned int k = 0; k < this->buffer_.size(); k++)
315
        {
315
        {
316
          log::Debug(log_module_, "this->buffer_[%u]=%u", k, (unsigned int)this->buffer_[k]);
316
          log::Extreme(log_module_, "this->buffer_[%u]=%u", k, (unsigned int)this->buffer_[k]);
317
        }
317
        }
318
       
318
       
319
        this->ProcessBuffer();
319
        this->ProcessBuffer();
320
       
320
       
321
        have_start = false;
321
        have_start = false;
Line 325... Line 325...
325
        this->buffer_.push_back(data[n]);
325
        this->buffer_.push_back(data[n]);
326
      }
326
      }
327
    }
327
    }
328
    else if (data[n] == PACKET_START)
328
    else if (data[n] == PACKET_START)
329
    {
329
    {
330
      log::Debug(log_module_, "PACKET_START");
330
      log::Extreme(log_module_, "PACKET_START");
331
     
331
     
332
      common::Byteset empty_vector;
332
      common::Byteset empty_vector;
333
      this->buffer_.swap(empty_vector);
333
      this->buffer_.swap(empty_vector);
334
 
334
 
335
      have_start = true;
335
      have_start = true;
Line 410... Line 410...
410
        PKTstring += " " + atom::common::ToHex8bit((unsigned int)this->buffer_[index]) ;
410
        PKTstring += " " + atom::common::ToHex8bit((unsigned int)this->buffer_[index]) ;
411
    }
411
    }
412
   
412
   
413
    PKTstring += "\n";
413
    PKTstring += "\n";
414
   
414
   
415
    LOG.Debug(PKTstring);
415
    LOG.Extreme(PKTstring);
416
   
416
   
417
  for (unsigned int n = 0; n < this->buffer_.size(); n++)
417
  for (unsigned int n = 0; n < this->buffer_.size(); n++)
418
  {
418
  {
419
     log::Debug(log_module_, "this->buffer_[%u]=%u", n, (unsigned int)this->buffer_[n]);
419
     log::Extreme(log_module_, "this->buffer_[%u]=%u", n, (unsigned int)this->buffer_[n]);
420
  }
420
  }
421
 
421
 
422
    std::string* payload_str = new std::string(PKTstring);
422
    std::string* payload_str = new std::string(PKTstring);
423
    broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_RAW_MESSAGE, broker::Message::PayloadPointer(payload_str), this)));
423
    broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_RAW_MESSAGE, broker::Message::PayloadPointer(payload_str), this)));
424
 
424
 
425
   
425
   
426
        unsigned int class_id = (this->buffer_[3] >> 1) & 0x0F;
426
        unsigned int class_id = (this->buffer_[3] >> 1) & 0x0F;
427
        LOG.Debug("class_id=" + boost::lexical_cast<std::string>(class_id));
427
        LOG.Extreme("class_id=" + boost::lexical_cast<std::string>(class_id));
428
        class_name = Protocol::Instance()->LookupClassName(class_id);
428
        class_name = Protocol::Instance()->LookupClassName(class_id);
429
       
429
       
430
        if (class_name == "nmt")
430
        if (class_name == "nmt")
431
        {
431
        {
432
            unsigned int command_id = this->buffer_[2];
432
            unsigned int command_id = this->buffer_[2];
433
            LOG.Debug("command_id=" + boost::lexical_cast<std::string>(command_id));
433
            LOG.Extreme("command_id=" + boost::lexical_cast<std::string>(command_id));
434
            command_name = Protocol::Instance()->LookupNMTCommandName(command_id);
434
            command_name = Protocol::Instance()->LookupNMTCommandName(command_id);
435
        }
435
        }
436
        else
436
        else
437
        {
437
        {
438
            unsigned int direction_flag = this->buffer_[3] & 0x01;
438
            unsigned int direction_flag = this->buffer_[3] & 0x01;
439
            LOG.Debug("direction_flag=" + boost::lexical_cast<std::string>(direction_flag));
439
            LOG.Extreme("direction_flag=" + boost::lexical_cast<std::string>(direction_flag));
440
            direction_name = Protocol::Instance()->LookupDirectionFlag(direction_flag);
440
            direction_name = Protocol::Instance()->LookupDirectionFlag(direction_flag);
441
           
441
           
442
            unsigned int module_id = this->buffer_[2];
442
            unsigned int module_id = this->buffer_[2];
443
            LOG.Debug("module_id=" + boost::lexical_cast<std::string>(module_id));
443
            LOG.Extreme("module_id=" + boost::lexical_cast<std::string>(module_id));
444
            module_name = Protocol::Instance()->LookupModuleName(module_id);
444
            module_name = Protocol::Instance()->LookupModuleName(module_id);
445
            LOG.Debug("module_name=" + module_name);
445
            LOG.Extreme("module_name=" + module_name);
446
            id = this->buffer_[1];
446
            id = this->buffer_[1];
447
           
447
           
448
            unsigned int command_id = this->buffer_[0];
448
            unsigned int command_id = this->buffer_[0];
449
            LOG.Debug("command_id=" + boost::lexical_cast<std::string>(command_id));
449
            LOG.Extreme("command_id=" + boost::lexical_cast<std::string>(command_id));
450
            command_name = Protocol::Instance()->LookupCommandName(command_id, module_name);
450
            command_name = Protocol::Instance()->LookupCommandName(command_id, module_name);
451
            LOG.Debug("command_name=" + command_name);
451
            LOG.Extreme("command_name=" + command_name);
452
        }
452
        }
453
 
453
 
454
        Message* payload = new Message(class_name, direction_name, module_name, id, command_name);
454
        Message* payload = new Message(class_name, direction_name, module_name, id, command_name);
455
 
455
 
456
        unsigned int length = this->buffer_[6];
456
        unsigned int length = this->buffer_[6];
Line 463... Line 463...
463
            data_set.push_back(this->buffer_[n + 7]);
463
            data_set.push_back(this->buffer_[n + 7]);
464
        }
464
        }
465
       
465
       
466
        for (unsigned int n = 0; n < data_set.size(); n++)
466
        for (unsigned int n = 0; n < data_set.size(); n++)
467
        {
467
        {
468
           log::Debug(log_module_, "data_set[%u]=%u", n, (unsigned int)data_set[n]);
468
           log::Extreme(log_module_, "data_set[%u]=%u", n, (unsigned int)data_set[n]);
469
        }
469
        }
470
 
470
 
471
        common::Bitset databits(data_set);
471
        common::Bitset databits(data_set);
472
        xml::Node::NodeList variable_nodes;
472
        xml::Node::NodeList variable_nodes;
473
        unsigned int start_bit;
473
        unsigned int start_bit;
Line 502... Line 502...
502
                    continue;
502
                    continue;
503
                }
503
                }
504
            }
504
            }
505
           
505
           
506
            type = variable_nodes[n].GetAttributeValue("type");
506
            type = variable_nodes[n].GetAttributeValue("type");
507
            LOG.Debug("type: type=" + type);
507
            LOG.Extreme("type: type=" + type);
508
           
508
           
509
            if (type == "int")
509
            if (type == "int")
510
            {
510
            {
511
                value = Protocol::Instance()->DecodeInt(databits, start_bit, bit_length);
511
                value = Protocol::Instance()->DecodeInt(databits, start_bit, bit_length);
512
            }
512
            }
Line 522... Line 522...
522
            {
522
            {
523
                value = Protocol::Instance()->DecodeHexstring(databits, start_bit, bit_length);
523
                value = Protocol::Instance()->DecodeHexstring(databits, start_bit, bit_length);
524
            }
524
            }
525
            else if (type == "enum")
525
            else if (type == "enum")
526
            {
526
            {
527
                LOG.Debug("Enum: command name=" + command_name);
527
                LOG.Extreme("Enum: command name=" + command_name);
528
                value = Protocol::Instance()->DecodeUint(databits, start_bit, bit_length);
528
                value = Protocol::Instance()->DecodeUint(databits, start_bit, bit_length);
529
                LOG.Debug("Enum: value=" + boost::lexical_cast<std::string>(value));
529
                LOG.Extreme("Enum: value=" + boost::lexical_cast<std::string>(value));
530
                LOG.Debug("start_bit=" + boost::lexical_cast<std::string>(start_bit) + ", bit_length=" + boost::lexical_cast<std::string>(bit_length));
530
                LOG.Extreme("start_bit=" + boost::lexical_cast<std::string>(start_bit) + ", bit_length=" + boost::lexical_cast<std::string>(bit_length));
531
               
531
               
532
                value = variable_nodes[n].SelectChild("id", value).GetAttributeValue("name");
532
                value = variable_nodes[n].SelectChild("id", value).GetAttributeValue("name");
533
            }
533
            }
534
            else// if (type == "uint")
534
            else// if (type == "uint")
535
            {
535
            {
536
                value = Protocol::Instance()->DecodeUint(databits, start_bit, bit_length);
536
                value = Protocol::Instance()->DecodeUint(databits, start_bit, bit_length);
537
            }
537
            }
538
           
538
           
539
            LOG.Debug("value=\"" + value + "\"");
539
            LOG.Extreme("value=\"" + value + "\"");
540
           
540
           
541
            payload->SetVariable(name, value);
541
            payload->SetVariable(name, value);
542
        }
542
        }
543
       
543
       
544
        broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), this)));
544
        broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), this)));