static void Main(string[] args) { try { T.Initialize("urbemobile"); T.CurrentLevel = 0; Net.TCP.Stream.StreamTraceLevel = 0; var appDomain = AppDomain.CurrentDomain; appDomain.UnhandledException += appDomain_UnhandledException; if (Math.Abs(CoreDLL.PowerPolicyNotify(PPNMessage.PPN_UNATTENDEDMODE, -1)) == 1) { T.ResetFileOnStartup = ConfigurationManager.AppSettings["hack_dont_reset_log"] == "active" ? false : true; UnattendedMain(args); }/* * else * { * MessageBox.Show("MAIN: es imposible activar modo inatendido, urbemobile no va a ejecutarse."); * }*/ CoreDLL.PowerPolicyNotify(PPNMessage.PPN_UNATTENDEDMODE, 0); } catch (Exception e) { T.EXCEPTION(e, "main"); T.DEAD_REPORT(e); } }
// 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(); } }
private static void ClientMobileStackFailure() { T.NOTICE("NETWORK: STACK FAILURE!"); CoreDLL.Beep(2); network_status = false; SyncTimedInternetDisconnect(60); }
private void stopUmtMenuItem_Click(object sender, EventArgs e) { umtRun.Reset(); if (nullIntPtr != wavPowerReqHandle) { CoreDLL.ReleasePowerRequirement(wavPowerReqHandle); wavPowerReqHandle = nullIntPtr; } CoreDLL.PowerPolicyNotify(PPNMessage.PPN_UNATTENDEDMODE, 0); }
public static void RunAppAtTime(string applicationEvent, DateTime startTime) { long fileTimeUTC = startTime.ToFileTime(); long fileTimeLocal = 0; var systemStartTime = new SystemTime(); CoreDLL.FileTimeToLocalFileTime(ref fileTimeUTC, ref fileTimeLocal); CoreDLL.FileTimeToSystemTime(ref fileTimeLocal, systemStartTime); CoreDLL.CeRunAppAtTime(applicationEvent, systemStartTime); }
private void startUmtMenuItem_Click(object sender, EventArgs e) { // See Unattended Mode example at http://stackoverflow.com/questions/336771/how-can-i-run-code-on-windows-mobile-while-being-suspended CoreDLL.PowerPolicyNotify(PPNMessage.PPN_UNATTENDEDMODE, 1); // Request that the audio device remain powered in unattended mode // NOTE: If you don't do this, the system suspends anyway 1 minute after you press the power button // (USB reader power light goes out, system publishes a Suspend notification.) // With this request, it seems to run indefinitely. wavPowerReqHandle = CoreDLL.SetPowerRequirement("wav1:", CEDeviceDriverPowerStates.D0, DevicePowerFlags.POWER_NAME | DevicePowerFlags.POWER_FORCE, new IntPtr(0), 0); umtRun.Set(); }
internal void LoginSuccess(object sender, short idDisp) { if (Estado == EstadoCliente.TRY_ONLINE) { CoreDLL.Beep(4); T.INFO("NETWORK: Estamos ONLINE..."); Estado = EstadoCliente.ONLINE; clientTU.IdDispositivo = IdDispositivo = idDisp; if (queued_fix != null) { T.TRACE("FIX - envaindo punto encolado"); Fix(queued_fix); } } }
static void Beep(string sound) { if (ConfigurationManager.AppSettings["sound_enabled"] != "1") { return; } var filename = ConfigurationManager.AppSettings[string.Format("sound_{0}", sound)]; if (filename == "") { filename = @"\windows\Alarm1.wav"; } CoreDLL.PlaySound(filename, IntPtr.Zero, CoreDLL.PlaySoundFlags.SND_FILENAME | CoreDLL.PlaySoundFlags.SND_ASYNC); }
private static void TrackerProc() { T.INFO(String.Format("TRACKER: iniciando GPS ({0})", GpsDeviceName)); CEDEVICE_POWER_STATE currentPowerState; CoreDLL.GetDevicePower(GpsDeviceName, DevicePowerFlags.POWER_NAME | DevicePowerFlags.POWER_FORCE, out currentPowerState); _gpsPowerRequirements = CoreDLL.SetPowerRequirement(GpsDeviceName, CEDEVICE_POWER_STATE.D0, DevicePowerFlags.POWER_NAME, IntPtr.Zero, 0); if (currentPowerState == CEDEVICE_POWER_STATE.D4) { T.INFO("TRACKER: el GPS esta apagado, activo guarda."); Thread.Sleep(500); } gps.Open(); LastestGpsDateTransition = DateTime.Now; while (running) { Thread.Sleep(5000); var position = gps.GetPosition(); if (position == null) { GpsSignalFixed = false; continue; } if (GPS.GPS.IsPositionValid(position, true, GpsMinimunPDOP)) { GpsSignalFixed = true; ProcessPosition(position); } else { GpsSignalFixed = false; } } gps.Close(); Thread.Sleep(800); CoreDLL.ReleasePowerRequirement(_gpsPowerRequirements); T.INFO("TRACKER: terminado."); }
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"); }