Rev 1657 | Rev 1788 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1657 | Rev 1665 | ||
|---|---|---|---|
| Line 36... | Line 36... | ||
| 36 | 36 | ||
| 37 | Node::Node(Node::Id id) : LOG("control::Node") |
37 | Node::Node(Node::Id id) : LOG("control::Node") |
| 38 | { |
38 | { |
| 39 | this->state_ = STATE_NORM_OFFLINE; |
39 | this->state_ = STATE_NORM_OFFLINE; |
| 40 | this->id_ = id; |
40 | this->id_ = id; |
| - | 41 | this->information_.has_application_ = false; |
|
| - | 42 | this->information_.bios_version_ = 0; |
|
| - | 43 | this->information_.device_type_ = "N/A"; |
|
| - | 44 | this->information_.last_active_ = 0; |
|
| - | 45 | this->information_.valid_ = false; |
|
| - | 46 | ||
| 41 | this->current_offset_ = 0; |
47 | this->current_offset_ = 0; |
| 42 | this->expected_ack_data_ = 0; |
48 | this->expected_ack_data_ = 0; |
| 43 | this->program_start_time_ = 0; |
49 | this->program_start_time_ = 0; |
| 44 | } |
50 | } |
| 45 | 51 | ||
| Line 56... | Line 62... | ||
| 56 | Node::Id Node::GetId() |
62 | Node::Id Node::GetId() |
| 57 | { |
63 | { |
| 58 | return this->id_; |
64 | return this->id_; |
| 59 | } |
65 | } |
| 60 | 66 | ||
| 61 | Node:: |
67 | Node::Information Node::GetInformation() |
| 62 | { |
68 | { |
| 63 | return this-> |
69 | return this->information_; |
| 64 | } |
70 | } |
| 65 | 71 | ||
| 66 | void Node::SetupStateMachine() |
72 | void Node::SetupStateMachine() |
| 67 | { |
73 | { |
| 68 | // Normal flow |
74 | // Normal flow |
| Line 161... | Line 167... | ||
| 161 | Node::TransitionList::iterator it1 = Node::transitions_.find(this->state_); |
167 | Node::TransitionList::iterator it1 = Node::transitions_.find(this->state_); |
| 162 | 168 | ||
| 163 | if (it1 == Node::transitions_.end()) |
169 | if (it1 == Node::transitions_.end()) |
| 164 | { |
170 | { |
| 165 | LOG.Warning("No transitions found for current state " + boost::lexical_cast<std::string>(this->state_)); |
171 | LOG.Warning("No transitions found for current state " + boost::lexical_cast<std::string>(this->state_)); |
| 166 | return STATE_INVALID; |
172 | return STATE_INVALID; |
| 167 | } |
173 | } |
| 168 | 174 | ||
| 169 | Node::Transition::iterator it2 = it1->second.find(event); |
175 | Node::Transition::iterator it2 = it1->second.find(event); |
| 170 | 176 | ||
| 171 | if (it2 == it1->second.end()) |
177 | if (it2 == it1->second.end()) |
| 172 | { |
178 | { |
| 173 | LOG.Warning("No transitions found for current state " + boost::lexical_cast<std::string>(this->state_) + " for event " + boost::lexical_cast<std::string>(event)); |
179 | LOG.Warning("No transitions found for current state " + boost::lexical_cast<std::string>(this->state_) + " for event " + boost::lexical_cast<std::string>(event)); |
| 174 | return STATE_INVALID; |
180 | return STATE_INVALID; |
| 175 | } |
181 | } |
| 176 | 182 | ||
| 177 | return it2->second; |
183 | return it2->second; |
| 178 | } |
184 | } |
| 179 | 185 | ||
| 180 | void Node::Trigger(Node::Event event, common::StringMap variables) |
186 | void Node::Trigger(Node::Event event, common::StringMap variables) |
| Line 182... | Line 188... | ||
| 182 | this->ResetTimeout(); |
188 | this->ResetTimeout(); |
| 183 | 189 | ||
| 184 | State target_state = this->GetTransitionTarget(event); |
190 | State target_state = this->GetTransitionTarget(event); |
| 185 | 191 | ||
| 186 | LOG.Debug("Trigger called on " + this->id_ + ", current state: " + Node::state_names_[this->state_] + ", event: " + Node::event_names_[event] + ", target state: " + Node::state_names_[target_state]); |
192 | LOG.Debug("Trigger called on " + this->id_ + ", current state: " + Node::state_names_[this->state_] + ", event: " + Node::event_names_[event] + ", target state: " + Node::state_names_[target_state]); |
| - | 193 | ||
| - | 194 | if (event == EVENT_BIOS_START) |
|
| - | 195 | { |
|
| - | 196 | this->information_.has_application_ = boost::lexical_cast<int>(variables["HasApplication"]) > 0; |
|
| - | 197 | this->information_.bios_version_ = boost::lexical_cast<unsigned int>(variables["BiosVersion"]); |
|
| - | 198 | this->information_.device_type_ = variables["DeviceType"]; |
|
| - | 199 | this->information_.valid_ = true; |
|
| - | 200 | } |
|
| 187 | 201 | ||
| 188 | if (target_state == STATE_INVALID) |
202 | if (target_state == STATE_INVALID) |
| 189 | { |
203 | { |
| 190 | this->SendReset(); |
204 | this->SendReset(); |
| 191 | target_state = STATE_NORM_OFFLINE; |
205 | target_state = STATE_NORM_OFFLINE; |
| Line 334... | Line 348... | ||
| 334 | this->code_->AddByte(0xFF); |
348 | this->code_->AddByte(0xFF); |
| 335 | this->code_->AddByte(0xFF); |
349 | this->code_->AddByte(0xFF); |
| 336 | } |
350 | } |
| 337 | else if (target_state == STATE_NORM_OFFLINE) |
351 | else if (target_state == STATE_NORM_OFFLINE) |
| 338 | { |
352 | { |
| - | 353 | this->information_.valid_ = false; |
|
| 339 | this->SendReset(); |
354 | this->SendReset(); |
| 340 | } |
355 | } |
| 341 | 356 | ||
| 342 | 357 | ||
| 343 | if (this->state_ != target_state) |
358 | if (this->state_ != target_state) |
| Line 353... | Line 368... | ||
| 353 | if (this->state_ == STATE_NORM_OFFLINE) |
368 | if (this->state_ == STATE_NORM_OFFLINE) |
| 354 | { |
369 | { |
| 355 | return true; |
370 | return true; |
| 356 | } |
371 | } |
| 357 | 372 | ||
| 358 | if (this->code_.use_count() == 0 && this->last_active_ + 10 < time(NULL)) |
373 | if (this->code_.use_count() == 0 && this->information_.last_active_ + 10 < time(NULL)) |
| 359 | { |
374 | { |
| 360 | this->state_ = STATE_NORM_OFFLINE; |
375 | this->state_ = STATE_NORM_OFFLINE; |
| 361 | return false; |
376 | return false; |
| 362 | } |
377 | } |
| 363 | 378 | ||
| 364 | return true; |
379 | return true; |
| 365 | } |
380 | } |
| 366 | 381 | ||
| 367 | void Node::ResetTimeout() |
382 | void Node::ResetTimeout() |
| 368 | { |
383 | { |
| 369 | this->last_active_ = time(NULL); |
384 | this->information_.last_active_ = time(NULL); |
| 370 | } |
385 | } |
| 371 | 386 | ||
| 372 | void Node::Reset() |
387 | void Node::Reset() |
| 373 | { |
388 | { |
| 374 | common::StringMap variables; |
389 | common::StringMap variables; |