typedef enum _APP_STATES {APP_IDLE, APP_SEND, APP_RECEIVE} APP_STATES;
typedef enum _SEND_STATES {SEND_PROCESS_KEY, SEND_HEADER, SEND_MESSAGE, SEND_TERMINATOR} SEND_STATES;
typedef enum _RECEIVE_STATES {RECEIVE_PROCESS_KEY, RECEIVE_HEADER, RECEIVE_MESSAGE} RECEIVE_STATES;
void main(void)
{
char key;
APP_STATES app_state = APP_IDLE;
SEND_STATES send_state = SEND_PROCESS_KEY;
RECEIVE_STATES = receive_state = RECEIVE_PROCESS_KEY;
while(1)
{
switch(app_state)
{
case APP_IDLE:
key = GetKey();
switch(key)
{
case 'S':
app_state = APP_SEND;
break;
case 'R'
app_state = APP_RECEIVE;
break;
}
break;
case APP_SEND:
ProcessSendState();
break;
case APP_RECEIVE:
ProcessReceiveState();
break;
}
}
}
void ProcessSendState(void)
{
switch(send_state)
{
case SEND_PROCESS_KEY:
key = GetKey();
switch(key)
{
case 'H': // Send Header
send_state = SEND_HEADER;
break;
case 'M' // Send Nessage
send_state = SEND_MESSAGE;
break;
case 'T' // Send Terminator
send_state = SEND_TERMINATOR;
break;
case 'Q' // Done sending
app_state = APP_IDLE; // Set App stat eto Idle
break;
}
break;
case SEND_HEADER:
SendHeader();
send_state = SEND_PROCESS_KEY;
break;
case SEND_MESSAGE:
SendMessage();
send_state = SEND_PROCESS_KEY;
break;
case SEND_TERMINATOR
SendTerminator();
send_state = SEND_PROCESS_KEY;
break;
}
}