Rev 1989 | Rev 1999 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1989 | Rev 1990 | ||
|---|---|---|---|
| Line 399... | Line 399... | ||
| 399 | PKTstring += " " + atom::common::ToHex8bit((unsigned int)this->buffer_[index]) ; |
399 | PKTstring += " " + atom::common::ToHex8bit((unsigned int)this->buffer_[index]) ; |
| 400 | } |
400 | } |
| 401 | 401 | ||
| 402 | PKTstring += "\n"; |
402 | PKTstring += "\n"; |
| 403 | 403 | ||
| 404 |
|
404 | LOG.Debug(PKTstring); |
| - | 405 | ||
| - | 406 | for (unsigned int n = 0; n < this->buffer_.size(); n++) |
|
| - | 407 | { |
|
| - | 408 | log::Debug(log_module_, "this->buffer_[%u]=%u", n, (unsigned int)this->buffer_[n]); |
|
| - | 409 | } |
|
| 405 | 410 | ||
| 406 | std::string* payload_str = new std::string(PKTstring); |
411 | std::string* payload_str = new std::string(PKTstring); |
| 407 | broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_RAW_MESSAGE, broker::Message::PayloadPointer(payload_str), this))); |
412 | broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_RAW_MESSAGE, broker::Message::PayloadPointer(payload_str), this))); |
| 408 | 413 | ||
| 409 | 414 | ||
| 410 | unsigned int class_id = (this->buffer_[3] >> 1) & 0x0F; |
415 | unsigned int class_id = (this->buffer_[3] >> 1) & 0x0F; |
| 411 |
|
416 | LOG.Debug("class_id=" + boost::lexical_cast<std::string>(class_id)); |
| 412 | class_name = Protocol::Instance()->LookupClassName(class_id); |
417 | class_name = Protocol::Instance()->LookupClassName(class_id); |
| 413 | 418 | ||
| 414 | if (class_name == "nmt") |
419 | if (class_name == "nmt") |
| 415 | { |
420 | { |
| 416 | unsigned int command_id = this->buffer_[2]; |
421 | unsigned int command_id = this->buffer_[2]; |
| 417 |
|
422 | LOG.Debug("command_id=" + boost::lexical_cast<std::string>(command_id)); |
| 418 | command_name = Protocol::Instance()->LookupNMTCommandName(command_id); |
423 | command_name = Protocol::Instance()->LookupNMTCommandName(command_id); |
| 419 | } |
424 | } |
| 420 | else |
425 | else |
| 421 | { |
426 | { |
| 422 | unsigned int direction_flag = this->buffer_[3] & 0x01; |
427 | unsigned int direction_flag = this->buffer_[3] & 0x01; |
| 423 |
|
428 | LOG.Debug("direction_flag=" + boost::lexical_cast<std::string>(direction_flag)); |
| 424 | direction_name = Protocol::Instance()->LookupDirectionFlag(direction_flag); |
429 | direction_name = Protocol::Instance()->LookupDirectionFlag(direction_flag); |
| 425 | 430 | ||
| 426 | unsigned int module_id = this->buffer_[2]; |
431 | unsigned int module_id = this->buffer_[2]; |
| 427 |
|
432 | LOG.Debug("module_id=" + boost::lexical_cast<std::string>(module_id)); |
| 428 | module_name = Protocol::Instance()->LookupModuleName(module_id); |
433 | module_name = Protocol::Instance()->LookupModuleName(module_id); |
| 429 |
|
434 | LOG.Debug("module_name=" + module_name); |
| 430 | id = this->buffer_[1]; |
435 | id = this->buffer_[1]; |
| 431 | 436 | ||
| 432 | unsigned int command_id = this->buffer_[0]; |
437 | unsigned int command_id = this->buffer_[0]; |
| 433 |
|
438 | LOG.Debug("command_id=" + boost::lexical_cast<std::string>(command_id)); |
| 434 | command_name = Protocol::Instance()->LookupCommandName(command_id, module_name); |
439 | command_name = Protocol::Instance()->LookupCommandName(command_id, module_name); |
| 435 |
|
440 | LOG.Debug("command_name=" + command_name); |
| 436 | } |
441 | } |
| 437 | 442 | ||
| 438 | Message* payload = new Message(class_name, direction_name, module_name, id, command_name); |
443 | Message* payload = new Message(class_name, direction_name, module_name, id, command_name); |
| 439 | 444 | ||
| 440 | unsigned int length = this->buffer_[6]; |
445 | unsigned int length = this->buffer_[6]; |
| 441 | 446 | ||
| 442 | common::Byteset data_set |
447 | common::Byteset data_set; |
| - | 448 | data_set.reserve(length); |
|
| 443 | 449 | ||
| 444 | for (unsigned int n = 0; n < length; n++) |
450 | for (unsigned int n = 0; n < length; n++) |
| 445 | { |
451 | { |
| 446 | data_set.push_back(this->buffer_[n + 7]); |
452 | data_set.push_back(this->buffer_[n + 7]); |
| - | 453 | } |
|
| - | 454 | ||
| - | 455 | for (unsigned int n = 0; n < data_set.size(); n++) |
|
| - | 456 | { |
|
| - | 457 | log::Debug(log_module_, "data_set[%u]=%u", n, (unsigned int)data_set[n]); |
|
| 447 | } |
458 | } |
| 448 | 459 | ||
| 449 | common::Bitset databits(data_set); |
460 | common::Bitset databits(data_set); |
| 450 | xml::Node::NodeList variable_nodes; |
461 | xml::Node::NodeList variable_nodes; |
| 451 | unsigned int start_bit; |
462 | unsigned int start_bit; |
| Line 457... | Line 468... | ||
| 457 | if (class_name == "nmt") |
468 | if (class_name == "nmt") |
| 458 | { |
469 | { |
| 459 | variable_nodes = Protocol::Instance()->GetNMTCommandVariables(command_name); |
470 | variable_nodes = Protocol::Instance()->GetNMTCommandVariables(command_name); |
| 460 | } |
471 | } |
| 461 | else |
472 | else |
| 462 | { |
473 | { |
| 463 | variable_nodes = Protocol::Instance()->GetCommandVariables(command_name, module_name); |
474 | variable_nodes = Protocol::Instance()->GetCommandVariables(command_name, module_name); |
| 464 | } |
475 | } |
| 465 | 476 | ||
| 466 | for (unsigned int n = 0; n < variable_nodes.size(); n++) |
477 | for (unsigned int n = 0; n < variable_nodes.size(); n++) |
| 467 | { |
478 | { |
| Line 474... | Line 485... | ||
| 474 | bit_length = databits.GetCount() - start_bit; |
485 | bit_length = databits.GetCount() - start_bit; |
| 475 | 486 | ||
| 476 | if (bit_length <= 0) |
487 | if (bit_length <= 0) |
| 477 | { |
488 | { |
| 478 | 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?"); |
489 | 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?"); |
| 479 |
|
490 | 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())); |
| 480 | continue; |
491 | continue; |
| 481 | } |
492 | } |
| 482 | } |
493 | } |
| 483 | 494 | ||
| 484 | type = variable_nodes[n].GetAttributeValue("type"); |
495 | type = variable_nodes[n].GetAttributeValue("type"); |
| - | 496 | LOG.Debug("type: type=" + type); |
|
| 485 | 497 | ||
| 486 | if (type == "int") |
498 | if (type == "int") |
| 487 | { |
499 | { |
| 488 | value = Protocol::Instance()->DecodeInt(databits, start_bit, bit_length); |
500 | value = Protocol::Instance()->DecodeInt(databits, start_bit, bit_length); |
| 489 | } |
501 | } |
| 490 | else if (type == "float") |
502 | else if (type == "float") |
| 491 | { |
503 | { |
| 492 | value = Protocol::Instance()->DecodeFloat(databits, start_bit, bit_length); |
504 | value = Protocol::Instance()->DecodeFloat(databits, start_bit, bit_length); |
| 493 | } |
505 | } |
| 494 | else if (type == "ascii") |
506 | else if (type == "ascii") |
| 495 | { |
507 | { |
| 496 | value = Protocol::Instance()->DecodeAscii(databits, start_bit, bit_length); |
508 | value = Protocol::Instance()->DecodeAscii(databits, start_bit, bit_length); |
| 497 | } |
509 | } |
| 498 | else if (type == "hexstring") |
510 | else if (type == "hexstring") |
| 499 | { |
511 | { |
| 500 | value = Protocol::Instance()->DecodeHexstring(databits, start_bit, bit_length); |
512 | value = Protocol::Instance()->DecodeHexstring(databits, start_bit, bit_length); |
| 501 | } |
513 | } |
| 502 | else if (type == "enum") |
514 | else if (type == "enum") |
| 503 | { |
515 | { |
| 504 |
|
516 | LOG.Debug("Enum: command name=" + command_name); |
| 505 | value = Protocol::Instance()->DecodeUint(databits, start_bit, bit_length); |
517 | value = Protocol::Instance()->DecodeUint(databits, start_bit, bit_length); |
| 506 |
|
518 | LOG.Debug("Enum: value=" + boost::lexical_cast<std::string>(value)); |
| 507 |
|
519 | LOG.Debug("start_bit=" + boost::lexical_cast<std::string>(start_bit) + ", bit_length=" + boost::lexical_cast<std::string>(bit_length)); |
| 508 | 520 | ||
| 509 | value = variable_nodes[n].SelectChild("id", value).GetAttributeValue("name"); |
521 | value = variable_nodes[n].SelectChild("id", value).GetAttributeValue("name"); |
| 510 | } |
522 | } |
| 511 | else// if (type == "uint") |
523 | else// if (type == "uint") |
| 512 | { |
524 | { |
| 513 | //LOG.Debug("type: type=" + type); |
- | |
| 514 | value = Protocol::Instance()->DecodeUint(databits, start_bit, bit_length); |
525 | value = Protocol::Instance()->DecodeUint(databits, start_bit, bit_length); |
| 515 | } |
526 | } |
| - | 527 | ||
| - | 528 | LOG.Debug("value=\"" + value + "\""); |
|
| 516 | 529 | ||
| 517 | payload->SetVariable(name, value); |
530 | payload->SetVariable(name, value); |
| 518 | } |
531 | } |
| 519 | 532 | ||
| 520 | broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), this))); |
533 | broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), this))); |