Example #1
0
        /// <summary>
        /// generate data packet from this vechile to the TargetVehicle.
        /// </summary>
        /// <param name="DestinationVehicle"></param>
        public void GeneratePacket(VehicleUi DestinationVehicle)
        {
            Dispatcher.Invoke((Action) delegate
            {
                Packet packet = new Packet();

                packet.Type = PacketType.Data;
                PublicStatistics.GeneratedPacketsCount += 1;
                packet.PID          = PublicStatistics.GeneratedPacketsCount;
                packet.PacketLength = PublicParamerters.DataPacketLength;

                packet.TravelledRoadSegmentString += CurrentLane.MyRoadSegment.RID; // add the first rs.
                packet.VehiclesString             += VID;                           // start by current sender.
                packet.SRID = CurrentLane.MyRoadSegment.RID;
                // set source and distination:
                packet.SourceVehicle      = this;
                packet.DestinationVehicle = DestinationVehicle;
                packet.Direction          = DestinationVehicle.CurrentLane.LaneDirection;
                packet.CurrentRoadSegment = CurrentLane.MyRoadSegment;                                                   // the segment of the vechile.

                packet.EuclideanDistance = Computations.Distance(InstanceLocation, DestinationVehicle.InstanceLocation); // the intial distance
                packet.RoutingDistance   = packet.EuclideanDistance;
                packet.SVID = VID;
                packet.DVID = DestinationVehicle.VID;

                this.SetNotationSign(NotationsSign.HasPacket);
                DestinationVehicle.SetNotationSign(NotationsSign.Destination);
                DestinationVehicle.WaitingPacketsIDsList.Add(packet.PID); // flage

                // start count the delay.
                PacketQueue.Enqueue(packet);                                                                  // add the packet to the queue.
                PacketQueueTimer.Interval = TimeSpan.FromSeconds(PublicParamerters.PacketQueueTimerInterval); // retry after...
                PacketQueueTimer.Start();                                                                     // start the timer.
            });
        }
Example #2
0
 /// <summary>
 /// forward the packet to the NEXT
 /// </summary>
 /// <param name="packet"></param>
 /// <param name="next"></param>
 public void RelayPacket(Packet packet, VehicleUi next)
 {
     Dispatcher.Invoke((Action) delegate
     {
         packet.PathWaitingTimes += packet.HopWaitingTimes; // save the path waiting time and clear the hop.
         packet.HopWaitingTimes   = 0;                      // re-intilize the hop-waiting.
         packet.PropagationAndTransmissionDelay += DelayModel.Delay(this, next);
         packet.HopsVehicles    += 1;
         packet.RoutingDistance += Computations.Distance(InstanceLocation, next.InstanceLocation);
         packet.VehiclesString  += "-" + next.VID;
         next.RecievePacket(packet);
         PacketQueueTimer.Interval = TimeSpan.FromSeconds(PublicParamerters.PacketQueueTimerInterval); // retry after...
         next.SetNotationSign(NotationsSign.HasPacket);
         SetNotationSign(NotationsSign.HasNoPacket);
     });
 }