Exemple #1
0
        private void ProcessHeartbeatData(string RouteFileName)
        {
            int totLines = UtilitiesJSON.CountLinesInFile(RouteFileName);

            //Utilities.setHeartbeatDefaults(txtUAV_SN.Text);
            processRouteFile();
        }
Exemple #2
0
        private void JSONView_Load(object sender, EventArgs e)
        {
            string heartBeatURI  = uri;
            string json          = UtilitiesJSON.BuildJSON().ToString();
            string jsonFormatted = JValue.Parse(json).ToString(Formatting.Indented);

            //textBox1.Text = jsonFormatted;
            txtJSON.Text = jsonFormatted;
        }
Exemple #3
0
        private void processRouteFile()
        {
            string msg       = "";
            string RouteLine = "";
            //string heartBeatURI = txtHeartbeatURI.Text;
            //string heartBeatURI = cmbHeartbeatURL.Text;
            int counter = 0;

            try
            {
                var reader = new StreamReader(File.OpenRead(RouteFile));
                //"Lat,Lon,Avionics Bat,Alt(ASL),Alt(AGL),RSSI,Speed,Bearing,Yaw,Pitch,Roll,Servo,Status";
                while (!reader.EndOfStream && TCPThread)
                {
                    //sleepTime = (int)numSleepTime.Value;
                    sleepTime = GetValue();
                    if (chkPause.Checked != true)
                    {
                        //reader.ReadLine();
                        string line   = reader.ReadLine();
                        var    values = line.Split(',');        //array to hold values from each line in the file
                        Heartbeat.Latitude  = Convert.ToDouble(values[0]);
                        Heartbeat.Longitude = Convert.ToDouble(values[1]);
                        Heartbeat.Bat1      = Convert.ToDouble(values[2]);
                        Heartbeat.Alt_ASL   = Convert.ToDouble(values[3]);
                        Heartbeat.Alt_AGL   = Convert.ToDouble(values[4]);
                        Heartbeat.RSSI      = Convert.ToInt16(values[5]);
                        Heartbeat.Speed     = Convert.ToDouble(values[6]);
                        Heartbeat.Bearing   = Convert.ToDouble(values[7]);
                        Heartbeat.Yaw       = Convert.ToDouble(values[8]);
                        Heartbeat.Pitch     = Convert.ToDouble(values[9]);
                        Heartbeat.Roll      = Convert.ToDouble(values[10]);
                        Heartbeat.Bat2      = Convert.ToDouble(values[11]);
                        //Heartbeat.Status = Convert.ToByte(values[12], 16);
                        Heartbeat.Status    = Convert.ToInt16(values[12]);
                        Heartbeat.UAVSerial = txtUAV_SN.Text;
                        Heartbeat.SecretKey = txtSecretKey.Text;
                        Heartbeat.Count     = counter;
                        Heartbeat.Sensor1   = 21.4;
                        Heartbeat.Sensor2   = -19.2;
                        Heartbeat.Sensor3   = 6.2;
                        Heartbeat.Sensor4   = 12.3;
                        Heartbeat.Sensor5   = 48.2;

                        JObject JSONPostData = UtilitiesJSON.BuildJSON();

                        if (radTCP.Checked)
                        {
                            SetResponseText(UtilitiesJSON.JSONPost(JSONPostData, false, heartbeatURL, null));
                        }
                        else
                        {
                            ////// Test UDP code using zLib ///////////
                            byte[] bIV         = Utilities.generateInitVector(); //generate a random initialization vector
                            string JSONString  = JsonConvert.SerializeObject(JSONPostData);
                            byte[] bJSON       = Encoding.ASCII.GetBytes(JSONString);
                            byte[] zLibEncoded = Utilities.Zip(JSONString);
                            byte[] encrypted   = Utilities.Encrypt(zLibEncoded, bEncryptionKey, bIV);
                            //prefix the encrypted code with the IV
                            byte[] encWithIV = AppendTwoByteArrays(bIV, encrypted);
                            //prefix encWithIV code with the session ID
                            byte[] encWithIVandSessionID = AppendTwoByteArrays(bSessionID, encWithIV);
                            Utilities.SendUDPData(encWithIVandSessionID, heartbeatURL, 11000);
                            //byte[] decrypted = Utilities.Decrypt(encrypted, bEncryptionKey, bInitVector);
                            //string JSON = Encoding.ASCII.GetString(decrypted);
                            //SetResponseText(JSON);
                            /////////////////

                            //////  Test UDP code using GZip ///////////
                            //byte[] bIV = Utilities.generateInitVector();  //generate a random initialization vector
                            //string JSONString = JsonConvert.SerializeObject(JSONPostData);
                            //byte[] bJSON = Encoding.ASCII.GetBytes(JSONString);
                            //byte[] gzipEncoded = Utilities.Zip(JSONString);
                            //byte[] encrypted = Utilities.Encrypt(gzipEncoded, bEncryptionKey, bIV);
                            ////prefix the encrypted code with the IV
                            //byte[] encWithIV = AppendTwoByteArrays(bIV, encrypted);
                            ////prefix encWithIV code with the session ID
                            //byte[] encWithIVandSessionID = AppendTwoByteArrays(bSessionID, encWithIV);
                            //Utilities.SendUDPData(encWithIVandSessionID, heartbeatURL, 11000);
                            //byte[] decrypted = Utilities.Decrypt(encrypted, bEncryptionKey, bInitVector);
                            //string JSON = Encoding.ASCII.GetString(decrypted);
                            //SetResponseText(JSON);
                            /////////////////
                        }

                        RouteLine = values[0] + ", " + values[1] + ", " + values[2] + ", " + values[3] + ", " + values[4] + ", " + values[4] + ", " + values[5] + ", " + values[6] + ", " + values[7] + ", " + values[8] + ", " + values[9];
                        if (txtMsgText.Text.Length < 1)
                        {
                            SetMsgText(RouteLine);
                        }
                        else
                        {
                            SetMsgText(txtMsgText.Text + Environment.NewLine + RouteLine);
                        }
                        //MessageBox.Show(values[0] + "," + values[1] + "," + values[2] + "," + values[3]);
                        counter++;
                    }

                    Thread.Sleep(sleepTime);
                }
                SetButtonText("Start");
                SetGrpBoxState(true);
            }
            catch (Exception ex)
            {
                SetMsgText(ex.Message);
            }
        }