Esempio n. 1
0
 // Call the SystemIdleTimerReset method to prevent the
 // device from sleeping
 private void PowerResetTimer_Tick(object sender, EventArgs e)
 {
     if (m_GPSWrapper.GPSConnected())      // only reset timer if the GPS is connected
     {
         CoreDLL.SystemIdleTimerReset();
     }
 }
Esempio n. 2
0
        static void RunApplication()
        {
            CoreDLL.SystemIdleTimerReset();

            //comandos.Name = "comandos";
            //comandos.Clear();
            //posicion.Name = "posicion";
            //status.Name = "status";
            mobile.StackFailure += ClientMobileStackFailure;
            mobile.destination   = new Destination();
            try
            {
                ServerAddress = new IPEndPoint(IPAddress.Parse(ConfigurationManager.AppSettings["ip_address"]) ?? IPAddress.Any, 2357);
                HostAddress   = new IPEndPoint(IPAddress.Parse("169.254.2.2") ?? IPAddress.Any, 2357);

                // establezo la direccion UDP y UIQ (inter queue)
                //mobile.destination.UIQ = mobile.destination.UDP = SystemState.ActiveSyncStatus == ActiveSyncStatus.Synchronizing ? HostAddress : ServerAddress;
                mobile.destination.UIQ = mobile.destination.UDP = ServerAddress;

                restart_timer = Convert.ToInt32(ConfigurationManager.AppSettings["restart_timer"]);
                if (restart_timer == 0)
                {
                    restart_timer = 300 * 1000;
                }
                shutdown_timer = Convert.ToInt32(ConfigurationManager.AppSettings["shutdown_timer"]);
                if (shutdown_timer == 0)
                {
                    shutdown_timer = 300 * 1000;
                }
                connection_timer = Convert.ToInt32(ConfigurationManager.AppSettings["connection_timer"]);
                if (connection_timer == 0)
                {
                    connection_timer = 60 * 1000;
                }
                GpsMinimunPDOP = Convert.ToInt32(ConfigurationManager.AppSettings["gps_min_pdop"]);
                if (GpsMinimunPDOP == 0)
                {
                    GpsMinimunPDOP = 8;
                }
                fix_interval = Convert.ToInt32(ConfigurationManager.AppSettings["gps_fix_interval"]);
                if (fix_interval == 0)
                {
                    fix_interval = 60;
                }
                destination_area_radio = Convert.ToInt32(ConfigurationManager.AppSettings["gps_area_radio"]);
                if (destination_area_radio == 0)
                {
                    destination_area_radio = 1500;
                }
                //notschedule = (ConfigurationManager.AppSettings["hack_not_re_schedule"] == "active" ? true : false);
                var auto_gc = ConfigurationManager.AppSettings["hack_auto_gc"];

                /*if (!string.IsNullOrEmpty(auto_gc)) {
                 *  T.TRACE(String.Format("HACK: Activo GeoCerca Automatica de Pruebas {0}",auto_gc));
                 *  var dummy = new byte[2];
                 *  comandos.Push(auto_gc, dummy);
                 * }*/
            }
            catch (Exception)
            {
                T.ERROR("ERROR FATAL: La configuracion no es valida, revisar.");
                T.ERROR("CUIDADO!!! No se programa el restart, debe ejecutar la aplicacion manualmente.");
                return;
            }

#if false
            mobile.IMEI = iPaqUtil.GetDeviceSN();
#else
            mobile.IMEI = "HTC-GUSTAVO";
#endif
            using (var script_hlp = File.Create(@"\Temp\pdaserial.txt"))
            {
                var buffer = Encoding.ASCII.GetBytes(mobile.IMEI);
                script_hlp.Write(buffer, 0, buffer.GetLength(0));
            }

            mobile.Password = "******";
            mobile.Init(2357, 2358, 8192, "entrante", "saliente");
            T.INFO("COMM: Init convocado.");

            network = new Thread(NetworkProc);
            T.INFO("NETWORK: lanzando hilo.");
            network.Start();

            tracker = new Thread(TrackerProc);
            T.INFO("TRACKER: lanzando hilo.");
            tracker.Start();

            CoreDLL.SystemIdleTimerReset();

            IntPtr wavHandle = CoreDLL.SetPowerRequirement("WAV1:",
                                                           CEDEVICE_POWER_STATE.D0,
                                                           DevicePowerFlags.POWER_NAME | DevicePowerFlags.POWER_FORCE, IntPtr.Zero, 0);
            if (wavHandle == IntPtr.Zero)
            {
                throw new System.ComponentModel.Win32Exception();
            }

            var gpsHandle = CoreDLL.SetPowerRequirement("GPD0:",
                                                        CEDEVICE_POWER_STATE.D0,
                                                        DevicePowerFlags.POWER_NAME | DevicePowerFlags.POWER_FORCE, IntPtr.Zero, 0);
            if (gpsHandle == IntPtr.Zero)
            {
                throw new System.ComponentModel.Win32Exception();
            }

            CoreDLL.Beep(1);
            T.TRACE("Lanzando Urbetrack Ready");
            LaunchGatewayRunning();

            var upgrade_count = 0;
            while (running)
            {
                CoreDLL.SystemIdleTimerReset();
                if (upgrade_count == 0)
                {
                    T.TRACE("Lanzando Urbetrack Update");
                    LaunchGatewayUpgrade();
                    upgrade_count = 360;
                }
                upgrade_count--;
                for (var x = 0; x < 10; x++)
                {
                    Thread.Sleep(1000);
                    Application.DoEvents();
                }
                var comando = "";
                try
                {
                    Thread.Sleep(1000);

                    /*comandos.Pop(ref comando);
                     * if (comando.Length > 0)
                     *  ProcessCommand(comando);*/
                } catch (Exception e)
                {
                    T.EXCEPTION(e, "Command Processor");
                }
            }

            if (wavHandle != IntPtr.Zero)
            {
                CoreDLL.ReleasePowerRequirement(wavHandle);
            }

            if (gpsHandle != IntPtr.Zero)
            {
                CoreDLL.ReleasePowerRequirement(gpsHandle);
            }

            T.INFO("URBEMOBILE: hora de ahorar energia...");
            mobile.Close();
            network.Join(10000);
            T.INFO("URBEMOBILE: network sincronizada.");
            //supervisor.Join(10000);
            //T.INFO("URBEMOBILE: supervisor sincornizado.");
            tracker.Join(10000);
            T.INFO("URBEMOBILE: tracker sincornizado.");

            T.TRACE("--- URBEMOBILE TERMINADO ---");

            Beep("end_app");
        }