示例#1
0
    def testParseSamplePacket(self):
        f = open(os.path.join(_location, "ParticipantInfoStringsAdditionalPacket_1.bin"), "rb")
        p = Packet.readFrom(f)
        self.assertEqual(ParticipantInfoStringsAdditionalPacket, p.__class__)

        # Packet Header
        self.assertEqual(1235, p.buildVersion)
        self.assertEqual(2, p.packetType)
        self.assertEqual(32, p.sequenceNumber)

        # Packet Data
        self.assertEqual(32, p["offset"])

        # Participants
        self.assertEqual(16, len(p["participants"]))
        self.assertEqual("Abdullah El Khereiji", p["participants"][0]["name"])

        try:
            # Python 2
            expect_name = unicode("Dominic Schnberner")
        except NameError:
            # Python 3
            expect_name = "Dominic Sch\udcf6nberner"

        self.assertEqual(expect_name, p["participants"][15]["name"])
def mainloop():
	global currentPacket, udp_isopen
	while udp_isopen:
		data = udpSocket.recv(1400)
		try:
			currentPacket = Packet.readFrom(StringIO(data))
		except:
			pass
示例#3
0
    def run(self):
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

        # Bind to the server address
        sock.bind(("", self.port))
        group = socket.inet_aton(_MCAST_ANY)
        mreq = struct.pack("4sL", group, socket.INADDR_ANY)
        sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)

        while True:
            data = sock.recv(1400)
            packet = Packet.readFrom(BytesIO(data))
            for listener in self.listeners:
                listener.handlePacket(packet)
示例#4
0
    def run(self):
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

        # Bind to the server address
        sock.bind(("", self.port))
        group = socket.inet_aton(_MCAST_ANY)
        mreq = struct.pack("4sL", group, socket.INADDR_ANY)
        sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)

        while True:
            try:
                data, addr = sock.recvfrom(1400)
                # print("Source:", addr[0])
                if addr[0] == local_ip:
                    packet = Packet.readFrom(BytesIO(data))
                    for listener in self.listeners:
                        listener.handlePacket(packet)
            except Exception as ex:
                print("Error in stream.py : ", ex)
    def testParseSamplePacket(self):
        f = open(os.path.join(_location, "ParticipantInfoStringsPacket_1.bin"), "rb")
        p = Packet.readFrom(f)
        self.assertEqual(ParticipantInfoStringsPacket, p.__class__)

        # Packet Header
        self.assertEqual(1235, p.buildVersion)
        self.assertEqual(1, p.packetType)
        self.assertEqual(8, p.sequenceNumber)

        # Packet Data
        self.assertEqual("Mitsubishi Lancer Evolution X FQ400", p.getValue("carName"))
        self.assertEqual("Road C1", p.getValue("carClassName"))
        self.assertEqual("Cadwell", p.getValue("trackLocation"))
        self.assertEqual("Woodland", p.getValue("trackVariation"))

        # Participants
        self.assertEqual(16, len(p.participants))
        participant0 = p.participants[0]
        self.assertEqual("Andrew", participant0["name"])
        self.assertAlmostEqual(62.403419494628906, participant0["fastestLapTime"])
示例#6
0
    def testParseSamplePacket0(self):
        f = open(os.path.join(__location__, "packet_0.bin"), 'rb')
        p = Packet.readFrom(f)
        self.assertEqual(TelemetryPacket, p.__class__)
        self.assertEqual(1122, p.buildVersion)
        self.assertEqual(0, p.packetType)
        self.assertEqual(0, p.sequenceNumber)
        self.assertEqual(SessionState.FORMATION_LAP,
                         p.getValue("sessionState"))
        self.assertEqual(GameState.INGAME_PLAYING, p.getValue("gameState"))
        self.assertEqual(0, p.getValue("viewedParticipantIndex"))
        self.assertEqual(21, p.getValue("numParticipants"))

        self.assertEqual(0, p.getValue("gear"))
        self.assertEqual(6, p.getValue("numGears"))

        self.assertEqual(PitMode.NONE, p.getValue("pitMode"))
        self.assertEqual(PitSchedule.NONE, p.getValue("pitSchedule"))

        self.assertEqual(
            TyreFlags.ATTACHED + TyreFlags.INFLATED + TyreFlags.IS_ON_GROUND,
            p.tyres[0]["tyreFlags"])
        self.assertEqual(
            0.0, p.tyres[1]["tyreRPS"])  # Hmm, we're stopped in the test data!
        self.assertEqual(729, p.tyres[2]["brakeTempCelsius"])
        self.assertAlmostEqual(0.06453919, p.tyres[3]["rideHeight"], 8)

        self.assertEqual(15, p.data["ambientTemperature"])

        participant0 = p.participants[0]
        self.assertEqual(0, participant0["currentLapDistance"])
        self.assertEqual(1, participant0["racePosition"])
        self.assertEqual(-123.0, participant0["lastSectorTime"])
        self.assertEqual(False, participant0["classSameAsPlayer"])
        self.assertEqual(Sector.SECTOR_2, participant0["sector"])

        self.assertAlmostEqual(3890.4072, p.data["trackLength"], 4)

        self.assertEqual(RaceState.NOT_STARTED, p.data["raceState"])
        self.assertEqual(FlagColour.NONE, p.data["highestFlagColour"])
    def testParseSamplePacket(self):
        f = open(os.path.join(_location, "ParticipantInfoStringsPacket_1.bin"),
                 "rb")
        p = Packet.readFrom(f)
        self.assertEqual(ParticipantInfoStringsPacket, p.__class__)

        # Packet Header
        self.assertEqual(1235, p.buildVersion)
        self.assertEqual(1, p.packetType)
        self.assertEqual(8, p.sequenceNumber)

        # Packet Data
        self.assertEqual("Mitsubishi Lancer Evolution X FQ400", p["carName"])
        self.assertEqual("Road C1", p["carClassName"])
        self.assertEqual("Cadwell", p["trackLocation"])
        self.assertEqual("Woodland", p["trackVariation"])

        # Participants
        self.assertEqual(16, len(p["participants"]))
        participant0 = p["participants"][0]
        self.assertEqual("Andrew", participant0["name"])
        self.assertAlmostEqual(62.403419494628906,
                               participant0["fastestLapTime"])
示例#8
0
    def testParseSamplePacket0(self):
        f = open(os.path.join(_location, "packet_0.bin"), "rb")
        p = Packet.readFrom(f)
        self.assertEqual(TelemetryPacket, p.__class__)
        self.assertEqual(1122, p.buildVersion)
        self.assertEqual(0, p.packetType)
        self.assertEqual(0, p.sequenceNumber)
        self.assertEqual(SessionState.RACE, p.getValue("sessionState"))
        self.assertEqual(GameState.INGAME_PLAYING, p.getValue("gameState"))
        self.assertEqual(0, p.getValue("viewedParticipantIndex"))
        self.assertEqual(21, p.getValue("numParticipants"))

        self.assertEqual(0, p.getValue("gear"))
        self.assertEqual(6, p.getValue("numGears"))

        self.assertEqual(PitMode.NONE, p.getValue("pitMode"))
        self.assertEqual(PitSchedule.NONE, p.getValue("pitSchedule"))

        self.assertEqual(TyreFlags.ATTACHED + TyreFlags.INFLATED + TyreFlags.IS_ON_GROUND, p.tyres[0]["tyreFlags"])
        self.assertEqual(0.0, p.tyres[1]["tyreRPS"])  # Hmm, we're stopped in the test data!
        self.assertEqual(729, p.tyres[2]["brakeTempCelsius"])
        self.assertAlmostEqual(0.06453919, p.tyres[3]["rideHeight"], 8)

        self.assertEqual(15, p.data["ambientTemperature"])

        participant0 = p.participants[0]
        self.assertEqual(0, participant0["currentLapDistance"])
        self.assertEqual(1, participant0["racePosition"])
        self.assertEqual(-123.0, participant0["lastSectorTime"])
        self.assertEqual(False, participant0["classSameAsPlayer"])
        self.assertEqual(Sector.SECTOR_2, participant0["sector"])

        self.assertAlmostEqual(3890.4072, p.data["trackLength"], 4)

        self.assertEqual(RaceState.NOT_STARTED, p.data["raceState"])
        self.assertEqual(FlagColour.NONE, p.data["highestFlagColour"])
示例#9
0
 def testParsePacketHeader(self):
     p = Packet.readFrom(BytesIO(b"\xd2\x04\x03"))
     self.assertEqual(1234, p.buildVersion)
     self.assertEqual(3, p.packetType)
示例#10
0
 def testParsePacketHeader(self):
     p = Packet.readFrom(BytesIO(b"\xd2\x04\x03"))
     self.assertEqual(1234, p.buildVersion)
     self.assertEqual(3, p.packetType)
示例#11
0
 def testParsePacketHeader(self):
     p = Packet.readFrom(StringIO('\xd2\x04\x01'))
     self.assertEqual(1234, p.buildVersion)
     self.assertEqual(1, p.packetType)
示例#12
0
 def testParsePacketHeader(self):
     p = Packet.readFrom(StringIO('\xd2\x04\x01'))
     self.assertEqual(1234, p.buildVersion)
     self.assertEqual(1, p.packetType)