#include "stdafx.h" #include <stdio.h> #include <string.h> #include <math.h> #include<stdlib.h> #include <dos.h> #include <conio.h> typedef enum _Cicurt_State { Cicuit_Init_State, open_circuit_State, short_cicuit_State, thoroughfare_State, }Cicurt_State; typedef struct _Cicurt { Cicurt_State cicurt_state; int Plain_conductor; int electronic_parts; int electricals; }Cicurt; typedef enum _Cicurt_Event { Plain_conductor_open_circuit_Event, Plain_conductor_short_cicuit_Event, Plain_conductor_thoroughfare_State, electronic_parts_open_circuit_Event, electronic_parts_short_cicuit_Event, electronic_parts_thoroughfare_State, electricals_open_circuit_Event, electricals_short_cicuit_Event, electricals_thoroughfare_State_Event, }Cicurt_Event; typedef struct _Fsm_Table { Cicurt_Event cicurt_event; void(*Event_Process)(Cicurt_Event cicurt_event, Cicurt_State cicurt_state); }Fsm_Table; static void Plain_conductor_Event_Process(Cicurt_Event cicurt_event, Cicurt_State cicurt_state) { int* Plain_conductor_Cicurt_state = (int*)&cicurt_state; switch (*Plain_conductor_Cicurt_state) { case Cicuit_Init_State: break; case open_circuit_State: break; case short_cicuit_State: break; case thoroughfare_State: break; } } static void electronic_parts_Event_Process(Cicurt_Event cicurt_event, Cicurt_State cicurt_state) { int* electronic_parts_Cicurt_state = (int*)&cicurt_state; switch (*electronic_parts_Cicurt_state) { case Cicuit_Init_State: break; case open_circuit_State: break; case short_cicuit_State: break; case thoroughfare_State: break; } } static void electricals_Event_Process(Cicurt_Event cicurt_event, Cicurt_State cicurt_state) { int* electricals_state = (int*)&cicurt_state; switch (*electricals_state) { case Cicuit_Init_State: break; case open_circuit_State: break; case short_cicuit_State: break; case thoroughfare_State: break; } } static Fsm_Table fsm_Table[] = { { Plain_conductor_open_circuit_Event,Plain_conductor_Event_Process}, { Plain_conductor_short_cicuit_Event,Plain_conductor_Event_Process}, { Plain_conductor_thoroughfare_State,Plain_conductor_Event_Process}, { electronic_parts_open_circuit_Event,electronic_parts_Event_Process }, { electronic_parts_short_cicuit_Event,electronic_parts_Event_Process }, { electronic_parts_thoroughfare_State,electronic_parts_Event_Process }, { electricals_open_circuit_Event,electricals_Event_Process }, { electricals_short_cicuit_Event,electricals_Event_Process }, { electricals_thoroughfare_State_Event,electricals_Event_Process }, }; static Cicurt_Event getCicurt_Event(Cicurt_Event cicurt_Event) { return cicurt_Event; } int main() { Cicurt_State cicurt_state = Cicuit_Init_State; Cicurt_Event cicurt_Event = electricals_open_circuit_Event; cicurt_Event = getCicurt_Event(cicurt_Event); for (int i = 0; i < sizeof(fsm_Table) / sizeof(Fsm_Table);i++) { if (fsm_Table[i].cicurt_event == cicurt_Event) { fsm_Table[i].Event_Process(cicurt_Event, Cicuit_Init_State); } } while (1); return 0; }