Beispiel #1
0
        private void BuggyDisconnectBtn_Click(object sender, EventArgs e)
        {
            //Disable button to prevent multiple disconnection requests.
            buggyDisconnectBtn.Enabled = false;

            //Send message to server to notify that the controller client is disconnecting from the buggy and that it is available for connections again.
            MessageHandler.BuggyDisconnect();

            //Wait until disconnection finishes before continuing with enabling/disabling buggy controls.
            while (ConnectionManager.buggyConnected)
            {
            }

            //Enable buggy connect button
            buggyConnectBtn.Enabled = true;

            //Disable buggy controls
            comboBoxIntMode.Enabled       = false;
            comboBoxConfig.Enabled        = false;
            ManualControlFocusBtn.Enabled = false;
            textBoxConfigStatus.Enabled   = false;
            textBoxCurrConfig.Enabled     = false;
            buttonConfigUpdate.Enabled    = false;
            comboBoxNewConfig.Enabled     = false;
            TempTextBox.Enabled           = false;
            HumTextBox.Enabled            = false;
            LIntTextBox.Enabled           = false;
            buttonReqData.Enabled         = false;

            //Don't record motor control inputs and don't send them to the buggy as requests
            BuggyMotorControl.PauseMotorControl();

            //Display disconnection status.
            textBoxBuggyConnectStatus.Text = "Disconnected";
        }
Beispiel #2
0
        private void comboBoxIntMode_SelectedIndexChanged(object sender, EventArgs e)
        {
            /*
             * Enable or disable buggy controls based on the interaction mode selected.
             * Set boolean that enables motor control values to be recorded in manual mode based on interaction mode.
             * Send interaction mode request to the buggy.
             */
            switch (comboBoxIntMode.SelectedItem.ToString())
            {
            case "Manual":
                ManualControlFocusBtn.Enabled = true;
                TempTextBox.Enabled           = true;
                HumTextBox.Enabled            = true;
                LIntTextBox.Enabled           = true;
                buttonReqData.Enabled         = true;
                comboBoxConfig.Enabled        = false;
                textBoxCurrConfig.Enabled     = false;
                textBoxConfigStatus.Enabled   = false;
                buttonConfigUpdate.Enabled    = false;
                comboBoxNewConfig.Enabled     = false;
                BuggyMotorControl.RestartMotorControl();
                MessageHandler.InteractionMode(InteractionMode.Manual);
                break;

            case "Autonomous":
                TempTextBox.Enabled           = true;
                HumTextBox.Enabled            = true;
                LIntTextBox.Enabled           = true;
                comboBoxConfig.Enabled        = false;
                ManualControlFocusBtn.Enabled = false;
                textBoxCurrConfig.Enabled     = false;
                textBoxConfigStatus.Enabled   = false;
                buttonConfigUpdate.Enabled    = false;
                comboBoxNewConfig.Enabled     = false;
                buttonReqData.Enabled         = false;
                BuggyMotorControl.PauseMotorControl();
                MessageHandler.InteractionMode(InteractionMode.Autonomous);
                break;

            case "Configuration":
                comboBoxConfig.Enabled        = true;
                ManualControlFocusBtn.Enabled = false;
                textBoxCurrConfig.Enabled     = true;
                textBoxConfigStatus.Enabled   = true;
                buttonConfigUpdate.Enabled    = true;
                comboBoxNewConfig.Enabled     = true;
                TempTextBox.Enabled           = false;
                HumTextBox.Enabled            = false;
                LIntTextBox.Enabled           = false;
                buttonReqData.Enabled         = false;
                BuggyMotorControl.PauseMotorControl();
                MessageHandler.InteractionMode(InteractionMode.Configuration);
                break;

            default:
                comboBoxConfig.Enabled        = false;
                ManualControlFocusBtn.Enabled = false;
                textBoxConfigStatus.Enabled   = false;
                textBoxCurrConfig.Enabled     = false;
                buttonConfigUpdate.Enabled    = false;
                comboBoxNewConfig.Enabled     = false;
                TempTextBox.Enabled           = false;
                HumTextBox.Enabled            = false;
                LIntTextBox.Enabled           = false;
                buttonReqData.Enabled         = false;
                BuggyMotorControl.PauseMotorControl();
                break;
            }
        }
Beispiel #3
0
        private void buggyConnectBtn_Click(object sender, EventArgs e)
        {
            int index = 0;

            if (listBox1.SelectedIndex == -1)        //if no client was selected from the listbox
            {
                textBoxBuggyConnectStatus.Text = "Select a buggy to connect to.";
            }
            else                                    //client was selected
            {
                //Disable button to prevent multiple requests from being made.
                buggyConnectBtn.Enabled = false;

                //Send request to server to ask for permission to connect to the selected buggy.
                MessageHandler.BuggyConnect(Convert.ToInt32(listBox1.SelectedItem));

                //Wait for the response from the server or until connection with server is lost
                while (BuggyConnectResponse.response == 0 && (ConnectionManager.ConnectionLost == false))
                {
                }

                if (ConnectionManager.ConnectionLost == false)  //Display response if connection with server was not lost
                {
                    switch (BuggyConnectResponse.response)
                    {
                    case BuggyConnectResponse.ConnectPermitted:
                        //find the buggy connection infromation from the list by searching the list by client id and make a connection to the buggy.
                        index = clientManager.Clients.FindIndex(x => x.clientID == Convert.ToInt32(listBox1.SelectedItem));
                        ConnectionManager.AddClient(clientManager.Clients[index].ipAddress, 80);

                        //display connection status of the buggy
                        textBoxBuggyConnectStatus.Text = "Connected to buggy";

                        /*
                         * Disable appropriate controls so that the user cannot connect to other buggies while connected to one.
                         * Enable appropriate buggy controls to allow the user to use the buggy.
                         */
                        buggyConnectBtn.Enabled    = false;
                        buggyDisconnectBtn.Enabled = true;
                        comboBoxIntMode.Enabled    = true;

                        //Start thread that will monitor motor control inputs if manual mode is on.
                        BuggyMotorControl.StartMotorControl();
                        break;

                    case BuggyConnectResponse.BuggyInUse:
                        textBoxBuggyConnectStatus.Text = "Buggy is used by another client";
                        buggyConnectBtn.Enabled        = true;
                        break;

                    default:
                        textBoxBuggyConnectStatus.Text = "Buggy is used by another client";
                        buggyConnectBtn.Enabled        = true;
                        break;
                    }
                }

                //Reset The response indicator
                BuggyConnectResponse.response = 0;
            }
        }