
ch = SBUF;
switch (state) {
    case WAIT_START:
        switch (ch) {
            case 'P': state = GET_P: idx = 0; break;
            case 'D': state = GET_D; idx = 0; break;
            ...
            default:
                ; // continue waiting for a valid command character
        }
        break;
    case WAIT_P:
        if (ch == '.' || ch >= '0' && ch <= '9') {
            if (idx < BUF_SIZE-1) {
                buf[idx++] = ch;
            } else {
                // error somewhere - too much data.
                state = WAIT_START;
            }
        } else {
            // first character not part of number.
            buf[idx] = ' ';
            my_num = atof(buf);
            store_proportional(my_num);
            // wait for new start character
            state = WAIT_START;
        }
        break;
    ...
    default:
        // error - unknown state.
        state = WAIT_START;
}
