public SimulationSaver(ArrayList _objs, Medium _med) { _objects = _objs; _MEDIUM = _med; }
//==================================================================================================== private void Form1_Load(object sender, EventArgs e) { piB = new PictureBox(); cmbAlgorithm.Items.Add(SLSAlgType.NullDataBased.ToString()); cmbAlgorithm.Items.Add(SLSAlgType.WindowBased.ToString()); piB.Parent = this; piB.Location = new Point(10, 10); piB.Size = new Size(_BOARDX, _BOARDY); piB.BackColor = Color.Black; piB.AllowDrop = true; this.piB.MouseDown += new System.Windows.Forms.MouseEventHandler(this.btnImage_MouseDown); this.piB.MouseUp += new System.Windows.Forms.MouseEventHandler(this.btnImage_MouseUp); this.piB.DragDrop += new System.Windows.Forms.DragEventHandler(this.pictureBox_DragDrop); this.piB.DragEnter += new System.Windows.Forms.DragEventHandler(this.pictureBox_DragEnter); this.piB.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.BoardDblClick); bm = new Bitmap(piB.Width, piB.Height); gr = Graphics.FromImage(bm); if (settings.getValue(_KEY_RECEIVE_DISTANCE).Length > 0) { Medium.ReceiveDistance = Convert.ToInt32(settings.getValue(_KEY_RECEIVE_DISTANCE)); } else { Medium.ReceiveDistance = 100; settings.setValue(_KEY_RECEIVE_DISTANCE, Medium.ReceiveDistance.ToString()); } if (settings.getValue(_KEY_MEDIUM_SLS_PERIOD).Length > 0) { Medium.SLSPeriod = Convert.ToInt32(settings.getValue(_KEY_MEDIUM_SLS_PERIOD)); } else { Medium.SLSPeriod = 1000; settings.setValue(_KEY_MEDIUM_SLS_PERIOD, Medium.SLSPeriod.ToString()); } if (settings.getValue(_KEY_MEDIUM_SLS_COUNTER).Length > 0) { Medium.SLSPacketsNumber = Convert.ToInt32(settings.getValue(_KEY_MEDIUM_SLS_COUNTER)); } else { Medium.SLSPacketsNumber = 20; settings.setValue(_KEY_MEDIUM_SLS_COUNTER, Medium.SLSPacketsNumber.ToString()); } if (settings.getValue(_KEY_MEDIUM_TDLS_STARTER_DELAY).Length > 0) { Medium.TdlsStarterDelay = Convert.ToInt32(settings.getValue(_KEY_MEDIUM_TDLS_STARTER_DELAY)); } else { Medium.TdlsStarterDelay = 5000; settings.setValue(_KEY_MEDIUM_TDLS_STARTER_DELAY, Medium.TdlsStarterDelay.ToString()); } if (settings.getValue(_KEY_MEDIUM_RUN_PERIOD).Length > 0) { Medium.RunPeriod = Convert.ToInt32(settings.getValue(_KEY_MEDIUM_RUN_PERIOD)); } else { Medium.RunPeriod = 3000; settings.setValue(_KEY_MEDIUM_RUN_PERIOD, Medium.RunPeriod.ToString()); } if (settings.getValue(_KEY_MEDIUM_BUFFER_SIZE).Length > 0) { Medium.PACKET_BUFFER_SIZE = Convert.ToInt32(settings.getValue(_KEY_MEDIUM_BUFFER_SIZE)); } else { Medium.PACKET_BUFFER_SIZE = 100000; settings.setValue(_KEY_MEDIUM_BUFFER_SIZE, Medium.PACKET_BUFFER_SIZE.ToString()); } if (settings.getValue(_KEY_SLS_ALGORITHM_USE).Length > 0) { Medium.SlsAlgorithm = (SLSAlgType)Enum.Parse(typeof(SLSAlgType), settings.getValue(_KEY_SLS_ALGORITHM_USE)); } else { Medium.SlsAlgorithm = SLSAlgType.NullDataBased; settings.setValue(_KEY_SLS_ALGORITHM_USE, Medium.SlsAlgorithm.ToString()); } if (settings.getValue(_KEY_SLS_AMOUNT_OF_WINDOW_SIZE).Length > 0) { Medium.slsWinNumOfPackPerSampleCycle = Convert.ToInt32(settings.getValue(_KEY_SLS_AMOUNT_OF_WINDOW_SIZE)); } else { Medium.slsWinNumOfPackPerSampleCycle = 30; settings.setValue(_KEY_SLS_AMOUNT_OF_WINDOW_SIZE, Medium.slsWinNumOfPackPerSampleCycle.ToString()); } if (settings.getValue(_KEY_SLS_ALG_AMOUNT_START).Length > 0) { Medium.slsWin_StartFromSLSWindowSize = (short)Convert.ToInt32(settings.getValue(_KEY_SLS_ALG_AMOUNT_START)); } else { Medium.slsWin_StartFromSLSWindowSize = 4; settings.setValue(_KEY_SLS_ALG_AMOUNT_START, Medium.slsWin_StartFromSLSWindowSize.ToString()); } if (settings.getValue(_KEY_SLS_ALG_AMOUNT_MAX).Length > 0) { Medium.slsWin_MaxSLSWindowSize = (short)Convert.ToInt32(settings.getValue(_KEY_SLS_ALG_AMOUNT_MAX)); } else { Medium.slsWin_MaxSLSWindowSize = 6; settings.setValue(_KEY_SLS_ALG_AMOUNT_MAX, Medium.slsWin_MaxSLSWindowSize.ToString()); } if (settings.getValue(_KEY_SLS_ALG_AMOUNT_MIN).Length > 0) { Medium.slsWin_MinSLSWindowSize = (short)Convert.ToInt32(settings.getValue(_KEY_SLS_ALG_AMOUNT_MIN)); } else { Medium.slsWin_MinSLSWindowSize = 2; settings.setValue(_KEY_SLS_ALG_AMOUNT_MIN, Medium.slsWin_MinSLSWindowSize.ToString()); } if (settings.getValue(_KEY_GRAFFIC_UPD_INT).Length > 0) { txtUpdateInterval.Text = settings.getValue(_KEY_GRAFFIC_UPD_INT); } GrafficUpdateInterval(); if (settings.getValue(_KEY_MEDIUM_SEND_RATIO).Length > 0) { txtMediumSendRatio.Text = settings.getValue(_KEY_MEDIUM_SEND_RATIO); } SetMedioRatio(); Medium.ListenDistance = 200; Medium.WaitBeforeRetransmit = 60; Medium.TrysToRetransmit = 5; Medium.RetransmitWindow = 100; Medium.MediumStart(); Medium.TDLS_TearDownAfterFails = 13; txtMediumReceiveDistance.Text = Medium.ReceiveDistance.ToString(CultureInfo.InvariantCulture); txtSLSPeriod.Text = Medium.SLSPeriod.ToString(CultureInfo.InvariantCulture); cmbAlgorithm.SelectedText = Medium.SlsAlgorithm.ToString(); txtSLSPacketsNumber.Text = Medium.SLSPacketsNumber.ToString(CultureInfo.InvariantCulture); txtTdlsStarterDelay.Text = Medium.TdlsStarterDelay.ToString(CultureInfo.InvariantCulture); txtMediumRunPeriod.Text = Medium.RunPeriod.ToString(CultureInfo.InvariantCulture); txtAmountWindowSize.Text = Medium.slsWinNumOfPackPerSampleCycle.ToString(CultureInfo.InvariantCulture); txtDataBufferSize.Text = Medium.PACKET_BUFFER_SIZE.ToString(CultureInfo.InvariantCulture); txtSlsAmountStart.Text = Medium.slsWin_StartFromSLSWindowSize.ToString(CultureInfo.InvariantCulture); txtSlsAmountMax.Text = Medium.slsWin_MaxSLSWindowSize.ToString(CultureInfo.InvariantCulture); txtSlsAmountMin.Text = Medium.slsWin_MinSLSWindowSize.ToString(CultureInfo.InvariantCulture); SetMedioRatio(); SetBSSDelay(); SetTDLSDelay(); }
//===================================================================== public static void SaveDumpToFile() { StringBuilder sb = new StringBuilder(); try { using (StreamWriter outfile = new StreamWriter(DUMP_FILE_PATH)) { outfile.Write(getMediumInfo() + "\r\n===================== Packets DUMP =====================\r\n" + Medium.DumpPackets()); } } catch (Exception ex) { if (DebugLogEnabled) { AddToLog("Medium SaveDumpToFile " + ex.Message); } } }
//===================================================================== /// <summary> /// Function for Listen And Receive Packets /// </summary> /// <param name="sender">Value for know info about received packets</param> /// <param name="args">Not used - needed by event</param> public void Listen(object sender, EventArgs args) { //while (_Enabled) //{ //SpinWait.SpinUntil(checkIfHaveDataReceive); //SpinWait.SpinUntil(RF_Ready); if (((SimulatorPacket)sender).PacketChannel != this.getOperateChannel()) { return; } if (((SimulatorPacket)sender).PacketFrequency != this.Freq) { return; } double dist = GetSTADist(((SimulatorPacket)sender).X, ((SimulatorPacket)sender).Y, this.x, this.y); if (dist > Medium.ReceiveDistance) { return; } string desinationOfReceivedPacket = ((SimulatorPacket)sender).Destination; if ((this.GetType() == typeof(STA) && desinationOfReceivedPacket.Equals("FF:FF:FF:FF:FF:FF")) || desinationOfReceivedPacket.Equals(this.getMACAddress())) { double t = GetNoiseRSSI(((SimulatorPacket)sender).Source); if (sender.GetType() == typeof(Data)) { if (!MissPacket(t, ((SimulatorPacket)sender).getTransmitRate())) { _badPackets++; return; } } //SpinWait.SpinUntil(ListenCondition);//,1); prev_guid = new Guid(); SimulatorPacket pack = null; lock (RfSync) { RF_STATUS = RFStatus.Rx; pack = Medium.ReceiveData(this); RF_STATUS = RFStatus.None; } if (pack == null) { } else //if (pack != null )//&& (prev_guid != pack.GuidD || pack.IsRetransmit)) { // Only if we have received packet before // but flag Rentransmit is UP if (prev_guid == pack.GuidD) { pack.IsReceivedRetransmit = true; } if (pack.GetType() != typeof(Beacon)) { prev_guid = pack.GuidD; } AllReceivedPackets += 1; //Thread newThread = new Thread(() => ParseReceivedPacket(pack),1); //newThread.Name = "ParseReceivedPacket of " + this.getMACAddress(); //newThread.Start(); ThreadPool.QueueUserWorkItem(new WaitCallback((s) => ParseReceivedPacket(pack))); } } }
//===================================================================== private bool checkIfHaveDataReceive() { return(Medium.MediumHaveAIRWork(this, ListenBeacon)); }