/// <summary>
        /// Set the radio into polling mode in a loop - Spending some time active listening for packets, and then some time powered down.
        /// </summary>
        public void RadioSetModePolling(double timeOn, double timeOff)
        {
            ReceiverPollingContext c = new ReceiverPollingContext();

            c.TimeOn  = timeOn * DeviceTimingSkew;
            c.TimeOff = timeOff * DeviceTimingSkew;
            ParentSimulation.NodeSetReceiverState(this, c);
        }
Exemple #2
0
        IEnumerable <TimeWindow> ComputeReceiveRegions()
        {
            SimulationEvent[] terminatingEvent = new SimulationEvent[] { new SimulationEvent(Node.ParentSimulation.CurrentTime, Node, EventType.PowerState, false) };

            SimulationEvent previousEvent = null;
            object          previousState = null;
            double          prevTime      = 0;

            foreach (var e in Node.PastEvents.Events.Where(e => e.Type == EventType.PowerState).Concat(terminatingEvent))
            {
                double curTime = e.StartTime;
                if (previousState is bool && (bool)previousState == true)
                {
                    // Radio was on for the current period
                    yield return(new TimeWindow()
                    {
                        Event = previousEvent, Start = prevTime, End = curTime
                    });
                }
                else if (previousState is ReceiverPollingContext)
                {
                    ReceiverPollingContext c = (ReceiverPollingContext)previousState;

                    double time = prevTime;
                    while (time < curTime)
                    {
                        double endTime = c.TimeOn + time;
                        if (endTime > curTime)
                        {
                            endTime = curTime;
                        }
                        yield return(new TimeWindow()
                        {
                            Event = previousEvent, Start = time, End = endTime
                        });

                        time += c.TimeOn + c.TimeOff;
                    }
                }
                previousEvent = e;
                previousState = e.EventContext;
                prevTime      = e.StartTime;
            }
        }