Ejemplo n.º 1
0
        public void doWork(FSM_Data data)
        {
            switch (data.type)
            {
            case FSM_Type.FSM_SET:
                this.set(data.state);
                break;

            case FSM_Type.FSM_ADV:
                this.advance(data.input);
                break;

            default:
                break;
            }
        }
Ejemplo n.º 2
0
        static public void FSMTest()
        {
            System.Console.WriteLine("\n------------ FSM Phase 1: Explicit Calls ---------------\n");

            FSM myFSM = new FSM();

            myFSM.advance(0);  //a
            myFSM.advance(1);  //b
            myFSM.advance(0);  //e
            myFSM.advance(1);  //a

            myFSM.advance(1);  //b
            myFSM.advance(0);  //e
            myFSM.advance(0);  //c
            myFSM.advance(1);  //e
            myFSM.advance(1);  //a

            myFSM.advance(1);  //b
            myFSM.advance(1);  //c
            myFSM.advance(0);  //d
            myFSM.advance(0);  //d
            myFSM.advance(1);  //b

            myFSM.set(FSM_StateEnum.STATE_C);
            myFSM.advance(0);
            myFSM.advance(0);
            myFSM.advance(0);

            myFSM.set(FSM_StateEnum.STATE_C);
            myFSM.advance(1);
            myFSM.advance(0);
            myFSM.advance(0);

            myFSM.set(FSM_StateEnum.STATE_B);
            myFSM.advance(1);
            myFSM.advance(1);
            myFSM.advance(0);

            myFSM.set(FSM_StateEnum.STATE_D);
            myFSM.advance(1);
            myFSM.advance(0);
            myFSM.advance(1);

            System.Console.WriteLine("\n------------ FSM Phase 2: Data Driven ---------------\n");

            FSM_Data myData;

            myData.input = 0;
            myData.state = FSM_StateEnum.STATE_A;
            myData.type  = FSM_Type.FSM_ADV;

            //myFSM.advance(0);  //a
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myFSM.doWork(myData);

            //myFSM.advance(1);  //b
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myFSM.doWork(myData);

            //myFSM.advance(0);  //e
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myFSM.doWork(myData);

            //myFSM.advance(1);  //a
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myFSM.doWork(myData);

            //myFSM.advance(1);  //b
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myFSM.doWork(myData);

            //myFSM.advance(0);  //e
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myFSM.doWork(myData);

            //myFSM.advance(0);  //c
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myFSM.doWork(myData);

            //myFSM.advance(1);  //e
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myFSM.doWork(myData);

            //myFSM.advance(1);  //a
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myFSM.doWork(myData);

            //myFSM.advance(1);  //b
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myFSM.doWork(myData);

            //myFSM.advance(1);  //c
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myFSM.doWork(myData);

            //myFSM.advance(0);  //d
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myFSM.doWork(myData);

            //myFSM.advance(0);  //d
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myFSM.doWork(myData);

            //myFSM.advance(1);  //b
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myFSM.doWork(myData);

            //myFSM.set(FSM_StateEnum.STATE_C);
            myData.type  = FSM_Type.FSM_SET;
            myData.state = FSM_StateEnum.STATE_C;
            myFSM.doWork(myData);

            //myFSM.advance(0);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myFSM.doWork(myData);

            //myFSM.advance(0);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myFSM.doWork(myData);

            //myFSM.advance(0);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myFSM.doWork(myData);

            //myFSM.set(FSM_StateEnum.STATE_C);
            myData.type  = FSM_Type.FSM_SET;
            myData.state = FSM_StateEnum.STATE_C;
            myFSM.doWork(myData);

            //myFSM.advance(1);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myFSM.doWork(myData);

            //myFSM.advance(0);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myFSM.doWork(myData);

            //myFSM.advance(0);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myFSM.doWork(myData);

            //myFSM.set(FSM_StateEnum.STATE_B);
            myData.type  = FSM_Type.FSM_SET;
            myData.state = FSM_StateEnum.STATE_B;
            myFSM.doWork(myData);

            //myFSM.advance(1);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myFSM.doWork(myData);

            //myFSM.advance(1);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myFSM.doWork(myData);

            //myFSM.advance(0);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myFSM.doWork(myData);

            //myFSM.set(FSM_StateEnum.STATE_D);
            myData.type  = FSM_Type.FSM_SET;
            myData.state = FSM_StateEnum.STATE_D;
            myFSM.doWork(myData);

            //myFSM.advance(1);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myFSM.doWork(myData);

            //myFSM.advance(0);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myFSM.doWork(myData);

            //myFSM.advance(1);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myFSM.doWork(myData);


            System.Console.WriteLine("\n------------ FSM Phase 3: Queued Data Driven ---------------\n");

            System.Collections.Generic.Queue <FSM_Data> myQ_FSM = new System.Collections.Generic.Queue <FSM_Data>();


            myData.input = 0;
            myData.state = FSM_StateEnum.STATE_A;
            myData.type  = FSM_Type.FSM_ADV;

            //myFSM.advance(0);  //a
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(1);  //b
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(0);  //e
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(1);  //a
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(1);  //b
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(0);  //e
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(0);  //c
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(1);  //e
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(1);  //a
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(1);  //b
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(1);  //c
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(0);  //d
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(0);  //d
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(1);  //b
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myQ_FSM.Enqueue(myData);

            //myFSM.set(FSM_StateEnum.STATE_C);
            myData.type  = FSM_Type.FSM_SET;
            myData.state = FSM_StateEnum.STATE_C;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(0);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(0);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(0);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myQ_FSM.Enqueue(myData);

            //myFSM.set(FSM_StateEnum.STATE_C);
            myData.type  = FSM_Type.FSM_SET;
            myData.state = FSM_StateEnum.STATE_C;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(1);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(0);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(0);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myQ_FSM.Enqueue(myData);

            //myFSM.set(FSM_StateEnum.STATE_B);
            myData.type  = FSM_Type.FSM_SET;
            myData.state = FSM_StateEnum.STATE_B;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(1);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(1);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(0);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myQ_FSM.Enqueue(myData);

            //myFSM.set(FSM_StateEnum.STATE_D);
            myData.type  = FSM_Type.FSM_SET;
            myData.state = FSM_StateEnum.STATE_D;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(1);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(0);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 0;
            myQ_FSM.Enqueue(myData);

            //myFSM.advance(1);
            myData.type  = FSM_Type.FSM_ADV;
            myData.input = 1;
            myQ_FSM.Enqueue(myData);


            // Now the queue is NOW filled
            // print the contents
            int count = myQ_FSM.Count;

            for (int i = 0; i < count; i++)
            {
                FSM_Data tmpData = myQ_FSM.Dequeue();
                myFSM.doWork(tmpData);
            }
        }