Пример #1
0
            public void SendData(ControlsUpdate controlUpdate)           //function called to encode data to be sent to simulator
            {
                string dataToSend;                                       //string to hold data being sent

                dataToSend = JsonConvert.SerializeObject(controlUpdate); //converting the control instructions to json and storing it in dataToSend

                byte[] rawData = Encoding.ASCII.GetBytes(dataToSend);    //converts string to bytes passing in string to get bytes function
                stream.Write(rawData, 0, rawData.Length);                // write to stream (ASCII data, starting at inex 0, ending at last index.)

                SendingEvent?.Invoke(controlUpdate);                     //invokes a new sending event with instance of controls update
            }
Пример #2
0
 private void setControlsUpdate(ControlsUpdate controlUpdate)                                    //called to set new control instructions to send to the simulator
 {
     if (this.InvokeRequired)                                                                    //if invoke is required
     {
         this.Invoke(new SendingDataHandler(setControlsUpdate), new object[] { controlUpdate }); //invokes a new sending event with instance of setcontrolsupdate
     }
     else
     {
         controlUpdate.Throttle      = trkThrottle.Value;       //set throttle control to value of throttle trackbar
         controlUpdate.ElevatorPitch = trkElevator.Value * 0.1; //set pitch control to value of pitch trackbar
     }
 }
Пример #3
0
        public void ControlsScrollUpdate()
        {
            NetworkStream stream = Client.GetStream();            //new stream to send instructions

            ControlsUpdate controlsUpdate = new ControlsUpdate(); //generate a new set of controls to send off to the simulator


            controlsUpdate.Throttle      = trkThrottle.Value;       //setting the new throttle control instructions to the trackbar value
            controlsUpdate.ElevatorPitch = trkElevator.Value * 0.1; //setting the new pitch control instructions to the trackbar value

            Sender.stream = stream;
            Sender.SendData(controlsUpdate);//pass controlsUpdate object to SendData function to be sent off to the simulator

            Thread.Sleep(0100);
        }
Пример #4
0
        //
        //Sending values to simulator from trackbars
        //
        private void sendTrackbarValues()
        {
            ControlsUpdate controlsUpdate = new ControlsUpdate();

            //
            // Assigning values from track bar to struck
            //
            controlsUpdate.Throttle      = trkThrottle.Value;
            controlsUpdate.ElevatorPitch = Convert.ToDouble(trkElevatorPitch.Value) / 10;
            //
            //   geting stream and sending serialized data
            //
            JavaScriptSerializer Serializer = new JavaScriptSerializer();
            string        jsonString        = Serializer.Serialize(controlsUpdate);
            NetworkStream stream            = client.GetStream();

            byte[] rawData = Encoding.ASCII.GetBytes(jsonString);   // serializing data
            stream.Write(rawData, 0, rawData.Length);               // writting to stream
            //
            // passing json string
            //
            addSendMessage(jsonString);
        }