Code:
enum states { STATE_1, STATE_2, STATE_3, STATE_4, STATE_5, STATE_6, STATE_7, STATE_8, STATE_8, MAX_STATES } current_state;
enum events { EVENT_1, EVENT_2, MAX_EVENTS } new_event;
void action_s1_e1 (INFO *info);
void action_s2_e1 (INFO *info);
void action_s3_e1 (INFO *info);
void action_s4_e1 (INFO *info);
void action_s5_e1 (INFO *info);
void action_s6_e1 (INFO *info);
void action_s7_e1 (INFO *info);
void action_s8_e1 (INFO *info);
void action_s9_e1 (INFO *info);
void action_s2_e2 (INFO *info);
void nothing();
enum events get_new_event (INFO *info);
void (*const state_table [MAX_STATES][MAX_EVENTS]) (INFO *info) = {
{ action_s1_e1}, {nothing},/* procedures for state 1 */
{ nothing}, {action_s2_e2},/* procedures for state 2 */
{ nothing}, {nothing},/* procedures for state 3 */
{ nothing}, {nothing},/* procedures for state 4 */
{ nothing}, {nothing},/* procedures for state 5 */
{ nothing}, {nothing},/* procedures for state 6 */
{ nothing}, {nothing},/* procedures for state 7 */
{ nothing}, {nothing}, /* procedures for state 8 */
{ nothing}, {nothing}/* procedures for state 9 */
};
Can anyone help me figure out this out, is this method called table lookup's?.
Any sugestions why it not working for me. I am not understanding the mapping. The action procedures in my test code above should be, at state 1 run function action_s1_e1, at state 2 run function action_s2_e2.
Function action_s1_e1 runs however function action_s2_e2 does not
I don't think I have the mapping correct because I tested the events enum values sent to state_table function by printing the value which were .0 and 1 which is what it should be.
I found this code at Writing Efficient State Machines in C