Exemplo n.º 1
0
        //=====================================================================
        //[MethodImpl(MethodImplOptions.Synchronized)]
        /// <summary>
        /// Function for parse received packet
        /// </summary>
        /// <param name="pack">SimulatorPacket</param>
        public override void ParseReceivedPacket(SimulatorPacket pack)
        {
            Type pt = pack.GetType();

            if (pt == typeof(Connect))
                ConnectRoutine(pack.Source);
            else if (pt == typeof(Disconnect))
                DisonnectRoutine(pack.Source);
            else if (pt == typeof(KeepAlive))
            {
                var newThread = new Thread(() => UpdateSTAKeepAliveInfoOnReceive(pack.Source));
                newThread.Start();
            }
            else if (pt == typeof(Data))
                DataRoutine((Data) pack);
            else if (pt == typeof(DataAck))
                DataAckRoutine((DataAck)pack);
            else
                OtherPacketsRoutine(pack);
        }
Exemplo n.º 2
0
 //=====================================================================
 /// <summary>
 /// This function work with all others packets which don't have special Routines
 /// </summary>
 /// <param name="pack">Simulator Packet </param>
 private void OtherPacketsRoutine(SimulatorPacket pack)
 {
     //  Generic Packet retransmitter
     //  This code will create new packet by him type
     var instance = (SimulatorPacket)Activator.CreateInstance(pack.GetType(), pack);
     instance.X              = this.x;
     instance.Y              = this.y;
     instance.Destination    = pack.Reciver;
     SendData(instance);
 }
Exemplo n.º 3
0
        //*********************************************************************
        public void SendData(SimulatorPacket pack)
        {
            CheckScanConditionOnSend();
            int Rate = pack.getTransmitRate();
            int sleep = (int)(600 / Rate);
            lock (RfSync)
            {
                try{
                    RF_STATUS = RFStatus.Tx;
                    short OperateChannel = this.getOperateChannel();
                    int try_counter = 0;
                    while (!Medium.Registration(this.Freq, OperateChannel, this.x, this.y, sleep))
                    {
                        Thread.Sleep(new TimeSpan(randomWait.Next(20, 50)));
                        if (try_counter++ > 200)
                            return;
                    }
                    this.MACLastTrnsmitRate = pack.getTransmitRate();
                    Medium.SendData(pack);
                }
                catch(Exception ex){
                    AddToLog("SendData:[" + this.GetType() + "] " + ex.Message);
                    MessageBox.Show("SendData :" + ex.Message);
                }

                RF_STATUS = RFStatus.None;
            }
            if (pack.GetType() == typeof(Data)){
                _DataSent++;
            }
        }