From 0c3aa34cbbaf605571e953098964527ca42c8464 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 10 Apr 2013 22:32:08 +0200 Subject: digital/io-hub/src/apbirthday: centralize FSM definitions --- digital/io-hub/src/apbirthday/candles.cc | 5 ---- digital/io-hub/src/apbirthday/main.cc | 5 ---- digital/io-hub/src/apbirthday/robot.cc | 2 +- digital/io-hub/src/apbirthday/top.cc | 11 -------- digital/io-hub/src/common-cc/fsm.hh | 44 +++++++++++++++++++++++++++++++ digital/io-hub/src/common-cc/fsm_queue.cc | 2 +- digital/io-hub/src/common-cc/fsm_queue.hh | 12 +-------- 7 files changed, 47 insertions(+), 34 deletions(-) create mode 100644 digital/io-hub/src/common-cc/fsm.hh diff --git a/digital/io-hub/src/apbirthday/candles.cc b/digital/io-hub/src/apbirthday/candles.cc index 0fd1beb1..daed19eb 100644 --- a/digital/io-hub/src/apbirthday/candles.cc +++ b/digital/io-hub/src/apbirthday/candles.cc @@ -26,11 +26,6 @@ #include "defs.hh" #include "candles.hh" -extern "C" { -#define ANGFSM_NAME AI -#include "angfsm.h" -} - Candles::Candles (int calif_mode) { int i; diff --git a/digital/io-hub/src/apbirthday/main.cc b/digital/io-hub/src/apbirthday/main.cc index bea4ceec..1a7d5f42 100644 --- a/digital/io-hub/src/apbirthday/main.cc +++ b/digital/io-hub/src/apbirthday/main.cc @@ -26,11 +26,6 @@ #include "robot.hh" #include "defs.hh" -extern "C" { -#define ANGFSM_NAME AI -#include "angfsm.h" -} - /// Global team color. TeamColor team_color = TEAM_COLOR_UNKNOWN; diff --git a/digital/io-hub/src/apbirthday/robot.cc b/digital/io-hub/src/apbirthday/robot.cc index cd782ffc..8ed99782 100644 --- a/digital/io-hub/src/apbirthday/robot.cc +++ b/digital/io-hub/src/apbirthday/robot.cc @@ -174,7 +174,7 @@ Robot::fsm_gen_event () // FSM queue. if (fsm_queue.poll ()) { - FsmQueue::Event event = fsm_queue.pop (); + Event event = fsm_queue.pop (); if (ANGFSM_HANDLE_VAR (AI, event)) return true; } diff --git a/digital/io-hub/src/apbirthday/top.cc b/digital/io-hub/src/apbirthday/top.cc index 79b97bc4..71c568ea 100644 --- a/digital/io-hub/src/apbirthday/top.cc +++ b/digital/io-hub/src/apbirthday/top.cc @@ -26,17 +26,6 @@ #include "playground_2013.hh" #include "bot.hh" -extern "C" { -#define ANGFSM_NAME AI -#include "angfsm.h" -} - -#ifdef TARGET_host -typedef unsigned Branch; -#else -typedef angfsm_AI_branch_t Branch; -#endif - #include /// Top context. diff --git a/digital/io-hub/src/common-cc/fsm.hh b/digital/io-hub/src/common-cc/fsm.hh new file mode 100644 index 00000000..300ea62f --- /dev/null +++ b/digital/io-hub/src/common-cc/fsm.hh @@ -0,0 +1,44 @@ +#ifndef fsm_hh +#define fsm_hh +// io-hub - Modular Input/Output. {{{ +// +// Copyright (C) 2013 Nicolas Schodet +// +// APBTeam: +// Web: http://apbteam.org/ +// Email: team AT apbteam DOT org +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// }}} + +extern "C" { +#define ANGFSM_NAME AI +#include "angfsm.h" +} + +#ifdef TARGET_host +typedef unsigned Branch; +#else +typedef angfsm_AI_branch_t Branch; +#endif + +#ifdef TARGET_host +typedef uint16_t Event; +#else +typedef angfsm_AI_event_t Event; +#endif + +#endif // fsm_hh diff --git a/digital/io-hub/src/common-cc/fsm_queue.cc b/digital/io-hub/src/common-cc/fsm_queue.cc index 816d836d..145f700a 100644 --- a/digital/io-hub/src/common-cc/fsm_queue.cc +++ b/digital/io-hub/src/common-cc/fsm_queue.cc @@ -37,7 +37,7 @@ FsmQueue::post (Event e) nb_++; } -FsmQueue::Event +Event FsmQueue::pop () { Event e; diff --git a/digital/io-hub/src/common-cc/fsm_queue.hh b/digital/io-hub/src/common-cc/fsm_queue.hh index 333bea80..5fe9c8cd 100644 --- a/digital/io-hub/src/common-cc/fsm_queue.hh +++ b/digital/io-hub/src/common-cc/fsm_queue.hh @@ -24,21 +24,11 @@ // // }}} #include "ucoolib/common.hh" - -extern "C" { -#define ANGFSM_NAME AI -#include "angfsm.h" -} +#include "fsm.hh" /// Handle asynchronous FSM event queue. class FsmQueue { - public: -#ifdef TARGET_host - typedef uint16_t Event; -#else - typedef angfsm_AI_event_t Event; -#endif public: /// Constructor. FsmQueue (); -- cgit v1.2.3