/*
Copyright (C) 2010 Mattias Runge
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef CAN_NODE_H
#define CAN_NODE_H
#include <string>
#include <map>
#include <boost/shared_ptr.hpp>
#include <boost/signals2.hpp>
#include <time.h>
#include "type/common.h"
#include "logging/Logger.h"
namespace atom {
namespace can {
class Node
{
public:
typedef boost::shared_ptr<Node> Pointer;
typedef unsigned int Id;
typedef enum
{
STATE_INVALID,
STATE_NO_CHANGE,
STATE_NORM_OFFLINE,
STATE_NORM_ONLINE,
STATE_NORM_LIST,
STATE_NORM_INITIALIZED,
STATE_BPGM_OFFLINE,
STATE_BPGM_START,
STATE_BPGM_DATA,
STATE_BPGM_END,
STATE_BPGM_COPY,
STATE_APGM_OFFLINE,
STATE_APGM_START,
STATE_APGM_DATA,
STATE_APGM_END,
} State;
typedef enum
{
EVENT_BIOS_START,
EVENT_APP_START,
EVENT_HEARTBEAT,
EVENT_PGM_ACK,
EVENT_PGM_NACK,
EVENT_LIST_DONE,
EVENT_PROGRAM_BIOS,
EVENT_PROGRAM_APP,
EVENT_RESET
} Event;
typedef boost::signals2::signal<void(Id, State, State)> SignalOnNewState;
Node(Id id);
virtual ~Node();
static void SetupStateMachine();
void ConnectSlots(const SignalOnNewState::slot_type& slot_on_new_state);
Id GetId();
State GetState();
void Trigger(Event event, type::StringMap variables);
bool CheckTimeout();
void ResetTimeout();
private:
typedef std::map<Event, State> Transition;
typedef std::map<State, Transition> TransitionList;
Id id_;
State state_;
time_t last_active_;
SignalOnNewState signal_on_new_state_;
logging::Logger LOG;
static TransitionList transitions_;
static void AddTransition(State current_state, Event event, State target_state);
State GetTransitionTarget(Event event);
void SendReset();
void SendListRequest();
};
}; // namespace can
}; // namespace atom
#endif // CAN_NODE_H