// called by FreeEvent public void Free(Event cause) { Reset(); status = RelayStatus.Free; // reschedule sleep sleepEvent = new SleepEvent() { time = Math.Max(awakeSince + sim.protocolParameters.t_listen, sim.clock), relay = this, sim = sim, previous = cause }; sim.eventQueue.Add(sleepEvent); // OLD CODE // check sleep schedule //if (sim.clock - awakeSince > 999) {//sim.protocolParameters.t_sleep) { // Sleep(cause); //} //else { // // free and reschedule sleep // Reset(); // status = RelayStatus.Free; // sleepEvent = new SleepEvent() { // time = awakeSince + sim.protocolParameters.t_listen,// THIS??? // relay = this, // sim = sim, // previous = cause // }; // sim.eventQueue.Add(sleepEvent); //} }
private void SetPauseState(bool focus, bool pause) { if (focus && !pause) { //唤醒 BeSleep = false; if (BeShowLog) { Debug.Log("[nafio-net]--->唤醒"); } ResumeEvent?.Invoke(); } if (!focus && pause) { if (BeShowLog) { Debug.Log("[nafio-net]--->睡眠"); } //睡 BeSleep = true; SleepEvent?.Invoke(); } }
public void Sleep(Event cause) { lastSleep = sim.clock; sleepEvent = null; // how to free if transmissions incoming? Reset(); receivingTransmissions.Clear(); status = RelayStatus.Asleep; // skip duty cycle events improves simulation performance dramatically if (sim.simulationParameters.skipCycleEvents == false) { // schedule awake sim.eventQueue.Add(new AwakeEvent() { relay = this, time = sim.clock + sim.protocolParameters.t_sleep, sim = sim, previous = cause }); } // update awake time stat totalAwake += sim.clock - awakeSince; }
private void CheckIcon() { RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero, 10f, layer); if (hit) { DialogueTrigger dt = hit.collider.gameObject.GetComponent <DialogueTrigger>(); if (dt && dt.enabled) { ChagueMouseIcon(0); return; } SleepEvent se = hit.collider.gameObject.GetComponent <SleepEvent>(); if (se && se.active) { ChagueMouseIcon(1); return; } RepairEvent re = hit.collider.gameObject.GetComponent <RepairEvent>(); if (re && re.active) { ChagueMouseIcon(2); return; } } else { ResetMouse(); } }
public void SelfReserve() { busyWith = this; // remove sleep (handle sleep when Free occurs) if (sleepEvent != null) { sim.eventQueue.Remove(sleepEvent); sleepEvent = null; } }
public void CreatingASleepEventStoresItsProperties() { SleepEvent shortsleep = new SleepEvent(5, 20, "2/16/15", 7, 3); Assert.AreEqual(5, shortsleep.Hours); Assert.AreEqual(20, shortsleep.Minutes); Assert.AreEqual("2/16/15", shortsleep.Date); Assert.AreEqual(7, shortsleep.MorningFeels); Assert.AreEqual(3, shortsleep.DayFeels); }
public void DatabaseDeleteItem() { repo.Clear(); Assert.AreEqual(0, repo.GetCount()); SleepEvent longsleep = new SleepEvent(10, 30, "2/16/2015", 6, 8); repo.Add(longsleep); Assert.AreEqual(1, repo.GetCount()); repo.Delete(longsleep); Assert.AreEqual(0, repo.GetCount()); }
public void TestSumHours() { SleepEvent sleep1 = new SleepEvent(10, 30, "2/15/2015", 7, 8); SleepEvent sleep2 = new SleepEvent(8, 20, "2/16/2015", 6, 7); SleepEvent sleep3 = new SleepEvent(7, 10, "2/17/2015", 5, 6); SleepEvent sleep4 = new SleepEvent(5, 40, "2/18/2015", 4, 5); repo.Add(sleep1); repo.Add(sleep2); repo.Add(sleep3); repo.Add(sleep4); Assert.AreEqual(30, repo.SumHours()); }
private void Reset() { busyWith = null; freeEvent = null; sleepEvent = null; packetToSend = null; REGION_index = 0; COL_count = 0; SENSE_count = 0; PKT_count = 0; SINK_RTS_count = 0; REGION_cycle = 0; }
//--// void SleepChange(SleepEvent ev) { if (ev.EventType == SleepEventType.ChangeRequested) { _change.Set(); _changeEvent = ev; } else if (ev.EventType == SleepEventType.WakeUp) { _wakeup.Set(); _wakeupEvent = ev; } else { Debug.Assert(false); } }
public MFTestResults Sleep_3_NoSystemTimerTest() { bool result = true; TimeSpan backup = PowerState.MaximumTimeToActive; try { PowerState.MaximumTimeToActive = new TimeSpan(0, 0, 0, 2); TimeSpan tsTimeout = PowerState.MaximumTimeToActive; PowerState.OnSleepChange += new SleepChangeEventHandler(this.SleepChange); HardwareEvent newEvents = HardwareEvent.OEMReserved1; _timerFired.Reset(); _wakeupEvent = null; Timer t = new Timer(new TimerCallback(this.TimerCallback), null, tsTimeout.Milliseconds / 2, Timeout.Infinite); DateTime dtStart = DateTime.Now; // this will wake up with the max time allowed PowerState.Sleep(SleepLevel.Sleep, newEvents); /// /// When the debugging is enbled on a device the debug port is selected as a wakeup event by default, /// so we ignore this test if we get any events. /// if (_timerFired.WaitOne(1000, false) && (_wakeupEvent == null || _wakeupEvent.WakeUpEvents == 0)) { result = (_timerTime - dtStart) > tsTimeout; } PowerState.OnSleepChange -= new SleepChangeEventHandler(this.SleepChange); } finally { PowerState.MaximumTimeToActive = backup; } return(result ? MFTestResults.Pass : MFTestResults.Fail); }
public void Awake(Event cause) { // no need for UpdateAwakeTime because the cause is a sleep event if (cause.GetType() != typeof(StartEvent) && cause.GetType() != typeof(AwakeEvent)) { throw new Exception("Awake with no reason"); } // set relay as free, schedule sleep, set awake_time (used in FreeEvent) status = RelayStatus.Free; awakeSince = sim.clock; sleepEvent = new SleepEvent() { time = sim.clock + sim.protocolParameters.t_listen, relay = this, sim = sim, previous = cause }; sim.eventQueue.Add(sleepEvent); }
// called only if relay is either free or already busy with the reserver public void Reserve(Relay reserver, Event cause) { if (this.status == RelayStatus.Free || this.busyWith == reserver) { // remove sleep (handle sleep when Free occurs) if (sleepEvent != null) { sim.eventQueue.Remove(sleepEvent); sleepEvent = null; } if (reserver == this) { throw new Exception("Can't use Reserve on self, use SelfReserve instead"); } else { if (busyWith == null) { busyWith = reserver; freeEvent = new FreeEvent { time = sim.clock + sim.protocolParameters.t_busy, relay = this, sim = sim, previous = cause }; sim.eventQueue.Add(freeEvent); } else { freeEvent.time = sim.clock + sim.protocolParameters.t_busy; sim.eventQueue.Reschedule(freeEvent); } } } else { throw new Exception("Cannot reserve this relay"); } }
public void AwakeMidtime(Event cause) { // update awake time, useful only when using skipCycle UpdateAwakeTime(); status = RelayStatus.Free; var n_cycles = Math.Floor((sim.clock - lastSleep) / sim.protocolParameters.t_cycle); lastSleep = lastSleep + n_cycles * sim.protocolParameters.t_cycle; awakeSince = lastSleep + sim.protocolParameters.t_sleep; sleepEvent = new SleepEvent() { time = awakeSince + sim.protocolParameters.t_listen, relay = this, sim = sim, previous = cause }; if (sleepEvent.time < sim.clock) { throw new Exception("no time travel plz"); } sim.eventQueue.Add(sleepEvent); }
} //Abort internal void PutToSleep() { SleepEvent.Reset(); } //PutToSleep
internal void OnSleepEvent(object sender, SleepEvent e) { if (SleepEvent != null) SleepEvent(sender, e); }
public void Delete(SleepEvent E) { _dbContext.SleepEvents.Remove(E); _dbContext.SaveChanges(); }
public void Add(SleepEvent E) { _dbContext.SleepEvents.Add(E); _dbContext.SaveChanges(); }
void _selectedObject_OnSleep(object sender, SleepEvent e) { MessageBox.Show("Sleeping"); ((GameObject)sender).OnSleep -= _selectedObject_OnSleep; }
} //PutToSleep internal void WakeUp() { SleepEvent.Set(); } //WakeUp
protected void SyncPoint() { SleepEvent.WaitOne(); } //SyncPoint