促进MSM EUML融合问题

boost msm euml fusion issue

本文关键字:问题 融合 EUML MSM 促进      更新时间:2023-10-16

我实际上正在使用eUML在boost::msm中工作,这确实是一件很棒的事情,我之前用它创建了一些更简单的FSM。

但是,我面临着一个我无法解决的问题,所以我希望在这里得到一些帮助。

代码相当简单(但有点长 - 见本文末尾)。问题位于转换表中,即某些人误导了:

BOOST_MSM_EUML_TRANSITION_TABLE ((
  state_entryPrimary == state_init  [ fsm_(FsmNo) == Int_<fsm_primary>() ]   ,
  state_entrySecondary == state_init  [ fsm_(FsmNo) == Int_<fsm_secondary>() ] ,
  state_1 == state_entryPrimary [ fsm_(uStatus) == Int_<statid_1>() ],
  state_2 == state_entryPrimary [ fsm_(uStatus) == Int_<statid_3>() ], //!!!!!
  state_3 == state_entryPrimary [ fsm_(uStatus) == Int_<statid_4>() ],
  state_6 == state_entryPrimary [ fsm_(uStatus) == Int_<statid_2>() ],
  state_4 == state_1 + event_1,
  state_5 == state_4 + event_2,
  state_1 == state_3 + event_3,
  state_7 == state_6 + event_4,
  state_exit == state_5 + event_9,
  state_exit == state_7 + event_9
), my_transition_table)

我收到了一条很长的错误消息,其中包含 g++ 5.4.0 和基于一些无法构建代码的融合代码的 boost 1.58。第一个错误行如下所示:

/usr/include/boost/fusion/container/set/convert.hpp:27:13: error: invalid use of incomplete type ‘struct boost::fusion::detail::barrier::as_set<11>’

万一,我注释掉标有//的行!!!!, FSM 编译没有任何问题。

有人在那里,谁能帮忙?

#include <boost/msm/front/euml/euml.hpp>
#include <boost/msm/front/euml/state_grammar.hpp>
#include <boost/msm/back/state_machine.hpp>
#include <boost/msm/front/euml/operator.hpp>
#include <iostream>
namespace msm = boost::msm;
using namespace boost::msm::front::euml;
using namespace msm::front::euml;
enum UStatusType {
    statid_1,
    statid_2,
    statid_3,
    statid_4
};
enum FsmType {
    fsm_primary,
    fsm_secondary
};
BOOST_MSM_EUML_DECLARE_ATTRIBUTE(UStatusType, uStatus)
BOOST_MSM_EUML_DECLARE_ATTRIBUTE(FsmType, FsmNo)
BOOST_MSM_EUML_DECLARE_ATTRIBUTE(int, cnt)
BOOST_MSM_EUML_ACTION(act_do_a) { 
  template <class Evt,class Fsm, class State> void operator()(Evt const& ,Fsm& fsm, State& state ) const
    { std::cout << " -> do a " << std::endl; } 
};
BOOST_MSM_EUML_ACTION(act_do_b) {
  template <class Evt,class Fsm, class State> void operator()(Evt const& ,Fsm& fsm, State& state ) const
    { std::cout << " -> do b " << std::endl; }
};
BOOST_MSM_EUML_STATE((), state_init)
BOOST_MSM_EUML_STATE((act_do_b), state_exit)
BOOST_MSM_EUML_STATE((), state_entryPrimary)
BOOST_MSM_EUML_STATE((act_do_a), state_1)
BOOST_MSM_EUML_STATE((act_do_a), state_2)
BOOST_MSM_EUML_STATE((act_do_a), state_3)
BOOST_MSM_EUML_STATE((act_do_a), state_4)
BOOST_MSM_EUML_STATE((act_do_a), state_5)
BOOST_MSM_EUML_STATE((act_do_a), state_6)
BOOST_MSM_EUML_STATE((act_do_a), state_7)
BOOST_MSM_EUML_STATE((), state_entrySecondary)
BOOST_MSM_EUML_EVENT(event_1)
BOOST_MSM_EUML_EVENT(event_2)
BOOST_MSM_EUML_EVENT(event_3)
BOOST_MSM_EUML_EVENT(event_4)
BOOST_MSM_EUML_EVENT(event_9)

BOOST_MSM_EUML_TRANSITION_TABLE ((
  state_entryPrimary == state_init  [ fsm_(FsmNo) == Int_<fsm_primary>() ]   ,
  state_entrySecondary == state_init  [ fsm_(FsmNo) == Int_<fsm_secondary>() ] ,
  state_1 == state_entryPrimary [ fsm_(uStatus) == Int_<statid_1>() ],
  state_2 == state_entryPrimary [ fsm_(uStatus) == Int_<statid_3>() ], //!!!!!
  state_3 == state_entryPrimary [ fsm_(uStatus) == Int_<statid_4>() ],
  state_6 == state_entryPrimary [ fsm_(uStatus) == Int_<statid_2>() ],
  state_4 == state_1 + event_1,
  state_5 == state_4 + event_2,
  state_1 == state_3 + event_3,
  state_7 == state_6 + event_4,
  state_exit == state_5 + event_9,
  state_exit == state_7 + event_9
), my_transition_table)
BOOST_MSM_EUML_DECLARE_STATE_MACHINE((my_transition_table, init_ << state_init, no_action, no_action, 
    attributes_ << FsmNo << uStatus << cnt ), my_fsm)
int main()
{
  msm::back::state_machine<my_fsm> my;
  // testing some start conditions
  my.get_attribute(uStatus) = statid_1; // read from device
  my.get_attribute(FsmNo) = fsm_primary;
  my.get_attribute(cnt) = 1;
  my.start(); 
  my.process_event(event_1);
  my.process_event(event_2);
  my.process_event(event_9);
  std::cout << "nRestart Statemachine with statid_3nn";
  my.get_attribute(uStatus) = statid_3;
  my.start();
  my.process_event(event_3);
  std::cout << "nRestart Statemachine with statid_2nn";
  my.get_attribute(uStatus) = statid_2;
  my.start();
  my.process_event(event_4);
  my.process_event(event_9);
}

在包含部分之前定义您需要的任何内容FUSION_MAX_VECTOR_SIZE。如果转换表超过 20 个条目,则必须添加以下定义:

#define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
#define BOOST_MPL_LIMIT_VECTOR_SIZE 30 //max table size                   
#define BOOST_MPL_LIMIT_MAP_SIZE 30 //max table size   

http://www.boost.org/doc/libs/1_63_0/libs/msm/doc/HTML/ch03s02.html#d0e358