public void GenerateEvent(double time, ILocation location) { // Overloads GenerateEvent to allow the simulation to provide the time the event occurs. XYDoubleLocation initalCorner = (XYDoubleLocation)field[0]; // Casting to xyLocation objects. Other XYDoubleLocation finalCorner = (XYDoubleLocation)field[1]; // coordinate systems are not supported. List<PEQNode> nodesInRange = new List<PEQNode>(); // Generate the random center location of the event. eventCenter = (XYDoubleLocation)location; eventCenter.SetField(field); Notify(generateStaticReport(time, eventCenter)); foreach (PEQNode node in nodes.NodeQueue) { // Find which nodes are within the effective detection area. if (eventCenter.Distance(node.Location) <= eventSize) // if in the event area nodesInRange.Add(node); } double eventTime = 0; for (int i = 0; i < this.numOccurances; i++) { eventTime = time + i / this.eventFreq; foreach (PEQNode node in nodesInRange) { PEQMessageApplication appMsg = new PEQMessageApplication(); // Create a new app message appMsg._Data._DataID = _dataID++; MessageEvent msgEvent = new MessageEvent(appMsg); // create a new message event msgEvent.Referrer = node; // set the referrer to the current node PEQDataInfoReport rep = new PEQDataInfoReport(node.ID, eventTime); rep._Sent = 1; rep._DataID = appMsg._Data._DataID; Notify(rep); PEQTimerInternal messageTimer = new PEQTimerInternal(appMsg, eventTime, node); eventMgr.AddEvent(messageTimer); // add the event to the Event Queue. } } SimulationCompleteEvent simCompleteEvent = new SimulationCompleteEvent(nodes); simCompleteEvent.Time = eventTime + 60; // one minute after last event occurs eventMgr.AddEvent(simCompleteEvent); }
public IInfoReport Subtract(IInfoReport targetFromThisObject) { // Probably will be unused for this report type. if (targetFromThisObject is PEQDataInfoReport) { PEQDataInfoReport target = (PEQDataInfoReport)targetFromThisObject; if (target._DataID != _DataID) return null; int newID; double newTimestamp; ILocation newLocation; bool sameNode = false; if (targetFromThisObject.ID == _id) { sameNode = true; newID = _id; newLocation = _location; } else { sameNode = false; newID = int.MaxValue; newLocation = null; } if (targetFromThisObject.Time > _timestamp) newTimestamp = targetFromThisObject.Time; else newTimestamp = _timestamp; PEQDataInfoReport output = new PEQDataInfoReport(newID, newTimestamp, _key, _label); output._location = newLocation; output._DataID = _DataID; output._Received = _Received - target._Received; output._Sent = _Sent - target._Sent; return output; } else return null; }
private void processNotify(PEQMessageNotify msg) { if ((msg._SinkID == _id) && _isSink) { sendAck(msg); _dataReceived++; msg._Data._TotalDistance += msg._nextHopCheat.Distance(_location); if (_SINK_REPORTS) Notify(GeneratePEQSinkInfoReport(_eventManager.CurrentClock - msg._Data._StartTime, msg)); PEQDataInfoReport dataReport = new PEQDataInfoReport(this.ID, _eventManager.CurrentClock); dataReport._Received = 1; dataReport._DataID = msg._Data._DataID; Notify(dataReport); } else { // Find route to Sink foreach (PEQTableEntryRouting entry in _tableRouting) { if ((entry._SinkID == msg._SinkID) && entry._Valid) { sendAck(msg); sendNotify(entry, msg); } } } }
/* / \ * // | \\ * / | \ * | */ public IInfoReport Add(IInfoReport withTarget) { if (withTarget is PEQDataInfoReport) { PEQDataInfoReport target = (PEQDataInfoReport)withTarget; if (target._DataID != _DataID) return null; int newID; double newTimestamp; ILocation newLocation; bool sameNode; if (withTarget.ID == _id) { sameNode = true; newID = _id; newLocation = _location; } else { sameNode = false; newID = int.MaxValue; newLocation = null; } if (withTarget.Time < _timestamp) newTimestamp = withTarget.Time; else newTimestamp = _timestamp; PEQDataInfoReport output = new PEQDataInfoReport(newID, newTimestamp, _key, _label); output._location = newLocation; output._DataID = _DataID; output._Received = _Received + target._Received; output._Sent = _Sent + target._Sent; return output; } else return null; }