Rev 2037 | Rev 2164 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 2037 | Rev 2039 | ||
|---|---|---|---|
| Line 176... | Line 176... | ||
| 176 | 176 | ||
| 177 | Node::Transition::iterator it2 = it1->second.find(event); |
177 | Node::Transition::iterator it2 = it1->second.find(event); |
| 178 | 178 | ||
| 179 | if (it2 == it1->second.end()) |
179 | if (it2 == it1->second.end()) |
| 180 | { |
180 | { |
| 181 |
|
181 | LOG.Warning("No transitions found for current state " + boost::lexical_cast<std::string>(this->state_) + " for event " + boost::lexical_cast<std::string>(event)); |
| 182 | return STATE_INVALID; |
182 | return STATE_INVALID; |
| 183 | } |
183 | } |
| 184 | 184 | ||
| 185 | return it2->second; |
185 | return it2->second; |
| 186 | } |
186 | } |
| 187 | 187 | ||
| 188 | void Node::Trigger(Node::Event event, common::StringMap variables) |
188 | void Node::Trigger(Node::Event event, common::StringMap variables) |
| - | 189 | { |
|
| - | 190 | if (!this->id_.empty()) |
|
| 189 | { |
191 | { |
| 190 | this->ResetTimeout(); |
192 | this->ResetTimeout(); |
| 191 | 193 | ||
| 192 | State target_state = this->GetTransitionTarget(event); |
194 | State target_state = this->GetTransitionTarget(event); |
| 193 | 195 | ||
| Line 245... | Line 247... | ||
| 245 | payload->SetVariable("Source1", boost::lexical_cast<std::string>(source1)); |
247 | payload->SetVariable("Source1", boost::lexical_cast<std::string>(source1)); |
| 246 | payload->SetVariable("Destination0", boost::lexical_cast<std::string>(destination0)); |
248 | payload->SetVariable("Destination0", boost::lexical_cast<std::string>(destination0)); |
| 247 | payload->SetVariable("Destination1", boost::lexical_cast<std::string>(destination1)); |
249 | payload->SetVariable("Destination1", boost::lexical_cast<std::string>(destination1)); |
| 248 | payload->SetVariable("Length0", boost::lexical_cast<std::string>(length0)); |
250 | payload->SetVariable("Length0", boost::lexical_cast<std::string>(length0)); |
| 249 | payload->SetVariable("Length1", boost::lexical_cast<std::string>(length1)); |
251 | payload->SetVariable("Length1", boost::lexical_cast<std::string>(length1)); |
| 250 | 252 | ||
| 251 | broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), Manager::Instance().get()))); |
253 | broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), Manager::Instance().get()))); |
| 252 | } |
254 | } |
| 253 | else |
255 | else |
| 254 | { |
256 | { |
| 255 | float speed = (float)this->code_->GetLength() / (float)(time(NULL) - this->program_start_time_); |
257 | float speed = (float)this->code_->GetLength() / (float)(time(NULL) - this->program_start_time_); |
| Line 365... | Line 367... | ||
| 365 | { |
367 | { |
| 366 | this->signal_on_new_state_(this->id_, this->state_, target_state); |
368 | this->signal_on_new_state_(this->id_, this->state_, target_state); |
| 367 | } |
369 | } |
| 368 | 370 | ||
| 369 | this->state_ = target_state; |
371 | this->state_ = target_state; |
| - | 372 | } |
|
| 370 | } |
373 | } |
| 371 | 374 | ||
| 372 | bool Node::CheckTimeout() |
375 | bool Node::CheckTimeout() |
| 373 | { |
376 | { |
| 374 | if (this->state_ == STATE_NORM_OFFLINE) |
377 | if (this->state_ == STATE_NORM_OFFLINE) |
| Line 396... | Line 399... | ||
| 396 | 399 | ||
| 397 | this->Trigger(EVENT_RESET, variables); |
400 | this->Trigger(EVENT_RESET, variables); |
| 398 | } |
401 | } |
| 399 | 402 | ||
| 400 | void Node::ProgramApplication(Code::Pointer code) |
403 | void Node::ProgramApplication(Code::Pointer code) |
| 401 | { |
404 | { |
| 402 | this->code_ = code; |
405 | this->code_ = code; |
| 403 | 406 | ||
| 404 | common::StringMap variables; |
407 | common::StringMap variables; |
| 405 | 408 | ||
| 406 | this->Trigger(EVENT_PROGRAM_APP, variables); |
409 | this->Trigger(EVENT_PROGRAM_APP, variables); |
| 407 | } |
410 | } |
| 408 | 411 | ||
| 409 | void Node::ProgramBios(Code::Pointer code) |
412 | void Node::ProgramBios(Code::Pointer code) |
| 410 | { |
413 | { |
| 411 | this->code_ = code; |
414 | this->code_ = code; |
| 412 | 415 | ||
| Line 414... | Line 417... | ||
| 414 | 417 | ||
| 415 | this->Trigger(EVENT_PROGRAM_BIOS, variables); |
418 | this->Trigger(EVENT_PROGRAM_BIOS, variables); |
| 416 | } |
419 | } |
| 417 | 420 | ||
| 418 | void Node::SendReset() |
421 | void Node::SendReset() |
| - | 422 | { |
|
| - | 423 | if (!this->id_.empty()) |
|
| 419 | { |
424 | { |
| 420 | LOG.Info("Sending node reset to " + this->id_); |
425 | LOG.Info("Sending node reset to " + this->id_); |
| 421 | can::Message* payload = new can::Message("nmt", "", "", 0, "Reset"); |
426 | can::Message* payload = new can::Message("nmt", "", "", 0, "Reset"); |
| 422 | payload->SetVariable("HardwareId", boost::lexical_cast<std::string>(common::FromHex(this->id_))); |
427 | payload->SetVariable("HardwareId", boost::lexical_cast<std::string>(common::FromHex(this->id_))); |
| 423 | 428 | ||
| 424 | broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), Manager::Instance().get()))); |
429 | broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), Manager::Instance().get()))); |
| - | 430 | } |
|
| 425 | } |
431 | } |
| 426 | 432 | ||
| 427 | void Node::SendListRequest() |
433 | void Node::SendListRequest() |
| - | 434 | { |
|
| - | 435 | if (!this->id_.empty()) |
|
| 428 | { |
436 | { |
| 429 | LOG.Debug("Sending module listing on node " + this->id_); |
437 | LOG.Debug("Sending module listing on node " + this->id_); |
| 430 | can::Message* payload = new can::Message("mnmt", "To_Owner", "", 0, "List"); |
438 | can::Message* payload = new can::Message("mnmt", "To_Owner", "", 0, "List"); |
| 431 | payload->SetVariable("HardwareId", boost::lexical_cast<std::string>(common::FromHex(this->id_))); |
439 | payload->SetVariable("HardwareId", boost::lexical_cast<std::string>(common::FromHex(this->id_))); |
| 432 | 440 | ||
| 433 | broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), Manager::Instance().get()))); |
441 | broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), Manager::Instance().get()))); |
| - | 442 | } |
|
| 434 | } |
443 | } |
| 435 | 444 | ||
| 436 | }; // namespace control |
445 | }; // namespace control |
| 437 | }; // namespace atom |
446 | }; // namespace atom |