コード例 #1
0
        /// <summary>
        /// Receives input from the microcontroller (used for acks informing of turn/stop complete).
        /// 
        /// This method is NOT CURRENTLY COMPLETE, due to changes in the specification.
        /// </summary>
        /// <param name="sender">The sending object</param>
        /// <param name="e">The event</param>
        private void serialPort_dataRecieved(object sender, SerialDataReceivedEventArgs e)
        {
            while (myMotors.BytesToRead > 0)
            {
                int b = myMotors.ReadByte();
                switch (state)
                {
                    case 0:
                        if (b == (int)MotorCommands.COMMAND_START) state = 1;
                        break;
                    case 1:
                        switch (b)
                        {
                            case (int)MotorCommands.ACK:
                                receive_ack = "Acknowledged";
                                SendAck a = new SendAck();
                                motorAckRecieve.Post(a);
                                state = 2;
                                break;
                            case (int)MotorCommands.STOP:
                                receive_ack = "STOP Acknowledged";
                                Stop stop = new Stop();
                                motorAckRecieve.Post(stop);
                                StopComplete c = new StopComplete();
                                motorAckRecieve.Post(c);
                                state = 2;
                                break;
                            case (int)MotorCommands.TURN:
                                receive_ack = "TURN Acknowledged";
                                Turn turn = new Turn();
                                motorAckRecieve.Post(turn);
                                state = 2;
                                break;
                            case (int)MotorCommands.MOVE:
                                receive_ack = "MOVE Acknowledged";
                                SetSpeed ss = new SetSpeed();
                                motorAckRecieve.Post(ss);
                                state = 2;
                                break;
                            case (int)MotorCommands.HAS_STOPPED:
                                receive_ack = "Has Stopped";
                                StopComplete sc = new StopComplete();
                                motorAckRecieve.Post(sc);
                                state = 2;
                                break;
                            case (int)MotorCommands.TURN_COMPLETE:
                                receive_ack = "Turn complete in serial handler";
                                TurnComplete tc = new TurnComplete();
                                motorAckRecieve.Post(tc);
                                state = 2;
                                break;
                            case (int)MotorCommands.BUMPER_ACTIVE:
                                bumper.sendBumperNotification();
                                state = 2;
                                break;
                            default:
                                receive_ack = "Unexpected input from motors!";
                                state = 0;
                                break;
                        }
                        Console.WriteLine(receive_ack);
                        break;
                    case 2:
                        if (b == (int)MotorCommands.COMMAND_STOP) state = 0;
//                        motorAckRecieve.Post(a);
                        Console.WriteLine(receive_ack);
                        break;
                    default:
                        state = 0;
                        break;
                }
            }
        }
コード例 #2
0
 public IEnumerator<ITask> SendAckHandler(SendAck s)
 {
     _motor.sendAck();
     yield break;
 }