コード例 #1
0
        private IEnumerable <CellularTowerEvent> DetectEvent(string vehicleId, string linkId, long currentTick)
        {
            VehicleEvent vEvent = vehicleEvents[vehicleId];

            //if the linkId is null, it means the vehicle event is pre-defined (non-vehicular event)
            if (string.IsNullOrEmpty(linkId))
            {
                linkId = vEvent.CurLinkId;
            }
            else
            {
                vEvent.PreLinkId = vEvent.CurLinkId;
                vEvent.CurLinkId = linkId;
            }

            //find out the active event on this vehicle
            foreach (Event evt in vEvent.GetActiveEvent(currentTick))
            {
                //check if the event is happenning
                if (evt != null)
                {
                    ///current time.
                    Location  curLocation = null;
                    CellTower curCell     = null;
                    Location  preLocation = null;
                    CellTower preCell     = null;
                    curLocation = cellularNetwork.FindLocationByLinkId(vEvent.CurLinkId);
                    curCell     = cellularNetwork.FindCellTowerByLinkId(vEvent.CurLinkId);

                    preLocation = cellularNetwork.FindLocationByLinkId(vEvent.PreLinkId);
                    preCell     = cellularNetwork.FindCellTowerByLinkId(vEvent.PreLinkId);

                    switch (evt.EventType)
                    {
                    case EventType.OnCall:
                        //for any oncall events, just return the location
                        if (curCell != null && preCell != null && !curCell.Equals(preCell))
                        {
                            yield return(new CellularTowerEvent(vehicleId, curLocation.LocationId, curCell.CellTowerId, preLocation?.LocationId, preCell?.CellTowerId, evt, currentTick));
                        }
                        break;

                    case EventType.PowerOn:
                        if (curLocation != null && curCell != null &&
                            preLocation != null && preCell != null &&
                            !curCell.Equals(preCell))
                        {
                            //for now just use vechileId to represnet IMSI
                            yield return(new CellularTowerEvent(vehicleId, curLocation.LocationId, curCell.CellTowerId, preLocation.LocationId, preCell.CellTowerId, evt, currentTick));
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            yield return(null);
        }
コード例 #2
0
        private CellularTowerEvent DetectEvent(string vehicleId, string linkId, long currentTick)
        {
            VehicleEvent vEvent = vehicleEvents[vehicleId];

            //find out the active event on this vehicle
            Event evt = vEvent.GetActiveEvent(currentTick);

            //check if the event is happenning
            if (evt != null)
            {
                ///current time.
                Location  curlocation = null;
                CellTower curCell     = null;
                switch (evt.EventType)
                {
                case EventType.PowerOn:     //this is a LU event
                    curlocation = cellularNetwork.FindLocationByLinkId(linkId);
                    curCell     = cellularNetwork.FindCellTowerByLinkId(linkId);
                    if (curlocation != null && curCell != null)
                    {
                        //for now just use vechileId to represnet IMSI
                        return(new CellularTowerEvent(vehicleId, curlocation.LocationId, curCell.CellTowerId, evt, currentTick));
                    }
                    break;

                case EventType.OnCall:     //this is a hand-off event
                    curlocation = cellularNetwork.FindLocationByLinkId(linkId);
                    curCell     = cellularNetwork.FindCellTowerByLinkId(linkId);
                    if (curlocation != null && curCell != null)
                    {
                        //for now just use vechileId to represnet IMSI
                        return(new CellularTowerEvent(vehicleId, curlocation.LocationId, curCell.CellTowerId, evt, currentTick));
                    }
                    break;

                default:
                    break;
                }
            }
            return(null);
        }
コード例 #3
0
        private void GenerateEvent(string vehicleId, int currentTick)
        {
            Random rnd = new Random();
            //get a random number
            int vehiclePossible = rnd.Next(0, 10);

            //let's say 80% of vehicles will have PowerOn event
            if (vehiclePossible <= 8)
            {
                //no vehicle event on this vehicle yet. Means this is a new vehicle in the vissim network
                VehicleEvent vEvent = new VehicleEvent(vehicleId);
                vEvent.AddPowerOnEvent();

                int nextPossibleOnCall = rnd.Next(0, 10);

                //let's say 10% of vehicles will have OnCall event
                if (nextPossibleOnCall < 1)
                {
                    vEvent.AddOnCallEvent(currentTick);
                }

                vehicleEvents.Add(vEvent.VehicleId, vEvent);
            }
        }