public void ThreadAbleReadFile(String fileName) { string[] lines = System.IO.File.ReadAllLines(@"C:\simulator\_DATA_TO_SEND\input.txt"); AP _connecttoAP = GetAPBySSID(_AccessPoint[0].ToString()); Data dataPack = new Data(CreatePacket()); dataPack.SSID = _connecttoAP.SSID; dataPack.Destination = _connecttoAP.getMACAddress(); dataPack.PacketChannel = this.getOperateChannel(); dataPack.PacketBand = this.getOperateBand(); dataPack.Reciver = fileName; Int32 SQID = 0; foreach (string line in lines) { // Use a tab to indent each line of the file. dataPack = new Data(CreatePacket()); dataPack.SSID = _connecttoAP.SSID; dataPack.Destination = _connecttoAP.getMACAddress(); dataPack.PacketChannel = this.getOperateChannel(); dataPack.PacketBand = this.getOperateBand(); dataPack.Reciver = fileName; SQID++; dataPack.setData(line); dataPack.PacketID = SQID; ackReceived = false; SendData(dataPack); WaitingForAck = true; int retrCounter = 60; Thread.Sleep(6); while (!ackReceived) { retrCounter--; Thread.Sleep(2); if (retrCounter < 0) { retrCounter = 60; SendData(dataPack); _DataRetransmited++; } } WaitingForAck = false; //SpinWait.SpinUntil(() => { return ackReceived; }); // Thread.Sleep(3); //Console.WriteLine("\t" + line); } }
public SimulatorPacket CreatePacket() { SimulatorPacket pack = new SimulatorPacket(getOperateChannel(), getOperateBand()); pack.Source = getMACAddress(); if (this.GetType() == typeof(AP)) { AP _ap = (AP)this; pack.SSID = _ap.SSID; } pack.X = this.x; pack.Y = this.y; return(pack); }
//********************************************************************* public AP GetAPBySSID(String _SSID) { foreach (var obj in _PointerToAllRfDevices) { if (obj.GetType() == typeof(AP)) { AP _tV = (AP)obj; if (_tV.SSID.Equals(_SSID)) { return(_tV); } } } return(null); }
private void lblAssociatedAP_MouseDoubleClick(object sender, MouseEventArgs e) { for (int i = 0; i < _objects.Count; i++) { if (_objects[i].GetType() == typeof(AP)) { AP _tap = (AP)_objects[i]; if (lblAssociatedAP.Text.ToString().Equals(_tap.SSID.ToString())) { //txtConsole.Text = "AP selected for move :" + i.ToString() + "\r\n" + txtConsole.Text; APInfo apInf = new APInfo(_tap, _objects); apInf.Show(); return; } } } }
private void cmdAdd1APforSTA_Click(object sender, EventArgs e) { ClearObjects(); LeftPannelSmall(); AP _ap = new AP(); _ap.setOperateChannel((short)rand.Next(1, 14)); _ap.SetVertex(300, 200, 0); _objects.Add(_ap); STA _sta = new STA(_objects); _sta.setOperateChannel(0); _sta.SetVertex(320, 210, 0); _objects.Add(_sta); _sta.Scan(); STA _sta2 = new STA(_objects); _sta2.setOperateChannel(0); _sta2.SetVertex(280, 170, 0); _objects.Add(_sta2); _sta2.Scan(); STA _sta3 = new STA(_objects); _sta3.setOperateChannel(0); _sta3.SetVertex(280, 210, 0); _objects.Add(_sta3); _sta3.Scan(); STA _sta4 = new STA(_objects); _sta4.setOperateChannel(0); _sta4.SetVertex(320, 170, 0); _objects.Add(_sta4); _sta4.Scan(); Medium.setMediumObj(_objects); SetMedioRatio(); Medium.Enable(); DrowOnBoard(); }
//==================================================================================================== private void btnImage_MouseUp(object sender, MouseEventArgs e) { MouseX = e.X; MouseY = e.Y; // txtConsole.Text = "X = " + e.X + " Y = " + e.Y + "\r\n" + txtConsole.Text; if (SelectedVertex < 0) { //ConsolePrint("No object selected for move"); return; } if (SelectedX != e.X && SelectedY != e.Y) { //ConsolePrint("Start move object"); if (_ob == SelectedObjectType.AP) { AP _tAP = (AP)_objects[SelectedVertex]; // ConsolePrint("Drawing " + _tAP.getMAC().getMAC()); _tAP.x = e.X; _tAP.y = e.Y; } if (_ob == SelectedObjectType.STA) { STA _tsta = (STA)_objects[SelectedVertex]; // ConsolePrint("Drawing " + _tsta.getMACAddress()); _tsta.x = e.X; _tsta.y = e.Y; } } else { ConsolePrint("Object not moved: Simple click"); } if (e.Button == MouseButtons.Right) { contextMenuStrip1.Show(this, new Point(e.X, e.Y)); } SelectedVertex = -1; refr(); }
//********************************************************************* private void ThreadableConnectToAP(String SSID, Connect _conn, AP _connecttoAP) { bool connectSuccess = false; _AssociatedWithAPList.Clear(); Int32 tRYStOcONNECT = 0; _conn.SSID = _connecttoAP.SSID; _conn.Destination = _connecttoAP.getMACAddress(); _conn.PacketChannel = _connecttoAP.getOperateChannel(); _conn.PacketBand = _connecttoAP.getOperateBand(); _conn.Reciver = _connecttoAP.getMACAddress(); this.setOperateChannel(_connecttoAP.getOperateChannel()); this.setOperateBand(_connecttoAP.getOperateBand()); while (!connectSuccess) { if (!_AssociatedWithAPList.Contains(SSID)) { if (tRYStOcONNECT < 10) { SendData(_conn); tRYStOcONNECT++; Thread.Sleep(1000); } } else { connectSuccess = true; } } if (connectSuccess && _scanning) { SpinWait.SpinUntil (() => { return((bool)!_scanning); } ); this.setOperateChannel(_connecttoAP.getOperateChannel()); this.setOperateBand(_connecttoAP.getOperateBand()); } // Fix Work Channel under scan }
//********************************************************************* public Boolean ConnectToAP(String SSID) { if (SSID.Length > 0 && _AccessPoint.Contains(SSID)) { Connect _conn = new Connect(CreatePacket()); AP _connecttoAP = GetAPBySSID(SSID); if (_connecttoAP != null) { Thread newThread = new Thread(() => ThreadableConnectToAP(SSID, _conn, _connecttoAP)); newThread.Start(); return(true); } else { AddToLog("Cannot find AP with SSID:" + SSID); } } return(false); }
//==================================================================================================== private void btnImage_MouseDown(object sender, MouseEventArgs e) { txtConsole.Text = "X = " + e.X + " Y = " + e.Y + "\r\n" + txtConsole.Text; const int _rad_size = 12; for (int i = 0; i < _objects.Count; i++) { if (_objects[i].GetType() == typeof(STA)) { STA _tsta = (STA)_objects[i]; if (_tsta.x >= e.X - _rad_size && _tsta.x <= e.X + _rad_size && _tsta.y >= e.Y - _rad_size && _tsta.y <= e.Y + _rad_size) { //txtConsole.Text = "Station selected for move :" + i.ToString() + "\r\n" + txtConsole.Text; SelectedVertex = i; SelectedX = e.X; SelectedY = e.Y; SelectedZ = e.X + e.Y; //_ob = SelectedObjectType.STA; _tsta.VColor = Color.Red; return; } } else if (_objects[i].GetType() == typeof(AP)) { AP _tap = (AP)_objects[i]; if (_tap.x >= e.X - _rad_size && _tap.x <= e.X + _rad_size && _tap.y >= e.Y - _rad_size && _tap.y <= e.Y + _rad_size) { //txtConsole.Text = "AP selected for move :" + i.ToString() + "\r\n" + txtConsole.Text; SelectedVertex = i; SelectedX = e.X; SelectedY = e.Y; SelectedZ = e.X + e.Y; _tap.VColor = Color.Red; //_ob = SelectedObjectType.AP; return; } } } }
//==================================================================================================== private void CreateRandomSimulation() { ClearObjects(); for (int i = 0; i < APs_SIZE; i++) { AP _ap = new AP(_MEDIUM); _ap.setOperateChannel(rand.Next(1, 14)); _ap.SetVertex(RandomC(_BOARDX), RandomC(_BOARDY), rand.NextDouble() * 500); _objects.Add(_ap); } for (int i = 0; i < STA_SIZE; i++) { STA _sta = new STA(_MEDIUM, _objects); _sta.setOperateChannel(0);// (rand.Next(1, 14)); // TODO delete this line _sta.SetVertex(RandomC(_BOARDX), RandomC(_BOARDY), rand.NextDouble() * 500); _objects.Add(_sta); _sta.Scan(); } _MEDIUM.setMediumObj(_objects); _MEDIUM.Enable(); }
//==================================================================================================== private void CreateRandomSimulation() { ClearObjects(); for (int i = 0; i < APs_SIZE; i++) { AP _ap = new AP(); _ap.setOperateChannel((short)rand.Next(1, 14)); _ap.SetVertex((int)RandomC(_BOARDX), (int)RandomC(_BOARDY), 0); _objects.Add(_ap); } for (int i = 0; i < STA_SIZE; i++) { STA _sta = new STA(_objects); _sta.setOperateChannel(0); // (rand.Next(1, 14)); // TODO delete this line _sta.SetVertex((int)RandomC(_BOARDX), (int)RandomC(_BOARDY), 0); _objects.Add(_sta); _sta.Scan(); } Medium.setMediumObj(_objects); SetMedioRatio(); Medium.Enable(); }
private void SendKeepAlive() { while (_Enabled) { if (!getAssociatedAP_SSID().Equals("")) { KeepAlive keepAl = new KeepAlive(CreatePacket()); AP _connecttoAP = GetAPBySSID(_AccessPoint[0].ToString()); Data dataPack = new Data(CreatePacket()); keepAl.SSID = _connecttoAP.SSID; keepAl.Destination = _connecttoAP.getMACAddress(); keepAl.PacketChannel = this.getOperateChannel(); keepAl.PacketBand = this.getOperateBand(); keepAl.Reciver = _connecttoAP.getMACAddress(); SendData(keepAl); Thread.Sleep(3000); } else { Thread.Sleep(10000); } } }
/// <summary> /// Constructor /// </summary> /// <param name="apP">Pointer to AP</param> /// <param name="_obj">Pointer to All Devices</param> public APInfo(AP apP,ArrayList _obj) { InitializeComponent(); _ap = apP; _objects = _obj; }
//==================================================================================================== private void CreateRandomSimulation() { ClearObjects(); for (int i = 0; i < APs_SIZE; i++) { AP _ap = new AP(); _ap.setOperateChannel((short)rand.Next(1, 14)); _ap.SetVertex((int)RandomC(_BOARDX), (int)RandomC(_BOARDY), 0); _objects.Add(_ap); } for (int i = 0; i < STA_SIZE; i++) { STA _sta = new STA( _objects); _sta.setOperateChannel(0); // (rand.Next(1, 14)); // TODO delete this line _sta.SetVertex((int)RandomC(_BOARDX), (int)RandomC(_BOARDY), 0); _objects.Add(_sta); _sta.Scan(); } Medium.setMediumObj(_objects); SetMedioRatio(); Medium.Enable(); }
//==================================================================================================== private void CreateAP() { AP _ap = new AP(); _ap.setOperateChannel((short)rand.Next(1, 14)); _ap.SetVertex((int)MouseX, (int)MouseY, 0); _objects.Add(_ap); Medium.setMediumObj(_objects); }
private void cmdCreateOneAPTwoSta_Click(object sender, EventArgs e) { ClearObjects(); LeftPannelSmall(); AP _ap = new AP(); _ap.setOperateChannel((short)rand.Next(1, 14)); _ap.SetVertex(300, 200, 0); _objects.Add(_ap); STA _sta = new STA(_objects); _sta.setOperateChannel(0); // (rand.Next(1, 14)); // TODO delete this line _sta.SetVertex(320, 210, 0); _objects.Add(_sta); _sta.Scan(); STA _sta2 = new STA(_objects); _sta2.setOperateChannel(0); // (rand.Next(1, 14)); // TODO delete this line _sta2.SetVertex(280, 170, 0); _objects.Add(_sta2); _sta2.Scan(); Medium.setMediumObj(_objects); SetMedioRatio(); Medium.Enable(); DrowOnBoard(); }
//********************************************************************* public void ParseReceivedPacket(IPacket pack) { Type _Pt = pack.GetType(); if (_Pt == typeof(Packets.ConnectionACK)) { Packets.ConnectionACK _ack = (Packets.ConnectionACK)pack; if (!_AssociatedWithAPList.Contains(_ack.SSID)) { _AssociatedWithAPList.Add(_ack.SSID); Thread.Sleep(5); } } else if (_Pt == typeof(Packets.Beacon)) { Packets.Beacon bec = (Packets.Beacon)pack; if (!_AccessPoint.Contains(bec.SSID)) { _AccessPoint.Add(bec.SSID); } _AccessPoint.Increase(bec.SSID); //Thread.Sleep(2); } else if (_Pt == typeof(Packets.Data)) { Packets.Data dat = (Packets.Data)pack; bool recieve = dat.PacketID != PrevDataID; if (recieve) { _DataReceived++; DataAck da = new DataAck(CreatePacket()); PrevDataID = dat.PacketID; AP _connecttoAP = GetAPBySSID(_AccessPoint[0].ToString()); da.Destination = _connecttoAP.getMACAddress(); da.PacketChannel = this.getOperateChannel(); da.PacketBand = this.getOperateBand(); da.Reciver = dat.Source; DataReceivedContainer.Append(dat.getData() + "\r\n"); //Thread.Sleep(2); da.PacketID = dat.PacketID; SendData(da); } else { // ACK Not received AddToLog("ACK Not received :" + dat.PacketID); DataAck da = new DataAck(CreatePacket()); //PrevDataID = dat.PacketID; AP _connecttoAP = GetAPBySSID(_AccessPoint[0].ToString()); da.Destination = _connecttoAP.getMACAddress(); da.PacketChannel = this.getOperateChannel(); da.PacketBand = this.getOperateBand(); da.Reciver = dat.Source; //DataReceivedContainer.Append(dat.getData() + "\r\n"); //Thread.Sleep(2); DataAckRetransmitted++; da.PacketID = dat.PacketID; SendData(da); } } else if (_Pt == typeof(Packets.DataAck)) { Packets.DataAck dat = (Packets.DataAck)pack; if (PrevDataAckID != dat.PacketID) { _DataAckReceived++; ackReceived = true; PrevDataAckID = dat.PacketID; } } else { //Console.WriteLine("[" + getMACAddress() + "]" + " listening."); } }
public APInfo(AP apP, ArrayList _obj) { InitializeComponent(); _ap = apP; _objects = _obj; }
//==================================================================================================== public void refr() { try { gr.Clear(BoardColor); Pen RadiusForApPen = null; Pen RadiusForStaPen = null; int DoubleRadius = _RADIUS * 2; int HalfRadius = _RADIUS; for (int i = 0; i < _objects.Count; i++) { if (_objects[i].GetType() == typeof(STA)) { STA _tsta = (STA)_objects[i]; if (_tsta.RFWorking()) { RadiusForStaPen = new Pen(System.Drawing.Color.SandyBrown); } else { RadiusForStaPen = new Pen(System.Drawing.Color.SpringGreen); } Point ulCorner = new Point((int)_tsta.x - 10, (int)_tsta.y - 10); gr.DrawImage(_tsta.STAImage, ulCorner); gr.DrawPie(RadiusForStaPen, (float)_tsta.x - HalfRadius, (float)_tsta.y - HalfRadius, DoubleRadius, DoubleRadius, 1, 360); string drawString = "STA:" + _tsta.getOperateChannel() + " " + _tsta.getMACAddress(); System.Drawing.Font drawFont = new System.Drawing.Font( "Arial", 7); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.YellowGreen); gr.DrawString(drawString, drawFont, drawBrush, (int)_tsta.x + 10, (int)_tsta.y + 10); drawFont.Dispose(); drawBrush.Dispose(); } else if (_objects[i].GetType() == typeof(AP)) { AP _tap = (AP)_objects[i]; Rectangle myRectangle = new Rectangle((int)_tap.x - 5, (int)_tap.y - 5, 10, 10); if (_tap.RFWorking()) { RadiusForApPen = new Pen(System.Drawing.Color.Coral); } else { RadiusForApPen = new Pen(System.Drawing.Color.Ivory); } gr.DrawPie(RadiusForApPen, (float)_tap.x - HalfRadius, (float)_tap.y - HalfRadius, DoubleRadius, DoubleRadius, 1, 360); Point ulCorner = new Point((int)_tap.x - 10, (int)_tap.y - 10); gr.DrawImage(_tap.APImage, ulCorner); string drawString = "AP:" + _tap.getOperateChannel() + " " + _tap.SSID + " " + _tap.getMACAddress(); System.Drawing.Font drawFont = new System.Drawing.Font( "Arial", 8); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.White); gr.DrawString(drawString, drawFont, drawBrush, (int)_tap.x + 10, (int)_tap.y - 10); drawFont.Dispose(); drawBrush.Dispose(); } } //gr.DrawPie(new Pen(Color.Yellow), 500/2, 500/2, 1, 1, 1, 360); piB.Image = bm; } catch (Exception ex) { MessageBox.Show("refr:" + ex.Message); } }