使用有限状态机解析控制台输入

1.缘起

手头的一款产品即将进入产品阶段。在构建和调试时随意搭建的命令行输入的解析,越来越难以适应最终的部署需求。并且,命令解析已经发展成为一个多字节非定长指令输入,且需要兼顾互联网传递,485半双工模式,也很难适应。有时逻辑会陷入阻塞。

2.可资利用的资源

手头一款几乎是15年前用过的有限状态机编译工具。SMC510.它支持把自定义的状态机伪代码,编译为多种语言的代码。我现在需要编译为C代码。编译器的位置: 

https://download.csdn.net/download/twicave/772570?spm=1001.2014.3001.5503zzhttps://download.csdn.net/download/twicave/772570?spm=1001.2014.3001.5503

这个项目叫“State Machine Compiler” ,作者还在维护,有限状态自动机的概念据说是那个最早提及编程模式的人发明的(好像是Robert Martin,但我很怀疑。),2023年的最新版是7.6。上面提到的5.10版内含例程,更好参考。下方的当前项目链接中,发行包仅包含最简要的信息:

SMC - The State Machine Compiler download | SourceForge.net

3.测试构建伪代码

下面的脚本是参考C目录下的工程写的。编译过程会出错。

// Code based on: Example State Map
//	This state map is recognizes the regular expression 0*1*.
//
// Code Writer: twicave
//
// First Version: V1.0.20230815
//

%start Map1::Start
%class ConsoleCmd
%header ConsoleCmd.h

%map Map1
%%
// State		Transition		End State		Action(s)
Start
{
				Key_R			ReadRegister    {}
				Key_W			WriteRegister   {}
				Key_D			DoWork			{}
				Key_?			Start			{ShowUsage();}
				Key_T           TestMode        {}
				Key_Other       Start           {}
}

ReadRegister
{
				Key_G			ReadGlobalVariable  {}
				Key_T			ReadTempValues		{}
				Key_?           Start               {ShowReadRegisterUsage();}
				Key_Other       Start               {}
}

ReadGlobalVariable
{
				Key_0		    Start			{ShowVolRatio();}
				Key_1			Start			{ShowCurrRatio();}
				Key_2           Start           {ShowTickInus();}
				Key_?           Start           {ShowReadGlobalVariableUsage();}
				Key_Other       Start           {}
				
}

ReadTempValues
{
                Key_0           Start          {ShowAdCh();}
                Key_1           Start          {ShowLastVol();}
                Key_2           Start          (ShowLastCurr();}
                Key_3           Start          {ShowLastS();}
                Key_4           Start          {ShowSampleCache();}
                Key_?           Start          {ShowReadTempValuesUsage();}
                Key_Other       Start          {}
}

TestMode   
{
                Key_?           Start          {ShowTestModeUsage();}
                Key_Other       Start          {}
}

DoWork
{
				KeyS			Start			{DoAdSample();}
				KeyE    		Start			{DoEdgeMeasure();}
				KeyD			Start			{DoDigitalVariableEdgeMeasure();}
				Key_?           Start           {ShowReadTempValuesUsage();}
                Key_Other       Start           {}
}

%%

4.编译

D:\git2023\20230815_有限状态机实现菜单系统\smc_5_1_0>java -jar bin/Smc.jar -c -g ../ConsoleCmd.sm
../ConsoleCmd.sm:49: error - Unknown token (token: Key_)

D:\git2023\20230815_有限状态机实现菜单系统\smc_5_1_0>java -jar bin/Smc.jar -c -g ../ConsoleCmd.sm
../ConsoleCmd.sm:49: error - Unknown token (token: Key_)

D:\git2023\20230815_有限状态机实现菜单系统\smc_5_1_0>java -jar bin/Smc.jar -c -g ../ConsoleCmd.sm
../ConsoleCmd.sm:76: error - A '{' must proceed any action definitions.

D:\git2023\20230815_有限状态机实现菜单系统\smc_5_1_0>java -jar bin/Smc.jar -c -g ../ConsoleCmd.sm
../ConsoleCmd.sm:47: error - no such state as "WriteRegister".

D:\git2023\20230815_有限状态机实现菜单系统\smc_5_1_0>java -jar bin/Smc.jar -c -g ../ConsoleCmd.sm

D:\git2023\20230815_有限状态机实现菜单系统\smc_5_1_0>

4.1 修改后的脚本:

它的命名有要求。另外也有必要的语法检查。这个修改过的脚本仍然有问题,因为信号的传递无视当前状态,所以,每个状态,都必须对所有的信号进行处理。但据说语法规则里有Default信号的处理。

%start Map1::Start
%class ConsoleCmd
%header ConsoleCmd.h

%map Map1
%%
// State		Transition		End State		Action(s)
Start
{
				KeyR			ReadRegister     {ClearAddr();}
				KeyW			WriteRegister    {ClearAddr();}
				KeyHelp			Start			 {ShowUsage();}
				KeyD            DoWork           {ClearValues();}
				KeyT            TestMode         {ClearValues();}
				KeyOther        Start            {}
}

ReadRegister
{
				Key0			ReadRegister     {PushAddr(0);}
                Key1            ReadRegister     {PushAddr(1);}
                Key2            ReadRegister     {PushAddr(2);}
                Key3            ReadRegister     {PushAddr(3);}
                Key4            ReadRegister     {PushAddr(4);}
                Key5            ReadRegister     {PushAddr(5);}
                Key6            ReadRegister     {PushAddr(6);}
                Key7            ReadRegister     {PushAddr(7);}
                Key8            ReadRegister     {PushAddr(8);}
                Key9            ReadRegister     {PushAddr(9);}
                KeyWarning      Start            {}
                KeyComma        ReadRegister     {ShowRegisterValue();}
                KeyHelp         ReadRegister     {ShowRegisterName();} 
				KeyOther        Start            {ShowErrorInput();}
}

WriteRegister
{
                Key0            WriteRegister     {PushAddr(0);}
                Key1            WriteRegister     {PushAddr(1);}
                Key2            WriteRegister     {PushAddr(2);}
                Key3            WriteRegister     {PushAddr(3);}
                Key4            WriteRegister     {PushAddr(4);}
                Key5            WriteRegister     {PushAddr(5);}
                Key6            WriteRegister     {PushAddr(6);}
                Key7            WriteRegister     {PushAddr(7);}
                Key8            WriteRegister     {PushAddr(8);}
                Key9            WriteRegister     {PushAddr(9);}
                KeyComma        WriteValues       {ClearValues();}
                KeyWarning      Start             {}
				KeyOther        Start             {ShowErrorInput();}
}

WriteValues
{
                Key0            WriteValues     {PushValues(1);}
                Key1            WriteValues     {PushValues(1);}
                Key2            WriteValues     {PushValues(2);}
                Key3            WriteValues     {PushValues(3);}
                Key4            WriteValues     {PushValues(4);}
                Key5            WriteValues     {PushValues(5);}
                Key6            WriteValues     {PushValues(6);}
                Key7            WriteValues     {PushValues(7);}
                Key8            WriteValues     {PushValues(8);}
                Key9            WriteValues     {PushValues(9);}
                KeyComma        WriteValues     {WriteRegister();ClearValues();AddrStepIn();}
                KeyDot          WriteValues     {PushValues('.');}
                KeySharp        Start           {WriteRegister();}
                KeyWarning      Start           {}
				KeyOther        Start           {ShowErrorInput();}
}

TestMode   
{
				Key0			TestMode     {PushValues(0);}
				Key1			TestMode	 {PushValues(1);}
                Key2            TestMode     {PushValues(2);}
                Key3            TestMode     {PushValues(3);}
                Key4            TestMode     {PushValues(4);}
                Key5            TestMode     {PushValues(5);}
                Key6            TestMode     {PushValues(6);}
                Key7            TestMode     {PushValues(7);}
                Key8            TestMode     {PushValues(8);}
                Key9            TestMode     {PushValues(9);}
                KeyWarning      Start        {}
                KeyComma        Start           {DoTest();}
                KeyHelp         ReadRegister     {ShowTestItemInfo();} 
				KeyOther        Start            {ShowErrorInput();}
}

DoWork
{
				Key0			DoWork     {PushValues(0);}
				Key1			DoWork	   {PushValues(1);}
                Key2            DoWork     {PushValues(2);}
                Key3            DoWork     {PushValues(3);}
                Key4            DoWork     {PushValues(4);}
                Key5            DoWork     {PushValues(5);}
                Key6            DoWork     {PushValues(6);}
                Key7            DoWork     {PushValues(7);}
                Key8            DoWork     {PushValues(8);}
                Key9            DoWork     {PushValues(9);}
                KeyWarning      Start            {}
                KeyComma        ReadRegister     {DoWork();}
                KeyHelp         ReadRegister     {ShowDoItemInfo();} 
				KeyOther        Start            {ShowErrorInput();}
}

%%

5.使用 

最终的源代码包含五部分:

  • StateMap.h //固定不变
  • XXXXX_sm.h //自动生成的代码
  • XXXXX_sm.c //自动生成的代码
  • XXXXX.h  你需要.sm缺失的函数接口补充进这个头文件中。
  • XXXXX.c

最后的两个文件,是需要用户自行提供的,依据上面的.sm脚本文件,它会包括在.sm中提及的一些用户自定义函数,比如

void PushValues(),

但是所有的函数都会自动增加一个Object的指针,指针指向你自己创建的类实例,你可以把相关的数据存储在那里,备调用。

5.1最终的调用

最终的调用代码大概是这么几步:

1.初始化。

extern void ConsoleCmdContext_Init(struct ConsoleCmdContext*, struct ConsoleCmd*);

它的第一个参数隶属smc自己构建的对象。第二个参数是用户维护的对象。用来暂存数据。


2.激发事件:就是 Ky0, Key7之类的事件:

extern void ConsoleCmdContext_Key0(struct ConsoleCmdContext*);

5.2嵌入式平台减少代码尺寸的优化建议:

//嵌入式平台,减少代码尺寸的必要修改:

//可以用自定义的可变参数函数将printf消掉,它的尺寸太大了
#define TRACE printf

//可以把下面的name干掉。无需Trace.
#define STATE_MEMBERS \
    const char *_name; \
    int _id;

//这里的调试用途的transition字符串统统可以消掉
#define setTransition(fsm, transition) \
    (fsm)->_transition = (transition)
#define getTransition(fsm) \
    (fsm)->_transition

7.10版新加了一个编译开关,可以整体把调试语句干掉。自己编写一个printf桩函数很容易。 

5.3 结果

我没有走通,各位。

我想把这个东东集成进一个嵌入式芯片里,编译器报了一个fatal error,平时4G内存就足够的虚拟机,内存加到8G另外又加了4G虚拟内存,才刚刚能不至内存耗尽。

我还在和编译器厂商沟通,了解那个错误是什么。这个模块的的代码编译没有问题。怀疑最终的问题出在比如内存空间的限制这类的地方。后续有结果,我再修订这个帖子。这里有一个锚点,有兴趣的同志可以关注实时进度:

https://forum.microchip.com/s/topic/a5C3l000000BqRgEAK/t391663

这个代码生成器,做的可以。值得在工作中试用。甚至模仿着来对自己工作中经常遇到的一些重复性的工作,自行建模,用python之类的工具构建自己的代码生成器。


附录A 代码生成器自动生成的可用代码(C格式)

/*
 * DO NOT EDIT.
 * generated by smc (http://smc.sourceforge.net/)
 * from file : ../ConsoleCmd.sm
 */

#ifndef _H_.._CONSOLECMD_SM
#define _H_.._CONSOLECMD_SM

#include <statemap.h>


struct ConsoleCmd;
struct ConsoleCmdContext;

struct ConsoleCmdState
{

    void(*Key0)(struct ConsoleCmdContext*);
    void(*Key1)(struct ConsoleCmdContext*);
    void(*Key2)(struct ConsoleCmdContext*);
    void(*Key3)(struct ConsoleCmdContext*);
    void(*Key4)(struct ConsoleCmdContext*);
    void(*Key5)(struct ConsoleCmdContext*);
    void(*Key6)(struct ConsoleCmdContext*);
    void(*Key7)(struct ConsoleCmdContext*);
    void(*Key8)(struct ConsoleCmdContext*);
    void(*Key9)(struct ConsoleCmdContext*);
    void(*KeyComma)(struct ConsoleCmdContext*);
    void(*KeyD)(struct ConsoleCmdContext*);
    void(*KeyDot)(struct ConsoleCmdContext*);
    void(*KeyHelp)(struct ConsoleCmdContext*);
    void(*KeyOther)(struct ConsoleCmdContext*);
    void(*KeyR)(struct ConsoleCmdContext*);
    void(*KeySharp)(struct ConsoleCmdContext*);
    void(*KeyT)(struct ConsoleCmdContext*);
    void(*KeyW)(struct ConsoleCmdContext*);
    void(*KeyWarning)(struct ConsoleCmdContext*);

    void(*Default)(struct ConsoleCmdContext*);

    STATE_MEMBERS
};

extern const struct ConsoleCmdState Map1_Start;
extern const struct ConsoleCmdState Map1_ReadRegister;
extern const struct ConsoleCmdState Map1_WriteRegister;
extern const struct ConsoleCmdState Map1_WriteValues;
extern const struct ConsoleCmdState Map1_TestMode;
extern const struct ConsoleCmdState Map1_DoWork;

struct ConsoleCmdContext
{
    FSM_MEMBERS(ConsoleCmd)
    struct ConsoleCmd *_owner;
};

extern void ConsoleCmdContext_Init(struct ConsoleCmdContext*, struct ConsoleCmd*);
extern void ConsoleCmdContext_Key0(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_Key1(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_Key2(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_Key3(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_Key4(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_Key5(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_Key6(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_Key7(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_Key8(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_Key9(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_KeyComma(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_KeyD(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_KeyDot(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_KeyHelp(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_KeyOther(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_KeyR(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_KeySharp(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_KeyT(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_KeyW(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_KeyWarning(struct ConsoleCmdContext*);

#endif



extern const struct ConsoleCmdState Map1_Start;
extern const struct ConsoleCmdState Map1_ReadRegister;
extern const struct ConsoleCmdState Map1_WriteRegister;
extern const struct ConsoleCmdState Map1_WriteValues;
extern const struct ConsoleCmdState Map1_TestMode;
extern const struct ConsoleCmdState Map1_DoWork;

struct ConsoleCmdContext
{
    FSM_MEMBERS(ConsoleCmd)
    struct ConsoleCmd *_owner;
};

extern void ConsoleCmdContext_Init(struct ConsoleCmdContext*, struct ConsoleCmd*);
extern void ConsoleCmdContext_Key0(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_Key1(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_Key2(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_Key3(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_Key4(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_Key5(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_Key6(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_Key7(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_Key8(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_Key9(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_KeyComma(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_KeyD(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_KeyDot(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_KeyHelp(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_KeyOther(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_KeyR(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_KeySharp(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_KeyT(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_KeyW(struct ConsoleCmdContext*);
extern void ConsoleCmdContext_KeyWarning(struct ConsoleCmdContext*);

#endif

//------------------ 上为头文件,以下为C源代码 -----------------------
/*
 * DO NOT EDIT.
 * generated by smc (http://smc.sourceforge.net/)
 * from file : ../ConsoleCmd.sm
 */


/* Test */


#include <assert.h>
#include "ConsoleCmd_sm.h"

#define getOwner(fsm) \
    (fsm)->_owner

#define POPULATE_STATE(state) \
    state##_Key0, \
    state##_Key1, \
    state##_Key2, \
    state##_Key3, \
    state##_Key4, \
    state##_Key5, \
    state##_Key6, \
    state##_Key7, \
    state##_Key8, \
    state##_Key9, \
    state##_KeyComma, \
    state##_KeyD, \
    state##_KeyDot, \
    state##_KeyHelp, \
    state##_KeyOther, \
    state##_KeyR, \
    state##_KeySharp, \
    state##_KeyT, \
    state##_KeyW, \
    state##_KeyWarning, \
    state##_Default

#define ENTRY_STATE(state)

#define EXIT_STATE(state)

static void ConsoleCmdState_Key0(struct ConsoleCmdContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void ConsoleCmdState_Key1(struct ConsoleCmdContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void ConsoleCmdState_Key2(struct ConsoleCmdContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void ConsoleCmdState_Key3(struct ConsoleCmdContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void ConsoleCmdState_Key4(struct ConsoleCmdContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void ConsoleCmdState_Key5(struct ConsoleCmdContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void ConsoleCmdState_Key6(struct ConsoleCmdContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void ConsoleCmdState_Key7(struct ConsoleCmdContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void ConsoleCmdState_Key8(struct ConsoleCmdContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void ConsoleCmdState_Key9(struct ConsoleCmdContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void ConsoleCmdState_KeyComma(struct ConsoleCmdContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void ConsoleCmdState_KeyD(struct ConsoleCmdContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void ConsoleCmdState_KeyDot(struct ConsoleCmdContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void ConsoleCmdState_KeyHelp(struct ConsoleCmdContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void ConsoleCmdState_KeyOther(struct ConsoleCmdContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void ConsoleCmdState_KeyR(struct ConsoleCmdContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void ConsoleCmdState_KeySharp(struct ConsoleCmdContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void ConsoleCmdState_KeyT(struct ConsoleCmdContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void ConsoleCmdState_KeyW(struct ConsoleCmdContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void ConsoleCmdState_KeyWarning(struct ConsoleCmdContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void ConsoleCmdState_Default(struct ConsoleCmdContext *fsm)
{
    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : %s.%s\n\r", getName(getState(fsm)), getTransition(fsm));
    }
    State_Default(fsm);
}

#define Map1_Start_Key0 ConsoleCmdState_Key0
#define Map1_Start_Key1 ConsoleCmdState_Key1
#define Map1_Start_Key2 ConsoleCmdState_Key2
#define Map1_Start_Key3 ConsoleCmdState_Key3
#define Map1_Start_Key4 ConsoleCmdState_Key4
#define Map1_Start_Key5 ConsoleCmdState_Key5
#define Map1_Start_Key6 ConsoleCmdState_Key6
#define Map1_Start_Key7 ConsoleCmdState_Key7
#define Map1_Start_Key8 ConsoleCmdState_Key8
#define Map1_Start_Key9 ConsoleCmdState_Key9
#define Map1_Start_KeyComma ConsoleCmdState_KeyComma
#define Map1_Start_KeyD ConsoleCmdState_KeyD
#define Map1_Start_KeyDot ConsoleCmdState_KeyDot
#define Map1_Start_KeyHelp ConsoleCmdState_KeyHelp
#define Map1_Start_KeyOther ConsoleCmdState_KeyOther
#define Map1_Start_KeyR ConsoleCmdState_KeyR
#define Map1_Start_KeySharp ConsoleCmdState_KeySharp
#define Map1_Start_KeyT ConsoleCmdState_KeyT
#define Map1_Start_KeyW ConsoleCmdState_KeyW
#define Map1_Start_KeyWarning ConsoleCmdState_KeyWarning
#define Map1_Start_Default ConsoleCmdState_Default
#define Map1_Start_Entry NULL
#define Map1_Start_Exit NULL
#define Map1_ReadRegister_Key0 ConsoleCmdState_Key0
#define Map1_ReadRegister_Key1 ConsoleCmdState_Key1
#define Map1_ReadRegister_Key2 ConsoleCmdState_Key2
#define Map1_ReadRegister_Key3 ConsoleCmdState_Key3
#define Map1_ReadRegister_Key4 ConsoleCmdState_Key4
#define Map1_ReadRegister_Key5 ConsoleCmdState_Key5
#define Map1_ReadRegister_Key6 ConsoleCmdState_Key6
#define Map1_ReadRegister_Key7 ConsoleCmdState_Key7
#define Map1_ReadRegister_Key8 ConsoleCmdState_Key8
#define Map1_ReadRegister_Key9 ConsoleCmdState_Key9
#define Map1_ReadRegister_KeyComma ConsoleCmdState_KeyComma
#define Map1_ReadRegister_KeyD ConsoleCmdState_KeyD
#define Map1_ReadRegister_KeyDot ConsoleCmdState_KeyDot
#define Map1_ReadRegister_KeyHelp ConsoleCmdState_KeyHelp
#define Map1_ReadRegister_KeyOther ConsoleCmdState_KeyOther
#define Map1_ReadRegister_KeyR ConsoleCmdState_KeyR
#define Map1_ReadRegister_KeySharp ConsoleCmdState_KeySharp
#define Map1_ReadRegister_KeyT ConsoleCmdState_KeyT
#define Map1_ReadRegister_KeyW ConsoleCmdState_KeyW
#define Map1_ReadRegister_KeyWarning ConsoleCmdState_KeyWarning
#define Map1_ReadRegister_Default ConsoleCmdState_Default
#define Map1_ReadRegister_Entry NULL
#define Map1_ReadRegister_Exit NULL
#define Map1_WriteRegister_Key0 ConsoleCmdState_Key0
#define Map1_WriteRegister_Key1 ConsoleCmdState_Key1
#define Map1_WriteRegister_Key2 ConsoleCmdState_Key2
#define Map1_WriteRegister_Key3 ConsoleCmdState_Key3
#define Map1_WriteRegister_Key4 ConsoleCmdState_Key4
#define Map1_WriteRegister_Key5 ConsoleCmdState_Key5
#define Map1_WriteRegister_Key6 ConsoleCmdState_Key6
#define Map1_WriteRegister_Key7 ConsoleCmdState_Key7
#define Map1_WriteRegister_Key8 ConsoleCmdState_Key8
#define Map1_WriteRegister_Key9 ConsoleCmdState_Key9
#define Map1_WriteRegister_KeyComma ConsoleCmdState_KeyComma
#define Map1_WriteRegister_KeyD ConsoleCmdState_KeyD
#define Map1_WriteRegister_KeyDot ConsoleCmdState_KeyDot
#define Map1_WriteRegister_KeyHelp ConsoleCmdState_KeyHelp
#define Map1_WriteRegister_KeyOther ConsoleCmdState_KeyOther
#define Map1_WriteRegister_KeyR ConsoleCmdState_KeyR
#define Map1_WriteRegister_KeySharp ConsoleCmdState_KeySharp
#define Map1_WriteRegister_KeyT ConsoleCmdState_KeyT
#define Map1_WriteRegister_KeyW ConsoleCmdState_KeyW
#define Map1_WriteRegister_KeyWarning ConsoleCmdState_KeyWarning
#define Map1_WriteRegister_Default ConsoleCmdState_Default
#define Map1_WriteRegister_Entry NULL
#define Map1_WriteRegister_Exit NULL
#define Map1_WriteValues_Key0 ConsoleCmdState_Key0
#define Map1_WriteValues_Key1 ConsoleCmdState_Key1
#define Map1_WriteValues_Key2 ConsoleCmdState_Key2
#define Map1_WriteValues_Key3 ConsoleCmdState_Key3
#define Map1_WriteValues_Key4 ConsoleCmdState_Key4
#define Map1_WriteValues_Key5 ConsoleCmdState_Key5
#define Map1_WriteValues_Key6 ConsoleCmdState_Key6
#define Map1_WriteValues_Key7 ConsoleCmdState_Key7
#define Map1_WriteValues_Key8 ConsoleCmdState_Key8
#define Map1_WriteValues_Key9 ConsoleCmdState_Key9
#define Map1_WriteValues_KeyComma ConsoleCmdState_KeyComma
#define Map1_WriteValues_KeyD ConsoleCmdState_KeyD
#define Map1_WriteValues_KeyDot ConsoleCmdState_KeyDot
#define Map1_WriteValues_KeyHelp ConsoleCmdState_KeyHelp
#define Map1_WriteValues_KeyOther ConsoleCmdState_KeyOther
#define Map1_WriteValues_KeyR ConsoleCmdState_KeyR
#define Map1_WriteValues_KeySharp ConsoleCmdState_KeySharp
#define Map1_WriteValues_KeyT ConsoleCmdState_KeyT
#define Map1_WriteValues_KeyW ConsoleCmdState_KeyW
#define Map1_WriteValues_KeyWarning ConsoleCmdState_KeyWarning
#define Map1_WriteValues_Default ConsoleCmdState_Default
#define Map1_WriteValues_Entry NULL
#define Map1_WriteValues_Exit NULL
#define Map1_TestMode_Key0 ConsoleCmdState_Key0
#define Map1_TestMode_Key1 ConsoleCmdState_Key1
#define Map1_TestMode_Key2 ConsoleCmdState_Key2
#define Map1_TestMode_Key3 ConsoleCmdState_Key3
#define Map1_TestMode_Key4 ConsoleCmdState_Key4
#define Map1_TestMode_Key5 ConsoleCmdState_Key5
#define Map1_TestMode_Key6 ConsoleCmdState_Key6
#define Map1_TestMode_Key7 ConsoleCmdState_Key7
#define Map1_TestMode_Key8 ConsoleCmdState_Key8
#define Map1_TestMode_Key9 ConsoleCmdState_Key9
#define Map1_TestMode_KeyComma ConsoleCmdState_KeyComma
#define Map1_TestMode_KeyD ConsoleCmdState_KeyD
#define Map1_TestMode_KeyDot ConsoleCmdState_KeyDot
#define Map1_TestMode_KeyHelp ConsoleCmdState_KeyHelp
#define Map1_TestMode_KeyOther ConsoleCmdState_KeyOther
#define Map1_TestMode_KeyR ConsoleCmdState_KeyR
#define Map1_TestMode_KeySharp ConsoleCmdState_KeySharp
#define Map1_TestMode_KeyT ConsoleCmdState_KeyT
#define Map1_TestMode_KeyW ConsoleCmdState_KeyW
#define Map1_TestMode_KeyWarning ConsoleCmdState_KeyWarning
#define Map1_TestMode_Default ConsoleCmdState_Default
#define Map1_TestMode_Entry NULL
#define Map1_TestMode_Exit NULL
#define Map1_DoWork_Key0 ConsoleCmdState_Key0
#define Map1_DoWork_Key1 ConsoleCmdState_Key1
#define Map1_DoWork_Key2 ConsoleCmdState_Key2
#define Map1_DoWork_Key3 ConsoleCmdState_Key3
#define Map1_DoWork_Key4 ConsoleCmdState_Key4
#define Map1_DoWork_Key5 ConsoleCmdState_Key5
#define Map1_DoWork_Key6 ConsoleCmdState_Key6
#define Map1_DoWork_Key7 ConsoleCmdState_Key7
#define Map1_DoWork_Key8 ConsoleCmdState_Key8
#define Map1_DoWork_Key9 ConsoleCmdState_Key9
#define Map1_DoWork_KeyComma ConsoleCmdState_KeyComma
#define Map1_DoWork_KeyD ConsoleCmdState_KeyD
#define Map1_DoWork_KeyDot ConsoleCmdState_KeyDot
#define Map1_DoWork_KeyHelp ConsoleCmdState_KeyHelp
#define Map1_DoWork_KeyOther ConsoleCmdState_KeyOther
#define Map1_DoWork_KeyR ConsoleCmdState_KeyR
#define Map1_DoWork_KeySharp ConsoleCmdState_KeySharp
#define Map1_DoWork_KeyT ConsoleCmdState_KeyT
#define Map1_DoWork_KeyW ConsoleCmdState_KeyW
#define Map1_DoWork_KeyWarning ConsoleCmdState_KeyWarning
#define Map1_DoWork_Default ConsoleCmdState_Default
#define Map1_DoWork_Entry NULL
#define Map1_DoWork_Exit NULL
#define Map1_DefaultState_Key0 ConsoleCmdState_Key0
#define Map1_DefaultState_Key1 ConsoleCmdState_Key1
#define Map1_DefaultState_Key2 ConsoleCmdState_Key2
#define Map1_DefaultState_Key3 ConsoleCmdState_Key3
#define Map1_DefaultState_Key4 ConsoleCmdState_Key4
#define Map1_DefaultState_Key5 ConsoleCmdState_Key5
#define Map1_DefaultState_Key6 ConsoleCmdState_Key6
#define Map1_DefaultState_Key7 ConsoleCmdState_Key7
#define Map1_DefaultState_Key8 ConsoleCmdState_Key8
#define Map1_DefaultState_Key9 ConsoleCmdState_Key9
#define Map1_DefaultState_KeyComma ConsoleCmdState_KeyComma
#define Map1_DefaultState_KeyD ConsoleCmdState_KeyD
#define Map1_DefaultState_KeyDot ConsoleCmdState_KeyDot
#define Map1_DefaultState_KeyHelp ConsoleCmdState_KeyHelp
#define Map1_DefaultState_KeyOther ConsoleCmdState_KeyOther
#define Map1_DefaultState_KeyR ConsoleCmdState_KeyR
#define Map1_DefaultState_KeySharp ConsoleCmdState_KeySharp
#define Map1_DefaultState_KeyT ConsoleCmdState_KeyT
#define Map1_DefaultState_KeyW ConsoleCmdState_KeyW
#define Map1_DefaultState_KeyWarning ConsoleCmdState_KeyWarning

#undef Map1_Start_KeyD
static void Map1_Start_KeyD(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_Start.KeyD()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_ClearValues(ctxt);
    setState(fsm, &Map1_DoWork);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_Start_KeyHelp
static void Map1_Start_KeyHelp(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_Start.KeyHelp()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_ShowUsage(ctxt);
    setState(fsm, &Map1_Start);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_Start_KeyOther
static void Map1_Start_KeyOther(struct ConsoleCmdContext *fsm)
{

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_Start.KeyOther()\n\r");
    }
    EXIT_STATE(getState(fsm));
    setState(fsm, &Map1_Start);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_Start_KeyR
static void Map1_Start_KeyR(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_Start.KeyR()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_ClearAddr(ctxt);
    setState(fsm, &Map1_ReadRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_Start_KeyT
static void Map1_Start_KeyT(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_Start.KeyT()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_ClearValues(ctxt);
    setState(fsm, &Map1_TestMode);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_Start_KeyW
static void Map1_Start_KeyW(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_Start.KeyW()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_ClearAddr(ctxt);
    setState(fsm, &Map1_WriteRegister);
    ENTRY_STATE(getState(fsm));
}

const struct ConsoleCmdState Map1_Start = { POPULATE_STATE(Map1_Start), "Map1_Start", 0 };

#undef Map1_ReadRegister_Key0
static void Map1_ReadRegister_Key0(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_ReadRegister.Key0()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushAddr(ctxt, 0);
    setState(fsm, &Map1_ReadRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_ReadRegister_Key1
static void Map1_ReadRegister_Key1(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_ReadRegister.Key1()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushAddr(ctxt, 1);
    setState(fsm, &Map1_ReadRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_ReadRegister_Key2
static void Map1_ReadRegister_Key2(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_ReadRegister.Key2()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushAddr(ctxt, 2);
    setState(fsm, &Map1_ReadRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_ReadRegister_Key3
static void Map1_ReadRegister_Key3(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_ReadRegister.Key3()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushAddr(ctxt, 3);
    setState(fsm, &Map1_ReadRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_ReadRegister_Key4
static void Map1_ReadRegister_Key4(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_ReadRegister.Key4()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushAddr(ctxt, 4);
    setState(fsm, &Map1_ReadRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_ReadRegister_Key5
static void Map1_ReadRegister_Key5(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_ReadRegister.Key5()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushAddr(ctxt, 5);
    setState(fsm, &Map1_ReadRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_ReadRegister_Key6
static void Map1_ReadRegister_Key6(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_ReadRegister.Key6()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushAddr(ctxt, 6);
    setState(fsm, &Map1_ReadRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_ReadRegister_Key7
static void Map1_ReadRegister_Key7(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_ReadRegister.Key7()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushAddr(ctxt, 7);
    setState(fsm, &Map1_ReadRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_ReadRegister_Key8
static void Map1_ReadRegister_Key8(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_ReadRegister.Key8()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushAddr(ctxt, 8);
    setState(fsm, &Map1_ReadRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_ReadRegister_Key9
static void Map1_ReadRegister_Key9(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_ReadRegister.Key9()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushAddr(ctxt, 9);
    setState(fsm, &Map1_ReadRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_ReadRegister_KeyComma
static void Map1_ReadRegister_KeyComma(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_ReadRegister.KeyComma()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_ShowRegisterValue(ctxt);
    setState(fsm, &Map1_ReadRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_ReadRegister_KeyHelp
static void Map1_ReadRegister_KeyHelp(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_ReadRegister.KeyHelp()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_ShowRegisterName(ctxt);
    setState(fsm, &Map1_ReadRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_ReadRegister_KeyOther
static void Map1_ReadRegister_KeyOther(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_ReadRegister.KeyOther()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_ShowErrorInput(ctxt);
    setState(fsm, &Map1_Start);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_ReadRegister_KeyWarning
static void Map1_ReadRegister_KeyWarning(struct ConsoleCmdContext *fsm)
{

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_ReadRegister.KeyWarning()\n\r");
    }
    EXIT_STATE(getState(fsm));
    setState(fsm, &Map1_Start);
    ENTRY_STATE(getState(fsm));
}

const struct ConsoleCmdState Map1_ReadRegister = { POPULATE_STATE(Map1_ReadRegister), "Map1_ReadRegister", 1 };

#undef Map1_WriteRegister_Key0
static void Map1_WriteRegister_Key0(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteRegister.Key0()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushAddr(ctxt, 0);
    setState(fsm, &Map1_WriteRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteRegister_Key1
static void Map1_WriteRegister_Key1(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteRegister.Key1()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushAddr(ctxt, 1);
    setState(fsm, &Map1_WriteRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteRegister_Key2
static void Map1_WriteRegister_Key2(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteRegister.Key2()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushAddr(ctxt, 2);
    setState(fsm, &Map1_WriteRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteRegister_Key3
static void Map1_WriteRegister_Key3(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteRegister.Key3()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushAddr(ctxt, 3);
    setState(fsm, &Map1_WriteRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteRegister_Key4
static void Map1_WriteRegister_Key4(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteRegister.Key4()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushAddr(ctxt, 4);
    setState(fsm, &Map1_WriteRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteRegister_Key5
static void Map1_WriteRegister_Key5(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteRegister.Key5()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushAddr(ctxt, 5);
    setState(fsm, &Map1_WriteRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteRegister_Key6
static void Map1_WriteRegister_Key6(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteRegister.Key6()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushAddr(ctxt, 6);
    setState(fsm, &Map1_WriteRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteRegister_Key7
static void Map1_WriteRegister_Key7(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteRegister.Key7()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushAddr(ctxt, 7);
    setState(fsm, &Map1_WriteRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteRegister_Key8
static void Map1_WriteRegister_Key8(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteRegister.Key8()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushAddr(ctxt, 8);
    setState(fsm, &Map1_WriteRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteRegister_Key9
static void Map1_WriteRegister_Key9(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteRegister.Key9()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushAddr(ctxt, 9);
    setState(fsm, &Map1_WriteRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteRegister_KeyComma
static void Map1_WriteRegister_KeyComma(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteRegister.KeyComma()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_ClearValues(ctxt);
    setState(fsm, &Map1_WriteValues);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteRegister_KeyOther
static void Map1_WriteRegister_KeyOther(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteRegister.KeyOther()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_ShowErrorInput(ctxt);
    setState(fsm, &Map1_Start);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteRegister_KeyWarning
static void Map1_WriteRegister_KeyWarning(struct ConsoleCmdContext *fsm)
{

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteRegister.KeyWarning()\n\r");
    }
    EXIT_STATE(getState(fsm));
    setState(fsm, &Map1_Start);
    ENTRY_STATE(getState(fsm));
}

const struct ConsoleCmdState Map1_WriteRegister = { POPULATE_STATE(Map1_WriteRegister), "Map1_WriteRegister", 2 };

#undef Map1_WriteValues_Key0
static void Map1_WriteValues_Key0(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteValues.Key0()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 1);
    setState(fsm, &Map1_WriteValues);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteValues_Key1
static void Map1_WriteValues_Key1(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteValues.Key1()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 1);
    setState(fsm, &Map1_WriteValues);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteValues_Key2
static void Map1_WriteValues_Key2(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteValues.Key2()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 2);
    setState(fsm, &Map1_WriteValues);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteValues_Key3
static void Map1_WriteValues_Key3(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteValues.Key3()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 3);
    setState(fsm, &Map1_WriteValues);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteValues_Key4
static void Map1_WriteValues_Key4(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteValues.Key4()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 4);
    setState(fsm, &Map1_WriteValues);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteValues_Key5
static void Map1_WriteValues_Key5(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteValues.Key5()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 5);
    setState(fsm, &Map1_WriteValues);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteValues_Key6
static void Map1_WriteValues_Key6(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteValues.Key6()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 6);
    setState(fsm, &Map1_WriteValues);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteValues_Key7
static void Map1_WriteValues_Key7(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteValues.Key7()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 7);
    setState(fsm, &Map1_WriteValues);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteValues_Key8
static void Map1_WriteValues_Key8(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteValues.Key8()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 8);
    setState(fsm, &Map1_WriteValues);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteValues_Key9
static void Map1_WriteValues_Key9(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteValues.Key9()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 9);
    setState(fsm, &Map1_WriteValues);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteValues_KeyComma
static void Map1_WriteValues_KeyComma(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteValues.KeyComma()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_WriteRegister(ctxt);
    ConsoleCmd_ClearValues(ctxt);
    ConsoleCmd_AddrStepIn(ctxt);
    setState(fsm, &Map1_WriteValues);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteValues_KeyDot
static void Map1_WriteValues_KeyDot(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteValues.KeyDot()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, '.');
    setState(fsm, &Map1_WriteValues);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteValues_KeyOther
static void Map1_WriteValues_KeyOther(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteValues.KeyOther()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_ShowErrorInput(ctxt);
    setState(fsm, &Map1_Start);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteValues_KeySharp
static void Map1_WriteValues_KeySharp(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteValues.KeySharp()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_WriteRegister(ctxt);
    setState(fsm, &Map1_Start);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_WriteValues_KeyWarning
static void Map1_WriteValues_KeyWarning(struct ConsoleCmdContext *fsm)
{

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_WriteValues.KeyWarning()\n\r");
    }
    EXIT_STATE(getState(fsm));
    setState(fsm, &Map1_Start);
    ENTRY_STATE(getState(fsm));
}

const struct ConsoleCmdState Map1_WriteValues = { POPULATE_STATE(Map1_WriteValues), "Map1_WriteValues", 3 };

#undef Map1_TestMode_Key0
static void Map1_TestMode_Key0(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_TestMode.Key0()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 0);
    setState(fsm, &Map1_TestMode);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_TestMode_Key1
static void Map1_TestMode_Key1(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_TestMode.Key1()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 1);
    setState(fsm, &Map1_TestMode);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_TestMode_Key2
static void Map1_TestMode_Key2(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_TestMode.Key2()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 2);
    setState(fsm, &Map1_TestMode);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_TestMode_Key3
static void Map1_TestMode_Key3(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_TestMode.Key3()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 3);
    setState(fsm, &Map1_TestMode);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_TestMode_Key4
static void Map1_TestMode_Key4(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_TestMode.Key4()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 4);
    setState(fsm, &Map1_TestMode);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_TestMode_Key5
static void Map1_TestMode_Key5(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_TestMode.Key5()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 5);
    setState(fsm, &Map1_TestMode);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_TestMode_Key6
static void Map1_TestMode_Key6(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_TestMode.Key6()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 6);
    setState(fsm, &Map1_TestMode);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_TestMode_Key7
static void Map1_TestMode_Key7(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_TestMode.Key7()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 7);
    setState(fsm, &Map1_TestMode);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_TestMode_Key8
static void Map1_TestMode_Key8(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_TestMode.Key8()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 8);
    setState(fsm, &Map1_TestMode);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_TestMode_Key9
static void Map1_TestMode_Key9(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_TestMode.Key9()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 9);
    setState(fsm, &Map1_TestMode);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_TestMode_KeyComma
static void Map1_TestMode_KeyComma(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_TestMode.KeyComma()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_DoTest(ctxt);
    setState(fsm, &Map1_Start);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_TestMode_KeyHelp
static void Map1_TestMode_KeyHelp(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_TestMode.KeyHelp()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_ShowTestItemInfo(ctxt);
    setState(fsm, &Map1_ReadRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_TestMode_KeyOther
static void Map1_TestMode_KeyOther(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_TestMode.KeyOther()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_ShowErrorInput(ctxt);
    setState(fsm, &Map1_Start);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_TestMode_KeyWarning
static void Map1_TestMode_KeyWarning(struct ConsoleCmdContext *fsm)
{

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_TestMode.KeyWarning()\n\r");
    }
    EXIT_STATE(getState(fsm));
    setState(fsm, &Map1_Start);
    ENTRY_STATE(getState(fsm));
}

const struct ConsoleCmdState Map1_TestMode = { POPULATE_STATE(Map1_TestMode), "Map1_TestMode", 4 };

#undef Map1_DoWork_Key0
static void Map1_DoWork_Key0(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_DoWork.Key0()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 0);
    setState(fsm, &Map1_DoWork);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_DoWork_Key1
static void Map1_DoWork_Key1(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_DoWork.Key1()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 1);
    setState(fsm, &Map1_DoWork);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_DoWork_Key2
static void Map1_DoWork_Key2(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_DoWork.Key2()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 2);
    setState(fsm, &Map1_DoWork);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_DoWork_Key3
static void Map1_DoWork_Key3(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_DoWork.Key3()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 3);
    setState(fsm, &Map1_DoWork);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_DoWork_Key4
static void Map1_DoWork_Key4(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_DoWork.Key4()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 4);
    setState(fsm, &Map1_DoWork);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_DoWork_Key5
static void Map1_DoWork_Key5(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_DoWork.Key5()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 5);
    setState(fsm, &Map1_DoWork);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_DoWork_Key6
static void Map1_DoWork_Key6(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_DoWork.Key6()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 6);
    setState(fsm, &Map1_DoWork);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_DoWork_Key7
static void Map1_DoWork_Key7(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_DoWork.Key7()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 7);
    setState(fsm, &Map1_DoWork);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_DoWork_Key8
static void Map1_DoWork_Key8(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_DoWork.Key8()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 8);
    setState(fsm, &Map1_DoWork);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_DoWork_Key9
static void Map1_DoWork_Key9(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_DoWork.Key9()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_PushValues(ctxt, 9);
    setState(fsm, &Map1_DoWork);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_DoWork_KeyComma
static void Map1_DoWork_KeyComma(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_DoWork.KeyComma()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_DoWork(ctxt);
    setState(fsm, &Map1_ReadRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_DoWork_KeyHelp
static void Map1_DoWork_KeyHelp(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_DoWork.KeyHelp()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_ShowDoItemInfo(ctxt);
    setState(fsm, &Map1_ReadRegister);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_DoWork_KeyOther
static void Map1_DoWork_KeyOther(struct ConsoleCmdContext *fsm)
{
    struct ConsoleCmd* ctxt = getOwner(fsm);

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_DoWork.KeyOther()\n\r");
    }
    EXIT_STATE(getState(fsm));
    clearState(fsm);
    ConsoleCmd_ShowErrorInput(ctxt);
    setState(fsm, &Map1_Start);
    ENTRY_STATE(getState(fsm));
}

#undef Map1_DoWork_KeyWarning
static void Map1_DoWork_KeyWarning(struct ConsoleCmdContext *fsm)
{

    if (getDebugFlag(fsm) != 0) {
        TRACE("TRANSITION   : Map1_DoWork.KeyWarning()\n\r");
    }
    EXIT_STATE(getState(fsm));
    setState(fsm, &Map1_Start);
    ENTRY_STATE(getState(fsm));
}

const struct ConsoleCmdState Map1_DoWork = { POPULATE_STATE(Map1_DoWork), "Map1_DoWork", 5 };

void ConsoleCmdContext_Init(struct ConsoleCmdContext* fsm, struct ConsoleCmd* owner)
{
    FSM_INIT(fsm);
    fsm->_owner = owner;
    setState(fsm, &Map1_Start);
    ENTRY_STATE(&Map1_Start);
}

void ConsoleCmdContext_Key0(struct ConsoleCmdContext* fsm)
{
    const struct ConsoleCmdState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "Key0");
    state->Key0(fsm);
    setTransition(fsm, NULL);
}

void ConsoleCmdContext_Key1(struct ConsoleCmdContext* fsm)
{
    const struct ConsoleCmdState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "Key1");
    state->Key1(fsm);
    setTransition(fsm, NULL);
}

void ConsoleCmdContext_Key2(struct ConsoleCmdContext* fsm)
{
    const struct ConsoleCmdState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "Key2");
    state->Key2(fsm);
    setTransition(fsm, NULL);
}

void ConsoleCmdContext_Key3(struct ConsoleCmdContext* fsm)
{
    const struct ConsoleCmdState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "Key3");
    state->Key3(fsm);
    setTransition(fsm, NULL);
}

void ConsoleCmdContext_Key4(struct ConsoleCmdContext* fsm)
{
    const struct ConsoleCmdState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "Key4");
    state->Key4(fsm);
    setTransition(fsm, NULL);
}

void ConsoleCmdContext_Key5(struct ConsoleCmdContext* fsm)
{
    const struct ConsoleCmdState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "Key5");
    state->Key5(fsm);
    setTransition(fsm, NULL);
}

void ConsoleCmdContext_Key6(struct ConsoleCmdContext* fsm)
{
    const struct ConsoleCmdState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "Key6");
    state->Key6(fsm);
    setTransition(fsm, NULL);
}

void ConsoleCmdContext_Key7(struct ConsoleCmdContext* fsm)
{
    const struct ConsoleCmdState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "Key7");
    state->Key7(fsm);
    setTransition(fsm, NULL);
}

void ConsoleCmdContext_Key8(struct ConsoleCmdContext* fsm)
{
    const struct ConsoleCmdState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "Key8");
    state->Key8(fsm);
    setTransition(fsm, NULL);
}

void ConsoleCmdContext_Key9(struct ConsoleCmdContext* fsm)
{
    const struct ConsoleCmdState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "Key9");
    state->Key9(fsm);
    setTransition(fsm, NULL);
}

void ConsoleCmdContext_KeyComma(struct ConsoleCmdContext* fsm)
{
    const struct ConsoleCmdState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "KeyComma");
    state->KeyComma(fsm);
    setTransition(fsm, NULL);
}

void ConsoleCmdContext_KeyD(struct ConsoleCmdContext* fsm)
{
    const struct ConsoleCmdState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "KeyD");
    state->KeyD(fsm);
    setTransition(fsm, NULL);
}

void ConsoleCmdContext_KeyDot(struct ConsoleCmdContext* fsm)
{
    const struct ConsoleCmdState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "KeyDot");
    state->KeyDot(fsm);
    setTransition(fsm, NULL);
}

void ConsoleCmdContext_KeyHelp(struct ConsoleCmdContext* fsm)
{
    const struct ConsoleCmdState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "KeyHelp");
    state->KeyHelp(fsm);
    setTransition(fsm, NULL);
}

void ConsoleCmdContext_KeyOther(struct ConsoleCmdContext* fsm)
{
    const struct ConsoleCmdState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "KeyOther");
    state->KeyOther(fsm);
    setTransition(fsm, NULL);
}

void ConsoleCmdContext_KeyR(struct ConsoleCmdContext* fsm)
{
    const struct ConsoleCmdState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "KeyR");
    state->KeyR(fsm);
    setTransition(fsm, NULL);
}

void ConsoleCmdContext_KeySharp(struct ConsoleCmdContext* fsm)
{
    const struct ConsoleCmdState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "KeySharp");
    state->KeySharp(fsm);
    setTransition(fsm, NULL);
}

void ConsoleCmdContext_KeyT(struct ConsoleCmdContext* fsm)
{
    const struct ConsoleCmdState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "KeyT");
    state->KeyT(fsm);
    setTransition(fsm, NULL);
}

void ConsoleCmdContext_KeyW(struct ConsoleCmdContext* fsm)
{
    const struct ConsoleCmdState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "KeyW");
    state->KeyW(fsm);
    setTransition(fsm, NULL);
}

void ConsoleCmdContext_KeyWarning(struct ConsoleCmdContext* fsm)
{
    const struct ConsoleCmdState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "KeyWarning");
    state->KeyWarning(fsm);
    setTransition(fsm, NULL);
}

附录B 依赖项 StateMap.h(5.10版)

#ifndef _H_STATEMAP
#define _H_STATEMAP

/*
 * The contents of this file are subject to the Mozilla Public
 * License Version 1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of
 * the License at http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.
 * 
 * The Original Code is State Machine Compiler (SMC).
 * 
 * The Initial Developer of the Original Code is Charles W. Rapp.
 * 
 * Port to C by Francois Perrad, francois.perrad@gadz.org
 * Copyright 2004, Francois Perrad.
 * All Rights Reserved.
 *
 * Contributor(s): 
 *
 * Description
 *
 * RCS ID
 * $Id: statemap.h,v 1.2 2007/08/05 12:58:11 cwrapp Exp $
 *
 * Change Log
 * $Log: statemap.h,v $
 * Revision 1.2  2007/08/05 12:58:11  cwrapp
 * Version 5.0.1 check-in. See net/sf/smc/CODE_README.txt for more information.
 *
 * Revision 1.1  2005/06/16 18:08:17  fperrad
 * Added C, Perl & Ruby.
 *
 */

#include <stdio.h>
#include <string.h>

#define TRACE printf

#define STATE_MEMBERS \
    const char *_name; \
    int _id;

struct State
{
    STATE_MEMBERS
};

#define getName(state) \
    (state)->_name
#define getId(state) \
    (state)->_id

#define State_Default(fsm) \
    assert(0)

#define FSM_MEMBERS(app) \
    const struct app##State * _state; \
    const struct app##State * _previous_state; \
    const struct app##State ** _stack_start; \
    const struct app##State ** _stack_curr; \
    const struct app##State ** _stack_max; \
    const char * _transition; \
    int _debug_flag;

struct FSMContext
{
    FSM_MEMBERS(_)
};

#define FSM_INIT(fsm) \
    (fsm)->_state = NULL; \
    (fsm)->_previous_state = NULL; \
    (fsm)->_stack_start = NULL; \
    (fsm)->_stack_curr = NULL; \
    (fsm)->_stack_max = NULL; \
    (fsm)->_transition = NULL; \
    (fsm)->_debug_flag = 0

#define FSM_STACK(fsm, stack) \
    (fsm)->_stack_start = &(stack)[0]; \
    (fsm)->_stack_curr = &(stack)[0]; \
    (fsm)->_stack_max = &(stack)[0] + (sizeof(stack) / sizeof(void*))


#define getState(fsm) \
    (fsm)->_state
#define clearState(fsm) \
    (fsm)->_previous_state = (fsm)->_state; \
    (fsm)->_state = NULL
#define setState(fsm, state) \
    (fsm)->_state = (state); \
    if ((fsm)->_debug_flag != 0) { \
        TRACE("NEW STATE    : %s\n", getName(state)); \
    }
#define pushState(fsm, state) \
    if ((fsm)->_stack_curr >= (fsm)->_stack_max) { \
        assert(0 == "STACK OVERFLOW"); \
    } \
    *((fsm)->_stack_curr) = (fsm)->_state; \
    (fsm)->_stack_curr ++; \
    (fsm)->_state = state; \
    if ((fsm)->_debug_flag != 0) { \
        TRACE("PUSH TO STATE: %s\n", getName(state)); \
    }
#define popState(fsm) \
    (fsm)->_stack_curr --; \
    (fsm)->_state = *((fsm)->_stack_curr); \
    if ((fsm)->_debug_flag != 0) { \
        TRACE("POP TO STATE : %s\n", getName((fsm)->_state)); \
    }
#define emptyStateStack(fsm) \
    (fsm)->_stack_curr = (fsm)->_stack_start
#define setTransition(fsm, transition) \
    (fsm)->_transition = (transition)
#define getTransition(fsm) \
    (fsm)->_transition
#define getDebugFlag(fsm) \
    (fsm)->_debug_flag
#define setDebugFlag(fsm, flag) \
    (fsm)->_debug_flag = (flag)

#endif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

子正

thanks, bro...

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值