M
Marian Aldenhövel
Hi,
To handle a custom protocol over a serial line I am trying to implement
a very small and simple state machine. The states are declared as enum:
enum CommState {
CS_WAIT_FOR_STX,
CS_WAIT_FOR_T,
CS_WAIT_FOR_0,
CS_WAIT_FOR_Key,
CS_WAIT_FOR_ETX
};
I wanted to switch on the current state and handle whatever needs to be
done in that state plus the transition to the next one. However, my
switch() is always falling through to the default case.
I have cut down my code to this nonsensical example:
CommState commState=CS_WAIT_FOR_STX;
if (commState==CS_WAIT_FOR_STX) {
std::cout << "commState==CS_WAIT_FOR_STX" << std::endl;
}
switch (commState) {
CS_WAIT_FOR_STX:
std::cout << "switch-label CS_WAIT_FOR_STX" << std::endl;
break;
default:
std::cout << "default" << std::endl;
}
I would have expected this to output
commState==CS_WAIT_FOR_STX
switch-label CS_WAIT_FOR_STX
But I am getting:
commState==CS_WAIT_FOR_STX
default
What am I doing wrong?
The Compiler is GCC 4.2.3, on Ubuntu 7.
Ciao, MM
To handle a custom protocol over a serial line I am trying to implement
a very small and simple state machine. The states are declared as enum:
enum CommState {
CS_WAIT_FOR_STX,
CS_WAIT_FOR_T,
CS_WAIT_FOR_0,
CS_WAIT_FOR_Key,
CS_WAIT_FOR_ETX
};
I wanted to switch on the current state and handle whatever needs to be
done in that state plus the transition to the next one. However, my
switch() is always falling through to the default case.
I have cut down my code to this nonsensical example:
CommState commState=CS_WAIT_FOR_STX;
if (commState==CS_WAIT_FOR_STX) {
std::cout << "commState==CS_WAIT_FOR_STX" << std::endl;
}
switch (commState) {
CS_WAIT_FOR_STX:
std::cout << "switch-label CS_WAIT_FOR_STX" << std::endl;
break;
default:
std::cout << "default" << std::endl;
}
I would have expected this to output
commState==CS_WAIT_FOR_STX
switch-label CS_WAIT_FOR_STX
But I am getting:
commState==CS_WAIT_FOR_STX
default
What am I doing wrong?
The Compiler is GCC 4.2.3, on Ubuntu 7.
Ciao, MM