Subversion Repositories HomeAutomation

Rev

Rev 1601 | Rev 1642 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  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 CAN_NODE_H
  22. #define CAN_NODE_H
  23.  
  24. #include <string>
  25. #include <map>
  26.  
  27. #include <boost/shared_ptr.hpp>
  28. #include <boost/signals2.hpp>
  29.  
  30. #include <time.h>
  31.  
  32. #include "type/common.h"
  33. #include "logging/Logger.h"
  34.  
  35. namespace atom {
  36. namespace can {
  37.  
  38. class Node
  39. {
  40. public:
  41.     typedef boost::shared_ptr<Node> Pointer;
  42.     typedef unsigned int Id;
  43.    
  44.     typedef enum
  45.     {
  46.         STATE_INVALID,
  47.         STATE_NO_CHANGE,
  48.         STATE_NORM_OFFLINE,
  49.         STATE_NORM_ONLINE,
  50.         STATE_NORM_LIST,
  51.         STATE_NORM_INITIALIZED,
  52.         STATE_BPGM_OFFLINE,
  53.         STATE_BPGM_START,
  54.         STATE_BPGM_DATA,
  55.         STATE_BPGM_END,
  56.         STATE_BPGM_COPY,
  57.         STATE_APGM_OFFLINE,
  58.         STATE_APGM_START,
  59.         STATE_APGM_DATA,
  60.         STATE_APGM_END,
  61.     } State;
  62.  
  63.     typedef enum
  64.     {
  65.         EVENT_BIOS_START,
  66.         EVENT_APP_START,
  67.         EVENT_HEARTBEAT,
  68.         EVENT_PGM_ACK,
  69.         EVENT_PGM_NACK,
  70.         EVENT_LIST_DONE,
  71.         EVENT_PROGRAM_BIOS,
  72.         EVENT_PROGRAM_APP,
  73.         EVENT_RESET
  74.     } Event;
  75.    
  76.     typedef boost::signals2::signal<void(Id, State, State)> SignalOnNewState;
  77.    
  78.    
  79.     Node(Id id);
  80.     virtual ~Node();
  81.    
  82.     static void SetupStateMachine();
  83.    
  84.     void ConnectSlots(const SignalOnNewState::slot_type& slot_on_new_state);
  85.    
  86.     Id GetId();
  87.     State GetState();
  88.  
  89.     void Trigger(Event event, type::StringMap variables);
  90.    
  91.     bool CheckTimeout();
  92.     void ResetTimeout();
  93.    
  94. private:
  95.     typedef std::map<Event, State> Transition;
  96.     typedef std::map<State, Transition> TransitionList;
  97.    
  98.     Id id_;
  99.     State state_;
  100.     time_t last_active_;
  101.     SignalOnNewState signal_on_new_state_;
  102.     logging::Logger LOG;
  103.    
  104.     static TransitionList transitions_;
  105.    
  106.     static void AddTransition(State current_state, Event event, State target_state);
  107.    
  108.     State GetTransitionTarget(Event event);
  109.     void SendReset();
  110.     void SendListRequest();
  111. };
  112.  
  113. }; // namespace can
  114. }; // namespace atom
  115.  
  116. #endif // CAN_NODE_H
  117.