Created
May 2, 2022 09:00
-
-
Save tuanpmt/2b8958bae06befbd24f2f2ab8409854d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define AWAIT(a) if (a != OK) continue; | |
status_t _connect(state_t *state) | |
{ | |
if (state >= CONNECTED) { | |
return OK; | |
} | |
// do connect, return FAIL if failed | |
state = CONNECTED; | |
return OK; | |
} | |
status_t _register(state_t *state) | |
{ | |
if (state < CONNECTED) { | |
return FAIL; | |
} | |
if (state > CONNECTED) { | |
return OK; | |
} | |
// do register, return FAIL if failed | |
state = DATA; | |
return OK; | |
} | |
status_t _exchange_data(state_t *state) | |
{ | |
if (state != DATA) { | |
return FAIL; | |
} | |
return OK; | |
} | |
void main() { | |
state_t state = INITILIZED; | |
while (true) { | |
AWAIT(_connect(&state)); | |
AWAIT(_register(&state)); | |
AWAIT(_exchange_data(&state)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment