-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.c
81 lines (69 loc) · 1.72 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
/*
* It's a Use-Case to smartfsm, write by Shanjin Yang.
* Email: sjyangv0@gmail.com
*
*/
#include "fsm.h"
#define wakeup_state 1
#define asr_state 2
#define tts_state 3
#define comm_state 4
#define sock_state 5
void wakeup_state_func(void *arg)
{
char *message = (char *)arg;
if (message != NULL)
printf("%s: %s\n", __func__, message);
state_tran(asr_state, "wakeup end message");
}
void asr_state_func(void *arg)
{
char *message = (char *)arg;
if (message != NULL)
printf("%s: %s\n", __func__, message);
state_tran(tts_state, "asr end message");
}
void tts_state_func(void *arg)
{
char *message = (char *)arg;
if (message != NULL)
printf("%s: %s\n", __func__, message);
state_tran(wakeup_state, NULL);
}
void comm_state_func(void *arg)
{
char *message = (char *)arg;
if (message != NULL)
printf("%s: %s\n", __func__, message);
state_tran(10, "ten message");
}
void sock_state_func(void *arg)
{
char *message = (char *)arg;
if (message != NULL)
printf("%s: %s\n", __func__, message);
state_tran(10, "ten message");
}
void func_default(void *arg)
{
char *message = (char *)arg;
if (message != NULL)
printf("default: %s\n", message);
state_tran(wakeup_state, "default message");
}
FSM user_app[5] = {
{wakeup_state, wakeup_state_func, "name_one"},
{asr_state, asr_state_func, "name_two"},
{tts_state, tts_state_func, "name_three"},
{comm_state, comm_state_func, "name_three"},
{sock_state, sock_state_func, "name_three"},
};
int main()
{
SET_STATE_DEFAULT_FUNC(func_default);
state_init(user_app[0].state, user_app[0].func, user_app[0].name);
state_add(user_app[1].state, user_app[1].func, user_app[1].name);
state_add(user_app[2].state, user_app[2].func, user_app[2].name);
fsm_while(fsm_obj);
return 0;
}