Rev 1788 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1598 | runge | 1 | /* |
| 1642 | runge | 2 | * |
| 3 | * Copyright (C) 2010 Mattias Runge |
||
| 4 | * |
||
| 5 | * This program is free software; you can redistribute it and/or modify |
||
| 6 | * it under the terms of the GNU General Public License as published by |
||
| 7 | * the Free Software Foundation; either version 2 of the License, or |
||
| 8 | * (at your option) any later version. |
||
| 9 | * |
||
| 10 | * This program is distributed in the hope that it will be useful, |
||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 13 | * GNU General Public License for more details. |
||
| 14 | * |
||
| 15 | * You should have received a copy of the GNU General Public License along |
||
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
||
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
||
| 18 | * |
||
| 19 | */ |
||
| 1598 | runge | 20 | |
| 1642 | runge | 21 | #ifndef CONTROL_NODE_H |
| 22 | #define CONTROL_NODE_H |
||
| 1598 | runge | 23 | |
| 24 | #include <string> |
||
| 1627 | runge | 25 | #include <map> |
| 1598 | runge | 26 | |
| 27 | #include <boost/shared_ptr.hpp> |
||
| 1627 | runge | 28 | #include <boost/signals2.hpp> |
| 1788 | arune | 29 | #include <boost/algorithm/string.hpp> |
| 1598 | runge | 30 | |
| 1601 | runge | 31 | #include <time.h> |
| 32 | |||
| 1642 | runge | 33 | #include "common/common.h" |
| 1627 | runge | 34 | #include "logging/Logger.h" |
| 35 | |||
| 1642 | runge | 36 | #include "Code.h" |
| 37 | #include <boost/concept_check.hpp> |
||
| 38 | |||
| 1598 | runge | 39 | namespace atom { |
| 1642 | runge | 40 | namespace control { |
| 1598 | runge | 41 | |
| 42 | class Node |
||
| 43 | { |
||
| 44 | public: |
||
| 45 | typedef boost::shared_ptr<Node> Pointer; |
||
| 1657 | runge | 46 | typedef std::string Id; |
| 1598 | runge | 47 | |
| 1665 | runge | 48 | typedef struct |
| 49 | { |
||
| 50 | bool valid_; |
||
| 51 | unsigned int bios_version_; |
||
| 52 | std::string device_type_; |
||
| 53 | bool has_application_; |
||
| 54 | time_t last_active_; |
||
| 55 | } Information; |
||
| 56 | |||
| 1598 | runge | 57 | typedef enum |
| 58 | { |
||
| 1627 | runge | 59 | STATE_INVALID, |
| 60 | STATE_NO_CHANGE, |
||
| 61 | STATE_NORM_OFFLINE, |
||
| 62 | STATE_NORM_ONLINE, |
||
| 63 | STATE_NORM_LIST, |
||
| 64 | STATE_NORM_INITIALIZED, |
||
| 65 | STATE_BPGM_OFFLINE, |
||
| 66 | STATE_BPGM_START, |
||
| 67 | STATE_BPGM_DATA, |
||
| 68 | STATE_BPGM_END, |
||
| 69 | STATE_BPGM_COPY, |
||
| 70 | STATE_APGM_OFFLINE, |
||
| 71 | STATE_APGM_START, |
||
| 72 | STATE_APGM_DATA, |
||
| 73 | STATE_APGM_END, |
||
| 1598 | runge | 74 | } State; |
| 1627 | runge | 75 | |
| 76 | typedef enum |
||
| 77 | { |
||
| 78 | EVENT_BIOS_START, |
||
| 79 | EVENT_APP_START, |
||
| 80 | EVENT_HEARTBEAT, |
||
| 81 | EVENT_PGM_ACK, |
||
| 82 | EVENT_PGM_NACK, |
||
| 83 | EVENT_LIST_DONE, |
||
| 84 | EVENT_PROGRAM_BIOS, |
||
| 85 | EVENT_PROGRAM_APP, |
||
| 86 | EVENT_RESET |
||
| 87 | } Event; |
||
| 1598 | runge | 88 | |
| 1627 | runge | 89 | typedef boost::signals2::signal<void(Id, State, State)> SignalOnNewState; |
| 90 | |||
| 1598 | runge | 91 | Node(Id id); |
| 92 | virtual ~Node(); |
||
| 93 | |||
| 1627 | runge | 94 | static void SetupStateMachine(); |
| 95 | |||
| 96 | void ConnectSlots(const SignalOnNewState::slot_type& slot_on_new_state); |
||
| 97 | |||
| 1598 | runge | 98 | Id GetId(); |
| 1665 | runge | 99 | Information GetInformation(); |
| 100 | unsigned int GetBiosVersion(); |
||
| 101 | bool HasApplication(); |
||
| 1598 | runge | 102 | State GetState(); |
| 1627 | runge | 103 | |
| 1642 | runge | 104 | void Trigger(Event event, common::StringMap variables); |
| 1598 | runge | 105 | |
| 1601 | runge | 106 | bool CheckTimeout(); |
| 107 | void ResetTimeout(); |
||
| 108 | |||
| 1642 | runge | 109 | void ProgramApplication(Code::Pointer code); |
| 110 | void ProgramBios(Code::Pointer code); |
||
| 1657 | runge | 111 | void Reset(); |
| 1642 | runge | 112 | |
| 2164 | arune | 113 | unsigned int GetProgramProgress(); |
| 114 | |||
| 1598 | runge | 115 | private: |
| 1627 | runge | 116 | typedef std::map<Event, State> Transition; |
| 117 | typedef std::map<State, Transition> TransitionList; |
||
| 118 | |||
| 1598 | runge | 119 | Id id_; |
| 1665 | runge | 120 | Information information_; |
| 1598 | runge | 121 | State state_; |
| 1665 | runge | 122 | |
| 1642 | runge | 123 | Code::Pointer code_; |
| 124 | unsigned int start_offset_; |
||
| 125 | unsigned int current_offset_; |
||
| 126 | unsigned int expected_ack_data_; |
||
| 127 | time_t program_start_time_; |
||
| 1665 | runge | 128 | |
| 129 | logging::Logger LOG; |
||
| 1627 | runge | 130 | |
| 131 | static TransitionList transitions_; |
||
| 1642 | runge | 132 | static std::map<State, std::string> state_names_; |
| 133 | static std::map<Event, std::string> event_names_; |
||
| 1627 | runge | 134 | |
| 1665 | runge | 135 | SignalOnNewState signal_on_new_state_; |
| 136 | |||
| 1627 | runge | 137 | static void AddTransition(State current_state, Event event, State target_state); |
| 138 | |||
| 139 | State GetTransitionTarget(Event event); |
||
| 140 | void SendReset(); |
||
| 141 | void SendListRequest(); |
||
| 1598 | runge | 142 | }; |
| 143 | |||
| 1642 | runge | 144 | }; // namespace control |
| 1598 | runge | 145 | }; // namespace atom |
| 146 | |||
| 1642 | runge | 147 | #endif // CONTROL_NODE_H |