private void simulacion()         //funcion donde se simula el movimiento de los objetivos
        {
            //timer para controlar el tiempo de sleep del hilo, cada ese tiempo, ejecutara la acción.
            TimeController temporizador = new TimeController(3, false);

            while (true)
            {
                if (temporizador.isCycleDone)
                {
                    if (listaObjetivos.Count > 0)
                    {
                        for (int i = 0; i < listaObjetivos.Count; i++)
                        {
                            //float tiempo = 10;//hrs
                            double timestampNow  = TimeController.timeStamp();
                            double tiempoEnHoras = (timestampNow - listaObjetivos[i].lastTime) / 3600;                            //en Hrs
                            //PONER EL NUEVO TIMESTAMP
                            double timestampNow2 = TimeController.timeStamp();
                            listaObjetivos[i].lastTime = timestampNow2;
                            //distancia en Kilometros
                            float distanciaKm = geodesicUtils.nauticalMilesToKilometer(calculaDistanciaMN2((float)tiempoEnHoras, listaObjetivos[i].speed));

                            position origen = new position(listaObjetivos[i].lat, listaObjetivos[i].lon);

                            position destino = geodesicUtils.FindPointAtDistanceFrom(origen, geodesicUtils.DegreesToRadians(listaObjetivos[i].course), distanciaKm);
                            //ajustamos las coordenadas de la nueva posicion
                            ajustaCoordenadas(destino, i);
                            //ajustamos el nuevo curso o bearing en la nueva posicion.
                            ajustaRumbo((float)geodesicUtils.bearingFinal(destino, origen), i);
                        }                        //del ciclo for
                    }
                }

                //esperar evento para detener el hilo
                if (eventoSimulacion.WaitOne(0, false) == true)
                {
                    //just wait until the last thread is done
                    //Sleep(500);
                    eventoSimulacion.Reset();                    //reset the event
                    break;
                }
            }
        }
Example #2
0
        /*
         * Calcula la distancia en millas nauticas, teniendo como datos de entrada, la velocidad del objetivo
         * y el tiempo.
         */

        private float calculaDistanciaMN(double lastTime, float VelEnNudos)         //calcula la dist en millas nauticas
        {
            /*
             * Variables
             * velocidad en Nudos (Millas nauticas / h)
             * Distancia en Millas  (Recordar que el extend de la Display prototype, esta en metros)
             * Tiempo en Hrs.
             *
             * V = D/t
             * Primer paso.
             * Tenemos un timestamp de referencia en segundos.
             * Si el timestamp de referencia, es menor que el timestampNow
             * iniciamos calculo de distancia recorrida.
             *
             */
            double timestampNow = TimeController.timeStamp();

            double tiempoEnHoras = (timestampNow - lastTime) / 3600;            //en Hrs

            float DistEnMillasNaut = VelEnNudos * (float)tiempoEnHoras;

            return(DistEnMillasNaut);
        }
        //funcion donde se simula el movimiento de los objetivos
        private void simulacion()
        {
            //timer para controlar el tiempo de sleep del hilo, cada ese tiempo, ejecutara la acción.
            TimeController temporizador = new TimeController(3, false);
            while (true)
            {

                if (temporizador.isCycleDone)
                {

                    if (listaObjetivos.Count > 0)
                    {
                        for (int i = 0; i < listaObjetivos.Count; i++)
                        {

                            //float tiempo = 10;//hrs
                            double timestampNow = TimeController.timeStamp();
                            double tiempoEnHoras = (timestampNow - listaObjetivos[i].lastTime) / 3600;//en Hrs
                            //PONER EL NUEVO TIMESTAMP
                            double timestampNow2 = TimeController.timeStamp();
                            listaObjetivos[i].lastTime = timestampNow2;
                            //distancia en Kilometros
                            float distanciaKm = geodesicUtils.nauticalMilesToKilometer(calculaDistanciaMN2((float)tiempoEnHoras, listaObjetivos[i].speed));

                            position origen = new position(listaObjetivos[i].lat, listaObjetivos[i].lon);

                            position destino = geodesicUtils.FindPointAtDistanceFrom(origen, geodesicUtils.DegreesToRadians(listaObjetivos[i].course), distanciaKm);
                            //ajustamos las coordenadas de la nueva posicion
                            ajustaCoordenadas(destino, i);
                            //ajustamos el nuevo curso o bearing en la nueva posicion.
                            ajustaRumbo((float)geodesicUtils.bearingFinal(destino, origen),i);

                        }//del ciclo for

                    }
                }

                //esperar evento para detener el hilo
                if (eventoSimulacion.WaitOne(0, false) == true)
                {
                    //just wait until the last thread is done
                    //Sleep(500);
                    eventoSimulacion.Reset();//reset the event
                   break;
                }

            }
        }
        //funcion para enviar los objetivos simulados a traves de la red
        private void envio()
        {
            TimeController temporizador = new TimeController(5, false);

            WrappedNMEADataSender sender;
            int  integratorServerPort= 12082;
            String integratorServerIpAddress = "192.168.0.17";
            sender = new WrappedNMEADataSender(integratorServerIpAddress, integratorServerPort);
            sender.setBaseStation(localBaseStation);
            sender.Connect();

            while (true)
            {

                if(temporizador.isCycleDone)
                {
                    if((listaObjetivos.Count > 0) && (sender.aliveConecction()))
                    {
                        for (int i = 0; i < listaObjetivos.Count; i++ )
                        {
                            sender.SendTarget(listaObjetivos[i]);
                        }
                    }
                }

                //esperar evento para detener el hilo
                if (eventoEnvio.WaitOne(0, false) == true)
                {
                    sender.Disconnect();
                    eventoEnvio.Reset();//reset the event
                    break;
                }
            }
        }
Example #5
0
        private void btAgregar_Click(object sender, EventArgs e)
        {
            //Agregaremos uno a uno los objetivos a la lista
            decodedMessage objetivo = new decodedMessage();

            // MessageBox.Show("Indice" + cbTiposObjetivos.SelectedIndex);

            //Del tipo seleccionado en la lista, le indicamos que tipo de objetivo es a traves de su msgType
            switch (cbTiposObjetivos.SelectedIndex)
            {
            case 0: objetivo.msgType = 1;                      //class A
                break;

            case 1: objetivo.msgType = 18;                     //class B
                break;

            case 2: objetivo.msgType = 9;                      //SART
                break;

            case 3: objetivo.msgType = 21;                     //AtoN
                break;
            }

            if (objetivo.msgType > 0)
            {
                //validacion del MMSI
                if (conversionValidaInt64(tbMMSI.Text))
                {
                    objetivo.MMSI = System.Convert.ToInt64(tbMMSI.Text);
                    //validacion del campo nombre del Objetivo
                    if (tbNombre.Text != "")
                    {
                        objetivo.shipname = tbNombre.Text;
                        //validacion del campo latitud
                        if ((conversionValidaDouble(tbLatitude.Text) == true) && (tbLatitude.Text != ""))
                        {
                            objetivo.lat = (float)(System.Convert.ToDouble(tbLatitude.Text));
                            //validacion del campo longitud
                            if ((conversionValidaDouble(tbLongitud.Text) == true) && (tbLongitud.Text != ""))
                            {
                                objetivo.lon = (float)(System.Convert.ToDouble(tbLongitud.Text));
                                //validacion del campo rumbo
                                if (conversionValidaDouble(tbRumbo.Text) && (tbRumbo.Text != ""))
                                {
                                    objetivo.course = (float)(System.Convert.ToDouble(tbRumbo.Text));
                                    //validacion del campo velocidad
                                    if (conversionValidaDouble(tbVelocidad.Text) && (tbVelocidad.Text != ""))
                                    {
                                        objetivo.speed = (float)(System.Convert.ToDouble(tbVelocidad.Text));
                                        //inicializamos con un timestamp en el campo lastTime
                                        //check for the current time stamp

                                        double now = TimeController.timeStamp();

                                        objetivo.lastTime = now;

                                        //MessageBox.Show("mas" + now);
                                        //finalmente, agregamos el objetivo
                                        listaObjetivos.Add(objetivo);
                                        //limpiamos cajas de texto
                                        tbMMSI.Clear();
                                        tbNombre.Clear();
                                        tbLatitude.Clear();
                                        tbLongitud.Clear();
                                        tbRumbo.Clear();
                                        tbVelocidad.Clear();
                                        //informamos al usuario
                                        //MessageBox.Show("Objetivo Agregado");
                                    }
                                    else
                                    {
                                        MessageBox.Show("El campo, Velocidad no es valido, o esta vacio");
                                        tbVelocidad.Clear();
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("El campo, Rumbo no es valido, o esta vacio");
                                    tbRumbo.Clear();
                                }
                            }
                            else
                            {
                                MessageBox.Show("El campo, Longitud no es valido, o esta vacio");
                                tbLongitud.Clear();
                            }
                        }
                        else
                        {
                            MessageBox.Show("El campo, Latitud no es valido, ó esta vacio");
                            tbLatitude.Clear();
                        }
                    }
                    else
                    {
                        MessageBox.Show("El campo, nombre de la Embarcación, no puede estar vacio");
                    }
                }
                else
                {
                    MessageBox.Show("El campo, MMSI de la Embarcación, no es valido ó esta vacio.");
                    tbMMSI.Clear();
                }
            }            //de la validacion del combo box
            else
            {
                MessageBox.Show("Seleccione un tipo de Objetivo");
            }            //else de la validacion del combo box
        }