コード例 #1
0
        private void ReceiveCallback(IAsyncResult ar)
        {
            try
            {
                // Retrieve the state object and the client socket
                // from the asynchronous state object.
                StateObject state  = (StateObject)ar.AsyncState;
                Socket      client = state.workSocket;

                // Read data from the remote device.
                client.EndReceive(ar);

                response         = Encoding.ASCII.GetString(state.buffer, 0, state.buffer.Length); //convertion from byte to string
                telementryValues = JsonConvert.DeserializeObject <TelemetryUpdate>(response);      //json data is tranformed into struct

                dataGridView1.Rows[0].Cells[0].Value = telementryValues.Throttle;
                dataGridView1.Rows[0].Cells[1].Value = telementryValues.ElevatorPitch;
                dataGridView2.Rows[0].Cells[0].Value = Math.Round(telementryValues.Altitude, 1);
                dataGridView2.Rows[0].Cells[1].Value = Math.Round(telementryValues.Pitch, 3);
                dataGridView3.Rows[0].Cells[0].Value = Math.Round(telementryValues.Speed, 1);
                dataGridView3.Rows[0].Cells[1].Value = Math.Round(telementryValues.VerticalSpeed, 1);
                warning();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
コード例 #2
0
 public void Copy(TelemetryUpdate t)
 {
     modeButton       = t.modeButton;
     NOSIG            = t.NOSIG;
     NOEP             = t.NOEP;
     BLK              = t.BLK;
     AUP              = t.AUP;
     ADN              = t.ADN;
     EP0              = t.EP0;
     EP1              = t.EP1;
     EP2              = t.EP2;
     CK1              = t.CK1;
     CK2              = t.CK2;
     CK3              = t.CK3;
     CP1              = t.CP1;
     CP2              = t.CP2;
     CP3              = t.CP3;
     SS0              = t.SS0;
     SS1              = t.SS1;
     SS2              = t.SS2;
     SS3              = t.SS3;
     SS4              = t.SS4;
     arrow_icon       = t.arrow_icon;
     arrow_tooltip    = t.arrow_tooltip;
     firstHop_icon    = t.firstHop_icon;
     firstHop_tooltip = t.firstHop_tooltip;
     lastHop_icon     = t.lastHop_icon;
     lastHop_tooltip  = t.lastHop_tooltip;
     control_icon     = t.control_icon;
     control_tooltip  = t.control_tooltip;
     signal_icon      = t.signal_icon;
     signal_tooltip   = t.signal_tooltip;
 }
コード例 #3
0
        protected override void Start()
        {
            CNVCommNetScenario.Instance = this;

            UnityEngine.Debug.Log("CommNet Scenario loading ...");

            //Replace the CommNet user interface
            CommNetUI ui = FindObjectOfType <CommNetUI>();              // the order of the three lines is important

            CustomCommNetUI = gameObject.AddComponent <CNVCommNetUI>(); // gameObject.AddComponent<>() is "new" keyword for Monohebaviour class
            UnityEngine.Object.Destroy(ui);

            //Replace the TelemetryUpdate
            TelemetryUpdate     tel      = TelemetryUpdate.Instance;                 //only appear in flight
            CommNetUIModeButton cnmodeUI = FindObjectOfType <CommNetUIModeButton>(); //only appear in tracking station; initialised separately by TelemetryUpdate in flight

            if (tel != null && HighLogic.LoadedSceneIsFlight)
            {
                TelemetryUpdateData tempData = new TelemetryUpdateData(tel);
                UnityEngine.Object.DestroyImmediate(tel); //seem like UE won't initialise CNCTelemetryUpdate instance in presence of TelemetryUpdate instance
                CustomCommNetTelemetry = gameObject.AddComponent <CNVTelemetryUpdate>();
                CustomCommNetTelemetry.copyOf(tempData);
            }
            else if (cnmodeUI != null && HighLogic.LoadedScene == GameScenes.TRACKSTATION)
            {
                CustomCommNetModeButton = cnmodeUI.gameObject.AddComponent <CNVCommNetUIModeButton>();
                CustomCommNetModeButton.copyOf(cnmodeUI);
                UnityEngine.Object.DestroyImmediate(cnmodeUI);
            }

            UnityEngine.Debug.Log("CommNet Scenario loading done! ");
        }
コード例 #4
0
        public Form1()
        {
            InitializeComponent();
            //Assign events with their repective delegates and functions
            eventControls  += new ControlsUpdated(SendData);
            eventTelemetry += new TelemetryUpdated(RecievedMessage);
            eventWarnings  += new WarningUpdated(UpdateWarnings);


            TU = new TelemetryUpdate();
            CU = new ControlUpdate();
        }
コード例 #5
0
        public void getData(object sender, DoWorkEventArgs e)
        {
            string incomingData = "";                                                          //incoming data from remote application

            byte[] bytesBuffer       = new Byte[256];                                          //byte array for incoming data
            int    bytesReceiveCount = socket.Receive(bytesBuffer);                            //amount of bytes stored to int

            incomingData      = Encoding.ASCII.GetString(bytesBuffer, 0, bytesReceiveCount);   //convertion from byte to string
            telementryUpdates = JsonConvert.DeserializeObject <TelemetryUpdate>(incomingData); //json data is tranformed into struct
            dataReceivedEvent();                                                               //relevant events are invoked
            isThereWarningEvent();
            sendData(sender, e);                                                               //repeat listening to socket
        }
コード例 #6
0
 private void AddMessage(string message)
 {
     if (this.InvokeRequired) //Invoke the AddMessageDelegate is required
     {
         this.Invoke(new AddMessageDelegate(AddMessage), new object[] { message });
     }
     else
     {
         //Deserialiing the JSON message into a TelemeteryUpdate instance
         JavaScriptSerializer Deserializer    = new JavaScriptSerializer();
         TelemetryUpdate      telemetryUpdate = Deserializer.Deserialize <TelemetryUpdate>(message);
         lblJsonRecieved.Text = message;          //Updates the label with the recieved JSON message
         eventTelemetry?.Invoke(telemetryUpdate); //Invoke the eventTelemetery event which using a delegate and the message ends up being recieved in the RecievedMessage Function
     }
 }
コード例 #7
0
        public void Listen()
        {
            NetworkStream stream = m_client.GetStream(); //network stream object to receive data

            byte[] buffer = new byte[256];               // buffer to write into

            while (true)
            {
                try
                {
                    int num_bytes = stream.Read(buffer, 0, 256);                             //256 is the max number of bytes we're willing to accept

                    string message = Encoding.ASCII.GetString(buffer, 0, num_bytes);         //decodes the data only up to bytes received

                    TelemetryUpdate obj = serializer.Deserialize <TelemetryUpdate>(message); // decodes the string(message)

                    //the events will only invoke if the event is not null

                    OnTelemetryUpdate?.Invoke(obj);

                    if (obj.WarningCode == 1)
                    {
                        OnWarningCode?.Invoke("Low altitude: fly back above 1000ft");
                    }
                    else if (obj.WarningCode == 0)
                    {
                        OnWarningCode?.Invoke("");
                    }
                    else if (obj.WarningCode == 2)
                    {
                        OnWarningCode?.Invoke("Stall risk: increase the speed or drop the nose to lower the elevator. ");
                    }

                    double throttle = obj.Throttle;
                    double elevator = obj.ElevatorPitch;
                    updateControls(throttle, elevator);
                }
                catch (Exception)
                {
                }
            }
        }
コード例 #8
0
        private void RecievedMessage(TelemetryUpdate updates)
        {
            if (updates.WarningCode != 0) //Determines if a warning code was recieved
            {
                string warning = "";
                switch (updates.WarningCode)
                {
                //Assign the approperiate message to each warning
                case 1:
                    warning = "Too Low (less than 1000ft)";
                    break;

                case 2:
                    warning = "Stall";
                    break;

                default:
                    break;
                }
                //Invokes eventWarning using the assigned delegate the message ends up in UpdateWarnings
                eventWarnings?.Invoke(warning);
            }
            else
            {
                lblWarnings.Text = updates.WarningCode.ToString(); //If no warning is recieved the the warnings label is set to 0
            }

            //update lables

            lblAltitude.Text      = updates.Altitude.ToString();
            lblSpeed.Text         = updates.Speed.ToString();
            lblPitch.Text         = updates.Pitch.ToString();
            lblVerticalSpeed.Text = updates.VerticalSpeed.ToString();
            lblThrottle.Text      = updates.Throttle.ToString();
            lblElevatorPitch.Text = updates.ElevatorPitch.ToString();

            //update data view table
            tabData.Rows.Add(new Object[] { updates.Altitude, updates.Speed, updates.Pitch, updates.VerticalSpeed, updates.Throttle, updates.ElevatorPitch, updates.WarningCode });
        }
コード例 #9
0
        public TelemetryUpdateData(TelemetryUpdate stockTU)
        {
            this.modeButton       = stockTU.modeButton;
            this.NOSIG            = stockTU.NOSIG;
            this.NOEP             = stockTU.NOEP;
            this.BLK              = stockTU.BLK;
            this.AUP              = stockTU.AUP;
            this.ADN              = stockTU.ADN;
            this.EP0              = stockTU.EP0;
            this.EP1              = stockTU.EP1;
            this.EP2              = stockTU.EP2;
            this.CK1              = stockTU.CK1;
            this.CK2              = stockTU.CK2;
            this.CK3              = stockTU.CK3;
            this.CP1              = stockTU.CP1;
            this.CP2              = stockTU.CP2;
            this.CP3              = stockTU.CP3;
            this.SS0              = stockTU.SS0;
            this.SS1              = stockTU.SS1;
            this.SS2              = stockTU.SS2;
            this.SS3              = stockTU.SS3;
            this.SS4              = stockTU.SS4;
            this.arrow_icon       = stockTU.arrow_icon;
            this.firstHop_icon    = stockTU.firstHop_icon;
            this.lastHop_icon     = stockTU.lastHop_icon;
            this.control_icon     = stockTU.control_icon;
            this.signal_icon      = stockTU.signal_icon;
            this.firstHop_tooltip = stockTU.firstHop_tooltip;
            this.arrow_tooltip    = stockTU.arrow_tooltip;
            this.lastHop_tooltip  = stockTU.lastHop_tooltip;
            this.control_tooltip  = stockTU.control_tooltip;
            this.signal_tooltip   = stockTU.signal_tooltip;

            //Doing Reflection to read and save attribute names and values seems too complex,
            //given most of attributes are not primitives
        }
コード例 #10
0
        protected override void Start()
        {
            CNCCommNetScenario.Instance = this;
            this.commVessels            = new List <CNCCommNetVessel>();
            this.dirtyCommNetVesselList = true;

            CNCLog.Verbose("CommNet Scenario loading ...");

            //Issue #13: Commnet behaves like vanilla when joining a DMP server for the second time.
            //if stock CommNet logic somehow runs (such as the order of CNCCommNetScenario and CommNetScenario in persisten.sfs)
            if (CommNetScenario.Instance != null)
            {
                UnityEngine.Object.DestroyImmediate(CommNetScenario.Instance);
                CNCCommNetScenario.Instance = this;
            }

            //Replace the CommNet user interface
            CommNetUI ui = FindObjectOfType <CommNetUI>();              // the order of the three lines is important

            CustomCommNetUI = gameObject.AddComponent <CNCCommNetUI>(); // gameObject.AddComponent<>() is "new" keyword for Monohebaviour class
            UnityEngine.Object.Destroy(ui);

            //Replace the CommNet network
            CommNetNetwork net = FindObjectOfType <CommNetNetwork>();

            CustomCommNetNetwork = gameObject.AddComponent <CNCCommNetNetwork>();
            UnityEngine.Object.Destroy(net);
            //CommNetNetwork.Instance.GetType().GetMethod("set_Instance").Invoke(CustomCommNetNetwork, null); // reflection to bypass Instance's protected set // don't seem to work

            //Replace the TelemetryUpdate
            TelemetryUpdate     tel      = TelemetryUpdate.Instance;                 //only appear in flight
            CommNetUIModeButton cnmodeUI = FindObjectOfType <CommNetUIModeButton>(); //only appear in tracking station; initialised separately by TelemetryUpdate in flight

            if (tel != null && HighLogic.LoadedSceneIsFlight)
            {
                TelemetryUpdateData tempData = new TelemetryUpdateData(tel);
                UnityEngine.Object.DestroyImmediate(tel); //seem like UE won't initialise CNCTelemetryUpdate instance in presence of TelemetryUpdate instance
                CustomCommNetTelemetry = gameObject.AddComponent <CNCTelemetryUpdate>();
                CustomCommNetTelemetry.copyOf(tempData);
            }
            else if (cnmodeUI != null && HighLogic.LoadedScene == GameScenes.TRACKSTATION)
            {
                CustomCommNetModeButton = cnmodeUI.gameObject.AddComponent <CNCCommNetUIModeButton>();
                CustomCommNetModeButton.copyOf(cnmodeUI);
                UnityEngine.Object.DestroyImmediate(cnmodeUI);
            }

            //Replace the CommNet ground stations
            groundStations.Clear();
            CommNetHome[] homes = FindObjectsOfType <CommNetHome>();
            for (int i = 0; i < homes.Length; i++)
            {
                CNCCommNetHome customHome = homes[i].gameObject.AddComponent(typeof(CNCCommNetHome)) as CNCCommNetHome;
                customHome.copyOf(homes[i]);
                UnityEngine.Object.Destroy(homes[i]);
                groundStations.Add(customHome);
            }
            groundStations.Sort();

            //Apply the ground-station changes from persistent.sfs
            for (int i = 0; i < persistentGroundStations.Count; i++)
            {
                if (groundStations.Exists(x => x.ID.Equals(persistentGroundStations[i].ID)))
                {
                    groundStations.Find(x => x.ID.Equals(persistentGroundStations[i].ID)).applySavedChanges(persistentGroundStations[i]);
                }
            }
            persistentGroundStations.Clear();//dont need anymore

            //Replace the CommNet celestial bodies
            CommNetBody[] bodies = FindObjectsOfType <CommNetBody>();
            for (int i = 0; i < bodies.Length; i++)
            {
                CNCCommNetBody customBody = bodies[i].gameObject.AddComponent(typeof(CNCCommNetBody)) as CNCCommNetBody;
                customBody.copyOf(bodies[i]);
                UnityEngine.Object.Destroy(bodies[i]);
            }

            //Imitate stock CommNetScenario.Instance in order to run certain stock functionalities
            //Comment: Vessel.GetControlLevel() has the check on CommNetScenario.Instance != null before calling vessel.connection.GetControlLevel()
            PropertyInfo property = typeof(CommNetScenario).GetProperty("Instance");

            property.DeclaringType.GetProperty("Instance");
            property.SetValue(CommNetScenario.Instance, this, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null);

            CNCLog.Verbose("CommNet Scenario loading done!");
        }
コード例 #11
0
        protected override void Start()
        {
            CNCCommNetScenario.Instance = this;
            this.commVessels            = new List <CNCCommNetVessel>();
            this.dirtyCommNetVesselList = true;

            CNCLog.Verbose("CommNet Scenario loading ...");

            //Replace the CommNet user interface
            CommNetUI ui = FindObjectOfType <CommNetUI>();              // the order of the three lines is important

            CustomCommNetUI = gameObject.AddComponent <CNCCommNetUI>(); // gameObject.AddComponent<>() is "new" keyword for Monohebaviour class
            UnityEngine.Object.Destroy(ui);

            //Replace the CommNet network
            CommNetNetwork net = FindObjectOfType <CommNetNetwork>();

            CustomCommNetNetwork = gameObject.AddComponent <CNCCommNetNetwork>();
            UnityEngine.Object.Destroy(net);
            //CommNetNetwork.Instance.GetType().GetMethod("set_Instance").Invoke(CustomCommNetNetwork, null); // reflection to bypass Instance's protected set // don't seem to work

            //Replace the TelemetryUpdate
            TelemetryUpdate     tel      = TelemetryUpdate.Instance;                 //only appear in flight
            CommNetUIModeButton cnmodeUI = FindObjectOfType <CommNetUIModeButton>(); //only appear in tracking station; initialised separately by TelemetryUpdate in flight

            if (tel != null && HighLogic.LoadedSceneIsFlight)
            {
                TelemetryUpdateData tempData = new TelemetryUpdateData(tel);
                UnityEngine.Object.DestroyImmediate(tel); //seem like UE won't initialise CNCTelemetryUpdate instance in presence of TelemetryUpdate instance
                CustomCommNetTelemetry = gameObject.AddComponent <CNCTelemetryUpdate>();
                CustomCommNetTelemetry.copyOf(tempData);
            }
            else if (cnmodeUI != null && HighLogic.LoadedScene == GameScenes.TRACKSTATION)
            {
                CustomCommNetModeButton = cnmodeUI.gameObject.AddComponent <CNCCommNetUIModeButton>();
                CustomCommNetModeButton.copyOf(cnmodeUI);
                UnityEngine.Object.DestroyImmediate(cnmodeUI);
            }

            //Replace the CommNet ground stations
            groundStations.Clear();
            CommNetHome[] homes = FindObjectsOfType <CommNetHome>();
            for (int i = 0; i < homes.Length; i++)
            {
                CNCCommNetHome customHome = homes[i].gameObject.AddComponent(typeof(CNCCommNetHome)) as CNCCommNetHome;
                customHome.copyOf(homes[i]);
                UnityEngine.Object.Destroy(homes[i]);
                groundStations.Add(customHome);
            }
            groundStations.Sort();

            //Apply the ground-station changes from persistent.sfs
            for (int i = 0; i < persistentGroundStations.Count; i++)
            {
                if (groundStations.Exists(x => x.ID.Equals(persistentGroundStations[i].ID)))
                {
                    groundStations.Find(x => x.ID.Equals(persistentGroundStations[i].ID)).applySavedChanges(persistentGroundStations[i]);
                }
            }
            persistentGroundStations.Clear();//dont need anymore

            //Replace the CommNet celestial bodies
            CommNetBody[] bodies = FindObjectsOfType <CommNetBody>();
            for (int i = 0; i < bodies.Length; i++)
            {
                CNCCommNetBody customBody = bodies[i].gameObject.AddComponent(typeof(CNCCommNetBody)) as CNCCommNetBody;
                customBody.copyOf(bodies[i]);
                UnityEngine.Object.Destroy(bodies[i]);
            }

            CNCLog.Verbose("CommNet Scenario loading done!");
        }
コード例 #12
0
 protected void OnTelemetryUpdate(TelemetryEventArgs e)
 {
     TelemetryUpdate?.Invoke(this, e);
 }
コード例 #13
0
 private static void HandleTelemetryUpdate(TelemetryUpdate update)
 {
 }