Rev 1627 | Rev 1642 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1627 | Rev 1633 | ||
|---|---|---|---|
| Line 36... | Line 36... | ||
| 36 | Manager::Pointer Manager::instance_; |
36 | Manager::Pointer Manager::instance_; |
| 37 | 37 | ||
| 38 | Manager::Manager() : broker::Subscriber(false), LOG("can::Manager") |
38 | Manager::Manager() : broker::Subscriber(false), LOG("can::Manager") |
| 39 | { |
39 | { |
| 40 | Node::SetupStateMachine(); |
40 | Node::SetupStateMachine(); |
| - | 41 | ||
| - | 42 | this->active_programming_node_id_ = 0; |
|
| 41 | 43 | ||
| 42 | // Nyquist–Shannon sampling theorem state that we need to double the time, modules send every 10 seconds |
44 | // Nyquist–Shannon sampling theorem state that we need to double the time, modules send every 10 seconds |
| 43 | this->timer_id_ = timer::Manager::Instance()->Set(20000, true); |
45 | this->timer_id_ = timer::Manager::Instance()->Set(20000, true); |
| 44 | } |
46 | } |
| 45 | 47 | ||
| Line 106... | Line 108... | ||
| 106 | } |
108 | } |
| 107 | else if (payload->GetCommandName() == "App_Start") |
109 | else if (payload->GetCommandName() == "App_Start") |
| 108 | { |
110 | { |
| 109 | node = this->GetNode(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"])); |
111 | node = this->GetNode(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"])); |
| 110 | node->Trigger(Node::EVENT_APP_START, payload->GetVariables()); |
112 | node->Trigger(Node::EVENT_APP_START, payload->GetVariables()); |
| 111 | } |
113 | } |
| 112 | else if (payload->GetCommandName() == "Heartbeat") |
114 | else if (payload->GetCommandName() == "Heartbeat") |
| 113 | { |
115 | { |
| 114 | node = this->GetNode(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"])); |
116 | node = this->GetNode(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"])); |
| 115 | node->Trigger(Node::EVENT_HEARTBEAT, payload->GetVariables()); |
117 | node->Trigger(Node::EVENT_HEARTBEAT, payload->GetVariables()); |
| 116 | } |
118 | } |
| 117 | } |
119 | } |
| 118 | else if (payload->GetDirectionName() == "From_Owner") |
120 | else if (payload->GetDirectionName() == "From_Owner") |
| 119 | { |
121 | { |
| 120 | Module::Pointer module = this->GetModule(boost::lexical_cast<unsigned int>(payload->GetId()), payload->GetModuleName(), payload->GetClassName()); |
122 | Module::Pointer module = this->GetModule(boost::lexical_cast<unsigned int>(payload->GetId()), payload->GetModuleName(), payload->GetClassName()); |
| 121 | 123 | ||
| 122 | if (payload->GetCommandName() == "List") |
124 | if (payload->GetCommandName() == "List") |
| 123 | { |
125 | { |
| 124 | node = this->GetNode(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"])); |
126 | node = this->GetNode(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"])); |
| 125 | node->ResetTimeout(); |
127 | node->ResetTimeout(); |
| 126 | 128 | ||
| 127 | module->SetNodeId(node->GetId()); |
129 | module->SetNodeId(node->GetId()); |
| 128 | 130 | ||
| 129 | if (this->GetNumberOfModules(node->GetId()) == boost::lexical_cast<unsigned int>(payload->GetVariables()["NumberOfModules"])) |
131 | if (this->GetNumberOfModules(node->GetId()) == boost::lexical_cast<unsigned int>(payload->GetVariables()["NumberOfModules"])) |
| 130 | { |
132 | { |
| Line 148... | Line 150... | ||
| 148 | void Manager::SlotOnNewState(Node::Id node_id, Node::State current_state, Node::State target_state) |
150 | void Manager::SlotOnNewState(Node::Id node_id, Node::State current_state, Node::State target_state) |
| 149 | { |
151 | { |
| 150 | if (target_state != Node::STATE_NORM_INITIALIZED) |
152 | if (target_state != Node::STATE_NORM_INITIALIZED) |
| 151 | { |
153 | { |
| 152 | this->RemoveModules(node_id); |
154 | this->RemoveModules(node_id); |
| - | 155 | } |
|
| - | 156 | ||
| - | 157 | if (target_state == Node::STATE_BPGM_OFFLINE || target_state == Node::STATE_APGM_OFFLINE) |
|
| - | 158 | { |
|
| - | 159 | this->active_programming_node_id_ = node_id; |
|
| - | 160 | } |
|
| - | 161 | else if (target_state == Node::STATE_NORM_OFFLINE) |
|
| - | 162 | { |
|
| - | 163 | this->active_programming_node_id_ = 0; |
|
| 153 | } |
164 | } |
| 154 | } |
165 | } |
| 155 | 166 | ||
| 156 | void Manager::SendMessageHandler(std::string full_id, std::string command, type::StringMap variables) |
167 | void Manager::SendMessageHandler(std::string full_id, std::string command, type::StringMap variables) |
| 157 | { |
168 | { |