Esempio n. 1
0
        /// <summary>
        /// intilize the MAC
        /// </summary>
        /// <param name="_Node"></param>
        public BoXMAC(Sensor _Node)
        {
            Node = _Node;
            if (Node != null)
            {
                if (Node.ID != PublicParamerters.SinkNode.ID)
                {
                    double xpasn = 1 + UnformRandomNumberGenerator.GetUniformSleepSec(MacStartUp);
                    // the swich on timer.
                    SwichOnTimer.Interval = TimeSpan.FromSeconds(xpasn);
                    SwichOnTimer.Start();
                    SwichOnTimer.Tick += ASwichOnTimer_Tick;
                    ActiveCounter      = 0;
                    // active/sleep timer:
                    ActiveSleepTimer.Interval = TimeSpan.FromSeconds(1);// the intervale is one second.
                    ActiveSleepTimer.Tick    += ActiveSleepTimer_Tick;;
                    SleepCounter = 0;

                    // intialized:
                    Node.CurrentSensorState = SensorStatus.intalized;
                    Node.Ellipse_MAC.Fill   = NodeStateColoring.IntializeColor;
                }
            }
            else
            {
                // the
                PublicParamerters.SinkNode.CurrentSensorState = SensorStatus.Active;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// intilize the MAC
        /// </summary>
        /// <param name="_Node"></param>
        public BoXMAC(Sensor _Node)
        {
            Node         = _Node;
            ActivePeriod = Periods.ActivePeriod; //初始值为系统默认值
            SleepPeriod  = Periods.SleepPeriod;  //初始值为系统默认值
            if (Node != null)
            {
                if (Node.ID != PublicParamerters.SinkNode.ID)//设置非sink节点的醒睡模式
                {
                    //为了实现异步通信,每个节点开启醒睡模式的时刻不同
                    double xpasn = UnformRandomNumberGenerator.GetUniformSleepSec(MacStartUp);
                    // the swich on timer.
                    SwichOnTimer.Interval = TimeSpan.FromSeconds(xpasn);
                    SwichOnTimer.Start();
                    SwichOnTimer.Tick += ASwichOnTimer_Tick;

                    SleepCounter  = 0; //睡计时器
                    ActiveCounter = 0; //醒计数器,表示节点处于当前模式的时间

                    // active/sleep timer:定时改变SensorState的值,分别用Active表示醒,Sleep表示睡
                    // ActiveSleepTimer.Interval = TimeSpan.FromSeconds(1);
                    ActiveSleepTimer.Interval = TimeSpan.FromMilliseconds(CheckActiveSleepTime);
                    ActiveSleepTimer.Tick    += ActiveSleepTimer_Tick;

                    //检测节点等待队列定时器的相关设置
                    QueueTimer.Interval = TimeSpan.FromMilliseconds(CheckQueueTime);
                    QueueTimer.Tick    += QueueTimer_Tick;

                    // intialized:
                    Node.CurrentSensorState = SensorState.intalized;
                    Node.Ellipse_MAC.Fill   = NodeStateColoring.IntializeColor;
                }
                else
                {
                    // sink节点的状态永远是Active
                    PublicParamerters.SinkNode.CurrentSensorState = SensorState.Active;
                }
            }
        }