-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
101 lines (83 loc) · 3.35 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/******************************************************************************
Code
******************************************************************************/
/******************************************************************************
Include files
******************************************************************************/
#include "hsm.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
/******************************************************************************
Function definitions
******************************************************************************/
static state_t topA;
static state_t subA1;
static state_t subA2;
static state_t topB;
static state_t subB1;
static state_t topA = {.itsInitialState = &subA1,
.itsParentState = NULL,
.onEntry = NULL,
.during = NULL,
.onExit = NULL,
.itsTransition = NULL,
.itsTransitionNum = 0,
.itsName = " topA"};
static state_t subA1 = {.itsInitialState = NULL,
.itsParentState = &topA,
.onEntry = NULL,
.during = NULL,
.onExit = NULL,
.itsTransition =
(hsm_transition_t[]){{NULL, NULL, &subA2}},
.itsTransitionNum = 1,
.itsName = "subA1"};
static state_t subA2 = {.itsInitialState = NULL,
.itsParentState = &topA,
.onEntry = NULL,
.during = NULL,
.onExit = NULL,
.itsTransition =
(hsm_transition_t[]){{NULL, NULL, &subB1}},
.itsTransitionNum = 1,
.itsName = "subA2"};
static state_t topB = {.itsInitialState = &subB1,
.itsParentState = NULL,
.onEntry = NULL,
.during = NULL,
.onExit = NULL,
.itsTransition = NULL,
.itsTransitionNum = 0,
.itsName = " topB"};
static state_t subB1 = {.itsInitialState = NULL,
.itsParentState = &topB,
.onEntry = NULL,
.during = NULL,
.onExit = NULL,
.itsTransition =
(hsm_transition_t[]){{NULL, NULL, &subA1}},
.itsTransitionNum = 1,
.itsName = "subB1"};
static state_t* stateList[] = {&topA, &subA1, &subA2, &topB, &subB1};
/**
* \brief This is the starting point of every C program...
* \return Always returns 0. I do not care about OS error reporting.
*/
int main(void)
{
hsm_t sys = hsm_build(&topA, stateList);
/* Greeting */
printf("Hierarchical state machine\nSystem ready...\n\n");
int i = 0;
while (1)
{
/* Handle event */
printf("[%5d] ", ++i);
hsm_handleEvent(&sys, NULL);
char buffer[100];
fgets(&buffer[0], 10, stdin);
}
return 0;
}