private void HandlePacket(PacketHeader packet, byte[] bytes)
        {
            _telemetryRecorder.RecordPacket(packet, bytes);

            switch (packet.PacketType)
            {
            case PacketType.Motion:
                var motionPacket = StructUtility.ConvertToPacket <PacketMotionData>(bytes);
                OnMotionPacketReceived(new PacketReceivedEventArgs <PacketMotionData>(_oldMotionData, motionPacket));
                _oldMotionData = motionPacket;
                break;

            case PacketType.Session:
                var sessionPacket = StructUtility.ConvertToPacket <PacketSessionData>(bytes);
                OnSessionPacketReceived(new PacketReceivedEventArgs <PacketSessionData>(_oldSessionData, sessionPacket));
                _oldSessionData = sessionPacket;
                break;

            case PacketType.LapData:
                var lapPacket = StructUtility.ConvertToPacket <PacketLapData>(bytes);
                OnLapPacketReceivedReceived(new PacketReceivedEventArgs <PacketLapData>(_oldLapData, lapPacket));
                _oldLapData = lapPacket;
                break;

            case PacketType.Event:
                var eventPacket = StructUtility.ConvertToPacket <EventPacket>(bytes);
                OnEventPacketReceived(new PacketReceivedEventArgs <EventPacket>(_oldEventPacket, eventPacket));
                _oldEventPacket = eventPacket;
                break;

            case PacketType.Participants:
                var participantPacket = StructUtility.ConvertToPacket <PacketParticipantsData>(bytes);
                OnParticipantsPacketReceived(new PacketReceivedEventArgs <PacketParticipantsData>(_oldParticipantsData, participantPacket));
                _oldParticipantsData = participantPacket;
                break;

            case PacketType.CarSetups:
                var carSetupsPacket = StructUtility.ConvertToPacket <PacketCarSetupData>(bytes);
                OnCarSetupPacketReceived(new PacketReceivedEventArgs <PacketCarSetupData>(_oldCarSetupData, carSetupsPacket));
                _oldCarSetupData = carSetupsPacket;
                break;

            case PacketType.CarTelemetry:
                var carTelemetryPacket = StructUtility.ConvertToPacket <PacketCarTelemetryData>(bytes);
                OnCarTelemetryPacketReceived(new PacketReceivedEventArgs <PacketCarTelemetryData>(_oldCarTelemetryData, carTelemetryPacket));
                _oldCarTelemetryData = carTelemetryPacket;
                break;

            case PacketType.CarStatus:
                var carStatusPacket = StructUtility.ConvertToPacket <PacketCarStatusData>(bytes);
                OnCarStatusPacketReceived(new PacketReceivedEventArgs <PacketCarStatusData>(_oldCarStatusData, carStatusPacket));
                _oldCarStatusData = carStatusPacket;
                break;
            }

            _oldSessionId       = packet.SessionUId;
            _oldFrameIdentifier = packet.FrameIdentifier;
        }
        public void OnDebugDataSelected(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count == 0)
            {
                return;
            }

            var selectedDebugData = ((DebugModel)e.AddedItems[0]);

            switch (selectedDebugData.PacketType)
            {
            case PacketType.Motion:
                PacketMotionData motionData = StructUtility.ConvertToPacket <PacketMotionData>(selectedDebugData.Data);
                DebugDetails = new ObjectViewModelHierarchy(motionData);
                return;

            case PacketType.Session:
                PacketSessionData sessionData = StructUtility.ConvertToPacket <PacketSessionData>(selectedDebugData.Data);
                DebugDetails = new ObjectViewModelHierarchy(sessionData);
                return;

            case PacketType.LapData:
                PacketLapData lapData = StructUtility.ConvertToPacket <PacketLapData>(selectedDebugData.Data);
                DebugDetails = new ObjectViewModelHierarchy(lapData);
                return;

            case PacketType.Event:
                EventPacket eventData = StructUtility.ConvertToPacket <EventPacket>(selectedDebugData.Data);
                DebugDetails = new ObjectViewModelHierarchy(eventData);
                return;

            case PacketType.Participants:
                PacketParticipantsData participantsData = StructUtility.ConvertToPacket <PacketParticipantsData>(selectedDebugData.Data);
                DebugDetails = new ObjectViewModelHierarchy(participantsData);
                return;

            case PacketType.CarSetups:
                PacketCarSetupData carSetupsData = StructUtility.ConvertToPacket <PacketCarSetupData>(selectedDebugData.Data);
                DebugDetails = new ObjectViewModelHierarchy(carSetupsData);
                return;

            case PacketType.CarTelemetry:
                PacketCarTelemetryData carTelemetryData = StructUtility.ConvertToPacket <PacketCarTelemetryData>(selectedDebugData.Data);
                DebugDetails = new ObjectViewModelHierarchy(carTelemetryData);
                return;

            case PacketType.CarStatus:
                PacketCarStatusData carStatusData = StructUtility.ConvertToPacket <PacketCarStatusData>(selectedDebugData.Data);
                DebugDetails = new ObjectViewModelHierarchy(carStatusData);
                return;
            }
        }
示例#3
0
        public async Task ReceiveLoop(CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                UdpReceiveResult receiveResult = await _udpReceiver.Receive(cancellationToken).ConfigureAwait(false);

                byte[]       rawPacked = receiveResult.Buffer;
                PacketHeader header    = DeserializePackedHeader(rawPacked);
                switch (header.MPacketId)
                {
                case 0:
                    PacketMotionData packetMotionData = Deserialize <PacketMotionData>(rawPacked);
                    _dataSetCompositor.ProcessPacket(packetMotionData);
                    break;

                case 1:
                    PacketSessionData packetSessionData = Deserialize <PacketSessionData>(rawPacked);
                    _dataSetCompositor.ProcessPacket(packetSessionData);
                    break;

                case 2:
                    PacketLapData packetLapData = Deserialize <PacketLapData>(rawPacked);
                    _dataSetCompositor.ProcessPacket(packetLapData);
                    break;

                case 3:
                    PacketEventData packetEventData = Deserialize <PacketEventData>(rawPacked);
                    _dataSetCompositor.ProcessPacket(packetEventData);
                    break;

                case 4:
                    PacketParticipantsData packetParticipantsData = Deserialize <PacketParticipantsData>(rawPacked);
                    _dataSetCompositor.ProcessPacket(packetParticipantsData);
                    break;

                case 5:
                    PacketCarSetupData packetCarSetupData = Deserialize <PacketCarSetupData>(rawPacked);
                    _dataSetCompositor.ProcessPacket(packetCarSetupData);
                    break;

                case 6:
                    PacketCarTelemetryData packetCarTelemetryData = Deserialize <PacketCarTelemetryData>(rawPacked);
                    _dataSetCompositor.ProcessPacket(packetCarTelemetryData);
                    break;

                case 7:
                    PacketCarStatusData packetCarStatusData = Deserialize <PacketCarStatusData>(rawPacked);
                    _dataSetCompositor.ProcessPacket(packetCarStatusData);
                    break;
                }
            }
        }
示例#4
0
        private static IPacket Participants(PacketHeader packetHeader, BinaryReader reader)
        {
            var packetParticipantsData = new PacketParticipantsData(packetHeader);

            packetParticipantsData.NumActiveCars = reader.ReadByte();

            for (int i = 0; i < MaxNumberOfCarsOnTrack; i++)
            {
                var participantData = new ParticipantData();

                packetParticipantsData.Participants[i] = participantData;

                participantData.AiControlled = (reader.ReadByte() != 0);
                participantData.DriverId     = reader.ReadByte();
                participantData.TeamId       = reader.ReadByte();
                participantData.RaceNumber   = reader.ReadByte();
                participantData.Nationality  = reader.ReadByte();
                participantData.Name         = reader.ReadChars(47);

                participantData.YourTelemetry = (TelemetrySetting)reader.ReadByte();
            }

            return(packetParticipantsData);
        }
 public void OnPacketParticipantsData(ref PacketParticipantsData pParticipants, PacketSource packetSource)
 {
     WritePacket(pParticipants.Header.SessionUID, ref pParticipants, packetSource);
 }
 public void OnPacketParticipantsData(ref PacketParticipantsData pParticipants, PacketSource packetSource)
 {
     HandlePacket(ph => ph.OnPacketParticipantsData, ref pParticipants, packetSource);
 }
示例#7
0
 internal void ProcessPacket(PacketParticipantsData packetParticipantsData)
 {
     AllPacketsComposition.PacketParticipantsData = packetParticipantsData;
     _isPacketParticipantsDataFilled = true;
 }
 public void OnPacketParticipantsData(ref PacketParticipantsData pParticipants, PacketSource packetSource)
 {
 }
示例#9
0
 public void OnPacketParticipantsData(ref PacketParticipantsData pParticipants, PacketSource packetSource)
 {
     Delay(pParticipants.Header.SessionUID, pParticipants.Header.SessionTime, packetSource);
 }