Rev 2216 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 2216 | Rev 2266 | ||
|---|---|---|---|
| Line 187... | Line 187... | ||
| 187 | Protocol::Instance()->EncodeInt(databits, start_bit, bit_length, value); |
187 | Protocol::Instance()->EncodeInt(databits, start_bit, bit_length, value); |
| 188 | } |
188 | } |
| 189 | else if (type == "float") |
189 | else if (type == "float") |
| 190 | { |
190 | { |
| 191 | Protocol::Instance()->EncodeFloat(databits, start_bit, bit_length, value); |
191 | Protocol::Instance()->EncodeFloat(databits, start_bit, bit_length, value); |
| - | 192 | } |
|
| - | 193 | else if (type == "IEEE32") |
|
| - | 194 | { |
|
| - | 195 | Protocol::Instance()->EncodeIEEE32(databits, start_bit, bit_length, value); |
|
| 192 | } |
196 | } |
| 193 | else if (type == "ascii") |
197 | else if (type == "ascii") |
| 194 | { |
198 | { |
| 195 | Protocol::Instance()->EncodeAscii(databits, start_bit, bit_length, value); |
199 | Protocol::Instance()->EncodeAscii(databits, start_bit, bit_length, value); |
| 196 | bit_length = value.length() * 8; |
200 | bit_length = value.length() * 8; |
| Line 272... | Line 276... | ||
| 272 | //LOG.Info("id4: " + value + " data: ");//+ data[4]); |
276 | //LOG.Info("id4: " + value + " data: ");//+ data[4]); |
| 273 | 277 | ||
| 274 | value = line.substr(13,1); |
278 | value = line.substr(13,1); |
| 275 | data[5] = common::FromHex(value); |
279 | data[5] = common::FromHex(value); |
| 276 | //LOG.Info("1: " + value + " data: ");//+ data[5]); |
280 | //LOG.Info("1: " + value + " data: ");//+ data[5]); |
| 277 | 281 | ||
| 278 | value = line.substr(15,1); |
282 | value = line.substr(15,1); |
| 279 | data[6] = common::FromHex(value); |
283 | data[6] = common::FromHex(value); |
| 280 | //LOG.Info("1: " + value + " data: ");//+ data[6]); |
284 | //LOG.Info("1: " + value + " data: ");//+ data[6]); |
| 281 | 285 | ||
| 282 | unsigned char length = 0; |
286 | unsigned char length = 0; |
| Line 354... | Line 358... | ||
| 354 | } |
358 | } |
| 355 | } |
359 | } |
| 356 | } |
360 | } |
| 357 | 361 | ||
| 358 | void Network::SlotOnNewClientHandler(net::SocketId id, net::SocketId server_id) |
362 | void Network::SlotOnNewClientHandler(net::SocketId id, net::SocketId server_id) |
| 359 | { |
363 | { |
| 360 | 364 | ||
| 361 | } |
365 | } |
| 362 | 366 | ||
| 363 | void Network::SlotOnNewStateHandler(net::SocketId client_id, net::ClientState client_state) |
367 | void Network::SlotOnNewStateHandler(net::SocketId client_id, net::ClientState client_state) |
| 364 | { |
368 | { |
| 365 | if (client_id != this->client_id_) |
369 | if (client_id != this->client_id_) |
| 366 | { |
370 | { |
| Line 375... | Line 379... | ||
| 375 | this->client_id_ = 0; |
379 | this->client_id_ = 0; |
| 376 | } |
380 | } |
| 377 | else |
381 | else |
| 378 | { |
382 | { |
| 379 | LOG.Debug("Got state: " + boost::lexical_cast<std::string>((int)client_state)); |
383 | LOG.Debug("Got state: " + boost::lexical_cast<std::string>((int)client_state)); |
| 380 | } |
384 | } |
| 381 | } |
385 | } |
| 382 | 386 | ||
| 383 | void Network::SlotOnTimeoutHandler(timer::TimerId timer_id) |
387 | void Network::SlotOnTimeoutHandler(timer::TimerId timer_id) |
| 384 | { |
388 | { |
| 385 | try |
389 | try |
| 386 | { |
390 | { |
| 387 | this->client_id_ = net::Manager::Instance()->Connect(this->protocol_, this->address_, this->port_or_baud_); |
391 | this->client_id_ = net::Manager::Instance()->Connect(this->protocol_, this->address_, this->port_or_baud_); |
| Line 393... | Line 397... | ||
| 393 | catch (std::runtime_error& e) |
397 | catch (std::runtime_error& e) |
| 394 | { |
398 | { |
| 395 | LOG.Error(e.what()); |
399 | LOG.Error(e.what()); |
| 396 | LOG.Warning("Will try again soon..."); |
400 | LOG.Warning("Will try again soon..."); |
| 397 | } |
401 | } |
| 398 | } |
402 | } |
| 399 | 403 | ||
| 400 | void Network::ProcessBuffer() |
404 | void Network::ProcessBuffer() |
| 401 | { |
405 | { |
| 402 | LOG_DEBUG_ENTER; |
406 | LOG_DEBUG_ENTER; |
| 403 | 407 | ||
| 404 | try |
408 | try |
| 405 | { |
409 | { |
| 406 | std::string class_name = ""; |
410 | std::string class_name = ""; |
| 407 | std::string direction_name = ""; |
411 | std::string direction_name = ""; |
| 408 | std::string module_name = ""; |
412 | std::string module_name = ""; |
| Line 412... | Line 416... | ||
| 412 | std::string PKTstring = "PKT " + |
416 | std::string PKTstring = "PKT " + |
| 413 | atom::common::ToHex8bit((unsigned int)this->buffer_[3]) + |
417 | atom::common::ToHex8bit((unsigned int)this->buffer_[3]) + |
| 414 | atom::common::ToHex8bit((unsigned int)this->buffer_[2]) + |
418 | atom::common::ToHex8bit((unsigned int)this->buffer_[2]) + |
| 415 | atom::common::ToHex8bit((unsigned int)this->buffer_[1]) + |
419 | atom::common::ToHex8bit((unsigned int)this->buffer_[1]) + |
| 416 | atom::common::ToHex8bit((unsigned int)this->buffer_[0]) + |
420 | atom::common::ToHex8bit((unsigned int)this->buffer_[0]) + |
| 417 | " " + |
421 | " " + |
| 418 | atom::common::ToHex4bit((unsigned int)this->buffer_[4]) + |
422 | atom::common::ToHex4bit((unsigned int)this->buffer_[4]) + |
| 419 | " " + |
423 | " " + |
| 420 | atom::common::ToHex4bit((unsigned int)this->buffer_[5]); |
424 | atom::common::ToHex4bit((unsigned int)this->buffer_[5]); |
| 421 | 425 | ||
| 422 | for (unsigned int index = 7; index < 7 + (unsigned int)this->buffer_[6]; index++) |
426 | for (unsigned int index = 7; index < 7 + (unsigned int)this->buffer_[6]; index++) |
| 423 | { |
427 | { |
| 424 | PKTstring += " " + atom::common::ToHex8bit((unsigned int)this->buffer_[index]) ; |
428 | PKTstring += " " + atom::common::ToHex8bit((unsigned int)this->buffer_[index]) ; |
| 425 | } |
429 | } |
| 426 | 430 | ||
| 427 | PKTstring += "\n"; |
431 | PKTstring += "\n"; |
| 428 | 432 | ||
| 429 | LOG.Extreme(PKTstring); |
433 | LOG.Extreme(PKTstring); |
| 430 | 434 | ||
| 431 | for (unsigned int n = 0; n < this->buffer_.size(); n++) |
435 | for (unsigned int n = 0; n < this->buffer_.size(); n++) |
| 432 | { |
436 | { |
| 433 | log::Extreme(log_module_, "this->buffer_[%u]=%u", n, (unsigned int)this->buffer_[n]); |
437 | log::Extreme(log_module_, "this->buffer_[%u]=%u", n, (unsigned int)this->buffer_[n]); |
| 434 | } |
438 | } |
| 435 | 439 | ||
| 436 | std::string* payload_str = new std::string(PKTstring); |
440 | std::string* payload_str = new std::string(PKTstring); |
| 437 | broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_RAW_MESSAGE, broker::Message::PayloadPointer(payload_str), this))); |
441 | broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_RAW_MESSAGE, broker::Message::PayloadPointer(payload_str), this))); |
| 438 | 442 | ||
| 439 | 443 | ||
| 440 | unsigned int class_id = (this->buffer_[3] >> 1) & 0x0F; |
444 | unsigned int class_id = (this->buffer_[3] >> 1) & 0x0F; |
| 441 | LOG.Extreme("class_id=" + boost::lexical_cast<std::string>(class_id)); |
445 | LOG.Extreme("class_id=" + boost::lexical_cast<std::string>(class_id)); |
| 442 | class_name = Protocol::Instance()->LookupClassName(class_id); |
446 | class_name = Protocol::Instance()->LookupClassName(class_id); |
| 443 | 447 | ||
| 444 | if (class_name == "nmt") |
448 | if (class_name == "nmt") |
| 445 | { |
449 | { |
| 446 | unsigned int command_id = this->buffer_[2]; |
450 | unsigned int command_id = this->buffer_[2]; |
| 447 | LOG.Extreme("command_id=" + boost::lexical_cast<std::string>(command_id)); |
451 | LOG.Extreme("command_id=" + boost::lexical_cast<std::string>(command_id)); |
| 448 | command_name = Protocol::Instance()->LookupNMTCommandName(command_id); |
452 | command_name = Protocol::Instance()->LookupNMTCommandName(command_id); |
| 449 | } |
453 | } |
| 450 | else |
454 | else |
| Line 525... | Line 529... | ||
| 525 | value = Protocol::Instance()->DecodeInt(databits, start_bit, bit_length); |
529 | value = Protocol::Instance()->DecodeInt(databits, start_bit, bit_length); |
| 526 | } |
530 | } |
| 527 | else if (type == "float") |
531 | else if (type == "float") |
| 528 | { |
532 | { |
| 529 | value = Protocol::Instance()->DecodeFloat(databits, start_bit, bit_length); |
533 | value = Protocol::Instance()->DecodeFloat(databits, start_bit, bit_length); |
| - | 534 | } |
|
| - | 535 | else if (type == "IEEE32") |
|
| - | 536 | { |
|
| - | 537 | value = Protocol::Instance()->DecodeIEEE32(databits, start_bit, bit_length); |
|
| 530 | } |
538 | } |
| 531 | else if (type == "ascii") |
539 | else if (type == "ascii") |
| 532 | { |
540 | { |
| 533 | value = Protocol::Instance()->DecodeAscii(databits, start_bit, bit_length); |
541 | value = Protocol::Instance()->DecodeAscii(databits, start_bit, bit_length); |
| 534 | } |
542 | } |