Subversion Repositories HomeAutomation

Rev

Rev 1627 | Rev 1657 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1627 Rev 1642
Line 1... Line 1...
1
/*
1
/*
-
 
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
 */
-
 
20
 
-
 
21
#ifndef CONTROL_NODE_H
-
 
22
#define CONTROL_NODE_H
2
 
23
 
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
*/
-
 
20
 
-
 
21
#ifndef CAN_NODE_H
-
 
22
#define CAN_NODE_H
-
 
23
 
-
 
24
#include <string>
24
#include <string>
25
#include <map>
25
#include <map>
26
 
26
 
27
#include <boost/shared_ptr.hpp>
27
#include <boost/shared_ptr.hpp>
28
#include <boost/signals2.hpp>
28
#include <boost/signals2.hpp>
29
 
29
 
30
#include <time.h>
30
#include <time.h>
31
 
31
 
32
#include "type/common.h"
32
#include "common/common.h"
33
#include "logging/Logger.h"
33
#include "logging/Logger.h"
-
 
34
 
-
 
35
#include "Code.h"
-
 
36
#include <boost/concept_check.hpp>
34
 
37
 
35
namespace atom {
38
namespace atom {
36
namespace can {
39
namespace control {
37
 
40
 
38
class Node
41
class Node
39
{
42
{
40
public:
43
public:
41
    typedef boost::shared_ptr<Node> Pointer;
44
    typedef boost::shared_ptr<Node> Pointer;
Line 57... Line 60...
57
        STATE_APGM_OFFLINE,
60
        STATE_APGM_OFFLINE,
58
        STATE_APGM_START,
61
        STATE_APGM_START,
59
        STATE_APGM_DATA,
62
        STATE_APGM_DATA,
60
        STATE_APGM_END,
63
        STATE_APGM_END,
61
    } State;
64
    } State;
62
 
65
 
63
    typedef enum
66
    typedef enum
64
    {
67
    {
65
        EVENT_BIOS_START,
68
        EVENT_BIOS_START,
66
        EVENT_APP_START,
69
        EVENT_APP_START,
67
        EVENT_HEARTBEAT,
70
        EVENT_HEARTBEAT,
Line 78... Line 81...
78
   
81
   
79
    Node(Id id);
82
    Node(Id id);
80
    virtual ~Node();
83
    virtual ~Node();
81
   
84
   
82
    static void SetupStateMachine();
85
    static void SetupStateMachine();
83
   
86
   
84
    void ConnectSlots(const SignalOnNewState::slot_type& slot_on_new_state);
87
    void ConnectSlots(const SignalOnNewState::slot_type& slot_on_new_state);
85
   
88
   
86
    Id GetId();
89
    Id GetId();
87
    State GetState();
90
    State GetState();
88
 
91
 
89
    void Trigger(Event event, type::StringMap variables);
92
    void Trigger(Event event, common::StringMap variables);
90
   
93
   
91
    bool CheckTimeout();
94
    bool CheckTimeout();
92
    void ResetTimeout();
95
    void ResetTimeout();
-
 
96
   
-
 
97
    void ProgramApplication(Code::Pointer code);
-
 
98
    void ProgramBios(Code::Pointer code);
93
   
99
   
94
private:
100
private:
95
    typedef std::map<Event, State> Transition;
101
    typedef std::map<Event, State> Transition;
96
    typedef std::map<State, Transition> TransitionList;
102
    typedef std::map<State, Transition> TransitionList;
97
   
103
   
98
    Id id_;
104
    Id id_;
99
    State state_;
105
    State state_;
100
    time_t last_active_;
106
    time_t last_active_;
101
    SignalOnNewState signal_on_new_state_;
107
    SignalOnNewState signal_on_new_state_;
102
    logging::Logger LOG;
108
    logging::Logger LOG;
-
 
109
    Code::Pointer code_;
-
 
110
    unsigned int start_offset_;
-
 
111
    unsigned int current_offset_;
-
 
112
    unsigned int expected_ack_data_;
-
 
113
    time_t program_start_time_;
-
 
114
   
103
   
115
   
104
    static TransitionList transitions_;
116
    static TransitionList transitions_;
-
 
117
    static std::map<State, std::string> state_names_;
-
 
118
    static std::map<Event, std::string> event_names_;
105
   
119
   
106
    static void AddTransition(State current_state, Event event, State target_state);
120
    static void AddTransition(State current_state, Event event, State target_state);
107
   
121
   
108
    State GetTransitionTarget(Event event);
122
    State GetTransitionTarget(Event event);
109
    void SendReset();
123
    void SendReset();
110
    void SendListRequest();
124
    void SendListRequest();
111
};
125
};
112
 
126
 
113
}; // namespace can
127
}; // namespace control
114
}; // namespace atom
128
}; // namespace atom
115
 
129
 
116
#endif // CAN_NODE_H
130
#endif // CONTROL_NODE_H