-
Notifications
You must be signed in to change notification settings - Fork 0
/
statemachine.c
63 lines (53 loc) · 1.7 KB
/
statemachine.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
#include "statemachine.h"
void transition(state_machine* st, unsigned char* frame, int len, unsigned char A, unsigned char C){
for (int i = 0; i < len; i++){
unsigned char trans = frame[i];
switch(st->current_state){
case START:
if (trans == FLAG){
st->current_state = FLAG_RCV;
continue;
}
continue;
case FLAG_RCV:
if (trans == FLAG) continue;;
if (trans == A){
st->current_state = A_RCV;
continue;
}
st->current_state = START;
continue;
case A_RCV:
if (trans == FLAG){
st->current_state = FLAG_RCV;
continue;
}
else if (trans == C){
st->current_state = C_RCV;
continue;
}
st->current_state = START;
continue;
case C_RCV:
if (trans == FLAG){
st->current_state = START;
continue;
}
else if (trans == (A^C)){
st->current_state = BCC_OK;
continue;
}
st->current_state = START;
continue;
case BCC_OK:
if (trans == FLAG){
st->current_state = STATE_STOP;
continue;
}
st->current_state = START;
continue;
default:
continue;
}
}
}